source: trunk/src/user32/edit.c@ 9523

Last change on this file since 9523 was 9523, checked in by sandervl, 23 years ago

removed obsolete files

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