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
28 * - EM_GETIMESTATUS, EM_SETIMESTATUS
47 #include "wine/debug.h"
48 #include "wine/heap.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 composition_len
; /* length of composition, 0 == no composition */
145 int composition_start
; /* the character position for the composition */
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 /* used for disabled or read-only edit control */
158 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
160 { /* Notify parent which has created this edit control */ \
161 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
162 SendMessageW(es->hwndParent, WM_COMMAND, \
163 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
164 (LPARAM)(es->hwndSelf)); \
167 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
169 /*********************************************************************
174 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
176 return (es
->undo_insert_count
|| lstrlenW(es
->undo_text
));
180 /*********************************************************************
185 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
187 es
->undo_insert_count
= 0;
188 *es
->undo_text
= '\0';
191 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
196 if ((!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
197 msg
= WM_CTLCOLORSTATIC
;
199 msg
= WM_CTLCOLOREDIT
;
201 /* Why do we notify to es->hwndParent, and we send this one to GetParent()? */
202 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
204 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
209 static inline UINT
get_text_length(EDITSTATE
*es
)
211 if(es
->text_length
== (UINT
)-1)
212 es
->text_length
= lstrlenW(es
->text
);
213 return es
->text_length
;
217 /*********************************************************************
221 * Find the beginning of words.
222 * Note: unlike the specs for a WordBreakProc, this function can
223 * only be called without linebreaks between s[0] up to
224 * s[count - 1]. Remember it is only called
225 * internally, so we can decide this for ourselves.
226 * Additionally we will always be breaking the full string.
229 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
233 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
241 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
242 psa
.eScript
= SCRIPT_UNDEFINED
;
244 es
->logAttr
= heap_alloc(sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
245 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
252 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
259 while (index
< count
&& s
[index
] && !es
->logAttr
[index
].fSoftBreak
)
264 ret
= es
->logAttr
[index
].fWhiteSpace
;
267 ERR("unknown action code, please report !\n");
274 /*********************************************************************
276 * EDIT_CallWordBreakProc
278 * Call appropriate WordBreakProc (internal or external).
280 * Note: The "start" argument should always be an index referring
281 * to es->text. The actual wordbreak proc might be
282 * 16 bit, so we can't always pass any 32 bit LPSTR.
283 * Hence we assume that es->text is the buffer that holds
284 * the string under examination (we can decide this for ourselves).
287 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
291 if (es
->word_break_proc
)
292 ret
= es
->word_break_proc(es
->text
+ start
, index
, count
, action
);
294 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+ start
, count
+ start
, action
) - start
;
299 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
303 ScriptStringFree(&line_def
->ssa
);
304 line_def
->ssa
= NULL
;
308 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
310 LINEDEF
*line_def
= es
->first_line_def
;
313 EDIT_InvalidateUniscribeData_linedef(line_def
);
314 line_def
= line_def
->next
;
318 ScriptStringFree(&es
->ssa
);
323 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
328 if (line_def
->net_length
&& !line_def
->ssa
)
330 int index
= line_def
->index
;
331 HFONT old_font
= NULL
;
333 SCRIPT_TABDEF tabdef
;
337 udc
= GetDC(es
->hwndSelf
);
339 old_font
= SelectObject(udc
, es
->font
);
341 tabdef
.cTabStops
= es
->tabs_count
;
342 tabdef
.iScale
= GdiGetCharDimensions(udc
, NULL
, NULL
);
343 tabdef
.pTabStops
= es
->tabs
;
344 tabdef
.iTabOrigin
= 0;
346 hr
= ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
,
347 (1.5*line_def
->net_length
+16), -1,
348 SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1,
349 NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
352 WARN("ScriptStringAnalyse failed (%x)\n",hr
);
353 line_def
->ssa
= NULL
;
357 SelectObject(udc
, old_font
);
359 ReleaseDC(es
->hwndSelf
, udc
);
362 return line_def
->ssa
;
365 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
369 if (!(es
->style
& ES_MULTILINE
))
373 INT length
= get_text_length(es
);
374 HFONT old_font
= NULL
;
378 udc
= GetDC(es
->hwndSelf
);
380 old_font
= SelectObject(udc
, es
->font
);
382 if (es
->style
& ES_PASSWORD
)
383 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
);
385 ScriptStringAnalyse(udc
, es
->text
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
388 SelectObject(udc
, old_font
);
390 ReleaseDC(es
->hwndSelf
, udc
);
396 line_def
= es
->first_line_def
;
397 while (line_def
&& line
)
399 line_def
= line_def
->next
;
403 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
407 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
409 INT vlc
= es
->line_height
? (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
: 0;
413 /*********************************************************************
415 * EDIT_BuildLineDefs_ML
417 * Build linked list of text lines.
418 * Lines can end with '\0' (last line), a character (if it is wrapped),
419 * a soft return '\r\r\n' or a hard return '\r\n'
422 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
424 LPWSTR current_position
, cp
;
426 LINEDEF
*current_line
;
427 LINEDEF
*previous_line
;
429 INT line_index
= 0, nstart_line
, nstart_index
;
430 INT line_count
= es
->line_count
;
435 if (istart
== iend
&& delta
== 0)
438 previous_line
= NULL
;
439 current_line
= es
->first_line_def
;
441 /* Find starting line. istart must lie inside an existing line or
442 * at the end of buffer */
444 if (istart
< current_line
->index
+ current_line
->length
||
445 current_line
->ending
== END_0
)
448 previous_line
= current_line
;
449 current_line
= current_line
->next
;
451 } while (current_line
);
453 if (!current_line
) /* Error occurred start is not inside previous buffer */
455 FIXME(" modification occurred outside buffer\n");
459 /* Remember start of modifications in order to calculate update region */
460 nstart_line
= line_index
;
461 nstart_index
= current_line
->index
;
463 /* We must start to reformat from the previous line since the modifications
464 * may have caused the line to wrap upwards. */
465 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
468 current_line
= previous_line
;
470 start_line
= current_line
;
472 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
473 current_position
= es
->text
+ current_line
->index
;
474 vlc
= get_vertical_line_count(es
);
476 if (current_line
!= start_line
)
478 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
480 /* The buffer has been expanded, create a new line and
481 insert it into the link list */
482 LINEDEF
*new_line
= heap_alloc_zero(sizeof(*new_line
));
483 new_line
->next
= previous_line
->next
;
484 previous_line
->next
= new_line
;
485 current_line
= new_line
;
488 else if (current_line
->index
+ delta
< current_position
- es
->text
)
490 /* The previous line merged with this line so we delete this extra entry */
491 previous_line
->next
= current_line
->next
;
492 heap_free(current_line
);
493 current_line
= previous_line
->next
;
497 else /* current_line->index + delta == current_position */
499 if (current_position
- es
->text
> iend
)
500 break; /* We reached end of line modifications */
501 /* else recalculate this line */
505 current_line
->index
= current_position
- es
->text
;
506 orig_net_length
= current_line
->net_length
;
508 /* Find end of line */
509 cp
= current_position
;
511 if (*cp
== '\n') break;
512 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
517 /* Mark type of line termination */
519 current_line
->ending
= END_0
;
520 current_line
->net_length
= lstrlenW(current_position
);
521 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
522 current_line
->ending
= END_SOFT
;
523 current_line
->net_length
= cp
- current_position
- 1;
524 } else if (*cp
== '\n') {
525 current_line
->ending
= END_RICH
;
526 current_line
->net_length
= cp
- current_position
;
528 current_line
->ending
= END_HARD
;
529 current_line
->net_length
= cp
- current_position
;
532 if (current_line
->net_length
)
535 EDIT_InvalidateUniscribeData_linedef(current_line
);
536 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
537 if (current_line
->ssa
)
539 sz
= ScriptString_pSize(current_line
->ssa
);
540 /* Calculate line width */
541 current_line
->width
= sz
->cx
;
543 else current_line
->width
= es
->char_width
* current_line
->net_length
;
545 else current_line
->width
= 0;
547 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
549 /* Line breaks just look back from the end and find the next break and try that. */
551 if (!(es
->style
& ES_AUTOHSCROLL
)) {
552 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
559 prev
= current_line
->net_length
- 1;
560 w
= current_line
->net_length
;
561 d
= (float)current_line
->width
/(float)fw
;
562 if (d
> 1.2f
) d
-= 0.2f
;
564 if (next
>= prev
) next
= prev
-1;
566 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
567 next
, current_line
->net_length
, WB_LEFT
);
568 current_line
->net_length
= prev
;
569 EDIT_InvalidateUniscribeData_linedef(current_line
);
570 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
571 if (current_line
->ssa
)
572 sz
= ScriptString_pSize(current_line
->ssa
);
575 current_line
->width
= sz
->cx
;
579 } while (prev
&& current_line
->width
> fw
);
580 current_line
->net_length
= w
;
582 if (prev
== 0) { /* Didn't find a line break so force a break */
586 EDIT_InvalidateUniscribeData_linedef(current_line
);
587 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
589 if (current_line
->ssa
)
591 count
= ScriptString_pcOutChars(current_line
->ssa
);
592 piDx
= heap_alloc(sizeof(INT
) * (*count
));
593 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
595 prev
= current_line
->net_length
-1;
597 current_line
->width
-= piDx
[prev
];
599 } while ( prev
> 0 && current_line
->width
> fw
);
605 prev
= (fw
/ es
->char_width
);
608 /* If the first line we are calculating, wrapped before istart, we must
609 * adjust istart in order for this to be reflected in the update region. */
610 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
611 istart
= current_line
->index
+ prev
;
612 /* else if we are updating the previous line before the first line we
613 * are re-calculating and it expanded */
614 else if (current_line
== start_line
&&
615 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
617 /* Line expanded due to an upwards line wrap so we must partially include
618 * previous line in update region */
619 nstart_line
= line_index
;
620 nstart_index
= current_line
->index
;
621 istart
= current_line
->index
+ orig_net_length
;
624 current_line
->net_length
= prev
;
625 current_line
->ending
= END_WRAP
;
627 if (current_line
->net_length
> 0)
629 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
630 if (current_line
->ssa
)
632 sz
= ScriptString_pSize(current_line
->ssa
);
633 current_line
->width
= sz
->cx
;
636 current_line
->width
= 0;
638 else current_line
->width
= 0;
640 else if (current_line
== start_line
&&
641 current_line
->index
!= nstart_index
&&
642 orig_net_length
< current_line
->net_length
) {
643 /* The previous line expanded but it's still not as wide as the client rect */
644 /* The expansion is due to an upwards line wrap so we must partially include
645 it in the update region */
646 nstart_line
= line_index
;
647 nstart_index
= current_line
->index
;
648 istart
= current_line
->index
+ orig_net_length
;
653 /* Adjust length to include line termination */
654 switch (current_line
->ending
) {
656 current_line
->length
= current_line
->net_length
+ 3;
659 current_line
->length
= current_line
->net_length
+ 1;
662 current_line
->length
= current_line
->net_length
+ 2;
666 current_line
->length
= current_line
->net_length
;
669 es
->text_width
= max(es
->text_width
, current_line
->width
);
670 current_position
+= current_line
->length
;
671 previous_line
= current_line
;
673 /* Discard data for non-visible lines. It will be calculated as needed */
674 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
675 EDIT_InvalidateUniscribeData_linedef(current_line
);
677 current_line
= current_line
->next
;
679 } while (previous_line
->ending
!= END_0
);
681 /* Finish adjusting line indexes by delta or remove hanging lines */
682 if (previous_line
->ending
== END_0
)
684 LINEDEF
*pnext
= NULL
;
686 previous_line
->next
= NULL
;
689 pnext
= current_line
->next
;
690 EDIT_InvalidateUniscribeData_linedef(current_line
);
691 heap_free(current_line
);
692 current_line
= pnext
;
700 current_line
->index
+= delta
;
701 current_line
= current_line
->next
;
705 /* Calculate rest of modification rectangle */
710 * We calculate two rectangles. One for the first line which may have
711 * an indent with respect to the format rect. The other is a format-width
712 * rectangle that spans the rest of the lines that changed or moved.
714 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
715 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
716 rc
.bottom
= rc
.top
+ es
->line_height
;
717 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
718 rc
.left
= es
->format_rect
.left
;
720 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
721 rc
.right
= es
->format_rect
.right
;
722 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
725 rc
.left
= es
->format_rect
.left
;
726 rc
.right
= es
->format_rect
.right
;
728 * If lines were added or removed we must re-paint the remainder of the
729 * lines since the remaining lines were either shifted up or down.
731 if (line_count
< es
->line_count
) /* We added lines */
732 rc
.bottom
= es
->line_count
* es
->line_height
;
733 else if (line_count
> es
->line_count
) /* We removed lines */
734 rc
.bottom
= line_count
* es
->line_height
;
736 rc
.bottom
= line_index
* es
->line_height
;
737 rc
.bottom
+= es
->format_rect
.top
;
738 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
739 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
740 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
741 DeleteObject(tmphrgn
);
745 /*********************************************************************
747 * EDIT_CalcLineWidth_SL
750 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
752 EDIT_UpdateUniscribeData(es
, NULL
, 0);
756 size
= ScriptString_pSize(es
->ssa
);
757 es
->text_width
= size
->cx
;
763 /*********************************************************************
767 * Beware: This is not the function called on EM_CHARFROMPOS
768 * The position _can_ be outside the formatting / client
770 * The return value is only the character index
773 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
777 if (es
->style
& ES_MULTILINE
) {
779 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
781 LINEDEF
*line_def
= es
->first_line_def
;
782 EDIT_UpdateUniscribeData(es
, NULL
, line
);
783 while ((line
> 0) && line_def
->next
) {
784 line_index
+= line_def
->length
;
785 line_def
= line_def
->next
;
789 x
+= es
->x_offset
- es
->format_rect
.left
;
790 if (es
->style
& ES_RIGHT
)
791 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
792 else if (es
->style
& ES_CENTER
)
793 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
794 if (x
>= line_def
->width
) {
796 *after_wrap
= (line_def
->ending
== END_WRAP
);
797 return line_index
+ line_def
->net_length
;
799 if (x
<= 0 || !line_def
->ssa
) {
805 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
806 if (trailing
) index
++;
809 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
810 (line_def
->ending
== END_WRAP
));
816 x
-= es
->format_rect
.left
;
822 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
823 if (es
->style
& ES_RIGHT
)
825 else if (es
->style
& ES_CENTER
)
829 EDIT_UpdateUniscribeData(es
, NULL
, 0);
834 if (es
->x_offset
>= get_text_length(es
))
837 size
= ScriptString_pSize(es
->ssa
);
840 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
847 if (x
+ xoff
> 0 || !es
->ssa
)
849 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
850 if (trailing
) index
++;
859 const SIZE
*size
= NULL
;
861 size
= ScriptString_pSize(es
->ssa
);
864 else if (x
> size
->cx
)
865 index
= get_text_length(es
);
868 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
869 if (trailing
) index
++;
875 index
= es
->x_offset
;
882 /*********************************************************************
886 * adjusts the point to be within the formatting rectangle
887 * (so CharFromPos returns the nearest _visible_ character)
890 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
892 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
893 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
897 /*********************************************************************
902 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
907 if (!(es
->style
& ES_MULTILINE
))
909 if (index
> (INT
)get_text_length(es
))
910 return es
->line_count
- 1;
912 index
= min(es
->selection_start
, es
->selection_end
);
915 line_def
= es
->first_line_def
;
916 index
-= line_def
->length
;
917 while ((index
>= 0) && line_def
->next
) {
919 line_def
= line_def
->next
;
920 index
-= line_def
->length
;
926 /*********************************************************************
931 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
934 const LINEDEF
*line_def
;
936 if (!(es
->style
& ES_MULTILINE
))
938 if (line
>= es
->line_count
)
942 line_def
= es
->first_line_def
;
944 INT index
= es
->selection_end
- line_def
->length
;
945 while ((index
>= 0) && line_def
->next
) {
946 line_index
+= line_def
->length
;
947 line_def
= line_def
->next
;
948 index
-= line_def
->length
;
952 line_index
+= line_def
->length
;
953 line_def
= line_def
->next
;
961 /*********************************************************************
966 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
970 if (!(es
->style
& ES_MULTILINE
))
971 return get_text_length(es
);
974 /* get the number of remaining non-selected chars of selected lines */
975 INT32 l
; /* line number */
976 INT32 li
; /* index of first char in line */
978 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
979 /* # chars before start of selection area */
980 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
981 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
982 /* # chars after end of selection */
983 li
= EDIT_EM_LineIndex(es
, l
);
984 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
987 line_def
= es
->first_line_def
;
988 index
-= line_def
->length
;
989 while ((index
>= 0) && line_def
->next
) {
990 line_def
= line_def
->next
;
991 index
-= line_def
->length
;
993 return line_def
->net_length
;
997 /*********************************************************************
1002 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1004 INT len
= get_text_length(es
);
1013 index
= min(index
, len
);
1014 if (es
->style
& ES_MULTILINE
) {
1015 l
= EDIT_EM_LineFromChar(es
, index
);
1016 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1018 y
= (l
- es
->y_offset
) * es
->line_height
;
1019 li
= EDIT_EM_LineIndex(es
, l
);
1020 if (after_wrap
&& (li
== index
) && l
) {
1022 line_def
= es
->first_line_def
;
1024 line_def
= line_def
->next
;
1027 if (line_def
->ending
== END_WRAP
) {
1029 y
-= es
->line_height
;
1030 li
= EDIT_EM_LineIndex(es
, l
);
1034 line_def
= es
->first_line_def
;
1035 while (line_def
->index
!= li
)
1036 line_def
= line_def
->next
;
1038 lw
= line_def
->width
;
1039 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1041 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1044 if (es
->style
& ES_RIGHT
)
1046 else if (es
->style
& ES_CENTER
)
1051 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1056 if (es
->x_offset
>= get_text_length(es
))
1058 int leftover
= es
->x_offset
- get_text_length(es
);
1062 size
= ScriptString_pSize(es
->ssa
);
1067 xoff
+= es
->char_width
* leftover
;
1070 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1077 if (index
>= get_text_length(es
))
1082 size
= ScriptString_pSize(es
->ssa
);
1089 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1095 if (index
>= es
->x_offset
) {
1096 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1098 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1099 if (w
> es
->text_width
)
1101 if (es
->style
& ES_RIGHT
)
1102 x
+= w
- es
->text_width
;
1103 else if (es
->style
& ES_CENTER
)
1104 x
+= (w
- es
->text_width
) / 2;
1110 x
+= es
->format_rect
.left
;
1111 y
+= es
->format_rect
.top
;
1112 return MAKELONG((INT16
)x
, (INT16
)y
);
1116 /*********************************************************************
1120 * Calculates the bounding rectangle for a line from a starting
1121 * column to an ending column.
1124 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1126 SCRIPT_STRING_ANALYSIS ssa
;
1130 if (es
->style
& ES_MULTILINE
)
1132 const LINEDEF
*line_def
= NULL
;
1133 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1134 if (line
>= es
->line_count
)
1137 line_def
= es
->first_line_def
;
1139 INT index
= es
->selection_end
- line_def
->length
;
1140 while ((index
>= 0) && line_def
->next
) {
1141 line_index
+= line_def
->length
;
1142 line_def
= line_def
->next
;
1143 index
-= line_def
->length
;
1147 line_index
+= line_def
->length
;
1148 line_def
= line_def
->next
;
1152 ssa
= line_def
->ssa
;
1157 rc
->top
= es
->format_rect
.top
;
1161 rc
->bottom
= rc
->top
+ es
->line_height
;
1162 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1163 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1166 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1167 pt3
+=es
->format_rect
.left
;
1170 rc
->right
= max(max(pt1
, pt2
),pt3
);
1171 rc
->left
= min(min(pt1
, pt2
),pt3
);
1175 static inline void text_buffer_changed(EDITSTATE
*es
)
1177 es
->text_length
= (UINT
)-1;
1179 heap_free( es
->logAttr
);
1181 EDIT_InvalidateUniscribeData(es
);
1184 /*********************************************************************
1188 static void EDIT_LockBuffer(EDITSTATE
*es
)
1195 es
->text
= LocalLock(es
->hloc32W
);
1202 /*********************************************************************
1207 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1209 /* Edit window might be already destroyed */
1210 if (!IsWindow(es
->hwndSelf
))
1212 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1216 if (!es
->lock_count
)
1218 ERR("lock_count == 0 ... please report\n");
1224 ERR("es->text == 0 ... please report\n");
1228 if (force
|| (es
->lock_count
== 1))
1232 LocalUnlock(es
->hloc32W
);
1237 ERR("no buffer ... please report\n");
1247 /*********************************************************************
1251 * Try to fit size + 1 characters in the buffer.
1253 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1257 if (size
<= es
->buffer_size
)
1260 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1262 /* Force edit to unlock its buffer. es->text now NULL */
1263 EDIT_UnlockBuffer(es
, TRUE
);
1266 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1267 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1268 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1269 es
->hloc32W
= hNew32W
;
1270 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1274 EDIT_LockBuffer(es
);
1276 if (es
->buffer_size
< size
) {
1277 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1278 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1281 TRACE("We now have %d+1\n", es
->buffer_size
);
1287 /*********************************************************************
1291 * Try to fit size + 1 bytes in the undo buffer.
1294 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1298 if (size
<= es
->undo_buffer_size
)
1301 TRACE("trying to ReAlloc to %d+1\n", size
);
1303 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1304 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1305 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1310 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1316 /*********************************************************************
1318 * EDIT_UpdateTextRegion
1321 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1323 if (es
->flags
& EF_UPDATE
) {
1324 es
->flags
&= ~EF_UPDATE
;
1325 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1327 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1331 /*********************************************************************
1336 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1338 if (es
->flags
& EF_UPDATE
) {
1339 es
->flags
&= ~EF_UPDATE
;
1340 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1342 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1345 /*********************************************************************
1347 * EDIT_SL_InvalidateText
1349 * Called from EDIT_InvalidateText().
1350 * Does the job for single-line controls only.
1353 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1358 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1359 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1360 EDIT_UpdateText(es
, &rc
, TRUE
);
1363 /*********************************************************************
1365 * EDIT_ML_InvalidateText
1367 * Called from EDIT_InvalidateText().
1368 * Does the job for multi-line controls only.
1371 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1373 INT vlc
= get_vertical_line_count(es
);
1374 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1375 INT el
= EDIT_EM_LineFromChar(es
, end
);
1384 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1387 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1388 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1389 if (sl
< es
->y_offset
) {
1393 if (el
> es
->y_offset
+ vlc
) {
1394 el
= es
->y_offset
+ vlc
;
1395 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1397 GetClientRect(es
->hwndSelf
, &rc1
);
1398 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1400 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1401 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1402 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1404 EDIT_GetLineRect(es
, sl
, sc
,
1405 EDIT_EM_LineLength(es
,
1406 EDIT_EM_LineIndex(es
, sl
)),
1408 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1409 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1410 for (l
= sl
+ 1 ; l
< el
; l
++) {
1411 EDIT_GetLineRect(es
, l
, 0,
1412 EDIT_EM_LineLength(es
,
1413 EDIT_EM_LineIndex(es
, l
)),
1415 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1416 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1418 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1419 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1420 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1425 /*********************************************************************
1427 * EDIT_InvalidateText
1429 * Invalidate the text from offset start up to, but not including,
1430 * offset end. Useful for (re)painting the selection.
1431 * Regions outside the linewidth are not invalidated.
1432 * end == -1 means end == TextLength.
1433 * start and end need not be ordered.
1436 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1442 end
= get_text_length(es
);
1450 if (es
->style
& ES_MULTILINE
)
1451 EDIT_ML_InvalidateText(es
, start
, end
);
1453 EDIT_SL_InvalidateText(es
, start
, end
);
1457 /*********************************************************************
1461 * note: unlike the specs say: the order of start and end
1462 * _is_ preserved in Windows. (i.e. start can be > end)
1463 * In other words: this handler is OK
1466 static BOOL
EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1468 UINT old_start
= es
->selection_start
;
1469 UINT old_end
= es
->selection_end
;
1470 UINT len
= get_text_length(es
);
1472 if (start
== old_start
&& end
== old_end
)
1475 if (start
== (UINT
)-1) {
1476 start
= es
->selection_end
;
1477 end
= es
->selection_end
;
1479 start
= min(start
, len
);
1480 end
= min(end
, len
);
1482 es
->selection_start
= start
;
1483 es
->selection_end
= end
;
1485 es
->flags
|= EF_AFTER_WRAP
;
1487 es
->flags
&= ~EF_AFTER_WRAP
;
1488 /* Compute the necessary invalidation region. */
1489 /* Note that we don't need to invalidate regions which have
1490 * "never" been selected, or those which are "still" selected.
1491 * In fact, every time we hit a selection boundary, we can
1492 * *toggle* whether we need to invalidate. Thus we can optimize by
1493 * *sorting* the interval endpoints. Let's assume that we sort them
1495 * start <= end <= old_start <= old_end
1496 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1497 * in 5 comparisons; i.e. it is impossible to do better than the
1499 ORDER_UINT(end
, old_end
);
1500 ORDER_UINT(start
, old_start
);
1501 ORDER_UINT(old_start
, old_end
);
1502 ORDER_UINT(start
, end
);
1503 /* Note that at this point 'end' and 'old_start' are not in order, but
1504 * start is definitely the min. and old_end is definitely the max. */
1505 if (end
!= old_start
)
1509 * ORDER_UINT32(end, old_start);
1510 * EDIT_InvalidateText(es, start, end);
1511 * EDIT_InvalidateText(es, old_start, old_end);
1512 * in place of the following if statement.
1513 * (That would complete the optimal five-comparison four-element sort.)
1515 if (old_start
> end
)
1517 EDIT_InvalidateText(es
, start
, end
);
1518 EDIT_InvalidateText(es
, old_start
, old_end
);
1522 EDIT_InvalidateText(es
, start
, old_start
);
1523 EDIT_InvalidateText(es
, end
, old_end
);
1526 else EDIT_InvalidateText(es
, start
, old_end
);
1532 /*********************************************************************
1534 * EDIT_UpdateScrollInfo
1537 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1539 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1542 si
.cbSize
= sizeof(SCROLLINFO
);
1543 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1545 si
.nMax
= es
->line_count
- 1;
1546 si
.nPage
= es
->line_height
? (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
: 0;
1547 si
.nPos
= es
->y_offset
;
1548 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1549 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1550 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1553 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1556 si
.cbSize
= sizeof(SCROLLINFO
);
1557 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1559 si
.nMax
= es
->text_width
- 1;
1560 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1561 si
.nPos
= es
->x_offset
;
1562 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1563 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1564 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1569 /*********************************************************************
1571 * EDIT_EM_LineScroll_internal
1573 * Version of EDIT_EM_LineScroll for internal use.
1574 * It doesn't refuse if ES_MULTILINE is set and assumes that
1575 * dx is in pixels, dy - in lines.
1578 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1581 INT x_offset_in_pixels
;
1584 if (!es
->line_height
|| !es
->char_width
)
1587 lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1589 if (es
->style
& ES_MULTILINE
)
1591 x_offset_in_pixels
= es
->x_offset
;
1596 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1599 if (-dx
> x_offset_in_pixels
)
1600 dx
= -x_offset_in_pixels
;
1601 if (dx
> es
->text_width
- x_offset_in_pixels
)
1602 dx
= es
->text_width
- x_offset_in_pixels
;
1603 nyoff
= max(0, es
->y_offset
+ dy
);
1604 if (nyoff
>= es
->line_count
- lines_per_page
)
1605 nyoff
= max(0, es
->line_count
- lines_per_page
);
1606 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1611 es
->y_offset
= nyoff
;
1612 if(es
->style
& ES_MULTILINE
)
1615 es
->x_offset
+= dx
/ es
->char_width
;
1617 GetClientRect(es
->hwndSelf
, &rc1
);
1618 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1619 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1620 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1621 /* force scroll info update */
1622 EDIT_UpdateScrollInfo(es
);
1624 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1625 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1626 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1627 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1631 /*********************************************************************
1635 * NOTE: dx is in average character widths, dy - in lines;
1638 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1640 if (!(es
->style
& ES_MULTILINE
))
1643 dx
*= es
->char_width
;
1644 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1648 /*********************************************************************
1653 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1657 if (!(es
->style
& ES_MULTILINE
))
1658 return (LRESULT
)FALSE
;
1668 if (es
->y_offset
< es
->line_count
- 1)
1673 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1676 if (es
->y_offset
< es
->line_count
- 1)
1677 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1680 return (LRESULT
)FALSE
;
1683 INT vlc
= get_vertical_line_count(es
);
1684 /* check if we are going to move too far */
1685 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1686 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1688 /* Notification is done in EDIT_EM_LineScroll */
1690 EDIT_EM_LineScroll(es
, 0, dy
);
1691 return MAKELONG(dy
, TRUE
);
1695 return (LRESULT
)FALSE
;
1699 /*********************************************************************
1704 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1709 if (es
->flags
& EF_FOCUSED
)
1711 res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1712 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1713 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1718 /*********************************************************************
1723 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1725 if (es
->style
& ES_MULTILINE
) {
1729 INT cw
= es
->char_width
;
1734 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1735 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1736 vlc
= get_vertical_line_count(es
);
1737 if (l
>= es
->y_offset
+ vlc
)
1738 dy
= l
- vlc
+ 1 - es
->y_offset
;
1739 if (l
< es
->y_offset
)
1740 dy
= l
- es
->y_offset
;
1741 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1742 if (x
< es
->format_rect
.left
)
1743 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1744 if (x
> es
->format_rect
.right
)
1745 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1746 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1748 /* check if we are going to move too far */
1749 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1750 dx
= es
->text_width
- ww
- es
->x_offset
;
1751 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1752 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1759 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1760 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1761 if (x
< es
->format_rect
.left
) {
1762 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1765 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1766 } while ((x
< goal
) && es
->x_offset
);
1767 /* FIXME: use ScrollWindow() somehow to improve performance */
1768 EDIT_UpdateText(es
, NULL
, TRUE
);
1769 } else if (x
> es
->format_rect
.right
) {
1771 INT len
= get_text_length(es
);
1772 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1775 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1776 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1777 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1778 /* FIXME: use ScrollWindow() somehow to improve performance */
1779 EDIT_UpdateText(es
, NULL
, TRUE
);
1783 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1787 /*********************************************************************
1792 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1794 INT e
= es
->selection_end
;
1798 if ((es
->style
& ES_MULTILINE
) && e
&&
1799 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1801 if (e
&& (es
->text
[e
- 1] == '\r'))
1805 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1806 EDIT_EM_ScrollCaret(es
);
1810 /*********************************************************************
1814 * Only for multi line controls
1815 * Move the caret one line down, on a column with the nearest
1816 * x coordinate on the screen (might be a different column).
1819 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1821 INT s
= es
->selection_start
;
1822 INT e
= es
->selection_end
;
1823 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1824 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1825 INT x
= (short)LOWORD(pos
);
1826 INT y
= (short)HIWORD(pos
);
1828 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1831 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1832 EDIT_EM_ScrollCaret(es
);
1836 /*********************************************************************
1841 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1843 BOOL after_wrap
= FALSE
;
1846 /* Pass a high value in x to make sure of receiving the end of the line */
1847 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1848 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1849 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1851 e
= get_text_length(es
);
1852 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1853 EDIT_EM_ScrollCaret(es
);
1857 /*********************************************************************
1862 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1864 INT e
= es
->selection_end
;
1868 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1869 if (es
->text
[e
] == '\n')
1871 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1875 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1876 EDIT_EM_ScrollCaret(es
);
1880 /*********************************************************************
1884 * Home key: move to beginning of line.
1887 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1891 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1892 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1893 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1894 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1897 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1898 EDIT_EM_ScrollCaret(es
);
1902 /*********************************************************************
1904 * EDIT_MovePageDown_ML
1906 * Only for multi line controls
1907 * Move the caret one page down, on a column with the nearest
1908 * x coordinate on the screen (might be a different column).
1911 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
1913 INT s
= es
->selection_start
;
1914 INT e
= es
->selection_end
;
1915 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1916 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1917 INT x
= (short)LOWORD(pos
);
1918 INT y
= (short)HIWORD(pos
);
1920 e
= EDIT_CharFromPos(es
, x
,
1921 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
1925 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1926 EDIT_EM_ScrollCaret(es
);
1930 /*********************************************************************
1932 * EDIT_MovePageUp_ML
1934 * Only for multi line controls
1935 * Move the caret one page up, on a column with the nearest
1936 * x coordinate on the screen (might be a different column).
1939 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
1941 INT s
= es
->selection_start
;
1942 INT e
= es
->selection_end
;
1943 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1944 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1945 INT x
= (short)LOWORD(pos
);
1946 INT y
= (short)HIWORD(pos
);
1948 e
= EDIT_CharFromPos(es
, x
,
1949 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
1953 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1954 EDIT_EM_ScrollCaret(es
);
1958 /*********************************************************************
1962 * Only for multi line controls
1963 * Move the caret one line up, on a column with the nearest
1964 * x coordinate on the screen (might be a different column).
1967 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
1969 INT s
= es
->selection_start
;
1970 INT e
= es
->selection_end
;
1971 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1972 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1973 INT x
= (short)LOWORD(pos
);
1974 INT y
= (short)HIWORD(pos
);
1976 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
1979 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1980 EDIT_EM_ScrollCaret(es
);
1984 /*********************************************************************
1986 * EDIT_MoveWordBackward
1989 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
1991 INT s
= es
->selection_start
;
1992 INT e
= es
->selection_end
;
1997 l
= EDIT_EM_LineFromChar(es
, e
);
1998 ll
= EDIT_EM_LineLength(es
, e
);
1999 li
= EDIT_EM_LineIndex(es
, l
);
2002 li
= EDIT_EM_LineIndex(es
, l
- 1);
2003 e
= li
+ EDIT_EM_LineLength(es
, li
);
2006 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2010 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2011 EDIT_EM_ScrollCaret(es
);
2015 /*********************************************************************
2017 * EDIT_MoveWordForward
2020 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2022 INT s
= es
->selection_start
;
2023 INT e
= es
->selection_end
;
2028 l
= EDIT_EM_LineFromChar(es
, e
);
2029 ll
= EDIT_EM_LineLength(es
, e
);
2030 li
= EDIT_EM_LineIndex(es
, l
);
2032 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2033 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2035 e
= li
+ EDIT_CallWordBreakProc(es
,
2036 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2040 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2041 EDIT_EM_ScrollCaret(es
);
2045 /*********************************************************************
2050 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2054 LOGFONTW underline_font
;
2055 HFONT hUnderline
= 0;
2064 BkMode
= GetBkMode(dc
);
2065 BkColor
= GetBkColor(dc
);
2066 TextColor
= GetTextColor(dc
);
2068 if (es
->composition_len
== 0)
2070 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2071 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2072 SetBkMode( dc
, OPAQUE
);
2076 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2077 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2078 underline_font
.lfUnderline
= TRUE
;
2079 hUnderline
= CreateFontIndirectW(&underline_font
);
2080 old_font
= SelectObject(dc
,hUnderline
);
2083 li
= EDIT_EM_LineIndex(es
, line
);
2084 if (es
->style
& ES_MULTILINE
) {
2085 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2086 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2088 TextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
);
2089 GetTextExtentPoint32W(dc
, es
->text
+ li
+ col
, count
, &size
);
2093 if (es
->composition_len
== 0)
2095 SetBkColor(dc
, BkColor
);
2096 SetTextColor(dc
, TextColor
);
2097 SetBkMode( dc
, BkMode
);
2102 SelectObject(dc
,old_font
);
2104 DeleteObject(hUnderline
);
2111 /*********************************************************************
2116 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2125 SCRIPT_STRING_ANALYSIS ssa
;
2127 if (es
->style
& ES_MULTILINE
) {
2128 INT vlc
= get_vertical_line_count(es
);
2130 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2135 TRACE("line=%d\n", line
);
2137 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2138 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2139 x
= (short)LOWORD(pos
);
2140 y
= (short)HIWORD(pos
);
2142 if (es
->style
& ES_MULTILINE
)
2144 int line_idx
= line
;
2146 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2148 LINEDEF
*line_def
= es
->first_line_def
;
2151 while (line_def
&& line_idx
)
2153 line_def
= line_def
->next
;
2156 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2157 lw
= line_def
->width
;
2159 if (es
->style
& ES_RIGHT
)
2161 else if (es
->style
& ES_CENTER
)
2164 x
+= es
->format_rect
.left
;
2169 li
= EDIT_EM_LineIndex(es
, line
);
2170 ll
= EDIT_EM_LineLength(es
, li
);
2171 s
= min(es
->selection_start
, es
->selection_end
);
2172 e
= max(es
->selection_start
, es
->selection_end
);
2173 s
= min(li
+ ll
, max(li
, s
));
2174 e
= min(li
+ ll
, max(li
, e
));
2178 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2179 else if (rev
&& (s
!= e
) &&
2180 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2181 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2182 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2183 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2185 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2187 if (es
->cue_banner_text
&& es
->text_length
== 0 && (!(es
->flags
& EF_FOCUSED
) || es
->cue_banner_draw_focused
))
2189 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
2190 TextOutW(dc
, x
, y
, es
->cue_banner_text
, lstrlenW(es
->cue_banner_text
));
2195 /*********************************************************************
2197 * EDIT_AdjustFormatRect
2199 * Adjusts the format rectangle for the current font and the
2200 * current client rectangle.
2203 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2207 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2208 if (es
->style
& ES_MULTILINE
)
2210 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2212 vlc
= get_vertical_line_count(es
);
2213 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2215 /* correct es->x_offset */
2216 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2217 max_x_offset
= es
->text_width
- fw
;
2218 if(max_x_offset
< 0) max_x_offset
= 0;
2219 if(es
->x_offset
> max_x_offset
)
2220 es
->x_offset
= max_x_offset
;
2222 /* correct es->y_offset */
2223 max_y_offset
= es
->line_count
- vlc
;
2224 if(max_y_offset
< 0) max_y_offset
= 0;
2225 if(es
->y_offset
> max_y_offset
)
2226 es
->y_offset
= max_y_offset
;
2228 /* force scroll info update */
2229 EDIT_UpdateScrollInfo(es
);
2232 /* Windows doesn't care to fix text placement for SL controls */
2233 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2235 /* Always stay within the client area */
2236 GetClientRect(es
->hwndSelf
, &ClientRect
);
2237 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2239 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2240 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2242 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2246 /*********************************************************************
2250 * note: this is not (exactly) the handler called on EM_SETRECTNP
2251 * it is also used to set the rect of a single line control
2254 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2258 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2260 CopyRect(&es
->format_rect
, rc
);
2262 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2263 es
->format_rect
.left
++;
2264 es
->format_rect
.right
--;
2266 if (es
->format_rect
.bottom
- es
->format_rect
.top
2267 >= es
->line_height
+ 2)
2269 es
->format_rect
.top
++;
2270 es
->format_rect
.bottom
--;
2273 else if (es
->style
& WS_BORDER
) {
2274 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2275 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2276 InflateRect(&es
->format_rect
, -bw
, 0);
2277 if (es
->format_rect
.bottom
- es
->format_rect
.top
>= es
->line_height
+ 2 * bh
)
2278 InflateRect(&es
->format_rect
, 0, -bh
);
2281 es
->format_rect
.left
+= es
->left_margin
;
2282 es
->format_rect
.right
-= es
->right_margin
;
2283 EDIT_AdjustFormatRect(es
);
2287 /*********************************************************************
2291 * returns line number (not index) in high-order word of result.
2292 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2293 * to Richedit, not to the edit control. Original documentation is valid.
2294 * FIXME: do the specs mean to return -1 if outside client area or
2295 * if outside formatting rectangle ???
2298 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2306 GetClientRect(es
->hwndSelf
, &rc
);
2307 if (!PtInRect(&rc
, pt
))
2310 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2311 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2315 /*********************************************************************
2319 * Enable or disable soft breaks.
2321 * This means: insert or remove the soft linebreak character (\r\r\n).
2322 * Take care to check if the text still fits the buffer after insertion.
2323 * If not, notify with EN_ERRSPACE.
2326 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2328 es
->flags
&= ~EF_USE_SOFTBRK
;
2330 es
->flags
|= EF_USE_SOFTBRK
;
2331 FIXME("soft break enabled, not implemented\n");
2337 /*********************************************************************
2341 * Hopefully this won't fire back at us.
2342 * We always start with a fixed buffer in the local heap.
2343 * Despite of the documentation says that the local heap is used
2344 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2345 * buffer on the local heap.
2348 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2350 if (!(es
->style
& ES_MULTILINE
))
2353 EDIT_UnlockBuffer(es
, TRUE
);
2355 /* The text buffer handle belongs to the app */
2356 es
->hlocapp
= es
->hloc32W
;
2358 TRACE("Returning %p, LocalSize() = %ld\n", es
->hlocapp
, LocalSize(es
->hlocapp
));
2363 /*********************************************************************
2368 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
)
2370 INT line_len
, dst_len
;
2374 if (es
->style
& ES_MULTILINE
)
2376 if (line
>= es
->line_count
)
2382 i
= EDIT_EM_LineIndex(es
, line
);
2384 line_len
= EDIT_EM_LineLength(es
, i
);
2385 dst_len
= *(WORD
*)dst
;
2387 if (dst_len
<= line_len
)
2389 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2392 else /* Append 0 if enough space */
2394 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2401 /*********************************************************************
2406 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2408 UINT s
= es
->selection_start
;
2409 UINT e
= es
->selection_end
;
2416 return MAKELONG(s
, e
);
2420 /*********************************************************************
2424 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2427 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, const WCHAR
*lpsz_replace
, UINT strl
,
2428 BOOL send_update
, BOOL honor_limit
)
2430 UINT tl
= get_text_length(es
);
2441 TRACE("%s, can_undo %d, send_update %d\n",
2442 debugstr_wn(lpsz_replace
, strl
), can_undo
, send_update
);
2444 s
= es
->selection_start
;
2445 e
= es
->selection_end
;
2447 EDIT_InvalidateUniscribeData(es
);
2448 if ((s
== e
) && !strl
)
2453 size
= tl
- (e
- s
) + strl
;
2457 /* Issue the EN_MAXTEXT notification and continue with replacing text
2458 * so that buffer limit is honored. */
2459 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2460 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2461 /* Buffer limit can be smaller than the actual length of text in combobox */
2462 if (es
->buffer_limit
< (tl
- (e
-s
)))
2465 strl
= min(strl
, es
->buffer_limit
- (tl
- (e
-s
)));
2468 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2472 /* there is something to be deleted */
2473 TRACE("deleting stuff.\n");
2475 buf
= heap_alloc((bufl
+ 1) * sizeof(WCHAR
));
2477 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2478 buf
[bufl
] = 0; /* ensure 0 termination */
2480 lstrcpyW(es
->text
+ s
, es
->text
+ e
);
2481 text_buffer_changed(es
);
2484 /* there is an insertion */
2485 tl
= get_text_length(es
);
2486 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
));
2487 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2489 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2490 p
[i
] = lpsz_replace
[i
];
2491 if(es
->style
& ES_UPPERCASE
)
2492 CharUpperBuffW(p
, strl
);
2493 else if(es
->style
& ES_LOWERCASE
)
2494 CharLowerBuffW(p
, strl
);
2495 text_buffer_changed(es
);
2497 if (es
->style
& ES_MULTILINE
)
2499 INT st
= min(es
->selection_start
, es
->selection_end
);
2500 INT vlc
= get_vertical_line_count(es
);
2502 hrgn
= CreateRectRgn(0, 0, 0, 0);
2503 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2504 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2505 /* if text is too long undo all changes */
2506 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2508 lstrcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2510 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2512 text_buffer_changed(es
);
2513 EDIT_BuildLineDefs_ML(es
, s
, e
,
2514 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2517 hrgn
= CreateRectRgn(0, 0, 0, 0);
2518 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2522 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2523 EDIT_InvalidateUniscribeData(es
);
2524 EDIT_CalcLineWidth_SL(es
);
2525 /* remove chars that don't fit */
2526 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2527 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2528 lstrcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2530 es
->text_length
= -1;
2531 EDIT_InvalidateUniscribeData(es
);
2532 EDIT_CalcLineWidth_SL(es
);
2534 text_buffer_changed(es
);
2535 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2541 utl
= lstrlenW(es
->undo_text
);
2542 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2543 /* undo-buffer is extended to the right */
2544 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2545 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2546 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2547 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2548 /* undo-buffer is extended to the left */
2549 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2550 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2552 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2554 es
->undo_position
= s
;
2556 /* new undo-buffer */
2557 EDIT_MakeUndoFit(es
, e
- s
);
2558 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2559 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2560 es
->undo_position
= s
;
2562 /* any deletion makes the old insertion-undo invalid */
2563 es
->undo_insert_count
= 0;
2565 EDIT_EM_EmptyUndoBuffer(es
);
2569 if ((s
== es
->undo_position
) ||
2570 ((es
->undo_insert_count
) &&
2571 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2573 * insertion is new and at delete position or
2574 * an extension to either left or right
2576 es
->undo_insert_count
+= strl
;
2578 /* new insertion undo */
2579 es
->undo_position
= s
;
2580 es
->undo_insert_count
= strl
;
2581 /* new insertion makes old delete-buffer invalid */
2582 *es
->undo_text
= '\0';
2585 EDIT_EM_EmptyUndoBuffer(es
);
2592 /* If text has been deleted and we're right or center aligned then scroll rightward */
2593 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2595 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2597 if (delta
< 0 && es
->x_offset
)
2599 if (abs(delta
) > es
->x_offset
)
2602 es
->x_offset
+= delta
;
2606 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2607 es
->flags
|= EF_MODIFIED
;
2608 if (send_update
) es
->flags
|= EF_UPDATE
;
2611 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2615 EDIT_UpdateText(es
, NULL
, TRUE
);
2617 EDIT_EM_ScrollCaret(es
);
2619 /* force scroll info update */
2620 EDIT_UpdateScrollInfo(es
);
2623 if(send_update
|| (es
->flags
& EF_UPDATE
))
2625 es
->flags
&= ~EF_UPDATE
;
2626 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2628 EDIT_InvalidateUniscribeData(es
);
2632 /*********************************************************************
2636 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2639 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2641 if (!(es
->style
& ES_MULTILINE
))
2647 EDIT_UnlockBuffer(es
, TRUE
);
2650 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2652 /* The text buffer handle belongs to the control */
2655 EDIT_LockBuffer(es
);
2656 text_buffer_changed(es
);
2658 es
->x_offset
= es
->y_offset
= 0;
2659 es
->selection_start
= es
->selection_end
= 0;
2660 EDIT_EM_EmptyUndoBuffer(es
);
2661 es
->flags
&= ~EF_MODIFIED
;
2662 es
->flags
&= ~EF_UPDATE
;
2663 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2664 EDIT_UpdateText(es
, NULL
, TRUE
);
2665 EDIT_EM_ScrollCaret(es
);
2666 /* force scroll info update */
2667 EDIT_UpdateScrollInfo(es
);
2671 /*********************************************************************
2675 * NOTE: this version currently implements WinNT limits
2678 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2680 if (!limit
) limit
= ~0u;
2681 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2682 es
->buffer_limit
= limit
;
2685 static BOOL
is_cjk(HDC dc
)
2687 const DWORD FS_DBCS_MASK
= FS_JISJAPAN
|FS_CHINESESIMP
|FS_WANSUNG
|FS_CHINESETRAD
|FS_JOHAB
;
2690 switch (GdiGetCodePage(dc
)) {
2691 case 932: case 936: case 949: case 950: case 1361:
2694 return (GetTextCharsetInfo(dc
, &fs
, 0) != DEFAULT_CHARSET
&&
2695 (fs
.fsCsb
[0] & FS_DBCS_MASK
));
2699 static int get_cjk_fontinfo_margin(int width
, int side_bearing
)
2702 if (side_bearing
< 0)
2703 margin
= min(-side_bearing
, width
/2);
2709 struct char_width_info
{
2710 INT min_lsb
, min_rsb
, unknown
;
2713 /* Undocumented gdi32 export */
2714 extern BOOL WINAPI
GetCharWidthInfo(HDC
, struct char_width_info
*);
2716 /*********************************************************************
2720 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2721 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2722 * margin according to the textmetrics of the current font.
2724 * When EC_USEFONTINFO is used, the margins only change if the edit control is
2725 * equal to or larger than a certain size. The empty client rect is treated as
2728 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2729 WORD left
, WORD right
, BOOL repaint
)
2732 INT default_left_margin
= 0; /* in pixels */
2733 INT default_right_margin
= 0; /* in pixels */
2735 /* Set the default margins depending on the font */
2736 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2737 HDC dc
= GetDC(es
->hwndSelf
);
2738 HFONT old_font
= SelectObject(dc
, es
->font
);
2739 LONG width
= GdiGetCharDimensions(dc
, &tm
, NULL
), rc_width
;
2742 /* The default margins are only non zero for TrueType or Vector fonts */
2743 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2744 struct char_width_info width_info
;
2746 if (is_cjk(dc
) && GetCharWidthInfo(dc
, &width_info
))
2748 default_left_margin
= get_cjk_fontinfo_margin(width
, width_info
.min_lsb
);
2749 default_right_margin
= get_cjk_fontinfo_margin(width
, width_info
.min_rsb
);
2753 default_left_margin
= width
/ 2;
2754 default_right_margin
= width
/ 2;
2757 GetClientRect(es
->hwndSelf
, &rc
);
2758 rc_width
= !IsRectEmpty(&rc
) ? rc
.right
- rc
.left
: 80;
2759 if (rc_width
< default_left_margin
+ default_right_margin
+ width
* 2) {
2760 default_left_margin
= es
->left_margin
;
2761 default_right_margin
= es
->right_margin
;
2764 SelectObject(dc
, old_font
);
2765 ReleaseDC(es
->hwndSelf
, dc
);
2768 if (action
& EC_LEFTMARGIN
) {
2769 es
->format_rect
.left
-= es
->left_margin
;
2770 if (left
!= EC_USEFONTINFO
)
2771 es
->left_margin
= left
;
2773 es
->left_margin
= default_left_margin
;
2774 es
->format_rect
.left
+= es
->left_margin
;
2777 if (action
& EC_RIGHTMARGIN
) {
2778 es
->format_rect
.right
+= es
->right_margin
;
2779 if (right
!= EC_USEFONTINFO
)
2780 es
->right_margin
= right
;
2782 es
->right_margin
= default_right_margin
;
2783 es
->format_rect
.right
-= es
->right_margin
;
2786 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2787 EDIT_AdjustFormatRect(es
);
2788 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2791 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2795 /*********************************************************************
2797 * EM_SETPASSWORDCHAR
2800 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2804 if (es
->style
& ES_MULTILINE
)
2807 if (es
->password_char
== c
)
2810 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2811 es
->password_char
= c
;
2813 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2814 es
->style
|= ES_PASSWORD
;
2816 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2817 es
->style
&= ~ES_PASSWORD
;
2819 EDIT_InvalidateUniscribeData(es
);
2820 EDIT_UpdateText(es
, NULL
, TRUE
);
2824 /*********************************************************************
2829 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2831 if (!(es
->style
& ES_MULTILINE
))
2833 heap_free(es
->tabs
);
2834 es
->tabs_count
= count
;
2838 es
->tabs
= heap_alloc(count
* sizeof(INT
));
2839 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2841 EDIT_InvalidateUniscribeData(es
);
2846 /*********************************************************************
2848 * EM_SETWORDBREAKPROC
2851 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, EDITWORDBREAKPROCW wbp
)
2853 if (es
->word_break_proc
== wbp
)
2856 es
->word_break_proc
= wbp
;
2858 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
2859 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2860 EDIT_UpdateText(es
, NULL
, TRUE
);
2865 /*********************************************************************
2870 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
2875 /* As per MSDN spec, for a single-line edit control,
2876 the return value is always TRUE */
2877 if( es
->style
& ES_READONLY
)
2878 return !(es
->style
& ES_MULTILINE
);
2880 ulength
= lstrlenW(es
->undo_text
);
2882 utext
= heap_alloc((ulength
+ 1) * sizeof(WCHAR
));
2884 lstrcpyW(utext
, es
->undo_text
);
2886 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2887 es
->undo_insert_count
, debugstr_w(utext
));
2889 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2890 EDIT_EM_EmptyUndoBuffer(es
);
2891 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, ulength
, TRUE
, TRUE
);
2892 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
2893 /* send the notification after the selection start and end are set */
2894 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2895 EDIT_EM_ScrollCaret(es
);
2898 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2899 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
2904 /* Helper function for WM_CHAR
2906 * According to an MSDN blog article titled "Just because you're a control
2907 * doesn't mean that you're necessarily inside a dialog box," multiline edit
2908 * controls without ES_WANTRETURN would attempt to detect whether it is inside
2909 * a dialog box or not.
2911 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
2913 return (es
->flags
& EF_DIALOGMODE
);
2917 /*********************************************************************
2922 static void EDIT_WM_Paste(EDITSTATE
*es
)
2928 /* Protect read-only edit control from modification */
2929 if(es
->style
& ES_READONLY
)
2932 OpenClipboard(es
->hwndSelf
);
2933 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
2934 src
= GlobalLock(hsrc
);
2935 len
= lstrlenW(src
);
2936 /* Protect single-line edit against pasting new line character */
2937 if (!(es
->style
& ES_MULTILINE
) && ((ptr
= wcschr(src
, '\n')))) {
2939 if (len
&& src
[len
- 1] == '\r')
2942 EDIT_EM_ReplaceSel(es
, TRUE
, src
, len
, TRUE
, TRUE
);
2945 else if (es
->style
& ES_PASSWORD
) {
2946 /* clear selected text in password edit box even with empty clipboard */
2947 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2953 /*********************************************************************
2958 static void EDIT_WM_Copy(EDITSTATE
*es
)
2960 INT s
= min(es
->selection_start
, es
->selection_end
);
2961 INT e
= max(es
->selection_start
, es
->selection_end
);
2969 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
2970 dst
= GlobalLock(hdst
);
2971 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
2972 dst
[len
] = 0; /* ensure 0 termination */
2973 TRACE("%s\n", debugstr_w(dst
));
2975 OpenClipboard(es
->hwndSelf
);
2977 SetClipboardData(CF_UNICODETEXT
, hdst
);
2982 /*********************************************************************
2987 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
2989 /* Protect read-only edit control from modification */
2990 if(es
->style
& ES_READONLY
)
2993 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
2997 /*********************************************************************
3002 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3009 /*********************************************************************
3014 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3018 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3022 /* If it's not a multiline edit box, it would be ignored below.
3023 * For multiline edit without ES_WANTRETURN, we have to make a
3026 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3027 if (EDIT_IsInsideDialog(es
))
3030 if (es
->style
& ES_MULTILINE
) {
3031 if (es
->style
& ES_READONLY
) {
3032 EDIT_MoveHome(es
, FALSE
, FALSE
);
3033 EDIT_MoveDown_ML(es
, FALSE
);
3035 EDIT_EM_ReplaceSel(es
, TRUE
, L
"\r\n", 2, TRUE
, TRUE
);
3039 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3041 if (EDIT_IsInsideDialog(es
))
3043 EDIT_EM_ReplaceSel(es
, TRUE
, L
"\t", 1, TRUE
, TRUE
);
3047 if (!(es
->style
& ES_READONLY
) && !control
) {
3048 if (es
->selection_start
!= es
->selection_end
)
3051 /* delete character left of caret */
3052 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3053 EDIT_MoveBackward(es
, TRUE
);
3059 if (!(es
->style
& ES_PASSWORD
))
3060 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3063 if (!(es
->style
& ES_READONLY
))
3064 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3067 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3068 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3071 if (!(es
->style
& ES_READONLY
))
3072 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3076 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3077 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3080 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127))
3081 EDIT_EM_ReplaceSel(es
, TRUE
, &c
, 1, TRUE
, TRUE
);
3088 /*********************************************************************
3090 * EDIT_ContextMenuCommand
3093 static void EDIT_ContextMenuCommand(EDITSTATE
*es
, UINT id
)
3097 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3100 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3103 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3106 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3109 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3112 SendMessageW(es
->hwndSelf
, EM_SETSEL
, 0, -1);
3115 ERR("unknown menu item, please report\n");
3121 /*********************************************************************
3125 * Note: the resource files resource/sysres_??.rc cannot define a
3126 * single popup menu. Hence we use a (dummy) menubar
3127 * containing the single popup menu as its first item.
3129 * FIXME: the message identifiers have been chosen arbitrarily,
3130 * hence we use MF_BYPOSITION.
3131 * We might as well use the "real" values (anybody knows ?)
3132 * The menu definition is in resources/sysres_??.rc.
3133 * Once these are OK, we better use MF_BYCOMMAND here
3134 * (as we do in EDIT_WM_Command()).
3137 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3139 HMENU menu
= LoadMenuA(GetModuleHandleA("user32.dll"), "EDITMENU");
3140 HMENU popup
= GetSubMenu(menu
, 0);
3141 UINT start
= es
->selection_start
;
3142 UINT end
= es
->selection_end
;
3146 ORDER_UINT(start
, end
);
3149 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3151 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3153 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3155 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3157 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3159 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3164 if (pt
.x
== -1 && pt
.y
== -1) /* passed via VK_APPS press/release */
3168 /* Windows places the menu at the edit's center in this case */
3169 GetClientRect(es
->hwndSelf
, &rc
);
3170 pt
.x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3171 pt
.y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3172 ClientToScreen(es
->hwndSelf
, &pt
);
3175 if (!(es
->flags
& EF_FOCUSED
))
3176 SetFocus(es
->hwndSelf
);
3178 cmd
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
| TPM_NONOTIFY
,
3179 pt
.x
, pt
.y
, 0, es
->hwndSelf
, NULL
);
3182 EDIT_ContextMenuCommand(es
, cmd
);
3188 /*********************************************************************
3193 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
)
3198 lstrcpynW(dst
, es
->text
, count
);
3199 return lstrlenW(dst
);
3202 /*********************************************************************
3207 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3209 HWND hLBox
= es
->hwndListBox
;
3217 hCombo
= GetParent(es
->hwndSelf
);
3221 TRACE("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3223 if (key
== VK_UP
|| key
== VK_DOWN
)
3225 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3228 if (msg
== WM_KEYDOWN
|| nEUI
)
3229 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3235 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3237 /* make sure ComboLBox pops up */
3238 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3243 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3246 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3248 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, !bDropped
, 0);
3250 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3255 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3261 /*********************************************************************
3265 * Handling of special keys that don't produce a WM_CHAR
3266 * (i.e. non-printable keys) & Backspace & Delete
3269 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3274 if (GetKeyState(VK_MENU
) & 0x8000)
3277 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3278 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3283 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3288 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3289 EDIT_MoveUp_ML(es
, shift
);
3292 EDIT_MoveWordBackward(es
, shift
);
3294 EDIT_MoveBackward(es
, shift
);
3297 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3301 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3302 EDIT_MoveDown_ML(es
, shift
);
3304 EDIT_MoveWordForward(es
, shift
);
3306 EDIT_MoveForward(es
, shift
);
3309 EDIT_MoveHome(es
, shift
, control
);
3312 EDIT_MoveEnd(es
, shift
, control
);
3315 if (es
->style
& ES_MULTILINE
)
3316 EDIT_MovePageUp_ML(es
, shift
);
3318 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3321 if (es
->style
& ES_MULTILINE
)
3322 EDIT_MovePageDown_ML(es
, shift
);
3324 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3327 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3328 if (es
->selection_start
!= es
->selection_end
) {
3334 EDIT_EM_SetSel(es
, ~0u, 0, FALSE
);
3336 /* delete character left of caret */
3337 EDIT_MoveBackward(es
, TRUE
);
3339 /* delete to end of line */
3340 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3342 /* delete character right of caret */
3343 EDIT_MoveForward(es
, TRUE
);
3350 if (!(es
->style
& ES_READONLY
))
3356 /* If the edit doesn't want the return send a message to the default object */
3357 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3361 if (!EDIT_IsInsideDialog(es
)) break;
3363 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3364 if (HIWORD(dw
) == DC_HASDEFID
)
3366 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3369 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3370 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3376 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3377 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3380 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3381 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3386 if (EDIT_EM_SetSel(es
, 0, get_text_length(es
), FALSE
))
3388 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3389 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3398 /*********************************************************************
3403 static LRESULT
EDIT_WM_KillFocus(HTHEME theme
, EDITSTATE
*es
)
3405 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3407 es
->flags
&= ~EF_FOCUSED
;
3409 if (!(es
->style
& ES_NOHIDESEL
))
3410 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3411 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3412 /* Throw away left over scroll when we lose focus */
3413 es
->wheelDeltaRemainder
= 0;
3418 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3423 /*********************************************************************
3427 * The caret position has been set on the WM_LBUTTONDOWN message
3430 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3433 INT e
= es
->selection_end
;
3438 es
->bCaptureState
= TRUE
;
3439 SetCapture(es
->hwndSelf
);
3441 l
= EDIT_EM_LineFromChar(es
, e
);
3442 li
= EDIT_EM_LineIndex(es
, l
);
3443 ll
= EDIT_EM_LineLength(es
, e
);
3444 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3445 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3446 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3447 EDIT_EM_ScrollCaret(es
);
3448 es
->region_posx
= es
->region_posy
= 0;
3449 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3454 /*********************************************************************
3459 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3464 es
->bCaptureState
= TRUE
;
3465 SetCapture(es
->hwndSelf
);
3466 EDIT_ConfinePoint(es
, &x
, &y
);
3467 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3468 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3469 EDIT_EM_ScrollCaret(es
);
3470 es
->region_posx
= es
->region_posy
= 0;
3471 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3473 if (!(es
->flags
& EF_FOCUSED
))
3474 SetFocus(es
->hwndSelf
);
3480 /*********************************************************************
3485 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3487 if (es
->bCaptureState
) {
3488 KillTimer(es
->hwndSelf
, 0);
3489 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3491 es
->bCaptureState
= FALSE
;
3496 /*********************************************************************
3501 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3503 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3508 /*********************************************************************
3513 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3519 /* If the mouse has been captured by process other than the edit control itself,
3520 * the windows edit controls will not select the strings with mouse move.
3522 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3526 * FIXME: gotta do some scrolling if outside client
3527 * area. Maybe reset the timer ?
3530 EDIT_ConfinePoint(es
, &x
, &y
);
3531 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3532 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3533 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3534 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3535 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3540 /*********************************************************************
3545 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3558 BOOL rev
= es
->bEnableState
&&
3559 ((es
->flags
& EF_FOCUSED
) ||
3560 (es
->style
& ES_NOHIDESEL
));
3561 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3563 /* The dc we use for calculating may not be the one we paint into.
3564 This is the safest action. */
3565 EDIT_InvalidateUniscribeData(es
);
3566 GetClientRect(es
->hwndSelf
, &rcClient
);
3568 /* get the background brush */
3569 brush
= EDIT_NotifyCtlColor(es
, dc
);
3571 /* paint the border and the background */
3572 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3574 if(es
->style
& WS_BORDER
) {
3575 bw
= GetSystemMetrics(SM_CXBORDER
);
3576 bh
= GetSystemMetrics(SM_CYBORDER
);
3578 if(es
->style
& ES_MULTILINE
) {
3579 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3580 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3583 /* Draw the frame. Same code as in nonclient.c */
3584 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3585 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3586 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3587 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3588 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3589 SelectObject(dc
, old_brush
);
3591 /* Keep the border clean */
3592 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3593 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3596 GetClipBox(dc
, &rc
);
3597 FillRect(dc
, &rc
, brush
);
3599 IntersectClipRect(dc
, es
->format_rect
.left
,
3600 es
->format_rect
.top
,
3601 es
->format_rect
.right
,
3602 es
->format_rect
.bottom
);
3603 if (es
->style
& ES_MULTILINE
) {
3605 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3608 old_font
= SelectObject(dc
, es
->font
);
3610 if (!es
->bEnableState
)
3611 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3612 GetClipBox(dc
, &rcRgn
);
3613 if (es
->style
& ES_MULTILINE
) {
3614 INT vlc
= get_vertical_line_count(es
);
3615 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3616 EDIT_UpdateUniscribeData(es
, dc
, i
);
3617 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3618 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3619 EDIT_PaintLine(es
, dc
, i
, rev
);
3622 EDIT_UpdateUniscribeData(es
, dc
, 0);
3623 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3624 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3625 EDIT_PaintLine(es
, dc
, 0, rev
);
3628 SelectObject(dc
, old_font
);
3631 EndPaint(es
->hwndSelf
, &ps
);
3634 static void EDIT_WM_NCPaint(HWND hwnd
, HRGN region
)
3636 DWORD exStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3637 HTHEME theme
= GetWindowTheme(hwnd
);
3638 HRGN cliprgn
= region
;
3640 if (theme
&& exStyle
& WS_EX_CLIENTEDGE
)
3644 int cxEdge
= GetSystemMetrics(SM_CXEDGE
),
3645 cyEdge
= GetSystemMetrics(SM_CYEDGE
);
3646 const int part
= EP_EDITTEXT
;
3647 int state
= ETS_NORMAL
;
3648 DWORD dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3650 if (!IsWindowEnabled(hwnd
))
3651 state
= ETS_DISABLED
;
3652 else if (dwStyle
& ES_READONLY
)
3653 state
= ETS_READONLY
;
3654 else if (GetFocus() == hwnd
)
3655 state
= ETS_FOCUSED
;
3657 GetWindowRect(hwnd
, &r
);
3659 /* New clipping region passed to default proc to exclude border */
3660 cliprgn
= CreateRectRgn(r
.left
+ cxEdge
, r
.top
+ cyEdge
,
3661 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
3662 if (region
!= (HRGN
)1)
3663 CombineRgn(cliprgn
, cliprgn
, region
, RGN_AND
);
3664 OffsetRect(&r
, -r
.left
, -r
.top
);
3666 dc
= GetDCEx(hwnd
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
3667 OffsetRect(&r
, -r
.left
, -r
.top
);
3669 if (IsThemeBackgroundPartiallyTransparent(theme
, part
, state
))
3670 DrawThemeParentBackground(hwnd
, dc
, &r
);
3671 DrawThemeBackground(theme
, dc
, part
, state
, &r
, 0);
3672 ReleaseDC(hwnd
, dc
);
3675 /* Call default proc to get the scrollbars etc. also painted */
3676 DefWindowProcW (hwnd
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
3679 /*********************************************************************
3684 static void EDIT_WM_SetFocus(HTHEME theme
, EDITSTATE
*es
)
3686 UINT flags
= RDW_INVALIDATE
| RDW_UPDATENOW
;
3688 es
->flags
|= EF_FOCUSED
;
3690 if (!(es
->style
& ES_NOHIDESEL
))
3691 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3693 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3694 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
3695 ShowCaret(es
->hwndSelf
);
3696 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3699 flags
|= RDW_FRAME
| RDW_ERASE
;
3701 RedrawWindow(es
->hwndSelf
, NULL
, NULL
, flags
);
3705 static DWORD
get_font_margins(HDC hdc
, const TEXTMETRICW
*tm
)
3711 if (!(tm
->tmPitchAndFamily
& (TMPF_VECTOR
| TMPF_TRUETYPE
)))
3712 return MAKELONG(EC_USEFONTINFO
, EC_USEFONTINFO
);
3715 return MAKELONG(EC_USEFONTINFO
, EC_USEFONTINFO
);
3717 if (!GetCharABCWidthsW(hdc
, 0, 255, abc
))
3721 for (i
= 0; i
< ARRAY_SIZE(abc
); i
++) {
3722 if (-abc
[i
].abcA
> right
) right
= -abc
[i
].abcA
;
3723 if (-abc
[i
].abcC
> left
) left
= -abc
[i
].abcC
;
3725 return MAKELONG(left
, right
);
3728 /*********************************************************************
3732 * With Win95 look the margins are set to default font value unless
3733 * the system font (font == 0) is being set, in which case they are left
3737 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3746 EDIT_InvalidateUniscribeData(es
);
3747 dc
= GetDC(es
->hwndSelf
);
3749 old_font
= SelectObject(dc
, font
);
3750 GetTextMetricsW(dc
, &tm
);
3751 es
->line_height
= tm
.tmHeight
;
3752 es
->char_width
= tm
.tmAveCharWidth
;
3753 margins
= get_font_margins(dc
, &tm
);
3755 SelectObject(dc
, old_font
);
3756 ReleaseDC(es
->hwndSelf
, dc
);
3758 /* Reset the format rect and the margins */
3759 GetClientRect(es
->hwndSelf
, &clientRect
);
3760 EDIT_SetRectNP(es
, &clientRect
);
3762 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3763 LOWORD(margins
), HIWORD(margins
), FALSE
);
3765 if (es
->style
& ES_MULTILINE
)
3766 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3768 EDIT_CalcLineWidth_SL(es
);
3771 EDIT_UpdateText(es
, NULL
, TRUE
);
3772 if (es
->flags
& EF_FOCUSED
) {
3774 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3775 EDIT_SetCaretPos(es
, es
->selection_end
,
3776 es
->flags
& EF_AFTER_WRAP
);
3777 ShowCaret(es
->hwndSelf
);
3782 /*********************************************************************
3787 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3788 * The modified flag is reset. No notifications are sent.
3790 * For single-line controls, reception of WM_SETTEXT triggers:
3791 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3794 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
)
3796 if (es
->flags
& EF_UPDATE
)
3797 /* fixed this bug once; complain if we see it about to happen again. */
3798 ERR("SetSel may generate UPDATE message whose handler may reset "
3801 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3804 TRACE("%s\n", debugstr_w(text
));
3805 EDIT_EM_ReplaceSel(es
, FALSE
, text
, lstrlenW(text
), FALSE
, FALSE
);
3810 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3813 es
->flags
&= ~EF_MODIFIED
;
3814 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3816 /* Send the notification after the selection start and end have been set
3817 * edit control doesn't send notification on WM_SETTEXT
3818 * if it is multiline, or it is part of combobox
3820 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3822 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3823 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3825 EDIT_EM_ScrollCaret(es
);
3826 EDIT_UpdateScrollInfo(es
);
3827 EDIT_InvalidateUniscribeData(es
);
3831 /*********************************************************************
3836 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3838 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3840 GetClientRect(es
->hwndSelf
, &rc
);
3841 EDIT_SetRectNP(es
, &rc
);
3842 EDIT_UpdateText(es
, NULL
, TRUE
);
3847 /*********************************************************************
3851 * This message is sent by SetWindowLong on having changed either the Style
3852 * or the extended style.
3854 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3856 * See also EDIT_WM_NCCreate
3858 * It appears that the Windows version of the edit control allows the style
3859 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3860 * style variable which will generally be different. In this function we
3861 * update the internal style based on what changed in the externally visible
3864 * Much of this content as based upon the MSDN, especially:
3865 * Platform SDK Documentation -> User Interface Services ->
3866 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3867 * Edit Control Styles
3869 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3871 if (GWL_STYLE
== which
) {
3872 DWORD style_change_mask
;
3874 /* Only a subset of changes can be applied after the control
3877 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3879 if (es
->style
& ES_MULTILINE
)
3880 style_change_mask
|= ES_WANTRETURN
;
3882 new_style
= style
->styleNew
& style_change_mask
;
3884 /* Number overrides lowercase overrides uppercase (at least it
3885 * does in Win95). However I'll bet that ES_NUMBER would be
3886 * invalid under Win 3.1.
3888 if (new_style
& ES_NUMBER
) {
3889 ; /* do not override the ES_NUMBER */
3890 } else if (new_style
& ES_LOWERCASE
) {
3891 new_style
&= ~ES_UPPERCASE
;
3894 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3895 } else if (GWL_EXSTYLE
== which
) {
3896 ; /* FIXME - what is needed here */
3898 WARN ("Invalid style change %ld\n",which
);
3904 /*********************************************************************
3909 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3911 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3912 if (EDIT_EM_CanUndo(es
))
3915 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3916 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3919 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3923 /*********************************************************************
3928 static void EDIT_WM_Timer(EDITSTATE
*es
)
3930 if (es
->region_posx
< 0) {
3931 EDIT_MoveBackward(es
, TRUE
);
3932 } else if (es
->region_posx
> 0) {
3933 EDIT_MoveForward(es
, TRUE
);
3936 * FIXME: gotta do some vertical scrolling here, like
3937 * EDIT_EM_LineScroll(hwnd, 0, 1);
3941 /*********************************************************************
3946 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
3951 if (!(es
->style
& ES_MULTILINE
))
3954 if (!(es
->style
& ES_AUTOHSCROLL
))
3958 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
3961 TRACE("SB_LINELEFT\n");
3963 dx
= -es
->char_width
;
3966 TRACE("SB_LINERIGHT\n");
3967 if (es
->x_offset
< es
->text_width
)
3968 dx
= es
->char_width
;
3971 TRACE("SB_PAGELEFT\n");
3973 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3976 TRACE("SB_PAGERIGHT\n");
3977 if (es
->x_offset
< es
->text_width
)
3978 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
3986 TRACE("SB_RIGHT\n");
3987 if (es
->x_offset
< es
->text_width
)
3988 dx
= es
->text_width
- es
->x_offset
;
3991 TRACE("SB_THUMBTRACK %d\n", pos
);
3992 es
->flags
|= EF_HSCROLL_TRACK
;
3993 if(es
->style
& WS_HSCROLL
)
3994 dx
= pos
- es
->x_offset
;
3999 if(pos
< 0 || pos
> 100) return 0;
4000 /* Assume default scroll range 0-100 */
4001 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4002 new_x
= pos
* (es
->text_width
- fw
) / 100;
4003 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4006 case SB_THUMBPOSITION
:
4007 TRACE("SB_THUMBPOSITION %d\n", pos
);
4008 es
->flags
&= ~EF_HSCROLL_TRACK
;
4009 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4010 dx
= pos
- es
->x_offset
;
4015 if(pos
< 0 || pos
> 100) return 0;
4016 /* Assume default scroll range 0-100 */
4017 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4018 new_x
= pos
* (es
->text_width
- fw
) / 100;
4019 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4022 /* force scroll info update */
4023 EDIT_UpdateScrollInfo(es
);
4024 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4028 TRACE("SB_ENDSCROLL\n");
4031 * FIXME : the next two are undocumented !
4032 * Are we doing the right thing ?
4033 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4034 * although it's also a regular control message.
4036 case EM_GETTHUMB
: /* this one is used by NT notepad */
4039 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4040 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4043 /* Assume default scroll range 0-100 */
4044 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4045 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4047 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4051 TRACE("EM_LINESCROLL16\n");
4056 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4062 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4063 /* check if we are going to move too far */
4064 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4065 dx
= es
->text_width
- fw
- es
->x_offset
;
4067 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4073 /*********************************************************************
4078 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4082 if (!(es
->style
& ES_MULTILINE
))
4085 if (!(es
->style
& ES_AUTOVSCROLL
))
4094 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4095 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4096 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4098 EDIT_EM_Scroll(es
, action
);
4105 TRACE("SB_BOTTOM\n");
4106 dy
= es
->line_count
- 1 - es
->y_offset
;
4109 TRACE("SB_THUMBTRACK %d\n", pos
);
4110 es
->flags
|= EF_VSCROLL_TRACK
;
4111 if(es
->style
& WS_VSCROLL
)
4112 dy
= pos
- es
->y_offset
;
4115 /* Assume default scroll range 0-100 */
4118 if(pos
< 0 || pos
> 100) return 0;
4119 vlc
= get_vertical_line_count(es
);
4120 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4121 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4122 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4123 es
->line_count
, es
->y_offset
, pos
, dy
);
4126 case SB_THUMBPOSITION
:
4127 TRACE("SB_THUMBPOSITION %d\n", pos
);
4128 es
->flags
&= ~EF_VSCROLL_TRACK
;
4129 if(es
->style
& WS_VSCROLL
)
4130 dy
= pos
- es
->y_offset
;
4133 /* Assume default scroll range 0-100 */
4136 if(pos
< 0 || pos
> 100) return 0;
4137 vlc
= get_vertical_line_count(es
);
4138 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4139 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4140 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4141 es
->line_count
, es
->y_offset
, pos
, dy
);
4145 /* force scroll info update */
4146 EDIT_UpdateScrollInfo(es
);
4147 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4151 TRACE("SB_ENDSCROLL\n");
4154 * FIXME : the next two are undocumented !
4155 * Are we doing the right thing ?
4156 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4157 * although it's also a regular control message.
4159 case EM_GETTHUMB
: /* this one is used by NT notepad */
4162 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4163 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4166 /* Assume default scroll range 0-100 */
4167 INT vlc
= get_vertical_line_count(es
);
4168 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4170 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4174 TRACE("EM_LINESCROLL %d\n", pos
);
4179 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4184 EDIT_EM_LineScroll(es
, 0, dy
);
4188 /*********************************************************************
4192 * FIXME: is this right ? (or should it be only VSCROLL)
4193 * (and maybe only for edit controls that really have their
4194 * own scrollbars) (and maybe only for multiline controls ?)
4195 * All in all: very poorly documented
4198 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4200 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4201 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4204 static inline WCHAR
*heap_strdupW(const WCHAR
*str
)
4206 int len
= lstrlenW(str
) + 1;
4207 WCHAR
*ret
= heap_alloc(len
* sizeof(WCHAR
));
4212 /*********************************************************************
4217 static BOOL
EDIT_EM_SetCueBanner(EDITSTATE
*es
, BOOL draw_focused
, const WCHAR
*cue_text
)
4219 if (es
->style
& ES_MULTILINE
|| !cue_text
)
4222 heap_free(es
->cue_banner_text
);
4223 es
->cue_banner_text
= heap_strdupW(cue_text
);
4224 es
->cue_banner_draw_focused
= draw_focused
;
4229 /*********************************************************************
4234 static BOOL
EDIT_EM_GetCueBanner(EDITSTATE
*es
, WCHAR
*buf
, DWORD size
)
4236 if (es
->style
& ES_MULTILINE
)
4239 if (!es
->cue_banner_text
)
4248 lstrcpynW(buf
, es
->cue_banner_text
, size
);
4254 /********************************************************************
4256 * The Following code is to handle inline editing from IMEs
4259 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4263 LPSTR lpCompStrAttr
= NULL
;
4266 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4273 lpCompStr
= heap_alloc(buflen
);
4276 ERR("Unable to allocate IME CompositionString\n");
4281 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4283 if (CompFlag
& GCS_COMPATTR
)
4286 * We do not use the attributes yet. it would tell us what characters
4287 * are in transition and which are converted or decided upon
4289 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4293 lpCompStrAttr
= heap_alloc(dwBufLenAttr
+ 1);
4296 ERR("Unable to allocate IME Attribute String\n");
4297 heap_free(lpCompStr
);
4300 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4302 lpCompStrAttr
[dwBufLenAttr
] = 0;
4306 /* check for change in composition start */
4307 if (es
->selection_end
< es
->composition_start
)
4308 es
->composition_start
= es
->selection_end
;
4310 /* replace existing selection string */
4311 es
->selection_start
= es
->composition_start
;
4313 if (es
->composition_len
> 0)
4314 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4316 es
->selection_end
= es
->selection_start
;
4318 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4319 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4321 es
->selection_start
= es
->composition_start
;
4322 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4324 heap_free(lpCompStrAttr
);
4325 heap_free(lpCompStr
);
4328 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4333 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4339 lpResultStr
= heap_alloc(buflen
);
4342 ERR("Unable to alloc buffer for IME string\n");
4346 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4348 /* check for change in composition start */
4349 if (es
->selection_end
< es
->composition_start
)
4350 es
->composition_start
= es
->selection_end
;
4352 es
->selection_start
= es
->composition_start
;
4353 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4354 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4355 es
->composition_start
= es
->selection_end
;
4356 es
->composition_len
= 0;
4358 heap_free(lpResultStr
);
4361 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4366 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4368 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4369 es
->composition_start
= es
->selection_end
;
4372 hIMC
= ImmGetContext(hwnd
);
4376 if (CompFlag
& GCS_RESULTSTR
)
4378 EDIT_GetResultStr(hIMC
, es
);
4383 if (CompFlag
& GCS_COMPSTR
)
4384 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4385 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4387 ImmReleaseContext(hwnd
, hIMC
);
4388 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4392 /*********************************************************************
4396 * See also EDIT_WM_StyleChanged
4398 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
)
4403 TRACE("Creating edit control, style = %08x\n", lpcs
->style
);
4405 if (!(es
= heap_alloc_zero(sizeof(*es
))))
4407 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4410 * Note: since the EDITSTATE has not been fully initialized yet,
4411 * we can't use any API calls that may send
4412 * WM_XXX messages before WM_NCCREATE is completed.
4415 es
->style
= lpcs
->style
;
4417 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4419 es
->hwndSelf
= hwnd
;
4420 /* Save parent, which will be notified by EN_* messages */
4421 es
->hwndParent
= lpcs
->hwndParent
;
4423 if (es
->style
& ES_COMBO
)
4424 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4426 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4427 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4429 /* Number overrides lowercase overrides uppercase (at least it
4430 * does in Win95). However I'll bet that ES_NUMBER would be
4431 * invalid under Win 3.1.
4433 if (es
->style
& ES_NUMBER
) {
4434 ; /* do not override the ES_NUMBER */
4435 } else if (es
->style
& ES_LOWERCASE
) {
4436 es
->style
&= ~ES_UPPERCASE
;
4438 if (es
->style
& ES_MULTILINE
) {
4439 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4440 if (es
->style
& WS_VSCROLL
)
4441 es
->style
|= ES_AUTOVSCROLL
;
4442 if (es
->style
& WS_HSCROLL
)
4443 es
->style
|= ES_AUTOHSCROLL
;
4444 es
->style
&= ~ES_PASSWORD
;
4445 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4446 /* Confirmed - RIGHT overrides CENTER */
4447 if (es
->style
& ES_RIGHT
)
4448 es
->style
&= ~ES_CENTER
;
4449 es
->style
&= ~WS_HSCROLL
;
4450 es
->style
&= ~ES_AUTOHSCROLL
;
4453 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4454 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4455 es
->style
&= ~ES_CENTER
;
4456 es
->style
&= ~WS_HSCROLL
;
4457 es
->style
&= ~WS_VSCROLL
;
4458 if (es
->style
& ES_PASSWORD
)
4459 es
->password_char
= '*';
4462 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4463 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4465 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4467 if (!(es
->undo_text
= heap_alloc_zero((es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4469 es
->undo_buffer_size
= es
->buffer_size
;
4471 if (es
->style
& ES_MULTILINE
)
4472 if (!(es
->first_line_def
= heap_alloc_zero(sizeof(LINEDEF
))))
4477 * In Win95 look and feel, the WS_BORDER style is replaced by the
4478 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4479 * control a nonclient area so we don't need to draw the border.
4480 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4481 * a nonclient area and we should handle painting the border ourselves.
4483 * When making modifications please ensure that the code still works
4484 * for edit controls created directly with style 0x50800000, exStyle 0
4485 * (which should have a single pixel border)
4487 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4488 es
->style
&= ~WS_BORDER
;
4489 else if (es
->style
& WS_BORDER
)
4490 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4495 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4496 EDIT_InvalidateUniscribeData(es
);
4497 heap_free(es
->first_line_def
);
4498 heap_free(es
->undo_text
);
4499 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4500 heap_free(es
->logAttr
);
4506 /*********************************************************************
4511 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, const WCHAR
*name
)
4515 TRACE("%s\n", debugstr_w(name
));
4518 * To initialize some final structure members, we call some helper
4519 * functions. However, since the EDITSTATE is not consistent (i.e.
4520 * not fully initialized), we should be very careful which
4521 * functions can be called, and in what order.
4523 EDIT_WM_SetFont(es
, 0, FALSE
);
4524 EDIT_EM_EmptyUndoBuffer(es
);
4526 /* We need to calculate the format rect
4527 (applications may send EM_SETMARGINS before the control gets visible) */
4528 GetClientRect(es
->hwndSelf
, &clientRect
);
4529 EDIT_SetRectNP(es
, &clientRect
);
4533 EDIT_EM_ReplaceSel(es
, FALSE
, name
, lstrlenW(name
), FALSE
, FALSE
);
4534 /* if we insert text to the editline, the text scrolls out
4535 * of the window, as the caret is placed after the insert
4536 * pos normally; thus we reset es->selection... to 0 and
4539 es
->selection_start
= es
->selection_end
= 0;
4540 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4541 * Messages are only to be sent when the USER does something to
4542 * change the contents. So I am removing this EN_CHANGE
4544 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4546 EDIT_EM_ScrollCaret(es
);
4549 /* force scroll info update */
4550 EDIT_UpdateScrollInfo(es
);
4551 OpenThemeData(es
->hwndSelf
, WC_EDITW
);
4553 /* The rule seems to return 1 here for success */
4554 /* Power Builder masked edit controls will crash */
4556 /* FIXME: is that in all cases so ? */
4561 /*********************************************************************
4566 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4571 theme
= GetWindowTheme(es
->hwndSelf
);
4572 CloseThemeData(theme
);
4574 /* The app can own the text buffer handle */
4575 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
))
4576 LocalFree(es
->hloc32W
);
4578 EDIT_InvalidateUniscribeData(es
);
4580 pc
= es
->first_line_def
;
4588 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4589 heap_free(es
->undo_text
);
4590 heap_free(es
->cue_banner_text
);
4596 static LRESULT CALLBACK
EDIT_WindowProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
4598 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW(hwnd
, 0);
4599 HTHEME theme
= GetWindowTheme(hwnd
);
4603 TRACE("hwnd=%p msg=%#x wparam=%lx lparam=%lx\n", hwnd
, msg
, wParam
, lParam
);
4605 if (!es
&& msg
!= WM_NCCREATE
)
4606 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4608 if (es
&& (msg
!= WM_NCDESTROY
))
4609 EDIT_LockBuffer(es
);
4614 result
= EDIT_EM_GetSel(es
, (UINT
*)wParam
, (UINT
*)lParam
);
4618 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4619 EDIT_EM_ScrollCaret(es
);
4624 rect
= (RECT
*)lParam
;
4626 *rect
= es
->format_rect
;
4630 if ((es
->style
& ES_MULTILINE
) && lParam
)
4632 EDIT_SetRectNP(es
, (RECT
*)lParam
);
4633 EDIT_UpdateText(es
, NULL
, TRUE
);
4638 if ((es
->style
& ES_MULTILINE
) && lParam
)
4639 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4643 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4647 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4650 case EM_SCROLLCARET
:
4651 EDIT_EM_ScrollCaret(es
);
4656 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4661 es
->flags
|= EF_MODIFIED
;
4663 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4666 case EM_GETLINECOUNT
:
4667 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4671 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4675 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4679 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4683 result
= EDIT_EM_GetThumb(es
);
4686 /* these messages missing from specs */
4691 FIXME("undocumented message 0x%x, please report\n", msg
);
4692 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4696 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4701 const WCHAR
*textW
= (const WCHAR
*)lParam
;
4703 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, lstrlenW(textW
), TRUE
, TRUE
);
4709 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4712 case EM_SETLIMITTEXT
:
4713 EDIT_EM_SetLimitText(es
, wParam
);
4717 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4722 result
= (LRESULT
)EDIT_EM_Undo(es
);
4726 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4729 case EM_LINEFROMCHAR
:
4730 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4733 case EM_SETTABSTOPS
:
4734 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4737 case EM_SETPASSWORDCHAR
:
4738 EDIT_EM_SetPasswordChar(es
, wParam
);
4741 case EM_EMPTYUNDOBUFFER
:
4742 EDIT_EM_EmptyUndoBuffer(es
);
4745 case EM_GETFIRSTVISIBLELINE
:
4746 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4749 case EM_SETREADONLY
:
4751 DWORD old_style
= es
->style
;
4755 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) | ES_READONLY
);
4756 es
->style
|= ES_READONLY
;
4760 SetWindowLongW(hwnd
, GWL_STYLE
, GetWindowLongW(hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4761 es
->style
&= ~ES_READONLY
;
4764 if (old_style
^ es
->style
)
4765 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4771 case EM_SETWORDBREAKPROC
:
4772 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4776 case EM_GETWORDBREAKPROC
:
4777 result
= (LRESULT
)es
->word_break_proc
;
4780 case EM_GETPASSWORDCHAR
:
4781 result
= es
->password_char
;
4785 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4789 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4792 case EM_GETLIMITTEXT
:
4793 result
= es
->buffer_limit
;
4796 case EM_POSFROMCHAR
:
4797 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4798 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4801 case EM_CHARFROMPOS
:
4802 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4805 case EM_SETCUEBANNER
:
4806 result
= EDIT_EM_SetCueBanner(es
, (BOOL
)wParam
, (const WCHAR
*)lParam
);
4809 case EM_GETCUEBANNER
:
4810 result
= EDIT_EM_GetCueBanner(es
, (WCHAR
*)wParam
, (DWORD
)lParam
);
4813 /* End of the EM_ messages which were in numerical order; what order
4814 * are these in? vaguely alphabetical?
4818 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
4822 result
= EDIT_WM_NCDestroy(es
);
4827 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4829 if (es
->style
& ES_MULTILINE
)
4830 result
|= DLGC_WANTALLKEYS
;
4834 MSG
*msg
= (MSG
*)lParam
;
4835 es
->flags
|= EF_DIALOGMODE
;
4837 if (msg
->message
== WM_KEYDOWN
)
4839 int vk
= (int)msg
->wParam
;
4841 if (es
->hwndListBox
)
4843 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4844 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4845 result
|= DLGC_WANTMESSAGE
;
4854 WCHAR charW
= wParam
;
4856 if (es
->hwndListBox
)
4858 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4860 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4861 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4865 result
= EDIT_WM_Char(es
, charW
);
4870 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4871 if (wParam
<= 0x000fffff)
4873 if (wParam
> 0xffff) /* convert to surrogates */
4876 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4877 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4880 EDIT_WM_Char(es
, wParam
);
4888 case WM_CONTEXTMENU
:
4889 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4897 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4905 es
->bEnableState
= (BOOL
) wParam
;
4906 EDIT_UpdateText(es
, NULL
, TRUE
);
4908 RedrawWindow(hwnd
, NULL
, NULL
, RDW_FRAME
| RDW_INVALIDATE
| RDW_UPDATENOW
);
4912 /* we do the proper erase in EDIT_WM_Paint */
4917 result
= (LRESULT
)es
->font
;
4921 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
);
4924 case WM_GETTEXTLENGTH
:
4925 result
= get_text_length(es
);
4929 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
4933 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
4937 result
= EDIT_WM_KillFocus(theme
, es
);
4940 case WM_LBUTTONDBLCLK
:
4941 result
= EDIT_WM_LButtonDblClk(es
);
4944 case WM_LBUTTONDOWN
:
4945 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4949 result
= EDIT_WM_LButtonUp(es
);
4952 case WM_MBUTTONDOWN
:
4953 result
= EDIT_WM_MButtonDown(es
);
4957 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4960 case WM_PRINTCLIENT
:
4962 EDIT_WM_Paint(es
, (HDC
)wParam
);
4966 EDIT_WM_NCPaint(hwnd
, (HRGN
)wParam
);
4974 EDIT_WM_SetFocus(theme
, es
);
4978 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
4982 /* FIXME: actually set an internal flag and behave accordingly */
4986 EDIT_WM_SetText(es
, (const WCHAR
*)lParam
);
4991 EDIT_WM_Size(es
, (UINT
)wParam
);
4994 case WM_STYLECHANGED
:
4995 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
4998 case WM_STYLECHANGING
:
4999 result
= 0; /* See EDIT_WM_StyleChanged */
5003 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5011 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5017 INT pulScrollLines
= 3;
5018 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5020 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
5022 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5026 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
5027 /* if scrolling changes direction, ignore left overs */
5028 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
5029 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
5030 es
->wheelDeltaRemainder
+= wheelDelta
;
5032 es
->wheelDeltaRemainder
= wheelDelta
;
5034 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
5037 pulScrollLines
= min(es
->line_count
, pulScrollLines
);
5038 cLineScroll
= pulScrollLines
* es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
5039 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
5040 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
5045 /* IME messages to make the edit control IME aware */
5046 case WM_IME_SETCONTEXT
:
5049 case WM_IME_STARTCOMPOSITION
:
5050 es
->composition_start
= es
->selection_end
;
5051 es
->composition_len
= 0;
5054 case WM_IME_COMPOSITION
:
5055 EDIT_ImeComposition(hwnd
, lParam
, es
);
5058 case WM_IME_ENDCOMPOSITION
:
5059 if (es
->composition_len
> 0)
5061 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
5062 es
->selection_end
= es
->selection_start
;
5063 es
->composition_len
= 0;
5067 case WM_IME_COMPOSITIONFULL
:
5073 case WM_IME_CONTROL
:
5076 case WM_IME_REQUEST
:
5079 case IMR_QUERYCHARPOSITION
:
5081 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
5084 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
5085 chpos
->pt
.x
= LOWORD(pos
);
5086 chpos
->pt
.y
= HIWORD(pos
);
5087 chpos
->cLineHeight
= es
->line_height
;
5088 chpos
->rcDocument
= es
->format_rect
;
5089 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
5090 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
5097 case WM_THEMECHANGED
:
5098 CloseThemeData (theme
);
5099 OpenThemeData(hwnd
, WC_EDITW
);
5103 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5107 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
5108 EDIT_UnlockBuffer(es
, FALSE
);
5110 TRACE("hwnd=%p msg=%x -- 0x%08lx\n", hwnd
, msg
, result
);
5115 void EDIT_Register(void)
5119 memset(&wndClass
, 0, sizeof(wndClass
));
5120 wndClass
.style
= CS_PARENTDC
| CS_GLOBALCLASS
| CS_DBLCLKS
;
5121 wndClass
.lpfnWndProc
= EDIT_WindowProc
;
5122 wndClass
.cbClsExtra
= 0;
5124 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*) + sizeof(WORD
);
5126 wndClass
.cbWndExtra
= sizeof(EDITSTATE
*);
5128 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_IBEAM
);
5129 wndClass
.hbrBackground
= NULL
;
5130 wndClass
.lpszClassName
= WC_EDITW
;
5131 RegisterClassW(&wndClass
);