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_HIDEBALLOONTIP/Edit_HideBalloonTip
27 * - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
52 #define BUFLIMIT_INITIAL 30000 /* initial buffer size */
53 #define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
54 #define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
55 #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
58 * extra flags for EDITSTATE.flags field
60 #define EF_MODIFIED 0x0001 /* text has been modified */
61 #define EF_FOCUSED 0x0002 /* we have input focus */
62 #define EF_UPDATE 0x0004 /* notify parent of changed state */
63 #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
64 #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
65 #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
66 wrapped line, instead of in front of the next character */
67 #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
68 #define EF_DIALOGMODE 0x0200 /* Indicates that we are inside a dialog window */
70 #define ID_CB_LISTBOX 1000
74 END_0
= 0, /* line ends with terminating '\0' character */
75 END_WRAP
, /* line is wrapped */
76 END_HARD
, /* line ends with a hard return '\r\n' */
77 END_SOFT
, /* line ends with a soft return '\r\r\n' */
78 END_RICH
/* line ends with a single '\n' */
81 typedef struct tagLINEDEF
{
82 INT length
; /* bruto length of a line in bytes */
83 INT net_length
; /* netto length of a line in visible characters */
85 INT width
; /* width of the line in pixels */
86 INT index
; /* line index into the buffer */
87 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data */
88 struct tagLINEDEF
*next
;
93 LPWSTR text
; /* the actual contents of the control */
94 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
95 UINT buffer_size
; /* the size of the buffer in characters */
96 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
97 HFONT font
; /* NULL means standard system font */
98 INT x_offset
; /* scroll offset for multi lines this is in pixels
99 for single lines it's in characters */
100 INT line_height
; /* height of a screen line in pixels */
101 INT char_width
; /* average character width in pixels */
102 DWORD style
; /* sane version of wnd->dwStyle */
103 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
104 INT undo_insert_count
; /* number of characters inserted in sequence */
105 UINT undo_position
; /* character index of the insertion and deletion */
106 LPWSTR undo_text
; /* deleted text */
107 UINT undo_buffer_size
; /* size of the deleted text buffer */
108 INT selection_start
; /* == selection_end if no selection */
109 INT selection_end
; /* == current caret position */
110 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
111 INT left_margin
; /* in pixels */
112 INT right_margin
; /* in pixels */
114 INT text_width
; /* width of the widest line in pixels for multi line controls
115 and just line width for single line controls */
116 EDITWORDBREAKPROCW word_break_proc
;
117 INT line_count
; /* number of lines */
118 INT y_offset
; /* scroll offset in number of lines */
119 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
120 BOOL bEnableState
; /* flag keeping the enable state */
121 HWND hwndSelf
; /* the our window handle */
122 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
123 Even if parent will change, EN_* messages
124 should be sent to the first parent. */
125 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
126 INT wheelDeltaRemainder
; /* scroll wheel delta left over after scrolling whole lines */
127 WCHAR
*cue_banner_text
;
128 BOOL cue_banner_draw_focused
;
131 * only for multi line controls
133 INT lock_count
; /* amount of re-entries in the EditWndProc */
136 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
137 HLOCAL hloc32W
; /* our unicode local memory block */
138 HLOCAL hlocapp
; /* The text buffer handle belongs to the app */
142 UINT ime_status
; /* IME status flag */
147 SCRIPT_LOGATTR
*logAttr
;
148 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data for single line controls */
152 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
153 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
155 static inline BOOL
notify_parent(const EDITSTATE
*es
, INT code
)
157 HWND hwnd
= es
->hwndSelf
;
158 TRACE("notification %d sent to %p.\n", code
, es
->hwndParent
);
159 SendMessageW(es
->hwndParent
, WM_COMMAND
, MAKEWPARAM(GetWindowLongPtrW(es
->hwndSelf
, GWLP_ID
), code
), (LPARAM
)es
->hwndSelf
);
160 return IsWindow(hwnd
);
163 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
165 /*********************************************************************
170 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
172 return (es
->undo_insert_count
|| lstrlenW(es
->undo_text
));
176 /*********************************************************************
181 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
183 es
->undo_insert_count
= 0;
184 *es
->undo_text
= '\0';
187 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
192 if ((!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
193 msg
= WM_CTLCOLORSTATIC
;
195 msg
= WM_CTLCOLOREDIT
;
197 /* Why do we notify to es->hwndParent, and we send this one to GetParent()? */
198 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
200 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
205 static inline UINT
get_text_length(EDITSTATE
*es
)
207 if(es
->text_length
== (UINT
)-1)
208 es
->text_length
= lstrlenW(es
->text
);
209 return es
->text_length
;
213 /*********************************************************************
217 * Find the beginning of words.
218 * Note: unlike the specs for a WordBreakProc, this function can
219 * only be called without linebreaks between s[0] up to
220 * s[count - 1]. Remember it is only called
221 * internally, so we can decide this for ourselves.
222 * Additionally we will always be breaking the full string.
225 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
229 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
237 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
238 psa
.eScript
= SCRIPT_UNDEFINED
;
240 es
->logAttr
= Alloc(sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
241 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
248 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
255 while (index
< count
&& s
[index
] && !es
->logAttr
[index
].fSoftBreak
)
260 ret
= es
->logAttr
[index
].fWhiteSpace
;
263 ERR("unknown action code, please report !\n");
270 /*********************************************************************
272 * EDIT_CallWordBreakProc
274 * Call appropriate WordBreakProc (internal or external).
276 * Note: The "start" argument should always be an index referring
277 * to es->text. The actual wordbreak proc might be
278 * 16 bit, so we can't always pass any 32 bit LPSTR.
279 * Hence we assume that es->text is the buffer that holds
280 * the string under examination (we can decide this for ourselves).
283 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
287 if (es
->word_break_proc
)
288 ret
= es
->word_break_proc(es
->text
+ start
, index
, count
, action
);
290 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+ start
, count
+ start
, action
) - start
;
295 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
299 ScriptStringFree(&line_def
->ssa
);
300 line_def
->ssa
= NULL
;
304 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
306 LINEDEF
*line_def
= es
->first_line_def
;
309 EDIT_InvalidateUniscribeData_linedef(line_def
);
310 line_def
= line_def
->next
;
314 ScriptStringFree(&es
->ssa
);
319 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
324 if (line_def
->net_length
&& !line_def
->ssa
)
326 int index
= line_def
->index
;
327 HFONT old_font
= NULL
;
329 SCRIPT_TABDEF tabdef
;
333 udc
= GetDC(es
->hwndSelf
);
335 old_font
= SelectObject(udc
, es
->font
);
337 tabdef
.cTabStops
= es
->tabs_count
;
338 tabdef
.iScale
= GdiGetCharDimensions(udc
, NULL
, NULL
);
339 tabdef
.pTabStops
= es
->tabs
;
340 tabdef
.iTabOrigin
= 0;
342 hr
= ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
,
343 (1.5*line_def
->net_length
+16), -1,
344 SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1,
345 NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
348 WARN("ScriptStringAnalyse failed, hr %#lx.\n", hr
);
349 line_def
->ssa
= NULL
;
353 SelectObject(udc
, old_font
);
355 ReleaseDC(es
->hwndSelf
, udc
);
358 return line_def
->ssa
;
361 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
365 if (!(es
->style
& ES_MULTILINE
))
369 INT length
= get_text_length(es
);
370 HFONT old_font
= NULL
;
374 udc
= GetDC(es
->hwndSelf
);
376 old_font
= SelectObject(udc
, es
->font
);
378 if (es
->style
& ES_PASSWORD
)
379 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
);
381 ScriptStringAnalyse(udc
, es
->text
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
384 SelectObject(udc
, old_font
);
386 ReleaseDC(es
->hwndSelf
, udc
);
392 line_def
= es
->first_line_def
;
393 while (line_def
&& line
)
395 line_def
= line_def
->next
;
399 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
403 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
405 INT vlc
= es
->line_height
? (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
: 0;
409 /*********************************************************************
411 * EDIT_BuildLineDefs_ML
413 * Build linked list of text lines.
414 * Lines can end with '\0' (last line), a character (if it is wrapped),
415 * a soft return '\r\r\n' or a hard return '\r\n'
418 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
420 LPWSTR current_position
, cp
;
422 LINEDEF
*current_line
;
423 LINEDEF
*previous_line
;
425 INT line_index
= 0, nstart_line
, nstart_index
;
426 INT line_count
= es
->line_count
;
431 if (istart
== iend
&& delta
== 0)
434 previous_line
= NULL
;
435 current_line
= es
->first_line_def
;
437 /* Find starting line. istart must lie inside an existing line or
438 * at the end of buffer */
440 if (istart
< current_line
->index
+ current_line
->length
||
441 current_line
->ending
== END_0
)
444 previous_line
= current_line
;
445 current_line
= current_line
->next
;
447 } while (current_line
);
449 if (!current_line
) /* Error occurred start is not inside previous buffer */
451 FIXME(" modification occurred outside buffer\n");
455 /* Remember start of modifications in order to calculate update region */
456 nstart_line
= line_index
;
457 nstart_index
= current_line
->index
;
459 /* We must start to reformat from the previous line since the modifications
460 * may have caused the line to wrap upwards. */
461 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
464 current_line
= previous_line
;
466 start_line
= current_line
;
468 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
469 current_position
= es
->text
+ current_line
->index
;
470 vlc
= get_vertical_line_count(es
);
472 if (current_line
!= start_line
)
474 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
476 /* The buffer has been expanded, create a new line and
477 insert it into the link list */
478 LINEDEF
*new_line
= Alloc(sizeof(*new_line
));
479 new_line
->next
= previous_line
->next
;
480 previous_line
->next
= new_line
;
481 current_line
= new_line
;
484 else if (current_line
->index
+ delta
< current_position
- es
->text
)
486 /* The previous line merged with this line so we delete this extra entry */
487 previous_line
->next
= current_line
->next
;
489 current_line
= previous_line
->next
;
493 else /* current_line->index + delta == current_position */
495 if (current_position
- es
->text
> iend
)
496 break; /* We reached end of line modifications */
497 /* else recalculate this line */
501 current_line
->index
= current_position
- es
->text
;
502 orig_net_length
= current_line
->net_length
;
504 /* Find end of line */
505 cp
= current_position
;
507 if (*cp
== '\n') break;
508 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
513 /* Mark type of line termination */
515 current_line
->ending
= END_0
;
516 current_line
->net_length
= lstrlenW(current_position
);
517 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
518 current_line
->ending
= END_SOFT
;
519 current_line
->net_length
= cp
- current_position
- 1;
520 } else if (*cp
== '\n') {
521 current_line
->ending
= END_RICH
;
522 current_line
->net_length
= cp
- current_position
;
524 current_line
->ending
= END_HARD
;
525 current_line
->net_length
= cp
- current_position
;
528 if (current_line
->net_length
)
531 EDIT_InvalidateUniscribeData_linedef(current_line
);
532 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
533 if (current_line
->ssa
)
535 sz
= ScriptString_pSize(current_line
->ssa
);
536 /* Calculate line width */
537 current_line
->width
= sz
->cx
;
539 else current_line
->width
= es
->char_width
* current_line
->net_length
;
541 else current_line
->width
= 0;
543 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
545 /* Line breaks just look back from the end and find the next break and try that. */
547 if (!(es
->style
& ES_AUTOHSCROLL
)) {
548 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
555 prev
= current_line
->net_length
- 1;
556 w
= current_line
->net_length
;
557 d
= (float)current_line
->width
/(float)fw
;
558 if (d
> 1.2f
) d
-= 0.2f
;
560 if (next
>= prev
) next
= prev
-1;
562 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
563 next
, current_line
->net_length
, WB_LEFT
);
564 current_line
->net_length
= prev
;
565 EDIT_InvalidateUniscribeData_linedef(current_line
);
566 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
567 if (current_line
->ssa
)
568 sz
= ScriptString_pSize(current_line
->ssa
);
571 current_line
->width
= sz
->cx
;
575 } while (prev
&& current_line
->width
> fw
);
576 current_line
->net_length
= w
;
578 if (prev
== 0) { /* Didn't find a line break so force a break */
582 EDIT_InvalidateUniscribeData_linedef(current_line
);
583 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
585 if (current_line
->ssa
)
587 count
= ScriptString_pcOutChars(current_line
->ssa
);
588 piDx
= Alloc(sizeof(INT
) * (*count
));
589 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
591 prev
= current_line
->net_length
-1;
593 current_line
->width
-= piDx
[prev
];
595 } while ( prev
> 0 && current_line
->width
> fw
);
601 prev
= (fw
/ es
->char_width
);
604 /* If the first line we are calculating, wrapped before istart, we must
605 * adjust istart in order for this to be reflected in the update region. */
606 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
607 istart
= current_line
->index
+ prev
;
608 /* else if we are updating the previous line before the first line we
609 * are re-calculating and it expanded */
610 else if (current_line
== start_line
&&
611 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
613 /* Line expanded due to an upwards line wrap so we must partially include
614 * previous line in update region */
615 nstart_line
= line_index
;
616 nstart_index
= current_line
->index
;
617 istart
= current_line
->index
+ orig_net_length
;
620 current_line
->net_length
= prev
;
621 current_line
->ending
= END_WRAP
;
623 if (current_line
->net_length
> 0)
625 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
626 if (current_line
->ssa
)
628 sz
= ScriptString_pSize(current_line
->ssa
);
629 current_line
->width
= sz
->cx
;
632 current_line
->width
= 0;
634 else current_line
->width
= 0;
636 else if (current_line
== start_line
&&
637 current_line
->index
!= nstart_index
&&
638 orig_net_length
< current_line
->net_length
) {
639 /* The previous line expanded but it's still not as wide as the client rect */
640 /* The expansion is due to an upwards line wrap so we must partially include
641 it in the update region */
642 nstart_line
= line_index
;
643 nstart_index
= current_line
->index
;
644 istart
= current_line
->index
+ orig_net_length
;
649 /* Adjust length to include line termination */
650 switch (current_line
->ending
) {
652 current_line
->length
= current_line
->net_length
+ 3;
655 current_line
->length
= current_line
->net_length
+ 1;
658 current_line
->length
= current_line
->net_length
+ 2;
662 current_line
->length
= current_line
->net_length
;
665 es
->text_width
= max(es
->text_width
, current_line
->width
);
666 current_position
+= current_line
->length
;
667 previous_line
= current_line
;
669 /* Discard data for non-visible lines. It will be calculated as needed */
670 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
671 EDIT_InvalidateUniscribeData_linedef(current_line
);
673 current_line
= current_line
->next
;
675 } while (previous_line
->ending
!= END_0
);
677 /* Finish adjusting line indexes by delta or remove hanging lines */
678 if (previous_line
->ending
== END_0
)
680 LINEDEF
*pnext
= NULL
;
682 previous_line
->next
= NULL
;
685 pnext
= current_line
->next
;
686 EDIT_InvalidateUniscribeData_linedef(current_line
);
688 current_line
= pnext
;
696 current_line
->index
+= delta
;
697 current_line
= current_line
->next
;
701 /* Calculate rest of modification rectangle */
706 * We calculate two rectangles. One for the first line which may have
707 * an indent with respect to the format rect. The other is a format-width
708 * rectangle that spans the rest of the lines that changed or moved.
710 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
711 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
712 rc
.bottom
= rc
.top
+ es
->line_height
;
713 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
714 rc
.left
= es
->format_rect
.left
;
716 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
717 rc
.right
= es
->format_rect
.right
;
718 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
721 rc
.left
= es
->format_rect
.left
;
722 rc
.right
= es
->format_rect
.right
;
724 * If lines were added or removed we must re-paint the remainder of the
725 * lines since the remaining lines were either shifted up or down.
727 if (line_count
< es
->line_count
) /* We added lines */
728 rc
.bottom
= es
->line_count
* es
->line_height
;
729 else if (line_count
> es
->line_count
) /* We removed lines */
730 rc
.bottom
= line_count
* es
->line_height
;
732 rc
.bottom
= line_index
* es
->line_height
;
733 rc
.bottom
+= es
->format_rect
.top
;
734 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
735 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
736 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
737 DeleteObject(tmphrgn
);
741 /*********************************************************************
743 * EDIT_CalcLineWidth_SL
746 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
748 EDIT_UpdateUniscribeData(es
, NULL
, 0);
752 size
= ScriptString_pSize(es
->ssa
);
753 es
->text_width
= size
->cx
;
759 /*********************************************************************
763 * Beware: This is not the function called on EM_CHARFROMPOS
764 * The position _can_ be outside the formatting / client
766 * The return value is only the character index
769 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
773 if (es
->style
& ES_MULTILINE
) {
775 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
777 LINEDEF
*line_def
= es
->first_line_def
;
778 EDIT_UpdateUniscribeData(es
, NULL
, line
);
779 while ((line
> 0) && line_def
->next
) {
780 line_index
+= line_def
->length
;
781 line_def
= line_def
->next
;
785 x
+= es
->x_offset
- es
->format_rect
.left
;
786 if (es
->style
& ES_RIGHT
)
787 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
788 else if (es
->style
& ES_CENTER
)
789 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
790 if (x
>= line_def
->width
) {
792 *after_wrap
= (line_def
->ending
== END_WRAP
);
793 return line_index
+ line_def
->net_length
;
795 if (x
<= 0 || !line_def
->ssa
) {
801 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
802 if (trailing
) index
++;
805 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
806 (line_def
->ending
== END_WRAP
));
812 x
-= es
->format_rect
.left
;
818 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
819 if (es
->style
& ES_RIGHT
)
821 else if (es
->style
& ES_CENTER
)
825 EDIT_UpdateUniscribeData(es
, NULL
, 0);
830 if (es
->x_offset
>= get_text_length(es
))
833 size
= ScriptString_pSize(es
->ssa
);
836 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
843 if (x
+ xoff
> 0 || !es
->ssa
)
845 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
846 if (trailing
) index
++;
855 const SIZE
*size
= NULL
;
857 size
= ScriptString_pSize(es
->ssa
);
860 else if (x
> size
->cx
)
861 index
= get_text_length(es
);
864 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
865 if (trailing
) index
++;
871 index
= es
->x_offset
;
878 /*********************************************************************
882 * adjusts the point to be within the formatting rectangle
883 * (so CharFromPos returns the nearest _visible_ character)
886 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
888 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
889 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
893 /*********************************************************************
898 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
903 if (!(es
->style
& ES_MULTILINE
))
905 if (index
> (INT
)get_text_length(es
))
906 return es
->line_count
- 1;
908 index
= min(es
->selection_start
, es
->selection_end
);
911 line_def
= es
->first_line_def
;
912 index
-= line_def
->length
;
913 while ((index
>= 0) && line_def
->next
) {
915 line_def
= line_def
->next
;
916 index
-= line_def
->length
;
922 /*********************************************************************
927 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
930 const LINEDEF
*line_def
;
932 if (!(es
->style
& ES_MULTILINE
))
934 if (line
>= es
->line_count
)
938 line_def
= es
->first_line_def
;
940 INT index
= es
->selection_end
- line_def
->length
;
941 while ((index
>= 0) && line_def
->next
) {
942 line_index
+= line_def
->length
;
943 line_def
= line_def
->next
;
944 index
-= line_def
->length
;
948 line_index
+= line_def
->length
;
949 line_def
= line_def
->next
;
957 /*********************************************************************
962 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
966 if (!(es
->style
& ES_MULTILINE
))
967 return get_text_length(es
);
970 /* get the number of remaining non-selected chars of selected lines */
971 INT32 l
; /* line number */
972 INT32 li
; /* index of first char in line */
974 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
975 /* # chars before start of selection area */
976 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
977 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
978 /* # chars after end of selection */
979 li
= EDIT_EM_LineIndex(es
, l
);
980 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
983 line_def
= es
->first_line_def
;
984 index
-= line_def
->length
;
985 while ((index
>= 0) && line_def
->next
) {
986 line_def
= line_def
->next
;
987 index
-= line_def
->length
;
989 return line_def
->net_length
;
993 /*********************************************************************
998 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1000 INT len
= get_text_length(es
);
1009 index
= min(index
, len
);
1010 if (es
->style
& ES_MULTILINE
) {
1011 l
= EDIT_EM_LineFromChar(es
, index
);
1012 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1014 y
= (l
- es
->y_offset
) * es
->line_height
;
1015 li
= EDIT_EM_LineIndex(es
, l
);
1016 if (after_wrap
&& (li
== index
) && l
) {
1018 line_def
= es
->first_line_def
;
1020 line_def
= line_def
->next
;
1023 if (line_def
->ending
== END_WRAP
) {
1025 y
-= es
->line_height
;
1026 li
= EDIT_EM_LineIndex(es
, l
);
1030 line_def
= es
->first_line_def
;
1031 while (line_def
->index
!= li
)
1032 line_def
= line_def
->next
;
1034 lw
= line_def
->width
;
1035 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1037 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1040 if (es
->style
& ES_RIGHT
)
1042 else if (es
->style
& ES_CENTER
)
1047 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1052 if (es
->x_offset
>= get_text_length(es
))
1054 int leftover
= es
->x_offset
- get_text_length(es
);
1058 size
= ScriptString_pSize(es
->ssa
);
1063 xoff
+= es
->char_width
* leftover
;
1066 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1073 if (index
>= get_text_length(es
))
1078 size
= ScriptString_pSize(es
->ssa
);
1085 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1091 if (index
>= es
->x_offset
) {
1092 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1094 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1095 if (w
> es
->text_width
)
1097 if (es
->style
& ES_RIGHT
)
1098 x
+= w
- es
->text_width
;
1099 else if (es
->style
& ES_CENTER
)
1100 x
+= (w
- es
->text_width
) / 2;
1106 x
+= es
->format_rect
.left
;
1107 y
+= es
->format_rect
.top
;
1108 return MAKELONG((INT16
)x
, (INT16
)y
);
1112 /*********************************************************************
1116 * Calculates the bounding rectangle for a line from a starting
1117 * column to an ending column.
1120 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1122 SCRIPT_STRING_ANALYSIS ssa
;
1126 if (es
->style
& ES_MULTILINE
)
1128 const LINEDEF
*line_def
= NULL
;
1129 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1130 if (line
>= es
->line_count
)
1133 line_def
= es
->first_line_def
;
1135 INT index
= es
->selection_end
- line_def
->length
;
1136 while ((index
>= 0) && line_def
->next
) {
1137 line_index
+= line_def
->length
;
1138 line_def
= line_def
->next
;
1139 index
-= line_def
->length
;
1143 line_index
+= line_def
->length
;
1144 line_def
= line_def
->next
;
1148 ssa
= line_def
->ssa
;
1153 rc
->top
= es
->format_rect
.top
;
1157 rc
->bottom
= rc
->top
+ es
->line_height
;
1158 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1159 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1162 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1163 pt3
+=es
->format_rect
.left
;
1166 rc
->right
= max(max(pt1
, pt2
),pt3
);
1167 rc
->left
= min(min(pt1
, pt2
),pt3
);
1171 static inline void text_buffer_changed(EDITSTATE
*es
)
1173 es
->text_length
= (UINT
)-1;
1177 EDIT_InvalidateUniscribeData(es
);
1180 /*********************************************************************
1184 static void EDIT_LockBuffer(EDITSTATE
*es
)
1191 es
->text
= LocalLock(es
->hloc32W
);
1198 /*********************************************************************
1203 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1205 /* Edit window might be already destroyed */
1206 if (!IsWindow(es
->hwndSelf
))
1208 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1212 if (!es
->lock_count
)
1214 ERR("lock_count == 0 ... please report\n");
1220 ERR("es->text == 0 ... please report\n");
1224 if (force
|| (es
->lock_count
== 1))
1228 LocalUnlock(es
->hloc32W
);
1233 ERR("no buffer ... please report\n");
1243 /*********************************************************************
1247 * Try to fit size + 1 characters in the buffer.
1249 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1253 if (size
<= es
->buffer_size
)
1256 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1258 /* Force edit to unlock its buffer. es->text now NULL */
1259 EDIT_UnlockBuffer(es
, TRUE
);
1262 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1263 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1264 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1265 es
->hloc32W
= hNew32W
;
1266 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1270 EDIT_LockBuffer(es
);
1272 if (es
->buffer_size
< size
) {
1273 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1274 notify_parent(es
, EN_ERRSPACE
);
1277 TRACE("We now have %d+1\n", es
->buffer_size
);
1283 /*********************************************************************
1287 * Try to fit size + 1 bytes in the undo buffer.
1290 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1293 WCHAR
*new_undo_text
;
1295 if (size
<= es
->undo_buffer_size
)
1298 TRACE("trying to ReAlloc to %d+1\n", size
);
1300 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1301 if ((new_undo_text
= ReAlloc(es
->undo_text
, alloc_size
))) {
1302 memset(new_undo_text
+ es
->undo_buffer_size
, 0, alloc_size
- es
->undo_buffer_size
* sizeof(WCHAR
));
1303 es
->undo_text
= new_undo_text
;
1304 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1309 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1315 /*********************************************************************
1317 * EDIT_UpdateTextRegion
1320 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1322 if (es
->flags
& EF_UPDATE
) {
1323 es
->flags
&= ~EF_UPDATE
;
1324 if (!notify_parent(es
, EN_UPDATE
)) return;
1326 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1330 /*********************************************************************
1335 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1337 if (es
->flags
& EF_UPDATE
) {
1338 es
->flags
&= ~EF_UPDATE
;
1339 if (!notify_parent(es
, EN_UPDATE
)) return;
1341 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1344 /*********************************************************************
1346 * EDIT_SL_InvalidateText
1348 * Called from EDIT_InvalidateText().
1349 * Does the job for single-line controls only.
1352 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1357 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1358 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1359 EDIT_UpdateText(es
, &rc
, TRUE
);
1362 /*********************************************************************
1364 * EDIT_ML_InvalidateText
1366 * Called from EDIT_InvalidateText().
1367 * Does the job for multi-line controls only.
1370 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1372 INT vlc
= get_vertical_line_count(es
);
1373 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1374 INT el
= EDIT_EM_LineFromChar(es
, end
);
1383 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1386 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1387 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1388 if (sl
< es
->y_offset
) {
1392 if (el
> es
->y_offset
+ vlc
) {
1393 el
= es
->y_offset
+ vlc
;
1394 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1396 GetClientRect(es
->hwndSelf
, &rc1
);
1397 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1399 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1400 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1401 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1403 EDIT_GetLineRect(es
, sl
, sc
,
1404 EDIT_EM_LineLength(es
,
1405 EDIT_EM_LineIndex(es
, sl
)),
1407 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1408 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1409 for (l
= sl
+ 1 ; l
< el
; l
++) {
1410 EDIT_GetLineRect(es
, l
, 0,
1411 EDIT_EM_LineLength(es
,
1412 EDIT_EM_LineIndex(es
, l
)),
1414 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1415 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1417 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1418 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1419 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1424 /*********************************************************************
1426 * EDIT_InvalidateText
1428 * Invalidate the text from offset start up to, but not including,
1429 * offset end. Useful for (re)painting the selection.
1430 * Regions outside the linewidth are not invalidated.
1431 * end == -1 means end == TextLength.
1432 * start and end need not be ordered.
1435 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1441 end
= get_text_length(es
);
1449 if (es
->style
& ES_MULTILINE
)
1450 EDIT_ML_InvalidateText(es
, start
, end
);
1452 EDIT_SL_InvalidateText(es
, start
, end
);
1456 /*********************************************************************
1460 * note: unlike the specs say: the order of start and end
1461 * _is_ preserved in Windows. (i.e. start can be > end)
1462 * In other words: this handler is OK
1465 static BOOL
EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1467 UINT old_start
= es
->selection_start
;
1468 UINT old_end
= es
->selection_end
;
1469 UINT len
= get_text_length(es
);
1471 if (start
== old_start
&& end
== old_end
)
1474 if (start
== (UINT
)-1) {
1475 start
= es
->selection_end
;
1476 end
= es
->selection_end
;
1478 start
= min(start
, len
);
1479 end
= min(end
, len
);
1481 es
->selection_start
= start
;
1482 es
->selection_end
= end
;
1484 es
->flags
|= EF_AFTER_WRAP
;
1486 es
->flags
&= ~EF_AFTER_WRAP
;
1487 /* Compute the necessary invalidation region. */
1488 /* Note that we don't need to invalidate regions which have
1489 * "never" been selected, or those which are "still" selected.
1490 * In fact, every time we hit a selection boundary, we can
1491 * *toggle* whether we need to invalidate. Thus we can optimize by
1492 * *sorting* the interval endpoints. Let's assume that we sort them
1494 * start <= end <= old_start <= old_end
1495 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1496 * in 5 comparisons; i.e. it is impossible to do better than the
1498 ORDER_UINT(end
, old_end
);
1499 ORDER_UINT(start
, old_start
);
1500 ORDER_UINT(old_start
, old_end
);
1501 ORDER_UINT(start
, end
);
1502 /* Note that at this point 'end' and 'old_start' are not in order, but
1503 * start is definitely the min. and old_end is definitely the max. */
1504 if (end
!= old_start
)
1508 * ORDER_UINT32(end, old_start);
1509 * EDIT_InvalidateText(es, start, end);
1510 * EDIT_InvalidateText(es, old_start, old_end);
1511 * in place of the following if statement.
1512 * (That would complete the optimal five-comparison four-element sort.)
1514 if (old_start
> end
)
1516 EDIT_InvalidateText(es
, start
, end
);
1517 EDIT_InvalidateText(es
, old_start
, old_end
);
1521 EDIT_InvalidateText(es
, start
, old_start
);
1522 EDIT_InvalidateText(es
, end
, old_end
);
1525 else EDIT_InvalidateText(es
, start
, old_end
);
1531 /*********************************************************************
1533 * EDIT_UpdateScrollInfo
1536 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1538 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1541 si
.cbSize
= sizeof(SCROLLINFO
);
1542 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1544 si
.nMax
= es
->line_count
- 1;
1545 si
.nPage
= es
->line_height
? (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
: 0;
1546 si
.nPos
= es
->y_offset
;
1547 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1548 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1549 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1552 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1555 si
.cbSize
= sizeof(SCROLLINFO
);
1556 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1558 si
.nMax
= es
->text_width
- 1;
1559 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1560 si
.nPos
= es
->x_offset
;
1561 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1562 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1563 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1568 /*********************************************************************
1570 * EDIT_EM_LineScroll_internal
1572 * Version of EDIT_EM_LineScroll for internal use.
1573 * It doesn't refuse if ES_MULTILINE is set and assumes that
1574 * dx is in pixels, dy - in lines.
1577 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1580 INT x_offset_in_pixels
;
1583 if (!es
->line_height
|| !es
->char_width
)
1586 lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1588 if (es
->style
& ES_MULTILINE
)
1590 x_offset_in_pixels
= es
->x_offset
;
1595 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1598 if (-dx
> x_offset_in_pixels
)
1599 dx
= -x_offset_in_pixels
;
1600 if (dx
> es
->text_width
- x_offset_in_pixels
)
1601 dx
= es
->text_width
- x_offset_in_pixels
;
1602 nyoff
= max(0, es
->y_offset
+ dy
);
1603 if (nyoff
>= es
->line_count
- lines_per_page
)
1604 nyoff
= max(0, es
->line_count
- lines_per_page
);
1605 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1610 es
->y_offset
= nyoff
;
1611 if(es
->style
& ES_MULTILINE
)
1614 es
->x_offset
+= dx
/ es
->char_width
;
1616 GetClientRect(es
->hwndSelf
, &rc1
);
1617 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1618 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1619 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1620 /* force scroll info update */
1621 EDIT_UpdateScrollInfo(es
);
1623 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1624 notify_parent(es
, EN_HSCROLL
);
1625 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1626 notify_parent(es
, EN_VSCROLL
);
1630 /*********************************************************************
1634 * NOTE: dx is in average character widths, dy - in lines;
1637 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1639 if (!(es
->style
& ES_MULTILINE
))
1642 dx
*= es
->char_width
;
1643 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1647 /*********************************************************************
1652 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1656 if (!(es
->style
& ES_MULTILINE
))
1657 return (LRESULT
)FALSE
;
1667 if (es
->y_offset
< es
->line_count
- 1)
1672 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1675 if (es
->y_offset
< es
->line_count
- 1)
1676 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1679 return (LRESULT
)FALSE
;
1682 INT vlc
= get_vertical_line_count(es
);
1683 /* check if we are going to move too far */
1684 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1685 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1687 /* Notification is done in EDIT_EM_LineScroll */
1689 EDIT_EM_LineScroll(es
, 0, dy
);
1690 return MAKELONG(dy
, TRUE
);
1694 return (LRESULT
)FALSE
;
1698 static void EDIT_UpdateImmCompositionWindow(EDITSTATE
*es
, UINT x
, UINT y
)
1700 COMPOSITIONFORM form
=
1702 .dwStyle
= CFS_RECT
,
1703 .ptCurrentPos
= {.x
= x
, .y
= y
},
1704 .rcArea
= es
->format_rect
,
1706 HIMC himc
= ImmGetContext(es
->hwndSelf
);
1707 ImmSetCompositionWindow(himc
, &form
);
1708 ImmReleaseContext(es
->hwndSelf
, himc
);
1712 /*********************************************************************
1717 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1722 if (es
->flags
& EF_FOCUSED
)
1724 res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1725 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1726 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1727 EDIT_UpdateImmCompositionWindow(es
, (short)LOWORD(res
), (short)HIWORD(res
));
1732 /*********************************************************************
1737 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1739 if (es
->style
& ES_MULTILINE
) {
1743 INT cw
= es
->char_width
;
1748 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1749 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1750 vlc
= get_vertical_line_count(es
);
1751 if (l
>= es
->y_offset
+ vlc
)
1752 dy
= l
- vlc
+ 1 - es
->y_offset
;
1753 if (l
< es
->y_offset
)
1754 dy
= l
- es
->y_offset
;
1755 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1756 if (x
< es
->format_rect
.left
)
1757 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1758 if (x
> es
->format_rect
.right
)
1759 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1760 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1762 /* check if we are going to move too far */
1763 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1764 dx
= es
->text_width
- ww
- es
->x_offset
;
1765 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1766 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1773 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1774 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1775 if (x
< es
->format_rect
.left
) {
1776 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1779 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1780 } while ((x
< goal
) && es
->x_offset
);
1781 /* FIXME: use ScrollWindow() somehow to improve performance */
1782 EDIT_UpdateText(es
, NULL
, TRUE
);
1783 } else if (x
> es
->format_rect
.right
) {
1785 INT len
= get_text_length(es
);
1786 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1789 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1790 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1791 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1792 /* FIXME: use ScrollWindow() somehow to improve performance */
1793 EDIT_UpdateText(es
, NULL
, TRUE
);
1797 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1801 /*********************************************************************
1806 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1808 INT e
= es
->selection_end
;
1812 if ((es
->style
& ES_MULTILINE
) && e
&&
1813 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1815 if (e
&& (es
->text
[e
- 1] == '\r'))
1819 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1820 EDIT_EM_ScrollCaret(es
);
1824 /*********************************************************************
1828 * Only for multi line controls
1829 * Move the caret one line down, on a column with the nearest
1830 * x coordinate on the screen (might be a different column).
1833 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1835 INT s
= es
->selection_start
;
1836 INT e
= es
->selection_end
;
1837 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1838 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1839 INT x
= (short)LOWORD(pos
);
1840 INT y
= (short)HIWORD(pos
);
1842 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1845 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1846 EDIT_EM_ScrollCaret(es
);
1850 /*********************************************************************
1855 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1857 BOOL after_wrap
= FALSE
;
1860 /* Pass a high value in x to make sure of receiving the end of the line */
1861 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1862 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1863 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1865 e
= get_text_length(es
);
1866 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1867 EDIT_EM_ScrollCaret(es
);
1871 /*********************************************************************
1876 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1878 INT e
= es
->selection_end
;
1882 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1883 if (es
->text
[e
] == '\n')
1885 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1889 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1890 EDIT_EM_ScrollCaret(es
);
1894 /*********************************************************************
1898 * Home key: move to beginning of line.
1901 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1905 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1906 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1907 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1908 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1911 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1912 EDIT_EM_ScrollCaret(es
);
1916 /*********************************************************************
1918 * EDIT_MovePageDown_ML
1920 * Only for multi line controls
1921 * Move the caret one page down, on a column with the nearest
1922 * x coordinate on the screen (might be a different column).
1925 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1927 INT s
= es
->selection_start
;
1928 INT e
= es
->selection_end
;
1929 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1930 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1931 INT x
= (short)LOWORD(pos
);
1932 INT y
= (short)HIWORD(pos
);
1934 e
= EDIT_CharFromPos(es
, x
,
1935 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1939 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1940 EDIT_EM_ScrollCaret(es
);
1944 /*********************************************************************
1946 * EDIT_MovePageUp_ML
1948 * Only for multi line controls
1949 * Move the caret one page up, on a column with the nearest
1950 * x coordinate on the screen (might be a different column).
1953 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1955 INT s
= es
->selection_start
;
1956 INT e
= es
->selection_end
;
1957 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1958 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1959 INT x
= (short)LOWORD(pos
);
1960 INT y
= (short)HIWORD(pos
);
1962 e
= EDIT_CharFromPos(es
, x
,
1963 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1967 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1968 EDIT_EM_ScrollCaret(es
);
1972 /*********************************************************************
1976 * Only for multi line controls
1977 * Move the caret one line up, on a column with the nearest
1978 * x coordinate on the screen (might be a different column).
1981 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1983 INT s
= es
->selection_start
;
1984 INT e
= es
->selection_end
;
1985 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1986 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1987 INT x
= (short)LOWORD(pos
);
1988 INT y
= (short)HIWORD(pos
);
1990 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1993 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1994 EDIT_EM_ScrollCaret(es
);
1998 /*********************************************************************
2000 * EDIT_MoveWordBackward
2003 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2005 INT s
= es
->selection_start
;
2006 INT e
= es
->selection_end
;
2011 l
= EDIT_EM_LineFromChar(es
, e
);
2012 ll
= EDIT_EM_LineLength(es
, e
);
2013 li
= EDIT_EM_LineIndex(es
, l
);
2016 li
= EDIT_EM_LineIndex(es
, l
- 1);
2017 e
= li
+ EDIT_EM_LineLength(es
, li
);
2020 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2024 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2025 EDIT_EM_ScrollCaret(es
);
2029 /*********************************************************************
2031 * EDIT_MoveWordForward
2034 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2036 INT s
= es
->selection_start
;
2037 INT e
= es
->selection_end
;
2042 l
= EDIT_EM_LineFromChar(es
, e
);
2043 ll
= EDIT_EM_LineLength(es
, e
);
2044 li
= EDIT_EM_LineIndex(es
, l
);
2046 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2047 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2049 e
= li
+ EDIT_CallWordBreakProc(es
,
2050 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2054 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2055 EDIT_EM_ScrollCaret(es
);
2059 /*********************************************************************
2064 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2075 BkMode
= GetBkMode(dc
);
2076 BkColor
= GetBkColor(dc
);
2077 TextColor
= GetTextColor(dc
);
2079 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2080 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2081 SetBkMode(dc
, OPAQUE
);
2083 li
= EDIT_EM_LineIndex(es
, line
);
2084 if (es
->style
& ES_MULTILINE
) {
2085 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2086 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2088 TextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
);
2089 GetTextExtentPoint32W(dc
, es
->text
+ li
+ col
, count
, &size
);
2093 SetBkColor(dc
, BkColor
);
2094 SetTextColor(dc
, TextColor
);
2095 SetBkMode(dc
, BkMode
);
2101 /*********************************************************************
2106 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2115 SCRIPT_STRING_ANALYSIS ssa
;
2117 if (es
->style
& ES_MULTILINE
) {
2118 INT vlc
= get_vertical_line_count(es
);
2120 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2125 TRACE("line=%d\n", line
);
2127 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2128 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2129 x
= (short)LOWORD(pos
);
2130 y
= (short)HIWORD(pos
);
2132 if (es
->style
& ES_MULTILINE
)
2134 int line_idx
= line
;
2136 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2138 LINEDEF
*line_def
= es
->first_line_def
;
2141 while (line_def
&& line_idx
)
2143 line_def
= line_def
->next
;
2146 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2147 lw
= line_def
->width
;
2149 if (es
->style
& ES_RIGHT
)
2151 else if (es
->style
& ES_CENTER
)
2154 x
+= es
->format_rect
.left
;
2159 li
= EDIT_EM_LineIndex(es
, line
);
2160 ll
= EDIT_EM_LineLength(es
, li
);
2161 s
= min(es
->selection_start
, es
->selection_end
);
2162 e
= max(es
->selection_start
, es
->selection_end
);
2163 s
= min(li
+ ll
, max(li
, s
));
2164 e
= min(li
+ ll
, max(li
, e
));
2168 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2169 else if (rev
&& (s
!= e
) &&
2170 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2171 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2172 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2173 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2175 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2177 if (es
->cue_banner_text
&& es
->text_length
== 0 && (!(es
->flags
& EF_FOCUSED
) || es
->cue_banner_draw_focused
))
2179 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
2180 TextOutW(dc
, x
, y
, es
->cue_banner_text
, lstrlenW(es
->cue_banner_text
));
2185 /*********************************************************************
2187 * EDIT_AdjustFormatRect
2189 * Adjusts the format rectangle for the current font and the
2190 * current client rectangle.
2193 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2197 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2198 if (es
->style
& ES_MULTILINE
)
2200 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2202 vlc
= get_vertical_line_count(es
);
2203 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2205 /* correct es->x_offset */
2206 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2207 max_x_offset
= es
->text_width
- fw
;
2208 if(max_x_offset
< 0) max_x_offset
= 0;
2209 if(es
->x_offset
> max_x_offset
)
2210 es
->x_offset
= max_x_offset
;
2212 /* correct es->y_offset */
2213 max_y_offset
= es
->line_count
- vlc
;
2214 if(max_y_offset
< 0) max_y_offset
= 0;
2215 if(es
->y_offset
> max_y_offset
)
2216 es
->y_offset
= max_y_offset
;
2218 /* force scroll info update */
2219 EDIT_UpdateScrollInfo(es
);
2222 /* Windows doesn't care to fix text placement for SL controls */
2223 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2225 /* Always stay within the client area */
2226 GetClientRect(es
->hwndSelf
, &ClientRect
);
2227 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2229 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2230 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2232 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2236 /*********************************************************************
2240 * note: this is not (exactly) the handler called on EM_SETRECTNP
2241 * it is also used to set the rect of a single line control
2244 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2248 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2250 CopyRect(&es
->format_rect
, rc
);
2252 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2253 es
->format_rect
.left
++;
2254 es
->format_rect
.right
--;
2256 if (es
->format_rect
.bottom
- es
->format_rect
.top
2257 >= es
->line_height
+ 2)
2259 es
->format_rect
.top
++;
2260 es
->format_rect
.bottom
--;
2263 else if (es
->style
& WS_BORDER
) {
2264 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2265 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2266 InflateRect(&es
->format_rect
, -bw
, 0);
2267 if (es
->format_rect
.bottom
- es
->format_rect
.top
>= es
->line_height
+ 2 * bh
)
2268 InflateRect(&es
->format_rect
, 0, -bh
);
2271 es
->format_rect
.left
+= es
->left_margin
;
2272 es
->format_rect
.right
-= es
->right_margin
;
2273 EDIT_AdjustFormatRect(es
);
2277 /*********************************************************************
2281 * returns line number (not index) in high-order word of result.
2282 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2283 * to Richedit, not to the edit control. Original documentation is valid.
2284 * FIXME: do the specs mean to return -1 if outside client area or
2285 * if outside formatting rectangle ???
2288 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2296 GetClientRect(es
->hwndSelf
, &rc
);
2297 if (!PtInRect(&rc
, pt
))
2300 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2301 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2305 /*********************************************************************
2309 * Enable or disable soft breaks.
2311 * This means: insert or remove the soft linebreak character (\r\r\n).
2312 * Take care to check if the text still fits the buffer after insertion.
2313 * If not, notify with EN_ERRSPACE.
2316 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2318 es
->flags
&= ~EF_USE_SOFTBRK
;
2320 es
->flags
|= EF_USE_SOFTBRK
;
2321 FIXME("soft break enabled, not implemented\n");
2327 /*********************************************************************
2331 * Hopefully this won't fire back at us.
2332 * We always start with a fixed buffer in the local heap.
2333 * Despite of the documentation says that the local heap is used
2334 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2335 * buffer on the local heap.
2338 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2340 if (!(es
->style
& ES_MULTILINE
))
2343 EDIT_UnlockBuffer(es
, TRUE
);
2345 /* The text buffer handle belongs to the app */
2346 es
->hlocapp
= es
->hloc32W
;
2348 TRACE("Returning %p, LocalSize() = %Id\n", es
->hlocapp
, LocalSize(es
->hlocapp
));
2353 /*********************************************************************
2358 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
)
2360 INT line_len
, dst_len
;
2364 if (es
->style
& ES_MULTILINE
)
2366 if (line
>= es
->line_count
)
2372 i
= EDIT_EM_LineIndex(es
, line
);
2374 line_len
= EDIT_EM_LineLength(es
, i
);
2375 dst_len
= *(WORD
*)dst
;
2377 if (dst_len
<= line_len
)
2379 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2382 else /* Append 0 if enough space */
2384 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2391 /*********************************************************************
2396 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2398 UINT s
= es
->selection_start
;
2399 UINT e
= es
->selection_end
;
2406 return MAKELONG(s
, e
);
2410 /*********************************************************************
2414 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2417 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, const WCHAR
*lpsz_replace
, UINT strl
,
2418 BOOL send_update
, BOOL honor_limit
)
2420 UINT tl
= get_text_length(es
);
2431 TRACE("%s, can_undo %d, send_update %d\n",
2432 debugstr_wn(lpsz_replace
, strl
), can_undo
, send_update
);
2434 s
= es
->selection_start
;
2435 e
= es
->selection_end
;
2437 EDIT_InvalidateUniscribeData(es
);
2438 if ((s
== e
) && !strl
)
2443 size
= tl
- (e
- s
) + strl
;
2447 /* Issue the EN_MAXTEXT notification and continue with replacing text
2448 * so that buffer limit is honored. */
2449 if ((honor_limit
) && (size
> es
->buffer_limit
))
2451 if (!notify_parent(es
, EN_MAXTEXT
)) return;
2452 /* Buffer limit can be smaller than the actual length of text in combobox */
2453 if (es
->buffer_limit
< (tl
- (e
-s
)))
2456 strl
= min(strl
, es
->buffer_limit
- (tl
- (e
-s
)));
2459 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2463 /* there is something to be deleted */
2464 TRACE("deleting stuff.\n");
2466 buf
= Alloc((bufl
+ 1) * sizeof(WCHAR
));
2468 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2469 buf
[bufl
] = 0; /* ensure 0 termination */
2471 lstrcpyW(es
->text
+ s
, es
->text
+ e
);
2472 text_buffer_changed(es
);
2475 /* there is an insertion */
2476 tl
= get_text_length(es
);
2477 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
));
2478 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2480 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2481 p
[i
] = lpsz_replace
[i
];
2482 if(es
->style
& ES_UPPERCASE
)
2483 CharUpperBuffW(p
, strl
);
2484 else if(es
->style
& ES_LOWERCASE
)
2485 CharLowerBuffW(p
, strl
);
2486 text_buffer_changed(es
);
2488 if (es
->style
& ES_MULTILINE
)
2490 INT st
= min(es
->selection_start
, es
->selection_end
);
2491 INT vlc
= get_vertical_line_count(es
);
2493 hrgn
= CreateRectRgn(0, 0, 0, 0);
2494 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2495 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2496 /* if text is too long undo all changes */
2497 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2499 lstrcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2501 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2503 text_buffer_changed(es
);
2504 EDIT_BuildLineDefs_ML(es
, s
, e
,
2505 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2508 SetRectRgn(hrgn
, 0, 0, 0, 0);
2509 if (!notify_parent(es
, EN_MAXTEXT
)) return;
2513 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2514 EDIT_InvalidateUniscribeData(es
);
2515 EDIT_CalcLineWidth_SL(es
);
2516 /* remove chars that don't fit */
2517 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2518 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2519 lstrcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2521 es
->text_length
= -1;
2522 EDIT_InvalidateUniscribeData(es
);
2523 EDIT_CalcLineWidth_SL(es
);
2525 text_buffer_changed(es
);
2526 if (!notify_parent(es
, EN_MAXTEXT
)) return;
2532 utl
= lstrlenW(es
->undo_text
);
2533 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2534 /* undo-buffer is extended to the right */
2535 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2536 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2537 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2538 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2539 /* undo-buffer is extended to the left */
2540 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2541 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2543 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2545 es
->undo_position
= s
;
2547 /* new undo-buffer */
2548 EDIT_MakeUndoFit(es
, e
- s
);
2549 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2550 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2551 es
->undo_position
= s
;
2553 /* any deletion makes the old insertion-undo invalid */
2554 es
->undo_insert_count
= 0;
2556 EDIT_EM_EmptyUndoBuffer(es
);
2560 if ((s
== es
->undo_position
) ||
2561 ((es
->undo_insert_count
) &&
2562 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2564 * insertion is new and at delete position or
2565 * an extension to either left or right
2567 es
->undo_insert_count
+= strl
;
2569 /* new insertion undo */
2570 es
->undo_position
= s
;
2571 es
->undo_insert_count
= strl
;
2572 /* new insertion makes old delete-buffer invalid */
2573 *es
->undo_text
= '\0';
2576 EDIT_EM_EmptyUndoBuffer(es
);
2583 /* If text has been deleted and we're right or center aligned then scroll rightward */
2584 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2586 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2588 if (delta
< 0 && es
->x_offset
)
2590 if (abs(delta
) > es
->x_offset
)
2593 es
->x_offset
+= delta
;
2597 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2598 es
->flags
|= EF_MODIFIED
;
2599 if (send_update
) es
->flags
|= EF_UPDATE
;
2602 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2606 EDIT_UpdateText(es
, NULL
, TRUE
);
2608 EDIT_EM_ScrollCaret(es
);
2610 /* force scroll info update */
2611 EDIT_UpdateScrollInfo(es
);
2614 if(send_update
|| (es
->flags
& EF_UPDATE
))
2616 es
->flags
&= ~EF_UPDATE
;
2617 if (!notify_parent(es
, EN_CHANGE
)) return;
2619 EDIT_InvalidateUniscribeData(es
);
2623 /*********************************************************************
2627 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2630 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2632 if (!(es
->style
& ES_MULTILINE
))
2638 EDIT_UnlockBuffer(es
, TRUE
);
2641 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2643 /* The text buffer handle belongs to the control */
2646 EDIT_LockBuffer(es
);
2647 text_buffer_changed(es
);
2649 es
->x_offset
= es
->y_offset
= 0;
2650 es
->selection_start
= es
->selection_end
= 0;
2651 EDIT_EM_EmptyUndoBuffer(es
);
2652 es
->flags
&= ~EF_MODIFIED
;
2653 es
->flags
&= ~EF_UPDATE
;
2654 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2655 EDIT_UpdateText(es
, NULL
, TRUE
);
2656 EDIT_EM_ScrollCaret(es
);
2657 /* force scroll info update */
2658 EDIT_UpdateScrollInfo(es
);
2662 /*********************************************************************
2666 * NOTE: this version currently implements WinNT limits
2669 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2671 if (!limit
) limit
= ~0u;
2672 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2673 es
->buffer_limit
= limit
;
2676 static BOOL
is_cjk(HDC dc
)
2678 const DWORD FS_DBCS_MASK
= FS_JISJAPAN
|FS_CHINESESIMP
|FS_WANSUNG
|FS_CHINESETRAD
|FS_JOHAB
;
2681 switch (GdiGetCodePage(dc
)) {
2682 case 932: case 936: case 949: case 950: case 1361:
2685 return (GetTextCharsetInfo(dc
, &fs
, 0) != DEFAULT_CHARSET
&&
2686 (fs
.fsCsb
[0] & FS_DBCS_MASK
));
2690 static int get_cjk_fontinfo_margin(int width
, int side_bearing
)
2693 if (side_bearing
< 0)
2694 margin
= min(-side_bearing
, width
/2);
2700 struct char_width_info
{
2701 INT min_lsb
, min_rsb
, unknown
;
2704 /* Undocumented gdi32 export */
2705 extern BOOL WINAPI
GetCharWidthInfo(HDC
, struct char_width_info
*);
2707 /*********************************************************************
2711 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2712 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2713 * margin according to the textmetrics of the current font.
2715 * When EC_USEFONTINFO is used, the margins only change if the edit control is
2716 * equal to or larger than a certain size. The empty client rect is treated as
2719 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2720 WORD left
, WORD right
, BOOL repaint
)
2723 INT default_left_margin
= 0; /* in pixels */
2724 INT default_right_margin
= 0; /* in pixels */
2726 /* Set the default margins depending on the font */
2727 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2728 HDC dc
= GetDC(es
->hwndSelf
);
2729 HFONT old_font
= SelectObject(dc
, es
->font
);
2730 LONG width
= GdiGetCharDimensions(dc
, &tm
, NULL
), rc_width
;
2733 /* The default margins are only non zero for TrueType or Vector fonts */
2734 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2735 struct char_width_info width_info
;
2737 if (is_cjk(dc
) && GetCharWidthInfo(dc
, &width_info
))
2739 default_left_margin
= get_cjk_fontinfo_margin(width
, width_info
.min_lsb
);
2740 default_right_margin
= get_cjk_fontinfo_margin(width
, width_info
.min_rsb
);
2744 default_left_margin
= width
/ 2;
2745 default_right_margin
= width
/ 2;
2748 GetClientRect(es
->hwndSelf
, &rc
);
2749 rc_width
= !IsRectEmpty(&rc
) ? rc
.right
- rc
.left
: 80;
2750 if (rc_width
< default_left_margin
+ default_right_margin
+ width
* 2) {
2751 default_left_margin
= es
->left_margin
;
2752 default_right_margin
= es
->right_margin
;
2755 SelectObject(dc
, old_font
);
2756 ReleaseDC(es
->hwndSelf
, dc
);
2759 if (action
& EC_LEFTMARGIN
) {
2760 es
->format_rect
.left
-= es
->left_margin
;
2761 if (left
!= EC_USEFONTINFO
)
2762 es
->left_margin
= left
;
2764 es
->left_margin
= default_left_margin
;
2765 es
->format_rect
.left
+= es
->left_margin
;
2768 if (action
& EC_RIGHTMARGIN
) {
2769 es
->format_rect
.right
+= es
->right_margin
;
2770 if (right
!= EC_USEFONTINFO
)
2771 es
->right_margin
= right
;
2773 es
->right_margin
= default_right_margin
;
2774 es
->format_rect
.right
-= es
->right_margin
;
2777 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2778 EDIT_AdjustFormatRect(es
);
2779 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2782 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2786 /*********************************************************************
2788 * EM_SETPASSWORDCHAR
2791 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2795 if (es
->style
& ES_MULTILINE
)
2798 if (es
->password_char
== c
)
2801 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2802 es
->password_char
= c
;
2804 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2805 es
->style
|= ES_PASSWORD
;
2807 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2808 es
->style
&= ~ES_PASSWORD
;
2810 EDIT_InvalidateUniscribeData(es
);
2811 EDIT_UpdateText(es
, NULL
, TRUE
);
2815 /*********************************************************************
2820 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2822 if (!(es
->style
& ES_MULTILINE
))
2825 es
->tabs_count
= count
;
2829 es
->tabs
= Alloc(count
* sizeof(INT
));
2830 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2832 EDIT_InvalidateUniscribeData(es
);
2837 /*********************************************************************
2839 * EM_SETWORDBREAKPROC
2842 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, EDITWORDBREAKPROCW wbp
)
2844 if (es
->word_break_proc
== wbp
)
2847 es
->word_break_proc
= wbp
;
2849 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2850 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2851 EDIT_UpdateText(es
, NULL
, TRUE
);
2856 /*********************************************************************
2861 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
2866 /* As per MSDN spec, for a single-line edit control,
2867 the return value is always TRUE */
2868 if( es
->style
& ES_READONLY
)
2869 return !(es
->style
& ES_MULTILINE
);
2871 ulength
= lstrlenW(es
->undo_text
);
2873 utext
= Alloc((ulength
+ 1) * sizeof(WCHAR
));
2875 lstrcpyW(utext
, es
->undo_text
);
2877 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2878 es
->undo_insert_count
, debugstr_w(utext
));
2880 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2881 EDIT_EM_EmptyUndoBuffer(es
);
2882 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, ulength
, TRUE
, TRUE
);
2883 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2884 /* send the notification after the selection start and end are set */
2885 if (!notify_parent(es
, EN_CHANGE
)) return TRUE
;
2886 EDIT_EM_ScrollCaret(es
);
2889 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2890 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
2895 /* Helper function for WM_CHAR
2897 * According to an MSDN blog article titled "Just because you're a control
2898 * doesn't mean that you're necessarily inside a dialog box," multiline edit
2899 * controls without ES_WANTRETURN would attempt to detect whether it is inside
2900 * a dialog box or not.
2902 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
2904 return (es
->flags
& EF_DIALOGMODE
);
2908 /*********************************************************************
2913 static void EDIT_WM_Paste(EDITSTATE
*es
)
2919 /* Protect read-only edit control from modification */
2920 if(es
->style
& ES_READONLY
)
2923 OpenClipboard(es
->hwndSelf
);
2924 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
2925 src
= GlobalLock(hsrc
);
2926 len
= lstrlenW(src
);
2927 /* Protect single-line edit against pasting new line character */
2928 if (!(es
->style
& ES_MULTILINE
) && ((ptr
= wcschr(src
, '\n')))) {
2930 if (len
&& src
[len
- 1] == '\r')
2933 EDIT_EM_ReplaceSel(es
, TRUE
, src
, len
, TRUE
, TRUE
);
2936 else if (es
->style
& ES_PASSWORD
) {
2937 /* clear selected text in password edit box even with empty clipboard */
2938 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2944 /*********************************************************************
2949 static void EDIT_WM_Copy(EDITSTATE
*es
)
2951 INT s
= min(es
->selection_start
, es
->selection_end
);
2952 INT e
= max(es
->selection_start
, es
->selection_end
);
2960 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
2961 dst
= GlobalLock(hdst
);
2962 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
2963 dst
[len
] = 0; /* ensure 0 termination */
2964 TRACE("%s\n", debugstr_w(dst
));
2966 OpenClipboard(es
->hwndSelf
);
2968 SetClipboardData(CF_UNICODETEXT
, hdst
);
2973 /*********************************************************************
2978 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
2980 /* Protect read-only edit control from modification */
2981 if(es
->style
& ES_READONLY
)
2984 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2988 /*********************************************************************
2993 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3000 /*********************************************************************
3005 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3009 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3013 /* If it's not a multiline edit box, it would be ignored below.
3014 * For multiline edit without ES_WANTRETURN, we have to make a
3017 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3018 if (EDIT_IsInsideDialog(es
))
3021 if (es
->style
& ES_MULTILINE
) {
3022 if (es
->style
& ES_READONLY
) {
3023 EDIT_MoveHome(es
, FALSE
, FALSE
);
3024 EDIT_MoveDown_ML(es
, FALSE
);
3026 EDIT_EM_ReplaceSel(es
, TRUE
, L
"\r\n", 2, TRUE
, TRUE
);
3030 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3032 if (EDIT_IsInsideDialog(es
))
3034 EDIT_EM_ReplaceSel(es
, TRUE
, L
"\t", 1, TRUE
, TRUE
);
3038 if (!(es
->style
& ES_READONLY
) && !control
) {
3039 if (es
->selection_start
!= es
->selection_end
)
3042 /* delete character left of caret */
3043 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3044 EDIT_MoveBackward(es
, TRUE
);
3050 if (!(es
->style
& ES_PASSWORD
))
3051 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3054 if (!(es
->style
& ES_READONLY
))
3055 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3058 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3059 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3062 if (!(es
->style
& ES_READONLY
))
3063 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3067 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3068 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3071 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127))
3072 EDIT_EM_ReplaceSel(es
, TRUE
, &c
, 1, TRUE
, TRUE
);
3079 /*********************************************************************
3081 * EDIT_ContextMenuCommand
3084 static void EDIT_ContextMenuCommand(EDITSTATE
*es
, UINT id
)
3088 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3091 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3094 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3097 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3100 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3103 SendMessageW(es
->hwndSelf
, EM_SETSEL
, 0, -1);
3106 ERR("unknown menu item, please report\n");
3112 /*********************************************************************
3116 * Note: the resource files resource/sysres_??.rc cannot define a
3117 * single popup menu. Hence we use a (dummy) menubar
3118 * containing the single popup menu as its first item.
3120 * FIXME: the message identifiers have been chosen arbitrarily,
3121 * hence we use MF_BYPOSITION.
3122 * We might as well use the "real" values (anybody knows ?)
3123 * The menu definition is in resources/sysres_??.rc.
3124 * Once these are OK, we better use MF_BYCOMMAND here
3125 * (as we do in EDIT_WM_Command()).
3128 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3130 HMENU menu
= LoadMenuA(GetModuleHandleA("user32.dll"), "EDITMENU");
3131 HMENU popup
= GetSubMenu(menu
, 0);
3132 UINT start
= es
->selection_start
;
3133 UINT end
= es
->selection_end
;
3137 ORDER_UINT(start
, end
);
3140 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3142 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3144 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3146 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3148 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3150 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3155 if (pt
.x
== -1 && pt
.y
== -1) /* passed via VK_APPS press/release */
3159 /* Windows places the menu at the edit's center in this case */
3160 GetClientRect(es
->hwndSelf
, &rc
);
3161 pt
.x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3162 pt
.y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3163 ClientToScreen(es
->hwndSelf
, &pt
);
3166 if (!(es
->flags
& EF_FOCUSED
))
3167 SetFocus(es
->hwndSelf
);
3169 cmd
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
| TPM_NONOTIFY
,
3170 pt
.x
, pt
.y
, 0, es
->hwndSelf
, NULL
);
3173 EDIT_ContextMenuCommand(es
, cmd
);
3179 /*********************************************************************
3184 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
)
3189 lstrcpynW(dst
, es
->text
, count
);
3190 return lstrlenW(dst
);
3193 /*********************************************************************
3198 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3200 HWND hLBox
= es
->hwndListBox
;
3208 hCombo
= GetParent(es
->hwndSelf
);
3212 TRACE("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3214 if (key
== VK_UP
|| key
== VK_DOWN
)
3216 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3219 if (msg
== WM_KEYDOWN
|| nEUI
)
3220 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3226 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3228 /* make sure ComboLBox pops up */
3229 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3234 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3237 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3239 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, !bDropped
, 0);
3241 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3246 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3252 /*********************************************************************
3256 * Handling of special keys that don't produce a WM_CHAR
3257 * (i.e. non-printable keys) & Backspace & Delete
3260 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3265 if (GetKeyState(VK_MENU
) & 0x8000)
3268 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3269 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3274 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3279 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3280 EDIT_MoveUp_ML(es
, shift
);
3283 EDIT_MoveWordBackward(es
, shift
);
3285 EDIT_MoveBackward(es
, shift
);
3288 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3292 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3293 EDIT_MoveDown_ML(es
, shift
);
3295 EDIT_MoveWordForward(es
, shift
);
3297 EDIT_MoveForward(es
, shift
);
3300 EDIT_MoveHome(es
, shift
, control
);
3303 EDIT_MoveEnd(es
, shift
, control
);
3306 if (es
->style
& ES_MULTILINE
)
3307 EDIT_MovePageUp_ML(es
, shift
);
3309 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3312 if (es
->style
& ES_MULTILINE
)
3313 EDIT_MovePageDown_ML(es
, shift
);
3315 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3318 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3319 if (es
->selection_start
!= es
->selection_end
) {
3325 EDIT_EM_SetSel(es
, ~0u, 0, FALSE
);
3327 /* delete character left of caret */
3328 EDIT_MoveBackward(es
, TRUE
);
3330 /* delete to end of line */
3331 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3333 /* delete character right of caret */
3334 EDIT_MoveForward(es
, TRUE
);
3341 if (!(es
->style
& ES_READONLY
))
3347 /* If the edit doesn't want the return send a message to the default object */
3348 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3352 if (!EDIT_IsInsideDialog(es
)) break;
3354 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3355 if (HIWORD(dw
) == DC_HASDEFID
)
3357 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3360 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3361 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3367 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3368 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3371 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3372 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3377 if (EDIT_EM_SetSel(es
, 0, get_text_length(es
), FALSE
))
3379 if (!notify_parent(es
, EN_UPDATE
)) break;
3380 notify_parent(es
, EN_CHANGE
);
3389 /*********************************************************************
3394 static LRESULT
EDIT_WM_KillFocus(HTHEME theme
, EDITSTATE
*es
)
3396 UINT flags
= RDW_INVALIDATE
;
3398 es
->flags
&= ~EF_FOCUSED
;
3400 if (!(es
->style
& ES_NOHIDESEL
))
3401 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3402 if (!notify_parent(es
, EN_KILLFOCUS
)) return 0;
3403 /* Throw away left over scroll when we lose focus */
3404 es
->wheelDeltaRemainder
= 0;
3409 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3414 /*********************************************************************
3418 * The caret position has been set on the WM_LBUTTONDOWN message
3421 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3424 INT e
= es
->selection_end
;
3429 es
->bCaptureState
= TRUE
;
3430 SetCapture(es
->hwndSelf
);
3432 l
= EDIT_EM_LineFromChar(es
, e
);
3433 li
= EDIT_EM_LineIndex(es
, l
);
3434 ll
= EDIT_EM_LineLength(es
, e
);
3435 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3436 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3437 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3438 EDIT_EM_ScrollCaret(es
);
3443 /*********************************************************************
3448 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3453 es
->bCaptureState
= TRUE
;
3454 SetCapture(es
->hwndSelf
);
3455 EDIT_ConfinePoint(es
, &x
, &y
);
3456 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3457 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3458 EDIT_EM_ScrollCaret(es
);
3460 if (!(es
->flags
& EF_FOCUSED
))
3461 SetFocus(es
->hwndSelf
);
3467 /*********************************************************************
3472 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3474 if (es
->bCaptureState
) {
3475 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3477 es
->bCaptureState
= FALSE
;
3482 /*********************************************************************
3487 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3489 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3494 /*********************************************************************
3499 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3504 /* If the mouse has been captured by process other than the edit control itself,
3505 * the windows edit controls will not select the strings with mouse move.
3507 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3510 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3511 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3512 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3513 EDIT_EM_ScrollCaret(es
);
3518 /*********************************************************************
3523 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3536 BOOL rev
= es
->bEnableState
&&
3537 ((es
->flags
& EF_FOCUSED
) ||
3538 (es
->style
& ES_NOHIDESEL
));
3539 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3541 /* The dc we use for calculating may not be the one we paint into.
3542 This is the safest action. */
3543 EDIT_InvalidateUniscribeData(es
);
3544 GetClientRect(es
->hwndSelf
, &rcClient
);
3546 /* get the background brush */
3547 brush
= EDIT_NotifyCtlColor(es
, dc
);
3549 /* paint the border and the background */
3550 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3552 if(es
->style
& WS_BORDER
) {
3553 bw
= GetSystemMetrics(SM_CXBORDER
);
3554 bh
= GetSystemMetrics(SM_CYBORDER
);
3556 if(es
->style
& ES_MULTILINE
) {
3557 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3558 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3561 /* Draw the frame. Same code as in nonclient.c */
3562 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3563 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3564 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3565 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3566 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3567 SelectObject(dc
, old_brush
);
3569 /* Keep the border clean */
3570 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3571 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3574 GetClipBox(dc
, &rc
);
3575 FillRect(dc
, &rc
, brush
);
3577 IntersectClipRect(dc
, es
->format_rect
.left
,
3578 es
->format_rect
.top
,
3579 es
->format_rect
.right
,
3580 es
->format_rect
.bottom
);
3581 if (es
->style
& ES_MULTILINE
) {
3583 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3586 old_font
= SelectObject(dc
, es
->font
);
3588 if (!es
->bEnableState
)
3589 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3590 GetClipBox(dc
, &rcRgn
);
3591 if (es
->style
& ES_MULTILINE
) {
3592 INT vlc
= get_vertical_line_count(es
);
3593 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3594 EDIT_UpdateUniscribeData(es
, dc
, i
);
3595 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3596 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3597 EDIT_PaintLine(es
, dc
, i
, rev
);
3600 EDIT_UpdateUniscribeData(es
, dc
, 0);
3601 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3602 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3603 EDIT_PaintLine(es
, dc
, 0, rev
);
3606 SelectObject(dc
, old_font
);
3609 EndPaint(es
->hwndSelf
, &ps
);
3612 static void EDIT_WM_NCPaint(HWND hwnd
, HRGN region
)
3614 DWORD exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3615 HTHEME theme
= GetWindowTheme(hwnd
);
3616 HRGN cliprgn
= region
;
3618 if (theme
&& exStyle
& WS_EX_CLIENTEDGE
)
3622 int cxEdge
= GetSystemMetrics(SM_CXEDGE
),
3623 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
3624 const int part
= EP_EDITTEXT
;
3625 int state
= ETS_NORMAL
;
3626 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3628 if (!IsWindowEnabled(hwnd
))
3629 state
= ETS_DISABLED
;
3630 else if (dwStyle
& ES_READONLY
)
3631 state
= ETS_READONLY
;
3632 else if (GetFocus() == hwnd
)
3633 state
= ETS_FOCUSED
;
3635 GetWindowRect(hwnd
, &r
);
3637 /* New clipping region passed to default proc to exclude border */
3638 cliprgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
,
3639 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
3640 if (region
!= (HRGN
)1)
3641 CombineRgn(cliprgn
, cliprgn
, region
, RGN_AND
);
3642 OffsetRect(&r
, -r
.left
, -r
.top
);
3644 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
3646 if (IsThemeBackgroundPartiallyTransparent(theme
, part
, state
))
3647 DrawThemeParentBackground(hwnd
, dc
, &r
);
3648 DrawThemeBackground(theme
, dc
, part
, state
, &r
, 0);
3649 ReleaseDC(hwnd
, dc
);
3652 /* Call default proc to get the scrollbars etc. also painted */
3653 DefWindowProcW (hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
3654 if (cliprgn
!= region
)
3655 DeleteObject(cliprgn
);
3658 /*********************************************************************
3663 static void EDIT_WM_SetFocus(HTHEME theme
, EDITSTATE
*es
)
3665 UINT flags
= RDW_INVALIDATE
;
3667 es
->flags
|= EF_FOCUSED
;
3669 if (!(es
->style
& ES_NOHIDESEL
))
3670 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3672 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3673 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3674 ShowCaret(es
->hwndSelf
);
3675 if (!notify_parent(es
, EN_SETFOCUS
)) return;
3678 flags
|= RDW_FRAME
| RDW_ERASE
;
3680 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3684 static DWORD
get_font_margins(HDC hdc
, const TEXTMETRICW
*tm
)
3690 if (!(tm
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
3691 return MAKELONG(EC_USEFONTINFO
, EC_USEFONTINFO
);
3694 return MAKELONG(EC_USEFONTINFO
, EC_USEFONTINFO
);
3696 if (!GetCharABCWidthsW(hdc
, 0, 255, abc
))
3700 for (i
= 0; i
< ARRAY_SIZE(abc
); i
++) {
3701 if (-abc
[i
].abcA
> right
) right
= -abc
[i
].abcA
;
3702 if (-abc
[i
].abcC
> left
) left
= -abc
[i
].abcC
;
3704 return MAKELONG(left
, right
);
3707 static void EDIT_UpdateImmCompositionFont(EDITSTATE
*es
)
3709 LOGFONTW composition_font
;
3710 HIMC himc
= ImmGetContext(es
->hwndSelf
);
3711 GetObjectW(es
->font
, sizeof(LOGFONTW
), &composition_font
);
3712 ImmSetCompositionFontW(himc
, &composition_font
);
3713 ImmReleaseContext(es
->hwndSelf
, himc
);
3716 /*********************************************************************
3720 * With Win95 look the margins are set to default font value unless
3721 * the system font (font == 0) is being set, in which case they are left
3725 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3734 EDIT_InvalidateUniscribeData(es
);
3735 dc
= GetDC(es
->hwndSelf
);
3737 old_font
= SelectObject(dc
, font
);
3738 GetTextMetricsW(dc
, &tm
);
3739 es
->line_height
= tm
.tmHeight
;
3740 es
->char_width
= tm
.tmAveCharWidth
;
3741 margins
= get_font_margins(dc
, &tm
);
3743 SelectObject(dc
, old_font
);
3744 ReleaseDC(es
->hwndSelf
, dc
);
3746 /* Reset the format rect and the margins */
3747 GetClientRect(es
->hwndSelf
, &clientRect
);
3748 EDIT_SetRectNP(es
, &clientRect
);
3750 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3751 LOWORD(margins
), HIWORD(margins
), FALSE
);
3753 if (es
->style
& ES_MULTILINE
)
3754 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3756 EDIT_CalcLineWidth_SL(es
);
3759 EDIT_UpdateText(es
, NULL
, TRUE
);
3760 if (es
->flags
& EF_FOCUSED
) {
3762 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3763 EDIT_SetCaretPos(es
, es
->selection_end
,
3764 es
->flags
& EF_AFTER_WRAP
);
3765 ShowCaret(es
->hwndSelf
);
3768 EDIT_UpdateImmCompositionFont(es
);
3772 /*********************************************************************
3777 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3778 * The modified flag is reset. No notifications are sent.
3780 * For single-line controls, reception of WM_SETTEXT triggers:
3781 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3784 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
)
3786 if (es
->flags
& EF_UPDATE
)
3787 /* fixed this bug once; complain if we see it about to happen again. */
3788 ERR("SetSel may generate UPDATE message whose handler may reset "
3791 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3794 TRACE("%s\n", debugstr_w(text
));
3795 EDIT_EM_ReplaceSel(es
, FALSE
, text
, lstrlenW(text
), FALSE
, FALSE
);
3800 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3803 es
->flags
&= ~EF_MODIFIED
;
3804 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3806 /* Send the notification after the selection start and end have been set
3807 * edit control doesn't send notification on WM_SETTEXT
3808 * if it is multiline, or it is part of combobox
3810 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3812 if (!notify_parent(es
, EN_UPDATE
)) return;
3813 if (!notify_parent(es
, EN_CHANGE
)) return;
3815 EDIT_EM_ScrollCaret(es
);
3816 EDIT_UpdateScrollInfo(es
);
3817 EDIT_InvalidateUniscribeData(es
);
3821 /*********************************************************************
3826 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3828 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3830 GetClientRect(es
->hwndSelf
, &rc
);
3831 EDIT_SetRectNP(es
, &rc
);
3832 EDIT_UpdateText(es
, NULL
, TRUE
);
3837 /*********************************************************************
3841 * This message is sent by SetWindowLong on having changed either the Style
3842 * or the extended style.
3844 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3846 * See also EDIT_WM_NCCreate
3848 * It appears that the Windows version of the edit control allows the style
3849 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3850 * style variable which will generally be different. In this function we
3851 * update the internal style based on what changed in the externally visible
3854 * Much of this content as based upon the MSDN, especially:
3855 * Platform SDK Documentation -> User Interface Services ->
3856 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3857 * Edit Control Styles
3859 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3861 if (GWL_STYLE
== which
) {
3862 DWORD style_change_mask
;
3864 /* Only a subset of changes can be applied after the control
3867 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3869 if (es
->style
& ES_MULTILINE
)
3870 style_change_mask
|= ES_WANTRETURN
;
3872 new_style
= style
->styleNew
& style_change_mask
;
3874 /* Number overrides lowercase overrides uppercase (at least it
3875 * does in Win95). However I'll bet that ES_NUMBER would be
3876 * invalid under Win 3.1.
3878 if (new_style
& ES_NUMBER
) {
3879 ; /* do not override the ES_NUMBER */
3880 } else if (new_style
& ES_LOWERCASE
) {
3881 new_style
&= ~ES_UPPERCASE
;
3884 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3885 } else if (GWL_EXSTYLE
== which
) {
3886 ; /* FIXME - what is needed here */
3888 WARN ("Invalid style change %#Ix.\n", which
);
3894 /*********************************************************************
3899 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3901 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3902 if (EDIT_EM_CanUndo(es
))
3905 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3906 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3909 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
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 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 %Id\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 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 %Id\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));
4175 /*********************************************************************
4180 static BOOL
EDIT_EM_SetCueBanner(EDITSTATE
*es
, BOOL draw_focused
, const WCHAR
*cue_text
)
4182 if (es
->style
& ES_MULTILINE
|| !cue_text
)
4185 Free(es
->cue_banner_text
);
4186 es
->cue_banner_text
= wcsdup(cue_text
);
4187 es
->cue_banner_draw_focused
= draw_focused
;
4192 /*********************************************************************
4197 static BOOL
EDIT_EM_GetCueBanner(EDITSTATE
*es
, WCHAR
*buf
, DWORD size
)
4199 if (es
->style
& ES_MULTILINE
)
4202 if (!es
->cue_banner_text
)
4211 lstrcpynW(buf
, es
->cue_banner_text
, size
);
4217 /********************************************************************
4219 * The Following code is to handle inline editing from IMEs
4222 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4227 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4233 lpResultStr
= Alloc(buflen
);
4236 ERR("Unable to alloc buffer for IME string\n");
4240 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4241 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4245 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4249 hIMC
= ImmGetContext(hwnd
);
4253 if (CompFlag
& GCS_RESULTSTR
)
4254 EDIT_GetResultStr(hIMC
, es
);
4256 ImmReleaseContext(hwnd
, hIMC
);
4260 /*********************************************************************
4264 * See also EDIT_WM_StyleChanged
4266 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
4271 TRACE("Creating edit control, style = %#lx\n", lpcs
->style
);
4273 if (!(es
= Alloc(sizeof(*es
))))
4275 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4278 * Note: since the EDITSTATE has not been fully initialized yet,
4279 * we can't use any API calls that may send
4280 * WM_XXX messages before WM_NCCREATE is completed.
4283 es
->style
= lpcs
->style
;
4285 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4287 es
->hwndSelf
= hwnd
;
4288 /* Save parent, which will be notified by EN_* messages */
4289 es
->hwndParent
= lpcs
->hwndParent
;
4291 if (es
->style
& ES_COMBO
)
4292 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4294 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4295 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4297 /* Number overrides lowercase overrides uppercase (at least it
4298 * does in Win95). However I'll bet that ES_NUMBER would be
4299 * invalid under Win 3.1.
4301 if (es
->style
& ES_NUMBER
) {
4302 ; /* do not override the ES_NUMBER */
4303 } else if (es
->style
& ES_LOWERCASE
) {
4304 es
->style
&= ~ES_UPPERCASE
;
4306 if (es
->style
& ES_MULTILINE
) {
4307 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4308 if (es
->style
& WS_VSCROLL
)
4309 es
->style
|= ES_AUTOVSCROLL
;
4310 if (es
->style
& WS_HSCROLL
)
4311 es
->style
|= ES_AUTOHSCROLL
;
4312 es
->style
&= ~ES_PASSWORD
;
4313 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4314 /* Confirmed - RIGHT overrides CENTER */
4315 if (es
->style
& ES_RIGHT
)
4316 es
->style
&= ~ES_CENTER
;
4317 es
->style
&= ~WS_HSCROLL
;
4318 es
->style
&= ~ES_AUTOHSCROLL
;
4321 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4322 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4323 es
->style
&= ~ES_CENTER
;
4324 es
->style
&= ~WS_HSCROLL
;
4325 es
->style
&= ~WS_VSCROLL
;
4326 if (es
->style
& ES_PASSWORD
)
4327 es
->password_char
= '*';
4330 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4331 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4333 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4335 if (!(es
->undo_text
= Alloc((es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4337 es
->undo_buffer_size
= es
->buffer_size
;
4339 if (es
->style
& ES_MULTILINE
)
4340 if (!(es
->first_line_def
= Alloc(sizeof(LINEDEF
))))
4345 * In Win95 look and feel, the WS_BORDER style is replaced by the
4346 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4347 * control a nonclient area so we don't need to draw the border.
4348 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4349 * a nonclient area and we should handle painting the border ourselves.
4351 * When making modifications please ensure that the code still works
4352 * for edit controls created directly with style 0x50800000, exStyle 0
4353 * (which should have a single pixel border)
4355 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4356 es
->style
&= ~WS_BORDER
;
4357 else if (es
->style
& WS_BORDER
)
4358 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4363 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4364 EDIT_InvalidateUniscribeData(es
);
4365 Free(es
->first_line_def
);
4366 Free(es
->undo_text
);
4367 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4374 /*********************************************************************
4379 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, const WCHAR
*name
)
4383 TRACE("%s\n", debugstr_w(name
));
4386 * To initialize some final structure members, we call some helper
4387 * functions. However, since the EDITSTATE is not consistent (i.e.
4388 * not fully initialized), we should be very careful which
4389 * functions can be called, and in what order.
4391 EDIT_WM_SetFont(es
, 0, FALSE
);
4392 EDIT_EM_EmptyUndoBuffer(es
);
4394 /* We need to calculate the format rect
4395 (applications may send EM_SETMARGINS before the control gets visible) */
4396 GetClientRect(es
->hwndSelf
, &clientRect
);
4397 EDIT_SetRectNP(es
, &clientRect
);
4401 EDIT_EM_ReplaceSel(es
, FALSE
, name
, lstrlenW(name
), FALSE
, FALSE
);
4402 /* if we insert text to the editline, the text scrolls out
4403 * of the window, as the caret is placed after the insert
4404 * pos normally; thus we reset es->selection... to 0 and
4407 es
->selection_start
= es
->selection_end
= 0;
4408 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4409 * Messages are only to be sent when the USER does something to
4410 * change the contents. So I am removing this EN_CHANGE
4412 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4414 EDIT_EM_ScrollCaret(es
);
4417 /* force scroll info update */
4418 EDIT_UpdateScrollInfo(es
);
4419 OpenThemeData(es
->hwndSelf
, WC_EDITW
);
4421 /* The rule seems to return 1 here for success */
4422 /* Power Builder masked edit controls will crash */
4424 /* FIXME: is that in all cases so ? */
4429 /*********************************************************************
4434 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4439 theme
= GetWindowTheme(es
->hwndSelf
);
4440 CloseThemeData(theme
);
4442 /* The app can own the text buffer handle */
4443 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
))
4444 LocalFree(es
->hloc32W
);
4446 EDIT_InvalidateUniscribeData(es
);
4448 pc
= es
->first_line_def
;
4456 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4457 Free(es
->undo_text
);
4458 Free(es
->cue_banner_text
);
4464 static LRESULT CALLBACK
EDIT_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4466 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW(hwnd
, 0);
4471 TRACE("hwnd %p, msg %#x, wparam %Ix, lparam %Ix\n", hwnd
, msg
, wParam
, lParam
);
4473 if (!es
&& msg
!= WM_NCCREATE
)
4474 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4476 if (es
&& (msg
!= WM_NCDESTROY
))
4477 EDIT_LockBuffer(es
);
4482 result
= EDIT_EM_GetSel(es
, (UINT
*)wParam
, (UINT
*)lParam
);
4486 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4487 EDIT_EM_ScrollCaret(es
);
4492 rect
= (RECT
*)lParam
;
4494 *rect
= es
->format_rect
;
4498 if ((es
->style
& ES_MULTILINE
) && lParam
)
4500 EDIT_SetRectNP(es
, (RECT
*)lParam
);
4501 EDIT_UpdateText(es
, NULL
, TRUE
);
4506 if ((es
->style
& ES_MULTILINE
) && lParam
)
4507 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4511 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4515 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4518 case EM_SCROLLCARET
:
4519 EDIT_EM_ScrollCaret(es
);
4524 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4529 es
->flags
|= EF_MODIFIED
;
4531 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4534 case EM_GETLINECOUNT
:
4535 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4539 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4543 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4547 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4551 result
= EDIT_EM_GetThumb(es
);
4554 /* these messages missing from specs */
4559 FIXME("undocumented message 0x%x, please report\n", msg
);
4560 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4564 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4569 const WCHAR
*textW
= (const WCHAR
*)lParam
;
4571 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, lstrlenW(textW
), TRUE
, TRUE
);
4577 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4580 case EM_SETLIMITTEXT
:
4581 EDIT_EM_SetLimitText(es
, wParam
);
4585 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4590 result
= (LRESULT
)EDIT_EM_Undo(es
);
4594 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4597 case EM_LINEFROMCHAR
:
4598 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4601 case EM_SETTABSTOPS
:
4602 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4605 case EM_SETPASSWORDCHAR
:
4606 EDIT_EM_SetPasswordChar(es
, wParam
);
4609 case EM_EMPTYUNDOBUFFER
:
4610 EDIT_EM_EmptyUndoBuffer(es
);
4613 case EM_GETFIRSTVISIBLELINE
:
4614 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4617 case EM_SETREADONLY
:
4619 DWORD old_style
= es
->style
;
4623 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | ES_READONLY
);
4624 es
->style
|= ES_READONLY
;
4628 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4629 es
->style
&= ~ES_READONLY
;
4632 if (old_style
^ es
->style
)
4633 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4639 case EM_SETWORDBREAKPROC
:
4640 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4644 case EM_GETWORDBREAKPROC
:
4645 result
= (LRESULT
)es
->word_break_proc
;
4648 case EM_GETPASSWORDCHAR
:
4649 result
= es
->password_char
;
4653 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4657 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4660 case EM_GETLIMITTEXT
:
4661 result
= es
->buffer_limit
;
4664 case EM_POSFROMCHAR
:
4665 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4666 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4669 case EM_CHARFROMPOS
:
4670 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4673 case EM_SETCUEBANNER
:
4674 result
= EDIT_EM_SetCueBanner(es
, (BOOL
)wParam
, (const WCHAR
*)lParam
);
4677 case EM_GETCUEBANNER
:
4678 result
= EDIT_EM_GetCueBanner(es
, (WCHAR
*)wParam
, (DWORD
)lParam
);
4681 case EM_SETIMESTATUS
:
4682 if (wParam
== EMSIS_COMPOSITIONSTRING
)
4683 es
->ime_status
= lParam
& 0xFFFF;
4688 case EM_GETIMESTATUS
:
4689 result
= wParam
== EMSIS_COMPOSITIONSTRING
? es
->ime_status
: 1;
4692 /* End of the EM_ messages which were in numerical order; what order
4693 * are these in? vaguely alphabetical?
4697 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
4701 result
= EDIT_WM_NCDestroy(es
);
4706 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4708 if (es
->style
& ES_MULTILINE
)
4709 result
|= DLGC_WANTALLKEYS
;
4713 MSG
*msg
= (MSG
*)lParam
;
4714 es
->flags
|= EF_DIALOGMODE
;
4716 if (msg
->message
== WM_KEYDOWN
)
4718 int vk
= (int)msg
->wParam
;
4720 if (es
->hwndListBox
)
4722 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4723 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4724 result
|= DLGC_WANTMESSAGE
;
4732 WCHAR charW
= wParam
;
4734 if (es
->hwndListBox
)
4736 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4738 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4739 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4743 result
= EDIT_WM_Char(es
, charW
);
4748 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4749 if (wParam
<= 0x000fffff)
4751 if (wParam
> 0xffff) /* convert to surrogates */
4754 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4755 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4758 EDIT_WM_Char(es
, wParam
);
4766 case WM_CONTEXTMENU
:
4767 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4775 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4783 es
->bEnableState
= (BOOL
) wParam
;
4784 EDIT_UpdateText(es
, NULL
, TRUE
);
4785 if (GetWindowTheme(hwnd
))
4786 RedrawWindow(hwnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
4790 /* we do the proper erase in EDIT_WM_Paint */
4795 result
= (LRESULT
)es
->font
;
4799 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4802 case WM_GETTEXTLENGTH
:
4803 result
= get_text_length(es
);
4807 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4811 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4815 result
= EDIT_WM_KillFocus(GetWindowTheme(hwnd
), es
);
4818 case WM_LBUTTONDBLCLK
:
4819 result
= EDIT_WM_LButtonDblClk(es
);
4822 case WM_LBUTTONDOWN
:
4823 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4827 result
= EDIT_WM_LButtonUp(es
);
4830 case WM_MBUTTONDOWN
:
4831 result
= EDIT_WM_MButtonDown(es
);
4835 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4838 case WM_PRINTCLIENT
:
4840 EDIT_WM_Paint(es
, (HDC
)wParam
);
4844 EDIT_WM_NCPaint(hwnd
, (HRGN
)wParam
);
4852 EDIT_WM_SetFocus(GetWindowTheme(hwnd
), es
);
4856 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4860 /* FIXME: actually set an internal flag and behave accordingly */
4864 EDIT_WM_SetText(es
, (const WCHAR
*)lParam
);
4869 EDIT_WM_Size(es
, (UINT
)wParam
);
4872 case WM_STYLECHANGED
:
4873 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4876 case WM_STYLECHANGING
:
4877 result
= 0; /* See EDIT_WM_StyleChanged */
4881 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
4885 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4891 INT pulScrollLines
= 3;
4892 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4894 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4896 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4900 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4901 /* if scrolling changes direction, ignore left overs */
4902 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
4903 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
4904 es
->wheelDeltaRemainder
+= wheelDelta
;
4906 es
->wheelDeltaRemainder
= wheelDelta
;
4908 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
4911 pulScrollLines
= min(es
->line_count
, pulScrollLines
);
4912 cLineScroll
= pulScrollLines
* es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
4913 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
4914 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
4919 /* IME messages to make the edit control IME aware */
4920 case WM_IME_SETCONTEXT
:
4922 EDIT_UpdateImmCompositionWindow(es
, pt
.x
, pt
.y
);
4923 EDIT_UpdateImmCompositionFont(es
);
4926 case WM_IME_COMPOSITION
:
4927 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4928 if ((lParam
& GCS_RESULTSTR
) && (es
->ime_status
& EIMES_GETCOMPSTRATONCE
))
4929 EDIT_ImeComposition(hwnd
, lParam
, es
);
4930 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4935 case WM_IME_CONTROL
:
4938 case WM_IME_REQUEST
:
4941 case IMR_QUERYCHARPOSITION
:
4943 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
4946 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
4947 chpos
->pt
.x
= LOWORD(pos
);
4948 chpos
->pt
.y
= HIWORD(pos
);
4949 chpos
->cLineHeight
= es
->line_height
;
4950 chpos
->rcDocument
= es
->format_rect
;
4951 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
4952 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
4959 case WM_THEMECHANGED
:
4960 CloseThemeData(GetWindowTheme(hwnd
));
4961 OpenThemeData(hwnd
, WC_EDITW
);
4962 InvalidateRect(hwnd
, NULL
, TRUE
);
4966 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4970 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
4971 EDIT_UnlockBuffer(es
, FALSE
);
4973 TRACE("hwnd=%p msg=%x -- %#Ix\n", hwnd
, msg
, result
);
4978 void EDIT_Register(void)
4982 memset(&wndClass
, 0, sizeof(wndClass
));
4983 wndClass
.style
= CS_PARENTDC
| CS_GLOBALCLASS
| CS_DBLCLKS
;
4984 wndClass
.lpfnWndProc
= EDIT_WindowProc
;
4985 wndClass
.cbClsExtra
= 0;
4987 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*) + sizeof(WORD
);
4989 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*);
4991 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_IBEAM
);
4992 wndClass
.hbrBackground
= NULL
;
4993 wndClass
.lpszClassName
= WC_EDITW
;
4994 RegisterClassW(&wndClass
);