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
) {
3311 EDIT_EM_SetSel(es
, ~0u, 0, FALSE
);
3313 /* delete character left of caret */
3314 EDIT_MoveBackward(es
, TRUE
);
3316 /* delete to end of line */
3317 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3319 /* delete character right of caret */
3320 EDIT_MoveForward(es
, TRUE
);
3327 if (!(es
->style
& ES_READONLY
))
3333 /* If the edit doesn't want the return send a message to the default object */
3334 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3338 if (!EDIT_IsInsideDialog(es
)) break;
3340 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3341 if (HIWORD(dw
) == DC_HASDEFID
)
3343 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3346 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3347 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3353 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3354 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3357 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3358 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3363 if (EDIT_EM_SetSel(es
, 0, get_text_length(es
), FALSE
))
3365 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3366 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3375 /*********************************************************************
3380 static LRESULT
EDIT_WM_KillFocus(HTHEME theme
, EDITSTATE
*es
)
3382 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3384 es
->flags
&= ~EF_FOCUSED
;
3386 if (!(es
->style
& ES_NOHIDESEL
))
3387 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3388 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3389 /* Throw away left over scroll when we lose focus */
3390 es
->wheelDeltaRemainder
= 0;
3395 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3400 /*********************************************************************
3404 * The caret position has been set on the WM_LBUTTONDOWN message
3407 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3410 INT e
= es
->selection_end
;
3415 es
->bCaptureState
= TRUE
;
3416 SetCapture(es
->hwndSelf
);
3418 l
= EDIT_EM_LineFromChar(es
, e
);
3419 li
= EDIT_EM_LineIndex(es
, l
);
3420 ll
= EDIT_EM_LineLength(es
, e
);
3421 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3422 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3423 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3424 EDIT_EM_ScrollCaret(es
);
3425 es
->region_posx
= es
->region_posy
= 0;
3426 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3431 /*********************************************************************
3436 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3441 es
->bCaptureState
= TRUE
;
3442 SetCapture(es
->hwndSelf
);
3443 EDIT_ConfinePoint(es
, &x
, &y
);
3444 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3445 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3446 EDIT_EM_ScrollCaret(es
);
3447 es
->region_posx
= es
->region_posy
= 0;
3448 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3450 if (!(es
->flags
& EF_FOCUSED
))
3451 SetFocus(es
->hwndSelf
);
3457 /*********************************************************************
3462 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3464 if (es
->bCaptureState
) {
3465 KillTimer(es
->hwndSelf
, 0);
3466 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3468 es
->bCaptureState
= FALSE
;
3473 /*********************************************************************
3478 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3480 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3485 /*********************************************************************
3490 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3496 /* If the mouse has been captured by process other than the edit control itself,
3497 * the windows edit controls will not select the strings with mouse move.
3499 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3503 * FIXME: gotta do some scrolling if outside client
3504 * area. Maybe reset the timer ?
3507 EDIT_ConfinePoint(es
, &x
, &y
);
3508 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3509 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3510 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3511 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3512 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3517 /*********************************************************************
3522 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3535 BOOL rev
= es
->bEnableState
&&
3536 ((es
->flags
& EF_FOCUSED
) ||
3537 (es
->style
& ES_NOHIDESEL
));
3538 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3540 /* The dc we use for calculating may not be the one we paint into.
3541 This is the safest action. */
3542 EDIT_InvalidateUniscribeData(es
);
3543 GetClientRect(es
->hwndSelf
, &rcClient
);
3545 /* get the background brush */
3546 brush
= EDIT_NotifyCtlColor(es
, dc
);
3548 /* paint the border and the background */
3549 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3551 if(es
->style
& WS_BORDER
) {
3552 bw
= GetSystemMetrics(SM_CXBORDER
);
3553 bh
= GetSystemMetrics(SM_CYBORDER
);
3555 if(es
->style
& ES_MULTILINE
) {
3556 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3557 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3560 /* Draw the frame. Same code as in nonclient.c */
3561 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3562 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3563 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3564 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3565 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3566 SelectObject(dc
, old_brush
);
3568 /* Keep the border clean */
3569 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3570 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3573 GetClipBox(dc
, &rc
);
3574 FillRect(dc
, &rc
, brush
);
3576 IntersectClipRect(dc
, es
->format_rect
.left
,
3577 es
->format_rect
.top
,
3578 es
->format_rect
.right
,
3579 es
->format_rect
.bottom
);
3580 if (es
->style
& ES_MULTILINE
) {
3582 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3585 old_font
= SelectObject(dc
, es
->font
);
3587 if (!es
->bEnableState
)
3588 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3589 GetClipBox(dc
, &rcRgn
);
3590 if (es
->style
& ES_MULTILINE
) {
3591 INT vlc
= get_vertical_line_count(es
);
3592 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3593 EDIT_UpdateUniscribeData(es
, dc
, i
);
3594 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3595 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3596 EDIT_PaintLine(es
, dc
, i
, rev
);
3599 EDIT_UpdateUniscribeData(es
, dc
, 0);
3600 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3601 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3602 EDIT_PaintLine(es
, dc
, 0, rev
);
3605 SelectObject(dc
, old_font
);
3608 EndPaint(es
->hwndSelf
, &ps
);
3611 static void EDIT_WM_NCPaint(HWND hwnd
, HRGN region
)
3613 DWORD exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3614 HTHEME theme
= GetWindowTheme(hwnd
);
3615 HRGN cliprgn
= region
;
3617 if (theme
&& exStyle
& WS_EX_CLIENTEDGE
)
3621 int cxEdge
= GetSystemMetrics(SM_CXEDGE
),
3622 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
3623 const int part
= EP_EDITTEXT
;
3624 int state
= ETS_NORMAL
;
3625 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3627 if (!IsWindowEnabled(hwnd
))
3628 state
= ETS_DISABLED
;
3629 else if (dwStyle
& ES_READONLY
)
3630 state
= ETS_READONLY
;
3631 else if (GetFocus() == hwnd
)
3632 state
= ETS_FOCUSED
;
3634 GetWindowRect(hwnd
, &r
);
3636 /* New clipping region passed to default proc to exclude border */
3637 cliprgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
,
3638 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
3639 if (region
!= (HRGN
)1)
3640 CombineRgn(cliprgn
, cliprgn
, region
, RGN_AND
);
3641 OffsetRect(&r
, -r
.left
, -r
.top
);
3643 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
3644 OffsetRect(&r
, -r
.left
, -r
.top
);
3646 if (IsThemeBackgroundPartiallyTransparent(theme
, part
, state
))
3647 DrawThemeParentBackground(hwnd
, dc
, &r
);
3648 DrawThemeBackground(theme
, dc
, part
, state
, &r
, 0);
3649 ReleaseDC(hwnd
, dc
);
3652 /* Call default proc to get the scrollbars etc. also painted */
3653 DefWindowProcW (hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
3656 /*********************************************************************
3661 static void EDIT_WM_SetFocus(HTHEME theme
, EDITSTATE
*es
)
3663 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3665 es
->flags
|= EF_FOCUSED
;
3667 if (!(es
->style
& ES_NOHIDESEL
))
3668 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3670 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3671 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3672 ShowCaret(es
->hwndSelf
);
3673 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3676 flags
|= RDW_FRAME
| RDW_ERASE
;
3678 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3682 /*********************************************************************
3686 * With Win95 look the margins are set to default font value unless
3687 * the system font (font == 0) is being set, in which case they are left
3691 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3699 EDIT_InvalidateUniscribeData(es
);
3700 dc
= GetDC(es
->hwndSelf
);
3702 old_font
= SelectObject(dc
, font
);
3703 GetTextMetricsW(dc
, &tm
);
3704 es
->line_height
= tm
.tmHeight
;
3705 es
->char_width
= tm
.tmAveCharWidth
;
3707 SelectObject(dc
, old_font
);
3708 ReleaseDC(es
->hwndSelf
, dc
);
3710 /* Reset the format rect and the margins */
3711 GetClientRect(es
->hwndSelf
, &clientRect
);
3712 EDIT_SetRectNP(es
, &clientRect
);
3713 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3714 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3716 if (es
->style
& ES_MULTILINE
)
3717 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3719 EDIT_CalcLineWidth_SL(es
);
3722 EDIT_UpdateText(es
, NULL
, TRUE
);
3723 if (es
->flags
& EF_FOCUSED
) {
3725 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3726 EDIT_SetCaretPos(es
, es
->selection_end
,
3727 es
->flags
& EF_AFTER_WRAP
);
3728 ShowCaret(es
->hwndSelf
);
3733 /*********************************************************************
3738 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3739 * The modified flag is reset. No notifications are sent.
3741 * For single-line controls, reception of WM_SETTEXT triggers:
3742 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3745 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
)
3747 if (es
->flags
& EF_UPDATE
)
3748 /* fixed this bug once; complain if we see it about to happen again. */
3749 ERR("SetSel may generate UPDATE message whose handler may reset "
3752 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3755 TRACE("%s\n", debugstr_w(text
));
3756 EDIT_EM_ReplaceSel(es
, FALSE
, text
, strlenW(text
), FALSE
, FALSE
);
3761 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3764 es
->flags
&= ~EF_MODIFIED
;
3765 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3767 /* Send the notification after the selection start and end have been set
3768 * edit control doesn't send notification on WM_SETTEXT
3769 * if it is multiline, or it is part of combobox
3771 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3773 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3774 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3776 EDIT_EM_ScrollCaret(es
);
3777 EDIT_UpdateScrollInfo(es
);
3778 EDIT_InvalidateUniscribeData(es
);
3782 /*********************************************************************
3787 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3789 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3791 GetClientRect(es
->hwndSelf
, &rc
);
3792 EDIT_SetRectNP(es
, &rc
);
3793 EDIT_UpdateText(es
, NULL
, TRUE
);
3798 /*********************************************************************
3802 * This message is sent by SetWindowLong on having changed either the Style
3803 * or the extended style.
3805 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3807 * See also EDIT_WM_NCCreate
3809 * It appears that the Windows version of the edit control allows the style
3810 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3811 * style variable which will generally be different. In this function we
3812 * update the internal style based on what changed in the externally visible
3815 * Much of this content as based upon the MSDN, especially:
3816 * Platform SDK Documentation -> User Interface Services ->
3817 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3818 * Edit Control Styles
3820 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3822 if (GWL_STYLE
== which
) {
3823 DWORD style_change_mask
;
3825 /* Only a subset of changes can be applied after the control
3828 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3830 if (es
->style
& ES_MULTILINE
)
3831 style_change_mask
|= ES_WANTRETURN
;
3833 new_style
= style
->styleNew
& style_change_mask
;
3835 /* Number overrides lowercase overrides uppercase (at least it
3836 * does in Win95). However I'll bet that ES_NUMBER would be
3837 * invalid under Win 3.1.
3839 if (new_style
& ES_NUMBER
) {
3840 ; /* do not override the ES_NUMBER */
3841 } else if (new_style
& ES_LOWERCASE
) {
3842 new_style
&= ~ES_UPPERCASE
;
3845 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3846 } else if (GWL_EXSTYLE
== which
) {
3847 ; /* FIXME - what is needed here */
3849 WARN ("Invalid style change %ld\n",which
);
3855 /*********************************************************************
3860 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3862 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3863 if (EDIT_EM_CanUndo(es
))
3866 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3867 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3870 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3874 /*********************************************************************
3879 static void EDIT_WM_Timer(EDITSTATE
*es
)
3881 if (es
->region_posx
< 0) {
3882 EDIT_MoveBackward(es
, TRUE
);
3883 } else if (es
->region_posx
> 0) {
3884 EDIT_MoveForward(es
, TRUE
);
3887 * FIXME: gotta do some vertical scrolling here, like
3888 * EDIT_EM_LineScroll(hwnd, 0, 1);
3892 /*********************************************************************
3897 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3902 if (!(es
->style
& ES_MULTILINE
))
3905 if (!(es
->style
& ES_AUTOHSCROLL
))
3909 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3912 TRACE("SB_LINELEFT\n");
3914 dx
= -es
->char_width
;
3917 TRACE("SB_LINERIGHT\n");
3918 if (es
->x_offset
< es
->text_width
)
3919 dx
= es
->char_width
;
3922 TRACE("SB_PAGELEFT\n");
3924 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3927 TRACE("SB_PAGERIGHT\n");
3928 if (es
->x_offset
< es
->text_width
)
3929 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3937 TRACE("SB_RIGHT\n");
3938 if (es
->x_offset
< es
->text_width
)
3939 dx
= es
->text_width
- es
->x_offset
;
3942 TRACE("SB_THUMBTRACK %d\n", pos
);
3943 es
->flags
|= EF_HSCROLL_TRACK
;
3944 if(es
->style
& WS_HSCROLL
)
3945 dx
= pos
- es
->x_offset
;
3950 if(pos
< 0 || pos
> 100) return 0;
3951 /* Assume default scroll range 0-100 */
3952 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3953 new_x
= pos
* (es
->text_width
- fw
) / 100;
3954 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3957 case SB_THUMBPOSITION
:
3958 TRACE("SB_THUMBPOSITION %d\n", pos
);
3959 es
->flags
&= ~EF_HSCROLL_TRACK
;
3960 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3961 dx
= pos
- es
->x_offset
;
3966 if(pos
< 0 || pos
> 100) return 0;
3967 /* Assume default scroll range 0-100 */
3968 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3969 new_x
= pos
* (es
->text_width
- fw
) / 100;
3970 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3973 /* force scroll info update */
3974 EDIT_UpdateScrollInfo(es
);
3975 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3979 TRACE("SB_ENDSCROLL\n");
3982 * FIXME : the next two are undocumented !
3983 * Are we doing the right thing ?
3984 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3985 * although it's also a regular control message.
3987 case EM_GETTHUMB
: /* this one is used by NT notepad */
3990 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3991 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
3994 /* Assume default scroll range 0-100 */
3995 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3996 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
3998 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4002 TRACE("EM_LINESCROLL16\n");
4007 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4013 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4014 /* check if we are going to move too far */
4015 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4016 dx
= es
->text_width
- fw
- es
->x_offset
;
4018 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4024 /*********************************************************************
4029 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4033 if (!(es
->style
& ES_MULTILINE
))
4036 if (!(es
->style
& ES_AUTOVSCROLL
))
4045 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4046 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4047 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4049 EDIT_EM_Scroll(es
, action
);
4056 TRACE("SB_BOTTOM\n");
4057 dy
= es
->line_count
- 1 - es
->y_offset
;
4060 TRACE("SB_THUMBTRACK %d\n", pos
);
4061 es
->flags
|= EF_VSCROLL_TRACK
;
4062 if(es
->style
& WS_VSCROLL
)
4063 dy
= pos
- es
->y_offset
;
4066 /* Assume default scroll range 0-100 */
4069 if(pos
< 0 || pos
> 100) return 0;
4070 vlc
= get_vertical_line_count(es
);
4071 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4072 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4073 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4074 es
->line_count
, es
->y_offset
, pos
, dy
);
4077 case SB_THUMBPOSITION
:
4078 TRACE("SB_THUMBPOSITION %d\n", pos
);
4079 es
->flags
&= ~EF_VSCROLL_TRACK
;
4080 if(es
->style
& WS_VSCROLL
)
4081 dy
= pos
- es
->y_offset
;
4084 /* Assume default scroll range 0-100 */
4087 if(pos
< 0 || pos
> 100) return 0;
4088 vlc
= get_vertical_line_count(es
);
4089 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4090 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4091 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4092 es
->line_count
, es
->y_offset
, pos
, dy
);
4096 /* force scroll info update */
4097 EDIT_UpdateScrollInfo(es
);
4098 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4102 TRACE("SB_ENDSCROLL\n");
4105 * FIXME : the next two are undocumented !
4106 * Are we doing the right thing ?
4107 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4108 * although it's also a regular control message.
4110 case EM_GETTHUMB
: /* this one is used by NT notepad */
4113 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4114 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4117 /* Assume default scroll range 0-100 */
4118 INT vlc
= get_vertical_line_count(es
);
4119 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4121 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4125 TRACE("EM_LINESCROLL %d\n", pos
);
4130 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4135 EDIT_EM_LineScroll(es
, 0, dy
);
4139 /*********************************************************************
4143 * FIXME: is this right ? (or should it be only VSCROLL)
4144 * (and maybe only for edit controls that really have their
4145 * own scrollbars) (and maybe only for multiline controls ?)
4146 * All in all: very poorly documented
4149 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4151 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4152 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4156 /********************************************************************
4158 * The Following code is to handle inline editing from IMEs
4161 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4165 LPSTR lpCompStrAttr
= NULL
;
4168 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4175 lpCompStr
= heap_alloc(buflen
);
4178 ERR("Unable to allocate IME CompositionString\n");
4183 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4185 if (CompFlag
& GCS_COMPATTR
)
4188 * We do not use the attributes yet. it would tell us what characters
4189 * are in transition and which are converted or decided upon
4191 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4195 lpCompStrAttr
= heap_alloc(dwBufLenAttr
+ 1);
4198 ERR("Unable to allocate IME Attribute String\n");
4199 heap_free(lpCompStr
);
4202 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4204 lpCompStrAttr
[dwBufLenAttr
] = 0;
4208 /* check for change in composition start */
4209 if (es
->selection_end
< es
->composition_start
)
4210 es
->composition_start
= es
->selection_end
;
4212 /* replace existing selection string */
4213 es
->selection_start
= es
->composition_start
;
4215 if (es
->composition_len
> 0)
4216 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4218 es
->selection_end
= es
->selection_start
;
4220 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4221 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4223 es
->selection_start
= es
->composition_start
;
4224 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4226 heap_free(lpCompStrAttr
);
4227 heap_free(lpCompStr
);
4230 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4235 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4241 lpResultStr
= heap_alloc(buflen
);
4244 ERR("Unable to alloc buffer for IME string\n");
4248 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4250 /* check for change in composition start */
4251 if (es
->selection_end
< es
->composition_start
)
4252 es
->composition_start
= es
->selection_end
;
4254 es
->selection_start
= es
->composition_start
;
4255 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4256 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4257 es
->composition_start
= es
->selection_end
;
4258 es
->composition_len
= 0;
4260 heap_free(lpResultStr
);
4263 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4268 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4270 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4271 es
->composition_start
= es
->selection_end
;
4274 hIMC
= ImmGetContext(hwnd
);
4278 if (CompFlag
& GCS_RESULTSTR
)
4280 EDIT_GetResultStr(hIMC
, es
);
4285 if (CompFlag
& GCS_COMPSTR
)
4286 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4287 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4289 ImmReleaseContext(hwnd
, hIMC
);
4290 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4294 /*********************************************************************
4298 * See also EDIT_WM_StyleChanged
4300 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
4305 TRACE("Creating edit control, style = %08x\n", lpcs
->style
);
4307 if (!(es
= heap_alloc_zero(sizeof(*es
))))
4309 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4312 * Note: since the EDITSTATE has not been fully initialized yet,
4313 * we can't use any API calls that may send
4314 * WM_XXX messages before WM_NCCREATE is completed.
4317 es
->style
= lpcs
->style
;
4319 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4321 es
->hwndSelf
= hwnd
;
4322 /* Save parent, which will be notified by EN_* messages */
4323 es
->hwndParent
= lpcs
->hwndParent
;
4325 if (es
->style
& ES_COMBO
)
4326 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4328 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4329 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4331 /* Number overrides lowercase overrides uppercase (at least it
4332 * does in Win95). However I'll bet that ES_NUMBER would be
4333 * invalid under Win 3.1.
4335 if (es
->style
& ES_NUMBER
) {
4336 ; /* do not override the ES_NUMBER */
4337 } else if (es
->style
& ES_LOWERCASE
) {
4338 es
->style
&= ~ES_UPPERCASE
;
4340 if (es
->style
& ES_MULTILINE
) {
4341 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4342 if (es
->style
& WS_VSCROLL
)
4343 es
->style
|= ES_AUTOVSCROLL
;
4344 if (es
->style
& WS_HSCROLL
)
4345 es
->style
|= ES_AUTOHSCROLL
;
4346 es
->style
&= ~ES_PASSWORD
;
4347 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4348 /* Confirmed - RIGHT overrides CENTER */
4349 if (es
->style
& ES_RIGHT
)
4350 es
->style
&= ~ES_CENTER
;
4351 es
->style
&= ~WS_HSCROLL
;
4352 es
->style
&= ~ES_AUTOHSCROLL
;
4355 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4356 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4357 es
->style
&= ~ES_CENTER
;
4358 es
->style
&= ~WS_HSCROLL
;
4359 es
->style
&= ~WS_VSCROLL
;
4360 if (es
->style
& ES_PASSWORD
)
4361 es
->password_char
= '*';
4364 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4365 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4367 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4369 if (!(es
->undo_text
= heap_alloc_zero((es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4371 es
->undo_buffer_size
= es
->buffer_size
;
4373 if (es
->style
& ES_MULTILINE
)
4374 if (!(es
->first_line_def
= heap_alloc_zero(sizeof(LINEDEF
))))
4379 * In Win95 look and feel, the WS_BORDER style is replaced by the
4380 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4381 * control a nonclient area so we don't need to draw the border.
4382 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4383 * a nonclient area and we should handle painting the border ourselves.
4385 * When making modifications please ensure that the code still works
4386 * for edit controls created directly with style 0x50800000, exStyle 0
4387 * (which should have a single pixel border)
4389 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4390 es
->style
&= ~WS_BORDER
;
4391 else if (es
->style
& WS_BORDER
)
4392 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4397 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4398 EDIT_InvalidateUniscribeData(es
);
4399 heap_free(es
->first_line_def
);
4400 heap_free(es
->undo_text
);
4401 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4402 heap_free(es
->logAttr
);
4408 /*********************************************************************
4413 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, const WCHAR
*name
)
4417 TRACE("%s\n", debugstr_w(name
));
4420 * To initialize some final structure members, we call some helper
4421 * functions. However, since the EDITSTATE is not consistent (i.e.
4422 * not fully initialized), we should be very careful which
4423 * functions can be called, and in what order.
4425 EDIT_WM_SetFont(es
, 0, FALSE
);
4426 EDIT_EM_EmptyUndoBuffer(es
);
4428 /* We need to calculate the format rect
4429 (applications may send EM_SETMARGINS before the control gets visible) */
4430 GetClientRect(es
->hwndSelf
, &clientRect
);
4431 EDIT_SetRectNP(es
, &clientRect
);
4435 EDIT_EM_ReplaceSel(es
, FALSE
, name
, strlenW(name
), FALSE
, FALSE
);
4436 /* if we insert text to the editline, the text scrolls out
4437 * of the window, as the caret is placed after the insert
4438 * pos normally; thus we reset es->selection... to 0 and
4441 es
->selection_start
= es
->selection_end
= 0;
4442 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4443 * Messages are only to be sent when the USER does something to
4444 * change the contents. So I am removing this EN_CHANGE
4446 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4448 EDIT_EM_ScrollCaret(es
);
4451 /* force scroll info update */
4452 EDIT_UpdateScrollInfo(es
);
4453 OpenThemeData(es
->hwndSelf
, WC_EDITW
);
4455 /* The rule seems to return 1 here for success */
4456 /* Power Builder masked edit controls will crash */
4458 /* FIXME: is that in all cases so ? */
4463 /*********************************************************************
4468 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4473 theme
= GetWindowTheme(es
->hwndSelf
);
4474 CloseThemeData(theme
);
4476 /* The app can own the text buffer handle */
4477 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
))
4478 LocalFree(es
->hloc32W
);
4480 EDIT_InvalidateUniscribeData(es
);
4482 pc
= es
->first_line_def
;
4490 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4491 heap_free(es
->undo_text
);
4497 static LRESULT CALLBACK
EDIT_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4499 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW(hwnd
, 0);
4500 HTHEME theme
= GetWindowTheme(hwnd
);
4504 TRACE("hwnd=%p msg=%#x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
4506 if (!es
&& msg
!= WM_NCCREATE
)
4507 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4509 if (es
&& (msg
!= WM_NCDESTROY
))
4510 EDIT_LockBuffer(es
);
4515 result
= EDIT_EM_GetSel(es
, (UINT
*)wParam
, (UINT
*)lParam
);
4519 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4520 EDIT_EM_ScrollCaret(es
);
4525 rect
= (RECT
*)lParam
;
4527 *rect
= es
->format_rect
;
4531 if ((es
->style
& ES_MULTILINE
) && lParam
)
4533 EDIT_SetRectNP(es
, (RECT
*)lParam
);
4534 EDIT_UpdateText(es
, NULL
, TRUE
);
4539 if ((es
->style
& ES_MULTILINE
) && lParam
)
4540 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4544 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4548 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4551 case EM_SCROLLCARET
:
4552 EDIT_EM_ScrollCaret(es
);
4557 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4562 es
->flags
|= EF_MODIFIED
;
4564 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4567 case EM_GETLINECOUNT
:
4568 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4572 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4576 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4580 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4584 result
= EDIT_EM_GetThumb(es
);
4587 /* these messages missing from specs */
4592 FIXME("undocumented message 0x%x, please report\n", msg
);
4593 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4597 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4602 const WCHAR
*textW
= (const WCHAR
*)lParam
;
4604 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, strlenW(textW
), TRUE
, TRUE
);
4610 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4613 case EM_SETLIMITTEXT
:
4614 EDIT_EM_SetLimitText(es
, wParam
);
4618 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4623 result
= (LRESULT
)EDIT_EM_Undo(es
);
4627 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4630 case EM_LINEFROMCHAR
:
4631 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4634 case EM_SETTABSTOPS
:
4635 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4638 case EM_SETPASSWORDCHAR
:
4639 EDIT_EM_SetPasswordChar(es
, wParam
);
4642 case EM_EMPTYUNDOBUFFER
:
4643 EDIT_EM_EmptyUndoBuffer(es
);
4646 case EM_GETFIRSTVISIBLELINE
:
4647 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4650 case EM_SETREADONLY
:
4652 DWORD old_style
= es
->style
;
4656 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | ES_READONLY
);
4657 es
->style
|= ES_READONLY
;
4661 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4662 es
->style
&= ~ES_READONLY
;
4665 if (old_style
^ es
->style
)
4666 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4672 case EM_SETWORDBREAKPROC
:
4673 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4677 case EM_GETWORDBREAKPROC
:
4678 result
= (LRESULT
)es
->word_break_proc
;
4681 case EM_GETPASSWORDCHAR
:
4682 result
= es
->password_char
;
4686 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4690 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4693 case EM_GETLIMITTEXT
:
4694 result
= es
->buffer_limit
;
4697 case EM_POSFROMCHAR
:
4698 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4699 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4702 case EM_CHARFROMPOS
:
4703 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4706 /* End of the EM_ messages which were in numerical order; what order
4707 * are these in? vaguely alphabetical?
4711 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
4715 result
= EDIT_WM_NCDestroy(es
);
4720 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4722 if (es
->style
& ES_MULTILINE
)
4723 result
|= DLGC_WANTALLKEYS
;
4727 MSG
*msg
= (MSG
*)lParam
;
4728 es
->flags
|= EF_DIALOGMODE
;
4730 if (msg
->message
== WM_KEYDOWN
)
4732 int vk
= (int)msg
->wParam
;
4734 if (es
->hwndListBox
)
4736 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4737 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4738 result
|= DLGC_WANTMESSAGE
;
4747 WCHAR charW
= wParam
;
4749 if (es
->hwndListBox
)
4751 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4753 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4754 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4758 result
= EDIT_WM_Char(es
, charW
);
4763 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4764 if (wParam
<= 0x000fffff)
4766 if (wParam
> 0xffff) /* convert to surrogates */
4769 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4770 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4773 EDIT_WM_Char(es
, wParam
);
4781 case WM_CONTEXTMENU
:
4782 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4790 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4798 es
->bEnableState
= (BOOL
) wParam
;
4799 EDIT_UpdateText(es
, NULL
, TRUE
);
4801 RedrawWindow(hwnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
4805 /* we do the proper erase in EDIT_WM_Paint */
4810 result
= (LRESULT
)es
->font
;
4814 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4817 case WM_GETTEXTLENGTH
:
4818 result
= get_text_length(es
);
4822 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4826 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4830 result
= EDIT_WM_KillFocus(theme
, es
);
4833 case WM_LBUTTONDBLCLK
:
4834 result
= EDIT_WM_LButtonDblClk(es
);
4837 case WM_LBUTTONDOWN
:
4838 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4842 result
= EDIT_WM_LButtonUp(es
);
4845 case WM_MBUTTONDOWN
:
4846 result
= EDIT_WM_MButtonDown(es
);
4850 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4853 case WM_PRINTCLIENT
:
4855 EDIT_WM_Paint(es
, (HDC
)wParam
);
4859 EDIT_WM_NCPaint(hwnd
, (HRGN
)wParam
);
4867 EDIT_WM_SetFocus(theme
, es
);
4871 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4875 /* FIXME: actually set an internal flag and behave accordingly */
4879 EDIT_WM_SetText(es
, (const WCHAR
*)lParam
);
4884 EDIT_WM_Size(es
, (UINT
)wParam
);
4887 case WM_STYLECHANGED
:
4888 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4891 case WM_STYLECHANGING
:
4892 result
= 0; /* See EDIT_WM_StyleChanged */
4896 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
4904 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4910 UINT pulScrollLines
= 3;
4911 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4913 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4915 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4919 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4920 /* if scrolling changes direction, ignore left overs */
4921 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
4922 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
4923 es
->wheelDeltaRemainder
+= wheelDelta
;
4925 es
->wheelDeltaRemainder
= wheelDelta
;
4927 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
4930 pulScrollLines
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
4931 cLineScroll
= pulScrollLines
* (float)es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
4932 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
4933 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
4938 /* IME messages to make the edit control IME aware */
4939 case WM_IME_SETCONTEXT
:
4942 case WM_IME_STARTCOMPOSITION
:
4943 es
->composition_start
= es
->selection_end
;
4944 es
->composition_len
= 0;
4947 case WM_IME_COMPOSITION
:
4948 EDIT_ImeComposition(hwnd
, lParam
, es
);
4951 case WM_IME_ENDCOMPOSITION
:
4952 if (es
->composition_len
> 0)
4954 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4955 es
->selection_end
= es
->selection_start
;
4956 es
->composition_len
= 0;
4960 case WM_IME_COMPOSITIONFULL
:
4966 case WM_IME_CONTROL
:
4969 case WM_IME_REQUEST
:
4972 case IMR_QUERYCHARPOSITION
:
4974 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
4977 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
4978 chpos
->pt
.x
= LOWORD(pos
);
4979 chpos
->pt
.y
= HIWORD(pos
);
4980 chpos
->cLineHeight
= es
->line_height
;
4981 chpos
->rcDocument
= es
->format_rect
;
4982 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
4983 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
4990 case WM_THEMECHANGED
:
4991 CloseThemeData (theme
);
4992 OpenThemeData(hwnd
, WC_EDITW
);
4996 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5000 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
5001 EDIT_UnlockBuffer(es
, FALSE
);
5003 TRACE("hwnd=%p msg=%x -- 0x%08lx\n", hwnd
, msg
, result
);
5008 void EDIT_Register(void)
5012 memset(&wndClass
, 0, sizeof(wndClass
));
5013 wndClass
.style
= CS_PARENTDC
| CS_GLOBALCLASS
| CS_DBLCLKS
;
5014 wndClass
.lpfnWndProc
= EDIT_WindowProc
;
5015 wndClass
.cbClsExtra
= 0;
5017 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*) + sizeof(WORD
);
5019 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*);
5021 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_IBEAM
);
5022 wndClass
.hbrBackground
= NULL
;
5023 wndClass
.lpszClassName
= WC_EDITW
;
5024 RegisterClassW(&wndClass
);