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 INT region_posx
; /* Position of cursor relative to region: */
117 INT region_posy
; /* -1: to left, 0: within, 1: to right */
118 EDITWORDBREAKPROCW word_break_proc
;
119 INT line_count
; /* number of lines */
120 INT y_offset
; /* scroll offset in number of lines */
121 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
122 BOOL bEnableState
; /* flag keeping the enable state */
123 HWND hwndSelf
; /* the our window handle */
124 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
125 Even if parent will change, EN_* messages
126 should be sent to the first parent. */
127 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
128 INT wheelDeltaRemainder
; /* scroll wheel delta left over after scrolling whole lines */
129 WCHAR
*cue_banner_text
;
130 BOOL cue_banner_draw_focused
;
133 * only for multi line controls
135 INT lock_count
; /* amount of re-entries in the EditWndProc */
138 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
139 HLOCAL hloc32W
; /* our unicode local memory block */
140 HLOCAL hlocapp
; /* The text buffer handle belongs to the app */
144 UINT ime_status
; /* IME status flag */
149 SCRIPT_LOGATTR
*logAttr
;
150 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data for single line controls */
154 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
155 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
157 static inline BOOL
notify_parent(const EDITSTATE
*es
, INT code
)
159 HWND hwnd
= es
->hwndSelf
;
160 TRACE("notification %d sent to %p.\n", code
, es
->hwndParent
);
161 SendMessageW(es
->hwndParent
, WM_COMMAND
, MAKEWPARAM(GetWindowLongPtrW(es
->hwndSelf
, GWLP_ID
), code
), (LPARAM
)es
->hwndSelf
);
162 return IsWindow(hwnd
);
165 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
167 /*********************************************************************
172 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
174 return (es
->undo_insert_count
|| lstrlenW(es
->undo_text
));
178 /*********************************************************************
183 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
185 es
->undo_insert_count
= 0;
186 *es
->undo_text
= '\0';
189 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
194 if ((!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
195 msg
= WM_CTLCOLORSTATIC
;
197 msg
= WM_CTLCOLOREDIT
;
199 /* Why do we notify to es->hwndParent, and we send this one to GetParent()? */
200 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
202 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
207 static inline UINT
get_text_length(EDITSTATE
*es
)
209 if(es
->text_length
== (UINT
)-1)
210 es
->text_length
= lstrlenW(es
->text
);
211 return es
->text_length
;
215 /*********************************************************************
219 * Find the beginning of words.
220 * Note: unlike the specs for a WordBreakProc, this function can
221 * only be called without linebreaks between s[0] up to
222 * s[count - 1]. Remember it is only called
223 * internally, so we can decide this for ourselves.
224 * Additionally we will always be breaking the full string.
227 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
231 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
239 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
240 psa
.eScript
= SCRIPT_UNDEFINED
;
242 es
->logAttr
= Alloc(sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
243 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
250 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
257 while (index
< count
&& s
[index
] && !es
->logAttr
[index
].fSoftBreak
)
262 ret
= es
->logAttr
[index
].fWhiteSpace
;
265 ERR("unknown action code, please report !\n");
272 /*********************************************************************
274 * EDIT_CallWordBreakProc
276 * Call appropriate WordBreakProc (internal or external).
278 * Note: The "start" argument should always be an index referring
279 * to es->text. The actual wordbreak proc might be
280 * 16 bit, so we can't always pass any 32 bit LPSTR.
281 * Hence we assume that es->text is the buffer that holds
282 * the string under examination (we can decide this for ourselves).
285 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
289 if (es
->word_break_proc
)
290 ret
= es
->word_break_proc(es
->text
+ start
, index
, count
, action
);
292 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+ start
, count
+ start
, action
) - start
;
297 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
301 ScriptStringFree(&line_def
->ssa
);
302 line_def
->ssa
= NULL
;
306 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
308 LINEDEF
*line_def
= es
->first_line_def
;
311 EDIT_InvalidateUniscribeData_linedef(line_def
);
312 line_def
= line_def
->next
;
316 ScriptStringFree(&es
->ssa
);
321 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
326 if (line_def
->net_length
&& !line_def
->ssa
)
328 int index
= line_def
->index
;
329 HFONT old_font
= NULL
;
331 SCRIPT_TABDEF tabdef
;
335 udc
= GetDC(es
->hwndSelf
);
337 old_font
= SelectObject(udc
, es
->font
);
339 tabdef
.cTabStops
= es
->tabs_count
;
340 tabdef
.iScale
= GdiGetCharDimensions(udc
, NULL
, NULL
);
341 tabdef
.pTabStops
= es
->tabs
;
342 tabdef
.iTabOrigin
= 0;
344 hr
= ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
,
345 (1.5*line_def
->net_length
+16), -1,
346 SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1,
347 NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
350 WARN("ScriptStringAnalyse failed, hr %#lx.\n", hr
);
351 line_def
->ssa
= NULL
;
355 SelectObject(udc
, old_font
);
357 ReleaseDC(es
->hwndSelf
, udc
);
360 return line_def
->ssa
;
363 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
367 if (!(es
->style
& ES_MULTILINE
))
371 INT length
= get_text_length(es
);
372 HFONT old_font
= NULL
;
376 udc
= GetDC(es
->hwndSelf
);
378 old_font
= SelectObject(udc
, es
->font
);
380 if (es
->style
& ES_PASSWORD
)
381 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
);
383 ScriptStringAnalyse(udc
, es
->text
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
386 SelectObject(udc
, old_font
);
388 ReleaseDC(es
->hwndSelf
, udc
);
394 line_def
= es
->first_line_def
;
395 while (line_def
&& line
)
397 line_def
= line_def
->next
;
401 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
405 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
407 INT vlc
= es
->line_height
? (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
: 0;
411 /*********************************************************************
413 * EDIT_BuildLineDefs_ML
415 * Build linked list of text lines.
416 * Lines can end with '\0' (last line), a character (if it is wrapped),
417 * a soft return '\r\r\n' or a hard return '\r\n'
420 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
422 LPWSTR current_position
, cp
;
424 LINEDEF
*current_line
;
425 LINEDEF
*previous_line
;
427 INT line_index
= 0, nstart_line
, nstart_index
;
428 INT line_count
= es
->line_count
;
433 if (istart
== iend
&& delta
== 0)
436 previous_line
= NULL
;
437 current_line
= es
->first_line_def
;
439 /* Find starting line. istart must lie inside an existing line or
440 * at the end of buffer */
442 if (istart
< current_line
->index
+ current_line
->length
||
443 current_line
->ending
== END_0
)
446 previous_line
= current_line
;
447 current_line
= current_line
->next
;
449 } while (current_line
);
451 if (!current_line
) /* Error occurred start is not inside previous buffer */
453 FIXME(" modification occurred outside buffer\n");
457 /* Remember start of modifications in order to calculate update region */
458 nstart_line
= line_index
;
459 nstart_index
= current_line
->index
;
461 /* We must start to reformat from the previous line since the modifications
462 * may have caused the line to wrap upwards. */
463 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
466 current_line
= previous_line
;
468 start_line
= current_line
;
470 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
471 current_position
= es
->text
+ current_line
->index
;
472 vlc
= get_vertical_line_count(es
);
474 if (current_line
!= start_line
)
476 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
478 /* The buffer has been expanded, create a new line and
479 insert it into the link list */
480 LINEDEF
*new_line
= Alloc(sizeof(*new_line
));
481 new_line
->next
= previous_line
->next
;
482 previous_line
->next
= new_line
;
483 current_line
= new_line
;
486 else if (current_line
->index
+ delta
< current_position
- es
->text
)
488 /* The previous line merged with this line so we delete this extra entry */
489 previous_line
->next
= current_line
->next
;
491 current_line
= previous_line
->next
;
495 else /* current_line->index + delta == current_position */
497 if (current_position
- es
->text
> iend
)
498 break; /* We reached end of line modifications */
499 /* else recalculate this line */
503 current_line
->index
= current_position
- es
->text
;
504 orig_net_length
= current_line
->net_length
;
506 /* Find end of line */
507 cp
= current_position
;
509 if (*cp
== '\n') break;
510 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
515 /* Mark type of line termination */
517 current_line
->ending
= END_0
;
518 current_line
->net_length
= lstrlenW(current_position
);
519 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
520 current_line
->ending
= END_SOFT
;
521 current_line
->net_length
= cp
- current_position
- 1;
522 } else if (*cp
== '\n') {
523 current_line
->ending
= END_RICH
;
524 current_line
->net_length
= cp
- current_position
;
526 current_line
->ending
= END_HARD
;
527 current_line
->net_length
= cp
- current_position
;
530 if (current_line
->net_length
)
533 EDIT_InvalidateUniscribeData_linedef(current_line
);
534 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
535 if (current_line
->ssa
)
537 sz
= ScriptString_pSize(current_line
->ssa
);
538 /* Calculate line width */
539 current_line
->width
= sz
->cx
;
541 else current_line
->width
= es
->char_width
* current_line
->net_length
;
543 else current_line
->width
= 0;
545 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
547 /* Line breaks just look back from the end and find the next break and try that. */
549 if (!(es
->style
& ES_AUTOHSCROLL
)) {
550 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
557 prev
= current_line
->net_length
- 1;
558 w
= current_line
->net_length
;
559 d
= (float)current_line
->width
/(float)fw
;
560 if (d
> 1.2f
) d
-= 0.2f
;
562 if (next
>= prev
) next
= prev
-1;
564 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
565 next
, current_line
->net_length
, WB_LEFT
);
566 current_line
->net_length
= prev
;
567 EDIT_InvalidateUniscribeData_linedef(current_line
);
568 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
569 if (current_line
->ssa
)
570 sz
= ScriptString_pSize(current_line
->ssa
);
573 current_line
->width
= sz
->cx
;
577 } while (prev
&& current_line
->width
> fw
);
578 current_line
->net_length
= w
;
580 if (prev
== 0) { /* Didn't find a line break so force a break */
584 EDIT_InvalidateUniscribeData_linedef(current_line
);
585 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
587 if (current_line
->ssa
)
589 count
= ScriptString_pcOutChars(current_line
->ssa
);
590 piDx
= Alloc(sizeof(INT
) * (*count
));
591 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
593 prev
= current_line
->net_length
-1;
595 current_line
->width
-= piDx
[prev
];
597 } while ( prev
> 0 && current_line
->width
> fw
);
603 prev
= (fw
/ es
->char_width
);
606 /* If the first line we are calculating, wrapped before istart, we must
607 * adjust istart in order for this to be reflected in the update region. */
608 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
609 istart
= current_line
->index
+ prev
;
610 /* else if we are updating the previous line before the first line we
611 * are re-calculating and it expanded */
612 else if (current_line
== start_line
&&
613 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
615 /* Line expanded due to an upwards line wrap so we must partially include
616 * previous line in update region */
617 nstart_line
= line_index
;
618 nstart_index
= current_line
->index
;
619 istart
= current_line
->index
+ orig_net_length
;
622 current_line
->net_length
= prev
;
623 current_line
->ending
= END_WRAP
;
625 if (current_line
->net_length
> 0)
627 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
628 if (current_line
->ssa
)
630 sz
= ScriptString_pSize(current_line
->ssa
);
631 current_line
->width
= sz
->cx
;
634 current_line
->width
= 0;
636 else current_line
->width
= 0;
638 else if (current_line
== start_line
&&
639 current_line
->index
!= nstart_index
&&
640 orig_net_length
< current_line
->net_length
) {
641 /* The previous line expanded but it's still not as wide as the client rect */
642 /* The expansion is due to an upwards line wrap so we must partially include
643 it in the update region */
644 nstart_line
= line_index
;
645 nstart_index
= current_line
->index
;
646 istart
= current_line
->index
+ orig_net_length
;
651 /* Adjust length to include line termination */
652 switch (current_line
->ending
) {
654 current_line
->length
= current_line
->net_length
+ 3;
657 current_line
->length
= current_line
->net_length
+ 1;
660 current_line
->length
= current_line
->net_length
+ 2;
664 current_line
->length
= current_line
->net_length
;
667 es
->text_width
= max(es
->text_width
, current_line
->width
);
668 current_position
+= current_line
->length
;
669 previous_line
= current_line
;
671 /* Discard data for non-visible lines. It will be calculated as needed */
672 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
673 EDIT_InvalidateUniscribeData_linedef(current_line
);
675 current_line
= current_line
->next
;
677 } while (previous_line
->ending
!= END_0
);
679 /* Finish adjusting line indexes by delta or remove hanging lines */
680 if (previous_line
->ending
== END_0
)
682 LINEDEF
*pnext
= NULL
;
684 previous_line
->next
= NULL
;
687 pnext
= current_line
->next
;
688 EDIT_InvalidateUniscribeData_linedef(current_line
);
690 current_line
= pnext
;
698 current_line
->index
+= delta
;
699 current_line
= current_line
->next
;
703 /* Calculate rest of modification rectangle */
708 * We calculate two rectangles. One for the first line which may have
709 * an indent with respect to the format rect. The other is a format-width
710 * rectangle that spans the rest of the lines that changed or moved.
712 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
713 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
714 rc
.bottom
= rc
.top
+ es
->line_height
;
715 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
716 rc
.left
= es
->format_rect
.left
;
718 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
719 rc
.right
= es
->format_rect
.right
;
720 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
723 rc
.left
= es
->format_rect
.left
;
724 rc
.right
= es
->format_rect
.right
;
726 * If lines were added or removed we must re-paint the remainder of the
727 * lines since the remaining lines were either shifted up or down.
729 if (line_count
< es
->line_count
) /* We added lines */
730 rc
.bottom
= es
->line_count
* es
->line_height
;
731 else if (line_count
> es
->line_count
) /* We removed lines */
732 rc
.bottom
= line_count
* es
->line_height
;
734 rc
.bottom
= line_index
* es
->line_height
;
735 rc
.bottom
+= es
->format_rect
.top
;
736 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
737 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
738 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
739 DeleteObject(tmphrgn
);
743 /*********************************************************************
745 * EDIT_CalcLineWidth_SL
748 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
750 EDIT_UpdateUniscribeData(es
, NULL
, 0);
754 size
= ScriptString_pSize(es
->ssa
);
755 es
->text_width
= size
->cx
;
761 /*********************************************************************
765 * Beware: This is not the function called on EM_CHARFROMPOS
766 * The position _can_ be outside the formatting / client
768 * The return value is only the character index
771 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
775 if (es
->style
& ES_MULTILINE
) {
777 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
779 LINEDEF
*line_def
= es
->first_line_def
;
780 EDIT_UpdateUniscribeData(es
, NULL
, line
);
781 while ((line
> 0) && line_def
->next
) {
782 line_index
+= line_def
->length
;
783 line_def
= line_def
->next
;
787 x
+= es
->x_offset
- es
->format_rect
.left
;
788 if (es
->style
& ES_RIGHT
)
789 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
790 else if (es
->style
& ES_CENTER
)
791 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
792 if (x
>= line_def
->width
) {
794 *after_wrap
= (line_def
->ending
== END_WRAP
);
795 return line_index
+ line_def
->net_length
;
797 if (x
<= 0 || !line_def
->ssa
) {
803 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
804 if (trailing
) index
++;
807 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
808 (line_def
->ending
== END_WRAP
));
814 x
-= es
->format_rect
.left
;
820 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
821 if (es
->style
& ES_RIGHT
)
823 else if (es
->style
& ES_CENTER
)
827 EDIT_UpdateUniscribeData(es
, NULL
, 0);
832 if (es
->x_offset
>= get_text_length(es
))
835 size
= ScriptString_pSize(es
->ssa
);
838 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
845 if (x
+ xoff
> 0 || !es
->ssa
)
847 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
848 if (trailing
) index
++;
857 const SIZE
*size
= NULL
;
859 size
= ScriptString_pSize(es
->ssa
);
862 else if (x
> size
->cx
)
863 index
= get_text_length(es
);
866 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
867 if (trailing
) index
++;
873 index
= es
->x_offset
;
880 /*********************************************************************
884 * adjusts the point to be within the formatting rectangle
885 * (so CharFromPos returns the nearest _visible_ character)
888 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
890 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
891 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
895 /*********************************************************************
900 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
905 if (!(es
->style
& ES_MULTILINE
))
907 if (index
> (INT
)get_text_length(es
))
908 return es
->line_count
- 1;
910 index
= min(es
->selection_start
, es
->selection_end
);
913 line_def
= es
->first_line_def
;
914 index
-= line_def
->length
;
915 while ((index
>= 0) && line_def
->next
) {
917 line_def
= line_def
->next
;
918 index
-= line_def
->length
;
924 /*********************************************************************
929 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
932 const LINEDEF
*line_def
;
934 if (!(es
->style
& ES_MULTILINE
))
936 if (line
>= es
->line_count
)
940 line_def
= es
->first_line_def
;
942 INT index
= es
->selection_end
- line_def
->length
;
943 while ((index
>= 0) && line_def
->next
) {
944 line_index
+= line_def
->length
;
945 line_def
= line_def
->next
;
946 index
-= line_def
->length
;
950 line_index
+= line_def
->length
;
951 line_def
= line_def
->next
;
959 /*********************************************************************
964 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
968 if (!(es
->style
& ES_MULTILINE
))
969 return get_text_length(es
);
972 /* get the number of remaining non-selected chars of selected lines */
973 INT32 l
; /* line number */
974 INT32 li
; /* index of first char in line */
976 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
977 /* # chars before start of selection area */
978 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
979 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
980 /* # chars after end of selection */
981 li
= EDIT_EM_LineIndex(es
, l
);
982 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
985 line_def
= es
->first_line_def
;
986 index
-= line_def
->length
;
987 while ((index
>= 0) && line_def
->next
) {
988 line_def
= line_def
->next
;
989 index
-= line_def
->length
;
991 return line_def
->net_length
;
995 /*********************************************************************
1000 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1002 INT len
= get_text_length(es
);
1011 index
= min(index
, len
);
1012 if (es
->style
& ES_MULTILINE
) {
1013 l
= EDIT_EM_LineFromChar(es
, index
);
1014 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1016 y
= (l
- es
->y_offset
) * es
->line_height
;
1017 li
= EDIT_EM_LineIndex(es
, l
);
1018 if (after_wrap
&& (li
== index
) && l
) {
1020 line_def
= es
->first_line_def
;
1022 line_def
= line_def
->next
;
1025 if (line_def
->ending
== END_WRAP
) {
1027 y
-= es
->line_height
;
1028 li
= EDIT_EM_LineIndex(es
, l
);
1032 line_def
= es
->first_line_def
;
1033 while (line_def
->index
!= li
)
1034 line_def
= line_def
->next
;
1036 lw
= line_def
->width
;
1037 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1039 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1042 if (es
->style
& ES_RIGHT
)
1044 else if (es
->style
& ES_CENTER
)
1049 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1054 if (es
->x_offset
>= get_text_length(es
))
1056 int leftover
= es
->x_offset
- get_text_length(es
);
1060 size
= ScriptString_pSize(es
->ssa
);
1065 xoff
+= es
->char_width
* leftover
;
1068 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1075 if (index
>= get_text_length(es
))
1080 size
= ScriptString_pSize(es
->ssa
);
1087 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1093 if (index
>= es
->x_offset
) {
1094 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1096 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1097 if (w
> es
->text_width
)
1099 if (es
->style
& ES_RIGHT
)
1100 x
+= w
- es
->text_width
;
1101 else if (es
->style
& ES_CENTER
)
1102 x
+= (w
- es
->text_width
) / 2;
1108 x
+= es
->format_rect
.left
;
1109 y
+= es
->format_rect
.top
;
1110 return MAKELONG((INT16
)x
, (INT16
)y
);
1114 /*********************************************************************
1118 * Calculates the bounding rectangle for a line from a starting
1119 * column to an ending column.
1122 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1124 SCRIPT_STRING_ANALYSIS ssa
;
1128 if (es
->style
& ES_MULTILINE
)
1130 const LINEDEF
*line_def
= NULL
;
1131 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1132 if (line
>= es
->line_count
)
1135 line_def
= es
->first_line_def
;
1137 INT index
= es
->selection_end
- line_def
->length
;
1138 while ((index
>= 0) && line_def
->next
) {
1139 line_index
+= line_def
->length
;
1140 line_def
= line_def
->next
;
1141 index
-= line_def
->length
;
1145 line_index
+= line_def
->length
;
1146 line_def
= line_def
->next
;
1150 ssa
= line_def
->ssa
;
1155 rc
->top
= es
->format_rect
.top
;
1159 rc
->bottom
= rc
->top
+ es
->line_height
;
1160 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1161 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1164 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1165 pt3
+=es
->format_rect
.left
;
1168 rc
->right
= max(max(pt1
, pt2
),pt3
);
1169 rc
->left
= min(min(pt1
, pt2
),pt3
);
1173 static inline void text_buffer_changed(EDITSTATE
*es
)
1175 es
->text_length
= (UINT
)-1;
1179 EDIT_InvalidateUniscribeData(es
);
1182 /*********************************************************************
1186 static void EDIT_LockBuffer(EDITSTATE
*es
)
1193 es
->text
= LocalLock(es
->hloc32W
);
1200 /*********************************************************************
1205 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1207 /* Edit window might be already destroyed */
1208 if (!IsWindow(es
->hwndSelf
))
1210 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1214 if (!es
->lock_count
)
1216 ERR("lock_count == 0 ... please report\n");
1222 ERR("es->text == 0 ... please report\n");
1226 if (force
|| (es
->lock_count
== 1))
1230 LocalUnlock(es
->hloc32W
);
1235 ERR("no buffer ... please report\n");
1245 /*********************************************************************
1249 * Try to fit size + 1 characters in the buffer.
1251 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1255 if (size
<= es
->buffer_size
)
1258 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1260 /* Force edit to unlock its buffer. es->text now NULL */
1261 EDIT_UnlockBuffer(es
, TRUE
);
1264 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1265 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1266 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1267 es
->hloc32W
= hNew32W
;
1268 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1272 EDIT_LockBuffer(es
);
1274 if (es
->buffer_size
< size
) {
1275 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1276 notify_parent(es
, EN_ERRSPACE
);
1279 TRACE("We now have %d+1\n", es
->buffer_size
);
1285 /*********************************************************************
1289 * Try to fit size + 1 bytes in the undo buffer.
1292 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1295 WCHAR
*new_undo_text
;
1297 if (size
<= es
->undo_buffer_size
)
1300 TRACE("trying to ReAlloc to %d+1\n", size
);
1302 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1303 if ((new_undo_text
= ReAlloc(es
->undo_text
, alloc_size
))) {
1304 memset(new_undo_text
+ es
->undo_buffer_size
, 0, alloc_size
- es
->undo_buffer_size
* sizeof(WCHAR
));
1305 es
->undo_text
= new_undo_text
;
1306 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1311 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1317 /*********************************************************************
1319 * EDIT_UpdateTextRegion
1322 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1324 if (es
->flags
& EF_UPDATE
) {
1325 es
->flags
&= ~EF_UPDATE
;
1326 if (!notify_parent(es
, EN_UPDATE
)) return;
1328 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1332 /*********************************************************************
1337 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1339 if (es
->flags
& EF_UPDATE
) {
1340 es
->flags
&= ~EF_UPDATE
;
1341 if (!notify_parent(es
, EN_UPDATE
)) return;
1343 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1346 /*********************************************************************
1348 * EDIT_SL_InvalidateText
1350 * Called from EDIT_InvalidateText().
1351 * Does the job for single-line controls only.
1354 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1359 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1360 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1361 EDIT_UpdateText(es
, &rc
, TRUE
);
1364 /*********************************************************************
1366 * EDIT_ML_InvalidateText
1368 * Called from EDIT_InvalidateText().
1369 * Does the job for multi-line controls only.
1372 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1374 INT vlc
= get_vertical_line_count(es
);
1375 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1376 INT el
= EDIT_EM_LineFromChar(es
, end
);
1385 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1388 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1389 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1390 if (sl
< es
->y_offset
) {
1394 if (el
> es
->y_offset
+ vlc
) {
1395 el
= es
->y_offset
+ vlc
;
1396 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1398 GetClientRect(es
->hwndSelf
, &rc1
);
1399 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1401 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1402 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1403 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1405 EDIT_GetLineRect(es
, sl
, sc
,
1406 EDIT_EM_LineLength(es
,
1407 EDIT_EM_LineIndex(es
, sl
)),
1409 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1410 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1411 for (l
= sl
+ 1 ; l
< el
; l
++) {
1412 EDIT_GetLineRect(es
, l
, 0,
1413 EDIT_EM_LineLength(es
,
1414 EDIT_EM_LineIndex(es
, l
)),
1416 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1417 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1419 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1420 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1421 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1426 /*********************************************************************
1428 * EDIT_InvalidateText
1430 * Invalidate the text from offset start up to, but not including,
1431 * offset end. Useful for (re)painting the selection.
1432 * Regions outside the linewidth are not invalidated.
1433 * end == -1 means end == TextLength.
1434 * start and end need not be ordered.
1437 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1443 end
= get_text_length(es
);
1451 if (es
->style
& ES_MULTILINE
)
1452 EDIT_ML_InvalidateText(es
, start
, end
);
1454 EDIT_SL_InvalidateText(es
, start
, end
);
1458 /*********************************************************************
1462 * note: unlike the specs say: the order of start and end
1463 * _is_ preserved in Windows. (i.e. start can be > end)
1464 * In other words: this handler is OK
1467 static BOOL
EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1469 UINT old_start
= es
->selection_start
;
1470 UINT old_end
= es
->selection_end
;
1471 UINT len
= get_text_length(es
);
1473 if (start
== old_start
&& end
== old_end
)
1476 if (start
== (UINT
)-1) {
1477 start
= es
->selection_end
;
1478 end
= es
->selection_end
;
1480 start
= min(start
, len
);
1481 end
= min(end
, len
);
1483 es
->selection_start
= start
;
1484 es
->selection_end
= end
;
1486 es
->flags
|= EF_AFTER_WRAP
;
1488 es
->flags
&= ~EF_AFTER_WRAP
;
1489 /* Compute the necessary invalidation region. */
1490 /* Note that we don't need to invalidate regions which have
1491 * "never" been selected, or those which are "still" selected.
1492 * In fact, every time we hit a selection boundary, we can
1493 * *toggle* whether we need to invalidate. Thus we can optimize by
1494 * *sorting* the interval endpoints. Let's assume that we sort them
1496 * start <= end <= old_start <= old_end
1497 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1498 * in 5 comparisons; i.e. it is impossible to do better than the
1500 ORDER_UINT(end
, old_end
);
1501 ORDER_UINT(start
, old_start
);
1502 ORDER_UINT(old_start
, old_end
);
1503 ORDER_UINT(start
, end
);
1504 /* Note that at this point 'end' and 'old_start' are not in order, but
1505 * start is definitely the min. and old_end is definitely the max. */
1506 if (end
!= old_start
)
1510 * ORDER_UINT32(end, old_start);
1511 * EDIT_InvalidateText(es, start, end);
1512 * EDIT_InvalidateText(es, old_start, old_end);
1513 * in place of the following if statement.
1514 * (That would complete the optimal five-comparison four-element sort.)
1516 if (old_start
> end
)
1518 EDIT_InvalidateText(es
, start
, end
);
1519 EDIT_InvalidateText(es
, old_start
, old_end
);
1523 EDIT_InvalidateText(es
, start
, old_start
);
1524 EDIT_InvalidateText(es
, end
, old_end
);
1527 else EDIT_InvalidateText(es
, start
, old_end
);
1533 /*********************************************************************
1535 * EDIT_UpdateScrollInfo
1538 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1540 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1543 si
.cbSize
= sizeof(SCROLLINFO
);
1544 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1546 si
.nMax
= es
->line_count
- 1;
1547 si
.nPage
= es
->line_height
? (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
: 0;
1548 si
.nPos
= es
->y_offset
;
1549 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1550 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1551 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1554 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1557 si
.cbSize
= sizeof(SCROLLINFO
);
1558 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1560 si
.nMax
= es
->text_width
- 1;
1561 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1562 si
.nPos
= es
->x_offset
;
1563 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1564 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1565 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1570 /*********************************************************************
1572 * EDIT_EM_LineScroll_internal
1574 * Version of EDIT_EM_LineScroll for internal use.
1575 * It doesn't refuse if ES_MULTILINE is set and assumes that
1576 * dx is in pixels, dy - in lines.
1579 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1582 INT x_offset_in_pixels
;
1585 if (!es
->line_height
|| !es
->char_width
)
1588 lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1590 if (es
->style
& ES_MULTILINE
)
1592 x_offset_in_pixels
= es
->x_offset
;
1597 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1600 if (-dx
> x_offset_in_pixels
)
1601 dx
= -x_offset_in_pixels
;
1602 if (dx
> es
->text_width
- x_offset_in_pixels
)
1603 dx
= es
->text_width
- x_offset_in_pixels
;
1604 nyoff
= max(0, es
->y_offset
+ dy
);
1605 if (nyoff
>= es
->line_count
- lines_per_page
)
1606 nyoff
= max(0, es
->line_count
- lines_per_page
);
1607 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1612 es
->y_offset
= nyoff
;
1613 if(es
->style
& ES_MULTILINE
)
1616 es
->x_offset
+= dx
/ es
->char_width
;
1618 GetClientRect(es
->hwndSelf
, &rc1
);
1619 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1620 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1621 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1622 /* force scroll info update */
1623 EDIT_UpdateScrollInfo(es
);
1625 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1626 notify_parent(es
, EN_HSCROLL
);
1627 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1628 notify_parent(es
, EN_VSCROLL
);
1632 /*********************************************************************
1636 * NOTE: dx is in average character widths, dy - in lines;
1639 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1641 if (!(es
->style
& ES_MULTILINE
))
1644 dx
*= es
->char_width
;
1645 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1649 /*********************************************************************
1654 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1658 if (!(es
->style
& ES_MULTILINE
))
1659 return (LRESULT
)FALSE
;
1669 if (es
->y_offset
< es
->line_count
- 1)
1674 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1677 if (es
->y_offset
< es
->line_count
- 1)
1678 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1681 return (LRESULT
)FALSE
;
1684 INT vlc
= get_vertical_line_count(es
);
1685 /* check if we are going to move too far */
1686 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1687 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1689 /* Notification is done in EDIT_EM_LineScroll */
1691 EDIT_EM_LineScroll(es
, 0, dy
);
1692 return MAKELONG(dy
, TRUE
);
1696 return (LRESULT
)FALSE
;
1700 static void EDIT_UpdateImmCompositionWindow(EDITSTATE
*es
, UINT x
, UINT y
)
1702 COMPOSITIONFORM form
=
1704 .dwStyle
= CFS_RECT
,
1705 .ptCurrentPos
= {.x
= x
, .y
= y
},
1706 .rcArea
= es
->format_rect
,
1708 HIMC himc
= ImmGetContext(es
->hwndSelf
);
1709 ImmSetCompositionWindow(himc
, &form
);
1710 ImmReleaseContext(es
->hwndSelf
, himc
);
1714 /*********************************************************************
1719 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1724 if (es
->flags
& EF_FOCUSED
)
1726 res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1727 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1728 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1729 EDIT_UpdateImmCompositionWindow(es
, (short)LOWORD(res
), (short)HIWORD(res
));
1734 /*********************************************************************
1739 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1741 if (es
->style
& ES_MULTILINE
) {
1745 INT cw
= es
->char_width
;
1750 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1751 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1752 vlc
= get_vertical_line_count(es
);
1753 if (l
>= es
->y_offset
+ vlc
)
1754 dy
= l
- vlc
+ 1 - es
->y_offset
;
1755 if (l
< es
->y_offset
)
1756 dy
= l
- es
->y_offset
;
1757 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1758 if (x
< es
->format_rect
.left
)
1759 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1760 if (x
> es
->format_rect
.right
)
1761 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1762 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1764 /* check if we are going to move too far */
1765 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1766 dx
= es
->text_width
- ww
- es
->x_offset
;
1767 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1768 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1775 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1776 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1777 if (x
< es
->format_rect
.left
) {
1778 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1781 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1782 } while ((x
< goal
) && es
->x_offset
);
1783 /* FIXME: use ScrollWindow() somehow to improve performance */
1784 EDIT_UpdateText(es
, NULL
, TRUE
);
1785 } else if (x
> es
->format_rect
.right
) {
1787 INT len
= get_text_length(es
);
1788 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1791 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1792 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1793 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1794 /* FIXME: use ScrollWindow() somehow to improve performance */
1795 EDIT_UpdateText(es
, NULL
, TRUE
);
1799 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1803 /*********************************************************************
1808 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1810 INT e
= es
->selection_end
;
1814 if ((es
->style
& ES_MULTILINE
) && e
&&
1815 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1817 if (e
&& (es
->text
[e
- 1] == '\r'))
1821 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1822 EDIT_EM_ScrollCaret(es
);
1826 /*********************************************************************
1830 * Only for multi line controls
1831 * Move the caret one line down, on a column with the nearest
1832 * x coordinate on the screen (might be a different column).
1835 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1837 INT s
= es
->selection_start
;
1838 INT e
= es
->selection_end
;
1839 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1840 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1841 INT x
= (short)LOWORD(pos
);
1842 INT y
= (short)HIWORD(pos
);
1844 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1847 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1848 EDIT_EM_ScrollCaret(es
);
1852 /*********************************************************************
1857 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1859 BOOL after_wrap
= FALSE
;
1862 /* Pass a high value in x to make sure of receiving the end of the line */
1863 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1864 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1865 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1867 e
= get_text_length(es
);
1868 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1869 EDIT_EM_ScrollCaret(es
);
1873 /*********************************************************************
1878 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1880 INT e
= es
->selection_end
;
1884 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1885 if (es
->text
[e
] == '\n')
1887 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1891 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1892 EDIT_EM_ScrollCaret(es
);
1896 /*********************************************************************
1900 * Home key: move to beginning of line.
1903 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1907 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1908 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1909 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1910 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1913 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1914 EDIT_EM_ScrollCaret(es
);
1918 /*********************************************************************
1920 * EDIT_MovePageDown_ML
1922 * Only for multi line controls
1923 * Move the caret one page down, on a column with the nearest
1924 * x coordinate on the screen (might be a different column).
1927 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1929 INT s
= es
->selection_start
;
1930 INT e
= es
->selection_end
;
1931 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1932 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1933 INT x
= (short)LOWORD(pos
);
1934 INT y
= (short)HIWORD(pos
);
1936 e
= EDIT_CharFromPos(es
, x
,
1937 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1941 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1942 EDIT_EM_ScrollCaret(es
);
1946 /*********************************************************************
1948 * EDIT_MovePageUp_ML
1950 * Only for multi line controls
1951 * Move the caret one page up, on a column with the nearest
1952 * x coordinate on the screen (might be a different column).
1955 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1957 INT s
= es
->selection_start
;
1958 INT e
= es
->selection_end
;
1959 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1960 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1961 INT x
= (short)LOWORD(pos
);
1962 INT y
= (short)HIWORD(pos
);
1964 e
= EDIT_CharFromPos(es
, x
,
1965 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1969 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1970 EDIT_EM_ScrollCaret(es
);
1974 /*********************************************************************
1978 * Only for multi line controls
1979 * Move the caret one line up, on a column with the nearest
1980 * x coordinate on the screen (might be a different column).
1983 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1985 INT s
= es
->selection_start
;
1986 INT e
= es
->selection_end
;
1987 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1988 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1989 INT x
= (short)LOWORD(pos
);
1990 INT y
= (short)HIWORD(pos
);
1992 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1995 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1996 EDIT_EM_ScrollCaret(es
);
2000 /*********************************************************************
2002 * EDIT_MoveWordBackward
2005 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2007 INT s
= es
->selection_start
;
2008 INT e
= es
->selection_end
;
2013 l
= EDIT_EM_LineFromChar(es
, e
);
2014 ll
= EDIT_EM_LineLength(es
, e
);
2015 li
= EDIT_EM_LineIndex(es
, l
);
2018 li
= EDIT_EM_LineIndex(es
, l
- 1);
2019 e
= li
+ EDIT_EM_LineLength(es
, li
);
2022 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2026 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2027 EDIT_EM_ScrollCaret(es
);
2031 /*********************************************************************
2033 * EDIT_MoveWordForward
2036 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2038 INT s
= es
->selection_start
;
2039 INT e
= es
->selection_end
;
2044 l
= EDIT_EM_LineFromChar(es
, e
);
2045 ll
= EDIT_EM_LineLength(es
, e
);
2046 li
= EDIT_EM_LineIndex(es
, l
);
2048 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2049 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2051 e
= li
+ EDIT_CallWordBreakProc(es
,
2052 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2056 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2057 EDIT_EM_ScrollCaret(es
);
2061 /*********************************************************************
2066 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2077 BkMode
= GetBkMode(dc
);
2078 BkColor
= GetBkColor(dc
);
2079 TextColor
= GetTextColor(dc
);
2081 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2082 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2083 SetBkMode(dc
, OPAQUE
);
2085 li
= EDIT_EM_LineIndex(es
, line
);
2086 if (es
->style
& ES_MULTILINE
) {
2087 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2088 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2090 TextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
);
2091 GetTextExtentPoint32W(dc
, es
->text
+ li
+ col
, count
, &size
);
2095 SetBkColor(dc
, BkColor
);
2096 SetTextColor(dc
, TextColor
);
2097 SetBkMode(dc
, BkMode
);
2103 /*********************************************************************
2108 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2117 SCRIPT_STRING_ANALYSIS ssa
;
2119 if (es
->style
& ES_MULTILINE
) {
2120 INT vlc
= get_vertical_line_count(es
);
2122 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2127 TRACE("line=%d\n", line
);
2129 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2130 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2131 x
= (short)LOWORD(pos
);
2132 y
= (short)HIWORD(pos
);
2134 if (es
->style
& ES_MULTILINE
)
2136 int line_idx
= line
;
2138 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2140 LINEDEF
*line_def
= es
->first_line_def
;
2143 while (line_def
&& line_idx
)
2145 line_def
= line_def
->next
;
2148 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2149 lw
= line_def
->width
;
2151 if (es
->style
& ES_RIGHT
)
2153 else if (es
->style
& ES_CENTER
)
2156 x
+= es
->format_rect
.left
;
2161 li
= EDIT_EM_LineIndex(es
, line
);
2162 ll
= EDIT_EM_LineLength(es
, li
);
2163 s
= min(es
->selection_start
, es
->selection_end
);
2164 e
= max(es
->selection_start
, es
->selection_end
);
2165 s
= min(li
+ ll
, max(li
, s
));
2166 e
= min(li
+ ll
, max(li
, e
));
2170 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2171 else if (rev
&& (s
!= e
) &&
2172 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2173 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2174 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2175 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2177 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2179 if (es
->cue_banner_text
&& es
->text_length
== 0 && (!(es
->flags
& EF_FOCUSED
) || es
->cue_banner_draw_focused
))
2181 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
2182 TextOutW(dc
, x
, y
, es
->cue_banner_text
, lstrlenW(es
->cue_banner_text
));
2187 /*********************************************************************
2189 * EDIT_AdjustFormatRect
2191 * Adjusts the format rectangle for the current font and the
2192 * current client rectangle.
2195 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2199 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2200 if (es
->style
& ES_MULTILINE
)
2202 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2204 vlc
= get_vertical_line_count(es
);
2205 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2207 /* correct es->x_offset */
2208 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2209 max_x_offset
= es
->text_width
- fw
;
2210 if(max_x_offset
< 0) max_x_offset
= 0;
2211 if(es
->x_offset
> max_x_offset
)
2212 es
->x_offset
= max_x_offset
;
2214 /* correct es->y_offset */
2215 max_y_offset
= es
->line_count
- vlc
;
2216 if(max_y_offset
< 0) max_y_offset
= 0;
2217 if(es
->y_offset
> max_y_offset
)
2218 es
->y_offset
= max_y_offset
;
2220 /* force scroll info update */
2221 EDIT_UpdateScrollInfo(es
);
2224 /* Windows doesn't care to fix text placement for SL controls */
2225 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2227 /* Always stay within the client area */
2228 GetClientRect(es
->hwndSelf
, &ClientRect
);
2229 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2231 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2232 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2234 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2238 /*********************************************************************
2242 * note: this is not (exactly) the handler called on EM_SETRECTNP
2243 * it is also used to set the rect of a single line control
2246 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2250 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2252 CopyRect(&es
->format_rect
, rc
);
2254 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2255 es
->format_rect
.left
++;
2256 es
->format_rect
.right
--;
2258 if (es
->format_rect
.bottom
- es
->format_rect
.top
2259 >= es
->line_height
+ 2)
2261 es
->format_rect
.top
++;
2262 es
->format_rect
.bottom
--;
2265 else if (es
->style
& WS_BORDER
) {
2266 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2267 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2268 InflateRect(&es
->format_rect
, -bw
, 0);
2269 if (es
->format_rect
.bottom
- es
->format_rect
.top
>= es
->line_height
+ 2 * bh
)
2270 InflateRect(&es
->format_rect
, 0, -bh
);
2273 es
->format_rect
.left
+= es
->left_margin
;
2274 es
->format_rect
.right
-= es
->right_margin
;
2275 EDIT_AdjustFormatRect(es
);
2279 /*********************************************************************
2283 * returns line number (not index) in high-order word of result.
2284 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2285 * to Richedit, not to the edit control. Original documentation is valid.
2286 * FIXME: do the specs mean to return -1 if outside client area or
2287 * if outside formatting rectangle ???
2290 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2298 GetClientRect(es
->hwndSelf
, &rc
);
2299 if (!PtInRect(&rc
, pt
))
2302 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2303 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2307 /*********************************************************************
2311 * Enable or disable soft breaks.
2313 * This means: insert or remove the soft linebreak character (\r\r\n).
2314 * Take care to check if the text still fits the buffer after insertion.
2315 * If not, notify with EN_ERRSPACE.
2318 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2320 es
->flags
&= ~EF_USE_SOFTBRK
;
2322 es
->flags
|= EF_USE_SOFTBRK
;
2323 FIXME("soft break enabled, not implemented\n");
2329 /*********************************************************************
2333 * Hopefully this won't fire back at us.
2334 * We always start with a fixed buffer in the local heap.
2335 * Despite of the documentation says that the local heap is used
2336 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2337 * buffer on the local heap.
2340 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2342 if (!(es
->style
& ES_MULTILINE
))
2345 EDIT_UnlockBuffer(es
, TRUE
);
2347 /* The text buffer handle belongs to the app */
2348 es
->hlocapp
= es
->hloc32W
;
2350 TRACE("Returning %p, LocalSize() = %Id\n", es
->hlocapp
, LocalSize(es
->hlocapp
));
2355 /*********************************************************************
2360 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
)
2362 INT line_len
, dst_len
;
2366 if (es
->style
& ES_MULTILINE
)
2368 if (line
>= es
->line_count
)
2374 i
= EDIT_EM_LineIndex(es
, line
);
2376 line_len
= EDIT_EM_LineLength(es
, i
);
2377 dst_len
= *(WORD
*)dst
;
2379 if (dst_len
<= line_len
)
2381 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2384 else /* Append 0 if enough space */
2386 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2393 /*********************************************************************
2398 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2400 UINT s
= es
->selection_start
;
2401 UINT e
= es
->selection_end
;
2408 return MAKELONG(s
, e
);
2412 /*********************************************************************
2416 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2419 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, const WCHAR
*lpsz_replace
, UINT strl
,
2420 BOOL send_update
, BOOL honor_limit
)
2422 UINT tl
= get_text_length(es
);
2433 TRACE("%s, can_undo %d, send_update %d\n",
2434 debugstr_wn(lpsz_replace
, strl
), can_undo
, send_update
);
2436 s
= es
->selection_start
;
2437 e
= es
->selection_end
;
2439 EDIT_InvalidateUniscribeData(es
);
2440 if ((s
== e
) && !strl
)
2445 size
= tl
- (e
- s
) + strl
;
2449 /* Issue the EN_MAXTEXT notification and continue with replacing text
2450 * so that buffer limit is honored. */
2451 if ((honor_limit
) && (size
> es
->buffer_limit
))
2453 if (!notify_parent(es
, EN_MAXTEXT
)) return;
2454 /* Buffer limit can be smaller than the actual length of text in combobox */
2455 if (es
->buffer_limit
< (tl
- (e
-s
)))
2458 strl
= min(strl
, es
->buffer_limit
- (tl
- (e
-s
)));
2461 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2465 /* there is something to be deleted */
2466 TRACE("deleting stuff.\n");
2468 buf
= Alloc((bufl
+ 1) * sizeof(WCHAR
));
2470 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2471 buf
[bufl
] = 0; /* ensure 0 termination */
2473 lstrcpyW(es
->text
+ s
, es
->text
+ e
);
2474 text_buffer_changed(es
);
2477 /* there is an insertion */
2478 tl
= get_text_length(es
);
2479 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
));
2480 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2482 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2483 p
[i
] = lpsz_replace
[i
];
2484 if(es
->style
& ES_UPPERCASE
)
2485 CharUpperBuffW(p
, strl
);
2486 else if(es
->style
& ES_LOWERCASE
)
2487 CharLowerBuffW(p
, strl
);
2488 text_buffer_changed(es
);
2490 if (es
->style
& ES_MULTILINE
)
2492 INT st
= min(es
->selection_start
, es
->selection_end
);
2493 INT vlc
= get_vertical_line_count(es
);
2495 hrgn
= CreateRectRgn(0, 0, 0, 0);
2496 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2497 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2498 /* if text is too long undo all changes */
2499 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2501 lstrcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2503 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2505 text_buffer_changed(es
);
2506 EDIT_BuildLineDefs_ML(es
, s
, e
,
2507 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2510 SetRectRgn(hrgn
, 0, 0, 0, 0);
2511 if (!notify_parent(es
, EN_MAXTEXT
)) return;
2515 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2516 EDIT_InvalidateUniscribeData(es
);
2517 EDIT_CalcLineWidth_SL(es
);
2518 /* remove chars that don't fit */
2519 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2520 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2521 lstrcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2523 es
->text_length
= -1;
2524 EDIT_InvalidateUniscribeData(es
);
2525 EDIT_CalcLineWidth_SL(es
);
2527 text_buffer_changed(es
);
2528 if (!notify_parent(es
, EN_MAXTEXT
)) return;
2534 utl
= lstrlenW(es
->undo_text
);
2535 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2536 /* undo-buffer is extended to the right */
2537 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2538 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2539 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2540 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2541 /* undo-buffer is extended to the left */
2542 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2543 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2545 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2547 es
->undo_position
= s
;
2549 /* new undo-buffer */
2550 EDIT_MakeUndoFit(es
, e
- s
);
2551 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2552 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2553 es
->undo_position
= s
;
2555 /* any deletion makes the old insertion-undo invalid */
2556 es
->undo_insert_count
= 0;
2558 EDIT_EM_EmptyUndoBuffer(es
);
2562 if ((s
== es
->undo_position
) ||
2563 ((es
->undo_insert_count
) &&
2564 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2566 * insertion is new and at delete position or
2567 * an extension to either left or right
2569 es
->undo_insert_count
+= strl
;
2571 /* new insertion undo */
2572 es
->undo_position
= s
;
2573 es
->undo_insert_count
= strl
;
2574 /* new insertion makes old delete-buffer invalid */
2575 *es
->undo_text
= '\0';
2578 EDIT_EM_EmptyUndoBuffer(es
);
2585 /* If text has been deleted and we're right or center aligned then scroll rightward */
2586 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2588 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2590 if (delta
< 0 && es
->x_offset
)
2592 if (abs(delta
) > es
->x_offset
)
2595 es
->x_offset
+= delta
;
2599 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2600 es
->flags
|= EF_MODIFIED
;
2601 if (send_update
) es
->flags
|= EF_UPDATE
;
2604 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2608 EDIT_UpdateText(es
, NULL
, TRUE
);
2610 EDIT_EM_ScrollCaret(es
);
2612 /* force scroll info update */
2613 EDIT_UpdateScrollInfo(es
);
2616 if(send_update
|| (es
->flags
& EF_UPDATE
))
2618 es
->flags
&= ~EF_UPDATE
;
2619 if (!notify_parent(es
, EN_CHANGE
)) return;
2621 EDIT_InvalidateUniscribeData(es
);
2625 /*********************************************************************
2629 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2632 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2634 if (!(es
->style
& ES_MULTILINE
))
2640 EDIT_UnlockBuffer(es
, TRUE
);
2643 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2645 /* The text buffer handle belongs to the control */
2648 EDIT_LockBuffer(es
);
2649 text_buffer_changed(es
);
2651 es
->x_offset
= es
->y_offset
= 0;
2652 es
->selection_start
= es
->selection_end
= 0;
2653 EDIT_EM_EmptyUndoBuffer(es
);
2654 es
->flags
&= ~EF_MODIFIED
;
2655 es
->flags
&= ~EF_UPDATE
;
2656 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2657 EDIT_UpdateText(es
, NULL
, TRUE
);
2658 EDIT_EM_ScrollCaret(es
);
2659 /* force scroll info update */
2660 EDIT_UpdateScrollInfo(es
);
2664 /*********************************************************************
2668 * NOTE: this version currently implements WinNT limits
2671 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2673 if (!limit
) limit
= ~0u;
2674 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2675 es
->buffer_limit
= limit
;
2678 static BOOL
is_cjk(HDC dc
)
2680 const DWORD FS_DBCS_MASK
= FS_JISJAPAN
|FS_CHINESESIMP
|FS_WANSUNG
|FS_CHINESETRAD
|FS_JOHAB
;
2683 switch (GdiGetCodePage(dc
)) {
2684 case 932: case 936: case 949: case 950: case 1361:
2687 return (GetTextCharsetInfo(dc
, &fs
, 0) != DEFAULT_CHARSET
&&
2688 (fs
.fsCsb
[0] & FS_DBCS_MASK
));
2692 static int get_cjk_fontinfo_margin(int width
, int side_bearing
)
2695 if (side_bearing
< 0)
2696 margin
= min(-side_bearing
, width
/2);
2702 struct char_width_info
{
2703 INT min_lsb
, min_rsb
, unknown
;
2706 /* Undocumented gdi32 export */
2707 extern BOOL WINAPI
GetCharWidthInfo(HDC
, struct char_width_info
*);
2709 /*********************************************************************
2713 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2714 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2715 * margin according to the textmetrics of the current font.
2717 * When EC_USEFONTINFO is used, the margins only change if the edit control is
2718 * equal to or larger than a certain size. The empty client rect is treated as
2721 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2722 WORD left
, WORD right
, BOOL repaint
)
2725 INT default_left_margin
= 0; /* in pixels */
2726 INT default_right_margin
= 0; /* in pixels */
2728 /* Set the default margins depending on the font */
2729 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2730 HDC dc
= GetDC(es
->hwndSelf
);
2731 HFONT old_font
= SelectObject(dc
, es
->font
);
2732 LONG width
= GdiGetCharDimensions(dc
, &tm
, NULL
), rc_width
;
2735 /* The default margins are only non zero for TrueType or Vector fonts */
2736 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2737 struct char_width_info width_info
;
2739 if (is_cjk(dc
) && GetCharWidthInfo(dc
, &width_info
))
2741 default_left_margin
= get_cjk_fontinfo_margin(width
, width_info
.min_lsb
);
2742 default_right_margin
= get_cjk_fontinfo_margin(width
, width_info
.min_rsb
);
2746 default_left_margin
= width
/ 2;
2747 default_right_margin
= width
/ 2;
2750 GetClientRect(es
->hwndSelf
, &rc
);
2751 rc_width
= !IsRectEmpty(&rc
) ? rc
.right
- rc
.left
: 80;
2752 if (rc_width
< default_left_margin
+ default_right_margin
+ width
* 2) {
2753 default_left_margin
= es
->left_margin
;
2754 default_right_margin
= es
->right_margin
;
2757 SelectObject(dc
, old_font
);
2758 ReleaseDC(es
->hwndSelf
, dc
);
2761 if (action
& EC_LEFTMARGIN
) {
2762 es
->format_rect
.left
-= es
->left_margin
;
2763 if (left
!= EC_USEFONTINFO
)
2764 es
->left_margin
= left
;
2766 es
->left_margin
= default_left_margin
;
2767 es
->format_rect
.left
+= es
->left_margin
;
2770 if (action
& EC_RIGHTMARGIN
) {
2771 es
->format_rect
.right
+= es
->right_margin
;
2772 if (right
!= EC_USEFONTINFO
)
2773 es
->right_margin
= right
;
2775 es
->right_margin
= default_right_margin
;
2776 es
->format_rect
.right
-= es
->right_margin
;
2779 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2780 EDIT_AdjustFormatRect(es
);
2781 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2784 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2788 /*********************************************************************
2790 * EM_SETPASSWORDCHAR
2793 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2797 if (es
->style
& ES_MULTILINE
)
2800 if (es
->password_char
== c
)
2803 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2804 es
->password_char
= c
;
2806 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2807 es
->style
|= ES_PASSWORD
;
2809 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2810 es
->style
&= ~ES_PASSWORD
;
2812 EDIT_InvalidateUniscribeData(es
);
2813 EDIT_UpdateText(es
, NULL
, TRUE
);
2817 /*********************************************************************
2822 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2824 if (!(es
->style
& ES_MULTILINE
))
2827 es
->tabs_count
= count
;
2831 es
->tabs
= Alloc(count
* sizeof(INT
));
2832 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2834 EDIT_InvalidateUniscribeData(es
);
2839 /*********************************************************************
2841 * EM_SETWORDBREAKPROC
2844 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, EDITWORDBREAKPROCW wbp
)
2846 if (es
->word_break_proc
== wbp
)
2849 es
->word_break_proc
= wbp
;
2851 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2852 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2853 EDIT_UpdateText(es
, NULL
, TRUE
);
2858 /*********************************************************************
2863 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
2868 /* As per MSDN spec, for a single-line edit control,
2869 the return value is always TRUE */
2870 if( es
->style
& ES_READONLY
)
2871 return !(es
->style
& ES_MULTILINE
);
2873 ulength
= lstrlenW(es
->undo_text
);
2875 utext
= Alloc((ulength
+ 1) * sizeof(WCHAR
));
2877 lstrcpyW(utext
, es
->undo_text
);
2879 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2880 es
->undo_insert_count
, debugstr_w(utext
));
2882 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2883 EDIT_EM_EmptyUndoBuffer(es
);
2884 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, ulength
, TRUE
, TRUE
);
2885 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2886 /* send the notification after the selection start and end are set */
2887 if (!notify_parent(es
, EN_CHANGE
)) return TRUE
;
2888 EDIT_EM_ScrollCaret(es
);
2891 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2892 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
2897 /* Helper function for WM_CHAR
2899 * According to an MSDN blog article titled "Just because you're a control
2900 * doesn't mean that you're necessarily inside a dialog box," multiline edit
2901 * controls without ES_WANTRETURN would attempt to detect whether it is inside
2902 * a dialog box or not.
2904 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
2906 return (es
->flags
& EF_DIALOGMODE
);
2910 /*********************************************************************
2915 static void EDIT_WM_Paste(EDITSTATE
*es
)
2921 /* Protect read-only edit control from modification */
2922 if(es
->style
& ES_READONLY
)
2925 OpenClipboard(es
->hwndSelf
);
2926 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
2927 src
= GlobalLock(hsrc
);
2928 len
= lstrlenW(src
);
2929 /* Protect single-line edit against pasting new line character */
2930 if (!(es
->style
& ES_MULTILINE
) && ((ptr
= wcschr(src
, '\n')))) {
2932 if (len
&& src
[len
- 1] == '\r')
2935 EDIT_EM_ReplaceSel(es
, TRUE
, src
, len
, TRUE
, TRUE
);
2938 else if (es
->style
& ES_PASSWORD
) {
2939 /* clear selected text in password edit box even with empty clipboard */
2940 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2946 /*********************************************************************
2951 static void EDIT_WM_Copy(EDITSTATE
*es
)
2953 INT s
= min(es
->selection_start
, es
->selection_end
);
2954 INT e
= max(es
->selection_start
, es
->selection_end
);
2962 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
2963 dst
= GlobalLock(hdst
);
2964 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
2965 dst
[len
] = 0; /* ensure 0 termination */
2966 TRACE("%s\n", debugstr_w(dst
));
2968 OpenClipboard(es
->hwndSelf
);
2970 SetClipboardData(CF_UNICODETEXT
, hdst
);
2975 /*********************************************************************
2980 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
2982 /* Protect read-only edit control from modification */
2983 if(es
->style
& ES_READONLY
)
2986 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2990 /*********************************************************************
2995 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3002 /*********************************************************************
3007 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3011 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3015 /* If it's not a multiline edit box, it would be ignored below.
3016 * For multiline edit without ES_WANTRETURN, we have to make a
3019 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3020 if (EDIT_IsInsideDialog(es
))
3023 if (es
->style
& ES_MULTILINE
) {
3024 if (es
->style
& ES_READONLY
) {
3025 EDIT_MoveHome(es
, FALSE
, FALSE
);
3026 EDIT_MoveDown_ML(es
, FALSE
);
3028 EDIT_EM_ReplaceSel(es
, TRUE
, L
"\r\n", 2, TRUE
, TRUE
);
3032 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3034 if (EDIT_IsInsideDialog(es
))
3036 EDIT_EM_ReplaceSel(es
, TRUE
, L
"\t", 1, TRUE
, TRUE
);
3040 if (!(es
->style
& ES_READONLY
) && !control
) {
3041 if (es
->selection_start
!= es
->selection_end
)
3044 /* delete character left of caret */
3045 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3046 EDIT_MoveBackward(es
, TRUE
);
3052 if (!(es
->style
& ES_PASSWORD
))
3053 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3056 if (!(es
->style
& ES_READONLY
))
3057 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3060 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3061 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3064 if (!(es
->style
& ES_READONLY
))
3065 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3069 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3070 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3073 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127))
3074 EDIT_EM_ReplaceSel(es
, TRUE
, &c
, 1, TRUE
, TRUE
);
3081 /*********************************************************************
3083 * EDIT_ContextMenuCommand
3086 static void EDIT_ContextMenuCommand(EDITSTATE
*es
, UINT id
)
3090 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3093 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3096 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3099 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3102 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3105 SendMessageW(es
->hwndSelf
, EM_SETSEL
, 0, -1);
3108 ERR("unknown menu item, please report\n");
3114 /*********************************************************************
3118 * Note: the resource files resource/sysres_??.rc cannot define a
3119 * single popup menu. Hence we use a (dummy) menubar
3120 * containing the single popup menu as its first item.
3122 * FIXME: the message identifiers have been chosen arbitrarily,
3123 * hence we use MF_BYPOSITION.
3124 * We might as well use the "real" values (anybody knows ?)
3125 * The menu definition is in resources/sysres_??.rc.
3126 * Once these are OK, we better use MF_BYCOMMAND here
3127 * (as we do in EDIT_WM_Command()).
3130 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3132 HMENU menu
= LoadMenuA(GetModuleHandleA("user32.dll"), "EDITMENU");
3133 HMENU popup
= GetSubMenu(menu
, 0);
3134 UINT start
= es
->selection_start
;
3135 UINT end
= es
->selection_end
;
3139 ORDER_UINT(start
, end
);
3142 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3144 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3146 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3148 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3150 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3152 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3157 if (pt
.x
== -1 && pt
.y
== -1) /* passed via VK_APPS press/release */
3161 /* Windows places the menu at the edit's center in this case */
3162 GetClientRect(es
->hwndSelf
, &rc
);
3163 pt
.x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3164 pt
.y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3165 ClientToScreen(es
->hwndSelf
, &pt
);
3168 if (!(es
->flags
& EF_FOCUSED
))
3169 SetFocus(es
->hwndSelf
);
3171 cmd
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
| TPM_NONOTIFY
,
3172 pt
.x
, pt
.y
, 0, es
->hwndSelf
, NULL
);
3175 EDIT_ContextMenuCommand(es
, cmd
);
3181 /*********************************************************************
3186 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
)
3191 lstrcpynW(dst
, es
->text
, count
);
3192 return lstrlenW(dst
);
3195 /*********************************************************************
3200 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3202 HWND hLBox
= es
->hwndListBox
;
3210 hCombo
= GetParent(es
->hwndSelf
);
3214 TRACE("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3216 if (key
== VK_UP
|| key
== VK_DOWN
)
3218 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3221 if (msg
== WM_KEYDOWN
|| nEUI
)
3222 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3228 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3230 /* make sure ComboLBox pops up */
3231 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3236 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3239 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3241 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, !bDropped
, 0);
3243 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3248 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3254 /*********************************************************************
3258 * Handling of special keys that don't produce a WM_CHAR
3259 * (i.e. non-printable keys) & Backspace & Delete
3262 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3267 if (GetKeyState(VK_MENU
) & 0x8000)
3270 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3271 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3276 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3281 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3282 EDIT_MoveUp_ML(es
, shift
);
3285 EDIT_MoveWordBackward(es
, shift
);
3287 EDIT_MoveBackward(es
, shift
);
3290 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3294 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3295 EDIT_MoveDown_ML(es
, shift
);
3297 EDIT_MoveWordForward(es
, shift
);
3299 EDIT_MoveForward(es
, shift
);
3302 EDIT_MoveHome(es
, shift
, control
);
3305 EDIT_MoveEnd(es
, shift
, control
);
3308 if (es
->style
& ES_MULTILINE
)
3309 EDIT_MovePageUp_ML(es
, shift
);
3311 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3314 if (es
->style
& ES_MULTILINE
)
3315 EDIT_MovePageDown_ML(es
, shift
);
3317 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3320 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3321 if (es
->selection_start
!= es
->selection_end
) {
3327 EDIT_EM_SetSel(es
, ~0u, 0, FALSE
);
3329 /* delete character left of caret */
3330 EDIT_MoveBackward(es
, TRUE
);
3332 /* delete to end of line */
3333 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3335 /* delete character right of caret */
3336 EDIT_MoveForward(es
, TRUE
);
3343 if (!(es
->style
& ES_READONLY
))
3349 /* If the edit doesn't want the return send a message to the default object */
3350 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3354 if (!EDIT_IsInsideDialog(es
)) break;
3356 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3357 if (HIWORD(dw
) == DC_HASDEFID
)
3359 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3362 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3363 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3369 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3370 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3373 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3374 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3379 if (EDIT_EM_SetSel(es
, 0, get_text_length(es
), FALSE
))
3381 if (!notify_parent(es
, EN_UPDATE
)) break;
3382 notify_parent(es
, EN_CHANGE
);
3391 /*********************************************************************
3396 static LRESULT
EDIT_WM_KillFocus(HTHEME theme
, EDITSTATE
*es
)
3398 UINT flags
= RDW_INVALIDATE
;
3400 es
->flags
&= ~EF_FOCUSED
;
3402 if (!(es
->style
& ES_NOHIDESEL
))
3403 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3404 if (!notify_parent(es
, EN_KILLFOCUS
)) return 0;
3405 /* Throw away left over scroll when we lose focus */
3406 es
->wheelDeltaRemainder
= 0;
3411 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3416 /*********************************************************************
3420 * The caret position has been set on the WM_LBUTTONDOWN message
3423 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3426 INT e
= es
->selection_end
;
3431 es
->bCaptureState
= TRUE
;
3432 SetCapture(es
->hwndSelf
);
3434 l
= EDIT_EM_LineFromChar(es
, e
);
3435 li
= EDIT_EM_LineIndex(es
, l
);
3436 ll
= EDIT_EM_LineLength(es
, e
);
3437 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3438 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3439 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3440 EDIT_EM_ScrollCaret(es
);
3441 es
->region_posx
= es
->region_posy
= 0;
3442 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3447 /*********************************************************************
3452 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3457 es
->bCaptureState
= TRUE
;
3458 SetCapture(es
->hwndSelf
);
3459 EDIT_ConfinePoint(es
, &x
, &y
);
3460 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3461 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3462 EDIT_EM_ScrollCaret(es
);
3463 es
->region_posx
= es
->region_posy
= 0;
3464 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3466 if (!(es
->flags
& EF_FOCUSED
))
3467 SetFocus(es
->hwndSelf
);
3473 /*********************************************************************
3478 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3480 if (es
->bCaptureState
) {
3481 KillTimer(es
->hwndSelf
, 0);
3482 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3484 es
->bCaptureState
= FALSE
;
3489 /*********************************************************************
3494 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3496 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3501 /*********************************************************************
3506 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3512 /* If the mouse has been captured by process other than the edit control itself,
3513 * the windows edit controls will not select the strings with mouse move.
3515 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3519 * FIXME: gotta do some scrolling if outside client
3520 * area. Maybe reset the timer ?
3523 EDIT_ConfinePoint(es
, &x
, &y
);
3524 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3525 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3526 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3527 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3528 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3533 /*********************************************************************
3538 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3551 BOOL rev
= es
->bEnableState
&&
3552 ((es
->flags
& EF_FOCUSED
) ||
3553 (es
->style
& ES_NOHIDESEL
));
3554 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3556 /* The dc we use for calculating may not be the one we paint into.
3557 This is the safest action. */
3558 EDIT_InvalidateUniscribeData(es
);
3559 GetClientRect(es
->hwndSelf
, &rcClient
);
3561 /* get the background brush */
3562 brush
= EDIT_NotifyCtlColor(es
, dc
);
3564 /* paint the border and the background */
3565 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3567 if(es
->style
& WS_BORDER
) {
3568 bw
= GetSystemMetrics(SM_CXBORDER
);
3569 bh
= GetSystemMetrics(SM_CYBORDER
);
3571 if(es
->style
& ES_MULTILINE
) {
3572 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3573 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3576 /* Draw the frame. Same code as in nonclient.c */
3577 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3578 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3579 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3580 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3581 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3582 SelectObject(dc
, old_brush
);
3584 /* Keep the border clean */
3585 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3586 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3589 GetClipBox(dc
, &rc
);
3590 FillRect(dc
, &rc
, brush
);
3592 IntersectClipRect(dc
, es
->format_rect
.left
,
3593 es
->format_rect
.top
,
3594 es
->format_rect
.right
,
3595 es
->format_rect
.bottom
);
3596 if (es
->style
& ES_MULTILINE
) {
3598 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3601 old_font
= SelectObject(dc
, es
->font
);
3603 if (!es
->bEnableState
)
3604 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3605 GetClipBox(dc
, &rcRgn
);
3606 if (es
->style
& ES_MULTILINE
) {
3607 INT vlc
= get_vertical_line_count(es
);
3608 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3609 EDIT_UpdateUniscribeData(es
, dc
, i
);
3610 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3611 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3612 EDIT_PaintLine(es
, dc
, i
, rev
);
3615 EDIT_UpdateUniscribeData(es
, dc
, 0);
3616 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3617 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3618 EDIT_PaintLine(es
, dc
, 0, rev
);
3621 SelectObject(dc
, old_font
);
3624 EndPaint(es
->hwndSelf
, &ps
);
3627 static void EDIT_WM_NCPaint(HWND hwnd
, HRGN region
)
3629 DWORD exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3630 HTHEME theme
= GetWindowTheme(hwnd
);
3631 HRGN cliprgn
= region
;
3633 if (theme
&& exStyle
& WS_EX_CLIENTEDGE
)
3637 int cxEdge
= GetSystemMetrics(SM_CXEDGE
),
3638 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
3639 const int part
= EP_EDITTEXT
;
3640 int state
= ETS_NORMAL
;
3641 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3643 if (!IsWindowEnabled(hwnd
))
3644 state
= ETS_DISABLED
;
3645 else if (dwStyle
& ES_READONLY
)
3646 state
= ETS_READONLY
;
3647 else if (GetFocus() == hwnd
)
3648 state
= ETS_FOCUSED
;
3650 GetWindowRect(hwnd
, &r
);
3652 /* New clipping region passed to default proc to exclude border */
3653 cliprgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
,
3654 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
3655 if (region
!= (HRGN
)1)
3656 CombineRgn(cliprgn
, cliprgn
, region
, RGN_AND
);
3657 OffsetRect(&r
, -r
.left
, -r
.top
);
3659 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
3661 if (IsThemeBackgroundPartiallyTransparent(theme
, part
, state
))
3662 DrawThemeParentBackground(hwnd
, dc
, &r
);
3663 DrawThemeBackground(theme
, dc
, part
, state
, &r
, 0);
3664 ReleaseDC(hwnd
, dc
);
3667 /* Call default proc to get the scrollbars etc. also painted */
3668 DefWindowProcW (hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
3669 if (cliprgn
!= region
)
3670 DeleteObject(cliprgn
);
3673 /*********************************************************************
3678 static void EDIT_WM_SetFocus(HTHEME theme
, EDITSTATE
*es
)
3680 UINT flags
= RDW_INVALIDATE
;
3682 es
->flags
|= EF_FOCUSED
;
3684 if (!(es
->style
& ES_NOHIDESEL
))
3685 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3687 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3688 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3689 ShowCaret(es
->hwndSelf
);
3690 if (!notify_parent(es
, EN_SETFOCUS
)) return;
3693 flags
|= RDW_FRAME
| RDW_ERASE
;
3695 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3699 static DWORD
get_font_margins(HDC hdc
, const TEXTMETRICW
*tm
)
3705 if (!(tm
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
3706 return MAKELONG(EC_USEFONTINFO
, EC_USEFONTINFO
);
3709 return MAKELONG(EC_USEFONTINFO
, EC_USEFONTINFO
);
3711 if (!GetCharABCWidthsW(hdc
, 0, 255, abc
))
3715 for (i
= 0; i
< ARRAY_SIZE(abc
); i
++) {
3716 if (-abc
[i
].abcA
> right
) right
= -abc
[i
].abcA
;
3717 if (-abc
[i
].abcC
> left
) left
= -abc
[i
].abcC
;
3719 return MAKELONG(left
, right
);
3722 static void EDIT_UpdateImmCompositionFont(EDITSTATE
*es
)
3724 LOGFONTW composition_font
;
3725 HIMC himc
= ImmGetContext(es
->hwndSelf
);
3726 GetObjectW(es
->font
, sizeof(LOGFONTW
), &composition_font
);
3727 ImmSetCompositionFontW(himc
, &composition_font
);
3728 ImmReleaseContext(es
->hwndSelf
, himc
);
3731 /*********************************************************************
3735 * With Win95 look the margins are set to default font value unless
3736 * the system font (font == 0) is being set, in which case they are left
3740 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3749 EDIT_InvalidateUniscribeData(es
);
3750 dc
= GetDC(es
->hwndSelf
);
3752 old_font
= SelectObject(dc
, font
);
3753 GetTextMetricsW(dc
, &tm
);
3754 es
->line_height
= tm
.tmHeight
;
3755 es
->char_width
= tm
.tmAveCharWidth
;
3756 margins
= get_font_margins(dc
, &tm
);
3758 SelectObject(dc
, old_font
);
3759 ReleaseDC(es
->hwndSelf
, dc
);
3761 /* Reset the format rect and the margins */
3762 GetClientRect(es
->hwndSelf
, &clientRect
);
3763 EDIT_SetRectNP(es
, &clientRect
);
3765 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3766 LOWORD(margins
), HIWORD(margins
), FALSE
);
3768 if (es
->style
& ES_MULTILINE
)
3769 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3771 EDIT_CalcLineWidth_SL(es
);
3774 EDIT_UpdateText(es
, NULL
, TRUE
);
3775 if (es
->flags
& EF_FOCUSED
) {
3777 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3778 EDIT_SetCaretPos(es
, es
->selection_end
,
3779 es
->flags
& EF_AFTER_WRAP
);
3780 ShowCaret(es
->hwndSelf
);
3783 EDIT_UpdateImmCompositionFont(es
);
3787 /*********************************************************************
3792 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3793 * The modified flag is reset. No notifications are sent.
3795 * For single-line controls, reception of WM_SETTEXT triggers:
3796 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3799 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
)
3801 if (es
->flags
& EF_UPDATE
)
3802 /* fixed this bug once; complain if we see it about to happen again. */
3803 ERR("SetSel may generate UPDATE message whose handler may reset "
3806 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3809 TRACE("%s\n", debugstr_w(text
));
3810 EDIT_EM_ReplaceSel(es
, FALSE
, text
, lstrlenW(text
), FALSE
, FALSE
);
3815 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3818 es
->flags
&= ~EF_MODIFIED
;
3819 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3821 /* Send the notification after the selection start and end have been set
3822 * edit control doesn't send notification on WM_SETTEXT
3823 * if it is multiline, or it is part of combobox
3825 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3827 if (!notify_parent(es
, EN_UPDATE
)) return;
3828 if (!notify_parent(es
, EN_CHANGE
)) return;
3830 EDIT_EM_ScrollCaret(es
);
3831 EDIT_UpdateScrollInfo(es
);
3832 EDIT_InvalidateUniscribeData(es
);
3836 /*********************************************************************
3841 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3843 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3845 GetClientRect(es
->hwndSelf
, &rc
);
3846 EDIT_SetRectNP(es
, &rc
);
3847 EDIT_UpdateText(es
, NULL
, TRUE
);
3852 /*********************************************************************
3856 * This message is sent by SetWindowLong on having changed either the Style
3857 * or the extended style.
3859 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3861 * See also EDIT_WM_NCCreate
3863 * It appears that the Windows version of the edit control allows the style
3864 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3865 * style variable which will generally be different. In this function we
3866 * update the internal style based on what changed in the externally visible
3869 * Much of this content as based upon the MSDN, especially:
3870 * Platform SDK Documentation -> User Interface Services ->
3871 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3872 * Edit Control Styles
3874 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3876 if (GWL_STYLE
== which
) {
3877 DWORD style_change_mask
;
3879 /* Only a subset of changes can be applied after the control
3882 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3884 if (es
->style
& ES_MULTILINE
)
3885 style_change_mask
|= ES_WANTRETURN
;
3887 new_style
= style
->styleNew
& style_change_mask
;
3889 /* Number overrides lowercase overrides uppercase (at least it
3890 * does in Win95). However I'll bet that ES_NUMBER would be
3891 * invalid under Win 3.1.
3893 if (new_style
& ES_NUMBER
) {
3894 ; /* do not override the ES_NUMBER */
3895 } else if (new_style
& ES_LOWERCASE
) {
3896 new_style
&= ~ES_UPPERCASE
;
3899 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3900 } else if (GWL_EXSTYLE
== which
) {
3901 ; /* FIXME - what is needed here */
3903 WARN ("Invalid style change %#Ix.\n", which
);
3909 /*********************************************************************
3914 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3916 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3917 if (EDIT_EM_CanUndo(es
))
3920 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3921 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3924 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3928 /*********************************************************************
3933 static void EDIT_WM_Timer(EDITSTATE
*es
)
3935 if (es
->region_posx
< 0) {
3936 EDIT_MoveBackward(es
, TRUE
);
3937 } else if (es
->region_posx
> 0) {
3938 EDIT_MoveForward(es
, TRUE
);
3941 * FIXME: gotta do some vertical scrolling here, like
3942 * EDIT_EM_LineScroll(hwnd, 0, 1);
3946 /*********************************************************************
3951 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3956 if (!(es
->style
& ES_MULTILINE
))
3959 if (!(es
->style
& ES_AUTOHSCROLL
))
3963 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3966 TRACE("SB_LINELEFT\n");
3968 dx
= -es
->char_width
;
3971 TRACE("SB_LINERIGHT\n");
3972 if (es
->x_offset
< es
->text_width
)
3973 dx
= es
->char_width
;
3976 TRACE("SB_PAGELEFT\n");
3978 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3981 TRACE("SB_PAGERIGHT\n");
3982 if (es
->x_offset
< es
->text_width
)
3983 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3991 TRACE("SB_RIGHT\n");
3992 if (es
->x_offset
< es
->text_width
)
3993 dx
= es
->text_width
- es
->x_offset
;
3996 TRACE("SB_THUMBTRACK %d\n", pos
);
3997 es
->flags
|= EF_HSCROLL_TRACK
;
3998 if(es
->style
& WS_HSCROLL
)
3999 dx
= pos
- es
->x_offset
;
4004 if(pos
< 0 || pos
> 100) return 0;
4005 /* Assume default scroll range 0-100 */
4006 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4007 new_x
= pos
* (es
->text_width
- fw
) / 100;
4008 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4011 case SB_THUMBPOSITION
:
4012 TRACE("SB_THUMBPOSITION %d\n", pos
);
4013 es
->flags
&= ~EF_HSCROLL_TRACK
;
4014 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4015 dx
= pos
- es
->x_offset
;
4020 if(pos
< 0 || pos
> 100) return 0;
4021 /* Assume default scroll range 0-100 */
4022 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4023 new_x
= pos
* (es
->text_width
- fw
) / 100;
4024 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4027 /* force scroll info update */
4028 EDIT_UpdateScrollInfo(es
);
4029 notify_parent(es
, EN_HSCROLL
);
4033 TRACE("SB_ENDSCROLL\n");
4036 * FIXME : the next two are undocumented !
4037 * Are we doing the right thing ?
4038 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4039 * although it's also a regular control message.
4041 case EM_GETTHUMB
: /* this one is used by NT notepad */
4044 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4045 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4048 /* Assume default scroll range 0-100 */
4049 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4050 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4052 TRACE("EM_GETTHUMB: returning %Id\n", ret
);
4056 TRACE("EM_LINESCROLL16\n");
4061 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4067 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4068 /* check if we are going to move too far */
4069 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4070 dx
= es
->text_width
- fw
- es
->x_offset
;
4072 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4078 /*********************************************************************
4083 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4087 if (!(es
->style
& ES_MULTILINE
))
4090 if (!(es
->style
& ES_AUTOVSCROLL
))
4099 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4100 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4101 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4103 EDIT_EM_Scroll(es
, action
);
4110 TRACE("SB_BOTTOM\n");
4111 dy
= es
->line_count
- 1 - es
->y_offset
;
4114 TRACE("SB_THUMBTRACK %d\n", pos
);
4115 es
->flags
|= EF_VSCROLL_TRACK
;
4116 if(es
->style
& WS_VSCROLL
)
4117 dy
= pos
- es
->y_offset
;
4120 /* Assume default scroll range 0-100 */
4123 if(pos
< 0 || pos
> 100) return 0;
4124 vlc
= get_vertical_line_count(es
);
4125 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4126 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4127 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4128 es
->line_count
, es
->y_offset
, pos
, dy
);
4131 case SB_THUMBPOSITION
:
4132 TRACE("SB_THUMBPOSITION %d\n", pos
);
4133 es
->flags
&= ~EF_VSCROLL_TRACK
;
4134 if(es
->style
& WS_VSCROLL
)
4135 dy
= pos
- es
->y_offset
;
4138 /* Assume default scroll range 0-100 */
4141 if(pos
< 0 || pos
> 100) return 0;
4142 vlc
= get_vertical_line_count(es
);
4143 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4144 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4145 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4146 es
->line_count
, es
->y_offset
, pos
, dy
);
4150 /* force scroll info update */
4151 EDIT_UpdateScrollInfo(es
);
4152 notify_parent(es
, EN_VSCROLL
);
4156 TRACE("SB_ENDSCROLL\n");
4159 * FIXME : the next two are undocumented !
4160 * Are we doing the right thing ?
4161 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4162 * although it's also a regular control message.
4164 case EM_GETTHUMB
: /* this one is used by NT notepad */
4167 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4168 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4171 /* Assume default scroll range 0-100 */
4172 INT vlc
= get_vertical_line_count(es
);
4173 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4175 TRACE("EM_GETTHUMB: returning %Id\n", ret
);
4179 TRACE("EM_LINESCROLL %d\n", pos
);
4184 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4189 EDIT_EM_LineScroll(es
, 0, dy
);
4193 /*********************************************************************
4197 * FIXME: is this right ? (or should it be only VSCROLL)
4198 * (and maybe only for edit controls that really have their
4199 * own scrollbars) (and maybe only for multiline controls ?)
4200 * All in all: very poorly documented
4203 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4205 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4206 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4209 /*********************************************************************
4214 static BOOL
EDIT_EM_SetCueBanner(EDITSTATE
*es
, BOOL draw_focused
, const WCHAR
*cue_text
)
4216 if (es
->style
& ES_MULTILINE
|| !cue_text
)
4219 Free(es
->cue_banner_text
);
4220 es
->cue_banner_text
= wcsdup(cue_text
);
4221 es
->cue_banner_draw_focused
= draw_focused
;
4226 /*********************************************************************
4231 static BOOL
EDIT_EM_GetCueBanner(EDITSTATE
*es
, WCHAR
*buf
, DWORD size
)
4233 if (es
->style
& ES_MULTILINE
)
4236 if (!es
->cue_banner_text
)
4245 lstrcpynW(buf
, es
->cue_banner_text
, size
);
4251 /********************************************************************
4253 * The Following code is to handle inline editing from IMEs
4256 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4261 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4267 lpResultStr
= Alloc(buflen
);
4270 ERR("Unable to alloc buffer for IME string\n");
4274 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4275 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4279 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4283 hIMC
= ImmGetContext(hwnd
);
4287 if (CompFlag
& GCS_RESULTSTR
)
4288 EDIT_GetResultStr(hIMC
, es
);
4290 ImmReleaseContext(hwnd
, hIMC
);
4294 /*********************************************************************
4298 * See also EDIT_WM_StyleChanged
4300 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
4305 TRACE("Creating edit control, style = %#lx\n", lpcs
->style
);
4307 if (!(es
= Alloc(sizeof(*es
))))
4309 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4312 * Note: since the EDITSTATE has not been fully initialized yet,
4313 * we can't use any API calls that may send
4314 * WM_XXX messages before WM_NCCREATE is completed.
4317 es
->style
= lpcs
->style
;
4319 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4321 es
->hwndSelf
= hwnd
;
4322 /* Save parent, which will be notified by EN_* messages */
4323 es
->hwndParent
= lpcs
->hwndParent
;
4325 if (es
->style
& ES_COMBO
)
4326 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4328 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4329 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4331 /* Number overrides lowercase overrides uppercase (at least it
4332 * does in Win95). However I'll bet that ES_NUMBER would be
4333 * invalid under Win 3.1.
4335 if (es
->style
& ES_NUMBER
) {
4336 ; /* do not override the ES_NUMBER */
4337 } else if (es
->style
& ES_LOWERCASE
) {
4338 es
->style
&= ~ES_UPPERCASE
;
4340 if (es
->style
& ES_MULTILINE
) {
4341 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4342 if (es
->style
& WS_VSCROLL
)
4343 es
->style
|= ES_AUTOVSCROLL
;
4344 if (es
->style
& WS_HSCROLL
)
4345 es
->style
|= ES_AUTOHSCROLL
;
4346 es
->style
&= ~ES_PASSWORD
;
4347 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4348 /* Confirmed - RIGHT overrides CENTER */
4349 if (es
->style
& ES_RIGHT
)
4350 es
->style
&= ~ES_CENTER
;
4351 es
->style
&= ~WS_HSCROLL
;
4352 es
->style
&= ~ES_AUTOHSCROLL
;
4355 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4356 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4357 es
->style
&= ~ES_CENTER
;
4358 es
->style
&= ~WS_HSCROLL
;
4359 es
->style
&= ~WS_VSCROLL
;
4360 if (es
->style
& ES_PASSWORD
)
4361 es
->password_char
= '*';
4364 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4365 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4367 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4369 if (!(es
->undo_text
= Alloc((es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4371 es
->undo_buffer_size
= es
->buffer_size
;
4373 if (es
->style
& ES_MULTILINE
)
4374 if (!(es
->first_line_def
= Alloc(sizeof(LINEDEF
))))
4379 * In Win95 look and feel, the WS_BORDER style is replaced by the
4380 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4381 * control a nonclient area so we don't need to draw the border.
4382 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4383 * a nonclient area and we should handle painting the border ourselves.
4385 * When making modifications please ensure that the code still works
4386 * for edit controls created directly with style 0x50800000, exStyle 0
4387 * (which should have a single pixel border)
4389 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4390 es
->style
&= ~WS_BORDER
;
4391 else if (es
->style
& WS_BORDER
)
4392 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4397 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4398 EDIT_InvalidateUniscribeData(es
);
4399 Free(es
->first_line_def
);
4400 Free(es
->undo_text
);
4401 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4408 /*********************************************************************
4413 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, const WCHAR
*name
)
4417 TRACE("%s\n", debugstr_w(name
));
4420 * To initialize some final structure members, we call some helper
4421 * functions. However, since the EDITSTATE is not consistent (i.e.
4422 * not fully initialized), we should be very careful which
4423 * functions can be called, and in what order.
4425 EDIT_WM_SetFont(es
, 0, FALSE
);
4426 EDIT_EM_EmptyUndoBuffer(es
);
4428 /* We need to calculate the format rect
4429 (applications may send EM_SETMARGINS before the control gets visible) */
4430 GetClientRect(es
->hwndSelf
, &clientRect
);
4431 EDIT_SetRectNP(es
, &clientRect
);
4435 EDIT_EM_ReplaceSel(es
, FALSE
, name
, lstrlenW(name
), FALSE
, FALSE
);
4436 /* if we insert text to the editline, the text scrolls out
4437 * of the window, as the caret is placed after the insert
4438 * pos normally; thus we reset es->selection... to 0 and
4441 es
->selection_start
= es
->selection_end
= 0;
4442 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4443 * Messages are only to be sent when the USER does something to
4444 * change the contents. So I am removing this EN_CHANGE
4446 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4448 EDIT_EM_ScrollCaret(es
);
4451 /* force scroll info update */
4452 EDIT_UpdateScrollInfo(es
);
4453 OpenThemeData(es
->hwndSelf
, WC_EDITW
);
4455 /* The rule seems to return 1 here for success */
4456 /* Power Builder masked edit controls will crash */
4458 /* FIXME: is that in all cases so ? */
4463 /*********************************************************************
4468 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4473 theme
= GetWindowTheme(es
->hwndSelf
);
4474 CloseThemeData(theme
);
4476 /* The app can own the text buffer handle */
4477 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
))
4478 LocalFree(es
->hloc32W
);
4480 EDIT_InvalidateUniscribeData(es
);
4482 pc
= es
->first_line_def
;
4490 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4491 Free(es
->undo_text
);
4492 Free(es
->cue_banner_text
);
4498 static LRESULT CALLBACK
EDIT_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4500 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW(hwnd
, 0);
4505 TRACE("hwnd %p, msg %#x, wparam %Ix, lparam %Ix\n", hwnd
, msg
, wParam
, lParam
);
4507 if (!es
&& msg
!= WM_NCCREATE
)
4508 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4510 if (es
&& (msg
!= WM_NCDESTROY
))
4511 EDIT_LockBuffer(es
);
4516 result
= EDIT_EM_GetSel(es
, (UINT
*)wParam
, (UINT
*)lParam
);
4520 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4521 EDIT_EM_ScrollCaret(es
);
4526 rect
= (RECT
*)lParam
;
4528 *rect
= es
->format_rect
;
4532 if ((es
->style
& ES_MULTILINE
) && lParam
)
4534 EDIT_SetRectNP(es
, (RECT
*)lParam
);
4535 EDIT_UpdateText(es
, NULL
, TRUE
);
4540 if ((es
->style
& ES_MULTILINE
) && lParam
)
4541 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4545 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4549 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4552 case EM_SCROLLCARET
:
4553 EDIT_EM_ScrollCaret(es
);
4558 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4563 es
->flags
|= EF_MODIFIED
;
4565 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4568 case EM_GETLINECOUNT
:
4569 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4573 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4577 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4581 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4585 result
= EDIT_EM_GetThumb(es
);
4588 /* these messages missing from specs */
4593 FIXME("undocumented message 0x%x, please report\n", msg
);
4594 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4598 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4603 const WCHAR
*textW
= (const WCHAR
*)lParam
;
4605 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, lstrlenW(textW
), TRUE
, TRUE
);
4611 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4614 case EM_SETLIMITTEXT
:
4615 EDIT_EM_SetLimitText(es
, wParam
);
4619 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4624 result
= (LRESULT
)EDIT_EM_Undo(es
);
4628 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4631 case EM_LINEFROMCHAR
:
4632 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4635 case EM_SETTABSTOPS
:
4636 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4639 case EM_SETPASSWORDCHAR
:
4640 EDIT_EM_SetPasswordChar(es
, wParam
);
4643 case EM_EMPTYUNDOBUFFER
:
4644 EDIT_EM_EmptyUndoBuffer(es
);
4647 case EM_GETFIRSTVISIBLELINE
:
4648 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4651 case EM_SETREADONLY
:
4653 DWORD old_style
= es
->style
;
4657 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | ES_READONLY
);
4658 es
->style
|= ES_READONLY
;
4662 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4663 es
->style
&= ~ES_READONLY
;
4666 if (old_style
^ es
->style
)
4667 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4673 case EM_SETWORDBREAKPROC
:
4674 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4678 case EM_GETWORDBREAKPROC
:
4679 result
= (LRESULT
)es
->word_break_proc
;
4682 case EM_GETPASSWORDCHAR
:
4683 result
= es
->password_char
;
4687 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4691 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4694 case EM_GETLIMITTEXT
:
4695 result
= es
->buffer_limit
;
4698 case EM_POSFROMCHAR
:
4699 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4700 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4703 case EM_CHARFROMPOS
:
4704 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4707 case EM_SETCUEBANNER
:
4708 result
= EDIT_EM_SetCueBanner(es
, (BOOL
)wParam
, (const WCHAR
*)lParam
);
4711 case EM_GETCUEBANNER
:
4712 result
= EDIT_EM_GetCueBanner(es
, (WCHAR
*)wParam
, (DWORD
)lParam
);
4715 case EM_SETIMESTATUS
:
4716 if (wParam
== EMSIS_COMPOSITIONSTRING
)
4717 es
->ime_status
= lParam
& 0xFFFF;
4722 case EM_GETIMESTATUS
:
4723 result
= wParam
== EMSIS_COMPOSITIONSTRING
? es
->ime_status
: 1;
4726 /* End of the EM_ messages which were in numerical order; what order
4727 * are these in? vaguely alphabetical?
4731 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
4735 result
= EDIT_WM_NCDestroy(es
);
4740 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4742 if (es
->style
& ES_MULTILINE
)
4743 result
|= DLGC_WANTALLKEYS
;
4747 MSG
*msg
= (MSG
*)lParam
;
4748 es
->flags
|= EF_DIALOGMODE
;
4750 if (msg
->message
== WM_KEYDOWN
)
4752 int vk
= (int)msg
->wParam
;
4754 if (es
->hwndListBox
)
4756 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4757 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4758 result
|= DLGC_WANTMESSAGE
;
4766 WCHAR charW
= wParam
;
4768 if (es
->hwndListBox
)
4770 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4772 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4773 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4777 result
= EDIT_WM_Char(es
, charW
);
4782 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4783 if (wParam
<= 0x000fffff)
4785 if (wParam
> 0xffff) /* convert to surrogates */
4788 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4789 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4792 EDIT_WM_Char(es
, wParam
);
4800 case WM_CONTEXTMENU
:
4801 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4809 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4817 es
->bEnableState
= (BOOL
) wParam
;
4818 EDIT_UpdateText(es
, NULL
, TRUE
);
4819 if (GetWindowTheme(hwnd
))
4820 RedrawWindow(hwnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
4824 /* we do the proper erase in EDIT_WM_Paint */
4829 result
= (LRESULT
)es
->font
;
4833 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4836 case WM_GETTEXTLENGTH
:
4837 result
= get_text_length(es
);
4841 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4845 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4849 result
= EDIT_WM_KillFocus(GetWindowTheme(hwnd
), es
);
4852 case WM_LBUTTONDBLCLK
:
4853 result
= EDIT_WM_LButtonDblClk(es
);
4856 case WM_LBUTTONDOWN
:
4857 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4861 result
= EDIT_WM_LButtonUp(es
);
4864 case WM_MBUTTONDOWN
:
4865 result
= EDIT_WM_MButtonDown(es
);
4869 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4872 case WM_PRINTCLIENT
:
4874 EDIT_WM_Paint(es
, (HDC
)wParam
);
4878 EDIT_WM_NCPaint(hwnd
, (HRGN
)wParam
);
4886 EDIT_WM_SetFocus(GetWindowTheme(hwnd
), es
);
4890 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4894 /* FIXME: actually set an internal flag and behave accordingly */
4898 EDIT_WM_SetText(es
, (const WCHAR
*)lParam
);
4903 EDIT_WM_Size(es
, (UINT
)wParam
);
4906 case WM_STYLECHANGED
:
4907 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4910 case WM_STYLECHANGING
:
4911 result
= 0; /* See EDIT_WM_StyleChanged */
4915 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
4923 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4929 INT pulScrollLines
= 3;
4930 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
4932 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
4934 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4938 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
4939 /* if scrolling changes direction, ignore left overs */
4940 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
4941 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
4942 es
->wheelDeltaRemainder
+= wheelDelta
;
4944 es
->wheelDeltaRemainder
= wheelDelta
;
4946 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
4949 pulScrollLines
= min(es
->line_count
, pulScrollLines
);
4950 cLineScroll
= pulScrollLines
* es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
4951 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
4952 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
4957 /* IME messages to make the edit control IME aware */
4958 case WM_IME_SETCONTEXT
:
4960 EDIT_UpdateImmCompositionWindow(es
, pt
.x
, pt
.y
);
4961 EDIT_UpdateImmCompositionFont(es
);
4964 case WM_IME_COMPOSITION
:
4965 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4966 if ((lParam
& GCS_RESULTSTR
) && (es
->ime_status
& EIMES_GETCOMPSTRATONCE
))
4967 EDIT_ImeComposition(hwnd
, lParam
, es
);
4968 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4973 case WM_IME_CONTROL
:
4976 case WM_IME_REQUEST
:
4979 case IMR_QUERYCHARPOSITION
:
4981 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
4984 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
4985 chpos
->pt
.x
= LOWORD(pos
);
4986 chpos
->pt
.y
= HIWORD(pos
);
4987 chpos
->cLineHeight
= es
->line_height
;
4988 chpos
->rcDocument
= es
->format_rect
;
4989 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
4990 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
4997 case WM_THEMECHANGED
:
4998 CloseThemeData(GetWindowTheme(hwnd
));
4999 OpenThemeData(hwnd
, WC_EDITW
);
5000 InvalidateRect(hwnd
, NULL
, TRUE
);
5004 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5008 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
5009 EDIT_UnlockBuffer(es
, FALSE
);
5011 TRACE("hwnd=%p msg=%x -- %#Ix\n", hwnd
, msg
, result
);
5016 void EDIT_Register(void)
5020 memset(&wndClass
, 0, sizeof(wndClass
));
5021 wndClass
.style
= CS_PARENTDC
| CS_GLOBALCLASS
| CS_DBLCLKS
;
5022 wndClass
.lpfnWndProc
= EDIT_WindowProc
;
5023 wndClass
.cbClsExtra
= 0;
5025 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*) + sizeof(WORD
);
5027 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*);
5029 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_IBEAM
);
5030 wndClass
.hbrBackground
= NULL
;
5031 wndClass
.lpszClassName
= WC_EDITW
;
5032 RegisterClassW(&wndClass
);