blob: 28373cd659f230bf0666a1217593538698279abb [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;
985 } else if (es->word_break_proc32A)
986 return (INT32)CallWordBreakProc32A((FARPROC32)es->word_break_proc32A,
987 es->text + start, index, count, action);
988 else
989 return EDIT_WordBreakProc(es->text + start, index, count, action);
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000990}
991
Alexandre Julliard329f0681996-04-14 13:21:20 +0000992
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000993/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000994 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000995 * EDIT_CharFromPos
Alexandre Julliard329f0681996-04-14 13:21:20 +0000996 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000997 * Beware: This is not the function called on EM_CHARFROMPOS
998 * The position _can_ be outside the formatting / client
999 * rectangle
1000 * The return value is only the character index
Alexandre Julliard329f0681996-04-14 13:21:20 +00001001 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001002 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001003static INT32 EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y, LPBOOL32 after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001004{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001005 INT32 index;
1006 HDC32 dc;
1007 HFONT32 old_font = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001008
Alexandre Julliard889f7421997-04-15 17:19:52 +00001009 if (es->style & ES_MULTILINE) {
1010 INT32 line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1011 INT32 line_index = 0;
1012 LINEDEF *line_def = es->first_line_def;
1013 while ((line > 0) && line_def->next) {
1014 line_index += line_def->length;
1015 line_def = line_def->next;
1016 line--;
1017 }
1018 x += es->x_offset - es->format_rect.left;
1019 if (x >= line_def->width) {
1020 if (after_wrap)
1021 *after_wrap = (line_def->ending == END_WRAP);
1022 return line_index + line_def->net_length;
1023 }
1024 if (x <= 0) {
1025 if (after_wrap)
1026 *after_wrap = FALSE;
1027 return line_index;
1028 }
1029 dc = GetDC32(wnd->hwndSelf);
1030 if (es->font)
1031 old_font = SelectObject32(dc, es->font);
1032 /* FIXME: inefficient algorithm */
1033 for (index = line_index + 1 ; index < line_index + line_def->net_length ; index++)
1034 if (LOWORD(GetTabbedTextExtent32A(dc, es->text + line_index,
1035 index - line_index, es->tabs_count, es->tabs)) >= x)
1036 break;
1037 if (after_wrap)
1038 *after_wrap = ((index == line_index + line_def->net_length) &&
1039 (line_def->ending == END_WRAP));
1040 } else {
1041 LPSTR text;
1042 SIZE32 size;
1043 if (after_wrap)
1044 *after_wrap = FALSE;
1045 x -= es->format_rect.left;
1046 if (!x)
1047 return es->x_offset;
1048 text = EDIT_GetPasswordPointer_SL(wnd, es);
1049 dc = GetDC32(wnd->hwndSelf);
1050 if (es->font)
1051 old_font = SelectObject32(dc, es->font);
1052 if (x < 0) {
1053 x = -x;
1054 /* FIXME: inefficient algorithm */
1055 for (index = es->x_offset ; index ; index--) {
1056 GetTextExtentPoint32A(dc, text + index,
1057 es->x_offset - index, &size);
1058 if (size.cx > x)
1059 break;
1060 }
1061 } else {
1062 INT32 len = lstrlen32A(es->text);
1063 /* FIXME: inefficient algorithm */
1064 for (index = es->x_offset ; index < len ; index++) {
1065 GetTextExtentPoint32A(dc, text + es->x_offset,
1066 index - es->x_offset, &size);
1067 if (size.cx >= x)
1068 break;
1069 }
1070 }
1071 if (es->style & ES_PASSWORD)
1072 HeapFree(es->heap, 0 ,text);
1073 }
1074 if (es->font)
1075 SelectObject32(dc, old_font);
1076 ReleaseDC32(wnd->hwndSelf, dc);
1077 return index;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001078}
1079
Alexandre Julliard329f0681996-04-14 13:21:20 +00001080
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001081/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001082 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001083 * EDIT_ConfinePoint
Alexandre Julliard329f0681996-04-14 13:21:20 +00001084 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001085 * adjusts the point to be within the formatting rectangle
1086 * (so CharFromPos returns the nearest _visible_ character)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001087 *
1088 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001089static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT32 x, LPINT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001090{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001091 *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1);
1092 *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001093}
1094
1095
1096/*********************************************************************
1097 *
1098 * EDIT_GetLineRect
1099 *
1100 * Calculates the bounding rectangle for a line from a starting
1101 * column to an ending column.
1102 *
1103 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001104static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT32 line, INT32 scol, INT32 ecol, LPRECT32 rc)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001105{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001106 INT32 line_index = EDIT_EM_LineIndex(wnd, es, line);
1107
1108 if (es->style & ES_MULTILINE)
1109 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1110 else
1111 rc->top = es->format_rect.top;
1112 rc->bottom = rc->top + es->line_height;
1113 rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE));
1114 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 +00001115}
1116
1117
1118/*********************************************************************
1119 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001120 * EDIT_GetPasswordPointer_SL
1121 *
1122 * note: caller should free the (optionally) allocated buffer
1123 *
1124 */
1125static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es)
1126{
1127 if (es->style & ES_PASSWORD) {
1128 INT32 len = lstrlen32A(es->text);
1129 LPSTR text = HeapAlloc(es->heap, 0, len + 1);
1130 RtlFillMemory(text, len, es->password_char);
1131 text[len] = '\0';
1132 return text;
1133 } else
1134 return es->text;
1135}
1136
1137
1138/*********************************************************************
1139 *
1140 * EDIT_LockBuffer
Alexandre Julliard329f0681996-04-14 13:21:20 +00001141 *
1142 * This acts as a LOCAL_Lock(), but it locks only once. This way
1143 * you can call it whenever you like, without unlocking.
1144 *
1145 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001146static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001147{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001148 if (!es) {
1149 fprintf(stderr, "edit: LockBuffer() without an EDITSTATE ... please report\n");
1150 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001151 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001152 if (!(es->style & ES_MULTILINE))
1153 return;
1154 if (!es->text) {
1155 if (es->hloc32)
1156 es->text = LocalLock32(es->hloc32);
1157 else if (es->hloc16)
1158 es->text = LOCAL_Lock(wnd->hInstance, es->hloc16);
1159 else {
1160 fprintf(stderr, "edit: LockBuffer() without a buffer ... please report\n");
1161 return;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001162 }
1163 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001164 es->lock_count++;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001165}
1166
1167
1168/*********************************************************************
1169 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001170 * EDIT_SL_InvalidateText
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001171 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001172 * Called from EDIT_InvalidateText().
1173 * Does the job for single-line controls only.
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001174 *
1175 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001176static void EDIT_SL_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end)
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001177{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001178 RECT32 line_rect;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001179 RECT32 rc;
1180
Alexandre Julliard889f7421997-04-15 17:19:52 +00001181 EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect);
1182 if (IntersectRect32(&rc, &line_rect, &es->format_rect))
1183 InvalidateRect32(wnd->hwndSelf, &rc, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001184}
1185
1186
1187/*********************************************************************
1188 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001189 * EDIT_ML_InvalidateText
1190 *
1191 * Called from EDIT_InvalidateText().
1192 * Does the job for multi-line controls only.
Alexandre Julliard329f0681996-04-14 13:21:20 +00001193 *
1194 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001195static void EDIT_ML_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001196{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001197 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1198 INT32 sl = EDIT_EM_LineFromChar(wnd, es, start);
1199 INT32 el = EDIT_EM_LineFromChar(wnd, es, end);
1200 INT32 sc;
1201 INT32 ec;
1202 RECT32 rc1;
1203 RECT32 rcWnd;
1204 RECT32 rcLine;
1205 RECT32 rcUpdate;
1206 INT32 l;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001207
Alexandre Julliard889f7421997-04-15 17:19:52 +00001208 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1209 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001210
Alexandre Julliard889f7421997-04-15 17:19:52 +00001211 sc = start - EDIT_EM_LineIndex(wnd, es, sl);
1212 ec = end - EDIT_EM_LineIndex(wnd, es, el);
1213 if (sl < es->y_offset) {
1214 sl = es->y_offset;
1215 sc = 0;
1216 }
1217 if (el > es->y_offset + vlc) {
1218 el = es->y_offset + vlc;
1219 ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el));
1220 }
1221 GetClientRect32(wnd->hwndSelf, &rc1);
1222 IntersectRect32(&rcWnd, &rc1, &es->format_rect);
1223 if (sl == el) {
1224 EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine);
1225 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1226 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1227 } else {
1228 EDIT_GetLineRect(wnd, es, sl, sc,
1229 EDIT_EM_LineLength(wnd, es,
1230 EDIT_EM_LineIndex(wnd, es, sl)),
1231 &rcLine);
1232 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1233 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1234 for (l = sl + 1 ; l < el ; l++) {
1235 EDIT_GetLineRect(wnd, es, l, 0,
1236 EDIT_EM_LineLength(wnd, es,
1237 EDIT_EM_LineIndex(wnd, es, l)),
1238 &rcLine);
1239 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1240 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1241 }
1242 EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine);
1243 if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine))
1244 InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE);
1245 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001246}
1247
1248
1249/*********************************************************************
1250 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001251 * EDIT_InvalidateText
1252 *
1253 * Invalidate the text from offset start upto, but not including,
1254 * offset end. Useful for (re)painting the selection.
1255 * Regions outside the linewidth are not invalidated.
1256 * end == -1 means end == TextLength.
1257 * start and end need not be ordered.
1258 *
1259 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001260static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end)
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001261{
Alexandre Julliard01d63461997-01-20 19:43:45 +00001262 if (end == start)
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001263 return;
1264
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001265 if (end == -1)
Alexandre Julliard889f7421997-04-15 17:19:52 +00001266 end = lstrlen32A(es->text);
1267
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001268 ORDER_INT32(start, end);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001269
Alexandre Julliard889f7421997-04-15 17:19:52 +00001270 if (es->style & ES_MULTILINE)
1271 EDIT_ML_InvalidateText(wnd, es, start, end);
1272 else
1273 EDIT_SL_InvalidateText(wnd, es, start, end);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001274}
1275
1276
1277/*********************************************************************
1278 *
1279 * EDIT_MakeFit
1280 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001281 * Try to fit size + 1 bytes in the buffer. Constrain to limits.
Alexandre Julliard329f0681996-04-14 13:21:20 +00001282 *
1283 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001284static BOOL32 EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT32 size)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001285{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001286 HLOCAL32 hNew32;
1287 HLOCAL16 hNew16;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001288
Alexandre Julliard889f7421997-04-15 17:19:52 +00001289 if (size <= es->buffer_size)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001290 return TRUE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001291 if (size > es->buffer_limit) {
1292 EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT");
Alexandre Julliard329f0681996-04-14 13:21:20 +00001293 return FALSE;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001294 }
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001295 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001296 if (size > es->buffer_limit)
1297 size = es->buffer_limit;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001298
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001299 dprintf_edit(stddeb, "edit: EDIT_MakeFit: trying to ReAlloc to %d+1\n", size);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001300
Alexandre Julliard889f7421997-04-15 17:19:52 +00001301 EDIT_UnlockBuffer(wnd, es, TRUE);
1302 if (es->text) {
1303 if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1)))
1304 es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
1305 else
1306 es->buffer_size = 0;
1307 } else if (es->hloc32) {
1308 if ((hNew32 = LocalReAlloc32(es->hloc32, size + 1, 0))) {
1309 dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32);
1310 es->hloc32 = hNew32;
1311 es->buffer_size = MIN(LocalSize32(es->hloc32) - 1, es->buffer_limit);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001312 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001313 } else if (es->hloc16) {
1314 if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) {
1315 dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16);
1316 es->hloc16 = hNew16;
1317 es->buffer_size = MIN(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001318 }
1319 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001320 if (es->buffer_size < size) {
1321 EDIT_LockBuffer(wnd, es);
1322 dprintf_edit(stddeb, "edit: EDIT_MakeFit: FAILED ! We now have %d+1\n", es->buffer_size);
1323 EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE");
1324 return FALSE;
1325 } else {
1326 EDIT_LockBuffer(wnd, es);
1327 dprintf_edit(stddeb, "edit: EDIT_MakeFit: We now have %d+1\n", es->buffer_size);
1328 return TRUE;
1329 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001330}
1331
1332
1333/*********************************************************************
1334 *
1335 * EDIT_MakeUndoFit
1336 *
1337 * Try to fit size + 1 bytes in the undo buffer.
1338 *
1339 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001340static BOOL32 EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT32 size)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001341{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001342 if (size <= es->undo_buffer_size)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001343 return TRUE;
1344 size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
1345
1346 dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: trying to ReAlloc to %d+1\n", size);
1347
Alexandre Julliard889f7421997-04-15 17:19:52 +00001348 if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) {
1349 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
1350 if (es->undo_buffer_size < size) {
1351 dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: FAILED ! We now have %d+1\n", es->undo_buffer_size);
Alexandre Julliard01d63461997-01-20 19:43:45 +00001352 return FALSE;
1353 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001354 return TRUE;
1355 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001356 return FALSE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001357}
1358
1359
1360/*********************************************************************
1361 *
1362 * EDIT_MoveBackward
1363 *
1364 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001365static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001366{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001367 INT32 e = es->selection_end;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001368
Alexandre Julliard889f7421997-04-15 17:19:52 +00001369 if (e) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001370 e--;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001371 if ((es->style & ES_MULTILINE) && e &&
1372 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1373 e--;
1374 if (e && (es->text[e - 1] == '\r'))
1375 e--;
1376 }
1377 }
1378 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1379 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001380}
1381
1382
1383/*********************************************************************
1384 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001385 * EDIT_MoveDown_ML
1386 *
1387 * Only for multi line controls
1388 * Move the caret one line down, on a column with the nearest
1389 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001390 *
1391 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001392static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001393{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001394 INT32 s = es->selection_start;
1395 INT32 e = es->selection_end;
1396 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1397 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1398 INT32 x = SLOWORD(pos);
1399 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001400
Alexandre Julliard889f7421997-04-15 17:19:52 +00001401 e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001402 if (!extend)
1403 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001404 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1405 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001406}
1407
1408
1409/*********************************************************************
1410 *
1411 * EDIT_MoveEnd
1412 *
1413 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001414static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001415{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001416 BOOL32 after_wrap = FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001417 INT32 e;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001418
Alexandre Julliard889f7421997-04-15 17:19:52 +00001419 if (es->style & ES_MULTILINE)
1420 e = EDIT_CharFromPos(wnd, es, 0x7fffffff,
1421 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
1422 else
1423 e = lstrlen32A(es->text);
1424 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap);
1425 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001426}
1427
1428
1429/*********************************************************************
1430 *
1431 * EDIT_MoveForward
1432 *
1433 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001434static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001435{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001436 INT32 e = es->selection_end;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001437
Alexandre Julliard889f7421997-04-15 17:19:52 +00001438 if (es->text[e]) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001439 e++;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001440 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1441 if (es->text[e] == '\n')
1442 e++;
1443 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1444 e += 2;
1445 }
1446 }
1447 EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE);
1448 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001449}
1450
1451
1452/*********************************************************************
1453 *
1454 * EDIT_MoveHome
1455 *
1456 * Home key: move to beginning of line.
1457 *
1458 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001459static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001460{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001461 INT32 e;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001462
Alexandre Julliard889f7421997-04-15 17:19:52 +00001463 if (es->style & ES_MULTILINE)
1464 e = EDIT_CharFromPos(wnd, es, 0x80000000,
1465 HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
1466 else
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001467 e = 0;
1468 EDIT_EM_SetSel(wnd, es, e, extend ? es->selection_start : e, FALSE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001469 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001470}
1471
1472
1473/*********************************************************************
1474 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001475 * EDIT_MovePageDown_ML
1476 *
1477 * Only for multi line controls
1478 * Move the caret one page down, on a column with the nearest
1479 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001480 *
1481 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001482static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001483{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001484 INT32 s = es->selection_start;
1485 INT32 e = es->selection_end;
1486 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1487 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1488 INT32 x = SLOWORD(pos);
1489 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001490
Alexandre Julliard889f7421997-04-15 17:19:52 +00001491 e = EDIT_CharFromPos(wnd, es, x,
1492 y + (es->format_rect.bottom - es->format_rect.top),
1493 &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001494 if (!extend)
1495 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001496 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1497 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001498}
1499
1500
1501/*********************************************************************
1502 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001503 * EDIT_MovePageUp_ML
1504 *
1505 * Only for multi line controls
1506 * Move the caret one page up, on a column with the nearest
1507 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001508 *
1509 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001510static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001511{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001512 INT32 s = es->selection_start;
1513 INT32 e = es->selection_end;
1514 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1515 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1516 INT32 x = SLOWORD(pos);
1517 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001518
Alexandre Julliard889f7421997-04-15 17:19:52 +00001519 e = EDIT_CharFromPos(wnd, es, x,
1520 y - (es->format_rect.bottom - es->format_rect.top),
1521 &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001522 if (!extend)
1523 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001524 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1525 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001526}
1527
1528
1529/*********************************************************************
1530 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001531 * EDIT_MoveUp_ML
Alexandre Julliard329f0681996-04-14 13:21:20 +00001532 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001533 * Only for multi line controls
1534 * Move the caret one line up, on a column with the nearest
1535 * x coordinate on the screen (might be a different column).
1536 *
1537 */
1538static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001539{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001540 INT32 s = es->selection_start;
1541 INT32 e = es->selection_end;
1542 BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP);
1543 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap);
1544 INT32 x = SLOWORD(pos);
1545 INT32 y = SHIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001546
Alexandre Julliard889f7421997-04-15 17:19:52 +00001547 e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001548 if (!extend)
1549 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001550 EDIT_EM_SetSel(wnd, es, s, e, after_wrap);
1551 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001552}
1553
1554
1555/*********************************************************************
1556 *
1557 * EDIT_MoveWordBackward
1558 *
1559 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001560static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001561{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001562 INT32 s = es->selection_start;
1563 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001564 INT32 l;
1565 INT32 ll;
1566 INT32 li;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001567
Alexandre Julliard889f7421997-04-15 17:19:52 +00001568 l = EDIT_EM_LineFromChar(wnd, es, e);
1569 ll = EDIT_EM_LineLength(wnd, es, e);
1570 li = EDIT_EM_LineIndex(wnd, es, l);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001571 if (e - li == 0) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001572 if (l) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001573 li = EDIT_EM_LineIndex(wnd, es, l - 1);
1574 e = li + EDIT_EM_LineLength(wnd, es, li);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001575 }
1576 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001577 e = li + (INT32)EDIT_CallWordBreakProc(wnd, es,
1578 li, e - li, ll, WB_LEFT);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001579 }
1580 if (!extend)
1581 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001582 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1583 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001584}
1585
1586
1587/*********************************************************************
1588 *
1589 * EDIT_MoveWordForward
1590 *
1591 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001592static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL32 extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001593{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001594 INT32 s = es->selection_start;
1595 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001596 INT32 l;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001597 INT32 ll;
1598 INT32 li;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001599
Alexandre Julliard889f7421997-04-15 17:19:52 +00001600 l = EDIT_EM_LineFromChar(wnd, es, e);
1601 ll = EDIT_EM_LineLength(wnd, es, e);
1602 li = EDIT_EM_LineIndex(wnd, es, l);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001603 if (e - li == ll) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001604 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
1605 e = EDIT_EM_LineIndex(wnd, es, l + 1);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001606 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001607 e = li + EDIT_CallWordBreakProc(wnd, es,
1608 li, e - li + 1, ll, WB_RIGHT);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001609 }
1610 if (!extend)
1611 s = e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001612 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
1613 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001614}
1615
1616
1617/*********************************************************************
1618 *
1619 * EDIT_PaintLine
1620 *
1621 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001622static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC32 dc, INT32 line, BOOL32 rev)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001623{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001624 INT32 s = es->selection_start;
1625 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001626 INT32 li;
1627 INT32 ll;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001628 INT32 x;
1629 INT32 y;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001630 LRESULT pos;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001631
Alexandre Julliard889f7421997-04-15 17:19:52 +00001632 if (es->style & ES_MULTILINE) {
1633 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1634 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
1635 return;
1636 } else if (line)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001637 return;
1638
1639 dprintf_edit(stddeb, "edit: EDIT_PaintLine: line=%d\n", line);
1640
Alexandre Julliard889f7421997-04-15 17:19:52 +00001641 pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE);
1642 x = SLOWORD(pos);
1643 y = SHIWORD(pos);
1644 li = EDIT_EM_LineIndex(wnd, es, line);
1645 ll = EDIT_EM_LineLength(wnd, es, li);
1646 s = es->selection_start;
1647 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001648 ORDER_INT32(s, e);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001649 s = MIN(li + ll, MAX(li, s));
1650 e = MIN(li + ll, MAX(li, e));
1651 if (rev && (s != e) &&
Alexandre Julliard889f7421997-04-15 17:19:52 +00001652 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
1653 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE);
1654 x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE);
1655 x += EDIT_PaintText(wnd, es, dc, x, y, line, e - li, li + ll - e, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001656 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00001657 x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001658}
1659
1660
1661/*********************************************************************
1662 *
1663 * EDIT_PaintText
1664 *
1665 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001666static 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 +00001667{
Alexandre Julliard329f0681996-04-14 13:21:20 +00001668 COLORREF BkColor;
1669 COLORREF TextColor;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001670 INT32 ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001671 INT32 li;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001672 SIZE32 size;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001673
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001674 if (!count)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001675 return 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001676 BkColor = GetBkColor32(dc);
1677 TextColor = GetTextColor32(dc);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001678 if (rev) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001679 SetBkColor32(dc, GetSysColor32(COLOR_HIGHLIGHT));
1680 SetTextColor32(dc, GetSysColor32(COLOR_HIGHLIGHTTEXT));
Alexandre Julliard329f0681996-04-14 13:21:20 +00001681 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001682 li = EDIT_EM_LineIndex(wnd, es, line);
1683 if (es->style & ES_MULTILINE) {
1684 ret = (INT32)LOWORD(TabbedTextOut32A(dc, x, y, es->text + li + col, count,
1685 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
1686 } else {
1687 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
1688 TextOut32A(dc, x, y, text + li + col, count);
1689 GetTextExtentPoint32A(dc, text + li + col, count, &size);
1690 ret = size.cx;
1691 if (es->style & ES_PASSWORD)
1692 HeapFree(es->heap, 0, text);
1693 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001694 if (rev) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001695 SetBkColor32(dc, BkColor);
1696 SetTextColor32(dc, TextColor);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001697 }
1698 return ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001699}
Alexandre Julliard329f0681996-04-14 13:21:20 +00001700
1701
1702/*********************************************************************
1703 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001704 * EM_SCROLLCARET
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001705 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00001706 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001707static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001708{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001709 if (es->style & ES_MULTILINE) {
1710 INT32 l;
1711 INT32 li;
1712 INT32 vlc;
1713 INT32 ww;
1714 INT32 cw = es->char_width;
1715 INT32 x;
1716 INT32 dy = 0;
1717 INT32 dx = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001718
Alexandre Julliard889f7421997-04-15 17:19:52 +00001719 l = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
1720 li = EDIT_EM_LineIndex(wnd, es, l);
1721 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP));
1722 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
1723 if (l >= es->y_offset + vlc)
1724 dy = l - vlc + 1 - es->y_offset;
1725 if (l < es->y_offset)
1726 dy = l - es->y_offset;
1727 ww = es->format_rect.right - es->format_rect.left;
1728 if (x < es->format_rect.left)
1729 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
1730 if (x > es->format_rect.right)
1731 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
1732 if (dy || dx)
1733 EDIT_EM_LineScroll(wnd, es, dx, dy);
1734 } else {
1735 INT32 x;
1736 INT32 goal;
1737 INT32 format_width;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001738
Alexandre Julliard889f7421997-04-15 17:19:52 +00001739 if (!(es->style & ES_AUTOHSCROLL))
1740 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001741
Alexandre Julliard889f7421997-04-15 17:19:52 +00001742 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
1743 format_width = es->format_rect.right - es->format_rect.left;
1744 if (x < es->format_rect.left) {
1745 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
1746 do {
1747 es->x_offset--;
1748 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
1749 } while ((x < goal) && es->x_offset);
1750 /* FIXME: use ScrollWindow() somehow to improve performance */
1751 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
1752 } else if (x > es->format_rect.right) {
1753 INT32 x_last;
1754 INT32 len = lstrlen32A(es->text);
1755 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
1756 do {
1757 es->x_offset++;
1758 x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE));
1759 x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE));
1760 } while ((x > goal) && (x_last > es->format_rect.right));
1761 /* FIXME: use ScrollWindow() somehow to improve performance */
1762 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliard01d63461997-01-20 19:43:45 +00001763 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001764 }
1765}
1766
1767
1768/*********************************************************************
1769 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001770 * EDIT_SetRectNP
Alexandre Julliard329f0681996-04-14 13:21:20 +00001771 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001772 * note: this is not (exactly) the handler called on EM_SETRECTNP
1773 * it is also used to set the rect of a single line control
Alexandre Julliard329f0681996-04-14 13:21:20 +00001774 *
1775 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001776static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT32 rc)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001777{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001778 CopyRect32(&es->format_rect, rc);
1779 if (es->style & WS_BORDER) {
1780 INT32 bw = GetSystemMetrics32(SM_CXBORDER) + 1;
1781 es->format_rect.left += bw;
1782 es->format_rect.top += bw;
1783 es->format_rect.right -= bw;
1784 es->format_rect.bottom -= bw;
1785 }
1786 es->format_rect.left += es->left_margin;
1787 es->format_rect.right -= es->right_margin;
1788 es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width);
1789 if (es->style & ES_MULTILINE)
1790 es->format_rect.bottom = es->format_rect.top +
1791 MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
1792 else
1793 es->format_rect.bottom = es->format_rect.top + es->line_height;
1794 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
1795 EDIT_BuildLineDefs_ML(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001796}
1797
1798
1799/*********************************************************************
1800 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001801 * EDIT_UnlockBuffer
Alexandre Julliard329f0681996-04-14 13:21:20 +00001802 *
1803 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001804static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL32 force)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001805{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001806 if (!es) {
1807 fprintf(stderr, "edit: UnlockBuffer() without an EDITSTATE ... please report\n");
1808 return;
1809 }
1810 if (!(es->style & ES_MULTILINE))
1811 return;
1812 if (!es->lock_count) {
1813 fprintf(stderr, "edit: UnlockBuffer() with lock_count == 0 ... please report\n");
1814 return;
1815 }
1816 if (!es->text) {
1817 fprintf(stderr, "edit: UnlockBuffer() with es->text == 0 ... please report\n");
1818 return;
1819 }
1820 if (force || (es->lock_count == 1)) {
1821 if (es->hloc32) {
1822 LocalUnlock32(es->hloc32);
1823 es->text = NULL;
1824 } else if (es->hloc16) {
1825 LOCAL_Unlock(wnd->hInstance, es->hloc16);
1826 es->text = NULL;
1827 }
1828 }
1829 es->lock_count--;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001830}
1831
1832
1833/*********************************************************************
1834 *
1835 * EDIT_WordBreakProc
1836 *
1837 * Find the beginning of words.
1838 * Note: unlike the specs for a WordBreakProc, this function only
1839 * allows to be called without linebreaks between s[0] upto
1840 * s[count - 1]. Remember it is only called
1841 * internally, so we can decide this for ourselves.
1842 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001843 */
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001844static INT32 EDIT_WordBreakProc(LPSTR s, INT32 index, INT32 count, INT32 action)
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001845{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001846 INT32 ret = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001847
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001848 dprintf_edit(stddeb, "edit: EDIT_WordBreakProc: s=%p, index=%u"
1849 ", count=%u, action=%d\n", s, index, count, action);
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001850
Alexandre Julliard329f0681996-04-14 13:21:20 +00001851 switch (action) {
1852 case WB_LEFT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001853 if (!count)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001854 break;
1855 if (index)
1856 index--;
1857 if (s[index] == ' ') {
1858 while (index && (s[index] == ' '))
1859 index--;
1860 if (index) {
1861 while (index && (s[index] != ' '))
1862 index--;
1863 if (s[index] == ' ')
1864 index++;
1865 }
1866 } else {
1867 while (index && (s[index] != ' '))
1868 index--;
1869 if (s[index] == ' ')
1870 index++;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001871 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001872 ret = index;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001873 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001874 case WB_RIGHT:
1875 if (!count)
1876 break;
1877 if (index)
1878 index--;
1879 if (s[index] == ' ')
1880 while ((index < count) && (s[index] == ' ')) index++;
1881 else {
1882 while (s[index] && (s[index] != ' ') && (index < count))
1883 index++;
1884 while ((s[index] == ' ') && (index < count)) index++;
1885 }
1886 ret = index;
1887 break;
1888 case WB_ISDELIMITER:
1889 ret = (s[index] == ' ');
1890 break;
1891 default:
1892 fprintf(stderr, "edit: EDIT_WordBreakProc: unknown action code, please report !\n");
1893 break;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001894 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001895 return ret;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001896}
1897
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001898
Alexandre Julliard329f0681996-04-14 13:21:20 +00001899/*********************************************************************
1900 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001901 * EM_CHARFROMPOS
1902 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001903 * FIXME: do the specs mean to return LineIndex or LineNumber ???
1904 * Let's assume LineIndex is meant
1905 * FIXME: do the specs mean to return -1 if outside client area or
1906 * if outside formatting rectangle ???
1907 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001908 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001909static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001910{
1911 POINT32 pt;
1912 RECT32 rc;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001913 INT32 index;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001914
Alexandre Julliard889f7421997-04-15 17:19:52 +00001915 pt.x = x;
1916 pt.y = y;
1917 GetClientRect32(wnd->hwndSelf, &rc);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001918 if (!PtInRect32(&rc, pt))
1919 return -1;
1920
Alexandre Julliard889f7421997-04-15 17:19:52 +00001921 index = EDIT_CharFromPos(wnd, es, x, y, NULL);
1922 return MAKELONG(index, EDIT_EM_LineIndex(wnd, es,
1923 EDIT_EM_LineFromChar(wnd, es, index)));
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001924}
1925
Alexandre Julliard329f0681996-04-14 13:21:20 +00001926
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00001927/*********************************************************************
Alexandre Julliard329f0681996-04-14 13:21:20 +00001928 *
1929 * EM_FMTLINES
1930 *
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001931 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001932static BOOL32 EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL32 add_eol)
Alexandre Julliard58199531994-04-21 01:20:00 +00001933{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001934 fprintf(stdnimp, "edit: EM_FMTLINES: message not implemented\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00001935 return add_eol;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001936}
Alexandre Julliard988ca971994-06-21 16:15:21 +00001937
Alexandre Julliard58199531994-04-21 01:20:00 +00001938
Alexandre Julliard329f0681996-04-14 13:21:20 +00001939/*********************************************************************
1940 *
1941 * EM_GETHANDLE
1942 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001943 * Hopefully this won't fire back at us.
1944 * We always start with a fixed buffer in our own heap.
1945 * However, with this message a 32 bit application requests
1946 * a handle to 32 bit moveable local heap memory, where it expects
1947 * to find the text.
1948 * It's a pitty that from this moment on we have to use this
1949 * local heap, because applications may rely on the handle
1950 * in the future.
1951 *
1952 * In this function we'll try to switch to local heap.
1953 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00001954 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001955static HLOCAL32 EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001956{
Alexandre Julliard889f7421997-04-15 17:19:52 +00001957 HLOCAL32 newBuf;
1958 LPSTR newText;
1959 INT32 newSize;
Alexandre Julliard58199531994-04-21 01:20:00 +00001960
Alexandre Julliard889f7421997-04-15 17:19:52 +00001961 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001962 return 0;
1963
Alexandre Julliard889f7421997-04-15 17:19:52 +00001964 if (es->hloc32)
1965 return es->hloc32;
1966 else if (es->hloc16)
1967 return (HLOCAL32)es->hloc16;
1968
1969 if (!(newBuf = LocalAlloc32(LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) {
1970 fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 32 bit buffer\n");
1971 return 0;
1972 }
1973 newSize = MIN(LocalSize32(newBuf) - 1, es->buffer_limit);
1974 if (!(newText = LocalLock32(newBuf))) {
1975 fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 32 bit buffer\n");
1976 LocalFree32(newBuf);
1977 return 0;
1978 }
1979 lstrcpy32A(newText, es->text);
1980 EDIT_UnlockBuffer(wnd, es, TRUE);
1981 if (es->text)
1982 HeapFree(es->heap, 0, es->text);
1983 es->hloc32 = newBuf;
1984 es->hloc16 = (HLOCAL16)NULL;
1985 es->buffer_size = newSize;
1986 es->text = newText;
1987 EDIT_LockBuffer(wnd, es);
1988 dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 32 bit local heap\n");
1989
1990 return es->hloc32;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001991}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001992
1993
1994/*********************************************************************
1995 *
1996 * EM_GETHANDLE16
1997 *
1998 * Hopefully this won't fire back at us.
1999 * We always start with a buffer in 32 bit linear memory.
2000 * However, with this message a 16 bit application requests
2001 * a handle of 16 bit local heap memory, where it expects to find
2002 * the text.
2003 * It's a pitty that from this moment on we have to use this
2004 * local heap, because applications may rely on the handle
2005 * in the future.
2006 *
2007 * In this function we'll try to switch to local heap.
2008 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002009static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002010{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002011 HLOCAL16 newBuf;
2012 LPSTR newText;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002013 INT32 newSize;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002014
Alexandre Julliard889f7421997-04-15 17:19:52 +00002015 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002016 return 0;
2017
Alexandre Julliard889f7421997-04-15 17:19:52 +00002018 if (es->hloc16)
2019 return es->hloc16;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002020
Alexandre Julliard889f7421997-04-15 17:19:52 +00002021 if (!LOCAL_HeapSize(wnd->hInstance)) {
2022 if (!LocalInit(wnd->hInstance, 0,
2023 GlobalSize16(wnd->hInstance))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002024 fprintf(stderr, "edit: EM_GETHANDLE: could not initialize local heap\n");
2025 return 0;
2026 }
2027 dprintf_edit(stddeb, "edit: EM_GETHANDLE: local heap initialized\n");
2028 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002029 if (!(newBuf = LOCAL_Alloc(wnd->hInstance, LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002030 fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 16 bit buffer\n");
2031 return 0;
2032 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002033 newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit);
2034 if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002035 fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 16 bit buffer\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002036 LOCAL_Free(wnd->hInstance, newBuf);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002037 return 0;
2038 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002039 lstrcpy32A(newText, es->text);
2040 EDIT_UnlockBuffer(wnd, es, TRUE);
2041 if (es->text)
2042 HeapFree(es->heap, 0, es->text);
2043 else if (es->hloc32) {
2044 while (LocalFree32(es->hloc32)) ;
2045 LocalFree32(es->hloc32);
2046 }
2047 es->hloc32 = (HLOCAL32)NULL;
2048 es->hloc16 = newBuf;
2049 es->buffer_size = newSize;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002050 es->text = newText;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002051 EDIT_LockBuffer(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002052 dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 16 bit buffer\n");
2053
Alexandre Julliard889f7421997-04-15 17:19:52 +00002054 return es->hloc16;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002055}
2056
Alexandre Julliard58199531994-04-21 01:20:00 +00002057
Alexandre Julliard329f0681996-04-14 13:21:20 +00002058/*********************************************************************
2059 *
2060 * EM_GETLINE
2061 *
2062 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002063static INT32 EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT32 line, LPSTR lpch)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002064{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002065 LPSTR src;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002066 INT32 len;
2067 INT32 i;
Alexandre Julliard58199531994-04-21 01:20:00 +00002068
Alexandre Julliard889f7421997-04-15 17:19:52 +00002069 if (es->style & ES_MULTILINE) {
2070 if (line >= es->line_count)
2071 return 0;
2072 } else
2073 line = 0;
2074 src = es->text + EDIT_EM_LineIndex(wnd, es, line);
2075 len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, line));
Alexandre Julliard329f0681996-04-14 13:21:20 +00002076 for (i = 0 ; i < len ; i++) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002077 *lpch = *src;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002078 src++;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002079 lpch++;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002080 }
2081 return (LRESULT)len;
2082}
Alexandre Julliard58199531994-04-21 01:20:00 +00002083
Alexandre Julliard58199531994-04-21 01:20:00 +00002084
Alexandre Julliard329f0681996-04-14 13:21:20 +00002085/*********************************************************************
2086 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002087 * EM_GETSEL
2088 *
2089 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002090static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT32 start, LPUINT32 end)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002091{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002092 UINT32 s = es->selection_start;
2093 UINT32 e = es->selection_end;
Alexandre Julliard58199531994-04-21 01:20:00 +00002094
Alexandre Julliard889f7421997-04-15 17:19:52 +00002095 ORDER_UINT32(s, e);
2096 if (start)
2097 *start = s;
2098 if (end)
2099 *end = e;
2100 return MAKELONG(s, e);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002101}
2102
2103
2104/*********************************************************************
2105 *
2106 * EM_GETTHUMB
2107 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002108 * FIXME: is this right ? (or should it be only VSCROLL)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002109 * (and maybe only for edit controls that really have their
2110 * own scrollbars) (and maybe only for multiline controls ?)
2111 * All in all: very poorly documented
Alexandre Julliard329f0681996-04-14 13:21:20 +00002112 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002113 * FIXME: now it's also broken, because of the new WM_HSCROLL /
2114 * WM_VSCROLL handlers
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002115 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002116 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002117static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002118{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002119 return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB16, 0, 0),
2120 EDIT_WM_HScroll(wnd, es, EM_GETTHUMB16, 0, 0));
Alexandre Julliard329f0681996-04-14 13:21:20 +00002121}
2122
2123
2124/*********************************************************************
2125 *
2126 * EM_LINEFROMCHAR
2127 *
2128 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002129static INT32 EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT32 index)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002130{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002131 INT32 line;
2132 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002133
Alexandre Julliard889f7421997-04-15 17:19:52 +00002134 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002135 return 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002136 if (index > lstrlen32A(es->text))
2137 return es->line_count - 1;
2138 if (index == -1)
2139 index = MIN(es->selection_start, es->selection_end);
2140
2141 line = 0;
2142 line_def = es->first_line_def;
2143 index -= line_def->length;
2144 while ((index >= 0) && line_def->next) {
2145 line++;
2146 line_def = line_def->next;
2147 index -= line_def->length;
2148 }
2149 return line;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002150}
2151
2152
2153/*********************************************************************
2154 *
2155 * EM_LINEINDEX
2156 *
2157 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002158static INT32 EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT32 line)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002159{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002160 INT32 line_index;
2161 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002162
Alexandre Julliard889f7421997-04-15 17:19:52 +00002163 if (!(es->style & ES_MULTILINE))
2164 return 0;
2165 if (line >= es->line_count)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002166 return -1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002167
2168 line_index = 0;
2169 line_def = es->first_line_def;
2170 if (line == -1) {
2171 INT32 index = es->selection_end - line_def->length;
2172 while ((index >= 0) && line_def->next) {
2173 line_index += line_def->length;
2174 line_def = line_def->next;
2175 index -= line_def->length;
2176 }
2177 } else {
2178 while (line > 0) {
2179 line_index += line_def->length;
2180 line_def = line_def->next;
2181 line--;
2182 }
2183 }
2184 return line_index;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002185}
2186
2187
2188/*********************************************************************
2189 *
2190 * EM_LINELENGTH
2191 *
2192 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002193static INT32 EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT32 index)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002194{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002195 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002196
Alexandre Julliard889f7421997-04-15 17:19:52 +00002197 if (!(es->style & ES_MULTILINE))
2198 return lstrlen32A(es->text);
2199
2200 if (index == -1) {
2201 /* FIXME: broken
2202 INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start);
2203 INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end);
2204 return es->selection_start - es->line_defs[sl].offset +
2205 es->line_defs[el].offset +
2206 es->line_defs[el].length - es->selection_end;
2207 */
2208 return 0;
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002209 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002210 line_def = es->first_line_def;
2211 index -= line_def->length;
2212 while ((index >= 0) && line_def->next) {
2213 line_def = line_def->next;
2214 index -= line_def->length;
2215 }
2216 return line_def->net_length;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002217}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002218
Alexandre Julliard329f0681996-04-14 13:21:20 +00002219
2220/*********************************************************************
2221 *
2222 * EM_LINESCROLL
2223 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002224 * FIXME: dx is in average character widths
2225 * However, we assume it is in pixels when we use this
2226 * function internally
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002227 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002228 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002229static BOOL32 EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT32 dx, INT32 dy)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002230{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002231 INT32 nyoff;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002232
Alexandre Julliard889f7421997-04-15 17:19:52 +00002233 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002234 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002235
2236 if (-dx > es->x_offset)
2237 dx = -es->x_offset;
2238 if (dx > es->text_width - es->x_offset)
2239 dx = es->text_width - es->x_offset;
2240 nyoff = MAX(0, es->y_offset + dy);
2241 if (nyoff >= es->line_count)
2242 nyoff = es->line_count - 1;
2243 dy = (es->y_offset - nyoff) * es->line_height;
2244 if (dx || dy) {
2245 if (!(wnd->flags & WIN_NO_REDRAW)) {
2246 RECT32 rc1;
2247 RECT32 rc;
2248 GetClientRect32(wnd->hwndSelf, &rc1);
2249 IntersectRect32(&rc, &rc1, &es->format_rect);
2250 ScrollWindowEx32(wnd->hwndSelf, -dx, dy,
2251 NULL, &rc, (HRGN32)NULL, NULL, SW_INVALIDATE);
2252 }
2253 es->y_offset = nyoff;
2254 es->x_offset += dx;
2255 }
2256 if (dx && !(es->flags & EF_HSCROLL_TRACK))
2257 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
2258 if (dy && !(es->flags & EF_VSCROLL_TRACK))
2259 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
2260 return TRUE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002261}
2262
2263
2264/*********************************************************************
2265 *
2266 * EM_POSFROMCHAR
2267 *
2268 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002269static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT32 index, BOOL32 after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002270{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002271 INT32 len = lstrlen32A(es->text);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002272 INT32 l;
2273 INT32 li;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002274 INT32 x;
2275 INT32 y = 0;
2276 HDC32 dc;
2277 HFONT32 old_font = 0;
2278 SIZE32 size;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002279
Alexandre Julliard889f7421997-04-15 17:19:52 +00002280 index = MIN(index, len);
2281 dc = GetDC32(wnd->hwndSelf);
2282 if (es->font)
2283 old_font = SelectObject32(dc, es->font);
2284 if (es->style & ES_MULTILINE) {
2285 l = EDIT_EM_LineFromChar(wnd, es, index);
2286 y = (l - es->y_offset) * es->line_height;
2287 li = EDIT_EM_LineIndex(wnd, es, l);
2288 if (after_wrap && (li == index) && l) {
2289 INT32 l2 = l - 1;
2290 LINEDEF *line_def = es->first_line_def;
2291 while (l2) {
2292 line_def = line_def->next;
2293 l2--;
2294 }
2295 if (line_def->ending == END_WRAP) {
2296 l--;
2297 y -= es->line_height;
2298 li = EDIT_EM_LineIndex(wnd, es, l);
2299 }
2300 }
2301 x = LOWORD(GetTabbedTextExtent32A(dc, es->text + li, index - li,
2302 es->tabs_count, es->tabs)) - es->x_offset;
2303 } else {
2304 LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es);
2305 if (index < es->x_offset) {
2306 GetTextExtentPoint32A(dc, text + index,
2307 es->x_offset - index, &size);
2308 x = -size.cx;
2309 } else {
2310 GetTextExtentPoint32A(dc, text + es->x_offset,
2311 index - es->x_offset, &size);
2312 x = size.cx;
2313 }
2314 y = 0;
2315 if (es->style & ES_PASSWORD)
2316 HeapFree(es->heap, 0 ,text);
2317 }
2318 x += es->format_rect.left;
2319 y += es->format_rect.top;
2320 if (es->font)
2321 SelectObject32(dc, old_font);
2322 ReleaseDC32(wnd->hwndSelf, dc);
2323 return MAKELONG((INT16)x, (INT16)y);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002324}
2325
2326
2327/*********************************************************************
2328 *
2329 * EM_REPLACESEL
2330 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002331 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2332 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002333 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002334static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL32 can_undo, LPCSTR lpsz_replace)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002335{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002336 INT32 strl = lstrlen32A(lpsz_replace);
2337 INT32 tl = lstrlen32A(es->text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002338 INT32 utl;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002339 UINT32 s;
2340 UINT32 e;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002341 INT32 i;
2342 LPSTR p;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002343
Alexandre Julliard889f7421997-04-15 17:19:52 +00002344 s = es->selection_start;
2345 e = es->selection_end;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002346
2347 if ((s == e) && !strl)
Alexandre Julliard889f7421997-04-15 17:19:52 +00002348 return;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002349
Alexandre Julliard889f7421997-04-15 17:19:52 +00002350 ORDER_UINT32(s, e);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002351
Alexandre Julliard889f7421997-04-15 17:19:52 +00002352 if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl))
2353 return;
2354
Alexandre Julliard01d63461997-01-20 19:43:45 +00002355 if (e != s) {
2356 /* there is something to be deleted */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002357 if (can_undo) {
2358 utl = lstrlen32A(es->undo_text);
2359 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
Alexandre Julliard01d63461997-01-20 19:43:45 +00002360 /* undo-buffer is extended to the right */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002361 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2362 lstrcpyn32A(es->undo_text + utl, es->text + s, e - s + 1);
2363 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
Alexandre Julliard01d63461997-01-20 19:43:45 +00002364 /* undo-buffer is extended to the left */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002365 EDIT_MakeUndoFit(wnd, es, utl + e - s);
2366 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002367 p[e - s] = p[0];
Alexandre Julliard889f7421997-04-15 17:19:52 +00002368 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2369 p[i] = (es->text + s)[i];
2370 es->undo_position = s;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002371 } else {
2372 /* new undo-buffer */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002373 EDIT_MakeUndoFit(wnd, es, e - s);
2374 lstrcpyn32A(es->undo_text, es->text + s, e - s + 1);
2375 es->undo_position = s;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002376 }
2377 /* any deletion makes the old insertion-undo invalid */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002378 es->undo_insert_count = 0;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002379 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002380 EDIT_EM_EmptyUndoBuffer(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002381
2382 /* now delete */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002383 lstrcpy32A(es->text + s, es->text + e);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002384 }
2385 if (strl) {
2386 /* there is an insertion */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002387 if (can_undo) {
2388 if ((s == es->undo_position) ||
2389 ((es->undo_insert_count) &&
2390 (s == es->undo_position + es->undo_insert_count)))
Alexandre Julliard01d63461997-01-20 19:43:45 +00002391 /*
2392 * insertion is new and at delete position or
2393 * an extension to either left or right
2394 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002395 es->undo_insert_count += strl;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002396 else {
2397 /* new insertion undo */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002398 es->undo_position = s;
2399 es->undo_insert_count = strl;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002400 /* new insertion makes old delete-buffer invalid */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002401 *es->undo_text = '\0';
Alexandre Julliard01d63461997-01-20 19:43:45 +00002402 }
2403 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002404 EDIT_EM_EmptyUndoBuffer(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002405
2406 /* now insert */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002407 tl = lstrlen32A(es->text);
2408 for (p = es->text + tl ; p >= es->text + s ; p--)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002409 p[strl] = p[0];
Alexandre Julliard889f7421997-04-15 17:19:52 +00002410 for (i = 0 , p = es->text + s ; i < strl ; i++)
2411 p[i] = lpsz_replace[i];
2412 if(es->style & ES_UPPERCASE)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002413 CharUpperBuff32A(p, strl);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002414 else if(es->style & ES_LOWERCASE)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002415 CharLowerBuff32A(p, strl);
2416 s += strl;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002417 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002418 /* FIXME: really inefficient */
2419 if (es->style & ES_MULTILINE)
2420 EDIT_BuildLineDefs_ML(wnd, es);
2421
2422 EDIT_EM_SetSel(wnd, es, s, s, FALSE);
2423 es->flags |= EF_MODIFIED;
2424 es->flags |= EF_UPDATE;
2425 EDIT_EM_ScrollCaret(wnd, es);
2426
2427 /* FIXME: really inefficient */
2428 if (!(wnd->flags & WIN_NO_REDRAW))
2429 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002430}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002431
Alexandre Julliard329f0681996-04-14 13:21:20 +00002432
2433/*********************************************************************
2434 *
2435 * EM_SCROLL
Alexandre Julliard889f7421997-04-15 17:19:52 +00002436 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002437 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002438static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT32 action)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002439{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002440 INT32 dy;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002441
Alexandre Julliard889f7421997-04-15 17:19:52 +00002442 if (!(es->style & ES_MULTILINE))
2443 return (LRESULT)FALSE;
2444
2445 dy = 0;
2446
2447 switch (action) {
2448 case SB_LINEUP:
2449 if (es->y_offset)
2450 dy = -1;
2451 break;
2452 case SB_LINEDOWN:
2453 if (es->y_offset < es->line_count - 1)
2454 dy = 1;
2455 break;
2456 case SB_PAGEUP:
2457 if (es->y_offset)
2458 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
2459 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002460 case SB_PAGEDOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002461 if (es->y_offset < es->line_count - 1)
2462 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2463 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002464 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002465 return (LRESULT)FALSE;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002466 }
2467 if (dy) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002468 EDIT_EM_LineScroll(wnd, es, 0, dy);
2469 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002470 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002471 return MAKELONG((INT16)dy, (BOOL16)TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002472}
2473
2474
2475/*********************************************************************
2476 *
2477 * EM_SETHANDLE
2478 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002479 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2480 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002481 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002482static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL32 hloc)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002483{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002484 if (!(es->style & ES_MULTILINE))
2485 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002486
Alexandre Julliard889f7421997-04-15 17:19:52 +00002487 if (!hloc) {
2488 fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n");
2489 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002490 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002491
2492 EDIT_UnlockBuffer(wnd, es, TRUE);
2493 /*
2494 * old buffer is freed by caller, unless
2495 * it is still in our own heap. (in that case
2496 * we free it, correcting the buggy caller.)
2497 */
2498 if (es->text)
2499 HeapFree(es->heap, 0, es->text);
2500
2501 es->hloc16 = (HLOCAL16)NULL;
2502 es->hloc32 = hloc;
2503 es->text = NULL;
2504 es->buffer_size = LocalSize32(es->hloc32) - 1;
2505 EDIT_LockBuffer(wnd, es);
2506
2507 es->x_offset = es->y_offset = 0;
2508 es->selection_start = es->selection_end = 0;
2509 EDIT_EM_EmptyUndoBuffer(wnd, es);
2510 es->flags &= ~EF_MODIFIED;
2511 es->flags &= ~EF_UPDATE;
2512 EDIT_BuildLineDefs_ML(wnd, es);
2513 if (!(wnd->flags & WIN_NO_REDRAW))
2514 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2515 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002516}
2517
2518
2519/*********************************************************************
2520 *
2521 * EM_SETHANDLE16
2522 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002523 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
2524 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002525 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002526static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002527{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002528 if (!(es->style & ES_MULTILINE))
2529 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002530
Alexandre Julliard889f7421997-04-15 17:19:52 +00002531 if (!hloc) {
2532 fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n");
2533 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002534 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002535
2536 EDIT_UnlockBuffer(wnd, es, TRUE);
2537 /*
2538 * old buffer is freed by caller, unless
2539 * it is still in our own heap. (in that case
2540 * we free it, correcting the buggy caller.)
2541 */
2542 if (es->text)
2543 HeapFree(es->heap, 0, es->text);
2544
2545 es->hloc16 = hloc;
2546 es->hloc32 = (HLOCAL32)NULL;
2547 es->text = NULL;
2548 es->buffer_size = LOCAL_Size(wnd->hInstance, es->hloc16) - 1;
2549 EDIT_LockBuffer(wnd, es);
2550
2551 es->x_offset = es->y_offset = 0;
2552 es->selection_start = es->selection_end = 0;
2553 EDIT_EM_EmptyUndoBuffer(wnd, es);
2554 es->flags &= ~EF_MODIFIED;
2555 es->flags &= ~EF_UPDATE;
2556 EDIT_BuildLineDefs_ML(wnd, es);
2557 if (!(wnd->flags & WIN_NO_REDRAW))
2558 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2559 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002560}
2561
2562
2563/*********************************************************************
2564 *
2565 * EM_SETLIMITTEXT
2566 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002567 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
2568 * However, the windows version is not complied to yet in all of edit.c
2569 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002570 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002571static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT32 limit)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002572{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002573 if (es->style & ES_MULTILINE) {
2574 if (limit)
2575 es->buffer_limit = MIN(limit, BUFLIMIT_MULTI);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002576 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002577 es->buffer_limit = BUFLIMIT_MULTI;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002578 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002579 if (limit)
2580 es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002581 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002582 es->buffer_limit = BUFLIMIT_SINGLE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002583 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002584}
2585
2586
2587/*********************************************************************
2588 *
2589 * EM_SETMARGINS
2590 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002591 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002592static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT32 action, INT32 left, INT32 right)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002593{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002594 if (action & EC_USEFONTINFO) {
2595 if (es->style & ES_MULTILINE) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002596 /*
2597 * FIXME: do some GetABCCharWidth, or so
2598 * This is just preliminary
2599 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002600 es->left_margin = es->right_margin = es->char_width;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002601 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002602 es->left_margin = es->right_margin = es->char_width;
2603 return;
2604 } else {
2605 if (action & EC_LEFTMARGIN)
2606 es->left_margin = left;
2607 if (action & EC_RIGHTMARGIN)
2608 es->right_margin = right;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002609 }
Alexandre Julliard58199531994-04-21 01:20:00 +00002610}
2611
Alexandre Julliard329f0681996-04-14 13:21:20 +00002612
2613/*********************************************************************
2614 *
2615 * EM_SETPASSWORDCHAR
2616 *
2617 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002618static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002619{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002620 if (es->style & ES_MULTILINE)
2621 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002622
Alexandre Julliard889f7421997-04-15 17:19:52 +00002623 if (es->password_char == c)
2624 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002625
Alexandre Julliard889f7421997-04-15 17:19:52 +00002626 es->password_char = c;
2627 if (c) {
2628 wnd->dwStyle |= ES_PASSWORD;
2629 es->style |= ES_PASSWORD;
2630 } else {
2631 wnd->dwStyle &= ~ES_PASSWORD;
2632 es->style &= ~ES_PASSWORD;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002633 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002634 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002635}
2636
2637
2638/*********************************************************************
2639 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002640 * EDIT_EM_SetSel
2641 *
2642 * note: unlike the specs say: the order of start and end
2643 * _is_ preserved in Windows. (i.e. start can be > end)
2644 * In other words: this handler is OK
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002645 *
2646 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002647static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT32 start, UINT32 end, BOOL32 after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002648{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002649 UINT32 old_start = es->selection_start;
2650 UINT32 old_end = es->selection_end;
2651 UINT32 len = lstrlen32A(es->text);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002652
Alexandre Julliard889f7421997-04-15 17:19:52 +00002653 if (start == -1) {
2654 start = es->selection_end;
2655 end = es->selection_end;
2656 } else {
2657 start = MIN(start, len);
2658 end = MIN(end, len);
2659 }
2660 es->selection_start = start;
2661 es->selection_end = end;
2662 if (after_wrap)
2663 es->flags |= EF_AFTER_WRAP;
2664 else
2665 es->flags &= ~EF_AFTER_WRAP;
2666 if (!(wnd->flags & WIN_NO_REDRAW)) {
2667 if (es->flags & EF_FOCUSED) {
2668 LRESULT pos = EDIT_EM_PosFromChar(wnd, es, end, after_wrap);
2669 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
2670 }
2671 /* FIXME: little efficiency, could be better */
2672 ORDER_UINT32(start, end);
2673 ORDER_UINT32(start, old_start);
2674 ORDER_UINT32(start, old_end);
2675 ORDER_UINT32(end, old_start);
2676 ORDER_UINT32(end, old_end);
2677 ORDER_UINT32(old_start, old_end);
2678 if (end != old_start) {
2679 EDIT_InvalidateText(wnd, es, start, end);
2680 EDIT_InvalidateText(wnd, es, old_start, old_end);
2681 } else
2682 EDIT_InvalidateText(wnd, es, start, old_end);
2683 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002684}
2685
2686
2687/*********************************************************************
2688 *
2689 * EM_SETTABSTOPS
2690 *
2691 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002692static BOOL32 EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT32 count, LPINT32 tabs)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002693{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002694 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002695 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002696 if (es->tabs)
2697 HeapFree(es->heap, 0, es->tabs);
2698 es->tabs_count = count;
2699 if (!count)
2700 es->tabs = NULL;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002701 else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002702 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32));
2703 memcpy(es->tabs, tabs, count * sizeof(INT32));
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002704 }
2705 return TRUE;
2706}
2707
2708
2709/*********************************************************************
2710 *
2711 * EM_SETTABSTOPS16
2712 *
2713 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002714static BOOL32 EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT32 count, LPINT16 tabs)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002715{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002716 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002717 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002718 if (es->tabs)
2719 HeapFree(es->heap, 0, es->tabs);
2720 es->tabs_count = count;
2721 if (!count)
2722 es->tabs = NULL;
2723 else {
2724 INT32 i;
2725 es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32));
2726 for (i = 0 ; i < count ; i++)
2727 es->tabs[i] = *tabs++;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002728 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002729 return TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002730}
2731
2732
2733/*********************************************************************
2734 *
2735 * EM_SETWORDBREAKPROC
2736 *
2737 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002738static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC32A wbp)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002739{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002740 if (es->word_break_proc32A == wbp)
2741 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002742
Alexandre Julliard889f7421997-04-15 17:19:52 +00002743 es->word_break_proc32A = wbp;
2744 es->word_break_proc16 = NULL;
2745 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2746 EDIT_BuildLineDefs_ML(wnd, es);
2747 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2748 }
2749}
2750
2751
2752/*********************************************************************
2753 *
2754 * EM_SETWORDBREAKPROC16
2755 *
2756 */
2757static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
2758{
2759 if (es->word_break_proc16 == wbp)
2760 return;
2761
2762 es->word_break_proc32A = NULL;
2763 es->word_break_proc16 = wbp;
2764 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
2765 EDIT_BuildLineDefs_ML(wnd, es);
2766 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
2767 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002768}
2769
2770
2771/*********************************************************************
2772 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002773 * EM_UNDO / WM_UNDO
Alexandre Julliard329f0681996-04-14 13:21:20 +00002774 *
2775 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002776static BOOL32 EDIT_EM_Undo(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002777{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002778 INT32 ulength = lstrlen32A(es->undo_text);
2779 LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1);
2780
2781 lstrcpy32A(utext, es->undo_text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002782
2783 dprintf_edit(stddeb, "edit: before UNDO:insertion length = %d, deletion buffer = %s\n",
Alexandre Julliard889f7421997-04-15 17:19:52 +00002784 es->undo_insert_count, utext);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002785
Alexandre Julliard889f7421997-04-15 17:19:52 +00002786 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2787 EDIT_EM_EmptyUndoBuffer(wnd, es);
2788 EDIT_EM_ReplaceSel(wnd, es, TRUE, utext);
2789 EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
2790 HeapFree(es->heap, 0, utext);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002791
2792 dprintf_edit(stddeb, "edit: after UNDO: insertion length = %d, deletion buffer = %s\n",
Alexandre Julliard889f7421997-04-15 17:19:52 +00002793 es->undo_insert_count, es->undo_text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002794
2795 return TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002796}
2797
2798
2799/*********************************************************************
2800 *
2801 * WM_CHAR
2802 *
2803 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002804static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002805{
Alexandre Julliard329f0681996-04-14 13:21:20 +00002806 switch (c) {
2807 case '\r':
2808 case '\n':
Alexandre Julliard889f7421997-04-15 17:19:52 +00002809 if (es->style & ES_MULTILINE) {
2810 if (es->style & ES_READONLY) {
2811 EDIT_MoveHome(wnd, es, FALSE);
2812 EDIT_MoveDown_ML(wnd, es, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002813 } else
Alexandre Julliard889f7421997-04-15 17:19:52 +00002814 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n");
Alexandre Julliard329f0681996-04-14 13:21:20 +00002815 }
2816 break;
2817 case '\t':
Alexandre Julliard889f7421997-04-15 17:19:52 +00002818 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
2819 EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t");
Alexandre Julliard329f0681996-04-14 13:21:20 +00002820 break;
2821 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002822 if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) {
2823 char str[2];
Alexandre Julliard329f0681996-04-14 13:21:20 +00002824 str[0] = c;
2825 str[1] = '\0';
Alexandre Julliard889f7421997-04-15 17:19:52 +00002826 EDIT_EM_ReplaceSel(wnd, es, TRUE, str);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002827 }
2828 break;
2829 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00002830}
2831
2832
2833/*********************************************************************
2834 *
2835 * WM_COMMAND
2836 *
2837 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002838static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT32 code, INT32 id, HWND32 control)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002839{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002840 if (code || control)
2841 return;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002842
Alexandre Julliard889f7421997-04-15 17:19:52 +00002843 switch (id) {
2844 case EM_UNDO32:
2845 EDIT_EM_Undo(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002846 break;
2847 case WM_CUT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002848 EDIT_WM_Cut(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002849 break;
2850 case WM_COPY:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002851 EDIT_WM_Copy(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002852 break;
2853 case WM_PASTE:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002854 EDIT_WM_Paste(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002855 break;
2856 case WM_CLEAR:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002857 EDIT_WM_Clear(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002858 break;
2859 case EM_SETSEL32:
Alexandre Julliard889f7421997-04-15 17:19:52 +00002860 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
2861 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002862 break;
2863 default:
2864 dprintf_edit(stddeb, "edit: unknown menu item, please report\n");
2865 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002866 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002867}
2868
2869
2870/*********************************************************************
2871 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002872 * WM_CONTEXTMENU
2873 *
2874 * Note: the resource files resource/sysres_??.rc cannot define a
2875 * single popup menu. Hence we use a (dummy) menubar
2876 * containing the single popup menu as its first item.
2877 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00002878 * FIXME: the message identifiers have been chosen arbitrarily,
2879 * hence we use MF_BYPOSITION.
2880 * We might as well use the "real" values (anybody knows ?)
2881 * The menu definition is in resources/sysres_??.rc.
2882 * Once these are OK, we better use MF_BYCOMMAND here
2883 * (as we do in EDIT_WM_Command()).
2884 *
2885 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002886static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND32 hwnd, INT32 x, INT32 y)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002887{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002888 HMENU32 menu = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU));
2889 HMENU32 popup = GetSubMenu32(menu, 0);
2890 UINT32 start = es->selection_start;
2891 UINT32 end = es->selection_end;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002892
Alexandre Julliard889f7421997-04-15 17:19:52 +00002893 ORDER_UINT32(start, end);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002894
2895 /* undo */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002896 EnableMenuItem32(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(wnd, es) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002897 /* cut */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002898 EnableMenuItem32(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002899 /* copy */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002900 EnableMenuItem32(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002901 /* paste */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002902 EnableMenuItem32(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable32(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002903 /* delete */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002904 EnableMenuItem32(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002905 /* select all */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002906 EnableMenuItem32(popup, 7, MF_BYPOSITION | (start || (end != lstrlen32A(es->text)) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002907
Alexandre Julliard889f7421997-04-15 17:19:52 +00002908 TrackPopupMenu32(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL);
2909 DestroyMenu32(menu);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002910}
2911
Alexandre Julliard889f7421997-04-15 17:19:52 +00002912
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002913/*********************************************************************
2914 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002915 * WM_COPY
2916 *
2917 * FIXME: replace with 32 bit calls as soon as they are implemented
2918 * in the clipboard code
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002919 *
2920 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002921static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002922{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002923 INT32 s = es->selection_start;
2924 INT32 e = es->selection_end;
2925 HGLOBAL16 hdst;
2926 LPSTR dst;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002927
Alexandre Julliard889f7421997-04-15 17:19:52 +00002928 if (e == s)
2929 return;
2930 ORDER_INT32(s, e);
2931 hdst = GlobalAlloc16(GMEM_MOVEABLE, (DWORD)(e - s + 1));
2932 dst = GlobalLock16(hdst);
2933 lstrcpyn32A(dst, es->text + s, e - s + 1);
2934 GlobalUnlock16(hdst);
2935 OpenClipboard32(wnd->hwndSelf);
2936 EmptyClipboard32();
2937 SetClipboardData16(CF_TEXT, hdst);
2938 CloseClipboard32();
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002939}
Alexandre Julliard01d63461997-01-20 19:43:45 +00002940
Alexandre Julliard889f7421997-04-15 17:19:52 +00002941
2942/*********************************************************************
2943 *
2944 * WM_CREATE
2945 *
2946 */
2947static LRESULT EDIT_WM_Create(WND *wnd, LPCREATESTRUCT32A cs)
2948{
2949 EDITSTATE *es;
2950
2951 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
2952 return -1;
2953 *(EDITSTATE **)wnd->wExtra = es;
2954 if (!(es->heap = HeapCreate(0, 0x10000, 0)))
2955 return -1;
2956 es->style = cs->style;
2957
2958 /* remove the WS_CAPTION style if it has been set - this is really a */
2959 /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */
2960 if ((es->style & WS_BORDER) && (es->style & WS_DLGFRAME))
2961 es->style ^= WS_DLGFRAME;
2962
2963 if (es->style & ES_MULTILINE) {
2964 es->buffer_size = BUFSTART_MULTI;
2965 es->buffer_limit = BUFLIMIT_MULTI;
2966 if (es->style & WS_VSCROLL)
2967 es->style |= ES_AUTOVSCROLL;
2968 if (es->style & WS_HSCROLL)
2969 es->style |= ES_AUTOHSCROLL;
2970 es->style &= ~ES_PASSWORD;
2971 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
2972 if (es->style & ES_RIGHT)
2973 es->style &= ~ES_CENTER;
2974 es->style &= ~WS_HSCROLL;
2975 es->style &= ~ES_AUTOHSCROLL;
2976 }
2977
2978 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
2979 es->style |= ES_AUTOVSCROLL;
2980 } else {
2981 es->buffer_size = BUFSTART_SINGLE;
2982 es->buffer_limit = BUFLIMIT_SINGLE;
2983 es->style &= ~ES_CENTER;
2984 es->style &= ~ES_RIGHT;
2985 es->style &= ~WS_HSCROLL;
2986 es->style &= ~WS_VSCROLL;
2987 es->style &= ~ES_AUTOVSCROLL;
2988 es->style &= ~ES_WANTRETURN;
2989 if (es->style & ES_UPPERCASE) {
2990 es->style &= ~ES_LOWERCASE;
2991 es->style &= ~ES_NUMBER;
2992 } else if (es->style & ES_LOWERCASE)
2993 es->style &= ~ES_NUMBER;
2994 if (es->style & ES_PASSWORD)
2995 es->password_char = '*';
2996
2997 /* FIXME: for now, all single line controls are AUTOHSCROLL */
2998 es->style |= ES_AUTOHSCROLL;
2999 }
3000 if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3001 return -1;
3002 es->buffer_size = HeapSize(es->heap, 0, es->text) - 1;
3003 if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1)))
3004 return -1;
3005 es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
3006 *es->text = '\0';
3007 if (es->style & ES_MULTILINE)
3008 if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
3009 return -1;
3010 es->line_count = 1;
3011 /*
3012 * To initialize some final structure members, we call some helper
3013 * functions. However, since the EDITSTATE is not consistent (i.e.
3014 * not fully initialized), we should be very careful which
3015 * functions can be called, and in what order.
3016 */
3017 EDIT_WM_SetFont(wnd, es, 0, FALSE);
Alexandre Julliard641ee761997-08-04 16:34:36 +00003018 if (cs->lpszName && *(cs->lpszName) != '\0') {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003019 EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName);
Alexandre Julliard641ee761997-08-04 16:34:36 +00003020 /* 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 */
3021 es->selection_start = es->selection_end = 0;
3022 EDIT_EM_ScrollCaret(wnd, es);
3023 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003024 return 0;
3025}
3026
3027
3028/*********************************************************************
3029 *
3030 * WM_DESTROY
3031 *
3032 */
3033static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es)
3034{
3035 if (es->hloc32) {
3036 while (LocalUnlock32(es->hloc32)) ;
3037 LocalFree32(es->hloc32);
3038 }
3039 if (es->hloc16) {
3040 while (LOCAL_Unlock(wnd->hInstance, es->hloc16)) ;
3041 LOCAL_Free(wnd->hInstance, es->hloc16);
3042 }
3043 HeapDestroy(es->heap);
3044 HeapFree(GetProcessHeap(), 0, es);
3045 *(EDITSTATE **)wnd->wExtra = NULL;
3046}
3047
3048
3049/*********************************************************************
3050 *
3051 * WM_ERASEBKGND
3052 *
3053 */
3054static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC32 dc)
3055{
3056 HBRUSH32 brush;
3057 RECT32 rc;
3058
3059 if (!(brush = (HBRUSH32)EDIT_SEND_CTLCOLOR(wnd, dc)))
3060 brush = (HBRUSH32)GetStockObject32(WHITE_BRUSH);
3061
3062 GetClientRect32(wnd->hwndSelf, &rc);
3063 IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom);
3064 GetClipBox32(dc, &rc);
3065 /*
3066 * FIXME: specs say that we should UnrealizeObject() the brush,
3067 * but the specs of UnrealizeObject() say that we shouldn't
3068 * unrealize a stock object. The default brush that
3069 * DefWndProc() returns is ... a stock object.
3070 */
3071 FillRect32(dc, &rc, brush);
3072 return -1;
3073}
3074
3075
3076/*********************************************************************
3077 *
3078 * WM_GETTEXT
3079 *
3080 */
3081static INT32 EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT32 count, LPSTR text)
3082{
3083 INT32 len = lstrlen32A(es->text);
3084
3085 if (count > len) {
3086 lstrcpy32A(text, es->text);
Alexandre Julliard33072e11997-06-29 18:08:02 +00003087 return len;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003088 } else
Alexandre Julliard33072e11997-06-29 18:08:02 +00003089 return -1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003090}
3091
3092
3093/*********************************************************************
3094 *
3095 * EDIT_HScroll_Hack
3096 *
3097 * 16 bit notepad needs this. Actually it is not _our_ hack,
3098 * it is notepad's. Notepad is sending us scrollbar messages with
3099 * undocumented parameters without us even having a scrollbar ... !?!?
3100 *
3101 */
3102static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
3103{
3104 INT32 dx = 0;
3105 INT32 fw = es->format_rect.right - es->format_rect.left;
3106 LRESULT ret = 0;
3107
3108 if (!(es->flags & EF_HSCROLL_HACK)) {
3109 fprintf(stderr, "edit: hacked WM_HSCROLL handler invoked\n");
3110 fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n");
3111 fprintf(stderr, " (this message is only displayed once per edit control)\n");
3112 es->flags |= EF_HSCROLL_HACK;
3113 }
3114
3115 switch (action) {
3116 case SB_LINELEFT:
3117 if (es->x_offset)
3118 dx = -es->char_width;
3119 break;
3120 case SB_LINERIGHT:
3121 if (es->x_offset < es->text_width)
3122 dx = es->char_width;
3123 break;
3124 case SB_PAGELEFT:
3125 if (es->x_offset)
3126 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3127 break;
3128 case SB_PAGERIGHT:
3129 if (es->x_offset < es->text_width)
3130 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3131 break;
3132 case SB_LEFT:
3133 if (es->x_offset)
3134 dx = -es->x_offset;
3135 break;
3136 case SB_RIGHT:
3137 if (es->x_offset < es->text_width)
3138 dx = es->text_width - es->x_offset;
3139 break;
3140 case SB_THUMBTRACK:
3141 es->flags |= EF_HSCROLL_TRACK;
3142 dx = pos * es->text_width / 100 - es->x_offset;
3143 break;
3144 case SB_THUMBPOSITION:
3145 es->flags &= ~EF_HSCROLL_TRACK;
3146 if (!(dx = pos * es->text_width / 100 - es->x_offset))
3147 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3148 break;
3149 case SB_ENDSCROLL:
3150 break;
3151
3152 /*
3153 * FIXME : the next two are undocumented !
3154 * Are we doing the right thing ?
3155 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3156 * although it's also a regular control message.
3157 */
3158 case EM_GETTHUMB16:
3159 ret = es->text_width ? es->x_offset * 100 / es->text_width : 0;
3160 break;
3161 case EM_LINESCROLL16:
3162 dx = pos;
3163 break;
3164
3165 default:
3166 dprintf_edit(stddeb, "edit: undocumented (hacked) WM_HSCROLL parameter, please report\n");
3167 return 0;
3168 }
3169 if (dx)
3170 EDIT_EM_LineScroll(wnd, es, dx, 0);
3171 return ret;
3172}
3173
3174
3175/*********************************************************************
3176 *
3177 * WM_HSCROLL
3178 *
3179 */
3180static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
3181{
3182 INT32 dx;
3183 INT32 fw;
3184
3185 if (!(es->style & ES_MULTILINE))
3186 return 0;
3187
3188 if (!(es->style & ES_AUTOHSCROLL))
3189 return 0;
3190
3191 if (!(es->style & WS_HSCROLL))
3192 return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar);
3193
3194 dx = 0;
3195 fw = es->format_rect.right - es->format_rect.left;
3196 switch (action) {
3197 case SB_LINELEFT:
3198 if (es->x_offset)
3199 dx = -es->char_width;
3200 break;
3201 case SB_LINERIGHT:
3202 if (es->x_offset < es->text_width)
3203 dx = es->char_width;
3204 break;
3205 case SB_PAGELEFT:
3206 if (es->x_offset)
3207 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3208 break;
3209 case SB_PAGERIGHT:
3210 if (es->x_offset < es->text_width)
3211 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3212 break;
3213 case SB_LEFT:
3214 if (es->x_offset)
3215 dx = -es->x_offset;
3216 break;
3217 case SB_RIGHT:
3218 if (es->x_offset < es->text_width)
3219 dx = es->text_width - es->x_offset;
3220 break;
3221 case SB_THUMBTRACK:
3222 es->flags |= EF_HSCROLL_TRACK;
3223 dx = pos - es->x_offset;
3224 break;
3225 case SB_THUMBPOSITION:
3226 es->flags &= ~EF_HSCROLL_TRACK;
3227 if (!(dx = pos - es->x_offset)) {
3228 SetScrollPos32(wnd->hwndSelf, SB_HORZ, pos, TRUE);
3229 EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL");
3230 }
3231 break;
3232 case SB_ENDSCROLL:
3233 break;
3234
3235 default:
3236 fprintf(stderr, "edit: undocumented WM_HSCROLL parameter, please report\n");
3237 return 0;
3238 }
3239 if (dx)
3240 EDIT_EM_LineScroll(wnd, es, dx, 0);
3241 return 0;
3242}
3243
3244
3245/*********************************************************************
3246 *
3247 * EDIT_CheckCombo
3248 *
3249 */
3250static BOOL32 EDIT_CheckCombo(WND *wnd, UINT32 msg, INT32 key, DWORD key_data)
3251{
3252 HWND32 hLBox;
3253
3254 if (WIDGETS_IsControl32(wnd->parent, BIC32_COMBO) &&
3255 (hLBox = COMBO_GetLBWindow(wnd->parent))) {
3256 HWND32 hCombo = wnd->parent->hwndSelf;
3257 BOOL32 bUIFlip = TRUE;
3258
3259 dprintf_combo(stddeb, "EDIT_CheckCombo [%04x]: handling msg %04x (%04x)\n",
3260 wnd->hwndSelf, (UINT16)msg, (UINT16)key);
3261
3262 switch (msg) {
3263 case WM_KEYDOWN: /* Handle F4 and arrow keys */
3264 if (key != VK_F4) {
3265 bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0);
3266 if (SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0))
3267 bUIFlip = FALSE;
3268 }
3269 if (!bUIFlip)
3270 SendMessage32A(hLBox, WM_KEYDOWN, (WPARAM32)key, 0);
3271 else {
3272 /* make sure ComboLBox pops up */
3273 SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 0, 0);
3274 SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0);
3275 SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 1, 0);
3276 }
3277 break;
3278 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
3279 bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0);
3280 if (bUIFlip) {
3281 bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0);
3282 SendMessage32A(hCombo, CB_SHOWDROPDOWN32, (bUIFlip) ? FALSE : TRUE, 0);
3283 } else
3284 SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0);
3285 break;
3286 }
3287 return TRUE;
3288 }
3289 return FALSE;
3290}
3291
3292
Alexandre Julliard01d63461997-01-20 19:43:45 +00003293/*********************************************************************
3294 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003295 * WM_KEYDOWN
3296 *
3297 * Handling of special keys that don't produce a WM_CHAR
3298 * (i.e. non-printable keys) & Backspace & Delete
3299 *
3300 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003301static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003302{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003303 BOOL32 shift;
3304 BOOL32 control;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003305
Alexandre Julliard349a9531997-02-02 19:01:52 +00003306 if (GetKeyState32(VK_MENU) & 0x8000)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003307 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003308
Alexandre Julliard349a9531997-02-02 19:01:52 +00003309 shift = GetKeyState32(VK_SHIFT) & 0x8000;
3310 control = GetKeyState32(VK_CONTROL) & 0x8000;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003311
Alexandre Julliard889f7421997-04-15 17:19:52 +00003312 switch (key) {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003313 case VK_F4:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003314 case VK_UP:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003315 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3316 break;
3317 if (key == VK_F4)
3318 break;
3319 /* fall through */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003320 case VK_LEFT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003321 if ((es->style & ES_MULTILINE) && (key == VK_UP))
3322 EDIT_MoveUp_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003323 else
3324 if (control)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003325 EDIT_MoveWordBackward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003326 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003327 EDIT_MoveBackward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003328 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003329 case VK_DOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003330 if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data))
3331 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003332 /* fall through */
3333 case VK_RIGHT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003334 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
3335 EDIT_MoveDown_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003336 else if (control)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003337 EDIT_MoveWordForward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003338 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003339 EDIT_MoveForward(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003340 break;
3341 case VK_HOME:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003342 EDIT_MoveHome(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003343 break;
3344 case VK_END:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003345 EDIT_MoveEnd(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003346 break;
3347 case VK_PRIOR:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003348 if (es->style & ES_MULTILINE)
3349 EDIT_MovePageUp_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003350 break;
3351 case VK_NEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003352 if (es->style & ES_MULTILINE)
3353 EDIT_MovePageDown_ML(wnd, es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003354 break;
3355 case VK_BACK:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003356 if (!(es->style & ES_READONLY) && !control)
3357 if (es->selection_start != es->selection_end)
3358 EDIT_WM_Clear(wnd, es);
3359 else {
3360 /* delete character left of caret */
3361 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3362 EDIT_MoveBackward(wnd, es, TRUE);
3363 EDIT_WM_Clear(wnd, es);
3364 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003365 break;
3366 case VK_DELETE:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003367 if (!(es->style & ES_READONLY) && !(shift && control))
3368 if (es->selection_start != es->selection_end) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00003369 if (shift)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003370 EDIT_WM_Cut(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003371 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003372 EDIT_WM_Clear(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003373 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003374 if (shift) {
3375 /* delete character left of caret */
3376 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3377 EDIT_MoveBackward(wnd, es, TRUE);
3378 EDIT_WM_Clear(wnd, es);
3379 } else if (control) {
3380 /* delete to end of line */
3381 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3382 EDIT_MoveEnd(wnd, es, TRUE);
3383 EDIT_WM_Clear(wnd, es);
3384 } else {
3385 /* delete character right of caret */
3386 EDIT_EM_SetSel(wnd, es, -1, 0, FALSE);
3387 EDIT_MoveForward(wnd, es, TRUE);
3388 EDIT_WM_Clear(wnd, es);
3389 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003390 }
3391 break;
3392 case VK_INSERT:
3393 if (shift) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003394 if (!(es->style & ES_READONLY))
3395 EDIT_WM_Paste(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003396 } else if (control)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003397 EDIT_WM_Copy(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003398 break;
3399 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003400 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003401}
3402
3403
3404/*********************************************************************
3405 *
3406 * WM_KILLFOCUS
3407 *
3408 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003409static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND32 window_getting_focus)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003410{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003411 es->flags &= ~EF_FOCUSED;
Alexandre Julliard21979011997-03-05 08:22:35 +00003412 DestroyCaret32();
Alexandre Julliard889f7421997-04-15 17:19:52 +00003413 if(!(es->style & ES_NOHIDESEL))
3414 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3415 EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS");
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003416 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003417}
3418
3419
3420/*********************************************************************
3421 *
3422 * WM_LBUTTONDBLCLK
3423 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00003424 * The caret position has been set on the WM_LBUTTONDOWN message
3425 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003426 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003427static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003428{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003429 INT32 s;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003430 INT32 e = es->selection_end;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003431 INT32 l;
3432 INT32 li;
3433 INT32 ll;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003434
Alexandre Julliard889f7421997-04-15 17:19:52 +00003435 if (!(es->flags & EF_FOCUSED))
3436 return 0;
3437
3438 l = EDIT_EM_LineFromChar(wnd, es, e);
3439 li = EDIT_EM_LineIndex(wnd, es, l);
3440 ll = EDIT_EM_LineLength(wnd, es, e);
3441 s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT);
3442 e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT);
3443 EDIT_EM_SetSel(wnd, es, s, e, FALSE);
3444 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003445 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003446}
3447
3448
3449/*********************************************************************
3450 *
3451 * WM_LBUTTONDOWN
3452 *
3453 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003454static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003455{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003456 INT32 e;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003457 BOOL32 after_wrap;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003458
Alexandre Julliard889f7421997-04-15 17:19:52 +00003459 if (!(es->flags & EF_FOCUSED))
3460 return 0;
3461
3462 SetCapture32(wnd->hwndSelf);
3463 EDIT_ConfinePoint(wnd, es, &x, &y);
3464 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3465 EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
3466 EDIT_EM_ScrollCaret(wnd, es);
3467 SetTimer32(wnd->hwndSelf, 0, 100, NULL);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003468 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003469}
3470
3471
3472/*********************************************************************
3473 *
3474 * WM_LBUTTONUP
3475 *
3476 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003477static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003478{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003479 if (GetCapture32() == wnd->hwndSelf) {
3480 KillTimer32(wnd->hwndSelf, 0);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003481 ReleaseCapture();
Alexandre Julliard01d63461997-01-20 19:43:45 +00003482 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003483 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003484}
3485
3486
3487/*********************************************************************
3488 *
3489 * WM_MOUSEMOVE
3490 *
3491 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003492static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003493{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003494 INT32 e;
3495 BOOL32 after_wrap;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003496
Alexandre Julliard889f7421997-04-15 17:19:52 +00003497 if (GetCapture32() != wnd->hwndSelf)
3498 return 0;
3499
Alexandre Julliard01d63461997-01-20 19:43:45 +00003500 /*
Alexandre Julliard889f7421997-04-15 17:19:52 +00003501 * FIXME: gotta do some scrolling if outside client
Alexandre Julliard01d63461997-01-20 19:43:45 +00003502 * area. Maybe reset the timer ?
3503 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003504 EDIT_ConfinePoint(wnd, es, &x, &y);
3505 e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap);
3506 EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003507 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003508}
3509
3510
3511/*********************************************************************
3512 *
3513 * WM_PAINT
3514 *
3515 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003516static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003517{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003518 PAINTSTRUCT32 ps;
3519 INT32 i;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003520 HDC32 dc;
3521 HFONT32 old_font = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003522 RECT32 rc;
3523 RECT32 rcLine;
3524 RECT32 rcRgn;
Alexandre Julliard01d63461997-01-20 19:43:45 +00003525 LRESULT pos;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003526 BOOL32 rev = IsWindowEnabled32(wnd->hwndSelf) &&
3527 ((es->flags & EF_FOCUSED) ||
3528 (es->style & ES_NOHIDESEL));
Alexandre Julliard329f0681996-04-14 13:21:20 +00003529
Alexandre Julliard889f7421997-04-15 17:19:52 +00003530 if (es->flags & EF_UPDATE)
3531 EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE");
3532
3533 dc = BeginPaint32(wnd->hwndSelf, &ps);
3534 IntersectClipRect32(dc, es->format_rect.left,
3535 es->format_rect.top,
3536 es->format_rect.right,
3537 es->format_rect.bottom);
3538 if (es->style & ES_MULTILINE) {
3539 GetClientRect32(wnd->hwndSelf, &rc);
3540 IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom);
3541 }
3542 if (es->font)
3543 old_font = SelectObject32(dc, es->font);
3544 EDIT_SEND_CTLCOLOR(wnd, dc);
3545 if (!IsWindowEnabled32(wnd->hwndSelf))
3546 SetTextColor32(dc, GetSysColor32(COLOR_GRAYTEXT));
3547 GetClipBox32(dc, &rcRgn);
3548 if (es->style & ES_MULTILINE) {
3549 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3550 for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
3551 EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine);
3552 if (IntersectRect32(&rc, &rcRgn, &rcLine))
3553 EDIT_PaintLine(wnd, es, dc, i, rev);
3554 }
3555 } else {
3556 EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003557 if (IntersectRect32(&rc, &rcRgn, &rcLine))
Alexandre Julliard889f7421997-04-15 17:19:52 +00003558 EDIT_PaintLine(wnd, es, dc, 0, rev);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003559 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003560 if (es->font)
3561 SelectObject32(dc, old_font);
3562 if (es->flags & EF_FOCUSED) {
3563 pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP);
3564 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003565 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003566 EndPaint32(wnd->hwndSelf, &ps);
3567 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) {
3568 INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3569 SCROLLINFO si;
3570 si.cbSize = sizeof(SCROLLINFO);
3571 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3572 si.nMin = 0;
3573 si.nMax = es->line_count + vlc - 2;
3574 si.nPage = vlc;
3575 si.nPos = es->y_offset;
3576 SetScrollInfo32(wnd->hwndSelf, SB_VERT, &si, TRUE);
3577 }
3578 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) {
3579 SCROLLINFO si;
3580 INT32 fw = es->format_rect.right - es->format_rect.left;
3581 si.cbSize = sizeof(SCROLLINFO);
3582 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
3583 si.nMin = 0;
3584 si.nMax = es->text_width + fw - 1;
3585 si.nPage = fw;
3586 si.nPos = es->x_offset;
3587 SetScrollInfo32(wnd->hwndSelf, SB_HORZ, &si, TRUE);
3588 }
3589
3590 if (es->flags & EF_UPDATE) {
3591 es->flags &= ~EF_UPDATE;
3592 EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE");
3593 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003594}
3595
3596
3597/*********************************************************************
3598 *
3599 * WM_PASTE
3600 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00003601 * FIXME: replace with 32 bit handler once GetClipboardData32() is
3602 * implemented in misc/clipboard.c
3603 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003604 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003605static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003606{
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +00003607 HGLOBAL16 hsrc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003608 LPSTR src;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003609
Alexandre Julliard889f7421997-04-15 17:19:52 +00003610 OpenClipboard32(wnd->hwndSelf);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003611 if ((hsrc = GetClipboardData16(CF_TEXT))) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003612 src = (LPSTR)GlobalLock16(hsrc);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003613 EDIT_EM_ReplaceSel(wnd, es, TRUE, src);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00003614 GlobalUnlock16(hsrc);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003615 }
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +00003616 CloseClipboard32();
Alexandre Julliard329f0681996-04-14 13:21:20 +00003617}
3618
3619
3620/*********************************************************************
3621 *
3622 * WM_SETFOCUS
3623 *
3624 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003625static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND32 window_losing_focus)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003626{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003627 LRESULT pos;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003628
Alexandre Julliard889f7421997-04-15 17:19:52 +00003629 es->flags |= EF_FOCUSED;
3630 CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height);
3631 pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP);
3632 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
3633 if(!(es->style & ES_NOHIDESEL))
3634 EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end);
3635 ShowCaret32(wnd->hwndSelf);
3636 EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS");
Alexandre Julliard329f0681996-04-14 13:21:20 +00003637}
3638
3639
3640/*********************************************************************
3641 *
3642 * WM_SETFONT
3643 *
3644 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003645static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT32 font, BOOL32 redraw)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003646{
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003647 TEXTMETRIC32A tm;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003648 HDC32 dc;
3649 HFONT32 old_font = 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003650
Alexandre Julliard889f7421997-04-15 17:19:52 +00003651 es->font = font;
3652 dc = GetDC32(wnd->hwndSelf);
3653 if (font)
3654 old_font = SelectObject32(dc, font);
3655 GetTextMetrics32A(dc, &tm);
3656 es->line_height = tm.tmHeight;
3657 es->char_width = tm.tmAveCharWidth;
3658 if (font)
3659 SelectObject32(dc, old_font);
3660 ReleaseDC32(wnd->hwndSelf, dc);
3661 if (wnd->flags & WIN_ISWIN32)
3662 EDIT_EM_SetMargins(wnd, es, EC_USEFONTINFO, 0, 0);
3663 if (es->style & ES_MULTILINE)
3664 EDIT_BuildLineDefs_ML(wnd, es);
3665 if (redraw && !(wnd->flags & WIN_NO_REDRAW))
3666 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
3667 if (es->flags & EF_FOCUSED) {
3668 LRESULT pos;
Alexandre Julliard21979011997-03-05 08:22:35 +00003669 DestroyCaret32();
Alexandre Julliard889f7421997-04-15 17:19:52 +00003670 CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height);
3671 pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP);
3672 SetCaretPos32(SLOWORD(pos), SHIWORD(pos));
3673 ShowCaret32(wnd->hwndSelf);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003674 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003675}
3676
3677
3678/*********************************************************************
3679 *
3680 * WM_SETTEXT
3681 *
3682 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003683static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003684{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003685 EDIT_EM_SetSel(wnd, es, 0, -1, FALSE);
3686 if (text) {
3687 dprintf_edit(stddeb, "\t'%s'\n", text);
3688 EDIT_EM_ReplaceSel(wnd, es, FALSE, text);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003689 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003690 es->flags |= EF_MODIFIED;
3691 es->flags |= EF_UPDATE;
3692 EDIT_EM_ScrollCaret(wnd, es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003693}
3694
3695
3696/*********************************************************************
3697 *
3698 * WM_SIZE
3699 *
3700 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003701static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT32 action, INT32 width, INT32 height)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003702{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003703 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
3704 RECT32 rc;
3705 SetRect32(&rc, 0, 0, width, height);
3706 EDIT_SetRectNP(wnd, es, &rc);
3707 InvalidateRect32(wnd->hwndSelf, NULL, TRUE);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00003708 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003709}
3710
3711
3712/*********************************************************************
3713 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00003714 * WM_SYSKEYDOWN
3715 *
3716 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003717static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data)
Alexandre Julliard01d63461997-01-20 19:43:45 +00003718{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003719 if ((key == VK_BACK) && (key_data & 0x2000)) {
3720 if (EDIT_EM_CanUndo(wnd, es))
3721 EDIT_EM_Undo(wnd, es);
3722 return 0;
3723 } else if (key == VK_UP || key == VK_DOWN)
3724 if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data))
3725 return 0;
3726 return DefWindowProc32A(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM32)key, (LPARAM)key_data);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003727}
3728
3729
3730/*********************************************************************
3731 *
3732 * WM_TIMER
3733 *
3734 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003735static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT32 id, TIMERPROC32 timer_proc)
Alexandre Julliard01d63461997-01-20 19:43:45 +00003736{
3737/*
3738 * FIXME: gotta do some scrolling here, like
Alexandre Julliard889f7421997-04-15 17:19:52 +00003739 * EDIT_EM_LineScroll(wnd, 0, 1);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003740 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003741}
3742
3743
3744/*********************************************************************
3745 *
3746 * EDIT_VScroll_Hack
3747 *
3748 * 16 bit notepad needs this. Actually it is not _our_ hack,
3749 * it is notepad's. Notepad is sending us scrollbar messages with
3750 * undocumented parameters without us even having a scrollbar ... !?!?
3751 *
3752 */
3753static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
3754{
3755 INT32 dy = 0;
3756 LRESULT ret = 0;
3757
3758 if (!(es->flags & EF_VSCROLL_HACK)) {
3759 fprintf(stderr, "edit: hacked WM_VSCROLL handler invoked\n");
3760 fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n");
3761 fprintf(stderr, " (this message is only displayed once per edit control)\n");
3762 es->flags |= EF_VSCROLL_HACK;
3763 }
3764
3765 switch (action) {
3766 case SB_LINEUP:
3767 case SB_LINEDOWN:
3768 case SB_PAGEUP:
3769 case SB_PAGEDOWN:
3770 EDIT_EM_Scroll(wnd, es, action);
3771 return 0;
3772 case SB_TOP:
3773 dy = -es->y_offset;
3774 break;
3775 case SB_BOTTOM:
3776 dy = es->line_count - 1 - es->y_offset;
3777 break;
3778 case SB_THUMBTRACK:
3779 es->flags |= EF_VSCROLL_TRACK;
3780 dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset;
3781 break;
3782 case SB_THUMBPOSITION:
3783 es->flags &= ~EF_VSCROLL_TRACK;
3784 if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset))
3785 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
3786 break;
3787 case SB_ENDSCROLL:
3788 break;
3789
3790 /*
3791 * FIXME : the next two are undocumented !
3792 * Are we doing the right thing ?
3793 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3794 * although it's also a regular control message.
3795 */
3796 case EM_GETTHUMB16:
3797 ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0;
3798 break;
3799 case EM_LINESCROLL16:
3800 dy = pos;
3801 break;
3802
3803 default:
3804 fprintf(stderr, "edit: undocumented (hacked) WM_VSCROLL parameter, please report\n");
3805 return 0;
3806 }
3807 if (dy)
3808 EDIT_EM_LineScroll(wnd, es, 0, dy);
3809 return ret;
Alexandre Julliard01d63461997-01-20 19:43:45 +00003810}
3811
3812
3813/*********************************************************************
3814 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003815 * WM_VSCROLL
3816 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003817 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00003818static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003819{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003820 INT32 dy;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003821
Alexandre Julliard889f7421997-04-15 17:19:52 +00003822 if (!(es->style & ES_MULTILINE))
3823 return 0;
3824
3825 if (!(es->style & ES_AUTOVSCROLL))
3826 return 0;
3827
3828 if (!(es->style & WS_VSCROLL))
3829 return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar);
3830
3831 dy = 0;
3832 switch (action) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00003833 case SB_LINEUP:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003834 case SB_LINEDOWN:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003835 case SB_PAGEUP:
Alexandre Julliard329f0681996-04-14 13:21:20 +00003836 case SB_PAGEDOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003837 EDIT_EM_Scroll(wnd, es, action);
3838 return 0;
3839
3840 case SB_TOP:
3841 dy = -es->y_offset;
3842 break;
3843 case SB_BOTTOM:
3844 dy = es->line_count - 1 - es->y_offset;
3845 break;
3846 case SB_THUMBTRACK:
3847 es->flags |= EF_VSCROLL_TRACK;
3848 dy = pos - es->y_offset;
3849 break;
3850 case SB_THUMBPOSITION:
3851 es->flags &= ~EF_VSCROLL_TRACK;
3852 if (!(dy = pos - es->y_offset)) {
3853 SetScrollPos32(wnd->hwndSelf, SB_VERT, pos, TRUE);
3854 EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL");
3855 }
3856 break;
3857 case SB_ENDSCROLL:
3858 break;
3859
Alexandre Julliard329f0681996-04-14 13:21:20 +00003860 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003861 fprintf(stderr, "edit: undocumented WM_VSCROLL parameter, please report\n");
3862 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003863 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003864 if (dy)
3865 EDIT_EM_LineScroll(wnd, es, 0, dy);
3866 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003867}