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
52 #include "wine/unicode.h"
53 #include "wine/debug.h"
54 #include "wine/heap.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
58 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
59 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
60 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
61 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
64 * extra flags for EDITSTATE.flags field
66 #define EF_MODIFIED 0x0001 /* text has been modified */
67 #define EF_FOCUSED 0x0002 /* we have input focus */
68 #define EF_UPDATE 0x0004 /* notify parent of changed state */
69 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
70 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
71 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
72 wrapped line, instead of in front of the next character */
73 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
74 #define EF_DIALOGMODE 0x0200 /* Indicates that we are inside a dialog window */
76 #define ID_CB_LISTBOX 1000
80 END_0
= 0, /* line ends with terminating '\0' character */
81 END_WRAP
, /* line is wrapped */
82 END_HARD
, /* line ends with a hard return '\r\n' */
83 END_SOFT
, /* line ends with a soft return '\r\r\n' */
84 END_RICH
/* line ends with a single '\n' */
87 typedef struct tagLINEDEF
{
88 INT length
; /* bruto length of a line in bytes */
89 INT net_length
; /* netto length of a line in visible characters */
91 INT width
; /* width of the line in pixels */
92 INT index
; /* line index into the buffer */
93 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data */
94 struct tagLINEDEF
*next
;
99 LPWSTR text
; /* the actual contents of the control */
100 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
101 UINT buffer_size
; /* the size of the buffer in characters */
102 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
103 HFONT font
; /* NULL means standard system font */
104 INT x_offset
; /* scroll offset for multi lines this is in pixels
105 for single lines it's in characters */
106 INT line_height
; /* height of a screen line in pixels */
107 INT char_width
; /* average character width in pixels */
108 DWORD style
; /* sane version of wnd->dwStyle */
109 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
110 INT undo_insert_count
; /* number of characters inserted in sequence */
111 UINT undo_position
; /* character index of the insertion and deletion */
112 LPWSTR undo_text
; /* deleted text */
113 UINT undo_buffer_size
; /* size of the deleted text buffer */
114 INT selection_start
; /* == selection_end if no selection */
115 INT selection_end
; /* == current caret position */
116 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
117 INT left_margin
; /* in pixels */
118 INT right_margin
; /* in pixels */
120 INT text_width
; /* width of the widest line in pixels for multi line controls
121 and just line width for single line controls */
122 INT region_posx
; /* Position of cursor relative to region: */
123 INT region_posy
; /* -1: to left, 0: within, 1: to right */
124 EDITWORDBREAKPROCW word_break_proc
;
125 INT line_count
; /* number of lines */
126 INT y_offset
; /* scroll offset in number of lines */
127 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
128 BOOL bEnableState
; /* flag keeping the enable state */
129 HWND hwndSelf
; /* the our window handle */
130 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
131 Even if parent will change, EN_* messages
132 should be sent to the first parent. */
133 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
134 INT wheelDeltaRemainder
; /* scroll wheel delta left over after scrolling whole lines */
136 * only for multi line controls
138 INT lock_count
; /* amount of re-entries in the EditWndProc */
141 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
142 HLOCAL hloc32W
; /* our unicode local memory block */
143 HLOCAL hlocapp
; /* The text buffer handle belongs to the app */
147 UINT composition_len
; /* length of composition, 0 == no composition */
148 int composition_start
; /* the character position for the composition */
152 SCRIPT_LOGATTR
*logAttr
;
153 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data for single line controls */
157 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
158 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
160 /* used for disabled or read-only edit control */
161 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
163 { /* Notify parent which has created this edit control */ \
164 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
165 SendMessageW(es->hwndParent, WM_COMMAND, \
166 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
167 (LPARAM)(es->hwndSelf)); \
170 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
172 /*********************************************************************
177 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
179 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
183 /*********************************************************************
188 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
190 es
->undo_insert_count
= 0;
191 *es
->undo_text
= '\0';
194 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
199 if ((!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
200 msg
= WM_CTLCOLORSTATIC
;
202 msg
= WM_CTLCOLOREDIT
;
204 /* Why do we notify to es->hwndParent, and we send this one to GetParent()? */
205 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
207 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
212 static inline UINT
get_text_length(EDITSTATE
*es
)
214 if(es
->text_length
== (UINT
)-1)
215 es
->text_length
= strlenW(es
->text
);
216 return es
->text_length
;
220 /*********************************************************************
224 * Find the beginning of words.
225 * Note: unlike the specs for a WordBreakProc, this function can
226 * only be called without linebreaks between s[0] up to
227 * s[count - 1]. Remember it is only called
228 * internally, so we can decide this for ourselves.
229 * Additionally we will always be breaking the full string.
232 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
236 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
244 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
245 psa
.eScript
= SCRIPT_UNDEFINED
;
247 es
->logAttr
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
248 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
255 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
262 while (index
< count
&& s
[index
] && !es
->logAttr
[index
].fSoftBreak
)
267 ret
= es
->logAttr
[index
].fWhiteSpace
;
270 ERR("unknown action code, please report !\n");
277 /*********************************************************************
279 * EDIT_CallWordBreakProc
281 * Call appropriate WordBreakProc (internal or external).
283 * Note: The "start" argument should always be an index referring
284 * to es->text. The actual wordbreak proc might be
285 * 16 bit, so we can't always pass any 32 bit LPSTR.
286 * Hence we assume that es->text is the buffer that holds
287 * the string under examination (we can decide this for ourselves).
290 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
294 if (es
->word_break_proc
)
295 ret
= es
->word_break_proc(es
->text
+ start
, index
, count
, action
);
297 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+ start
, count
+ start
, action
) - start
;
302 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
306 ScriptStringFree(&line_def
->ssa
);
307 line_def
->ssa
= NULL
;
311 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
313 LINEDEF
*line_def
= es
->first_line_def
;
316 EDIT_InvalidateUniscribeData_linedef(line_def
);
317 line_def
= line_def
->next
;
321 ScriptStringFree(&es
->ssa
);
326 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
331 if (line_def
->net_length
&& !line_def
->ssa
)
333 int index
= line_def
->index
;
334 HFONT old_font
= NULL
;
336 SCRIPT_TABDEF tabdef
;
340 udc
= GetDC(es
->hwndSelf
);
342 old_font
= SelectObject(udc
, es
->font
);
344 tabdef
.cTabStops
= es
->tabs_count
;
345 tabdef
.iScale
= GdiGetCharDimensions(udc
, NULL
, NULL
);
346 tabdef
.pTabStops
= es
->tabs
;
347 tabdef
.iTabOrigin
= 0;
349 hr
= ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
,
350 (1.5*line_def
->net_length
+16), -1,
351 SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1,
352 NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
355 WARN("ScriptStringAnalyse failed (%x)\n",hr
);
356 line_def
->ssa
= NULL
;
360 SelectObject(udc
, old_font
);
362 ReleaseDC(es
->hwndSelf
, udc
);
365 return line_def
->ssa
;
368 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
372 if (!(es
->style
& ES_MULTILINE
))
376 INT length
= get_text_length(es
);
377 HFONT old_font
= NULL
;
381 udc
= GetDC(es
->hwndSelf
);
383 old_font
= SelectObject(udc
, es
->font
);
385 if (es
->style
& ES_PASSWORD
)
386 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
);
388 ScriptStringAnalyse(udc
, es
->text
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
391 SelectObject(udc
, old_font
);
393 ReleaseDC(es
->hwndSelf
, udc
);
399 line_def
= es
->first_line_def
;
400 while (line_def
&& line
)
402 line_def
= line_def
->next
;
406 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
410 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
412 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
416 /*********************************************************************
418 * EDIT_BuildLineDefs_ML
420 * Build linked list of text lines.
421 * Lines can end with '\0' (last line), a character (if it is wrapped),
422 * a soft return '\r\r\n' or a hard return '\r\n'
425 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
427 LPWSTR current_position
, cp
;
429 LINEDEF
*current_line
;
430 LINEDEF
*previous_line
;
432 INT line_index
= 0, nstart_line
, nstart_index
;
433 INT line_count
= es
->line_count
;
438 if (istart
== iend
&& delta
== 0)
441 previous_line
= NULL
;
442 current_line
= es
->first_line_def
;
444 /* Find starting line. istart must lie inside an existing line or
445 * at the end of buffer */
447 if (istart
< current_line
->index
+ current_line
->length
||
448 current_line
->ending
== END_0
)
451 previous_line
= current_line
;
452 current_line
= current_line
->next
;
454 } while (current_line
);
456 if (!current_line
) /* Error occurred start is not inside previous buffer */
458 FIXME(" modification occurred outside buffer\n");
462 /* Remember start of modifications in order to calculate update region */
463 nstart_line
= line_index
;
464 nstart_index
= current_line
->index
;
466 /* We must start to reformat from the previous line since the modifications
467 * may have caused the line to wrap upwards. */
468 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
471 current_line
= previous_line
;
473 start_line
= current_line
;
475 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
476 current_position
= es
->text
+ current_line
->index
;
477 vlc
= get_vertical_line_count(es
);
479 if (current_line
!= start_line
)
481 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
483 /* The buffer has been expanded, create a new line and
484 insert it into the link list */
485 LINEDEF
*new_line
= heap_alloc_zero(sizeof(*new_line
));
486 new_line
->next
= previous_line
->next
;
487 previous_line
->next
= new_line
;
488 current_line
= new_line
;
491 else if (current_line
->index
+ delta
< current_position
- es
->text
)
493 /* The previous line merged with this line so we delete this extra entry */
494 previous_line
->next
= current_line
->next
;
495 heap_free(current_line
);
496 current_line
= previous_line
->next
;
500 else /* current_line->index + delta == current_position */
502 if (current_position
- es
->text
> iend
)
503 break; /* We reached end of line modifications */
504 /* else recalculate this line */
508 current_line
->index
= current_position
- es
->text
;
509 orig_net_length
= current_line
->net_length
;
511 /* Find end of line */
512 cp
= current_position
;
514 if (*cp
== '\n') break;
515 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
520 /* Mark type of line termination */
522 current_line
->ending
= END_0
;
523 current_line
->net_length
= strlenW(current_position
);
524 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
525 current_line
->ending
= END_SOFT
;
526 current_line
->net_length
= cp
- current_position
- 1;
527 } else if (*cp
== '\n') {
528 current_line
->ending
= END_RICH
;
529 current_line
->net_length
= cp
- current_position
;
531 current_line
->ending
= END_HARD
;
532 current_line
->net_length
= cp
- current_position
;
535 if (current_line
->net_length
)
538 EDIT_InvalidateUniscribeData_linedef(current_line
);
539 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
540 if (current_line
->ssa
)
542 sz
= ScriptString_pSize(current_line
->ssa
);
543 /* Calculate line width */
544 current_line
->width
= sz
->cx
;
546 else current_line
->width
= es
->char_width
* current_line
->net_length
;
548 else current_line
->width
= 0;
550 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
552 /* Line breaks just look back from the end and find the next break and try that. */
554 if (!(es
->style
& ES_AUTOHSCROLL
)) {
555 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
562 prev
= current_line
->net_length
- 1;
563 w
= current_line
->net_length
;
564 d
= (float)current_line
->width
/(float)fw
;
565 if (d
> 1.2f
) d
-= 0.2f
;
567 if (next
>= prev
) next
= prev
-1;
569 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
570 next
, current_line
->net_length
, WB_LEFT
);
571 current_line
->net_length
= prev
;
572 EDIT_InvalidateUniscribeData_linedef(current_line
);
573 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
574 if (current_line
->ssa
)
575 sz
= ScriptString_pSize(current_line
->ssa
);
578 current_line
->width
= sz
->cx
;
582 } while (prev
&& current_line
->width
> fw
);
583 current_line
->net_length
= w
;
585 if (prev
== 0) { /* Didn't find a line break so force a break */
589 EDIT_InvalidateUniscribeData_linedef(current_line
);
590 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
592 if (current_line
->ssa
)
594 count
= ScriptString_pcOutChars(current_line
->ssa
);
595 piDx
= heap_alloc(sizeof(INT
) * (*count
));
596 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
598 prev
= current_line
->net_length
-1;
600 current_line
->width
-= piDx
[prev
];
602 } while ( prev
> 0 && current_line
->width
> fw
);
608 prev
= (fw
/ es
->char_width
);
611 /* If the first line we are calculating, wrapped before istart, we must
612 * adjust istart in order for this to be reflected in the update region. */
613 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
614 istart
= current_line
->index
+ prev
;
615 /* else if we are updating the previous line before the first line we
616 * are re-calculating and it expanded */
617 else if (current_line
== start_line
&&
618 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
620 /* Line expanded due to an upwards line wrap so we must partially include
621 * previous line in update region */
622 nstart_line
= line_index
;
623 nstart_index
= current_line
->index
;
624 istart
= current_line
->index
+ orig_net_length
;
627 current_line
->net_length
= prev
;
628 current_line
->ending
= END_WRAP
;
630 if (current_line
->net_length
> 0)
632 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
633 if (current_line
->ssa
)
635 sz
= ScriptString_pSize(current_line
->ssa
);
636 current_line
->width
= sz
->cx
;
639 current_line
->width
= 0;
641 else current_line
->width
= 0;
643 else if (current_line
== start_line
&&
644 current_line
->index
!= nstart_index
&&
645 orig_net_length
< current_line
->net_length
) {
646 /* The previous line expanded but it's still not as wide as the client rect */
647 /* The expansion is due to an upwards line wrap so we must partially include
648 it in the update region */
649 nstart_line
= line_index
;
650 nstart_index
= current_line
->index
;
651 istart
= current_line
->index
+ orig_net_length
;
656 /* Adjust length to include line termination */
657 switch (current_line
->ending
) {
659 current_line
->length
= current_line
->net_length
+ 3;
662 current_line
->length
= current_line
->net_length
+ 1;
665 current_line
->length
= current_line
->net_length
+ 2;
669 current_line
->length
= current_line
->net_length
;
672 es
->text_width
= max(es
->text_width
, current_line
->width
);
673 current_position
+= current_line
->length
;
674 previous_line
= current_line
;
676 /* Discard data for non-visible lines. It will be calculated as needed */
677 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
678 EDIT_InvalidateUniscribeData_linedef(current_line
);
680 current_line
= current_line
->next
;
682 } while (previous_line
->ending
!= END_0
);
684 /* Finish adjusting line indexes by delta or remove hanging lines */
685 if (previous_line
->ending
== END_0
)
687 LINEDEF
*pnext
= NULL
;
689 previous_line
->next
= NULL
;
692 pnext
= current_line
->next
;
693 EDIT_InvalidateUniscribeData_linedef(current_line
);
694 heap_free(current_line
);
695 current_line
= pnext
;
703 current_line
->index
+= delta
;
704 current_line
= current_line
->next
;
708 /* Calculate rest of modification rectangle */
713 * We calculate two rectangles. One for the first line which may have
714 * an indent with respect to the format rect. The other is a format-width
715 * rectangle that spans the rest of the lines that changed or moved.
717 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
718 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
719 rc
.bottom
= rc
.top
+ es
->line_height
;
720 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
721 rc
.left
= es
->format_rect
.left
;
723 #ifdef __REACTOS__ /* CORE-11475 */
724 rc
.left
= (short)LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
726 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
728 rc
.right
= es
->format_rect
.right
;
729 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
732 rc
.left
= es
->format_rect
.left
;
733 rc
.right
= es
->format_rect
.right
;
735 * If lines were added or removed we must re-paint the remainder of the
736 * lines since the remaining lines were either shifted up or down.
738 if (line_count
< es
->line_count
) /* We added lines */
739 rc
.bottom
= es
->line_count
* es
->line_height
;
740 else if (line_count
> es
->line_count
) /* We removed lines */
741 rc
.bottom
= line_count
* es
->line_height
;
743 rc
.bottom
= line_index
* es
->line_height
;
744 rc
.bottom
+= es
->format_rect
.top
;
745 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
746 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
747 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
748 DeleteObject(tmphrgn
);
752 /*********************************************************************
754 * EDIT_CalcLineWidth_SL
757 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
759 EDIT_UpdateUniscribeData(es
, NULL
, 0);
763 size
= ScriptString_pSize(es
->ssa
);
764 es
->text_width
= size
->cx
;
770 /*********************************************************************
774 * Beware: This is not the function called on EM_CHARFROMPOS
775 * The position _can_ be outside the formatting / client
777 * The return value is only the character index
780 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
784 if (es
->style
& ES_MULTILINE
) {
786 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
788 LINEDEF
*line_def
= es
->first_line_def
;
789 EDIT_UpdateUniscribeData(es
, NULL
, line
);
790 while ((line
> 0) && line_def
->next
) {
791 line_index
+= line_def
->length
;
792 line_def
= line_def
->next
;
796 x
+= es
->x_offset
- es
->format_rect
.left
;
797 if (es
->style
& ES_RIGHT
)
798 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
799 else if (es
->style
& ES_CENTER
)
800 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
801 if (x
>= line_def
->width
) {
803 *after_wrap
= (line_def
->ending
== END_WRAP
);
804 return line_index
+ line_def
->net_length
;
806 if (x
<= 0 || !line_def
->ssa
) {
812 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
813 if (trailing
) index
++;
816 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
817 (line_def
->ending
== END_WRAP
));
823 x
-= es
->format_rect
.left
;
829 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
830 if (es
->style
& ES_RIGHT
)
832 else if (es
->style
& ES_CENTER
)
836 EDIT_UpdateUniscribeData(es
, NULL
, 0);
841 if (es
->x_offset
>= get_text_length(es
))
844 size
= ScriptString_pSize(es
->ssa
);
847 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
854 if (x
+ xoff
> 0 || !es
->ssa
)
856 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
857 if (trailing
) index
++;
866 const SIZE
*size
= NULL
;
868 size
= ScriptString_pSize(es
->ssa
);
871 else if (x
> size
->cx
)
872 index
= get_text_length(es
);
875 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
876 if (trailing
) index
++;
882 index
= es
->x_offset
;
889 /*********************************************************************
893 * adjusts the point to be within the formatting rectangle
894 * (so CharFromPos returns the nearest _visible_ character)
897 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
899 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
900 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
904 /*********************************************************************
909 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
914 if (!(es
->style
& ES_MULTILINE
))
916 if (index
> (INT
)get_text_length(es
))
917 return es
->line_count
- 1;
919 index
= min(es
->selection_start
, es
->selection_end
);
922 line_def
= es
->first_line_def
;
923 index
-= line_def
->length
;
924 while ((index
>= 0) && line_def
->next
) {
926 line_def
= line_def
->next
;
927 index
-= line_def
->length
;
933 /*********************************************************************
938 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
941 const LINEDEF
*line_def
;
943 if (!(es
->style
& ES_MULTILINE
))
945 if (line
>= es
->line_count
)
949 line_def
= es
->first_line_def
;
951 INT index
= es
->selection_end
- line_def
->length
;
952 while ((index
>= 0) && line_def
->next
) {
953 line_index
+= line_def
->length
;
954 line_def
= line_def
->next
;
955 index
-= line_def
->length
;
959 line_index
+= line_def
->length
;
960 line_def
= line_def
->next
;
968 /*********************************************************************
973 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
977 if (!(es
->style
& ES_MULTILINE
))
978 return get_text_length(es
);
981 /* get the number of remaining non-selected chars of selected lines */
982 INT32 l
; /* line number */
983 INT32 li
; /* index of first char in line */
985 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
986 /* # chars before start of selection area */
987 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
988 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
989 /* # chars after end of selection */
990 li
= EDIT_EM_LineIndex(es
, l
);
991 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
994 line_def
= es
->first_line_def
;
995 index
-= line_def
->length
;
996 while ((index
>= 0) && line_def
->next
) {
997 line_def
= line_def
->next
;
998 index
-= line_def
->length
;
1000 return line_def
->net_length
;
1004 /*********************************************************************
1009 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1011 INT len
= get_text_length(es
);
1020 index
= min(index
, len
);
1021 if (es
->style
& ES_MULTILINE
) {
1022 l
= EDIT_EM_LineFromChar(es
, index
);
1023 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1025 y
= (l
- es
->y_offset
) * es
->line_height
;
1026 li
= EDIT_EM_LineIndex(es
, l
);
1027 if (after_wrap
&& (li
== index
) && l
) {
1029 line_def
= es
->first_line_def
;
1031 line_def
= line_def
->next
;
1034 if (line_def
->ending
== END_WRAP
) {
1036 y
-= es
->line_height
;
1037 li
= EDIT_EM_LineIndex(es
, l
);
1041 line_def
= es
->first_line_def
;
1042 while (line_def
->index
!= li
)
1043 line_def
= line_def
->next
;
1045 lw
= line_def
->width
;
1046 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1049 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1055 if (es
->style
& ES_RIGHT
)
1057 else if (es
->style
& ES_CENTER
)
1062 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1067 if (es
->x_offset
>= get_text_length(es
))
1069 int leftover
= es
->x_offset
- get_text_length(es
);
1073 size
= ScriptString_pSize(es
->ssa
);
1078 xoff
+= es
->char_width
* leftover
;
1081 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1088 if (index
>= get_text_length(es
))
1093 size
= ScriptString_pSize(es
->ssa
);
1100 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1106 if (index
>= es
->x_offset
) {
1107 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1109 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1110 if (w
> es
->text_width
)
1112 if (es
->style
& ES_RIGHT
)
1113 x
+= w
- es
->text_width
;
1114 else if (es
->style
& ES_CENTER
)
1115 x
+= (w
- es
->text_width
) / 2;
1121 x
+= es
->format_rect
.left
;
1122 y
+= es
->format_rect
.top
;
1123 return MAKELONG((INT16
)x
, (INT16
)y
);
1127 /*********************************************************************
1131 * Calculates the bounding rectangle for a line from a starting
1132 * column to an ending column.
1135 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1137 SCRIPT_STRING_ANALYSIS ssa
;
1141 if (es
->style
& ES_MULTILINE
)
1143 const LINEDEF
*line_def
= NULL
;
1144 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1145 if (line
>= es
->line_count
)
1148 line_def
= es
->first_line_def
;
1150 INT index
= es
->selection_end
- line_def
->length
;
1151 while ((index
>= 0) && line_def
->next
) {
1152 line_index
+= line_def
->length
;
1153 line_def
= line_def
->next
;
1154 index
-= line_def
->length
;
1158 line_index
+= line_def
->length
;
1159 line_def
= line_def
->next
;
1163 ssa
= line_def
->ssa
;
1168 rc
->top
= es
->format_rect
.top
;
1172 rc
->bottom
= rc
->top
+ es
->line_height
;
1173 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1174 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1177 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1178 pt3
+=es
->format_rect
.left
;
1181 rc
->right
= max(max(pt1
, pt2
),pt3
);
1182 rc
->left
= min(min(pt1
, pt2
),pt3
);
1186 static inline void text_buffer_changed(EDITSTATE
*es
)
1188 es
->text_length
= (UINT
)-1;
1190 heap_free( es
->logAttr
);
1192 EDIT_InvalidateUniscribeData(es
);
1195 /*********************************************************************
1199 static void EDIT_LockBuffer(EDITSTATE
*es
)
1206 es
->text
= LocalLock(es
->hloc32W
);
1213 /*********************************************************************
1218 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1220 /* Edit window might be already destroyed */
1221 if (!IsWindow(es
->hwndSelf
))
1223 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1227 if (!es
->lock_count
)
1229 ERR("lock_count == 0 ... please report\n");
1235 ERR("es->text == 0 ... please report\n");
1239 if (force
|| (es
->lock_count
== 1))
1243 LocalUnlock(es
->hloc32W
);
1248 ERR("no buffer ... please report\n");
1258 /*********************************************************************
1262 * Try to fit size + 1 characters in the buffer.
1264 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1268 if (size
<= es
->buffer_size
)
1271 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1273 /* Force edit to unlock its buffer. es->text now NULL */
1274 EDIT_UnlockBuffer(es
, TRUE
);
1277 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1278 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1279 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1280 es
->hloc32W
= hNew32W
;
1281 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1285 EDIT_LockBuffer(es
);
1287 if (es
->buffer_size
< size
) {
1288 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1289 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1292 TRACE("We now have %d+1\n", es
->buffer_size
);
1298 /*********************************************************************
1302 * Try to fit size + 1 bytes in the undo buffer.
1305 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1309 if (size
<= es
->undo_buffer_size
)
1312 TRACE("trying to ReAlloc to %d+1\n", size
);
1314 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1315 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1316 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1321 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1327 /*********************************************************************
1329 * EDIT_UpdateTextRegion
1332 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1334 if (es
->flags
& EF_UPDATE
) {
1335 es
->flags
&= ~EF_UPDATE
;
1336 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1338 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1342 /*********************************************************************
1347 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1349 if (es
->flags
& EF_UPDATE
) {
1350 es
->flags
&= ~EF_UPDATE
;
1351 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1353 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1356 /*********************************************************************
1358 * EDIT_SL_InvalidateText
1360 * Called from EDIT_InvalidateText().
1361 * Does the job for single-line controls only.
1364 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1369 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1370 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1371 EDIT_UpdateText(es
, &rc
, TRUE
);
1374 /*********************************************************************
1376 * EDIT_ML_InvalidateText
1378 * Called from EDIT_InvalidateText().
1379 * Does the job for multi-line controls only.
1382 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1384 INT vlc
= get_vertical_line_count(es
);
1385 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1386 INT el
= EDIT_EM_LineFromChar(es
, end
);
1395 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1398 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1399 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1400 if (sl
< es
->y_offset
) {
1404 if (el
> es
->y_offset
+ vlc
) {
1405 el
= es
->y_offset
+ vlc
;
1406 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1408 GetClientRect(es
->hwndSelf
, &rc1
);
1409 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1411 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1412 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1413 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1415 EDIT_GetLineRect(es
, sl
, sc
,
1416 EDIT_EM_LineLength(es
,
1417 EDIT_EM_LineIndex(es
, sl
)),
1419 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1420 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1421 for (l
= sl
+ 1 ; l
< el
; l
++) {
1422 EDIT_GetLineRect(es
, l
, 0,
1423 EDIT_EM_LineLength(es
,
1424 EDIT_EM_LineIndex(es
, l
)),
1426 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1427 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1429 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1430 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1431 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1436 /*********************************************************************
1438 * EDIT_InvalidateText
1440 * Invalidate the text from offset start up to, but not including,
1441 * offset end. Useful for (re)painting the selection.
1442 * Regions outside the linewidth are not invalidated.
1443 * end == -1 means end == TextLength.
1444 * start and end need not be ordered.
1447 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1453 end
= get_text_length(es
);
1461 if (es
->style
& ES_MULTILINE
)
1462 EDIT_ML_InvalidateText(es
, start
, end
);
1464 EDIT_SL_InvalidateText(es
, start
, end
);
1468 /*********************************************************************
1472 * note: unlike the specs say: the order of start and end
1473 * _is_ preserved in Windows. (i.e. start can be > end)
1474 * In other words: this handler is OK
1477 static BOOL
EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1479 UINT old_start
= es
->selection_start
;
1480 UINT old_end
= es
->selection_end
;
1481 UINT len
= get_text_length(es
);
1483 if (start
== old_start
&& end
== old_end
)
1486 if (start
== (UINT
)-1) {
1487 start
= es
->selection_end
;
1488 end
= es
->selection_end
;
1490 start
= min(start
, len
);
1491 end
= min(end
, len
);
1493 es
->selection_start
= start
;
1494 es
->selection_end
= end
;
1496 es
->flags
|= EF_AFTER_WRAP
;
1498 es
->flags
&= ~EF_AFTER_WRAP
;
1499 /* Compute the necessary invalidation region. */
1500 /* Note that we don't need to invalidate regions which have
1501 * "never" been selected, or those which are "still" selected.
1502 * In fact, every time we hit a selection boundary, we can
1503 * *toggle* whether we need to invalidate. Thus we can optimize by
1504 * *sorting* the interval endpoints. Let's assume that we sort them
1506 * start <= end <= old_start <= old_end
1507 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1508 * in 5 comparisons; i.e. it is impossible to do better than the
1510 ORDER_UINT(end
, old_end
);
1511 ORDER_UINT(start
, old_start
);
1512 ORDER_UINT(old_start
, old_end
);
1513 ORDER_UINT(start
, end
);
1514 /* Note that at this point 'end' and 'old_start' are not in order, but
1515 * start is definitely the min. and old_end is definitely the max. */
1516 if (end
!= old_start
)
1520 * ORDER_UINT32(end, old_start);
1521 * EDIT_InvalidateText(es, start, end);
1522 * EDIT_InvalidateText(es, old_start, old_end);
1523 * in place of the following if statement.
1524 * (That would complete the optimal five-comparison four-element sort.)
1526 if (old_start
> end
)
1528 EDIT_InvalidateText(es
, start
, end
);
1529 EDIT_InvalidateText(es
, old_start
, old_end
);
1533 EDIT_InvalidateText(es
, start
, old_start
);
1534 EDIT_InvalidateText(es
, end
, old_end
);
1537 else EDIT_InvalidateText(es
, start
, old_end
);
1543 /*********************************************************************
1545 * EDIT_UpdateScrollInfo
1548 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1550 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1553 si
.cbSize
= sizeof(SCROLLINFO
);
1554 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1556 si
.nMax
= es
->line_count
- 1;
1557 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1558 si
.nPos
= es
->y_offset
;
1559 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1560 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1561 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1564 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1567 si
.cbSize
= sizeof(SCROLLINFO
);
1568 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1570 si
.nMax
= es
->text_width
- 1;
1571 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1572 si
.nPos
= es
->x_offset
;
1573 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1574 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1575 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1580 /*********************************************************************
1582 * EDIT_EM_LineScroll_internal
1584 * Version of EDIT_EM_LineScroll for internal use.
1585 * It doesn't refuse if ES_MULTILINE is set and assumes that
1586 * dx is in pixels, dy - in lines.
1589 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1592 INT x_offset_in_pixels
;
1593 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1596 if (es
->style
& ES_MULTILINE
)
1598 x_offset_in_pixels
= es
->x_offset
;
1603 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1606 if (-dx
> x_offset_in_pixels
)
1607 dx
= -x_offset_in_pixels
;
1608 if (dx
> es
->text_width
- x_offset_in_pixels
)
1609 dx
= es
->text_width
- x_offset_in_pixels
;
1610 nyoff
= max(0, es
->y_offset
+ dy
);
1611 if (nyoff
>= es
->line_count
- lines_per_page
)
1612 nyoff
= max(0, es
->line_count
- lines_per_page
);
1613 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1618 es
->y_offset
= nyoff
;
1619 if(es
->style
& ES_MULTILINE
)
1622 es
->x_offset
+= dx
/ es
->char_width
;
1624 GetClientRect(es
->hwndSelf
, &rc1
);
1625 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1626 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1627 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1628 /* force scroll info update */
1629 EDIT_UpdateScrollInfo(es
);
1631 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1632 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1633 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1634 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1638 /*********************************************************************
1642 * NOTE: dx is in average character widths, dy - in lines;
1645 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1647 if (!(es
->style
& ES_MULTILINE
))
1650 dx
*= es
->char_width
;
1651 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1655 /*********************************************************************
1660 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1664 if (!(es
->style
& ES_MULTILINE
))
1665 return (LRESULT
)FALSE
;
1675 if (es
->y_offset
< es
->line_count
- 1)
1680 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1683 if (es
->y_offset
< es
->line_count
- 1)
1684 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1687 return (LRESULT
)FALSE
;
1690 INT vlc
= get_vertical_line_count(es
);
1691 /* check if we are going to move too far */
1692 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1693 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1695 /* Notification is done in EDIT_EM_LineScroll */
1697 EDIT_EM_LineScroll(es
, 0, dy
);
1698 return MAKELONG(dy
, TRUE
);
1702 return (LRESULT
)FALSE
;
1706 /*********************************************************************
1711 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1714 LRESULT res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1715 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1716 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1720 /*********************************************************************
1725 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1727 if (es
->style
& ES_MULTILINE
) {
1731 INT cw
= es
->char_width
;
1736 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1737 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1738 vlc
= get_vertical_line_count(es
);
1739 if (l
>= es
->y_offset
+ vlc
)
1740 dy
= l
- vlc
+ 1 - es
->y_offset
;
1741 if (l
< es
->y_offset
)
1742 dy
= l
- es
->y_offset
;
1743 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1744 if (x
< es
->format_rect
.left
)
1745 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1746 if (x
> es
->format_rect
.right
)
1747 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1748 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1750 /* check if we are going to move too far */
1751 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1752 dx
= es
->text_width
- ww
- es
->x_offset
;
1753 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1754 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1761 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1762 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1763 if (x
< es
->format_rect
.left
) {
1764 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1767 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1768 } while ((x
< goal
) && es
->x_offset
);
1769 /* FIXME: use ScrollWindow() somehow to improve performance */
1770 EDIT_UpdateText(es
, NULL
, TRUE
);
1771 } else if (x
> es
->format_rect
.right
) {
1773 INT len
= get_text_length(es
);
1774 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1777 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1778 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1779 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1780 /* FIXME: use ScrollWindow() somehow to improve performance */
1781 EDIT_UpdateText(es
, NULL
, TRUE
);
1785 if(es
->flags
& EF_FOCUSED
)
1786 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1790 /*********************************************************************
1795 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1797 INT e
= es
->selection_end
;
1801 if ((es
->style
& ES_MULTILINE
) && e
&&
1802 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1804 if (e
&& (es
->text
[e
- 1] == '\r'))
1808 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1809 EDIT_EM_ScrollCaret(es
);
1813 /*********************************************************************
1817 * Only for multi line controls
1818 * Move the caret one line down, on a column with the nearest
1819 * x coordinate on the screen (might be a different column).
1822 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1824 INT s
= es
->selection_start
;
1825 INT e
= es
->selection_end
;
1826 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1827 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1828 INT x
= (short)LOWORD(pos
);
1829 INT y
= (short)HIWORD(pos
);
1831 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1834 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1835 EDIT_EM_ScrollCaret(es
);
1839 /*********************************************************************
1844 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1846 BOOL after_wrap
= FALSE
;
1849 /* Pass a high value in x to make sure of receiving the end of the line */
1850 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1851 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1852 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1854 e
= get_text_length(es
);
1855 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1856 EDIT_EM_ScrollCaret(es
);
1860 /*********************************************************************
1865 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1867 INT e
= es
->selection_end
;
1871 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1872 if (es
->text
[e
] == '\n')
1874 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1878 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1879 EDIT_EM_ScrollCaret(es
);
1883 /*********************************************************************
1887 * Home key: move to beginning of line.
1890 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1894 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1895 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1896 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1897 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1900 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1901 EDIT_EM_ScrollCaret(es
);
1905 /*********************************************************************
1907 * EDIT_MovePageDown_ML
1909 * Only for multi line controls
1910 * Move the caret one page down, on a column with the nearest
1911 * x coordinate on the screen (might be a different column).
1914 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1916 INT s
= es
->selection_start
;
1917 INT e
= es
->selection_end
;
1918 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1919 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1920 INT x
= (short)LOWORD(pos
);
1921 INT y
= (short)HIWORD(pos
);
1923 e
= EDIT_CharFromPos(es
, x
,
1924 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1928 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1929 EDIT_EM_ScrollCaret(es
);
1933 /*********************************************************************
1935 * EDIT_MovePageUp_ML
1937 * Only for multi line controls
1938 * Move the caret one page up, on a column with the nearest
1939 * x coordinate on the screen (might be a different column).
1942 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1944 INT s
= es
->selection_start
;
1945 INT e
= es
->selection_end
;
1946 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1947 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1948 INT x
= (short)LOWORD(pos
);
1949 INT y
= (short)HIWORD(pos
);
1951 e
= EDIT_CharFromPos(es
, x
,
1952 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1956 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1957 EDIT_EM_ScrollCaret(es
);
1961 /*********************************************************************
1965 * Only for multi line controls
1966 * Move the caret one line up, on a column with the nearest
1967 * x coordinate on the screen (might be a different column).
1970 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1972 INT s
= es
->selection_start
;
1973 INT e
= es
->selection_end
;
1974 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1975 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1976 INT x
= (short)LOWORD(pos
);
1977 INT y
= (short)HIWORD(pos
);
1979 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1982 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1983 EDIT_EM_ScrollCaret(es
);
1987 /*********************************************************************
1989 * EDIT_MoveWordBackward
1992 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1994 INT s
= es
->selection_start
;
1995 INT e
= es
->selection_end
;
2000 l
= EDIT_EM_LineFromChar(es
, e
);
2001 ll
= EDIT_EM_LineLength(es
, e
);
2002 li
= EDIT_EM_LineIndex(es
, l
);
2005 li
= EDIT_EM_LineIndex(es
, l
- 1);
2006 e
= li
+ EDIT_EM_LineLength(es
, li
);
2009 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2013 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2014 EDIT_EM_ScrollCaret(es
);
2018 /*********************************************************************
2020 * EDIT_MoveWordForward
2023 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2025 INT s
= es
->selection_start
;
2026 INT e
= es
->selection_end
;
2031 l
= EDIT_EM_LineFromChar(es
, e
);
2032 ll
= EDIT_EM_LineLength(es
, e
);
2033 li
= EDIT_EM_LineIndex(es
, l
);
2035 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2036 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2038 e
= li
+ EDIT_CallWordBreakProc(es
,
2039 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2043 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2044 EDIT_EM_ScrollCaret(es
);
2048 /*********************************************************************
2053 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2057 LOGFONTW underline_font
;
2058 HFONT hUnderline
= 0;
2067 BkMode
= GetBkMode(dc
);
2068 BkColor
= GetBkColor(dc
);
2069 TextColor
= GetTextColor(dc
);
2071 if (es
->composition_len
== 0)
2073 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2074 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2075 SetBkMode( dc
, OPAQUE
);
2079 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2080 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2081 underline_font
.lfUnderline
= TRUE
;
2082 hUnderline
= CreateFontIndirectW(&underline_font
);
2083 old_font
= SelectObject(dc
,hUnderline
);
2086 li
= EDIT_EM_LineIndex(es
, line
);
2087 if (es
->style
& ES_MULTILINE
) {
2088 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2089 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2091 TextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
);
2092 GetTextExtentPoint32W(dc
, es
->text
+ li
+ col
, count
, &size
);
2096 if (es
->composition_len
== 0)
2098 SetBkColor(dc
, BkColor
);
2099 SetTextColor(dc
, TextColor
);
2100 SetBkMode( dc
, BkMode
);
2105 SelectObject(dc
,old_font
);
2107 DeleteObject(hUnderline
);
2114 /*********************************************************************
2119 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2128 SCRIPT_STRING_ANALYSIS ssa
;
2130 if (es
->style
& ES_MULTILINE
) {
2131 INT vlc
= get_vertical_line_count(es
);
2133 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2138 TRACE("line=%d\n", line
);
2140 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2141 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2142 x
= (short)LOWORD(pos
);
2143 y
= (short)HIWORD(pos
);
2145 if (es
->style
& ES_MULTILINE
)
2147 int line_idx
= line
;
2149 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2151 LINEDEF
*line_def
= es
->first_line_def
;
2154 while (line_def
&& line_idx
)
2156 line_def
= line_def
->next
;
2159 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2160 lw
= line_def
->width
;
2162 if (es
->style
& ES_RIGHT
)
2164 else if (es
->style
& ES_CENTER
)
2167 x
+= es
->format_rect
.left
;
2172 li
= EDIT_EM_LineIndex(es
, line
);
2173 ll
= EDIT_EM_LineLength(es
, li
);
2174 s
= min(es
->selection_start
, es
->selection_end
);
2175 e
= max(es
->selection_start
, es
->selection_end
);
2176 s
= min(li
+ ll
, max(li
, s
));
2177 e
= min(li
+ ll
, max(li
, e
));
2181 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2182 else if (rev
&& (s
!= e
) &&
2183 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2184 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2185 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2186 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2188 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2192 /*********************************************************************
2194 * EDIT_AdjustFormatRect
2196 * Adjusts the format rectangle for the current font and the
2197 * current client rectangle.
2200 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2204 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2205 if (es
->style
& ES_MULTILINE
)
2207 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2209 vlc
= get_vertical_line_count(es
);
2210 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2212 /* correct es->x_offset */
2213 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2214 max_x_offset
= es
->text_width
- fw
;
2215 if(max_x_offset
< 0) max_x_offset
= 0;
2216 if(es
->x_offset
> max_x_offset
)
2217 es
->x_offset
= max_x_offset
;
2219 /* correct es->y_offset */
2220 max_y_offset
= es
->line_count
- vlc
;
2221 if(max_y_offset
< 0) max_y_offset
= 0;
2222 if(es
->y_offset
> max_y_offset
)
2223 es
->y_offset
= max_y_offset
;
2225 /* force scroll info update */
2226 EDIT_UpdateScrollInfo(es
);
2229 /* Windows doesn't care to fix text placement for SL controls */
2230 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2232 /* Always stay within the client area */
2233 GetClientRect(es
->hwndSelf
, &ClientRect
);
2234 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2236 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2237 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2239 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2243 /*********************************************************************
2247 * note: this is not (exactly) the handler called on EM_SETRECTNP
2248 * it is also used to set the rect of a single line control
2251 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2255 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2257 CopyRect(&es
->format_rect
, rc
);
2259 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2260 es
->format_rect
.left
++;
2261 es
->format_rect
.right
--;
2263 if (es
->format_rect
.bottom
- es
->format_rect
.top
2264 >= es
->line_height
+ 2)
2266 es
->format_rect
.top
++;
2267 es
->format_rect
.bottom
--;
2270 else if (es
->style
& WS_BORDER
) {
2271 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2272 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2273 InflateRect(&es
->format_rect
, -bw
, 0);
2274 if (es
->format_rect
.bottom
- es
->format_rect
.top
>= es
->line_height
+ 2 * bh
)
2275 InflateRect(&es
->format_rect
, 0, -bh
);
2278 es
->format_rect
.left
+= es
->left_margin
;
2279 es
->format_rect
.right
-= es
->right_margin
;
2280 EDIT_AdjustFormatRect(es
);
2284 /*********************************************************************
2288 * returns line number (not index) in high-order word of result.
2289 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2290 * to Richedit, not to the edit control. Original documentation is valid.
2291 * FIXME: do the specs mean to return -1 if outside client area or
2292 * if outside formatting rectangle ???
2295 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2303 GetClientRect(es
->hwndSelf
, &rc
);
2304 if (!PtInRect(&rc
, pt
))
2307 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2308 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2312 /*********************************************************************
2316 * Enable or disable soft breaks.
2318 * This means: insert or remove the soft linebreak character (\r\r\n).
2319 * Take care to check if the text still fits the buffer after insertion.
2320 * If not, notify with EN_ERRSPACE.
2323 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2325 es
->flags
&= ~EF_USE_SOFTBRK
;
2327 es
->flags
|= EF_USE_SOFTBRK
;
2328 FIXME("soft break enabled, not implemented\n");
2334 /*********************************************************************
2338 * Hopefully this won't fire back at us.
2339 * We always start with a fixed buffer in the local heap.
2340 * Despite of the documentation says that the local heap is used
2341 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2342 * buffer on the local heap.
2345 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2347 if (!(es
->style
& ES_MULTILINE
))
2350 EDIT_UnlockBuffer(es
, TRUE
);
2352 /* The text buffer handle belongs to the app */
2353 es
->hlocapp
= es
->hloc32W
;
2355 TRACE("Returning %p, LocalSize() = %ld\n", es
->hlocapp
, LocalSize(es
->hlocapp
));
2360 /*********************************************************************
2365 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
)
2367 INT line_len
, dst_len
;
2371 if (es
->style
& ES_MULTILINE
)
2373 if (line
>= es
->line_count
)
2379 i
= EDIT_EM_LineIndex(es
, line
);
2381 line_len
= EDIT_EM_LineLength(es
, i
);
2382 dst_len
= *(WORD
*)dst
;
2384 if (dst_len
<= line_len
)
2386 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2389 else /* Append 0 if enough space */
2391 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2398 /*********************************************************************
2403 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2405 UINT s
= es
->selection_start
;
2406 UINT e
= es
->selection_end
;
2413 return MAKELONG(s
, e
);
2417 /*********************************************************************
2421 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2424 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, const WCHAR
*lpsz_replace
, UINT strl
,
2425 BOOL send_update
, BOOL honor_limit
)
2427 UINT tl
= get_text_length(es
);
2438 TRACE("%s, can_undo %d, send_update %d\n",
2439 debugstr_wn(lpsz_replace
, strl
), can_undo
, send_update
);
2441 s
= es
->selection_start
;
2442 e
= es
->selection_end
;
2444 EDIT_InvalidateUniscribeData(es
);
2445 if ((s
== e
) && !strl
)
2450 size
= tl
- (e
- s
) + strl
;
2454 /* Issue the EN_MAXTEXT notification and continue with replacing text
2455 * so that buffer limit is honored. */
2456 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2457 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2458 /* Buffer limit can be smaller than the actual length of text in combobox */
2459 if (es
->buffer_limit
< (tl
- (e
-s
)))
2462 strl
= min(strl
, es
->buffer_limit
- (tl
- (e
-s
)));
2465 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2469 /* there is something to be deleted */
2470 TRACE("deleting stuff.\n");
2472 buf
= heap_alloc((bufl
+ 1) * sizeof(WCHAR
));
2474 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2475 buf
[bufl
] = 0; /* ensure 0 termination */
2477 strcpyW(es
->text
+ s
, es
->text
+ e
);
2478 text_buffer_changed(es
);
2481 /* there is an insertion */
2482 tl
= get_text_length(es
);
2483 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
));
2484 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2486 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2487 p
[i
] = lpsz_replace
[i
];
2488 if(es
->style
& ES_UPPERCASE
)
2489 CharUpperBuffW(p
, strl
);
2490 else if(es
->style
& ES_LOWERCASE
)
2491 CharLowerBuffW(p
, strl
);
2492 text_buffer_changed(es
);
2494 if (es
->style
& ES_MULTILINE
)
2496 INT st
= min(es
->selection_start
, es
->selection_end
);
2497 INT vlc
= get_vertical_line_count(es
);
2499 hrgn
= CreateRectRgn(0, 0, 0, 0);
2500 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2501 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2502 /* if text is too long undo all changes */
2503 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2505 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2507 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2509 text_buffer_changed(es
);
2510 EDIT_BuildLineDefs_ML(es
, s
, e
,
2511 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2514 hrgn
= CreateRectRgn(0, 0, 0, 0);
2515 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2519 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2520 EDIT_InvalidateUniscribeData(es
);
2521 EDIT_CalcLineWidth_SL(es
);
2522 /* remove chars that don't fit */
2523 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2524 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2525 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2527 es
->text_length
= -1;
2528 EDIT_InvalidateUniscribeData(es
);
2529 EDIT_CalcLineWidth_SL(es
);
2531 text_buffer_changed(es
);
2532 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2538 utl
= strlenW(es
->undo_text
);
2539 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2540 /* undo-buffer is extended to the right */
2541 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2542 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2543 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2544 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2545 /* undo-buffer is extended to the left */
2546 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2547 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2549 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2551 es
->undo_position
= s
;
2553 /* new undo-buffer */
2554 EDIT_MakeUndoFit(es
, e
- s
);
2555 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2556 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2557 es
->undo_position
= s
;
2559 /* any deletion makes the old insertion-undo invalid */
2560 es
->undo_insert_count
= 0;
2562 EDIT_EM_EmptyUndoBuffer(es
);
2566 if ((s
== es
->undo_position
) ||
2567 ((es
->undo_insert_count
) &&
2568 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2570 * insertion is new and at delete position or
2571 * an extension to either left or right
2573 es
->undo_insert_count
+= strl
;
2575 /* new insertion undo */
2576 es
->undo_position
= s
;
2577 es
->undo_insert_count
= strl
;
2578 /* new insertion makes old delete-buffer invalid */
2579 *es
->undo_text
= '\0';
2582 EDIT_EM_EmptyUndoBuffer(es
);
2589 /* If text has been deleted and we're right or center aligned then scroll rightward */
2590 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2592 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2594 if (delta
< 0 && es
->x_offset
)
2596 if (abs(delta
) > es
->x_offset
)
2599 es
->x_offset
+= delta
;
2603 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2604 es
->flags
|= EF_MODIFIED
;
2605 if (send_update
) es
->flags
|= EF_UPDATE
;
2608 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2612 EDIT_UpdateText(es
, NULL
, TRUE
);
2614 EDIT_EM_ScrollCaret(es
);
2616 /* force scroll info update */
2617 EDIT_UpdateScrollInfo(es
);
2620 if(send_update
|| (es
->flags
& EF_UPDATE
))
2622 es
->flags
&= ~EF_UPDATE
;
2623 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2625 EDIT_InvalidateUniscribeData(es
);
2629 /*********************************************************************
2633 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2636 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2638 if (!(es
->style
& ES_MULTILINE
))
2644 EDIT_UnlockBuffer(es
, TRUE
);
2647 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2649 /* The text buffer handle belongs to the control */
2652 EDIT_LockBuffer(es
);
2653 text_buffer_changed(es
);
2655 es
->x_offset
= es
->y_offset
= 0;
2656 es
->selection_start
= es
->selection_end
= 0;
2657 EDIT_EM_EmptyUndoBuffer(es
);
2658 es
->flags
&= ~EF_MODIFIED
;
2659 es
->flags
&= ~EF_UPDATE
;
2660 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2661 EDIT_UpdateText(es
, NULL
, TRUE
);
2662 EDIT_EM_ScrollCaret(es
);
2663 /* force scroll info update */
2664 EDIT_UpdateScrollInfo(es
);
2668 /*********************************************************************
2672 * NOTE: this version currently implements WinNT limits
2675 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2677 if (!limit
) limit
= ~0u;
2678 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2679 es
->buffer_limit
= limit
;
2683 /*********************************************************************
2687 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2688 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2689 * margin according to the textmetrics of the current font.
2691 * When EC_USEFONTINFO is used in the non_cjk case the margins only
2692 * change if the edit control is equal to or larger than a certain
2693 * size. Though there is an exception for the empty client rect case
2694 * with small font sizes.
2696 static BOOL
is_cjk(UINT charset
)
2700 case SHIFTJIS_CHARSET
:
2701 case HANGUL_CHARSET
:
2702 case GB2312_CHARSET
:
2703 case CHINESEBIG5_CHARSET
:
2706 /* HANGUL_CHARSET is strange, though treated as CJK by Win 8, it is
2707 * not by other versions including Win 10. */
2711 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2712 WORD left
, WORD right
, BOOL repaint
)
2715 INT default_left_margin
= 0; /* in pixels */
2716 INT default_right_margin
= 0; /* in pixels */
2718 /* Set the default margins depending on the font */
2719 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2720 HDC dc
= GetDC(es
->hwndSelf
);
2721 HFONT old_font
= SelectObject(dc
, es
->font
);
2722 LONG width
= GdiGetCharDimensions(dc
, &tm
, NULL
);
2725 /* The default margins are only non zero for TrueType or Vector fonts */
2726 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2727 if (!is_cjk(tm
.tmCharSet
)) {
2728 default_left_margin
= width
/ 2;
2729 default_right_margin
= width
/ 2;
2731 GetClientRect(es
->hwndSelf
, &rc
);
2732 if (rc
.right
- rc
.left
< (width
/ 2 + width
) * 2 &&
2733 (width
>= 28 || !IsRectEmpty(&rc
)) ) {
2734 default_left_margin
= es
->left_margin
;
2735 default_right_margin
= es
->right_margin
;
2738 /* FIXME: figure out the CJK values. They are not affected by the client rect. */
2739 default_left_margin
= width
/ 2;
2740 default_right_margin
= width
/ 2;
2743 SelectObject(dc
, old_font
);
2744 ReleaseDC(es
->hwndSelf
, dc
);
2747 if (action
& EC_LEFTMARGIN
) {
2748 es
->format_rect
.left
-= es
->left_margin
;
2749 if (left
!= EC_USEFONTINFO
)
2750 es
->left_margin
= left
;
2752 es
->left_margin
= default_left_margin
;
2753 es
->format_rect
.left
+= es
->left_margin
;
2756 if (action
& EC_RIGHTMARGIN
) {
2757 es
->format_rect
.right
+= es
->right_margin
;
2758 if (right
!= EC_USEFONTINFO
)
2759 es
->right_margin
= right
;
2761 es
->right_margin
= default_right_margin
;
2762 es
->format_rect
.right
-= es
->right_margin
;
2765 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2766 EDIT_AdjustFormatRect(es
);
2767 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2770 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2774 /*********************************************************************
2776 * EM_SETPASSWORDCHAR
2779 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2783 if (es
->style
& ES_MULTILINE
)
2786 if (es
->password_char
== c
)
2789 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2790 es
->password_char
= c
;
2792 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2793 es
->style
|= ES_PASSWORD
;
2795 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2796 es
->style
&= ~ES_PASSWORD
;
2798 EDIT_InvalidateUniscribeData(es
);
2799 EDIT_UpdateText(es
, NULL
, TRUE
);
2803 /*********************************************************************
2808 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2810 if (!(es
->style
& ES_MULTILINE
))
2812 heap_free(es
->tabs
);
2813 es
->tabs_count
= count
;
2817 es
->tabs
= heap_alloc(count
* sizeof(INT
));
2818 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2820 EDIT_InvalidateUniscribeData(es
);
2825 /*********************************************************************
2827 * EM_SETWORDBREAKPROC
2830 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, EDITWORDBREAKPROCW wbp
)
2832 if (es
->word_break_proc
== wbp
)
2835 es
->word_break_proc
= wbp
;
2837 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2838 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2839 EDIT_UpdateText(es
, NULL
, TRUE
);
2844 /*********************************************************************
2849 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
2854 /* As per MSDN spec, for a single-line edit control,
2855 the return value is always TRUE */
2856 if( es
->style
& ES_READONLY
)
2857 return !(es
->style
& ES_MULTILINE
);
2859 ulength
= strlenW(es
->undo_text
);
2861 utext
= heap_alloc((ulength
+ 1) * sizeof(WCHAR
));
2863 strcpyW(utext
, es
->undo_text
);
2865 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2866 es
->undo_insert_count
, debugstr_w(utext
));
2868 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2869 EDIT_EM_EmptyUndoBuffer(es
);
2870 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, ulength
, TRUE
, TRUE
);
2871 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2872 /* send the notification after the selection start and end are set */
2873 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2874 EDIT_EM_ScrollCaret(es
);
2877 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2878 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
2883 /* Helper function for WM_CHAR
2885 * According to an MSDN blog article titled "Just because you're a control
2886 * doesn't mean that you're necessarily inside a dialog box," multiline edit
2887 * controls without ES_WANTRETURN would attempt to detect whether it is inside
2888 * a dialog box or not.
2890 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
2892 return (es
->flags
& EF_DIALOGMODE
);
2896 /*********************************************************************
2901 static void EDIT_WM_Paste(EDITSTATE
*es
)
2907 /* Protect read-only edit control from modification */
2908 if(es
->style
& ES_READONLY
)
2911 OpenClipboard(es
->hwndSelf
);
2912 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
2913 src
= GlobalLock(hsrc
);
2915 /* Protect single-line edit against pasting new line character */
2916 if (!(es
->style
& ES_MULTILINE
) && ((ptr
= strchrW(src
, '\n')))) {
2918 if (len
&& src
[len
- 1] == '\r')
2921 EDIT_EM_ReplaceSel(es
, TRUE
, src
, len
, TRUE
, TRUE
);
2924 else if (es
->style
& ES_PASSWORD
) {
2925 /* clear selected text in password edit box even with empty clipboard */
2926 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2932 /*********************************************************************
2937 static void EDIT_WM_Copy(EDITSTATE
*es
)
2939 INT s
= min(es
->selection_start
, es
->selection_end
);
2940 INT e
= max(es
->selection_start
, es
->selection_end
);
2948 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
2949 dst
= GlobalLock(hdst
);
2950 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
2951 dst
[len
] = 0; /* ensure 0 termination */
2952 TRACE("%s\n", debugstr_w(dst
));
2954 OpenClipboard(es
->hwndSelf
);
2956 SetClipboardData(CF_UNICODETEXT
, hdst
);
2961 /*********************************************************************
2966 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
2968 /* Protect read-only edit control from modification */
2969 if(es
->style
& ES_READONLY
)
2972 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2976 /*********************************************************************
2981 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
2988 /*********************************************************************
2993 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
2997 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3001 /* If it's not a multiline edit box, it would be ignored below.
3002 * For multiline edit without ES_WANTRETURN, we have to make a
3005 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3006 if (EDIT_IsInsideDialog(es
))
3009 if (es
->style
& ES_MULTILINE
) {
3010 if (es
->style
& ES_READONLY
) {
3011 EDIT_MoveHome(es
, FALSE
, FALSE
);
3012 EDIT_MoveDown_ML(es
, FALSE
);
3014 static const WCHAR cr_lfW
[] = {'\r','\n'};
3015 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, 2, TRUE
, TRUE
);
3020 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3022 static const WCHAR tabW
[] = {'\t'};
3023 if (EDIT_IsInsideDialog(es
))
3025 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, 1, TRUE
, TRUE
);
3029 if (!(es
->style
& ES_READONLY
) && !control
) {
3030 if (es
->selection_start
!= es
->selection_end
)
3033 /* delete character left of caret */
3034 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3035 EDIT_MoveBackward(es
, TRUE
);
3041 if (!(es
->style
& ES_PASSWORD
))
3042 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3045 if (!(es
->style
& ES_READONLY
))
3046 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3049 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3050 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3053 if (!(es
->style
& ES_READONLY
))
3054 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3058 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3059 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3062 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127))
3063 EDIT_EM_ReplaceSel(es
, TRUE
, &c
, 1, TRUE
, TRUE
);
3070 /*********************************************************************
3072 * EDIT_ContextMenuCommand
3075 static void EDIT_ContextMenuCommand(EDITSTATE
*es
, UINT id
)
3079 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3082 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3085 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3088 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3091 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3094 SendMessageW(es
->hwndSelf
, EM_SETSEL
, 0, -1);
3097 ERR("unknown menu item, please report\n");
3103 /*********************************************************************
3107 * Note: the resource files resource/sysres_??.rc cannot define a
3108 * single popup menu. Hence we use a (dummy) menubar
3109 * containing the single popup menu as its first item.
3111 * FIXME: the message identifiers have been chosen arbitrarily,
3112 * hence we use MF_BYPOSITION.
3113 * We might as well use the "real" values (anybody knows ?)
3114 * The menu definition is in resources/sysres_??.rc.
3115 * Once these are OK, we better use MF_BYCOMMAND here
3116 * (as we do in EDIT_WM_Command()).
3119 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3121 HMENU menu
= LoadMenuA(GetModuleHandleA("user32.dll"), "EDITMENU");
3122 HMENU popup
= GetSubMenu(menu
, 0);
3123 UINT start
= es
->selection_start
;
3124 UINT end
= es
->selection_end
;
3128 ORDER_UINT(start
, end
);
3131 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3133 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3135 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3137 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3139 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3141 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3146 if (pt
.x
== -1 && pt
.y
== -1) /* passed via VK_APPS press/release */
3150 /* Windows places the menu at the edit's center in this case */
3151 GetClientRect(es
->hwndSelf
, &rc
);
3152 pt
.x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3153 pt
.y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3154 ClientToScreen(es
->hwndSelf
, &pt
);
3157 if (!(es
->flags
& EF_FOCUSED
))
3158 SetFocus(es
->hwndSelf
);
3160 cmd
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
| TPM_NONOTIFY
,
3161 pt
.x
, pt
.y
, 0, es
->hwndSelf
, NULL
);
3164 EDIT_ContextMenuCommand(es
, cmd
);
3170 /*********************************************************************
3175 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
)
3180 lstrcpynW(dst
, es
->text
, count
);
3181 return strlenW(dst
);
3184 /*********************************************************************
3189 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3191 HWND hLBox
= es
->hwndListBox
;
3199 hCombo
= GetParent(es
->hwndSelf
);
3203 TRACE("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3205 if (key
== VK_UP
|| key
== VK_DOWN
)
3207 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3210 if (msg
== WM_KEYDOWN
|| nEUI
)
3211 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3217 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3219 /* make sure ComboLBox pops up */
3220 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3225 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3228 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3230 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, !bDropped
, 0);
3232 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3237 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3243 /*********************************************************************
3247 * Handling of special keys that don't produce a WM_CHAR
3248 * (i.e. non-printable keys) & Backspace & Delete
3251 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3256 if (GetKeyState(VK_MENU
) & 0x8000)
3259 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3260 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3265 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3270 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3271 EDIT_MoveUp_ML(es
, shift
);
3274 EDIT_MoveWordBackward(es
, shift
);
3276 EDIT_MoveBackward(es
, shift
);
3279 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3283 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3284 EDIT_MoveDown_ML(es
, shift
);
3286 EDIT_MoveWordForward(es
, shift
);
3288 EDIT_MoveForward(es
, shift
);
3291 EDIT_MoveHome(es
, shift
, control
);
3294 EDIT_MoveEnd(es
, shift
, control
);
3297 if (es
->style
& ES_MULTILINE
)
3298 EDIT_MovePageUp_ML(es
, shift
);
3300 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3303 if (es
->style
& ES_MULTILINE
)
3304 EDIT_MovePageDown_ML(es
, shift
);
3306 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3309 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3310 if (es
->selection_start
!= es
->selection_end
) {
3317 /* delete character left of caret */
3318 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3319 EDIT_MoveBackward(es
, TRUE
);
3321 } else if (control
) {
3322 /* delete to end of line */
3323 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3324 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3327 /* delete character right of caret */
3328 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3329 EDIT_MoveForward(es
, TRUE
);
3337 if (!(es
->style
& ES_READONLY
))
3343 /* If the edit doesn't want the return send a message to the default object */
3344 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3348 if (!EDIT_IsInsideDialog(es
)) break;
3350 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3351 if (HIWORD(dw
) == DC_HASDEFID
)
3353 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3356 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3357 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3363 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3364 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3367 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3368 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3373 if (EDIT_EM_SetSel(es
, 0, get_text_length(es
), FALSE
))
3375 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3376 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3385 /*********************************************************************
3390 static LRESULT
EDIT_WM_KillFocus(HTHEME theme
, EDITSTATE
*es
)
3392 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3394 es
->flags
&= ~EF_FOCUSED
;
3396 if (!(es
->style
& ES_NOHIDESEL
))
3397 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3398 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3399 /* Throw away left over scroll when we lose focus */
3400 es
->wheelDeltaRemainder
= 0;
3405 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3410 /*********************************************************************
3414 * The caret position has been set on the WM_LBUTTONDOWN message
3417 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3420 INT e
= es
->selection_end
;
3425 es
->bCaptureState
= TRUE
;
3426 SetCapture(es
->hwndSelf
);
3428 l
= EDIT_EM_LineFromChar(es
, e
);
3429 li
= EDIT_EM_LineIndex(es
, l
);
3430 ll
= EDIT_EM_LineLength(es
, e
);
3431 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3432 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3433 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3434 EDIT_EM_ScrollCaret(es
);
3435 es
->region_posx
= es
->region_posy
= 0;
3436 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3441 /*********************************************************************
3446 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3451 es
->bCaptureState
= TRUE
;
3452 SetCapture(es
->hwndSelf
);
3453 EDIT_ConfinePoint(es
, &x
, &y
);
3454 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3455 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3456 EDIT_EM_ScrollCaret(es
);
3457 es
->region_posx
= es
->region_posy
= 0;
3458 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3460 if (!(es
->flags
& EF_FOCUSED
))
3461 SetFocus(es
->hwndSelf
);
3467 /*********************************************************************
3472 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3474 if (es
->bCaptureState
) {
3475 KillTimer(es
->hwndSelf
, 0);
3476 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3478 es
->bCaptureState
= FALSE
;
3483 /*********************************************************************
3488 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3490 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3495 /*********************************************************************
3500 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3506 /* If the mouse has been captured by process other than the edit control itself,
3507 * the windows edit controls will not select the strings with mouse move.
3509 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3513 * FIXME: gotta do some scrolling if outside client
3514 * area. Maybe reset the timer ?
3517 EDIT_ConfinePoint(es
, &x
, &y
);
3518 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3519 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3520 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3521 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3522 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3527 /*********************************************************************
3532 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3545 BOOL rev
= es
->bEnableState
&&
3546 ((es
->flags
& EF_FOCUSED
) ||
3547 (es
->style
& ES_NOHIDESEL
));
3548 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3550 /* The dc we use for calculating may not be the one we paint into.
3551 This is the safest action. */
3552 EDIT_InvalidateUniscribeData(es
);
3553 GetClientRect(es
->hwndSelf
, &rcClient
);
3555 /* get the background brush */
3556 brush
= EDIT_NotifyCtlColor(es
, dc
);
3558 /* paint the border and the background */
3559 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3561 if(es
->style
& WS_BORDER
) {
3562 bw
= GetSystemMetrics(SM_CXBORDER
);
3563 bh
= GetSystemMetrics(SM_CYBORDER
);
3565 if(es
->style
& ES_MULTILINE
) {
3566 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3567 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3570 /* Draw the frame. Same code as in nonclient.c */
3571 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3572 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3573 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3574 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3575 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3576 SelectObject(dc
, old_brush
);
3578 /* Keep the border clean */
3579 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3580 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3583 GetClipBox(dc
, &rc
);
3584 FillRect(dc
, &rc
, brush
);
3586 IntersectClipRect(dc
, es
->format_rect
.left
,
3587 es
->format_rect
.top
,
3588 es
->format_rect
.right
,
3589 es
->format_rect
.bottom
);
3590 if (es
->style
& ES_MULTILINE
) {
3592 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3595 old_font
= SelectObject(dc
, es
->font
);
3597 if (!es
->bEnableState
)
3598 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3599 GetClipBox(dc
, &rcRgn
);
3600 if (es
->style
& ES_MULTILINE
) {
3601 INT vlc
= get_vertical_line_count(es
);
3602 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3603 EDIT_UpdateUniscribeData(es
, dc
, i
);
3604 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3605 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3606 EDIT_PaintLine(es
, dc
, i
, rev
);
3609 EDIT_UpdateUniscribeData(es
, dc
, 0);
3610 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3611 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3612 EDIT_PaintLine(es
, dc
, 0, rev
);
3615 SelectObject(dc
, old_font
);
3618 EndPaint(es
->hwndSelf
, &ps
);
3621 static void EDIT_WM_NCPaint(HWND hwnd
, HRGN region
)
3623 DWORD exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3624 HTHEME theme
= GetWindowTheme(hwnd
);
3625 HRGN cliprgn
= region
;
3627 if (theme
&& exStyle
& WS_EX_CLIENTEDGE
)
3631 int cxEdge
= GetSystemMetrics(SM_CXEDGE
),
3632 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
3633 const int part
= EP_EDITTEXT
;
3634 int state
= ETS_NORMAL
;
3635 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3637 if (!IsWindowEnabled(hwnd
))
3638 state
= ETS_DISABLED
;
3639 else if (dwStyle
& ES_READONLY
)
3640 state
= ETS_READONLY
;
3641 else if (GetFocus() == hwnd
)
3642 state
= ETS_FOCUSED
;
3644 GetWindowRect(hwnd
, &r
);
3646 /* New clipping region passed to default proc to exclude border */
3647 cliprgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
,
3648 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
3649 if (region
!= (HRGN
)1)
3650 CombineRgn(cliprgn
, cliprgn
, region
, RGN_AND
);
3651 OffsetRect(&r
, -r
.left
, -r
.top
);
3653 #ifdef __REACTOS__ /* r73789 */
3654 dc
= GetWindowDC(hwnd
);
3655 /* Exclude client part */
3662 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
3663 OffsetRect(&r
, -r
.left
, -r
.top
);
3666 if (IsThemeBackgroundPartiallyTransparent(theme
, part
, state
))
3667 DrawThemeParentBackground(hwnd
, dc
, &r
);
3668 DrawThemeBackground(theme
, dc
, part
, state
, &r
, 0);
3669 ReleaseDC(hwnd
, dc
);
3672 /* Call default proc to get the scrollbars etc. also painted */
3673 DefWindowProcW (hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
3676 /*********************************************************************
3681 static void EDIT_WM_SetFocus(HTHEME theme
, EDITSTATE
*es
)
3683 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3685 es
->flags
|= EF_FOCUSED
;
3687 if (!(es
->style
& ES_NOHIDESEL
))
3688 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3690 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3691 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3692 ShowCaret(es
->hwndSelf
);
3693 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3696 flags
|= RDW_FRAME
| RDW_ERASE
;
3698 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3702 /*********************************************************************
3706 * With Win95 look the margins are set to default font value unless
3707 * the system font (font == 0) is being set, in which case they are left
3711 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3719 EDIT_InvalidateUniscribeData(es
);
3720 dc
= GetDC(es
->hwndSelf
);
3722 old_font
= SelectObject(dc
, font
);
3723 GetTextMetricsW(dc
, &tm
);
3724 es
->line_height
= tm
.tmHeight
;
3725 es
->char_width
= tm
.tmAveCharWidth
;
3727 SelectObject(dc
, old_font
);
3728 ReleaseDC(es
->hwndSelf
, dc
);
3730 /* Reset the format rect and the margins */
3731 GetClientRect(es
->hwndSelf
, &clientRect
);
3732 EDIT_SetRectNP(es
, &clientRect
);
3733 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3734 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3736 if (es
->style
& ES_MULTILINE
)
3737 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3739 EDIT_CalcLineWidth_SL(es
);
3742 EDIT_UpdateText(es
, NULL
, TRUE
);
3743 if (es
->flags
& EF_FOCUSED
) {
3745 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3746 EDIT_SetCaretPos(es
, es
->selection_end
,
3747 es
->flags
& EF_AFTER_WRAP
);
3748 ShowCaret(es
->hwndSelf
);
3753 /*********************************************************************
3758 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3759 * The modified flag is reset. No notifications are sent.
3761 * For single-line controls, reception of WM_SETTEXT triggers:
3762 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3765 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
)
3767 if (es
->flags
& EF_UPDATE
)
3768 /* fixed this bug once; complain if we see it about to happen again. */
3769 ERR("SetSel may generate UPDATE message whose handler may reset "
3772 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3775 TRACE("%s\n", debugstr_w(text
));
3776 EDIT_EM_ReplaceSel(es
, FALSE
, text
, strlenW(text
), FALSE
, FALSE
);
3781 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3784 es
->flags
&= ~EF_MODIFIED
;
3785 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3787 /* Send the notification after the selection start and end have been set
3788 * edit control doesn't send notification on WM_SETTEXT
3789 * if it is multiline, or it is part of combobox
3791 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3793 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3794 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3796 EDIT_EM_ScrollCaret(es
);
3797 EDIT_UpdateScrollInfo(es
);
3798 EDIT_InvalidateUniscribeData(es
);
3802 /*********************************************************************
3807 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3809 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3811 GetClientRect(es
->hwndSelf
, &rc
);
3812 EDIT_SetRectNP(es
, &rc
);
3813 EDIT_UpdateText(es
, NULL
, TRUE
);
3818 /*********************************************************************
3822 * This message is sent by SetWindowLong on having changed either the Style
3823 * or the extended style.
3825 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3827 * See also EDIT_WM_NCCreate
3829 * It appears that the Windows version of the edit control allows the style
3830 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3831 * style variable which will generally be different. In this function we
3832 * update the internal style based on what changed in the externally visible
3835 * Much of this content as based upon the MSDN, especially:
3836 * Platform SDK Documentation -> User Interface Services ->
3837 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3838 * Edit Control Styles
3840 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3842 if (GWL_STYLE
== which
) {
3843 DWORD style_change_mask
;
3845 /* Only a subset of changes can be applied after the control
3848 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3850 if (es
->style
& ES_MULTILINE
)
3851 style_change_mask
|= ES_WANTRETURN
;
3853 new_style
= style
->styleNew
& style_change_mask
;
3855 /* Number overrides lowercase overrides uppercase (at least it
3856 * does in Win95). However I'll bet that ES_NUMBER would be
3857 * invalid under Win 3.1.
3859 if (new_style
& ES_NUMBER
) {
3860 ; /* do not override the ES_NUMBER */
3861 } else if (new_style
& ES_LOWERCASE
) {
3862 new_style
&= ~ES_UPPERCASE
;
3865 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3866 } else if (GWL_EXSTYLE
== which
) {
3867 ; /* FIXME - what is needed here */
3869 WARN ("Invalid style change %ld\n",which
);
3875 /*********************************************************************
3880 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3882 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3883 if (EDIT_EM_CanUndo(es
))
3886 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3887 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3890 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3894 /*********************************************************************
3899 static void EDIT_WM_Timer(EDITSTATE
*es
)
3901 if (es
->region_posx
< 0) {
3902 EDIT_MoveBackward(es
, TRUE
);
3903 } else if (es
->region_posx
> 0) {
3904 EDIT_MoveForward(es
, TRUE
);
3907 * FIXME: gotta do some vertical scrolling here, like
3908 * EDIT_EM_LineScroll(hwnd, 0, 1);
3912 /*********************************************************************
3917 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3922 if (!(es
->style
& ES_MULTILINE
))
3925 if (!(es
->style
& ES_AUTOHSCROLL
))
3929 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3932 TRACE("SB_LINELEFT\n");
3934 dx
= -es
->char_width
;
3937 TRACE("SB_LINERIGHT\n");
3938 if (es
->x_offset
< es
->text_width
)
3939 dx
= es
->char_width
;
3942 TRACE("SB_PAGELEFT\n");
3944 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3947 TRACE("SB_PAGERIGHT\n");
3948 if (es
->x_offset
< es
->text_width
)
3949 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3957 TRACE("SB_RIGHT\n");
3958 if (es
->x_offset
< es
->text_width
)
3959 dx
= es
->text_width
- es
->x_offset
;
3962 TRACE("SB_THUMBTRACK %d\n", pos
);
3963 es
->flags
|= EF_HSCROLL_TRACK
;
3964 if(es
->style
& WS_HSCROLL
)
3965 dx
= pos
- es
->x_offset
;
3970 if(pos
< 0 || pos
> 100) return 0;
3971 /* Assume default scroll range 0-100 */
3972 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3973 new_x
= pos
* (es
->text_width
- fw
) / 100;
3974 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3977 case SB_THUMBPOSITION
:
3978 TRACE("SB_THUMBPOSITION %d\n", pos
);
3979 es
->flags
&= ~EF_HSCROLL_TRACK
;
3980 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
3981 dx
= pos
- es
->x_offset
;
3986 if(pos
< 0 || pos
> 100) return 0;
3987 /* Assume default scroll range 0-100 */
3988 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3989 new_x
= pos
* (es
->text_width
- fw
) / 100;
3990 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
3993 /* force scroll info update */
3994 EDIT_UpdateScrollInfo(es
);
3995 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
3999 TRACE("SB_ENDSCROLL\n");
4002 * FIXME : the next two are undocumented !
4003 * Are we doing the right thing ?
4004 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4005 * although it's also a regular control message.
4007 case EM_GETTHUMB
: /* this one is used by NT notepad */
4010 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4011 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4014 /* Assume default scroll range 0-100 */
4015 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4016 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4018 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4022 TRACE("EM_LINESCROLL16\n");
4027 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4033 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4034 /* check if we are going to move too far */
4035 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4036 dx
= es
->text_width
- fw
- es
->x_offset
;
4038 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4044 /*********************************************************************
4049 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4053 if (!(es
->style
& ES_MULTILINE
))
4056 if (!(es
->style
& ES_AUTOVSCROLL
))
4065 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4066 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4067 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4069 EDIT_EM_Scroll(es
, action
);
4076 TRACE("SB_BOTTOM\n");
4077 dy
= es
->line_count
- 1 - es
->y_offset
;
4080 TRACE("SB_THUMBTRACK %d\n", pos
);
4081 es
->flags
|= EF_VSCROLL_TRACK
;
4082 if(es
->style
& WS_VSCROLL
)
4083 dy
= pos
- es
->y_offset
;
4086 /* Assume default scroll range 0-100 */
4089 if(pos
< 0 || pos
> 100) return 0;
4090 vlc
= get_vertical_line_count(es
);
4091 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4092 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4093 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4094 es
->line_count
, es
->y_offset
, pos
, dy
);
4097 case SB_THUMBPOSITION
:
4098 TRACE("SB_THUMBPOSITION %d\n", pos
);
4099 es
->flags
&= ~EF_VSCROLL_TRACK
;
4100 if(es
->style
& WS_VSCROLL
)
4101 dy
= pos
- es
->y_offset
;
4104 /* Assume default scroll range 0-100 */
4107 if(pos
< 0 || pos
> 100) return 0;
4108 vlc
= get_vertical_line_count(es
);
4109 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4110 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4111 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4112 es
->line_count
, es
->y_offset
, pos
, dy
);
4116 /* force scroll info update */
4117 EDIT_UpdateScrollInfo(es
);
4118 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4122 TRACE("SB_ENDSCROLL\n");
4125 * FIXME : the next two are undocumented !
4126 * Are we doing the right thing ?
4127 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4128 * although it's also a regular control message.
4130 case EM_GETTHUMB
: /* this one is used by NT notepad */
4133 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4134 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4137 /* Assume default scroll range 0-100 */
4138 INT vlc
= get_vertical_line_count(es
);
4139 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4141 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4145 TRACE("EM_LINESCROLL %d\n", pos
);
4150 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4155 EDIT_EM_LineScroll(es
, 0, dy
);
4159 /*********************************************************************
4163 * FIXME: is this right ? (or should it be only VSCROLL)
4164 * (and maybe only for edit controls that really have their
4165 * own scrollbars) (and maybe only for multiline controls ?)
4166 * All in all: very poorly documented
4169 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4171 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4172 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4176 /********************************************************************
4178 * The Following code is to handle inline editing from IMEs
4181 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4185 LPSTR lpCompStrAttr
= NULL
;
4188 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4195 lpCompStr
= heap_alloc(buflen
);
4198 ERR("Unable to allocate IME CompositionString\n");
4203 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4205 if (CompFlag
& GCS_COMPATTR
)
4208 * We do not use the attributes yet. it would tell us what characters
4209 * are in transition and which are converted or decided upon
4211 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4215 lpCompStrAttr
= heap_alloc(dwBufLenAttr
+ 1);
4218 ERR("Unable to allocate IME Attribute String\n");
4219 heap_free(lpCompStr
);
4222 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4224 lpCompStrAttr
[dwBufLenAttr
] = 0;
4228 /* check for change in composition start */
4229 if (es
->selection_end
< es
->composition_start
)
4230 es
->composition_start
= es
->selection_end
;
4232 /* replace existing selection string */
4233 es
->selection_start
= es
->composition_start
;
4235 if (es
->composition_len
> 0)
4236 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4238 es
->selection_end
= es
->selection_start
;
4240 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4241 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4243 es
->selection_start
= es
->composition_start
;
4244 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4246 heap_free(lpCompStrAttr
);
4247 heap_free(lpCompStr
);
4250 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4255 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4261 lpResultStr
= heap_alloc(buflen
);
4264 ERR("Unable to alloc buffer for IME string\n");
4268 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4270 /* check for change in composition start */
4271 if (es
->selection_end
< es
->composition_start
)
4272 es
->composition_start
= es
->selection_end
;
4274 es
->selection_start
= es
->composition_start
;
4275 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4276 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4277 es
->composition_start
= es
->selection_end
;
4278 es
->composition_len
= 0;
4280 heap_free(lpResultStr
);
4283 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4288 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4290 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4291 es
->composition_start
= es
->selection_end
;
4294 hIMC
= ImmGetContext(hwnd
);
4298 if (CompFlag
& GCS_RESULTSTR
)
4300 EDIT_GetResultStr(hIMC
, es
);
4305 if (CompFlag
& GCS_COMPSTR
)
4306 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4307 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4309 ImmReleaseContext(hwnd
, hIMC
);
4310 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4314 /*********************************************************************
4318 * See also EDIT_WM_StyleChanged
4320 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
4325 TRACE("Creating edit control, style = %08x\n", lpcs
->style
);
4327 if (!(es
= heap_alloc_zero(sizeof(*es
))))
4329 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4332 * Note: since the EDITSTATE has not been fully initialized yet,
4333 * we can't use any API calls that may send
4334 * WM_XXX messages before WM_NCCREATE is completed.
4337 es
->style
= lpcs
->style
;
4339 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4341 es
->hwndSelf
= hwnd
;
4342 /* Save parent, which will be notified by EN_* messages */
4343 es
->hwndParent
= lpcs
->hwndParent
;
4345 if (es
->style
& ES_COMBO
)
4346 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4348 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4349 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4351 /* Number overrides lowercase overrides uppercase (at least it
4352 * does in Win95). However I'll bet that ES_NUMBER would be
4353 * invalid under Win 3.1.
4355 if (es
->style
& ES_NUMBER
) {
4356 ; /* do not override the ES_NUMBER */
4357 } else if (es
->style
& ES_LOWERCASE
) {
4358 es
->style
&= ~ES_UPPERCASE
;
4360 if (es
->style
& ES_MULTILINE
) {
4361 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4362 if (es
->style
& WS_VSCROLL
)
4363 es
->style
|= ES_AUTOVSCROLL
;
4364 if (es
->style
& WS_HSCROLL
)
4365 es
->style
|= ES_AUTOHSCROLL
;
4366 es
->style
&= ~ES_PASSWORD
;
4367 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4368 /* Confirmed - RIGHT overrides CENTER */
4369 if (es
->style
& ES_RIGHT
)
4370 es
->style
&= ~ES_CENTER
;
4371 es
->style
&= ~WS_HSCROLL
;
4372 es
->style
&= ~ES_AUTOHSCROLL
;
4375 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4376 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4377 es
->style
&= ~ES_CENTER
;
4378 es
->style
&= ~WS_HSCROLL
;
4379 es
->style
&= ~WS_VSCROLL
;
4380 if (es
->style
& ES_PASSWORD
)
4381 es
->password_char
= '*';
4384 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4385 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4387 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4389 if (!(es
->undo_text
= heap_alloc_zero((es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4391 es
->undo_buffer_size
= es
->buffer_size
;
4393 if (es
->style
& ES_MULTILINE
)
4394 if (!(es
->first_line_def
= heap_alloc_zero(sizeof(LINEDEF
))))
4399 * In Win95 look and feel, the WS_BORDER style is replaced by the
4400 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4401 * control a nonclient area so we don't need to draw the border.
4402 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4403 * a nonclient area and we should handle painting the border ourselves.
4405 * When making modifications please ensure that the code still works
4406 * for edit controls created directly with style 0x50800000, exStyle 0
4407 * (which should have a single pixel border)
4409 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4410 es
->style
&= ~WS_BORDER
;
4411 else if (es
->style
& WS_BORDER
)
4412 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4417 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4418 EDIT_InvalidateUniscribeData(es
);
4419 heap_free(es
->first_line_def
);
4420 heap_free(es
->undo_text
);
4421 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4422 heap_free(es
->logAttr
);
4428 /*********************************************************************
4433 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, const WCHAR
*name
)
4437 TRACE("%s\n", debugstr_w(name
));
4440 * To initialize some final structure members, we call some helper
4441 * functions. However, since the EDITSTATE is not consistent (i.e.
4442 * not fully initialized), we should be very careful which
4443 * functions can be called, and in what order.
4445 EDIT_WM_SetFont(es
, 0, FALSE
);
4446 EDIT_EM_EmptyUndoBuffer(es
);
4448 /* We need to calculate the format rect
4449 (applications may send EM_SETMARGINS before the control gets visible) */
4450 GetClientRect(es
->hwndSelf
, &clientRect
);
4451 EDIT_SetRectNP(es
, &clientRect
);
4455 EDIT_EM_ReplaceSel(es
, FALSE
, name
, strlenW(name
), FALSE
, FALSE
);
4456 /* if we insert text to the editline, the text scrolls out
4457 * of the window, as the caret is placed after the insert
4458 * pos normally; thus we reset es->selection... to 0 and
4461 es
->selection_start
= es
->selection_end
= 0;
4462 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4463 * Messages are only to be sent when the USER does something to
4464 * change the contents. So I am removing this EN_CHANGE
4466 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4468 EDIT_EM_ScrollCaret(es
);
4471 /* force scroll info update */
4472 EDIT_UpdateScrollInfo(es
);
4473 OpenThemeData(es
->hwndSelf
, WC_EDITW
);
4475 /* The rule seems to return 1 here for success */
4476 /* Power Builder masked edit controls will crash */
4478 /* FIXME: is that in all cases so ? */
4483 /*********************************************************************
4488 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4493 theme
= GetWindowTheme(es
->hwndSelf
);
4494 CloseThemeData(theme
);
4496 /* The app can own the text buffer handle */
4497 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
))
4498 LocalFree(es
->hloc32W
);
4500 EDIT_InvalidateUniscribeData(es
);
4502 pc
= es
->first_line_def
;
4510 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4511 heap_free(es
->undo_text
);
4517 static LRESULT CALLBACK
EDIT_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4519 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW(hwnd
, 0);
4520 HTHEME theme
= GetWindowTheme(hwnd
);
4524 TRACE("hwnd=%p msg=%#x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
4526 if (!es
&& msg
!= WM_NCCREATE
)
4527 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4529 if (es
&& (msg
!= WM_NCDESTROY
))
4530 EDIT_LockBuffer(es
);
4535 result
= EDIT_EM_GetSel(es
, (UINT
*)wParam
, (UINT
*)lParam
);
4539 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4540 EDIT_EM_ScrollCaret(es
);
4545 rect
= (RECT
*)lParam
;
4547 *rect
= es
->format_rect
;
4551 if ((es
->style
& ES_MULTILINE
) && lParam
)
4553 EDIT_SetRectNP(es
, (RECT
*)lParam
);
4554 EDIT_UpdateText(es
, NULL
, TRUE
);
4559 if ((es
->style
& ES_MULTILINE
) && lParam
)
4560 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4564 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4568 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4571 case EM_SCROLLCARET
:
4572 EDIT_EM_ScrollCaret(es
);
4577 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4582 es
->flags
|= EF_MODIFIED
;
4584 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4587 case EM_GETLINECOUNT
:
4588 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4592 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4596 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4600 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4604 result
= EDIT_EM_GetThumb(es
);
4607 /* these messages missing from specs */
4612 FIXME("undocumented message 0x%x, please report\n", msg
);
4613 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4617 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4622 const WCHAR
*textW
= (const WCHAR
*)lParam
;
4624 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, strlenW(textW
), TRUE
, TRUE
);
4630 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4633 case EM_SETLIMITTEXT
:
4634 EDIT_EM_SetLimitText(es
, wParam
);
4638 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4643 result
= (LRESULT
)EDIT_EM_Undo(es
);
4647 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4650 case EM_LINEFROMCHAR
:
4651 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4654 case EM_SETTABSTOPS
:
4655 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4658 case EM_SETPASSWORDCHAR
:
4659 EDIT_EM_SetPasswordChar(es
, wParam
);
4662 case EM_EMPTYUNDOBUFFER
:
4663 EDIT_EM_EmptyUndoBuffer(es
);
4666 case EM_GETFIRSTVISIBLELINE
:
4667 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4670 case EM_SETREADONLY
:
4672 DWORD old_style
= es
->style
;
4676 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | ES_READONLY
);
4677 es
->style
|= ES_READONLY
;
4681 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4682 es
->style
&= ~ES_READONLY
;
4685 if (old_style
^ es
->style
)
4686 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4692 case EM_SETWORDBREAKPROC
:
4693 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4697 case EM_GETWORDBREAKPROC
:
4698 result
= (LRESULT
)es
->word_break_proc
;
4701 case EM_GETPASSWORDCHAR
:
4702 result
= es
->password_char
;
4706 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4710 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4713 case EM_GETLIMITTEXT
:
4714 result
= es
->buffer_limit
;
4717 case EM_POSFROMCHAR
:
4718 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4719 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4722 case EM_CHARFROMPOS
:
4723 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4726 /* End of the EM_ messages which were in numerical order; what order
4727 * are these in? vaguely alphabetical?
4731 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
4735 result
= EDIT_WM_NCDestroy(es
);
4740 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4742 if (es
->style
& ES_MULTILINE
)
4743 result
|= DLGC_WANTALLKEYS
;
4747 MSG
*msg
= (MSG
*)lParam
;
4748 es
->flags
|= EF_DIALOGMODE
;
4750 if (msg
->message
== WM_KEYDOWN
)
4752 int vk
= (int)msg
->wParam
;
4754 if (es
->hwndListBox
)
4756 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4757 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4758 result
|= DLGC_WANTMESSAGE
;
4767 WCHAR charW
= wParam
;
4769 if (es
->hwndListBox
)
4771 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4773 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4774 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4778 result
= EDIT_WM_Char(es
, charW
);
4783 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4784 if (wParam
<= 0x000fffff)
4786 if (wParam
> 0xffff) /* convert to surrogates */
4789 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4790 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4793 EDIT_WM_Char(es
, wParam
);
4801 case WM_CONTEXTMENU
:
4802 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4810 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4818 es
->bEnableState
= (BOOL
) wParam
;
4819 EDIT_UpdateText(es
, NULL
, TRUE
);
4821 RedrawWindow(hwnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
4825 /* we do the proper erase in EDIT_WM_Paint */
4830 result
= (LRESULT
)es
->font
;
4834 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4837 case WM_GETTEXTLENGTH
:
4838 result
= get_text_length(es
);
4842 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4846 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4850 result
= EDIT_WM_KillFocus(theme
, es
);
4853 case WM_LBUTTONDBLCLK
:
4854 result
= EDIT_WM_LButtonDblClk(es
);
4857 case WM_LBUTTONDOWN
:
4858 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4862 result
= EDIT_WM_LButtonUp(es
);
4865 case WM_MBUTTONDOWN
:
4866 result
= EDIT_WM_MButtonDown(es
);
4870 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4873 case WM_PRINTCLIENT
:
4875 EDIT_WM_Paint(es
, (HDC
)wParam
);
4879 EDIT_WM_NCPaint(hwnd
, (HRGN
)wParam
);
4887 EDIT_WM_SetFocus(theme
, es
);
4891 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4895 /* FIXME: actually set an internal flag and behave accordingly */
4899 EDIT_WM_SetText(es
, (const WCHAR
*)lParam
);
4904 EDIT_WM_Size(es
, (UINT
)wParam
);
4907 case WM_STYLECHANGED
:
4908 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4911 case WM_STYLECHANGING
:
4912 result
= 0; /* See EDIT_WM_StyleChanged */
4916 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
4924 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4930 UINT pulScrollLines
= 3;
4931 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4933 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4935 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4939 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4940 /* if scrolling changes direction, ignore left overs */
4941 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
4942 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
4943 es
->wheelDeltaRemainder
+= wheelDelta
;
4945 es
->wheelDeltaRemainder
= wheelDelta
;
4947 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
4950 pulScrollLines
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
4951 cLineScroll
= pulScrollLines
* (float)es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
4952 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
4953 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
4958 /* IME messages to make the edit control IME aware */
4959 case WM_IME_SETCONTEXT
:
4962 case WM_IME_STARTCOMPOSITION
:
4963 es
->composition_start
= es
->selection_end
;
4964 es
->composition_len
= 0;
4967 case WM_IME_COMPOSITION
:
4968 EDIT_ImeComposition(hwnd
, lParam
, es
);
4971 case WM_IME_ENDCOMPOSITION
:
4972 if (es
->composition_len
> 0)
4974 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4975 es
->selection_end
= es
->selection_start
;
4976 es
->composition_len
= 0;
4980 case WM_IME_COMPOSITIONFULL
:
4986 case WM_IME_CONTROL
:
4989 case WM_IME_REQUEST
:
4992 case IMR_QUERYCHARPOSITION
:
4994 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
4997 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
4998 chpos
->pt
.x
= LOWORD(pos
);
4999 chpos
->pt
.y
= HIWORD(pos
);
5000 chpos
->cLineHeight
= es
->line_height
;
5001 chpos
->rcDocument
= es
->format_rect
;
5002 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
5003 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
5010 case WM_THEMECHANGED
:
5011 CloseThemeData (theme
);
5012 OpenThemeData(hwnd
, WC_EDITW
);
5016 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5020 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
5021 EDIT_UnlockBuffer(es
, FALSE
);
5023 TRACE("hwnd=%p msg=%x -- 0x%08lx\n", hwnd
, msg
, result
);
5028 void EDIT_Register(void)
5032 memset(&wndClass
, 0, sizeof(wndClass
));
5033 wndClass
.style
= CS_PARENTDC
| CS_GLOBALCLASS
| CS_DBLCLKS
;
5034 wndClass
.lpfnWndProc
= EDIT_WindowProc
;
5035 wndClass
.cbClsExtra
= 0;
5037 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*) + sizeof(WORD
);
5039 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*);
5041 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_IBEAM
);
5042 wndClass
.hbrBackground
= NULL
;
5043 wndClass
.lpszClassName
= WC_EDITW
;
5044 RegisterClassW(&wndClass
);
5048 void EDIT_Unregister(void)
5050 UnregisterClassW(WC_EDITW
, NULL
);