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

Last change on this file since 10607 was 10607, checked in by sandervl, 21 years ago

KOM: Updates

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