Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comctl32/edit.c
4394 views
1
/*
2
* Edit control
3
*
4
* Copyright David W. Metcalfe, 1994
5
* Copyright William Magro, 1995, 1996
6
* Copyright Frans van Dorsselaer, 1996, 1997
7
* Copyright Frank Richter, 2005
8
*
9
*
10
* This library is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public
12
* License as published by the Free Software Foundation; either
13
* version 2.1 of the License, or (at your option) any later version.
14
*
15
* This library is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
* Lesser General Public License for more details.
19
*
20
* You should have received a copy of the GNU Lesser General Public
21
* License along with this library; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23
*
24
* TODO:
25
* - EDITBALLOONTIP structure
26
* - EM_HIDEBALLOONTIP/Edit_HideBalloonTip
27
* - EM_SHOWBALLOONTIP/Edit_ShowBalloonTip
28
* - EN_ALIGN_LTR_EC
29
* - EN_ALIGN_RTL_EC
30
* - ES_OEMCONVERT
31
*
32
*/
33
34
#include <stdarg.h>
35
#include <string.h>
36
#include <stdlib.h>
37
38
#include "windef.h"
39
#include "winbase.h"
40
#include "winnt.h"
41
#include "wingdi.h"
42
#include "imm.h"
43
#include "usp10.h"
44
#include "commctrl.h"
45
#include "uxtheme.h"
46
#include "vsstyle.h"
47
#include "comctl32.h"
48
#include "wine/debug.h"
49
50
WINE_DEFAULT_DEBUG_CHANNEL(edit);
51
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 */
56
57
/*
58
* extra flags for EDITSTATE.flags field
59
*/
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 */
69
70
#define ID_CB_LISTBOX 1000
71
72
typedef enum
73
{
74
END_0 = 0, /* line ends with terminating '\0' character */
75
END_WRAP, /* line is wrapped */
76
END_HARD, /* line ends with a hard return '\r\n' */
77
END_SOFT, /* line ends with a soft return '\r\r\n' */
78
END_RICH /* line ends with a single '\n' */
79
} LINE_END;
80
81
typedef struct tagLINEDEF {
82
INT length; /* bruto length of a line in bytes */
83
INT net_length; /* netto length of a line in visible characters */
84
LINE_END ending;
85
INT width; /* width of the line in pixels */
86
INT index; /* line index into the buffer */
87
SCRIPT_STRING_ANALYSIS ssa; /* Uniscribe Data */
88
struct tagLINEDEF *next;
89
} LINEDEF;
90
91
typedef struct
92
{
93
LPWSTR text; /* the actual contents of the control */
94
UINT text_length; /* cached length of text buffer (in WCHARs) - use get_text_length() to retrieve */
95
UINT buffer_size; /* the size of the buffer in characters */
96
UINT buffer_limit; /* the maximum size to which the buffer may grow in characters */
97
HFONT font; /* NULL means standard system font */
98
INT x_offset; /* scroll offset for multi lines this is in pixels
99
for single lines it's in characters */
100
INT line_height; /* height of a screen line in pixels */
101
INT char_width; /* average character width in pixels */
102
DWORD style; /* sane version of wnd->dwStyle */
103
WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
104
INT undo_insert_count; /* number of characters inserted in sequence */
105
UINT undo_position; /* character index of the insertion and deletion */
106
LPWSTR undo_text; /* deleted text */
107
UINT undo_buffer_size; /* size of the deleted text buffer */
108
INT selection_start; /* == selection_end if no selection */
109
INT selection_end; /* == current caret position */
110
WCHAR password_char; /* == 0 if no password char, and for multi line controls */
111
INT left_margin; /* in pixels */
112
INT right_margin; /* in pixels */
113
RECT format_rect;
114
INT text_width; /* width of the widest line in pixels for multi line controls
115
and just line width for single line controls */
116
EDITWORDBREAKPROCW word_break_proc;
117
INT line_count; /* number of lines */
118
INT y_offset; /* scroll offset in number of lines */
119
BOOL bCaptureState; /* flag indicating whether mouse was captured */
120
BOOL bEnableState; /* flag keeping the enable state */
121
HWND hwndSelf; /* the our window handle */
122
HWND hwndParent; /* Handle of parent for sending EN_* messages.
123
Even if parent will change, EN_* messages
124
should be sent to the first parent. */
125
HWND hwndListBox; /* handle of ComboBox's listbox or NULL */
126
INT wheelDeltaRemainder; /* scroll wheel delta left over after scrolling whole lines */
127
WCHAR *cue_banner_text;
128
BOOL cue_banner_draw_focused;
129
130
/*
131
* only for multi line controls
132
*/
133
INT lock_count; /* amount of re-entries in the EditWndProc */
134
INT tabs_count;
135
LPINT tabs;
136
LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
137
HLOCAL hloc32W; /* our unicode local memory block */
138
HLOCAL hlocapp; /* The text buffer handle belongs to the app */
139
/*
140
* IME Data
141
*/
142
UINT ime_status; /* IME status flag */
143
144
/*
145
* Uniscribe Data
146
*/
147
SCRIPT_LOGATTR *logAttr;
148
SCRIPT_STRING_ANALYSIS ssa; /* Uniscribe Data for single line controls */
149
} EDITSTATE;
150
151
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)
154
155
static inline BOOL notify_parent(const EDITSTATE *es, INT code)
156
{
157
HWND hwnd = es->hwndSelf;
158
TRACE("notification %d sent to %p.\n", code, es->hwndParent);
159
SendMessageW(es->hwndParent, WM_COMMAND, MAKEWPARAM(GetWindowLongPtrW(es->hwndSelf, GWLP_ID), code), (LPARAM)es->hwndSelf);
160
return IsWindow(hwnd);
161
}
162
163
static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap);
164
165
/*********************************************************************
166
*
167
* EM_CANUNDO
168
*
169
*/
170
static inline BOOL EDIT_EM_CanUndo(const EDITSTATE *es)
171
{
172
return (es->undo_insert_count || lstrlenW(es->undo_text));
173
}
174
175
176
/*********************************************************************
177
*
178
* EM_EMPTYUNDOBUFFER
179
*
180
*/
181
static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es)
182
{
183
es->undo_insert_count = 0;
184
*es->undo_text = '\0';
185
}
186
187
static HBRUSH EDIT_NotifyCtlColor(EDITSTATE *es, HDC hdc)
188
{
189
HBRUSH hbrush;
190
UINT msg;
191
192
if ((!es->bEnableState || (es->style & ES_READONLY)))
193
msg = WM_CTLCOLORSTATIC;
194
else
195
msg = WM_CTLCOLOREDIT;
196
197
/* Why do we notify to es->hwndParent, and we send this one to GetParent()? */
198
hbrush = (HBRUSH)SendMessageW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf);
199
if (!hbrush)
200
hbrush = (HBRUSH)DefWindowProcW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf);
201
return hbrush;
202
}
203
204
205
static inline UINT get_text_length(EDITSTATE *es)
206
{
207
if(es->text_length == (UINT)-1)
208
es->text_length = lstrlenW(es->text);
209
return es->text_length;
210
}
211
212
213
/*********************************************************************
214
*
215
* EDIT_WordBreakProc
216
*
217
* Find the beginning of words.
218
* Note: unlike the specs for a WordBreakProc, this function can
219
* only be called without linebreaks between s[0] up to
220
* s[count - 1]. Remember it is only called
221
* internally, so we can decide this for ourselves.
222
* Additionally we will always be breaking the full string.
223
*
224
*/
225
static INT EDIT_WordBreakProc(EDITSTATE *es, LPWSTR s, INT index, INT count, INT action)
226
{
227
INT ret = 0;
228
229
TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action);
230
231
if(!s) return 0;
232
233
if (!es->logAttr)
234
{
235
SCRIPT_ANALYSIS psa;
236
237
memset(&psa,0,sizeof(SCRIPT_ANALYSIS));
238
psa.eScript = SCRIPT_UNDEFINED;
239
240
es->logAttr = Alloc(sizeof(SCRIPT_LOGATTR) * get_text_length(es));
241
ScriptBreak(es->text, get_text_length(es), &psa, es->logAttr);
242
}
243
244
switch (action) {
245
case WB_LEFT:
246
if (index)
247
index--;
248
while (index && !es->logAttr[index].fSoftBreak)
249
index--;
250
ret = index;
251
break;
252
case WB_RIGHT:
253
if (!count)
254
break;
255
while (index < count && s[index] && !es->logAttr[index].fSoftBreak)
256
index++;
257
ret = index;
258
break;
259
case WB_ISDELIMITER:
260
ret = es->logAttr[index].fWhiteSpace;
261
break;
262
default:
263
ERR("unknown action code, please report !\n");
264
break;
265
}
266
return ret;
267
}
268
269
270
/*********************************************************************
271
*
272
* EDIT_CallWordBreakProc
273
*
274
* Call appropriate WordBreakProc (internal or external).
275
*
276
* Note: The "start" argument should always be an index referring
277
* to es->text. The actual wordbreak proc might be
278
* 16 bit, so we can't always pass any 32 bit LPSTR.
279
* Hence we assume that es->text is the buffer that holds
280
* the string under examination (we can decide this for ourselves).
281
*
282
*/
283
static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action)
284
{
285
INT ret;
286
287
if (es->word_break_proc)
288
ret = es->word_break_proc(es->text + start, index, count, action);
289
else
290
ret = EDIT_WordBreakProc(es, es->text, index + start, count + start, action) - start;
291
292
return ret;
293
}
294
295
static inline void EDIT_InvalidateUniscribeData_linedef(LINEDEF *line_def)
296
{
297
if (line_def->ssa)
298
{
299
ScriptStringFree(&line_def->ssa);
300
line_def->ssa = NULL;
301
}
302
}
303
304
static inline void EDIT_InvalidateUniscribeData(EDITSTATE *es)
305
{
306
LINEDEF *line_def = es->first_line_def;
307
while (line_def)
308
{
309
EDIT_InvalidateUniscribeData_linedef(line_def);
310
line_def = line_def->next;
311
}
312
if (es->ssa)
313
{
314
ScriptStringFree(&es->ssa);
315
es->ssa = NULL;
316
}
317
}
318
319
static SCRIPT_STRING_ANALYSIS EDIT_UpdateUniscribeData_linedef(EDITSTATE *es, HDC dc, LINEDEF *line_def)
320
{
321
if (!line_def)
322
return NULL;
323
324
if (line_def->net_length && !line_def->ssa)
325
{
326
int index = line_def->index;
327
HFONT old_font = NULL;
328
HDC udc = dc;
329
SCRIPT_TABDEF tabdef;
330
HRESULT hr;
331
332
if (!udc)
333
udc = GetDC(es->hwndSelf);
334
if (es->font)
335
old_font = SelectObject(udc, es->font);
336
337
tabdef.cTabStops = es->tabs_count;
338
tabdef.iScale = GdiGetCharDimensions(udc, NULL, NULL);
339
tabdef.pTabStops = es->tabs;
340
tabdef.iTabOrigin = 0;
341
342
hr = ScriptStringAnalyse(udc, &es->text[index], line_def->net_length,
343
(1.5*line_def->net_length+16), -1,
344
SSA_LINK|SSA_FALLBACK|SSA_GLYPHS|SSA_TAB, -1,
345
NULL, NULL, NULL, &tabdef, NULL, &line_def->ssa);
346
if (FAILED(hr))
347
{
348
WARN("ScriptStringAnalyse failed, hr %#lx.\n", hr);
349
line_def->ssa = NULL;
350
}
351
352
if (es->font)
353
SelectObject(udc, old_font);
354
if (udc != dc)
355
ReleaseDC(es->hwndSelf, udc);
356
}
357
358
return line_def->ssa;
359
}
360
361
static SCRIPT_STRING_ANALYSIS EDIT_UpdateUniscribeData(EDITSTATE *es, HDC dc, INT line)
362
{
363
LINEDEF *line_def;
364
365
if (!(es->style & ES_MULTILINE))
366
{
367
if (!es->ssa)
368
{
369
INT length = get_text_length(es);
370
HFONT old_font = NULL;
371
HDC udc = dc;
372
373
if (!udc)
374
udc = GetDC(es->hwndSelf);
375
if (es->font)
376
old_font = SelectObject(udc, es->font);
377
378
if (es->style & ES_PASSWORD)
379
ScriptStringAnalyse(udc, &es->password_char, length, (1.5*length+16), -1, SSA_LINK|SSA_FALLBACK|SSA_GLYPHS|SSA_PASSWORD, -1, NULL, NULL, NULL, NULL, NULL, &es->ssa);
380
else
381
ScriptStringAnalyse(udc, es->text, length, (1.5*length+16), -1, SSA_LINK|SSA_FALLBACK|SSA_GLYPHS, -1, NULL, NULL, NULL, NULL, NULL, &es->ssa);
382
383
if (es->font)
384
SelectObject(udc, old_font);
385
if (udc != dc)
386
ReleaseDC(es->hwndSelf, udc);
387
}
388
return es->ssa;
389
}
390
else
391
{
392
line_def = es->first_line_def;
393
while (line_def && line)
394
{
395
line_def = line_def->next;
396
line--;
397
}
398
399
return EDIT_UpdateUniscribeData_linedef(es,dc,line_def);
400
}
401
}
402
403
static inline INT get_vertical_line_count(EDITSTATE *es)
404
{
405
INT vlc = es->line_height ? (es->format_rect.bottom - es->format_rect.top) / es->line_height : 0;
406
return max(1,vlc);
407
}
408
409
/*********************************************************************
410
*
411
* EDIT_BuildLineDefs_ML
412
*
413
* Build linked list of text lines.
414
* Lines can end with '\0' (last line), a character (if it is wrapped),
415
* a soft return '\r\r\n' or a hard return '\r\n'
416
*
417
*/
418
static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT istart, INT iend, INT delta, HRGN hrgn)
419
{
420
LPWSTR current_position, cp;
421
INT fw;
422
LINEDEF *current_line;
423
LINEDEF *previous_line;
424
LINEDEF *start_line;
425
INT line_index = 0, nstart_line, nstart_index;
426
INT line_count = es->line_count;
427
INT orig_net_length;
428
RECT rc;
429
INT vlc;
430
431
if (istart == iend && delta == 0)
432
return;
433
434
previous_line = NULL;
435
current_line = es->first_line_def;
436
437
/* Find starting line. istart must lie inside an existing line or
438
* at the end of buffer */
439
do {
440
if (istart < current_line->index + current_line->length ||
441
current_line->ending == END_0)
442
break;
443
444
previous_line = current_line;
445
current_line = current_line->next;
446
line_index++;
447
} while (current_line);
448
449
if (!current_line) /* Error occurred start is not inside previous buffer */
450
{
451
FIXME(" modification occurred outside buffer\n");
452
return;
453
}
454
455
/* Remember start of modifications in order to calculate update region */
456
nstart_line = line_index;
457
nstart_index = current_line->index;
458
459
/* We must start to reformat from the previous line since the modifications
460
* may have caused the line to wrap upwards. */
461
if (!(es->style & ES_AUTOHSCROLL) && line_index > 0)
462
{
463
line_index--;
464
current_line = previous_line;
465
}
466
start_line = current_line;
467
468
fw = es->format_rect.right - es->format_rect.left;
469
current_position = es->text + current_line->index;
470
vlc = get_vertical_line_count(es);
471
do {
472
if (current_line != start_line)
473
{
474
if (!current_line || current_line->index + delta > current_position - es->text)
475
{
476
/* The buffer has been expanded, create a new line and
477
insert it into the link list */
478
LINEDEF *new_line = Alloc(sizeof(*new_line));
479
new_line->next = previous_line->next;
480
previous_line->next = new_line;
481
current_line = new_line;
482
es->line_count++;
483
}
484
else if (current_line->index + delta < current_position - es->text)
485
{
486
/* The previous line merged with this line so we delete this extra entry */
487
previous_line->next = current_line->next;
488
Free(current_line);
489
current_line = previous_line->next;
490
es->line_count--;
491
continue;
492
}
493
else /* current_line->index + delta == current_position */
494
{
495
if (current_position - es->text > iend)
496
break; /* We reached end of line modifications */
497
/* else recalculate this line */
498
}
499
}
500
501
current_line->index = current_position - es->text;
502
orig_net_length = current_line->net_length;
503
504
/* Find end of line */
505
cp = current_position;
506
while (*cp) {
507
if (*cp == '\n') break;
508
if ((*cp == '\r') && (*(cp + 1) == '\n'))
509
break;
510
cp++;
511
}
512
513
/* Mark type of line termination */
514
if (!(*cp)) {
515
current_line->ending = END_0;
516
current_line->net_length = lstrlenW(current_position);
517
} else if ((cp > current_position) && (*(cp - 1) == '\r')) {
518
current_line->ending = END_SOFT;
519
current_line->net_length = cp - current_position - 1;
520
} else if (*cp == '\n') {
521
current_line->ending = END_RICH;
522
current_line->net_length = cp - current_position;
523
} else {
524
current_line->ending = END_HARD;
525
current_line->net_length = cp - current_position;
526
}
527
528
if (current_line->net_length)
529
{
530
const SIZE *sz;
531
EDIT_InvalidateUniscribeData_linedef(current_line);
532
EDIT_UpdateUniscribeData_linedef(es, NULL, current_line);
533
if (current_line->ssa)
534
{
535
sz = ScriptString_pSize(current_line->ssa);
536
/* Calculate line width */
537
current_line->width = sz->cx;
538
}
539
else current_line->width = es->char_width * current_line->net_length;
540
}
541
else current_line->width = 0;
542
543
/* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
544
545
/* Line breaks just look back from the end and find the next break and try that. */
546
547
if (!(es->style & ES_AUTOHSCROLL)) {
548
if (current_line->width > fw && fw > es->char_width) {
549
550
INT prev, next;
551
int w;
552
const SIZE *sz;
553
float d;
554
555
prev = current_line->net_length - 1;
556
w = current_line->net_length;
557
d = (float)current_line->width/(float)fw;
558
if (d > 1.2f) d -= 0.2f;
559
next = prev/d;
560
if (next >= prev) next = prev-1;
561
do {
562
prev = EDIT_CallWordBreakProc(es, current_position - es->text,
563
next, current_line->net_length, WB_LEFT);
564
current_line->net_length = prev;
565
EDIT_InvalidateUniscribeData_linedef(current_line);
566
EDIT_UpdateUniscribeData_linedef(es, NULL, current_line);
567
if (current_line->ssa)
568
sz = ScriptString_pSize(current_line->ssa);
569
else sz = 0;
570
if (sz)
571
current_line->width = sz->cx;
572
else
573
prev = 0;
574
next = prev - 1;
575
} while (prev && current_line->width > fw);
576
current_line->net_length = w;
577
578
if (prev == 0) { /* Didn't find a line break so force a break */
579
INT *piDx;
580
const INT *count;
581
582
EDIT_InvalidateUniscribeData_linedef(current_line);
583
EDIT_UpdateUniscribeData_linedef(es, NULL, current_line);
584
585
if (current_line->ssa)
586
{
587
count = ScriptString_pcOutChars(current_line->ssa);
588
piDx = Alloc(sizeof(INT) * (*count));
589
ScriptStringGetLogicalWidths(current_line->ssa,piDx);
590
591
prev = current_line->net_length-1;
592
do {
593
current_line->width -= piDx[prev];
594
prev--;
595
} while ( prev > 0 && current_line->width > fw);
596
if (prev<=0)
597
prev = 1;
598
Free(piDx);
599
}
600
else
601
prev = (fw / es->char_width);
602
}
603
604
/* If the first line we are calculating, wrapped before istart, we must
605
* adjust istart in order for this to be reflected in the update region. */
606
if (current_line->index == nstart_index && istart > current_line->index + prev)
607
istart = current_line->index + prev;
608
/* else if we are updating the previous line before the first line we
609
* are re-calculating and it expanded */
610
else if (current_line == start_line &&
611
current_line->index != nstart_index && orig_net_length < prev)
612
{
613
/* Line expanded due to an upwards line wrap so we must partially include
614
* previous line in update region */
615
nstart_line = line_index;
616
nstart_index = current_line->index;
617
istart = current_line->index + orig_net_length;
618
}
619
620
current_line->net_length = prev;
621
current_line->ending = END_WRAP;
622
623
if (current_line->net_length > 0)
624
{
625
EDIT_UpdateUniscribeData_linedef(es, NULL, current_line);
626
if (current_line->ssa)
627
{
628
sz = ScriptString_pSize(current_line->ssa);
629
current_line->width = sz->cx;
630
}
631
else
632
current_line->width = 0;
633
}
634
else current_line->width = 0;
635
}
636
else if (current_line == start_line &&
637
current_line->index != nstart_index &&
638
orig_net_length < current_line->net_length) {
639
/* The previous line expanded but it's still not as wide as the client rect */
640
/* The expansion is due to an upwards line wrap so we must partially include
641
it in the update region */
642
nstart_line = line_index;
643
nstart_index = current_line->index;
644
istart = current_line->index + orig_net_length;
645
}
646
}
647
648
649
/* Adjust length to include line termination */
650
switch (current_line->ending) {
651
case END_SOFT:
652
current_line->length = current_line->net_length + 3;
653
break;
654
case END_RICH:
655
current_line->length = current_line->net_length + 1;
656
break;
657
case END_HARD:
658
current_line->length = current_line->net_length + 2;
659
break;
660
case END_WRAP:
661
case END_0:
662
current_line->length = current_line->net_length;
663
break;
664
}
665
es->text_width = max(es->text_width, current_line->width);
666
current_position += current_line->length;
667
previous_line = current_line;
668
669
/* Discard data for non-visible lines. It will be calculated as needed */
670
if ((line_index < es->y_offset) || (line_index > es->y_offset + vlc))
671
EDIT_InvalidateUniscribeData_linedef(current_line);
672
673
current_line = current_line->next;
674
line_index++;
675
} while (previous_line->ending != END_0);
676
677
/* Finish adjusting line indexes by delta or remove hanging lines */
678
if (previous_line->ending == END_0)
679
{
680
LINEDEF *pnext = NULL;
681
682
previous_line->next = NULL;
683
while (current_line)
684
{
685
pnext = current_line->next;
686
EDIT_InvalidateUniscribeData_linedef(current_line);
687
Free(current_line);
688
current_line = pnext;
689
es->line_count--;
690
}
691
}
692
else if (delta != 0)
693
{
694
while (current_line)
695
{
696
current_line->index += delta;
697
current_line = current_line->next;
698
}
699
}
700
701
/* Calculate rest of modification rectangle */
702
if (hrgn)
703
{
704
HRGN tmphrgn;
705
/*
706
* We calculate two rectangles. One for the first line which may have
707
* an indent with respect to the format rect. The other is a format-width
708
* rectangle that spans the rest of the lines that changed or moved.
709
*/
710
rc.top = es->format_rect.top + nstart_line * es->line_height -
711
(es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
712
rc.bottom = rc.top + es->line_height;
713
if ((es->style & ES_CENTER) || (es->style & ES_RIGHT))
714
rc.left = es->format_rect.left;
715
else
716
rc.left = LOWORD(EDIT_EM_PosFromChar(es, nstart_index, FALSE));
717
rc.right = es->format_rect.right;
718
SetRectRgn(hrgn, rc.left, rc.top, rc.right, rc.bottom);
719
720
rc.top = rc.bottom;
721
rc.left = es->format_rect.left;
722
rc.right = es->format_rect.right;
723
/*
724
* If lines were added or removed we must re-paint the remainder of the
725
* lines since the remaining lines were either shifted up or down.
726
*/
727
if (line_count < es->line_count) /* We added lines */
728
rc.bottom = es->line_count * es->line_height;
729
else if (line_count > es->line_count) /* We removed lines */
730
rc.bottom = line_count * es->line_height;
731
else
732
rc.bottom = line_index * es->line_height;
733
rc.bottom += es->format_rect.top;
734
rc.bottom -= (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
735
tmphrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
736
CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR);
737
DeleteObject(tmphrgn);
738
}
739
}
740
741
/*********************************************************************
742
*
743
* EDIT_CalcLineWidth_SL
744
*
745
*/
746
static void EDIT_CalcLineWidth_SL(EDITSTATE *es)
747
{
748
EDIT_UpdateUniscribeData(es, NULL, 0);
749
if (es->ssa)
750
{
751
const SIZE *size;
752
size = ScriptString_pSize(es->ssa);
753
es->text_width = size->cx;
754
}
755
else
756
es->text_width = 0;
757
}
758
759
/*********************************************************************
760
*
761
* EDIT_CharFromPos
762
*
763
* Beware: This is not the function called on EM_CHARFROMPOS
764
* The position _can_ be outside the formatting / client
765
* rectangle
766
* The return value is only the character index
767
*
768
*/
769
static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
770
{
771
INT index;
772
773
if (es->style & ES_MULTILINE) {
774
int trailing;
775
INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
776
INT line_index = 0;
777
LINEDEF *line_def = es->first_line_def;
778
EDIT_UpdateUniscribeData(es, NULL, line);
779
while ((line > 0) && line_def->next) {
780
line_index += line_def->length;
781
line_def = line_def->next;
782
line--;
783
}
784
785
x += es->x_offset - es->format_rect.left;
786
if (es->style & ES_RIGHT)
787
x -= (es->format_rect.right - es->format_rect.left) - line_def->width;
788
else if (es->style & ES_CENTER)
789
x -= ((es->format_rect.right - es->format_rect.left) - line_def->width) / 2;
790
if (x >= line_def->width) {
791
if (after_wrap)
792
*after_wrap = (line_def->ending == END_WRAP);
793
return line_index + line_def->net_length;
794
}
795
if (x <= 0 || !line_def->ssa) {
796
if (after_wrap)
797
*after_wrap = FALSE;
798
return line_index;
799
}
800
801
ScriptStringXtoCP(line_def->ssa, x , &index, &trailing);
802
if (trailing) index++;
803
index += line_index;
804
if (after_wrap)
805
*after_wrap = ((index == line_index + line_def->net_length) &&
806
(line_def->ending == END_WRAP));
807
} else {
808
INT xoff = 0;
809
INT trailing;
810
if (after_wrap)
811
*after_wrap = FALSE;
812
x -= es->format_rect.left;
813
if (!x)
814
return es->x_offset;
815
816
if (!es->x_offset)
817
{
818
INT indent = (es->format_rect.right - es->format_rect.left) - es->text_width;
819
if (es->style & ES_RIGHT)
820
x -= indent;
821
else if (es->style & ES_CENTER)
822
x -= indent / 2;
823
}
824
825
EDIT_UpdateUniscribeData(es, NULL, 0);
826
if (es->x_offset)
827
{
828
if (es->ssa)
829
{
830
if (es->x_offset>= get_text_length(es))
831
{
832
const SIZE *size;
833
size = ScriptString_pSize(es->ssa);
834
xoff = size->cx;
835
}
836
ScriptStringCPtoX(es->ssa, es->x_offset, FALSE, &xoff);
837
}
838
else
839
xoff = 0;
840
}
841
if (x < 0)
842
{
843
if (x + xoff > 0 || !es->ssa)
844
{
845
ScriptStringXtoCP(es->ssa, x+xoff, &index, &trailing);
846
if (trailing) index++;
847
}
848
else
849
index = 0;
850
}
851
else
852
{
853
if (x)
854
{
855
const SIZE *size = NULL;
856
if (es->ssa)
857
size = ScriptString_pSize(es->ssa);
858
if (!size)
859
index = 0;
860
else if (x > size->cx)
861
index = get_text_length(es);
862
else if (es->ssa)
863
{
864
ScriptStringXtoCP(es->ssa, x+xoff, &index, &trailing);
865
if (trailing) index++;
866
}
867
else
868
index = 0;
869
}
870
else
871
index = es->x_offset;
872
}
873
}
874
return index;
875
}
876
877
878
/*********************************************************************
879
*
880
* EDIT_ConfinePoint
881
*
882
* adjusts the point to be within the formatting rectangle
883
* (so CharFromPos returns the nearest _visible_ character)
884
*
885
*/
886
static void EDIT_ConfinePoint(const EDITSTATE *es, LPINT x, LPINT y)
887
{
888
*x = min(max(*x, es->format_rect.left), es->format_rect.right - 1);
889
*y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1);
890
}
891
892
893
/*********************************************************************
894
*
895
* EM_LINEFROMCHAR
896
*
897
*/
898
static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index)
899
{
900
INT line;
901
LINEDEF *line_def;
902
903
if (!(es->style & ES_MULTILINE))
904
return 0;
905
if (index > (INT)get_text_length(es))
906
return es->line_count - 1;
907
if (index == -1)
908
index = min(es->selection_start, es->selection_end);
909
910
line = 0;
911
line_def = es->first_line_def;
912
index -= line_def->length;
913
while ((index >= 0) && line_def->next) {
914
line++;
915
line_def = line_def->next;
916
index -= line_def->length;
917
}
918
return line;
919
}
920
921
922
/*********************************************************************
923
*
924
* EM_LINEINDEX
925
*
926
*/
927
static INT EDIT_EM_LineIndex(const EDITSTATE *es, INT line)
928
{
929
INT line_index;
930
const LINEDEF *line_def;
931
932
if (!(es->style & ES_MULTILINE))
933
return 0;
934
if (line >= es->line_count)
935
return -1;
936
937
line_index = 0;
938
line_def = es->first_line_def;
939
if (line == -1) {
940
INT index = es->selection_end - line_def->length;
941
while ((index >= 0) && line_def->next) {
942
line_index += line_def->length;
943
line_def = line_def->next;
944
index -= line_def->length;
945
}
946
} else {
947
while (line > 0) {
948
line_index += line_def->length;
949
line_def = line_def->next;
950
line--;
951
}
952
}
953
return line_index;
954
}
955
956
957
/*********************************************************************
958
*
959
* EM_LINELENGTH
960
*
961
*/
962
static INT EDIT_EM_LineLength(EDITSTATE *es, INT index)
963
{
964
LINEDEF *line_def;
965
966
if (!(es->style & ES_MULTILINE))
967
return get_text_length(es);
968
969
if (index == -1) {
970
/* get the number of remaining non-selected chars of selected lines */
971
INT32 l; /* line number */
972
INT32 li; /* index of first char in line */
973
INT32 count;
974
l = EDIT_EM_LineFromChar(es, es->selection_start);
975
/* # chars before start of selection area */
976
count = es->selection_start - EDIT_EM_LineIndex(es, l);
977
l = EDIT_EM_LineFromChar(es, es->selection_end);
978
/* # chars after end of selection */
979
li = EDIT_EM_LineIndex(es, l);
980
count += li + EDIT_EM_LineLength(es, li) - es->selection_end;
981
return count;
982
}
983
line_def = es->first_line_def;
984
index -= line_def->length;
985
while ((index >= 0) && line_def->next) {
986
line_def = line_def->next;
987
index -= line_def->length;
988
}
989
return line_def->net_length;
990
}
991
992
993
/*********************************************************************
994
*
995
* EM_POSFROMCHAR
996
*
997
*/
998
static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap)
999
{
1000
INT len = get_text_length(es);
1001
INT l;
1002
INT li;
1003
INT x = 0;
1004
INT y = 0;
1005
INT w;
1006
INT lw;
1007
LINEDEF *line_def;
1008
1009
index = min(index, len);
1010
if (es->style & ES_MULTILINE) {
1011
l = EDIT_EM_LineFromChar(es, index);
1012
EDIT_UpdateUniscribeData(es, NULL, l);
1013
1014
y = (l - es->y_offset) * es->line_height;
1015
li = EDIT_EM_LineIndex(es, l);
1016
if (after_wrap && (li == index) && l) {
1017
INT l2 = l - 1;
1018
line_def = es->first_line_def;
1019
while (l2) {
1020
line_def = line_def->next;
1021
l2--;
1022
}
1023
if (line_def->ending == END_WRAP) {
1024
l--;
1025
y -= es->line_height;
1026
li = EDIT_EM_LineIndex(es, l);
1027
}
1028
}
1029
1030
line_def = es->first_line_def;
1031
while (line_def->index != li)
1032
line_def = line_def->next;
1033
1034
lw = line_def->width;
1035
w = es->format_rect.right - es->format_rect.left;
1036
if (line_def->ssa)
1037
ScriptStringCPtoX(line_def->ssa, (index - 1) - li, TRUE, &x);
1038
x -= es->x_offset;
1039
1040
if (es->style & ES_RIGHT)
1041
x = w - (lw - x);
1042
else if (es->style & ES_CENTER)
1043
x += (w - lw) / 2;
1044
} else {
1045
INT xoff = 0;
1046
INT xi = 0;
1047
EDIT_UpdateUniscribeData(es, NULL, 0);
1048
if (es->x_offset)
1049
{
1050
if (es->ssa)
1051
{
1052
if (es->x_offset >= get_text_length(es))
1053
{
1054
int leftover = es->x_offset - get_text_length(es);
1055
if (es->ssa)
1056
{
1057
const SIZE *size;
1058
size = ScriptString_pSize(es->ssa);
1059
xoff = size->cx;
1060
}
1061
else
1062
xoff = 0;
1063
xoff += es->char_width * leftover;
1064
}
1065
else
1066
ScriptStringCPtoX(es->ssa, es->x_offset, FALSE, &xoff);
1067
}
1068
else
1069
xoff = 0;
1070
}
1071
if (index)
1072
{
1073
if (index >= get_text_length(es))
1074
{
1075
if (es->ssa)
1076
{
1077
const SIZE *size;
1078
size = ScriptString_pSize(es->ssa);
1079
xi = size->cx;
1080
}
1081
else
1082
xi = 0;
1083
}
1084
else if (es->ssa)
1085
ScriptStringCPtoX(es->ssa, index, FALSE, &xi);
1086
else
1087
xi = 0;
1088
}
1089
x = xi - xoff;
1090
1091
if (index >= es->x_offset) {
1092
if (!es->x_offset && (es->style & (ES_RIGHT | ES_CENTER)))
1093
{
1094
w = es->format_rect.right - es->format_rect.left;
1095
if (w > es->text_width)
1096
{
1097
if (es->style & ES_RIGHT)
1098
x += w - es->text_width;
1099
else if (es->style & ES_CENTER)
1100
x += (w - es->text_width) / 2;
1101
}
1102
}
1103
}
1104
y = 0;
1105
}
1106
x += es->format_rect.left;
1107
y += es->format_rect.top;
1108
return MAKELONG((INT16)x, (INT16)y);
1109
}
1110
1111
1112
/*********************************************************************
1113
*
1114
* EDIT_GetLineRect
1115
*
1116
* Calculates the bounding rectangle for a line from a starting
1117
* column to an ending column.
1118
*
1119
*/
1120
static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
1121
{
1122
SCRIPT_STRING_ANALYSIS ssa;
1123
INT line_index = 0;
1124
INT pt1, pt2, pt3;
1125
1126
if (es->style & ES_MULTILINE)
1127
{
1128
const LINEDEF *line_def = NULL;
1129
rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1130
if (line >= es->line_count)
1131
return;
1132
1133
line_def = es->first_line_def;
1134
if (line == -1) {
1135
INT index = es->selection_end - line_def->length;
1136
while ((index >= 0) && line_def->next) {
1137
line_index += line_def->length;
1138
line_def = line_def->next;
1139
index -= line_def->length;
1140
}
1141
} else {
1142
while (line > 0) {
1143
line_index += line_def->length;
1144
line_def = line_def->next;
1145
line--;
1146
}
1147
}
1148
ssa = line_def->ssa;
1149
}
1150
else
1151
{
1152
line_index = 0;
1153
rc->top = es->format_rect.top;
1154
ssa = es->ssa;
1155
}
1156
1157
rc->bottom = rc->top + es->line_height;
1158
pt1 = (scol == 0) ? es->format_rect.left : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + scol, TRUE));
1159
pt2 = (ecol == -1) ? es->format_rect.right : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + ecol, TRUE));
1160
if (ssa)
1161
{
1162
ScriptStringCPtoX(ssa, scol, FALSE, &pt3);
1163
pt3+=es->format_rect.left;
1164
}
1165
else pt3 = pt1;
1166
rc->right = max(max(pt1 , pt2),pt3);
1167
rc->left = min(min(pt1, pt2),pt3);
1168
}
1169
1170
1171
static inline void text_buffer_changed(EDITSTATE *es)
1172
{
1173
es->text_length = (UINT)-1;
1174
1175
Free(es->logAttr);
1176
es->logAttr = NULL;
1177
EDIT_InvalidateUniscribeData(es);
1178
}
1179
1180
/*********************************************************************
1181
* EDIT_LockBuffer
1182
*
1183
*/
1184
static void EDIT_LockBuffer(EDITSTATE *es)
1185
{
1186
if (!es->text)
1187
{
1188
if (!es->hloc32W)
1189
return;
1190
1191
es->text = LocalLock(es->hloc32W);
1192
}
1193
1194
es->lock_count++;
1195
}
1196
1197
1198
/*********************************************************************
1199
*
1200
* EDIT_UnlockBuffer
1201
*
1202
*/
1203
static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force)
1204
{
1205
/* Edit window might be already destroyed */
1206
if (!IsWindow(es->hwndSelf))
1207
{
1208
WARN("edit hwnd %p already destroyed\n", es->hwndSelf);
1209
return;
1210
}
1211
1212
if (!es->lock_count)
1213
{
1214
ERR("lock_count == 0 ... please report\n");
1215
return;
1216
}
1217
1218
if (!es->text)
1219
{
1220
ERR("es->text == 0 ... please report\n");
1221
return;
1222
}
1223
1224
if (force || (es->lock_count == 1))
1225
{
1226
if (es->hloc32W)
1227
{
1228
LocalUnlock(es->hloc32W);
1229
es->text = NULL;
1230
}
1231
else
1232
{
1233
ERR("no buffer ... please report\n");
1234
return;
1235
}
1236
1237
}
1238
1239
es->lock_count--;
1240
}
1241
1242
1243
/*********************************************************************
1244
*
1245
* EDIT_MakeFit
1246
*
1247
* Try to fit size + 1 characters in the buffer.
1248
*/
1249
static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size)
1250
{
1251
HLOCAL hNew32W;
1252
1253
if (size <= es->buffer_size)
1254
return TRUE;
1255
1256
TRACE("trying to ReAlloc to %d+1 characters\n", size);
1257
1258
/* Force edit to unlock its buffer. es->text now NULL */
1259
EDIT_UnlockBuffer(es, TRUE);
1260
1261
if (es->hloc32W) {
1262
UINT alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
1263
if ((hNew32W = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT))) {
1264
TRACE("Old 32 bit handle %p, new handle %p\n", es->hloc32W, hNew32W);
1265
es->hloc32W = hNew32W;
1266
es->buffer_size = LocalSize(hNew32W)/sizeof(WCHAR) - 1;
1267
}
1268
}
1269
1270
EDIT_LockBuffer(es);
1271
1272
if (es->buffer_size < size) {
1273
WARN("FAILED ! We now have %d+1\n", es->buffer_size);
1274
notify_parent(es, EN_ERRSPACE);
1275
return FALSE;
1276
} else {
1277
TRACE("We now have %d+1\n", es->buffer_size);
1278
return TRUE;
1279
}
1280
}
1281
1282
1283
/*********************************************************************
1284
*
1285
* EDIT_MakeUndoFit
1286
*
1287
* Try to fit size + 1 bytes in the undo buffer.
1288
*
1289
*/
1290
static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size)
1291
{
1292
UINT alloc_size;
1293
WCHAR *new_undo_text;
1294
1295
if (size <= es->undo_buffer_size)
1296
return TRUE;
1297
1298
TRACE("trying to ReAlloc to %d+1\n", size);
1299
1300
alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
1301
if ((new_undo_text = ReAlloc(es->undo_text, alloc_size))) {
1302
memset(new_undo_text + es->undo_buffer_size, 0, alloc_size - es->undo_buffer_size * sizeof(WCHAR));
1303
es->undo_text = new_undo_text;
1304
es->undo_buffer_size = alloc_size/sizeof(WCHAR) - 1;
1305
return TRUE;
1306
}
1307
else
1308
{
1309
WARN("FAILED ! We now have %d+1\n", es->undo_buffer_size);
1310
return FALSE;
1311
}
1312
}
1313
1314
1315
/*********************************************************************
1316
*
1317
* EDIT_UpdateTextRegion
1318
*
1319
*/
1320
static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase)
1321
{
1322
if (es->flags & EF_UPDATE) {
1323
es->flags &= ~EF_UPDATE;
1324
if (!notify_parent(es, EN_UPDATE)) return;
1325
}
1326
InvalidateRgn(es->hwndSelf, hrgn, bErase);
1327
}
1328
1329
1330
/*********************************************************************
1331
*
1332
* EDIT_UpdateText
1333
*
1334
*/
1335
static void EDIT_UpdateText(EDITSTATE *es, const RECT *rc, BOOL bErase)
1336
{
1337
if (es->flags & EF_UPDATE) {
1338
es->flags &= ~EF_UPDATE;
1339
if (!notify_parent(es, EN_UPDATE)) return;
1340
}
1341
InvalidateRect(es->hwndSelf, rc, bErase);
1342
}
1343
1344
/*********************************************************************
1345
*
1346
* EDIT_SL_InvalidateText
1347
*
1348
* Called from EDIT_InvalidateText().
1349
* Does the job for single-line controls only.
1350
*
1351
*/
1352
static void EDIT_SL_InvalidateText(EDITSTATE *es, INT start, INT end)
1353
{
1354
RECT line_rect;
1355
RECT rc;
1356
1357
EDIT_GetLineRect(es, 0, start, end, &line_rect);
1358
if (IntersectRect(&rc, &line_rect, &es->format_rect))
1359
EDIT_UpdateText(es, &rc, TRUE);
1360
}
1361
1362
/*********************************************************************
1363
*
1364
* EDIT_ML_InvalidateText
1365
*
1366
* Called from EDIT_InvalidateText().
1367
* Does the job for multi-line controls only.
1368
*
1369
*/
1370
static void EDIT_ML_InvalidateText(EDITSTATE *es, INT start, INT end)
1371
{
1372
INT vlc = get_vertical_line_count(es);
1373
INT sl = EDIT_EM_LineFromChar(es, start);
1374
INT el = EDIT_EM_LineFromChar(es, end);
1375
INT sc;
1376
INT ec;
1377
RECT rc1;
1378
RECT rcWnd;
1379
RECT rcLine;
1380
RECT rcUpdate;
1381
INT l;
1382
1383
if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1384
return;
1385
1386
sc = start - EDIT_EM_LineIndex(es, sl);
1387
ec = end - EDIT_EM_LineIndex(es, el);
1388
if (sl < es->y_offset) {
1389
sl = es->y_offset;
1390
sc = 0;
1391
}
1392
if (el > es->y_offset + vlc) {
1393
el = es->y_offset + vlc;
1394
ec = EDIT_EM_LineLength(es, EDIT_EM_LineIndex(es, el));
1395
}
1396
GetClientRect(es->hwndSelf, &rc1);
1397
IntersectRect(&rcWnd, &rc1, &es->format_rect);
1398
if (sl == el) {
1399
EDIT_GetLineRect(es, sl, sc, ec, &rcLine);
1400
if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1401
EDIT_UpdateText(es, &rcUpdate, TRUE);
1402
} else {
1403
EDIT_GetLineRect(es, sl, sc,
1404
EDIT_EM_LineLength(es,
1405
EDIT_EM_LineIndex(es, sl)),
1406
&rcLine);
1407
if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1408
EDIT_UpdateText(es, &rcUpdate, TRUE);
1409
for (l = sl + 1 ; l < el ; l++) {
1410
EDIT_GetLineRect(es, l, 0,
1411
EDIT_EM_LineLength(es,
1412
EDIT_EM_LineIndex(es, l)),
1413
&rcLine);
1414
if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1415
EDIT_UpdateText(es, &rcUpdate, TRUE);
1416
}
1417
EDIT_GetLineRect(es, el, 0, ec, &rcLine);
1418
if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
1419
EDIT_UpdateText(es, &rcUpdate, TRUE);
1420
}
1421
}
1422
1423
1424
/*********************************************************************
1425
*
1426
* EDIT_InvalidateText
1427
*
1428
* Invalidate the text from offset start up to, but not including,
1429
* offset end. Useful for (re)painting the selection.
1430
* Regions outside the linewidth are not invalidated.
1431
* end == -1 means end == TextLength.
1432
* start and end need not be ordered.
1433
*
1434
*/
1435
static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end)
1436
{
1437
if (end == start)
1438
return;
1439
1440
if (end == -1)
1441
end = get_text_length(es);
1442
1443
if (end < start) {
1444
INT tmp = start;
1445
start = end;
1446
end = tmp;
1447
}
1448
1449
if (es->style & ES_MULTILINE)
1450
EDIT_ML_InvalidateText(es, start, end);
1451
else
1452
EDIT_SL_InvalidateText(es, start, end);
1453
}
1454
1455
1456
/*********************************************************************
1457
*
1458
* EDIT_EM_SetSel
1459
*
1460
* note: unlike the specs say: the order of start and end
1461
* _is_ preserved in Windows. (i.e. start can be > end)
1462
* In other words: this handler is OK
1463
*
1464
*/
1465
static BOOL EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
1466
{
1467
UINT old_start = es->selection_start;
1468
UINT old_end = es->selection_end;
1469
UINT len = get_text_length(es);
1470
1471
if (start == old_start && end == old_end)
1472
return FALSE;
1473
1474
if (start == (UINT)-1) {
1475
start = es->selection_end;
1476
end = es->selection_end;
1477
} else {
1478
start = min(start, len);
1479
end = min(end, len);
1480
}
1481
es->selection_start = start;
1482
es->selection_end = end;
1483
if (after_wrap)
1484
es->flags |= EF_AFTER_WRAP;
1485
else
1486
es->flags &= ~EF_AFTER_WRAP;
1487
/* Compute the necessary invalidation region. */
1488
/* Note that we don't need to invalidate regions which have
1489
* "never" been selected, or those which are "still" selected.
1490
* In fact, every time we hit a selection boundary, we can
1491
* *toggle* whether we need to invalidate. Thus we can optimize by
1492
* *sorting* the interval endpoints. Let's assume that we sort them
1493
* in this order:
1494
* start <= end <= old_start <= old_end
1495
* Knuth 5.3.1 (p 183) assures us that this can be done optimally
1496
* in 5 comparisons; i.e. it is impossible to do better than the
1497
* following: */
1498
ORDER_UINT(end, old_end);
1499
ORDER_UINT(start, old_start);
1500
ORDER_UINT(old_start, old_end);
1501
ORDER_UINT(start, end);
1502
/* Note that at this point 'end' and 'old_start' are not in order, but
1503
* start is definitely the min. and old_end is definitely the max. */
1504
if (end != old_start)
1505
{
1506
/*
1507
* One can also do
1508
* ORDER_UINT32(end, old_start);
1509
* EDIT_InvalidateText(es, start, end);
1510
* EDIT_InvalidateText(es, old_start, old_end);
1511
* in place of the following if statement.
1512
* (That would complete the optimal five-comparison four-element sort.)
1513
*/
1514
if (old_start > end )
1515
{
1516
EDIT_InvalidateText(es, start, end);
1517
EDIT_InvalidateText(es, old_start, old_end);
1518
}
1519
else
1520
{
1521
EDIT_InvalidateText(es, start, old_start);
1522
EDIT_InvalidateText(es, end, old_end);
1523
}
1524
}
1525
else EDIT_InvalidateText(es, start, old_end);
1526
1527
return TRUE;
1528
}
1529
1530
1531
/*********************************************************************
1532
*
1533
* EDIT_UpdateScrollInfo
1534
*
1535
*/
1536
static void EDIT_UpdateScrollInfo(EDITSTATE *es)
1537
{
1538
if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
1539
{
1540
SCROLLINFO si;
1541
si.cbSize = sizeof(SCROLLINFO);
1542
si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
1543
si.nMin = 0;
1544
si.nMax = es->line_count - 1;
1545
si.nPage = es->line_height ? (es->format_rect.bottom - es->format_rect.top) / es->line_height : 0;
1546
si.nPos = es->y_offset;
1547
TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1548
si.nMin, si.nMax, si.nPage, si.nPos);
1549
SetScrollInfo(es->hwndSelf, SB_VERT, &si, TRUE);
1550
}
1551
1552
if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
1553
{
1554
SCROLLINFO si;
1555
si.cbSize = sizeof(SCROLLINFO);
1556
si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
1557
si.nMin = 0;
1558
si.nMax = es->text_width - 1;
1559
si.nPage = es->format_rect.right - es->format_rect.left;
1560
si.nPos = es->x_offset;
1561
TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
1562
si.nMin, si.nMax, si.nPage, si.nPos);
1563
SetScrollInfo(es->hwndSelf, SB_HORZ, &si, TRUE);
1564
}
1565
}
1566
1567
1568
/*********************************************************************
1569
*
1570
* EDIT_EM_LineScroll_internal
1571
*
1572
* Version of EDIT_EM_LineScroll for internal use.
1573
* It doesn't refuse if ES_MULTILINE is set and assumes that
1574
* dx is in pixels, dy - in lines.
1575
*
1576
*/
1577
static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy)
1578
{
1579
INT nyoff;
1580
INT x_offset_in_pixels;
1581
INT lines_per_page;
1582
1583
if (!es->line_height || !es->char_width)
1584
return TRUE;
1585
1586
lines_per_page = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1587
1588
if (es->style & ES_MULTILINE)
1589
{
1590
x_offset_in_pixels = es->x_offset;
1591
}
1592
else
1593
{
1594
dy = 0;
1595
x_offset_in_pixels = (short)LOWORD(EDIT_EM_PosFromChar(es, es->x_offset, FALSE));
1596
}
1597
1598
if (-dx > x_offset_in_pixels)
1599
dx = -x_offset_in_pixels;
1600
if (dx > es->text_width - x_offset_in_pixels)
1601
dx = es->text_width - x_offset_in_pixels;
1602
nyoff = max(0, es->y_offset + dy);
1603
if (nyoff >= es->line_count - lines_per_page)
1604
nyoff = max(0, es->line_count - lines_per_page);
1605
dy = (es->y_offset - nyoff) * es->line_height;
1606
if (dx || dy) {
1607
RECT rc1;
1608
RECT rc;
1609
1610
es->y_offset = nyoff;
1611
if(es->style & ES_MULTILINE)
1612
es->x_offset += dx;
1613
else
1614
es->x_offset += dx / es->char_width;
1615
1616
GetClientRect(es->hwndSelf, &rc1);
1617
IntersectRect(&rc, &rc1, &es->format_rect);
1618
ScrollWindowEx(es->hwndSelf, -dx, dy,
1619
NULL, &rc, NULL, NULL, SW_INVALIDATE);
1620
/* force scroll info update */
1621
EDIT_UpdateScrollInfo(es);
1622
}
1623
if (dx && !(es->flags & EF_HSCROLL_TRACK))
1624
notify_parent(es, EN_HSCROLL);
1625
if (dy && !(es->flags & EF_VSCROLL_TRACK))
1626
notify_parent(es, EN_VSCROLL);
1627
return TRUE;
1628
}
1629
1630
/*********************************************************************
1631
*
1632
* EM_LINESCROLL
1633
*
1634
* NOTE: dx is in average character widths, dy - in lines;
1635
*
1636
*/
1637
static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy)
1638
{
1639
if (!(es->style & ES_MULTILINE))
1640
return FALSE;
1641
1642
dx *= es->char_width;
1643
return EDIT_EM_LineScroll_internal(es, dx, dy);
1644
}
1645
1646
1647
/*********************************************************************
1648
*
1649
* EM_SCROLL
1650
*
1651
*/
1652
static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
1653
{
1654
INT dy;
1655
1656
if (!(es->style & ES_MULTILINE))
1657
return (LRESULT)FALSE;
1658
1659
dy = 0;
1660
1661
switch (action) {
1662
case SB_LINEUP:
1663
if (es->y_offset)
1664
dy = -1;
1665
break;
1666
case SB_LINEDOWN:
1667
if (es->y_offset < es->line_count - 1)
1668
dy = 1;
1669
break;
1670
case SB_PAGEUP:
1671
if (es->y_offset)
1672
dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
1673
break;
1674
case SB_PAGEDOWN:
1675
if (es->y_offset < es->line_count - 1)
1676
dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1677
break;
1678
default:
1679
return (LRESULT)FALSE;
1680
}
1681
if (dy) {
1682
INT vlc = get_vertical_line_count(es);
1683
/* check if we are going to move too far */
1684
if(es->y_offset + dy > es->line_count - vlc)
1685
dy = max(es->line_count - vlc, 0) - es->y_offset;
1686
1687
/* Notification is done in EDIT_EM_LineScroll */
1688
if(dy) {
1689
EDIT_EM_LineScroll(es, 0, dy);
1690
return MAKELONG(dy, TRUE);
1691
}
1692
1693
}
1694
return (LRESULT)FALSE;
1695
}
1696
1697
1698
static void EDIT_UpdateImmCompositionWindow(EDITSTATE *es, UINT x, UINT y)
1699
{
1700
COMPOSITIONFORM form =
1701
{
1702
.dwStyle = CFS_RECT,
1703
.ptCurrentPos = {.x = x, .y = y},
1704
.rcArea = es->format_rect,
1705
};
1706
HIMC himc = ImmGetContext(es->hwndSelf);
1707
ImmSetCompositionWindow(himc, &form);
1708
ImmReleaseContext(es->hwndSelf, himc);
1709
}
1710
1711
1712
/*********************************************************************
1713
*
1714
* EDIT_SetCaretPos
1715
*
1716
*/
1717
static void EDIT_SetCaretPos(EDITSTATE *es, INT pos,
1718
BOOL after_wrap)
1719
{
1720
LRESULT res;
1721
1722
if (es->flags & EF_FOCUSED)
1723
{
1724
res = EDIT_EM_PosFromChar(es, pos, after_wrap);
1725
TRACE("%d - %dx%d\n", pos, (short)LOWORD(res), (short)HIWORD(res));
1726
SetCaretPos((short)LOWORD(res), (short)HIWORD(res));
1727
EDIT_UpdateImmCompositionWindow(es, (short)LOWORD(res), (short)HIWORD(res));
1728
}
1729
}
1730
1731
1732
/*********************************************************************
1733
*
1734
* EM_SCROLLCARET
1735
*
1736
*/
1737
static void EDIT_EM_ScrollCaret(EDITSTATE *es)
1738
{
1739
if (es->style & ES_MULTILINE) {
1740
INT l;
1741
INT vlc;
1742
INT ww;
1743
INT cw = es->char_width;
1744
INT x;
1745
INT dy = 0;
1746
INT dx = 0;
1747
1748
l = EDIT_EM_LineFromChar(es, es->selection_end);
1749
x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP));
1750
vlc = get_vertical_line_count(es);
1751
if (l >= es->y_offset + vlc)
1752
dy = l - vlc + 1 - es->y_offset;
1753
if (l < es->y_offset)
1754
dy = l - es->y_offset;
1755
ww = es->format_rect.right - es->format_rect.left;
1756
if (x < es->format_rect.left)
1757
dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
1758
if (x > es->format_rect.right)
1759
dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
1760
if (dy || dx || (es->y_offset && (es->line_count - es->y_offset < vlc)))
1761
{
1762
/* check if we are going to move too far */
1763
if(es->x_offset + dx + ww > es->text_width)
1764
dx = es->text_width - ww - es->x_offset;
1765
if(dx || dy || (es->y_offset && (es->line_count - es->y_offset < vlc)))
1766
EDIT_EM_LineScroll_internal(es, dx, dy);
1767
}
1768
} else {
1769
INT x;
1770
INT goal;
1771
INT format_width;
1772
1773
x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
1774
format_width = es->format_rect.right - es->format_rect.left;
1775
if (x < es->format_rect.left) {
1776
goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
1777
do {
1778
es->x_offset--;
1779
x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
1780
} while ((x < goal) && es->x_offset);
1781
/* FIXME: use ScrollWindow() somehow to improve performance */
1782
EDIT_UpdateText(es, NULL, TRUE);
1783
} else if (x > es->format_rect.right) {
1784
INT x_last;
1785
INT len = get_text_length(es);
1786
goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
1787
do {
1788
es->x_offset++;
1789
x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
1790
x_last = (short)LOWORD(EDIT_EM_PosFromChar(es, len, FALSE));
1791
} while ((x > goal) && (x_last > es->format_rect.right));
1792
/* FIXME: use ScrollWindow() somehow to improve performance */
1793
EDIT_UpdateText(es, NULL, TRUE);
1794
}
1795
}
1796
1797
EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
1798
}
1799
1800
1801
/*********************************************************************
1802
*
1803
* EDIT_MoveBackward
1804
*
1805
*/
1806
static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend)
1807
{
1808
INT e = es->selection_end;
1809
1810
if (e) {
1811
e--;
1812
if ((es->style & ES_MULTILINE) && e &&
1813
(es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1814
e--;
1815
if (e && (es->text[e - 1] == '\r'))
1816
e--;
1817
}
1818
}
1819
EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1820
EDIT_EM_ScrollCaret(es);
1821
}
1822
1823
1824
/*********************************************************************
1825
*
1826
* EDIT_MoveDown_ML
1827
*
1828
* Only for multi line controls
1829
* Move the caret one line down, on a column with the nearest
1830
* x coordinate on the screen (might be a different column).
1831
*
1832
*/
1833
static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend)
1834
{
1835
INT s = es->selection_start;
1836
INT e = es->selection_end;
1837
BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1838
LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1839
INT x = (short)LOWORD(pos);
1840
INT y = (short)HIWORD(pos);
1841
1842
e = EDIT_CharFromPos(es, x, y + es->line_height, &after_wrap);
1843
if (!extend)
1844
s = e;
1845
EDIT_EM_SetSel(es, s, e, after_wrap);
1846
EDIT_EM_ScrollCaret(es);
1847
}
1848
1849
1850
/*********************************************************************
1851
*
1852
* EDIT_MoveEnd
1853
*
1854
*/
1855
static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend, BOOL ctrl)
1856
{
1857
BOOL after_wrap = FALSE;
1858
INT e;
1859
1860
/* Pass a high value in x to make sure of receiving the end of the line */
1861
if (!ctrl && (es->style & ES_MULTILINE))
1862
e = EDIT_CharFromPos(es, 0x3fffffff,
1863
HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1864
else
1865
e = get_text_length(es);
1866
EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, after_wrap);
1867
EDIT_EM_ScrollCaret(es);
1868
}
1869
1870
1871
/*********************************************************************
1872
*
1873
* EDIT_MoveForward
1874
*
1875
*/
1876
static void EDIT_MoveForward(EDITSTATE *es, BOOL extend)
1877
{
1878
INT e = es->selection_end;
1879
1880
if (es->text[e]) {
1881
e++;
1882
if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1883
if (es->text[e] == '\n')
1884
e++;
1885
else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1886
e += 2;
1887
}
1888
}
1889
EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1890
EDIT_EM_ScrollCaret(es);
1891
}
1892
1893
1894
/*********************************************************************
1895
*
1896
* EDIT_MoveHome
1897
*
1898
* Home key: move to beginning of line.
1899
*
1900
*/
1901
static void EDIT_MoveHome(EDITSTATE *es, BOOL extend, BOOL ctrl)
1902
{
1903
INT e;
1904
1905
/* Pass the x_offset in x to make sure of receiving the first position of the line */
1906
if (!ctrl && (es->style & ES_MULTILINE))
1907
e = EDIT_CharFromPos(es, -es->x_offset,
1908
HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1909
else
1910
e = 0;
1911
EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1912
EDIT_EM_ScrollCaret(es);
1913
}
1914
1915
1916
/*********************************************************************
1917
*
1918
* EDIT_MovePageDown_ML
1919
*
1920
* Only for multi line controls
1921
* Move the caret one page down, on a column with the nearest
1922
* x coordinate on the screen (might be a different column).
1923
*
1924
*/
1925
static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend)
1926
{
1927
INT s = es->selection_start;
1928
INT e = es->selection_end;
1929
BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1930
LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1931
INT x = (short)LOWORD(pos);
1932
INT y = (short)HIWORD(pos);
1933
1934
e = EDIT_CharFromPos(es, x,
1935
y + (es->format_rect.bottom - es->format_rect.top),
1936
&after_wrap);
1937
if (!extend)
1938
s = e;
1939
EDIT_EM_SetSel(es, s, e, after_wrap);
1940
EDIT_EM_ScrollCaret(es);
1941
}
1942
1943
1944
/*********************************************************************
1945
*
1946
* EDIT_MovePageUp_ML
1947
*
1948
* Only for multi line controls
1949
* Move the caret one page up, on a column with the nearest
1950
* x coordinate on the screen (might be a different column).
1951
*
1952
*/
1953
static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend)
1954
{
1955
INT s = es->selection_start;
1956
INT e = es->selection_end;
1957
BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1958
LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1959
INT x = (short)LOWORD(pos);
1960
INT y = (short)HIWORD(pos);
1961
1962
e = EDIT_CharFromPos(es, x,
1963
y - (es->format_rect.bottom - es->format_rect.top),
1964
&after_wrap);
1965
if (!extend)
1966
s = e;
1967
EDIT_EM_SetSel(es, s, e, after_wrap);
1968
EDIT_EM_ScrollCaret(es);
1969
}
1970
1971
1972
/*********************************************************************
1973
*
1974
* EDIT_MoveUp_ML
1975
*
1976
* Only for multi line controls
1977
* Move the caret one line up, on a column with the nearest
1978
* x coordinate on the screen (might be a different column).
1979
*
1980
*/
1981
static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend)
1982
{
1983
INT s = es->selection_start;
1984
INT e = es->selection_end;
1985
BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
1986
LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
1987
INT x = (short)LOWORD(pos);
1988
INT y = (short)HIWORD(pos);
1989
1990
e = EDIT_CharFromPos(es, x, y - es->line_height, &after_wrap);
1991
if (!extend)
1992
s = e;
1993
EDIT_EM_SetSel(es, s, e, after_wrap);
1994
EDIT_EM_ScrollCaret(es);
1995
}
1996
1997
1998
/*********************************************************************
1999
*
2000
* EDIT_MoveWordBackward
2001
*
2002
*/
2003
static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend)
2004
{
2005
INT s = es->selection_start;
2006
INT e = es->selection_end;
2007
INT l;
2008
INT ll;
2009
INT li;
2010
2011
l = EDIT_EM_LineFromChar(es, e);
2012
ll = EDIT_EM_LineLength(es, e);
2013
li = EDIT_EM_LineIndex(es, l);
2014
if (e - li == 0) {
2015
if (l) {
2016
li = EDIT_EM_LineIndex(es, l - 1);
2017
e = li + EDIT_EM_LineLength(es, li);
2018
}
2019
} else {
2020
e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT);
2021
}
2022
if (!extend)
2023
s = e;
2024
EDIT_EM_SetSel(es, s, e, FALSE);
2025
EDIT_EM_ScrollCaret(es);
2026
}
2027
2028
2029
/*********************************************************************
2030
*
2031
* EDIT_MoveWordForward
2032
*
2033
*/
2034
static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend)
2035
{
2036
INT s = es->selection_start;
2037
INT e = es->selection_end;
2038
INT l;
2039
INT ll;
2040
INT li;
2041
2042
l = EDIT_EM_LineFromChar(es, e);
2043
ll = EDIT_EM_LineLength(es, e);
2044
li = EDIT_EM_LineIndex(es, l);
2045
if (e - li == ll) {
2046
if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
2047
e = EDIT_EM_LineIndex(es, l + 1);
2048
} else {
2049
e = li + EDIT_CallWordBreakProc(es,
2050
li, e - li + 1, ll, WB_RIGHT);
2051
}
2052
if (!extend)
2053
s = e;
2054
EDIT_EM_SetSel(es, s, e, FALSE);
2055
EDIT_EM_ScrollCaret(es);
2056
}
2057
2058
2059
/*********************************************************************
2060
*
2061
* EDIT_PaintText
2062
*
2063
*/
2064
static INT EDIT_PaintText(EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
2065
{
2066
COLORREF BkColor;
2067
COLORREF TextColor;
2068
INT ret;
2069
INT li;
2070
INT BkMode;
2071
SIZE size;
2072
2073
if (!count)
2074
return 0;
2075
BkMode = GetBkMode(dc);
2076
BkColor = GetBkColor(dc);
2077
TextColor = GetTextColor(dc);
2078
if (rev) {
2079
SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
2080
SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
2081
SetBkMode(dc, OPAQUE);
2082
}
2083
li = EDIT_EM_LineIndex(es, line);
2084
if (es->style & ES_MULTILINE) {
2085
ret = (INT)LOWORD(TabbedTextOutW(dc, x, y, es->text + li + col, count,
2086
es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
2087
} else {
2088
TextOutW(dc, x, y, es->text + li + col, count);
2089
GetTextExtentPoint32W(dc, es->text + li + col, count, &size);
2090
ret = size.cx;
2091
}
2092
if (rev) {
2093
SetBkColor(dc, BkColor);
2094
SetTextColor(dc, TextColor);
2095
SetBkMode(dc, BkMode);
2096
}
2097
return ret;
2098
}
2099
2100
2101
/*********************************************************************
2102
*
2103
* EDIT_PaintLine
2104
*
2105
*/
2106
static void EDIT_PaintLine(EDITSTATE *es, HDC dc, INT line, BOOL rev)
2107
{
2108
INT s = 0;
2109
INT e = 0;
2110
INT li = 0;
2111
INT ll = 0;
2112
INT x;
2113
INT y;
2114
LRESULT pos;
2115
SCRIPT_STRING_ANALYSIS ssa;
2116
2117
if (es->style & ES_MULTILINE) {
2118
INT vlc = get_vertical_line_count(es);
2119
2120
if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
2121
return;
2122
} else if (line)
2123
return;
2124
2125
TRACE("line=%d\n", line);
2126
2127
ssa = EDIT_UpdateUniscribeData(es, dc, line);
2128
pos = EDIT_EM_PosFromChar(es, EDIT_EM_LineIndex(es, line), FALSE);
2129
x = (short)LOWORD(pos);
2130
y = (short)HIWORD(pos);
2131
2132
if (es->style & ES_MULTILINE)
2133
{
2134
int line_idx = line;
2135
x = -es->x_offset;
2136
if (es->style & ES_RIGHT || es->style & ES_CENTER)
2137
{
2138
LINEDEF *line_def = es->first_line_def;
2139
int w, lw;
2140
2141
while (line_def && line_idx)
2142
{
2143
line_def = line_def->next;
2144
line_idx--;
2145
}
2146
w = es->format_rect.right - es->format_rect.left;
2147
lw = line_def->width;
2148
2149
if (es->style & ES_RIGHT)
2150
x = w - (lw - x);
2151
else if (es->style & ES_CENTER)
2152
x += (w - lw) / 2;
2153
}
2154
x += es->format_rect.left;
2155
}
2156
2157
if (rev)
2158
{
2159
li = EDIT_EM_LineIndex(es, line);
2160
ll = EDIT_EM_LineLength(es, li);
2161
s = min(es->selection_start, es->selection_end);
2162
e = max(es->selection_start, es->selection_end);
2163
s = min(li + ll, max(li, s));
2164
e = min(li + ll, max(li, e));
2165
}
2166
2167
if (ssa)
2168
ScriptStringOut(ssa, x, y, 0, &es->format_rect, s - li, e - li, FALSE);
2169
else if (rev && (s != e) &&
2170
((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
2171
x += EDIT_PaintText(es, dc, x, y, line, 0, s - li, FALSE);
2172
x += EDIT_PaintText(es, dc, x, y, line, s - li, e - s, TRUE);
2173
x += EDIT_PaintText(es, dc, x, y, line, e - li, li + ll - e, FALSE);
2174
} else
2175
x += EDIT_PaintText(es, dc, x, y, line, 0, ll, FALSE);
2176
2177
if (es->cue_banner_text && es->text_length == 0 && (!(es->flags & EF_FOCUSED) || es->cue_banner_draw_focused))
2178
{
2179
SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
2180
TextOutW(dc, x, y, es->cue_banner_text, lstrlenW(es->cue_banner_text));
2181
}
2182
}
2183
2184
2185
/*********************************************************************
2186
*
2187
* EDIT_AdjustFormatRect
2188
*
2189
* Adjusts the format rectangle for the current font and the
2190
* current client rectangle.
2191
*
2192
*/
2193
static void EDIT_AdjustFormatRect(EDITSTATE *es)
2194
{
2195
RECT ClientRect;
2196
2197
es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width);
2198
if (es->style & ES_MULTILINE)
2199
{
2200
INT fw, vlc, max_x_offset, max_y_offset;
2201
2202
vlc = get_vertical_line_count(es);
2203
es->format_rect.bottom = es->format_rect.top + vlc * es->line_height;
2204
2205
/* correct es->x_offset */
2206
fw = es->format_rect.right - es->format_rect.left;
2207
max_x_offset = es->text_width - fw;
2208
if(max_x_offset < 0) max_x_offset = 0;
2209
if(es->x_offset > max_x_offset)
2210
es->x_offset = max_x_offset;
2211
2212
/* correct es->y_offset */
2213
max_y_offset = es->line_count - vlc;
2214
if(max_y_offset < 0) max_y_offset = 0;
2215
if(es->y_offset > max_y_offset)
2216
es->y_offset = max_y_offset;
2217
2218
/* force scroll info update */
2219
EDIT_UpdateScrollInfo(es);
2220
}
2221
else
2222
{
2223
/* Windows doesn't care to fix text placement for SL controls */
2224
es->format_rect.bottom = es->format_rect.top + es->line_height;
2225
2226
/* Always stay within the client area */
2227
GetClientRect(es->hwndSelf, &ClientRect);
2228
es->format_rect.bottom = min(es->format_rect.bottom, ClientRect.bottom);
2229
}
2230
2231
if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
2232
EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL);
2233
2234
EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
2235
}
2236
2237
static int EDIT_is_valid_format_rect(const EDITSTATE *es, const RECT *rc)
2238
{
2239
if (IsRectEmpty(rc))
2240
return 0;
2241
if (es->text_width > (rc->right - rc->left) || (es->line_height * es->line_count) > (rc->bottom - rc->top))
2242
return 0;
2243
return 1;
2244
}
2245
2246
/*********************************************************************
2247
*
2248
* EDIT_SetRectNP
2249
*
2250
* note: this is not (exactly) the handler called on EM_SETRECTNP
2251
* it is also used to set the rect of a single line control
2252
*
2253
*/
2254
static void EDIT_SetRectNP(EDITSTATE *es, const RECT *rc)
2255
{
2256
LONG_PTR ExStyle;
2257
INT bw, bh;
2258
BOOL too_large = FALSE;
2259
RECT edit_rect;
2260
2261
ExStyle = GetWindowLongPtrW(es->hwndSelf, GWL_EXSTYLE);
2262
2263
if (EDIT_is_valid_format_rect(es, rc))
2264
{
2265
CopyRect(&es->format_rect, rc);
2266
GetClientRect(es->hwndSelf, &edit_rect);
2267
too_large = (rc->bottom - rc->top) > (edit_rect.bottom - edit_rect.top);
2268
}
2269
else
2270
{
2271
GetClientRect(es->hwndSelf, &es->format_rect);
2272
}
2273
2274
if (ExStyle & WS_EX_CLIENTEDGE && !too_large) {
2275
es->format_rect.left++;
2276
es->format_rect.right--;
2277
2278
if (es->format_rect.bottom - es->format_rect.top
2279
>= es->line_height + 2)
2280
{
2281
es->format_rect.top++;
2282
es->format_rect.bottom--;
2283
}
2284
}
2285
else if (es->style & WS_BORDER) {
2286
bw = GetSystemMetrics(SM_CXBORDER) + 1;
2287
bh = GetSystemMetrics(SM_CYBORDER) + 1;
2288
InflateRect(&es->format_rect, -bw, 0);
2289
if (es->format_rect.bottom - es->format_rect.top >= es->line_height + 2 * bh)
2290
InflateRect(&es->format_rect, 0, -bh);
2291
}
2292
2293
es->format_rect.left += es->left_margin;
2294
es->format_rect.right -= es->right_margin;
2295
EDIT_AdjustFormatRect(es);
2296
}
2297
2298
2299
/*********************************************************************
2300
*
2301
* EM_CHARFROMPOS
2302
*
2303
* returns line number (not index) in high-order word of result.
2304
* NB : Q137805 is unclear about this. POINT * pointer in lParam apply
2305
* to Richedit, not to the edit control. Original documentation is valid.
2306
* FIXME: do the specs mean to return -1 if outside client area or
2307
* if outside formatting rectangle ???
2308
*
2309
*/
2310
static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y)
2311
{
2312
POINT pt;
2313
RECT rc;
2314
INT index;
2315
2316
pt.x = x;
2317
pt.y = y;
2318
GetClientRect(es->hwndSelf, &rc);
2319
if (!PtInRect(&rc, pt))
2320
return -1;
2321
2322
index = EDIT_CharFromPos(es, x, y, NULL);
2323
return MAKELONG(index, EDIT_EM_LineFromChar(es, index));
2324
}
2325
2326
2327
/*********************************************************************
2328
*
2329
* EM_FMTLINES
2330
*
2331
* Enable or disable soft breaks.
2332
*
2333
* This means: insert or remove the soft linebreak character (\r\r\n).
2334
* Take care to check if the text still fits the buffer after insertion.
2335
* If not, notify with EN_ERRSPACE.
2336
*
2337
*/
2338
static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol)
2339
{
2340
es->flags &= ~EF_USE_SOFTBRK;
2341
if (add_eol) {
2342
es->flags |= EF_USE_SOFTBRK;
2343
FIXME("soft break enabled, not implemented\n");
2344
}
2345
return add_eol;
2346
}
2347
2348
2349
/*********************************************************************
2350
*
2351
* EM_GETHANDLE
2352
*
2353
* Hopefully this won't fire back at us.
2354
* We always start with a fixed buffer in the local heap.
2355
* Despite of the documentation says that the local heap is used
2356
* only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2357
* buffer on the local heap.
2358
*
2359
*/
2360
static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es)
2361
{
2362
if (!(es->style & ES_MULTILINE))
2363
return 0;
2364
2365
EDIT_UnlockBuffer(es, TRUE);
2366
2367
/* The text buffer handle belongs to the app */
2368
es->hlocapp = es->hloc32W;
2369
2370
TRACE("Returning %p, LocalSize() = %Id\n", es->hlocapp, LocalSize(es->hlocapp));
2371
return es->hlocapp;
2372
}
2373
2374
2375
/*********************************************************************
2376
*
2377
* EM_GETLINE
2378
*
2379
*/
2380
static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPWSTR dst)
2381
{
2382
INT line_len, dst_len;
2383
LPWSTR src;
2384
INT i;
2385
2386
if (es->style & ES_MULTILINE)
2387
{
2388
if (line >= es->line_count)
2389
return 0;
2390
}
2391
else
2392
line = 0;
2393
2394
i = EDIT_EM_LineIndex(es, line);
2395
src = es->text + i;
2396
line_len = EDIT_EM_LineLength(es, i);
2397
dst_len = *(WORD *)dst;
2398
2399
if (dst_len <= line_len)
2400
{
2401
memcpy(dst, src, dst_len * sizeof(WCHAR));
2402
return dst_len;
2403
}
2404
else /* Append 0 if enough space */
2405
{
2406
memcpy(dst, src, line_len * sizeof(WCHAR));
2407
dst[line_len] = 0;
2408
return line_len;
2409
}
2410
}
2411
2412
2413
/*********************************************************************
2414
*
2415
* EM_GETSEL
2416
*
2417
*/
2418
static LRESULT EDIT_EM_GetSel(const EDITSTATE *es, PUINT start, PUINT end)
2419
{
2420
UINT s = es->selection_start;
2421
UINT e = es->selection_end;
2422
2423
ORDER_UINT(s, e);
2424
if (start)
2425
*start = s;
2426
if (end)
2427
*end = e;
2428
return MAKELONG(s, e);
2429
}
2430
2431
2432
/*********************************************************************
2433
*
2434
* EM_REPLACESEL
2435
*
2436
* FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2437
*
2438
*/
2439
static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, const WCHAR *lpsz_replace, UINT strl,
2440
BOOL send_update, BOOL honor_limit)
2441
{
2442
UINT tl = get_text_length(es);
2443
UINT utl;
2444
UINT s;
2445
UINT e;
2446
UINT i;
2447
UINT size;
2448
LPWSTR p;
2449
HRGN hrgn = 0;
2450
LPWSTR buf = NULL;
2451
UINT bufl;
2452
2453
TRACE("%s, can_undo %d, send_update %d\n",
2454
debugstr_wn(lpsz_replace, strl), can_undo, send_update);
2455
2456
s = es->selection_start;
2457
e = es->selection_end;
2458
2459
EDIT_InvalidateUniscribeData(es);
2460
if ((s == e) && !strl)
2461
return;
2462
2463
ORDER_UINT(s, e);
2464
2465
size = tl - (e - s) + strl;
2466
if (!size)
2467
es->text_width = 0;
2468
2469
/* Issue the EN_MAXTEXT notification and continue with replacing text
2470
* so that buffer limit is honored. */
2471
if ((honor_limit) && (size > es->buffer_limit))
2472
{
2473
if (!notify_parent(es, EN_MAXTEXT)) return;
2474
/* Buffer limit can be smaller than the actual length of text in combobox */
2475
if (es->buffer_limit < (tl - (e-s)))
2476
strl = 0;
2477
else
2478
strl = min(strl, es->buffer_limit - (tl - (e-s)));
2479
}
2480
2481
if (!EDIT_MakeFit(es, tl - (e - s) + strl))
2482
return;
2483
2484
if (e != s) {
2485
/* there is something to be deleted */
2486
TRACE("deleting stuff.\n");
2487
bufl = e - s;
2488
buf = Alloc((bufl + 1) * sizeof(WCHAR));
2489
if (!buf) return;
2490
memcpy(buf, es->text + s, bufl * sizeof(WCHAR));
2491
buf[bufl] = 0; /* ensure 0 termination */
2492
/* now delete */
2493
lstrcpyW(es->text + s, es->text + e);
2494
text_buffer_changed(es);
2495
}
2496
if (strl) {
2497
/* there is an insertion */
2498
tl = get_text_length(es);
2499
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));
2500
for (p = es->text + tl ; p >= es->text + s ; p--)
2501
p[strl] = p[0];
2502
for (i = 0 , p = es->text + s ; i < strl ; i++)
2503
p[i] = lpsz_replace[i];
2504
if(es->style & ES_UPPERCASE)
2505
CharUpperBuffW(p, strl);
2506
else if(es->style & ES_LOWERCASE)
2507
CharLowerBuffW(p, strl);
2508
text_buffer_changed(es);
2509
}
2510
if (es->style & ES_MULTILINE)
2511
{
2512
INT st = min(es->selection_start, es->selection_end);
2513
INT vlc = get_vertical_line_count(es);
2514
2515
hrgn = CreateRectRgn(0, 0, 0, 0);
2516
EDIT_BuildLineDefs_ML(es, st, st + strl,
2517
strl - abs(es->selection_end - es->selection_start), hrgn);
2518
/* if text is too long undo all changes */
2519
if (honor_limit && !(es->style & ES_AUTOVSCROLL) && (es->line_count > vlc)) {
2520
if (strl)
2521
lstrcpyW(es->text + e, es->text + e + strl);
2522
if (e != s)
2523
for (i = 0 , p = es->text ; i < e - s ; i++)
2524
p[i + s] = buf[i];
2525
text_buffer_changed(es);
2526
EDIT_BuildLineDefs_ML(es, s, e,
2527
abs(es->selection_end - es->selection_start) - strl, hrgn);
2528
strl = 0;
2529
e = s;
2530
SetRectRgn(hrgn, 0, 0, 0, 0);
2531
if (!notify_parent(es, EN_MAXTEXT)) return;
2532
}
2533
}
2534
else {
2535
INT fw = es->format_rect.right - es->format_rect.left;
2536
EDIT_InvalidateUniscribeData(es);
2537
EDIT_CalcLineWidth_SL(es);
2538
/* remove chars that don't fit */
2539
if (honor_limit && !(es->style & ES_AUTOHSCROLL) && (es->text_width > fw)) {
2540
while ((es->text_width > fw) && s + strl >= s) {
2541
lstrcpyW(es->text + s + strl - 1, es->text + s + strl);
2542
strl--;
2543
es->text_length = -1;
2544
EDIT_InvalidateUniscribeData(es);
2545
EDIT_CalcLineWidth_SL(es);
2546
}
2547
text_buffer_changed(es);
2548
if (!notify_parent(es, EN_MAXTEXT)) return;
2549
}
2550
}
2551
2552
if (e != s) {
2553
if (can_undo) {
2554
utl = lstrlenW(es->undo_text);
2555
if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
2556
/* undo-buffer is extended to the right */
2557
EDIT_MakeUndoFit(es, utl + e - s);
2558
memcpy(es->undo_text + utl, buf, (e - s)*sizeof(WCHAR));
2559
(es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */
2560
} else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
2561
/* undo-buffer is extended to the left */
2562
EDIT_MakeUndoFit(es, utl + e - s);
2563
for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
2564
p[e - s] = p[0];
2565
for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2566
p[i] = buf[i];
2567
es->undo_position = s;
2568
} else {
2569
/* new undo-buffer */
2570
EDIT_MakeUndoFit(es, e - s);
2571
memcpy(es->undo_text, buf, (e - s)*sizeof(WCHAR));
2572
es->undo_text[e - s] = 0; /* ensure 0 termination */
2573
es->undo_position = s;
2574
}
2575
/* any deletion makes the old insertion-undo invalid */
2576
es->undo_insert_count = 0;
2577
} else
2578
EDIT_EM_EmptyUndoBuffer(es);
2579
}
2580
if (strl) {
2581
if (can_undo) {
2582
if ((s == es->undo_position) ||
2583
((es->undo_insert_count) &&
2584
(s == es->undo_position + es->undo_insert_count)))
2585
/*
2586
* insertion is new and at delete position or
2587
* an extension to either left or right
2588
*/
2589
es->undo_insert_count += strl;
2590
else {
2591
/* new insertion undo */
2592
es->undo_position = s;
2593
es->undo_insert_count = strl;
2594
/* new insertion makes old delete-buffer invalid */
2595
*es->undo_text = '\0';
2596
}
2597
} else
2598
EDIT_EM_EmptyUndoBuffer(es);
2599
}
2600
2601
Free(buf);
2602
2603
s += strl;
2604
2605
/* If text has been deleted and we're right or center aligned then scroll rightward */
2606
if (es->style & (ES_RIGHT | ES_CENTER))
2607
{
2608
INT delta = strl - abs(es->selection_end - es->selection_start);
2609
2610
if (delta < 0 && es->x_offset)
2611
{
2612
if (abs(delta) > es->x_offset)
2613
es->x_offset = 0;
2614
else
2615
es->x_offset += delta;
2616
}
2617
}
2618
2619
EDIT_EM_SetSel(es, s, s, FALSE);
2620
es->flags |= EF_MODIFIED;
2621
if (send_update) es->flags |= EF_UPDATE;
2622
if (hrgn)
2623
{
2624
EDIT_UpdateTextRegion(es, hrgn, TRUE);
2625
DeleteObject(hrgn);
2626
}
2627
else
2628
EDIT_UpdateText(es, NULL, TRUE);
2629
2630
EDIT_EM_ScrollCaret(es);
2631
2632
/* force scroll info update */
2633
EDIT_UpdateScrollInfo(es);
2634
2635
2636
if(send_update || (es->flags & EF_UPDATE))
2637
{
2638
es->flags &= ~EF_UPDATE;
2639
if (!notify_parent(es, EN_CHANGE)) return;
2640
}
2641
EDIT_InvalidateUniscribeData(es);
2642
2643
NotifyWinEvent(EVENT_OBJECT_VALUECHANGE, es->hwndSelf, OBJID_CLIENT, 0);
2644
}
2645
2646
2647
/*********************************************************************
2648
*
2649
* EM_SETHANDLE
2650
*
2651
* FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2652
*
2653
*/
2654
static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc)
2655
{
2656
if (!(es->style & ES_MULTILINE))
2657
return;
2658
2659
if (!hloc)
2660
return;
2661
2662
EDIT_UnlockBuffer(es, TRUE);
2663
2664
es->hloc32W = hloc;
2665
es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
2666
2667
/* The text buffer handle belongs to the control */
2668
es->hlocapp = NULL;
2669
2670
EDIT_LockBuffer(es);
2671
text_buffer_changed(es);
2672
2673
es->x_offset = es->y_offset = 0;
2674
es->selection_start = es->selection_end = 0;
2675
EDIT_EM_EmptyUndoBuffer(es);
2676
es->flags &= ~EF_MODIFIED;
2677
es->flags &= ~EF_UPDATE;
2678
EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL);
2679
EDIT_UpdateText(es, NULL, TRUE);
2680
EDIT_EM_ScrollCaret(es);
2681
/* force scroll info update */
2682
EDIT_UpdateScrollInfo(es);
2683
}
2684
2685
2686
/*********************************************************************
2687
*
2688
* EM_SETLIMITTEXT
2689
*
2690
* NOTE: this version currently implements WinNT limits
2691
*
2692
*/
2693
static void EDIT_EM_SetLimitText(EDITSTATE *es, UINT limit)
2694
{
2695
if (!limit) limit = ~0u;
2696
if (!(es->style & ES_MULTILINE)) limit = min(limit, 0x7ffffffe);
2697
es->buffer_limit = limit;
2698
}
2699
2700
static BOOL is_cjk(HDC dc)
2701
{
2702
const DWORD FS_DBCS_MASK = FS_JISJAPAN|FS_CHINESESIMP|FS_WANSUNG|FS_CHINESETRAD|FS_JOHAB;
2703
FONTSIGNATURE fs;
2704
2705
switch (GdiGetCodePage(dc)) {
2706
case 932: case 936: case 949: case 950: case 1361:
2707
return TRUE;
2708
default:
2709
return (GetTextCharsetInfo(dc, &fs, 0) != DEFAULT_CHARSET &&
2710
(fs.fsCsb[0] & FS_DBCS_MASK));
2711
}
2712
}
2713
2714
static int get_cjk_fontinfo_margin(int width, int side_bearing)
2715
{
2716
int margin;
2717
if (side_bearing < 0)
2718
margin = min(-side_bearing, width/2);
2719
else
2720
margin = 0;
2721
return margin;
2722
}
2723
2724
struct char_width_info {
2725
INT min_lsb, min_rsb, unknown;
2726
};
2727
2728
/* Undocumented gdi32 export */
2729
extern BOOL WINAPI GetCharWidthInfo(HDC, struct char_width_info *);
2730
2731
/*********************************************************************
2732
*
2733
* EM_SETMARGINS
2734
*
2735
* EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
2736
* action wParam despite what the docs say. EC_USEFONTINFO calculates the
2737
* margin according to the textmetrics of the current font.
2738
*
2739
* When EC_USEFONTINFO is used, the margins only change if the edit control is
2740
* equal to or larger than a certain size. The empty client rect is treated as
2741
* 80 pixels width.
2742
*/
2743
static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
2744
WORD left, WORD right, BOOL repaint)
2745
{
2746
TEXTMETRICW tm;
2747
INT default_left_margin = 0; /* in pixels */
2748
INT default_right_margin = 0; /* in pixels */
2749
2750
/* Set the default margins depending on the font */
2751
if (es->font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO)) {
2752
HDC dc = GetDC(es->hwndSelf);
2753
HFONT old_font = SelectObject(dc, es->font);
2754
LONG width = GdiGetCharDimensions(dc, &tm, NULL), rc_width;
2755
RECT rc;
2756
2757
/* The default margins are only non zero for TrueType or Vector fonts */
2758
if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) {
2759
struct char_width_info width_info;
2760
2761
if (is_cjk(dc) && GetCharWidthInfo(dc, &width_info))
2762
{
2763
default_left_margin = get_cjk_fontinfo_margin(width, width_info.min_lsb);
2764
default_right_margin = get_cjk_fontinfo_margin(width, width_info.min_rsb);
2765
}
2766
else
2767
{
2768
default_left_margin = width / 2;
2769
default_right_margin = width / 2;
2770
}
2771
2772
GetClientRect(es->hwndSelf, &rc);
2773
rc_width = !IsRectEmpty(&rc) ? rc.right - rc.left : 80;
2774
if (rc_width < default_left_margin + default_right_margin + width * 2) {
2775
default_left_margin = es->left_margin;
2776
default_right_margin = es->right_margin;
2777
}
2778
}
2779
SelectObject(dc, old_font);
2780
ReleaseDC(es->hwndSelf, dc);
2781
}
2782
2783
if (action & EC_LEFTMARGIN) {
2784
es->format_rect.left -= es->left_margin;
2785
if (left != EC_USEFONTINFO)
2786
es->left_margin = left;
2787
else
2788
es->left_margin = default_left_margin;
2789
es->format_rect.left += es->left_margin;
2790
}
2791
2792
if (action & EC_RIGHTMARGIN) {
2793
es->format_rect.right += es->right_margin;
2794
if (right != EC_USEFONTINFO)
2795
es->right_margin = right;
2796
else
2797
es->right_margin = default_right_margin;
2798
es->format_rect.right -= es->right_margin;
2799
}
2800
2801
if (action & (EC_LEFTMARGIN | EC_RIGHTMARGIN)) {
2802
EDIT_AdjustFormatRect(es);
2803
if (repaint) EDIT_UpdateText(es, NULL, TRUE);
2804
}
2805
2806
TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin);
2807
}
2808
2809
2810
/*********************************************************************
2811
*
2812
* EM_SETPASSWORDCHAR
2813
*
2814
*/
2815
static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c)
2816
{
2817
LONG style;
2818
2819
if (es->style & ES_MULTILINE)
2820
return;
2821
2822
if (es->password_char == c)
2823
return;
2824
2825
style = GetWindowLongW( es->hwndSelf, GWL_STYLE );
2826
es->password_char = c;
2827
if (c) {
2828
SetWindowLongW( es->hwndSelf, GWL_STYLE, style | ES_PASSWORD );
2829
es->style |= ES_PASSWORD;
2830
} else {
2831
SetWindowLongW( es->hwndSelf, GWL_STYLE, style & ~ES_PASSWORD );
2832
es->style &= ~ES_PASSWORD;
2833
}
2834
EDIT_InvalidateUniscribeData(es);
2835
EDIT_UpdateText(es, NULL, TRUE);
2836
}
2837
2838
2839
/*********************************************************************
2840
*
2841
* EM_SETTABSTOPS
2842
*
2843
*/
2844
static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, const INT *tabs)
2845
{
2846
if (!(es->style & ES_MULTILINE))
2847
return FALSE;
2848
Free(es->tabs);
2849
es->tabs_count = count;
2850
if (!count)
2851
es->tabs = NULL;
2852
else {
2853
es->tabs = Alloc(count * sizeof(INT));
2854
memcpy(es->tabs, tabs, count * sizeof(INT));
2855
}
2856
EDIT_InvalidateUniscribeData(es);
2857
return TRUE;
2858
}
2859
2860
2861
/*********************************************************************
2862
*
2863
* EM_SETWORDBREAKPROC
2864
*
2865
*/
2866
static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, EDITWORDBREAKPROCW wbp)
2867
{
2868
if (es->word_break_proc == wbp)
2869
return;
2870
2871
es->word_break_proc = wbp;
2872
2873
if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2874
EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL);
2875
EDIT_UpdateText(es, NULL, TRUE);
2876
}
2877
}
2878
2879
2880
/*********************************************************************
2881
*
2882
* EM_UNDO / WM_UNDO
2883
*
2884
*/
2885
static BOOL EDIT_EM_Undo(EDITSTATE *es)
2886
{
2887
INT ulength;
2888
LPWSTR utext;
2889
2890
/* As per MSDN spec, for a single-line edit control,
2891
the return value is always TRUE */
2892
if( es->style & ES_READONLY )
2893
return !(es->style & ES_MULTILINE);
2894
2895
ulength = lstrlenW(es->undo_text);
2896
2897
utext = Alloc((ulength + 1) * sizeof(WCHAR));
2898
2899
lstrcpyW(utext, es->undo_text);
2900
2901
TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
2902
es->undo_insert_count, debugstr_w(utext));
2903
2904
EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2905
EDIT_EM_EmptyUndoBuffer(es);
2906
EDIT_EM_ReplaceSel(es, TRUE, utext, ulength, TRUE, TRUE);
2907
EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2908
/* send the notification after the selection start and end are set */
2909
if (!notify_parent(es, EN_CHANGE)) return TRUE;
2910
EDIT_EM_ScrollCaret(es);
2911
Free(utext);
2912
2913
NotifyWinEvent(EVENT_OBJECT_VALUECHANGE, es->hwndSelf, OBJID_CLIENT, 0);
2914
TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
2915
es->undo_insert_count, debugstr_w(es->undo_text));
2916
return TRUE;
2917
}
2918
2919
2920
/* Helper function for WM_CHAR
2921
*
2922
* According to an MSDN blog article titled "Just because you're a control
2923
* doesn't mean that you're necessarily inside a dialog box," multiline edit
2924
* controls without ES_WANTRETURN would attempt to detect whether it is inside
2925
* a dialog box or not.
2926
*/
2927
static inline BOOL EDIT_IsInsideDialog(EDITSTATE *es)
2928
{
2929
return (es->flags & EF_DIALOGMODE);
2930
}
2931
2932
2933
/*********************************************************************
2934
*
2935
* WM_PASTE
2936
*
2937
*/
2938
static void EDIT_WM_Paste(EDITSTATE *es)
2939
{
2940
HGLOBAL hsrc;
2941
LPWSTR src, ptr;
2942
int len;
2943
2944
/* Protect read-only edit control from modification */
2945
if(es->style & ES_READONLY)
2946
return;
2947
2948
OpenClipboard(es->hwndSelf);
2949
if ((hsrc = GetClipboardData(CF_UNICODETEXT))) {
2950
src = GlobalLock(hsrc);
2951
len = lstrlenW(src);
2952
/* Protect single-line edit against pasting new line character */
2953
if (!(es->style & ES_MULTILINE) && ((ptr = wcschr(src, '\n')))) {
2954
len = ptr - src;
2955
if (len && src[len - 1] == '\r')
2956
--len;
2957
}
2958
EDIT_EM_ReplaceSel(es, TRUE, src, len, TRUE, TRUE);
2959
GlobalUnlock(hsrc);
2960
}
2961
else if (es->style & ES_PASSWORD) {
2962
/* clear selected text in password edit box even with empty clipboard */
2963
EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE);
2964
}
2965
CloseClipboard();
2966
}
2967
2968
2969
/*********************************************************************
2970
*
2971
* WM_COPY
2972
*
2973
*/
2974
static void EDIT_WM_Copy(EDITSTATE *es)
2975
{
2976
INT s = min(es->selection_start, es->selection_end);
2977
INT e = max(es->selection_start, es->selection_end);
2978
HGLOBAL hdst;
2979
LPWSTR dst;
2980
DWORD len;
2981
2982
if (e == s) return;
2983
2984
len = e - s;
2985
hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (len + 1) * sizeof(WCHAR));
2986
dst = GlobalLock(hdst);
2987
memcpy(dst, es->text + s, len * sizeof(WCHAR));
2988
dst[len] = 0; /* ensure 0 termination */
2989
TRACE("%s\n", debugstr_w(dst));
2990
GlobalUnlock(hdst);
2991
OpenClipboard(es->hwndSelf);
2992
EmptyClipboard();
2993
SetClipboardData(CF_UNICODETEXT, hdst);
2994
CloseClipboard();
2995
}
2996
2997
2998
/*********************************************************************
2999
*
3000
* WM_CLEAR
3001
*
3002
*/
3003
static inline void EDIT_WM_Clear(EDITSTATE *es)
3004
{
3005
/* Protect read-only edit control from modification */
3006
if(es->style & ES_READONLY)
3007
return;
3008
3009
EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE);
3010
}
3011
3012
3013
/*********************************************************************
3014
*
3015
* WM_CUT
3016
*
3017
*/
3018
static inline void EDIT_WM_Cut(EDITSTATE *es)
3019
{
3020
EDIT_WM_Copy(es);
3021
EDIT_WM_Clear(es);
3022
}
3023
3024
3025
/*********************************************************************
3026
*
3027
* WM_CHAR
3028
*
3029
*/
3030
static LRESULT EDIT_WM_Char(EDITSTATE *es, WCHAR c)
3031
{
3032
BOOL control;
3033
3034
if (es->bCaptureState)
3035
return 1;
3036
3037
control = GetKeyState(VK_CONTROL) & 0x8000;
3038
3039
switch (c) {
3040
case '\r':
3041
/* If it's not a multiline edit box, it would be ignored below.
3042
* For multiline edit without ES_WANTRETURN, we have to make a
3043
* special case.
3044
*/
3045
if ((es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
3046
if (EDIT_IsInsideDialog(es))
3047
break;
3048
case '\n':
3049
if (es->style & ES_MULTILINE) {
3050
if (es->style & ES_READONLY) {
3051
EDIT_MoveHome(es, FALSE, FALSE);
3052
EDIT_MoveDown_ML(es, FALSE);
3053
} else
3054
EDIT_EM_ReplaceSel(es, TRUE, L"\r\n", 2, TRUE, TRUE);
3055
}
3056
break;
3057
case '\t':
3058
if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
3059
{
3060
if (EDIT_IsInsideDialog(es))
3061
break;
3062
EDIT_EM_ReplaceSel(es, TRUE, L"\t", 1, TRUE, TRUE);
3063
}
3064
break;
3065
case VK_BACK:
3066
if (!(es->style & ES_READONLY) && !control) {
3067
if (es->selection_start != es->selection_end)
3068
EDIT_WM_Clear(es);
3069
else {
3070
/* delete character left of caret */
3071
EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
3072
EDIT_MoveBackward(es, TRUE);
3073
EDIT_WM_Clear(es);
3074
}
3075
}
3076
break;
3077
case 0x03: /* ^C */
3078
if (!(es->style & ES_PASSWORD))
3079
SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
3080
break;
3081
case 0x16: /* ^V */
3082
if (!(es->style & ES_READONLY))
3083
SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
3084
break;
3085
case 0x18: /* ^X */
3086
if (!((es->style & ES_READONLY) || (es->style & ES_PASSWORD)))
3087
SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
3088
break;
3089
case 0x1A: /* ^Z */
3090
if (!(es->style & ES_READONLY))
3091
SendMessageW(es->hwndSelf, WM_UNDO, 0, 0);
3092
break;
3093
3094
default:
3095
/*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3096
if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') )
3097
break;
3098
3099
if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127))
3100
EDIT_EM_ReplaceSel(es, TRUE, &c, 1, TRUE, TRUE);
3101
break;
3102
}
3103
return 1;
3104
}
3105
3106
3107
/*********************************************************************
3108
*
3109
* EDIT_ContextMenuCommand
3110
*
3111
*/
3112
static void EDIT_ContextMenuCommand(EDITSTATE *es, UINT id)
3113
{
3114
switch (id) {
3115
case EM_UNDO:
3116
SendMessageW(es->hwndSelf, WM_UNDO, 0, 0);
3117
break;
3118
case WM_CUT:
3119
SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
3120
break;
3121
case WM_COPY:
3122
SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
3123
break;
3124
case WM_PASTE:
3125
SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
3126
break;
3127
case WM_CLEAR:
3128
SendMessageW(es->hwndSelf, WM_CLEAR, 0, 0);
3129
break;
3130
case EM_SETSEL:
3131
SendMessageW(es->hwndSelf, EM_SETSEL, 0, -1);
3132
break;
3133
default:
3134
ERR("unknown menu item, please report\n");
3135
break;
3136
}
3137
}
3138
3139
3140
/*********************************************************************
3141
*
3142
* WM_CONTEXTMENU
3143
*
3144
* Note: the resource files resource/sysres_??.rc cannot define a
3145
* single popup menu. Hence we use a (dummy) menubar
3146
* containing the single popup menu as its first item.
3147
*
3148
* FIXME: the message identifiers have been chosen arbitrarily,
3149
* hence we use MF_BYPOSITION.
3150
* We might as well use the "real" values (anybody knows ?)
3151
* The menu definition is in resources/sysres_??.rc.
3152
* Once these are OK, we better use MF_BYCOMMAND here
3153
* (as we do in EDIT_WM_Command()).
3154
*
3155
*/
3156
static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
3157
{
3158
HMENU menu = LoadMenuA(GetModuleHandleA("user32.dll"), "EDITMENU");
3159
HMENU popup = GetSubMenu(menu, 0);
3160
UINT start = es->selection_start;
3161
UINT end = es->selection_end;
3162
UINT cmd;
3163
POINT pt;
3164
3165
ORDER_UINT(start, end);
3166
3167
/* undo */
3168
EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3169
/* cut */
3170
EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3171
/* copy */
3172
EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
3173
/* paste */
3174
EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3175
/* delete */
3176
EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
3177
/* select all */
3178
EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != get_text_length(es)) ? MF_ENABLED : MF_GRAYED));
3179
3180
pt.x = x;
3181
pt.y = y;
3182
3183
if (pt.x == -1 && pt.y == -1) /* passed via VK_APPS press/release */
3184
{
3185
RECT rc;
3186
3187
/* Windows places the menu at the edit's center in this case */
3188
GetClientRect(es->hwndSelf, &rc);
3189
pt.x = rc.left + (rc.right - rc.left) / 2;
3190
pt.y = rc.top + (rc.bottom - rc.top) / 2;
3191
ClientToScreen(es->hwndSelf, &pt);
3192
}
3193
3194
if (!(es->flags & EF_FOCUSED))
3195
SetFocus(es->hwndSelf);
3196
3197
cmd = TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY,
3198
pt.x, pt.y, 0, es->hwndSelf, NULL);
3199
3200
if (cmd)
3201
EDIT_ContextMenuCommand(es, cmd);
3202
3203
DestroyMenu(menu);
3204
}
3205
3206
3207
/*********************************************************************
3208
*
3209
* WM_GETTEXT
3210
*
3211
*/
3212
static INT EDIT_WM_GetText(const EDITSTATE *es, INT count, LPWSTR dst)
3213
{
3214
if (!count)
3215
return 0;
3216
3217
lstrcpynW(dst, es->text, count);
3218
return lstrlenW(dst);
3219
}
3220
3221
/*********************************************************************
3222
*
3223
* EDIT_CheckCombo
3224
*
3225
*/
3226
static BOOL EDIT_CheckCombo(EDITSTATE *es, UINT msg, INT key)
3227
{
3228
HWND hLBox = es->hwndListBox;
3229
HWND hCombo;
3230
BOOL bDropped;
3231
int nEUI;
3232
3233
if (!hLBox)
3234
return FALSE;
3235
3236
hCombo = GetParent(es->hwndSelf);
3237
bDropped = TRUE;
3238
nEUI = 0;
3239
3240
TRACE("[%p]: handling msg %x (%x)\n", es->hwndSelf, msg, key);
3241
3242
if (key == VK_UP || key == VK_DOWN)
3243
{
3244
if (SendMessageW(hCombo, CB_GETEXTENDEDUI, 0, 0))
3245
nEUI = 1;
3246
3247
if (msg == WM_KEYDOWN || nEUI)
3248
bDropped = (BOOL)SendMessageW(hCombo, CB_GETDROPPEDSTATE, 0, 0);
3249
}
3250
3251
switch (msg)
3252
{
3253
case WM_KEYDOWN:
3254
if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN))
3255
{
3256
/* make sure ComboLBox pops up */
3257
SendMessageW(hCombo, CB_SETEXTENDEDUI, FALSE, 0);
3258
key = VK_F4;
3259
nEUI = 2;
3260
}
3261
3262
SendMessageW(hLBox, WM_KEYDOWN, key, 0);
3263
break;
3264
3265
case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
3266
if (nEUI)
3267
SendMessageW(hCombo, CB_SHOWDROPDOWN, !bDropped, 0);
3268
else
3269
SendMessageW(hLBox, WM_KEYDOWN, VK_F4, 0);
3270
break;
3271
}
3272
3273
if (nEUI == 2)
3274
SendMessageW(hCombo, CB_SETEXTENDEDUI, TRUE, 0);
3275
3276
return TRUE;
3277
}
3278
3279
3280
/*********************************************************************
3281
*
3282
* WM_KEYDOWN
3283
*
3284
* Handling of special keys that don't produce a WM_CHAR
3285
* (i.e. non-printable keys) & Backspace & Delete
3286
*
3287
*/
3288
static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key)
3289
{
3290
BOOL shift;
3291
BOOL control;
3292
3293
if (es->bCaptureState)
3294
return 1;
3295
3296
if (GetKeyState(VK_MENU) & 0x8000)
3297
return 0;
3298
3299
shift = GetKeyState(VK_SHIFT) & 0x8000;
3300
control = GetKeyState(VK_CONTROL) & 0x8000;
3301
3302
switch (key) {
3303
case VK_F4:
3304
case VK_UP:
3305
if (EDIT_CheckCombo(es, WM_KEYDOWN, key) || key == VK_F4)
3306
break;
3307
3308
/* fall through */
3309
case VK_LEFT:
3310
if ((es->style & ES_MULTILINE) && (key == VK_UP))
3311
EDIT_MoveUp_ML(es, shift);
3312
else
3313
if (control)
3314
EDIT_MoveWordBackward(es, shift);
3315
else
3316
EDIT_MoveBackward(es, shift);
3317
break;
3318
case VK_DOWN:
3319
if (EDIT_CheckCombo(es, WM_KEYDOWN, key))
3320
break;
3321
/* fall through */
3322
case VK_RIGHT:
3323
if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
3324
EDIT_MoveDown_ML(es, shift);
3325
else if (control)
3326
EDIT_MoveWordForward(es, shift);
3327
else
3328
EDIT_MoveForward(es, shift);
3329
break;
3330
case VK_HOME:
3331
EDIT_MoveHome(es, shift, control);
3332
break;
3333
case VK_END:
3334
EDIT_MoveEnd(es, shift, control);
3335
break;
3336
case VK_PRIOR:
3337
if (es->style & ES_MULTILINE)
3338
EDIT_MovePageUp_ML(es, shift);
3339
else
3340
EDIT_CheckCombo(es, WM_KEYDOWN, key);
3341
break;
3342
case VK_NEXT:
3343
if (es->style & ES_MULTILINE)
3344
EDIT_MovePageDown_ML(es, shift);
3345
else
3346
EDIT_CheckCombo(es, WM_KEYDOWN, key);
3347
break;
3348
case VK_DELETE:
3349
if (!(es->style & ES_READONLY) && !(shift && control)) {
3350
if (es->selection_start != es->selection_end) {
3351
if (shift)
3352
EDIT_WM_Cut(es);
3353
else
3354
EDIT_WM_Clear(es);
3355
} else {
3356
EDIT_EM_SetSel(es, ~0u, 0, FALSE);
3357
if (shift)
3358
/* delete character left of caret */
3359
EDIT_MoveBackward(es, TRUE);
3360
else if (control)
3361
/* delete to end of line */
3362
EDIT_MoveEnd(es, TRUE, FALSE);
3363
else
3364
/* delete character right of caret */
3365
EDIT_MoveForward(es, TRUE);
3366
EDIT_WM_Clear(es);
3367
}
3368
}
3369
break;
3370
case VK_INSERT:
3371
if (shift) {
3372
if (!(es->style & ES_READONLY))
3373
EDIT_WM_Paste(es);
3374
} else if (control)
3375
EDIT_WM_Copy(es);
3376
break;
3377
case VK_RETURN:
3378
/* If the edit doesn't want the return send a message to the default object */
3379
if(!(es->style & ES_MULTILINE) || !(es->style & ES_WANTRETURN))
3380
{
3381
DWORD dw;
3382
3383
if (!EDIT_IsInsideDialog(es)) break;
3384
if (control) break;
3385
dw = SendMessageW(es->hwndParent, DM_GETDEFID, 0, 0);
3386
if (HIWORD(dw) == DC_HASDEFID)
3387
{
3388
HWND hwDefCtrl = GetDlgItem(es->hwndParent, LOWORD(dw));
3389
if (hwDefCtrl)
3390
{
3391
SendMessageW(es->hwndParent, WM_NEXTDLGCTL, (WPARAM)hwDefCtrl, TRUE);
3392
PostMessageW(hwDefCtrl, WM_KEYDOWN, VK_RETURN, 0);
3393
}
3394
}
3395
}
3396
break;
3397
case VK_ESCAPE:
3398
if ((es->style & ES_MULTILINE) && EDIT_IsInsideDialog(es))
3399
PostMessageW(es->hwndParent, WM_CLOSE, 0, 0);
3400
break;
3401
case VK_TAB:
3402
if ((es->style & ES_MULTILINE) && EDIT_IsInsideDialog(es))
3403
SendMessageW(es->hwndParent, WM_NEXTDLGCTL, shift, 0);
3404
break;
3405
case 'A':
3406
if (control)
3407
{
3408
if (EDIT_EM_SetSel(es, 0, get_text_length(es), FALSE))
3409
EDIT_EM_ScrollCaret(es);
3410
}
3411
break;
3412
}
3413
return TRUE;
3414
}
3415
3416
3417
/*********************************************************************
3418
*
3419
* WM_KILLFOCUS
3420
*
3421
*/
3422
static LRESULT EDIT_WM_KillFocus(HTHEME theme, EDITSTATE *es)
3423
{
3424
UINT flags = RDW_INVALIDATE;
3425
3426
es->flags &= ~EF_FOCUSED;
3427
DestroyCaret();
3428
if (!(es->style & ES_NOHIDESEL))
3429
EDIT_InvalidateText(es, es->selection_start, es->selection_end);
3430
if (!notify_parent(es, EN_KILLFOCUS)) return 0;
3431
/* Throw away left over scroll when we lose focus */
3432
es->wheelDeltaRemainder = 0;
3433
3434
if (theme)
3435
flags |= RDW_FRAME;
3436
3437
RedrawWindow(es->hwndSelf, NULL, NULL, flags);
3438
return 0;
3439
}
3440
3441
3442
/*********************************************************************
3443
*
3444
* WM_LBUTTONDBLCLK
3445
*
3446
* The caret position has been set on the WM_LBUTTONDOWN message
3447
*
3448
*/
3449
static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es)
3450
{
3451
INT s;
3452
INT e = es->selection_end;
3453
INT l;
3454
INT li;
3455
INT ll;
3456
3457
es->bCaptureState = TRUE;
3458
SetCapture(es->hwndSelf);
3459
3460
l = EDIT_EM_LineFromChar(es, e);
3461
li = EDIT_EM_LineIndex(es, l);
3462
ll = EDIT_EM_LineLength(es, e);
3463
s = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT);
3464
e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_RIGHT);
3465
EDIT_EM_SetSel(es, s, e, FALSE);
3466
EDIT_EM_ScrollCaret(es);
3467
return 0;
3468
}
3469
3470
3471
/*********************************************************************
3472
*
3473
* WM_LBUTTONDOWN
3474
*
3475
*/
3476
static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y)
3477
{
3478
INT e;
3479
BOOL after_wrap;
3480
3481
es->bCaptureState = TRUE;
3482
SetCapture(es->hwndSelf);
3483
EDIT_ConfinePoint(es, &x, &y);
3484
e = EDIT_CharFromPos(es, x, y, &after_wrap);
3485
EDIT_EM_SetSel(es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
3486
EDIT_EM_ScrollCaret(es);
3487
3488
if (!(es->flags & EF_FOCUSED))
3489
SetFocus(es->hwndSelf);
3490
3491
return 0;
3492
}
3493
3494
3495
/*********************************************************************
3496
*
3497
* WM_LBUTTONUP
3498
*
3499
*/
3500
static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es)
3501
{
3502
if (es->bCaptureState) {
3503
if (GetCapture() == es->hwndSelf) ReleaseCapture();
3504
}
3505
es->bCaptureState = FALSE;
3506
return 0;
3507
}
3508
3509
3510
/*********************************************************************
3511
*
3512
* WM_MBUTTONDOWN
3513
*
3514
*/
3515
static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es)
3516
{
3517
SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
3518
return 0;
3519
}
3520
3521
3522
/*********************************************************************
3523
*
3524
* WM_MOUSEMOVE
3525
*
3526
*/
3527
static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y)
3528
{
3529
INT e;
3530
BOOL after_wrap;
3531
3532
/* If the mouse has been captured by process other than the edit control itself,
3533
* the windows edit controls will not select the strings with mouse move.
3534
*/
3535
if (!es->bCaptureState || GetCapture() != es->hwndSelf)
3536
return 0;
3537
3538
e = EDIT_CharFromPos(es, x, y, &after_wrap);
3539
EDIT_EM_SetSel(es, es->selection_start, e, after_wrap);
3540
EDIT_SetCaretPos(es,es->selection_end,es->flags & EF_AFTER_WRAP);
3541
EDIT_EM_ScrollCaret(es);
3542
return 0;
3543
}
3544
3545
3546
/*********************************************************************
3547
*
3548
* WM_PAINT
3549
*
3550
*/
3551
static void EDIT_WM_Paint(EDITSTATE *es, HDC hdc)
3552
{
3553
PAINTSTRUCT ps;
3554
INT i;
3555
HDC dc;
3556
HFONT old_font = 0;
3557
RECT rc;
3558
RECT rcClient;
3559
RECT rcLine;
3560
RECT rcRgn;
3561
HBRUSH brush;
3562
HBRUSH old_brush;
3563
INT bw, bh;
3564
BOOL rev = es->bEnableState &&
3565
((es->flags & EF_FOCUSED) ||
3566
(es->style & ES_NOHIDESEL));
3567
dc = hdc ? hdc : BeginPaint(es->hwndSelf, &ps);
3568
3569
/* The dc we use for calculating may not be the one we paint into.
3570
This is the safest action. */
3571
EDIT_InvalidateUniscribeData(es);
3572
GetClientRect(es->hwndSelf, &rcClient);
3573
3574
/* get the background brush */
3575
brush = EDIT_NotifyCtlColor(es, dc);
3576
3577
/* paint the border and the background */
3578
IntersectClipRect(dc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
3579
3580
if(es->style & WS_BORDER) {
3581
bw = GetSystemMetrics(SM_CXBORDER);
3582
bh = GetSystemMetrics(SM_CYBORDER);
3583
rc = rcClient;
3584
if(es->style & ES_MULTILINE) {
3585
if(es->style & WS_HSCROLL) rc.bottom+=bh;
3586
if(es->style & WS_VSCROLL) rc.right+=bw;
3587
}
3588
3589
/* Draw the frame. Same code as in nonclient.c */
3590
old_brush = SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
3591
PatBlt(dc, rc.left, rc.top, rc.right - rc.left, bh, PATCOPY);
3592
PatBlt(dc, rc.left, rc.top, bw, rc.bottom - rc.top, PATCOPY);
3593
PatBlt(dc, rc.left, rc.bottom - 1, rc.right - rc.left, -bw, PATCOPY);
3594
PatBlt(dc, rc.right - 1, rc.top, -bw, rc.bottom - rc.top, PATCOPY);
3595
SelectObject(dc, old_brush);
3596
3597
/* Keep the border clean */
3598
IntersectClipRect(dc, rc.left+bw, rc.top+bh,
3599
max(rc.right-bw, rc.left+bw), max(rc.bottom-bh, rc.top+bh));
3600
}
3601
3602
GetClipBox(dc, &rc);
3603
FillRect(dc, &rc, brush);
3604
3605
IntersectClipRect(dc, es->format_rect.left,
3606
es->format_rect.top,
3607
es->format_rect.right,
3608
es->format_rect.bottom);
3609
if (es->style & ES_MULTILINE) {
3610
rc = rcClient;
3611
IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
3612
}
3613
if (es->font)
3614
old_font = SelectObject(dc, es->font);
3615
3616
if (!es->bEnableState)
3617
SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
3618
GetClipBox(dc, &rcRgn);
3619
if (es->style & ES_MULTILINE) {
3620
INT vlc = get_vertical_line_count(es);
3621
for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
3622
EDIT_UpdateUniscribeData(es, dc, i);
3623
EDIT_GetLineRect(es, i, 0, -1, &rcLine);
3624
if (IntersectRect(&rc, &rcRgn, &rcLine))
3625
EDIT_PaintLine(es, dc, i, rev);
3626
}
3627
} else {
3628
EDIT_UpdateUniscribeData(es, dc, 0);
3629
EDIT_GetLineRect(es, 0, 0, -1, &rcLine);
3630
if (IntersectRect(&rc, &rcRgn, &rcLine))
3631
EDIT_PaintLine(es, dc, 0, rev);
3632
}
3633
if (es->font)
3634
SelectObject(dc, old_font);
3635
3636
if (!hdc)
3637
EndPaint(es->hwndSelf, &ps);
3638
}
3639
3640
static void EDIT_WM_NCPaint(HWND hwnd, HRGN region)
3641
{
3642
DWORD exStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
3643
HTHEME theme = GetWindowTheme(hwnd);
3644
HRGN cliprgn = region;
3645
3646
if (theme && exStyle & WS_EX_CLIENTEDGE)
3647
{
3648
HDC dc;
3649
RECT r;
3650
int cxEdge = GetSystemMetrics(SM_CXEDGE),
3651
cyEdge = GetSystemMetrics(SM_CYEDGE);
3652
const int part = EP_EDITTEXT;
3653
int state = ETS_NORMAL;
3654
DWORD dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
3655
3656
if (!IsWindowEnabled(hwnd))
3657
state = ETS_DISABLED;
3658
else if (dwStyle & ES_READONLY)
3659
state = ETS_READONLY;
3660
else if (GetFocus() == hwnd)
3661
state = ETS_FOCUSED;
3662
3663
GetWindowRect(hwnd, &r);
3664
3665
/* New clipping region passed to default proc to exclude border */
3666
cliprgn = CreateRectRgn(r.left + cxEdge, r.top + cyEdge,
3667
r.right - cxEdge, r.bottom - cyEdge);
3668
if (region != (HRGN)1)
3669
CombineRgn(cliprgn, cliprgn, region, RGN_AND);
3670
OffsetRect(&r, -r.left, -r.top);
3671
3672
dc = GetDCEx(hwnd, region, DCX_WINDOW|DCX_INTERSECTRGN);
3673
3674
if (IsThemeBackgroundPartiallyTransparent(theme, part, state))
3675
DrawThemeParentBackground(hwnd, dc, &r);
3676
DrawThemeBackground(theme, dc, part, state, &r, 0);
3677
ReleaseDC(hwnd, dc);
3678
}
3679
3680
/* Call default proc to get the scrollbars etc. also painted */
3681
DefWindowProcW (hwnd, WM_NCPAINT, (WPARAM)cliprgn, 0);
3682
if (cliprgn != region)
3683
DeleteObject(cliprgn);
3684
}
3685
3686
/*********************************************************************
3687
*
3688
* WM_SETFOCUS
3689
*
3690
*/
3691
static void EDIT_WM_SetFocus(HTHEME theme, EDITSTATE *es)
3692
{
3693
UINT flags = RDW_INVALIDATE;
3694
3695
es->flags |= EF_FOCUSED;
3696
3697
if (!(es->style & ES_NOHIDESEL))
3698
EDIT_InvalidateText(es, es->selection_start, es->selection_end);
3699
3700
CreateCaret(es->hwndSelf, 0, 1, es->line_height);
3701
EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
3702
ShowCaret(es->hwndSelf);
3703
if (!notify_parent(es, EN_SETFOCUS)) return;
3704
3705
if (theme)
3706
flags |= RDW_FRAME | RDW_ERASE;
3707
3708
RedrawWindow(es->hwndSelf, NULL, NULL, flags);
3709
}
3710
3711
3712
static DWORD get_font_margins(HDC hdc, const TEXTMETRICW *tm)
3713
{
3714
ABC abc[256];
3715
SHORT left, right;
3716
UINT i;
3717
3718
if (!(tm->tmPitchAndFamily & (TMPF_VECTOR | TMPF_TRUETYPE)))
3719
return MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO);
3720
3721
if (!is_cjk(hdc))
3722
return MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO);
3723
3724
if (!GetCharABCWidthsW(hdc, 0, 255, abc))
3725
return 0;
3726
3727
left = right = 0;
3728
for (i = 0; i < ARRAY_SIZE(abc); i++) {
3729
if (-abc[i].abcA > right) right = -abc[i].abcA;
3730
if (-abc[i].abcC > left ) left = -abc[i].abcC;
3731
}
3732
return MAKELONG(left, right);
3733
}
3734
3735
static void EDIT_UpdateImmCompositionFont(EDITSTATE *es)
3736
{
3737
LOGFONTW composition_font;
3738
HIMC himc = ImmGetContext(es->hwndSelf);
3739
GetObjectW(es->font, sizeof(LOGFONTW), &composition_font);
3740
ImmSetCompositionFontW(himc, &composition_font);
3741
ImmReleaseContext(es->hwndSelf, himc);
3742
}
3743
3744
/*********************************************************************
3745
*
3746
* WM_SETFONT
3747
*
3748
* With Win95 look the margins are set to default font value unless
3749
* the system font (font == 0) is being set, in which case they are left
3750
* unchanged.
3751
*
3752
*/
3753
static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
3754
{
3755
TEXTMETRICW tm;
3756
HDC dc;
3757
HFONT old_font = 0;
3758
RECT clientRect;
3759
DWORD margins;
3760
3761
es->font = font;
3762
EDIT_InvalidateUniscribeData(es);
3763
dc = GetDC(es->hwndSelf);
3764
if (font)
3765
old_font = SelectObject(dc, font);
3766
GetTextMetricsW(dc, &tm);
3767
es->line_height = tm.tmHeight;
3768
es->char_width = tm.tmAveCharWidth;
3769
margins = get_font_margins(dc, &tm);
3770
if (font)
3771
SelectObject(dc, old_font);
3772
ReleaseDC(es->hwndSelf, dc);
3773
3774
/* Reset the format rect and the margins */
3775
GetClientRect(es->hwndSelf, &clientRect);
3776
EDIT_SetRectNP(es, &clientRect);
3777
if (margins)
3778
EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
3779
LOWORD(margins), HIWORD(margins), FALSE);
3780
3781
if (es->style & ES_MULTILINE)
3782
EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL);
3783
else
3784
EDIT_CalcLineWidth_SL(es);
3785
3786
if (redraw)
3787
EDIT_UpdateText(es, NULL, TRUE);
3788
if (es->flags & EF_FOCUSED) {
3789
DestroyCaret();
3790
CreateCaret(es->hwndSelf, 0, 1, es->line_height);
3791
EDIT_SetCaretPos(es, es->selection_end,
3792
es->flags & EF_AFTER_WRAP);
3793
ShowCaret(es->hwndSelf);
3794
}
3795
3796
EDIT_UpdateImmCompositionFont(es);
3797
}
3798
3799
3800
/*********************************************************************
3801
*
3802
* WM_SETTEXT
3803
*
3804
* NOTES
3805
* For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
3806
* The modified flag is reset. No notifications are sent.
3807
*
3808
* For single-line controls, reception of WM_SETTEXT triggers:
3809
* The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
3810
*
3811
*/
3812
static void EDIT_WM_SetText(EDITSTATE *es, LPCWSTR text)
3813
{
3814
if (es->flags & EF_UPDATE)
3815
/* fixed this bug once; complain if we see it about to happen again. */
3816
ERR("SetSel may generate UPDATE message whose handler may reset "
3817
"selection.\n");
3818
3819
EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
3820
if (text)
3821
{
3822
TRACE("%s\n", debugstr_w(text));
3823
EDIT_EM_ReplaceSel(es, FALSE, text, lstrlenW(text), FALSE, FALSE);
3824
}
3825
else
3826
{
3827
TRACE("<NULL>\n");
3828
EDIT_EM_ReplaceSel(es, FALSE, NULL, 0, FALSE, FALSE);
3829
}
3830
es->x_offset = 0;
3831
es->flags &= ~EF_MODIFIED;
3832
EDIT_EM_SetSel(es, 0, 0, FALSE);
3833
3834
/* Send the notification after the selection start and end have been set
3835
* edit control doesn't send notification on WM_SETTEXT
3836
* if it is multiline, or it is part of combobox
3837
*/
3838
if( !((es->style & ES_MULTILINE) || es->hwndListBox))
3839
{
3840
if (!notify_parent(es, EN_UPDATE)) return;
3841
if (!notify_parent(es, EN_CHANGE)) return;
3842
}
3843
EDIT_EM_ScrollCaret(es);
3844
EDIT_UpdateScrollInfo(es);
3845
EDIT_InvalidateUniscribeData(es);
3846
NotifyWinEvent(EVENT_OBJECT_VALUECHANGE, es->hwndSelf, OBJID_CLIENT, 0);
3847
}
3848
3849
3850
/*********************************************************************
3851
*
3852
* WM_SIZE
3853
*
3854
*/
3855
static void EDIT_WM_Size(EDITSTATE *es, UINT action)
3856
{
3857
if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
3858
RECT rc;
3859
GetClientRect(es->hwndSelf, &rc);
3860
EDIT_SetRectNP(es, &rc);
3861
EDIT_UpdateText(es, NULL, TRUE);
3862
}
3863
}
3864
3865
3866
/*********************************************************************
3867
*
3868
* WM_STYLECHANGED
3869
*
3870
* This message is sent by SetWindowLong on having changed either the Style
3871
* or the extended style.
3872
*
3873
* We ensure that the window's version of the styles and the EDITSTATE's agree.
3874
*
3875
* See also EDIT_WM_NCCreate
3876
*
3877
* It appears that the Windows version of the edit control allows the style
3878
* (as retrieved by GetWindowLong) to be any value and maintains an internal
3879
* style variable which will generally be different. In this function we
3880
* update the internal style based on what changed in the externally visible
3881
* style.
3882
*
3883
* Much of this content as based upon the MSDN, especially:
3884
* Platform SDK Documentation -> User Interface Services ->
3885
* Windows User Interface -> Edit Controls -> Edit Control Reference ->
3886
* Edit Control Styles
3887
*/
3888
static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLESTRUCT *style)
3889
{
3890
if (GWL_STYLE == which) {
3891
DWORD style_change_mask;
3892
DWORD new_style;
3893
/* Only a subset of changes can be applied after the control
3894
* has been created.
3895
*/
3896
style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
3897
ES_NUMBER;
3898
if (es->style & ES_MULTILINE)
3899
style_change_mask |= ES_WANTRETURN;
3900
3901
new_style = style->styleNew & style_change_mask;
3902
3903
/* Number overrides lowercase overrides uppercase (at least it
3904
* does in Win95). However I'll bet that ES_NUMBER would be
3905
* invalid under Win 3.1.
3906
*/
3907
if (new_style & ES_NUMBER) {
3908
; /* do not override the ES_NUMBER */
3909
} else if (new_style & ES_LOWERCASE) {
3910
new_style &= ~ES_UPPERCASE;
3911
}
3912
3913
es->style = (es->style & ~style_change_mask) | new_style;
3914
} else if (GWL_EXSTYLE == which) {
3915
; /* FIXME - what is needed here */
3916
} else {
3917
WARN ("Invalid style change %#Ix.\n", which);
3918
}
3919
3920
return 0;
3921
}
3922
3923
/*********************************************************************
3924
*
3925
* WM_SYSKEYDOWN
3926
*
3927
*/
3928
static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data)
3929
{
3930
if ((key == VK_BACK) && (key_data & 0x2000)) {
3931
if (EDIT_EM_CanUndo(es))
3932
EDIT_EM_Undo(es);
3933
return 0;
3934
} else if (key == VK_UP || key == VK_DOWN) {
3935
if (EDIT_CheckCombo(es, WM_SYSKEYDOWN, key))
3936
return 0;
3937
}
3938
return DefWindowProcW(es->hwndSelf, WM_SYSKEYDOWN, key, key_data);
3939
}
3940
3941
/*********************************************************************
3942
*
3943
* WM_HSCROLL
3944
*
3945
*/
3946
static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos)
3947
{
3948
INT dx;
3949
INT fw;
3950
3951
if (!(es->style & ES_MULTILINE))
3952
return 0;
3953
3954
if (!(es->style & ES_AUTOHSCROLL))
3955
return 0;
3956
3957
dx = 0;
3958
fw = es->format_rect.right - es->format_rect.left;
3959
switch (action) {
3960
case SB_LINELEFT:
3961
TRACE("SB_LINELEFT\n");
3962
if (es->x_offset)
3963
dx = -es->char_width;
3964
break;
3965
case SB_LINERIGHT:
3966
TRACE("SB_LINERIGHT\n");
3967
if (es->x_offset < es->text_width)
3968
dx = es->char_width;
3969
break;
3970
case SB_PAGELEFT:
3971
TRACE("SB_PAGELEFT\n");
3972
if (es->x_offset)
3973
dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3974
break;
3975
case SB_PAGERIGHT:
3976
TRACE("SB_PAGERIGHT\n");
3977
if (es->x_offset < es->text_width)
3978
dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3979
break;
3980
case SB_LEFT:
3981
TRACE("SB_LEFT\n");
3982
if (es->x_offset)
3983
dx = -es->x_offset;
3984
break;
3985
case SB_RIGHT:
3986
TRACE("SB_RIGHT\n");
3987
if (es->x_offset < es->text_width)
3988
dx = es->text_width - es->x_offset;
3989
break;
3990
case SB_THUMBTRACK:
3991
TRACE("SB_THUMBTRACK %d\n", pos);
3992
es->flags |= EF_HSCROLL_TRACK;
3993
if(es->style & WS_HSCROLL)
3994
dx = pos - es->x_offset;
3995
else
3996
{
3997
INT fw, new_x;
3998
/* Sanity check */
3999
if(pos < 0 || pos > 100) return 0;
4000
/* Assume default scroll range 0-100 */
4001
fw = es->format_rect.right - es->format_rect.left;
4002
new_x = pos * (es->text_width - fw) / 100;
4003
dx = es->text_width ? (new_x - es->x_offset) : 0;
4004
}
4005
break;
4006
case SB_THUMBPOSITION:
4007
TRACE("SB_THUMBPOSITION %d\n", pos);
4008
es->flags &= ~EF_HSCROLL_TRACK;
4009
if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
4010
dx = pos - es->x_offset;
4011
else
4012
{
4013
INT fw, new_x;
4014
/* Sanity check */
4015
if(pos < 0 || pos > 100) return 0;
4016
/* Assume default scroll range 0-100 */
4017
fw = es->format_rect.right - es->format_rect.left;
4018
new_x = pos * (es->text_width - fw) / 100;
4019
dx = es->text_width ? (new_x - es->x_offset) : 0;
4020
}
4021
if (!dx) {
4022
/* force scroll info update */
4023
EDIT_UpdateScrollInfo(es);
4024
notify_parent(es, EN_HSCROLL);
4025
}
4026
break;
4027
case SB_ENDSCROLL:
4028
TRACE("SB_ENDSCROLL\n");
4029
break;
4030
/*
4031
* FIXME : the next two are undocumented !
4032
* Are we doing the right thing ?
4033
* At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4034
* although it's also a regular control message.
4035
*/
4036
case EM_GETTHUMB: /* this one is used by NT notepad */
4037
{
4038
LRESULT ret;
4039
if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
4040
ret = GetScrollPos(es->hwndSelf, SB_HORZ);
4041
else
4042
{
4043
/* Assume default scroll range 0-100 */
4044
INT fw = es->format_rect.right - es->format_rect.left;
4045
ret = es->text_width ? es->x_offset * 100 / (es->text_width - fw) : 0;
4046
}
4047
TRACE("EM_GETTHUMB: returning %Id\n", ret);
4048
return ret;
4049
}
4050
case EM_LINESCROLL:
4051
TRACE("EM_LINESCROLL16\n");
4052
dx = pos;
4053
break;
4054
4055
default:
4056
ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4057
action, action);
4058
return 0;
4059
}
4060
if (dx)
4061
{
4062
INT fw = es->format_rect.right - es->format_rect.left;
4063
/* check if we are going to move too far */
4064
if(es->x_offset + dx + fw > es->text_width)
4065
dx = es->text_width - fw - es->x_offset;
4066
if(dx)
4067
EDIT_EM_LineScroll_internal(es, dx, 0);
4068
}
4069
return 0;
4070
}
4071
4072
4073
/*********************************************************************
4074
*
4075
* WM_VSCROLL
4076
*
4077
*/
4078
static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos)
4079
{
4080
INT dy;
4081
4082
if (!(es->style & ES_MULTILINE))
4083
return 0;
4084
4085
if (!(es->style & ES_AUTOVSCROLL))
4086
return 0;
4087
4088
dy = 0;
4089
switch (action) {
4090
case SB_LINEUP:
4091
case SB_LINEDOWN:
4092
case SB_PAGEUP:
4093
case SB_PAGEDOWN:
4094
TRACE("action %d (%s)\n", action, (action == SB_LINEUP ? "SB_LINEUP" :
4095
(action == SB_LINEDOWN ? "SB_LINEDOWN" :
4096
(action == SB_PAGEUP ? "SB_PAGEUP" :
4097
"SB_PAGEDOWN"))));
4098
EDIT_EM_Scroll(es, action);
4099
return 0;
4100
case SB_TOP:
4101
TRACE("SB_TOP\n");
4102
dy = -es->y_offset;
4103
break;
4104
case SB_BOTTOM:
4105
TRACE("SB_BOTTOM\n");
4106
dy = es->line_count - 1 - es->y_offset;
4107
break;
4108
case SB_THUMBTRACK:
4109
TRACE("SB_THUMBTRACK %d\n", pos);
4110
es->flags |= EF_VSCROLL_TRACK;
4111
if(es->style & WS_VSCROLL)
4112
dy = pos - es->y_offset;
4113
else
4114
{
4115
/* Assume default scroll range 0-100 */
4116
INT vlc, new_y;
4117
/* Sanity check */
4118
if(pos < 0 || pos > 100) return 0;
4119
vlc = get_vertical_line_count(es);
4120
new_y = pos * (es->line_count - vlc) / 100;
4121
dy = es->line_count ? (new_y - es->y_offset) : 0;
4122
TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4123
es->line_count, es->y_offset, pos, dy);
4124
}
4125
break;
4126
case SB_THUMBPOSITION:
4127
TRACE("SB_THUMBPOSITION %d\n", pos);
4128
es->flags &= ~EF_VSCROLL_TRACK;
4129
if(es->style & WS_VSCROLL)
4130
dy = pos - es->y_offset;
4131
else
4132
{
4133
/* Assume default scroll range 0-100 */
4134
INT vlc, new_y;
4135
/* Sanity check */
4136
if(pos < 0 || pos > 100) return 0;
4137
vlc = get_vertical_line_count(es);
4138
new_y = pos * (es->line_count - vlc) / 100;
4139
dy = es->line_count ? (new_y - es->y_offset) : 0;
4140
TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4141
es->line_count, es->y_offset, pos, dy);
4142
}
4143
if (!dy)
4144
{
4145
/* force scroll info update */
4146
EDIT_UpdateScrollInfo(es);
4147
notify_parent(es, EN_VSCROLL);
4148
}
4149
break;
4150
case SB_ENDSCROLL:
4151
TRACE("SB_ENDSCROLL\n");
4152
break;
4153
/*
4154
* FIXME : the next two are undocumented !
4155
* Are we doing the right thing ?
4156
* At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4157
* although it's also a regular control message.
4158
*/
4159
case EM_GETTHUMB: /* this one is used by NT notepad */
4160
{
4161
LRESULT ret;
4162
if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_VSCROLL)
4163
ret = GetScrollPos(es->hwndSelf, SB_VERT);
4164
else
4165
{
4166
/* Assume default scroll range 0-100 */
4167
INT vlc = get_vertical_line_count(es);
4168
ret = es->line_count ? es->y_offset * 100 / (es->line_count - vlc) : 0;
4169
}
4170
TRACE("EM_GETTHUMB: returning %Id\n", ret);
4171
return ret;
4172
}
4173
case EM_LINESCROLL:
4174
TRACE("EM_LINESCROLL %d\n", pos);
4175
dy = pos;
4176
break;
4177
4178
default:
4179
ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4180
action, action);
4181
return 0;
4182
}
4183
if (dy)
4184
EDIT_EM_LineScroll(es, 0, dy);
4185
return 0;
4186
}
4187
4188
/*********************************************************************
4189
*
4190
* EM_GETTHUMB
4191
*
4192
* FIXME: is this right ? (or should it be only VSCROLL)
4193
* (and maybe only for edit controls that really have their
4194
* own scrollbars) (and maybe only for multiline controls ?)
4195
* All in all: very poorly documented
4196
*
4197
*/
4198
static LRESULT EDIT_EM_GetThumb(EDITSTATE *es)
4199
{
4200
return MAKELONG(EDIT_WM_VScroll(es, EM_GETTHUMB, 0),
4201
EDIT_WM_HScroll(es, EM_GETTHUMB, 0));
4202
}
4203
4204
/*********************************************************************
4205
*
4206
* EM_SETCUEBANNER
4207
*
4208
*/
4209
static BOOL EDIT_EM_SetCueBanner(EDITSTATE *es, BOOL draw_focused, const WCHAR *cue_text)
4210
{
4211
if (es->style & ES_MULTILINE || !cue_text)
4212
return FALSE;
4213
4214
Free(es->cue_banner_text);
4215
es->cue_banner_text = wcsdup(cue_text);
4216
es->cue_banner_draw_focused = draw_focused;
4217
4218
return TRUE;
4219
}
4220
4221
/*********************************************************************
4222
*
4223
* EM_GETCUEBANNER
4224
*
4225
*/
4226
static BOOL EDIT_EM_GetCueBanner(EDITSTATE *es, WCHAR *buf, DWORD size)
4227
{
4228
if (es->style & ES_MULTILINE)
4229
return FALSE;
4230
4231
if (!es->cue_banner_text)
4232
{
4233
if (buf && size)
4234
*buf = 0;
4235
return FALSE;
4236
}
4237
else
4238
{
4239
if (buf)
4240
lstrcpynW(buf, es->cue_banner_text, size);
4241
return TRUE;
4242
}
4243
}
4244
4245
4246
/********************************************************************
4247
*
4248
* The Following code is to handle inline editing from IMEs
4249
*/
4250
4251
static void EDIT_GetResultStr(HIMC hIMC, EDITSTATE *es)
4252
{
4253
LONG buflen;
4254
LPWSTR lpResultStr;
4255
4256
buflen = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, NULL, 0);
4257
if (buflen <= 0)
4258
{
4259
return;
4260
}
4261
4262
lpResultStr = Alloc(buflen);
4263
if (!lpResultStr)
4264
{
4265
ERR("Unable to alloc buffer for IME string\n");
4266
return;
4267
}
4268
4269
ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, lpResultStr, buflen);
4270
EDIT_EM_ReplaceSel(es, TRUE, lpResultStr, buflen / sizeof(WCHAR), TRUE, TRUE);
4271
Free(lpResultStr);
4272
}
4273
4274
static void EDIT_ImeComposition(HWND hwnd, LPARAM CompFlag, EDITSTATE *es)
4275
{
4276
HIMC hIMC;
4277
4278
hIMC = ImmGetContext(hwnd);
4279
if (!hIMC)
4280
return;
4281
4282
if (CompFlag & GCS_RESULTSTR)
4283
EDIT_GetResultStr(hIMC, es);
4284
4285
ImmReleaseContext(hwnd, hIMC);
4286
}
4287
4288
4289
/*********************************************************************
4290
*
4291
* WM_NCCREATE
4292
*
4293
* See also EDIT_WM_StyleChanged
4294
*/
4295
static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
4296
{
4297
EDITSTATE *es;
4298
UINT alloc_size;
4299
4300
TRACE("Creating edit control, style = %#lx\n", lpcs->style);
4301
4302
if (!(es = Alloc(sizeof(*es))))
4303
return FALSE;
4304
SetWindowLongPtrW( hwnd, 0, (LONG_PTR)es );
4305
4306
/*
4307
* Note: since the EDITSTATE has not been fully initialized yet,
4308
* we can't use any API calls that may send
4309
* WM_XXX messages before WM_NCCREATE is completed.
4310
*/
4311
4312
es->style = lpcs->style;
4313
4314
es->bEnableState = !(es->style & WS_DISABLED);
4315
4316
es->hwndSelf = hwnd;
4317
/* Save parent, which will be notified by EN_* messages */
4318
es->hwndParent = lpcs->hwndParent;
4319
4320
if (es->style & ES_COMBO)
4321
es->hwndListBox = GetDlgItem(es->hwndParent, ID_CB_LISTBOX);
4322
4323
/* FIXME: should we handle changes to WS_EX_RIGHT style after creation? */
4324
if (lpcs->dwExStyle & WS_EX_RIGHT) es->style |= ES_RIGHT;
4325
4326
/* Number overrides lowercase overrides uppercase (at least it
4327
* does in Win95). However I'll bet that ES_NUMBER would be
4328
* invalid under Win 3.1.
4329
*/
4330
if (es->style & ES_NUMBER) {
4331
; /* do not override the ES_NUMBER */
4332
} else if (es->style & ES_LOWERCASE) {
4333
es->style &= ~ES_UPPERCASE;
4334
}
4335
if (es->style & ES_MULTILINE) {
4336
es->buffer_limit = BUFLIMIT_INITIAL;
4337
if (es->style & WS_VSCROLL)
4338
es->style |= ES_AUTOVSCROLL;
4339
if (es->style & WS_HSCROLL)
4340
es->style |= ES_AUTOHSCROLL;
4341
es->style &= ~ES_PASSWORD;
4342
if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
4343
/* Confirmed - RIGHT overrides CENTER */
4344
if (es->style & ES_RIGHT)
4345
es->style &= ~ES_CENTER;
4346
es->style &= ~WS_HSCROLL;
4347
es->style &= ~ES_AUTOHSCROLL;
4348
}
4349
} else {
4350
es->buffer_limit = BUFLIMIT_INITIAL;
4351
if ((es->style & ES_RIGHT) && (es->style & ES_CENTER))
4352
es->style &= ~ES_CENTER;
4353
es->style &= ~WS_HSCROLL;
4354
es->style &= ~WS_VSCROLL;
4355
if (es->style & ES_PASSWORD)
4356
es->password_char = '*';
4357
}
4358
4359
alloc_size = ROUND_TO_GROW((es->buffer_size + 1) * sizeof(WCHAR));
4360
if(!(es->hloc32W = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
4361
goto cleanup;
4362
es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
4363
4364
if (!(es->undo_text = Alloc((es->buffer_size + 1) * sizeof(WCHAR))))
4365
goto cleanup;
4366
es->undo_buffer_size = es->buffer_size;
4367
4368
if (es->style & ES_MULTILINE)
4369
if (!(es->first_line_def = Alloc(sizeof(LINEDEF))))
4370
goto cleanup;
4371
es->line_count = 1;
4372
4373
/*
4374
* In Win95 look and feel, the WS_BORDER style is replaced by the
4375
* WS_EX_CLIENTEDGE style for the edit control. This gives the edit
4376
* control a nonclient area so we don't need to draw the border.
4377
* If WS_BORDER without WS_EX_CLIENTEDGE is specified we shouldn't have
4378
* a nonclient area and we should handle painting the border ourselves.
4379
*
4380
* When making modifications please ensure that the code still works
4381
* for edit controls created directly with style 0x50800000, exStyle 0
4382
* (which should have a single pixel border)
4383
*/
4384
if (lpcs->dwExStyle & WS_EX_CLIENTEDGE)
4385
es->style &= ~WS_BORDER;
4386
else if (es->style & WS_BORDER)
4387
SetWindowLongW(hwnd, GWL_STYLE, es->style & ~WS_BORDER);
4388
4389
return TRUE;
4390
4391
cleanup:
4392
SetWindowLongPtrW(es->hwndSelf, 0, 0);
4393
EDIT_InvalidateUniscribeData(es);
4394
Free(es->first_line_def);
4395
Free(es->undo_text);
4396
if (es->hloc32W) LocalFree(es->hloc32W);
4397
Free(es->logAttr);
4398
Free(es);
4399
return FALSE;
4400
}
4401
4402
4403
/*********************************************************************
4404
*
4405
* WM_CREATE
4406
*
4407
*/
4408
static LRESULT EDIT_WM_Create(EDITSTATE *es, const WCHAR *name)
4409
{
4410
RECT clientRect;
4411
4412
TRACE("%s\n", debugstr_w(name));
4413
4414
/*
4415
* To initialize some final structure members, we call some helper
4416
* functions. However, since the EDITSTATE is not consistent (i.e.
4417
* not fully initialized), we should be very careful which
4418
* functions can be called, and in what order.
4419
*/
4420
EDIT_WM_SetFont(es, 0, FALSE);
4421
EDIT_EM_EmptyUndoBuffer(es);
4422
4423
/* We need to calculate the format rect
4424
(applications may send EM_SETMARGINS before the control gets visible) */
4425
GetClientRect(es->hwndSelf, &clientRect);
4426
EDIT_SetRectNP(es, &clientRect);
4427
4428
if (name && *name)
4429
{
4430
EDIT_EM_ReplaceSel(es, FALSE, name, lstrlenW(name), FALSE, FALSE);
4431
/* if we insert text to the editline, the text scrolls out
4432
* of the window, as the caret is placed after the insert
4433
* pos normally; thus we reset es->selection... to 0 and
4434
* update caret
4435
*/
4436
es->selection_start = es->selection_end = 0;
4437
/* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
4438
* Messages are only to be sent when the USER does something to
4439
* change the contents. So I am removing this EN_CHANGE
4440
*
4441
* EDIT_NOTIFY_PARENT(es, EN_CHANGE);
4442
*/
4443
EDIT_EM_ScrollCaret(es);
4444
}
4445
4446
/* force scroll info update */
4447
EDIT_UpdateScrollInfo(es);
4448
OpenThemeData(es->hwndSelf, WC_EDITW);
4449
4450
/* The rule seems to return 1 here for success */
4451
/* Power Builder masked edit controls will crash */
4452
/* if not. */
4453
/* FIXME: is that in all cases so ? */
4454
return 1;
4455
}
4456
4457
4458
/*********************************************************************
4459
*
4460
* WM_NCDESTROY
4461
*
4462
*/
4463
static LRESULT EDIT_WM_NCDestroy(EDITSTATE *es)
4464
{
4465
LINEDEF *pc, *pp;
4466
HTHEME theme;
4467
4468
theme = GetWindowTheme(es->hwndSelf);
4469
CloseThemeData(theme);
4470
4471
/* The app can own the text buffer handle */
4472
if (es->hloc32W && (es->hloc32W != es->hlocapp))
4473
LocalFree(es->hloc32W);
4474
4475
EDIT_InvalidateUniscribeData(es);
4476
4477
pc = es->first_line_def;
4478
while (pc)
4479
{
4480
pp = pc->next;
4481
Free(pc);
4482
pc = pp;
4483
}
4484
4485
SetWindowLongPtrW( es->hwndSelf, 0, 0 );
4486
Free(es->undo_text);
4487
Free(es->cue_banner_text);
4488
Free(es);
4489
4490
return 0;
4491
}
4492
4493
static LRESULT CALLBACK EDIT_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
4494
{
4495
EDITSTATE *es = (EDITSTATE *)GetWindowLongPtrW(hwnd, 0);
4496
LRESULT result = 0;
4497
RECT *rect;
4498
POINT pt;
4499
4500
TRACE("hwnd %p, msg %#x, wparam %Ix, lparam %Ix\n", hwnd, msg, wParam, lParam);
4501
4502
if (!es && msg != WM_NCCREATE)
4503
return DefWindowProcW(hwnd, msg, wParam, lParam);
4504
4505
if (es && (msg != WM_NCDESTROY))
4506
EDIT_LockBuffer(es);
4507
4508
switch (msg)
4509
{
4510
case EM_GETSEL:
4511
result = EDIT_EM_GetSel(es, (UINT *)wParam, (UINT *)lParam);
4512
break;
4513
4514
case EM_SETSEL:
4515
EDIT_EM_SetSel(es, wParam, lParam, FALSE);
4516
EDIT_EM_ScrollCaret(es);
4517
result = 1;
4518
break;
4519
4520
case EM_GETRECT:
4521
rect = (RECT *)lParam;
4522
if (rect)
4523
*rect = es->format_rect;
4524
break;
4525
4526
case EM_SETRECT:
4527
if ((es->style & ES_MULTILINE) && lParam)
4528
{
4529
EDIT_SetRectNP(es, (RECT *)lParam);
4530
EDIT_UpdateText(es, NULL, TRUE);
4531
}
4532
break;
4533
4534
case EM_SETRECTNP:
4535
if ((es->style & ES_MULTILINE) && lParam)
4536
EDIT_SetRectNP(es, (LPRECT)lParam);
4537
break;
4538
4539
case EM_SCROLL:
4540
result = EDIT_EM_Scroll(es, (INT)wParam);
4541
break;
4542
4543
case EM_LINESCROLL:
4544
result = (LRESULT)EDIT_EM_LineScroll(es, (INT)wParam, (INT)lParam);
4545
break;
4546
4547
case EM_SCROLLCARET:
4548
EDIT_EM_ScrollCaret(es);
4549
result = 1;
4550
break;
4551
4552
case EM_GETMODIFY:
4553
result = ((es->flags & EF_MODIFIED) != 0);
4554
break;
4555
4556
case EM_SETMODIFY:
4557
if (wParam)
4558
es->flags |= EF_MODIFIED;
4559
else
4560
es->flags &= ~(EF_MODIFIED | EF_UPDATE); /* reset pending updates */
4561
break;
4562
4563
case EM_GETLINECOUNT:
4564
result = (es->style & ES_MULTILINE) ? es->line_count : 1;
4565
break;
4566
4567
case EM_LINEINDEX:
4568
result = (LRESULT)EDIT_EM_LineIndex(es, (INT)wParam);
4569
break;
4570
4571
case EM_SETHANDLE:
4572
EDIT_EM_SetHandle(es, (HLOCAL)wParam);
4573
break;
4574
4575
case EM_GETHANDLE:
4576
result = (LRESULT)EDIT_EM_GetHandle(es);
4577
break;
4578
4579
case EM_GETTHUMB:
4580
result = EDIT_EM_GetThumb(es);
4581
break;
4582
4583
/* these messages missing from specs */
4584
case 0x00bf:
4585
case 0x00c0:
4586
case 0x00c3:
4587
case 0x00ca:
4588
FIXME("undocumented message 0x%x, please report\n", msg);
4589
result = DefWindowProcW(hwnd, msg, wParam, lParam);
4590
break;
4591
4592
case EM_LINELENGTH:
4593
result = (LRESULT)EDIT_EM_LineLength(es, (INT)wParam);
4594
break;
4595
4596
case EM_REPLACESEL:
4597
{
4598
const WCHAR *textW = (const WCHAR *)lParam;
4599
4600
EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, lstrlenW(textW), TRUE, TRUE);
4601
result = 1;
4602
break;
4603
}
4604
4605
case EM_GETLINE:
4606
result = (LRESULT)EDIT_EM_GetLine(es, (INT)wParam, (LPWSTR)lParam);
4607
break;
4608
4609
case EM_SETLIMITTEXT:
4610
EDIT_EM_SetLimitText(es, wParam);
4611
break;
4612
4613
case EM_CANUNDO:
4614
result = (LRESULT)EDIT_EM_CanUndo(es);
4615
break;
4616
4617
case EM_UNDO:
4618
case WM_UNDO:
4619
result = (LRESULT)EDIT_EM_Undo(es);
4620
break;
4621
4622
case EM_FMTLINES:
4623
result = (LRESULT)EDIT_EM_FmtLines(es, (BOOL)wParam);
4624
break;
4625
4626
case EM_LINEFROMCHAR:
4627
result = (LRESULT)EDIT_EM_LineFromChar(es, (INT)wParam);
4628
break;
4629
4630
case EM_SETTABSTOPS:
4631
result = (LRESULT)EDIT_EM_SetTabStops(es, (INT)wParam, (LPINT)lParam);
4632
break;
4633
4634
case EM_SETPASSWORDCHAR:
4635
EDIT_EM_SetPasswordChar(es, wParam);
4636
break;
4637
4638
case EM_EMPTYUNDOBUFFER:
4639
EDIT_EM_EmptyUndoBuffer(es);
4640
break;
4641
4642
case EM_GETFIRSTVISIBLELINE:
4643
result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
4644
break;
4645
4646
case EM_SETREADONLY:
4647
{
4648
DWORD old_style = es->style;
4649
4650
if (wParam)
4651
{
4652
SetWindowLongW(hwnd, GWL_STYLE, GetWindowLongW(hwnd, GWL_STYLE) | ES_READONLY);
4653
es->style |= ES_READONLY;
4654
}
4655
else
4656
{
4657
SetWindowLongW(hwnd, GWL_STYLE, GetWindowLongW(hwnd, GWL_STYLE) & ~ES_READONLY);
4658
es->style &= ~ES_READONLY;
4659
}
4660
4661
if (old_style ^ es->style)
4662
InvalidateRect(es->hwndSelf, NULL, TRUE);
4663
4664
result = 1;
4665
break;
4666
}
4667
4668
case EM_SETWORDBREAKPROC:
4669
EDIT_EM_SetWordBreakProc(es, (void *)lParam);
4670
result = 1;
4671
break;
4672
4673
case EM_GETWORDBREAKPROC:
4674
result = (LRESULT)es->word_break_proc;
4675
break;
4676
4677
case EM_GETPASSWORDCHAR:
4678
result = es->password_char;
4679
break;
4680
4681
case EM_SETMARGINS:
4682
EDIT_EM_SetMargins(es, (INT)wParam, LOWORD(lParam), HIWORD(lParam), TRUE);
4683
break;
4684
4685
case EM_GETMARGINS:
4686
result = MAKELONG(es->left_margin, es->right_margin);
4687
break;
4688
4689
case EM_GETLIMITTEXT:
4690
result = es->buffer_limit;
4691
break;
4692
4693
case EM_POSFROMCHAR:
4694
if ((INT)wParam >= get_text_length(es)) result = -1;
4695
else result = EDIT_EM_PosFromChar(es, (INT)wParam, FALSE);
4696
break;
4697
4698
case EM_CHARFROMPOS:
4699
result = EDIT_EM_CharFromPos(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
4700
break;
4701
4702
case EM_SETCUEBANNER:
4703
result = EDIT_EM_SetCueBanner(es, (BOOL)wParam, (const WCHAR *)lParam);
4704
break;
4705
4706
case EM_GETCUEBANNER:
4707
result = EDIT_EM_GetCueBanner(es, (WCHAR *)wParam, (DWORD)lParam);
4708
break;
4709
4710
case EM_SETIMESTATUS:
4711
if (wParam == EMSIS_COMPOSITIONSTRING)
4712
es->ime_status = lParam & 0xFFFF;
4713
4714
result = 1;
4715
break;
4716
4717
case EM_GETIMESTATUS:
4718
result = wParam == EMSIS_COMPOSITIONSTRING ? es->ime_status : 1;
4719
break;
4720
4721
/* End of the EM_ messages which were in numerical order; what order
4722
* are these in? vaguely alphabetical?
4723
*/
4724
4725
case WM_NCCREATE:
4726
result = EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTW)lParam);
4727
break;
4728
4729
case WM_NCDESTROY:
4730
result = EDIT_WM_NCDestroy(es);
4731
es = NULL;
4732
break;
4733
4734
case WM_GETDLGCODE:
4735
result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
4736
4737
if (es->style & ES_MULTILINE)
4738
result |= DLGC_WANTALLKEYS;
4739
4740
if (lParam)
4741
{
4742
MSG *msg = (MSG *)lParam;
4743
es->flags |= EF_DIALOGMODE;
4744
4745
if (msg->message == WM_KEYDOWN)
4746
{
4747
int vk = (int)msg->wParam;
4748
4749
if (es->hwndListBox)
4750
{
4751
if (vk == VK_RETURN || vk == VK_ESCAPE)
4752
if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
4753
result |= DLGC_WANTMESSAGE;
4754
}
4755
}
4756
}
4757
break;
4758
4759
case WM_CHAR:
4760
{
4761
WCHAR charW = wParam;
4762
4763
if (es->hwndListBox)
4764
{
4765
if (charW == VK_RETURN || charW == VK_ESCAPE)
4766
{
4767
if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
4768
SendMessageW(GetParent(hwnd), WM_KEYDOWN, charW, 0);
4769
break;
4770
}
4771
}
4772
result = EDIT_WM_Char(es, charW);
4773
break;
4774
}
4775
4776
case WM_UNICHAR:
4777
if (wParam == UNICODE_NOCHAR) return TRUE;
4778
if (wParam <= 0x000fffff)
4779
{
4780
if (wParam > 0xffff) /* convert to surrogates */
4781
{
4782
wParam -= 0x10000;
4783
EDIT_WM_Char(es, (wParam >> 10) + 0xd800);
4784
EDIT_WM_Char(es, (wParam & 0x03ff) + 0xdc00);
4785
}
4786
else
4787
EDIT_WM_Char(es, wParam);
4788
}
4789
return 0;
4790
4791
case WM_CLEAR:
4792
EDIT_WM_Clear(es);
4793
break;
4794
4795
case WM_CONTEXTMENU:
4796
EDIT_WM_ContextMenu(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
4797
break;
4798
4799
case WM_COPY:
4800
EDIT_WM_Copy(es);
4801
break;
4802
4803
case WM_CREATE:
4804
result = EDIT_WM_Create(es, ((LPCREATESTRUCTW)lParam)->lpszName);
4805
break;
4806
4807
case WM_CUT:
4808
EDIT_WM_Cut(es);
4809
break;
4810
4811
case WM_ENABLE:
4812
es->bEnableState = (BOOL) wParam;
4813
EDIT_UpdateText(es, NULL, TRUE);
4814
if (GetWindowTheme(hwnd))
4815
RedrawWindow(hwnd, NULL, NULL, RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
4816
break;
4817
4818
case WM_ERASEBKGND:
4819
/* we do the proper erase in EDIT_WM_Paint */
4820
result = 1;
4821
break;
4822
4823
case WM_GETFONT:
4824
result = (LRESULT)es->font;
4825
break;
4826
4827
case WM_GETOBJECT:
4828
if ((LONG)lParam == OBJID_QUERYCLASSNAMEIDX)
4829
return 0x10004;
4830
break;
4831
4832
case WM_GETTEXT:
4833
result = (LRESULT)EDIT_WM_GetText(es, (INT)wParam, (LPWSTR)lParam);
4834
break;
4835
4836
case WM_GETTEXTLENGTH:
4837
result = get_text_length(es);
4838
break;
4839
4840
case WM_HSCROLL:
4841
result = EDIT_WM_HScroll(es, LOWORD(wParam), (short)HIWORD(wParam));
4842
break;
4843
4844
case WM_KEYDOWN:
4845
result = EDIT_WM_KeyDown(es, (INT)wParam);
4846
break;
4847
4848
case WM_KILLFOCUS:
4849
result = EDIT_WM_KillFocus(GetWindowTheme(hwnd), es);
4850
break;
4851
4852
case WM_LBUTTONDBLCLK:
4853
result = EDIT_WM_LButtonDblClk(es);
4854
break;
4855
4856
case WM_LBUTTONDOWN:
4857
result = EDIT_WM_LButtonDown(es, wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
4858
break;
4859
4860
case WM_LBUTTONUP:
4861
result = EDIT_WM_LButtonUp(es);
4862
break;
4863
4864
case WM_MBUTTONDOWN:
4865
result = EDIT_WM_MButtonDown(es);
4866
break;
4867
4868
case WM_MOUSEMOVE:
4869
result = EDIT_WM_MouseMove(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
4870
break;
4871
4872
case WM_PRINTCLIENT:
4873
case WM_PAINT:
4874
EDIT_WM_Paint(es, (HDC)wParam);
4875
break;
4876
4877
case WM_NCPAINT:
4878
EDIT_WM_NCPaint(hwnd, (HRGN)wParam);
4879
break;
4880
4881
case WM_PASTE:
4882
EDIT_WM_Paste(es);
4883
break;
4884
4885
case WM_SETFOCUS:
4886
EDIT_WM_SetFocus(GetWindowTheme(hwnd), es);
4887
break;
4888
4889
case WM_SETFONT:
4890
EDIT_WM_SetFont(es, (HFONT)wParam, LOWORD(lParam) != 0);
4891
break;
4892
4893
case WM_SETREDRAW:
4894
/* FIXME: actually set an internal flag and behave accordingly */
4895
break;
4896
4897
case WM_SETTEXT:
4898
EDIT_WM_SetText(es, (const WCHAR *)lParam);
4899
result = TRUE;
4900
break;
4901
4902
case WM_SIZE:
4903
EDIT_WM_Size(es, (UINT)wParam);
4904
break;
4905
4906
case WM_STYLECHANGED:
4907
result = EDIT_WM_StyleChanged(es, wParam, (const STYLESTRUCT *)lParam);
4908
break;
4909
4910
case WM_STYLECHANGING:
4911
result = 0; /* See EDIT_WM_StyleChanged */
4912
break;
4913
4914
case WM_SYSKEYDOWN:
4915
result = EDIT_WM_SysKeyDown(es, (INT)wParam, (DWORD)lParam);
4916
break;
4917
4918
case WM_VSCROLL:
4919
result = EDIT_WM_VScroll(es, LOWORD(wParam), (short)HIWORD(wParam));
4920
break;
4921
4922
case WM_CAPTURECHANGED:
4923
es->bCaptureState = FALSE;
4924
break;
4925
4926
case WM_MOUSEWHEEL:
4927
{
4928
int wheelDelta;
4929
INT pulScrollLines = 3;
4930
SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
4931
4932
if (wParam & (MK_SHIFT | MK_CONTROL))
4933
{
4934
result = DefWindowProcW(hwnd, msg, wParam, lParam);
4935
break;
4936
}
4937
4938
wheelDelta = GET_WHEEL_DELTA_WPARAM(wParam);
4939
/* if scrolling changes direction, ignore left overs */
4940
if ((wheelDelta < 0 && es->wheelDeltaRemainder < 0) ||
4941
(wheelDelta > 0 && es->wheelDeltaRemainder > 0))
4942
es->wheelDeltaRemainder += wheelDelta;
4943
else
4944
es->wheelDeltaRemainder = wheelDelta;
4945
4946
if (es->wheelDeltaRemainder && pulScrollLines)
4947
{
4948
int cLineScroll;
4949
pulScrollLines = min(es->line_count, pulScrollLines);
4950
cLineScroll = pulScrollLines * es->wheelDeltaRemainder / WHEEL_DELTA;
4951
es->wheelDeltaRemainder -= WHEEL_DELTA * cLineScroll / pulScrollLines;
4952
result = EDIT_EM_LineScroll(es, 0, -cLineScroll);
4953
}
4954
break;
4955
}
4956
4957
/* IME messages to make the edit control IME aware */
4958
case WM_IME_SETCONTEXT:
4959
GetCaretPos(&pt);
4960
EDIT_UpdateImmCompositionWindow(es, pt.x, pt.y);
4961
EDIT_UpdateImmCompositionFont(es);
4962
break;
4963
4964
case WM_IME_COMPOSITION:
4965
EDIT_EM_ReplaceSel(es, TRUE, NULL, 0, TRUE, TRUE);
4966
if ((lParam & GCS_RESULTSTR) && (es->ime_status & EIMES_GETCOMPSTRATONCE))
4967
EDIT_ImeComposition(hwnd, lParam, es);
4968
return DefWindowProcW(hwnd, msg, wParam, lParam);
4969
4970
case WM_IME_SELECT:
4971
break;
4972
4973
case WM_IME_CONTROL:
4974
break;
4975
4976
case WM_IME_REQUEST:
4977
switch (wParam)
4978
{
4979
case IMR_QUERYCHARPOSITION:
4980
{
4981
IMECHARPOSITION *chpos = (IMECHARPOSITION *)lParam;
4982
LRESULT pos;
4983
4984
pos = EDIT_EM_PosFromChar(es, es->selection_start + chpos->dwCharPos, FALSE);
4985
chpos->pt.x = LOWORD(pos);
4986
chpos->pt.y = HIWORD(pos);
4987
chpos->cLineHeight = es->line_height;
4988
chpos->rcDocument = es->format_rect;
4989
MapWindowPoints(hwnd, 0, &chpos->pt, 1);
4990
MapWindowPoints(hwnd, 0, (POINT*)&chpos->rcDocument, 2);
4991
result = 1;
4992
break;
4993
}
4994
}
4995
break;
4996
4997
case WM_THEMECHANGED:
4998
CloseThemeData(GetWindowTheme(hwnd));
4999
OpenThemeData(hwnd, WC_EDITW);
5000
InvalidateRect(hwnd, NULL, TRUE);
5001
break;
5002
5003
default:
5004
result = DefWindowProcW(hwnd, msg, wParam, lParam);
5005
break;
5006
}
5007
5008
if (IsWindow(hwnd) && es && msg != EM_GETHANDLE)
5009
EDIT_UnlockBuffer(es, FALSE);
5010
5011
TRACE("hwnd=%p msg=%x -- %#Ix\n", hwnd, msg, result);
5012
5013
return result;
5014
}
5015
5016
void EDIT_Register(void)
5017
{
5018
WNDCLASSW wndClass;
5019
5020
memset(&wndClass, 0, sizeof(wndClass));
5021
wndClass.style = CS_PARENTDC | CS_GLOBALCLASS | CS_DBLCLKS;
5022
wndClass.lpfnWndProc = EDIT_WindowProc;
5023
wndClass.cbClsExtra = 0;
5024
#ifdef __i386__
5025
wndClass.cbWndExtra = sizeof(EDITSTATE *) + sizeof(WORD);
5026
#else
5027
wndClass.cbWndExtra = sizeof(EDITSTATE *);
5028
#endif
5029
wndClass.hCursor = LoadCursorW(0, (LPWSTR)IDC_IBEAM);
5030
wndClass.hbrBackground = NULL;
5031
wndClass.lpszClassName = WC_EDITW;
5032
RegisterClassW(&wndClass);
5033
}
5034
5035