4 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
6 * Copyright Frans van Dorsselaer, 1996, 1997
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * - EM_GETIMESTATUS, EM_SETIMESTATUS
43 #include "wine/unicode.h"
45 #include "user_private.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(edit
);
49 WINE_DECLARE_DEBUG_CHANNEL(combo
);
50 WINE_DECLARE_DEBUG_CHANNEL(relay
);
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 */
72 END_0
= 0, /* line ends with terminating '\0' character */
73 END_WRAP
, /* line is wrapped */
74 END_HARD
, /* line ends with a hard return '\r\n' */
75 END_SOFT
, /* line ends with a soft return '\r\r\n' */
76 END_RICH
/* line ends with a single '\n' */
79 typedef struct tagLINEDEF
{
80 INT length
; /* bruto length of a line in bytes */
81 INT net_length
; /* netto length of a line in visible characters */
83 INT width
; /* width of the line in pixels */
84 INT index
; /* line index into the buffer */
85 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data */
86 struct tagLINEDEF
*next
;
91 BOOL is_unicode
; /* how the control was created */
92 LPWSTR text
; /* the actual contents of the control */
93 UINT text_length
; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
94 UINT buffer_size
; /* the size of the buffer in characters */
95 UINT buffer_limit
; /* the maximum size to which the buffer may grow in characters */
96 HFONT font
; /* NULL means standard system font */
97 INT x_offset
; /* scroll offset for multi lines this is in pixels
98 for single lines it's in characters */
99 INT line_height
; /* height of a screen line in pixels */
100 INT char_width
; /* average character width in pixels */
101 DWORD style
; /* sane version of wnd->dwStyle */
102 WORD flags
; /* flags that are not in es->style or wnd->flags (EF_XXX) */
103 INT undo_insert_count
; /* number of characters inserted in sequence */
104 UINT undo_position
; /* character index of the insertion and deletion */
105 LPWSTR undo_text
; /* deleted text */
106 UINT undo_buffer_size
; /* size of the deleted text buffer */
107 INT selection_start
; /* == selection_end if no selection */
108 INT selection_end
; /* == current caret position */
109 WCHAR password_char
; /* == 0 if no password char, and for multi line controls */
110 INT left_margin
; /* in pixels */
111 INT right_margin
; /* in pixels */
113 INT text_width
; /* width of the widest line in pixels for multi line controls
114 and just line width for single line controls */
115 INT region_posx
; /* Position of cursor relative to region: */
116 INT region_posy
; /* -1: to left, 0: within, 1: to right */
117 void *word_break_proc
; /* 32-bit word break proc: ANSI or Unicode */
118 INT line_count
; /* number of lines */
119 INT y_offset
; /* scroll offset in number of lines */
120 BOOL bCaptureState
; /* flag indicating whether mouse was captured */
121 BOOL bEnableState
; /* flag keeping the enable state */
122 HWND hwndSelf
; /* the our window handle */
123 HWND hwndParent
; /* Handle of parent for sending EN_* messages.
124 Even if parent will change, EN_* messages
125 should be sent to the first parent. */
126 HWND hwndListBox
; /* handle of ComboBox's listbox or NULL */
127 INT wheelDeltaRemainder
; /* scroll wheel delta left over after scrolling whole lines */
129 * only for multi line controls
131 INT lock_count
; /* amount of re-entries in the EditWndProc */
134 LINEDEF
*first_line_def
; /* linked list of (soft) linebreaks */
135 HLOCAL hloc32W
; /* our unicode local memory block */
136 HLOCAL hloc32A
; /* alias for ANSI control receiving EM_GETHANDLE
138 HLOCAL hlocapp
; /* The text buffer handle belongs to the app */
142 UINT composition_len
; /* length of composition, 0 == no composition */
143 int composition_start
; /* the character position for the composition */
147 SCRIPT_LOGATTR
*logAttr
;
148 SCRIPT_STRING_ANALYSIS ssa
; /* Uniscribe Data for single line controls */
152 #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
153 #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
155 /* used for disabled or read-only edit control */
156 #define EDIT_NOTIFY_PARENT(es, wNotifyCode) \
158 { /* Notify parent which has created this edit control */ \
159 TRACE("notification " #wNotifyCode " sent to hwnd=%p\n", es->hwndParent); \
160 SendMessageW(es->hwndParent, WM_COMMAND, \
161 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
162 (LPARAM)(es->hwndSelf)); \
165 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
);
167 /*********************************************************************
172 static inline BOOL
EDIT_EM_CanUndo(const EDITSTATE
*es
)
174 return (es
->undo_insert_count
|| strlenW(es
->undo_text
));
178 /*********************************************************************
183 static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE
*es
)
185 es
->undo_insert_count
= 0;
186 *es
->undo_text
= '\0';
190 /**********************************************************************
193 * Returns the window version in case Wine emulates a later version
194 * of windows than the application expects.
196 * In a number of cases when windows runs an application that was
197 * designed for an earlier windows version, windows reverts
198 * to "old" behaviour of that earlier version.
200 * An example is a disabled edit control that needs to be painted.
201 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
202 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
203 * applications with an expected version 0f 4.0 or higher.
206 static DWORD
get_app_version(void)
208 static DWORD version
;
211 DWORD dwEmulatedVersion
;
213 DWORD dwProcVersion
= GetProcessVersion(0);
215 info
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOW
);
216 GetVersionExW( &info
);
217 dwEmulatedVersion
= MAKELONG( info
.dwMinorVersion
, info
.dwMajorVersion
);
218 /* FIXME: this may not be 100% correct; see discussion on the
219 * wine developer list in Nov 1999 */
220 version
= dwProcVersion
< dwEmulatedVersion
? dwProcVersion
: dwEmulatedVersion
;
225 static HBRUSH
EDIT_NotifyCtlColor(EDITSTATE
*es
, HDC hdc
)
230 if ( get_app_version() >= 0x40000 && (!es
->bEnableState
|| (es
->style
& ES_READONLY
)))
231 msg
= WM_CTLCOLORSTATIC
;
233 msg
= WM_CTLCOLOREDIT
;
235 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
236 hbrush
= (HBRUSH
)SendMessageW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
238 hbrush
= (HBRUSH
)DefWindowProcW(GetParent(es
->hwndSelf
), msg
, (WPARAM
)hdc
, (LPARAM
)es
->hwndSelf
);
243 static inline UINT
get_text_length(EDITSTATE
*es
)
245 if(es
->text_length
== (UINT
)-1)
246 es
->text_length
= strlenW(es
->text
);
247 return es
->text_length
;
251 /*********************************************************************
255 * Find the beginning of words.
256 * Note: unlike the specs for a WordBreakProc, this function can
257 * only be called without linebreaks between s[0] up to
258 * s[count - 1]. Remember it is only called
259 * internally, so we can decide this for ourselves.
260 * Additionally we will always be breaking the full string.
263 static INT
EDIT_WordBreakProc(EDITSTATE
*es
, LPWSTR s
, INT index
, INT count
, INT action
)
267 TRACE("s=%p, index=%d, count=%d, action=%d\n", s
, index
, count
, action
);
275 memset(&psa
,0,sizeof(SCRIPT_ANALYSIS
));
276 psa
.eScript
= SCRIPT_UNDEFINED
;
278 es
->logAttr
= HeapAlloc(GetProcessHeap(), 0, sizeof(SCRIPT_LOGATTR
) * get_text_length(es
));
279 ScriptBreak(es
->text
, get_text_length(es
), &psa
, es
->logAttr
);
286 while (index
&& !es
->logAttr
[index
].fSoftBreak
)
293 while (index
< count
&& s
[index
] && !es
->logAttr
[index
].fSoftBreak
)
298 ret
= es
->logAttr
[index
].fWhiteSpace
;
301 ERR("unknown action code, please report !\n");
308 /*********************************************************************
310 * EDIT_CallWordBreakProc
312 * Call appropriate WordBreakProc (internal or external).
314 * Note: The "start" argument should always be an index referring
315 * to es->text. The actual wordbreak proc might be
316 * 16 bit, so we can't always pass any 32 bit LPSTR.
317 * Hence we assume that es->text is the buffer that holds
318 * the string under examination (we can decide this for ourselves).
321 static INT
EDIT_CallWordBreakProc(EDITSTATE
*es
, INT start
, INT index
, INT count
, INT action
)
325 if (es
->word_break_proc
)
329 EDITWORDBREAKPROCW wbpW
= (EDITWORDBREAKPROCW
)es
->word_break_proc
;
331 TRACE_(relay
)("\1Call wordbreakW %p (str=%s,idx=%d,cnt=%d,act=%d)\n",
332 es
->word_break_proc
, debugstr_wn(es
->text
+ start
, count
), index
, count
, action
);
333 ret
= wbpW(es
->text
+ start
, index
, count
, action
);
334 TRACE_(relay
)("\1Ret wordbreakW %p retval=%d\n", es
->word_break_proc
, ret
);
338 EDITWORDBREAKPROCA wbpA
= (EDITWORDBREAKPROCA
)es
->word_break_proc
;
342 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, NULL
, 0, NULL
, NULL
);
343 textA
= HeapAlloc(GetProcessHeap(), 0, countA
);
344 WideCharToMultiByte(CP_ACP
, 0, es
->text
+ start
, count
, textA
, countA
, NULL
, NULL
);
345 TRACE_(relay
)("\1Call wordbreakA %p(str=%s,idx=%d,cnt=%d,act=%d)\n",
346 es
->word_break_proc
, debugstr_an(textA
, countA
), index
, countA
, action
);
347 ret
= wbpA(textA
, index
, countA
, action
);
348 HeapFree(GetProcessHeap(), 0, textA
);
349 TRACE_(relay
)("\1Ret wordbreakA %p retval=%d\n", es
->word_break_proc
, ret
);
353 ret
= EDIT_WordBreakProc(es
, es
->text
, index
+start
, count
+start
, action
) - start
;
358 static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF
*line_def
)
362 ScriptStringFree(&line_def
->ssa
);
363 line_def
->ssa
= NULL
;
367 static inline void EDIT_InvalidateUniscribeData(EDITSTATE
*es
)
369 LINEDEF
*line_def
= es
->first_line_def
;
372 EDIT_InvalidateUniscribeData_linedef(line_def
);
373 line_def
= line_def
->next
;
377 ScriptStringFree(&es
->ssa
);
382 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData_linedef(EDITSTATE
*es
, HDC dc
, LINEDEF
*line_def
)
387 if (line_def
->net_length
&& !line_def
->ssa
)
389 int index
= line_def
->index
;
390 HFONT old_font
= NULL
;
392 SCRIPT_TABDEF tabdef
;
396 udc
= GetDC(es
->hwndSelf
);
398 old_font
= SelectObject(udc
, es
->font
);
400 tabdef
.cTabStops
= es
->tabs_count
;
401 tabdef
.iScale
= GdiGetCharDimensions(udc
, NULL
, NULL
);
402 tabdef
.pTabStops
= es
->tabs
;
403 tabdef
.iTabOrigin
= 0;
405 hr
= ScriptStringAnalyse(udc
, &es
->text
[index
], line_def
->net_length
,
406 (1.5*line_def
->net_length
+16), -1,
407 SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
|SSA_TAB
, -1,
408 NULL
, NULL
, NULL
, &tabdef
, NULL
, &line_def
->ssa
);
411 WARN("ScriptStringAnalyse failed (%x)\n",hr
);
412 line_def
->ssa
= NULL
;
416 SelectObject(udc
, old_font
);
418 ReleaseDC(es
->hwndSelf
, udc
);
421 return line_def
->ssa
;
424 static SCRIPT_STRING_ANALYSIS
EDIT_UpdateUniscribeData(EDITSTATE
*es
, HDC dc
, INT line
)
428 if (!(es
->style
& ES_MULTILINE
))
432 INT length
= get_text_length(es
);
433 HFONT old_font
= NULL
;
437 udc
= GetDC(es
->hwndSelf
);
439 old_font
= SelectObject(udc
, es
->font
);
441 if (es
->style
& ES_PASSWORD
)
442 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
);
444 ScriptStringAnalyse(udc
, es
->text
, length
, (1.5*length
+16), -1, SSA_LINK
|SSA_FALLBACK
|SSA_GLYPHS
, -1, NULL
, NULL
, NULL
, NULL
, NULL
, &es
->ssa
);
447 SelectObject(udc
, old_font
);
449 ReleaseDC(es
->hwndSelf
, udc
);
455 line_def
= es
->first_line_def
;
456 while (line_def
&& line
)
458 line_def
= line_def
->next
;
462 return EDIT_UpdateUniscribeData_linedef(es
,dc
,line_def
);
466 static inline INT
get_vertical_line_count(EDITSTATE
*es
)
468 INT vlc
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
472 /*********************************************************************
474 * EDIT_BuildLineDefs_ML
476 * Build linked list of text lines.
477 * Lines can end with '\0' (last line), a character (if it is wrapped),
478 * a soft return '\r\r\n' or a hard return '\r\n'
481 static void EDIT_BuildLineDefs_ML(EDITSTATE
*es
, INT istart
, INT iend
, INT delta
, HRGN hrgn
)
483 LPWSTR current_position
, cp
;
485 LINEDEF
*current_line
;
486 LINEDEF
*previous_line
;
488 INT line_index
= 0, nstart_line
, nstart_index
;
489 INT line_count
= es
->line_count
;
494 if (istart
== iend
&& delta
== 0)
497 previous_line
= NULL
;
498 current_line
= es
->first_line_def
;
500 /* Find starting line. istart must lie inside an existing line or
501 * at the end of buffer */
503 if (istart
< current_line
->index
+ current_line
->length
||
504 current_line
->ending
== END_0
)
507 previous_line
= current_line
;
508 current_line
= current_line
->next
;
510 } while (current_line
);
512 if (!current_line
) /* Error occurred start is not inside previous buffer */
514 FIXME(" modification occurred outside buffer\n");
518 /* Remember start of modifications in order to calculate update region */
519 nstart_line
= line_index
;
520 nstart_index
= current_line
->index
;
522 /* We must start to reformat from the previous line since the modifications
523 * may have caused the line to wrap upwards. */
524 if (!(es
->style
& ES_AUTOHSCROLL
) && line_index
> 0)
527 current_line
= previous_line
;
529 start_line
= current_line
;
531 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
532 current_position
= es
->text
+ current_line
->index
;
533 vlc
= get_vertical_line_count(es
);
535 if (current_line
!= start_line
)
537 if (!current_line
|| current_line
->index
+ delta
> current_position
- es
->text
)
539 /* The buffer has been expanded, create a new line and
540 insert it into the link list */
541 LINEDEF
*new_line
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
));
542 new_line
->next
= previous_line
->next
;
543 previous_line
->next
= new_line
;
544 current_line
= new_line
;
547 else if (current_line
->index
+ delta
< current_position
- es
->text
)
549 /* The previous line merged with this line so we delete this extra entry */
550 previous_line
->next
= current_line
->next
;
551 HeapFree(GetProcessHeap(), 0, current_line
);
552 current_line
= previous_line
->next
;
556 else /* current_line->index + delta == current_position */
558 if (current_position
- es
->text
> iend
)
559 break; /* We reached end of line modifications */
560 /* else recalculate this line */
564 current_line
->index
= current_position
- es
->text
;
565 orig_net_length
= current_line
->net_length
;
567 /* Find end of line */
568 cp
= current_position
;
570 if (*cp
== '\n') break;
571 if ((*cp
== '\r') && (*(cp
+ 1) == '\n'))
576 /* Mark type of line termination */
578 current_line
->ending
= END_0
;
579 current_line
->net_length
= strlenW(current_position
);
580 } else if ((cp
> current_position
) && (*(cp
- 1) == '\r')) {
581 current_line
->ending
= END_SOFT
;
582 current_line
->net_length
= cp
- current_position
- 1;
583 } else if (*cp
== '\n') {
584 current_line
->ending
= END_RICH
;
585 current_line
->net_length
= cp
- current_position
;
587 current_line
->ending
= END_HARD
;
588 current_line
->net_length
= cp
- current_position
;
591 if (current_line
->net_length
)
594 EDIT_InvalidateUniscribeData_linedef(current_line
);
595 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
596 if (current_line
->ssa
)
598 sz
= ScriptString_pSize(current_line
->ssa
);
599 /* Calculate line width */
600 current_line
->width
= sz
->cx
;
602 else current_line
->width
= es
->char_width
* current_line
->net_length
;
604 else current_line
->width
= 0;
606 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
608 /* Line breaks just look back from the end and find the next break and try that. */
610 if (!(es
->style
& ES_AUTOHSCROLL
)) {
611 if (current_line
->width
> fw
&& fw
> es
->char_width
) {
618 prev
= current_line
->net_length
- 1;
619 w
= current_line
->net_length
;
620 d
= (float)current_line
->width
/(float)fw
;
621 if (d
> 1.2f
) d
-= 0.2f
;
623 if (next
>= prev
) next
= prev
-1;
625 prev
= EDIT_CallWordBreakProc(es
, current_position
- es
->text
,
626 next
, current_line
->net_length
, WB_LEFT
);
627 current_line
->net_length
= prev
;
628 EDIT_InvalidateUniscribeData_linedef(current_line
);
629 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
630 if (current_line
->ssa
)
631 sz
= ScriptString_pSize(current_line
->ssa
);
634 current_line
->width
= sz
->cx
;
638 } while (prev
&& current_line
->width
> fw
);
639 current_line
->net_length
= w
;
641 if (prev
== 0) { /* Didn't find a line break so force a break */
645 EDIT_InvalidateUniscribeData_linedef(current_line
);
646 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
648 if (current_line
->ssa
)
650 count
= ScriptString_pcOutChars(current_line
->ssa
);
651 piDx
= HeapAlloc(GetProcessHeap(),0,sizeof(INT
) * (*count
));
652 ScriptStringGetLogicalWidths(current_line
->ssa
,piDx
);
654 prev
= current_line
->net_length
-1;
656 current_line
->width
-= piDx
[prev
];
658 } while ( prev
> 0 && current_line
->width
> fw
);
661 HeapFree(GetProcessHeap(),0,piDx
);
664 prev
= (fw
/ es
->char_width
);
667 /* If the first line we are calculating, wrapped before istart, we must
668 * adjust istart in order for this to be reflected in the update region. */
669 if (current_line
->index
== nstart_index
&& istart
> current_line
->index
+ prev
)
670 istart
= current_line
->index
+ prev
;
671 /* else if we are updating the previous line before the first line we
672 * are re-calculating and it expanded */
673 else if (current_line
== start_line
&&
674 current_line
->index
!= nstart_index
&& orig_net_length
< prev
)
676 /* Line expanded due to an upwards line wrap so we must partially include
677 * previous line in update region */
678 nstart_line
= line_index
;
679 nstart_index
= current_line
->index
;
680 istart
= current_line
->index
+ orig_net_length
;
683 current_line
->net_length
= prev
;
684 current_line
->ending
= END_WRAP
;
686 if (current_line
->net_length
> 0)
688 EDIT_UpdateUniscribeData_linedef(es
, NULL
, current_line
);
689 if (current_line
->ssa
)
691 sz
= ScriptString_pSize(current_line
->ssa
);
692 current_line
->width
= sz
->cx
;
695 current_line
->width
= 0;
697 else current_line
->width
= 0;
699 else if (current_line
== start_line
&&
700 current_line
->index
!= nstart_index
&&
701 orig_net_length
< current_line
->net_length
) {
702 /* The previous line expanded but it's still not as wide as the client rect */
703 /* The expansion is due to an upwards line wrap so we must partially include
704 it in the update region */
705 nstart_line
= line_index
;
706 nstart_index
= current_line
->index
;
707 istart
= current_line
->index
+ orig_net_length
;
712 /* Adjust length to include line termination */
713 switch (current_line
->ending
) {
715 current_line
->length
= current_line
->net_length
+ 3;
718 current_line
->length
= current_line
->net_length
+ 1;
721 current_line
->length
= current_line
->net_length
+ 2;
725 current_line
->length
= current_line
->net_length
;
728 es
->text_width
= max(es
->text_width
, current_line
->width
);
729 current_position
+= current_line
->length
;
730 previous_line
= current_line
;
732 /* Discard data for non-visible lines. It will be calculated as needed */
733 if ((line_index
< es
->y_offset
) || (line_index
> es
->y_offset
+ vlc
))
734 EDIT_InvalidateUniscribeData_linedef(current_line
);
736 current_line
= current_line
->next
;
738 } while (previous_line
->ending
!= END_0
);
740 /* Finish adjusting line indexes by delta or remove hanging lines */
741 if (previous_line
->ending
== END_0
)
743 LINEDEF
*pnext
= NULL
;
745 previous_line
->next
= NULL
;
748 pnext
= current_line
->next
;
749 EDIT_InvalidateUniscribeData_linedef(current_line
);
750 HeapFree(GetProcessHeap(), 0, current_line
);
751 current_line
= pnext
;
759 current_line
->index
+= delta
;
760 current_line
= current_line
->next
;
764 /* Calculate rest of modification rectangle */
769 * We calculate two rectangles. One for the first line which may have
770 * an indent with respect to the format rect. The other is a format-width
771 * rectangle that spans the rest of the lines that changed or moved.
773 rc
.top
= es
->format_rect
.top
+ nstart_line
* es
->line_height
-
774 (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
775 rc
.bottom
= rc
.top
+ es
->line_height
;
776 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
))
777 rc
.left
= es
->format_rect
.left
;
779 rc
.left
= LOWORD(EDIT_EM_PosFromChar(es
, nstart_index
, FALSE
));
780 rc
.right
= es
->format_rect
.right
;
781 SetRectRgn(hrgn
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
784 rc
.left
= es
->format_rect
.left
;
785 rc
.right
= es
->format_rect
.right
;
787 * If lines were added or removed we must re-paint the remainder of the
788 * lines since the remaining lines were either shifted up or down.
790 if (line_count
< es
->line_count
) /* We added lines */
791 rc
.bottom
= es
->line_count
* es
->line_height
;
792 else if (line_count
> es
->line_count
) /* We removed lines */
793 rc
.bottom
= line_count
* es
->line_height
;
795 rc
.bottom
= line_index
* es
->line_height
;
796 rc
.bottom
+= es
->format_rect
.top
;
797 rc
.bottom
-= (es
->y_offset
* es
->line_height
); /* Adjust for vertical scrollbar */
798 tmphrgn
= CreateRectRgn(rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
799 CombineRgn(hrgn
, hrgn
, tmphrgn
, RGN_OR
);
800 DeleteObject(tmphrgn
);
804 /*********************************************************************
806 * EDIT_CalcLineWidth_SL
809 static void EDIT_CalcLineWidth_SL(EDITSTATE
*es
)
811 EDIT_UpdateUniscribeData(es
, NULL
, 0);
815 size
= ScriptString_pSize(es
->ssa
);
816 es
->text_width
= size
->cx
;
822 /*********************************************************************
826 * Beware: This is not the function called on EM_CHARFROMPOS
827 * The position _can_ be outside the formatting / client
829 * The return value is only the character index
832 static INT
EDIT_CharFromPos(EDITSTATE
*es
, INT x
, INT y
, LPBOOL after_wrap
)
836 if (es
->style
& ES_MULTILINE
) {
838 INT line
= (y
- es
->format_rect
.top
) / es
->line_height
+ es
->y_offset
;
840 LINEDEF
*line_def
= es
->first_line_def
;
841 EDIT_UpdateUniscribeData(es
, NULL
, line
);
842 while ((line
> 0) && line_def
->next
) {
843 line_index
+= line_def
->length
;
844 line_def
= line_def
->next
;
848 x
+= es
->x_offset
- es
->format_rect
.left
;
849 if (es
->style
& ES_RIGHT
)
850 x
-= (es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
;
851 else if (es
->style
& ES_CENTER
)
852 x
-= ((es
->format_rect
.right
- es
->format_rect
.left
) - line_def
->width
) / 2;
853 if (x
>= line_def
->width
) {
855 *after_wrap
= (line_def
->ending
== END_WRAP
);
856 return line_index
+ line_def
->net_length
;
858 if (x
<= 0 || !line_def
->ssa
) {
864 ScriptStringXtoCP(line_def
->ssa
, x
, &index
, &trailing
);
865 if (trailing
) index
++;
868 *after_wrap
= ((index
== line_index
+ line_def
->net_length
) &&
869 (line_def
->ending
== END_WRAP
));
875 x
-= es
->format_rect
.left
;
881 INT indent
= (es
->format_rect
.right
- es
->format_rect
.left
) - es
->text_width
;
882 if (es
->style
& ES_RIGHT
)
884 else if (es
->style
& ES_CENTER
)
888 EDIT_UpdateUniscribeData(es
, NULL
, 0);
893 if (es
->x_offset
>= get_text_length(es
))
896 size
= ScriptString_pSize(es
->ssa
);
899 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
906 if (x
+ xoff
> 0 || !es
->ssa
)
908 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
909 if (trailing
) index
++;
918 const SIZE
*size
= NULL
;
920 size
= ScriptString_pSize(es
->ssa
);
923 else if (x
> size
->cx
)
924 index
= get_text_length(es
);
927 ScriptStringXtoCP(es
->ssa
, x
+xoff
, &index
, &trailing
);
928 if (trailing
) index
++;
934 index
= es
->x_offset
;
941 /*********************************************************************
945 * adjusts the point to be within the formatting rectangle
946 * (so CharFromPos returns the nearest _visible_ character)
949 static void EDIT_ConfinePoint(const EDITSTATE
*es
, LPINT x
, LPINT y
)
951 *x
= min(max(*x
, es
->format_rect
.left
), es
->format_rect
.right
- 1);
952 *y
= min(max(*y
, es
->format_rect
.top
), es
->format_rect
.bottom
- 1);
956 /*********************************************************************
961 static INT
EDIT_EM_LineFromChar(EDITSTATE
*es
, INT index
)
966 if (!(es
->style
& ES_MULTILINE
))
968 if (index
> (INT
)get_text_length(es
))
969 return es
->line_count
- 1;
971 index
= min(es
->selection_start
, es
->selection_end
);
974 line_def
= es
->first_line_def
;
975 index
-= line_def
->length
;
976 while ((index
>= 0) && line_def
->next
) {
978 line_def
= line_def
->next
;
979 index
-= line_def
->length
;
985 /*********************************************************************
990 static INT
EDIT_EM_LineIndex(const EDITSTATE
*es
, INT line
)
993 const LINEDEF
*line_def
;
995 if (!(es
->style
& ES_MULTILINE
))
997 if (line
>= es
->line_count
)
1001 line_def
= es
->first_line_def
;
1003 INT index
= es
->selection_end
- line_def
->length
;
1004 while ((index
>= 0) && line_def
->next
) {
1005 line_index
+= line_def
->length
;
1006 line_def
= line_def
->next
;
1007 index
-= line_def
->length
;
1011 line_index
+= line_def
->length
;
1012 line_def
= line_def
->next
;
1020 /*********************************************************************
1025 static INT
EDIT_EM_LineLength(EDITSTATE
*es
, INT index
)
1029 if (!(es
->style
& ES_MULTILINE
))
1030 return get_text_length(es
);
1033 /* get the number of remaining non-selected chars of selected lines */
1034 INT32 l
; /* line number */
1035 INT32 li
; /* index of first char in line */
1037 l
= EDIT_EM_LineFromChar(es
, es
->selection_start
);
1038 /* # chars before start of selection area */
1039 count
= es
->selection_start
- EDIT_EM_LineIndex(es
, l
);
1040 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1041 /* # chars after end of selection */
1042 li
= EDIT_EM_LineIndex(es
, l
);
1043 count
+= li
+ EDIT_EM_LineLength(es
, li
) - es
->selection_end
;
1046 line_def
= es
->first_line_def
;
1047 index
-= line_def
->length
;
1048 while ((index
>= 0) && line_def
->next
) {
1049 line_def
= line_def
->next
;
1050 index
-= line_def
->length
;
1052 return line_def
->net_length
;
1056 /*********************************************************************
1061 static LRESULT
EDIT_EM_PosFromChar(EDITSTATE
*es
, INT index
, BOOL after_wrap
)
1063 INT len
= get_text_length(es
);
1072 index
= min(index
, len
);
1073 if (es
->style
& ES_MULTILINE
) {
1074 l
= EDIT_EM_LineFromChar(es
, index
);
1075 EDIT_UpdateUniscribeData(es
, NULL
, l
);
1077 y
= (l
- es
->y_offset
) * es
->line_height
;
1078 li
= EDIT_EM_LineIndex(es
, l
);
1079 if (after_wrap
&& (li
== index
) && l
) {
1081 line_def
= es
->first_line_def
;
1083 line_def
= line_def
->next
;
1086 if (line_def
->ending
== END_WRAP
) {
1088 y
-= es
->line_height
;
1089 li
= EDIT_EM_LineIndex(es
, l
);
1093 line_def
= es
->first_line_def
;
1094 while (line_def
->index
!= li
)
1095 line_def
= line_def
->next
;
1097 lw
= line_def
->width
;
1098 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1101 ScriptStringCPtoX(line_def
->ssa
, (index
- 1) - li
, TRUE
, &x
);
1107 if (es
->style
& ES_RIGHT
)
1109 else if (es
->style
& ES_CENTER
)
1114 EDIT_UpdateUniscribeData(es
, NULL
, 0);
1119 if (es
->x_offset
>= get_text_length(es
))
1121 int leftover
= es
->x_offset
- get_text_length(es
);
1125 size
= ScriptString_pSize(es
->ssa
);
1130 xoff
+= es
->char_width
* leftover
;
1133 ScriptStringCPtoX(es
->ssa
, es
->x_offset
, FALSE
, &xoff
);
1140 if (index
>= get_text_length(es
))
1145 size
= ScriptString_pSize(es
->ssa
);
1152 ScriptStringCPtoX(es
->ssa
, index
, FALSE
, &xi
);
1158 if (index
>= es
->x_offset
) {
1159 if (!es
->x_offset
&& (es
->style
& (ES_RIGHT
| ES_CENTER
)))
1161 w
= es
->format_rect
.right
- es
->format_rect
.left
;
1162 if (w
> es
->text_width
)
1164 if (es
->style
& ES_RIGHT
)
1165 x
+= w
- es
->text_width
;
1166 else if (es
->style
& ES_CENTER
)
1167 x
+= (w
- es
->text_width
) / 2;
1173 x
+= es
->format_rect
.left
;
1174 y
+= es
->format_rect
.top
;
1175 return MAKELONG((INT16
)x
, (INT16
)y
);
1179 /*********************************************************************
1183 * Calculates the bounding rectangle for a line from a starting
1184 * column to an ending column.
1187 static void EDIT_GetLineRect(EDITSTATE
*es
, INT line
, INT scol
, INT ecol
, LPRECT rc
)
1189 SCRIPT_STRING_ANALYSIS ssa
;
1193 if (es
->style
& ES_MULTILINE
)
1195 const LINEDEF
*line_def
= NULL
;
1196 rc
->top
= es
->format_rect
.top
+ (line
- es
->y_offset
) * es
->line_height
;
1197 if (line
>= es
->line_count
)
1200 line_def
= es
->first_line_def
;
1202 INT index
= es
->selection_end
- line_def
->length
;
1203 while ((index
>= 0) && line_def
->next
) {
1204 line_index
+= line_def
->length
;
1205 line_def
= line_def
->next
;
1206 index
-= line_def
->length
;
1210 line_index
+= line_def
->length
;
1211 line_def
= line_def
->next
;
1215 ssa
= line_def
->ssa
;
1220 rc
->top
= es
->format_rect
.top
;
1224 rc
->bottom
= rc
->top
+ es
->line_height
;
1225 pt1
= (scol
== 0) ? es
->format_rect
.left
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ scol
, TRUE
));
1226 pt2
= (ecol
== -1) ? es
->format_rect
.right
: (short)LOWORD(EDIT_EM_PosFromChar(es
, line_index
+ ecol
, TRUE
));
1229 ScriptStringCPtoX(ssa
, scol
, FALSE
, &pt3
);
1230 pt3
+=es
->format_rect
.left
;
1233 rc
->right
= max(max(pt1
, pt2
),pt3
);
1234 rc
->left
= min(min(pt1
, pt2
),pt3
);
1238 static inline void text_buffer_changed(EDITSTATE
*es
)
1240 es
->text_length
= (UINT
)-1;
1242 HeapFree( GetProcessHeap(), 0, es
->logAttr
);
1244 EDIT_InvalidateUniscribeData(es
);
1247 /*********************************************************************
1251 static void EDIT_LockBuffer(EDITSTATE
*es
)
1255 if(!es
->hloc32W
) return;
1259 CHAR
*textA
= LocalLock(es
->hloc32A
);
1261 UINT countW_new
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
1262 if(countW_new
> es
->buffer_size
+ 1)
1264 UINT alloc_size
= ROUND_TO_GROW(countW_new
* sizeof(WCHAR
));
1265 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es
->buffer_size
, countW_new
);
1266 hloc32W_new
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1269 es
->hloc32W
= hloc32W_new
;
1270 es
->buffer_size
= LocalSize(hloc32W_new
)/sizeof(WCHAR
) - 1;
1271 TRACE("Real new size %d+1 WCHARs\n", es
->buffer_size
);
1274 WARN("FAILED! Will synchronize partially\n");
1276 es
->text
= LocalLock(es
->hloc32W
);
1277 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, es
->text
, es
->buffer_size
+ 1);
1278 LocalUnlock(es
->hloc32A
);
1280 else es
->text
= LocalLock(es
->hloc32W
);
1286 /*********************************************************************
1291 static void EDIT_UnlockBuffer(EDITSTATE
*es
, BOOL force
)
1293 /* Edit window might be already destroyed */
1294 if(!IsWindow(es
->hwndSelf
))
1296 WARN("edit hwnd %p already destroyed\n", es
->hwndSelf
);
1300 if (!es
->lock_count
) {
1301 ERR("lock_count == 0 ... please report\n");
1305 ERR("es->text == 0 ... please report\n");
1308 if (force
|| (es
->lock_count
== 1)) {
1311 UINT countW
= get_text_length(es
) + 1;
1315 UINT countA_new
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
, NULL
, 0, NULL
, NULL
);
1316 TRACE("Synchronizing with 32-bit ANSI buffer\n");
1317 TRACE("%d WCHARs translated to %d bytes\n", countW
, countA_new
);
1318 countA
= LocalSize(es
->hloc32A
);
1319 if(countA_new
> countA
)
1322 UINT alloc_size
= ROUND_TO_GROW(countA_new
);
1323 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA
, alloc_size
);
1324 hloc32A_new
= LocalReAlloc(es
->hloc32A
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
);
1327 es
->hloc32A
= hloc32A_new
;
1328 countA
= LocalSize(hloc32A_new
);
1329 TRACE("Real new size %d bytes\n", countA
);
1332 WARN("FAILED! Will synchronize partially\n");
1334 WideCharToMultiByte(CP_ACP
, 0, es
->text
, countW
,
1335 LocalLock(es
->hloc32A
), countA
, NULL
, NULL
);
1336 LocalUnlock(es
->hloc32A
);
1339 LocalUnlock(es
->hloc32W
);
1343 ERR("no buffer ... please report\n");
1351 /*********************************************************************
1355 * Try to fit size + 1 characters in the buffer.
1357 static BOOL
EDIT_MakeFit(EDITSTATE
*es
, UINT size
)
1361 if (size
<= es
->buffer_size
)
1364 TRACE("trying to ReAlloc to %d+1 characters\n", size
);
1366 /* Force edit to unlock its buffer. es->text now NULL */
1367 EDIT_UnlockBuffer(es
, TRUE
);
1370 UINT alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1371 if ((hNew32W
= LocalReAlloc(es
->hloc32W
, alloc_size
, LMEM_MOVEABLE
| LMEM_ZEROINIT
))) {
1372 TRACE("Old 32 bit handle %p, new handle %p\n", es
->hloc32W
, hNew32W
);
1373 es
->hloc32W
= hNew32W
;
1374 es
->buffer_size
= LocalSize(hNew32W
)/sizeof(WCHAR
) - 1;
1378 EDIT_LockBuffer(es
);
1380 if (es
->buffer_size
< size
) {
1381 WARN("FAILED ! We now have %d+1\n", es
->buffer_size
);
1382 EDIT_NOTIFY_PARENT(es
, EN_ERRSPACE
);
1385 TRACE("We now have %d+1\n", es
->buffer_size
);
1391 /*********************************************************************
1395 * Try to fit size + 1 bytes in the undo buffer.
1398 static BOOL
EDIT_MakeUndoFit(EDITSTATE
*es
, UINT size
)
1402 if (size
<= es
->undo_buffer_size
)
1405 TRACE("trying to ReAlloc to %d+1\n", size
);
1407 alloc_size
= ROUND_TO_GROW((size
+ 1) * sizeof(WCHAR
));
1408 if ((es
->undo_text
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, es
->undo_text
, alloc_size
))) {
1409 es
->undo_buffer_size
= alloc_size
/sizeof(WCHAR
) - 1;
1414 WARN("FAILED ! We now have %d+1\n", es
->undo_buffer_size
);
1420 /*********************************************************************
1422 * EDIT_UpdateTextRegion
1425 static void EDIT_UpdateTextRegion(EDITSTATE
*es
, HRGN hrgn
, BOOL bErase
)
1427 if (es
->flags
& EF_UPDATE
) {
1428 es
->flags
&= ~EF_UPDATE
;
1429 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1431 InvalidateRgn(es
->hwndSelf
, hrgn
, bErase
);
1435 /*********************************************************************
1440 static void EDIT_UpdateText(EDITSTATE
*es
, const RECT
*rc
, BOOL bErase
)
1442 if (es
->flags
& EF_UPDATE
) {
1443 es
->flags
&= ~EF_UPDATE
;
1444 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
1446 InvalidateRect(es
->hwndSelf
, rc
, bErase
);
1449 /*********************************************************************
1451 * EDIT_SL_InvalidateText
1453 * Called from EDIT_InvalidateText().
1454 * Does the job for single-line controls only.
1457 static void EDIT_SL_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1462 EDIT_GetLineRect(es
, 0, start
, end
, &line_rect
);
1463 if (IntersectRect(&rc
, &line_rect
, &es
->format_rect
))
1464 EDIT_UpdateText(es
, &rc
, TRUE
);
1467 /*********************************************************************
1469 * EDIT_ML_InvalidateText
1471 * Called from EDIT_InvalidateText().
1472 * Does the job for multi-line controls only.
1475 static void EDIT_ML_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1477 INT vlc
= get_vertical_line_count(es
);
1478 INT sl
= EDIT_EM_LineFromChar(es
, start
);
1479 INT el
= EDIT_EM_LineFromChar(es
, end
);
1488 if ((el
< es
->y_offset
) || (sl
> es
->y_offset
+ vlc
))
1491 sc
= start
- EDIT_EM_LineIndex(es
, sl
);
1492 ec
= end
- EDIT_EM_LineIndex(es
, el
);
1493 if (sl
< es
->y_offset
) {
1497 if (el
> es
->y_offset
+ vlc
) {
1498 el
= es
->y_offset
+ vlc
;
1499 ec
= EDIT_EM_LineLength(es
, EDIT_EM_LineIndex(es
, el
));
1501 GetClientRect(es
->hwndSelf
, &rc1
);
1502 IntersectRect(&rcWnd
, &rc1
, &es
->format_rect
);
1504 EDIT_GetLineRect(es
, sl
, sc
, ec
, &rcLine
);
1505 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1506 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1508 EDIT_GetLineRect(es
, sl
, sc
,
1509 EDIT_EM_LineLength(es
,
1510 EDIT_EM_LineIndex(es
, sl
)),
1512 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1513 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1514 for (l
= sl
+ 1 ; l
< el
; l
++) {
1515 EDIT_GetLineRect(es
, l
, 0,
1516 EDIT_EM_LineLength(es
,
1517 EDIT_EM_LineIndex(es
, l
)),
1519 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1520 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1522 EDIT_GetLineRect(es
, el
, 0, ec
, &rcLine
);
1523 if (IntersectRect(&rcUpdate
, &rcWnd
, &rcLine
))
1524 EDIT_UpdateText(es
, &rcUpdate
, TRUE
);
1529 /*********************************************************************
1531 * EDIT_InvalidateText
1533 * Invalidate the text from offset start up to, but not including,
1534 * offset end. Useful for (re)painting the selection.
1535 * Regions outside the linewidth are not invalidated.
1536 * end == -1 means end == TextLength.
1537 * start and end need not be ordered.
1540 static void EDIT_InvalidateText(EDITSTATE
*es
, INT start
, INT end
)
1546 end
= get_text_length(es
);
1554 if (es
->style
& ES_MULTILINE
)
1555 EDIT_ML_InvalidateText(es
, start
, end
);
1557 EDIT_SL_InvalidateText(es
, start
, end
);
1561 /*********************************************************************
1565 * note: unlike the specs say: the order of start and end
1566 * _is_ preserved in Windows. (i.e. start can be > end)
1567 * In other words: this handler is OK
1570 static void EDIT_EM_SetSel(EDITSTATE
*es
, UINT start
, UINT end
, BOOL after_wrap
)
1572 UINT old_start
= es
->selection_start
;
1573 UINT old_end
= es
->selection_end
;
1574 UINT len
= get_text_length(es
);
1576 if (start
== (UINT
)-1) {
1577 start
= es
->selection_end
;
1578 end
= es
->selection_end
;
1580 start
= min(start
, len
);
1581 end
= min(end
, len
);
1583 es
->selection_start
= start
;
1584 es
->selection_end
= end
;
1586 es
->flags
|= EF_AFTER_WRAP
;
1588 es
->flags
&= ~EF_AFTER_WRAP
;
1589 /* Compute the necessary invalidation region. */
1590 /* Note that we don't need to invalidate regions which have
1591 * "never" been selected, or those which are "still" selected.
1592 * In fact, every time we hit a selection boundary, we can
1593 * *toggle* whether we need to invalidate. Thus we can optimize by
1594 * *sorting* the interval endpoints. Let's assume that we sort them
1596 * start <= end <= old_start <= old_end
1597 * Knuth 5.3.1 (p 183) assures us that this can be done optimally
1598 * in 5 comparisons; i.e. it is impossible to do better than the
1600 ORDER_UINT(end
, old_end
);
1601 ORDER_UINT(start
, old_start
);
1602 ORDER_UINT(old_start
, old_end
);
1603 ORDER_UINT(start
, end
);
1604 /* Note that at this point 'end' and 'old_start' are not in order, but
1605 * start is definitely the min. and old_end is definitely the max. */
1606 if (end
!= old_start
)
1610 * ORDER_UINT32(end, old_start);
1611 * EDIT_InvalidateText(es, start, end);
1612 * EDIT_InvalidateText(es, old_start, old_end);
1613 * in place of the following if statement.
1614 * (That would complete the optimal five-comparison four-element sort.)
1616 if (old_start
> end
)
1618 EDIT_InvalidateText(es
, start
, end
);
1619 EDIT_InvalidateText(es
, old_start
, old_end
);
1623 EDIT_InvalidateText(es
, start
, old_start
);
1624 EDIT_InvalidateText(es
, end
, old_end
);
1627 else EDIT_InvalidateText(es
, start
, old_end
);
1631 /*********************************************************************
1633 * EDIT_UpdateScrollInfo
1636 static void EDIT_UpdateScrollInfo(EDITSTATE
*es
)
1638 if ((es
->style
& WS_VSCROLL
) && !(es
->flags
& EF_VSCROLL_TRACK
))
1641 si
.cbSize
= sizeof(SCROLLINFO
);
1642 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1644 si
.nMax
= es
->line_count
- 1;
1645 si
.nPage
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1646 si
.nPos
= es
->y_offset
;
1647 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1648 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1649 SetScrollInfo(es
->hwndSelf
, SB_VERT
, &si
, TRUE
);
1652 if ((es
->style
& WS_HSCROLL
) && !(es
->flags
& EF_HSCROLL_TRACK
))
1655 si
.cbSize
= sizeof(SCROLLINFO
);
1656 si
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_DISABLENOSCROLL
;
1658 si
.nMax
= es
->text_width
- 1;
1659 si
.nPage
= es
->format_rect
.right
- es
->format_rect
.left
;
1660 si
.nPos
= es
->x_offset
;
1661 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1662 si
.nMin
, si
.nMax
, si
.nPage
, si
.nPos
);
1663 SetScrollInfo(es
->hwndSelf
, SB_HORZ
, &si
, TRUE
);
1668 /*********************************************************************
1670 * EDIT_EM_LineScroll_internal
1672 * Version of EDIT_EM_LineScroll for internal use.
1673 * It doesn't refuse if ES_MULTILINE is set and assumes that
1674 * dx is in pixels, dy - in lines.
1677 static BOOL
EDIT_EM_LineScroll_internal(EDITSTATE
*es
, INT dx
, INT dy
)
1680 INT x_offset_in_pixels
;
1681 INT lines_per_page
= (es
->format_rect
.bottom
- es
->format_rect
.top
) /
1684 if (es
->style
& ES_MULTILINE
)
1686 x_offset_in_pixels
= es
->x_offset
;
1691 x_offset_in_pixels
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->x_offset
, FALSE
));
1694 if (-dx
> x_offset_in_pixels
)
1695 dx
= -x_offset_in_pixels
;
1696 if (dx
> es
->text_width
- x_offset_in_pixels
)
1697 dx
= es
->text_width
- x_offset_in_pixels
;
1698 nyoff
= max(0, es
->y_offset
+ dy
);
1699 if (nyoff
>= es
->line_count
- lines_per_page
)
1700 nyoff
= max(0, es
->line_count
- lines_per_page
);
1701 dy
= (es
->y_offset
- nyoff
) * es
->line_height
;
1706 es
->y_offset
= nyoff
;
1707 if(es
->style
& ES_MULTILINE
)
1710 es
->x_offset
+= dx
/ es
->char_width
;
1712 GetClientRect(es
->hwndSelf
, &rc1
);
1713 IntersectRect(&rc
, &rc1
, &es
->format_rect
);
1714 ScrollWindowEx(es
->hwndSelf
, -dx
, dy
,
1715 NULL
, &rc
, NULL
, NULL
, SW_INVALIDATE
);
1716 /* force scroll info update */
1717 EDIT_UpdateScrollInfo(es
);
1719 if (dx
&& !(es
->flags
& EF_HSCROLL_TRACK
))
1720 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
1721 if (dy
&& !(es
->flags
& EF_VSCROLL_TRACK
))
1722 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
1726 /*********************************************************************
1730 * NOTE: dx is in average character widths, dy - in lines;
1733 static BOOL
EDIT_EM_LineScroll(EDITSTATE
*es
, INT dx
, INT dy
)
1735 if (!(es
->style
& ES_MULTILINE
))
1738 dx
*= es
->char_width
;
1739 return EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1743 /*********************************************************************
1748 static LRESULT
EDIT_EM_Scroll(EDITSTATE
*es
, INT action
)
1752 if (!(es
->style
& ES_MULTILINE
))
1753 return (LRESULT
)FALSE
;
1763 if (es
->y_offset
< es
->line_count
- 1)
1768 dy
= -(es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1771 if (es
->y_offset
< es
->line_count
- 1)
1772 dy
= (es
->format_rect
.bottom
- es
->format_rect
.top
) / es
->line_height
;
1775 return (LRESULT
)FALSE
;
1778 INT vlc
= get_vertical_line_count(es
);
1779 /* check if we are going to move too far */
1780 if(es
->y_offset
+ dy
> es
->line_count
- vlc
)
1781 dy
= max(es
->line_count
- vlc
, 0) - es
->y_offset
;
1783 /* Notification is done in EDIT_EM_LineScroll */
1785 EDIT_EM_LineScroll(es
, 0, dy
);
1786 return MAKELONG(dy
, TRUE
);
1790 return (LRESULT
)FALSE
;
1794 /*********************************************************************
1799 static void EDIT_SetCaretPos(EDITSTATE
*es
, INT pos
,
1804 if (es
->flags
& EF_FOCUSED
)
1806 res
= EDIT_EM_PosFromChar(es
, pos
, after_wrap
);
1807 TRACE("%d - %dx%d\n", pos
, (short)LOWORD(res
), (short)HIWORD(res
));
1808 SetCaretPos((short)LOWORD(res
), (short)HIWORD(res
));
1813 /*********************************************************************
1818 static void EDIT_EM_ScrollCaret(EDITSTATE
*es
)
1820 if (es
->style
& ES_MULTILINE
) {
1824 INT cw
= es
->char_width
;
1829 l
= EDIT_EM_LineFromChar(es
, es
->selection_end
);
1830 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
));
1831 vlc
= get_vertical_line_count(es
);
1832 if (l
>= es
->y_offset
+ vlc
)
1833 dy
= l
- vlc
+ 1 - es
->y_offset
;
1834 if (l
< es
->y_offset
)
1835 dy
= l
- es
->y_offset
;
1836 ww
= es
->format_rect
.right
- es
->format_rect
.left
;
1837 if (x
< es
->format_rect
.left
)
1838 dx
= x
- es
->format_rect
.left
- ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1839 if (x
> es
->format_rect
.right
)
1840 dx
= x
- es
->format_rect
.left
- (HSCROLL_FRACTION
- 1) * ww
/ HSCROLL_FRACTION
/ cw
* cw
;
1841 if (dy
|| dx
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1843 /* check if we are going to move too far */
1844 if(es
->x_offset
+ dx
+ ww
> es
->text_width
)
1845 dx
= es
->text_width
- ww
- es
->x_offset
;
1846 if(dx
|| dy
|| (es
->y_offset
&& (es
->line_count
- es
->y_offset
< vlc
)))
1847 EDIT_EM_LineScroll_internal(es
, dx
, dy
);
1854 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1855 format_width
= es
->format_rect
.right
- es
->format_rect
.left
;
1856 if (x
< es
->format_rect
.left
) {
1857 goal
= es
->format_rect
.left
+ format_width
/ HSCROLL_FRACTION
;
1860 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1861 } while ((x
< goal
) && es
->x_offset
);
1862 /* FIXME: use ScrollWindow() somehow to improve performance */
1863 EDIT_UpdateText(es
, NULL
, TRUE
);
1864 } else if (x
> es
->format_rect
.right
) {
1866 INT len
= get_text_length(es
);
1867 goal
= es
->format_rect
.right
- format_width
/ HSCROLL_FRACTION
;
1870 x
= (short)LOWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, FALSE
));
1871 x_last
= (short)LOWORD(EDIT_EM_PosFromChar(es
, len
, FALSE
));
1872 } while ((x
> goal
) && (x_last
> es
->format_rect
.right
));
1873 /* FIXME: use ScrollWindow() somehow to improve performance */
1874 EDIT_UpdateText(es
, NULL
, TRUE
);
1878 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
1882 /*********************************************************************
1887 static void EDIT_MoveBackward(EDITSTATE
*es
, BOOL extend
)
1889 INT e
= es
->selection_end
;
1893 if ((es
->style
& ES_MULTILINE
) && e
&&
1894 (es
->text
[e
- 1] == '\r') && (es
->text
[e
] == '\n')) {
1896 if (e
&& (es
->text
[e
- 1] == '\r'))
1900 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1901 EDIT_EM_ScrollCaret(es
);
1905 /*********************************************************************
1909 * Only for multi line controls
1910 * Move the caret one line down, on a column with the nearest
1911 * x coordinate on the screen (might be a different column).
1914 static void EDIT_MoveDown_ML(EDITSTATE
*es
, BOOL extend
)
1916 INT s
= es
->selection_start
;
1917 INT e
= es
->selection_end
;
1918 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
1919 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
1920 INT x
= (short)LOWORD(pos
);
1921 INT y
= (short)HIWORD(pos
);
1923 e
= EDIT_CharFromPos(es
, x
, y
+ es
->line_height
, &after_wrap
);
1926 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
1927 EDIT_EM_ScrollCaret(es
);
1931 /*********************************************************************
1936 static void EDIT_MoveEnd(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1938 BOOL after_wrap
= FALSE
;
1941 /* Pass a high value in x to make sure of receiving the end of the line */
1942 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1943 e
= EDIT_CharFromPos(es
, 0x3fffffff,
1944 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), &after_wrap
);
1946 e
= get_text_length(es
);
1947 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, after_wrap
);
1948 EDIT_EM_ScrollCaret(es
);
1952 /*********************************************************************
1957 static void EDIT_MoveForward(EDITSTATE
*es
, BOOL extend
)
1959 INT e
= es
->selection_end
;
1963 if ((es
->style
& ES_MULTILINE
) && (es
->text
[e
- 1] == '\r')) {
1964 if (es
->text
[e
] == '\n')
1966 else if ((es
->text
[e
] == '\r') && (es
->text
[e
+ 1] == '\n'))
1970 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1971 EDIT_EM_ScrollCaret(es
);
1975 /*********************************************************************
1979 * Home key: move to beginning of line.
1982 static void EDIT_MoveHome(EDITSTATE
*es
, BOOL extend
, BOOL ctrl
)
1986 /* Pass the x_offset in x to make sure of receiving the first position of the line */
1987 if (!ctrl
&& (es
->style
& ES_MULTILINE
))
1988 e
= EDIT_CharFromPos(es
, -es
->x_offset
,
1989 HIWORD(EDIT_EM_PosFromChar(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
)), NULL
);
1992 EDIT_EM_SetSel(es
, extend
? es
->selection_start
: e
, e
, FALSE
);
1993 EDIT_EM_ScrollCaret(es
);
1997 /*********************************************************************
1999 * EDIT_MovePageDown_ML
2001 * Only for multi line controls
2002 * Move the caret one page down, on a column with the nearest
2003 * x coordinate on the screen (might be a different column).
2006 static void EDIT_MovePageDown_ML(EDITSTATE
*es
, BOOL extend
)
2008 INT s
= es
->selection_start
;
2009 INT e
= es
->selection_end
;
2010 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2011 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2012 INT x
= (short)LOWORD(pos
);
2013 INT y
= (short)HIWORD(pos
);
2015 e
= EDIT_CharFromPos(es
, x
,
2016 y
+ (es
->format_rect
.bottom
- es
->format_rect
.top
),
2020 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2021 EDIT_EM_ScrollCaret(es
);
2025 /*********************************************************************
2027 * EDIT_MovePageUp_ML
2029 * Only for multi line controls
2030 * Move the caret one page up, on a column with the nearest
2031 * x coordinate on the screen (might be a different column).
2034 static void EDIT_MovePageUp_ML(EDITSTATE
*es
, BOOL extend
)
2036 INT s
= es
->selection_start
;
2037 INT e
= es
->selection_end
;
2038 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2039 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2040 INT x
= (short)LOWORD(pos
);
2041 INT y
= (short)HIWORD(pos
);
2043 e
= EDIT_CharFromPos(es
, x
,
2044 y
- (es
->format_rect
.bottom
- es
->format_rect
.top
),
2048 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2049 EDIT_EM_ScrollCaret(es
);
2053 /*********************************************************************
2057 * Only for multi line controls
2058 * Move the caret one line up, on a column with the nearest
2059 * x coordinate on the screen (might be a different column).
2062 static void EDIT_MoveUp_ML(EDITSTATE
*es
, BOOL extend
)
2064 INT s
= es
->selection_start
;
2065 INT e
= es
->selection_end
;
2066 BOOL after_wrap
= (es
->flags
& EF_AFTER_WRAP
);
2067 LRESULT pos
= EDIT_EM_PosFromChar(es
, e
, after_wrap
);
2068 INT x
= (short)LOWORD(pos
);
2069 INT y
= (short)HIWORD(pos
);
2071 e
= EDIT_CharFromPos(es
, x
, y
- es
->line_height
, &after_wrap
);
2074 EDIT_EM_SetSel(es
, s
, e
, after_wrap
);
2075 EDIT_EM_ScrollCaret(es
);
2079 /*********************************************************************
2081 * EDIT_MoveWordBackward
2084 static void EDIT_MoveWordBackward(EDITSTATE
*es
, BOOL extend
)
2086 INT s
= es
->selection_start
;
2087 INT e
= es
->selection_end
;
2092 l
= EDIT_EM_LineFromChar(es
, e
);
2093 ll
= EDIT_EM_LineLength(es
, e
);
2094 li
= EDIT_EM_LineIndex(es
, l
);
2097 li
= EDIT_EM_LineIndex(es
, l
- 1);
2098 e
= li
+ EDIT_EM_LineLength(es
, li
);
2101 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
2105 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2106 EDIT_EM_ScrollCaret(es
);
2110 /*********************************************************************
2112 * EDIT_MoveWordForward
2115 static void EDIT_MoveWordForward(EDITSTATE
*es
, BOOL extend
)
2117 INT s
= es
->selection_start
;
2118 INT e
= es
->selection_end
;
2123 l
= EDIT_EM_LineFromChar(es
, e
);
2124 ll
= EDIT_EM_LineLength(es
, e
);
2125 li
= EDIT_EM_LineIndex(es
, l
);
2127 if ((es
->style
& ES_MULTILINE
) && (l
!= es
->line_count
- 1))
2128 e
= EDIT_EM_LineIndex(es
, l
+ 1);
2130 e
= li
+ EDIT_CallWordBreakProc(es
,
2131 li
, e
- li
+ 1, ll
, WB_RIGHT
);
2135 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
2136 EDIT_EM_ScrollCaret(es
);
2140 /*********************************************************************
2145 static INT
EDIT_PaintText(EDITSTATE
*es
, HDC dc
, INT x
, INT y
, INT line
, INT col
, INT count
, BOOL rev
)
2149 LOGFONTW underline_font
;
2150 HFONT hUnderline
= 0;
2159 BkMode
= GetBkMode(dc
);
2160 BkColor
= GetBkColor(dc
);
2161 TextColor
= GetTextColor(dc
);
2163 if (es
->composition_len
== 0)
2165 SetBkColor(dc
, GetSysColor(COLOR_HIGHLIGHT
));
2166 SetTextColor(dc
, GetSysColor(COLOR_HIGHLIGHTTEXT
));
2167 SetBkMode( dc
, OPAQUE
);
2171 HFONT current
= GetCurrentObject(dc
,OBJ_FONT
);
2172 GetObjectW(current
,sizeof(LOGFONTW
),&underline_font
);
2173 underline_font
.lfUnderline
= TRUE
;
2174 hUnderline
= CreateFontIndirectW(&underline_font
);
2175 old_font
= SelectObject(dc
,hUnderline
);
2178 li
= EDIT_EM_LineIndex(es
, line
);
2179 if (es
->style
& ES_MULTILINE
) {
2180 ret
= (INT
)LOWORD(TabbedTextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
,
2181 es
->tabs_count
, es
->tabs
, es
->format_rect
.left
- es
->x_offset
));
2183 TextOutW(dc
, x
, y
, es
->text
+ li
+ col
, count
);
2184 GetTextExtentPoint32W(dc
, es
->text
+ li
+ col
, count
, &size
);
2188 if (es
->composition_len
== 0)
2190 SetBkColor(dc
, BkColor
);
2191 SetTextColor(dc
, TextColor
);
2192 SetBkMode( dc
, BkMode
);
2197 SelectObject(dc
,old_font
);
2199 DeleteObject(hUnderline
);
2206 /*********************************************************************
2211 static void EDIT_PaintLine(EDITSTATE
*es
, HDC dc
, INT line
, BOOL rev
)
2220 SCRIPT_STRING_ANALYSIS ssa
;
2222 if (es
->style
& ES_MULTILINE
) {
2223 INT vlc
= get_vertical_line_count(es
);
2225 if ((line
< es
->y_offset
) || (line
> es
->y_offset
+ vlc
) || (line
>= es
->line_count
))
2230 TRACE("line=%d\n", line
);
2232 ssa
= EDIT_UpdateUniscribeData(es
, dc
, line
);
2233 pos
= EDIT_EM_PosFromChar(es
, EDIT_EM_LineIndex(es
, line
), FALSE
);
2234 x
= (short)LOWORD(pos
);
2235 y
= (short)HIWORD(pos
);
2237 if (es
->style
& ES_MULTILINE
)
2239 int line_idx
= line
;
2241 if (es
->style
& ES_RIGHT
|| es
->style
& ES_CENTER
)
2243 LINEDEF
*line_def
= es
->first_line_def
;
2246 while (line_def
&& line_idx
)
2248 line_def
= line_def
->next
;
2251 w
= es
->format_rect
.right
- es
->format_rect
.left
;
2252 lw
= line_def
->width
;
2254 if (es
->style
& ES_RIGHT
)
2256 else if (es
->style
& ES_CENTER
)
2259 x
+= es
->format_rect
.left
;
2264 li
= EDIT_EM_LineIndex(es
, line
);
2265 ll
= EDIT_EM_LineLength(es
, li
);
2266 s
= min(es
->selection_start
, es
->selection_end
);
2267 e
= max(es
->selection_start
, es
->selection_end
);
2268 s
= min(li
+ ll
, max(li
, s
));
2269 e
= min(li
+ ll
, max(li
, e
));
2273 ScriptStringOut(ssa
, x
, y
, 0, &es
->format_rect
, s
- li
, e
- li
, FALSE
);
2274 else if (rev
&& (s
!= e
) &&
2275 ((es
->flags
& EF_FOCUSED
) || (es
->style
& ES_NOHIDESEL
))) {
2276 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, s
- li
, FALSE
);
2277 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, s
- li
, e
- s
, TRUE
);
2278 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, e
- li
, li
+ ll
- e
, FALSE
);
2280 x
+= EDIT_PaintText(es
, dc
, x
, y
, line
, 0, ll
, FALSE
);
2284 /*********************************************************************
2286 * EDIT_AdjustFormatRect
2288 * Adjusts the format rectangle for the current font and the
2289 * current client rectangle.
2292 static void EDIT_AdjustFormatRect(EDITSTATE
*es
)
2296 es
->format_rect
.right
= max(es
->format_rect
.right
, es
->format_rect
.left
+ es
->char_width
);
2297 if (es
->style
& ES_MULTILINE
)
2299 INT fw
, vlc
, max_x_offset
, max_y_offset
;
2301 vlc
= get_vertical_line_count(es
);
2302 es
->format_rect
.bottom
= es
->format_rect
.top
+ vlc
* es
->line_height
;
2304 /* correct es->x_offset */
2305 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2306 max_x_offset
= es
->text_width
- fw
;
2307 if(max_x_offset
< 0) max_x_offset
= 0;
2308 if(es
->x_offset
> max_x_offset
)
2309 es
->x_offset
= max_x_offset
;
2311 /* correct es->y_offset */
2312 max_y_offset
= es
->line_count
- vlc
;
2313 if(max_y_offset
< 0) max_y_offset
= 0;
2314 if(es
->y_offset
> max_y_offset
)
2315 es
->y_offset
= max_y_offset
;
2317 /* force scroll info update */
2318 EDIT_UpdateScrollInfo(es
);
2321 /* Windows doesn't care to fix text placement for SL controls */
2322 es
->format_rect
.bottom
= es
->format_rect
.top
+ es
->line_height
;
2324 /* Always stay within the client area */
2325 GetClientRect(es
->hwndSelf
, &ClientRect
);
2326 es
->format_rect
.bottom
= min(es
->format_rect
.bottom
, ClientRect
.bottom
);
2328 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
))
2329 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2331 EDIT_SetCaretPos(es
, es
->selection_end
, es
->flags
& EF_AFTER_WRAP
);
2335 /*********************************************************************
2339 * note: this is not (exactly) the handler called on EM_SETRECTNP
2340 * it is also used to set the rect of a single line control
2343 static void EDIT_SetRectNP(EDITSTATE
*es
, const RECT
*rc
)
2347 ExStyle
= GetWindowLongPtrW(es
->hwndSelf
, GWL_EXSTYLE
);
2349 CopyRect(&es
->format_rect
, rc
);
2351 if (ExStyle
& WS_EX_CLIENTEDGE
) {
2352 es
->format_rect
.left
++;
2353 es
->format_rect
.right
--;
2355 if (es
->format_rect
.bottom
- es
->format_rect
.top
2356 >= es
->line_height
+ 2)
2358 es
->format_rect
.top
++;
2359 es
->format_rect
.bottom
--;
2362 else if (es
->style
& WS_BORDER
) {
2363 bw
= GetSystemMetrics(SM_CXBORDER
) + 1;
2364 bh
= GetSystemMetrics(SM_CYBORDER
) + 1;
2365 InflateRect(&es
->format_rect
, -bw
, 0);
2366 if (es
->format_rect
.bottom
- es
->format_rect
.top
>= es
->line_height
+ 2 * bh
)
2367 InflateRect(&es
->format_rect
, 0, -bh
);
2370 es
->format_rect
.left
+= es
->left_margin
;
2371 es
->format_rect
.right
-= es
->right_margin
;
2372 EDIT_AdjustFormatRect(es
);
2376 /*********************************************************************
2380 * returns line number (not index) in high-order word of result.
2381 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2382 * to Richedit, not to the edit control. Original documentation is valid.
2383 * FIXME: do the specs mean to return -1 if outside client area or
2384 * if outside formatting rectangle ???
2387 static LRESULT
EDIT_EM_CharFromPos(EDITSTATE
*es
, INT x
, INT y
)
2395 GetClientRect(es
->hwndSelf
, &rc
);
2396 if (!PtInRect(&rc
, pt
))
2399 index
= EDIT_CharFromPos(es
, x
, y
, NULL
);
2400 return MAKELONG(index
, EDIT_EM_LineFromChar(es
, index
));
2404 /*********************************************************************
2408 * Enable or disable soft breaks.
2410 * This means: insert or remove the soft linebreak character (\r\r\n).
2411 * Take care to check if the text still fits the buffer after insertion.
2412 * If not, notify with EN_ERRSPACE.
2415 static BOOL
EDIT_EM_FmtLines(EDITSTATE
*es
, BOOL add_eol
)
2417 es
->flags
&= ~EF_USE_SOFTBRK
;
2419 es
->flags
|= EF_USE_SOFTBRK
;
2420 FIXME("soft break enabled, not implemented\n");
2426 /*********************************************************************
2430 * Hopefully this won't fire back at us.
2431 * We always start with a fixed buffer in the local heap.
2432 * Despite of the documentation says that the local heap is used
2433 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2434 * buffer on the local heap.
2437 static HLOCAL
EDIT_EM_GetHandle(EDITSTATE
*es
)
2441 if (!(es
->style
& ES_MULTILINE
))
2445 hLocal
= es
->hloc32W
;
2451 UINT countA
, alloc_size
;
2452 TRACE("Allocating 32-bit ANSI alias buffer\n");
2453 countA
= WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, NULL
, 0, NULL
, NULL
);
2454 alloc_size
= ROUND_TO_GROW(countA
);
2455 if(!(es
->hloc32A
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
2457 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size
);
2460 textA
= LocalLock(es
->hloc32A
);
2461 WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, countA
, NULL
, NULL
);
2462 LocalUnlock(es
->hloc32A
);
2464 hLocal
= es
->hloc32A
;
2467 EDIT_UnlockBuffer(es
, TRUE
);
2469 /* The text buffer handle belongs to the app */
2470 es
->hlocapp
= hLocal
;
2472 TRACE("Returning %p, LocalSize() = %ld\n", hLocal
, LocalSize(hLocal
));
2477 /*********************************************************************
2482 static INT
EDIT_EM_GetLine(EDITSTATE
*es
, INT line
, LPWSTR dst
, BOOL unicode
)
2485 INT line_len
, dst_len
;
2488 if (es
->style
& ES_MULTILINE
) {
2489 if (line
>= es
->line_count
)
2493 i
= EDIT_EM_LineIndex(es
, line
);
2495 line_len
= EDIT_EM_LineLength(es
, i
);
2496 dst_len
= *(WORD
*)dst
;
2499 if(dst_len
<= line_len
)
2501 memcpy(dst
, src
, dst_len
* sizeof(WCHAR
));
2504 else /* Append 0 if enough space */
2506 memcpy(dst
, src
, line_len
* sizeof(WCHAR
));
2513 INT ret
= WideCharToMultiByte(CP_ACP
, 0, src
, line_len
, (LPSTR
)dst
, dst_len
, NULL
, NULL
);
2514 if(!ret
&& line_len
) /* Insufficient buffer size */
2516 if(ret
< dst_len
) /* Append 0 if enough space */
2517 ((LPSTR
)dst
)[ret
] = 0;
2523 /*********************************************************************
2528 static LRESULT
EDIT_EM_GetSel(const EDITSTATE
*es
, PUINT start
, PUINT end
)
2530 UINT s
= es
->selection_start
;
2531 UINT e
= es
->selection_end
;
2538 return MAKELONG(s
, e
);
2542 /*********************************************************************
2546 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2549 static void EDIT_EM_ReplaceSel(EDITSTATE
*es
, BOOL can_undo
, const WCHAR
*lpsz_replace
, UINT strl
,
2550 BOOL send_update
, BOOL honor_limit
)
2552 UINT tl
= get_text_length(es
);
2563 TRACE("%s, can_undo %d, send_update %d\n",
2564 debugstr_wn(lpsz_replace
, strl
), can_undo
, send_update
);
2566 s
= es
->selection_start
;
2567 e
= es
->selection_end
;
2569 EDIT_InvalidateUniscribeData(es
);
2570 if ((s
== e
) && !strl
)
2575 size
= tl
- (e
- s
) + strl
;
2579 /* Issue the EN_MAXTEXT notification and continue with replacing text
2580 * so that buffer limit is honored. */
2581 if ((honor_limit
) && (size
> es
->buffer_limit
)) {
2582 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2583 /* Buffer limit can be smaller than the actual length of text in combobox */
2584 if (es
->buffer_limit
< (tl
- (e
-s
)))
2587 strl
= min(strl
, es
->buffer_limit
- (tl
- (e
-s
)));
2590 if (!EDIT_MakeFit(es
, tl
- (e
- s
) + strl
))
2594 /* there is something to be deleted */
2595 TRACE("deleting stuff.\n");
2597 buf
= HeapAlloc(GetProcessHeap(), 0, (bufl
+ 1) * sizeof(WCHAR
));
2599 memcpy(buf
, es
->text
+ s
, bufl
* sizeof(WCHAR
));
2600 buf
[bufl
] = 0; /* ensure 0 termination */
2602 strcpyW(es
->text
+ s
, es
->text
+ e
);
2603 text_buffer_changed(es
);
2606 /* there is an insertion */
2607 tl
= get_text_length(es
);
2608 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
));
2609 for (p
= es
->text
+ tl
; p
>= es
->text
+ s
; p
--)
2611 for (i
= 0 , p
= es
->text
+ s
; i
< strl
; i
++)
2612 p
[i
] = lpsz_replace
[i
];
2613 if(es
->style
& ES_UPPERCASE
)
2614 CharUpperBuffW(p
, strl
);
2615 else if(es
->style
& ES_LOWERCASE
)
2616 CharLowerBuffW(p
, strl
);
2617 text_buffer_changed(es
);
2619 if (es
->style
& ES_MULTILINE
)
2621 INT st
= min(es
->selection_start
, es
->selection_end
);
2622 INT vlc
= get_vertical_line_count(es
);
2624 hrgn
= CreateRectRgn(0, 0, 0, 0);
2625 EDIT_BuildLineDefs_ML(es
, st
, st
+ strl
,
2626 strl
- abs(es
->selection_end
- es
->selection_start
), hrgn
);
2627 /* if text is too long undo all changes */
2628 if (honor_limit
&& !(es
->style
& ES_AUTOVSCROLL
) && (es
->line_count
> vlc
)) {
2630 strcpyW(es
->text
+ e
, es
->text
+ e
+ strl
);
2632 for (i
= 0 , p
= es
->text
; i
< e
- s
; i
++)
2634 text_buffer_changed(es
);
2635 EDIT_BuildLineDefs_ML(es
, s
, e
,
2636 abs(es
->selection_end
- es
->selection_start
) - strl
, hrgn
);
2639 hrgn
= CreateRectRgn(0, 0, 0, 0);
2640 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2644 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
2645 EDIT_InvalidateUniscribeData(es
);
2646 EDIT_CalcLineWidth_SL(es
);
2647 /* remove chars that don't fit */
2648 if (honor_limit
&& !(es
->style
& ES_AUTOHSCROLL
) && (es
->text_width
> fw
)) {
2649 while ((es
->text_width
> fw
) && s
+ strl
>= s
) {
2650 strcpyW(es
->text
+ s
+ strl
- 1, es
->text
+ s
+ strl
);
2652 es
->text_length
= -1;
2653 EDIT_InvalidateUniscribeData(es
);
2654 EDIT_CalcLineWidth_SL(es
);
2656 text_buffer_changed(es
);
2657 EDIT_NOTIFY_PARENT(es
, EN_MAXTEXT
);
2663 utl
= strlenW(es
->undo_text
);
2664 if (!es
->undo_insert_count
&& (*es
->undo_text
&& (s
== es
->undo_position
))) {
2665 /* undo-buffer is extended to the right */
2666 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2667 memcpy(es
->undo_text
+ utl
, buf
, (e
- s
)*sizeof(WCHAR
));
2668 (es
->undo_text
+ utl
)[e
- s
] = 0; /* ensure 0 termination */
2669 } else if (!es
->undo_insert_count
&& (*es
->undo_text
&& (e
== es
->undo_position
))) {
2670 /* undo-buffer is extended to the left */
2671 EDIT_MakeUndoFit(es
, utl
+ e
- s
);
2672 for (p
= es
->undo_text
+ utl
; p
>= es
->undo_text
; p
--)
2674 for (i
= 0 , p
= es
->undo_text
; i
< e
- s
; i
++)
2676 es
->undo_position
= s
;
2678 /* new undo-buffer */
2679 EDIT_MakeUndoFit(es
, e
- s
);
2680 memcpy(es
->undo_text
, buf
, (e
- s
)*sizeof(WCHAR
));
2681 es
->undo_text
[e
- s
] = 0; /* ensure 0 termination */
2682 es
->undo_position
= s
;
2684 /* any deletion makes the old insertion-undo invalid */
2685 es
->undo_insert_count
= 0;
2687 EDIT_EM_EmptyUndoBuffer(es
);
2691 if ((s
== es
->undo_position
) ||
2692 ((es
->undo_insert_count
) &&
2693 (s
== es
->undo_position
+ es
->undo_insert_count
)))
2695 * insertion is new and at delete position or
2696 * an extension to either left or right
2698 es
->undo_insert_count
+= strl
;
2700 /* new insertion undo */
2701 es
->undo_position
= s
;
2702 es
->undo_insert_count
= strl
;
2703 /* new insertion makes old delete-buffer invalid */
2704 *es
->undo_text
= '\0';
2707 EDIT_EM_EmptyUndoBuffer(es
);
2710 HeapFree(GetProcessHeap(), 0, buf
);
2714 /* If text has been deleted and we're right or center aligned then scroll rightward */
2715 if (es
->style
& (ES_RIGHT
| ES_CENTER
))
2717 INT delta
= strl
- abs(es
->selection_end
- es
->selection_start
);
2719 if (delta
< 0 && es
->x_offset
)
2721 if (abs(delta
) > es
->x_offset
)
2724 es
->x_offset
+= delta
;
2728 EDIT_EM_SetSel(es
, s
, s
, FALSE
);
2729 es
->flags
|= EF_MODIFIED
;
2730 if (send_update
) es
->flags
|= EF_UPDATE
;
2733 EDIT_UpdateTextRegion(es
, hrgn
, TRUE
);
2737 EDIT_UpdateText(es
, NULL
, TRUE
);
2739 EDIT_EM_ScrollCaret(es
);
2741 /* force scroll info update */
2742 EDIT_UpdateScrollInfo(es
);
2745 if(send_update
|| (es
->flags
& EF_UPDATE
))
2747 es
->flags
&= ~EF_UPDATE
;
2748 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
2750 EDIT_InvalidateUniscribeData(es
);
2754 /*********************************************************************
2758 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2761 static void EDIT_EM_SetHandle(EDITSTATE
*es
, HLOCAL hloc
)
2763 if (!(es
->style
& ES_MULTILINE
))
2767 WARN("called with NULL handle\n");
2771 EDIT_UnlockBuffer(es
, TRUE
);
2777 LocalFree(es
->hloc32A
);
2789 countA
= LocalSize(hloc
);
2790 textA
= LocalLock(hloc
);
2791 countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, NULL
, 0);
2792 if(!(hloc32W_new
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, countW
* sizeof(WCHAR
))))
2794 ERR("Could not allocate new unicode buffer\n");
2797 textW
= LocalLock(hloc32W_new
);
2798 MultiByteToWideChar(CP_ACP
, 0, textA
, countA
, textW
, countW
);
2799 LocalUnlock(hloc32W_new
);
2803 LocalFree(es
->hloc32W
);
2805 es
->hloc32W
= hloc32W_new
;
2809 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
2811 /* The text buffer handle belongs to the control */
2814 EDIT_LockBuffer(es
);
2815 text_buffer_changed(es
);
2817 es
->x_offset
= es
->y_offset
= 0;
2818 es
->selection_start
= es
->selection_end
= 0;
2819 EDIT_EM_EmptyUndoBuffer(es
);
2820 es
->flags
&= ~EF_MODIFIED
;
2821 es
->flags
&= ~EF_UPDATE
;
2822 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
2823 EDIT_UpdateText(es
, NULL
, TRUE
);
2824 EDIT_EM_ScrollCaret(es
);
2825 /* force scroll info update */
2826 EDIT_UpdateScrollInfo(es
);
2830 /*********************************************************************
2834 * NOTE: this version currently implements WinNT limits
2837 static void EDIT_EM_SetLimitText(EDITSTATE
*es
, UINT limit
)
2839 if (!limit
) limit
= ~0u;
2840 if (!(es
->style
& ES_MULTILINE
)) limit
= min(limit
, 0x7ffffffe);
2841 es
->buffer_limit
= limit
;
2845 /*********************************************************************
2849 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2850 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
2851 * margin according to the textmetrics of the current font.
2853 * When EC_USEFONTINFO is used in the non_cjk case the margins only
2854 * change if the edit control is equal to or larger than a certain
2855 * size. Though there is an exception for the empty client rect case
2856 * with small font sizes.
2858 static BOOL
is_cjk(UINT charset
)
2862 case SHIFTJIS_CHARSET
:
2863 case HANGUL_CHARSET
:
2864 case GB2312_CHARSET
:
2865 case CHINESEBIG5_CHARSET
:
2868 /* HANGUL_CHARSET is strange, though treated as CJK by Win 8, it is
2869 * not by other versions including Win 10. */
2873 static void EDIT_EM_SetMargins(EDITSTATE
*es
, INT action
,
2874 WORD left
, WORD right
, BOOL repaint
)
2877 INT default_left_margin
= 0; /* in pixels */
2878 INT default_right_margin
= 0; /* in pixels */
2880 /* Set the default margins depending on the font */
2881 if (es
->font
&& (left
== EC_USEFONTINFO
|| right
== EC_USEFONTINFO
)) {
2882 HDC dc
= GetDC(es
->hwndSelf
);
2883 HFONT old_font
= SelectObject(dc
, es
->font
);
2884 LONG width
= GdiGetCharDimensions(dc
, &tm
, NULL
);
2887 /* The default margins are only non zero for TrueType or Vector fonts */
2888 if (tm
.tmPitchAndFamily
& ( TMPF_VECTOR
| TMPF_TRUETYPE
)) {
2889 if (!is_cjk(tm
.tmCharSet
)) {
2890 default_left_margin
= width
/ 2;
2891 default_right_margin
= width
/ 2;
2893 GetClientRect(es
->hwndSelf
, &rc
);
2894 if (rc
.right
- rc
.left
< (width
/ 2 + width
) * 2 &&
2895 (width
>= 28 || !IsRectEmpty(&rc
)) ) {
2896 default_left_margin
= es
->left_margin
;
2897 default_right_margin
= es
->right_margin
;
2900 /* FIXME: figure out the CJK values. They are not affected by the client rect. */
2901 default_left_margin
= width
/ 2;
2902 default_right_margin
= width
/ 2;
2905 SelectObject(dc
, old_font
);
2906 ReleaseDC(es
->hwndSelf
, dc
);
2909 if (action
& EC_LEFTMARGIN
) {
2910 es
->format_rect
.left
-= es
->left_margin
;
2911 if (left
!= EC_USEFONTINFO
)
2912 es
->left_margin
= left
;
2914 es
->left_margin
= default_left_margin
;
2915 es
->format_rect
.left
+= es
->left_margin
;
2918 if (action
& EC_RIGHTMARGIN
) {
2919 es
->format_rect
.right
+= es
->right_margin
;
2920 if (right
!= EC_USEFONTINFO
)
2921 es
->right_margin
= right
;
2923 es
->right_margin
= default_right_margin
;
2924 es
->format_rect
.right
-= es
->right_margin
;
2927 if (action
& (EC_LEFTMARGIN
| EC_RIGHTMARGIN
)) {
2928 EDIT_AdjustFormatRect(es
);
2929 if (repaint
) EDIT_UpdateText(es
, NULL
, TRUE
);
2932 TRACE("left=%d, right=%d\n", es
->left_margin
, es
->right_margin
);
2936 /*********************************************************************
2938 * EM_SETPASSWORDCHAR
2941 static void EDIT_EM_SetPasswordChar(EDITSTATE
*es
, WCHAR c
)
2945 if (es
->style
& ES_MULTILINE
)
2948 if (es
->password_char
== c
)
2951 style
= GetWindowLongW( es
->hwndSelf
, GWL_STYLE
);
2952 es
->password_char
= c
;
2954 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
| ES_PASSWORD
);
2955 es
->style
|= ES_PASSWORD
;
2957 SetWindowLongW( es
->hwndSelf
, GWL_STYLE
, style
& ~ES_PASSWORD
);
2958 es
->style
&= ~ES_PASSWORD
;
2960 EDIT_InvalidateUniscribeData(es
);
2961 EDIT_UpdateText(es
, NULL
, TRUE
);
2965 /*********************************************************************
2970 static BOOL
EDIT_EM_SetTabStops(EDITSTATE
*es
, INT count
, const INT
*tabs
)
2972 if (!(es
->style
& ES_MULTILINE
))
2974 HeapFree(GetProcessHeap(), 0, es
->tabs
);
2975 es
->tabs_count
= count
;
2979 es
->tabs
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(INT
));
2980 memcpy(es
->tabs
, tabs
, count
* sizeof(INT
));
2982 EDIT_InvalidateUniscribeData(es
);
2987 /*********************************************************************
2989 * EM_SETWORDBREAKPROC
2992 static void EDIT_EM_SetWordBreakProc(EDITSTATE
*es
, void *wbp
)
2994 if (es
->word_break_proc
== wbp
)
2997 es
->word_break_proc
= wbp
;
2999 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_AUTOHSCROLL
)) {
3000 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3001 EDIT_UpdateText(es
, NULL
, TRUE
);
3006 /*********************************************************************
3011 static BOOL
EDIT_EM_Undo(EDITSTATE
*es
)
3016 /* As per MSDN spec, for a single-line edit control,
3017 the return value is always TRUE */
3018 if( es
->style
& ES_READONLY
)
3019 return !(es
->style
& ES_MULTILINE
);
3021 ulength
= strlenW(es
->undo_text
);
3023 utext
= HeapAlloc(GetProcessHeap(), 0, (ulength
+ 1) * sizeof(WCHAR
));
3025 strcpyW(utext
, es
->undo_text
);
3027 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
3028 es
->undo_insert_count
, debugstr_w(utext
));
3030 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3031 EDIT_EM_EmptyUndoBuffer(es
);
3032 EDIT_EM_ReplaceSel(es
, TRUE
, utext
, ulength
, TRUE
, TRUE
);
3033 EDIT_EM_SetSel(es
, es
->undo_position
, es
->undo_position
+ es
->undo_insert_count
, FALSE
);
3034 /* send the notification after the selection start and end are set */
3035 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3036 EDIT_EM_ScrollCaret(es
);
3037 HeapFree(GetProcessHeap(), 0, utext
);
3039 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
3040 es
->undo_insert_count
, debugstr_w(es
->undo_text
));
3045 /* Helper function for WM_CHAR
3047 * According to an MSDN blog article titled "Just because you're a control
3048 * doesn't mean that you're necessarily inside a dialog box," multiline edit
3049 * controls without ES_WANTRETURN would attempt to detect whether it is inside
3050 * a dialog box or not.
3052 static inline BOOL
EDIT_IsInsideDialog(EDITSTATE
*es
)
3054 return (es
->flags
& EF_DIALOGMODE
);
3058 /*********************************************************************
3063 static void EDIT_WM_Paste(EDITSTATE
*es
)
3069 /* Protect read-only edit control from modification */
3070 if(es
->style
& ES_READONLY
)
3073 OpenClipboard(es
->hwndSelf
);
3074 if ((hsrc
= GetClipboardData(CF_UNICODETEXT
))) {
3075 src
= GlobalLock(hsrc
);
3077 /* Protect single-line edit against pasting new line character */
3078 if (!(es
->style
& ES_MULTILINE
) && ((ptr
= strchrW(src
, '\n')))) {
3080 if (len
&& src
[len
- 1] == '\r')
3083 EDIT_EM_ReplaceSel(es
, TRUE
, src
, len
, TRUE
, TRUE
);
3086 else if (es
->style
& ES_PASSWORD
) {
3087 /* clear selected text in password edit box even with empty clipboard */
3088 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
3094 /*********************************************************************
3099 static void EDIT_WM_Copy(EDITSTATE
*es
)
3101 INT s
= min(es
->selection_start
, es
->selection_end
);
3102 INT e
= max(es
->selection_start
, es
->selection_end
);
3110 hdst
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_DDESHARE
, (len
+ 1) * sizeof(WCHAR
));
3111 dst
= GlobalLock(hdst
);
3112 memcpy(dst
, es
->text
+ s
, len
* sizeof(WCHAR
));
3113 dst
[len
] = 0; /* ensure 0 termination */
3114 TRACE("%s\n", debugstr_w(dst
));
3116 OpenClipboard(es
->hwndSelf
);
3118 SetClipboardData(CF_UNICODETEXT
, hdst
);
3123 /*********************************************************************
3128 static inline void EDIT_WM_Clear(EDITSTATE
*es
)
3130 /* Protect read-only edit control from modification */
3131 if(es
->style
& ES_READONLY
)
3134 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
3138 /*********************************************************************
3143 static inline void EDIT_WM_Cut(EDITSTATE
*es
)
3150 /*********************************************************************
3155 static LRESULT
EDIT_WM_Char(EDITSTATE
*es
, WCHAR c
)
3159 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3163 /* If it's not a multiline edit box, it would be ignored below.
3164 * For multiline edit without ES_WANTRETURN, we have to make a
3167 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_WANTRETURN
))
3168 if (EDIT_IsInsideDialog(es
))
3171 if (es
->style
& ES_MULTILINE
) {
3172 if (es
->style
& ES_READONLY
) {
3173 EDIT_MoveHome(es
, FALSE
, FALSE
);
3174 EDIT_MoveDown_ML(es
, FALSE
);
3176 static const WCHAR cr_lfW
[] = {'\r','\n'};
3177 EDIT_EM_ReplaceSel(es
, TRUE
, cr_lfW
, 2, TRUE
, TRUE
);
3182 if ((es
->style
& ES_MULTILINE
) && !(es
->style
& ES_READONLY
))
3184 static const WCHAR tabW
[] = {'\t'};
3185 if (EDIT_IsInsideDialog(es
))
3187 EDIT_EM_ReplaceSel(es
, TRUE
, tabW
, 1, TRUE
, TRUE
);
3191 if (!(es
->style
& ES_READONLY
) && !control
) {
3192 if (es
->selection_start
!= es
->selection_end
)
3195 /* delete character left of caret */
3196 EDIT_EM_SetSel(es
, (UINT
)-1, 0, FALSE
);
3197 EDIT_MoveBackward(es
, TRUE
);
3203 if (!(es
->style
& ES_PASSWORD
))
3204 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3207 if (!(es
->style
& ES_READONLY
))
3208 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3211 if (!((es
->style
& ES_READONLY
) || (es
->style
& ES_PASSWORD
)))
3212 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3215 if (!(es
->style
& ES_READONLY
))
3216 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3220 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3221 if( (es
->style
& ES_NUMBER
) && !( c
>= '0' && c
<= '9') )
3224 if (!(es
->style
& ES_READONLY
) && (c
>= ' ') && (c
!= 127))
3225 EDIT_EM_ReplaceSel(es
, TRUE
, &c
, 1, TRUE
, TRUE
);
3232 /*********************************************************************
3234 * EDIT_ContextMenuCommand
3237 static void EDIT_ContextMenuCommand(EDITSTATE
*es
, UINT id
)
3241 SendMessageW(es
->hwndSelf
, WM_UNDO
, 0, 0);
3244 SendMessageW(es
->hwndSelf
, WM_CUT
, 0, 0);
3247 SendMessageW(es
->hwndSelf
, WM_COPY
, 0, 0);
3250 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3253 SendMessageW(es
->hwndSelf
, WM_CLEAR
, 0, 0);
3256 SendMessageW(es
->hwndSelf
, EM_SETSEL
, 0, -1);
3259 ERR("unknown menu item, please report\n");
3265 /*********************************************************************
3269 * Note: the resource files resource/sysres_??.rc cannot define a
3270 * single popup menu. Hence we use a (dummy) menubar
3271 * containing the single popup menu as its first item.
3273 * FIXME: the message identifiers have been chosen arbitrarily,
3274 * hence we use MF_BYPOSITION.
3275 * We might as well use the "real" values (anybody knows ?)
3276 * The menu definition is in resources/sysres_??.rc.
3277 * Once these are OK, we better use MF_BYCOMMAND here
3278 * (as we do in EDIT_WM_Command()).
3281 static void EDIT_WM_ContextMenu(EDITSTATE
*es
, INT x
, INT y
)
3283 HMENU menu
= LoadMenuA(user32_module
, "EDITMENU");
3284 HMENU popup
= GetSubMenu(menu
, 0);
3285 UINT start
= es
->selection_start
;
3286 UINT end
= es
->selection_end
;
3289 ORDER_UINT(start
, end
);
3292 EnableMenuItem(popup
, 0, MF_BYPOSITION
| (EDIT_EM_CanUndo(es
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3294 EnableMenuItem(popup
, 2, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3296 EnableMenuItem(popup
, 3, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_PASSWORD
) ? MF_ENABLED
: MF_GRAYED
));
3298 EnableMenuItem(popup
, 4, MF_BYPOSITION
| (IsClipboardFormatAvailable(CF_UNICODETEXT
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3300 EnableMenuItem(popup
, 5, MF_BYPOSITION
| ((end
- start
) && !(es
->style
& ES_READONLY
) ? MF_ENABLED
: MF_GRAYED
));
3302 EnableMenuItem(popup
, 7, MF_BYPOSITION
| (start
|| (end
!= get_text_length(es
)) ? MF_ENABLED
: MF_GRAYED
));
3304 if (x
== -1 && y
== -1) /* passed via VK_APPS press/release */
3307 /* Windows places the menu at the edit's center in this case */
3308 WIN_GetRectangles( es
->hwndSelf
, COORDS_SCREEN
, NULL
, &rc
);
3309 x
= rc
.left
+ (rc
.right
- rc
.left
) / 2;
3310 y
= rc
.top
+ (rc
.bottom
- rc
.top
) / 2;
3313 if (!(es
->flags
& EF_FOCUSED
))
3314 SetFocus(es
->hwndSelf
);
3316 cmd
= TrackPopupMenu(popup
, TPM_LEFTALIGN
| TPM_RIGHTBUTTON
| TPM_RETURNCMD
| TPM_NONOTIFY
,
3317 x
, y
, 0, es
->hwndSelf
, NULL
);
3320 EDIT_ContextMenuCommand(es
, cmd
);
3326 /*********************************************************************
3331 static INT
EDIT_WM_GetText(const EDITSTATE
*es
, INT count
, LPWSTR dst
, BOOL unicode
)
3333 if(!count
) return 0;
3337 lstrcpynW(dst
, es
->text
, count
);
3338 return strlenW(dst
);
3342 LPSTR textA
= (LPSTR
)dst
;
3343 if (!WideCharToMultiByte(CP_ACP
, 0, es
->text
, -1, textA
, count
, NULL
, NULL
))
3344 textA
[count
- 1] = 0; /* ensure 0 termination */
3345 return strlen(textA
);
3349 /*********************************************************************
3354 static BOOL
EDIT_CheckCombo(EDITSTATE
*es
, UINT msg
, INT key
)
3356 HWND hLBox
= es
->hwndListBox
;
3364 hCombo
= GetParent(es
->hwndSelf
);
3368 TRACE_(combo
)("[%p]: handling msg %x (%x)\n", es
->hwndSelf
, msg
, key
);
3370 if (key
== VK_UP
|| key
== VK_DOWN
)
3372 if (SendMessageW(hCombo
, CB_GETEXTENDEDUI
, 0, 0))
3375 if (msg
== WM_KEYDOWN
|| nEUI
)
3376 bDropped
= (BOOL
)SendMessageW(hCombo
, CB_GETDROPPEDSTATE
, 0, 0);
3382 if (!bDropped
&& nEUI
&& (key
== VK_UP
|| key
== VK_DOWN
))
3384 /* make sure ComboLBox pops up */
3385 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, FALSE
, 0);
3390 SendMessageW(hLBox
, WM_KEYDOWN
, key
, 0);
3393 case WM_SYSKEYDOWN
: /* Handle Alt+up/down arrows */
3395 SendMessageW(hCombo
, CB_SHOWDROPDOWN
, !bDropped
, 0);
3397 SendMessageW(hLBox
, WM_KEYDOWN
, VK_F4
, 0);
3402 SendMessageW(hCombo
, CB_SETEXTENDEDUI
, TRUE
, 0);
3408 /*********************************************************************
3412 * Handling of special keys that don't produce a WM_CHAR
3413 * (i.e. non-printable keys) & Backspace & Delete
3416 static LRESULT
EDIT_WM_KeyDown(EDITSTATE
*es
, INT key
)
3421 if (GetKeyState(VK_MENU
) & 0x8000)
3424 shift
= GetKeyState(VK_SHIFT
) & 0x8000;
3425 control
= GetKeyState(VK_CONTROL
) & 0x8000;
3430 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
) || key
== VK_F4
)
3435 if ((es
->style
& ES_MULTILINE
) && (key
== VK_UP
))
3436 EDIT_MoveUp_ML(es
, shift
);
3439 EDIT_MoveWordBackward(es
, shift
);
3441 EDIT_MoveBackward(es
, shift
);
3444 if (EDIT_CheckCombo(es
, WM_KEYDOWN
, key
))
3448 if ((es
->style
& ES_MULTILINE
) && (key
== VK_DOWN
))
3449 EDIT_MoveDown_ML(es
, shift
);
3451 EDIT_MoveWordForward(es
, shift
);
3453 EDIT_MoveForward(es
, shift
);
3456 EDIT_MoveHome(es
, shift
, control
);
3459 EDIT_MoveEnd(es
, shift
, control
);
3462 if (es
->style
& ES_MULTILINE
)
3463 EDIT_MovePageUp_ML(es
, shift
);
3465 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3468 if (es
->style
& ES_MULTILINE
)
3469 EDIT_MovePageDown_ML(es
, shift
);
3471 EDIT_CheckCombo(es
, WM_KEYDOWN
, key
);
3474 if (!(es
->style
& ES_READONLY
) && !(shift
&& control
)) {
3475 if (es
->selection_start
!= es
->selection_end
) {
3481 EDIT_EM_SetSel(es
, ~0u, 0, FALSE
);
3483 /* delete character left of caret */
3484 EDIT_MoveBackward(es
, TRUE
);
3486 /* delete to end of line */
3487 EDIT_MoveEnd(es
, TRUE
, FALSE
);
3489 /* delete character right of caret */
3490 EDIT_MoveForward(es
, TRUE
);
3497 if (!(es
->style
& ES_READONLY
))
3503 /* If the edit doesn't want the return send a message to the default object */
3504 if(!(es
->style
& ES_MULTILINE
) || !(es
->style
& ES_WANTRETURN
))
3508 if (!EDIT_IsInsideDialog(es
)) break;
3510 dw
= SendMessageW(es
->hwndParent
, DM_GETDEFID
, 0, 0);
3511 if (HIWORD(dw
) == DC_HASDEFID
)
3513 HWND hwDefCtrl
= GetDlgItem(es
->hwndParent
, LOWORD(dw
));
3516 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, (WPARAM
)hwDefCtrl
, TRUE
);
3517 PostMessageW(hwDefCtrl
, WM_KEYDOWN
, VK_RETURN
, 0);
3523 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3524 PostMessageW(es
->hwndParent
, WM_CLOSE
, 0, 0);
3527 if ((es
->style
& ES_MULTILINE
) && EDIT_IsInsideDialog(es
))
3528 SendMessageW(es
->hwndParent
, WM_NEXTDLGCTL
, shift
, 0);
3535 /*********************************************************************
3540 static LRESULT
EDIT_WM_KillFocus(EDITSTATE
*es
)
3542 es
->flags
&= ~EF_FOCUSED
;
3544 if(!(es
->style
& ES_NOHIDESEL
))
3545 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3546 EDIT_NOTIFY_PARENT(es
, EN_KILLFOCUS
);
3547 /* throw away left over scroll when we lose focus */
3548 es
->wheelDeltaRemainder
= 0;
3553 /*********************************************************************
3557 * The caret position has been set on the WM_LBUTTONDOWN message
3560 static LRESULT
EDIT_WM_LButtonDblClk(EDITSTATE
*es
)
3563 INT e
= es
->selection_end
;
3568 es
->bCaptureState
= TRUE
;
3569 SetCapture(es
->hwndSelf
);
3571 l
= EDIT_EM_LineFromChar(es
, e
);
3572 li
= EDIT_EM_LineIndex(es
, l
);
3573 ll
= EDIT_EM_LineLength(es
, e
);
3574 s
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_LEFT
);
3575 e
= li
+ EDIT_CallWordBreakProc(es
, li
, e
- li
, ll
, WB_RIGHT
);
3576 EDIT_EM_SetSel(es
, s
, e
, FALSE
);
3577 EDIT_EM_ScrollCaret(es
);
3578 es
->region_posx
= es
->region_posy
= 0;
3579 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3584 /*********************************************************************
3589 static LRESULT
EDIT_WM_LButtonDown(EDITSTATE
*es
, DWORD keys
, INT x
, INT y
)
3594 es
->bCaptureState
= TRUE
;
3595 SetCapture(es
->hwndSelf
);
3596 EDIT_ConfinePoint(es
, &x
, &y
);
3597 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3598 EDIT_EM_SetSel(es
, (keys
& MK_SHIFT
) ? es
->selection_start
: e
, e
, after_wrap
);
3599 EDIT_EM_ScrollCaret(es
);
3600 es
->region_posx
= es
->region_posy
= 0;
3601 SetTimer(es
->hwndSelf
, 0, 100, NULL
);
3603 if (!(es
->flags
& EF_FOCUSED
))
3604 SetFocus(es
->hwndSelf
);
3610 /*********************************************************************
3615 static LRESULT
EDIT_WM_LButtonUp(EDITSTATE
*es
)
3617 if (es
->bCaptureState
) {
3618 KillTimer(es
->hwndSelf
, 0);
3619 if (GetCapture() == es
->hwndSelf
) ReleaseCapture();
3621 es
->bCaptureState
= FALSE
;
3626 /*********************************************************************
3631 static LRESULT
EDIT_WM_MButtonDown(EDITSTATE
*es
)
3633 SendMessageW(es
->hwndSelf
, WM_PASTE
, 0, 0);
3638 /*********************************************************************
3643 static LRESULT
EDIT_WM_MouseMove(EDITSTATE
*es
, INT x
, INT y
)
3649 /* If the mouse has been captured by process other than the edit control itself,
3650 * the windows edit controls will not select the strings with mouse move.
3652 if (!es
->bCaptureState
|| GetCapture() != es
->hwndSelf
)
3656 * FIXME: gotta do some scrolling if outside client
3657 * area. Maybe reset the timer ?
3660 EDIT_ConfinePoint(es
, &x
, &y
);
3661 es
->region_posx
= (prex
< x
) ? -1 : ((prex
> x
) ? 1 : 0);
3662 es
->region_posy
= (prey
< y
) ? -1 : ((prey
> y
) ? 1 : 0);
3663 e
= EDIT_CharFromPos(es
, x
, y
, &after_wrap
);
3664 EDIT_EM_SetSel(es
, es
->selection_start
, e
, after_wrap
);
3665 EDIT_SetCaretPos(es
,es
->selection_end
,es
->flags
& EF_AFTER_WRAP
);
3670 /*********************************************************************
3675 static void EDIT_WM_Paint(EDITSTATE
*es
, HDC hdc
)
3688 BOOL rev
= es
->bEnableState
&&
3689 ((es
->flags
& EF_FOCUSED
) ||
3690 (es
->style
& ES_NOHIDESEL
));
3691 dc
= hdc
? hdc
: BeginPaint(es
->hwndSelf
, &ps
);
3693 /* The dc we use for calculating may not be the one we paint into.
3694 This is the safest action. */
3695 EDIT_InvalidateUniscribeData(es
);
3696 GetClientRect(es
->hwndSelf
, &rcClient
);
3698 /* get the background brush */
3699 brush
= EDIT_NotifyCtlColor(es
, dc
);
3701 /* paint the border and the background */
3702 IntersectClipRect(dc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
3704 if(es
->style
& WS_BORDER
) {
3705 bw
= GetSystemMetrics(SM_CXBORDER
);
3706 bh
= GetSystemMetrics(SM_CYBORDER
);
3708 if(es
->style
& ES_MULTILINE
) {
3709 if(es
->style
& WS_HSCROLL
) rc
.bottom
+=bh
;
3710 if(es
->style
& WS_VSCROLL
) rc
.right
+=bw
;
3713 /* Draw the frame. Same code as in nonclient.c */
3714 old_brush
= SelectObject(dc
, GetSysColorBrush(COLOR_WINDOWFRAME
));
3715 PatBlt(dc
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, bh
, PATCOPY
);
3716 PatBlt(dc
, rc
.left
, rc
.top
, bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3717 PatBlt(dc
, rc
.left
, rc
.bottom
- 1, rc
.right
- rc
.left
, -bw
, PATCOPY
);
3718 PatBlt(dc
, rc
.right
- 1, rc
.top
, -bw
, rc
.bottom
- rc
.top
, PATCOPY
);
3719 SelectObject(dc
, old_brush
);
3721 /* Keep the border clean */
3722 IntersectClipRect(dc
, rc
.left
+bw
, rc
.top
+bh
,
3723 max(rc
.right
-bw
, rc
.left
+bw
), max(rc
.bottom
-bh
, rc
.top
+bh
));
3726 GetClipBox(dc
, &rc
);
3727 FillRect(dc
, &rc
, brush
);
3729 IntersectClipRect(dc
, es
->format_rect
.left
,
3730 es
->format_rect
.top
,
3731 es
->format_rect
.right
,
3732 es
->format_rect
.bottom
);
3733 if (es
->style
& ES_MULTILINE
) {
3735 IntersectClipRect(dc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3738 old_font
= SelectObject(dc
, es
->font
);
3740 if (!es
->bEnableState
)
3741 SetTextColor(dc
, GetSysColor(COLOR_GRAYTEXT
));
3742 GetClipBox(dc
, &rcRgn
);
3743 if (es
->style
& ES_MULTILINE
) {
3744 INT vlc
= get_vertical_line_count(es
);
3745 for (i
= es
->y_offset
; i
<= min(es
->y_offset
+ vlc
, es
->y_offset
+ es
->line_count
- 1) ; i
++) {
3746 EDIT_UpdateUniscribeData(es
, dc
, i
);
3747 EDIT_GetLineRect(es
, i
, 0, -1, &rcLine
);
3748 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3749 EDIT_PaintLine(es
, dc
, i
, rev
);
3752 EDIT_UpdateUniscribeData(es
, dc
, 0);
3753 EDIT_GetLineRect(es
, 0, 0, -1, &rcLine
);
3754 if (IntersectRect(&rc
, &rcRgn
, &rcLine
))
3755 EDIT_PaintLine(es
, dc
, 0, rev
);
3758 SelectObject(dc
, old_font
);
3761 EndPaint(es
->hwndSelf
, &ps
);
3765 /*********************************************************************
3770 static void EDIT_WM_SetFocus(EDITSTATE
*es
)
3772 es
->flags
|= EF_FOCUSED
;
3774 if (!(es
->style
& ES_NOHIDESEL
))
3775 EDIT_InvalidateText(es
, es
->selection_start
, es
->selection_end
);
3777 /* single line edit updates itself */
3778 if (IsWindowVisible(es
->hwndSelf
) && !(es
->style
& ES_MULTILINE
))
3780 HDC hdc
= GetDC(es
->hwndSelf
);
3781 EDIT_WM_Paint(es
, hdc
);
3782 ReleaseDC(es
->hwndSelf
, hdc
);
3785 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3786 EDIT_SetCaretPos(es
, es
->selection_end
,
3787 es
->flags
& EF_AFTER_WRAP
);
3788 ShowCaret(es
->hwndSelf
);
3789 EDIT_NOTIFY_PARENT(es
, EN_SETFOCUS
);
3793 /*********************************************************************
3797 * With Win95 look the margins are set to default font value unless
3798 * the system font (font == 0) is being set, in which case they are left
3802 static void EDIT_WM_SetFont(EDITSTATE
*es
, HFONT font
, BOOL redraw
)
3810 EDIT_InvalidateUniscribeData(es
);
3811 dc
= GetDC(es
->hwndSelf
);
3813 old_font
= SelectObject(dc
, font
);
3814 GetTextMetricsW(dc
, &tm
);
3815 es
->line_height
= tm
.tmHeight
;
3816 es
->char_width
= tm
.tmAveCharWidth
;
3818 SelectObject(dc
, old_font
);
3819 ReleaseDC(es
->hwndSelf
, dc
);
3821 /* Reset the format rect and the margins */
3822 GetClientRect(es
->hwndSelf
, &clientRect
);
3823 EDIT_SetRectNP(es
, &clientRect
);
3824 EDIT_EM_SetMargins(es
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
,
3825 EC_USEFONTINFO
, EC_USEFONTINFO
, FALSE
);
3827 if (es
->style
& ES_MULTILINE
)
3828 EDIT_BuildLineDefs_ML(es
, 0, get_text_length(es
), 0, NULL
);
3830 EDIT_CalcLineWidth_SL(es
);
3833 EDIT_UpdateText(es
, NULL
, TRUE
);
3834 if (es
->flags
& EF_FOCUSED
) {
3836 CreateCaret(es
->hwndSelf
, 0, 1, es
->line_height
);
3837 EDIT_SetCaretPos(es
, es
->selection_end
,
3838 es
->flags
& EF_AFTER_WRAP
);
3839 ShowCaret(es
->hwndSelf
);
3844 /*********************************************************************
3849 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3850 * The modified flag is reset. No notifications are sent.
3852 * For single-line controls, reception of WM_SETTEXT triggers:
3853 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3856 static void EDIT_WM_SetText(EDITSTATE
*es
, LPCWSTR text
, BOOL unicode
)
3858 LPWSTR textW
= NULL
;
3859 if (!unicode
&& text
)
3861 LPCSTR textA
= (LPCSTR
)text
;
3862 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
3863 textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
));
3865 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
3869 if (es
->flags
& EF_UPDATE
)
3870 /* fixed this bug once; complain if we see it about to happen again. */
3871 ERR("SetSel may generate UPDATE message whose handler may reset "
3874 EDIT_EM_SetSel(es
, 0, (UINT
)-1, FALSE
);
3877 TRACE("%s\n", debugstr_w(text
));
3878 EDIT_EM_ReplaceSel(es
, FALSE
, text
, strlenW(text
), FALSE
, FALSE
);
3880 HeapFree(GetProcessHeap(), 0, textW
);
3885 EDIT_EM_ReplaceSel(es
, FALSE
, NULL
, 0, FALSE
, FALSE
);
3888 es
->flags
&= ~EF_MODIFIED
;
3889 EDIT_EM_SetSel(es
, 0, 0, FALSE
);
3891 /* Send the notification after the selection start and end have been set
3892 * edit control doesn't send notification on WM_SETTEXT
3893 * if it is multiline, or it is part of combobox
3895 if( !((es
->style
& ES_MULTILINE
) || es
->hwndListBox
))
3897 EDIT_NOTIFY_PARENT(es
, EN_UPDATE
);
3898 EDIT_NOTIFY_PARENT(es
, EN_CHANGE
);
3900 EDIT_EM_ScrollCaret(es
);
3901 EDIT_UpdateScrollInfo(es
);
3902 EDIT_InvalidateUniscribeData(es
);
3906 /*********************************************************************
3911 static void EDIT_WM_Size(EDITSTATE
*es
, UINT action
)
3913 if ((action
== SIZE_MAXIMIZED
) || (action
== SIZE_RESTORED
)) {
3915 GetClientRect(es
->hwndSelf
, &rc
);
3916 EDIT_SetRectNP(es
, &rc
);
3917 EDIT_UpdateText(es
, NULL
, TRUE
);
3922 /*********************************************************************
3926 * This message is sent by SetWindowLong on having changed either the Style
3927 * or the extended style.
3929 * We ensure that the window's version of the styles and the EDITSTATE's agree.
3931 * See also EDIT_WM_NCCreate
3933 * It appears that the Windows version of the edit control allows the style
3934 * (as retrieved by GetWindowLong) to be any value and maintains an internal
3935 * style variable which will generally be different. In this function we
3936 * update the internal style based on what changed in the externally visible
3939 * Much of this content as based upon the MSDN, especially:
3940 * Platform SDK Documentation -> User Interface Services ->
3941 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
3942 * Edit Control Styles
3944 static LRESULT
EDIT_WM_StyleChanged ( EDITSTATE
*es
, WPARAM which
, const STYLESTRUCT
*style
)
3946 if (GWL_STYLE
== which
) {
3947 DWORD style_change_mask
;
3949 /* Only a subset of changes can be applied after the control
3952 style_change_mask
= ES_UPPERCASE
| ES_LOWERCASE
|
3954 if (es
->style
& ES_MULTILINE
)
3955 style_change_mask
|= ES_WANTRETURN
;
3957 new_style
= style
->styleNew
& style_change_mask
;
3959 /* Number overrides lowercase overrides uppercase (at least it
3960 * does in Win95). However I'll bet that ES_NUMBER would be
3961 * invalid under Win 3.1.
3963 if (new_style
& ES_NUMBER
) {
3964 ; /* do not override the ES_NUMBER */
3965 } else if (new_style
& ES_LOWERCASE
) {
3966 new_style
&= ~ES_UPPERCASE
;
3969 es
->style
= (es
->style
& ~style_change_mask
) | new_style
;
3970 } else if (GWL_EXSTYLE
== which
) {
3971 ; /* FIXME - what is needed here */
3973 WARN ("Invalid style change %ld\n",which
);
3979 /*********************************************************************
3984 static LRESULT
EDIT_WM_SysKeyDown(EDITSTATE
*es
, INT key
, DWORD key_data
)
3986 if ((key
== VK_BACK
) && (key_data
& 0x2000)) {
3987 if (EDIT_EM_CanUndo(es
))
3990 } else if (key
== VK_UP
|| key
== VK_DOWN
) {
3991 if (EDIT_CheckCombo(es
, WM_SYSKEYDOWN
, key
))
3994 return DefWindowProcW(es
->hwndSelf
, WM_SYSKEYDOWN
, key
, key_data
);
3998 /*********************************************************************
4003 static void EDIT_WM_Timer(EDITSTATE
*es
)
4005 if (es
->region_posx
< 0) {
4006 EDIT_MoveBackward(es
, TRUE
);
4007 } else if (es
->region_posx
> 0) {
4008 EDIT_MoveForward(es
, TRUE
);
4011 * FIXME: gotta do some vertical scrolling here, like
4012 * EDIT_EM_LineScroll(hwnd, 0, 1);
4016 /*********************************************************************
4021 static LRESULT
EDIT_WM_HScroll(EDITSTATE
*es
, INT action
, INT pos
)
4026 if (!(es
->style
& ES_MULTILINE
))
4029 if (!(es
->style
& ES_AUTOHSCROLL
))
4033 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4036 TRACE("SB_LINELEFT\n");
4038 dx
= -es
->char_width
;
4041 TRACE("SB_LINERIGHT\n");
4042 if (es
->x_offset
< es
->text_width
)
4043 dx
= es
->char_width
;
4046 TRACE("SB_PAGELEFT\n");
4048 dx
= -fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4051 TRACE("SB_PAGERIGHT\n");
4052 if (es
->x_offset
< es
->text_width
)
4053 dx
= fw
/ HSCROLL_FRACTION
/ es
->char_width
* es
->char_width
;
4061 TRACE("SB_RIGHT\n");
4062 if (es
->x_offset
< es
->text_width
)
4063 dx
= es
->text_width
- es
->x_offset
;
4066 TRACE("SB_THUMBTRACK %d\n", pos
);
4067 es
->flags
|= EF_HSCROLL_TRACK
;
4068 if(es
->style
& WS_HSCROLL
)
4069 dx
= pos
- es
->x_offset
;
4074 if(pos
< 0 || pos
> 100) return 0;
4075 /* Assume default scroll range 0-100 */
4076 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4077 new_x
= pos
* (es
->text_width
- fw
) / 100;
4078 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4081 case SB_THUMBPOSITION
:
4082 TRACE("SB_THUMBPOSITION %d\n", pos
);
4083 es
->flags
&= ~EF_HSCROLL_TRACK
;
4084 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4085 dx
= pos
- es
->x_offset
;
4090 if(pos
< 0 || pos
> 100) return 0;
4091 /* Assume default scroll range 0-100 */
4092 fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4093 new_x
= pos
* (es
->text_width
- fw
) / 100;
4094 dx
= es
->text_width
? (new_x
- es
->x_offset
) : 0;
4097 /* force scroll info update */
4098 EDIT_UpdateScrollInfo(es
);
4099 EDIT_NOTIFY_PARENT(es
, EN_HSCROLL
);
4103 TRACE("SB_ENDSCROLL\n");
4106 * FIXME : the next two are undocumented !
4107 * Are we doing the right thing ?
4108 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4109 * although it's also a regular control message.
4111 case EM_GETTHUMB
: /* this one is used by NT notepad */
4114 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
)
4115 ret
= GetScrollPos(es
->hwndSelf
, SB_HORZ
);
4118 /* Assume default scroll range 0-100 */
4119 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4120 ret
= es
->text_width
? es
->x_offset
* 100 / (es
->text_width
- fw
) : 0;
4122 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4126 TRACE("EM_LINESCROLL16\n");
4131 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4137 INT fw
= es
->format_rect
.right
- es
->format_rect
.left
;
4138 /* check if we are going to move too far */
4139 if(es
->x_offset
+ dx
+ fw
> es
->text_width
)
4140 dx
= es
->text_width
- fw
- es
->x_offset
;
4142 EDIT_EM_LineScroll_internal(es
, dx
, 0);
4148 /*********************************************************************
4153 static LRESULT
EDIT_WM_VScroll(EDITSTATE
*es
, INT action
, INT pos
)
4157 if (!(es
->style
& ES_MULTILINE
))
4160 if (!(es
->style
& ES_AUTOVSCROLL
))
4169 TRACE("action %d (%s)\n", action
, (action
== SB_LINEUP
? "SB_LINEUP" :
4170 (action
== SB_LINEDOWN
? "SB_LINEDOWN" :
4171 (action
== SB_PAGEUP
? "SB_PAGEUP" :
4173 EDIT_EM_Scroll(es
, action
);
4180 TRACE("SB_BOTTOM\n");
4181 dy
= es
->line_count
- 1 - es
->y_offset
;
4184 TRACE("SB_THUMBTRACK %d\n", pos
);
4185 es
->flags
|= EF_VSCROLL_TRACK
;
4186 if(es
->style
& WS_VSCROLL
)
4187 dy
= pos
- es
->y_offset
;
4190 /* Assume default scroll range 0-100 */
4193 if(pos
< 0 || pos
> 100) return 0;
4194 vlc
= get_vertical_line_count(es
);
4195 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4196 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4197 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4198 es
->line_count
, es
->y_offset
, pos
, dy
);
4201 case SB_THUMBPOSITION
:
4202 TRACE("SB_THUMBPOSITION %d\n", pos
);
4203 es
->flags
&= ~EF_VSCROLL_TRACK
;
4204 if(es
->style
& WS_VSCROLL
)
4205 dy
= pos
- es
->y_offset
;
4208 /* Assume default scroll range 0-100 */
4211 if(pos
< 0 || pos
> 100) return 0;
4212 vlc
= get_vertical_line_count(es
);
4213 new_y
= pos
* (es
->line_count
- vlc
) / 100;
4214 dy
= es
->line_count
? (new_y
- es
->y_offset
) : 0;
4215 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4216 es
->line_count
, es
->y_offset
, pos
, dy
);
4220 /* force scroll info update */
4221 EDIT_UpdateScrollInfo(es
);
4222 EDIT_NOTIFY_PARENT(es
, EN_VSCROLL
);
4226 TRACE("SB_ENDSCROLL\n");
4229 * FIXME : the next two are undocumented !
4230 * Are we doing the right thing ?
4231 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4232 * although it's also a regular control message.
4234 case EM_GETTHUMB
: /* this one is used by NT notepad */
4237 if(GetWindowLongW( es
->hwndSelf
, GWL_STYLE
) & WS_VSCROLL
)
4238 ret
= GetScrollPos(es
->hwndSelf
, SB_VERT
);
4241 /* Assume default scroll range 0-100 */
4242 INT vlc
= get_vertical_line_count(es
);
4243 ret
= es
->line_count
? es
->y_offset
* 100 / (es
->line_count
- vlc
) : 0;
4245 TRACE("EM_GETTHUMB: returning %ld\n", ret
);
4249 TRACE("EM_LINESCROLL %d\n", pos
);
4254 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4259 EDIT_EM_LineScroll(es
, 0, dy
);
4263 /*********************************************************************
4267 * FIXME: is this right ? (or should it be only VSCROLL)
4268 * (and maybe only for edit controls that really have their
4269 * own scrollbars) (and maybe only for multiline controls ?)
4270 * All in all: very poorly documented
4273 static LRESULT
EDIT_EM_GetThumb(EDITSTATE
*es
)
4275 return MAKELONG(EDIT_WM_VScroll(es
, EM_GETTHUMB
, 0),
4276 EDIT_WM_HScroll(es
, EM_GETTHUMB
, 0));
4280 /********************************************************************
4282 * The Following code is to handle inline editing from IMEs
4285 static void EDIT_GetCompositionStr(HIMC hIMC
, LPARAM CompFlag
, EDITSTATE
*es
)
4289 LPSTR lpCompStrAttr
= NULL
;
4292 buflen
= ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, NULL
, 0);
4299 lpCompStr
= HeapAlloc(GetProcessHeap(),0,buflen
);
4302 ERR("Unable to allocate IME CompositionString\n");
4307 ImmGetCompositionStringW(hIMC
, GCS_COMPSTR
, lpCompStr
, buflen
);
4309 if (CompFlag
& GCS_COMPATTR
)
4312 * We do not use the attributes yet. it would tell us what characters
4313 * are in transition and which are converted or decided upon
4315 dwBufLenAttr
= ImmGetCompositionStringW(hIMC
, GCS_COMPATTR
, NULL
, 0);
4319 lpCompStrAttr
= HeapAlloc(GetProcessHeap(),0,dwBufLenAttr
+1);
4322 ERR("Unable to allocate IME Attribute String\n");
4323 HeapFree(GetProcessHeap(),0,lpCompStr
);
4326 ImmGetCompositionStringW(hIMC
,GCS_COMPATTR
, lpCompStrAttr
,
4328 lpCompStrAttr
[dwBufLenAttr
] = 0;
4332 /* check for change in composition start */
4333 if (es
->selection_end
< es
->composition_start
)
4334 es
->composition_start
= es
->selection_end
;
4336 /* replace existing selection string */
4337 es
->selection_start
= es
->composition_start
;
4339 if (es
->composition_len
> 0)
4340 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4342 es
->selection_end
= es
->selection_start
;
4344 EDIT_EM_ReplaceSel(es
, FALSE
, lpCompStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4345 es
->composition_len
= abs(es
->composition_start
- es
->selection_end
);
4347 es
->selection_start
= es
->composition_start
;
4348 es
->selection_end
= es
->selection_start
+ es
->composition_len
;
4350 HeapFree(GetProcessHeap(),0,lpCompStrAttr
);
4351 HeapFree(GetProcessHeap(),0,lpCompStr
);
4354 static void EDIT_GetResultStr(HIMC hIMC
, EDITSTATE
*es
)
4359 buflen
= ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, NULL
, 0);
4365 lpResultStr
= HeapAlloc(GetProcessHeap(),0, buflen
);
4368 ERR("Unable to alloc buffer for IME string\n");
4372 ImmGetCompositionStringW(hIMC
, GCS_RESULTSTR
, lpResultStr
, buflen
);
4374 /* check for change in composition start */
4375 if (es
->selection_end
< es
->composition_start
)
4376 es
->composition_start
= es
->selection_end
;
4378 es
->selection_start
= es
->composition_start
;
4379 es
->selection_end
= es
->composition_start
+ es
->composition_len
;
4380 EDIT_EM_ReplaceSel(es
, TRUE
, lpResultStr
, buflen
/ sizeof(WCHAR
), TRUE
, TRUE
);
4381 es
->composition_start
= es
->selection_end
;
4382 es
->composition_len
= 0;
4384 HeapFree(GetProcessHeap(),0,lpResultStr
);
4387 static void EDIT_ImeComposition(HWND hwnd
, LPARAM CompFlag
, EDITSTATE
*es
)
4392 if (es
->composition_len
== 0 && es
->selection_start
!= es
->selection_end
)
4394 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
4395 es
->composition_start
= es
->selection_end
;
4398 hIMC
= ImmGetContext(hwnd
);
4402 if (CompFlag
& GCS_RESULTSTR
)
4404 EDIT_GetResultStr(hIMC
, es
);
4409 if (CompFlag
& GCS_COMPSTR
)
4410 EDIT_GetCompositionStr(hIMC
, CompFlag
, es
);
4411 cursor
= ImmGetCompositionStringW(hIMC
, GCS_CURSORPOS
, 0, 0);
4413 ImmReleaseContext(hwnd
, hIMC
);
4414 EDIT_SetCaretPos(es
, es
->selection_start
+ cursor
, es
->flags
& EF_AFTER_WRAP
);
4418 /*********************************************************************
4422 * See also EDIT_WM_StyleChanged
4424 static LRESULT
EDIT_WM_NCCreate(HWND hwnd
, LPCREATESTRUCTW lpcs
, BOOL unicode
)
4429 TRACE("Creating %s edit control, style = %08x\n",
4430 unicode
? "Unicode" : "ANSI", lpcs
->style
);
4432 if (!(es
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*es
))))
4434 SetWindowLongPtrW( hwnd
, 0, (LONG_PTR
)es
);
4437 * Note: since the EDITSTATE has not been fully initialized yet,
4438 * we can't use any API calls that may send
4439 * WM_XXX messages before WM_NCCREATE is completed.
4442 es
->is_unicode
= unicode
;
4443 es
->style
= lpcs
->style
;
4445 es
->bEnableState
= !(es
->style
& WS_DISABLED
);
4447 es
->hwndSelf
= hwnd
;
4448 /* Save parent, which will be notified by EN_* messages */
4449 es
->hwndParent
= lpcs
->hwndParent
;
4451 if (es
->style
& ES_COMBO
)
4452 es
->hwndListBox
= GetDlgItem(es
->hwndParent
, ID_CB_LISTBOX
);
4454 /* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4455 if (lpcs
->dwExStyle
& WS_EX_RIGHT
) es
->style
|= ES_RIGHT
;
4457 /* Number overrides lowercase overrides uppercase (at least it
4458 * does in Win95). However I'll bet that ES_NUMBER would be
4459 * invalid under Win 3.1.
4461 if (es
->style
& ES_NUMBER
) {
4462 ; /* do not override the ES_NUMBER */
4463 } else if (es
->style
& ES_LOWERCASE
) {
4464 es
->style
&= ~ES_UPPERCASE
;
4466 if (es
->style
& ES_MULTILINE
) {
4467 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4468 if (es
->style
& WS_VSCROLL
)
4469 es
->style
|= ES_AUTOVSCROLL
;
4470 if (es
->style
& WS_HSCROLL
)
4471 es
->style
|= ES_AUTOHSCROLL
;
4472 es
->style
&= ~ES_PASSWORD
;
4473 if ((es
->style
& ES_CENTER
) || (es
->style
& ES_RIGHT
)) {
4474 /* Confirmed - RIGHT overrides CENTER */
4475 if (es
->style
& ES_RIGHT
)
4476 es
->style
&= ~ES_CENTER
;
4477 es
->style
&= ~WS_HSCROLL
;
4478 es
->style
&= ~ES_AUTOHSCROLL
;
4481 es
->buffer_limit
= BUFLIMIT_INITIAL
;
4482 if ((es
->style
& ES_RIGHT
) && (es
->style
& ES_CENTER
))
4483 es
->style
&= ~ES_CENTER
;
4484 es
->style
&= ~WS_HSCROLL
;
4485 es
->style
&= ~WS_VSCROLL
;
4486 if (es
->style
& ES_PASSWORD
)
4487 es
->password_char
= '*';
4490 alloc_size
= ROUND_TO_GROW((es
->buffer_size
+ 1) * sizeof(WCHAR
));
4491 if(!(es
->hloc32W
= LocalAlloc(LMEM_MOVEABLE
| LMEM_ZEROINIT
, alloc_size
)))
4493 es
->buffer_size
= LocalSize(es
->hloc32W
)/sizeof(WCHAR
) - 1;
4495 if (!(es
->undo_text
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (es
->buffer_size
+ 1) * sizeof(WCHAR
))))
4497 es
->undo_buffer_size
= es
->buffer_size
;
4499 if (es
->style
& ES_MULTILINE
)
4500 if (!(es
->first_line_def
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(LINEDEF
))))
4505 * In Win95 look and feel, the WS_BORDER style is replaced by the
4506 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4507 * control a nonclient area so we don't need to draw the border.
4508 * If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4509 * a nonclient area and we should handle painting the border ourselves.
4511 * When making modifications please ensure that the code still works
4512 * for edit controls created directly with style 0x50800000, exStyle 0
4513 * (which should have a single pixel border)
4515 if (lpcs
->dwExStyle
& WS_EX_CLIENTEDGE
)
4516 es
->style
&= ~WS_BORDER
;
4517 else if (es
->style
& WS_BORDER
)
4518 SetWindowLongW(hwnd
, GWL_STYLE
, es
->style
& ~WS_BORDER
);
4523 SetWindowLongPtrW(es
->hwndSelf
, 0, 0);
4524 EDIT_InvalidateUniscribeData(es
);
4525 HeapFree(GetProcessHeap(), 0, es
->first_line_def
);
4526 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4527 if (es
->hloc32W
) LocalFree(es
->hloc32W
);
4528 HeapFree(GetProcessHeap(), 0, es
->logAttr
);
4529 HeapFree(GetProcessHeap(), 0, es
);
4534 /*********************************************************************
4539 static LRESULT
EDIT_WM_Create(EDITSTATE
*es
, LPCWSTR name
)
4543 TRACE("%s\n", debugstr_w(name
));
4545 * To initialize some final structure members, we call some helper
4546 * functions. However, since the EDITSTATE is not consistent (i.e.
4547 * not fully initialized), we should be very careful which
4548 * functions can be called, and in what order.
4550 EDIT_WM_SetFont(es
, 0, FALSE
);
4551 EDIT_EM_EmptyUndoBuffer(es
);
4553 /* We need to calculate the format rect
4554 (applications may send EM_SETMARGINS before the control gets visible) */
4555 GetClientRect(es
->hwndSelf
, &clientRect
);
4556 EDIT_SetRectNP(es
, &clientRect
);
4558 if (name
&& *name
) {
4559 EDIT_EM_ReplaceSel(es
, FALSE
, name
, strlenW(name
), FALSE
, FALSE
);
4560 /* if we insert text to the editline, the text scrolls out
4561 * of the window, as the caret is placed after the insert
4562 * pos normally; thus we reset es->selection... to 0 and
4565 es
->selection_start
= es
->selection_end
= 0;
4566 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4567 * Messages are only to be sent when the USER does something to
4568 * change the contents. So I am removing this EN_CHANGE
4570 * EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4572 EDIT_EM_ScrollCaret(es
);
4574 /* force scroll info update */
4575 EDIT_UpdateScrollInfo(es
);
4576 /* The rule seems to return 1 here for success */
4577 /* Power Builder masked edit controls will crash */
4579 /* FIXME: is that in all cases so ? */
4584 /*********************************************************************
4589 static LRESULT
EDIT_WM_NCDestroy(EDITSTATE
*es
)
4593 /* The app can own the text buffer handle */
4594 if (es
->hloc32W
&& (es
->hloc32W
!= es
->hlocapp
)) {
4595 LocalFree(es
->hloc32W
);
4597 if (es
->hloc32A
&& (es
->hloc32A
!= es
->hlocapp
)) {
4598 LocalFree(es
->hloc32A
);
4600 EDIT_InvalidateUniscribeData(es
);
4601 pc
= es
->first_line_def
;
4605 HeapFree(GetProcessHeap(), 0, pc
);
4609 SetWindowLongPtrW( es
->hwndSelf
, 0, 0 );
4610 HeapFree(GetProcessHeap(), 0, es
->undo_text
);
4611 HeapFree(GetProcessHeap(), 0, es
);
4617 static inline LRESULT
DefWindowProcT(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4620 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4622 return DefWindowProcA(hwnd
, msg
, wParam
, lParam
);
4625 /*********************************************************************
4627 * EditWndProc_common
4629 * The messages are in the order of the actual integer values
4630 * (which can be found in include/windows.h)
4632 LRESULT
EditWndProc_common( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL unicode
)
4634 EDITSTATE
*es
= (EDITSTATE
*)GetWindowLongPtrW( hwnd
, 0 );
4637 TRACE("hwnd=%p msg=%x (%s) wparam=%lx lparam=%lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
4639 if (!es
&& msg
!= WM_NCCREATE
)
4640 return DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
4642 if (es
&& (msg
!= WM_NCDESTROY
)) EDIT_LockBuffer(es
);
4646 result
= EDIT_EM_GetSel(es
, (PUINT
)wParam
, (PUINT
)lParam
);
4650 EDIT_EM_SetSel(es
, wParam
, lParam
, FALSE
);
4651 EDIT_EM_ScrollCaret(es
);
4657 *((LPRECT
)lParam
) = es
->format_rect
;
4661 if ((es
->style
& ES_MULTILINE
) && lParam
) {
4662 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4663 EDIT_UpdateText(es
, NULL
, TRUE
);
4668 if ((es
->style
& ES_MULTILINE
) && lParam
)
4669 EDIT_SetRectNP(es
, (LPRECT
)lParam
);
4673 result
= EDIT_EM_Scroll(es
, (INT
)wParam
);
4677 result
= (LRESULT
)EDIT_EM_LineScroll(es
, (INT
)wParam
, (INT
)lParam
);
4680 case EM_SCROLLCARET
:
4681 EDIT_EM_ScrollCaret(es
);
4686 result
= ((es
->flags
& EF_MODIFIED
) != 0);
4691 es
->flags
|= EF_MODIFIED
;
4693 es
->flags
&= ~(EF_MODIFIED
| EF_UPDATE
); /* reset pending updates */
4696 case EM_GETLINECOUNT
:
4697 result
= (es
->style
& ES_MULTILINE
) ? es
->line_count
: 1;
4701 result
= (LRESULT
)EDIT_EM_LineIndex(es
, (INT
)wParam
);
4705 EDIT_EM_SetHandle(es
, (HLOCAL
)wParam
);
4709 result
= (LRESULT
)EDIT_EM_GetHandle(es
);
4713 result
= EDIT_EM_GetThumb(es
);
4716 /* these messages missing from specs */
4721 FIXME("undocumented message 0x%x, please report\n", msg
);
4722 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
4726 result
= (LRESULT
)EDIT_EM_LineLength(es
, (INT
)wParam
);
4734 textW
= (LPWSTR
)lParam
;
4737 LPSTR textA
= (LPSTR
)lParam
;
4738 INT countW
= MultiByteToWideChar(CP_ACP
, 0, textA
, -1, NULL
, 0);
4739 if (!(textW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
)))) break;
4740 MultiByteToWideChar(CP_ACP
, 0, textA
, -1, textW
, countW
);
4743 EDIT_EM_ReplaceSel(es
, (BOOL
)wParam
, textW
, strlenW(textW
), TRUE
, TRUE
);
4747 HeapFree(GetProcessHeap(), 0, textW
);
4752 result
= (LRESULT
)EDIT_EM_GetLine(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
4755 case EM_SETLIMITTEXT
:
4756 EDIT_EM_SetLimitText(es
, wParam
);
4760 result
= (LRESULT
)EDIT_EM_CanUndo(es
);
4765 result
= (LRESULT
)EDIT_EM_Undo(es
);
4769 result
= (LRESULT
)EDIT_EM_FmtLines(es
, (BOOL
)wParam
);
4772 case EM_LINEFROMCHAR
:
4773 result
= (LRESULT
)EDIT_EM_LineFromChar(es
, (INT
)wParam
);
4776 case EM_SETTABSTOPS
:
4777 result
= (LRESULT
)EDIT_EM_SetTabStops(es
, (INT
)wParam
, (LPINT
)lParam
);
4780 case EM_SETPASSWORDCHAR
:
4785 charW
= (WCHAR
)wParam
;
4788 CHAR charA
= wParam
;
4789 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
4792 EDIT_EM_SetPasswordChar(es
, charW
);
4796 case EM_EMPTYUNDOBUFFER
:
4797 EDIT_EM_EmptyUndoBuffer(es
);
4800 case EM_GETFIRSTVISIBLELINE
:
4801 result
= (es
->style
& ES_MULTILINE
) ? es
->y_offset
: es
->x_offset
;
4804 case EM_SETREADONLY
:
4806 DWORD old_style
= es
->style
;
4809 SetWindowLongW( hwnd
, GWL_STYLE
,
4810 GetWindowLongW( hwnd
, GWL_STYLE
) | ES_READONLY
);
4811 es
->style
|= ES_READONLY
;
4813 SetWindowLongW( hwnd
, GWL_STYLE
,
4814 GetWindowLongW( hwnd
, GWL_STYLE
) & ~ES_READONLY
);
4815 es
->style
&= ~ES_READONLY
;
4818 if (old_style
^ es
->style
)
4819 InvalidateRect(es
->hwndSelf
, NULL
, TRUE
);
4825 case EM_SETWORDBREAKPROC
:
4826 EDIT_EM_SetWordBreakProc(es
, (void *)lParam
);
4830 case EM_GETWORDBREAKPROC
:
4831 result
= (LRESULT
)es
->word_break_proc
;
4834 case EM_GETPASSWORDCHAR
:
4837 result
= es
->password_char
;
4840 WCHAR charW
= es
->password_char
;
4842 WideCharToMultiByte(CP_ACP
, 0, &charW
, 1, &charA
, 1, NULL
, NULL
);
4849 EDIT_EM_SetMargins(es
, (INT
)wParam
, LOWORD(lParam
), HIWORD(lParam
), TRUE
);
4853 result
= MAKELONG(es
->left_margin
, es
->right_margin
);
4856 case EM_GETLIMITTEXT
:
4857 result
= es
->buffer_limit
;
4860 case EM_POSFROMCHAR
:
4861 if ((INT
)wParam
>= get_text_length(es
)) result
= -1;
4862 else result
= EDIT_EM_PosFromChar(es
, (INT
)wParam
, FALSE
);
4865 case EM_CHARFROMPOS
:
4866 result
= EDIT_EM_CharFromPos(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4869 /* End of the EM_ messages which were in numerical order; what order
4870 * are these in? vaguely alphabetical?
4874 result
= EDIT_WM_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
, unicode
);
4878 result
= EDIT_WM_NCDestroy(es
);
4883 result
= DLGC_HASSETSEL
| DLGC_WANTCHARS
| DLGC_WANTARROWS
;
4885 if (es
->style
& ES_MULTILINE
)
4886 result
|= DLGC_WANTALLKEYS
;
4890 es
->flags
|=EF_DIALOGMODE
;
4892 if (((LPMSG
)lParam
)->message
== WM_KEYDOWN
)
4894 int vk
= (int)((LPMSG
)lParam
)->wParam
;
4896 if (es
->hwndListBox
)
4898 if (vk
== VK_RETURN
|| vk
== VK_ESCAPE
)
4899 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4900 result
|= DLGC_WANTMESSAGE
;
4912 strng
[0] = wParam
>> 8;
4913 strng
[1] = wParam
& 0xff;
4914 if (strng
[0]) MultiByteToWideChar(CP_ACP
, 0, strng
, 2, &charW
, 1);
4915 else MultiByteToWideChar(CP_ACP
, 0, &strng
[1], 1, &charW
, 1);
4916 result
= EDIT_WM_Char(es
, charW
);
4928 CHAR charA
= wParam
;
4929 MultiByteToWideChar(CP_ACP
, 0, &charA
, 1, &charW
, 1);
4932 if (es
->hwndListBox
)
4934 if (charW
== VK_RETURN
|| charW
== VK_ESCAPE
)
4936 if (SendMessageW(GetParent(hwnd
), CB_GETDROPPEDSTATE
, 0, 0))
4937 SendMessageW(GetParent(hwnd
), WM_KEYDOWN
, charW
, 0);
4941 result
= EDIT_WM_Char(es
, charW
);
4948 if (wParam
== UNICODE_NOCHAR
) return TRUE
;
4949 if (wParam
<= 0x000fffff)
4951 if(wParam
> 0xffff) /* convert to surrogates */
4954 EDIT_WM_Char(es
, (wParam
>> 10) + 0xd800);
4955 EDIT_WM_Char(es
, (wParam
& 0x03ff) + 0xdc00);
4957 else EDIT_WM_Char(es
, wParam
);
4967 case WM_CONTEXTMENU
:
4968 EDIT_WM_ContextMenu(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
4977 result
= EDIT_WM_Create(es
, ((LPCREATESTRUCTW
)lParam
)->lpszName
);
4980 LPCSTR nameA
= ((LPCREATESTRUCTA
)lParam
)->lpszName
;
4981 LPWSTR nameW
= NULL
;
4984 INT countW
= MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, NULL
, 0);
4985 if((nameW
= HeapAlloc(GetProcessHeap(), 0, countW
* sizeof(WCHAR
))))
4986 MultiByteToWideChar(CP_ACP
, 0, nameA
, -1, nameW
, countW
);
4988 result
= EDIT_WM_Create(es
, nameW
);
4989 HeapFree(GetProcessHeap(), 0, nameW
);
4998 es
->bEnableState
= (BOOL
) wParam
;
4999 EDIT_UpdateText(es
, NULL
, TRUE
);
5003 /* we do the proper erase in EDIT_WM_Paint */
5008 result
= (LRESULT
)es
->font
;
5012 result
= (LRESULT
)EDIT_WM_GetText(es
, (INT
)wParam
, (LPWSTR
)lParam
, unicode
);
5015 case WM_GETTEXTLENGTH
:
5016 if (unicode
) result
= get_text_length(es
);
5017 else result
= WideCharToMultiByte( CP_ACP
, 0, es
->text
, get_text_length(es
),
5018 NULL
, 0, NULL
, NULL
);
5022 result
= EDIT_WM_HScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5026 result
= EDIT_WM_KeyDown(es
, (INT
)wParam
);
5030 result
= EDIT_WM_KillFocus(es
);
5033 case WM_LBUTTONDBLCLK
:
5034 result
= EDIT_WM_LButtonDblClk(es
);
5037 case WM_LBUTTONDOWN
:
5038 result
= EDIT_WM_LButtonDown(es
, wParam
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5042 result
= EDIT_WM_LButtonUp(es
);
5045 case WM_MBUTTONDOWN
:
5046 result
= EDIT_WM_MButtonDown(es
);
5050 result
= EDIT_WM_MouseMove(es
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
5053 case WM_PRINTCLIENT
:
5055 EDIT_WM_Paint(es
, (HDC
)wParam
);
5063 EDIT_WM_SetFocus(es
);
5067 EDIT_WM_SetFont(es
, (HFONT
)wParam
, LOWORD(lParam
) != 0);
5071 /* FIXME: actually set an internal flag and behave accordingly */
5075 EDIT_WM_SetText(es
, (LPCWSTR
)lParam
, unicode
);
5080 EDIT_WM_Size(es
, (UINT
)wParam
);
5083 case WM_STYLECHANGED
:
5084 result
= EDIT_WM_StyleChanged(es
, wParam
, (const STYLESTRUCT
*)lParam
);
5087 case WM_STYLECHANGING
:
5088 result
= 0; /* See EDIT_WM_StyleChanged */
5092 result
= EDIT_WM_SysKeyDown(es
, (INT
)wParam
, (DWORD
)lParam
);
5100 result
= EDIT_WM_VScroll(es
, LOWORD(wParam
), (short)HIWORD(wParam
));
5106 UINT pulScrollLines
= 3;
5107 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
5109 if (wParam
& (MK_SHIFT
| MK_CONTROL
)) {
5110 result
= DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
5113 wheelDelta
= GET_WHEEL_DELTA_WPARAM(wParam
);
5114 /* if scrolling changes direction, ignore left overs */
5115 if ((wheelDelta
< 0 && es
->wheelDeltaRemainder
< 0) ||
5116 (wheelDelta
> 0 && es
->wheelDeltaRemainder
> 0))
5117 es
->wheelDeltaRemainder
+= wheelDelta
;
5119 es
->wheelDeltaRemainder
= wheelDelta
;
5120 if (es
->wheelDeltaRemainder
&& pulScrollLines
)
5123 pulScrollLines
= (int) min((UINT
) es
->line_count
, pulScrollLines
);
5124 cLineScroll
= pulScrollLines
* (float)es
->wheelDeltaRemainder
/ WHEEL_DELTA
;
5125 es
->wheelDeltaRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
5126 result
= EDIT_EM_LineScroll(es
, 0, -cLineScroll
);
5132 /* IME messages to make the edit control IME aware */
5133 case WM_IME_SETCONTEXT
:
5136 case WM_IME_STARTCOMPOSITION
:
5137 es
->composition_start
= es
->selection_end
;
5138 es
->composition_len
= 0;
5141 case WM_IME_COMPOSITION
:
5142 EDIT_ImeComposition(hwnd
, lParam
, es
);
5145 case WM_IME_ENDCOMPOSITION
:
5146 if (es
->composition_len
> 0)
5148 EDIT_EM_ReplaceSel(es
, TRUE
, NULL
, 0, TRUE
, TRUE
);
5149 es
->selection_end
= es
->selection_start
;
5150 es
->composition_len
= 0;
5154 case WM_IME_COMPOSITIONFULL
:
5160 case WM_IME_CONTROL
:
5163 case WM_IME_REQUEST
:
5166 case IMR_QUERYCHARPOSITION
:
5169 IMECHARPOSITION
*chpos
= (IMECHARPOSITION
*)lParam
;
5171 pos
= EDIT_EM_PosFromChar(es
, es
->selection_start
+ chpos
->dwCharPos
, FALSE
);
5172 chpos
->pt
.x
= LOWORD(pos
);
5173 chpos
->pt
.y
= HIWORD(pos
);
5174 chpos
->cLineHeight
= es
->line_height
;
5175 chpos
->rcDocument
= es
->format_rect
;
5176 MapWindowPoints(hwnd
, 0, &chpos
->pt
, 1);
5177 MapWindowPoints(hwnd
, 0, (POINT
*)&chpos
->rcDocument
, 2);
5185 result
= DefWindowProcT(hwnd
, msg
, wParam
, lParam
, unicode
);
5189 if (IsWindow(hwnd
) && es
&& msg
!= EM_GETHANDLE
)
5190 EDIT_UnlockBuffer(es
, FALSE
);
5192 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), result
);
5198 /*********************************************************************
5199 * edit class descriptor
5201 static const WCHAR editW
[] = {'E','d','i','t',0};
5202 const struct builtin_class_descr EDIT_builtin_class
=
5205 CS_DBLCLKS
| CS_PARENTDC
, /* style */
5206 WINPROC_EDIT
, /* proc */
5208 sizeof(EDITSTATE
*) + sizeof(WORD
), /* extra */
5210 sizeof(EDITSTATE
*), /* extra */
5212 IDC_IBEAM
, /* cursor */