blob: 7e32b57890df51cf91dfd502ac95d2193eea7388 [file] [log] [blame]
Alexandre Julliard58199531994-04-21 01:20:00 +00001/*
Alexandre Julliard329f0681996-04-14 13:21:20 +00002 * Edit control
Alexandre Julliard58199531994-04-21 01:20:00 +00003 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
Alexandre Julliardc6c09441997-01-12 18:32:19 +00006 * Copyright Frans van Dorsselaer, 1996, 1997
Alexandre Julliard58199531994-04-21 01:20:00 +00007 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00008 */
9
10/*
Alexandre Julliardc6c09441997-01-12 18:32:19 +000011 * please read EDIT.TODO (and update it when you change things)
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000012 */
Alexandre Julliard58199531994-04-21 01:20:00 +000013
Alexandre Julliardaca05781994-10-17 18:12:41 +000014#include <stdio.h>
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000015#include "windows.h"
Alexandre Julliard889f7421997-04-15 17:19:52 +000016#include "winnt.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000017#include "win.h"
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000018#include "combo.h"
Alexandre Julliard329f0681996-04-14 13:21:20 +000019#include "local.h"
Alexandre Julliard01d63461997-01-20 19:43:45 +000020#include "resource.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000021#include "stddebug.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000022#include "debug.h"
Alexandre Julliard02ed4c21996-03-02 19:34:10 +000023#include "callback.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000024
Alexandre Julliard889f7421997-04-15 17:19:52 +000025#define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
26 FIXME: BTW, new specs say 65535 (do you dare ???) */
27#define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
28#define BUFSTART_MULTI 1024 /* starting size */
29#define BUFSTART_SINGLE 256 /* starting size */
Alexandre Julliard329f0681996-04-14 13:21:20 +000030#define GROWLENGTH 64 /* buffers grow by this much */
31#define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
Alexandre Julliard58199531994-04-21 01:20:00 +000032
Alexandre Julliard889f7421997-04-15 17:19:52 +000033/*
34 * extra flags for EDITSTATE.flags field
35 */
36#define EF_MODIFIED 0x0001 /* text has been modified */
37#define EF_FOCUSED 0x0002 /* we have input focus */
38#define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
39#define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
40#define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
41#define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
42#define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
43#define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
44 wrapped line, instead of in front of the next character */
45
46typedef BOOL32 *LPBOOL32;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000047
Alexandre Julliard329f0681996-04-14 13:21:20 +000048typedef enum
49{
Alexandre Julliard889f7421997-04-15 17:19:52 +000050 END_0 = 0, /* line ends with terminating '\0' character */
51 END_WRAP, /* line is wrapped */
52 END_HARD, /* line ends with a hard return '\r\n' */
53 END_SOFT, /* line ends with a soft return '\r\r\n' */
Alexandre Julliard329f0681996-04-14 13:21:20 +000054} LINE_END;
55
Alexandre Julliard889f7421997-04-15 17:19:52 +000056typedef struct tagLINEDEF {
57 INT32 length; /* bruto length of a line in bytes */
58 INT32 net_length; /* netto length of a line in visible characters */
Alexandre Julliard329f0681996-04-14 13:21:20 +000059 LINE_END ending;
Alexandre Julliard889f7421997-04-15 17:19:52 +000060 INT32 width; /* width of the line in pixels */
61 struct tagLINEDEF *next;
Alexandre Julliard329f0681996-04-14 13:21:20 +000062} LINEDEF;
Alexandre Julliard58199531994-04-21 01:20:00 +000063
Alexandre Julliard58199531994-04-21 01:20:00 +000064typedef struct
65{
Alexandre Julliard889f7421997-04-15 17:19:52 +000066 HANDLE32 heap; /* our own heap */
67 LPSTR text; /* the actual contents of the control */
68 INT32 buffer_size; /* the size of the buffer */
69 INT32 buffer_limit; /* the maximum size to which the buffer may grow */
70 HFONT32 font; /* NULL means standard system font */
71 INT32 x_offset; /* scroll offset for multi lines this is in pixels
72 for single lines it's in characters */
73 INT32 line_height; /* height of a screen line in pixels */
74 INT32 char_width; /* average character width in pixels */
75 DWORD style; /* sane version of wnd->dwStyle */
76 WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
77 INT32 undo_insert_count; /* number of characters inserted in sequence */
78 INT32 undo_position; /* character index of the insertion and deletion */
79 LPSTR undo_text; /* deleted text */
80 INT32 undo_buffer_size; /* size of the deleted text buffer */
81 INT32 selection_start; /* == selection_end if no selection */
82 INT32 selection_end; /* == current caret position */
83 CHAR password_char; /* == 0 if no password char, and for multi line controls */
84 INT32 left_margin; /* in pixels */
85 INT32 right_margin; /* in pixels */
86 RECT32 format_rect;
87 EDITWORDBREAKPROC16 word_break_proc16;
88 EDITWORDBREAKPROC32A word_break_proc32A;
89 INT32 line_count; /* number of lines */
90 INT32 y_offset; /* scroll offset in number of lines */
Alexandre Julliardc6c09441997-01-12 18:32:19 +000091 /*
Alexandre Julliard889f7421997-04-15 17:19:52 +000092 * only for multi line controls
Alexandre Julliardc6c09441997-01-12 18:32:19 +000093 */
Alexandre Julliard889f7421997-04-15 17:19:52 +000094 INT32 lock_count; /* amount of re-entries in the EditWndProc */
95 INT32 tabs_count;
96 LPINT32 tabs;
97 INT32 text_width; /* width of the widest line in pixels */
98 LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
99 HLOCAL16 hloc16; /* for controls receiving EM_GETHANDLE16 */
100 HLOCAL32 hloc32; /* for controls receiving EM_GETHANDLE */
Alexandre Julliard58199531994-04-21 01:20:00 +0000101} EDITSTATE;
102
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000103
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000104#define SWAP_INT32(x,y) do { INT32 temp = (INT32)(x); (x) = (INT32)(y); (y) = temp; } while(0)
105#define ORDER_INT32(x,y) do { if ((INT32)(y) < (INT32)(x)) SWAP_INT32((x),(y)); } while(0)
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000106
Alexandre Julliard889f7421997-04-15 17:19:52 +0000107#define SWAP_UINT32(x,y) do { UINT32 temp = (UINT32)(x); (x) = (UINT32)(y); (y) = temp; } while(0)
108#define ORDER_UINT32(x,y) do { if ((UINT32)(y) < (UINT32)(x)) SWAP_UINT32((x),(y)); } while(0)
Alexandre Julliard58199531994-04-21 01:20:00 +0000109
Alexandre Julliard889f7421997-04-15 17:19:52 +0000110#define DPRINTF_EDIT_NOTIFY(hwnd, str) \
111 ({dprintf_edit(stddeb, \
112 "edit: notification " str " sent to hwnd=%08x\n", \
113 (UINT32)(hwnd));})
Alexandre Julliard58199531994-04-21 01:20:00 +0000114
Alexandre Julliard889f7421997-04-15 17:19:52 +0000115#define EDIT_SEND_CTLCOLOR(wnd,hdc) \
116 (SendMessage32A((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \
117 (WPARAM32)(hdc), (LPARAM)(wnd)->hwndSelf))
118#define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \
119 (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \
120 SendMessage32A((wnd)->parent->hwndSelf, WM_COMMAND, \
121 MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \
122 (LPARAM)(wnd)->hwndSelf))
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000123#define DPRINTF_EDIT_MSG16(str) \
Alexandre Julliard889f7421997-04-15 17:19:52 +0000124 dprintf_edit(stddeb, \
125 "edit: 16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
126 (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000127#define DPRINTF_EDIT_MSG32(str) \
Alexandre Julliard889f7421997-04-15 17:19:52 +0000128 dprintf_edit(stddeb, \
129 "edit: 32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \
130 (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam)
131
Alexandre Julliardca22b331996-07-12 19:02:39 +0000132
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000133/*********************************************************************
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000134 *
Alexandre Julliard329f0681996-04-14 13:21:20 +0000135 * Declarations
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000136 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000137 */
138
139/*
140 * These functions have trivial implementations
141 * We still like to call them internally
142 * "static __inline__" makes them more like macro's
143 */
144static __inline__ BOOL32 EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es);
145static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es);
146static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es);
147static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es);
148/*
149 * This is the only exported function
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000150 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000151LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg,
152 WPARAM32 wParam, LPARAM lParam );
Alexandre Julliard889f7421997-04-15 17:19:52 +0000153/*
154 * Helper functions only valid for one type of control
155 */
156static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es);
157static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es);
158static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend);
159static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend);
160static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend);
161static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend);
162/*
163 * Helper functions valid for both single line _and_ multi line controls
164 */
165static INT32 EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT32 start, INT32 index, INT32 count, INT32 action);
166static INT32 EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y, LPBOOL32 after_wrap);
167static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT32 x, LPINT32 y);
168static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT32 line, INT32 scol, INT32 ecol, LPRECT32 rc);
169static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end);
170static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es);
171static BOOL32 EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT32 size);
172static BOOL32 EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT32 size);
173static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL32 extend);
174static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL32 extend);
175static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL32 extend);
176static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL32 extend);
177static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL32 extend);
178static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL32 extend);
179static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC32 hdc, INT32 line, BOOL32 rev);
180static INT32 EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC32 hdc, INT32 x, INT32 y, INT32 line, INT32 col, INT32 count, BOOL32 rev);
181static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT32 lprc);
182static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL32 force);
183static INT32 EDIT_WordBreakProc(LPSTR s, INT32 index, INT32 count, INT32 action);
184/*
185 * EM_XXX message handlers
186 */
187static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y);
188static BOOL32 EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL32 add_eol);
189static HLOCAL32 EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es);
190static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es);
191static INT32 EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT32 line, LPSTR lpch);
192static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT32 start, LPUINT32 end);
193static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es);
194static INT32 EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT32 index);
195static INT32 EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT32 line);
196static INT32 EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT32 index);
197static BOOL32 EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT32 dx, INT32 dy);
198static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT32 index, BOOL32 after_wrap);
199static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL32 can_undo, LPCSTR lpsz_replace);
200static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT32 action);
201static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es);
202static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL32 hloc);
203static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc);
204static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT32 limit);
205static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT32 action, INT32 left, INT32 right);
206static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c);
207static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT32 start, UINT32 end, BOOL32 after_wrap);
208static BOOL32 EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT32 count, LPINT32 tabs);
209static BOOL32 EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT32 count, LPINT16 tabs);
210static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC32A wbp);
211static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp);
212static BOOL32 EDIT_EM_Undo(WND *wnd, EDITSTATE *es);
213/*
214 * WM_XXX message handlers
215 */
216static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data);
217static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT32 code, INT32 id, HWND32 conrtol);
218static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND32 hwnd, INT32 x, INT32 y);
219static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es);
220static LRESULT EDIT_WM_Create(WND *wnd, LPCREATESTRUCT32A cs);
221static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es);
222static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC32 dc);
223static INT32 EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT32 count, LPSTR text);
224static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar);
225static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data);
226static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND32 window_getting_focus);
227static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y);
228static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y);
229static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y);
230static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y);
231static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es);
232static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es);
233static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND32 window_losing_focus);
234static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT32 font, BOOL32 redraw);
235static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text);
236static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT32 action, INT32 width, INT32 height);
237static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data);
238static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT32 id, TIMERPROC32 timer_proc);
239static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar);
Alexandre Julliard58199531994-04-21 01:20:00 +0000240
241
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000242/*********************************************************************
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000243 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000244 * EM_CANUNDO
Alexandre Julliardcdcdede1996-04-21 14:57:41 +0000245 *
246 */
Alexandre Julliard889f7421997-04-15 17:19:52 +0000247static __inline__ BOOL32 EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es)
248{
249 return (es->undo_insert_count || lstrlen32A(es->undo_text));
250}
251
252
253/*********************************************************************
254 *
255 * EM_EMPTYUNDOBUFFER
256 *
257 */
258static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es)
259{
260 es->undo_insert_count = 0;
261 *es->undo_text = '\0';
262}
263
264
265/*********************************************************************
266 *
267 * WM_CLEAR
268 *
269 */
270static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es)
271{
272 EDIT_EM_ReplaceSel(wnd, es, TRUE, "");
273}
274
275
276/*********************************************************************
277 *
278 * WM_CUT
279 *
280 */
281static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es)
282{
283 EDIT_WM_Copy(wnd, es);
284 EDIT_WM_Clear(wnd, es);
285}
Alexandre Julliardcdcdede1996-04-21 14:57:41 +0000286
287
288/*********************************************************************
289 *
Alexandre Julliard329f0681996-04-14 13:21:20 +0000290 * EditWndProc()
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000291 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000292 * The messages are in the order of the actual integer values
293 * (which can be found in include/windows.h)
294 * Whereever possible the 16 bit versions are converted to
295 * the 32 bit ones, so that we can 'fall through' to the
296 * helper functions. These are mostly 32 bit (with a few
297 * exceptions, clearly indicated by a '16' extension to their
298 * names).
299 *
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000300 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000301LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg,
302 WPARAM32 wParam, LPARAM lParam )
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000303{
Alexandre Julliard889f7421997-04-15 17:19:52 +0000304 WND *wnd = WIN_FindWndPtr(hwnd);
305 EDITSTATE *es = *(EDITSTATE **)((wnd)->wExtra);
306 LRESULT result = 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000307
Alexandre Julliard889f7421997-04-15 17:19:52 +0000308 switch (msg) {
309 case WM_CREATE:
310 DPRINTF_EDIT_MSG32("WM_CREATE");
311 return EDIT_WM_Create(wnd, (LPCREATESTRUCT32A)lParam);
312
313 case WM_DESTROY:
314 DPRINTF_EDIT_MSG32("WM_DESTROY");
315 EDIT_WM_Destroy(wnd, es);
316 return 0;
317 }
318
319 if (!es)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000320 return DefWindowProc32A(hwnd, msg, wParam, lParam);
Alexandre Julliardbf9130a1996-10-13 17:45:47 +0000321
Alexandre Julliard889f7421997-04-15 17:19:52 +0000322 EDIT_LockBuffer(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000323 switch (msg) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000324 case EM_GETSEL16:
325 DPRINTF_EDIT_MSG16("EM_GETSEL");
326 wParam = 0;
327 lParam = 0;
328 /* fall through */
329 case EM_GETSEL32:
330 DPRINTF_EDIT_MSG32("EM_GETSEL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000331 result = EDIT_EM_GetSel(wnd, es, (LPUINT32)wParam, (LPUINT32)lParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000332 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000333
334 case EM_SETSEL16:
335 DPRINTF_EDIT_MSG16("EM_SETSEL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000336 if (SLOWORD(lParam) == -1)
337 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
338 else
339 EDIT_EM_SetSel(wnd, es, LOWORD(lParam), HIWORD(lParam), FALSE);
340 if (!wParam)
341 EDIT_EM_ScrollCaret(wnd, es);
342 result = 1;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000343 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000344 case EM_SETSEL32:
345 DPRINTF_EDIT_MSG32("EM_SETSEL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000346 EDIT_EM_SetSel(wnd, es, wParam, lParam, FALSE);
347 result = 1;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000348 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000349
350 case EM_GETRECT16:
351 DPRINTF_EDIT_MSG16("EM_GETRECT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000352 if (lParam)
353 CONV_RECT32TO16(&es->format_rect, (LPRECT16)PTR_SEG_TO_LIN(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000354 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000355 case EM_GETRECT32:
356 DPRINTF_EDIT_MSG32("EM_GETRECT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000357 if (lParam)
358 CopyRect32((LPRECT32)lParam, &es->format_rect);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000359 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000360
361 case EM_SETRECT16:
362 DPRINTF_EDIT_MSG16("EM_SETRECT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000363 if ((es->style & ES_MULTILINE) && lParam) {
364 RECT32 rc;
365 CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc);
366 EDIT_SetRectNP(wnd, es, &rc);
367 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
368 }
369 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000370 case EM_SETRECT32:
371 DPRINTF_EDIT_MSG32("EM_SETRECT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000372 if ((es->style & ES_MULTILINE) && lParam) {
373 EDIT_SetRectNP(wnd, es, (LPRECT32)lParam);
374 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
375 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000376 break;
377
378 case EM_SETRECTNP16:
379 DPRINTF_EDIT_MSG16("EM_SETRECTNP");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000380 if ((es->style & ES_MULTILINE) && lParam) {
381 RECT32 rc;
382 CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc);
383 EDIT_SetRectNP(wnd, es, &rc);
384 }
385 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000386 case EM_SETRECTNP32:
387 DPRINTF_EDIT_MSG32("EM_SETRECTNP");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000388 if ((es->style & ES_MULTILINE) && lParam)
389 EDIT_SetRectNP(wnd, es, (LPRECT32)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000390 break;
391
392 case EM_SCROLL16:
393 DPRINTF_EDIT_MSG16("EM_SCROLL");
394 /* fall through */
395 case EM_SCROLL32:
396 DPRINTF_EDIT_MSG32("EM_SCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000397 result = EDIT_EM_Scroll(wnd, es, (INT32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000398 break;
399
400 case EM_LINESCROLL16:
401 DPRINTF_EDIT_MSG16("EM_LINESCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000402 wParam = (WPARAM32)(INT32)SHIWORD(lParam);
403 lParam = (LPARAM)(INT32)SLOWORD(lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000404 /* fall through */
405 case EM_LINESCROLL32:
406 DPRINTF_EDIT_MSG32("EM_LINESCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000407 result = (LRESULT)EDIT_EM_LineScroll(wnd, es, (INT32)wParam, (INT32)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000408 break;
409
410 case EM_SCROLLCARET16:
411 DPRINTF_EDIT_MSG16("EM_SCROLLCARET");
412 /* fall through */
413 case EM_SCROLLCARET32:
414 DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000415 EDIT_EM_ScrollCaret(wnd, es);
416 result = 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000417 break;
418
419 case EM_GETMODIFY16:
420 DPRINTF_EDIT_MSG16("EM_GETMODIFY");
421 /* fall through */
422 case EM_GETMODIFY32:
423 DPRINTF_EDIT_MSG32("EM_GETMODIFY");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000424 return ((es->flags & EF_MODIFIED) != 0);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000425 break;
426
427 case EM_SETMODIFY16:
428 DPRINTF_EDIT_MSG16("EM_SETMODIFY");
429 /* fall through */
430 case EM_SETMODIFY32:
431 DPRINTF_EDIT_MSG32("EM_SETMODIFY");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000432 if (wParam)
433 es->flags |= EF_MODIFIED;
434 else
435 es->flags &= ~EF_MODIFIED;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000436 break;
437
438 case EM_GETLINECOUNT16:
439 DPRINTF_EDIT_MSG16("EM_GETLINECOUNT");
440 /* fall through */
441 case EM_GETLINECOUNT32:
442 DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000443 result = (es->style & ES_MULTILINE) ? es->line_count : 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000444 break;
445
446 case EM_LINEINDEX16:
447 DPRINTF_EDIT_MSG16("EM_LINEINDEX");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000448 if ((INT16)wParam == -1)
449 wParam = (WPARAM32)-1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000450 /* fall through */
451 case EM_LINEINDEX32:
452 DPRINTF_EDIT_MSG32("EM_LINEINDEX");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000453 result = (LRESULT)EDIT_EM_LineIndex(wnd, es, (INT32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000454 break;
455
456 case EM_SETHANDLE16:
457 DPRINTF_EDIT_MSG16("EM_SETHANDLE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000458 EDIT_EM_SetHandle16(wnd, es, (HLOCAL16)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000459 break;
460 case EM_SETHANDLE32:
461 DPRINTF_EDIT_MSG32("EM_SETHANDLE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000462 EDIT_EM_SetHandle(wnd, es, (HLOCAL32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000463 break;
464
465 case EM_GETHANDLE16:
466 DPRINTF_EDIT_MSG16("EM_GETHANDLE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000467 result = (LRESULT)EDIT_EM_GetHandle16(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000468 break;
469 case EM_GETHANDLE32:
470 DPRINTF_EDIT_MSG32("EM_GETHANDLE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000471 result = (LRESULT)EDIT_EM_GetHandle(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000472 break;
473
474 case EM_GETTHUMB16:
475 DPRINTF_EDIT_MSG16("EM_GETTHUMB");
476 /* fall through */
477 case EM_GETTHUMB32:
478 DPRINTF_EDIT_MSG32("EM_GETTHUMB");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000479 result = EDIT_EM_GetThumb(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000480 break;
481
482 /* messages 0x00bf and 0x00c0 missing from specs */
483
484 case WM_USER+15:
485 DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
486 /* fall through */
487 case 0x00bf:
488 DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000489 result = DefWindowProc32A(hwnd, msg, wParam, lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000490 break;
491
492 case WM_USER+16:
493 DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
494 /* fall through */
495 case 0x00c0:
496 DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000497 result = DefWindowProc32A(hwnd, msg, wParam, lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000498 break;
499
500 case EM_LINELENGTH16:
501 DPRINTF_EDIT_MSG16("EM_LINELENGTH");
502 /* fall through */
503 case EM_LINELENGTH32:
504 DPRINTF_EDIT_MSG32("EM_LINELENGTH");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000505 result = (LRESULT)EDIT_EM_LineLength(wnd, es, (INT32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000506 break;
507
508 case EM_REPLACESEL16:
509 DPRINTF_EDIT_MSG16("EM_REPLACESEL");
510 lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam);
511 /* fall through */
512 case EM_REPLACESEL32:
513 DPRINTF_EDIT_MSG32("EM_REPLACESEL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000514 EDIT_EM_ReplaceSel(wnd, es, (BOOL32)wParam, (LPCSTR)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000515 break;
516
517 /* message 0x00c3 missing from specs */
518
519 case WM_USER+19:
520 DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
521 /* fall through */
522 case 0x00c3:
523 DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000524 result = DefWindowProc32A(hwnd, msg, wParam, lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000525 break;
526
527 case EM_GETLINE16:
528 DPRINTF_EDIT_MSG16("EM_GETLINE");
529 lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam);
530 /* fall through */
531 case EM_GETLINE32:
532 DPRINTF_EDIT_MSG32("EM_GETLINE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000533 result = (LRESULT)EDIT_EM_GetLine(wnd, es, (INT32)wParam, (LPSTR)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000534 break;
535
536 case EM_LIMITTEXT16:
537 DPRINTF_EDIT_MSG16("EM_LIMITTEXT");
538 /* fall through */
539 case EM_SETLIMITTEXT32:
540 DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000541 EDIT_EM_SetLimitText(wnd, es, (INT32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000542 break;
543
544 case EM_CANUNDO16:
545 DPRINTF_EDIT_MSG16("EM_CANUNDO");
546 /* fall through */
547 case EM_CANUNDO32:
548 DPRINTF_EDIT_MSG32("EM_CANUNDO");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000549 result = (LRESULT)EDIT_EM_CanUndo(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000550 break;
551
552 case EM_UNDO16:
553 DPRINTF_EDIT_MSG16("EM_UNDO");
554 /* fall through */
555 case EM_UNDO32:
556 /* fall through */
Alexandre Julliard329f0681996-04-14 13:21:20 +0000557 case WM_UNDO:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000558 DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000559 result = (LRESULT)EDIT_EM_Undo(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000560 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000561
562 case EM_FMTLINES16:
563 DPRINTF_EDIT_MSG16("EM_FMTLINES");
564 /* fall through */
565 case EM_FMTLINES32:
566 DPRINTF_EDIT_MSG32("EM_FMTLINES");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000567 result = (LRESULT)EDIT_EM_FmtLines(wnd, es, (BOOL32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000568 break;
569
570 case EM_LINEFROMCHAR16:
571 DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR");
572 /* fall through */
573 case EM_LINEFROMCHAR32:
574 DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000575 result = (LRESULT)EDIT_EM_LineFromChar(wnd, es, (INT32)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000576 break;
577
578 /* message 0x00ca missing from specs */
579
580 case WM_USER+26:
581 DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
582 /* fall through */
583 case 0x00ca:
584 DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000585 result = DefWindowProc32A(hwnd, msg, wParam, lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000586 break;
587
588 case EM_SETTABSTOPS16:
589 DPRINTF_EDIT_MSG16("EM_SETTABSTOPS");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000590 result = (LRESULT)EDIT_EM_SetTabStops16(wnd, es, (INT32)wParam, (LPINT16)PTR_SEG_TO_LIN((SEGPTR)lParam));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000591 break;
592 case EM_SETTABSTOPS32:
593 DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000594 result = (LRESULT)EDIT_EM_SetTabStops(wnd, es, (INT32)wParam, (LPINT32)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000595 break;
596
597 case EM_SETPASSWORDCHAR16:
598 DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR");
599 /* fall through */
600 case EM_SETPASSWORDCHAR32:
601 DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000602 EDIT_EM_SetPasswordChar(wnd, es, (CHAR)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000603 break;
604
605 case EM_EMPTYUNDOBUFFER16:
606 DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER");
607 /* fall through */
608 case EM_EMPTYUNDOBUFFER32:
609 DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000610 EDIT_EM_EmptyUndoBuffer(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000611 break;
612
613 case EM_GETFIRSTVISIBLELINE16:
614 DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000615 result = es->y_offset;
616 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000617 case EM_GETFIRSTVISIBLELINE32:
618 DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000619 result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000620 break;
621
622 case EM_SETREADONLY16:
623 DPRINTF_EDIT_MSG16("EM_SETREADONLY");
624 /* fall through */
625 case EM_SETREADONLY32:
626 DPRINTF_EDIT_MSG32("EM_SETREADONLY");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000627 if (wParam) {
628 wnd->dwStyle |= ES_READONLY;
629 es->style |= ES_READONLY;
630 } else {
631 wnd->dwStyle &= ~ES_READONLY;
632 es->style &= ~ES_READONLY;
633 }
634 return 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000635 break;
636
637 case EM_SETWORDBREAKPROC16:
638 DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000639 EDIT_EM_SetWordBreakProc16(wnd, es, (EDITWORDBREAKPROC16)lParam);
640 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000641 case EM_SETWORDBREAKPROC32:
642 DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000643 EDIT_EM_SetWordBreakProc(wnd, es, (EDITWORDBREAKPROC32A)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000644 break;
645
646 case EM_GETWORDBREAKPROC16:
647 DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000648 result = (LRESULT)es->word_break_proc16;
649 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000650 case EM_GETWORDBREAKPROC32:
651 DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000652 result = (LRESULT)es->word_break_proc32A;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000653 break;
654
655 case EM_GETPASSWORDCHAR16:
656 DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR");
657 /* fall through */
658 case EM_GETPASSWORDCHAR32:
659 DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000660 result = es->password_char;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000661 break;
662
663 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
664
665 case EM_SETMARGINS32:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000666 DPRINTF_EDIT_MSG32("EM_SETMARGINS");
667 EDIT_EM_SetMargins(wnd, es, (INT32)wParam, SLOWORD(lParam), SHIWORD(lParam));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000668 break;
669
670 case EM_GETMARGINS32:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000671 DPRINTF_EDIT_MSG32("EM_GETMARGINS");
672 result = MAKELONG(es->left_margin, es->right_margin);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000673 break;
674
675 case EM_GETLIMITTEXT32:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000676 DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
677 result = es->buffer_limit;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000678 break;
679
680 case EM_POSFROMCHAR32:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000681 DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
682 result = EDIT_EM_PosFromChar(wnd, es, (INT32)wParam, FALSE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000683 break;
684
685 case EM_CHARFROMPOS32:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000686 DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
687 result = EDIT_EM_CharFromPos(wnd, es, SLOWORD(lParam), SHIWORD(lParam));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000688 break;
689
Alexandre Julliard329f0681996-04-14 13:21:20 +0000690 case WM_GETDLGCODE:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000691 DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000692 result = (es->style & ES_MULTILINE) ?
693 DLGC_WANTALLKEYS | DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS :
694 DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000695 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000696
Alexandre Julliard329f0681996-04-14 13:21:20 +0000697 case WM_CHAR:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000698 DPRINTF_EDIT_MSG32("WM_CHAR");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000699 EDIT_WM_Char(wnd, es, (CHAR)wParam, (DWORD)lParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000700 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000701
Alexandre Julliard329f0681996-04-14 13:21:20 +0000702 case WM_CLEAR:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000703 DPRINTF_EDIT_MSG32("WM_CLEAR");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000704 EDIT_WM_Clear(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000705 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000706
Alexandre Julliard01d63461997-01-20 19:43:45 +0000707 case WM_COMMAND:
708 DPRINTF_EDIT_MSG32("WM_COMMAND");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000709 EDIT_WM_Command(wnd, es, HIWORD(wParam), LOWORD(wParam), (HWND32)lParam);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000710 break;
711
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000712 case WM_CONTEXTMENU:
713 DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000714 EDIT_WM_ContextMenu(wnd, es, (HWND32)wParam, SLOWORD(lParam), SHIWORD(lParam));
Alexandre Julliard01d63461997-01-20 19:43:45 +0000715 break;
716
Alexandre Julliard329f0681996-04-14 13:21:20 +0000717 case WM_COPY:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000718 DPRINTF_EDIT_MSG32("WM_COPY");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000719 EDIT_WM_Copy(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000720 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000721
Alexandre Julliard329f0681996-04-14 13:21:20 +0000722 case WM_CUT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000723 DPRINTF_EDIT_MSG32("WM_CUT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000724 EDIT_WM_Cut(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000725 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000726
Alexandre Julliard329f0681996-04-14 13:21:20 +0000727 case WM_ENABLE:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000728 DPRINTF_EDIT_MSG32("WM_ENABLE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000729 InvalidateRect32(hwnd, NULL, TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000730 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000731
Alexandre Julliard329f0681996-04-14 13:21:20 +0000732 case WM_ERASEBKGND:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000733 DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000734 result = EDIT_WM_EraseBkGnd(wnd, es, (HDC32)wParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000735 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000736
Alexandre Julliard329f0681996-04-14 13:21:20 +0000737 case WM_GETFONT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000738 DPRINTF_EDIT_MSG32("WM_GETFONT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000739 result = (LRESULT)es->font;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000740 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000741
Alexandre Julliard329f0681996-04-14 13:21:20 +0000742 case WM_GETTEXT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000743 DPRINTF_EDIT_MSG32("WM_GETTEXT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000744 result = (LRESULT)EDIT_WM_GetText(wnd, es, (INT32)wParam, (LPSTR)lParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000745 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000746
Alexandre Julliard329f0681996-04-14 13:21:20 +0000747 case WM_GETTEXTLENGTH:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000748 DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000749 result = lstrlen32A(es->text);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000750 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000751
Alexandre Julliard329f0681996-04-14 13:21:20 +0000752 case WM_HSCROLL:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000753 DPRINTF_EDIT_MSG32("WM_HSCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000754 result = EDIT_WM_HScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND32)lParam);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000755 break;
756
Alexandre Julliard329f0681996-04-14 13:21:20 +0000757 case WM_KEYDOWN:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000758 DPRINTF_EDIT_MSG32("WM_KEYDOWN");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000759 result = EDIT_WM_KeyDown(wnd, es, (INT32)wParam, (DWORD)lParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000760 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000761
Alexandre Julliard329f0681996-04-14 13:21:20 +0000762 case WM_KILLFOCUS:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000763 DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000764 result = EDIT_WM_KillFocus(wnd, es, (HWND32)wParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000765 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000766
Alexandre Julliard329f0681996-04-14 13:21:20 +0000767 case WM_LBUTTONDBLCLK:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000768 DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000769 result = EDIT_WM_LButtonDblClk(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000770 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000771
Alexandre Julliard329f0681996-04-14 13:21:20 +0000772 case WM_LBUTTONDOWN:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000773 DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000774 result = EDIT_WM_LButtonDown(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000775 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000776
Alexandre Julliard329f0681996-04-14 13:21:20 +0000777 case WM_LBUTTONUP:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000778 DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000779 result = EDIT_WM_LButtonUp(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
780 break;
781
782 case WM_MOUSEACTIVATE:
783 /*
784 * FIXME: maybe DefWindowProc() screws up, but it seems that
785 * modalless dialog boxes need this. If we don't do this, the focus
786 * will _not_ be set by DefWindowProc() for edit controls in a
787 * modalless dialog box ???
788 */
789 DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
790 SetFocus32(wnd->hwndSelf);
791 result = MA_ACTIVATE;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000792 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000793
Alexandre Julliard329f0681996-04-14 13:21:20 +0000794 case WM_MOUSEMOVE:
795 /*
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000796 * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
Alexandre Julliard329f0681996-04-14 13:21:20 +0000797 */
Alexandre Julliard889f7421997-04-15 17:19:52 +0000798 result = EDIT_WM_MouseMove(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000799 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000800
Alexandre Julliard329f0681996-04-14 13:21:20 +0000801 case WM_PAINT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000802 DPRINTF_EDIT_MSG32("WM_PAINT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000803 EDIT_WM_Paint(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000804 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000805
Alexandre Julliard329f0681996-04-14 13:21:20 +0000806 case WM_PASTE:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000807 DPRINTF_EDIT_MSG32("WM_PASTE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000808 EDIT_WM_Paste(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000809 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000810
Alexandre Julliard329f0681996-04-14 13:21:20 +0000811 case WM_SETFOCUS:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000812 DPRINTF_EDIT_MSG32("WM_SETFOCUS");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000813 EDIT_WM_SetFocus(wnd, es, (HWND32)wParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000814 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000815
Alexandre Julliard329f0681996-04-14 13:21:20 +0000816 case WM_SETFONT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000817 DPRINTF_EDIT_MSG32("WM_SETFONT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000818 EDIT_WM_SetFont(wnd, es, (HFONT32)wParam, LOWORD(lParam) != 0);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000819 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000820
Alexandre Julliard329f0681996-04-14 13:21:20 +0000821 case WM_SETTEXT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000822 DPRINTF_EDIT_MSG32("WM_SETTEXT");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000823 EDIT_WM_SetText(wnd, es, (LPCSTR)lParam);
824 result = TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000825 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000826
Alexandre Julliard329f0681996-04-14 13:21:20 +0000827 case WM_SIZE:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000828 DPRINTF_EDIT_MSG32("WM_SIZE");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000829 EDIT_WM_Size(wnd, es, (UINT32)wParam, LOWORD(lParam), HIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000830 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000831
Alexandre Julliard01d63461997-01-20 19:43:45 +0000832 case WM_SYSKEYDOWN:
833 DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000834 result = EDIT_WM_SysKeyDown(wnd, es, (INT32)wParam, (DWORD)lParam);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000835 break;
836
837 case WM_TIMER:
838 DPRINTF_EDIT_MSG32("WM_TIMER");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000839 EDIT_WM_Timer(wnd, es, (INT32)wParam, (TIMERPROC32)lParam);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000840 break;
841
Alexandre Julliard329f0681996-04-14 13:21:20 +0000842 case WM_VSCROLL:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000843 DPRINTF_EDIT_MSG32("WM_VSCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +0000844 result = EDIT_WM_VScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND32)(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000845 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000846
Alexandre Julliard329f0681996-04-14 13:21:20 +0000847 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000848 result = DefWindowProc32A(hwnd, msg, wParam, lParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000849 break;
850 }
Alexandre Julliard889f7421997-04-15 17:19:52 +0000851 EDIT_UnlockBuffer(wnd, es, FALSE);
852 return result;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000853}
854
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000855
856/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000857 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000858 * EDIT_BuildLineDefs_ML
Alexandre Julliard329f0681996-04-14 13:21:20 +0000859 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000860 * Build linked list of text lines.
861 * Lines can end with '\0' (last line), a character (if it is wrapped),
862 * a soft return '\r\r\n' or a hard return '\r\n'
Alexandre Julliard329f0681996-04-14 13:21:20 +0000863 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000864 */
Alexandre Julliard889f7421997-04-15 17:19:52 +0000865static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es)
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000866{
Alexandre Julliard889f7421997-04-15 17:19:52 +0000867 HDC32 dc;
868 HFONT32 old_font = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000869 LPSTR start, cp;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000870 INT32 fw;
871 LINEDEF *current_def;
872 LINEDEF **previous_next;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000873
Alexandre Julliard889f7421997-04-15 17:19:52 +0000874 current_def = es->first_line_def;
875 do {
876 LINEDEF *next_def = current_def->next;
877 HeapFree(es->heap, 0, current_def);
878 current_def = next_def;
879 } while (current_def);
880 es->line_count = 0;
881 es->text_width = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000882
Alexandre Julliard889f7421997-04-15 17:19:52 +0000883 dc = GetDC32(wnd->hwndSelf);
884 if (es->font)
885 old_font = SelectObject32(dc, es->font);
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000886
Alexandre Julliard889f7421997-04-15 17:19:52 +0000887 fw = es->format_rect.right - es->format_rect.left;
888 start = es->text;
889 previous_next = &es->first_line_def;
890 do {
891 current_def = HeapAlloc(es->heap, 0, sizeof(LINEDEF));
892 current_def->next = NULL;
893 cp = start;
894 while (*cp) {
895 if ((*cp == '\r') && (*(cp + 1) == '\n'))
896 break;
897 cp++;
898 }
899 if (!(*cp)) {
900 current_def->ending = END_0;
901 current_def->net_length = lstrlen32A(start);
902 } else if ((cp > start) && (*(cp - 1) == '\r')) {
903 current_def->ending = END_SOFT;
904 current_def->net_length = cp - start - 1;
905 } else {
906 current_def->ending = END_HARD;
907 current_def->net_length = cp - start;
908 }
909 current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc,
910 start, current_def->net_length,
911 es->tabs_count, es->tabs));
912 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
913 if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) {
914 INT32 next = 0;
915 INT32 prev;
916 do {
917 prev = next;
918 next = EDIT_CallWordBreakProc(wnd, es, start - es->text,
919 prev + 1, current_def->net_length, WB_RIGHT);
920 current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc,
921 start, next, es->tabs_count, es->tabs));
922 } while (current_def->width <= fw);
923 if (!prev) {
Alexandre Julliard329f0681996-04-14 13:21:20 +0000924 next = 0;
925 do {
926 prev = next;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000927 next++;
928 current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc,
929 start, next, es->tabs_count, es->tabs));
930 } while (current_def->width <= fw);
931 if (!prev)
932 prev = 1;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000933 }
Alexandre Julliard889f7421997-04-15 17:19:52 +0000934 current_def->net_length = prev;
935 current_def->ending = END_WRAP;
936 current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc, start,
937 current_def->net_length, es->tabs_count, es->tabs));
938 }
939 switch (current_def->ending) {
940 case END_SOFT:
941 current_def->length = current_def->net_length + 3;
942 break;
943 case END_HARD:
944 current_def->length = current_def->net_length + 2;
945 break;
946 case END_WRAP:
947 case END_0:
948 current_def->length = current_def->net_length;
949 break;
950 }
951 es->text_width = MAX(es->text_width, current_def->width);
952 start += current_def->length;
953 *previous_next = current_def;
954 previous_next = &current_def->next;
955 es->line_count++;
956 } while (current_def->ending != END_0);
957 if (es->font)
958 SelectObject32(dc, old_font);
959 ReleaseDC32(wnd->hwndSelf, dc);
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000960}
961
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000962
Alexandre Julliard329f0681996-04-14 13:21:20 +0000963/*********************************************************************
964 *
965 * EDIT_CallWordBreakProc
966 *
967 * Call appropriate WordBreakProc (internal or external).
968 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000969 * Note: The "start" argument should always be an index refering
970 * to es->text. The actual wordbreak proc might be
971 * 16 bit, so we can't always pass any 32 bit LPSTR.
972 * Hence we assume that es->text is the buffer that holds
973 * the string under examination (we can decide this for ourselves).
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000974 *
Alexandre Julliard329f0681996-04-14 13:21:20 +0000975 */
Alexandre Julliard889f7421997-04-15 17:19:52 +0000976static INT32 EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT32 start, INT32 index, INT32 count, INT32 action)
Alexandre Julliard329f0681996-04-14 13:21:20 +0000977{
Alexandre Julliard889f7421997-04-15 17:19:52 +0000978 if (es->word_break_proc16) {
979 HLOCAL16 hloc16 = EDIT_EM_GetHandle16(wnd, es);
980 SEGPTR segptr = LocalLock16(hloc16);
981 INT32 ret = (INT32)CallWordBreakProc16((FARPROC16)es->word_break_proc16,
982 segptr + start, index, count, action);
983 LocalUnlock16(hloc16);
984 return ret;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000985 }
986 else if (es->word_break_proc32A)
987 {
988 dprintf_relay( stddeb, "CallTo32(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
989 es->word_break_proc32A, es->text + start, index,
990 count, action );
991 return (INT32)es->word_break_proc32A( es->text + start, index,
992 count, action );
993 }
Alexandre Julliard889f7421997-04-15 17:19:52 +0000994 else
Alexandre Julliard77b99181997-09-14 17:17:23 +0000995 return EDIT_WordBreakProc(es->text + start, index, count, action);
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000996}
997
Alexandre Julliard329f0681996-04-14 13:21:20 +0000998
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000999/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001000 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001001 * EDIT_CharFromPos
Alexandre Julliard329f0681996-04-14 13:21:20 +00001002 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001003 * Beware: This is not the function called on EM_CHARFROMPOS
1004 * The position _can_ be outside the formatting / client
1005 * rectangle
1006 * The return value is only the character index
Alexandre Julliard329f0681996-04-14 13:21:20 +00001007 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001008 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001009static INT32 EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y, LPBOOL32 after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001010{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001011 INT32 index;
1012 HDC32 dc;
1013 HFONT32 old_font = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001014
Alexandre Julliard889f7421997-04-15 17:19:52 +00001015 if (es->style & ES_MULTILINE) {
1016 INT32 line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1017 INT32 line_index = 0;
1018 LINEDEF *line_def = es->first_line_def;
1019 while ((line > 0) && line_def->next) {
1020 line_index += line_def->length;
1021 line_def = line_def->next;
1022 line--;
1023 }
1024 x += es->x_offset - es->format_rect.left;
1025 if (x >= line_def->width) {
1026 if (after_wrap)
1027 *after_wrap = (line_def->ending == END_WRAP);
1028 return line_index + line_def->net_length;
1029 }
1030 if (x <= 0) {
1031 if (after_wrap)
1032 *after_wrap = FALSE;
1033 return line_index;
1034 }
1035 dc = GetDC32(wnd->hwndSelf);
1036 if (es->font)
1037 old_font = SelectObject32(dc, es->font);
1038 /* FIXME: inefficient algorithm */
1039 for (index = line_index + 1 ; index < line_index + line_def->net_length ; index++)
1040 if (LOWORD(GetTabbedTextExtent32A(dc, es->text + line_index,
1041 index - line_index, es->tabs_count, es->tabs)) >= x)
1042 break;
1043 if (after_wrap)
1044 *after_wrap = ((index == line_index + line_def->net_length) &&
1045 (line_def->ending == END_WRAP));
1046 } else {
1047 LPSTR text;
1048 SIZE32 size;
1049 if (after_wrap)
1050 *after_wrap = FALSE;
1051 x -= es->format_rect.left;
1052 if (!x)
1053 return es->x_offset;
1054 text = EDIT_GetPasswordPointer_SL(wnd, es);
1055 dc = GetDC32(wnd->hwndSelf);
1056 if (es->font)
1057 old_font = SelectObject32(dc, es->font);
1058 if (x < 0) {
1059 x = -x;
1060 /* FIXME: inefficient algorithm */
1061 for (index = es->x_offset ; index ; index--) {
1062 GetTextExtentPoint32A(dc, text + index,
1063 es->x_offset - index, &size);
1064 if (size.cx > x)
1065 break;
1066 }
1067 } else {
1068 INT32 len = lstrlen32A(es->text);
1069 /* FIXME: inefficient algorithm */
1070 for (index = es->x_offset ; index < len ; index++) {
1071 GetTextExtentPoint32A(dc, text + es->x_offset,
1072 index - es->x_offset, &size);
1073 if (size.cx >= x)
1074 break;
1075 }
1076 }
1077 if (es->style & ES_PASSWORD)
1078 HeapFree(es->heap, 0 ,text);
1079 }
1080 if (es->font)
1081 SelectObject32(dc, old_font);
1082 ReleaseDC32(wnd->hwndSelf, dc);
1083 return index;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001084}
1085
Alexandre Julliard329f0681996-04-14 13:21:20 +00001086
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001087/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001088 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001089 * EDIT_ConfinePoint
Alexandre Julliard329f0681996-04-14 13:21:20 +00001090 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001091 * adjusts the point to be within the formatting rectangle
1092 * (so CharFromPos returns the nearest _visible_ character)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001093 *
1094 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001095static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT32 x, LPINT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001096{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001097 *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1);
1098 *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001099}
1100
1101
1102/*********************************************************************
1103 *
1104 * EDIT_GetLineRect
1105 *
1106 * Calculates the bounding rectangle for a line from a starting
1107 * column to an ending column.
1108 *
1109 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001110static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT32 line, INT32 scol, INT32 ecol, LPRECT32 rc)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001111{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001112 INT32 line_index = EDIT_EM_LineIndex(wnd, es, line);
1113
1114 if (es->style & ES_MULTILINE)
1115 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1116 else
1117 rc->top = es->format_rect.top;
1118 rc->bottom = rc->top + es->line_height;
1119 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE));
1120 rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + ecol, TRUE));
Alexandre Julliard329f0681996-04-14 13:21:20 +00001121}
1122
1123
1124/*********************************************************************
1125 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001126 * EDIT_GetPasswordPointer_SL
1127 *
1128 * note: caller should free the (optionally) allocated buffer
1129 *
1130 */
1131static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es)
1132{
1133 if (es->style & ES_PASSWORD) {
1134 INT32 len = lstrlen32A(es->text);
1135 LPSTR text = HeapAlloc(es->heap, 0, len + 1);
1136 RtlFillMemory(text, len, es->password_char);
1137 text[len] = '\0';
1138 return text;
1139 } else
1140 return es->text;
1141}
1142
1143
1144/*********************************************************************
1145 *
1146 * EDIT_LockBuffer
Alexandre Julliard329f0681996-04-14 13:21:20 +00001147 *
1148 * This acts as a LOCAL_Lock(), but it locks only once. This way
1149 * you can call it whenever you like, without unlocking.
1150 *
1151 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001152static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001153{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001154 if (!es) {
1155 fprintf(stderr, "edit: LockBuffer() without an EDITSTATE ... please report\n");
1156 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001157 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001158 if (!(es->style & ES_MULTILINE))
1159 return;
1160 if (!es->text) {
1161 if (es->hloc32)
1162 es->text = LocalLock32(es->hloc32);
1163 else if (es->hloc16)
1164 es->text = LOCAL_Lock(wnd->hInstance, es->hloc16);
1165 else {
1166 fprintf(stderr, "edit: LockBuffer() without a buffer ... please report\n");
1167 return;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001168 }
1169 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001170 es->lock_count++;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001171}
1172
1173
1174/*********************************************************************
1175 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001176 * EDIT_SL_InvalidateText
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001177 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001178 * Called from EDIT_InvalidateText().
1179 * Does the job for single-line controls only.
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001180 *
1181 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001182static void EDIT_SL_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end)
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001183{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001184 RECT32 line_rect;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001185 RECT32 rc;
1186
Alexandre Julliard889f7421997-04-15 17:19:52 +00001187 EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect);
1188 if (IntersectRect32(&rc, &line_rect, &es->format_rect))
1189 InvalidateRect32(wnd->hwndSelf, &rc, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001190}
1191
1192
1193/*********************************************************************
1194 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001195 * EDIT_ML_InvalidateText
1196 *
1197 * Called from EDIT_InvalidateText().
1198 * Does the job for multi-line controls only.
Alexandre Julliard329f0681996-04-14 13:21:20 +00001199 *
1200 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001201static void EDIT_ML_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001202{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001203 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1204 INT32 sl = EDIT_EM_LineFromChar(wnd, es, start);
1205 INT32 el = EDIT_EM_LineFromChar(wnd, es, end);
1206 INT32 sc;
1207 INT32 ec;
1208 RECT32 rc1;
1209 RECT32 rcWnd;
1210 RECT32 rcLine;
1211 RECT32 rcUpdate;
1212 INT32 l;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001213
Alexandre Julliard889f7421997-04-15 17:19:52 +00001214 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1215 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001216
Alexandre Julliard889f7421997-04-15 17:19:52 +00001217 sc = start - EDIT_EM_LineIndex(wnd, es, sl);
1218 ec = end - EDIT_EM_LineIndex(wnd, es, el);
1219 if (sl < es->y_offset) {
1220 sl = es->y_offset;
1221 sc = 0;
1222 }
1223 if (el > es->y_offset + vlc) {
1224 el = es->y_offset + vlc;
1225 ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el));
1226 }
1227 GetClientRect32(wnd->hwndSelf, &rc1);
1228 IntersectRect32(&rcWnd, &rc1, &es->format_rect);
1229 if (sl == el) {
1230 EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine);
1231 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1232 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1233 } else {
1234 EDIT_GetLineRect(wnd, es, sl, sc,
1235 EDIT_EM_LineLength(wnd, es,
1236 EDIT_EM_LineIndex(wnd, es, sl)),
1237 &rcLine);
1238 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1239 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1240 for (l = sl + 1 ; l < el ; l++) {
1241 EDIT_GetLineRect(wnd, es, l, 0,
1242 EDIT_EM_LineLength(wnd, es,
1243 EDIT_EM_LineIndex(wnd, es, l)),
1244 &rcLine);
1245 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1246 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1247 }
1248 EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine);
1249 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1250 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1251 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001252}
1253
1254
1255/*********************************************************************
1256 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001257 * EDIT_InvalidateText
1258 *
1259 * Invalidate the text from offset start upto, but not including,
1260 * offset end. Useful for (re)painting the selection.
1261 * Regions outside the linewidth are not invalidated.
1262 * end == -1 means end == TextLength.
1263 * start and end need not be ordered.
1264 *
1265 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001266static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end)
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001267{
Alexandre Julliard01d63461997-01-20 19:43:45 +00001268 if (end == start)
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001269 return;
1270
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001271 if (end == -1)
Alexandre Julliard889f7421997-04-15 17:19:52 +00001272 end = lstrlen32A(es->text);
1273
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001274 ORDER_INT32(start, end);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001275
Alexandre Julliard889f7421997-04-15 17:19:52 +00001276 if (es->style & ES_MULTILINE)
1277 EDIT_ML_InvalidateText(wnd, es, start, end);
1278 else
1279 EDIT_SL_InvalidateText(wnd, es, start, end);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001280}
1281
1282
1283/*********************************************************************
1284 *
1285 * EDIT_MakeFit
1286 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001287 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
Alexandre Julliard329f0681996-04-14 13:21:20 +00001288 *
1289 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001290static BOOL32 EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT32 size)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001291{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001292 HLOCAL32 hNew32;
1293 HLOCAL16 hNew16;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001294
Alexandre Julliard889f7421997-04-15 17:19:52 +00001295 if (size <= es->buffer_size)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001296 return TRUE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001297 if (size > es->buffer_limit) {
1298 EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT");
Alexandre Julliard329f0681996-04-14 13:21:20 +00001299 return FALSE;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001300 }
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001301 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001302 if (size > es->buffer_limit)
1303 size = es->buffer_limit;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001304
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001305 dprintf_edit(stddeb, "edit: EDIT_MakeFit: trying to ReAlloc to %d+1\n", size);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001306
Alexandre Julliard889f7421997-04-15 17:19:52 +00001307 EDIT_UnlockBuffer(wnd, es, TRUE);
1308 if (es->text) {
1309 if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1)))
1310 es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
1311 else
1312 es->buffer_size = 0;
1313 } else if (es->hloc32) {
1314 if ((hNew32 = LocalReAlloc32(es->hloc32, size + 1, 0))) {
1315 dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32);
1316 es->hloc32 = hNew32;
1317 es->buffer_size = MIN(LocalSize32(es->hloc32) - 1, es->buffer_limit);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001318 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001319 } else if (es->hloc16) {
1320 if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) {
1321 dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16);
1322 es->hloc16 = hNew16;
1323 es->buffer_size = MIN(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001324 }
1325 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001326 if (es->buffer_size < size) {
1327 EDIT_LockBuffer(wnd, es);
1328 dprintf_edit(stddeb, "edit: EDIT_MakeFit: FAILED ! We now have %d+1\n", es->buffer_size);
1329 EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE");
1330 return FALSE;
1331 } else {
1332 EDIT_LockBuffer(wnd, es);
1333 dprintf_edit(stddeb, "edit: EDIT_MakeFit: We now have %d+1\n", es->buffer_size);
1334 return TRUE;
1335 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001336}
1337
1338
1339/*********************************************************************
1340 *
1341 * EDIT_MakeUndoFit
1342 *
1343 * Try to fit size + 1 bytes in the undo buffer.
1344 *
1345 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001346static BOOL32 EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT32 size)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001347{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001348 if (size <= es->undo_buffer_size)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001349 return TRUE;
1350 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
1351
1352 dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: trying to ReAlloc to %d+1\n", size);
1353
Alexandre Julliard889f7421997-04-15 17:19:52 +00001354 if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) {
1355 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
1356 if (es->undo_buffer_size < size) {
1357 dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: FAILED ! We now have %d+1\n", es->undo_buffer_size);
Alexandre Julliard01d63461997-01-20 19:43:45 +00001358 return FALSE;
1359 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001360 return TRUE;
1361 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001362 return FALSE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001363}
1364
1365
1366/*********************************************************************
1367 *
1368 * EDIT_MoveBackward
1369 *
1370 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001371static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001372{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001373 INT32 e = es->selection_end;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001374
Alexandre Julliard889f7421997-04-15 17:19:52 +00001375 if (e) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001376 e--;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001377 if ((es->style & ES_MULTILINE) && e &&
1378 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1379 e--;
1380 if (e && (es->text[e - 1] == '\r'))
1381 e--;
1382 }
1383 }
1384 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1385 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001386}
1387
1388
1389/*********************************************************************
1390 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001391 * EDIT_MoveDown_ML
1392 *
1393 * Only for multi line controls
1394 * Move the caret one line down, on a column with the nearest
1395 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001396 *
1397 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001398static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001399{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001400 INT32 s = es->selection_start;
1401 INT32 e = es->selection_end;
1402 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1403 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1404 INT32 x = SLOWORD(pos);
1405 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001406
Alexandre Julliard889f7421997-04-15 17:19:52 +00001407 e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001408 if (!extend)
1409 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001410 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1411 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001412}
1413
1414
1415/*********************************************************************
1416 *
1417 * EDIT_MoveEnd
1418 *
1419 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001420static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001421{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001422 BOOL32 after_wrap = FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001423 INT32 e;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001424
Alexandre Julliard889f7421997-04-15 17:19:52 +00001425 if (es->style & ES_MULTILINE)
1426 e = EDIT_CharFromPos(wnd, es, 0x7fffffff,
1427 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1428 else
1429 e = lstrlen32A(es->text);
1430 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap);
1431 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001432}
1433
1434
1435/*********************************************************************
1436 *
1437 * EDIT_MoveForward
1438 *
1439 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001440static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001441{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001442 INT32 e = es->selection_end;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001443
Alexandre Julliard889f7421997-04-15 17:19:52 +00001444 if (es->text[e]) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001445 e++;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001446 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1447 if (es->text[e] == '\n')
1448 e++;
1449 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1450 e += 2;
1451 }
1452 }
1453 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1454 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001455}
1456
1457
1458/*********************************************************************
1459 *
1460 * EDIT_MoveHome
1461 *
1462 * Home key: move to beginning of line.
1463 *
1464 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001465static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001466{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001467 INT32 e;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001468
Alexandre Julliard889f7421997-04-15 17:19:52 +00001469 if (es->style & ES_MULTILINE)
1470 e = EDIT_CharFromPos(wnd, es, 0x80000000,
1471 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1472 else
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001473 e = 0;
1474 EDIT_EM_SetSel(wnd, es, e, extend ? es->selection_start : e, FALSE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001475 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001476}
1477
1478
1479/*********************************************************************
1480 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001481 * EDIT_MovePageDown_ML
1482 *
1483 * Only for multi line controls
1484 * Move the caret one page down, on a column with the nearest
1485 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001486 *
1487 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001488static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001489{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001490 INT32 s = es->selection_start;
1491 INT32 e = es->selection_end;
1492 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1493 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1494 INT32 x = SLOWORD(pos);
1495 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001496
Alexandre Julliard889f7421997-04-15 17:19:52 +00001497 e = EDIT_CharFromPos(wnd, es, x,
1498 y + (es->format_rect.bottom - es->format_rect.top),
1499 &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001500 if (!extend)
1501 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001502 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1503 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001504}
1505
1506
1507/*********************************************************************
1508 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001509 * EDIT_MovePageUp_ML
1510 *
1511 * Only for multi line controls
1512 * Move the caret one page up, on a column with the nearest
1513 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001514 *
1515 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001516static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001517{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001518 INT32 s = es->selection_start;
1519 INT32 e = es->selection_end;
1520 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1521 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1522 INT32 x = SLOWORD(pos);
1523 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001524
Alexandre Julliard889f7421997-04-15 17:19:52 +00001525 e = EDIT_CharFromPos(wnd, es, x,
1526 y - (es->format_rect.bottom - es->format_rect.top),
1527 &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001528 if (!extend)
1529 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001530 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1531 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001532}
1533
1534
1535/*********************************************************************
1536 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001537 * EDIT_MoveUp_ML
Alexandre Julliard329f0681996-04-14 13:21:20 +00001538 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001539 * Only for multi line controls
1540 * Move the caret one line up, on a column with the nearest
1541 * x coordinate on the screen (might be a different column).
1542 *
1543 */
1544static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001545{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001546 INT32 s = es->selection_start;
1547 INT32 e = es->selection_end;
1548 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1549 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1550 INT32 x = SLOWORD(pos);
1551 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001552
Alexandre Julliard889f7421997-04-15 17:19:52 +00001553 e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001554 if (!extend)
1555 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001556 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1557 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001558}
1559
1560
1561/*********************************************************************
1562 *
1563 * EDIT_MoveWordBackward
1564 *
1565 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001566static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001567{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001568 INT32 s = es->selection_start;
1569 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001570 INT32 l;
1571 INT32 ll;
1572 INT32 li;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001573
Alexandre Julliard889f7421997-04-15 17:19:52 +00001574 l = EDIT_EM_LineFromChar(wnd, es, e);
1575 ll = EDIT_EM_LineLength(wnd, es, e);
1576 li = EDIT_EM_LineIndex(wnd, es, l);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001577 if (e - li == 0) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001578 if (l) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001579 li = EDIT_EM_LineIndex(wnd, es, l - 1);
1580 e = li + EDIT_EM_LineLength(wnd, es, li);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001581 }
1582 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001583 e = li + (INT32)EDIT_CallWordBreakProc(wnd, es,
1584 li, e - li, ll, WB_LEFT);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001585 }
1586 if (!extend)
1587 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001588 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1589 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001590}
1591
1592
1593/*********************************************************************
1594 *
1595 * EDIT_MoveWordForward
1596 *
1597 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001598static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001599{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001600 INT32 s = es->selection_start;
1601 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001602 INT32 l;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001603 INT32 ll;
1604 INT32 li;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001605
Alexandre Julliard889f7421997-04-15 17:19:52 +00001606 l = EDIT_EM_LineFromChar(wnd, es, e);
1607 ll = EDIT_EM_LineLength(wnd, es, e);
1608 li = EDIT_EM_LineIndex(wnd, es, l);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001609 if (e - li == ll) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001610 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
1611 e = EDIT_EM_LineIndex(wnd, es, l + 1);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001612 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001613 e = li + EDIT_CallWordBreakProc(wnd, es,
1614 li, e - li + 1, ll, WB_RIGHT);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001615 }
1616 if (!extend)
1617 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001618 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1619 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001620}
1621
1622
1623/*********************************************************************
1624 *
1625 * EDIT_PaintLine
1626 *
1627 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001628static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC32 dc, INT32 line, BOOL32 rev)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001629{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001630 INT32 s = es->selection_start;
1631 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001632 INT32 li;
1633 INT32 ll;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001634 INT32 x;
1635 INT32 y;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001636 LRESULT pos;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001637
Alexandre Julliard889f7421997-04-15 17:19:52 +00001638 if (es->style & ES_MULTILINE) {
1639 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1640 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
1641 return;
1642 } else if (line)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001643 return;
1644
1645 dprintf_edit(stddeb, "edit: EDIT_PaintLine: line=%d\n", line);
1646
Alexandre Julliard889f7421997-04-15 17:19:52 +00001647 pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE);
1648 x = SLOWORD(pos);
1649 y = SHIWORD(pos);
1650 li = EDIT_EM_LineIndex(wnd, es, line);
1651 ll = EDIT_EM_LineLength(wnd, es, li);
1652 s = es->selection_start;
1653 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001654 ORDER_INT32(s, e);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001655 s = MIN(li + ll, MAX(li, s));
1656 e = MIN(li + ll, MAX(li, e));
1657 if (rev && (s != e) &&
Alexandre Julliard889f7421997-04-15 17:19:52 +00001658 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
1659 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE);
1660 x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE);
1661 x += EDIT_PaintText(wnd, es, dc, x, y, line, e - li, li + ll - e, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001662 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00001663 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001664}
1665
1666
1667/*********************************************************************
1668 *
1669 * EDIT_PaintText
1670 *
1671 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001672static INT32 EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC32 dc, INT32 x, INT32 y, INT32 line, INT32 col, INT32 count, BOOL32 rev)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001673{
Alexandre Julliard329f0681996-04-14 13:21:20 +00001674 COLORREF BkColor;
1675 COLORREF TextColor;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001676 INT32 ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001677 INT32 li;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001678 SIZE32 size;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001679
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001680 if (!count)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001681 return 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001682 BkColor = GetBkColor32(dc);
1683 TextColor = GetTextColor32(dc);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001684 if (rev) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001685 SetBkColor32(dc, GetSysColor32(COLOR_HIGHLIGHT));
1686 SetTextColor32(dc, GetSysColor32(COLOR_HIGHLIGHTTEXT));
Alexandre Julliard329f0681996-04-14 13:21:20 +00001687 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001688 li = EDIT_EM_LineIndex(wnd, es, line);
1689 if (es->style & ES_MULTILINE) {
1690 ret = (INT32)LOWORD(TabbedTextOut32A(dc, x, y, es->text + li + col, count,
1691 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
1692 } else {
1693 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
1694 TextOut32A(dc, x, y, text + li + col, count);
1695 GetTextExtentPoint32A(dc, text + li + col, count, &size);
1696 ret = size.cx;
1697 if (es->style & ES_PASSWORD)
1698 HeapFree(es->heap, 0, text);
1699 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001700 if (rev) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001701 SetBkColor32(dc, BkColor);
1702 SetTextColor32(dc, TextColor);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001703 }
1704 return ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001705}
Alexandre Julliard329f0681996-04-14 13:21:20 +00001706
1707
1708/*********************************************************************
1709 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001710 * EM_SCROLLCARET
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001711 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00001712 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001713static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001714{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001715 if (es->style & ES_MULTILINE) {
1716 INT32 l;
1717 INT32 li;
1718 INT32 vlc;
1719 INT32 ww;
1720 INT32 cw = es->char_width;
1721 INT32 x;
1722 INT32 dy = 0;
1723 INT32 dx = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001724
Alexandre Julliard889f7421997-04-15 17:19:52 +00001725 l = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
1726 li = EDIT_EM_LineIndex(wnd, es, l);
1727 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP));
1728 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1729 if (l >= es->y_offset + vlc)
1730 dy = l - vlc + 1 - es->y_offset;
1731 if (l < es->y_offset)
1732 dy = l - es->y_offset;
1733 ww = es->format_rect.right - es->format_rect.left;
1734 if (x < es->format_rect.left)
1735 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
1736 if (x > es->format_rect.right)
1737 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
1738 if (dy || dx)
1739 EDIT_EM_LineScroll(wnd, es, dx, dy);
1740 } else {
1741 INT32 x;
1742 INT32 goal;
1743 INT32 format_width;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001744
Alexandre Julliard889f7421997-04-15 17:19:52 +00001745 if (!(es->style & ES_AUTOHSCROLL))
1746 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001747
Alexandre Julliard889f7421997-04-15 17:19:52 +00001748 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
1749 format_width = es->format_rect.right - es->format_rect.left;
1750 if (x < es->format_rect.left) {
1751 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
1752 do {
1753 es->x_offset--;
1754 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
1755 } while ((x < goal) && es->x_offset);
1756 /* FIXME: use ScrollWindow() somehow to improve performance */
1757 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
1758 } else if (x > es->format_rect.right) {
1759 INT32 x_last;
1760 INT32 len = lstrlen32A(es->text);
1761 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
1762 do {
1763 es->x_offset++;
1764 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
1765 x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE));
1766 } while ((x > goal) && (x_last > es->format_rect.right));
1767 /* FIXME: use ScrollWindow() somehow to improve performance */
1768 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliard01d63461997-01-20 19:43:45 +00001769 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001770 }
1771}
1772
1773
1774/*********************************************************************
1775 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001776 * EDIT_SetRectNP
Alexandre Julliard329f0681996-04-14 13:21:20 +00001777 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001778 * note: this is not (exactly) the handler called on EM_SETRECTNP
1779 * it is also used to set the rect of a single line control
Alexandre Julliard329f0681996-04-14 13:21:20 +00001780 *
1781 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001782static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT32 rc)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001783{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001784 CopyRect32(&es->format_rect, rc);
1785 if (es->style & WS_BORDER) {
1786 INT32 bw = GetSystemMetrics32(SM_CXBORDER) + 1;
1787 es->format_rect.left += bw;
1788 es->format_rect.top += bw;
1789 es->format_rect.right -= bw;
1790 es->format_rect.bottom -= bw;
1791 }
1792 es->format_rect.left += es->left_margin;
1793 es->format_rect.right -= es->right_margin;
1794 es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width);
1795 if (es->style & ES_MULTILINE)
1796 es->format_rect.bottom = es->format_rect.top +
1797 MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
1798 else
1799 es->format_rect.bottom = es->format_rect.top + es->line_height;
1800 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
1801 EDIT_BuildLineDefs_ML(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001802}
1803
1804
1805/*********************************************************************
1806 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001807 * EDIT_UnlockBuffer
Alexandre Julliard329f0681996-04-14 13:21:20 +00001808 *
1809 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001810static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL32 force)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001811{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001812 if (!es) {
1813 fprintf(stderr, "edit: UnlockBuffer() without an EDITSTATE ... please report\n");
1814 return;
1815 }
1816 if (!(es->style & ES_MULTILINE))
1817 return;
1818 if (!es->lock_count) {
1819 fprintf(stderr, "edit: UnlockBuffer() with lock_count == 0 ... please report\n");
1820 return;
1821 }
1822 if (!es->text) {
1823 fprintf(stderr, "edit: UnlockBuffer() with es->text == 0 ... please report\n");
1824 return;
1825 }
1826 if (force || (es->lock_count == 1)) {
1827 if (es->hloc32) {
1828 LocalUnlock32(es->hloc32);
1829 es->text = NULL;
1830 } else if (es->hloc16) {
1831 LOCAL_Unlock(wnd->hInstance, es->hloc16);
1832 es->text = NULL;
1833 }
1834 }
1835 es->lock_count--;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001836}
1837
1838
1839/*********************************************************************
1840 *
1841 * EDIT_WordBreakProc
1842 *
1843 * Find the beginning of words.
1844 * Note: unlike the specs for a WordBreakProc, this function only
1845 * allows to be called without linebreaks between s[0] upto
1846 * s[count - 1]. Remember it is only called
1847 * internally, so we can decide this for ourselves.
1848 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001849 */
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001850static INT32 EDIT_WordBreakProc(LPSTR s, INT32 index, INT32 count, INT32 action)
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001851{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001852 INT32 ret = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001853
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001854 dprintf_edit(stddeb, "edit: EDIT_WordBreakProc: s=%p, index=%u"
1855 ", count=%u, action=%d\n", s, index, count, action);
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001856
Alexandre Julliard329f0681996-04-14 13:21:20 +00001857 switch (action) {
1858 case WB_LEFT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001859 if (!count)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001860 break;
1861 if (index)
1862 index--;
1863 if (s[index] == ' ') {
1864 while (index && (s[index] == ' '))
1865 index--;
1866 if (index) {
1867 while (index && (s[index] != ' '))
1868 index--;
1869 if (s[index] == ' ')
1870 index++;
1871 }
1872 } else {
1873 while (index && (s[index] != ' '))
1874 index--;
1875 if (s[index] == ' ')
1876 index++;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001877 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001878 ret = index;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001879 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001880 case WB_RIGHT:
1881 if (!count)
1882 break;
1883 if (index)
1884 index--;
1885 if (s[index] == ' ')
1886 while ((index < count) && (s[index] == ' ')) index++;
1887 else {
1888 while (s[index] && (s[index] != ' ') && (index < count))
1889 index++;
1890 while ((s[index] == ' ') && (index < count)) index++;
1891 }
1892 ret = index;
1893 break;
1894 case WB_ISDELIMITER:
1895 ret = (s[index] == ' ');
1896 break;
1897 default:
1898 fprintf(stderr, "edit: EDIT_WordBreakProc: unknown action code, please report !\n");
1899 break;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001900 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001901 return ret;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001902}
1903
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001904
Alexandre Julliard329f0681996-04-14 13:21:20 +00001905/*********************************************************************
1906 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001907 * EM_CHARFROMPOS
1908 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001909 * FIXME: do the specs mean to return LineIndex or LineNumber ???
1910 * Let's assume LineIndex is meant
1911 * FIXME: do the specs mean to return -1 if outside client area or
1912 * if outside formatting rectangle ???
1913 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001914 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001915static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001916{
1917 POINT32 pt;
1918 RECT32 rc;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001919 INT32 index;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001920
Alexandre Julliard889f7421997-04-15 17:19:52 +00001921 pt.x = x;
1922 pt.y = y;
1923 GetClientRect32(wnd->hwndSelf, &rc);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001924 if (!PtInRect32(&rc, pt))
1925 return -1;
1926
Alexandre Julliard889f7421997-04-15 17:19:52 +00001927 index = EDIT_CharFromPos(wnd, es, x, y, NULL);
1928 return MAKELONG(index, EDIT_EM_LineIndex(wnd, es,
1929 EDIT_EM_LineFromChar(wnd, es, index)));
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001930}
1931
Alexandre Julliard329f0681996-04-14 13:21:20 +00001932
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001933/*********************************************************************
Alexandre Julliard329f0681996-04-14 13:21:20 +00001934 *
1935 * EM_FMTLINES
1936 *
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001937 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001938static BOOL32 EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL32 add_eol)
Alexandre Julliard58199531994-04-21 01:20:00 +00001939{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001940 fprintf(stdnimp, "edit: EM_FMTLINES: message not implemented\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00001941 return add_eol;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001942}
Alexandre Julliard988ca971994-06-21 16:15:21 +00001943
Alexandre Julliard58199531994-04-21 01:20:00 +00001944
Alexandre Julliard329f0681996-04-14 13:21:20 +00001945/*********************************************************************
1946 *
1947 * EM_GETHANDLE
1948 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001949 * Hopefully this won't fire back at us.
1950 * We always start with a fixed buffer in our own heap.
1951 * However, with this message a 32 bit application requests
1952 * a handle to 32 bit moveable local heap memory, where it expects
1953 * to find the text.
1954 * It's a pitty that from this moment on we have to use this
1955 * local heap, because applications may rely on the handle
1956 * in the future.
1957 *
1958 * In this function we'll try to switch to local heap.
1959 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00001960 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001961static HLOCAL32 EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001962{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001963 HLOCAL32 newBuf;
1964 LPSTR newText;
1965 INT32 newSize;
Alexandre Julliard58199531994-04-21 01:20:00 +00001966
Alexandre Julliard889f7421997-04-15 17:19:52 +00001967 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001968 return 0;
1969
Alexandre Julliard889f7421997-04-15 17:19:52 +00001970 if (es->hloc32)
1971 return es->hloc32;
1972 else if (es->hloc16)
1973 return (HLOCAL32)es->hloc16;
1974
1975 if (!(newBuf = LocalAlloc32(LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) {
1976 fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 32 bit buffer\n");
1977 return 0;
1978 }
1979 newSize = MIN(LocalSize32(newBuf) - 1, es->buffer_limit);
1980 if (!(newText = LocalLock32(newBuf))) {
1981 fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 32 bit buffer\n");
1982 LocalFree32(newBuf);
1983 return 0;
1984 }
1985 lstrcpy32A(newText, es->text);
1986 EDIT_UnlockBuffer(wnd, es, TRUE);
1987 if (es->text)
1988 HeapFree(es->heap, 0, es->text);
1989 es->hloc32 = newBuf;
1990 es->hloc16 = (HLOCAL16)NULL;
1991 es->buffer_size = newSize;
1992 es->text = newText;
1993 EDIT_LockBuffer(wnd, es);
1994 dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 32 bit local heap\n");
1995
1996 return es->hloc32;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001997}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001998
1999
2000/*********************************************************************
2001 *
2002 * EM_GETHANDLE16
2003 *
2004 * Hopefully this won't fire back at us.
2005 * We always start with a buffer in 32 bit linear memory.
2006 * However, with this message a 16 bit application requests
2007 * a handle of 16 bit local heap memory, where it expects to find
2008 * the text.
2009 * It's a pitty that from this moment on we have to use this
2010 * local heap, because applications may rely on the handle
2011 * in the future.
2012 *
2013 * In this function we'll try to switch to local heap.
2014 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002015static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002016{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002017 HLOCAL16 newBuf;
2018 LPSTR newText;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002019 INT32 newSize;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002020
Alexandre Julliard889f7421997-04-15 17:19:52 +00002021 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002022 return 0;
2023
Alexandre Julliard889f7421997-04-15 17:19:52 +00002024 if (es->hloc16)
2025 return es->hloc16;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002026
Alexandre Julliard889f7421997-04-15 17:19:52 +00002027 if (!LOCAL_HeapSize(wnd->hInstance)) {
2028 if (!LocalInit(wnd->hInstance, 0,
2029 GlobalSize16(wnd->hInstance))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002030 fprintf(stderr, "edit: EM_GETHANDLE: could not initialize local heap\n");
2031 return 0;
2032 }
2033 dprintf_edit(stddeb, "edit: EM_GETHANDLE: local heap initialized\n");
2034 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002035 if (!(newBuf = LOCAL_Alloc(wnd->hInstance, LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002036 fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 16 bit buffer\n");
2037 return 0;
2038 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002039 newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit);
2040 if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002041 fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 16 bit buffer\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002042 LOCAL_Free(wnd->hInstance, newBuf);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002043 return 0;
2044 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002045 lstrcpy32A(newText, es->text);
2046 EDIT_UnlockBuffer(wnd, es, TRUE);
2047 if (es->text)
2048 HeapFree(es->heap, 0, es->text);
2049 else if (es->hloc32) {
2050 while (LocalFree32(es->hloc32)) ;
2051 LocalFree32(es->hloc32);
2052 }
2053 es->hloc32 = (HLOCAL32)NULL;
2054 es->hloc16 = newBuf;
2055 es->buffer_size = newSize;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002056 es->text = newText;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002057 EDIT_LockBuffer(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002058 dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 16 bit buffer\n");
2059
Alexandre Julliard889f7421997-04-15 17:19:52 +00002060 return es->hloc16;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002061}
2062
Alexandre Julliard58199531994-04-21 01:20:00 +00002063
Alexandre Julliard329f0681996-04-14 13:21:20 +00002064/*********************************************************************
2065 *
2066 * EM_GETLINE
2067 *
2068 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002069static INT32 EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT32 line, LPSTR lpch)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002070{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002071 LPSTR src;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002072 INT32 len;
2073 INT32 i;
Alexandre Julliard58199531994-04-21 01:20:00 +00002074
Alexandre Julliard889f7421997-04-15 17:19:52 +00002075 if (es->style & ES_MULTILINE) {
2076 if (line >= es->line_count)
2077 return 0;
2078 } else
2079 line = 0;
2080 src = es->text + EDIT_EM_LineIndex(wnd, es, line);
2081 len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, line));
Alexandre Julliard329f0681996-04-14 13:21:20 +00002082 for (i = 0 ; i < len ; i++) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002083 *lpch = *src;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002084 src++;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002085 lpch++;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002086 }
2087 return (LRESULT)len;
2088}
Alexandre Julliard58199531994-04-21 01:20:00 +00002089
Alexandre Julliard58199531994-04-21 01:20:00 +00002090
Alexandre Julliard329f0681996-04-14 13:21:20 +00002091/*********************************************************************
2092 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002093 * EM_GETSEL
2094 *
2095 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002096static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT32 start, LPUINT32 end)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002097{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002098 UINT32 s = es->selection_start;
2099 UINT32 e = es->selection_end;
Alexandre Julliard58199531994-04-21 01:20:00 +00002100
Alexandre Julliard889f7421997-04-15 17:19:52 +00002101 ORDER_UINT32(s, e);
2102 if (start)
2103 *start = s;
2104 if (end)
2105 *end = e;
2106 return MAKELONG(s, e);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002107}
2108
2109
2110/*********************************************************************
2111 *
2112 * EM_GETTHUMB
2113 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002114 * FIXME: is this right ? (or should it be only VSCROLL)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002115 * (and maybe only for edit controls that really have their
2116 * own scrollbars) (and maybe only for multiline controls ?)
2117 * All in all: very poorly documented
Alexandre Julliard329f0681996-04-14 13:21:20 +00002118 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002119 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2120 * WM_VSCROLL handlers
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002121 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002122 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002123static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002124{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002125 return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB16, 0, 0),
2126 EDIT_WM_HScroll(wnd, es, EM_GETTHUMB16, 0, 0));
Alexandre Julliard329f0681996-04-14 13:21:20 +00002127}
2128
2129
2130/*********************************************************************
2131 *
2132 * EM_LINEFROMCHAR
2133 *
2134 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002135static INT32 EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT32 index)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002136{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002137 INT32 line;
2138 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002139
Alexandre Julliard889f7421997-04-15 17:19:52 +00002140 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002141 return 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002142 if (index > lstrlen32A(es->text))
2143 return es->line_count - 1;
2144 if (index == -1)
2145 index = MIN(es->selection_start, es->selection_end);
2146
2147 line = 0;
2148 line_def = es->first_line_def;
2149 index -= line_def->length;
2150 while ((index >= 0) && line_def->next) {
2151 line++;
2152 line_def = line_def->next;
2153 index -= line_def->length;
2154 }
2155 return line;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002156}
2157
2158
2159/*********************************************************************
2160 *
2161 * EM_LINEINDEX
2162 *
2163 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002164static INT32 EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT32 line)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002165{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002166 INT32 line_index;
2167 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002168
Alexandre Julliard889f7421997-04-15 17:19:52 +00002169 if (!(es->style & ES_MULTILINE))
2170 return 0;
2171 if (line >= es->line_count)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002172 return -1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002173
2174 line_index = 0;
2175 line_def = es->first_line_def;
2176 if (line == -1) {
2177 INT32 index = es->selection_end - line_def->length;
2178 while ((index >= 0) && line_def->next) {
2179 line_index += line_def->length;
2180 line_def = line_def->next;
2181 index -= line_def->length;
2182 }
2183 } else {
2184 while (line > 0) {
2185 line_index += line_def->length;
2186 line_def = line_def->next;
2187 line--;
2188 }
2189 }
2190 return line_index;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002191}
2192
2193
2194/*********************************************************************
2195 *
2196 * EM_LINELENGTH
2197 *
2198 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002199static INT32 EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT32 index)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002200{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002201 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002202
Alexandre Julliard889f7421997-04-15 17:19:52 +00002203 if (!(es->style & ES_MULTILINE))
2204 return lstrlen32A(es->text);
2205
2206 if (index == -1) {
2207 /* FIXME: broken
2208 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2209 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2210 return es->selection_start - es->line_defs[sl].offset +
2211 es->line_defs[el].offset +
2212 es->line_defs[el].length - es->selection_end;
2213 */
2214 return 0;
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002215 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002216 line_def = es->first_line_def;
2217 index -= line_def->length;
2218 while ((index >= 0) && line_def->next) {
2219 line_def = line_def->next;
2220 index -= line_def->length;
2221 }
2222 return line_def->net_length;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002223}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002224
Alexandre Julliard329f0681996-04-14 13:21:20 +00002225
2226/*********************************************************************
2227 *
2228 * EM_LINESCROLL
2229 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002230 * FIXME: dx is in average character widths
2231 * However, we assume it is in pixels when we use this
2232 * function internally
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002233 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002234 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002235static BOOL32 EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT32 dx, INT32 dy)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002236{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002237 INT32 nyoff;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002238
Alexandre Julliard889f7421997-04-15 17:19:52 +00002239 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002240 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002241
2242 if (-dx > es->x_offset)
2243 dx = -es->x_offset;
2244 if (dx > es->text_width - es->x_offset)
2245 dx = es->text_width - es->x_offset;
2246 nyoff = MAX(0, es->y_offset + dy);
2247 if (nyoff >= es->line_count)
2248 nyoff = es->line_count - 1;
2249 dy = (es->y_offset - nyoff) * es->line_height;
2250 if (dx || dy) {
2251 if (!(wnd->flags & WIN_NO_REDRAW)) {
2252 RECT32 rc1;
2253 RECT32 rc;
2254 GetClientRect32(wnd->hwndSelf, &rc1);
2255 IntersectRect32(&rc, &rc1, &es->format_rect);
2256 ScrollWindowEx32(wnd->hwndSelf, -dx, dy,
2257 NULL, &rc, (HRGN32)NULL, NULL, SW_INVALIDATE);
2258 }
2259 es->y_offset = nyoff;
2260 es->x_offset += dx;
2261 }
2262 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2263 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
2264 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2265 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
2266 return TRUE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002267}
2268
2269
2270/*********************************************************************
2271 *
2272 * EM_POSFROMCHAR
2273 *
2274 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002275static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT32 index, BOOL32 after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002276{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002277 INT32 len = lstrlen32A(es->text);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002278 INT32 l;
2279 INT32 li;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002280 INT32 x;
2281 INT32 y = 0;
2282 HDC32 dc;
2283 HFONT32 old_font = 0;
2284 SIZE32 size;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002285
Alexandre Julliard889f7421997-04-15 17:19:52 +00002286 index = MIN(index, len);
2287 dc = GetDC32(wnd->hwndSelf);
2288 if (es->font)
2289 old_font = SelectObject32(dc, es->font);
2290 if (es->style & ES_MULTILINE) {
2291 l = EDIT_EM_LineFromChar(wnd, es, index);
2292 y = (l - es->y_offset) * es->line_height;
2293 li = EDIT_EM_LineIndex(wnd, es, l);
2294 if (after_wrap && (li == index) && l) {
2295 INT32 l2 = l - 1;
2296 LINEDEF *line_def = es->first_line_def;
2297 while (l2) {
2298 line_def = line_def->next;
2299 l2--;
2300 }
2301 if (line_def->ending == END_WRAP) {
2302 l--;
2303 y -= es->line_height;
2304 li = EDIT_EM_LineIndex(wnd, es, l);
2305 }
2306 }
2307 x = LOWORD(GetTabbedTextExtent32A(dc, es->text + li, index - li,
2308 es->tabs_count, es->tabs)) - es->x_offset;
2309 } else {
2310 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
2311 if (index < es->x_offset) {
2312 GetTextExtentPoint32A(dc, text + index,
2313 es->x_offset - index, &size);
2314 x = -size.cx;
2315 } else {
2316 GetTextExtentPoint32A(dc, text + es->x_offset,
2317 index - es->x_offset, &size);
2318 x = size.cx;
2319 }
2320 y = 0;
2321 if (es->style & ES_PASSWORD)
2322 HeapFree(es->heap, 0 ,text);
2323 }
2324 x += es->format_rect.left;
2325 y += es->format_rect.top;
2326 if (es->font)
2327 SelectObject32(dc, old_font);
2328 ReleaseDC32(wnd->hwndSelf, dc);
2329 return MAKELONG((INT16)x, (INT16)y);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002330}
2331
2332
2333/*********************************************************************
2334 *
2335 * EM_REPLACESEL
2336 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002337 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2338 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002339 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002340static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL32 can_undo, LPCSTR lpsz_replace)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002341{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002342 INT32 strl = lstrlen32A(lpsz_replace);
2343 INT32 tl = lstrlen32A(es->text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002344 INT32 utl;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002345 UINT32 s;
2346 UINT32 e;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002347 INT32 i;
2348 LPSTR p;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002349
Alexandre Julliard889f7421997-04-15 17:19:52 +00002350 s = es->selection_start;
2351 e = es->selection_end;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002352
2353 if ((s == e) && !strl)
Alexandre Julliard889f7421997-04-15 17:19:52 +00002354 return;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002355
Alexandre Julliard889f7421997-04-15 17:19:52 +00002356 ORDER_UINT32(s, e);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002357
Alexandre Julliard889f7421997-04-15 17:19:52 +00002358 if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl))
2359 return;
2360
Alexandre Julliard01d63461997-01-20 19:43:45 +00002361 if (e != s) {
2362 /* there is something to be deleted */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002363 if (can_undo) {
2364 utl = lstrlen32A(es->undo_text);
2365 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
Alexandre Julliard01d63461997-01-20 19:43:45 +00002366 /* undo-buffer is extended to the right */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002367 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2368 lstrcpyn32A(es->undo_text + utl, es->text + s, e - s + 1);
2369 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
Alexandre Julliard01d63461997-01-20 19:43:45 +00002370 /* undo-buffer is extended to the left */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002371 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2372 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002373 p[e - s] = p[0];
Alexandre Julliard889f7421997-04-15 17:19:52 +00002374 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2375 p[i] = (es->text + s)[i];
2376 es->undo_position = s;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002377 } else {
2378 /* new undo-buffer */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002379 EDIT_MakeUndoFit(wnd, es, e - s);
2380 lstrcpyn32A(es->undo_text, es->text + s, e - s + 1);
2381 es->undo_position = s;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002382 }
2383 /* any deletion makes the old insertion-undo invalid */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002384 es->undo_insert_count = 0;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002385 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002386 EDIT_EM_EmptyUndoBuffer(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002387
2388 /* now delete */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002389 lstrcpy32A(es->text + s, es->text + e);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002390 }
2391 if (strl) {
2392 /* there is an insertion */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002393 if (can_undo) {
2394 if ((s == es->undo_position) ||
2395 ((es->undo_insert_count) &&
2396 (s == es->undo_position + es->undo_insert_count)))
Alexandre Julliard01d63461997-01-20 19:43:45 +00002397 /*
2398 * insertion is new and at delete position or
2399 * an extension to either left or right
2400 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002401 es->undo_insert_count += strl;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002402 else {
2403 /* new insertion undo */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002404 es->undo_position = s;
2405 es->undo_insert_count = strl;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002406 /* new insertion makes old delete-buffer invalid */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002407 *es->undo_text = '\0';
Alexandre Julliard01d63461997-01-20 19:43:45 +00002408 }
2409 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002410 EDIT_EM_EmptyUndoBuffer(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002411
2412 /* now insert */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002413 tl = lstrlen32A(es->text);
2414 for (p = es->text + tl ; p >= es->text + s ; p--)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002415 p[strl] = p[0];
Alexandre Julliard889f7421997-04-15 17:19:52 +00002416 for (i = 0 , p = es->text + s ; i < strl ; i++)
2417 p[i] = lpsz_replace[i];
2418 if(es->style & ES_UPPERCASE)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002419 CharUpperBuff32A(p, strl);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002420 else if(es->style & ES_LOWERCASE)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002421 CharLowerBuff32A(p, strl);
2422 s += strl;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002423 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002424 /* FIXME: really inefficient */
2425 if (es->style & ES_MULTILINE)
2426 EDIT_BuildLineDefs_ML(wnd, es);
2427
2428 EDIT_EM_SetSel(wnd, es, s, s, FALSE);
2429 es->flags |= EF_MODIFIED;
2430 es->flags |= EF_UPDATE;
2431 EDIT_EM_ScrollCaret(wnd, es);
2432
2433 /* FIXME: really inefficient */
2434 if (!(wnd->flags & WIN_NO_REDRAW))
2435 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002436}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002437
Alexandre Julliard329f0681996-04-14 13:21:20 +00002438
2439/*********************************************************************
2440 *
2441 * EM_SCROLL
Alexandre Julliard889f7421997-04-15 17:19:52 +00002442 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002443 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002444static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT32 action)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002445{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002446 INT32 dy;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002447
Alexandre Julliard889f7421997-04-15 17:19:52 +00002448 if (!(es->style & ES_MULTILINE))
2449 return (LRESULT)FALSE;
2450
2451 dy = 0;
2452
2453 switch (action) {
2454 case SB_LINEUP:
2455 if (es->y_offset)
2456 dy = -1;
2457 break;
2458 case SB_LINEDOWN:
2459 if (es->y_offset < es->line_count - 1)
2460 dy = 1;
2461 break;
2462 case SB_PAGEUP:
2463 if (es->y_offset)
2464 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
2465 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002466 case SB_PAGEDOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002467 if (es->y_offset < es->line_count - 1)
2468 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2469 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002470 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002471 return (LRESULT)FALSE;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002472 }
2473 if (dy) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002474 EDIT_EM_LineScroll(wnd, es, 0, dy);
2475 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002476 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002477 return MAKELONG((INT16)dy, (BOOL16)TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002478}
2479
2480
2481/*********************************************************************
2482 *
2483 * EM_SETHANDLE
2484 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002485 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2486 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002487 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002488static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL32 hloc)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002489{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002490 if (!(es->style & ES_MULTILINE))
2491 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002492
Alexandre Julliard889f7421997-04-15 17:19:52 +00002493 if (!hloc) {
2494 fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n");
2495 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002496 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002497
2498 EDIT_UnlockBuffer(wnd, es, TRUE);
2499 /*
2500 * old buffer is freed by caller, unless
2501 * it is still in our own heap. (in that case
2502 * we free it, correcting the buggy caller.)
2503 */
2504 if (es->text)
2505 HeapFree(es->heap, 0, es->text);
2506
2507 es->hloc16 = (HLOCAL16)NULL;
2508 es->hloc32 = hloc;
2509 es->text = NULL;
2510 es->buffer_size = LocalSize32(es->hloc32) - 1;
2511 EDIT_LockBuffer(wnd, es);
2512
2513 es->x_offset = es->y_offset = 0;
2514 es->selection_start = es->selection_end = 0;
2515 EDIT_EM_EmptyUndoBuffer(wnd, es);
2516 es->flags &= ~EF_MODIFIED;
2517 es->flags &= ~EF_UPDATE;
2518 EDIT_BuildLineDefs_ML(wnd, es);
2519 if (!(wnd->flags & WIN_NO_REDRAW))
2520 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2521 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002522}
2523
2524
2525/*********************************************************************
2526 *
2527 * EM_SETHANDLE16
2528 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002529 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2530 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002531 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002532static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002533{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002534 if (!(es->style & ES_MULTILINE))
2535 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002536
Alexandre Julliard889f7421997-04-15 17:19:52 +00002537 if (!hloc) {
2538 fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n");
2539 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002540 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002541
2542 EDIT_UnlockBuffer(wnd, es, TRUE);
2543 /*
2544 * old buffer is freed by caller, unless
2545 * it is still in our own heap. (in that case
2546 * we free it, correcting the buggy caller.)
2547 */
2548 if (es->text)
2549 HeapFree(es->heap, 0, es->text);
2550
2551 es->hloc16 = hloc;
2552 es->hloc32 = (HLOCAL32)NULL;
2553 es->text = NULL;
2554 es->buffer_size = LOCAL_Size(wnd->hInstance, es->hloc16) - 1;
2555 EDIT_LockBuffer(wnd, es);
2556
2557 es->x_offset = es->y_offset = 0;
2558 es->selection_start = es->selection_end = 0;
2559 EDIT_EM_EmptyUndoBuffer(wnd, es);
2560 es->flags &= ~EF_MODIFIED;
2561 es->flags &= ~EF_UPDATE;
2562 EDIT_BuildLineDefs_ML(wnd, es);
2563 if (!(wnd->flags & WIN_NO_REDRAW))
2564 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2565 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002566}
2567
2568
2569/*********************************************************************
2570 *
2571 * EM_SETLIMITTEXT
2572 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002573 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2574 * However, the windows version is not complied to yet in all of edit.c
2575 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002576 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002577static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT32 limit)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002578{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002579 if (es->style & ES_MULTILINE) {
2580 if (limit)
2581 es->buffer_limit = MIN(limit, BUFLIMIT_MULTI);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002582 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002583 es->buffer_limit = BUFLIMIT_MULTI;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002584 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002585 if (limit)
2586 es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002587 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002588 es->buffer_limit = BUFLIMIT_SINGLE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002589 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002590}
2591
2592
2593/*********************************************************************
2594 *
2595 * EM_SETMARGINS
2596 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002597 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002598static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT32 action, INT32 left, INT32 right)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002599{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002600 if (action & EC_USEFONTINFO) {
2601 if (es->style & ES_MULTILINE) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002602 /*
2603 * FIXME: do some GetABCCharWidth, or so
2604 * This is just preliminary
2605 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002606 es->left_margin = es->right_margin = es->char_width;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002607 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002608 es->left_margin = es->right_margin = es->char_width;
2609 return;
2610 } else {
2611 if (action & EC_LEFTMARGIN)
2612 es->left_margin = left;
2613 if (action & EC_RIGHTMARGIN)
2614 es->right_margin = right;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002615 }
Alexandre Julliard58199531994-04-21 01:20:00 +00002616}
2617
Alexandre Julliard329f0681996-04-14 13:21:20 +00002618
2619/*********************************************************************
2620 *
2621 * EM_SETPASSWORDCHAR
2622 *
2623 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002624static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002625{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002626 if (es->style & ES_MULTILINE)
2627 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002628
Alexandre Julliard889f7421997-04-15 17:19:52 +00002629 if (es->password_char == c)
2630 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002631
Alexandre Julliard889f7421997-04-15 17:19:52 +00002632 es->password_char = c;
2633 if (c) {
2634 wnd->dwStyle |= ES_PASSWORD;
2635 es->style |= ES_PASSWORD;
2636 } else {
2637 wnd->dwStyle &= ~ES_PASSWORD;
2638 es->style &= ~ES_PASSWORD;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002639 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002640 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002641}
2642
2643
2644/*********************************************************************
2645 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002646 * EDIT_EM_SetSel
2647 *
2648 * note: unlike the specs say: the order of start and end
2649 * _is_ preserved in Windows. (i.e. start can be > end)
2650 * In other words: this handler is OK
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002651 *
2652 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002653static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT32 start, UINT32 end, BOOL32 after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002654{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002655 UINT32 old_start = es->selection_start;
2656 UINT32 old_end = es->selection_end;
2657 UINT32 len = lstrlen32A(es->text);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002658
Alexandre Julliard889f7421997-04-15 17:19:52 +00002659 if (start == -1) {
2660 start = es->selection_end;
2661 end = es->selection_end;
2662 } else {
2663 start = MIN(start, len);
2664 end = MIN(end, len);
2665 }
2666 es->selection_start = start;
2667 es->selection_end = end;
2668 if (after_wrap)
2669 es->flags |= EF_AFTER_WRAP;
2670 else
2671 es->flags &= ~EF_AFTER_WRAP;
2672 if (!(wnd->flags & WIN_NO_REDRAW)) {
2673 if (es->flags & EF_FOCUSED) {
2674 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, end, after_wrap);
2675 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
2676 }
2677 /* FIXME: little efficiency, could be better */
2678 ORDER_UINT32(start, end);
2679 ORDER_UINT32(start, old_start);
2680 ORDER_UINT32(start, old_end);
2681 ORDER_UINT32(end, old_start);
2682 ORDER_UINT32(end, old_end);
2683 ORDER_UINT32(old_start, old_end);
2684 if (end != old_start) {
2685 EDIT_InvalidateText(wnd, es, start, end);
2686 EDIT_InvalidateText(wnd, es, old_start, old_end);
2687 } else
2688 EDIT_InvalidateText(wnd, es, start, old_end);
2689 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002690}
2691
2692
2693/*********************************************************************
2694 *
2695 * EM_SETTABSTOPS
2696 *
2697 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002698static BOOL32 EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT32 count, LPINT32 tabs)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002699{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002700 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002701 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002702 if (es->tabs)
2703 HeapFree(es->heap, 0, es->tabs);
2704 es->tabs_count = count;
2705 if (!count)
2706 es->tabs = NULL;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002707 else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002708 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32));
2709 memcpy(es->tabs, tabs, count * sizeof(INT32));
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002710 }
2711 return TRUE;
2712}
2713
2714
2715/*********************************************************************
2716 *
2717 * EM_SETTABSTOPS16
2718 *
2719 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002720static BOOL32 EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT32 count, LPINT16 tabs)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002721{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002722 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002723 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002724 if (es->tabs)
2725 HeapFree(es->heap, 0, es->tabs);
2726 es->tabs_count = count;
2727 if (!count)
2728 es->tabs = NULL;
2729 else {
2730 INT32 i;
2731 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32));
2732 for (i = 0 ; i < count ; i++)
2733 es->tabs[i] = *tabs++;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002734 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002735 return TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002736}
2737
2738
2739/*********************************************************************
2740 *
2741 * EM_SETWORDBREAKPROC
2742 *
2743 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002744static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC32A wbp)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002745{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002746 if (es->word_break_proc32A == wbp)
2747 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002748
Alexandre Julliard889f7421997-04-15 17:19:52 +00002749 es->word_break_proc32A = wbp;
2750 es->word_break_proc16 = NULL;
2751 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2752 EDIT_BuildLineDefs_ML(wnd, es);
2753 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2754 }
2755}
2756
2757
2758/*********************************************************************
2759 *
2760 * EM_SETWORDBREAKPROC16
2761 *
2762 */
2763static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
2764{
2765 if (es->word_break_proc16 == wbp)
2766 return;
2767
2768 es->word_break_proc32A = NULL;
2769 es->word_break_proc16 = wbp;
2770 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2771 EDIT_BuildLineDefs_ML(wnd, es);
2772 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2773 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002774}
2775
2776
2777/*********************************************************************
2778 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002779 * EM_UNDO / WM_UNDO
Alexandre Julliard329f0681996-04-14 13:21:20 +00002780 *
2781 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002782static BOOL32 EDIT_EM_Undo(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002783{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002784 INT32 ulength = lstrlen32A(es->undo_text);
2785 LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1);
2786
2787 lstrcpy32A(utext, es->undo_text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002788
2789 dprintf_edit(stddeb, "edit: before UNDO:insertion length = %d, deletion buffer = %s\n",
Alexandre Julliard889f7421997-04-15 17:19:52 +00002790 es->undo_insert_count, utext);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002791
Alexandre Julliard889f7421997-04-15 17:19:52 +00002792 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2793 EDIT_EM_EmptyUndoBuffer(wnd, es);
2794 EDIT_EM_ReplaceSel(wnd, es, TRUE, utext);
2795 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2796 HeapFree(es->heap, 0, utext);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002797
2798 dprintf_edit(stddeb, "edit: after UNDO: insertion length = %d, deletion buffer = %s\n",
Alexandre Julliard889f7421997-04-15 17:19:52 +00002799 es->undo_insert_count, es->undo_text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002800
2801 return TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002802}
2803
2804
2805/*********************************************************************
2806 *
2807 * WM_CHAR
2808 *
2809 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002810static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002811{
Alexandre Julliard329f0681996-04-14 13:21:20 +00002812 switch (c) {
2813 case '\r':
2814 case '\n':
Alexandre Julliard889f7421997-04-15 17:19:52 +00002815 if (es->style & ES_MULTILINE) {
2816 if (es->style & ES_READONLY) {
2817 EDIT_MoveHome(wnd, es, FALSE);
2818 EDIT_MoveDown_ML(wnd, es, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002819 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002820 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n");
Alexandre Julliard329f0681996-04-14 13:21:20 +00002821 }
2822 break;
2823 case '\t':
Alexandre Julliard889f7421997-04-15 17:19:52 +00002824 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
2825 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t");
Alexandre Julliard329f0681996-04-14 13:21:20 +00002826 break;
2827 default:
Alexandre Julliard77b99181997-09-14 17:17:23 +00002828 if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002829 char str[2];
Alexandre Julliard329f0681996-04-14 13:21:20 +00002830 str[0] = c;
2831 str[1] = '\0';
Alexandre Julliard889f7421997-04-15 17:19:52 +00002832 EDIT_EM_ReplaceSel(wnd, es, TRUE, str);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002833 }
2834 break;
2835 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00002836}
2837
2838
2839/*********************************************************************
2840 *
2841 * WM_COMMAND
2842 *
2843 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002844static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT32 code, INT32 id, HWND32 control)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002845{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002846 if (code || control)
2847 return;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002848
Alexandre Julliard889f7421997-04-15 17:19:52 +00002849 switch (id) {
2850 case EM_UNDO32:
2851 EDIT_EM_Undo(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002852 break;
2853 case WM_CUT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002854 EDIT_WM_Cut(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002855 break;
2856 case WM_COPY:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002857 EDIT_WM_Copy(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002858 break;
2859 case WM_PASTE:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002860 EDIT_WM_Paste(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002861 break;
2862 case WM_CLEAR:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002863 EDIT_WM_Clear(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002864 break;
2865 case EM_SETSEL32:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002866 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
2867 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002868 break;
2869 default:
2870 dprintf_edit(stddeb, "edit: unknown menu item, please report\n");
2871 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002872 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002873}
2874
2875
2876/*********************************************************************
2877 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002878 * WM_CONTEXTMENU
2879 *
2880 * Note: the resource files resource/sysres_??.rc cannot define a
2881 * single popup menu. Hence we use a (dummy) menubar
2882 * containing the single popup menu as its first item.
2883 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002884 * FIXME: the message identifiers have been chosen arbitrarily,
2885 * hence we use MF_BYPOSITION.
2886 * We might as well use the "real" values (anybody knows ?)
2887 * The menu definition is in resources/sysres_??.rc.
2888 * Once these are OK, we better use MF_BYCOMMAND here
2889 * (as we do in EDIT_WM_Command()).
2890 *
2891 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002892static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND32 hwnd, INT32 x, INT32 y)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002893{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002894 HMENU32 menu = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU));
2895 HMENU32 popup = GetSubMenu32(menu, 0);
2896 UINT32 start = es->selection_start;
2897 UINT32 end = es->selection_end;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002898
Alexandre Julliard889f7421997-04-15 17:19:52 +00002899 ORDER_UINT32(start, end);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002900
2901 /* undo */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002902 EnableMenuItem32(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(wnd, es) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002903 /* cut */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002904 EnableMenuItem32(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002905 /* copy */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002906 EnableMenuItem32(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002907 /* paste */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002908 EnableMenuItem32(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable32(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002909 /* delete */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002910 EnableMenuItem32(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002911 /* select all */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002912 EnableMenuItem32(popup, 7, MF_BYPOSITION | (start || (end != lstrlen32A(es->text)) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002913
Alexandre Julliard889f7421997-04-15 17:19:52 +00002914 TrackPopupMenu32(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL);
2915 DestroyMenu32(menu);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002916}
2917
Alexandre Julliard889f7421997-04-15 17:19:52 +00002918
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002919/*********************************************************************
2920 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002921 * WM_COPY
2922 *
2923 * FIXME: replace with 32 bit calls as soon as they are implemented
2924 * in the clipboard code
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002925 *
2926 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002927static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002928{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002929 INT32 s = es->selection_start;
2930 INT32 e = es->selection_end;
2931 HGLOBAL16 hdst;
2932 LPSTR dst;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002933
Alexandre Julliard889f7421997-04-15 17:19:52 +00002934 if (e == s)
2935 return;
2936 ORDER_INT32(s, e);
2937 hdst = GlobalAlloc16(GMEM_MOVEABLE, (DWORD)(e - s + 1));
2938 dst = GlobalLock16(hdst);
2939 lstrcpyn32A(dst, es->text + s, e - s + 1);
2940 GlobalUnlock16(hdst);
2941 OpenClipboard32(wnd->hwndSelf);
2942 EmptyClipboard32();
2943 SetClipboardData16(CF_TEXT, hdst);
2944 CloseClipboard32();
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002945}
Alexandre Julliard01d63461997-01-20 19:43:45 +00002946
Alexandre Julliard889f7421997-04-15 17:19:52 +00002947
2948/*********************************************************************
2949 *
2950 * WM_CREATE
2951 *
2952 */
2953static LRESULT EDIT_WM_Create(WND *wnd, LPCREATESTRUCT32A cs)
2954{
2955 EDITSTATE *es;
2956
2957 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
2958 return -1;
2959 *(EDITSTATE **)wnd->wExtra = es;
2960 if (!(es->heap = HeapCreate(0, 0x10000, 0)))
2961 return -1;
2962 es->style = cs->style;
2963
2964 /* remove the WS_CAPTION style if it has been set - this is really a */
2965 /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
2966 if ((es->style & WS_BORDER) && (es->style & WS_DLGFRAME))
2967 es->style ^= WS_DLGFRAME;
2968
2969 if (es->style & ES_MULTILINE) {
2970 es->buffer_size = BUFSTART_MULTI;
2971 es->buffer_limit = BUFLIMIT_MULTI;
2972 if (es->style & WS_VSCROLL)
2973 es->style |= ES_AUTOVSCROLL;
2974 if (es->style & WS_HSCROLL)
2975 es->style |= ES_AUTOHSCROLL;
2976 es->style &= ~ES_PASSWORD;
2977 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
2978 if (es->style & ES_RIGHT)
2979 es->style &= ~ES_CENTER;
2980 es->style &= ~WS_HSCROLL;
2981 es->style &= ~ES_AUTOHSCROLL;
2982 }
2983
2984 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
2985 es->style |= ES_AUTOVSCROLL;
2986 } else {
2987 es->buffer_size = BUFSTART_SINGLE;
2988 es->buffer_limit = BUFLIMIT_SINGLE;
2989 es->style &= ~ES_CENTER;
2990 es->style &= ~ES_RIGHT;
2991 es->style &= ~WS_HSCROLL;
2992 es->style &= ~WS_VSCROLL;
2993 es->style &= ~ES_AUTOVSCROLL;
2994 es->style &= ~ES_WANTRETURN;
2995 if (es->style & ES_UPPERCASE) {
2996 es->style &= ~ES_LOWERCASE;
2997 es->style &= ~ES_NUMBER;
2998 } else if (es->style & ES_LOWERCASE)
2999 es->style &= ~ES_NUMBER;
3000 if (es->style & ES_PASSWORD)
3001 es->password_char = '*';
3002
3003 /* FIXME: for now, all single line controls are AUTOHSCROLL */
3004 es->style |= ES_AUTOHSCROLL;
3005 }
3006 if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3007 return -1;
3008 es->buffer_size = HeapSize(es->heap, 0, es->text) - 1;
3009 if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3010 return -1;
3011 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
3012 *es->text = '\0';
3013 if (es->style & ES_MULTILINE)
3014 if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
3015 return -1;
3016 es->line_count = 1;
3017 /*
3018 * To initialize some final structure members, we call some helper
3019 * functions. However, since the EDITSTATE is not consistent (i.e.
3020 * not fully initialized), we should be very careful which
3021 * functions can be called, and in what order.
3022 */
3023 EDIT_WM_SetFont(wnd, es, 0, FALSE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00003024 if (cs->lpszName && *(cs->lpszName) != '\0') {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003025 EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName);
Alexandre Julliard641ee761997-08-04 16:34:36 +00003026 /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */
3027 es->selection_start = es->selection_end = 0;
3028 EDIT_EM_ScrollCaret(wnd, es);
3029 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003030 return 0;
3031}
3032
3033
3034/*********************************************************************
3035 *
3036 * WM_DESTROY
3037 *
3038 */
3039static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es)
3040{
3041 if (es->hloc32) {
3042 while (LocalUnlock32(es->hloc32)) ;
3043 LocalFree32(es->hloc32);
3044 }
3045 if (es->hloc16) {
3046 while (LOCAL_Unlock(wnd->hInstance, es->hloc16)) ;
3047 LOCAL_Free(wnd->hInstance, es->hloc16);
3048 }
3049 HeapDestroy(es->heap);
3050 HeapFree(GetProcessHeap(), 0, es);
3051 *(EDITSTATE **)wnd->wExtra = NULL;
3052}
3053
3054
3055/*********************************************************************
3056 *
3057 * WM_ERASEBKGND
3058 *
3059 */
3060static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC32 dc)
3061{
3062 HBRUSH32 brush;
3063 RECT32 rc;
3064
3065 if (!(brush = (HBRUSH32)EDIT_SEND_CTLCOLOR(wnd, dc)))
3066 brush = (HBRUSH32)GetStockObject32(WHITE_BRUSH);
3067
3068 GetClientRect32(wnd->hwndSelf, &rc);
3069 IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom);
3070 GetClipBox32(dc, &rc);
3071 /*
3072 * FIXME: specs say that we should UnrealizeObject() the brush,
3073 * but the specs of UnrealizeObject() say that we shouldn't
3074 * unrealize a stock object. The default brush that
3075 * DefWndProc() returns is ... a stock object.
3076 */
3077 FillRect32(dc, &rc, brush);
3078 return -1;
3079}
3080
3081
3082/*********************************************************************
3083 *
3084 * WM_GETTEXT
3085 *
3086 */
3087static INT32 EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT32 count, LPSTR text)
3088{
3089 INT32 len = lstrlen32A(es->text);
3090
3091 if (count > len) {
3092 lstrcpy32A(text, es->text);
Alexandre Julliard33072e11997-06-29 18:08:02 +00003093 return len;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003094 } else
Alexandre Julliard33072e11997-06-29 18:08:02 +00003095 return -1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003096}
3097
3098
3099/*********************************************************************
3100 *
3101 * EDIT_HScroll_Hack
3102 *
3103 * 16 bit notepad needs this. Actually it is not _our_ hack,
3104 * it is notepad's. Notepad is sending us scrollbar messages with
3105 * undocumented parameters without us even having a scrollbar ... !?!?
3106 *
3107 */
3108static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
3109{
3110 INT32 dx = 0;
3111 INT32 fw = es->format_rect.right - es->format_rect.left;
3112 LRESULT ret = 0;
3113
3114 if (!(es->flags & EF_HSCROLL_HACK)) {
3115 fprintf(stderr, "edit: hacked WM_HSCROLL handler invoked\n");
3116 fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n");
3117 fprintf(stderr, " (this message is only displayed once per edit control)\n");
3118 es->flags |= EF_HSCROLL_HACK;
3119 }
3120
3121 switch (action) {
3122 case SB_LINELEFT:
3123 if (es->x_offset)
3124 dx = -es->char_width;
3125 break;
3126 case SB_LINERIGHT:
3127 if (es->x_offset < es->text_width)
3128 dx = es->char_width;
3129 break;
3130 case SB_PAGELEFT:
3131 if (es->x_offset)
3132 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3133 break;
3134 case SB_PAGERIGHT:
3135 if (es->x_offset < es->text_width)
3136 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3137 break;
3138 case SB_LEFT:
3139 if (es->x_offset)
3140 dx = -es->x_offset;
3141 break;
3142 case SB_RIGHT:
3143 if (es->x_offset < es->text_width)
3144 dx = es->text_width - es->x_offset;
3145 break;
3146 case SB_THUMBTRACK:
3147 es->flags |= EF_HSCROLL_TRACK;
3148 dx = pos * es->text_width / 100 - es->x_offset;
3149 break;
3150 case SB_THUMBPOSITION:
3151 es->flags &= ~EF_HSCROLL_TRACK;
3152 if (!(dx = pos * es->text_width / 100 - es->x_offset))
3153 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3154 break;
3155 case SB_ENDSCROLL:
3156 break;
3157
3158 /*
3159 * FIXME : the next two are undocumented !
3160 * Are we doing the right thing ?
3161 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3162 * although it's also a regular control message.
3163 */
3164 case EM_GETTHUMB16:
3165 ret = es->text_width ? es->x_offset * 100 / es->text_width : 0;
3166 break;
3167 case EM_LINESCROLL16:
3168 dx = pos;
3169 break;
3170
3171 default:
3172 dprintf_edit(stddeb, "edit: undocumented (hacked) WM_HSCROLL parameter, please report\n");
3173 return 0;
3174 }
3175 if (dx)
3176 EDIT_EM_LineScroll(wnd, es, dx, 0);
3177 return ret;
3178}
3179
3180
3181/*********************************************************************
3182 *
3183 * WM_HSCROLL
3184 *
3185 */
3186static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
3187{
3188 INT32 dx;
3189 INT32 fw;
3190
3191 if (!(es->style & ES_MULTILINE))
3192 return 0;
3193
3194 if (!(es->style & ES_AUTOHSCROLL))
3195 return 0;
3196
3197 if (!(es->style & WS_HSCROLL))
3198 return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar);
3199
3200 dx = 0;
3201 fw = es->format_rect.right - es->format_rect.left;
3202 switch (action) {
3203 case SB_LINELEFT:
3204 if (es->x_offset)
3205 dx = -es->char_width;
3206 break;
3207 case SB_LINERIGHT:
3208 if (es->x_offset < es->text_width)
3209 dx = es->char_width;
3210 break;
3211 case SB_PAGELEFT:
3212 if (es->x_offset)
3213 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3214 break;
3215 case SB_PAGERIGHT:
3216 if (es->x_offset < es->text_width)
3217 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3218 break;
3219 case SB_LEFT:
3220 if (es->x_offset)
3221 dx = -es->x_offset;
3222 break;
3223 case SB_RIGHT:
3224 if (es->x_offset < es->text_width)
3225 dx = es->text_width - es->x_offset;
3226 break;
3227 case SB_THUMBTRACK:
3228 es->flags |= EF_HSCROLL_TRACK;
3229 dx = pos - es->x_offset;
3230 break;
3231 case SB_THUMBPOSITION:
3232 es->flags &= ~EF_HSCROLL_TRACK;
3233 if (!(dx = pos - es->x_offset)) {
3234 SetScrollPos32(wnd->hwndSelf, SB_HORZ, pos, TRUE);
3235 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3236 }
3237 break;
3238 case SB_ENDSCROLL:
3239 break;
3240
3241 default:
3242 fprintf(stderr, "edit: undocumented WM_HSCROLL parameter, please report\n");
3243 return 0;
3244 }
3245 if (dx)
3246 EDIT_EM_LineScroll(wnd, es, dx, 0);
3247 return 0;
3248}
3249
3250
3251/*********************************************************************
3252 *
3253 * EDIT_CheckCombo
3254 *
3255 */
3256static BOOL32 EDIT_CheckCombo(WND *wnd, UINT32 msg, INT32 key, DWORD key_data)
3257{
3258 HWND32 hLBox;
3259
3260 if (WIDGETS_IsControl32(wnd->parent, BIC32_COMBO) &&
3261 (hLBox = COMBO_GetLBWindow(wnd->parent))) {
3262 HWND32 hCombo = wnd->parent->hwndSelf;
3263 BOOL32 bUIFlip = TRUE;
3264
3265 dprintf_combo(stddeb, "EDIT_CheckCombo [%04x]: handling msg %04x (%04x)\n",
3266 wnd->hwndSelf, (UINT16)msg, (UINT16)key);
3267
3268 switch (msg) {
3269 case WM_KEYDOWN: /* Handle F4 and arrow keys */
3270 if (key != VK_F4) {
3271 bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0);
3272 if (SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0))
3273 bUIFlip = FALSE;
3274 }
3275 if (!bUIFlip)
3276 SendMessage32A(hLBox, WM_KEYDOWN, (WPARAM32)key, 0);
3277 else {
3278 /* make sure ComboLBox pops up */
3279 SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 0, 0);
3280 SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0);
3281 SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 1, 0);
3282 }
3283 break;
3284 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
3285 bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0);
3286 if (bUIFlip) {
3287 bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0);
3288 SendMessage32A(hCombo, CB_SHOWDROPDOWN32, (bUIFlip) ? FALSE : TRUE, 0);
3289 } else
3290 SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0);
3291 break;
3292 }
3293 return TRUE;
3294 }
3295 return FALSE;
3296}
3297
3298
Alexandre Julliard01d63461997-01-20 19:43:45 +00003299/*********************************************************************
3300 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003301 * WM_KEYDOWN
3302 *
3303 * Handling of special keys that don't produce a WM_CHAR
3304 * (i.e. non-printable keys) & Backspace & Delete
3305 *
3306 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003307static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003308{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003309 BOOL32 shift;
3310 BOOL32 control;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003311
Alexandre Julliard349a9531997-02-02 19:01:52 +00003312 if (GetKeyState32(VK_MENU) & 0x8000)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003313 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003314
Alexandre Julliard349a9531997-02-02 19:01:52 +00003315 shift = GetKeyState32(VK_SHIFT) & 0x8000;
3316 control = GetKeyState32(VK_CONTROL) & 0x8000;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003317
Alexandre Julliard889f7421997-04-15 17:19:52 +00003318 switch (key) {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003319 case VK_F4:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003320 case VK_UP:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003321 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3322 break;
3323 if (key == VK_F4)
3324 break;
3325 /* fall through */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003326 case VK_LEFT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003327 if ((es->style & ES_MULTILINE) && (key == VK_UP))
3328 EDIT_MoveUp_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003329 else
3330 if (control)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003331 EDIT_MoveWordBackward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003332 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003333 EDIT_MoveBackward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003334 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003335 case VK_DOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003336 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3337 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003338 /* fall through */
3339 case VK_RIGHT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003340 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
3341 EDIT_MoveDown_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003342 else if (control)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003343 EDIT_MoveWordForward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003344 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003345 EDIT_MoveForward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003346 break;
3347 case VK_HOME:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003348 EDIT_MoveHome(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003349 break;
3350 case VK_END:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003351 EDIT_MoveEnd(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003352 break;
3353 case VK_PRIOR:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003354 if (es->style & ES_MULTILINE)
3355 EDIT_MovePageUp_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003356 break;
3357 case VK_NEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003358 if (es->style & ES_MULTILINE)
3359 EDIT_MovePageDown_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003360 break;
3361 case VK_BACK:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003362 if (!(es->style & ES_READONLY) && !control)
3363 if (es->selection_start != es->selection_end)
3364 EDIT_WM_Clear(wnd, es);
3365 else {
3366 /* delete character left of caret */
3367 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3368 EDIT_MoveBackward(wnd, es, TRUE);
3369 EDIT_WM_Clear(wnd, es);
3370 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003371 break;
3372 case VK_DELETE:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003373 if (!(es->style & ES_READONLY) && !(shift && control))
3374 if (es->selection_start != es->selection_end) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00003375 if (shift)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003376 EDIT_WM_Cut(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003377 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003378 EDIT_WM_Clear(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003379 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003380 if (shift) {
3381 /* delete character left of caret */
3382 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3383 EDIT_MoveBackward(wnd, es, TRUE);
3384 EDIT_WM_Clear(wnd, es);
3385 } else if (control) {
3386 /* delete to end of line */
3387 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3388 EDIT_MoveEnd(wnd, es, TRUE);
3389 EDIT_WM_Clear(wnd, es);
3390 } else {
3391 /* delete character right of caret */
3392 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3393 EDIT_MoveForward(wnd, es, TRUE);
3394 EDIT_WM_Clear(wnd, es);
3395 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003396 }
3397 break;
3398 case VK_INSERT:
3399 if (shift) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003400 if (!(es->style & ES_READONLY))
3401 EDIT_WM_Paste(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003402 } else if (control)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003403 EDIT_WM_Copy(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003404 break;
3405 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003406 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003407}
3408
3409
3410/*********************************************************************
3411 *
3412 * WM_KILLFOCUS
3413 *
3414 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003415static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND32 window_getting_focus)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003416{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003417 es->flags &= ~EF_FOCUSED;
Alexandre Julliard21979011997-03-05 08:22:35 +00003418 DestroyCaret32();
Alexandre Julliard889f7421997-04-15 17:19:52 +00003419 if(!(es->style & ES_NOHIDESEL))
3420 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3421 EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS");
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003422 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003423}
3424
3425
3426/*********************************************************************
3427 *
3428 * WM_LBUTTONDBLCLK
3429 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00003430 * The caret position has been set on the WM_LBUTTONDOWN message
3431 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003432 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003433static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003434{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003435 INT32 s;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003436 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003437 INT32 l;
3438 INT32 li;
3439 INT32 ll;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003440
Alexandre Julliard889f7421997-04-15 17:19:52 +00003441 if (!(es->flags & EF_FOCUSED))
3442 return 0;
3443
3444 l = EDIT_EM_LineFromChar(wnd, es, e);
3445 li = EDIT_EM_LineIndex(wnd, es, l);
3446 ll = EDIT_EM_LineLength(wnd, es, e);
3447 s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT);
3448 e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT);
3449 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
3450 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003451 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003452}
3453
3454
3455/*********************************************************************
3456 *
3457 * WM_LBUTTONDOWN
3458 *
3459 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003460static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003461{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003462 INT32 e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003463 BOOL32 after_wrap;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003464
Alexandre Julliard889f7421997-04-15 17:19:52 +00003465 if (!(es->flags & EF_FOCUSED))
3466 return 0;
3467
3468 SetCapture32(wnd->hwndSelf);
3469 EDIT_ConfinePoint(wnd, es, &x, &y);
3470 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3471 EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
3472 EDIT_EM_ScrollCaret(wnd, es);
3473 SetTimer32(wnd->hwndSelf, 0, 100, NULL);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003474 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003475}
3476
3477
3478/*********************************************************************
3479 *
3480 * WM_LBUTTONUP
3481 *
3482 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003483static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003484{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003485 if (GetCapture32() == wnd->hwndSelf) {
3486 KillTimer32(wnd->hwndSelf, 0);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003487 ReleaseCapture();
Alexandre Julliard01d63461997-01-20 19:43:45 +00003488 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003489 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003490}
3491
3492
3493/*********************************************************************
3494 *
3495 * WM_MOUSEMOVE
3496 *
3497 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003498static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003499{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003500 INT32 e;
3501 BOOL32 after_wrap;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003502
Alexandre Julliard889f7421997-04-15 17:19:52 +00003503 if (GetCapture32() != wnd->hwndSelf)
3504 return 0;
3505
Alexandre Julliard01d63461997-01-20 19:43:45 +00003506 /*
Alexandre Julliard889f7421997-04-15 17:19:52 +00003507 * FIXME: gotta do some scrolling if outside client
Alexandre Julliard01d63461997-01-20 19:43:45 +00003508 * area. Maybe reset the timer ?
3509 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003510 EDIT_ConfinePoint(wnd, es, &x, &y);
3511 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3512 EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003513 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003514}
3515
3516
3517/*********************************************************************
3518 *
3519 * WM_PAINT
3520 *
3521 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003522static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003523{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003524 PAINTSTRUCT32 ps;
3525 INT32 i;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003526 HDC32 dc;
3527 HFONT32 old_font = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003528 RECT32 rc;
3529 RECT32 rcLine;
3530 RECT32 rcRgn;
Alexandre Julliard01d63461997-01-20 19:43:45 +00003531 LRESULT pos;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003532 BOOL32 rev = IsWindowEnabled32(wnd->hwndSelf) &&
3533 ((es->flags & EF_FOCUSED) ||
3534 (es->style & ES_NOHIDESEL));
Alexandre Julliard329f0681996-04-14 13:21:20 +00003535
Alexandre Julliard889f7421997-04-15 17:19:52 +00003536 if (es->flags & EF_UPDATE)
3537 EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE");
3538
3539 dc = BeginPaint32(wnd->hwndSelf, &ps);
3540 IntersectClipRect32(dc, es->format_rect.left,
3541 es->format_rect.top,
3542 es->format_rect.right,
3543 es->format_rect.bottom);
3544 if (es->style & ES_MULTILINE) {
3545 GetClientRect32(wnd->hwndSelf, &rc);
3546 IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom);
3547 }
3548 if (es->font)
3549 old_font = SelectObject32(dc, es->font);
3550 EDIT_SEND_CTLCOLOR(wnd, dc);
3551 if (!IsWindowEnabled32(wnd->hwndSelf))
3552 SetTextColor32(dc, GetSysColor32(COLOR_GRAYTEXT));
3553 GetClipBox32(dc, &rcRgn);
3554 if (es->style & ES_MULTILINE) {
3555 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3556 for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
3557 EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine);
3558 if (IntersectRect32(&rc, &rcRgn, &rcLine))
3559 EDIT_PaintLine(wnd, es, dc, i, rev);
3560 }
3561 } else {
3562 EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003563 if (IntersectRect32(&rc, &rcRgn, &rcLine))
Alexandre Julliard889f7421997-04-15 17:19:52 +00003564 EDIT_PaintLine(wnd, es, dc, 0, rev);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003565 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003566 if (es->font)
3567 SelectObject32(dc, old_font);
3568 if (es->flags & EF_FOCUSED) {
3569 pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP);
3570 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003571 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003572 EndPaint32(wnd->hwndSelf, &ps);
3573 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) {
3574 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3575 SCROLLINFO si;
3576 si.cbSize = sizeof(SCROLLINFO);
3577 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3578 si.nMin = 0;
3579 si.nMax = es->line_count + vlc - 2;
3580 si.nPage = vlc;
3581 si.nPos = es->y_offset;
3582 SetScrollInfo32(wnd->hwndSelf, SB_VERT, &si, TRUE);
3583 }
3584 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) {
3585 SCROLLINFO si;
3586 INT32 fw = es->format_rect.right - es->format_rect.left;
3587 si.cbSize = sizeof(SCROLLINFO);
3588 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3589 si.nMin = 0;
3590 si.nMax = es->text_width + fw - 1;
3591 si.nPage = fw;
3592 si.nPos = es->x_offset;
3593 SetScrollInfo32(wnd->hwndSelf, SB_HORZ, &si, TRUE);
3594 }
3595
3596 if (es->flags & EF_UPDATE) {
3597 es->flags &= ~EF_UPDATE;
3598 EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE");
3599 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003600}
3601
3602
3603/*********************************************************************
3604 *
3605 * WM_PASTE
3606 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00003607 * FIXME: replace with 32 bit handler once GetClipboardData32() is
3608 * implemented in misc/clipboard.c
3609 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003610 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003611static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003612{
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +00003613 HGLOBAL16 hsrc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003614 LPSTR src;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003615
Alexandre Julliard889f7421997-04-15 17:19:52 +00003616 OpenClipboard32(wnd->hwndSelf);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003617 if ((hsrc = GetClipboardData16(CF_TEXT))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003618 src = (LPSTR)GlobalLock16(hsrc);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003619 EDIT_EM_ReplaceSel(wnd, es, TRUE, src);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003620 GlobalUnlock16(hsrc);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003621 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00003622 CloseClipboard32();
Alexandre Julliard329f0681996-04-14 13:21:20 +00003623}
3624
3625
3626/*********************************************************************
3627 *
3628 * WM_SETFOCUS
3629 *
3630 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003631static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND32 window_losing_focus)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003632{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003633 LRESULT pos;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003634
Alexandre Julliard889f7421997-04-15 17:19:52 +00003635 es->flags |= EF_FOCUSED;
3636 CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height);
3637 pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP);
3638 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
3639 if(!(es->style & ES_NOHIDESEL))
3640 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3641 ShowCaret32(wnd->hwndSelf);
3642 EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS");
Alexandre Julliard329f0681996-04-14 13:21:20 +00003643}
3644
3645
3646/*********************************************************************
3647 *
3648 * WM_SETFONT
3649 *
3650 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003651static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT32 font, BOOL32 redraw)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003652{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003653 TEXTMETRIC32A tm;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003654 HDC32 dc;
3655 HFONT32 old_font = 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003656
Alexandre Julliard889f7421997-04-15 17:19:52 +00003657 es->font = font;
3658 dc = GetDC32(wnd->hwndSelf);
3659 if (font)
3660 old_font = SelectObject32(dc, font);
3661 GetTextMetrics32A(dc, &tm);
3662 es->line_height = tm.tmHeight;
3663 es->char_width = tm.tmAveCharWidth;
3664 if (font)
3665 SelectObject32(dc, old_font);
3666 ReleaseDC32(wnd->hwndSelf, dc);
3667 if (wnd->flags & WIN_ISWIN32)
3668 EDIT_EM_SetMargins(wnd, es, EC_USEFONTINFO, 0, 0);
3669 if (es->style & ES_MULTILINE)
3670 EDIT_BuildLineDefs_ML(wnd, es);
3671 if (redraw && !(wnd->flags & WIN_NO_REDRAW))
3672 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
3673 if (es->flags & EF_FOCUSED) {
3674 LRESULT pos;
Alexandre Julliard21979011997-03-05 08:22:35 +00003675 DestroyCaret32();
Alexandre Julliard889f7421997-04-15 17:19:52 +00003676 CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height);
3677 pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP);
3678 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
3679 ShowCaret32(wnd->hwndSelf);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003680 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003681}
3682
3683
3684/*********************************************************************
3685 *
3686 * WM_SETTEXT
3687 *
3688 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003689static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003690{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003691 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
3692 if (text) {
3693 dprintf_edit(stddeb, "\t'%s'\n", text);
3694 EDIT_EM_ReplaceSel(wnd, es, FALSE, text);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003695 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003696 es->flags |= EF_MODIFIED;
3697 es->flags |= EF_UPDATE;
3698 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003699}
3700
3701
3702/*********************************************************************
3703 *
3704 * WM_SIZE
3705 *
3706 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003707static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT32 action, INT32 width, INT32 height)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003708{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003709 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
3710 RECT32 rc;
3711 SetRect32(&rc, 0, 0, width, height);
3712 EDIT_SetRectNP(wnd, es, &rc);
3713 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00003714 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003715}
3716
3717
3718/*********************************************************************
3719 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00003720 * WM_SYSKEYDOWN
3721 *
3722 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003723static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data)
Alexandre Julliard01d63461997-01-20 19:43:45 +00003724{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003725 if ((key == VK_BACK) && (key_data & 0x2000)) {
3726 if (EDIT_EM_CanUndo(wnd, es))
3727 EDIT_EM_Undo(wnd, es);
3728 return 0;
3729 } else if (key == VK_UP || key == VK_DOWN)
3730 if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data))
3731 return 0;
3732 return DefWindowProc32A(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM32)key, (LPARAM)key_data);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003733}
3734
3735
3736/*********************************************************************
3737 *
3738 * WM_TIMER
3739 *
3740 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003741static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT32 id, TIMERPROC32 timer_proc)
Alexandre Julliard01d63461997-01-20 19:43:45 +00003742{
3743/*
3744 * FIXME: gotta do some scrolling here, like
Alexandre Julliard889f7421997-04-15 17:19:52 +00003745 * EDIT_EM_LineScroll(wnd, 0, 1);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003746 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003747}
3748
3749
3750/*********************************************************************
3751 *
3752 * EDIT_VScroll_Hack
3753 *
3754 * 16 bit notepad needs this. Actually it is not _our_ hack,
3755 * it is notepad's. Notepad is sending us scrollbar messages with
3756 * undocumented parameters without us even having a scrollbar ... !?!?
3757 *
3758 */
3759static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
3760{
3761 INT32 dy = 0;
3762 LRESULT ret = 0;
3763
3764 if (!(es->flags & EF_VSCROLL_HACK)) {
3765 fprintf(stderr, "edit: hacked WM_VSCROLL handler invoked\n");
3766 fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n");
3767 fprintf(stderr, " (this message is only displayed once per edit control)\n");
3768 es->flags |= EF_VSCROLL_HACK;
3769 }
3770
3771 switch (action) {
3772 case SB_LINEUP:
3773 case SB_LINEDOWN:
3774 case SB_PAGEUP:
3775 case SB_PAGEDOWN:
3776 EDIT_EM_Scroll(wnd, es, action);
3777 return 0;
3778 case SB_TOP:
3779 dy = -es->y_offset;
3780 break;
3781 case SB_BOTTOM:
3782 dy = es->line_count - 1 - es->y_offset;
3783 break;
3784 case SB_THUMBTRACK:
3785 es->flags |= EF_VSCROLL_TRACK;
3786 dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset;
3787 break;
3788 case SB_THUMBPOSITION:
3789 es->flags &= ~EF_VSCROLL_TRACK;
3790 if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset))
3791 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
3792 break;
3793 case SB_ENDSCROLL:
3794 break;
3795
3796 /*
3797 * FIXME : the next two are undocumented !
3798 * Are we doing the right thing ?
3799 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3800 * although it's also a regular control message.
3801 */
3802 case EM_GETTHUMB16:
3803 ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0;
3804 break;
3805 case EM_LINESCROLL16:
3806 dy = pos;
3807 break;
3808
3809 default:
3810 fprintf(stderr, "edit: undocumented (hacked) WM_VSCROLL parameter, please report\n");
3811 return 0;
3812 }
3813 if (dy)
3814 EDIT_EM_LineScroll(wnd, es, 0, dy);
3815 return ret;
Alexandre Julliard01d63461997-01-20 19:43:45 +00003816}
3817
3818
3819/*********************************************************************
3820 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003821 * WM_VSCROLL
3822 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003823 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003824static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003825{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003826 INT32 dy;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003827
Alexandre Julliard889f7421997-04-15 17:19:52 +00003828 if (!(es->style & ES_MULTILINE))
3829 return 0;
3830
3831 if (!(es->style & ES_AUTOVSCROLL))
3832 return 0;
3833
3834 if (!(es->style & WS_VSCROLL))
3835 return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar);
3836
3837 dy = 0;
3838 switch (action) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00003839 case SB_LINEUP:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003840 case SB_LINEDOWN:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003841 case SB_PAGEUP:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003842 case SB_PAGEDOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003843 EDIT_EM_Scroll(wnd, es, action);
3844 return 0;
3845
3846 case SB_TOP:
3847 dy = -es->y_offset;
3848 break;
3849 case SB_BOTTOM:
3850 dy = es->line_count - 1 - es->y_offset;
3851 break;
3852 case SB_THUMBTRACK:
3853 es->flags |= EF_VSCROLL_TRACK;
3854 dy = pos - es->y_offset;
3855 break;
3856 case SB_THUMBPOSITION:
3857 es->flags &= ~EF_VSCROLL_TRACK;
3858 if (!(dy = pos - es->y_offset)) {
3859 SetScrollPos32(wnd->hwndSelf, SB_VERT, pos, TRUE);
3860 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
3861 }
3862 break;
3863 case SB_ENDSCROLL:
3864 break;
3865
Alexandre Julliard329f0681996-04-14 13:21:20 +00003866 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003867 fprintf(stderr, "edit: undocumented WM_VSCROLL parameter, please report\n");
3868 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003869 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003870 if (dy)
3871 EDIT_EM_LineScroll(wnd, es, 0, dy);
3872 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003873}