1 | /* $Id: edit.cpp,v 1.43 2001-07-08 15:51:41 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Edit control
|
---|
4 | *
|
---|
5 | * Copyright David W. Metcalfe, 1994
|
---|
6 | * Copyright William Magro, 1995, 1996
|
---|
7 | * Copyright Frans van Dorsselaer, 1996, 1997
|
---|
8 | *
|
---|
9 | * Copyright 1999 Christoph Bratschi
|
---|
10 | *
|
---|
11 | * Corel version: 20000513
|
---|
12 | * (WINE version: 991212)
|
---|
13 | *
|
---|
14 | * Status: complete
|
---|
15 | * Version: 5.00
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* CB: todo
|
---|
19 | - EN_ALIGN_LTR_EC, EN_ALIGN_RTL_EC -> undocumented notifications
|
---|
20 | - text alignment for single and multi line (ES_LEFT, ES_RIGHT, ES_CENTER)
|
---|
21 | new in Win98, Win2k: for single line too
|
---|
22 | - WinNT/Win2k: higher size limits (single: 0x7FFFFFFE, multi: none)
|
---|
23 | SvL: Limits removed. EM_SETTEXTLIMIT has no effect in NT4, SP6 (EM_GETTEXTLIMIT
|
---|
24 | only returns that value); limits are simply ignored, no EN_MAXTEXT is ever sent)
|
---|
25 | - too many redraws and recalculations!
|
---|
26 | */
|
---|
27 |
|
---|
28 | #include <stdlib.h>
|
---|
29 | #include <os2win.h>
|
---|
30 | #include <string.h>
|
---|
31 | #include "controls.h"
|
---|
32 | #include "combo.h"
|
---|
33 |
|
---|
34 | #define DBG_LOCALLOG DBG_edit
|
---|
35 | #include "dbglocal.h"
|
---|
36 |
|
---|
37 | #ifdef DEBUG
|
---|
38 | char *GetMsgText(int Msg);
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
|
---|
42 | FIXME: BTW, Win95 specs say 65535 (do you dare ???) */
|
---|
43 | #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
|
---|
44 |
|
---|
45 | #ifdef __WIN32OS2__
|
---|
46 | #define BUFLIMIT_SINGLE_NT 0x7FFFFFFF
|
---|
47 | #endif
|
---|
48 | //#define BUFLIMIT_MULTI 0xFFFFFFFE
|
---|
49 | //#define BUFLIMIT_SINGLE 0x7FFFFFFF
|
---|
50 |
|
---|
51 | #define BUFSTART_MULTI 1024 /* starting size */
|
---|
52 | #define BUFSTART_SINGLE 256 /* starting size */
|
---|
53 | #define GROWLENGTH 64 /* buffers grow by this much */
|
---|
54 | #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
|
---|
55 |
|
---|
56 | /*
|
---|
57 | * extra flags for EDITSTATE.flags field
|
---|
58 | */
|
---|
59 | #define EF_MODIFIED 0x0001 /* text has been modified */
|
---|
60 | #define EF_FOCUSED 0x0002 /* we have input focus */
|
---|
61 | #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */
|
---|
62 | #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
|
---|
63 | #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
|
---|
64 | #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */
|
---|
65 | #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */
|
---|
66 | #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
|
---|
67 | wrapped line, instead of in front of the next character */
|
---|
68 | #define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
|
---|
69 |
|
---|
70 | typedef enum
|
---|
71 | {
|
---|
72 | END_0 = 0, /* line ends with terminating '\0' character */
|
---|
73 | END_WRAP, /* line is wrapped */
|
---|
74 | END_HARD, /* line ends with a hard return '\r\n' */
|
---|
75 | END_SOFT /* line ends with a soft return '\r\r\n' */
|
---|
76 | } LINE_END;
|
---|
77 |
|
---|
78 | typedef struct tagLINEDEF {
|
---|
79 | INT length; /* bruto length of a line in bytes */
|
---|
80 | INT net_length; /* netto length of a line in visible characters */
|
---|
81 | LINE_END ending;
|
---|
82 | INT width; /* width of the line in pixels */
|
---|
83 | struct tagLINEDEF *next;
|
---|
84 | } LINEDEF;
|
---|
85 |
|
---|
86 | typedef struct
|
---|
87 | {
|
---|
88 | HANDLE heap; /* our own heap */
|
---|
89 | LPSTR text; /* the actual contents of the control */
|
---|
90 | INT buffer_size; /* the size of the buffer */
|
---|
91 | INT buffer_limit; /* the maximum size to which the buffer may grow */
|
---|
92 | HFONT font; /* NULL means standard system font */
|
---|
93 | INT x_offset; /* scroll offset for multi lines this is in pixels
|
---|
94 | for single lines it's in characters */
|
---|
95 | INT line_height; /* height of a screen line in pixels */
|
---|
96 | INT char_width; /* average character width in pixels */
|
---|
97 | DWORD style; /* sane version of wnd->dwStyle */
|
---|
98 | WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
|
---|
99 | INT undo_insert_count; /* number of characters inserted in sequence */
|
---|
100 | INT undo_position; /* character index of the insertion and deletion */
|
---|
101 | LPSTR undo_text; /* deleted text */
|
---|
102 | INT undo_buffer_size; /* size of the deleted text buffer */
|
---|
103 | INT selection_start; /* == selection_end if no selection */
|
---|
104 | INT selection_end; /* == current caret position */
|
---|
105 | CHAR password_char; /* == 0 if no password char, and for multi line controls */
|
---|
106 | INT left_margin; /* in pixels */
|
---|
107 | INT right_margin; /* in pixels */
|
---|
108 | RECT format_rect;
|
---|
109 | INT region_posx; /* Position of cursor relative to region: */
|
---|
110 | INT region_posy; /* -1: to left, 0: within, 1: to right */
|
---|
111 | EDITWORDBREAKPROCA word_break_procA;
|
---|
112 | INT line_count; /* number of lines */
|
---|
113 | INT y_offset; /* scroll offset in number of lines */
|
---|
114 | BOOL bCaptureState; /* flag indicating whether mouse was captured */
|
---|
115 | BOOL bEnableState; /* flag keeping the enable state */
|
---|
116 | HWND hwndListBox; /* handle of ComboBox's listbox or NULL */
|
---|
117 | /*
|
---|
118 | * only for multi line controls
|
---|
119 | */
|
---|
120 | INT lock_count; /* amount of re-entries in the EditWndProc */
|
---|
121 | INT tabs_count;
|
---|
122 | LPINT tabs;
|
---|
123 | INT text_width; /* width of the widest line in pixels */
|
---|
124 | LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
|
---|
125 | HLOCAL hloc; /* for controls receiving EM_GETHANDLE */
|
---|
126 | } EDITSTATE;
|
---|
127 |
|
---|
128 |
|
---|
129 | #define SWAP_INT32(x,y) do { INT temp = (INT)(x); (x) = (INT)(y); (y) = temp; } while(0)
|
---|
130 | #define ORDER_INT(x,y) do { if ((INT)(y) < (INT)(x)) SWAP_INT32((x),(y)); } while(0)
|
---|
131 |
|
---|
132 | #define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
|
---|
133 | #define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
|
---|
134 |
|
---|
135 | /* used for disabled or read-only edit control */
|
---|
136 | #define EDIT_SEND_CTLCOLORSTATIC(hwnd,hdc) \
|
---|
137 | (SendMessageA(GetParent(hwnd), WM_CTLCOLORSTATIC, \
|
---|
138 | (WPARAM)(hdc), (LPARAM)hwnd))
|
---|
139 | #define EDIT_SEND_CTLCOLOR(hwnd,hdc) \
|
---|
140 | (SendMessageA(GetParent(hwnd), WM_CTLCOLOREDIT, \
|
---|
141 | (WPARAM)(hdc), (LPARAM)hwnd))
|
---|
142 | #define EDIT_NOTIFY_PARENT(hwnd, wNotifyCode) \
|
---|
143 | (SendMessageA(GetParent(hwnd), WM_COMMAND, \
|
---|
144 | MAKEWPARAM(GetWindowLongA(hwnd,GWL_ID), wNotifyCode), (LPARAM)hwnd))
|
---|
145 |
|
---|
146 | /*********************************************************************
|
---|
147 | *
|
---|
148 | * Declarations
|
---|
149 | *
|
---|
150 | */
|
---|
151 |
|
---|
152 | /*
|
---|
153 | * These functions have trivial implementations
|
---|
154 | * We still like to call them internally
|
---|
155 | * "static inline" makes them more like macro's
|
---|
156 | */
|
---|
157 | static inline BOOL EDIT_EM_CanUndo(HWND hwnd, EDITSTATE *es);
|
---|
158 | static inline void EDIT_EM_EmptyUndoBuffer(HWND hwnd, EDITSTATE *es);
|
---|
159 | static inline void EDIT_WM_Clear(HWND hwnd, EDITSTATE *es);
|
---|
160 | static inline void EDIT_WM_Cut(HWND hwnd, EDITSTATE *es);
|
---|
161 |
|
---|
162 | /*
|
---|
163 | * Helper functions only valid for one type of control
|
---|
164 | */
|
---|
165 | static void EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es);
|
---|
166 | static LPSTR EDIT_GetPasswordPointer_SL(HWND hwnd, EDITSTATE *es);
|
---|
167 | static void EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
168 | static void EDIT_MovePageDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
169 | static void EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
170 | static void EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
171 | static VOID EDIT_UpdateScrollBars(HWND hwnd,EDITSTATE *es,BOOL updateHorz,BOOL updateVert);
|
---|
172 | /*
|
---|
173 | * Helper functions valid for both single line _and_ multi line controls
|
---|
174 | */
|
---|
175 | static INT EDIT_CallWordBreakProc(HWND hwnd, EDITSTATE *es, INT start, INT index, INT count, INT action);
|
---|
176 | static INT EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
|
---|
177 | static void EDIT_ConfinePoint(HWND hwnd, EDITSTATE *es, LPINT x, LPINT y);
|
---|
178 | static void EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
|
---|
179 | static void EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end);
|
---|
180 | static void EDIT_LockBuffer(HWND hwnd, EDITSTATE *es);
|
---|
181 | static BOOL EDIT_MakeFit(HWND hwnd, EDITSTATE *es, INT size);
|
---|
182 | static BOOL EDIT_MakeUndoFit(HWND hwnd, EDITSTATE *es, INT size);
|
---|
183 | static void EDIT_MoveBackward(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
184 | static void EDIT_MoveEnd(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
185 | static void EDIT_MoveForward(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
186 | static void EDIT_MoveHome(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
187 | static void EDIT_MoveWordBackward(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
188 | static void EDIT_MoveWordForward(HWND hwnd, EDITSTATE *es, BOOL extend);
|
---|
189 | static void EDIT_PaintLine(HWND hwnd, EDITSTATE *es, HDC hdc, INT line, BOOL rev);
|
---|
190 | static VOID EDIT_PaintText(HWND hwnd, EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev);
|
---|
191 | static void EDIT_SetCaretPos(HWND hwnd, EDITSTATE *es, INT pos, BOOL after_wrap);
|
---|
192 | static void EDIT_SetRectNP(HWND hwnd, EDITSTATE *es, LPRECT lprc);
|
---|
193 | static void EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force);
|
---|
194 | static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action);
|
---|
195 | static VOID EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc);
|
---|
196 | static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache);
|
---|
197 |
|
---|
198 | /*
|
---|
199 | * EM_XXX message handlers
|
---|
200 | */
|
---|
201 | static LRESULT EDIT_EM_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y);
|
---|
202 | static BOOL EDIT_EM_FmtLines(HWND hwnd, EDITSTATE *es, BOOL add_eol);
|
---|
203 | static INT EDIT_EM_GetFirstVisibleLine(HWND hwnd,EDITSTATE *es);
|
---|
204 | static HLOCAL EDIT_EM_GetHandle(HWND hwnd, EDITSTATE *es);
|
---|
205 | static INT EDIT_EM_GetLimitText(HWND hwnd,EDITSTATE *es);
|
---|
206 | static INT EDIT_EM_GetLine(HWND hwnd, EDITSTATE *es, INT line, LPSTR lpch);
|
---|
207 | static INT EDIT_EM_GetLineCount(HWND hwnd,EDITSTATE *es);
|
---|
208 | static LONG EDIT_EM_GetMargins(HWND hwnd,EDITSTATE *es);
|
---|
209 | static BOOL EDIT_EM_GetModify(HWND hwnd,EDITSTATE *es);
|
---|
210 | static CHAR EDIT_EM_GetPasswordChar(HWND hwnd,EDITSTATE *es);
|
---|
211 | static VOID EDIT_EM_GetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc);
|
---|
212 | static LRESULT EDIT_EM_GetSel(HWND hwnd, EDITSTATE *es, LPUINT start, LPUINT end);
|
---|
213 | static LRESULT EDIT_EM_GetThumb(HWND hwnd, EDITSTATE *es);
|
---|
214 | static PVOID EDIT_EM_GetWordbreakProc(HWND hwnd,EDITSTATE *es);
|
---|
215 | static INT EDIT_EM_LineFromChar(HWND hwnd, EDITSTATE *es, INT index);
|
---|
216 | static INT EDIT_EM_LineIndex(HWND hwnd, EDITSTATE *es, INT line);
|
---|
217 | static INT EDIT_EM_LineLength(HWND hwnd, EDITSTATE *es, INT index);
|
---|
218 | static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy);
|
---|
219 | static LRESULT EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap);
|
---|
220 | static void EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace);
|
---|
221 | static LRESULT EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action);
|
---|
222 | static void EDIT_EM_ScrollCaret(HWND hwnd, EDITSTATE *es);
|
---|
223 | static void EDIT_EM_SetHandle(HWND hwnd, EDITSTATE *es, HLOCAL hloc);
|
---|
224 | static void EDIT_EM_SetLimitText(HWND hwnd, EDITSTATE *es, INT limit);
|
---|
225 | static void EDIT_EM_SetMargins(HWND hwnd, EDITSTATE *es, INT action, INT left, INT right);
|
---|
226 | static void EDIT_EM_SetModify(HWND hwnd,EDITSTATE *es,BOOL fModified);
|
---|
227 | static void EDIT_EM_SetPasswordChar(HWND hwnd, EDITSTATE *es, CHAR c);
|
---|
228 | static BOOL EDIT_EM_SetReadOnly(HWND hwnd,EDITSTATE *es,BOOL fReadOnly);
|
---|
229 | static void EDIT_EM_SetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc);
|
---|
230 | static void EDIT_EM_SetRectNP(HWND hwnd,EDITSTATE *es,LPRECT lprc);
|
---|
231 | static void EDIT_EM_SetSel(HWND hwnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap);
|
---|
232 | static BOOL EDIT_EM_SetTabStops(HWND hwnd, EDITSTATE *es, INT count, LPINT tabs);
|
---|
233 | static void EDIT_EM_SetWordBreakProc(HWND hwnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp);
|
---|
234 | static BOOL EDIT_EM_Undo(HWND hwnd, EDITSTATE *es);
|
---|
235 | static LRESULT EDIT_EM_SetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam);
|
---|
236 | static LRESULT EDIT_EM_GetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam);
|
---|
237 | /*
|
---|
238 | * WM_XXX message handlers
|
---|
239 | */
|
---|
240 | static void EDIT_WM_Char(HWND hwnd, EDITSTATE *es, CHAR c, DWORD key_data);
|
---|
241 | static void EDIT_WM_Command(HWND hwnd, EDITSTATE *es, INT code, INT id, HWND conrtol);
|
---|
242 | static void EDIT_WM_ContextMenu(HWND hwnd, EDITSTATE *es, HWND hwndBtn, INT x, INT y);
|
---|
243 | static void EDIT_WM_Copy(HWND hwnd, EDITSTATE *es);
|
---|
244 | static LRESULT EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCREATESTRUCTA cs);
|
---|
245 | static void EDIT_WM_Destroy(HWND hwnd, EDITSTATE *es);
|
---|
246 | static LRESULT EDIT_WM_EraseBkGnd(HWND hwnd, EDITSTATE *es, HDC dc);
|
---|
247 | static INT EDIT_WM_GetText(HWND hwnd, EDITSTATE *es, INT count, LPSTR text);
|
---|
248 | static LRESULT EDIT_WM_HScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar);
|
---|
249 | static LRESULT EDIT_WM_KeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data);
|
---|
250 | static LRESULT EDIT_WM_KillFocus(HWND hwnd, EDITSTATE *es, HWND window_getting_focus);
|
---|
251 | static LRESULT EDIT_WM_LButtonDblClk(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y);
|
---|
252 | static LRESULT EDIT_WM_LButtonDown(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y);
|
---|
253 | static LRESULT EDIT_WM_LButtonUp(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y);
|
---|
254 | static LRESULT EDIT_WM_CaptureChanged(HWND hwnd,EDITSTATE *es);
|
---|
255 | static LRESULT EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y);
|
---|
256 | static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTA cs);
|
---|
257 | static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam);
|
---|
258 | static void EDIT_WM_Paste(HWND hwnd, EDITSTATE *es);
|
---|
259 | static void EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es, HWND window_losing_focus);
|
---|
260 | static void EDIT_WM_SetFont(HWND hwnd, EDITSTATE *es, HFONT font, BOOL redraw);
|
---|
261 | static void EDIT_WM_SetText(HWND hwnd, EDITSTATE *es, LPCSTR text);
|
---|
262 | static void EDIT_WM_Size(HWND hwnd, EDITSTATE *es, UINT action, INT width, INT height);
|
---|
263 | static LRESULT EDIT_WM_SysKeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data);
|
---|
264 | static void EDIT_WM_Timer(HWND hwnd, EDITSTATE *es, INT id, TIMERPROC timer_proc);
|
---|
265 | static LRESULT EDIT_WM_VScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar);
|
---|
266 | static LRESULT EDIT_WM_MouseWheel(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam);
|
---|
267 |
|
---|
268 | /*********************************************************************
|
---|
269 | *
|
---|
270 | * EM_CANUNDO
|
---|
271 | *
|
---|
272 | */
|
---|
273 | static inline BOOL EDIT_EM_CanUndo(HWND hwnd, EDITSTATE *es)
|
---|
274 | {
|
---|
275 | return (es->undo_insert_count || lstrlenA(es->undo_text));
|
---|
276 | }
|
---|
277 |
|
---|
278 |
|
---|
279 | /*********************************************************************
|
---|
280 | *
|
---|
281 | * EM_EMPTYUNDOBUFFER
|
---|
282 | *
|
---|
283 | */
|
---|
284 | static inline void EDIT_EM_EmptyUndoBuffer(HWND hwnd, EDITSTATE *es)
|
---|
285 | {
|
---|
286 | es->undo_insert_count = 0;
|
---|
287 | *es->undo_text = '\0';
|
---|
288 | }
|
---|
289 |
|
---|
290 |
|
---|
291 | /*********************************************************************
|
---|
292 | *
|
---|
293 | * WM_CLEAR
|
---|
294 | *
|
---|
295 | */
|
---|
296 | static inline void EDIT_WM_Clear(HWND hwnd, EDITSTATE *es)
|
---|
297 | {
|
---|
298 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, "");
|
---|
299 | if (es->flags & EF_UPDATE) {
|
---|
300 | es->flags &= ~EF_UPDATE;
|
---|
301 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
302 | }
|
---|
303 | }
|
---|
304 |
|
---|
305 |
|
---|
306 | /*********************************************************************
|
---|
307 | *
|
---|
308 | * WM_CUT
|
---|
309 | *
|
---|
310 | */
|
---|
311 | static inline void EDIT_WM_Cut(HWND hwnd, EDITSTATE *es)
|
---|
312 | {
|
---|
313 | EDIT_WM_Copy(hwnd, es);
|
---|
314 | EDIT_WM_Clear(hwnd, es);
|
---|
315 | }
|
---|
316 |
|
---|
317 |
|
---|
318 | /*********************************************************************
|
---|
319 | *
|
---|
320 | * EditWndProc()
|
---|
321 | *
|
---|
322 | * The messages are in the order of the actual integer values
|
---|
323 | * (which can be found in include/windows.h)
|
---|
324 | * Whereever possible the 16 bit versions are converted to
|
---|
325 | * the 32 bit ones, so that we can 'fall through' to the
|
---|
326 | * helper functions. These are mostly 32 bit (with a few
|
---|
327 | * exceptions, clearly indicated by a '16' extension to their
|
---|
328 | * names).
|
---|
329 | *
|
---|
330 | */
|
---|
331 | LRESULT WINAPI EditWndProc( HWND hwnd, UINT msg,
|
---|
332 | WPARAM wParam, LPARAM lParam )
|
---|
333 | {
|
---|
334 | EDITSTATE *es = (EDITSTATE*)GetInfoPtr(hwnd);
|
---|
335 | LRESULT result = 0;
|
---|
336 |
|
---|
337 | // dprintf(("EditWndProc hwnd: %04x, msg %s, wp %08x lp %08lx\n",
|
---|
338 | // hwnd, GetMsgText(msg), wParam, lParam));
|
---|
339 |
|
---|
340 | switch (msg) {
|
---|
341 | case WM_DESTROY:
|
---|
342 | //DPRINTF_EDIT_MSG32("WM_DESTROY");
|
---|
343 | EDIT_WM_Destroy(hwnd, es);
|
---|
344 | result = 0;
|
---|
345 | goto END;
|
---|
346 |
|
---|
347 | case WM_NCCREATE:
|
---|
348 | //DPRINTF_EDIT_MSG32("WM_NCCREATE");
|
---|
349 | result = EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTA)lParam);
|
---|
350 | goto END;
|
---|
351 | }
|
---|
352 |
|
---|
353 | if (!es)
|
---|
354 | {
|
---|
355 | result = DefWindowProcA(hwnd, msg, wParam, lParam);
|
---|
356 | goto END;
|
---|
357 | }
|
---|
358 |
|
---|
359 |
|
---|
360 | EDIT_LockBuffer(hwnd, es);
|
---|
361 | switch (msg) {
|
---|
362 | case EM_GETSEL:
|
---|
363 | //DPRINTF_EDIT_MSG32("EM_GETSEL");
|
---|
364 | result = EDIT_EM_GetSel(hwnd, es, (LPUINT)wParam, (LPUINT)lParam);
|
---|
365 | break;
|
---|
366 |
|
---|
367 | case EM_SETSEL:
|
---|
368 | //DPRINTF_EDIT_MSG32("EM_SETSEL");
|
---|
369 | EDIT_EM_SetSel(hwnd, es, wParam, lParam, FALSE);
|
---|
370 | EDIT_EM_ScrollCaret(hwnd,es);
|
---|
371 | result = 1;
|
---|
372 | break;
|
---|
373 |
|
---|
374 | case EM_GETRECT:
|
---|
375 | //DPRINTF_EDIT_MSG32("EM_GETRECT");
|
---|
376 | EDIT_EM_GetRect(hwnd,es,(LPRECT)lParam);
|
---|
377 | break;
|
---|
378 |
|
---|
379 | case EM_SETRECT:
|
---|
380 | //DPRINTF_EDIT_MSG32("EM_SETRECT");
|
---|
381 | EDIT_EM_SetRect(hwnd,es,(LPRECT)lParam);
|
---|
382 | break;
|
---|
383 |
|
---|
384 | case EM_SETRECTNP:
|
---|
385 | //DPRINTF_EDIT_MSG32("EM_SETRECTNP");
|
---|
386 | EDIT_EM_SetRectNP(hwnd,es,(LPRECT)lParam);
|
---|
387 | break;
|
---|
388 |
|
---|
389 | case EM_SCROLL:
|
---|
390 | //DPRINTF_EDIT_MSG32("EM_SCROLL");
|
---|
391 | result = EDIT_EM_Scroll(hwnd, es, (INT)wParam);
|
---|
392 | break;
|
---|
393 |
|
---|
394 | case EM_LINESCROLL:
|
---|
395 | //DPRINTF_EDIT_MSG32("EM_LINESCROLL");
|
---|
396 | result = (LRESULT)EDIT_EM_LineScroll(hwnd, es, (INT)wParam, (INT)lParam);
|
---|
397 | break;
|
---|
398 |
|
---|
399 | case EM_SCROLLCARET:
|
---|
400 | //DPRINTF_EDIT_MSG32("EM_SCROLLCARET");
|
---|
401 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
402 | result = 1;
|
---|
403 | break;
|
---|
404 |
|
---|
405 | case EM_GETMODIFY:
|
---|
406 | //DPRINTF_EDIT_MSG32("EM_GETMODIFY");
|
---|
407 | result = (LRESULT)EDIT_EM_GetModify(hwnd,es);
|
---|
408 | break;
|
---|
409 |
|
---|
410 | case EM_SETMODIFY:
|
---|
411 | //DPRINTF_EDIT_MSG32("EM_SETMODIFY");
|
---|
412 | EDIT_EM_SetModify(hwnd,es,(BOOL)wParam);
|
---|
413 | break;
|
---|
414 |
|
---|
415 | case EM_GETLINECOUNT:
|
---|
416 | //DPRINTF_EDIT_MSG32("EM_GETLINECOUNT");
|
---|
417 | result = (LRESULT)EDIT_EM_GetLineCount(hwnd,es);
|
---|
418 | break;
|
---|
419 |
|
---|
420 | case EM_LINEINDEX:
|
---|
421 | //DPRINTF_EDIT_MSG32("EM_LINEINDEX");
|
---|
422 | result = (LRESULT)EDIT_EM_LineIndex(hwnd, es, (INT)wParam);
|
---|
423 | break;
|
---|
424 |
|
---|
425 | case EM_SETHANDLE:
|
---|
426 | //DPRINTF_EDIT_MSG32("EM_SETHANDLE");
|
---|
427 | EDIT_EM_SetHandle(hwnd, es, (HLOCAL)wParam);
|
---|
428 | break;
|
---|
429 |
|
---|
430 | case EM_GETHANDLE:
|
---|
431 | //DPRINTF_EDIT_MSG32("EM_GETHANDLE");
|
---|
432 | result = (LRESULT)EDIT_EM_GetHandle(hwnd, es);
|
---|
433 | break;
|
---|
434 |
|
---|
435 | case EM_GETTHUMB:
|
---|
436 | //DPRINTF_EDIT_MSG32("EM_GETTHUMB");
|
---|
437 | result = EDIT_EM_GetThumb(hwnd, es);
|
---|
438 | break;
|
---|
439 |
|
---|
440 | /* messages 0x00bf and 0x00c0 missing from specs */
|
---|
441 |
|
---|
442 | case WM_USER+15:
|
---|
443 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report");
|
---|
444 | /* fall through */
|
---|
445 | case 0x00bf:
|
---|
446 | //DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report");
|
---|
447 | result = DefWindowProcA(hwnd, msg, wParam, lParam);
|
---|
448 | break;
|
---|
449 |
|
---|
450 | case WM_USER+16:
|
---|
451 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report");
|
---|
452 | /* fall through */
|
---|
453 | case 0x00c0:
|
---|
454 | //DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report");
|
---|
455 | result = DefWindowProcA(hwnd, msg, wParam, lParam);
|
---|
456 | break;
|
---|
457 |
|
---|
458 | case EM_LINELENGTH:
|
---|
459 | //DPRINTF_EDIT_MSG32("EM_LINELENGTH");
|
---|
460 | result = (LRESULT)EDIT_EM_LineLength(hwnd, es, (INT)wParam);
|
---|
461 | break;
|
---|
462 |
|
---|
463 | case EM_REPLACESEL:
|
---|
464 | //DPRINTF_EDIT_MSG32("EM_REPLACESEL");
|
---|
465 | EDIT_EM_ReplaceSel(hwnd, es, (BOOL)wParam, (LPCSTR)lParam);
|
---|
466 | result = 1;
|
---|
467 | break;
|
---|
468 |
|
---|
469 | /* message 0x00c3 missing from specs */
|
---|
470 |
|
---|
471 | case WM_USER+19:
|
---|
472 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report");
|
---|
473 | /* fall through */
|
---|
474 | case 0x00c3:
|
---|
475 | //DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report");
|
---|
476 | result = DefWindowProcA(hwnd, msg, wParam, lParam);
|
---|
477 | break;
|
---|
478 |
|
---|
479 | case EM_GETLINE:
|
---|
480 | //DPRINTF_EDIT_MSG32("EM_GETLINE");
|
---|
481 | result = (LRESULT)EDIT_EM_GetLine(hwnd, es, (INT)wParam, (LPSTR)lParam);
|
---|
482 | break;
|
---|
483 |
|
---|
484 | case EM_SETLIMITTEXT:
|
---|
485 | //DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT");
|
---|
486 | EDIT_EM_SetLimitText(hwnd, es, (INT)wParam);
|
---|
487 | break;
|
---|
488 |
|
---|
489 | case EM_CANUNDO:
|
---|
490 | //DPRINTF_EDIT_MSG32("EM_CANUNDO");
|
---|
491 | result = (LRESULT)EDIT_EM_CanUndo(hwnd, es);
|
---|
492 | break;
|
---|
493 |
|
---|
494 | case EM_UNDO:
|
---|
495 | /* fall through */
|
---|
496 | case WM_UNDO:
|
---|
497 | //DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO");
|
---|
498 | result = (LRESULT)EDIT_EM_Undo(hwnd, es);
|
---|
499 | break;
|
---|
500 |
|
---|
501 | case EM_FMTLINES:
|
---|
502 | //DPRINTF_EDIT_MSG32("EM_FMTLINES");
|
---|
503 | result = (LRESULT)EDIT_EM_FmtLines(hwnd, es, (BOOL)wParam);
|
---|
504 | break;
|
---|
505 |
|
---|
506 | case EM_LINEFROMCHAR:
|
---|
507 | //DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR");
|
---|
508 | result = (LRESULT)EDIT_EM_LineFromChar(hwnd, es, (INT)wParam);
|
---|
509 | break;
|
---|
510 |
|
---|
511 | /* message 0x00ca missing from specs */
|
---|
512 |
|
---|
513 | case WM_USER+26:
|
---|
514 | //DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report");
|
---|
515 | /* fall through */
|
---|
516 | case 0x00ca:
|
---|
517 | //DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report");
|
---|
518 | result = DefWindowProcA(hwnd, msg, wParam, lParam);
|
---|
519 | break;
|
---|
520 |
|
---|
521 | case EM_SETTABSTOPS:
|
---|
522 | //DPRINTF_EDIT_MSG32("EM_SETTABSTOPS");
|
---|
523 | result = (LRESULT)EDIT_EM_SetTabStops(hwnd, es, (INT)wParam, (LPINT)lParam);
|
---|
524 | break;
|
---|
525 |
|
---|
526 | case EM_SETPASSWORDCHAR:
|
---|
527 | //DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR");
|
---|
528 | EDIT_EM_SetPasswordChar(hwnd, es, (CHAR)wParam);
|
---|
529 | break;
|
---|
530 |
|
---|
531 | case EM_EMPTYUNDOBUFFER:
|
---|
532 | //DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER");
|
---|
533 | EDIT_EM_EmptyUndoBuffer(hwnd, es);
|
---|
534 | break;
|
---|
535 |
|
---|
536 | case EM_GETFIRSTVISIBLELINE:
|
---|
537 | //DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE");
|
---|
538 | result = (LRESULT)EDIT_EM_GetFirstVisibleLine(hwnd,es);
|
---|
539 | break;
|
---|
540 |
|
---|
541 | case EM_SETREADONLY:
|
---|
542 | //DPRINTF_EDIT_MSG32("EM_SETREADONLY");
|
---|
543 | result = (LRESULT)EDIT_EM_SetReadOnly(hwnd,es,(BOOL)wParam);
|
---|
544 | break;
|
---|
545 |
|
---|
546 | case EM_SETWORDBREAKPROC:
|
---|
547 | //DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC");
|
---|
548 | EDIT_EM_SetWordBreakProc(hwnd, es, (EDITWORDBREAKPROCA)lParam);
|
---|
549 | break;
|
---|
550 |
|
---|
551 | case EM_GETWORDBREAKPROC:
|
---|
552 | //DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC");
|
---|
553 | result = (LRESULT)EDIT_EM_GetWordbreakProc(hwnd,es);
|
---|
554 | break;
|
---|
555 |
|
---|
556 | case EM_GETPASSWORDCHAR:
|
---|
557 | //DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR");
|
---|
558 | result = (LRESULT)EDIT_EM_GetPasswordChar(hwnd,es);
|
---|
559 | break;
|
---|
560 |
|
---|
561 | /* The following EM_xxx are new to win95 and don't exist for 16 bit */
|
---|
562 |
|
---|
563 | case EM_SETMARGINS:
|
---|
564 | //DPRINTF_EDIT_MSG32("EM_SETMARGINS");
|
---|
565 | EDIT_EM_SetMargins(hwnd, es, (INT)wParam, SLOWORD(lParam), SHIWORD(lParam));
|
---|
566 | break;
|
---|
567 |
|
---|
568 | case EM_GETMARGINS:
|
---|
569 | //DPRINTF_EDIT_MSG32("EM_GETMARGINS");
|
---|
570 | result = EDIT_EM_GetMargins(hwnd,es);
|
---|
571 | break;
|
---|
572 |
|
---|
573 | case EM_GETLIMITTEXT:
|
---|
574 | //DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT");
|
---|
575 | result = (LRESULT)EDIT_EM_GetLimitText(hwnd,es);
|
---|
576 | break;
|
---|
577 |
|
---|
578 | case EM_POSFROMCHAR:
|
---|
579 | //DPRINTF_EDIT_MSG32("EM_POSFROMCHAR");
|
---|
580 | result = EDIT_EM_PosFromChar(hwnd,0, es, (INT)wParam, FALSE);
|
---|
581 | break;
|
---|
582 |
|
---|
583 | case EM_CHARFROMPOS:
|
---|
584 | //DPRINTF_EDIT_MSG32("EM_CHARFROMPOS");
|
---|
585 | result = EDIT_EM_CharFromPos(hwnd, es, SLOWORD(lParam), SHIWORD(lParam));
|
---|
586 | break;
|
---|
587 |
|
---|
588 | case EM_SETIMESTATUS:
|
---|
589 | result = EDIT_EM_SetIMEStatus(hwnd,es,wParam,lParam);
|
---|
590 | break;
|
---|
591 |
|
---|
592 | case EM_GETIMESTATUS:
|
---|
593 | result = EDIT_EM_GetIMEStatus(hwnd,es,wParam,lParam);
|
---|
594 | break;
|
---|
595 |
|
---|
596 | case WM_GETDLGCODE:
|
---|
597 | //DPRINTF_EDIT_MSG32("WM_GETDLGCODE");
|
---|
598 | result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
|
---|
599 |
|
---|
600 | if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
|
---|
601 | {
|
---|
602 | int vk = (int)((LPMSG)lParam)->wParam;
|
---|
603 |
|
---|
604 | if ((GetWindowLongA(hwnd,GWL_STYLE) & ES_WANTRETURN) && vk == VK_RETURN)
|
---|
605 | {
|
---|
606 | result |= DLGC_WANTMESSAGE;
|
---|
607 | }
|
---|
608 | else if (es->hwndListBox && (vk == VK_RETURN || vk == VK_ESCAPE))
|
---|
609 | {
|
---|
610 | if (SendMessageA(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
|
---|
611 | result |= DLGC_WANTMESSAGE;
|
---|
612 | }
|
---|
613 | }
|
---|
614 | break;
|
---|
615 |
|
---|
616 | case WM_CHAR:
|
---|
617 | //DPRINTF_EDIT_MSG32("WM_CHAR");
|
---|
618 | if (((CHAR)wParam == VK_RETURN || (CHAR)wParam == VK_ESCAPE) && es->hwndListBox)
|
---|
619 | {
|
---|
620 | HWND hwndParent = GetParent(hwnd);
|
---|
621 |
|
---|
622 | if (SendMessageA(hwndParent, CB_GETDROPPEDSTATE, 0, 0))
|
---|
623 | SendMessageA(hwndParent, WM_KEYDOWN, wParam, 0);
|
---|
624 | break;
|
---|
625 | }
|
---|
626 | EDIT_WM_Char(hwnd, es, (CHAR)wParam, (DWORD)lParam);
|
---|
627 | break;
|
---|
628 |
|
---|
629 | case WM_CLEAR:
|
---|
630 | //DPRINTF_EDIT_MSG32("WM_CLEAR");
|
---|
631 | EDIT_WM_Clear(hwnd, es);
|
---|
632 | break;
|
---|
633 |
|
---|
634 | case WM_COMMAND:
|
---|
635 | //DPRINTF_EDIT_MSG32("WM_COMMAND");
|
---|
636 | EDIT_WM_Command(hwnd, es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
|
---|
637 | break;
|
---|
638 |
|
---|
639 | case WM_CONTEXTMENU:
|
---|
640 | //DPRINTF_EDIT_MSG32("WM_CONTEXTMENU");
|
---|
641 | EDIT_WM_ContextMenu(hwnd, es, (HWND)wParam, SLOWORD(lParam), SHIWORD(lParam));
|
---|
642 | break;
|
---|
643 |
|
---|
644 | case WM_COPY:
|
---|
645 | //DPRINTF_EDIT_MSG32("WM_COPY");
|
---|
646 | EDIT_WM_Copy(hwnd, es);
|
---|
647 | break;
|
---|
648 |
|
---|
649 | case WM_CREATE:
|
---|
650 | //DPRINTF_EDIT_MSG32("WM_CREATE");
|
---|
651 | result = EDIT_WM_Create(hwnd, es, (LPCREATESTRUCTA)lParam);
|
---|
652 | break;
|
---|
653 |
|
---|
654 | case WM_CUT:
|
---|
655 | //DPRINTF_EDIT_MSG32("WM_CUT");
|
---|
656 | EDIT_WM_Cut(hwnd, es);
|
---|
657 | break;
|
---|
658 |
|
---|
659 | case WM_ENABLE:
|
---|
660 | //DPRINTF_EDIT_MSG32("WM_ENABLE");
|
---|
661 | es->bEnableState = (BOOL)wParam;
|
---|
662 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
663 | break;
|
---|
664 |
|
---|
665 | case WM_ERASEBKGND:
|
---|
666 | //DPRINTF_EDIT_MSG32("WM_ERASEBKGND");
|
---|
667 | result = EDIT_WM_EraseBkGnd(hwnd, es, (HDC)wParam);
|
---|
668 | break;
|
---|
669 |
|
---|
670 | case WM_GETFONT:
|
---|
671 | //DPRINTF_EDIT_MSG32("WM_GETFONT");
|
---|
672 | result = (LRESULT)es->font;
|
---|
673 | break;
|
---|
674 |
|
---|
675 | case WM_GETTEXT:
|
---|
676 | //DPRINTF_EDIT_MSG32("WM_GETTEXT");
|
---|
677 | result = (LRESULT)EDIT_WM_GetText(hwnd, es, (INT)wParam, (LPSTR)lParam);
|
---|
678 | break;
|
---|
679 |
|
---|
680 | case WM_GETTEXTLENGTH:
|
---|
681 | //DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH");
|
---|
682 | result = lstrlenA(es->text);
|
---|
683 | break;
|
---|
684 |
|
---|
685 | case WM_HSCROLL:
|
---|
686 | //DPRINTF_EDIT_MSG32("WM_HSCROLL");
|
---|
687 | result = EDIT_WM_HScroll(hwnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)lParam);
|
---|
688 | break;
|
---|
689 |
|
---|
690 | case WM_KEYDOWN:
|
---|
691 | //DPRINTF_EDIT_MSG32("WM_KEYDOWN");
|
---|
692 | result = EDIT_WM_KeyDown(hwnd, es, (INT)wParam, (DWORD)lParam);
|
---|
693 | break;
|
---|
694 |
|
---|
695 | case WM_KILLFOCUS:
|
---|
696 | //DPRINTF_EDIT_MSG32("WM_KILLFOCUS");
|
---|
697 | result = EDIT_WM_KillFocus(hwnd, es, (HWND)wParam);
|
---|
698 | break;
|
---|
699 |
|
---|
700 | case WM_LBUTTONDBLCLK:
|
---|
701 | //DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK");
|
---|
702 | result = EDIT_WM_LButtonDblClk(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
|
---|
703 | break;
|
---|
704 |
|
---|
705 | case WM_LBUTTONDOWN:
|
---|
706 | //DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN");
|
---|
707 | result = EDIT_WM_LButtonDown(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
|
---|
708 | break;
|
---|
709 |
|
---|
710 | case WM_LBUTTONUP:
|
---|
711 | //DPRINTF_EDIT_MSG32("WM_LBUTTONUP");
|
---|
712 | result = EDIT_WM_LButtonUp(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
|
---|
713 | break;
|
---|
714 |
|
---|
715 | case WM_CAPTURECHANGED:
|
---|
716 | result = EDIT_WM_CaptureChanged(hwnd,es);
|
---|
717 | break;
|
---|
718 |
|
---|
719 | case WM_MOUSEACTIVATE:
|
---|
720 | /*
|
---|
721 | * FIXME: maybe DefWindowProc() screws up, but it seems that
|
---|
722 | * modalless dialog boxes need this. If we don't do this, the focus
|
---|
723 | * will _not_ be set by DefWindowProc() for edit controls in a
|
---|
724 | * modalless dialog box ???
|
---|
725 | */
|
---|
726 | //DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE");
|
---|
727 | result = MA_ACTIVATE;
|
---|
728 | break;
|
---|
729 |
|
---|
730 | case WM_MOUSEMOVE:
|
---|
731 | /*
|
---|
732 | * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE");
|
---|
733 | */
|
---|
734 | result = EDIT_WM_MouseMove(hwnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam));
|
---|
735 | break;
|
---|
736 |
|
---|
737 | case WM_PAINT:
|
---|
738 | //DPRINTF_EDIT_MSG32("WM_PAINT");
|
---|
739 | EDIT_WM_Paint(hwnd, es,wParam);
|
---|
740 | break;
|
---|
741 |
|
---|
742 | case WM_PASTE:
|
---|
743 | //DPRINTF_EDIT_MSG32("WM_PASTE");
|
---|
744 | EDIT_WM_Paste(hwnd, es);
|
---|
745 | break;
|
---|
746 |
|
---|
747 | case WM_SETFOCUS:
|
---|
748 | //DPRINTF_EDIT_MSG32("WM_SETFOCUS");
|
---|
749 | EDIT_WM_SetFocus(hwnd, es, (HWND)wParam);
|
---|
750 | break;
|
---|
751 |
|
---|
752 | case WM_SETFONT:
|
---|
753 | //DPRINTF_EDIT_MSG32("WM_SETFONT");
|
---|
754 | EDIT_WM_SetFont(hwnd, es, (HFONT)wParam, LOWORD(lParam) != 0);
|
---|
755 | break;
|
---|
756 |
|
---|
757 | case WM_SETTEXT:
|
---|
758 | //DPRINTF_EDIT_MSG32("WM_SETTEXT");
|
---|
759 | EDIT_WM_SetText(hwnd, es, (LPCSTR)lParam);
|
---|
760 | result = TRUE;
|
---|
761 | break;
|
---|
762 |
|
---|
763 | case WM_SIZE:
|
---|
764 | //DPRINTF_EDIT_MSG32("WM_SIZE");
|
---|
765 | EDIT_WM_Size(hwnd, es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam));
|
---|
766 | break;
|
---|
767 |
|
---|
768 | case WM_SYSKEYDOWN:
|
---|
769 | //DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN");
|
---|
770 | result = EDIT_WM_SysKeyDown(hwnd, es, (INT)wParam, (DWORD)lParam);
|
---|
771 | break;
|
---|
772 |
|
---|
773 | case WM_TIMER:
|
---|
774 | //DPRINTF_EDIT_MSG32("WM_TIMER");
|
---|
775 | EDIT_WM_Timer(hwnd, es, (INT)wParam, (TIMERPROC)lParam);
|
---|
776 | break;
|
---|
777 |
|
---|
778 | case WM_VSCROLL:
|
---|
779 | //DPRINTF_EDIT_MSG32("WM_VSCROLL");
|
---|
780 | result = EDIT_WM_VScroll(hwnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND)(lParam));
|
---|
781 | break;
|
---|
782 |
|
---|
783 | case WM_MOUSEWHEEL:
|
---|
784 | result = EDIT_WM_MouseWheel(hwnd,es,wParam,lParam);
|
---|
785 | break;
|
---|
786 |
|
---|
787 | default:
|
---|
788 | result = DefWindowProcA(hwnd, msg, wParam, lParam);
|
---|
789 | break;
|
---|
790 | }
|
---|
791 | EDIT_UnlockBuffer(hwnd, es, FALSE);
|
---|
792 | END:
|
---|
793 | return result;
|
---|
794 |
|
---|
795 | }
|
---|
796 |
|
---|
797 |
|
---|
798 | /*********************************************************************
|
---|
799 | *
|
---|
800 | * EDIT_BuildLineDefs_ML
|
---|
801 | *
|
---|
802 | * Build linked list of text lines.
|
---|
803 | * Lines can end with '\0' (last line), a character (if it is wrapped),
|
---|
804 | * a soft return '\r\r\n' or a hard return '\r\n'
|
---|
805 | *
|
---|
806 | */
|
---|
807 | static void EDIT_BuildLineDefs_ML(HWND hwnd,EDITSTATE *es)
|
---|
808 | {
|
---|
809 | HDC hdc = 0;
|
---|
810 | HFONT old_font = 0;
|
---|
811 | LPSTR start, cp;
|
---|
812 | INT fw;
|
---|
813 | LINEDEF *current_def;
|
---|
814 | LINEDEF **previous_next;
|
---|
815 |
|
---|
816 | current_def = es->first_line_def;
|
---|
817 | do {
|
---|
818 | LINEDEF *next_def = current_def->next;
|
---|
819 | HeapFree(es->heap, 0, current_def);
|
---|
820 | current_def = next_def;
|
---|
821 | } while (current_def);
|
---|
822 | es->line_count = 0;
|
---|
823 | es->text_width = 0;
|
---|
824 |
|
---|
825 | fw = es->format_rect.right - es->format_rect.left;
|
---|
826 | start = es->text;
|
---|
827 | previous_next = &es->first_line_def;
|
---|
828 | do {
|
---|
829 | current_def = (LINEDEF*)HeapAlloc(es->heap, 0, sizeof(LINEDEF));
|
---|
830 | current_def->next = NULL;
|
---|
831 | cp = start;
|
---|
832 | while (*cp) {
|
---|
833 | if ((*cp == '\r') && (*(cp + 1) == '\n'))
|
---|
834 | break;
|
---|
835 | cp++;
|
---|
836 | }
|
---|
837 | if (!(*cp)) {
|
---|
838 | current_def->ending = END_0;
|
---|
839 | current_def->net_length = lstrlenA(start);
|
---|
840 | } else if ((cp > start) && (*(cp - 1) == '\r')) {
|
---|
841 | current_def->ending = END_SOFT;
|
---|
842 | current_def->net_length = cp - start - 1;
|
---|
843 | } else {
|
---|
844 | current_def->ending = END_HARD;
|
---|
845 | current_def->net_length = cp - start;
|
---|
846 | }
|
---|
847 |
|
---|
848 | if (!hdc)
|
---|
849 | {
|
---|
850 | hdc = GetDC(hwnd);
|
---|
851 | if (es->font)
|
---|
852 | old_font = SelectObject(hdc, es->font);
|
---|
853 | }
|
---|
854 |
|
---|
855 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc,
|
---|
856 | start, current_def->net_length,
|
---|
857 | es->tabs_count, es->tabs));
|
---|
858 | /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
|
---|
859 | if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) {
|
---|
860 | INT next = 0;
|
---|
861 | INT prev;
|
---|
862 | do {
|
---|
863 | prev = next;
|
---|
864 | next = EDIT_CallWordBreakProc(hwnd, es, start - es->text,
|
---|
865 | prev + 1, current_def->net_length, WB_RIGHT);
|
---|
866 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc,
|
---|
867 | start, next, es->tabs_count, es->tabs));
|
---|
868 | } while (current_def->width <= fw);
|
---|
869 | if (!prev) {
|
---|
870 | next = 0;
|
---|
871 | do {
|
---|
872 | prev = next;
|
---|
873 | next++;
|
---|
874 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc,
|
---|
875 | start, next, es->tabs_count, es->tabs));
|
---|
876 | } while (current_def->width <= fw);
|
---|
877 | if (!prev)
|
---|
878 | prev = 1;
|
---|
879 | }
|
---|
880 | current_def->net_length = prev;
|
---|
881 | current_def->ending = END_WRAP;
|
---|
882 | current_def->width = (INT)LOWORD(GetTabbedTextExtentA(hdc, start,
|
---|
883 | current_def->net_length, es->tabs_count, es->tabs));
|
---|
884 | }
|
---|
885 | switch (current_def->ending) {
|
---|
886 | case END_SOFT:
|
---|
887 | current_def->length = current_def->net_length + 3;
|
---|
888 | break;
|
---|
889 | case END_HARD:
|
---|
890 | current_def->length = current_def->net_length + 2;
|
---|
891 | break;
|
---|
892 | case END_WRAP:
|
---|
893 | case END_0:
|
---|
894 | current_def->length = current_def->net_length;
|
---|
895 | break;
|
---|
896 | }
|
---|
897 | es->text_width = MAX(es->text_width, current_def->width);
|
---|
898 | start += current_def->length;
|
---|
899 | *previous_next = current_def;
|
---|
900 | previous_next = ¤t_def->next;
|
---|
901 | es->line_count++;
|
---|
902 | } while (current_def->ending != END_0);
|
---|
903 | if (hdc)
|
---|
904 | {
|
---|
905 | if (es->font)
|
---|
906 | SelectObject(hdc, old_font);
|
---|
907 | ReleaseDC(hwnd, hdc);
|
---|
908 | }
|
---|
909 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
|
---|
910 | }
|
---|
911 |
|
---|
912 |
|
---|
913 | /*********************************************************************
|
---|
914 | *
|
---|
915 | * EDIT_CallWordBreakProc
|
---|
916 | *
|
---|
917 | * Call appropriate WordBreakProc (internal or external).
|
---|
918 | *
|
---|
919 | * Note: The "start" argument should always be an index refering
|
---|
920 | * to es->text. The actual wordbreak proc might be
|
---|
921 | * 16 bit, so we can't always pass any 32 bit LPSTR.
|
---|
922 | * Hence we assume that es->text is the buffer that holds
|
---|
923 | * the string under examination (we can decide this for ourselves).
|
---|
924 | *
|
---|
925 | */
|
---|
926 | static INT EDIT_CallWordBreakProc(HWND hwnd, EDITSTATE *es, INT start, INT index, INT count, INT action)
|
---|
927 | {
|
---|
928 | if (es->word_break_procA)
|
---|
929 | {
|
---|
930 | //TRACE_(relay)("(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n",
|
---|
931 | // es->word_break_proc32A, es->text + start, index,
|
---|
932 | // count, action );
|
---|
933 | return (INT)es->word_break_procA( es->text + start, index,
|
---|
934 | count, action );
|
---|
935 | }
|
---|
936 | else
|
---|
937 | return EDIT_WordBreakProc(es->text + start, index, count, action);
|
---|
938 | }
|
---|
939 |
|
---|
940 |
|
---|
941 | /*********************************************************************
|
---|
942 | *
|
---|
943 | * EDIT_CharFromPos
|
---|
944 | *
|
---|
945 | * Beware: This is not the function called on EM_CHARFROMPOS
|
---|
946 | * The position _can_ be outside the formatting / client
|
---|
947 | * rectangle
|
---|
948 | * The return value is only the character index
|
---|
949 | *
|
---|
950 | */
|
---|
951 | static INT EDIT_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
|
---|
952 | {
|
---|
953 | INT index;
|
---|
954 | HDC dc = 0;
|
---|
955 | HFONT old_font = 0;
|
---|
956 |
|
---|
957 | if (es->style & ES_MULTILINE) {
|
---|
958 | INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
|
---|
959 | INT line_index = 0;
|
---|
960 | LINEDEF *line_def = es->first_line_def;
|
---|
961 | INT low, high;
|
---|
962 | while ((line > 0) && line_def->next) {
|
---|
963 | line_index += line_def->length;
|
---|
964 | line_def = line_def->next;
|
---|
965 | line--;
|
---|
966 | }
|
---|
967 | x += es->x_offset - es->format_rect.left;
|
---|
968 | if (x >= line_def->width) {
|
---|
969 | if (after_wrap)
|
---|
970 | *after_wrap = (line_def->ending == END_WRAP);
|
---|
971 | return line_index + line_def->net_length;
|
---|
972 | }
|
---|
973 | if (x <= 0) {
|
---|
974 | if (after_wrap)
|
---|
975 | *after_wrap = FALSE;
|
---|
976 | return line_index;
|
---|
977 | }
|
---|
978 | low = line_index + 1;
|
---|
979 | high = line_index + line_def->net_length + 1;
|
---|
980 | if (low < high-1)
|
---|
981 | {
|
---|
982 | if (!dc)
|
---|
983 | {
|
---|
984 | dc = GetDC(hwnd);
|
---|
985 | if (es->font)
|
---|
986 | old_font = SelectObject(dc, es->font);
|
---|
987 | }
|
---|
988 |
|
---|
989 | while (low < high-1)
|
---|
990 | {
|
---|
991 | INT mid = (low + high) / 2;
|
---|
992 | if (LOWORD(GetTabbedTextExtentA(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
|
---|
993 | else low = mid;
|
---|
994 | }
|
---|
995 | }
|
---|
996 | index = low;
|
---|
997 |
|
---|
998 | if (after_wrap)
|
---|
999 | *after_wrap = ((index == line_index + line_def->net_length) &&
|
---|
1000 | (line_def->ending == END_WRAP));
|
---|
1001 | } else {
|
---|
1002 | LPSTR text;
|
---|
1003 | SIZE size;
|
---|
1004 | if (after_wrap)
|
---|
1005 | *after_wrap = FALSE;
|
---|
1006 | x -= es->format_rect.left;
|
---|
1007 | if (!x)
|
---|
1008 | return es->x_offset;
|
---|
1009 | text = EDIT_GetPasswordPointer_SL(hwnd, es);
|
---|
1010 | if (x < 0)
|
---|
1011 | {
|
---|
1012 | INT low = 0;
|
---|
1013 | INT high = es->x_offset;
|
---|
1014 |
|
---|
1015 | if (low < high-1)
|
---|
1016 | {
|
---|
1017 | if (!dc)
|
---|
1018 | {
|
---|
1019 | dc = GetDC(hwnd);
|
---|
1020 | if (es->font)
|
---|
1021 | old_font = SelectObject(dc, es->font);
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | while (low < high-1)
|
---|
1025 | {
|
---|
1026 | INT mid = (low + high) / 2;
|
---|
1027 |
|
---|
1028 | GetTextExtentPoint32A( dc, text + mid,
|
---|
1029 | es->x_offset - mid, &size );
|
---|
1030 | if (size.cx > -x) low = mid;
|
---|
1031 | else high = mid;
|
---|
1032 | }
|
---|
1033 | }
|
---|
1034 | index = low;
|
---|
1035 | } else
|
---|
1036 | {
|
---|
1037 | INT low = es->x_offset;
|
---|
1038 | INT high = lstrlenA(es->text) + 1;
|
---|
1039 |
|
---|
1040 | if (low < high-1)
|
---|
1041 | {
|
---|
1042 | if (!dc)
|
---|
1043 | {
|
---|
1044 | dc = GetDC(hwnd);
|
---|
1045 | if (es->font)
|
---|
1046 | old_font = SelectObject(dc, es->font);
|
---|
1047 | }
|
---|
1048 |
|
---|
1049 | while (low < high-1)
|
---|
1050 | {
|
---|
1051 | INT mid = (low + high) / 2;
|
---|
1052 |
|
---|
1053 | GetTextExtentPoint32A( dc, text + es->x_offset,
|
---|
1054 | mid - es->x_offset, &size );
|
---|
1055 | if (size.cx > x) high = mid;
|
---|
1056 | else low = mid;
|
---|
1057 | }
|
---|
1058 | }
|
---|
1059 | index = low;
|
---|
1060 | }
|
---|
1061 | if (es->style & ES_PASSWORD)
|
---|
1062 | HeapFree(es->heap, 0 ,text);
|
---|
1063 | }
|
---|
1064 | if (dc)
|
---|
1065 | {
|
---|
1066 | if (es->font)
|
---|
1067 | SelectObject(dc, old_font);
|
---|
1068 | ReleaseDC(hwnd, dc);
|
---|
1069 | }
|
---|
1070 | return index;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 |
|
---|
1074 | /*********************************************************************
|
---|
1075 | *
|
---|
1076 | * EDIT_ConfinePoint
|
---|
1077 | *
|
---|
1078 | * adjusts the point to be within the formatting rectangle
|
---|
1079 | * (so CharFromPos returns the nearest _visible_ character)
|
---|
1080 | *
|
---|
1081 | */
|
---|
1082 | static void EDIT_ConfinePoint(HWND hwnd, EDITSTATE *es, LPINT x, LPINT y)
|
---|
1083 | {
|
---|
1084 | *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1);
|
---|
1085 | *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1);
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 |
|
---|
1089 | /*********************************************************************
|
---|
1090 | *
|
---|
1091 | * EDIT_GetLineRect
|
---|
1092 | *
|
---|
1093 | * Calculates the bounding rectangle for a line from a starting
|
---|
1094 | * column to an ending column.
|
---|
1095 | *
|
---|
1096 | */
|
---|
1097 | static void EDIT_GetLineRect(HWND hwnd,HDC dc,EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
|
---|
1098 | {
|
---|
1099 | INT line_index = EDIT_EM_LineIndex(hwnd, es, line);
|
---|
1100 |
|
---|
1101 | if (es->style & ES_MULTILINE)
|
---|
1102 | rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
|
---|
1103 | else
|
---|
1104 | rc->top = es->format_rect.top;
|
---|
1105 | rc->bottom = rc->top + es->line_height;
|
---|
1106 |
|
---|
1107 | rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + scol, TRUE));
|
---|
1108 | rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(hwnd,dc, es, line_index + ecol, TRUE))+1;
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 |
|
---|
1112 | /*********************************************************************
|
---|
1113 | *
|
---|
1114 | * EDIT_GetPasswordPointer_SL
|
---|
1115 | *
|
---|
1116 | * note: caller should free the (optionally) allocated buffer
|
---|
1117 | *
|
---|
1118 | */
|
---|
1119 | static LPSTR EDIT_GetPasswordPointer_SL(HWND hwnd, EDITSTATE *es)
|
---|
1120 | {
|
---|
1121 | if (es->style & ES_PASSWORD) {
|
---|
1122 | INT len = lstrlenA(es->text);
|
---|
1123 | LPSTR text = (LPSTR)HeapAlloc(es->heap, 0, len + 1);
|
---|
1124 | RtlFillMemory(text, len, es->password_char);
|
---|
1125 | text[len] = '\0';
|
---|
1126 | return text;
|
---|
1127 | } else
|
---|
1128 | return es->text;
|
---|
1129 | }
|
---|
1130 |
|
---|
1131 |
|
---|
1132 | /*********************************************************************
|
---|
1133 | *
|
---|
1134 | * EDIT_LockBuffer
|
---|
1135 | *
|
---|
1136 | * This acts as a LOCAL_Lock(), but it locks only once. This way
|
---|
1137 | * you can call it whenever you like, without unlocking.
|
---|
1138 | *
|
---|
1139 | */
|
---|
1140 | static void EDIT_LockBuffer(HWND hwnd, EDITSTATE *es)
|
---|
1141 | {
|
---|
1142 | if (!es) {
|
---|
1143 | //ERR_(edit)("no EDITSTATE ... please report\n");
|
---|
1144 | return;
|
---|
1145 | }
|
---|
1146 | if (!(es->style & ES_MULTILINE))
|
---|
1147 | return;
|
---|
1148 | if (!es->text) {
|
---|
1149 | if (es->hloc)
|
---|
1150 | es->text = (char*)LocalLock(es->hloc);
|
---|
1151 | else {
|
---|
1152 | //ERR_(edit)("no buffer ... please report\n");
|
---|
1153 | return;
|
---|
1154 | }
|
---|
1155 | }
|
---|
1156 | es->lock_count++;
|
---|
1157 | }
|
---|
1158 |
|
---|
1159 |
|
---|
1160 | /*********************************************************************
|
---|
1161 | *
|
---|
1162 | * EDIT_SL_InvalidateText
|
---|
1163 | *
|
---|
1164 | * Called from EDIT_InvalidateText().
|
---|
1165 | * Does the job for single-line controls only.
|
---|
1166 | *
|
---|
1167 | */
|
---|
1168 | static void EDIT_SL_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end)
|
---|
1169 | {
|
---|
1170 | RECT line_rect;
|
---|
1171 | RECT rc;
|
---|
1172 |
|
---|
1173 | EDIT_GetLineRect(hwnd,0, es, 0, start, end, &line_rect);
|
---|
1174 |
|
---|
1175 | if (IntersectRect(&rc, &line_rect, &es->format_rect))
|
---|
1176 | {
|
---|
1177 | HideCaret(hwnd);
|
---|
1178 | InvalidateRect(hwnd, &rc, TRUE);
|
---|
1179 | ShowCaret(hwnd);
|
---|
1180 | }
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 |
|
---|
1184 | /*********************************************************************
|
---|
1185 | *
|
---|
1186 | * EDIT_ML_InvalidateText
|
---|
1187 | *
|
---|
1188 | * Called from EDIT_InvalidateText().
|
---|
1189 | * Does the job for multi-line controls only.
|
---|
1190 | *
|
---|
1191 | */
|
---|
1192 | static void EDIT_ML_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end)
|
---|
1193 | {
|
---|
1194 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
1195 | INT sl = EDIT_EM_LineFromChar(hwnd, es, start);
|
---|
1196 | INT el = EDIT_EM_LineFromChar(hwnd, es, end);
|
---|
1197 | INT sc;
|
---|
1198 | INT ec;
|
---|
1199 | RECT rc1;
|
---|
1200 | RECT rcWnd;
|
---|
1201 | RECT rcLine;
|
---|
1202 | RECT rcUpdate;
|
---|
1203 | INT l;
|
---|
1204 |
|
---|
1205 | if ((el < es->y_offset) || (sl > es->y_offset + vlc))
|
---|
1206 | return;
|
---|
1207 |
|
---|
1208 | sc = start - EDIT_EM_LineIndex(hwnd, es, sl);
|
---|
1209 | ec = end - EDIT_EM_LineIndex(hwnd, es, el);
|
---|
1210 | if (sl < es->y_offset) {
|
---|
1211 | sl = es->y_offset;
|
---|
1212 | sc = 0;
|
---|
1213 | }
|
---|
1214 | if (el > es->y_offset + vlc) {
|
---|
1215 | el = es->y_offset + vlc;
|
---|
1216 | ec = EDIT_EM_LineLength(hwnd, es, EDIT_EM_LineIndex(hwnd, es, el));
|
---|
1217 | }
|
---|
1218 | GetClientRect(hwnd, &rc1);
|
---|
1219 | IntersectRect(&rcWnd, &rc1, &es->format_rect);
|
---|
1220 | HideCaret(hwnd);
|
---|
1221 | if (sl == el) {
|
---|
1222 | EDIT_GetLineRect(hwnd,0, es, sl, sc, ec, &rcLine);
|
---|
1223 |
|
---|
1224 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
|
---|
1225 | InvalidateRect(hwnd, &rcUpdate, TRUE);
|
---|
1226 | } else {
|
---|
1227 | EDIT_GetLineRect(hwnd,0, es, sl, sc,
|
---|
1228 | EDIT_EM_LineLength(hwnd, es,
|
---|
1229 | EDIT_EM_LineIndex(hwnd, es, sl)),
|
---|
1230 | &rcLine);
|
---|
1231 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
|
---|
1232 | InvalidateRect(hwnd, &rcUpdate, TRUE);
|
---|
1233 | for (l = sl + 1 ; l < el ; l++) {
|
---|
1234 | EDIT_GetLineRect(hwnd,0, es, l, 0,
|
---|
1235 | EDIT_EM_LineLength(hwnd, es,
|
---|
1236 | EDIT_EM_LineIndex(hwnd, es, l)),
|
---|
1237 | &rcLine);
|
---|
1238 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
|
---|
1239 | InvalidateRect(hwnd, &rcUpdate, TRUE);
|
---|
1240 | }
|
---|
1241 | EDIT_GetLineRect(hwnd,0, es, el, 0, ec, &rcLine);
|
---|
1242 | if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
|
---|
1243 | InvalidateRect(hwnd, &rcUpdate, TRUE);
|
---|
1244 | }
|
---|
1245 | ShowCaret(hwnd);
|
---|
1246 | }
|
---|
1247 |
|
---|
1248 |
|
---|
1249 | /*********************************************************************
|
---|
1250 | *
|
---|
1251 | * 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 | */
|
---|
1260 | static void EDIT_InvalidateText(HWND hwnd, EDITSTATE *es, INT start, INT end)
|
---|
1261 | {
|
---|
1262 | if (end == start)
|
---|
1263 | return;
|
---|
1264 |
|
---|
1265 | if (end == -1)
|
---|
1266 | end = lstrlenA(es->text);
|
---|
1267 |
|
---|
1268 | ORDER_INT(start, end);
|
---|
1269 |
|
---|
1270 | if (es->style & ES_MULTILINE)
|
---|
1271 | EDIT_ML_InvalidateText(hwnd, es, start, end);
|
---|
1272 | else
|
---|
1273 | EDIT_SL_InvalidateText(hwnd, es, start, end);
|
---|
1274 | }
|
---|
1275 |
|
---|
1276 |
|
---|
1277 | /*********************************************************************
|
---|
1278 | *
|
---|
1279 | * EDIT_MakeFit
|
---|
1280 | *
|
---|
1281 | * Try to fit size + 1 bytes in the buffer. Constrain to limits.
|
---|
1282 | *
|
---|
1283 | */
|
---|
1284 | static BOOL EDIT_MakeFit(HWND hwnd, EDITSTATE *es, INT size)
|
---|
1285 | {
|
---|
1286 | HLOCAL hNew32;
|
---|
1287 |
|
---|
1288 | #ifndef __WIN32OS2__
|
---|
1289 | if (size > es->buffer_limit) {
|
---|
1290 | EDIT_NOTIFY_PARENT(hwnd, EN_MAXTEXT);
|
---|
1291 | return FALSE;
|
---|
1292 | }
|
---|
1293 | #endif
|
---|
1294 |
|
---|
1295 | if (size <= es->buffer_size)
|
---|
1296 | return TRUE;
|
---|
1297 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
|
---|
1298 |
|
---|
1299 | #ifndef __WIN32OS2__
|
---|
1300 | if (size > es->buffer_limit)
|
---|
1301 | size = es->buffer_limit;
|
---|
1302 | #endif
|
---|
1303 |
|
---|
1304 | //TRACE_(edit)("trying to ReAlloc to %d+1\n", size);
|
---|
1305 |
|
---|
1306 | EDIT_UnlockBuffer(hwnd, es, TRUE);
|
---|
1307 | if (es->text) {
|
---|
1308 | es->text = (char*)HeapReAlloc(es->heap, 0, es->text, size + 1);
|
---|
1309 | if (es->text)
|
---|
1310 | #ifdef __WIN32OS2__
|
---|
1311 | es->buffer_size = HeapSize(es->heap, 0, es->text) - 1;
|
---|
1312 | #else
|
---|
1313 | es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit);
|
---|
1314 | #endif
|
---|
1315 | else
|
---|
1316 | es->buffer_size = 0;
|
---|
1317 | } else if (es->hloc) {
|
---|
1318 | hNew32 = LocalReAlloc(es->hloc, size + 1, 0);
|
---|
1319 | if (hNew32) {
|
---|
1320 | //TRACE_(edit)("Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32);
|
---|
1321 | es->hloc = hNew32;
|
---|
1322 | #ifdef __WIN32OS2__
|
---|
1323 | es->buffer_size = LocalSize(es->hloc) - 1;
|
---|
1324 | #else
|
---|
1325 | es->buffer_size = MIN(LocalSize(es->hloc) - 1, es->buffer_limit);
|
---|
1326 | #endif
|
---|
1327 | }
|
---|
1328 | }
|
---|
1329 | if (es->buffer_size < size) {
|
---|
1330 | EDIT_LockBuffer(hwnd, es);
|
---|
1331 | //WARN_(edit)("FAILED ! We now have %d+1\n", es->buffer_size);
|
---|
1332 | EDIT_NOTIFY_PARENT(hwnd, EN_ERRSPACE);
|
---|
1333 | return FALSE;
|
---|
1334 | } else {
|
---|
1335 | EDIT_LockBuffer(hwnd, es);
|
---|
1336 | //TRACE_(edit)("We now have %d+1\n", es->buffer_size);
|
---|
1337 | return TRUE;
|
---|
1338 | }
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 |
|
---|
1342 | /*********************************************************************
|
---|
1343 | *
|
---|
1344 | * EDIT_MakeUndoFit
|
---|
1345 | *
|
---|
1346 | * Try to fit size + 1 bytes in the undo buffer.
|
---|
1347 | *
|
---|
1348 | */
|
---|
1349 | static BOOL EDIT_MakeUndoFit(HWND hwnd, EDITSTATE *es, INT size)
|
---|
1350 | {
|
---|
1351 | if (size <= es->undo_buffer_size)
|
---|
1352 | return TRUE;
|
---|
1353 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH;
|
---|
1354 |
|
---|
1355 | //TRACE_(edit)("trying to ReAlloc to %d+1\n", size);
|
---|
1356 | es->undo_text = (char*)HeapReAlloc(es->heap, 0, es->undo_text, size + 1);
|
---|
1357 | if (es->undo_text) {
|
---|
1358 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
|
---|
1359 | if (es->undo_buffer_size < size) {
|
---|
1360 | //WARN_(edit)("FAILED ! We now have %d+1\n", es->undo_buffer_size);
|
---|
1361 | return FALSE;
|
---|
1362 | }
|
---|
1363 | return TRUE;
|
---|
1364 | }
|
---|
1365 | return FALSE;
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 |
|
---|
1369 | /*********************************************************************
|
---|
1370 | *
|
---|
1371 | * EDIT_MoveBackward
|
---|
1372 | *
|
---|
1373 | */
|
---|
1374 | static void EDIT_MoveBackward(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1375 | {
|
---|
1376 | INT e = es->selection_end;
|
---|
1377 |
|
---|
1378 | if (e) {
|
---|
1379 | e--;
|
---|
1380 | if ((es->style & ES_MULTILINE) && e &&
|
---|
1381 | (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
|
---|
1382 | e--;
|
---|
1383 | if (e && (es->text[e - 1] == '\r'))
|
---|
1384 | e--;
|
---|
1385 | }
|
---|
1386 | }
|
---|
1387 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE);
|
---|
1388 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1389 | }
|
---|
1390 |
|
---|
1391 |
|
---|
1392 | /*********************************************************************
|
---|
1393 | *
|
---|
1394 | * EDIT_MoveDown_ML
|
---|
1395 | *
|
---|
1396 | * Only for multi line controls
|
---|
1397 | * Move the caret one line down, on a column with the nearest
|
---|
1398 | * x coordinate on the screen (might be a different column).
|
---|
1399 | *
|
---|
1400 | */
|
---|
1401 | static void EDIT_MoveDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1402 | {
|
---|
1403 | INT s = es->selection_start;
|
---|
1404 | INT e = es->selection_end;
|
---|
1405 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
|
---|
1406 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
|
---|
1407 | INT x = SLOWORD(pos);
|
---|
1408 | INT y = SHIWORD(pos);
|
---|
1409 |
|
---|
1410 | e = EDIT_CharFromPos(hwnd, es, x, y + es->line_height, &after_wrap);
|
---|
1411 | if (!extend)
|
---|
1412 | s = e;
|
---|
1413 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap);
|
---|
1414 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 |
|
---|
1418 | /*********************************************************************
|
---|
1419 | *
|
---|
1420 | * EDIT_MoveEnd
|
---|
1421 | *
|
---|
1422 | */
|
---|
1423 | static void EDIT_MoveEnd(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1424 | {
|
---|
1425 | BOOL after_wrap = FALSE;
|
---|
1426 | INT e;
|
---|
1427 |
|
---|
1428 | /* Pass a high value in x to make sure of receiving the en of the line */
|
---|
1429 | if (es->style & ES_MULTILINE)
|
---|
1430 | e = EDIT_CharFromPos(hwnd, es, 0x3fffffff,
|
---|
1431 | HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
|
---|
1432 | else
|
---|
1433 | e = lstrlenA(es->text);
|
---|
1434 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, after_wrap);
|
---|
1435 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 |
|
---|
1439 | /*********************************************************************
|
---|
1440 | *
|
---|
1441 | * EDIT_MoveForward
|
---|
1442 | *
|
---|
1443 | */
|
---|
1444 | static void EDIT_MoveForward(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1445 | {
|
---|
1446 | INT e = es->selection_end;
|
---|
1447 |
|
---|
1448 | if (es->text[e]) {
|
---|
1449 | e++;
|
---|
1450 | if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
|
---|
1451 | if (es->text[e] == '\n')
|
---|
1452 | e++;
|
---|
1453 | else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
|
---|
1454 | e += 2;
|
---|
1455 | }
|
---|
1456 | }
|
---|
1457 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE);
|
---|
1458 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1459 | }
|
---|
1460 |
|
---|
1461 |
|
---|
1462 | /*********************************************************************
|
---|
1463 | *
|
---|
1464 | * EDIT_MoveHome
|
---|
1465 | *
|
---|
1466 | * Home key: move to beginning of line.
|
---|
1467 | *
|
---|
1468 | */
|
---|
1469 | static void EDIT_MoveHome(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1470 | {
|
---|
1471 | INT e;
|
---|
1472 |
|
---|
1473 | /* Pass the x_offset in x to make sure of receiving the first position of the line */
|
---|
1474 | if (es->style & ES_MULTILINE)
|
---|
1475 | e = EDIT_CharFromPos(hwnd, es, -es->x_offset,
|
---|
1476 | HIWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
|
---|
1477 | else
|
---|
1478 | e = 0;
|
---|
1479 | EDIT_EM_SetSel(hwnd, es, extend ? es->selection_start : e, e, FALSE);
|
---|
1480 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1481 | }
|
---|
1482 |
|
---|
1483 |
|
---|
1484 | /*********************************************************************
|
---|
1485 | *
|
---|
1486 | * EDIT_MovePageDown_ML
|
---|
1487 | *
|
---|
1488 | * Only for multi line controls
|
---|
1489 | * Move the caret one page down, on a column with the nearest
|
---|
1490 | * x coordinate on the screen (might be a different column).
|
---|
1491 | *
|
---|
1492 | */
|
---|
1493 | static void EDIT_MovePageDown_ML(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1494 | {
|
---|
1495 | INT s = es->selection_start;
|
---|
1496 | INT e = es->selection_end;
|
---|
1497 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
|
---|
1498 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
|
---|
1499 | INT x = SLOWORD(pos);
|
---|
1500 | INT y = SHIWORD(pos);
|
---|
1501 |
|
---|
1502 | e = EDIT_CharFromPos(hwnd, es, x,
|
---|
1503 | y + (es->format_rect.bottom - es->format_rect.top),
|
---|
1504 | &after_wrap);
|
---|
1505 | if (!extend)
|
---|
1506 | s = e;
|
---|
1507 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap);
|
---|
1508 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1509 | }
|
---|
1510 |
|
---|
1511 |
|
---|
1512 | /*********************************************************************
|
---|
1513 | *
|
---|
1514 | * EDIT_MovePageUp_ML
|
---|
1515 | *
|
---|
1516 | * Only for multi line controls
|
---|
1517 | * Move the caret one page up, on a column with the nearest
|
---|
1518 | * x coordinate on the screen (might be a different column).
|
---|
1519 | *
|
---|
1520 | */
|
---|
1521 | static void EDIT_MovePageUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1522 | {
|
---|
1523 | INT s = es->selection_start;
|
---|
1524 | INT e = es->selection_end;
|
---|
1525 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
|
---|
1526 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
|
---|
1527 | INT x = SLOWORD(pos);
|
---|
1528 | INT y = SHIWORD(pos);
|
---|
1529 |
|
---|
1530 | e = EDIT_CharFromPos(hwnd, es, x,
|
---|
1531 | y - (es->format_rect.bottom - es->format_rect.top),
|
---|
1532 | &after_wrap);
|
---|
1533 | if (!extend)
|
---|
1534 | s = e;
|
---|
1535 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap);
|
---|
1536 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1537 | }
|
---|
1538 |
|
---|
1539 |
|
---|
1540 | /*********************************************************************
|
---|
1541 | *
|
---|
1542 | * EDIT_MoveUp_ML
|
---|
1543 | *
|
---|
1544 | * Only for multi line controls
|
---|
1545 | * Move the caret one line up, on a column with the nearest
|
---|
1546 | * x coordinate on the screen (might be a different column).
|
---|
1547 | *
|
---|
1548 | */
|
---|
1549 | static void EDIT_MoveUp_ML(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1550 | {
|
---|
1551 | INT s = es->selection_start;
|
---|
1552 | INT e = es->selection_end;
|
---|
1553 | BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
|
---|
1554 | LRESULT pos = EDIT_EM_PosFromChar(hwnd,0, es, e, after_wrap);
|
---|
1555 | INT x = SLOWORD(pos);
|
---|
1556 | INT y = SHIWORD(pos);
|
---|
1557 |
|
---|
1558 | e = EDIT_CharFromPos(hwnd, es, x, y - es->line_height, &after_wrap);
|
---|
1559 | if (!extend)
|
---|
1560 | s = e;
|
---|
1561 | EDIT_EM_SetSel(hwnd, es, s, e, after_wrap);
|
---|
1562 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1563 | }
|
---|
1564 |
|
---|
1565 |
|
---|
1566 | /*********************************************************************
|
---|
1567 | *
|
---|
1568 | * EDIT_MoveWordBackward
|
---|
1569 | *
|
---|
1570 | */
|
---|
1571 | static void EDIT_MoveWordBackward(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1572 | {
|
---|
1573 | INT s = es->selection_start;
|
---|
1574 | INT e = es->selection_end;
|
---|
1575 | INT l;
|
---|
1576 | INT ll;
|
---|
1577 | INT li;
|
---|
1578 |
|
---|
1579 | l = EDIT_EM_LineFromChar(hwnd, es, e);
|
---|
1580 | ll = EDIT_EM_LineLength(hwnd, es, e);
|
---|
1581 | li = EDIT_EM_LineIndex(hwnd, es, l);
|
---|
1582 | if (e - li == 0) {
|
---|
1583 | if (l) {
|
---|
1584 | li = EDIT_EM_LineIndex(hwnd, es, l - 1);
|
---|
1585 | e = li + EDIT_EM_LineLength(hwnd, es, li);
|
---|
1586 | }
|
---|
1587 | } else {
|
---|
1588 | e = li + (INT)EDIT_CallWordBreakProc(hwnd, es,
|
---|
1589 | li, e - li, ll, WB_LEFT);
|
---|
1590 | }
|
---|
1591 | if (!extend)
|
---|
1592 | s = e;
|
---|
1593 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE);
|
---|
1594 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1595 | }
|
---|
1596 |
|
---|
1597 |
|
---|
1598 | /*********************************************************************
|
---|
1599 | *
|
---|
1600 | * EDIT_MoveWordForward
|
---|
1601 | *
|
---|
1602 | */
|
---|
1603 | static void EDIT_MoveWordForward(HWND hwnd, EDITSTATE *es, BOOL extend)
|
---|
1604 | {
|
---|
1605 | INT s = es->selection_start;
|
---|
1606 | INT e = es->selection_end;
|
---|
1607 | INT l;
|
---|
1608 | INT ll;
|
---|
1609 | INT li;
|
---|
1610 |
|
---|
1611 | l = EDIT_EM_LineFromChar(hwnd, es, e);
|
---|
1612 | ll = EDIT_EM_LineLength(hwnd, es, e);
|
---|
1613 | li = EDIT_EM_LineIndex(hwnd, es, l);
|
---|
1614 | if (e - li == ll) {
|
---|
1615 | if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
|
---|
1616 | e = EDIT_EM_LineIndex(hwnd, es, l + 1);
|
---|
1617 | } else {
|
---|
1618 | e = li + EDIT_CallWordBreakProc(hwnd, es,
|
---|
1619 | li, e - li + 1, ll, WB_RIGHT);
|
---|
1620 | }
|
---|
1621 | if (!extend)
|
---|
1622 | s = e;
|
---|
1623 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE);
|
---|
1624 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
1625 | }
|
---|
1626 |
|
---|
1627 |
|
---|
1628 | /*********************************************************************
|
---|
1629 | *
|
---|
1630 | * EDIT_PaintLine
|
---|
1631 | *
|
---|
1632 | */
|
---|
1633 | static void EDIT_PaintLine(HWND hwnd, EDITSTATE *es, HDC dc, INT line, BOOL rev)
|
---|
1634 | {
|
---|
1635 | INT s = es->selection_start;
|
---|
1636 | INT e = es->selection_end;
|
---|
1637 | INT li;
|
---|
1638 | INT ll;
|
---|
1639 | INT x;
|
---|
1640 | INT y;
|
---|
1641 | LRESULT pos;
|
---|
1642 |
|
---|
1643 | if (es->style & ES_MULTILINE) {
|
---|
1644 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
1645 | if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
|
---|
1646 | return;
|
---|
1647 | } else if (line)
|
---|
1648 | return;
|
---|
1649 |
|
---|
1650 | //TRACE_(edit)("line=%d\n", line);
|
---|
1651 |
|
---|
1652 | pos = EDIT_EM_PosFromChar(hwnd,dc, es, EDIT_EM_LineIndex(hwnd, es, line), FALSE);
|
---|
1653 | x = SLOWORD(pos);
|
---|
1654 | y = SHIWORD(pos);
|
---|
1655 | li = EDIT_EM_LineIndex(hwnd, es, line);
|
---|
1656 | ll = EDIT_EM_LineLength(hwnd, es, li);
|
---|
1657 | s = es->selection_start;
|
---|
1658 | e = es->selection_end;
|
---|
1659 | ORDER_INT(s, e);
|
---|
1660 | s = MIN(li + ll, MAX(li, s));
|
---|
1661 | e = MIN(li + ll, MAX(li, e));
|
---|
1662 |
|
---|
1663 | if (rev && (s != e) && ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL)))
|
---|
1664 | {
|
---|
1665 | HRGN oldRgn,newRgn,combRgn;
|
---|
1666 | RECT rect;
|
---|
1667 | //CB: OS/2 has problems with relative string positions (i.e. Communicator)
|
---|
1668 | // fix: always calculate string from starting point, tab bugs fixed too
|
---|
1669 | // otherwise we have 'dancing characters'
|
---|
1670 |
|
---|
1671 | if (!(es->style & ES_MULTILINE))
|
---|
1672 | {
|
---|
1673 | SIZE size;
|
---|
1674 |
|
---|
1675 | rect.top = y;
|
---|
1676 | rect.bottom = y+es->line_height;
|
---|
1677 | GetTextExtentPoint32A(dc,es->text+li,s-li,&size);
|
---|
1678 | rect.left = x+size.cx;
|
---|
1679 | GetTextExtentPoint32A(dc,es->text+li,e-li,&size);
|
---|
1680 | rect.right = x+size.cx;
|
---|
1681 |
|
---|
1682 | oldRgn = CreateRectRgnIndirect(&rect); //dummy parameter
|
---|
1683 | GetClipRgn(dc,oldRgn);
|
---|
1684 | newRgn = CreateRectRgnIndirect(&rect);
|
---|
1685 | combRgn = CreateRectRgnIndirect(&rect); //dummy parameter
|
---|
1686 | CombineRgn(combRgn,oldRgn,newRgn,RGN_XOR);
|
---|
1687 | SelectClipRgn(dc,combRgn);
|
---|
1688 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,ll,FALSE);
|
---|
1689 | CombineRgn(combRgn,oldRgn,newRgn,RGN_AND);
|
---|
1690 | SelectClipRgn(dc,combRgn);
|
---|
1691 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,e-li,TRUE);
|
---|
1692 | DeleteObject(oldRgn);
|
---|
1693 | DeleteObject(newRgn);
|
---|
1694 | DeleteObject(combRgn);
|
---|
1695 | } else
|
---|
1696 | {
|
---|
1697 | rect.top = y;
|
---|
1698 | rect.bottom = y+es->line_height;
|
---|
1699 | rect.left = x+LOWORD(TabbedTextOutA(dc,x,y,es->text+li,s-li,es->tabs_count,es->tabs,es->format_rect.left-es->x_offset));
|
---|
1700 | rect.right = x+LOWORD(TabbedTextOutA(dc,x,y,es->text+li,e-li,es->tabs_count,es->tabs,es->format_rect.left-es->x_offset));
|
---|
1701 |
|
---|
1702 | oldRgn = CreateRectRgnIndirect(&rect); //dummy parameter
|
---|
1703 | GetClipRgn(dc,oldRgn);
|
---|
1704 | newRgn = CreateRectRgnIndirect(&rect);
|
---|
1705 | combRgn = CreateRectRgnIndirect(&rect); //dummy parameter
|
---|
1706 | CombineRgn(combRgn,oldRgn,newRgn,RGN_XOR);
|
---|
1707 | CombineRgn(combRgn,oldRgn,combRgn,RGN_AND);
|
---|
1708 | SelectClipRgn(dc,combRgn);
|
---|
1709 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,ll,FALSE);
|
---|
1710 | CombineRgn(combRgn,oldRgn,newRgn,RGN_AND);
|
---|
1711 | SelectClipRgn(dc,combRgn);
|
---|
1712 | EDIT_PaintText(hwnd,es,dc,x,y,line,0,e-li,TRUE);
|
---|
1713 | SelectClipRgn(dc,oldRgn);
|
---|
1714 | DeleteObject(oldRgn);
|
---|
1715 | DeleteObject(newRgn);
|
---|
1716 | DeleteObject(combRgn);
|
---|
1717 | }
|
---|
1718 | } else EDIT_PaintText(hwnd, es, dc, x, y, line, 0, ll, FALSE);
|
---|
1719 | }
|
---|
1720 |
|
---|
1721 |
|
---|
1722 | /*********************************************************************
|
---|
1723 | *
|
---|
1724 | * EDIT_PaintText
|
---|
1725 | *
|
---|
1726 | */
|
---|
1727 | static VOID EDIT_PaintText(HWND hwnd, EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
|
---|
1728 | {
|
---|
1729 | COLORREF BkColor;
|
---|
1730 | COLORREF TextColor;
|
---|
1731 | INT li;
|
---|
1732 |
|
---|
1733 | if (!count)
|
---|
1734 | return;
|
---|
1735 | BkColor = GetBkColor(dc);
|
---|
1736 | TextColor = GetTextColor(dc);
|
---|
1737 | if (rev)
|
---|
1738 | {
|
---|
1739 | SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
|
---|
1740 | SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
|
---|
1741 | }
|
---|
1742 | li = EDIT_EM_LineIndex(hwnd, es, line);
|
---|
1743 | if (es->style & ES_MULTILINE)
|
---|
1744 | {
|
---|
1745 | TabbedTextOutA(dc, x, y, es->text + li + col, count,
|
---|
1746 | es->tabs_count, es->tabs, es->format_rect.left - es->x_offset);
|
---|
1747 | } else
|
---|
1748 | {
|
---|
1749 | LPSTR text = EDIT_GetPasswordPointer_SL(hwnd, es);
|
---|
1750 | POINT pt;
|
---|
1751 |
|
---|
1752 | TextOutA(dc,x,y,text+li+col,count);
|
---|
1753 | if (es->style & ES_PASSWORD)
|
---|
1754 | HeapFree(es->heap, 0, text);
|
---|
1755 | }
|
---|
1756 | if (rev)
|
---|
1757 | {
|
---|
1758 | SetBkColor(dc, BkColor);
|
---|
1759 | SetTextColor(dc, TextColor);
|
---|
1760 | }
|
---|
1761 | }
|
---|
1762 |
|
---|
1763 |
|
---|
1764 | /*********************************************************************
|
---|
1765 | *
|
---|
1766 | * EDIT_SetCaretPos
|
---|
1767 | *
|
---|
1768 | */
|
---|
1769 | static void EDIT_SetCaretPos(HWND hwnd, EDITSTATE *es, INT pos,
|
---|
1770 | BOOL after_wrap)
|
---|
1771 | {
|
---|
1772 | LRESULT res = EDIT_EM_PosFromChar(hwnd,0, es, pos, after_wrap);
|
---|
1773 | INT x = SLOWORD(res);
|
---|
1774 | INT y = SHIWORD(res);
|
---|
1775 |
|
---|
1776 | if(x < es->format_rect.left)
|
---|
1777 | x = es->format_rect.left;
|
---|
1778 | if(x > es->format_rect.right - 2)
|
---|
1779 | x = es->format_rect.right - 2;
|
---|
1780 | if(y > es->format_rect.bottom)
|
---|
1781 | y = es->format_rect.bottom;
|
---|
1782 | if(y < es->format_rect.top)
|
---|
1783 | y = es->format_rect.top;
|
---|
1784 | SetCaretPos(x, y);
|
---|
1785 | return;
|
---|
1786 | }
|
---|
1787 |
|
---|
1788 |
|
---|
1789 | /*********************************************************************
|
---|
1790 | *
|
---|
1791 | * EDIT_SetRectNP
|
---|
1792 | *
|
---|
1793 | * note: this is not (exactly) the handler called on EM_SETRECTNP
|
---|
1794 | * it is also used to set the rect of a single line control
|
---|
1795 | *
|
---|
1796 | */
|
---|
1797 | static void EDIT_SetRectNP(HWND hwnd, EDITSTATE *es, LPRECT rc)
|
---|
1798 | {
|
---|
1799 | CopyRect(&es->format_rect, rc);
|
---|
1800 | if (es->style & WS_BORDER)
|
---|
1801 | {
|
---|
1802 | INT bw = GetSystemMetrics(SM_CXBORDER)+1,bh = GetSystemMetrics(SM_CYBORDER)+1;
|
---|
1803 |
|
---|
1804 | es->format_rect.left += bw;
|
---|
1805 | es->format_rect.top += bh;
|
---|
1806 | es->format_rect.right -= bw;
|
---|
1807 | es->format_rect.bottom -= bh;
|
---|
1808 | }
|
---|
1809 | es->format_rect.left += es->left_margin;
|
---|
1810 | es->format_rect.right -= es->right_margin;
|
---|
1811 | es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width);
|
---|
1812 | if (es->style & ES_MULTILINE)
|
---|
1813 | es->format_rect.bottom = es->format_rect.top +
|
---|
1814 | MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height;
|
---|
1815 | else
|
---|
1816 | es->format_rect.bottom = es->format_rect.top + es->line_height;
|
---|
1817 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
|
---|
1818 | EDIT_BuildLineDefs_ML(hwnd,es);
|
---|
1819 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
|
---|
1820 | }
|
---|
1821 |
|
---|
1822 |
|
---|
1823 | /*********************************************************************
|
---|
1824 | *
|
---|
1825 | * EDIT_UnlockBuffer
|
---|
1826 | *
|
---|
1827 | */
|
---|
1828 | static void EDIT_UnlockBuffer(HWND hwnd, EDITSTATE *es, BOOL force)
|
---|
1829 | {
|
---|
1830 | if (!es) {
|
---|
1831 | //ERR_(edit)("no EDITSTATE ... please report\n");
|
---|
1832 | return;
|
---|
1833 | }
|
---|
1834 | if (!(es->style & ES_MULTILINE))
|
---|
1835 | return;
|
---|
1836 | if (!es->lock_count) {
|
---|
1837 | //ERR_(edit)("lock_count == 0 ... please report\n");
|
---|
1838 | return;
|
---|
1839 | }
|
---|
1840 | if (!es->text) {
|
---|
1841 | //ERR_(edit)("es->text == 0 ... please report\n");
|
---|
1842 | return;
|
---|
1843 | }
|
---|
1844 | if (force || (es->lock_count == 1)) {
|
---|
1845 | if (es->hloc) {
|
---|
1846 | LocalUnlock(es->hloc);
|
---|
1847 | es->text = NULL;
|
---|
1848 | }
|
---|
1849 | }
|
---|
1850 | es->lock_count--;
|
---|
1851 | }
|
---|
1852 |
|
---|
1853 |
|
---|
1854 | /*********************************************************************
|
---|
1855 | *
|
---|
1856 | * EDIT_WordBreakProc
|
---|
1857 | *
|
---|
1858 | * Find the beginning of words.
|
---|
1859 | * Note: unlike the specs for a WordBreakProc, this function only
|
---|
1860 | * allows to be called without linebreaks between s[0] upto
|
---|
1861 | * s[count - 1]. Remember it is only called
|
---|
1862 | * internally, so we can decide this for ourselves.
|
---|
1863 | *
|
---|
1864 | */
|
---|
1865 | static INT EDIT_WordBreakProc(LPSTR s, INT index, INT count, INT action)
|
---|
1866 | {
|
---|
1867 | INT ret = 0;
|
---|
1868 |
|
---|
1869 | //TRACE_(edit)("s=%p, index=%u, count=%u, action=%d\n",
|
---|
1870 | // s, index, count, action);
|
---|
1871 |
|
---|
1872 | switch (action) {
|
---|
1873 | case WB_LEFT:
|
---|
1874 | if (!count)
|
---|
1875 | break;
|
---|
1876 | if (index)
|
---|
1877 | index--;
|
---|
1878 | if (s[index] == ' ') {
|
---|
1879 | while (index && (s[index] == ' '))
|
---|
1880 | index--;
|
---|
1881 | if (index) {
|
---|
1882 | while (index && (s[index] != ' '))
|
---|
1883 | index--;
|
---|
1884 | if (s[index] == ' ')
|
---|
1885 | index++;
|
---|
1886 | }
|
---|
1887 | } else {
|
---|
1888 | while (index && (s[index] != ' '))
|
---|
1889 | index--;
|
---|
1890 | if (s[index] == ' ')
|
---|
1891 | index++;
|
---|
1892 | }
|
---|
1893 | ret = index;
|
---|
1894 | break;
|
---|
1895 | case WB_RIGHT:
|
---|
1896 | if (!count)
|
---|
1897 | break;
|
---|
1898 | if (index)
|
---|
1899 | index--;
|
---|
1900 | if (s[index] == ' ')
|
---|
1901 | while ((index < count) && (s[index] == ' ')) index++;
|
---|
1902 | else {
|
---|
1903 | while (s[index] && (s[index] != ' ') && (index < count))
|
---|
1904 | index++;
|
---|
1905 | while ((s[index] == ' ') && (index < count)) index++;
|
---|
1906 | }
|
---|
1907 | ret = index;
|
---|
1908 | break;
|
---|
1909 | case WB_ISDELIMITER:
|
---|
1910 | ret = (s[index] == ' ');
|
---|
1911 | break;
|
---|
1912 | default:
|
---|
1913 | //ERR_(edit)("unknown action code, please report !\n");
|
---|
1914 | break;
|
---|
1915 | }
|
---|
1916 | return ret;
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 |
|
---|
1920 | /*********************************************************************
|
---|
1921 | *
|
---|
1922 | * EM_CHARFROMPOS
|
---|
1923 | *
|
---|
1924 | * returns line number (not index) in high-order word of result.
|
---|
1925 | * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
|
---|
1926 | * to Richedit, not to the edit control. Original documentation is valid.
|
---|
1927 | *
|
---|
1928 | */
|
---|
1929 | static LRESULT EDIT_EM_CharFromPos(HWND hwnd, EDITSTATE *es, INT x, INT y)
|
---|
1930 | {
|
---|
1931 | POINT pt;
|
---|
1932 | INT index;
|
---|
1933 |
|
---|
1934 | pt.x = x;
|
---|
1935 | pt.y = y;
|
---|
1936 |
|
---|
1937 | if (!PtInRect(&es->format_rect,pt)) return -1;
|
---|
1938 |
|
---|
1939 | index = EDIT_CharFromPos(hwnd, es, x, y, NULL);
|
---|
1940 | return MAKELONG(index, EDIT_EM_LineFromChar(hwnd, es, index));
|
---|
1941 | }
|
---|
1942 |
|
---|
1943 |
|
---|
1944 | /*********************************************************************
|
---|
1945 | *
|
---|
1946 | * EM_FMTLINES
|
---|
1947 | *
|
---|
1948 | * Enable or disable soft breaks.
|
---|
1949 | */
|
---|
1950 | static BOOL EDIT_EM_FmtLines(HWND hwnd, EDITSTATE *es, BOOL add_eol)
|
---|
1951 | {
|
---|
1952 | es->flags &= ~EF_USE_SOFTBRK;
|
---|
1953 | if (add_eol) {
|
---|
1954 | es->flags |= EF_USE_SOFTBRK;
|
---|
1955 | dprintf(("EDIT: EM_FMTLINES: soft break enabled, not implemented\n"));
|
---|
1956 | }
|
---|
1957 | return add_eol;
|
---|
1958 | }
|
---|
1959 |
|
---|
1960 | static INT EDIT_EM_GetFirstVisibleLine(HWND hwnd,EDITSTATE *es)
|
---|
1961 | {
|
---|
1962 | return (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
|
---|
1963 | }
|
---|
1964 |
|
---|
1965 | /*********************************************************************
|
---|
1966 | *
|
---|
1967 | * EM_GETHANDLE
|
---|
1968 | *
|
---|
1969 | * Hopefully this won't fire back at us.
|
---|
1970 | * We always start with a fixed buffer in our own heap.
|
---|
1971 | * However, with this message a 32 bit application requests
|
---|
1972 | * a handle to 32 bit moveable local heap memory, where it expects
|
---|
1973 | * to find the text.
|
---|
1974 | * It's a pity that from this moment on we have to use this
|
---|
1975 | * local heap, because applications may rely on the handle
|
---|
1976 | * in the future.
|
---|
1977 | *
|
---|
1978 | * In this function we'll try to switch to local heap.
|
---|
1979 | *
|
---|
1980 | */
|
---|
1981 | static HLOCAL EDIT_EM_GetHandle(HWND hwnd, EDITSTATE *es)
|
---|
1982 | {
|
---|
1983 | HLOCAL newBuf;
|
---|
1984 | LPSTR newText;
|
---|
1985 | INT newSize;
|
---|
1986 |
|
---|
1987 | if (!(es->style & ES_MULTILINE))
|
---|
1988 | return 0;
|
---|
1989 |
|
---|
1990 | if (es->hloc)
|
---|
1991 | return es->hloc;
|
---|
1992 |
|
---|
1993 | if (!(newBuf = LocalAlloc(LMEM_MOVEABLE, lstrlenA(es->text) + 1))) {
|
---|
1994 | //ERR_(edit)("could not allocate new 32 bit buffer\n");
|
---|
1995 | return 0;
|
---|
1996 | }
|
---|
1997 | #ifdef __WIN32OS2__
|
---|
1998 | newSize = LocalSize(newBuf) - 1;
|
---|
1999 | #else
|
---|
2000 | newSize = MIN(LocalSize(newBuf) - 1, es->buffer_limit);
|
---|
2001 | #endif
|
---|
2002 | if (!(newText = (char*)LocalLock(newBuf))) {
|
---|
2003 | //ERR_(edit)("could not lock new 32 bit buffer\n");
|
---|
2004 | LocalFree(newBuf);
|
---|
2005 | return 0;
|
---|
2006 | }
|
---|
2007 | lstrcpyA(newText, es->text);
|
---|
2008 | EDIT_UnlockBuffer(hwnd, es, TRUE);
|
---|
2009 | if (es->text)
|
---|
2010 | HeapFree(es->heap, 0, es->text);
|
---|
2011 | es->hloc = newBuf;
|
---|
2012 | es->buffer_size = newSize;
|
---|
2013 | es->text = newText;
|
---|
2014 | EDIT_LockBuffer(hwnd, es);
|
---|
2015 | //TRACE_(edit)("switched to 32 bit local heap\n");
|
---|
2016 |
|
---|
2017 | return es->hloc;
|
---|
2018 | }
|
---|
2019 |
|
---|
2020 | static INT EDIT_EM_GetLimitText(HWND hwnd,EDITSTATE *es)
|
---|
2021 | {
|
---|
2022 | return es->buffer_limit;
|
---|
2023 | }
|
---|
2024 |
|
---|
2025 | /*********************************************************************
|
---|
2026 | *
|
---|
2027 | * EM_GETLINE
|
---|
2028 | *
|
---|
2029 | */
|
---|
2030 | static INT EDIT_EM_GetLine(HWND hwnd, EDITSTATE *es, INT line, LPSTR lpch)
|
---|
2031 | {
|
---|
2032 | LPSTR src;
|
---|
2033 | INT len;
|
---|
2034 | INT i;
|
---|
2035 |
|
---|
2036 | if (!lpch || (*(WORD*)lpch == 0)) return 0;
|
---|
2037 |
|
---|
2038 | if (es->style & ES_MULTILINE) {
|
---|
2039 | if (line >= es->line_count)
|
---|
2040 | return 0;
|
---|
2041 | } else
|
---|
2042 | line = 0;
|
---|
2043 | i = EDIT_EM_LineIndex(hwnd, es, line);
|
---|
2044 | src = es->text + i;
|
---|
2045 | len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(hwnd, es, i));
|
---|
2046 | for (i = 0 ; i < len ; i++) {
|
---|
2047 | *lpch = *src;
|
---|
2048 | src++;
|
---|
2049 | lpch++;
|
---|
2050 | }
|
---|
2051 | //SvL: Terminate string
|
---|
2052 | *lpch = 0;
|
---|
2053 | return (LRESULT)len;
|
---|
2054 | }
|
---|
2055 |
|
---|
2056 | static INT EDIT_EM_GetLineCount(HWND hwnd,EDITSTATE *es)
|
---|
2057 | {
|
---|
2058 | return (es->style & ES_MULTILINE) ? es->line_count : 1;
|
---|
2059 | }
|
---|
2060 |
|
---|
2061 | static LONG EDIT_EM_GetMargins(HWND hwnd,EDITSTATE *es)
|
---|
2062 | {
|
---|
2063 | return MAKELONG(es->left_margin, es->right_margin);
|
---|
2064 | }
|
---|
2065 |
|
---|
2066 | static BOOL EDIT_EM_GetModify(HWND hwnd,EDITSTATE *es)
|
---|
2067 | {
|
---|
2068 | return ((es->flags & EF_MODIFIED) != 0);
|
---|
2069 | }
|
---|
2070 |
|
---|
2071 | static CHAR EDIT_EM_GetPasswordChar(HWND hwnd,EDITSTATE *es)
|
---|
2072 | {
|
---|
2073 | return es->password_char;
|
---|
2074 | }
|
---|
2075 |
|
---|
2076 | static VOID EDIT_EM_GetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc)
|
---|
2077 | {
|
---|
2078 | if (lprc) CopyRect(lprc,&es->format_rect);
|
---|
2079 | }
|
---|
2080 |
|
---|
2081 | /*********************************************************************
|
---|
2082 | *
|
---|
2083 | * EM_GETSEL
|
---|
2084 | *
|
---|
2085 | */
|
---|
2086 | static LRESULT EDIT_EM_GetSel(HWND hwnd, EDITSTATE *es, LPUINT start, LPUINT end)
|
---|
2087 | {
|
---|
2088 | UINT s = es->selection_start;
|
---|
2089 | UINT e = es->selection_end;
|
---|
2090 |
|
---|
2091 | ORDER_UINT(s, e);
|
---|
2092 |
|
---|
2093 | if (start)
|
---|
2094 | *start = s;
|
---|
2095 | if (end)
|
---|
2096 | *end = e;
|
---|
2097 | return MAKELONG(s, e);
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | /*********************************************************************
|
---|
2101 | *
|
---|
2102 | * EM_GETTHUMB
|
---|
2103 | */
|
---|
2104 | static LRESULT EDIT_EM_GetThumb(HWND hwnd, EDITSTATE *es)
|
---|
2105 | {
|
---|
2106 | SCROLLINFO si;
|
---|
2107 |
|
---|
2108 | if (!(es->style & ES_MULTILINE)) return 0;
|
---|
2109 |
|
---|
2110 | si.cbSize = sizeof(si);
|
---|
2111 | si.fMask = SIF_TRACKPOS;
|
---|
2112 | return GetScrollInfo(hwnd,SB_VERT,&si) ? si.nTrackPos:0;
|
---|
2113 | }
|
---|
2114 |
|
---|
2115 | static PVOID EDIT_EM_GetWordbreakProc(HWND hwnd,EDITSTATE *es)
|
---|
2116 | {
|
---|
2117 | return es->word_break_procA;
|
---|
2118 | }
|
---|
2119 |
|
---|
2120 | /*********************************************************************
|
---|
2121 | *
|
---|
2122 | * EM_LINEFROMCHAR
|
---|
2123 | *
|
---|
2124 | */
|
---|
2125 | static INT EDIT_EM_LineFromChar(HWND hwnd, EDITSTATE *es, INT index)
|
---|
2126 | {
|
---|
2127 | INT line;
|
---|
2128 | LINEDEF *line_def;
|
---|
2129 |
|
---|
2130 | if (!(es->style & ES_MULTILINE))
|
---|
2131 | return 0;
|
---|
2132 | if (index > lstrlenA(es->text))
|
---|
2133 | return es->line_count - 1;
|
---|
2134 | if (index == -1)
|
---|
2135 | index = MIN(es->selection_start, es->selection_end); //selection_end == caret pos
|
---|
2136 |
|
---|
2137 | line = 0;
|
---|
2138 | line_def = es->first_line_def;
|
---|
2139 | index -= line_def->length;
|
---|
2140 | while ((index >= 0) && line_def->next) {
|
---|
2141 | line++;
|
---|
2142 | line_def = line_def->next;
|
---|
2143 | index -= line_def->length;
|
---|
2144 | }
|
---|
2145 | return line;
|
---|
2146 | }
|
---|
2147 |
|
---|
2148 |
|
---|
2149 | /*********************************************************************
|
---|
2150 | *
|
---|
2151 | * EM_LINEINDEX
|
---|
2152 | *
|
---|
2153 | */
|
---|
2154 | static INT EDIT_EM_LineIndex(HWND hwnd, EDITSTATE *es, INT line)
|
---|
2155 | {
|
---|
2156 | INT line_index;
|
---|
2157 | LINEDEF *line_def;
|
---|
2158 |
|
---|
2159 | if (!(es->style & ES_MULTILINE))
|
---|
2160 | return 0;
|
---|
2161 | if (line >= es->line_count)
|
---|
2162 | return -1;
|
---|
2163 |
|
---|
2164 | line_index = 0;
|
---|
2165 | line_def = es->first_line_def;
|
---|
2166 | if (line == -1) {
|
---|
2167 | INT index = es->selection_end - line_def->length;
|
---|
2168 | while ((index >= 0) && line_def->next) {
|
---|
2169 | line_index += line_def->length;
|
---|
2170 | line_def = line_def->next;
|
---|
2171 | index -= line_def->length;
|
---|
2172 | }
|
---|
2173 | } else {
|
---|
2174 | while (line > 0) {
|
---|
2175 | line_index += line_def->length;
|
---|
2176 | line_def = line_def->next;
|
---|
2177 | line--;
|
---|
2178 | }
|
---|
2179 | }
|
---|
2180 | return line_index;
|
---|
2181 | }
|
---|
2182 |
|
---|
2183 |
|
---|
2184 | /*********************************************************************
|
---|
2185 | *
|
---|
2186 | * EM_LINELENGTH
|
---|
2187 | *
|
---|
2188 | */
|
---|
2189 | static INT EDIT_EM_LineLength(HWND hwnd, EDITSTATE *es, INT index)
|
---|
2190 | {
|
---|
2191 | LINEDEF *line_def;
|
---|
2192 |
|
---|
2193 | if (!(es->style & ES_MULTILINE))
|
---|
2194 | return lstrlenA(es->text);
|
---|
2195 |
|
---|
2196 | if (index == -1)
|
---|
2197 | {
|
---|
2198 | INT sl = EDIT_EM_LineFromChar(hwnd,es,MIN(es->selection_start,es->selection_end));
|
---|
2199 | INT el = EDIT_EM_LineFromChar(hwnd,es,MAX(es->selection_start,es->selection_end));
|
---|
2200 |
|
---|
2201 | if (sl == el)
|
---|
2202 | return EDIT_EM_LineLength(hwnd,es,sl)+es->selection_start-es->selection_end;
|
---|
2203 | else
|
---|
2204 | return es->selection_start+EDIT_EM_LineLength(hwnd,es,el)-es->selection_end;
|
---|
2205 | }
|
---|
2206 | line_def = es->first_line_def;
|
---|
2207 | index -= line_def->length;
|
---|
2208 | while ((index >= 0) && line_def->next) {
|
---|
2209 | line_def = line_def->next;
|
---|
2210 | index -= line_def->length;
|
---|
2211 | }
|
---|
2212 | return line_def->net_length;
|
---|
2213 | }
|
---|
2214 |
|
---|
2215 | static VOID EDIT_UpdateScrollBars(HWND hwnd,EDITSTATE *es,BOOL updateHorz,BOOL updateVert)
|
---|
2216 | {
|
---|
2217 | if (updateHorz && (es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
|
---|
2218 | {
|
---|
2219 | SCROLLINFO si;
|
---|
2220 | INT fw = es->format_rect.right - es->format_rect.left;
|
---|
2221 |
|
---|
2222 | si.cbSize = sizeof(SCROLLINFO);
|
---|
2223 | si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
|
---|
2224 | si.nMin = 0;
|
---|
2225 | si.nMax = es->text_width + fw - 1;
|
---|
2226 | si.nPage = fw;
|
---|
2227 | si.nPos = es->x_offset;
|
---|
2228 | SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
|
---|
2229 | }
|
---|
2230 |
|
---|
2231 | if (updateVert && (es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
|
---|
2232 | {
|
---|
2233 | INT vlc = (es->format_rect.bottom-es->format_rect.top)/es->line_height;
|
---|
2234 | SCROLLINFO si;
|
---|
2235 |
|
---|
2236 | si.cbSize = sizeof(SCROLLINFO);
|
---|
2237 | si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
|
---|
2238 | si.nMin = 0;
|
---|
2239 | si.nMax = es->line_count + vlc - 2;
|
---|
2240 | si.nPage = vlc;
|
---|
2241 | si.nPos = es->y_offset;
|
---|
2242 | SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
|
---|
2243 | }
|
---|
2244 | }
|
---|
2245 |
|
---|
2246 |
|
---|
2247 | /*********************************************************************
|
---|
2248 | *
|
---|
2249 | * EM_LINESCROLL
|
---|
2250 | *
|
---|
2251 | * FIXME: dx is in average character widths
|
---|
2252 | * However, we assume it is in pixels when we use this
|
---|
2253 | * function internally
|
---|
2254 | *
|
---|
2255 | */
|
---|
2256 | static BOOL EDIT_EM_LineScroll(HWND hwnd, EDITSTATE *es, INT dx, INT dy)
|
---|
2257 | {
|
---|
2258 | INT nyoff;
|
---|
2259 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
2260 |
|
---|
2261 | if (!(es->style & ES_MULTILINE))
|
---|
2262 | return FALSE;
|
---|
2263 |
|
---|
2264 | if (-dx > es->x_offset)
|
---|
2265 | dx = -es->x_offset;
|
---|
2266 | if (dx > es->text_width - es->x_offset)
|
---|
2267 | dx = es->text_width - es->x_offset;
|
---|
2268 | nyoff = MAX(0, es->y_offset + dy);
|
---|
2269 |
|
---|
2270 | //SvL: If nyoff > nr lines in control -> last line in control
|
---|
2271 | // window should show last line of control
|
---|
2272 | // Wine code shows last line at the top of the control
|
---|
2273 | // (Quake 3 startup edit control shows the problem)
|
---|
2274 | if (nyoff >= es->line_count) {
|
---|
2275 | if(es->line_count <= vlc) {
|
---|
2276 | nyoff = es->y_offset; //no need to scroll
|
---|
2277 | }
|
---|
2278 | else nyoff = es->line_count - vlc - 1;
|
---|
2279 | }
|
---|
2280 | dy = (es->y_offset - nyoff) * es->line_height;
|
---|
2281 | if (dx || dy)
|
---|
2282 | {
|
---|
2283 | RECT rc1;
|
---|
2284 | RECT rc;
|
---|
2285 |
|
---|
2286 | if (dx && !(es->flags & EF_HSCROLL_TRACK))
|
---|
2287 | EDIT_NOTIFY_PARENT(hwnd, EN_HSCROLL);
|
---|
2288 | if (dy && !(es->flags & EF_VSCROLL_TRACK))
|
---|
2289 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL);
|
---|
2290 |
|
---|
2291 | GetClientRect(hwnd, &rc1);
|
---|
2292 | IntersectRect(&rc, &rc1, &es->format_rect);
|
---|
2293 |
|
---|
2294 | ScrollWindowEx(hwnd,-dx,dy,NULL,&rc,(HRGN)NULL,NULL,SW_INVALIDATE);
|
---|
2295 | es->y_offset = nyoff;
|
---|
2296 | es->x_offset += dx;
|
---|
2297 | EDIT_UpdateScrollBars(hwnd,es,dx,dy);
|
---|
2298 | }
|
---|
2299 |
|
---|
2300 | return TRUE;
|
---|
2301 | }
|
---|
2302 |
|
---|
2303 |
|
---|
2304 | /*********************************************************************
|
---|
2305 | *
|
---|
2306 | * EM_POSFROMCHAR
|
---|
2307 | *
|
---|
2308 | */
|
---|
2309 | static LRESULT EDIT_EM_PosFromChar(HWND hwnd,HDC dc, EDITSTATE *es, INT index, BOOL after_wrap)
|
---|
2310 | {
|
---|
2311 | INT len = lstrlenA(es->text);
|
---|
2312 | INT l;
|
---|
2313 | INT li;
|
---|
2314 | INT x;
|
---|
2315 | INT y = 0;
|
---|
2316 | BOOL createdDC = FALSE;
|
---|
2317 | HFONT old_font = 0;
|
---|
2318 | SIZE size;
|
---|
2319 |
|
---|
2320 | index = MIN(index, len);
|
---|
2321 | if (!dc)
|
---|
2322 | {
|
---|
2323 | dc = GetDC(hwnd);
|
---|
2324 | if (es->font)
|
---|
2325 | old_font = SelectObject(dc, es->font);
|
---|
2326 | createdDC = TRUE;
|
---|
2327 | }
|
---|
2328 | if (es->style & ES_MULTILINE) {
|
---|
2329 | l = EDIT_EM_LineFromChar(hwnd, es, index);
|
---|
2330 | y = (l - es->y_offset) * es->line_height;
|
---|
2331 | li = EDIT_EM_LineIndex(hwnd, es, l);
|
---|
2332 | if (after_wrap && (li == index) && l) {
|
---|
2333 | INT l2 = l - 1;
|
---|
2334 | LINEDEF *line_def = es->first_line_def;
|
---|
2335 | while (l2) {
|
---|
2336 | line_def = line_def->next;
|
---|
2337 | l2--;
|
---|
2338 | }
|
---|
2339 | if (line_def->ending == END_WRAP) {
|
---|
2340 | l--;
|
---|
2341 | y -= es->line_height;
|
---|
2342 | li = EDIT_EM_LineIndex(hwnd, es, l);
|
---|
2343 | }
|
---|
2344 | }
|
---|
2345 | x = LOWORD(GetTabbedTextExtentA(dc, es->text + li, index - li,
|
---|
2346 | es->tabs_count, es->tabs)) - es->x_offset;
|
---|
2347 | } else
|
---|
2348 | {
|
---|
2349 | LPSTR text = EDIT_GetPasswordPointer_SL(hwnd, es);
|
---|
2350 |
|
---|
2351 | GetTextExtentPoint32A(dc,text,index,&size);
|
---|
2352 | x = size.cx;
|
---|
2353 | if (es->x_offset)
|
---|
2354 | {
|
---|
2355 | GetTextExtentPoint32A(dc,text,es->x_offset,&size);
|
---|
2356 | x -= size.cx;
|
---|
2357 | }
|
---|
2358 | y = 0;
|
---|
2359 | if (es->style & ES_PASSWORD)
|
---|
2360 | HeapFree(es->heap, 0 ,text);
|
---|
2361 | }
|
---|
2362 | x += es->format_rect.left;
|
---|
2363 | y += es->format_rect.top;
|
---|
2364 | if (createdDC)
|
---|
2365 | {
|
---|
2366 | if (es->font)
|
---|
2367 | SelectObject(dc, old_font);
|
---|
2368 | ReleaseDC(hwnd, dc);
|
---|
2369 | }
|
---|
2370 | return MAKELONG((INT16)x, (INT16)y);
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | BOOL EDIT_CheckNumber(CHAR *text)
|
---|
2374 | {
|
---|
2375 | if (!text) return TRUE;
|
---|
2376 |
|
---|
2377 | while (text[0] != 0)
|
---|
2378 | {
|
---|
2379 | if ((BYTE)text[0] < '0' || (BYTE)text[0] > '9') return FALSE;
|
---|
2380 | text++;
|
---|
2381 | }
|
---|
2382 |
|
---|
2383 | return TRUE;
|
---|
2384 | }
|
---|
2385 |
|
---|
2386 | /*********************************************************************
|
---|
2387 | *
|
---|
2388 | * EM_REPLACESEL
|
---|
2389 | *
|
---|
2390 | */
|
---|
2391 | static void EDIT_EM_ReplaceSel(HWND hwnd, EDITSTATE *es, BOOL can_undo, LPCSTR lpsz_replace)
|
---|
2392 | {
|
---|
2393 | INT strl = lstrlenA(lpsz_replace);
|
---|
2394 | INT tl = lstrlenA(es->text);
|
---|
2395 | INT utl;
|
---|
2396 | UINT s;
|
---|
2397 | UINT e;
|
---|
2398 | INT i;
|
---|
2399 | LPSTR p;
|
---|
2400 |
|
---|
2401 | s = es->selection_start;
|
---|
2402 | e = es->selection_end;
|
---|
2403 |
|
---|
2404 | if ((s == e) && !strl)
|
---|
2405 | return;
|
---|
2406 |
|
---|
2407 | ORDER_UINT(s, e);
|
---|
2408 |
|
---|
2409 | if (!EDIT_MakeFit(hwnd, es, tl - (e - s) + strl))
|
---|
2410 | return;
|
---|
2411 |
|
---|
2412 | if (e != s) {
|
---|
2413 | /* there is something to be deleted */
|
---|
2414 | if (can_undo) {
|
---|
2415 | utl = lstrlenA(es->undo_text);
|
---|
2416 | if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
|
---|
2417 | /* undo-buffer is extended to the right */
|
---|
2418 | EDIT_MakeUndoFit(hwnd, es, utl + e - s);
|
---|
2419 | lstrcpynA(es->undo_text + utl, es->text + s, e - s + 1);
|
---|
2420 | } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
|
---|
2421 | /* undo-buffer is extended to the left */
|
---|
2422 | EDIT_MakeUndoFit(hwnd, es, utl + e - s);
|
---|
2423 | for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
|
---|
2424 | p[e - s] = p[0];
|
---|
2425 | for (i = 0 , p = es->undo_text ; i < e - s ; i++)
|
---|
2426 | p[i] = (es->text + s)[i];
|
---|
2427 | es->undo_position = s;
|
---|
2428 | } else {
|
---|
2429 | /* new undo-buffer */
|
---|
2430 | EDIT_MakeUndoFit(hwnd, es, e - s);
|
---|
2431 | lstrcpynA(es->undo_text, es->text + s, e - s + 1);
|
---|
2432 | es->undo_position = s;
|
---|
2433 | }
|
---|
2434 | /* any deletion makes the old insertion-undo invalid */
|
---|
2435 | es->undo_insert_count = 0;
|
---|
2436 | } else
|
---|
2437 | EDIT_EM_EmptyUndoBuffer(hwnd, es);
|
---|
2438 |
|
---|
2439 | /* now delete */
|
---|
2440 | lstrcpyA(es->text + s, es->text + e);
|
---|
2441 | }
|
---|
2442 | if (strl)
|
---|
2443 | {
|
---|
2444 | if ((es->style & ES_NUMBER) && !EDIT_CheckNumber((CHAR*)lpsz_replace))
|
---|
2445 | MessageBeep(MB_ICONEXCLAMATION);
|
---|
2446 | else
|
---|
2447 | {
|
---|
2448 | /* there is an insertion */
|
---|
2449 | if (can_undo) {
|
---|
2450 | if ((s == es->undo_position) ||
|
---|
2451 | ((es->undo_insert_count) &&
|
---|
2452 | (s == es->undo_position + es->undo_insert_count)))
|
---|
2453 | /*
|
---|
2454 | * insertion is new and at delete position or
|
---|
2455 | * an extension to either left or right
|
---|
2456 | */
|
---|
2457 | es->undo_insert_count += strl;
|
---|
2458 | else {
|
---|
2459 | /* new insertion undo */
|
---|
2460 | es->undo_position = s;
|
---|
2461 | es->undo_insert_count = strl;
|
---|
2462 | /* new insertion makes old delete-buffer invalid */
|
---|
2463 | *es->undo_text = '\0';
|
---|
2464 | }
|
---|
2465 | } else
|
---|
2466 | EDIT_EM_EmptyUndoBuffer(hwnd, es);
|
---|
2467 |
|
---|
2468 |
|
---|
2469 | /* now insert */
|
---|
2470 | tl = lstrlenA(es->text);
|
---|
2471 | for (p = es->text + tl ; p >= es->text + s ; p--)
|
---|
2472 | p[strl] = p[0];
|
---|
2473 | for (i = 0 , p = es->text + s ; i < strl ; i++)
|
---|
2474 | p[i] = lpsz_replace[i];
|
---|
2475 |
|
---|
2476 | if (es->style & ES_OEMCONVERT)
|
---|
2477 | {
|
---|
2478 | CHAR *text = (LPSTR)HeapAlloc(es->heap,0,strl);
|
---|
2479 |
|
---|
2480 | CharToOemBuffA(lpsz_replace,text,strl);
|
---|
2481 | OemToCharBuffA(text,p,strl);
|
---|
2482 | HeapFree(es->heap,0,text);
|
---|
2483 | }
|
---|
2484 |
|
---|
2485 | if(es->style & ES_UPPERCASE)
|
---|
2486 | CharUpperBuffA(p, strl);
|
---|
2487 | else if(es->style & ES_LOWERCASE)
|
---|
2488 | CharLowerBuffA(p, strl);
|
---|
2489 |
|
---|
2490 | s += strl;
|
---|
2491 | }
|
---|
2492 | }
|
---|
2493 | /* FIXME: really inefficient */
|
---|
2494 | if (es->style & ES_MULTILINE)
|
---|
2495 | EDIT_BuildLineDefs_ML(hwnd,es);
|
---|
2496 |
|
---|
2497 | EDIT_EM_SetSel(hwnd, es, s, s, FALSE);
|
---|
2498 |
|
---|
2499 | es->flags |= EF_MODIFIED;
|
---|
2500 | es->flags |= EF_UPDATE;
|
---|
2501 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
2502 |
|
---|
2503 | /* FIXME: really inefficient */
|
---|
2504 | EDIT_Refresh(hwnd,es,TRUE);
|
---|
2505 | }
|
---|
2506 |
|
---|
2507 |
|
---|
2508 | /*********************************************************************
|
---|
2509 | *
|
---|
2510 | * EM_SCROLL
|
---|
2511 | *
|
---|
2512 | */
|
---|
2513 | static LRESULT EDIT_EM_Scroll(HWND hwnd, EDITSTATE *es, INT action)
|
---|
2514 | {
|
---|
2515 | INT dy;
|
---|
2516 |
|
---|
2517 | if (!(es->style & ES_MULTILINE))
|
---|
2518 | return (LRESULT)FALSE;
|
---|
2519 |
|
---|
2520 | dy = 0;
|
---|
2521 |
|
---|
2522 | switch (action) {
|
---|
2523 | case SB_LINEUP:
|
---|
2524 | if (es->y_offset)
|
---|
2525 | dy = -1;
|
---|
2526 | break;
|
---|
2527 | case SB_LINEDOWN:
|
---|
2528 | if (es->y_offset < es->line_count - 1)
|
---|
2529 | dy = 1;
|
---|
2530 | break;
|
---|
2531 | case SB_PAGEUP:
|
---|
2532 | if (es->y_offset)
|
---|
2533 | dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
2534 | break;
|
---|
2535 | case SB_PAGEDOWN:
|
---|
2536 | if (es->y_offset < es->line_count - 1)
|
---|
2537 | dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
2538 | break;
|
---|
2539 | default:
|
---|
2540 | return (LRESULT)FALSE;
|
---|
2541 | }
|
---|
2542 | if (dy) {
|
---|
2543 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL);
|
---|
2544 | EDIT_EM_LineScroll(hwnd, es, 0, dy);
|
---|
2545 | }
|
---|
2546 | return MAKELONG((INT16)dy, (BOOL16)TRUE);
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 |
|
---|
2550 | /*********************************************************************
|
---|
2551 | *
|
---|
2552 | * EM_SCROLLCARET
|
---|
2553 | *
|
---|
2554 | */
|
---|
2555 | static void EDIT_EM_ScrollCaret(HWND hwnd, EDITSTATE *es)
|
---|
2556 | {
|
---|
2557 | if (es->style & ES_MULTILINE) {
|
---|
2558 | INT l;
|
---|
2559 | INT li;
|
---|
2560 | INT vlc;
|
---|
2561 | INT ww;
|
---|
2562 | INT cw = es->char_width;
|
---|
2563 | INT x;
|
---|
2564 | INT dy = 0;
|
---|
2565 | INT dx = 0;
|
---|
2566 |
|
---|
2567 | l = EDIT_EM_LineFromChar(hwnd, es, es->selection_end);
|
---|
2568 | li = EDIT_EM_LineIndex(hwnd, es, l);
|
---|
2569 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, es->flags & EF_AFTER_WRAP));
|
---|
2570 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
2571 | if (l >= es->y_offset + vlc)
|
---|
2572 | dy = l - vlc + 1 - es->y_offset;
|
---|
2573 | if (l < es->y_offset)
|
---|
2574 | dy = l - es->y_offset;
|
---|
2575 | ww = es->format_rect.right - es->format_rect.left;
|
---|
2576 | if (x < es->format_rect.left)
|
---|
2577 | dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
|
---|
2578 | if (x > es->format_rect.right)
|
---|
2579 | dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
|
---|
2580 | if (dy || dx)
|
---|
2581 | EDIT_EM_LineScroll(hwnd, es, dx, dy);
|
---|
2582 | } else {
|
---|
2583 | INT x;
|
---|
2584 | INT goal;
|
---|
2585 | INT format_width;
|
---|
2586 |
|
---|
2587 | if (!(es->style & ES_AUTOHSCROLL))
|
---|
2588 | return;
|
---|
2589 |
|
---|
2590 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE));
|
---|
2591 | format_width = es->format_rect.right - es->format_rect.left;
|
---|
2592 | if (x < es->format_rect.left)
|
---|
2593 | {
|
---|
2594 | goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
|
---|
2595 | do {
|
---|
2596 | es->x_offset--;
|
---|
2597 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE));
|
---|
2598 | } while ((x < goal) && es->x_offset);
|
---|
2599 | /* FIXME: use ScrollWindow() somehow to improve performance */
|
---|
2600 | EDIT_Refresh(hwnd,es,TRUE);
|
---|
2601 | EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE);
|
---|
2602 | } else if (x > es->format_rect.right)
|
---|
2603 | {
|
---|
2604 | INT x_last;
|
---|
2605 | INT len = lstrlenA(es->text);
|
---|
2606 | goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
|
---|
2607 | do {
|
---|
2608 | es->x_offset++;
|
---|
2609 | x = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, es->selection_end, FALSE));
|
---|
2610 | x_last = SLOWORD(EDIT_EM_PosFromChar(hwnd,0, es, len, FALSE));
|
---|
2611 | } while ((x > goal) && (x_last > es->format_rect.right));
|
---|
2612 | /* FIXME: use ScrollWindow() somehow to improve performance */
|
---|
2613 | EDIT_Refresh(hwnd,es,TRUE);
|
---|
2614 | EDIT_UpdateScrollBars(hwnd,es,TRUE,FALSE);
|
---|
2615 | }
|
---|
2616 | }
|
---|
2617 | }
|
---|
2618 |
|
---|
2619 |
|
---|
2620 | /*********************************************************************
|
---|
2621 | *
|
---|
2622 | * EM_SETHANDLE
|
---|
2623 | *
|
---|
2624 | */
|
---|
2625 | static void EDIT_EM_SetHandle(HWND hwnd, EDITSTATE *es, HLOCAL hloc)
|
---|
2626 | {
|
---|
2627 | if (!(es->style & ES_MULTILINE))
|
---|
2628 | return;
|
---|
2629 |
|
---|
2630 | if (!hloc) {
|
---|
2631 | //WARN_(edit)("called with NULL handle\n");
|
---|
2632 | return;
|
---|
2633 | }
|
---|
2634 |
|
---|
2635 | EDIT_UnlockBuffer(hwnd, es, TRUE);
|
---|
2636 | /*
|
---|
2637 | * old buffer is freed by caller, unless
|
---|
2638 | * it is still in our own heap. (in that case
|
---|
2639 | * we free it, correcting the buggy caller.)
|
---|
2640 | */
|
---|
2641 | if (es->text)
|
---|
2642 | HeapFree(es->heap, 0, es->text);
|
---|
2643 |
|
---|
2644 | es->hloc = hloc;
|
---|
2645 | es->text = NULL;
|
---|
2646 | es->buffer_size = LocalSize(es->hloc) - 1;
|
---|
2647 | EDIT_LockBuffer(hwnd, es);
|
---|
2648 |
|
---|
2649 | if (es->text && (es->text[0] != 0))
|
---|
2650 | {
|
---|
2651 | if (es->style & ES_NUMBER)
|
---|
2652 | {
|
---|
2653 | //CB: todo
|
---|
2654 | }
|
---|
2655 |
|
---|
2656 | if (es->style & ES_OEMCONVERT)
|
---|
2657 | {
|
---|
2658 | INT len = lstrlenA(es->text);
|
---|
2659 | CHAR *text = (LPSTR)HeapAlloc(es->heap,0,len);
|
---|
2660 |
|
---|
2661 | CharToOemBuffA(es->text,text,len);
|
---|
2662 | OemToCharBuffA(text,es->text,len);
|
---|
2663 | HeapFree(es->heap,0,text);
|
---|
2664 | }
|
---|
2665 |
|
---|
2666 | if(es->style & ES_UPPERCASE)
|
---|
2667 | CharUpperA(es->text);
|
---|
2668 | else if(es->style & ES_LOWERCASE)
|
---|
2669 | CharLowerA(es->text);
|
---|
2670 | }
|
---|
2671 |
|
---|
2672 | es->x_offset = es->y_offset = 0;
|
---|
2673 | es->selection_start = es->selection_end = 0;
|
---|
2674 | EDIT_EM_EmptyUndoBuffer(hwnd, es);
|
---|
2675 | es->flags &= ~EF_MODIFIED;
|
---|
2676 | es->flags &= ~EF_UPDATE;
|
---|
2677 | EDIT_BuildLineDefs_ML(hwnd,es);
|
---|
2678 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
2679 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
2680 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
|
---|
2681 | }
|
---|
2682 |
|
---|
2683 | /*********************************************************************
|
---|
2684 | *
|
---|
2685 | * EM_SETLIMITTEXT
|
---|
2686 | *
|
---|
2687 | * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
|
---|
2688 | * However, the windows version is not complied to yet in all of edit.c
|
---|
2689 | *
|
---|
2690 | */
|
---|
2691 | static void EDIT_EM_SetLimitText(HWND hwnd, EDITSTATE *es, INT limit)
|
---|
2692 | {
|
---|
2693 | if (es->style & ES_MULTILINE) {
|
---|
2694 | if (limit)
|
---|
2695 | #ifdef __WIN32OS2__
|
---|
2696 | es->buffer_limit = limit;
|
---|
2697 | #else
|
---|
2698 | es->buffer_limit = MIN(limit, BUFLIMIT_MULTI);
|
---|
2699 | #endif
|
---|
2700 | else
|
---|
2701 | es->buffer_limit = BUFLIMIT_MULTI;
|
---|
2702 | } else {
|
---|
2703 | if (limit)
|
---|
2704 | #ifdef __WIN32OS2__
|
---|
2705 | es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE_NT);
|
---|
2706 | #else
|
---|
2707 | es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE);
|
---|
2708 | #endif
|
---|
2709 | else
|
---|
2710 | es->buffer_limit = BUFLIMIT_SINGLE;
|
---|
2711 | }
|
---|
2712 | }
|
---|
2713 |
|
---|
2714 |
|
---|
2715 | /*********************************************************************
|
---|
2716 | *
|
---|
2717 | * EM_SETMARGINS
|
---|
2718 | *
|
---|
2719 | * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
|
---|
2720 | * action wParam despite what the docs say. EC_USEFONTINFO means one third
|
---|
2721 | * of the char's width, according to the new docs.
|
---|
2722 | *
|
---|
2723 | */
|
---|
2724 | static void EDIT_EM_SetMargins(HWND hwnd, EDITSTATE *es, INT action,
|
---|
2725 | INT left, INT right)
|
---|
2726 | {
|
---|
2727 | RECT r;
|
---|
2728 | INT oldLeft = es->left_margin,oldRight = es->right_margin;
|
---|
2729 |
|
---|
2730 | if (action & EC_LEFTMARGIN) {
|
---|
2731 | if (left != EC_USEFONTINFO)
|
---|
2732 | es->left_margin = left;
|
---|
2733 | else
|
---|
2734 | es->left_margin = es->char_width / 3;
|
---|
2735 | }
|
---|
2736 |
|
---|
2737 | if (action & EC_RIGHTMARGIN) {
|
---|
2738 | if (right != EC_USEFONTINFO)
|
---|
2739 | es->right_margin = right;
|
---|
2740 | else
|
---|
2741 | es->right_margin = es->char_width / 3;
|
---|
2742 | }
|
---|
2743 | //TRACE_(edit)("left=%d, right=%d\n", es->left_margin, es->right_margin);
|
---|
2744 |
|
---|
2745 | if ((oldLeft != es->left_margin) || (oldRight != es->right_margin))
|
---|
2746 | {
|
---|
2747 | GetClientRect(hwnd, &r);
|
---|
2748 | EDIT_SetRectNP(hwnd, es, &r);
|
---|
2749 | if (es->style & ES_MULTILINE)
|
---|
2750 | EDIT_BuildLineDefs_ML(hwnd,es);
|
---|
2751 |
|
---|
2752 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
2753 | if (es->flags & EF_FOCUSED) {
|
---|
2754 | DestroyCaret();
|
---|
2755 | CreateCaret(hwnd, 0, 2, es->line_height);
|
---|
2756 | EDIT_SetCaretPos(hwnd, es, es->selection_end,
|
---|
2757 | es->flags & EF_AFTER_WRAP);
|
---|
2758 | ShowCaret(hwnd);
|
---|
2759 | }
|
---|
2760 | }
|
---|
2761 | }
|
---|
2762 |
|
---|
2763 | static void EDIT_EM_SetModify(HWND hwnd,EDITSTATE *es,BOOL fModified)
|
---|
2764 | {
|
---|
2765 | if (fModified)
|
---|
2766 | es->flags |= EF_MODIFIED;
|
---|
2767 | else
|
---|
2768 | es->flags &= ~(EF_MODIFIED | EF_UPDATE); /* reset pending updates */
|
---|
2769 | }
|
---|
2770 |
|
---|
2771 | /*********************************************************************
|
---|
2772 | *
|
---|
2773 | * EM_SETPASSWORDCHAR
|
---|
2774 | *
|
---|
2775 | */
|
---|
2776 | static void EDIT_EM_SetPasswordChar(HWND hwnd, EDITSTATE *es, CHAR c)
|
---|
2777 | {
|
---|
2778 | if (es->style & ES_MULTILINE)
|
---|
2779 | return;
|
---|
2780 |
|
---|
2781 | if (es->password_char == c)
|
---|
2782 | return;
|
---|
2783 |
|
---|
2784 | es->password_char = c;
|
---|
2785 | if (c) {
|
---|
2786 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) | ES_PASSWORD);
|
---|
2787 | es->style |= ES_PASSWORD;
|
---|
2788 | } else {
|
---|
2789 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~ES_PASSWORD);
|
---|
2790 | es->style &= ~ES_PASSWORD;
|
---|
2791 | }
|
---|
2792 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
2793 | }
|
---|
2794 |
|
---|
2795 | static BOOL EDIT_EM_SetReadOnly(HWND hwnd,EDITSTATE *es,BOOL fReadOnly)
|
---|
2796 | {
|
---|
2797 | if (fReadOnly)
|
---|
2798 | {
|
---|
2799 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) | ES_READONLY);
|
---|
2800 | es->style |= ES_READONLY;
|
---|
2801 | } else
|
---|
2802 | {
|
---|
2803 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~ES_READONLY);
|
---|
2804 | es->style &= ~ES_READONLY;
|
---|
2805 | }
|
---|
2806 |
|
---|
2807 | return TRUE;
|
---|
2808 | }
|
---|
2809 |
|
---|
2810 | static void EDIT_EM_SetRect(HWND hwnd,EDITSTATE *es,LPRECT lprc)
|
---|
2811 | {
|
---|
2812 | if ((es->style & ES_MULTILINE) && lprc)
|
---|
2813 | {
|
---|
2814 | EDIT_SetRectNP(hwnd,es,lprc);
|
---|
2815 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
2816 | }
|
---|
2817 | }
|
---|
2818 |
|
---|
2819 | static void EDIT_EM_SetRectNP(HWND hwnd,EDITSTATE *es,LPRECT lprc)
|
---|
2820 | {
|
---|
2821 | if ((es->style & ES_MULTILINE) && lprc)
|
---|
2822 | EDIT_SetRectNP(hwnd,es,lprc);
|
---|
2823 | }
|
---|
2824 |
|
---|
2825 | /*********************************************************************
|
---|
2826 | *
|
---|
2827 | * EDIT_EM_SetSel
|
---|
2828 | *
|
---|
2829 | * note: unlike the specs say: the order of start and end
|
---|
2830 | * _is_ preserved in Windows. (i.e. start can be > end)
|
---|
2831 | * In other words: this handler is OK
|
---|
2832 | *
|
---|
2833 | */
|
---|
2834 | static void EDIT_EM_SetSel(HWND hwnd, EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
|
---|
2835 | {
|
---|
2836 | UINT old_start = es->selection_start;
|
---|
2837 | UINT old_end = es->selection_end;
|
---|
2838 | UINT len = lstrlenA(es->text);
|
---|
2839 |
|
---|
2840 | if (start == -1) {
|
---|
2841 | start = es->selection_end;
|
---|
2842 | end = es->selection_end;
|
---|
2843 | } else {
|
---|
2844 | start = MIN(start, len);
|
---|
2845 | end = MIN(end, len);
|
---|
2846 | }
|
---|
2847 | es->selection_start = start;
|
---|
2848 | es->selection_end = end;
|
---|
2849 | if (after_wrap)
|
---|
2850 | es->flags |= EF_AFTER_WRAP;
|
---|
2851 | else
|
---|
2852 | es->flags &= ~EF_AFTER_WRAP;
|
---|
2853 | if (es->flags & EF_FOCUSED)
|
---|
2854 | EDIT_SetCaretPos(hwnd, es, end, after_wrap);
|
---|
2855 | /* This is little bit more efficient than before, not sure if it can be improved. FIXME? */
|
---|
2856 | ORDER_UINT(start, end);
|
---|
2857 | ORDER_UINT(end, old_end);
|
---|
2858 | ORDER_UINT(start, old_start);
|
---|
2859 | ORDER_UINT(old_start, old_end);
|
---|
2860 | if ((start == old_start) && (end == old_end)) return;
|
---|
2861 | if (end != old_start)
|
---|
2862 | {
|
---|
2863 | /*
|
---|
2864 | * One can also do
|
---|
2865 | * ORDER_UINT32(end, old_start);
|
---|
2866 | * EDIT_InvalidateText(wnd, es, start, end);
|
---|
2867 | * EDIT_InvalidateText(wnd, es, old_start, old_end);
|
---|
2868 | * in place of the following if statement.
|
---|
2869 | */
|
---|
2870 | if (old_start > end )
|
---|
2871 | {
|
---|
2872 | EDIT_InvalidateText(hwnd, es, start, end);
|
---|
2873 | EDIT_InvalidateText(hwnd, es, old_start, old_end);
|
---|
2874 | }
|
---|
2875 | else
|
---|
2876 | {
|
---|
2877 | EDIT_InvalidateText(hwnd, es, start, old_start);
|
---|
2878 | EDIT_InvalidateText(hwnd, es, end, old_end);
|
---|
2879 | }
|
---|
2880 | }
|
---|
2881 | else EDIT_InvalidateText(hwnd, es, start, old_end);
|
---|
2882 | }
|
---|
2883 |
|
---|
2884 |
|
---|
2885 | /*********************************************************************
|
---|
2886 | *
|
---|
2887 | * EM_SETTABSTOPS
|
---|
2888 | *
|
---|
2889 | */
|
---|
2890 | static BOOL EDIT_EM_SetTabStops(HWND hwnd, EDITSTATE *es, INT count, LPINT tabs)
|
---|
2891 | {
|
---|
2892 | if (!(es->style & ES_MULTILINE))
|
---|
2893 | return FALSE;
|
---|
2894 | if (es->tabs)
|
---|
2895 | HeapFree(es->heap, 0, es->tabs);
|
---|
2896 | es->tabs_count = count;
|
---|
2897 | if (!count)
|
---|
2898 | es->tabs = NULL;
|
---|
2899 | else {
|
---|
2900 | es->tabs = (INT*)HeapAlloc(es->heap, 0, count * sizeof(INT));
|
---|
2901 | memcpy(es->tabs, tabs, count * sizeof(INT));
|
---|
2902 | }
|
---|
2903 | return TRUE;
|
---|
2904 | }
|
---|
2905 |
|
---|
2906 |
|
---|
2907 | /*********************************************************************
|
---|
2908 | *
|
---|
2909 | * EM_SETWORDBREAKPROC
|
---|
2910 | *
|
---|
2911 | */
|
---|
2912 | static void EDIT_EM_SetWordBreakProc(HWND hwnd, EDITSTATE *es, EDITWORDBREAKPROCA wbp)
|
---|
2913 | {
|
---|
2914 | if (es->word_break_procA == wbp)
|
---|
2915 | return;
|
---|
2916 |
|
---|
2917 | es->word_break_procA = wbp;
|
---|
2918 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
|
---|
2919 | EDIT_BuildLineDefs_ML(hwnd,es);
|
---|
2920 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
2921 | }
|
---|
2922 | }
|
---|
2923 |
|
---|
2924 |
|
---|
2925 | /*********************************************************************
|
---|
2926 | *
|
---|
2927 | * EM_UNDO / WM_UNDO
|
---|
2928 | *
|
---|
2929 | */
|
---|
2930 | static BOOL EDIT_EM_Undo(HWND hwnd, EDITSTATE *es)
|
---|
2931 | {
|
---|
2932 | INT ulength = lstrlenA(es->undo_text);
|
---|
2933 | LPSTR utext = (LPSTR)HeapAlloc(es->heap, 0, ulength + 1);
|
---|
2934 |
|
---|
2935 | lstrcpyA(utext, es->undo_text);
|
---|
2936 |
|
---|
2937 | //TRACE_(edit)("before UNDO:insertion length = %d, deletion buffer = %s\n",
|
---|
2938 | // es->undo_insert_count, utext);
|
---|
2939 |
|
---|
2940 | EDIT_EM_SetSel(hwnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
|
---|
2941 | EDIT_EM_EmptyUndoBuffer(hwnd, es);
|
---|
2942 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, utext);
|
---|
2943 | EDIT_EM_SetSel(hwnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
|
---|
2944 | HeapFree(es->heap, 0, utext);
|
---|
2945 |
|
---|
2946 | //TRACE_(edit)("after UNDO:insertion length = %d, deletion buffer = %s\n",
|
---|
2947 | // es->undo_insert_count, es->undo_text);
|
---|
2948 |
|
---|
2949 | if (es->flags & EF_UPDATE) {
|
---|
2950 | es->flags &= ~EF_UPDATE;
|
---|
2951 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
2952 | }
|
---|
2953 |
|
---|
2954 | return TRUE;
|
---|
2955 | }
|
---|
2956 |
|
---|
2957 | static LRESULT EDIT_EM_SetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam)
|
---|
2958 | {
|
---|
2959 | if (wParam == EMSIS_COMPOSITIONSTRING)
|
---|
2960 | {
|
---|
2961 | //CB: todo
|
---|
2962 | }
|
---|
2963 |
|
---|
2964 | return 0;
|
---|
2965 | }
|
---|
2966 |
|
---|
2967 | static LRESULT EDIT_EM_GetIMEStatus(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam)
|
---|
2968 | {
|
---|
2969 | //CB: todo
|
---|
2970 |
|
---|
2971 | return 0; //default
|
---|
2972 | }
|
---|
2973 |
|
---|
2974 | /*********************************************************************
|
---|
2975 | *
|
---|
2976 | * WM_CHAR
|
---|
2977 | *
|
---|
2978 | */
|
---|
2979 | static void EDIT_WM_Char(HWND hwnd, EDITSTATE *es, CHAR c, DWORD key_data)
|
---|
2980 | {
|
---|
2981 | BOOL control = GetKeyState(VK_CONTROL) & 0x8000;
|
---|
2982 | switch (c) {
|
---|
2983 | case '\r':
|
---|
2984 | /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
|
---|
2985 | if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
|
---|
2986 | {
|
---|
2987 | MessageBeep(MB_ICONEXCLAMATION);
|
---|
2988 | break;
|
---|
2989 | }
|
---|
2990 | case '\n':
|
---|
2991 | if (es->style & ES_MULTILINE) {
|
---|
2992 | if (es->style & ES_READONLY) {
|
---|
2993 | EDIT_MoveHome(hwnd, es, FALSE);
|
---|
2994 | EDIT_MoveDown_ML(hwnd, es, FALSE);
|
---|
2995 | } else
|
---|
2996 | {
|
---|
2997 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, "\r\n");
|
---|
2998 | if (es->flags & EF_UPDATE) {
|
---|
2999 | es->flags &= ~EF_UPDATE;
|
---|
3000 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
3001 | }
|
---|
3002 | }
|
---|
3003 | }
|
---|
3004 | break;
|
---|
3005 | case '\t':
|
---|
3006 | if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
|
---|
3007 | {
|
---|
3008 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, "\t");
|
---|
3009 | if (es->flags & EF_UPDATE) {
|
---|
3010 | es->flags &= ~EF_UPDATE;
|
---|
3011 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
3012 | }
|
---|
3013 | }
|
---|
3014 | break;
|
---|
3015 | case VK_BACK:
|
---|
3016 | if (!(es->style & ES_READONLY) && !control) {
|
---|
3017 | if (es->selection_start != es->selection_end)
|
---|
3018 | EDIT_WM_Clear(hwnd, es);
|
---|
3019 | else {
|
---|
3020 | /* delete character left of caret */
|
---|
3021 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE);
|
---|
3022 | EDIT_MoveBackward(hwnd, es, TRUE);
|
---|
3023 | EDIT_WM_Clear(hwnd, es);
|
---|
3024 | }
|
---|
3025 | }
|
---|
3026 | break;
|
---|
3027 | //CB: are these three keys documented or Linux style???
|
---|
3028 | case 0x03: /* ^C */
|
---|
3029 | SendMessageA(hwnd, WM_COPY, 0, 0);
|
---|
3030 | break;
|
---|
3031 | case 0x16: /* ^V */
|
---|
3032 | SendMessageA(hwnd, WM_PASTE, 0, 0);
|
---|
3033 | break;
|
---|
3034 | case 0x18: /* ^X */
|
---|
3035 | SendMessageA(hwnd, WM_CUT, 0, 0);
|
---|
3036 | break;
|
---|
3037 |
|
---|
3038 | default:
|
---|
3039 | if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127))
|
---|
3040 | {
|
---|
3041 | char str[2];
|
---|
3042 |
|
---|
3043 | if (es->style & ES_NUMBER)
|
---|
3044 | {
|
---|
3045 | if (((BYTE)c < '0') || ((BYTE)c > '9')) {
|
---|
3046 | MessageBeep(MB_ICONEXCLAMATION);
|
---|
3047 | return;
|
---|
3048 | }
|
---|
3049 | }
|
---|
3050 | str[0] = c;
|
---|
3051 | str[1] = '\0';
|
---|
3052 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, str);
|
---|
3053 | if (es->flags & EF_UPDATE)
|
---|
3054 | {
|
---|
3055 | es->flags &= ~EF_UPDATE;
|
---|
3056 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
3057 | }
|
---|
3058 | } else MessageBeep(MB_ICONEXCLAMATION);
|
---|
3059 | break;
|
---|
3060 | }
|
---|
3061 | }
|
---|
3062 |
|
---|
3063 |
|
---|
3064 | /*********************************************************************
|
---|
3065 | *
|
---|
3066 | * WM_COMMAND
|
---|
3067 | *
|
---|
3068 | */
|
---|
3069 | static void EDIT_WM_Command(HWND hwnd, EDITSTATE *es, INT code, INT id, HWND control)
|
---|
3070 | {
|
---|
3071 | if (code || control)
|
---|
3072 | return;
|
---|
3073 |
|
---|
3074 | switch (id) {
|
---|
3075 | case EM_UNDO:
|
---|
3076 | EDIT_EM_Undo(hwnd, es);
|
---|
3077 | break;
|
---|
3078 | case WM_CUT:
|
---|
3079 | EDIT_WM_Cut(hwnd, es);
|
---|
3080 | break;
|
---|
3081 | case WM_COPY:
|
---|
3082 | EDIT_WM_Copy(hwnd, es);
|
---|
3083 | break;
|
---|
3084 | case WM_PASTE:
|
---|
3085 | EDIT_WM_Paste(hwnd, es);
|
---|
3086 | break;
|
---|
3087 | case WM_CLEAR:
|
---|
3088 | EDIT_WM_Clear(hwnd, es);
|
---|
3089 | break;
|
---|
3090 | case EM_SETSEL:
|
---|
3091 | EDIT_EM_SetSel(hwnd, es, 0, -1, FALSE);
|
---|
3092 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
3093 | break;
|
---|
3094 | default:
|
---|
3095 | //ERR_(edit)("unknown menu item, please report\n");
|
---|
3096 | break;
|
---|
3097 | }
|
---|
3098 | }
|
---|
3099 |
|
---|
3100 |
|
---|
3101 | /*********************************************************************
|
---|
3102 | *
|
---|
3103 | * WM_CONTEXTMENU
|
---|
3104 | *
|
---|
3105 | * Note: the resource files resource/sysres_??.rc cannot define a
|
---|
3106 | * single popup menu. Hence we use a (dummy) menubar
|
---|
3107 | * containing the single popup menu as its first item.
|
---|
3108 | *
|
---|
3109 | * FIXME: the message identifiers have been chosen arbitrarily,
|
---|
3110 | * hence we use MF_BYPOSITION.
|
---|
3111 | * We might as well use the "real" values (anybody knows ?)
|
---|
3112 | * The menu definition is in resources/sysres_??.rc.
|
---|
3113 | * Once these are OK, we better use MF_BYCOMMAND here
|
---|
3114 | * (as we do in EDIT_WM_Command()).
|
---|
3115 | *
|
---|
3116 | */
|
---|
3117 | static void EDIT_WM_ContextMenu(HWND hwnd, EDITSTATE *es, HWND hwndBtn, INT x, INT y)
|
---|
3118 | {
|
---|
3119 | HMENU menu = LoadMenuA(GetModuleHandleA("USER32"), "EDITMENU");
|
---|
3120 | HMENU popup = GetSubMenu(menu, 0);
|
---|
3121 | UINT start = es->selection_start;
|
---|
3122 | UINT end = es->selection_end;
|
---|
3123 |
|
---|
3124 | ORDER_UINT(start, end);
|
---|
3125 |
|
---|
3126 | /* undo */
|
---|
3127 | EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(hwnd, es) ? MF_ENABLED : MF_GRAYED));
|
---|
3128 | /* cut */
|
---|
3129 | EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & (ES_PASSWORD | ES_READONLY)) ? MF_ENABLED : MF_GRAYED));
|
---|
3130 | /* copy */
|
---|
3131 | EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
|
---|
3132 | /* paste */
|
---|
3133 | EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_TEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
|
---|
3134 | /* delete */
|
---|
3135 | EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
|
---|
3136 | /* select all */
|
---|
3137 | EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != lstrlenA(es->text)) ? MF_ENABLED : MF_GRAYED));
|
---|
3138 |
|
---|
3139 | TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, hwnd, NULL);
|
---|
3140 | DestroyMenu(menu);
|
---|
3141 | }
|
---|
3142 |
|
---|
3143 |
|
---|
3144 | /*********************************************************************
|
---|
3145 | *
|
---|
3146 | * WM_COPY
|
---|
3147 | *
|
---|
3148 | */
|
---|
3149 | static void EDIT_WM_Copy(HWND hwnd, EDITSTATE *es)
|
---|
3150 | {
|
---|
3151 | INT s = es->selection_start;
|
---|
3152 | INT e = es->selection_end;
|
---|
3153 | HGLOBAL hdst;
|
---|
3154 | LPSTR dst;
|
---|
3155 |
|
---|
3156 | if (e == s)
|
---|
3157 | return;
|
---|
3158 | ORDER_INT(s, e);
|
---|
3159 | hdst = GlobalAlloc(GMEM_MOVEABLE, (DWORD)(e - s + 1));
|
---|
3160 | dst = (LPSTR)GlobalLock(hdst);
|
---|
3161 | lstrcpynA(dst, es->text + s, e - s + 1);
|
---|
3162 | GlobalUnlock(hdst);
|
---|
3163 | OpenClipboard(hwnd);
|
---|
3164 | EmptyClipboard();
|
---|
3165 | SetClipboardData(CF_TEXT, hdst);
|
---|
3166 | CloseClipboard();
|
---|
3167 | }
|
---|
3168 |
|
---|
3169 |
|
---|
3170 | /*********************************************************************
|
---|
3171 | *
|
---|
3172 | * WM_CREATE
|
---|
3173 | *
|
---|
3174 | */
|
---|
3175 | static LRESULT EDIT_WM_Create(HWND hwnd, EDITSTATE *es, LPCREATESTRUCTA cs)
|
---|
3176 | {
|
---|
3177 | /*
|
---|
3178 | * To initialize some final structure members, we call some helper
|
---|
3179 | * functions. However, since the EDITSTATE is not consistent (i.e.
|
---|
3180 | * not fully initialized), we should be very careful which
|
---|
3181 | * functions can be called, and in what order.
|
---|
3182 | */
|
---|
3183 | EDIT_WM_SetFont(hwnd, es, 0, FALSE);
|
---|
3184 | EDIT_EM_EmptyUndoBuffer(hwnd, es);
|
---|
3185 | if (cs->lpszName && *(cs->lpszName) != '\0') {
|
---|
3186 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, cs->lpszName);
|
---|
3187 | /* if we insert text to the editline, the text scrolls out
|
---|
3188 | * of the window, as the caret is placed after the insert
|
---|
3189 | * pos normally; thus we reset es->selection... to 0 and
|
---|
3190 | * update caret
|
---|
3191 | */
|
---|
3192 | es->selection_start = es->selection_end = 0;
|
---|
3193 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
3194 | if (es->flags & EF_UPDATE) {
|
---|
3195 | es->flags &= ~EF_UPDATE;
|
---|
3196 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
3197 | }
|
---|
3198 | }
|
---|
3199 | return 0;
|
---|
3200 | }
|
---|
3201 |
|
---|
3202 |
|
---|
3203 | /*********************************************************************
|
---|
3204 | *
|
---|
3205 | * WM_DESTROY
|
---|
3206 | *
|
---|
3207 | */
|
---|
3208 | static void EDIT_WM_Destroy(HWND hwnd, EDITSTATE *es)
|
---|
3209 | {
|
---|
3210 | if (!es) /* Protect against multiple destroy messages */
|
---|
3211 | return;
|
---|
3212 |
|
---|
3213 | if (es->hloc) {
|
---|
3214 | while (LocalUnlock(es->hloc)) ;
|
---|
3215 | LocalFree(es->hloc);
|
---|
3216 | }
|
---|
3217 |
|
---|
3218 | HeapDestroy(es->heap);
|
---|
3219 | HeapFree(GetProcessHeap(), 0, es);
|
---|
3220 | SetInfoPtr(hwnd,0);
|
---|
3221 | }
|
---|
3222 |
|
---|
3223 |
|
---|
3224 | /*********************************************************************
|
---|
3225 | *
|
---|
3226 | * WM_ERASEBKGND
|
---|
3227 | *
|
---|
3228 | */
|
---|
3229 | static LRESULT EDIT_WM_EraseBkGnd(HWND hwnd, EDITSTATE *es, HDC dc)
|
---|
3230 | {
|
---|
3231 | HBRUSH brush;
|
---|
3232 | RECT rc;
|
---|
3233 |
|
---|
3234 | HideCaret(hwnd);
|
---|
3235 |
|
---|
3236 | if (!es->bEnableState || (es->style & ES_READONLY))
|
---|
3237 | brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, dc);
|
---|
3238 | else
|
---|
3239 | brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, dc);
|
---|
3240 |
|
---|
3241 | if (!brush)
|
---|
3242 | brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
---|
3243 |
|
---|
3244 | GetClientRect(hwnd, &rc);
|
---|
3245 | IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
|
---|
3246 | GetClipBox(dc, &rc);
|
---|
3247 | /*
|
---|
3248 | * FIXME: specs say that we should UnrealizeObject() the brush,
|
---|
3249 | * but the specs of UnrealizeObject() say that we shouldn't
|
---|
3250 | * unrealize a stock object. The default brush that
|
---|
3251 | * DefWndProc() returns is ... a stock object.
|
---|
3252 | */
|
---|
3253 | FillRect(dc, &rc, brush);
|
---|
3254 |
|
---|
3255 | ShowCaret(hwnd);
|
---|
3256 |
|
---|
3257 | return -1;
|
---|
3258 | }
|
---|
3259 |
|
---|
3260 |
|
---|
3261 | /*********************************************************************
|
---|
3262 | *
|
---|
3263 | * WM_GETTEXT
|
---|
3264 | *
|
---|
3265 | */
|
---|
3266 | static INT EDIT_WM_GetText(HWND hwnd, EDITSTATE *es, INT count, LPSTR text)
|
---|
3267 | {
|
---|
3268 | INT len;
|
---|
3269 |
|
---|
3270 | if (es->text == NULL) // the only case of failure i can imagine
|
---|
3271 | return 0;
|
---|
3272 |
|
---|
3273 | len = min(count, lstrlenA(es->text)+1); // determine length
|
---|
3274 | lstrcpynA(text, es->text, len); // copy as much as possible
|
---|
3275 | return len;
|
---|
3276 | }
|
---|
3277 |
|
---|
3278 |
|
---|
3279 | /*********************************************************************
|
---|
3280 | *
|
---|
3281 | * EDIT_HScroll_Hack
|
---|
3282 | *
|
---|
3283 | * 16 bit notepad needs this. Actually it is not _our_ hack,
|
---|
3284 | * it is notepad's. Notepad is sending us scrollbar messages with
|
---|
3285 | * undocumented parameters without us even having a scrollbar ... !?!?
|
---|
3286 | *
|
---|
3287 | */
|
---|
3288 | static LRESULT EDIT_HScroll_Hack(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
|
---|
3289 | {
|
---|
3290 | INT dx = 0;
|
---|
3291 | INT fw = es->format_rect.right - es->format_rect.left;
|
---|
3292 | LRESULT ret = 0;
|
---|
3293 |
|
---|
3294 | if (!(es->flags & EF_HSCROLL_HACK)) {
|
---|
3295 | //ERR_(edit)("hacked WM_HSCROLL handler invoked\n");
|
---|
3296 | //ERR_(edit)(" if you are _not_ running 16 bit notepad, please report\n");
|
---|
3297 | //ERR_(edit)(" (this message is only displayed once per edit control)\n");
|
---|
3298 | es->flags |= EF_HSCROLL_HACK;
|
---|
3299 | }
|
---|
3300 |
|
---|
3301 | switch (action) {
|
---|
3302 | case SB_LINELEFT:
|
---|
3303 | if (es->x_offset)
|
---|
3304 | dx = -es->char_width;
|
---|
3305 | break;
|
---|
3306 | case SB_LINERIGHT:
|
---|
3307 | if (es->x_offset < es->text_width)
|
---|
3308 | dx = es->char_width;
|
---|
3309 | break;
|
---|
3310 | case SB_PAGELEFT:
|
---|
3311 | if (es->x_offset)
|
---|
3312 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
|
---|
3313 | break;
|
---|
3314 | case SB_PAGERIGHT:
|
---|
3315 | if (es->x_offset < es->text_width)
|
---|
3316 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
|
---|
3317 | break;
|
---|
3318 | case SB_LEFT:
|
---|
3319 | if (es->x_offset)
|
---|
3320 | dx = -es->x_offset;
|
---|
3321 | break;
|
---|
3322 | case SB_RIGHT:
|
---|
3323 | if (es->x_offset < es->text_width)
|
---|
3324 | dx = es->text_width - es->x_offset;
|
---|
3325 | break;
|
---|
3326 | case SB_THUMBTRACK:
|
---|
3327 | es->flags |= EF_HSCROLL_TRACK;
|
---|
3328 | dx = pos * es->text_width / 100 - es->x_offset;
|
---|
3329 | break;
|
---|
3330 | case SB_THUMBPOSITION:
|
---|
3331 | es->flags &= ~EF_HSCROLL_TRACK;
|
---|
3332 | if (!(dx = pos * es->text_width / 100 - es->x_offset))
|
---|
3333 | EDIT_NOTIFY_PARENT(hwnd, EN_HSCROLL);
|
---|
3334 | break;
|
---|
3335 | case SB_ENDSCROLL:
|
---|
3336 | break;
|
---|
3337 |
|
---|
3338 | default:
|
---|
3339 | //ERR_(edit)("undocumented (hacked) WM_HSCROLL parameter, please report\n");
|
---|
3340 | return 0;
|
---|
3341 | }
|
---|
3342 | if (dx)
|
---|
3343 | EDIT_EM_LineScroll(hwnd, es, dx, 0);
|
---|
3344 | return ret;
|
---|
3345 | }
|
---|
3346 |
|
---|
3347 |
|
---|
3348 | /*********************************************************************
|
---|
3349 | *
|
---|
3350 | * WM_HSCROLL
|
---|
3351 | *
|
---|
3352 | */
|
---|
3353 | static LRESULT EDIT_WM_HScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
|
---|
3354 | {
|
---|
3355 | INT dx;
|
---|
3356 | INT fw;
|
---|
3357 |
|
---|
3358 | if (!(es->style & ES_MULTILINE))
|
---|
3359 | return 0;
|
---|
3360 |
|
---|
3361 | if (!(es->style & ES_AUTOHSCROLL))
|
---|
3362 | return 0;
|
---|
3363 |
|
---|
3364 | if (!(es->style & WS_HSCROLL))
|
---|
3365 | return EDIT_HScroll_Hack(hwnd, es, action, pos, scroll_bar);
|
---|
3366 |
|
---|
3367 | dx = 0;
|
---|
3368 | fw = es->format_rect.right - es->format_rect.left;
|
---|
3369 | switch (action) {
|
---|
3370 | case SB_LINELEFT:
|
---|
3371 | if (es->x_offset)
|
---|
3372 | dx = -es->char_width;
|
---|
3373 | break;
|
---|
3374 | case SB_LINERIGHT:
|
---|
3375 | if (es->x_offset < es->text_width)
|
---|
3376 | dx = es->char_width;
|
---|
3377 | break;
|
---|
3378 | case SB_PAGELEFT:
|
---|
3379 | if (es->x_offset)
|
---|
3380 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
|
---|
3381 | break;
|
---|
3382 | case SB_PAGERIGHT:
|
---|
3383 | if (es->x_offset < es->text_width)
|
---|
3384 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
|
---|
3385 | break;
|
---|
3386 | case SB_LEFT:
|
---|
3387 | if (es->x_offset)
|
---|
3388 | dx = -es->x_offset;
|
---|
3389 | break;
|
---|
3390 | case SB_RIGHT:
|
---|
3391 | if (es->x_offset < es->text_width)
|
---|
3392 | dx = es->text_width - es->x_offset;
|
---|
3393 | break;
|
---|
3394 | case SB_THUMBTRACK:
|
---|
3395 | es->flags |= EF_HSCROLL_TRACK;
|
---|
3396 | dx = pos - es->x_offset;
|
---|
3397 | break;
|
---|
3398 | case SB_THUMBPOSITION:
|
---|
3399 | es->flags &= ~EF_HSCROLL_TRACK;
|
---|
3400 | if (!(dx = pos - es->x_offset)) {
|
---|
3401 | SetScrollPos(hwnd, SB_HORZ, pos, TRUE);
|
---|
3402 | EDIT_NOTIFY_PARENT(hwnd, EN_HSCROLL);
|
---|
3403 | }
|
---|
3404 | break;
|
---|
3405 | case SB_ENDSCROLL:
|
---|
3406 | break;
|
---|
3407 |
|
---|
3408 | default:
|
---|
3409 | //ERR_(edit)("undocumented WM_HSCROLL parameter, please report\n");
|
---|
3410 | return 0;
|
---|
3411 | }
|
---|
3412 | if (dx)
|
---|
3413 | EDIT_EM_LineScroll(hwnd, es, dx, 0);
|
---|
3414 | return 0;
|
---|
3415 | }
|
---|
3416 |
|
---|
3417 |
|
---|
3418 | /*********************************************************************
|
---|
3419 | *
|
---|
3420 | * EDIT_CheckCombo
|
---|
3421 | *
|
---|
3422 | */
|
---|
3423 | static BOOL EDIT_CheckCombo(HWND hwnd, EDITSTATE *es, UINT msg, INT key, DWORD key_data)
|
---|
3424 | {
|
---|
3425 | HWND hLBox = es->hwndListBox;
|
---|
3426 | HWND hCombo;
|
---|
3427 | BOOL bDropped;
|
---|
3428 | int nEUI;
|
---|
3429 |
|
---|
3430 | if (!hLBox)
|
---|
3431 | return FALSE;
|
---|
3432 |
|
---|
3433 | hCombo = GetParent(hwnd);
|
---|
3434 | bDropped = TRUE;
|
---|
3435 | nEUI = 0;
|
---|
3436 |
|
---|
3437 | //TRACE_(combo)("[%04x]: handling msg %04x (%04x)\n",
|
---|
3438 | // wnd->hwndSelf, (UINT16)msg, (UINT16)key);
|
---|
3439 |
|
---|
3440 | if (key == VK_UP || key == VK_DOWN)
|
---|
3441 | {
|
---|
3442 | if (SendMessageA(hCombo, CB_GETEXTENDEDUI, 0, 0))
|
---|
3443 | nEUI = 1;
|
---|
3444 |
|
---|
3445 | if (msg == WM_KEYDOWN || nEUI)
|
---|
3446 | bDropped = (BOOL)SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0);
|
---|
3447 | }
|
---|
3448 |
|
---|
3449 | switch (msg)
|
---|
3450 | {
|
---|
3451 | case WM_KEYDOWN:
|
---|
3452 | if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN))
|
---|
3453 | {
|
---|
3454 | /* make sure ComboLBox pops up */
|
---|
3455 | SendMessageA(hCombo, CB_SETEXTENDEDUI, FALSE, 0);
|
---|
3456 | key = VK_F4;
|
---|
3457 | nEUI = 2;
|
---|
3458 | }
|
---|
3459 |
|
---|
3460 | SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
|
---|
3461 | break;
|
---|
3462 |
|
---|
3463 | case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
|
---|
3464 | if (nEUI)
|
---|
3465 | SendMessageA(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0);
|
---|
3466 | else
|
---|
3467 | SendMessageA(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0);
|
---|
3468 | break;
|
---|
3469 | }
|
---|
3470 |
|
---|
3471 | if(nEUI == 2)
|
---|
3472 | SendMessageA(hCombo, CB_SETEXTENDEDUI, TRUE, 0);
|
---|
3473 |
|
---|
3474 | return TRUE;
|
---|
3475 | }
|
---|
3476 |
|
---|
3477 | /*********************************************************************
|
---|
3478 | *
|
---|
3479 | * WM_KEYDOWN
|
---|
3480 | *
|
---|
3481 | * Handling of special keys that don't produce a WM_CHAR
|
---|
3482 | * (i.e. non-printable keys) & Backspace & Delete
|
---|
3483 | *
|
---|
3484 | */
|
---|
3485 | static LRESULT EDIT_WM_KeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data)
|
---|
3486 | {
|
---|
3487 | BOOL shift;
|
---|
3488 | BOOL control;
|
---|
3489 |
|
---|
3490 | if (GetKeyState(VK_MENU) & 0x8000)
|
---|
3491 | return 0;
|
---|
3492 |
|
---|
3493 | shift = GetKeyState(VK_SHIFT) & 0x8000;
|
---|
3494 | control = GetKeyState(VK_CONTROL) & 0x8000;
|
---|
3495 |
|
---|
3496 | switch (key) {
|
---|
3497 | case VK_F4:
|
---|
3498 | case VK_UP:
|
---|
3499 | if (EDIT_CheckCombo(hwnd,es, WM_KEYDOWN, key, key_data) || key == VK_F4)
|
---|
3500 | break;
|
---|
3501 | /* fall through */
|
---|
3502 | case VK_LEFT:
|
---|
3503 | if ((es->style & ES_MULTILINE) && (key == VK_UP))
|
---|
3504 | EDIT_MoveUp_ML(hwnd, es, shift);
|
---|
3505 | else
|
---|
3506 | if (control)
|
---|
3507 | EDIT_MoveWordBackward(hwnd, es, shift);
|
---|
3508 | else
|
---|
3509 | EDIT_MoveBackward(hwnd, es, shift);
|
---|
3510 | break;
|
---|
3511 | case VK_DOWN:
|
---|
3512 | if (EDIT_CheckCombo(hwnd,es, WM_KEYDOWN, key, key_data))
|
---|
3513 | break;
|
---|
3514 | /* fall through */
|
---|
3515 | case VK_RIGHT:
|
---|
3516 | if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
|
---|
3517 | EDIT_MoveDown_ML(hwnd, es, shift);
|
---|
3518 | else if (control)
|
---|
3519 | EDIT_MoveWordForward(hwnd, es, shift);
|
---|
3520 | else
|
---|
3521 | EDIT_MoveForward(hwnd, es, shift);
|
---|
3522 | break;
|
---|
3523 | case VK_HOME:
|
---|
3524 | EDIT_MoveHome(hwnd, es, shift);
|
---|
3525 | break;
|
---|
3526 | case VK_END:
|
---|
3527 | EDIT_MoveEnd(hwnd, es, shift);
|
---|
3528 | break;
|
---|
3529 | case VK_PRIOR:
|
---|
3530 | if (es->style & ES_MULTILINE)
|
---|
3531 | EDIT_MovePageUp_ML(hwnd, es, shift);
|
---|
3532 | else
|
---|
3533 | EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key, key_data);
|
---|
3534 | break;
|
---|
3535 | case VK_NEXT:
|
---|
3536 | if (es->style & ES_MULTILINE)
|
---|
3537 | EDIT_MovePageDown_ML(hwnd, es, shift);
|
---|
3538 | else
|
---|
3539 | EDIT_CheckCombo(hwnd, es, WM_KEYDOWN, key, key_data);
|
---|
3540 | break;
|
---|
3541 | case VK_DELETE:
|
---|
3542 | if (!(es->style & ES_READONLY) && !(shift && control)) {
|
---|
3543 | if (es->selection_start != es->selection_end) {
|
---|
3544 | if (shift)
|
---|
3545 | EDIT_WM_Cut(hwnd, es);
|
---|
3546 | else
|
---|
3547 | EDIT_WM_Clear(hwnd, es);
|
---|
3548 | } else {
|
---|
3549 | if (shift) {
|
---|
3550 | /* delete character left of caret */
|
---|
3551 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE);
|
---|
3552 | EDIT_MoveBackward(hwnd, es, TRUE);
|
---|
3553 | EDIT_WM_Clear(hwnd, es);
|
---|
3554 | } else if (control) {
|
---|
3555 | /* delete to end of line */
|
---|
3556 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE);
|
---|
3557 | EDIT_MoveEnd(hwnd, es, TRUE);
|
---|
3558 | EDIT_WM_Clear(hwnd, es);
|
---|
3559 | } else {
|
---|
3560 | /* delete character right of caret */
|
---|
3561 | EDIT_EM_SetSel(hwnd, es, -1, 0, FALSE);
|
---|
3562 | EDIT_MoveForward(hwnd, es, TRUE);
|
---|
3563 | EDIT_WM_Clear(hwnd, es);
|
---|
3564 | }
|
---|
3565 | }
|
---|
3566 | }
|
---|
3567 | break;
|
---|
3568 | case VK_INSERT:
|
---|
3569 | if (shift) {
|
---|
3570 | if (!(es->style & ES_READONLY))
|
---|
3571 | EDIT_WM_Paste(hwnd, es);
|
---|
3572 | } else if (control)
|
---|
3573 | EDIT_WM_Copy(hwnd, es);
|
---|
3574 | break;
|
---|
3575 | case VK_RETURN:
|
---|
3576 | /* If the edit doesn't want the return send a message to the default object */
|
---|
3577 | if(!(es->style & ES_WANTRETURN))
|
---|
3578 | {
|
---|
3579 | HWND hwndParent = GetParent(hwnd);
|
---|
3580 | DWORD dw = SendMessageA( hwndParent, DM_GETDEFID, 0, 0 );
|
---|
3581 | if (HIWORD(dw) == DC_HASDEFID)
|
---|
3582 | {
|
---|
3583 | SendMessageA( hwndParent, WM_COMMAND,
|
---|
3584 | MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
|
---|
3585 | (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
|
---|
3586 | }
|
---|
3587 | }
|
---|
3588 | break;
|
---|
3589 | }
|
---|
3590 | return 0;
|
---|
3591 | }
|
---|
3592 |
|
---|
3593 |
|
---|
3594 | /*********************************************************************
|
---|
3595 | *
|
---|
3596 | * WM_KILLFOCUS
|
---|
3597 | *
|
---|
3598 | */
|
---|
3599 | static LRESULT EDIT_WM_KillFocus(HWND hwnd, EDITSTATE *es, HWND window_getting_focus)
|
---|
3600 | {
|
---|
3601 | es->flags &= ~EF_FOCUSED;
|
---|
3602 | DestroyCaret();
|
---|
3603 | if(!(es->style & ES_NOHIDESEL))
|
---|
3604 | EDIT_InvalidateText(hwnd, es, es->selection_start, es->selection_end);
|
---|
3605 | EDIT_NOTIFY_PARENT(hwnd, EN_KILLFOCUS);
|
---|
3606 | return 0;
|
---|
3607 | }
|
---|
3608 |
|
---|
3609 |
|
---|
3610 | /*********************************************************************
|
---|
3611 | *
|
---|
3612 | * WM_LBUTTONDBLCLK
|
---|
3613 | *
|
---|
3614 | * The caret position has been set on the WM_LBUTTONDOWN message
|
---|
3615 | *
|
---|
3616 | */
|
---|
3617 | static LRESULT EDIT_WM_LButtonDblClk(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y)
|
---|
3618 | {
|
---|
3619 | INT s;
|
---|
3620 | INT e = es->selection_end;
|
---|
3621 | INT l;
|
---|
3622 | INT li;
|
---|
3623 | INT ll;
|
---|
3624 |
|
---|
3625 | if (!(es->flags & EF_FOCUSED))
|
---|
3626 | return 0;
|
---|
3627 |
|
---|
3628 | l = EDIT_EM_LineFromChar(hwnd, es, e);
|
---|
3629 | li = EDIT_EM_LineIndex(hwnd, es, l);
|
---|
3630 | ll = EDIT_EM_LineLength(hwnd, es, e);
|
---|
3631 | s = li + EDIT_CallWordBreakProc (hwnd, es, li, e - li, ll, WB_LEFT);
|
---|
3632 | e = li + EDIT_CallWordBreakProc(hwnd, es, li, e - li, ll, WB_RIGHT);
|
---|
3633 | EDIT_EM_SetSel(hwnd, es, s, e, FALSE);
|
---|
3634 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
3635 | return 0;
|
---|
3636 | }
|
---|
3637 |
|
---|
3638 |
|
---|
3639 | /*********************************************************************
|
---|
3640 | *
|
---|
3641 | * WM_LBUTTONDOWN
|
---|
3642 | *
|
---|
3643 | */
|
---|
3644 | static LRESULT EDIT_WM_LButtonDown(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y)
|
---|
3645 | {
|
---|
3646 | INT e;
|
---|
3647 | BOOL after_wrap;
|
---|
3648 |
|
---|
3649 | if (!(es->flags & EF_FOCUSED))
|
---|
3650 | SetFocus(hwnd);
|
---|
3651 |
|
---|
3652 | es->bCaptureState = TRUE;
|
---|
3653 | SetCapture(hwnd);
|
---|
3654 | EDIT_ConfinePoint(hwnd, es, &x, &y);
|
---|
3655 | e = EDIT_CharFromPos(hwnd, es, x, y, &after_wrap);
|
---|
3656 | EDIT_EM_SetSel(hwnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
|
---|
3657 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
3658 | es->region_posx = es->region_posy = 0;
|
---|
3659 | SetTimer(hwnd, 0, 100, NULL);
|
---|
3660 | return 0;
|
---|
3661 | }
|
---|
3662 |
|
---|
3663 |
|
---|
3664 | /*********************************************************************
|
---|
3665 | *
|
---|
3666 | * WM_LBUTTONUP
|
---|
3667 | *
|
---|
3668 | */
|
---|
3669 | static LRESULT EDIT_WM_LButtonUp(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y)
|
---|
3670 | {
|
---|
3671 | if (es->bCaptureState)
|
---|
3672 | {
|
---|
3673 | KillTimer(hwnd,0);
|
---|
3674 | ReleaseCapture();
|
---|
3675 | }
|
---|
3676 | es->bCaptureState = FALSE;
|
---|
3677 |
|
---|
3678 | return 0;
|
---|
3679 | }
|
---|
3680 |
|
---|
3681 | static LRESULT EDIT_WM_CaptureChanged(HWND hwnd,EDITSTATE *es)
|
---|
3682 | {
|
---|
3683 | if (es->bCaptureState) KillTimer(hwnd,0);
|
---|
3684 | es->bCaptureState = FALSE;
|
---|
3685 |
|
---|
3686 | return 0;
|
---|
3687 | }
|
---|
3688 |
|
---|
3689 | /*********************************************************************
|
---|
3690 | *
|
---|
3691 | * WM_MOUSEMOVE
|
---|
3692 | *
|
---|
3693 | */
|
---|
3694 | static LRESULT EDIT_WM_MouseMove(HWND hwnd, EDITSTATE *es, DWORD keys, INT x, INT y)
|
---|
3695 | {
|
---|
3696 | INT e;
|
---|
3697 | BOOL after_wrap;
|
---|
3698 | INT prex, prey;
|
---|
3699 |
|
---|
3700 | if (!es->bCaptureState) return 0;
|
---|
3701 |
|
---|
3702 | /*
|
---|
3703 | * FIXME: gotta do some scrolling if outside client
|
---|
3704 | * area. Maybe reset the timer ?
|
---|
3705 | */
|
---|
3706 | prex = x; prey = y;
|
---|
3707 | EDIT_ConfinePoint(hwnd, es, &x, &y);
|
---|
3708 | es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
|
---|
3709 | es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
|
---|
3710 | e = EDIT_CharFromPos(hwnd, es, x, y, &after_wrap);
|
---|
3711 | EDIT_EM_SetSel(hwnd, es, es->selection_start, e, after_wrap);
|
---|
3712 |
|
---|
3713 | return 0;
|
---|
3714 | }
|
---|
3715 |
|
---|
3716 |
|
---|
3717 | /*********************************************************************
|
---|
3718 | *
|
---|
3719 | * WM_NCCREATE
|
---|
3720 | *
|
---|
3721 | */
|
---|
3722 | static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTA cs)
|
---|
3723 | {
|
---|
3724 | EDITSTATE *es;
|
---|
3725 |
|
---|
3726 | if (!(es = (EDITSTATE*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
|
---|
3727 | return FALSE;
|
---|
3728 | SetInfoPtr(hwnd,(DWORD)es);
|
---|
3729 |
|
---|
3730 | /*
|
---|
3731 | * Note: since the EDITSTATE has not been fully initialized yet,
|
---|
3732 | * we can't use any API calls that may send
|
---|
3733 | * WM_XXX messages before WM_NCCREATE is completed.
|
---|
3734 | */
|
---|
3735 |
|
---|
3736 | if (!(es->heap = HeapCreate(0, 0x10000, 0)))
|
---|
3737 | return FALSE;
|
---|
3738 | es->style = cs->style;
|
---|
3739 |
|
---|
3740 | es->bEnableState = !(cs->style & WS_DISABLED);
|
---|
3741 |
|
---|
3742 | /*
|
---|
3743 | * In Win95 look and feel, the WS_BORDER style is replaced by the
|
---|
3744 | * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
|
---|
3745 | * control a non client area.
|
---|
3746 | */
|
---|
3747 | if (es->style & WS_BORDER)
|
---|
3748 | {
|
---|
3749 | es->style &= ~WS_BORDER;
|
---|
3750 | SetWindowLongA(hwnd,GWL_STYLE,GetWindowLongA(hwnd,GWL_STYLE) & ~WS_BORDER);
|
---|
3751 | SetWindowLongA(hwnd,GWL_EXSTYLE,GetWindowLongA(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE);
|
---|
3752 | }
|
---|
3753 |
|
---|
3754 | if (es->style & ES_COMBO)
|
---|
3755 | es->hwndListBox = GetDlgItem(cs->hwndParent, ID_CB_LISTBOX);
|
---|
3756 |
|
---|
3757 | if (es->style & ES_MULTILINE) {
|
---|
3758 | es->buffer_size = BUFSTART_MULTI;
|
---|
3759 | es->buffer_limit = BUFLIMIT_MULTI;
|
---|
3760 | if (es->style & WS_VSCROLL)
|
---|
3761 | es->style |= ES_AUTOVSCROLL;
|
---|
3762 | if (es->style & WS_HSCROLL)
|
---|
3763 | es->style |= ES_AUTOHSCROLL;
|
---|
3764 | es->style &= ~ES_PASSWORD;
|
---|
3765 | if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
|
---|
3766 | if (es->style & ES_RIGHT)
|
---|
3767 | es->style &= ~ES_CENTER;
|
---|
3768 | es->style &= ~WS_HSCROLL;
|
---|
3769 | es->style &= ~ES_AUTOHSCROLL;
|
---|
3770 | }
|
---|
3771 |
|
---|
3772 | /* FIXME: for now, all multi line controls are AUTOVSCROLL */
|
---|
3773 | es->style |= ES_AUTOVSCROLL;
|
---|
3774 | } else {
|
---|
3775 | es->buffer_size = BUFSTART_SINGLE;
|
---|
3776 | es->buffer_limit = BUFLIMIT_SINGLE;
|
---|
3777 | es->style &= ~ES_CENTER;
|
---|
3778 | es->style &= ~ES_RIGHT;
|
---|
3779 | es->style &= ~WS_HSCROLL;
|
---|
3780 | es->style &= ~WS_VSCROLL;
|
---|
3781 | es->style &= ~ES_AUTOVSCROLL;
|
---|
3782 | es->style &= ~ES_WANTRETURN;
|
---|
3783 | if (es->style & ES_UPPERCASE) {
|
---|
3784 | es->style &= ~ES_LOWERCASE;
|
---|
3785 | es->style &= ~ES_NUMBER;
|
---|
3786 | } else if (es->style & ES_LOWERCASE)
|
---|
3787 | es->style &= ~ES_NUMBER;
|
---|
3788 | if (es->style & ES_PASSWORD)
|
---|
3789 | es->password_char = '*';
|
---|
3790 |
|
---|
3791 | /* FIXME: for now, all single line controls are AUTOHSCROLL */
|
---|
3792 | es->style |= ES_AUTOHSCROLL;
|
---|
3793 | }
|
---|
3794 | if (!(es->text = (char*)HeapAlloc(es->heap, 0, es->buffer_size + 1)))
|
---|
3795 | return FALSE;
|
---|
3796 | es->buffer_size = HeapSize(es->heap, 0, es->text) - 1;
|
---|
3797 | if (!(es->undo_text = (char*)HeapAlloc(es->heap, 0, es->buffer_size + 1)))
|
---|
3798 | return FALSE;
|
---|
3799 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1;
|
---|
3800 | *es->text = '\0';
|
---|
3801 | if (es->style & ES_MULTILINE)
|
---|
3802 | if (!(es->first_line_def = (LINEDEF*)HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
|
---|
3803 | return FALSE;
|
---|
3804 | es->line_count = 1;
|
---|
3805 |
|
---|
3806 | return TRUE;
|
---|
3807 | }
|
---|
3808 |
|
---|
3809 | static VOID EDIT_Draw(HWND hwnd,EDITSTATE *es,HDC hdc,BOOL eraseBkGnd)
|
---|
3810 | {
|
---|
3811 | INT i;
|
---|
3812 | HFONT old_font = 0;
|
---|
3813 | RECT rc;
|
---|
3814 | RECT rcLine;
|
---|
3815 | RECT rcRgn;
|
---|
3816 | BOOL rev = es->bEnableState && ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL));
|
---|
3817 |
|
---|
3818 | HideCaret(hwnd);
|
---|
3819 |
|
---|
3820 | if (eraseBkGnd)
|
---|
3821 | {
|
---|
3822 | HBRUSH brush;
|
---|
3823 |
|
---|
3824 | if (!es->bEnableState || (es->style & ES_READONLY))
|
---|
3825 | brush = (HBRUSH)EDIT_SEND_CTLCOLORSTATIC(hwnd, hdc);
|
---|
3826 | else
|
---|
3827 | brush = (HBRUSH)EDIT_SEND_CTLCOLOR(hwnd, hdc);
|
---|
3828 |
|
---|
3829 | if (!brush)
|
---|
3830 | brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
---|
3831 |
|
---|
3832 | GetClientRect(hwnd, &rc);
|
---|
3833 | /*
|
---|
3834 | * FIXME: specs say that we should UnrealizeObject() the brush,
|
---|
3835 | * but the specs of UnrealizeObject() say that we shouldn't
|
---|
3836 | * unrealize a stock object. The default brush that
|
---|
3837 | * DefWndProc() returns is ... a stock object.
|
---|
3838 | */
|
---|
3839 | FillRect(hdc, &rc, brush);
|
---|
3840 | }
|
---|
3841 |
|
---|
3842 | if(es->style & WS_BORDER)
|
---|
3843 | {
|
---|
3844 | GetClientRect(hwnd, &rc);
|
---|
3845 | if(es->style & ES_MULTILINE)
|
---|
3846 | {
|
---|
3847 | if(es->style & WS_HSCROLL) rc.bottom++;
|
---|
3848 | if(es->style & WS_VSCROLL) rc.right++;
|
---|
3849 | }
|
---|
3850 | Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
|
---|
3851 | }
|
---|
3852 |
|
---|
3853 | IntersectClipRect(hdc, es->format_rect.left,
|
---|
3854 | es->format_rect.top,
|
---|
3855 | es->format_rect.right,
|
---|
3856 | es->format_rect.bottom);
|
---|
3857 | if (es->style & ES_MULTILINE)
|
---|
3858 | {
|
---|
3859 | GetClientRect(hwnd, &rc);
|
---|
3860 | IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);
|
---|
3861 | }
|
---|
3862 | if (es->font) old_font = SelectObject(hdc, es->font);
|
---|
3863 | if (!es->bEnableState || (es->style & ES_READONLY))
|
---|
3864 | EDIT_SEND_CTLCOLORSTATIC(hwnd, hdc);
|
---|
3865 | else
|
---|
3866 | EDIT_SEND_CTLCOLOR(hwnd, hdc);
|
---|
3867 | if (!es->bEnableState)
|
---|
3868 | SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
|
---|
3869 | GetClipBox(hdc, &rcRgn);
|
---|
3870 | if (es->style & ES_MULTILINE)
|
---|
3871 | {
|
---|
3872 | INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
|
---|
3873 |
|
---|
3874 | for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++)
|
---|
3875 | {
|
---|
3876 | EDIT_GetLineRect(hwnd,hdc, es, i, 0, -1, &rcLine);
|
---|
3877 | if (IntersectRect(&rc, &rcRgn, &rcLine))
|
---|
3878 | EDIT_PaintLine(hwnd, es, hdc, i, rev);
|
---|
3879 | }
|
---|
3880 | } else
|
---|
3881 | {
|
---|
3882 | EDIT_GetLineRect(hwnd,hdc, es, 0, 0, -1, &rcLine);
|
---|
3883 | if (IntersectRect(&rc, &rcRgn, &rcLine))
|
---|
3884 | EDIT_PaintLine(hwnd, es, hdc, 0, rev);
|
---|
3885 | }
|
---|
3886 | if (es->font) SelectObject(hdc, old_font);
|
---|
3887 | if (es->flags & EF_FOCUSED)
|
---|
3888 | EDIT_SetCaretPos(hwnd, es, es->selection_end,es->flags & EF_AFTER_WRAP);
|
---|
3889 |
|
---|
3890 | ShowCaret(hwnd);
|
---|
3891 | }
|
---|
3892 |
|
---|
3893 | static VOID EDIT_Refresh(HWND hwnd,EDITSTATE *es,BOOL useCache)
|
---|
3894 | {
|
---|
3895 | HDC hdc,hdcCompatible;
|
---|
3896 | HBITMAP bitmap,oldbmp;
|
---|
3897 | RECT rect;
|
---|
3898 |
|
---|
3899 | if (es->flags & EF_UPDATE)
|
---|
3900 | {
|
---|
3901 | //CB: don't reset flag or EN_CHANGE is lost!
|
---|
3902 | //es->flags &= ~EF_UPDATE;
|
---|
3903 | EDIT_NOTIFY_PARENT(hwnd,EN_UPDATE);
|
---|
3904 | }
|
---|
3905 |
|
---|
3906 | if (!IsWindowVisible(hwnd)) return;
|
---|
3907 |
|
---|
3908 | if (!useCache)
|
---|
3909 | {
|
---|
3910 | InvalidateRect(hwnd,NULL,TRUE);
|
---|
3911 | return;
|
---|
3912 | }
|
---|
3913 |
|
---|
3914 | //CB: original control redraws many times, cache drawing
|
---|
3915 | HideCaret(hwnd);
|
---|
3916 | GetClientRect(hwnd,&rect);
|
---|
3917 | hdc = GetDC(hwnd);
|
---|
3918 | hdcCompatible = CreateCompatibleDC(hdc);
|
---|
3919 | bitmap = CreateCompatibleBitmap(hdc,rect.right,rect.bottom);
|
---|
3920 | oldbmp = SelectObject(hdcCompatible,bitmap);
|
---|
3921 | EDIT_Draw(hwnd,es,hdcCompatible,TRUE);
|
---|
3922 | SelectClipRgn(hdcCompatible,0);
|
---|
3923 | BitBlt(hdc,0,0,rect.right,rect.bottom,hdcCompatible,0,0,SRCCOPY);
|
---|
3924 | SelectObject(hdcCompatible,oldbmp);
|
---|
3925 | DeleteObject(bitmap);
|
---|
3926 | DeleteDC(hdcCompatible);
|
---|
3927 | ReleaseDC(hwnd,hdc);
|
---|
3928 | ShowCaret(hwnd);
|
---|
3929 | }
|
---|
3930 |
|
---|
3931 | /*********************************************************************
|
---|
3932 | *
|
---|
3933 | * WM_PAINT
|
---|
3934 | *
|
---|
3935 | */
|
---|
3936 | static void EDIT_WM_Paint(HWND hwnd, EDITSTATE *es,WPARAM wParam)
|
---|
3937 | {
|
---|
3938 | PAINTSTRUCT ps;
|
---|
3939 | HDC hdc;
|
---|
3940 |
|
---|
3941 | if (!wParam) hdc = BeginPaint(hwnd, &ps);
|
---|
3942 | else hdc = (HDC) wParam;
|
---|
3943 |
|
---|
3944 | EDIT_Draw(hwnd,es,hdc,FALSE);
|
---|
3945 |
|
---|
3946 | if (!wParam) EndPaint(hwnd, &ps);
|
---|
3947 | }
|
---|
3948 |
|
---|
3949 |
|
---|
3950 | /*********************************************************************
|
---|
3951 | *
|
---|
3952 | * WM_PASTE
|
---|
3953 | *
|
---|
3954 | */
|
---|
3955 | static void EDIT_WM_Paste(HWND hwnd, EDITSTATE *es)
|
---|
3956 | {
|
---|
3957 | HGLOBAL hsrc;
|
---|
3958 | LPSTR src;
|
---|
3959 |
|
---|
3960 | OpenClipboard(hwnd);
|
---|
3961 | hsrc = GetClipboardData(CF_TEXT);
|
---|
3962 | if (hsrc) {
|
---|
3963 | src = (LPSTR)GlobalLock(hsrc);
|
---|
3964 | EDIT_EM_ReplaceSel(hwnd, es, TRUE, src);
|
---|
3965 | GlobalUnlock(hsrc);
|
---|
3966 |
|
---|
3967 | if (es->flags & EF_UPDATE) {
|
---|
3968 | es->flags &= ~EF_UPDATE;
|
---|
3969 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
3970 | }
|
---|
3971 | }
|
---|
3972 | CloseClipboard();
|
---|
3973 | }
|
---|
3974 |
|
---|
3975 |
|
---|
3976 | /*********************************************************************
|
---|
3977 | *
|
---|
3978 | * WM_SETFOCUS
|
---|
3979 | *
|
---|
3980 | */
|
---|
3981 | static void EDIT_WM_SetFocus(HWND hwnd, EDITSTATE *es, HWND window_losing_focus)
|
---|
3982 | {
|
---|
3983 | es->flags |= EF_FOCUSED;
|
---|
3984 | CreateCaret(hwnd, 0, 2, es->line_height);
|
---|
3985 | EDIT_SetCaretPos(hwnd, es, es->selection_end,
|
---|
3986 | es->flags & EF_AFTER_WRAP);
|
---|
3987 | if(!(es->style & ES_NOHIDESEL))
|
---|
3988 | EDIT_InvalidateText(hwnd, es, es->selection_start, es->selection_end);
|
---|
3989 | ShowCaret(hwnd);
|
---|
3990 | EDIT_NOTIFY_PARENT(hwnd, EN_SETFOCUS);
|
---|
3991 | }
|
---|
3992 |
|
---|
3993 | /*********************************************************************
|
---|
3994 | *
|
---|
3995 | * WM_SETFONT
|
---|
3996 | *
|
---|
3997 | * With Win95 look the margins are set to default font value unless
|
---|
3998 | * the system font (font == 0) is being set, in which case they are left
|
---|
3999 | * unchanged.
|
---|
4000 | *
|
---|
4001 | */
|
---|
4002 | static void EDIT_WM_SetFont(HWND hwnd, EDITSTATE *es, HFONT font, BOOL redraw)
|
---|
4003 | {
|
---|
4004 | TEXTMETRICA tm;
|
---|
4005 | HDC dc;
|
---|
4006 | HFONT old_font = 0;
|
---|
4007 | RECT r;
|
---|
4008 |
|
---|
4009 | dc = GetDC(hwnd);
|
---|
4010 | if (font)
|
---|
4011 | old_font = SelectObject(dc, font);
|
---|
4012 | if (!GetTextMetricsA(dc, &tm))
|
---|
4013 | {
|
---|
4014 | if (font) SelectObject(dc,old_font);
|
---|
4015 | ReleaseDC(hwnd,dc);
|
---|
4016 |
|
---|
4017 | return;
|
---|
4018 | }
|
---|
4019 | es->font = font;
|
---|
4020 | es->line_height = tm.tmHeight;
|
---|
4021 |
|
---|
4022 | es->char_width = tm.tmAveCharWidth;
|
---|
4023 | if (font)
|
---|
4024 | SelectObject(dc, old_font);
|
---|
4025 | ReleaseDC(hwnd, dc);
|
---|
4026 | if (font)
|
---|
4027 | EDIT_EM_SetMargins(hwnd, es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
|
---|
4028 | EC_USEFONTINFO, EC_USEFONTINFO);
|
---|
4029 | /* Force the recalculation of the format rect for each font change */
|
---|
4030 | GetClientRect(hwnd, &r);
|
---|
4031 | EDIT_SetRectNP(hwnd, es, &r);
|
---|
4032 | if (es->style & ES_MULTILINE)
|
---|
4033 | EDIT_BuildLineDefs_ML(hwnd,es);
|
---|
4034 |
|
---|
4035 | if (redraw)
|
---|
4036 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
4037 | if (es->flags & EF_FOCUSED) {
|
---|
4038 | DestroyCaret();
|
---|
4039 | CreateCaret(hwnd, 0, 2, es->line_height);
|
---|
4040 | EDIT_SetCaretPos(hwnd, es, es->selection_end,
|
---|
4041 | es->flags & EF_AFTER_WRAP);
|
---|
4042 | ShowCaret(hwnd);
|
---|
4043 | }
|
---|
4044 | }
|
---|
4045 |
|
---|
4046 |
|
---|
4047 | /*********************************************************************
|
---|
4048 | *
|
---|
4049 | * WM_SETTEXT
|
---|
4050 | *
|
---|
4051 | * NOTES
|
---|
4052 | * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
|
---|
4053 | * The modified flag is reset. No notifications are sent.
|
---|
4054 | *
|
---|
4055 | * For single-line controls, reception of WM_SETTEXT triggers:
|
---|
4056 | * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
|
---|
4057 | *
|
---|
4058 | */
|
---|
4059 | static void EDIT_WM_SetText(HWND hwnd, EDITSTATE *es, LPCSTR text)
|
---|
4060 | {
|
---|
4061 | #ifdef __WIN32OS2__
|
---|
4062 | //SvL: Acrobat Distiller keeps on sending WM_SETTEXT with the same
|
---|
4063 | // string in responds to a WM_COMMAND with EN_UPDATE -> stack
|
---|
4064 | // overflow (TODO: Need to check if this behaviour is correct compared to NT)
|
---|
4065 | if(text && es->text) {
|
---|
4066 | if(!strcmp(es->text, text)) {
|
---|
4067 | return;
|
---|
4068 | }
|
---|
4069 | }
|
---|
4070 | #endif
|
---|
4071 | es->selection_start = 0;
|
---|
4072 | es->selection_end = lstrlenA(es->text);
|
---|
4073 | if (es->flags & EF_FOCUSED)
|
---|
4074 | EDIT_SetCaretPos(hwnd, es, es->selection_end, FALSE);
|
---|
4075 |
|
---|
4076 | if (text) {
|
---|
4077 | //TRACE_(edit)("\t'%s'\n", text);
|
---|
4078 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, text);
|
---|
4079 | } else {
|
---|
4080 | //TRACE_(edit)("\t<NULL>\n");
|
---|
4081 | EDIT_EM_ReplaceSel(hwnd, es, FALSE, "");
|
---|
4082 | }
|
---|
4083 | es->x_offset = 0;
|
---|
4084 | if (es->style & ES_MULTILINE) {
|
---|
4085 | es->flags &= ~EF_UPDATE;
|
---|
4086 | } else {
|
---|
4087 | es->flags |= EF_UPDATE;
|
---|
4088 | }
|
---|
4089 | es->flags &= ~EF_MODIFIED;
|
---|
4090 | EDIT_EM_SetSel(hwnd, es, 0, 0, FALSE);
|
---|
4091 | EDIT_EM_ScrollCaret(hwnd, es);
|
---|
4092 | EDIT_UpdateScrollBars(hwnd,es,TRUE,TRUE);
|
---|
4093 | if (es->flags & EF_UPDATE)
|
---|
4094 | {
|
---|
4095 | EDIT_NOTIFY_PARENT(hwnd,EN_UPDATE);
|
---|
4096 | /* EN_CHANGE notification need to be sent too
|
---|
4097 | Windows doc says it's only done after the display,
|
---|
4098 | the doc is WRONG. EN_CHANGE notification is sent
|
---|
4099 | while processing WM_SETTEXT */
|
---|
4100 | EDIT_NOTIFY_PARENT(hwnd, EN_CHANGE);
|
---|
4101 | es->flags &= ~EF_UPDATE;
|
---|
4102 | }
|
---|
4103 | }
|
---|
4104 |
|
---|
4105 |
|
---|
4106 | /*********************************************************************
|
---|
4107 | *
|
---|
4108 | * WM_SIZE
|
---|
4109 | *
|
---|
4110 | */
|
---|
4111 | static void EDIT_WM_Size(HWND hwnd, EDITSTATE *es, UINT action, INT width, INT height)
|
---|
4112 | {
|
---|
4113 | if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
|
---|
4114 | RECT rc;
|
---|
4115 | SetRect(&rc, 0, 0, width, height);
|
---|
4116 | EDIT_SetRectNP(hwnd, es, &rc);
|
---|
4117 | EDIT_Refresh(hwnd,es,FALSE);
|
---|
4118 | }
|
---|
4119 | }
|
---|
4120 |
|
---|
4121 |
|
---|
4122 | /*********************************************************************
|
---|
4123 | *
|
---|
4124 | * WM_SYSKEYDOWN
|
---|
4125 | *
|
---|
4126 | */
|
---|
4127 | static LRESULT EDIT_WM_SysKeyDown(HWND hwnd, EDITSTATE *es, INT key, DWORD key_data)
|
---|
4128 | {
|
---|
4129 | if ((key == VK_BACK) && (key_data & 0x2000)) {
|
---|
4130 | if (EDIT_EM_CanUndo(hwnd, es))
|
---|
4131 | EDIT_EM_Undo(hwnd, es);
|
---|
4132 | return 0;
|
---|
4133 | } else if ((key == VK_UP) || (key == VK_DOWN))
|
---|
4134 | {
|
---|
4135 | if (EDIT_CheckCombo(hwnd,es, WM_SYSKEYDOWN, key, key_data))
|
---|
4136 | return 0;
|
---|
4137 | }
|
---|
4138 | return DefWindowProcA(hwnd, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
|
---|
4139 | }
|
---|
4140 |
|
---|
4141 |
|
---|
4142 | /*********************************************************************
|
---|
4143 | *
|
---|
4144 | * WM_TIMER
|
---|
4145 | *
|
---|
4146 | */
|
---|
4147 | static void EDIT_WM_Timer(HWND hwnd, EDITSTATE *es, INT id, TIMERPROC timer_proc)
|
---|
4148 | {
|
---|
4149 | if (es->region_posx < 0) {
|
---|
4150 | EDIT_MoveBackward(hwnd, es, TRUE);
|
---|
4151 | } else if (es->region_posx > 0) {
|
---|
4152 | EDIT_MoveForward(hwnd, es, TRUE);
|
---|
4153 | }
|
---|
4154 |
|
---|
4155 | if (!(es->style & ES_MULTILINE)) return;
|
---|
4156 |
|
---|
4157 | if (es->region_posy < 0)
|
---|
4158 | {
|
---|
4159 | EDIT_MoveUp_ML(hwnd,es,TRUE);
|
---|
4160 | } else if (es->region_posy > 0)
|
---|
4161 | {
|
---|
4162 | EDIT_MoveDown_ML(hwnd,es,TRUE);
|
---|
4163 | }
|
---|
4164 | }
|
---|
4165 |
|
---|
4166 |
|
---|
4167 | /*********************************************************************
|
---|
4168 | *
|
---|
4169 | * EDIT_VScroll_Hack
|
---|
4170 | *
|
---|
4171 | * 16 bit notepad needs this. Actually it is not _our_ hack,
|
---|
4172 | * it is notepad's. Notepad is sending us scrollbar messages with
|
---|
4173 | * undocumented parameters without us even having a scrollbar ... !?!?
|
---|
4174 | *
|
---|
4175 | */
|
---|
4176 | static LRESULT EDIT_VScroll_Hack(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
|
---|
4177 | {
|
---|
4178 | INT dy = 0;
|
---|
4179 | LRESULT ret = 0;
|
---|
4180 |
|
---|
4181 | if (!(es->flags & EF_VSCROLL_HACK)) {
|
---|
4182 | //ERR_(edit)("hacked WM_VSCROLL handler invoked\n");
|
---|
4183 | //ERR_(edit)(" if you are _not_ running 16 bit notepad, please report\n");
|
---|
4184 | //ERR_(edit)(" (this message is only displayed once per edit control)\n");
|
---|
4185 | es->flags |= EF_VSCROLL_HACK;
|
---|
4186 | }
|
---|
4187 |
|
---|
4188 | switch (action) {
|
---|
4189 | case SB_LINEUP:
|
---|
4190 | case SB_LINEDOWN:
|
---|
4191 | case SB_PAGEUP:
|
---|
4192 | case SB_PAGEDOWN:
|
---|
4193 | EDIT_EM_Scroll(hwnd, es, action);
|
---|
4194 | return 0;
|
---|
4195 | case SB_TOP:
|
---|
4196 | dy = -es->y_offset;
|
---|
4197 | break;
|
---|
4198 | case SB_BOTTOM:
|
---|
4199 | dy = es->line_count - 1 - es->y_offset;
|
---|
4200 | break;
|
---|
4201 | case SB_THUMBTRACK:
|
---|
4202 | es->flags |= EF_VSCROLL_TRACK;
|
---|
4203 | dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset;
|
---|
4204 | break;
|
---|
4205 | case SB_THUMBPOSITION:
|
---|
4206 | es->flags &= ~EF_VSCROLL_TRACK;
|
---|
4207 | if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset))
|
---|
4208 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL);
|
---|
4209 | break;
|
---|
4210 | case SB_ENDSCROLL:
|
---|
4211 | break;
|
---|
4212 |
|
---|
4213 | default:
|
---|
4214 | //ERR_(edit)("undocumented (hacked) WM_VSCROLL parameter, please report\n");
|
---|
4215 | return 0;
|
---|
4216 | }
|
---|
4217 | if (dy)
|
---|
4218 | EDIT_EM_LineScroll(hwnd, es, 0, dy);
|
---|
4219 | return ret;
|
---|
4220 | }
|
---|
4221 |
|
---|
4222 |
|
---|
4223 | /*********************************************************************
|
---|
4224 | *
|
---|
4225 | * WM_VSCROLL
|
---|
4226 | *
|
---|
4227 | */
|
---|
4228 | static LRESULT EDIT_WM_VScroll(HWND hwnd, EDITSTATE *es, INT action, INT pos, HWND scroll_bar)
|
---|
4229 | {
|
---|
4230 | INT dy;
|
---|
4231 |
|
---|
4232 | if (!(es->style & ES_MULTILINE))
|
---|
4233 | return 0;
|
---|
4234 |
|
---|
4235 | if (!(es->style & ES_AUTOVSCROLL))
|
---|
4236 | return 0;
|
---|
4237 |
|
---|
4238 | if (!(es->style & WS_VSCROLL))
|
---|
4239 | return EDIT_VScroll_Hack(hwnd, es, action, pos, scroll_bar);
|
---|
4240 |
|
---|
4241 | dy = 0;
|
---|
4242 | switch (action) {
|
---|
4243 | case SB_LINEUP:
|
---|
4244 | case SB_LINEDOWN:
|
---|
4245 | case SB_PAGEUP:
|
---|
4246 | case SB_PAGEDOWN:
|
---|
4247 | EDIT_EM_Scroll(hwnd, es, action);
|
---|
4248 | return 0;
|
---|
4249 |
|
---|
4250 | case SB_TOP:
|
---|
4251 | dy = -es->y_offset;
|
---|
4252 | break;
|
---|
4253 | case SB_BOTTOM:
|
---|
4254 | dy = es->line_count - 1 - es->y_offset;
|
---|
4255 | break;
|
---|
4256 | case SB_THUMBTRACK:
|
---|
4257 | es->flags |= EF_VSCROLL_TRACK;
|
---|
4258 | dy = pos - es->y_offset;
|
---|
4259 | break;
|
---|
4260 | case SB_THUMBPOSITION:
|
---|
4261 | es->flags &= ~EF_VSCROLL_TRACK;
|
---|
4262 | if (!(dy = pos - es->y_offset)) {
|
---|
4263 | SetScrollPos(hwnd, SB_VERT, pos, TRUE);
|
---|
4264 | EDIT_NOTIFY_PARENT(hwnd, EN_VSCROLL);
|
---|
4265 | }
|
---|
4266 | break;
|
---|
4267 | case SB_ENDSCROLL:
|
---|
4268 | break;
|
---|
4269 |
|
---|
4270 | default:
|
---|
4271 | //ERR_(edit)("undocumented WM_VSCROLL action %d, please report\n",
|
---|
4272 | // action);
|
---|
4273 | return 0;
|
---|
4274 | }
|
---|
4275 | if (dy)
|
---|
4276 | EDIT_EM_LineScroll(hwnd, es, 0, dy);
|
---|
4277 | return 0;
|
---|
4278 | }
|
---|
4279 |
|
---|
4280 | static LRESULT EDIT_WM_MouseWheel(HWND hwnd,EDITSTATE *es,WPARAM wParam,LPARAM lParam)
|
---|
4281 | {
|
---|
4282 | short gcWheelDelta = 0;
|
---|
4283 | UINT pulScrollLines = 3;
|
---|
4284 | SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
|
---|
4285 |
|
---|
4286 | if (wParam & (MK_SHIFT | MK_CONTROL))
|
---|
4287 | return DefWindowProcA(hwnd,WM_MOUSEWHEEL, wParam, lParam);
|
---|
4288 | gcWheelDelta -= (short) HIWORD(wParam);
|
---|
4289 | if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
|
---|
4290 | {
|
---|
4291 | int cLineScroll= (int) min((UINT) es->line_count, pulScrollLines);
|
---|
4292 |
|
---|
4293 | cLineScroll *= (gcWheelDelta / WHEEL_DELTA);
|
---|
4294 | return EDIT_EM_LineScroll(hwnd, es, 0, cLineScroll);
|
---|
4295 | }
|
---|
4296 |
|
---|
4297 | return 0;
|
---|
4298 | }
|
---|
4299 |
|
---|
4300 | BOOL EDIT_Register()
|
---|
4301 | {
|
---|
4302 | WNDCLASSA wndClass;
|
---|
4303 |
|
---|
4304 | //SvL: Don't check this now
|
---|
4305 | // if (GlobalFindAtomA(EDITCLASSNAME)) return FALSE;
|
---|
4306 |
|
---|
4307 | ZeroMemory(&wndClass,sizeof(WNDCLASSA));
|
---|
4308 | wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
|
---|
4309 | wndClass.lpfnWndProc = (WNDPROC)EditWndProc;
|
---|
4310 | wndClass.cbClsExtra = 0;
|
---|
4311 | wndClass.cbWndExtra = sizeof(VOID*);
|
---|
4312 | wndClass.hCursor = LoadCursorA(0,IDC_IBEAMA);
|
---|
4313 | wndClass.hbrBackground = (HBRUSH)0;
|
---|
4314 | wndClass.lpszClassName = EDITCLASSNAME;
|
---|
4315 |
|
---|
4316 | return RegisterClassA(&wndClass);
|
---|
4317 | }
|
---|
4318 |
|
---|
4319 | BOOL EDIT_Unregister()
|
---|
4320 | {
|
---|
4321 | if (GlobalFindAtomA(EDITCLASSNAME))
|
---|
4322 | return UnregisterClassA(EDITCLASSNAME,(HINSTANCE)NULL);
|
---|
4323 | else return FALSE;
|
---|
4324 | }
|
---|