blob: 83fba06f85660af9e9622f7057d5b56d65ef09dc [file] [log] [blame]
Alexandre Julliard58199531994-04-21 01:20:00 +00001/*
Alexandre Julliard329f0681996-04-14 13:21:20 +00002 * Edit control
Alexandre Julliard58199531994-04-21 01:20:00 +00003 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004 * Copyright David W. Metcalfe, 1994
5 * Copyright William Magro, 1995, 1996
Alexandre Julliardc6c09441997-01-12 18:32:19 +00006 * Copyright Frans van Dorsselaer, 1996, 1997
Alexandre Julliard58199531994-04-21 01:20:00 +00007 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00008 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +000022 *
23 * TODO:
24 * - ES_CENTER
25 * - ES_RIGHT
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +000026 * - ES_OEMCONVERT
27 * -!ES_AUTOVSCROLL (every multi line control *is* auto vscroll)
28 * -!ES_AUTOHSCROLL (every single line control *is* auto hscroll)
29 *
30 * When there is no autoscrolling, the control should first check whether
31 * the new text would fit. If not, an EN_MAXTEXT should be sent.
32 * However, currently this would require the actual change to be made,
33 * then call EDIT_BuildLineDefs() and then find out that the new text doesn't
34 * fit. After all this, things should be put back in the state before the
35 * changes. Note that for multi line controls !ES_AUTOHSCROLL works : wordwrap.
36 *
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000037 */
Alexandre Julliard58199531994-04-21 01:20:00 +000038
Patrik Stridvall1bb94031999-05-08 15:47:44 +000039#include "config.h"
40
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000041#include <stdarg.h>
Jeff Garzikc3e1f721999-02-19 15:42:11 +000042#include <string.h>
Alexandre Julliard908464d2000-11-01 03:11:12 +000043#include <stdlib.h>
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000044
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000045#include "windef.h"
Patrik Stridvall6cc47d42000-03-08 18:26:56 +000046#include "winbase.h"
Alexandre Julliard889f7421997-04-15 17:19:52 +000047#include "winnt.h"
Alexandre Julliard7e92c9a2003-02-27 21:09:45 +000048#include "wownt32.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000049#include "win.h"
Marcus Meissner317af321999-02-17 13:51:06 +000050#include "wine/winbase16.h"
Alexandre Julliard198746d2000-08-14 14:29:22 +000051#include "wine/winuser16.h"
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +000052#include "wine/unicode.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000053#include "controls.h"
Alexandre Julliard329f0681996-04-14 13:21:20 +000054#include "local.h"
Lionel Ulmer28d9aaf2004-03-29 22:54:05 +000055#include "message.h"
Alexandre Julliarda41b2cf2001-01-15 20:12:55 +000056#include "user.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000057#include "wine/debug.h"
Alexandre Julliard58199531994-04-21 01:20:00 +000058
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000059WINE_DEFAULT_DEBUG_CHANNEL(edit);
60WINE_DECLARE_DEBUG_CHANNEL(combo);
61WINE_DECLARE_DEBUG_CHANNEL(relay);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000062
Alexandre Julliard889f7421997-04-15 17:19:52 +000063#define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0')
64 FIXME: BTW, new specs say 65535 (do you dare ???) */
65#define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +000066#define GROWLENGTH 32 /* buffers granularity in bytes: must be power of 2 */
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +000067#define ROUND_TO_GROW(size) (((size) + (GROWLENGTH - 1)) & ~(GROWLENGTH - 1))
Alexandre Julliard329f0681996-04-14 13:21:20 +000068#define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */
Alexandre Julliard58199531994-04-21 01:20:00 +000069
Alexandre Julliard889f7421997-04-15 17:19:52 +000070/*
71 * extra flags for EDITSTATE.flags field
72 */
73#define EF_MODIFIED 0x0001 /* text has been modified */
74#define EF_FOCUSED 0x0002 /* we have input focus */
Dmitry Timoshkova62f06d2001-03-13 23:31:08 +000075#define EF_UPDATE 0x0004 /* notify parent of changed state */
Alexandre Julliard889f7421997-04-15 17:19:52 +000076#define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */
77#define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */
Alexandre Julliard889f7421997-04-15 17:19:52 +000078#define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a
79 wrapped line, instead of in front of the next character */
Alexandre Julliarda845b881998-06-01 10:44:35 +000080#define EF_USE_SOFTBRK 0x0100 /* Enable soft breaks in text. */
Alexandre Julliard889f7421997-04-15 17:19:52 +000081
Alexandre Julliard329f0681996-04-14 13:21:20 +000082typedef enum
83{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +000084 END_0 = 0, /* line ends with terminating '\0' character */
85 END_WRAP, /* line is wrapped */
86 END_HARD, /* line ends with a hard return '\r\n' */
87 END_SOFT, /* line ends with a soft return '\r\r\n' */
88 END_RICH /* line ends with a single '\n' */
Alexandre Julliard329f0681996-04-14 13:21:20 +000089} LINE_END;
90
Alexandre Julliard889f7421997-04-15 17:19:52 +000091typedef struct tagLINEDEF {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +000092 INT length; /* bruto length of a line in bytes */
93 INT net_length; /* netto length of a line in visible characters */
Alexandre Julliard329f0681996-04-14 13:21:20 +000094 LINE_END ending;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +000095 INT width; /* width of the line in pixels */
96 INT index; /* line index into the buffer */
Alexandre Julliard889f7421997-04-15 17:19:52 +000097 struct tagLINEDEF *next;
Alexandre Julliard329f0681996-04-14 13:21:20 +000098} LINEDEF;
Alexandre Julliard58199531994-04-21 01:20:00 +000099
Alexandre Julliard58199531994-04-21 01:20:00 +0000100typedef struct
101{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000102 BOOL is_unicode; /* how the control was created */
103 LPWSTR text; /* the actual contents of the control */
104 UINT buffer_size; /* the size of the buffer in characters */
105 UINT buffer_limit; /* the maximum size to which the buffer may grow in characters */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000106 HFONT font; /* NULL means standard system font */
107 INT x_offset; /* scroll offset for multi lines this is in pixels
Alexandre Julliard889f7421997-04-15 17:19:52 +0000108 for single lines it's in characters */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000109 INT line_height; /* height of a screen line in pixels */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000110 INT char_width; /* average character width in pixels */
Alexandre Julliard889f7421997-04-15 17:19:52 +0000111 DWORD style; /* sane version of wnd->dwStyle */
112 WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000113 INT undo_insert_count; /* number of characters inserted in sequence */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000114 UINT undo_position; /* character index of the insertion and deletion */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000115 LPWSTR undo_text; /* deleted text */
Dmitry Timoshkov366c0a12000-12-22 20:28:05 +0000116 UINT undo_buffer_size; /* size of the deleted text buffer */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000117 INT selection_start; /* == selection_end if no selection */
118 INT selection_end; /* == current caret position */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000119 WCHAR password_char; /* == 0 if no password char, and for multi line controls */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000120 INT left_margin; /* in pixels */
121 INT right_margin; /* in pixels */
122 RECT format_rect;
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +0000123 INT text_width; /* width of the widest line in pixels for multi line controls
124 and just line width for single line controls */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000125 INT region_posx; /* Position of cursor relative to region: */
126 INT region_posy; /* -1: to left, 0: within, 1: to right */
Alexandre Julliard889f7421997-04-15 17:19:52 +0000127 EDITWORDBREAKPROC16 word_break_proc16;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000128 void *word_break_proc; /* 32-bit word break proc: ANSI or Unicode */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000129 INT line_count; /* number of lines */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000130 INT y_offset; /* scroll offset in number of lines */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000131 BOOL bCaptureState; /* flag indicating whether mouse was captured */
132 BOOL bEnableState; /* flag keeping the enable state */
133 HWND hwndSelf; /* the our window handle */
134 HWND hwndParent; /* Handle of parent for sending EN_* messages.
135 Even if parent will change, EN_* messages
136 should be sent to the first parent. */
137 HWND hwndListBox; /* handle of ComboBox's listbox or NULL */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000138 /*
Alexandre Julliard889f7421997-04-15 17:19:52 +0000139 * only for multi line controls
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000140 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000141 INT lock_count; /* amount of re-entries in the EditWndProc */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000142 INT tabs_count;
143 LPINT tabs;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000144 LINEDEF *first_line_def; /* linked list of (soft) linebreaks */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000145 HLOCAL hloc32W; /* our unicode local memory block */
146 HLOCAL16 hloc16; /* alias for 16-bit control receiving EM_GETHANDLE16
147 or EM_SETHANDLE16 */
148 HLOCAL hloc32A; /* alias for ANSI control receiving EM_GETHANDLE
149 or EM_SETHANDLE */
Alexandre Julliard58199531994-04-21 01:20:00 +0000150} EDITSTATE;
151
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000152
Alexandre Julliarda3960291999-02-26 11:11:13 +0000153#define SWAP_UINT32(x,y) do { UINT temp = (UINT)(x); (x) = (UINT)(y); (y) = temp; } while(0)
154#define ORDER_UINT(x,y) do { if ((UINT)(y) < (UINT)(x)) SWAP_UINT32((x),(y)); } while(0)
Alexandre Julliard58199531994-04-21 01:20:00 +0000155
Luc Tourangeaudf5fbc71999-04-03 11:14:30 +0000156/* used for disabled or read-only edit control */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000157#define EDIT_NOTIFY_PARENT(es, wNotifyCode, str) \
Dmitry Timoshkov87880c52001-03-10 19:16:46 +0000158 do \
Dmitry Timoshkova62f06d2001-03-13 23:31:08 +0000159 { /* Notify parent which has created this edit control */ \
Alexandre Julliardaff7dda2002-11-22 21:22:14 +0000160 TRACE("notification " str " sent to hwnd=%p\n", es->hwndParent); \
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000161 SendMessageW(es->hwndParent, WM_COMMAND, \
Robert Shearman2e9436c2004-08-17 22:29:29 +0000162 MAKEWPARAM(GetWindowLongPtrW((es->hwndSelf),GWLP_ID), wNotifyCode), \
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000163 (LPARAM)(es->hwndSelf)); \
Dmitry Timoshkov87880c52001-03-10 19:16:46 +0000164 } while(0)
Alexandre Julliardca22b331996-07-12 19:02:39 +0000165
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000166/*********************************************************************
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000167 *
Alexandre Julliard329f0681996-04-14 13:21:20 +0000168 * Declarations
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000169 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000170 */
171
172/*
173 * These functions have trivial implementations
174 * We still like to call them internally
Patrik Stridvall1bb94031999-05-08 15:47:44 +0000175 * "static inline" makes them more like macro's
Alexandre Julliard889f7421997-04-15 17:19:52 +0000176 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000177static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es);
178static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000179static inline void EDIT_WM_Clear(EDITSTATE *es);
180static inline void EDIT_WM_Cut(EDITSTATE *es);
Patrik Stridvall1ed4ecf1999-06-26 14:58:24 +0000181
Alexandre Julliard889f7421997-04-15 17:19:52 +0000182/*
183 * Helper functions only valid for one type of control
184 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000185static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT iStart, INT iEnd, INT delta, HRGN hrgn);
186static void EDIT_CalcLineWidth_SL(EDITSTATE *es);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000187static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000188static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend);
189static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend);
190static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend);
191static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000192/*
193 * Helper functions valid for both single line _and_ multi line controls
194 */
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +0000195static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000196static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000197static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000198static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc);
199static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end);
200static void EDIT_LockBuffer(EDITSTATE *es);
Krishna Murthy4af4ba42004-05-29 00:21:51 +0000201static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size);
Dmitry Timoshkov366c0a12000-12-22 20:28:05 +0000202static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000203static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend);
204static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend);
205static void EDIT_MoveForward(EDITSTATE *es, BOOL extend);
206static void EDIT_MoveHome(EDITSTATE *es, BOOL extend);
207static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend);
208static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend);
209static void EDIT_PaintLine(EDITSTATE *es, HDC hdc, INT line, BOOL rev);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000210static INT EDIT_PaintText(EDITSTATE *es, HDC hdc, INT x, INT y, INT line, INT col, INT count, BOOL rev);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000211static void EDIT_SetCaretPos(EDITSTATE *es, INT pos, BOOL after_wrap);
212static void EDIT_SetRectNP(EDITSTATE *es, LPRECT lprc);
213static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force);
214static void EDIT_UpdateScrollInfo(EDITSTATE *es);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000215static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000216/*
217 * EM_XXX message handlers
218 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000219static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000220static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol);
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +0000221static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000222static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es);
Dmitry Timoshkovbf604532001-02-12 19:15:33 +0000223static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPARAM lParam, BOOL unicode);
Francois Gougetbba4bb12002-09-17 01:35:09 +0000224static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000225static LRESULT EDIT_EM_GetThumb(EDITSTATE *es);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000226static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index);
227static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line);
228static INT EDIT_EM_LineLength(EDITSTATE *es, INT index);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000229static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy);
230static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy);
231static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap);
Carl Sopchak23b88ef2002-11-21 03:57:05 +0000232static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000233static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action);
234static void EDIT_EM_ScrollCaret(EDITSTATE *es);
235static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc);
236static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000237static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit);
238static void EDIT_EM_SetMargins(EDITSTATE *es, INT action, INT left, INT right);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000239static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c);
240static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000241static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs);
242static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000243static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, LPARAM lParam);
244static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp);
245static BOOL EDIT_EM_Undo(EDITSTATE *es);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000246/*
247 * WM_XXX message handlers
248 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000249static void EDIT_WM_Char(EDITSTATE *es, WCHAR c);
250static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND conrtol);
251static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y);
252static void EDIT_WM_Copy(EDITSTATE *es);
253static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name);
254static LRESULT EDIT_WM_Destroy(EDITSTATE *es);
255static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000256static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPARAM lParam, BOOL unicode);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000257static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos);
258static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key);
259static LRESULT EDIT_WM_KillFocus(EDITSTATE *es);
260static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es);
261static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y);
262static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es);
263static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es);
264static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y);
265static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode);
266static void EDIT_WM_Paint(EDITSTATE *es, WPARAM wParam);
267static void EDIT_WM_Paste(EDITSTATE *es);
268static void EDIT_WM_SetFocus(EDITSTATE *es);
269static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw);
270static void EDIT_WM_SetText(EDITSTATE *es, LPARAM lParam, BOOL unicode);
271static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height);
272static LRESULT EDIT_WM_StyleChanged(EDITSTATE *es, WPARAM which, const STYLESTRUCT *style);
273static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data);
274static void EDIT_WM_Timer(EDITSTATE *es);
275static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos);
276static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase);
277static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase);
Alexandre Julliard58199531994-04-21 01:20:00 +0000278
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000279LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
280LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Alexandre Julliard91222da2000-12-10 23:01:33 +0000281
282/*********************************************************************
283 * edit class descriptor
284 */
285const struct builtin_class_descr EDIT_builtin_class =
286{
287 "Edit", /* name */
Alexandre Julliardb0622102003-12-10 04:14:35 +0000288 CS_DBLCLKS | CS_PARENTDC, /* style */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000289 EditWndProcA, /* procA */
290 EditWndProcW, /* procW */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000291 sizeof(EDITSTATE *), /* extra */
Alexandre Julliardcf526442003-09-10 03:56:47 +0000292 IDC_IBEAM, /* cursor */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000293 0 /* brush */
294};
295
Alexandre Julliard58199531994-04-21 01:20:00 +0000296
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000297/*********************************************************************
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000298 *
Alexandre Julliard889f7421997-04-15 17:19:52 +0000299 * EM_CANUNDO
Alexandre Julliardcdcdede1996-04-21 14:57:41 +0000300 *
301 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000302static inline BOOL EDIT_EM_CanUndo(EDITSTATE *es)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000303{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000304 return (es->undo_insert_count || strlenW(es->undo_text));
Alexandre Julliard889f7421997-04-15 17:19:52 +0000305}
306
307
308/*********************************************************************
309 *
310 * EM_EMPTYUNDOBUFFER
311 *
312 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000313static inline void EDIT_EM_EmptyUndoBuffer(EDITSTATE *es)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000314{
315 es->undo_insert_count = 0;
316 *es->undo_text = '\0';
317}
318
319
320/*********************************************************************
321 *
322 * WM_CLEAR
323 *
324 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000325static inline void EDIT_WM_Clear(EDITSTATE *es)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000326{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000327 static const WCHAR empty_stringW[] = {0};
328
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +0000329 /* Protect read-only edit control from modification */
330 if(es->style & ES_READONLY)
331 return;
332
Carl Sopchak23b88ef2002-11-21 03:57:05 +0000333 EDIT_EM_ReplaceSel(es, TRUE, empty_stringW, TRUE, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000334}
335
336
337/*********************************************************************
338 *
339 * WM_CUT
340 *
341 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000342static inline void EDIT_WM_Cut(EDITSTATE *es)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000343{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000344 EDIT_WM_Copy(es);
345 EDIT_WM_Clear(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000346}
Alexandre Julliardcdcdede1996-04-21 14:57:41 +0000347
348
Alexandre Julliard198746d2000-08-14 14:29:22 +0000349/**********************************************************************
350 * get_app_version
351 *
352 * Returns the window version in case Wine emulates a later version
Francois Gouget61aac4e2003-06-04 20:29:05 +0000353 * of windows than the application expects.
Vincent Béron9a624912002-05-31 23:06:46 +0000354 *
Alexandre Julliard198746d2000-08-14 14:29:22 +0000355 * In a number of cases when windows runs an application that was
356 * designed for an earlier windows version, windows reverts
357 * to "old" behaviour of that earlier version.
Vincent Béron9a624912002-05-31 23:06:46 +0000358 *
359 * An example is a disabled edit control that needs to be painted.
360 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
361 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
Alexandre Julliard198746d2000-08-14 14:29:22 +0000362 * applications with an expected version 0f 4.0 or higher.
Vincent Béron9a624912002-05-31 23:06:46 +0000363 *
Alexandre Julliard198746d2000-08-14 14:29:22 +0000364 */
365static DWORD get_app_version(void)
366{
367 static DWORD version;
368 if (!version)
369 {
370 DWORD dwEmulatedVersion;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000371 OSVERSIONINFOW info;
Alexandre Julliard198746d2000-08-14 14:29:22 +0000372 DWORD dwProcVersion = GetProcessVersion(0);
373
James Juran75c525c2001-05-18 20:56:37 +0000374 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000375 GetVersionExW( &info );
Alexandre Julliard198746d2000-08-14 14:29:22 +0000376 dwEmulatedVersion = MAKELONG( info.dwMinorVersion, info.dwMajorVersion );
Dimitrie O. Paun693cca52002-01-29 03:12:19 +0000377 /* FIXME: this may not be 100% correct; see discussion on the
Alexandre Julliard198746d2000-08-14 14:29:22 +0000378 * wine developer list in Nov 1999 */
Vincent Béron9a624912002-05-31 23:06:46 +0000379 version = dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion;
Alexandre Julliard198746d2000-08-14 14:29:22 +0000380 }
381 return version;
382}
383
384
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000385static HBRUSH EDIT_NotifyCtlColor(EDITSTATE *es, HDC hdc)
386{
387 UINT msg;
388
389 if ( get_app_version() >= 0x40000 && (!es->bEnableState || (es->style & ES_READONLY)))
390 msg = WM_CTLCOLORSTATIC;
391 else
392 msg = WM_CTLCOLOREDIT;
393
394 /* why do we notify to es->hwndParent, and we send this one to GetParent()? */
395 return (HBRUSH)SendMessageW(GetParent(es->hwndSelf), msg, (WPARAM)hdc, (LPARAM)es->hwndSelf);
396}
397
398static inline LRESULT DefWindowProcT(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode)
399{
400 if(unicode)
401 return DefWindowProcW(hwnd, msg, wParam, lParam);
402 else
403 return DefWindowProcA(hwnd, msg, wParam, lParam);
404}
405
Alexandre Julliardcdcdede1996-04-21 14:57:41 +0000406/*********************************************************************
407 *
Alexandre Julliardde424282001-08-10 22:51:42 +0000408 * EditWndProc_common
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000409 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000410 * The messages are in the order of the actual integer values
411 * (which can be found in include/windows.h)
Bill Medland86bfa4c2001-06-28 18:01:00 +0000412 * Wherever possible the 16 bit versions are converted to
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000413 * the 32 bit ones, so that we can 'fall through' to the
414 * helper functions. These are mostly 32 bit (with a few
415 * exceptions, clearly indicated by a '16' extension to their
416 * names).
417 *
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000418 */
Alexandre Julliardde424282001-08-10 22:51:42 +0000419static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg,
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000420 WPARAM wParam, LPARAM lParam, BOOL unicode )
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000421{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000422 EDITSTATE *es = (EDITSTATE *)GetWindowLongW( hwnd, 0 );
Alexandre Julliard889f7421997-04-15 17:19:52 +0000423 LRESULT result = 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000424
Lionel Ulmer28d9aaf2004-03-29 22:54:05 +0000425 TRACE("hwnd=%p msg=%x (%s) wparam=%x lparam=%lx\n", hwnd, msg, SPY_GetMsgName(msg, hwnd), wParam, lParam);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000426
427 if (!es && msg != WM_NCCREATE)
428 return DefWindowProcT(hwnd, msg, wParam, lParam, unicode);
429 else if (msg == WM_NCCREATE)
430 return EDIT_WM_NCCreate(hwnd, (LPCREATESTRUCTW)lParam, unicode);
431 else if (msg == WM_DESTROY)
432 return EDIT_WM_Destroy(es);
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000433
Alexandre Julliardbf9130a1996-10-13 17:45:47 +0000434
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000435 if (es) EDIT_LockBuffer(es);
436
Alexandre Julliard329f0681996-04-14 13:21:20 +0000437 switch (msg) {
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000438 case EM_GETSEL16:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000439 wParam = 0;
440 lParam = 0;
441 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000442 case EM_GETSEL:
Francois Gougetbba4bb12002-09-17 01:35:09 +0000443 result = EDIT_EM_GetSel(es, (PUINT)wParam, (PUINT)lParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000444 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000445
446 case EM_SETSEL16:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000447 if ((short)LOWORD(lParam) == -1)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000448 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000449 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000450 EDIT_EM_SetSel(es, LOWORD(lParam), HIWORD(lParam), FALSE);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000451 if (!wParam)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000452 EDIT_EM_ScrollCaret(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000453 result = 1;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000454 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000455 case EM_SETSEL:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000456 EDIT_EM_SetSel(es, wParam, lParam, FALSE);
457 EDIT_EM_ScrollCaret(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000458 result = 1;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000459 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000460
461 case EM_GETRECT16:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000462 if (lParam)
Alexandre Julliard3c39a992004-08-31 00:02:02 +0000463 {
464 RECT16 *r16 = MapSL(lParam);
465 r16->left = es->format_rect.left;
466 r16->top = es->format_rect.top;
467 r16->right = es->format_rect.right;
468 r16->bottom = es->format_rect.bottom;
469 }
Alexandre Julliard329f0681996-04-14 13:21:20 +0000470 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000471 case EM_GETRECT:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000472 if (lParam)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000473 CopyRect((LPRECT)lParam, &es->format_rect);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000474 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000475
476 case EM_SETRECT16:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000477 if ((es->style & ES_MULTILINE) && lParam) {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000478 RECT rc;
Alexandre Julliard3c39a992004-08-31 00:02:02 +0000479 RECT16 *r16 = MapSL(lParam);
480 rc.left = r16->left;
481 rc.top = r16->top;
482 rc.right = r16->right;
483 rc.bottom = r16->bottom;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000484 EDIT_SetRectNP(es, &rc);
485 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000486 }
487 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000488 case EM_SETRECT:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000489 if ((es->style & ES_MULTILINE) && lParam) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000490 EDIT_SetRectNP(es, (LPRECT)lParam);
491 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000492 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000493 break;
494
495 case EM_SETRECTNP16:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000496 if ((es->style & ES_MULTILINE) && lParam) {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000497 RECT rc;
Alexandre Julliard3c39a992004-08-31 00:02:02 +0000498 RECT16 *r16 = MapSL(lParam);
499 rc.left = r16->left;
500 rc.top = r16->top;
501 rc.right = r16->right;
502 rc.bottom = r16->bottom;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000503 EDIT_SetRectNP(es, &rc);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000504 }
505 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000506 case EM_SETRECTNP:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000507 if ((es->style & ES_MULTILINE) && lParam)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000508 EDIT_SetRectNP(es, (LPRECT)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000509 break;
510
511 case EM_SCROLL16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000512 case EM_SCROLL:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000513 result = EDIT_EM_Scroll(es, (INT)wParam);
Alexandre Julliard9d615962003-09-17 04:28:28 +0000514 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000515
516 case EM_LINESCROLL16:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000517 wParam = (WPARAM)(INT)(SHORT)HIWORD(lParam);
518 lParam = (LPARAM)(INT)(SHORT)LOWORD(lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000519 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000520 case EM_LINESCROLL:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000521 result = (LRESULT)EDIT_EM_LineScroll(es, (INT)wParam, (INT)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000522 break;
523
524 case EM_SCROLLCARET16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000525 case EM_SCROLLCARET:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000526 EDIT_EM_ScrollCaret(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000527 result = 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000528 break;
529
530 case EM_GETMODIFY16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000531 case EM_GETMODIFY:
Eric Pouech8dde5a41999-04-25 10:58:04 +0000532 result = ((es->flags & EF_MODIFIED) != 0);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000533 break;
534
535 case EM_SETMODIFY16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000536 case EM_SETMODIFY:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000537 if (wParam)
538 es->flags |= EF_MODIFIED;
539 else
Gerard Patel40ed5111999-07-03 15:47:50 +0000540 es->flags &= ~(EF_MODIFIED | EF_UPDATE); /* reset pending updates */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000541 break;
542
543 case EM_GETLINECOUNT16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000544 case EM_GETLINECOUNT:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000545 result = (es->style & ES_MULTILINE) ? es->line_count : 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000546 break;
547
548 case EM_LINEINDEX16:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000549 if ((INT16)wParam == -1)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000550 wParam = (WPARAM)-1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000551 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000552 case EM_LINEINDEX:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000553 result = (LRESULT)EDIT_EM_LineIndex(es, (INT)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000554 break;
555
556 case EM_SETHANDLE16:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000557 EDIT_EM_SetHandle16(es, (HLOCAL16)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000558 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000559 case EM_SETHANDLE:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000560 EDIT_EM_SetHandle(es, (HLOCAL)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000561 break;
562
563 case EM_GETHANDLE16:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000564 result = (LRESULT)EDIT_EM_GetHandle16(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000565 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000566 case EM_GETHANDLE:
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +0000567 result = (LRESULT)EDIT_EM_GetHandle(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000568 break;
569
570 case EM_GETTHUMB16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000571 case EM_GETTHUMB:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000572 result = EDIT_EM_GetThumb(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000573 break;
574
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000575 /* these messages missing from specs */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000576 case WM_USER+15:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000577 case 0x00bf:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000578 case WM_USER+16:
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000579 case 0x00c0:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000580 case WM_USER+19:
581 case 0x00c3:
582 case WM_USER+26:
583 case 0x00ca:
584 FIXME("undocumented message 0x%x, please report\n", msg);
Alexandre Julliardde424282001-08-10 22:51:42 +0000585 result = DefWindowProcW(hwnd, msg, wParam, lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000586 break;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000587
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000588 case EM_LINELENGTH16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000589 case EM_LINELENGTH:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000590 result = (LRESULT)EDIT_EM_LineLength(es, (INT)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000591 break;
592
593 case EM_REPLACESEL16:
Alexandre Julliard982a2232000-12-13 20:20:09 +0000594 lParam = (LPARAM)MapSL(lParam);
Alexandre Julliardc9e11392001-04-10 21:46:27 +0000595 unicode = FALSE; /* 16-bit message is always ascii */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000596 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000597 case EM_REPLACESEL:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000598 {
599 LPWSTR textW;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000600
601 if(unicode)
602 textW = (LPWSTR)lParam;
603 else
604 {
605 LPSTR textA = (LPSTR)lParam;
606 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
607 if((textW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
608 MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, countW);
609 }
610
Carl Sopchak23b88ef2002-11-21 03:57:05 +0000611 EDIT_EM_ReplaceSel(es, (BOOL)wParam, textW, TRUE, TRUE);
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000612 result = 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000613
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000614 if(!unicode)
615 HeapFree(GetProcessHeap(), 0, textW);
616 break;
617 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000618
619 case EM_GETLINE16:
Alexandre Julliard982a2232000-12-13 20:20:09 +0000620 lParam = (LPARAM)MapSL(lParam);
Alexandre Julliardc9e11392001-04-10 21:46:27 +0000621 unicode = FALSE; /* 16-bit message is always ascii */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000622 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000623 case EM_GETLINE:
Dmitry Timoshkovbf604532001-02-12 19:15:33 +0000624 result = (LRESULT)EDIT_EM_GetLine(es, (INT)wParam, lParam, unicode);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000625 break;
626
627 case EM_LIMITTEXT16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000628 case EM_SETLIMITTEXT:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000629 EDIT_EM_SetLimitText(es, (INT)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000630 break;
631
632 case EM_CANUNDO16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000633 case EM_CANUNDO:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000634 result = (LRESULT)EDIT_EM_CanUndo(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000635 break;
636
637 case EM_UNDO16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000638 case EM_UNDO:
Alexandre Julliard329f0681996-04-14 13:21:20 +0000639 case WM_UNDO:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000640 result = (LRESULT)EDIT_EM_Undo(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000641 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000642
643 case EM_FMTLINES16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000644 case EM_FMTLINES:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000645 result = (LRESULT)EDIT_EM_FmtLines(es, (BOOL)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000646 break;
647
648 case EM_LINEFROMCHAR16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000649 case EM_LINEFROMCHAR:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000650 result = (LRESULT)EDIT_EM_LineFromChar(es, (INT)wParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000651 break;
652
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000653 case EM_SETTABSTOPS16:
Alexandre Julliard982a2232000-12-13 20:20:09 +0000654 result = (LRESULT)EDIT_EM_SetTabStops16(es, (INT)wParam, MapSL(lParam));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000655 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000656 case EM_SETTABSTOPS:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000657 result = (LRESULT)EDIT_EM_SetTabStops(es, (INT)wParam, (LPINT)lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000658 break;
659
660 case EM_SETPASSWORDCHAR16:
Alexandre Julliardc9e11392001-04-10 21:46:27 +0000661 unicode = FALSE; /* 16-bit message is always ascii */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000662 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000663 case EM_SETPASSWORDCHAR:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000664 {
665 WCHAR charW = 0;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000666
667 if(unicode)
668 charW = (WCHAR)wParam;
669 else
670 {
671 CHAR charA = wParam;
672 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
673 }
674
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000675 EDIT_EM_SetPasswordChar(es, charW);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000676 break;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000677 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000678
679 case EM_EMPTYUNDOBUFFER16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000680 case EM_EMPTYUNDOBUFFER:
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000681 EDIT_EM_EmptyUndoBuffer(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000682 break;
683
684 case EM_GETFIRSTVISIBLELINE16:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000685 result = es->y_offset;
686 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000687 case EM_GETFIRSTVISIBLELINE:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000688 result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000689 break;
690
691 case EM_SETREADONLY16:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000692 case EM_SETREADONLY:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000693 if (wParam) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000694 SetWindowLongW( hwnd, GWL_STYLE,
695 GetWindowLongW( hwnd, GWL_STYLE ) | ES_READONLY );
Alexandre Julliardde424282001-08-10 22:51:42 +0000696 es->style |= ES_READONLY;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000697 } else {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000698 SetWindowLongW( hwnd, GWL_STYLE,
699 GetWindowLongW( hwnd, GWL_STYLE ) & ~ES_READONLY );
Alexandre Julliardde424282001-08-10 22:51:42 +0000700 es->style &= ~ES_READONLY;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000701 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000702 result = 1;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000703 break;
704
705 case EM_SETWORDBREAKPROC16:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000706 EDIT_EM_SetWordBreakProc16(es, (EDITWORDBREAKPROC16)lParam);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000707 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000708 case EM_SETWORDBREAKPROC:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000709 EDIT_EM_SetWordBreakProc(es, lParam);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000710 break;
711
712 case EM_GETWORDBREAKPROC16:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000713 result = (LRESULT)es->word_break_proc16;
714 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000715 case EM_GETWORDBREAKPROC:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000716 result = (LRESULT)es->word_break_proc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000717 break;
718
719 case EM_GETPASSWORDCHAR16:
Alexandre Julliardc9e11392001-04-10 21:46:27 +0000720 unicode = FALSE; /* 16-bit message is always ascii */
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000721 /* fall through */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000722 case EM_GETPASSWORDCHAR:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000723 {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000724 if(unicode)
725 result = es->password_char;
726 else
727 {
728 WCHAR charW = es->password_char;
729 CHAR charA = 0;
730 WideCharToMultiByte(CP_ACP, 0, &charW, 1, &charA, 1, NULL, NULL);
731 result = charA;
732 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000733 break;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000734 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000735
736 /* The following EM_xxx are new to win95 and don't exist for 16 bit */
737
Alexandre Julliarda3960291999-02-26 11:11:13 +0000738 case EM_SETMARGINS:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000739 EDIT_EM_SetMargins(es, (INT)wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000740 break;
741
Alexandre Julliarda3960291999-02-26 11:11:13 +0000742 case EM_GETMARGINS:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000743 result = MAKELONG(es->left_margin, es->right_margin);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000744 break;
745
Alexandre Julliarda3960291999-02-26 11:11:13 +0000746 case EM_GETLIMITTEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000747 result = es->buffer_limit;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000748 break;
749
Alexandre Julliarda3960291999-02-26 11:11:13 +0000750 case EM_POSFROMCHAR:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000751 result = EDIT_EM_PosFromChar(es, (INT)wParam, FALSE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000752 break;
753
Alexandre Julliarda3960291999-02-26 11:11:13 +0000754 case EM_CHARFROMPOS:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000755 result = EDIT_EM_CharFromPos(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000756 break;
757
Bill Medland86bfa4c2001-06-28 18:01:00 +0000758 /* End of the EM_ messages which were in numerical order; what order
759 * are these in? vaguely alphabetical?
760 */
761
Alexandre Julliard329f0681996-04-14 13:21:20 +0000762 case WM_GETDLGCODE:
Rein Klazeseb359e22003-05-15 04:14:53 +0000763 result = DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS;
Rein Klazesa762b4c2003-05-19 21:40:31 +0000764
765 if (lParam && (((LPMSG)lParam)->message == WM_KEYDOWN))
766 {
767 int vk = (int)((LPMSG)lParam)->wParam;
768
769 if (vk == VK_RETURN && (GetWindowLongW( hwnd, GWL_STYLE ) & ES_WANTRETURN))
770 {
771 result |= DLGC_WANTMESSAGE;
772 }
773 else if (es->hwndListBox && (vk == VK_RETURN || vk == VK_ESCAPE))
774 {
775 if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
776 result |= DLGC_WANTMESSAGE;
777 }
778 }
Rein Klazeseb359e22003-05-15 04:14:53 +0000779 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000780
Aric Stewart199449d2003-05-12 03:24:10 +0000781 case WM_IME_CHAR:
782 if (!unicode)
783 {
784 WCHAR charW;
785 CHAR strng[2];
786
787 strng[0] = wParam >> 8;
788 strng[1] = wParam & 0xff;
Yoshiro Takenoc91d9f02004-01-26 20:20:07 +0000789 if (strng[0]) MultiByteToWideChar(CP_ACP, 0, strng, 2, &charW, 1);
790 else MultiByteToWideChar(CP_ACP, 0, &strng[1], 1, &charW, 1);
Aric Stewart199449d2003-05-12 03:24:10 +0000791 EDIT_WM_Char(es, charW);
792 break;
793 }
794 /* fall through */
Alexandre Julliard329f0681996-04-14 13:21:20 +0000795 case WM_CHAR:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000796 {
797 WCHAR charW;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000798
799 if(unicode)
800 charW = wParam;
801 else
Serge Ivanov9eedcf52000-06-07 03:47:34 +0000802 {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000803 CHAR charA = wParam;
804 MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
805 }
806
807 if ((charW == VK_RETURN || charW == VK_ESCAPE) && es->hwndListBox)
808 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000809 if (SendMessageW(GetParent(hwnd), CB_GETDROPPEDSTATE, 0, 0))
810 SendMessageW(GetParent(hwnd), WM_KEYDOWN, charW, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +0000811 break;
812 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000813 EDIT_WM_Char(es, charW);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000814 break;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000815 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000816
Alexandre Julliard329f0681996-04-14 13:21:20 +0000817 case WM_CLEAR:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000818 EDIT_WM_Clear(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000819 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000820
Alexandre Julliard01d63461997-01-20 19:43:45 +0000821 case WM_COMMAND:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000822 EDIT_WM_Command(es, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000823 break;
824
Alexandre Julliard9d615962003-09-17 04:28:28 +0000825 case WM_CONTEXTMENU:
826 EDIT_WM_ContextMenu(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
Alexandre Julliard01d63461997-01-20 19:43:45 +0000827 break;
828
Alexandre Julliard329f0681996-04-14 13:21:20 +0000829 case WM_COPY:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000830 EDIT_WM_Copy(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000831 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000832
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000833 case WM_CREATE:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000834 if(unicode)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000835 result = EDIT_WM_Create(es, ((LPCREATESTRUCTW)lParam)->lpszName);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000836 else
837 {
838 LPCSTR nameA = ((LPCREATESTRUCTA)lParam)->lpszName;
839 LPWSTR nameW = NULL;
840 if(nameA)
841 {
842 INT countW = MultiByteToWideChar(CP_ACP, 0, nameA, -1, NULL, 0);
843 if((nameW = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
844 MultiByteToWideChar(CP_ACP, 0, nameA, -1, nameW, countW);
845 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000846 result = EDIT_WM_Create(es, nameW);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000847 if(nameW)
848 HeapFree(GetProcessHeap(), 0, nameW);
849 }
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +0000850 break;
851
Alexandre Julliard329f0681996-04-14 13:21:20 +0000852 case WM_CUT:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000853 EDIT_WM_Cut(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000854 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000855
Alexandre Julliard329f0681996-04-14 13:21:20 +0000856 case WM_ENABLE:
Stephane Lussier93805341999-09-03 16:37:00 +0000857 es->bEnableState = (BOOL) wParam;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000858 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000859 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000860
Alexandre Julliard329f0681996-04-14 13:21:20 +0000861 case WM_ERASEBKGND:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000862 result = EDIT_WM_EraseBkGnd(es, (HDC)wParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000863 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000864
Alexandre Julliard329f0681996-04-14 13:21:20 +0000865 case WM_GETFONT:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000866 result = (LRESULT)es->font;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000867 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000868
Alexandre Julliard329f0681996-04-14 13:21:20 +0000869 case WM_GETTEXT:
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000870 result = (LRESULT)EDIT_WM_GetText(es, (INT)wParam, lParam, unicode);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000871 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000872
Alexandre Julliard329f0681996-04-14 13:21:20 +0000873 case WM_GETTEXTLENGTH:
Alexandre Julliard741325b2002-06-13 19:20:43 +0000874 if (unicode) result = strlenW(es->text);
875 else result = WideCharToMultiByte( CP_ACP, 0, es->text, strlenW(es->text),
876 NULL, 0, NULL, NULL );
Alexandre Julliard329f0681996-04-14 13:21:20 +0000877 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000878
Alexandre Julliard329f0681996-04-14 13:21:20 +0000879 case WM_HSCROLL:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000880 result = EDIT_WM_HScroll(es, LOWORD(wParam), (short)HIWORD(wParam));
Alexandre Julliard01d63461997-01-20 19:43:45 +0000881 break;
882
Alexandre Julliard329f0681996-04-14 13:21:20 +0000883 case WM_KEYDOWN:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000884 result = EDIT_WM_KeyDown(es, (INT)wParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000885 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000886
Alexandre Julliard329f0681996-04-14 13:21:20 +0000887 case WM_KILLFOCUS:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000888 result = EDIT_WM_KillFocus(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000889 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000890
Alexandre Julliard329f0681996-04-14 13:21:20 +0000891 case WM_LBUTTONDBLCLK:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000892 result = EDIT_WM_LButtonDblClk(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000893 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000894
Alexandre Julliard329f0681996-04-14 13:21:20 +0000895 case WM_LBUTTONDOWN:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000896 result = EDIT_WM_LButtonDown(es, wParam, (short)LOWORD(lParam), (short)HIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000897 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000898
Alexandre Julliard329f0681996-04-14 13:21:20 +0000899 case WM_LBUTTONUP:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000900 result = EDIT_WM_LButtonUp(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000901 break;
902
Vincent Béron9a624912002-05-31 23:06:46 +0000903 case WM_MBUTTONDOWN:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000904 result = EDIT_WM_MButtonDown(es);
Alexandre Julliardc6166252000-05-25 23:01:39 +0000905 break;
906
Alexandre Julliard889f7421997-04-15 17:19:52 +0000907 case WM_MOUSEACTIVATE:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000908 result = MA_ACTIVATE;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000909 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000910
Alexandre Julliard329f0681996-04-14 13:21:20 +0000911 case WM_MOUSEMOVE:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000912 result = EDIT_WM_MouseMove(es, (short)LOWORD(lParam), (short)HIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000913 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000914
Alexandre Julliard329f0681996-04-14 13:21:20 +0000915 case WM_PAINT:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000916 EDIT_WM_Paint(es, wParam);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000917 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000918
Alexandre Julliard329f0681996-04-14 13:21:20 +0000919 case WM_PASTE:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000920 EDIT_WM_Paste(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000921 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000922
Alexandre Julliard329f0681996-04-14 13:21:20 +0000923 case WM_SETFOCUS:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000924 EDIT_WM_SetFocus(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000925 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000926
Alexandre Julliard329f0681996-04-14 13:21:20 +0000927 case WM_SETFONT:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000928 EDIT_WM_SetFont(es, (HFONT)wParam, LOWORD(lParam) != 0);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000929 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000930
Dmitry Timoshkova234db82001-01-19 20:49:54 +0000931 case WM_SETREDRAW:
932 /* FIXME: actually set an internal flag and behave accordingly */
933 break;
934
Alexandre Julliard329f0681996-04-14 13:21:20 +0000935 case WM_SETTEXT:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000936 EDIT_WM_SetText(es, lParam, unicode);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000937 result = TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000938 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000939
Alexandre Julliard329f0681996-04-14 13:21:20 +0000940 case WM_SIZE:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000941 EDIT_WM_Size(es, (UINT)wParam, LOWORD(lParam), HIWORD(lParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000942 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000943
Bill Medland86bfa4c2001-06-28 18:01:00 +0000944 case WM_STYLECHANGED:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000945 result = EDIT_WM_StyleChanged(es, wParam, (const STYLESTRUCT *)lParam);
Bill Medland86bfa4c2001-06-28 18:01:00 +0000946 break;
Vincent Béron9a624912002-05-31 23:06:46 +0000947
Bill Medland86bfa4c2001-06-28 18:01:00 +0000948 case WM_STYLECHANGING:
Bill Medland86bfa4c2001-06-28 18:01:00 +0000949 result = 0; /* See EDIT_WM_StyleChanged */
950 break;
951
Alexandre Julliard01d63461997-01-20 19:43:45 +0000952 case WM_SYSKEYDOWN:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000953 result = EDIT_WM_SysKeyDown(es, (INT)wParam, (DWORD)lParam);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000954 break;
955
956 case WM_TIMER:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000957 EDIT_WM_Timer(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000958 break;
959
Alexandre Julliard329f0681996-04-14 13:21:20 +0000960 case WM_VSCROLL:
Alexandre Julliard9d615962003-09-17 04:28:28 +0000961 result = EDIT_WM_VScroll(es, LOWORD(wParam), (short)HIWORD(wParam));
Alexandre Julliard329f0681996-04-14 13:21:20 +0000962 break;
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000963
Stephane Lussier4bdf4af2000-04-18 11:56:33 +0000964 case WM_MOUSEWHEEL:
965 {
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +0000966 int gcWheelDelta = 0;
Stephane Lussier4bdf4af2000-04-18 11:56:33 +0000967 UINT pulScrollLines = 3;
968 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
969
970 if (wParam & (MK_SHIFT | MK_CONTROL)) {
Alexandre Julliardde424282001-08-10 22:51:42 +0000971 result = DefWindowProcW(hwnd, msg, wParam, lParam);
Stephane Lussier4bdf4af2000-04-18 11:56:33 +0000972 break;
973 }
Alexandre Julliard9d615962003-09-17 04:28:28 +0000974 gcWheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
Stephane Lussier4bdf4af2000-04-18 11:56:33 +0000975 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
976 {
977 int cLineScroll= (int) min((UINT) es->line_count, pulScrollLines);
978 cLineScroll *= (gcWheelDelta / WHEEL_DELTA);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000979 result = EDIT_EM_LineScroll(es, 0, cLineScroll);
Stephane Lussier4bdf4af2000-04-18 11:56:33 +0000980 }
981 }
982 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +0000983 default:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000984 result = DefWindowProcT(hwnd, msg, wParam, lParam, unicode);
Alexandre Julliard329f0681996-04-14 13:21:20 +0000985 break;
986 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +0000987
988 if (es) EDIT_UnlockBuffer(es, FALSE);
Robert Shearman85703282004-08-17 22:09:16 +0000989
990 TRACE("hwnd=%p msg=%x (%s) -- 0x%08lx\n", hwnd, msg, SPY_GetMsgName(msg, hwnd), result);
991
Alexandre Julliard889f7421997-04-15 17:19:52 +0000992 return result;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +0000993}
994
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +0000995/*********************************************************************
996 *
997 * EditWndProcW (USER32.@)
998 */
999LRESULT WINAPI EditWndProcW(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1000{
Alexandre Julliardde424282001-08-10 22:51:42 +00001001 return EditWndProc_common(hWnd, uMsg, wParam, lParam, TRUE);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001002}
1003
1004/*********************************************************************
1005 *
Patrik Stridvall15a3b742001-04-27 18:03:51 +00001006 * EditWndProc (USER32.@)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001007 */
1008LRESULT WINAPI EditWndProcA(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1009{
Alexandre Julliardde424282001-08-10 22:51:42 +00001010 return EditWndProc_common(hWnd, uMsg, wParam, lParam, FALSE);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001011}
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00001012
1013/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001014 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001015 * EDIT_BuildLineDefs_ML
Alexandre Julliard329f0681996-04-14 13:21:20 +00001016 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001017 * Build linked list of text lines.
1018 * Lines can end with '\0' (last line), a character (if it is wrapped),
1019 * a soft return '\r\r\n' or a hard return '\r\n'
Alexandre Julliard329f0681996-04-14 13:21:20 +00001020 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001021 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001022static void EDIT_BuildLineDefs_ML(EDITSTATE *es, INT istart, INT iend, INT delta, HRGN hrgn)
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001023{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001024 HDC dc;
1025 HFONT old_font = 0;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001026 LPWSTR current_position, cp;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001027 INT fw;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001028 LINEDEF *current_line;
1029 LINEDEF *previous_line;
1030 LINEDEF *start_line;
1031 INT line_index = 0, nstart_line = 0, nstart_index = 0;
1032 INT line_count = es->line_count;
1033 INT orig_net_length;
1034 RECT rc;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001035
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001036 if (istart == iend && delta == 0)
1037 return;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001038
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001039 dc = GetDC(es->hwndSelf);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001040 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001041 old_font = SelectObject(dc, es->font);
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001042
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001043 previous_line = NULL;
1044 current_line = es->first_line_def;
1045
1046 /* Find starting line. istart must lie inside an existing line or
1047 * at the end of buffer */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001048 do {
Vincent Béron9a624912002-05-31 23:06:46 +00001049 if (istart < current_line->index + current_line->length ||
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001050 current_line->ending == END_0)
1051 break;
Vincent Béron9a624912002-05-31 23:06:46 +00001052
1053 previous_line = current_line;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001054 current_line = current_line->next;
1055 line_index++;
1056 } while (current_line);
1057
1058 if (!current_line) /* Error occurred start is not inside previous buffer */
1059 {
1060 FIXME(" modification occurred outside buffer\n");
Christian Costa6e7d78e2003-05-11 03:27:23 +00001061 ReleaseDC(es->hwndSelf, dc);
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001062 return;
1063 }
1064
1065 /* Remember start of modifications in order to calculate update region */
1066 nstart_line = line_index;
1067 nstart_index = current_line->index;
1068
1069 /* We must start to reformat from the previous line since the modifications
1070 * may have caused the line to wrap upwards. */
1071 if (!(es->style & ES_AUTOHSCROLL) && line_index > 0)
1072 {
1073 line_index--;
1074 current_line = previous_line;
1075 }
1076 start_line = current_line;
1077
1078 fw = es->format_rect.right - es->format_rect.left;
1079 current_position = es->text + current_line->index;
1080 do {
1081 if (current_line != start_line)
1082 {
1083 if (!current_line || current_line->index + delta > current_position - es->text)
1084 {
Vincent Béron9a624912002-05-31 23:06:46 +00001085 /* The buffer has been expanded, create a new line and
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001086 insert it into the link list */
1087 LINEDEF *new_line = HeapAlloc(GetProcessHeap(), 0, sizeof(LINEDEF));
1088 new_line->next = previous_line->next;
1089 previous_line->next = new_line;
1090 current_line = new_line;
1091 es->line_count++;
1092 }
1093 else if (current_line->index + delta < current_position - es->text)
1094 {
1095 /* The previous line merged with this line so we delete this extra entry */
1096 previous_line->next = current_line->next;
1097 HeapFree(GetProcessHeap(), 0, current_line);
1098 current_line = previous_line->next;
1099 es->line_count--;
1100 continue;
1101 }
1102 else /* current_line->index + delta == current_position */
1103 {
1104 if (current_position - es->text > iend)
1105 break; /* We reached end of line modifications */
1106 /* else recalulate this line */
1107 }
1108 }
1109
1110 current_line->index = current_position - es->text;
1111 orig_net_length = current_line->net_length;
1112
1113 /* Find end of line */
1114 cp = current_position;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001115 while (*cp) {
Chuck Craynece2024c2002-04-22 23:08:19 +00001116 if (*cp == '\n') break;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001117 if ((*cp == '\r') && (*(cp + 1) == '\n'))
1118 break;
1119 cp++;
1120 }
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001121
1122 /* Mark type of line termination */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001123 if (!(*cp)) {
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001124 current_line->ending = END_0;
1125 current_line->net_length = strlenW(current_position);
1126 } else if ((cp > current_position) && (*(cp - 1) == '\r')) {
1127 current_line->ending = END_SOFT;
1128 current_line->net_length = cp - current_position - 1;
Chuck Craynece2024c2002-04-22 23:08:19 +00001129 } else if (*cp == '\n') {
1130 current_line->ending = END_RICH;
1131 current_line->net_length = cp - current_position;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001132 } else {
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001133 current_line->ending = END_HARD;
1134 current_line->net_length = cp - current_position;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001135 }
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001136
1137 /* Calculate line width */
1138 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1139 current_position, current_line->net_length,
Alexandre Julliard889f7421997-04-15 17:19:52 +00001140 es->tabs_count, es->tabs));
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001141
Alexandre Julliard889f7421997-04-15 17:19:52 +00001142 /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */
Ulrich Czekallaa935c2a2004-05-25 18:04:48 +00001143 if (!(es->style & ES_AUTOHSCROLL)) {
1144 if (current_line->width > fw) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001145 INT next = 0;
1146 INT prev;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001147 do {
1148 prev = next;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001149 next = EDIT_CallWordBreakProc(es, current_position - es->text,
1150 prev + 1, current_line->net_length, WB_RIGHT);
1151 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1152 current_position, next, es->tabs_count, es->tabs));
1153 } while (current_line->width <= fw);
1154 if (!prev) { /* Didn't find a line break so force a break */
Alexandre Julliard329f0681996-04-14 13:21:20 +00001155 next = 0;
1156 do {
1157 prev = next;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001158 next++;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001159 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc,
1160 current_position, next, es->tabs_count, es->tabs));
1161 } while (current_line->width <= fw);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001162 if (!prev)
1163 prev = 1;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001164 }
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001165
Vincent Béron9a624912002-05-31 23:06:46 +00001166 /* If the first line we are calculating, wrapped before istart, we must
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001167 * adjust istart in order for this to be reflected in the update region. */
1168 if (current_line->index == nstart_index && istart > current_line->index + prev)
1169 istart = current_line->index + prev;
1170 /* else if we are updating the previous line before the first line we
Andreas Mohr07216db2001-11-13 21:29:38 +00001171 * are re-calculating and it expanded */
Vincent Béron9a624912002-05-31 23:06:46 +00001172 else if (current_line == start_line &&
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001173 current_line->index != nstart_index && orig_net_length < prev)
Vincent Béron9a624912002-05-31 23:06:46 +00001174 {
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001175 /* Line expanded due to an upwards line wrap so we must partially include
1176 * previous line in update region */
1177 nstart_line = line_index;
1178 nstart_index = current_line->index;
1179 istart = current_line->index + orig_net_length;
1180 }
1181
1182 current_line->net_length = prev;
1183 current_line->ending = END_WRAP;
1184 current_line->width = (INT)LOWORD(GetTabbedTextExtentW(dc, current_position,
1185 current_line->net_length, es->tabs_count, es->tabs));
Ulrich Czekallaa935c2a2004-05-25 18:04:48 +00001186 }
1187 else if (orig_net_length < current_line->net_length &&
1188 current_line == start_line &&
1189 current_line->index != nstart_index) {
1190 /* The previous line expanded but it's still not as wide as the client rect */
1191 /* The expansion is due to an upwards line wrap so we must partially include
1192 it in the update region */
1193 nstart_line = line_index;
1194 nstart_index = current_line->index;
1195 istart = current_line->index + orig_net_length;
1196 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001197 }
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001198
1199
1200 /* Adjust length to include line termination */
1201 switch (current_line->ending) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001202 case END_SOFT:
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001203 current_line->length = current_line->net_length + 3;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001204 break;
Chuck Craynece2024c2002-04-22 23:08:19 +00001205 case END_RICH:
1206 current_line->length = current_line->net_length + 1;
1207 break;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001208 case END_HARD:
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001209 current_line->length = current_line->net_length + 2;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001210 break;
1211 case END_WRAP:
1212 case END_0:
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001213 current_line->length = current_line->net_length;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001214 break;
1215 }
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001216 es->text_width = max(es->text_width, current_line->width);
1217 current_position += current_line->length;
1218 previous_line = current_line;
1219 current_line = current_line->next;
1220 line_index++;
1221 } while (previous_line->ending != END_0);
1222
Andreas Mohr07216db2001-11-13 21:29:38 +00001223 /* Finish adjusting line indexes by delta or remove hanging lines */
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001224 if (previous_line->ending == END_0)
1225 {
1226 LINEDEF *pnext = NULL;
1227
1228 previous_line->next = NULL;
1229 while (current_line)
1230 {
1231 pnext = current_line->next;
1232 HeapFree(GetProcessHeap(), 0, current_line);
1233 current_line = pnext;
1234 es->line_count--;
1235 }
1236 }
1237 else
1238 {
1239 while (current_line)
1240 {
1241 current_line->index += delta;
1242 current_line = current_line->next;
1243 }
1244 }
1245
1246 /* Calculate rest of modification rectangle */
1247 if (hrgn)
1248 {
1249 HRGN tmphrgn;
Vincent Béron9a624912002-05-31 23:06:46 +00001250 /*
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001251 * We calculate two rectangles. One for the first line which may have
1252 * an indent with respect to the format rect. The other is a format-width
1253 * rectangle that spans the rest of the lines that changed or moved.
1254 */
Vincent Béron9a624912002-05-31 23:06:46 +00001255 rc.top = es->format_rect.top + nstart_line * es->line_height -
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001256 (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
1257 rc.bottom = rc.top + es->line_height;
Vincent Béron9a624912002-05-31 23:06:46 +00001258 rc.left = es->format_rect.left + (INT)LOWORD(GetTabbedTextExtentW(dc,
1259 es->text + nstart_index, istart - nstart_index,
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001260 es->tabs_count, es->tabs)) - es->x_offset; /* Adjust for horz scroll */
1261 rc.right = es->format_rect.right;
1262 SetRectRgn(hrgn, rc.left, rc.top, rc.right, rc.bottom);
1263
1264 rc.top = rc.bottom;
1265 rc.left = es->format_rect.left;
1266 rc.right = es->format_rect.right;
Vincent Béron9a624912002-05-31 23:06:46 +00001267 /*
1268 * If lines were added or removed we must re-paint the remainder of the
1269 * lines since the remaining lines were either shifted up or down.
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001270 */
1271 if (line_count < es->line_count) /* We added lines */
1272 rc.bottom = es->line_count * es->line_height;
1273 else if (line_count > es->line_count) /* We removed lines */
1274 rc.bottom = line_count * es->line_height;
1275 else
1276 rc.bottom = line_index * es->line_height;
1277 rc.bottom -= (es->y_offset * es->line_height); /* Adjust for vertical scrollbar */
1278 tmphrgn = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
1279 CombineRgn(hrgn, hrgn, tmphrgn, RGN_OR);
1280 DeleteObject(tmphrgn);
1281 }
1282
Alexandre Julliard889f7421997-04-15 17:19:52 +00001283 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001284 SelectObject(dc, old_font);
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00001285
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001286 ReleaseDC(es->hwndSelf, dc);
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001287}
1288
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00001289/*********************************************************************
1290 *
1291 * EDIT_CalcLineWidth_SL
1292 *
1293 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001294static void EDIT_CalcLineWidth_SL(EDITSTATE *es)
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00001295{
Alexandre Julliard9d615962003-09-17 04:28:28 +00001296 es->text_width = (short)LOWORD(EDIT_EM_PosFromChar(es, strlenW(es->text), FALSE));
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00001297}
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001298
Alexandre Julliard329f0681996-04-14 13:21:20 +00001299/*********************************************************************
1300 *
1301 * EDIT_CallWordBreakProc
1302 *
1303 * Call appropriate WordBreakProc (internal or external).
1304 *
Andreas Mohr07216db2001-11-13 21:29:38 +00001305 * Note: The "start" argument should always be an index referring
Alexandre Julliard889f7421997-04-15 17:19:52 +00001306 * to es->text. The actual wordbreak proc might be
1307 * 16 bit, so we can't always pass any 32 bit LPSTR.
1308 * Hence we assume that es->text is the buffer that holds
1309 * the string under examination (we can decide this for ourselves).
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001310 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00001311 */
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +00001312static INT EDIT_CallWordBreakProc(EDITSTATE *es, INT start, INT index, INT count, INT action)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001313{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001314 INT ret, iWndsLocks;
1315
Andreas Mohr07216db2001-11-13 21:29:38 +00001316 /* To avoid any deadlocks, all the locks on the window structures
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001317 must be suspended before the control is passed to the application */
1318 iWndsLocks = WIN_SuspendWndsLock();
1319
Alexandre Julliard889f7421997-04-15 17:19:52 +00001320 if (es->word_break_proc16) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001321 HGLOBAL16 hglob16;
1322 SEGPTR segptr;
1323 INT countA;
Alexandre Julliard7e92c9a2003-02-27 21:09:45 +00001324 WORD args[5];
1325 DWORD result;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001326
1327 countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
1328 hglob16 = GlobalAlloc16(GMEM_MOVEABLE | GMEM_ZEROINIT, countA);
Alexandre Julliard58017232000-12-22 01:09:26 +00001329 segptr = K32WOWGlobalLock16(hglob16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001330 WideCharToMultiByte(CP_ACP, 0, es->text + start, count, MapSL(segptr), countA, NULL, NULL);
Alexandre Julliard7e92c9a2003-02-27 21:09:45 +00001331 args[4] = SELECTOROF(segptr);
1332 args[3] = OFFSETOF(segptr);
1333 args[2] = index;
1334 args[1] = countA;
1335 args[0] = action;
1336 WOWCallback16Ex((DWORD)es->word_break_proc16, WCB16_PASCAL, sizeof(args), args, &result);
1337 ret = LOWORD(result);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001338 GlobalUnlock16(hglob16);
1339 GlobalFree16(hglob16);
Alexandre Julliard77b99181997-09-14 17:17:23 +00001340 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001341 else if (es->word_break_proc)
Alexandre Julliard77b99181997-09-14 17:17:23 +00001342 {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001343 if(es->is_unicode)
1344 {
1345 EDITWORDBREAKPROCW wbpW = (EDITWORDBREAKPROCW)es->word_break_proc;
1346
1347 TRACE_(relay)("(UNICODE wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1348 es->word_break_proc, debugstr_wn(es->text + start, count), index, count, action);
1349 ret = wbpW(es->text + start, index, count, action);
1350 }
1351 else
1352 {
1353 EDITWORDBREAKPROCA wbpA = (EDITWORDBREAKPROCA)es->word_break_proc;
1354 INT countA;
1355 CHAR *textA;
1356
1357 countA = WideCharToMultiByte(CP_ACP, 0, es->text + start, count, NULL, 0, NULL, NULL);
1358 textA = HeapAlloc(GetProcessHeap(), 0, countA);
1359 WideCharToMultiByte(CP_ACP, 0, es->text + start, count, textA, countA, NULL, NULL);
1360 TRACE_(relay)("(ANSI wordbrk=%p,str=%s,idx=%d,cnt=%d,act=%d)\n",
1361 es->word_break_proc, debugstr_an(textA, countA), index, countA, action);
1362 ret = wbpA(textA, index, countA, action);
1363 HeapFree(GetProcessHeap(), 0, textA);
1364 }
Alexandre Julliard77b99181997-09-14 17:17:23 +00001365 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001366 else
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001367 ret = EDIT_WordBreakProc(es->text + start, index, count, action);
1368
1369 WIN_RestoreWndsLock(iWndsLocks);
1370 return ret;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001371}
1372
Alexandre Julliard329f0681996-04-14 13:21:20 +00001373
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001374/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001375 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001376 * EDIT_CharFromPos
Alexandre Julliard329f0681996-04-14 13:21:20 +00001377 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001378 * Beware: This is not the function called on EM_CHARFROMPOS
1379 * The position _can_ be outside the formatting / client
1380 * rectangle
1381 * The return value is only the character index
Alexandre Julliard329f0681996-04-14 13:21:20 +00001382 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001383 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001384static INT EDIT_CharFromPos(EDITSTATE *es, INT x, INT y, LPBOOL after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001385{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001386 INT index;
1387 HDC dc;
1388 HFONT old_font = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001389
Alexandre Julliard889f7421997-04-15 17:19:52 +00001390 if (es->style & ES_MULTILINE) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001391 INT line = (y - es->format_rect.top) / es->line_height + es->y_offset;
1392 INT line_index = 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001393 LINEDEF *line_def = es->first_line_def;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001394 INT low, high;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001395 while ((line > 0) && line_def->next) {
1396 line_index += line_def->length;
1397 line_def = line_def->next;
1398 line--;
1399 }
1400 x += es->x_offset - es->format_rect.left;
1401 if (x >= line_def->width) {
1402 if (after_wrap)
1403 *after_wrap = (line_def->ending == END_WRAP);
1404 return line_index + line_def->net_length;
1405 }
1406 if (x <= 0) {
1407 if (after_wrap)
1408 *after_wrap = FALSE;
1409 return line_index;
1410 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001411 dc = GetDC(es->hwndSelf);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001412 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001413 old_font = SelectObject(dc, es->font);
Alexandre Julliarde658d821997-11-30 17:45:40 +00001414 low = line_index + 1;
1415 high = line_index + line_def->net_length + 1;
1416 while (low < high - 1)
1417 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001418 INT mid = (low + high) / 2;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001419 if (LOWORD(GetTabbedTextExtentW(dc, es->text + line_index,mid - line_index, es->tabs_count, es->tabs)) > x) high = mid;
Alexandre Julliarde658d821997-11-30 17:45:40 +00001420 else low = mid;
1421 }
1422 index = low;
1423
Alexandre Julliard889f7421997-04-15 17:19:52 +00001424 if (after_wrap)
1425 *after_wrap = ((index == line_index + line_def->net_length) &&
1426 (line_def->ending == END_WRAP));
1427 } else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001428 LPWSTR text;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001429 SIZE size;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001430 if (after_wrap)
1431 *after_wrap = FALSE;
1432 x -= es->format_rect.left;
1433 if (!x)
1434 return es->x_offset;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001435 text = EDIT_GetPasswordPointer_SL(es);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001436 dc = GetDC(es->hwndSelf);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001437 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001438 old_font = SelectObject(dc, es->font);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001439 if (x < 0)
1440 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001441 INT low = 0;
1442 INT high = es->x_offset;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001443 while (low < high - 1)
1444 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001445 INT mid = (low + high) / 2;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001446 GetTextExtentPoint32W( dc, text + mid,
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001447 es->x_offset - mid, &size );
1448 if (size.cx > -x) low = mid;
1449 else high = mid;
1450 }
1451 index = low;
1452 }
1453 else
1454 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001455 INT low = es->x_offset;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001456 INT high = strlenW(es->text) + 1;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001457 while (low < high - 1)
1458 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001459 INT mid = (low + high) / 2;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001460 GetTextExtentPoint32W( dc, text + es->x_offset,
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001461 mid - es->x_offset, &size );
1462 if (size.cx > x) high = mid;
1463 else low = mid;
1464 }
1465 index = low;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001466 }
1467 if (es->style & ES_PASSWORD)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001468 HeapFree(GetProcessHeap(), 0, text);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001469 }
1470 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001471 SelectObject(dc, old_font);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001472 ReleaseDC(es->hwndSelf, dc);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001473 return index;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001474}
1475
Alexandre Julliard329f0681996-04-14 13:21:20 +00001476
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001477/*********************************************************************
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00001478 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001479 * EDIT_ConfinePoint
Alexandre Julliard329f0681996-04-14 13:21:20 +00001480 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001481 * adjusts the point to be within the formatting rectangle
1482 * (so CharFromPos returns the nearest _visible_ character)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001483 *
1484 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001485static void EDIT_ConfinePoint(EDITSTATE *es, LPINT x, LPINT y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001486{
Francois Gouget6d77d3a2000-03-25 21:44:35 +00001487 *x = min(max(*x, es->format_rect.left), es->format_rect.right - 1);
1488 *y = min(max(*y, es->format_rect.top), es->format_rect.bottom - 1);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001489}
1490
1491
1492/*********************************************************************
1493 *
1494 * EDIT_GetLineRect
1495 *
1496 * Calculates the bounding rectangle for a line from a starting
1497 * column to an ending column.
1498 *
1499 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001500static void EDIT_GetLineRect(EDITSTATE *es, INT line, INT scol, INT ecol, LPRECT rc)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001501{
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001502 INT line_index = EDIT_EM_LineIndex(es, line);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001503
1504 if (es->style & ES_MULTILINE)
1505 rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height;
1506 else
1507 rc->top = es->format_rect.top;
1508 rc->bottom = rc->top + es->line_height;
Alexandre Julliard9d615962003-09-17 04:28:28 +00001509 rc->left = (scol == 0) ? es->format_rect.left : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + scol, TRUE));
1510 rc->right = (ecol == -1) ? es->format_rect.right : (short)LOWORD(EDIT_EM_PosFromChar(es, line_index + ecol, TRUE));
Alexandre Julliard329f0681996-04-14 13:21:20 +00001511}
1512
1513
1514/*********************************************************************
1515 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001516 * EDIT_GetPasswordPointer_SL
1517 *
1518 * note: caller should free the (optionally) allocated buffer
1519 *
1520 */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001521static LPWSTR EDIT_GetPasswordPointer_SL(EDITSTATE *es)
Alexandre Julliard889f7421997-04-15 17:19:52 +00001522{
1523 if (es->style & ES_PASSWORD) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001524 INT len = strlenW(es->text);
1525 LPWSTR text = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
Alexandre Julliard889f7421997-04-15 17:19:52 +00001526 text[len] = '\0';
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +00001527 while(len) text[--len] = es->password_char;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001528 return text;
1529 } else
1530 return es->text;
1531}
1532
1533
1534/*********************************************************************
1535 *
1536 * EDIT_LockBuffer
Alexandre Julliard329f0681996-04-14 13:21:20 +00001537 *
1538 * This acts as a LOCAL_Lock(), but it locks only once. This way
1539 * you can call it whenever you like, without unlocking.
1540 *
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001541 * Initially the edit control allocates a HLOCAL32 buffer
1542 * (32 bit linear memory handler). However, 16 bit application
1543 * might send a EM_GETHANDLE message and expect a HLOCAL16 (16 bit SEG:OFF
1544 * handler). From that moment on we have to keep using this 16 bit memory
1545 * handler, because it is supposed to be valid at all times after EM_GETHANDLE.
1546 * What we do is create a HLOCAL16 buffer, copy the text, and do pointer
1547 * conversion.
1548 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00001549 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001550static void EDIT_LockBuffer(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001551{
Robert Shearman2e9436c2004-08-17 22:29:29 +00001552 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
Alexandre Julliard889f7421997-04-15 17:19:52 +00001553 if (!es->text) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001554 CHAR *textA = NULL;
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00001555 UINT countA = 0;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001556 BOOL _16bit = FALSE;
1557
1558 if(es->hloc32W)
1559 {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001560 if(es->hloc32A)
1561 {
1562 TRACE("Synchronizing with 32-bit ANSI buffer\n");
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001563 textA = LocalLock(es->hloc32A);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00001564 countA = strlen(textA) + 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001565 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001566 else if(es->hloc16)
1567 {
1568 TRACE("Synchronizing with 16-bit ANSI buffer\n");
Alexandre Julliardde424282001-08-10 22:51:42 +00001569 textA = LOCAL_Lock(hInstance, es->hloc16);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00001570 countA = strlen(textA) + 1;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001571 _16bit = TRUE;
1572 }
1573 }
1574 else {
1575 ERR("no buffer ... please report\n");
1576 return;
1577 }
1578
1579 if(textA)
1580 {
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00001581 HLOCAL hloc32W_new;
1582 UINT countW_new = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
1583 TRACE("%d bytes translated to %d WCHARs\n", countA, countW_new);
1584 if(countW_new > es->buffer_size + 1)
1585 {
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00001586 UINT alloc_size = ROUND_TO_GROW(countW_new * sizeof(WCHAR));
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00001587 TRACE("Resizing 32-bit UNICODE buffer from %d+1 to %d WCHARs\n", es->buffer_size, countW_new);
1588 hloc32W_new = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
1589 if(hloc32W_new)
1590 {
1591 es->hloc32W = hloc32W_new;
1592 es->buffer_size = LocalSize(hloc32W_new)/sizeof(WCHAR) - 1;
1593 TRACE("Real new size %d+1 WCHARs\n", es->buffer_size);
1594 }
1595 else
1596 WARN("FAILED! Will synchronize partially\n");
1597 }
1598 }
1599
1600 /*TRACE("Locking 32-bit UNICODE buffer\n");*/
1601 es->text = LocalLock(es->hloc32W);
1602
1603 if(textA)
1604 {
1605 MultiByteToWideChar(CP_ACP, 0, textA, countA, es->text, es->buffer_size + 1);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001606 if(_16bit)
Alexandre Julliardde424282001-08-10 22:51:42 +00001607 LOCAL_Unlock(hInstance, es->hloc16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001608 else
1609 LocalUnlock(es->hloc32A);
1610 }
Alexandre Julliard3051b641996-07-05 17:14:13 +00001611 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00001612 es->lock_count++;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001613}
1614
1615
1616/*********************************************************************
1617 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001618 * EDIT_SL_InvalidateText
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001619 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001620 * Called from EDIT_InvalidateText().
1621 * Does the job for single-line controls only.
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001622 *
1623 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001624static void EDIT_SL_InvalidateText(EDITSTATE *es, INT start, INT end)
Alexandre Julliard139a4b11996-11-02 14:24:07 +00001625{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001626 RECT line_rect;
1627 RECT rc;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001628
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001629 EDIT_GetLineRect(es, 0, start, end, &line_rect);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001630 if (IntersectRect(&rc, &line_rect, &es->format_rect))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001631 EDIT_UpdateText(es, &rc, TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001632}
1633
1634
1635/*********************************************************************
1636 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001637 * EDIT_ML_InvalidateText
1638 *
1639 * Called from EDIT_InvalidateText().
1640 * Does the job for multi-line controls only.
Alexandre Julliard329f0681996-04-14 13:21:20 +00001641 *
1642 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001643static void EDIT_ML_InvalidateText(EDITSTATE *es, INT start, INT end)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001644{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001645 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001646 INT sl = EDIT_EM_LineFromChar(es, start);
1647 INT el = EDIT_EM_LineFromChar(es, end);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001648 INT sc;
1649 INT ec;
1650 RECT rc1;
1651 RECT rcWnd;
1652 RECT rcLine;
1653 RECT rcUpdate;
1654 INT l;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001655
Alexandre Julliard889f7421997-04-15 17:19:52 +00001656 if ((el < es->y_offset) || (sl > es->y_offset + vlc))
1657 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001658
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001659 sc = start - EDIT_EM_LineIndex(es, sl);
1660 ec = end - EDIT_EM_LineIndex(es, el);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001661 if (sl < es->y_offset) {
1662 sl = es->y_offset;
1663 sc = 0;
1664 }
1665 if (el > es->y_offset + vlc) {
1666 el = es->y_offset + vlc;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001667 ec = EDIT_EM_LineLength(es, EDIT_EM_LineIndex(es, el));
Alexandre Julliard889f7421997-04-15 17:19:52 +00001668 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001669 GetClientRect(es->hwndSelf, &rc1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001670 IntersectRect(&rcWnd, &rc1, &es->format_rect);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001671 if (sl == el) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001672 EDIT_GetLineRect(es, sl, sc, ec, &rcLine);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001673 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001674 EDIT_UpdateText(es, &rcUpdate, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001675 } else {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001676 EDIT_GetLineRect(es, sl, sc,
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001677 EDIT_EM_LineLength(es,
1678 EDIT_EM_LineIndex(es, sl)),
Alexandre Julliard889f7421997-04-15 17:19:52 +00001679 &rcLine);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001680 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001681 EDIT_UpdateText(es, &rcUpdate, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001682 for (l = sl + 1 ; l < el ; l++) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001683 EDIT_GetLineRect(es, l, 0,
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00001684 EDIT_EM_LineLength(es,
1685 EDIT_EM_LineIndex(es, l)),
Alexandre Julliard889f7421997-04-15 17:19:52 +00001686 &rcLine);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001687 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001688 EDIT_UpdateText(es, &rcUpdate, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001689 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001690 EDIT_GetLineRect(es, el, 0, ec, &rcLine);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001691 if (IntersectRect(&rcUpdate, &rcWnd, &rcLine))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001692 EDIT_UpdateText(es, &rcUpdate, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001693 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001694}
1695
1696
1697/*********************************************************************
1698 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001699 * EDIT_InvalidateText
1700 *
1701 * Invalidate the text from offset start upto, but not including,
1702 * offset end. Useful for (re)painting the selection.
1703 * Regions outside the linewidth are not invalidated.
1704 * end == -1 means end == TextLength.
1705 * start and end need not be ordered.
1706 *
1707 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001708static void EDIT_InvalidateText(EDITSTATE *es, INT start, INT end)
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001709{
Alexandre Julliard01d63461997-01-20 19:43:45 +00001710 if (end == start)
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001711 return;
1712
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001713 if (end == -1)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001714 end = strlenW(es->text);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001715
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001716 if (end < start) {
1717 INT tmp = start;
1718 start = end;
1719 end = tmp;
1720 }
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00001721
Alexandre Julliard889f7421997-04-15 17:19:52 +00001722 if (es->style & ES_MULTILINE)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001723 EDIT_ML_InvalidateText(es, start, end);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001724 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001725 EDIT_SL_InvalidateText(es, start, end);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001726}
1727
1728
1729/*********************************************************************
1730 *
1731 * EDIT_MakeFit
1732 *
Carl Sopchak23b88ef2002-11-21 03:57:05 +00001733 * Try to fit size + 1 characters in the buffer.
Alexandre Julliard329f0681996-04-14 13:21:20 +00001734 */
Krishna Murthy4af4ba42004-05-29 00:21:51 +00001735static BOOL EDIT_MakeFit(EDITSTATE *es, UINT size)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001736{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001737 HLOCAL hNew32W;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001738
Brad Campbell4ba690e2003-04-27 00:32:22 +00001739 if (size <= es->buffer_size)
1740 return TRUE;
1741
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001742 TRACE("trying to ReAlloc to %d+1 characters\n", size);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001743
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001744 /* Force edit to unlock it's buffer. es->text now NULL */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001745 EDIT_UnlockBuffer(es, TRUE);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001746
1747 if (es->hloc32W) {
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00001748 UINT alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00001749 if ((hNew32W = LocalReAlloc(es->hloc32W, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT))) {
Alexandre Julliardaff7dda2002-11-22 21:22:14 +00001750 TRACE("Old 32 bit handle %p, new handle %p\n", es->hloc32W, hNew32W);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001751 es->hloc32W = hNew32W;
1752 es->buffer_size = LocalSize(hNew32W)/sizeof(WCHAR) - 1;
1753 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00001754 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001755
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001756 EDIT_LockBuffer(es);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001757
Alexandre Julliard889f7421997-04-15 17:19:52 +00001758 if (es->buffer_size < size) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001759 WARN("FAILED ! We now have %d+1\n", es->buffer_size);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001760 EDIT_NOTIFY_PARENT(es, EN_ERRSPACE, "EN_ERRSPACE");
Alexandre Julliard889f7421997-04-15 17:19:52 +00001761 return FALSE;
1762 } else {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001763 TRACE("We now have %d+1\n", es->buffer_size);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001764 return TRUE;
1765 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00001766}
1767
1768
1769/*********************************************************************
1770 *
1771 * EDIT_MakeUndoFit
1772 *
1773 * Try to fit size + 1 bytes in the undo buffer.
1774 *
1775 */
Dmitry Timoshkov366c0a12000-12-22 20:28:05 +00001776static BOOL EDIT_MakeUndoFit(EDITSTATE *es, UINT size)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001777{
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00001778 UINT alloc_size;
1779
Alexandre Julliard889f7421997-04-15 17:19:52 +00001780 if (size <= es->undo_buffer_size)
Alexandre Julliard01d63461997-01-20 19:43:45 +00001781 return TRUE;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001782
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00001783 TRACE("trying to ReAlloc to %d+1\n", size);
Alexandre Julliard01d63461997-01-20 19:43:45 +00001784
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00001785 alloc_size = ROUND_TO_GROW((size + 1) * sizeof(WCHAR));
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00001786 if ((es->undo_text = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, es->undo_text, alloc_size))) {
Alexandre Julliard6356a442003-02-19 22:04:03 +00001787 es->undo_buffer_size = alloc_size/sizeof(WCHAR) - 1;
Alexandre Julliard01d63461997-01-20 19:43:45 +00001788 return TRUE;
1789 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001790 else
1791 {
1792 WARN("FAILED ! We now have %d+1\n", es->undo_buffer_size);
1793 return FALSE;
1794 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00001795}
1796
1797
1798/*********************************************************************
1799 *
1800 * EDIT_MoveBackward
1801 *
1802 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001803static void EDIT_MoveBackward(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001804{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001805 INT e = es->selection_end;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001806
Alexandre Julliard889f7421997-04-15 17:19:52 +00001807 if (e) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001808 e--;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001809 if ((es->style & ES_MULTILINE) && e &&
1810 (es->text[e - 1] == '\r') && (es->text[e] == '\n')) {
1811 e--;
1812 if (e && (es->text[e - 1] == '\r'))
1813 e--;
1814 }
1815 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001816 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1817 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001818}
1819
1820
1821/*********************************************************************
1822 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001823 * EDIT_MoveDown_ML
1824 *
1825 * Only for multi line controls
1826 * Move the caret one line down, on a column with the nearest
1827 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001828 *
1829 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001830static void EDIT_MoveDown_ML(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001831{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001832 INT s = es->selection_start;
1833 INT e = es->selection_end;
1834 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001835 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
Alexandre Julliard9d615962003-09-17 04:28:28 +00001836 INT x = (short)LOWORD(pos);
1837 INT y = (short)HIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001838
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001839 e = EDIT_CharFromPos(es, x, y + es->line_height, &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001840 if (!extend)
1841 s = e;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001842 EDIT_EM_SetSel(es, s, e, after_wrap);
1843 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001844}
1845
1846
1847/*********************************************************************
1848 *
1849 * EDIT_MoveEnd
1850 *
1851 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001852static void EDIT_MoveEnd(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001853{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001854 BOOL after_wrap = FALSE;
1855 INT e;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001856
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001857 /* Pass a high value in x to make sure of receiving the end of the line */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001858 if (es->style & ES_MULTILINE)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001859 e = EDIT_CharFromPos(es, 0x3fffffff,
1860 HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001861 else
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00001862 e = strlenW(es->text);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001863 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, after_wrap);
1864 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001865}
1866
1867
1868/*********************************************************************
1869 *
1870 * EDIT_MoveForward
1871 *
1872 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001873static void EDIT_MoveForward(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001874{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001875 INT e = es->selection_end;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001876
Alexandre Julliard889f7421997-04-15 17:19:52 +00001877 if (es->text[e]) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00001878 e++;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001879 if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) {
1880 if (es->text[e] == '\n')
1881 e++;
1882 else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n'))
1883 e += 2;
1884 }
1885 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001886 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1887 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001888}
1889
1890
1891/*********************************************************************
1892 *
1893 * EDIT_MoveHome
1894 *
1895 * Home key: move to beginning of line.
1896 *
1897 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001898static void EDIT_MoveHome(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001899{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001900 INT e;
Alexandre Julliard329f0681996-04-14 13:21:20 +00001901
Pascal Lessard3405f5c1999-09-04 10:59:07 +00001902 /* Pass the x_offset in x to make sure of receiving the first position of the line */
Alexandre Julliard889f7421997-04-15 17:19:52 +00001903 if (es->style & ES_MULTILINE)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001904 e = EDIT_CharFromPos(es, -es->x_offset,
1905 HIWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001906 else
Alexandre Julliardd37eb361997-07-20 16:23:21 +00001907 e = 0;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001908 EDIT_EM_SetSel(es, extend ? es->selection_start : e, e, FALSE);
1909 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001910}
1911
1912
1913/*********************************************************************
1914 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001915 * EDIT_MovePageDown_ML
1916 *
1917 * Only for multi line controls
1918 * Move the caret one page down, on a column with the nearest
1919 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001920 *
1921 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001922static void EDIT_MovePageDown_ML(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001923{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001924 INT s = es->selection_start;
1925 INT e = es->selection_end;
1926 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001927 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
Alexandre Julliard9d615962003-09-17 04:28:28 +00001928 INT x = (short)LOWORD(pos);
1929 INT y = (short)HIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001930
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001931 e = EDIT_CharFromPos(es, x,
Alexandre Julliard889f7421997-04-15 17:19:52 +00001932 y + (es->format_rect.bottom - es->format_rect.top),
1933 &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001934 if (!extend)
1935 s = e;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001936 EDIT_EM_SetSel(es, s, e, after_wrap);
1937 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001938}
1939
1940
1941/*********************************************************************
1942 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001943 * EDIT_MovePageUp_ML
1944 *
1945 * Only for multi line controls
1946 * Move the caret one page up, on a column with the nearest
1947 * x coordinate on the screen (might be a different column).
Alexandre Julliard329f0681996-04-14 13:21:20 +00001948 *
1949 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001950static void EDIT_MovePageUp_ML(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001951{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001952 INT s = es->selection_start;
1953 INT e = es->selection_end;
1954 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001955 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
Alexandre Julliard9d615962003-09-17 04:28:28 +00001956 INT x = (short)LOWORD(pos);
1957 INT y = (short)HIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001958
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001959 e = EDIT_CharFromPos(es, x,
Alexandre Julliard889f7421997-04-15 17:19:52 +00001960 y - (es->format_rect.bottom - es->format_rect.top),
1961 &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001962 if (!extend)
1963 s = e;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001964 EDIT_EM_SetSel(es, s, e, after_wrap);
1965 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001966}
1967
1968
1969/*********************************************************************
1970 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001971 * EDIT_MoveUp_ML
Alexandre Julliard329f0681996-04-14 13:21:20 +00001972 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00001973 * Only for multi line controls
1974 * Move the caret one line up, on a column with the nearest
1975 * x coordinate on the screen (might be a different column).
1976 *
Vincent Béron9a624912002-05-31 23:06:46 +00001977 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001978static void EDIT_MoveUp_ML(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00001979{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001980 INT s = es->selection_start;
1981 INT e = es->selection_end;
1982 BOOL after_wrap = (es->flags & EF_AFTER_WRAP);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001983 LRESULT pos = EDIT_EM_PosFromChar(es, e, after_wrap);
Alexandre Julliard9d615962003-09-17 04:28:28 +00001984 INT x = (short)LOWORD(pos);
1985 INT y = (short)HIWORD(pos);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001986
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001987 e = EDIT_CharFromPos(es, x, y - es->line_height, &after_wrap);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001988 if (!extend)
1989 s = e;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00001990 EDIT_EM_SetSel(es, s, e, after_wrap);
1991 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00001992}
1993
1994
1995/*********************************************************************
1996 *
1997 * EDIT_MoveWordBackward
1998 *
1999 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002000static void EDIT_MoveWordBackward(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002001{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002002 INT s = es->selection_start;
2003 INT e = es->selection_end;
2004 INT l;
2005 INT ll;
2006 INT li;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002007
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002008 l = EDIT_EM_LineFromChar(es, e);
2009 ll = EDIT_EM_LineLength(es, e);
2010 li = EDIT_EM_LineIndex(es, l);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002011 if (e - li == 0) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00002012 if (l) {
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002013 li = EDIT_EM_LineIndex(es, l - 1);
2014 e = li + EDIT_EM_LineLength(es, li);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002015 }
2016 } else {
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +00002017 e = li + (INT)EDIT_CallWordBreakProc(es,
Alexandre Julliard889f7421997-04-15 17:19:52 +00002018 li, e - li, ll, WB_LEFT);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002019 }
2020 if (!extend)
2021 s = e;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002022 EDIT_EM_SetSel(es, s, e, FALSE);
2023 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002024}
2025
2026
2027/*********************************************************************
2028 *
2029 * EDIT_MoveWordForward
2030 *
2031 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002032static void EDIT_MoveWordForward(EDITSTATE *es, BOOL extend)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002033{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002034 INT s = es->selection_start;
2035 INT e = es->selection_end;
2036 INT l;
2037 INT ll;
2038 INT li;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002039
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002040 l = EDIT_EM_LineFromChar(es, e);
2041 ll = EDIT_EM_LineLength(es, e);
2042 li = EDIT_EM_LineIndex(es, l);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002043 if (e - li == ll) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002044 if ((es->style & ES_MULTILINE) && (l != es->line_count - 1))
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002045 e = EDIT_EM_LineIndex(es, l + 1);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002046 } else {
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +00002047 e = li + EDIT_CallWordBreakProc(es,
Alexandre Julliard889f7421997-04-15 17:19:52 +00002048 li, e - li + 1, ll, WB_RIGHT);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002049 }
2050 if (!extend)
2051 s = e;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002052 EDIT_EM_SetSel(es, s, e, FALSE);
2053 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002054}
2055
2056
2057/*********************************************************************
2058 *
2059 * EDIT_PaintLine
2060 *
2061 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002062static void EDIT_PaintLine(EDITSTATE *es, HDC dc, INT line, BOOL rev)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002063{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002064 INT s = es->selection_start;
2065 INT e = es->selection_end;
2066 INT li;
2067 INT ll;
2068 INT x;
2069 INT y;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002070 LRESULT pos;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002071
Alexandre Julliard889f7421997-04-15 17:19:52 +00002072 if (es->style & ES_MULTILINE) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002073 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002074 if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count))
2075 return;
2076 } else if (line)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002077 return;
2078
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002079 TRACE("line=%d\n", line);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002080
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002081 pos = EDIT_EM_PosFromChar(es, EDIT_EM_LineIndex(es, line), FALSE);
Alexandre Julliard9d615962003-09-17 04:28:28 +00002082 x = (short)LOWORD(pos);
2083 y = (short)HIWORD(pos);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002084 li = EDIT_EM_LineIndex(es, line);
2085 ll = EDIT_EM_LineLength(es, li);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002086 s = min(es->selection_start, es->selection_end);
2087 e = max(es->selection_start, es->selection_end);
Francois Gouget6d77d3a2000-03-25 21:44:35 +00002088 s = min(li + ll, max(li, s));
2089 e = min(li + ll, max(li, e));
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002090 if (rev && (s != e) &&
Alexandre Julliard889f7421997-04-15 17:19:52 +00002091 ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) {
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002092 x += EDIT_PaintText(es, dc, x, y, line, 0, s - li, FALSE);
2093 x += EDIT_PaintText(es, dc, x, y, line, s - li, e - s, TRUE);
2094 x += EDIT_PaintText(es, dc, x, y, line, e - li, li + ll - e, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002095 } else
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002096 x += EDIT_PaintText(es, dc, x, y, line, 0, ll, FALSE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002097}
2098
2099
2100/*********************************************************************
2101 *
2102 * EDIT_PaintText
2103 *
2104 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002105static INT EDIT_PaintText(EDITSTATE *es, HDC dc, INT x, INT y, INT line, INT col, INT count, BOOL rev)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002106{
Alexandre Julliard329f0681996-04-14 13:21:20 +00002107 COLORREF BkColor;
2108 COLORREF TextColor;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002109 INT ret;
2110 INT li;
Dan Engel7c7a3572001-04-16 19:32:05 +00002111 INT BkMode;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002112 SIZE size;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002113
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002114 if (!count)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002115 return 0;
Dan Engel7c7a3572001-04-16 19:32:05 +00002116 BkMode = GetBkMode(dc);
Alexandre Julliarda3960291999-02-26 11:11:13 +00002117 BkColor = GetBkColor(dc);
2118 TextColor = GetTextColor(dc);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002119 if (rev) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002120 SetBkColor(dc, GetSysColor(COLOR_HIGHLIGHT));
2121 SetTextColor(dc, GetSysColor(COLOR_HIGHLIGHTTEXT));
Dan Engel7c7a3572001-04-16 19:32:05 +00002122 SetBkMode( dc, OPAQUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002123 }
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002124 li = EDIT_EM_LineIndex(es, line);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002125 if (es->style & ES_MULTILINE) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002126 ret = (INT)LOWORD(TabbedTextOutW(dc, x, y, es->text + li + col, count,
Alexandre Julliard889f7421997-04-15 17:19:52 +00002127 es->tabs_count, es->tabs, es->format_rect.left - es->x_offset));
2128 } else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002129 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
2130 TextOutW(dc, x, y, text + li + col, count);
2131 GetTextExtentPoint32W(dc, text + li + col, count, &size);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002132 ret = size.cx;
2133 if (es->style & ES_PASSWORD)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002134 HeapFree(GetProcessHeap(), 0, text);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002135 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002136 if (rev) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002137 SetBkColor(dc, BkColor);
2138 SetTextColor(dc, TextColor);
Dan Engel7c7a3572001-04-16 19:32:05 +00002139 SetBkMode( dc, BkMode);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002140 }
2141 return ret;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002142}
Alexandre Julliard329f0681996-04-14 13:21:20 +00002143
2144
2145/*********************************************************************
2146 *
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00002147 * EDIT_SetCaretPos
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002148 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002149 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002150static void EDIT_SetCaretPos(EDITSTATE *es, INT pos,
Alexandre Julliarda3960291999-02-26 11:11:13 +00002151 BOOL after_wrap)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002152{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002153 LRESULT res = EDIT_EM_PosFromChar(es, pos, after_wrap);
Lionel Ulmer28d9aaf2004-03-29 22:54:05 +00002154 TRACE("%d - %dx%d\n", pos, (short)LOWORD(res), (short)HIWORD(res));
Alexandre Julliard9d615962003-09-17 04:28:28 +00002155 SetCaretPos((short)LOWORD(res), (short)HIWORD(res));
Alexandre Julliard01d63461997-01-20 19:43:45 +00002156}
2157
2158
2159/*********************************************************************
2160 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002161 * EDIT_SetRectNP
Alexandre Julliard329f0681996-04-14 13:21:20 +00002162 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002163 * note: this is not (exactly) the handler called on EM_SETRECTNP
2164 * it is also used to set the rect of a single line control
Alexandre Julliard329f0681996-04-14 13:21:20 +00002165 *
2166 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002167static void EDIT_SetRectNP(EDITSTATE *es, LPRECT rc)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002168{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002169 CopyRect(&es->format_rect, rc);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002170 if (es->style & WS_BORDER) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002171 INT bw = GetSystemMetrics(SM_CXBORDER) + 1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002172 es->format_rect.left += bw;
2173 es->format_rect.top += bw;
2174 es->format_rect.right -= bw;
2175 es->format_rect.bottom -= bw;
2176 }
2177 es->format_rect.left += es->left_margin;
2178 es->format_rect.right -= es->right_margin;
Francois Gouget6d77d3a2000-03-25 21:44:35 +00002179 es->format_rect.right = max(es->format_rect.right, es->format_rect.left + es->char_width);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002180 if (es->style & ES_MULTILINE)
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002181 {
2182 INT fw, vlc, max_x_offset, max_y_offset;
2183
2184 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2185 es->format_rect.bottom = es->format_rect.top + max(1, vlc) * es->line_height;
2186
2187 /* correct es->x_offset */
2188 fw = es->format_rect.right - es->format_rect.left;
2189 max_x_offset = es->text_width - fw;
2190 if(max_x_offset < 0) max_x_offset = 0;
2191 if(es->x_offset > max_x_offset)
2192 es->x_offset = max_x_offset;
2193
2194 /* correct es->y_offset */
2195 max_y_offset = es->line_count - vlc;
2196 if(max_y_offset < 0) max_y_offset = 0;
2197 if(es->y_offset > max_y_offset)
2198 es->y_offset = max_y_offset;
Dmitry Timoshkova234db82001-01-19 20:49:54 +00002199
2200 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002201 EDIT_UpdateScrollInfo(es);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002202 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002203 else
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002204 /* Windows doesn't care to fix text placement for SL controls */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002205 es->format_rect.bottom = es->format_rect.top + es->line_height;
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002206
Alexandre Julliard889f7421997-04-15 17:19:52 +00002207 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL))
Francois Gougetd2667a42002-12-02 18:10:57 +00002208 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002209}
2210
2211
2212/*********************************************************************
2213 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002214 * EDIT_UnlockBuffer
Alexandre Julliard329f0681996-04-14 13:21:20 +00002215 *
2216 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002217static void EDIT_UnlockBuffer(EDITSTATE *es, BOOL force)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002218{
Robert Shearman2e9436c2004-08-17 22:29:29 +00002219 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +00002220
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002221 /* Edit window might be already destroyed */
2222 if(!IsWindow(es->hwndSelf))
2223 {
Alexandre Julliardaff7dda2002-11-22 21:22:14 +00002224 WARN("edit hwnd %p already destroyed\n", es->hwndSelf);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002225 return;
2226 }
Dmitry Timoshkovfbc36192001-03-05 19:29:47 +00002227
Alexandre Julliard889f7421997-04-15 17:19:52 +00002228 if (!es->lock_count) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002229 ERR("lock_count == 0 ... please report\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002230 return;
2231 }
2232 if (!es->text) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002233 ERR("es->text == 0 ... please report\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002234 return;
2235 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002236
Alexandre Julliard889f7421997-04-15 17:19:52 +00002237 if (force || (es->lock_count == 1)) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002238 if (es->hloc32W) {
2239 CHAR *textA = NULL;
2240 BOOL _16bit = FALSE;
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002241 UINT countA = 0;
2242 UINT countW = strlenW(es->text) + 1;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002243
2244 if(es->hloc32A)
2245 {
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002246 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002247 TRACE("Synchronizing with 32-bit ANSI buffer\n");
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002248 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002249 countA = LocalSize(es->hloc32A);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002250 if(countA_new > countA)
2251 {
2252 HLOCAL hloc32A_new;
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002253 UINT alloc_size = ROUND_TO_GROW(countA_new);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002254 TRACE("Resizing 32-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
2255 hloc32A_new = LocalReAlloc(es->hloc32A, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
2256 if(hloc32A_new)
2257 {
2258 es->hloc32A = hloc32A_new;
2259 countA = LocalSize(hloc32A_new);
2260 TRACE("Real new size %d bytes\n", countA);
2261 }
2262 else
2263 WARN("FAILED! Will synchronize partially\n");
2264 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002265 textA = LocalLock(es->hloc32A);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002266 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002267 else if(es->hloc16)
2268 {
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002269 UINT countA_new = WideCharToMultiByte(CP_ACP, 0, es->text, countW, NULL, 0, NULL, NULL);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002270 TRACE("Synchronizing with 16-bit ANSI buffer\n");
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002271 TRACE("%d WCHARs translated to %d bytes\n", countW, countA_new);
Alexandre Julliardde424282001-08-10 22:51:42 +00002272 countA = LOCAL_Size(hInstance, es->hloc16);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002273 if(countA_new > countA)
2274 {
2275 HLOCAL16 hloc16_new;
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002276 UINT alloc_size = ROUND_TO_GROW(countA_new);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002277 TRACE("Resizing 16-bit ANSI buffer from %d to %d bytes\n", countA, alloc_size);
Alexandre Julliardde424282001-08-10 22:51:42 +00002278 hloc16_new = LOCAL_ReAlloc(hInstance, es->hloc16, alloc_size, LMEM_MOVEABLE | LMEM_ZEROINIT);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002279 if(hloc16_new)
2280 {
2281 es->hloc16 = hloc16_new;
Alexandre Julliardde424282001-08-10 22:51:42 +00002282 countA = LOCAL_Size(hInstance, hloc16_new);
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002283 TRACE("Real new size %d bytes\n", countA);
2284 }
2285 else
2286 WARN("FAILED! Will synchronize partially\n");
2287 }
Alexandre Julliardde424282001-08-10 22:51:42 +00002288 textA = LOCAL_Lock(hInstance, es->hloc16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002289 _16bit = TRUE;
2290 }
2291
2292 if(textA)
2293 {
Dmitry Timoshkovf77709e2001-01-10 23:55:02 +00002294 WideCharToMultiByte(CP_ACP, 0, es->text, countW, textA, countA, NULL, NULL);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002295 if(_16bit)
Alexandre Julliardde424282001-08-10 22:51:42 +00002296 LOCAL_Unlock(hInstance, es->hloc16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002297 else
2298 LocalUnlock(es->hloc32A);
2299 }
2300
2301 LocalUnlock(es->hloc32W);
2302 es->text = NULL;
2303 }
2304 else {
2305 ERR("no buffer ... please report\n");
2306 return;
2307 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002308 }
2309 es->lock_count--;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002310}
2311
2312
2313/*********************************************************************
2314 *
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002315 * EDIT_UpdateScrollInfo
2316 *
2317 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002318static void EDIT_UpdateScrollInfo(EDITSTATE *es)
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002319{
2320 if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK))
2321 {
2322 SCROLLINFO si;
2323 si.cbSize = sizeof(SCROLLINFO);
2324 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2325 si.nMin = 0;
2326 si.nMax = es->line_count - 1;
2327 si.nPage = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
2328 si.nPos = es->y_offset;
2329 TRACE("SB_VERT, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2330 si.nMin, si.nMax, si.nPage, si.nPos);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002331 SetScrollInfo(es->hwndSelf, SB_VERT, &si, TRUE);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002332 }
2333
2334 if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK))
2335 {
2336 SCROLLINFO si;
2337 si.cbSize = sizeof(SCROLLINFO);
2338 si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
2339 si.nMin = 0;
2340 si.nMax = es->text_width - 1;
2341 si.nPage = es->format_rect.right - es->format_rect.left;
2342 si.nPos = es->x_offset;
2343 TRACE("SB_HORZ, nMin=%d, nMax=%d, nPage=%d, nPos=%d\n",
2344 si.nMin, si.nMax, si.nPage, si.nPos);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002345 SetScrollInfo(es->hwndSelf, SB_HORZ, &si, TRUE);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002346 }
2347}
2348
2349/*********************************************************************
2350 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002351 * EDIT_WordBreakProc
2352 *
2353 * Find the beginning of words.
2354 * Note: unlike the specs for a WordBreakProc, this function only
2355 * allows to be called without linebreaks between s[0] upto
2356 * s[count - 1]. Remember it is only called
2357 * internally, so we can decide this for ourselves.
2358 *
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00002359 */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002360static INT CALLBACK EDIT_WordBreakProc(LPWSTR s, INT index, INT count, INT action)
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00002361{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002362 INT ret = 0;
Alexandre Julliard02ed4c21996-03-02 19:34:10 +00002363
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002364 TRACE("s=%p, index=%d, count=%d, action=%d\n", s, index, count, action);
2365
2366 if(!s) return 0;
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00002367
Alexandre Julliard329f0681996-04-14 13:21:20 +00002368 switch (action) {
2369 case WB_LEFT:
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002370 if (!count)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002371 break;
2372 if (index)
2373 index--;
2374 if (s[index] == ' ') {
2375 while (index && (s[index] == ' '))
2376 index--;
2377 if (index) {
2378 while (index && (s[index] != ' '))
2379 index--;
2380 if (s[index] == ' ')
2381 index++;
2382 }
2383 } else {
2384 while (index && (s[index] != ' '))
2385 index--;
2386 if (s[index] == ' ')
2387 index++;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00002388 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002389 ret = index;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00002390 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002391 case WB_RIGHT:
2392 if (!count)
2393 break;
2394 if (index)
2395 index--;
2396 if (s[index] == ' ')
2397 while ((index < count) && (s[index] == ' ')) index++;
2398 else {
2399 while (s[index] && (s[index] != ' ') && (index < count))
2400 index++;
2401 while ((s[index] == ' ') && (index < count)) index++;
2402 }
2403 ret = index;
2404 break;
2405 case WB_ISDELIMITER:
2406 ret = (s[index] == ' ');
2407 break;
2408 default:
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002409 ERR("unknown action code, please report !\n");
Alexandre Julliard329f0681996-04-14 13:21:20 +00002410 break;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00002411 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002412 return ret;
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00002413}
2414
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00002415
Alexandre Julliard329f0681996-04-14 13:21:20 +00002416/*********************************************************************
2417 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002418 * EM_CHARFROMPOS
2419 *
Gerard Patelc9b65341999-01-24 18:57:23 +00002420 * returns line number (not index) in high-order word of result.
Vincent Béron9a624912002-05-31 23:06:46 +00002421 * NB : Q137805 is unclear about this. POINT * pointer in lParam apply
Gerard Patelc9b65341999-01-24 18:57:23 +00002422 * to Richedit, not to the edit control. Original documentation is valid.
Alexandre Julliard889f7421997-04-15 17:19:52 +00002423 * FIXME: do the specs mean to return -1 if outside client area or
2424 * if outside formatting rectangle ???
2425 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002426 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002427static LRESULT EDIT_EM_CharFromPos(EDITSTATE *es, INT x, INT y)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002428{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002429 POINT pt;
2430 RECT rc;
2431 INT index;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002432
Alexandre Julliard889f7421997-04-15 17:19:52 +00002433 pt.x = x;
2434 pt.y = y;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002435 GetClientRect(es->hwndSelf, &rc);
Alexandre Julliarda3960291999-02-26 11:11:13 +00002436 if (!PtInRect(&rc, pt))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002437 return -1;
2438
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002439 index = EDIT_CharFromPos(es, x, y, NULL);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002440 return MAKELONG(index, EDIT_EM_LineFromChar(es, index));
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00002441}
2442
Alexandre Julliard329f0681996-04-14 13:21:20 +00002443
Alexandre Julliardd2e1c1a1996-03-09 16:12:43 +00002444/*********************************************************************
Alexandre Julliard329f0681996-04-14 13:21:20 +00002445 *
2446 * EM_FMTLINES
2447 *
Alexandre Julliarda845b881998-06-01 10:44:35 +00002448 * Enable or disable soft breaks.
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002449 *
2450 * This means: insert or remove the soft linebreak character (\r\r\n).
2451 * Take care to check if the text still fits the buffer after insertion.
2452 * If not, notify with EN_ERRSPACE.
2453 *
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +00002454 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002455static BOOL EDIT_EM_FmtLines(EDITSTATE *es, BOOL add_eol)
Alexandre Julliard58199531994-04-21 01:20:00 +00002456{
Alexandre Julliarda845b881998-06-01 10:44:35 +00002457 es->flags &= ~EF_USE_SOFTBRK;
2458 if (add_eol) {
2459 es->flags |= EF_USE_SOFTBRK;
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002460 FIXME("soft break enabled, not implemented\n");
Alexandre Julliarda845b881998-06-01 10:44:35 +00002461 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002462 return add_eol;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002463}
Alexandre Julliard988ca971994-06-21 16:15:21 +00002464
Alexandre Julliard58199531994-04-21 01:20:00 +00002465
Alexandre Julliard329f0681996-04-14 13:21:20 +00002466/*********************************************************************
2467 *
2468 * EM_GETHANDLE
2469 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002470 * Hopefully this won't fire back at us.
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002471 * We always start with a fixed buffer in the local heap.
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002472 * Despite of the documentation says that the local heap is used
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002473 * only if DS_LOCALEDIT flag is set, NT and 2000 always allocate
2474 * buffer on the local heap.
Alexandre Julliard889f7421997-04-15 17:19:52 +00002475 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002476 */
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +00002477static HLOCAL EDIT_EM_GetHandle(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002478{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002479 HLOCAL hLocal;
Alexandre Julliard58199531994-04-21 01:20:00 +00002480
Alexandre Julliard889f7421997-04-15 17:19:52 +00002481 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002482 return 0;
2483
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002484 if(es->is_unicode)
2485 hLocal = es->hloc32W;
2486 else
2487 {
2488 if(!es->hloc32A)
2489 {
2490 CHAR *textA;
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002491 UINT countA, alloc_size;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002492 TRACE("Allocating 32-bit ANSI alias buffer\n");
James Hathewayba9b9642001-01-10 22:54:33 +00002493 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002494 alloc_size = ROUND_TO_GROW(countA);
2495 if(!(es->hloc32A = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002496 {
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002497 ERR("Could not allocate %d bytes for 32-bit ANSI alias buffer\n", alloc_size);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002498 return 0;
2499 }
2500 textA = LocalLock(es->hloc32A);
James Hathewayba9b9642001-01-10 22:54:33 +00002501 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002502 LocalUnlock(es->hloc32A);
2503 }
2504 hLocal = es->hloc32A;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002505 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002506
Alexandre Julliardaff7dda2002-11-22 21:22:14 +00002507 TRACE("Returning %p, LocalSize() = %ld\n", hLocal, LocalSize(hLocal));
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002508 return hLocal;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002509}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002510
2511
2512/*********************************************************************
2513 *
2514 * EM_GETHANDLE16
2515 *
2516 * Hopefully this won't fire back at us.
2517 * We always start with a buffer in 32 bit linear memory.
2518 * However, with this message a 16 bit application requests
2519 * a handle of 16 bit local heap memory, where it expects to find
2520 * the text.
2521 * It's a pitty that from this moment on we have to use this
2522 * local heap, because applications may rely on the handle
2523 * in the future.
2524 *
2525 * In this function we'll try to switch to local heap.
2526 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002527static HLOCAL16 EDIT_EM_GetHandle16(EDITSTATE *es)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002528{
Robert Shearman2e9436c2004-08-17 22:29:29 +00002529 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002530 CHAR *textA;
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002531 UINT countA, alloc_size;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002532
Alexandre Julliard889f7421997-04-15 17:19:52 +00002533 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002534 return 0;
2535
Alexandre Julliard889f7421997-04-15 17:19:52 +00002536 if (es->hloc16)
2537 return es->hloc16;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002538
Alexandre Julliardde424282001-08-10 22:51:42 +00002539 if (!LOCAL_HeapSize(hInstance)) {
2540 if (!LocalInit16(hInstance, 0,
2541 GlobalSize16(hInstance))) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002542 ERR("could not initialize local heap\n");
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002543 return 0;
2544 }
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002545 TRACE("local heap initialized\n");
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002546 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002547
James Hathewayba9b9642001-01-10 22:54:33 +00002548 countA = WideCharToMultiByte(CP_ACP, 0, es->text, -1, NULL, 0, NULL, NULL);
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00002549 alloc_size = ROUND_TO_GROW(countA);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002550
2551 TRACE("Allocating 16-bit ANSI alias buffer\n");
Alexandre Julliardde424282001-08-10 22:51:42 +00002552 if (!(es->hloc16 = LOCAL_Alloc(hInstance, LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size))) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002553 ERR("could not allocate new 16 bit buffer\n");
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002554 return 0;
2555 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002556
Alexandre Julliardde424282001-08-10 22:51:42 +00002557 if (!(textA = (LPSTR)LOCAL_Lock(hInstance, es->hloc16))) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00002558 ERR("could not lock new 16 bit buffer\n");
Alexandre Julliardde424282001-08-10 22:51:42 +00002559 LOCAL_Free(hInstance, es->hloc16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002560 es->hloc16 = 0;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002561 return 0;
2562 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002563
James Hathewayba9b9642001-01-10 22:54:33 +00002564 WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, countA, NULL, NULL);
Alexandre Julliardde424282001-08-10 22:51:42 +00002565 LOCAL_Unlock(hInstance, es->hloc16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002566
Alexandre Julliardde424282001-08-10 22:51:42 +00002567 TRACE("Returning %04X, LocalSize() = %d\n", es->hloc16, LOCAL_Size(hInstance, es->hloc16));
Alexandre Julliard889f7421997-04-15 17:19:52 +00002568 return es->hloc16;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002569}
2570
Alexandre Julliard58199531994-04-21 01:20:00 +00002571
Alexandre Julliard329f0681996-04-14 13:21:20 +00002572/*********************************************************************
2573 *
2574 * EM_GETLINE
2575 *
2576 */
Dmitry Timoshkovbf604532001-02-12 19:15:33 +00002577static INT EDIT_EM_GetLine(EDITSTATE *es, INT line, LPARAM lParam, BOOL unicode)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002578{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002579 LPWSTR src;
Dmitry Timoshkovbf604532001-02-12 19:15:33 +00002580 INT line_len, dst_len;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002581 INT i;
Alexandre Julliard58199531994-04-21 01:20:00 +00002582
Alexandre Julliard889f7421997-04-15 17:19:52 +00002583 if (es->style & ES_MULTILINE) {
2584 if (line >= es->line_count)
2585 return 0;
2586 } else
2587 line = 0;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002588 i = EDIT_EM_LineIndex(es, line);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00002589 src = es->text + i;
Dmitry Timoshkovbf604532001-02-12 19:15:33 +00002590 line_len = EDIT_EM_LineLength(es, i);
2591 dst_len = *(WORD *)lParam;
2592 if(unicode)
2593 {
2594 LPWSTR dst = (LPWSTR)lParam;
2595 if(dst_len <= line_len)
2596 {
2597 memcpy(dst, src, dst_len * sizeof(WCHAR));
2598 return dst_len;
2599 }
2600 else /* Append 0 if enough space */
2601 {
2602 memcpy(dst, src, line_len * sizeof(WCHAR));
2603 dst[line_len] = 0;
2604 return line_len;
2605 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002606 }
Dmitry Timoshkovbf604532001-02-12 19:15:33 +00002607 else
2608 {
2609 LPSTR dst = (LPSTR)lParam;
2610 INT ret;
2611 ret = WideCharToMultiByte(CP_ACP, 0, src, line_len, dst, dst_len, NULL, NULL);
2612 if(!ret) /* Insufficient buffer size */
2613 return dst_len;
2614 if(ret < dst_len) /* Append 0 if enough space */
2615 dst[ret] = 0;
2616 return ret;
2617 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00002618}
Alexandre Julliard58199531994-04-21 01:20:00 +00002619
Alexandre Julliard58199531994-04-21 01:20:00 +00002620
Alexandre Julliard329f0681996-04-14 13:21:20 +00002621/*********************************************************************
2622 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002623 * EM_GETSEL
2624 *
2625 */
Francois Gougetbba4bb12002-09-17 01:35:09 +00002626static LRESULT EDIT_EM_GetSel(EDITSTATE *es, PUINT start, PUINT end)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002627{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002628 UINT s = es->selection_start;
2629 UINT e = es->selection_end;
Alexandre Julliard58199531994-04-21 01:20:00 +00002630
Alexandre Julliarda3960291999-02-26 11:11:13 +00002631 ORDER_UINT(s, e);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002632 if (start)
2633 *start = s;
2634 if (end)
2635 *end = e;
2636 return MAKELONG(s, e);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002637}
2638
2639
2640/*********************************************************************
2641 *
2642 * EM_GETTHUMB
2643 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002644 * FIXME: is this right ? (or should it be only VSCROLL)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002645 * (and maybe only for edit controls that really have their
2646 * own scrollbars) (and maybe only for multiline controls ?)
2647 * All in all: very poorly documented
Alexandre Julliard329f0681996-04-14 13:21:20 +00002648 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002649 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002650static LRESULT EDIT_EM_GetThumb(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002651{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002652 return MAKELONG(EDIT_WM_VScroll(es, EM_GETTHUMB16, 0),
2653 EDIT_WM_HScroll(es, EM_GETTHUMB16, 0));
Alexandre Julliard329f0681996-04-14 13:21:20 +00002654}
2655
2656
2657/*********************************************************************
2658 *
2659 * EM_LINEFROMCHAR
2660 *
2661 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002662static INT EDIT_EM_LineFromChar(EDITSTATE *es, INT index)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002663{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002664 INT line;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002665 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002666
Alexandre Julliard889f7421997-04-15 17:19:52 +00002667 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002668 return 0;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002669 if (index > (INT)strlenW(es->text))
Alexandre Julliard889f7421997-04-15 17:19:52 +00002670 return es->line_count - 1;
2671 if (index == -1)
Francois Gouget6d77d3a2000-03-25 21:44:35 +00002672 index = min(es->selection_start, es->selection_end);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002673
2674 line = 0;
2675 line_def = es->first_line_def;
2676 index -= line_def->length;
2677 while ((index >= 0) && line_def->next) {
2678 line++;
2679 line_def = line_def->next;
2680 index -= line_def->length;
2681 }
2682 return line;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002683}
2684
2685
2686/*********************************************************************
2687 *
2688 * EM_LINEINDEX
2689 *
2690 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002691static INT EDIT_EM_LineIndex(EDITSTATE *es, INT line)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002692{
Alexandre Julliarda3960291999-02-26 11:11:13 +00002693 INT line_index;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002694 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002695
Alexandre Julliard889f7421997-04-15 17:19:52 +00002696 if (!(es->style & ES_MULTILINE))
2697 return 0;
2698 if (line >= es->line_count)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002699 return -1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002700
2701 line_index = 0;
2702 line_def = es->first_line_def;
2703 if (line == -1) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002704 INT index = es->selection_end - line_def->length;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002705 while ((index >= 0) && line_def->next) {
2706 line_index += line_def->length;
2707 line_def = line_def->next;
2708 index -= line_def->length;
2709 }
2710 } else {
2711 while (line > 0) {
2712 line_index += line_def->length;
2713 line_def = line_def->next;
2714 line--;
2715 }
2716 }
2717 return line_index;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002718}
2719
2720
2721/*********************************************************************
2722 *
2723 * EM_LINELENGTH
2724 *
2725 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002726static INT EDIT_EM_LineLength(EDITSTATE *es, INT index)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002727{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002728 LINEDEF *line_def;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002729
Alexandre Julliard889f7421997-04-15 17:19:52 +00002730 if (!(es->style & ES_MULTILINE))
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002731 return strlenW(es->text);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002732
2733 if (index == -1) {
Andreas Mohra8edb3e2000-05-23 04:05:05 +00002734 /* get the number of remaining non-selected chars of selected lines */
Andreas Mohr07216db2001-11-13 21:29:38 +00002735 INT32 l; /* line number */
2736 INT32 li; /* index of first char in line */
Andreas Mohra8edb3e2000-05-23 04:05:05 +00002737 INT32 count;
Andreas Mohr07216db2001-11-13 21:29:38 +00002738 l = EDIT_EM_LineFromChar(es, es->selection_start);
Andreas Mohra8edb3e2000-05-23 04:05:05 +00002739 /* # chars before start of selection area */
Andreas Mohr07216db2001-11-13 21:29:38 +00002740 count = es->selection_start - EDIT_EM_LineIndex(es, l);
2741 l = EDIT_EM_LineFromChar(es, es->selection_end);
Andreas Mohra8edb3e2000-05-23 04:05:05 +00002742 /* # chars after end of selection */
Andreas Mohr07216db2001-11-13 21:29:38 +00002743 li = EDIT_EM_LineIndex(es, l);
2744 count += li + EDIT_EM_LineLength(es, li) - es->selection_end;
Andreas Mohra8edb3e2000-05-23 04:05:05 +00002745 return count;
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00002746 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00002747 line_def = es->first_line_def;
2748 index -= line_def->length;
2749 while ((index >= 0) && line_def->next) {
2750 line_def = line_def->next;
2751 index -= line_def->length;
2752 }
2753 return line_def->net_length;
Alexandre Julliard329f0681996-04-14 13:21:20 +00002754}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002755
Alexandre Julliard329f0681996-04-14 13:21:20 +00002756
2757/*********************************************************************
2758 *
2759 * EM_LINESCROLL
2760 *
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002761 * NOTE: dx is in average character widths, dy - in lines;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002762 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002763 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002764static BOOL EDIT_EM_LineScroll(EDITSTATE *es, INT dx, INT dy)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002765{
Alexandre Julliard889f7421997-04-15 17:19:52 +00002766 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002767 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002768
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002769 dx *= es->char_width;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002770 return EDIT_EM_LineScroll_internal(es, dx, dy);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002771}
2772
2773/*********************************************************************
2774 *
2775 * EDIT_EM_LineScroll_internal
2776 *
2777 * Version of EDIT_EM_LineScroll for internal use.
2778 * It doesn't refuse if ES_MULTILINE is set and assumes that
2779 * dx is in pixels, dy - in lines.
2780 *
2781 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002782static BOOL EDIT_EM_LineScroll_internal(EDITSTATE *es, INT dx, INT dy)
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002783{
2784 INT nyoff;
2785 INT x_offset_in_pixels;
2786
2787 if (es->style & ES_MULTILINE)
2788 {
2789 x_offset_in_pixels = es->x_offset;
2790 }
2791 else
2792 {
2793 dy = 0;
Alexandre Julliard9d615962003-09-17 04:28:28 +00002794 x_offset_in_pixels = (short)LOWORD(EDIT_EM_PosFromChar(es, es->x_offset, FALSE));
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002795 }
2796
2797 if (-dx > x_offset_in_pixels)
2798 dx = -x_offset_in_pixels;
2799 if (dx > es->text_width - x_offset_in_pixels)
2800 dx = es->text_width - x_offset_in_pixels;
Francois Gouget6d77d3a2000-03-25 21:44:35 +00002801 nyoff = max(0, es->y_offset + dy);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002802 if (nyoff >= es->line_count)
2803 nyoff = es->line_count - 1;
2804 dy = (es->y_offset - nyoff) * es->line_height;
2805 if (dx || dy) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002806 RECT rc1;
2807 RECT rc;
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00002808
2809 es->y_offset = nyoff;
2810 if(es->style & ES_MULTILINE)
2811 es->x_offset += dx;
2812 else
2813 es->x_offset += dx / es->char_width;
2814
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002815 GetClientRect(es->hwndSelf, &rc1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00002816 IntersectRect(&rc, &rc1, &es->format_rect);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002817 ScrollWindowEx(es->hwndSelf, -dx, dy,
Francois Gougetd2667a42002-12-02 18:10:57 +00002818 NULL, &rc, NULL, NULL, SW_INVALIDATE);
Dmitry Timoshkova234db82001-01-19 20:49:54 +00002819 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002820 EDIT_UpdateScrollInfo(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002821 }
2822 if (dx && !(es->flags & EF_HSCROLL_TRACK))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002823 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002824 if (dy && !(es->flags & EF_VSCROLL_TRACK))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002825 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002826 return TRUE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002827}
2828
2829
2830/*********************************************************************
2831 *
2832 * EM_POSFROMCHAR
2833 *
2834 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002835static LRESULT EDIT_EM_PosFromChar(EDITSTATE *es, INT index, BOOL after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002836{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002837 INT len = strlenW(es->text);
Alexandre Julliarda3960291999-02-26 11:11:13 +00002838 INT l;
2839 INT li;
2840 INT x;
2841 INT y = 0;
2842 HDC dc;
2843 HFONT old_font = 0;
2844 SIZE size;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002845
Francois Gouget6d77d3a2000-03-25 21:44:35 +00002846 index = min(index, len);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002847 dc = GetDC(es->hwndSelf);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002848 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00002849 old_font = SelectObject(dc, es->font);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002850 if (es->style & ES_MULTILINE) {
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002851 l = EDIT_EM_LineFromChar(es, index);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002852 y = (l - es->y_offset) * es->line_height;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002853 li = EDIT_EM_LineIndex(es, l);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002854 if (after_wrap && (li == index) && l) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00002855 INT l2 = l - 1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002856 LINEDEF *line_def = es->first_line_def;
2857 while (l2) {
2858 line_def = line_def->next;
2859 l2--;
2860 }
2861 if (line_def->ending == END_WRAP) {
2862 l--;
2863 y -= es->line_height;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002864 li = EDIT_EM_LineIndex(es, l);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002865 }
2866 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002867 x = LOWORD(GetTabbedTextExtentW(dc, es->text + li, index - li,
Alexandre Julliard889f7421997-04-15 17:19:52 +00002868 es->tabs_count, es->tabs)) - es->x_offset;
2869 } else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002870 LPWSTR text = EDIT_GetPasswordPointer_SL(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002871 if (index < es->x_offset) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002872 GetTextExtentPoint32W(dc, text + index,
Alexandre Julliard889f7421997-04-15 17:19:52 +00002873 es->x_offset - index, &size);
2874 x = -size.cx;
2875 } else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002876 GetTextExtentPoint32W(dc, text + es->x_offset,
Alexandre Julliard889f7421997-04-15 17:19:52 +00002877 index - es->x_offset, &size);
2878 x = size.cx;
2879 }
2880 y = 0;
2881 if (es->style & ES_PASSWORD)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002882 HeapFree(GetProcessHeap(), 0, text);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002883 }
2884 x += es->format_rect.left;
2885 y += es->format_rect.top;
2886 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00002887 SelectObject(dc, old_font);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00002888 ReleaseDC(es->hwndSelf, dc);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002889 return MAKELONG((INT16)x, (INT16)y);
Alexandre Julliard329f0681996-04-14 13:21:20 +00002890}
2891
2892
2893/*********************************************************************
2894 *
2895 * EM_REPLACESEL
2896 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00002897 * FIXME: handle ES_NUMBER and ES_OEMCONVERT here
2898 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00002899 */
Carl Sopchak23b88ef2002-11-21 03:57:05 +00002900static void EDIT_EM_ReplaceSel(EDITSTATE *es, BOOL can_undo, LPCWSTR lpsz_replace, BOOL send_update, BOOL honor_limit)
Alexandre Julliard329f0681996-04-14 13:21:20 +00002901{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002902 UINT strl = strlenW(lpsz_replace);
2903 UINT tl = strlenW(es->text);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002904 UINT utl;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002905 UINT s;
2906 UINT e;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002907 UINT i;
Krishna Murthy4af4ba42004-05-29 00:21:51 +00002908 UINT size;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002909 LPWSTR p;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00002910 HRGN hrgn = 0;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002911
2912 TRACE("%s, can_undo %d, send_update %d\n",
2913 debugstr_w(lpsz_replace), can_undo, send_update);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00002914
Alexandre Julliard889f7421997-04-15 17:19:52 +00002915 s = es->selection_start;
2916 e = es->selection_end;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002917
2918 if ((s == e) && !strl)
Alexandre Julliard889f7421997-04-15 17:19:52 +00002919 return;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002920
Alexandre Julliarda3960291999-02-26 11:11:13 +00002921 ORDER_UINT(s, e);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002922
Krishna Murthy4af4ba42004-05-29 00:21:51 +00002923 /* Issue the EN_MAXTEXT notification and continue with replacing text
2924 * such that buffer limit is honored. */
2925 size = tl - (e - s) + strl;
2926 if ((honor_limit) && (es->buffer_limit > 0) && (size > es->buffer_limit)) {
2927 EDIT_NOTIFY_PARENT(es, EN_MAXTEXT, "EN_MAXTEXT");
2928 strl = es->buffer_limit - (tl - (e-s));
2929 }
2930
2931 if (!EDIT_MakeFit(es, tl - (e - s) + strl))
Alexandre Julliard889f7421997-04-15 17:19:52 +00002932 return;
2933
Alexandre Julliard01d63461997-01-20 19:43:45 +00002934 if (e != s) {
2935 /* there is something to be deleted */
Andreas Mohr07216db2001-11-13 21:29:38 +00002936 TRACE("deleting stuff.\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00002937 if (can_undo) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002938 utl = strlenW(es->undo_text);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002939 if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) {
Alexandre Julliard01d63461997-01-20 19:43:45 +00002940 /* undo-buffer is extended to the right */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002941 EDIT_MakeUndoFit(es, utl + e - s);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002942 strncpyW(es->undo_text + utl, es->text + s, e - s + 1);
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00002943 (es->undo_text + utl)[e - s] = 0; /* ensure 0 termination */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002944 } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) {
Alexandre Julliard01d63461997-01-20 19:43:45 +00002945 /* undo-buffer is extended to the left */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002946 EDIT_MakeUndoFit(es, utl + e - s);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002947 for (p = es->undo_text + utl ; p >= es->undo_text ; p--)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002948 p[e - s] = p[0];
Alexandre Julliard889f7421997-04-15 17:19:52 +00002949 for (i = 0 , p = es->undo_text ; i < e - s ; i++)
2950 p[i] = (es->text + s)[i];
2951 es->undo_position = s;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002952 } else {
2953 /* new undo-buffer */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002954 EDIT_MakeUndoFit(es, e - s);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002955 strncpyW(es->undo_text, es->text + s, e - s + 1);
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00002956 es->undo_text[e - s] = 0; /* ensure 0 termination */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002957 es->undo_position = s;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002958 }
2959 /* any deletion makes the old insertion-undo invalid */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002960 es->undo_insert_count = 0;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002961 } else
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002962 EDIT_EM_EmptyUndoBuffer(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002963
2964 /* now delete */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002965 strcpyW(es->text + s, es->text + e);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002966 }
2967 if (strl) {
2968 /* there is an insertion */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002969 if (can_undo) {
2970 if ((s == es->undo_position) ||
2971 ((es->undo_insert_count) &&
2972 (s == es->undo_position + es->undo_insert_count)))
Alexandre Julliard01d63461997-01-20 19:43:45 +00002973 /*
2974 * insertion is new and at delete position or
2975 * an extension to either left or right
2976 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002977 es->undo_insert_count += strl;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002978 else {
2979 /* new insertion undo */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002980 es->undo_position = s;
2981 es->undo_insert_count = strl;
Alexandre Julliard01d63461997-01-20 19:43:45 +00002982 /* new insertion makes old delete-buffer invalid */
Alexandre Julliard889f7421997-04-15 17:19:52 +00002983 *es->undo_text = '\0';
Alexandre Julliard01d63461997-01-20 19:43:45 +00002984 }
2985 } else
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00002986 EDIT_EM_EmptyUndoBuffer(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002987
2988 /* now insert */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002989 tl = strlenW(es->text);
Andreas Mohr07216db2001-11-13 21:29:38 +00002990 TRACE("inserting stuff (tl %d, strl %d, selstart %d ('%s'), text '%s')\n", tl, strl, s, debugstr_w(es->text + s), debugstr_w(es->text));
Alexandre Julliard889f7421997-04-15 17:19:52 +00002991 for (p = es->text + tl ; p >= es->text + s ; p--)
Alexandre Julliard01d63461997-01-20 19:43:45 +00002992 p[strl] = p[0];
Alexandre Julliard889f7421997-04-15 17:19:52 +00002993 for (i = 0 , p = es->text + s ; i < strl ; i++)
2994 p[i] = lpsz_replace[i];
2995 if(es->style & ES_UPPERCASE)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002996 CharUpperBuffW(p, strl);
Alexandre Julliard889f7421997-04-15 17:19:52 +00002997 else if(es->style & ES_LOWERCASE)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00002998 CharLowerBuffW(p, strl);
Alexandre Julliard01d63461997-01-20 19:43:45 +00002999 s += strl;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003000 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003001 if (es->style & ES_MULTILINE)
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00003002 {
3003 INT s = min(es->selection_start, es->selection_end);
3004
3005 hrgn = CreateRectRgn(0, 0, 0, 0);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003006 EDIT_BuildLineDefs_ML(es, s, s + strl,
Ulrich Czekalla2d382c62001-05-09 17:12:30 +00003007 strl - abs(es->selection_end - es->selection_start), hrgn);
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00003008 }
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00003009 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003010 EDIT_CalcLineWidth_SL(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003011
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003012 EDIT_EM_SetSel(es, s, s, FALSE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003013 es->flags |= EF_MODIFIED;
Ulrich Weigand6bfbc3d2000-10-23 00:38:10 +00003014 if (send_update) es->flags |= EF_UPDATE;
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00003015 if (hrgn)
3016 {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003017 EDIT_UpdateTextRegion(es, hrgn, TRUE);
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00003018 DeleteObject(hrgn);
3019 }
3020 else
Huw Davies4c7b65d2003-11-11 00:26:53 +00003021 EDIT_UpdateText(es, NULL, TRUE);
3022
3023 EDIT_EM_ScrollCaret(es);
3024
3025 /* force scroll info update */
3026 EDIT_UpdateScrollInfo(es);
3027
Dmitry Timoshkova62f06d2001-03-13 23:31:08 +00003028
3029 if(es->flags & EF_UPDATE)
3030 {
3031 es->flags &= ~EF_UPDATE;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003032 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
Dmitry Timoshkova62f06d2001-03-13 23:31:08 +00003033 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003034}
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003035
Alexandre Julliard329f0681996-04-14 13:21:20 +00003036
3037/*********************************************************************
3038 *
3039 * EM_SCROLL
Alexandre Julliard889f7421997-04-15 17:19:52 +00003040 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003041 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003042static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003043{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003044 INT dy;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003045
Alexandre Julliard889f7421997-04-15 17:19:52 +00003046 if (!(es->style & ES_MULTILINE))
3047 return (LRESULT)FALSE;
3048
3049 dy = 0;
3050
3051 switch (action) {
3052 case SB_LINEUP:
3053 if (es->y_offset)
3054 dy = -1;
3055 break;
3056 case SB_LINEDOWN:
3057 if (es->y_offset < es->line_count - 1)
3058 dy = 1;
3059 break;
3060 case SB_PAGEUP:
3061 if (es->y_offset)
3062 dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height;
3063 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003064 case SB_PAGEDOWN:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003065 if (es->y_offset < es->line_count - 1)
3066 dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3067 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003068 default:
Alexandre Julliard889f7421997-04-15 17:19:52 +00003069 return (LRESULT)FALSE;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003070 }
3071 if (dy) {
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00003072 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3073 /* check if we are going to move too far */
3074 if(es->y_offset + dy > es->line_count - vlc)
3075 dy = es->line_count - vlc - es->y_offset;
3076
3077 /* Notification is done in EDIT_EM_LineScroll */
3078 if(dy)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003079 EDIT_EM_LineScroll(es, 0, dy);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003080 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003081 return MAKELONG((INT16)dy, (BOOL16)TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003082}
3083
3084
3085/*********************************************************************
3086 *
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003087 * EM_SCROLLCARET
3088 *
3089 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003090static void EDIT_EM_ScrollCaret(EDITSTATE *es)
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003091{
3092 if (es->style & ES_MULTILINE) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003093 INT l;
3094 INT li;
3095 INT vlc;
3096 INT ww;
3097 INT cw = es->char_width;
3098 INT x;
3099 INT dy = 0;
3100 INT dx = 0;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003101
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003102 l = EDIT_EM_LineFromChar(es, es->selection_end);
3103 li = EDIT_EM_LineIndex(es, l);
Alexandre Julliard9d615962003-09-17 04:28:28 +00003104 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, es->flags & EF_AFTER_WRAP));
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003105 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
3106 if (l >= es->y_offset + vlc)
3107 dy = l - vlc + 1 - es->y_offset;
3108 if (l < es->y_offset)
3109 dy = l - es->y_offset;
3110 ww = es->format_rect.right - es->format_rect.left;
3111 if (x < es->format_rect.left)
3112 dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw;
3113 if (x > es->format_rect.right)
3114 dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw;
3115 if (dy || dx)
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00003116 {
3117 /* check if we are going to move too far */
3118 if(es->x_offset + dx + ww > es->text_width)
3119 dx = es->text_width - ww - es->x_offset;
3120 if(dx || dy)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003121 EDIT_EM_LineScroll_internal(es, dx, dy);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00003122 }
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003123 } else {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003124 INT x;
3125 INT goal;
3126 INT format_width;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003127
3128 if (!(es->style & ES_AUTOHSCROLL))
3129 return;
3130
Alexandre Julliard9d615962003-09-17 04:28:28 +00003131 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003132 format_width = es->format_rect.right - es->format_rect.left;
3133 if (x < es->format_rect.left) {
3134 goal = es->format_rect.left + format_width / HSCROLL_FRACTION;
3135 do {
3136 es->x_offset--;
Alexandre Julliard9d615962003-09-17 04:28:28 +00003137 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003138 } while ((x < goal) && es->x_offset);
3139 /* FIXME: use ScrollWindow() somehow to improve performance */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003140 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003141 } else if (x > es->format_rect.right) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003142 INT x_last;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003143 INT len = strlenW(es->text);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003144 goal = es->format_rect.right - format_width / HSCROLL_FRACTION;
3145 do {
3146 es->x_offset++;
Alexandre Julliard9d615962003-09-17 04:28:28 +00003147 x = (short)LOWORD(EDIT_EM_PosFromChar(es, es->selection_end, FALSE));
3148 x_last = (short)LOWORD(EDIT_EM_PosFromChar(es, len, FALSE));
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003149 } while ((x > goal) && (x_last > es->format_rect.right));
3150 /* FIXME: use ScrollWindow() somehow to improve performance */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003151 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003152 }
3153 }
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00003154
3155 if(es->flags & EF_FOCUSED)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003156 EDIT_SetCaretPos(es, es->selection_end, es->flags & EF_AFTER_WRAP);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003157}
3158
3159
3160/*********************************************************************
3161 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003162 * EM_SETHANDLE
3163 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00003164 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3165 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00003166 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003167static void EDIT_EM_SetHandle(EDITSTATE *es, HLOCAL hloc)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003168{
Robert Shearman2e9436c2004-08-17 22:29:29 +00003169 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +00003170
Alexandre Julliard889f7421997-04-15 17:19:52 +00003171 if (!(es->style & ES_MULTILINE))
3172 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003173
Alexandre Julliard889f7421997-04-15 17:19:52 +00003174 if (!hloc) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00003175 WARN("called with NULL handle\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003176 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003177 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003178
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003179 EDIT_UnlockBuffer(es, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003180
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003181 if(es->hloc16)
3182 {
Alexandre Julliardde424282001-08-10 22:51:42 +00003183 LOCAL_Free(hInstance, es->hloc16);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003184 es->hloc16 = (HLOCAL16)NULL;
3185 }
3186
3187 if(es->is_unicode)
3188 {
3189 if(es->hloc32A)
3190 {
3191 LocalFree(es->hloc32A);
Francois Gougetd2667a42002-12-02 18:10:57 +00003192 es->hloc32A = NULL;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003193 }
3194 es->hloc32W = hloc;
3195 }
3196 else
3197 {
3198 INT countW, countA;
3199 HLOCAL hloc32W_new;
3200 WCHAR *textW;
3201 CHAR *textA;
3202
3203 countA = LocalSize(hloc);
3204 textA = LocalLock(hloc);
3205 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3206 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3207 {
3208 ERR("Could not allocate new unicode buffer\n");
3209 return;
3210 }
3211 textW = LocalLock(hloc32W_new);
3212 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3213 LocalUnlock(hloc32W_new);
3214 LocalUnlock(hloc);
3215
3216 if(es->hloc32W)
3217 LocalFree(es->hloc32W);
3218
3219 es->hloc32W = hloc32W_new;
3220 es->hloc32A = hloc;
3221 }
3222
3223 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3224
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003225 EDIT_LockBuffer(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003226
3227 es->x_offset = es->y_offset = 0;
3228 es->selection_start = es->selection_end = 0;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003229 EDIT_EM_EmptyUndoBuffer(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003230 es->flags &= ~EF_MODIFIED;
3231 es->flags &= ~EF_UPDATE;
Francois Gougetd2667a42002-12-02 18:10:57 +00003232 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003233 EDIT_UpdateText(es, NULL, TRUE);
3234 EDIT_EM_ScrollCaret(es);
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003235 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003236 EDIT_UpdateScrollInfo(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003237}
3238
3239
3240/*********************************************************************
3241 *
3242 * EM_SETHANDLE16
3243 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00003244 * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ???
3245 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003246 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003247static void EDIT_EM_SetHandle16(EDITSTATE *es, HLOCAL16 hloc)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003248{
Robert Shearman2e9436c2004-08-17 22:29:29 +00003249 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003250 INT countW, countA;
3251 HLOCAL hloc32W_new;
3252 WCHAR *textW;
3253 CHAR *textA;
3254
Alexandre Julliard889f7421997-04-15 17:19:52 +00003255 if (!(es->style & ES_MULTILINE))
3256 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003257
Alexandre Julliard889f7421997-04-15 17:19:52 +00003258 if (!hloc) {
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00003259 WARN("called with NULL handle\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003260 return;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003261 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003262
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003263 EDIT_UnlockBuffer(es, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003264
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003265 if(es->hloc32A)
3266 {
3267 LocalFree(es->hloc32A);
Francois Gougetd2667a42002-12-02 18:10:57 +00003268 es->hloc32A = NULL;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003269 }
3270
Alexandre Julliardde424282001-08-10 22:51:42 +00003271 countA = LOCAL_Size(hInstance, hloc);
3272 textA = LOCAL_Lock(hInstance, hloc);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003273 countW = MultiByteToWideChar(CP_ACP, 0, textA, countA, NULL, 0);
3274 if(!(hloc32W_new = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, countW * sizeof(WCHAR))))
3275 {
3276 ERR("Could not allocate new unicode buffer\n");
3277 return;
3278 }
3279 textW = LocalLock(hloc32W_new);
3280 MultiByteToWideChar(CP_ACP, 0, textA, countA, textW, countW);
3281 LocalUnlock(hloc32W_new);
Alexandre Julliardde424282001-08-10 22:51:42 +00003282 LOCAL_Unlock(hInstance, hloc);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003283
3284 if(es->hloc32W)
3285 LocalFree(es->hloc32W);
3286
3287 es->hloc32W = hloc32W_new;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003288 es->hloc16 = hloc;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003289
3290 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
3291
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003292 EDIT_LockBuffer(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003293
3294 es->x_offset = es->y_offset = 0;
3295 es->selection_start = es->selection_end = 0;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003296 EDIT_EM_EmptyUndoBuffer(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003297 es->flags &= ~EF_MODIFIED;
3298 es->flags &= ~EF_UPDATE;
Francois Gougetd2667a42002-12-02 18:10:57 +00003299 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003300 EDIT_UpdateText(es, NULL, TRUE);
3301 EDIT_EM_ScrollCaret(es);
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003302 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003303 EDIT_UpdateScrollInfo(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003304}
3305
3306
3307/*********************************************************************
3308 *
3309 * EM_SETLIMITTEXT
3310 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00003311 * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF
3312 * However, the windows version is not complied to yet in all of edit.c
3313 *
Aric Stewart08e69392002-08-16 01:41:32 +00003314 * Additionally as the wrapper for RichEdit controls we need larger buffers
3315 * at present -1 will represent nolimit
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003316 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003317static void EDIT_EM_SetLimitText(EDITSTATE *es, INT limit)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003318{
Aric Stewart08e69392002-08-16 01:41:32 +00003319 if (limit == 0xFFFFFFFF)
3320 es->buffer_limit = -1;
3321 else if (es->style & ES_MULTILINE) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003322 if (limit)
Francois Gouget6d77d3a2000-03-25 21:44:35 +00003323 es->buffer_limit = min(limit, BUFLIMIT_MULTI);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003324 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003325 es->buffer_limit = BUFLIMIT_MULTI;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003326 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003327 if (limit)
Francois Gouget6d77d3a2000-03-25 21:44:35 +00003328 es->buffer_limit = min(limit, BUFLIMIT_SINGLE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003329 else
Alexandre Julliard889f7421997-04-15 17:19:52 +00003330 es->buffer_limit = BUFLIMIT_SINGLE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003331 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003332}
3333
3334
3335/*********************************************************************
3336 *
3337 * EM_SETMARGINS
Vincent Béron9a624912002-05-31 23:06:46 +00003338 *
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003339 * EC_USEFONTINFO is used as a left or right value i.e. lParam and not as an
Achim Kaiser6d3ce412003-05-06 18:23:17 +00003340 * action wParam despite what the docs say. EC_USEFONTINFO calculates the
3341 * margin according to the textmetrics of the current font.
3342 *
3343 * FIXME - With TrueType or vector fonts EC_USEFONTINFO currently sets one third
3344 * of the char's width as the margin, but this is not how Windows handles this.
3345 * For all other fonts Windows sets the margins to zero.
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003346 *
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003347 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003348static void EDIT_EM_SetMargins(EDITSTATE *es, INT action,
Alexandre Julliarda3960291999-02-26 11:11:13 +00003349 INT left, INT right)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003350{
Achim Kaiser6d3ce412003-05-06 18:23:17 +00003351 TEXTMETRICW tm;
3352 INT default_left_margin = 0; /* in pixels */
3353 INT default_right_margin = 0; /* in pixels */
3354
3355 /* Set the default margins depending on the font */
3356 if (es->font && (left == EC_USEFONTINFO || right == EC_USEFONTINFO)) {
3357 HDC dc = GetDC(es->hwndSelf);
3358 HFONT old_font = SelectObject(dc, es->font);
3359 GetTextMetricsW(dc, &tm);
3360 /* The default margins are only non zero for TrueType or Vector fonts */
3361 if (tm.tmPitchAndFamily & ( TMPF_VECTOR | TMPF_TRUETYPE )) {
3362 /* This must be calculated more exactly! But how? */
3363 default_left_margin = tm.tmAveCharWidth / 3;
3364 default_right_margin = tm.tmAveCharWidth / 3;
3365 }
3366 SelectObject(dc, old_font);
3367 ReleaseDC(es->hwndSelf, dc);
3368 }
3369
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003370 if (action & EC_LEFTMARGIN) {
3371 if (left != EC_USEFONTINFO)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003372 es->left_margin = left;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003373 else
Achim Kaiser6d3ce412003-05-06 18:23:17 +00003374 es->left_margin = default_left_margin;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00003375 }
3376
3377 if (action & EC_RIGHTMARGIN) {
3378 if (right != EC_USEFONTINFO)
3379 es->right_margin = right;
3380 else
Achim Kaiser6d3ce412003-05-06 18:23:17 +00003381 es->right_margin = default_right_margin;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003382 }
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00003383 TRACE("left=%d, right=%d\n", es->left_margin, es->right_margin);
Alexandre Julliard58199531994-04-21 01:20:00 +00003384}
3385
Alexandre Julliard329f0681996-04-14 13:21:20 +00003386
3387/*********************************************************************
3388 *
3389 * EM_SETPASSWORDCHAR
3390 *
3391 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003392static void EDIT_EM_SetPasswordChar(EDITSTATE *es, WCHAR c)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003393{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003394 LONG style;
Alexandre Julliardde424282001-08-10 22:51:42 +00003395
Alexandre Julliard889f7421997-04-15 17:19:52 +00003396 if (es->style & ES_MULTILINE)
3397 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003398
Alexandre Julliard889f7421997-04-15 17:19:52 +00003399 if (es->password_char == c)
3400 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003401
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003402 style = GetWindowLongW( es->hwndSelf, GWL_STYLE );
Alexandre Julliard889f7421997-04-15 17:19:52 +00003403 es->password_char = c;
3404 if (c) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003405 SetWindowLongW( es->hwndSelf, GWL_STYLE, style | ES_PASSWORD );
Alexandre Julliardde424282001-08-10 22:51:42 +00003406 es->style |= ES_PASSWORD;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003407 } else {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003408 SetWindowLongW( es->hwndSelf, GWL_STYLE, style & ~ES_PASSWORD );
Alexandre Julliardde424282001-08-10 22:51:42 +00003409 es->style &= ~ES_PASSWORD;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003410 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003411 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003412}
3413
3414
3415/*********************************************************************
3416 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00003417 * EDIT_EM_SetSel
3418 *
3419 * note: unlike the specs say: the order of start and end
3420 * _is_ preserved in Windows. (i.e. start can be > end)
3421 * In other words: this handler is OK
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003422 *
3423 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003424static void EDIT_EM_SetSel(EDITSTATE *es, UINT start, UINT end, BOOL after_wrap)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003425{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003426 UINT old_start = es->selection_start;
3427 UINT old_end = es->selection_end;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003428 UINT len = strlenW(es->text);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003429
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003430 if (start == (UINT)-1) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00003431 start = es->selection_end;
3432 end = es->selection_end;
3433 } else {
Francois Gouget6d77d3a2000-03-25 21:44:35 +00003434 start = min(start, len);
3435 end = min(end, len);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003436 }
3437 es->selection_start = start;
3438 es->selection_end = end;
3439 if (after_wrap)
3440 es->flags |= EF_AFTER_WRAP;
3441 else
3442 es->flags &= ~EF_AFTER_WRAP;
Andreas Mohra8edb3e2000-05-23 04:05:05 +00003443/* This is a little bit more efficient than before, not sure if it can be improved. FIXME? */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003444 ORDER_UINT(start, end);
3445 ORDER_UINT(end, old_end);
3446 ORDER_UINT(start, old_start);
3447 ORDER_UINT(old_start, old_end);
Alexandre Julliarde658d821997-11-30 17:45:40 +00003448 if (end != old_start)
3449 {
3450/*
Vincent Béron9a624912002-05-31 23:06:46 +00003451 * One can also do
Alexandre Julliarde658d821997-11-30 17:45:40 +00003452 * ORDER_UINT32(end, old_start);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003453 * EDIT_InvalidateText(es, start, end);
3454 * EDIT_InvalidateText(es, old_start, old_end);
Vincent Béron9a624912002-05-31 23:06:46 +00003455 * in place of the following if statement.
Alexandre Julliarde658d821997-11-30 17:45:40 +00003456 */
3457 if (old_start > end )
3458 {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003459 EDIT_InvalidateText(es, start, end);
3460 EDIT_InvalidateText(es, old_start, old_end);
Alexandre Julliarde658d821997-11-30 17:45:40 +00003461 }
3462 else
3463 {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003464 EDIT_InvalidateText(es, start, old_start);
3465 EDIT_InvalidateText(es, end, old_end);
Alexandre Julliarde658d821997-11-30 17:45:40 +00003466 }
3467 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003468 else EDIT_InvalidateText(es, start, old_end);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003469}
3470
3471
3472/*********************************************************************
3473 *
3474 * EM_SETTABSTOPS
3475 *
3476 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003477static BOOL EDIT_EM_SetTabStops(EDITSTATE *es, INT count, LPINT tabs)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003478{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003479 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003480 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003481 if (es->tabs)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003482 HeapFree(GetProcessHeap(), 0, es->tabs);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003483 es->tabs_count = count;
3484 if (!count)
3485 es->tabs = NULL;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003486 else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003487 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
Alexandre Julliarda3960291999-02-26 11:11:13 +00003488 memcpy(es->tabs, tabs, count * sizeof(INT));
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003489 }
3490 return TRUE;
3491}
3492
3493
3494/*********************************************************************
3495 *
3496 * EM_SETTABSTOPS16
3497 *
3498 */
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003499static BOOL EDIT_EM_SetTabStops16(EDITSTATE *es, INT count, LPINT16 tabs)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003500{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003501 if (!(es->style & ES_MULTILINE))
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003502 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003503 if (es->tabs)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003504 HeapFree(GetProcessHeap(), 0, es->tabs);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003505 es->tabs_count = count;
3506 if (!count)
3507 es->tabs = NULL;
3508 else {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003509 INT i;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003510 es->tabs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
Alexandre Julliard889f7421997-04-15 17:19:52 +00003511 for (i = 0 ; i < count ; i++)
3512 es->tabs[i] = *tabs++;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003513 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00003514 return TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003515}
3516
3517
3518/*********************************************************************
3519 *
3520 * EM_SETWORDBREAKPROC
3521 *
3522 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003523static void EDIT_EM_SetWordBreakProc(EDITSTATE *es, LPARAM lParam)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003524{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003525 if (es->word_break_proc == (void *)lParam)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003526 return;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003527
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003528 es->word_break_proc = (void *)lParam;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003529 es->word_break_proc16 = NULL;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003530
Alexandre Julliard889f7421997-04-15 17:19:52 +00003531 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
Francois Gougetd2667a42002-12-02 18:10:57 +00003532 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003533 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003534 }
3535}
3536
3537
3538/*********************************************************************
3539 *
3540 * EM_SETWORDBREAKPROC16
3541 *
3542 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003543static void EDIT_EM_SetWordBreakProc16(EDITSTATE *es, EDITWORDBREAKPROC16 wbp)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003544{
3545 if (es->word_break_proc16 == wbp)
3546 return;
3547
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003548 es->word_break_proc = NULL;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003549 es->word_break_proc16 = wbp;
3550 if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) {
Francois Gougetd2667a42002-12-02 18:10:57 +00003551 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003552 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003553 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003554}
3555
3556
3557/*********************************************************************
3558 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00003559 * EM_UNDO / WM_UNDO
Alexandre Julliard329f0681996-04-14 13:21:20 +00003560 *
3561 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003562static BOOL EDIT_EM_Undo(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003563{
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003564 INT ulength;
3565 LPWSTR utext;
3566
Krishna Murthya7c31072004-05-07 00:40:18 +00003567 /* As per MSDN spec, for a single-line edit control,
3568 the return value is always TRUE */
3569 if( es->style & ES_READONLY )
3570 return !(es->style & ES_MULTILINE);
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003571
3572 ulength = strlenW(es->undo_text);
Krishna Murthya7c31072004-05-07 00:40:18 +00003573
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003574 utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR));
Alexandre Julliard889f7421997-04-15 17:19:52 +00003575
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003576 strcpyW(utext, es->undo_text);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003577
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00003578 TRACE("before UNDO:insertion length = %d, deletion buffer = %s\n",
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003579 es->undo_insert_count, debugstr_w(utext));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003580
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003581 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003582 EDIT_EM_EmptyUndoBuffer(es);
Krishna Murthyca8e3132004-06-18 22:29:05 +00003583 EDIT_EM_ReplaceSel(es, TRUE, utext, TRUE, TRUE);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003584 EDIT_EM_SetSel(es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE);
Rein Klazes9d4ae0e2001-04-02 19:13:24 +00003585 /* send the notification after the selection start and end are set */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003586 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
3587 EDIT_EM_ScrollCaret(es);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003588 HeapFree(GetProcessHeap(), 0, utext);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003589
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00003590 TRACE("after UNDO:insertion length = %d, deletion buffer = %s\n",
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003591 es->undo_insert_count, debugstr_w(es->undo_text));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003592 return TRUE;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003593}
3594
3595
3596/*********************************************************************
3597 *
3598 * WM_CHAR
3599 *
3600 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003601static void EDIT_WM_Char(EDITSTATE *es, WCHAR c)
Alexandre Julliard329f0681996-04-14 13:21:20 +00003602{
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003603 BOOL control;
3604
3605 /* Protect read-only edit control from modification */
3606 if(es->style & ES_READONLY)
3607 return;
3608
3609 control = GetKeyState(VK_CONTROL) & 0x8000;
3610
Alexandre Julliard329f0681996-04-14 13:21:20 +00003611 switch (c) {
3612 case '\r':
Stephane Lussier5ca2ec41999-09-27 11:45:07 +00003613 /* If the edit doesn't want the return and it's not a multiline edit, do nothing */
3614 if(!(es->style & ES_MULTILINE) && !(es->style & ES_WANTRETURN))
Pascal Lessardaed79e51999-09-10 13:58:34 +00003615 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003616 case '\n':
Alexandre Julliard889f7421997-04-15 17:19:52 +00003617 if (es->style & ES_MULTILINE) {
3618 if (es->style & ES_READONLY) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003619 EDIT_MoveHome(es, FALSE);
3620 EDIT_MoveDown_ML(es, FALSE);
Alexandre Julliardfa2c7932000-05-26 01:24:56 +00003621 } else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003622 static const WCHAR cr_lfW[] = {'\r','\n',0};
Carl Sopchak23b88ef2002-11-21 03:57:05 +00003623 EDIT_EM_ReplaceSel(es, TRUE, cr_lfW, TRUE, TRUE);
Alexandre Julliardfa2c7932000-05-26 01:24:56 +00003624 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003625 }
3626 break;
3627 case '\t':
Alexandre Julliard889f7421997-04-15 17:19:52 +00003628 if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY))
Alexandre Julliardfa2c7932000-05-26 01:24:56 +00003629 {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003630 static const WCHAR tabW[] = {'\t',0};
Carl Sopchak23b88ef2002-11-21 03:57:05 +00003631 EDIT_EM_ReplaceSel(es, TRUE, tabW, TRUE, TRUE);
Alexandre Julliardfa2c7932000-05-26 01:24:56 +00003632 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003633 break;
Pascal Lessard6fe38e51999-09-03 15:02:48 +00003634 case VK_BACK:
3635 if (!(es->style & ES_READONLY) && !control) {
3636 if (es->selection_start != es->selection_end)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003637 EDIT_WM_Clear(es);
Pascal Lessard6fe38e51999-09-03 15:02:48 +00003638 else {
3639 /* delete character left of caret */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003640 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
3641 EDIT_MoveBackward(es, TRUE);
3642 EDIT_WM_Clear(es);
Pascal Lessard6fe38e51999-09-03 15:02:48 +00003643 }
3644 }
3645 break;
Ulrich Czekallac804e3e2000-05-23 21:16:07 +00003646 case 0x03: /* ^C */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003647 SendMessageW(es->hwndSelf, WM_COPY, 0, 0);
Susan Farley86d0b032000-05-05 18:21:02 +00003648 break;
Ulrich Czekallac804e3e2000-05-23 21:16:07 +00003649 case 0x16: /* ^V */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003650 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
Susan Farley86d0b032000-05-05 18:21:02 +00003651 break;
Ulrich Czekallac804e3e2000-05-23 21:16:07 +00003652 case 0x18: /* ^X */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003653 SendMessageW(es->hwndSelf, WM_CUT, 0, 0);
Susan Farley86d0b032000-05-05 18:21:02 +00003654 break;
Vincent Béron9a624912002-05-31 23:06:46 +00003655
Alexandre Julliard329f0681996-04-14 13:21:20 +00003656 default:
Krishna Murthyfd43a462004-07-24 02:26:24 +00003657 /*If Edit control style is ES_NUMBER allow users to key in only numeric values*/
3658 if( (es->style & ES_NUMBER) && !( c >= '0' && c <= '9') )
3659 break;
3660
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003661 if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) {
3662 WCHAR str[2];
Alexandre Julliard329f0681996-04-14 13:21:20 +00003663 str[0] = c;
3664 str[1] = '\0';
Carl Sopchak23b88ef2002-11-21 03:57:05 +00003665 EDIT_EM_ReplaceSel(es, TRUE, str, TRUE, TRUE);
Alexandre Julliard329f0681996-04-14 13:21:20 +00003666 }
3667 break;
3668 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00003669}
3670
3671
3672/*********************************************************************
3673 *
3674 * WM_COMMAND
3675 *
3676 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003677static void EDIT_WM_Command(EDITSTATE *es, INT code, INT id, HWND control)
Alexandre Julliard01d63461997-01-20 19:43:45 +00003678{
Alexandre Julliard889f7421997-04-15 17:19:52 +00003679 if (code || control)
3680 return;
Alexandre Julliard01d63461997-01-20 19:43:45 +00003681
Alexandre Julliard889f7421997-04-15 17:19:52 +00003682 switch (id) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00003683 case EM_UNDO:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003684 EDIT_EM_Undo(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003685 break;
3686 case WM_CUT:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003687 EDIT_WM_Cut(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003688 break;
3689 case WM_COPY:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003690 EDIT_WM_Copy(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003691 break;
3692 case WM_PASTE:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003693 EDIT_WM_Paste(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003694 break;
3695 case WM_CLEAR:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003696 EDIT_WM_Clear(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003697 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +00003698 case EM_SETSEL:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003699 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
3700 EDIT_EM_ScrollCaret(es);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003701 break;
3702 default:
Dimitrie O. Paundd03cc11999-12-08 03:56:23 +00003703 ERR("unknown menu item, please report\n");
Alexandre Julliard01d63461997-01-20 19:43:45 +00003704 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00003705 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00003706}
3707
3708
3709/*********************************************************************
3710 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00003711 * WM_CONTEXTMENU
3712 *
3713 * Note: the resource files resource/sysres_??.rc cannot define a
3714 * single popup menu. Hence we use a (dummy) menubar
3715 * containing the single popup menu as its first item.
3716 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00003717 * FIXME: the message identifiers have been chosen arbitrarily,
3718 * hence we use MF_BYPOSITION.
3719 * We might as well use the "real" values (anybody knows ?)
3720 * The menu definition is in resources/sysres_??.rc.
3721 * Once these are OK, we better use MF_BYCOMMAND here
3722 * (as we do in EDIT_WM_Command()).
3723 *
3724 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003725static void EDIT_WM_ContextMenu(EDITSTATE *es, INT x, INT y)
Alexandre Julliard01d63461997-01-20 19:43:45 +00003726{
Alexandre Julliarda2e2e182004-02-12 00:35:01 +00003727 HMENU menu = LoadMenuA(user32_module, "EDITMENU");
Alexandre Julliarda3960291999-02-26 11:11:13 +00003728 HMENU popup = GetSubMenu(menu, 0);
3729 UINT start = es->selection_start;
3730 UINT end = es->selection_end;
Alexandre Julliard01d63461997-01-20 19:43:45 +00003731
Alexandre Julliarda3960291999-02-26 11:11:13 +00003732 ORDER_UINT(start, end);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003733
3734 /* undo */
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003735 EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003736 /* cut */
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003737 EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003738 /* copy */
Alexandre Julliarda3960291999-02-26 11:11:13 +00003739 EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003740 /* paste */
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003741 EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003742 /* delete */
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00003743 EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003744 /* select all */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003745 EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != strlenW(es->text)) ? MF_ENABLED : MF_GRAYED));
Alexandre Julliard01d63461997-01-20 19:43:45 +00003746
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003747 TrackPopupMenu(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, es->hwndSelf, NULL);
Alexandre Julliarda3960291999-02-26 11:11:13 +00003748 DestroyMenu(menu);
Alexandre Julliard01d63461997-01-20 19:43:45 +00003749}
3750
Alexandre Julliard889f7421997-04-15 17:19:52 +00003751
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003752/*********************************************************************
3753 *
Alexandre Julliard889f7421997-04-15 17:19:52 +00003754 * WM_COPY
3755 *
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003756 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003757static void EDIT_WM_Copy(EDITSTATE *es)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003758{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003759 INT s = min(es->selection_start, es->selection_end);
3760 INT e = max(es->selection_start, es->selection_end);
Alexandre Julliarda3960291999-02-26 11:11:13 +00003761 HGLOBAL hdst;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003762 LPWSTR dst;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003763
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003764 if (e == s) return;
3765
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00003766 hdst = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (DWORD)(e - s + 1) * sizeof(WCHAR));
Alexandre Julliarda3960291999-02-26 11:11:13 +00003767 dst = GlobalLock(hdst);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003768 strncpyW(dst, es->text + s, e - s);
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00003769 dst[e - s] = 0; /* ensure 0 termination */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003770 TRACE("%s\n", debugstr_w(dst));
Alexandre Julliarda3960291999-02-26 11:11:13 +00003771 GlobalUnlock(hdst);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003772 OpenClipboard(es->hwndSelf);
Alexandre Julliarda3960291999-02-26 11:11:13 +00003773 EmptyClipboard();
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003774 SetClipboardData(CF_UNICODETEXT, hdst);
Alexandre Julliarda3960291999-02-26 11:11:13 +00003775 CloseClipboard();
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00003776}
Alexandre Julliard01d63461997-01-20 19:43:45 +00003777
Alexandre Julliard889f7421997-04-15 17:19:52 +00003778
3779/*********************************************************************
3780 *
3781 * WM_CREATE
3782 *
3783 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003784static LRESULT EDIT_WM_Create(EDITSTATE *es, LPCWSTR name)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003785{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003786 TRACE("%s\n", debugstr_w(name));
Pascal Lessarddde4d611999-08-15 16:30:11 +00003787 /*
3788 * To initialize some final structure members, we call some helper
3789 * functions. However, since the EDITSTATE is not consistent (i.e.
3790 * not fully initialized), we should be very careful which
3791 * functions can be called, and in what order.
3792 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003793 EDIT_WM_SetFont(es, 0, FALSE);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00003794 EDIT_EM_EmptyUndoBuffer(es);
Andreas Mohr5f5213a1999-02-13 09:04:22 +00003795
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003796 if (name && *name) {
Carl Sopchak23b88ef2002-11-21 03:57:05 +00003797 EDIT_EM_ReplaceSel(es, FALSE, name, FALSE, TRUE);
Pascal Lessarddde4d611999-08-15 16:30:11 +00003798 /* if we insert text to the editline, the text scrolls out
3799 * of the window, as the caret is placed after the insert
3800 * pos normally; thus we reset es->selection... to 0 and
3801 * update caret
3802 */
3803 es->selection_start = es->selection_end = 0;
Aric Stewart2e0d8cf2002-08-20 00:24:17 +00003804 /* Adobe Photoshop does NOT like this. and MSDN says that EN_CHANGE
3805 * Messages are only to be sent when the USER does something to
3806 * change the contents. So I am removing this EN_CHANGE
3807 *
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003808 * EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
Aric Stewart2e0d8cf2002-08-20 00:24:17 +00003809 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003810 EDIT_EM_ScrollCaret(es);
Pascal Lessarddde4d611999-08-15 16:30:11 +00003811 }
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003812 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003813 EDIT_UpdateScrollInfo(es);
Rein Klazes0de8b212003-10-21 23:49:03 +00003814 /* The rule seems to return 1 here for success */
3815 /* Power Builder masked edit controls will crash */
3816 /* if not. */
3817 /* FIXME: is that in all cases so ? */
3818 return 1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003819}
3820
3821
3822/*********************************************************************
3823 *
3824 * WM_DESTROY
3825 *
3826 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003827static LRESULT EDIT_WM_Destroy(EDITSTATE *es)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003828{
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00003829 LINEDEF *pc, *pp;
3830
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003831 if (es->hloc32W) {
3832 while (LocalUnlock(es->hloc32W)) ;
3833 LocalFree(es->hloc32W);
3834 }
3835 if (es->hloc32A) {
3836 while (LocalUnlock(es->hloc32A)) ;
3837 LocalFree(es->hloc32A);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003838 }
3839 if (es->hloc16) {
Robert Shearman2e9436c2004-08-17 22:29:29 +00003840 HINSTANCE16 hInstance = GetWindowLongPtrW( es->hwndSelf, GWLP_HINSTANCE );
Alexandre Julliardde424282001-08-10 22:51:42 +00003841 while (LOCAL_Unlock(hInstance, es->hloc16)) ;
3842 LOCAL_Free(hInstance, es->hloc16);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003843 }
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00003844
3845 pc = es->first_line_def;
3846 while (pc)
3847 {
3848 pp = pc->next;
3849 HeapFree(GetProcessHeap(), 0, pc);
3850 pc = pp;
3851 }
3852
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003853 SetWindowLongW( es->hwndSelf, 0, 0 );
Alexandre Julliard889f7421997-04-15 17:19:52 +00003854 HeapFree(GetProcessHeap(), 0, es);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003855
3856 return 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003857}
3858
3859
3860/*********************************************************************
3861 *
3862 * WM_ERASEBKGND
3863 *
3864 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003865static LRESULT EDIT_WM_EraseBkGnd(EDITSTATE *es, HDC dc)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003866{
Robert Shearman85703282004-08-17 22:09:16 +00003867 /* we do the proper erase in EDIT_WM_Paint */
3868 return -1;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003869}
3870
3871
3872/*********************************************************************
3873 *
3874 * WM_GETTEXT
3875 *
3876 */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003877static INT EDIT_WM_GetText(EDITSTATE *es, INT count, LPARAM lParam, BOOL unicode)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003878{
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00003879 if(!count) return 0;
3880
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003881 if(unicode)
3882 {
3883 LPWSTR textW = (LPWSTR)lParam;
Alexandre Julliard331bf3d2002-08-15 23:28:45 +00003884 lstrcpynW(textW, es->text, count);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003885 return strlenW(textW);
3886 }
3887 else
3888 {
3889 LPSTR textA = (LPSTR)lParam;
Alexandre Julliard331bf3d2002-08-15 23:28:45 +00003890 if (!WideCharToMultiByte(CP_ACP, 0, es->text, -1, textA, count, NULL, NULL))
3891 textA[count - 1] = 0; /* ensure 0 termination */
Dmitry Timoshkov785203c2001-01-11 20:17:21 +00003892 return strlen(textA);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00003893 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003894}
3895
Alexandre Julliard889f7421997-04-15 17:19:52 +00003896/*********************************************************************
3897 *
3898 * WM_HSCROLL
3899 *
3900 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003901static LRESULT EDIT_WM_HScroll(EDITSTATE *es, INT action, INT pos)
Alexandre Julliard889f7421997-04-15 17:19:52 +00003902{
Alexandre Julliarda3960291999-02-26 11:11:13 +00003903 INT dx;
3904 INT fw;
Alexandre Julliard889f7421997-04-15 17:19:52 +00003905
3906 if (!(es->style & ES_MULTILINE))
3907 return 0;
3908
3909 if (!(es->style & ES_AUTOHSCROLL))
3910 return 0;
3911
Alexandre Julliard889f7421997-04-15 17:19:52 +00003912 dx = 0;
3913 fw = es->format_rect.right - es->format_rect.left;
3914 switch (action) {
3915 case SB_LINELEFT:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003916 TRACE("SB_LINELEFT\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003917 if (es->x_offset)
3918 dx = -es->char_width;
3919 break;
3920 case SB_LINERIGHT:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003921 TRACE("SB_LINERIGHT\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003922 if (es->x_offset < es->text_width)
3923 dx = es->char_width;
3924 break;
3925 case SB_PAGELEFT:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003926 TRACE("SB_PAGELEFT\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003927 if (es->x_offset)
3928 dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3929 break;
3930 case SB_PAGERIGHT:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003931 TRACE("SB_PAGERIGHT\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003932 if (es->x_offset < es->text_width)
3933 dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width;
3934 break;
3935 case SB_LEFT:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003936 TRACE("SB_LEFT\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003937 if (es->x_offset)
3938 dx = -es->x_offset;
3939 break;
3940 case SB_RIGHT:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003941 TRACE("SB_RIGHT\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003942 if (es->x_offset < es->text_width)
3943 dx = es->text_width - es->x_offset;
3944 break;
3945 case SB_THUMBTRACK:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003946 TRACE("SB_THUMBTRACK %d\n", pos);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003947 es->flags |= EF_HSCROLL_TRACK;
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003948 if(es->style & WS_HSCROLL)
3949 dx = pos - es->x_offset;
3950 else
3951 {
3952 INT fw, new_x;
3953 /* Sanity check */
3954 if(pos < 0 || pos > 100) return 0;
3955 /* Assume default scroll range 0-100 */
3956 fw = es->format_rect.right - es->format_rect.left;
3957 new_x = pos * (es->text_width - fw) / 100;
3958 dx = es->text_width ? (new_x - es->x_offset) : 0;
3959 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00003960 break;
3961 case SB_THUMBPOSITION:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003962 TRACE("SB_THUMBPOSITION %d\n", pos);
Alexandre Julliard889f7421997-04-15 17:19:52 +00003963 es->flags &= ~EF_HSCROLL_TRACK;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003964 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003965 dx = pos - es->x_offset;
3966 else
3967 {
3968 INT fw, new_x;
3969 /* Sanity check */
3970 if(pos < 0 || pos > 100) return 0;
3971 /* Assume default scroll range 0-100 */
3972 fw = es->format_rect.right - es->format_rect.left;
3973 new_x = pos * (es->text_width - fw) / 100;
3974 dx = es->text_width ? (new_x - es->x_offset) : 0;
3975 }
3976 if (!dx) {
3977 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003978 EDIT_UpdateScrollInfo(es);
3979 EDIT_NOTIFY_PARENT(es, EN_HSCROLL, "EN_HSCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +00003980 }
3981 break;
3982 case SB_ENDSCROLL:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003983 TRACE("SB_ENDSCROLL\n");
3984 break;
3985 /*
3986 * FIXME : the next two are undocumented !
3987 * Are we doing the right thing ?
3988 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
3989 * although it's also a regular control message.
3990 */
3991 case EM_GETTHUMB: /* this one is used by NT notepad */
3992 case EM_GETTHUMB16:
3993 {
3994 LRESULT ret;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00003995 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_HSCROLL)
3996 ret = GetScrollPos(es->hwndSelf, SB_HORZ);
Dmitry Timoshkova234db82001-01-19 20:49:54 +00003997 else
3998 {
3999 /* Assume default scroll range 0-100 */
4000 INT fw = es->format_rect.right - es->format_rect.left;
4001 ret = es->text_width ? es->x_offset * 100 / (es->text_width - fw) : 0;
4002 }
4003 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4004 return ret;
4005 }
4006 case EM_LINESCROLL16:
4007 TRACE("EM_LINESCROLL16\n");
4008 dx = pos;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004009 break;
4010
4011 default:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004012 ERR("undocumented WM_HSCROLL action %d (0x%04x), please report\n",
4013 action, action);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004014 return 0;
4015 }
4016 if (dx)
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00004017 {
4018 INT fw = es->format_rect.right - es->format_rect.left;
4019 /* check if we are going to move too far */
4020 if(es->x_offset + dx + fw > es->text_width)
4021 dx = es->text_width - fw - es->x_offset;
4022 if(dx)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004023 EDIT_EM_LineScroll_internal(es, dx, 0);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00004024 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00004025 return 0;
4026}
4027
4028
4029/*********************************************************************
4030 *
4031 * EDIT_CheckCombo
4032 *
4033 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004034static BOOL EDIT_CheckCombo(EDITSTATE *es, UINT msg, INT key)
Alexandre Julliard889f7421997-04-15 17:19:52 +00004035{
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004036 HWND hLBox = es->hwndListBox;
4037 HWND hCombo;
4038 BOOL bDropped;
4039 int nEUI;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004040
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004041 if (!hLBox)
4042 return FALSE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004043
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004044 hCombo = GetParent(es->hwndSelf);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004045 bDropped = TRUE;
4046 nEUI = 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004047
Alexandre Julliardaff7dda2002-11-22 21:22:14 +00004048 TRACE_(combo)("[%p]: handling msg %x (%x)\n", es->hwndSelf, msg, key);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004049
4050 if (key == VK_UP || key == VK_DOWN)
4051 {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004052 if (SendMessageW(hCombo, CB_GETEXTENDEDUI, 0, 0))
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004053 nEUI = 1;
4054
4055 if (msg == WM_KEYDOWN || nEUI)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004056 bDropped = (BOOL)SendMessageW(hCombo, CB_GETDROPPEDSTATE, 0, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004057 }
4058
4059 switch (msg)
4060 {
4061 case WM_KEYDOWN:
4062 if (!bDropped && nEUI && (key == VK_UP || key == VK_DOWN))
4063 {
4064 /* make sure ComboLBox pops up */
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004065 SendMessageW(hCombo, CB_SETEXTENDEDUI, FALSE, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004066 key = VK_F4;
4067 nEUI = 2;
4068 }
4069
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004070 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)key, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004071 break;
4072
4073 case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */
4074 if (nEUI)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004075 SendMessageW(hCombo, CB_SHOWDROPDOWN, bDropped ? FALSE : TRUE, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004076 else
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004077 SendMessageW(hLBox, WM_KEYDOWN, (WPARAM)VK_F4, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004078 break;
4079 }
4080
4081 if(nEUI == 2)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004082 SendMessageW(hCombo, CB_SETEXTENDEDUI, TRUE, 0);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004083
4084 return TRUE;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004085}
4086
4087
Alexandre Julliard01d63461997-01-20 19:43:45 +00004088/*********************************************************************
4089 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004090 * WM_KEYDOWN
4091 *
4092 * Handling of special keys that don't produce a WM_CHAR
4093 * (i.e. non-printable keys) & Backspace & Delete
4094 *
4095 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004096static LRESULT EDIT_WM_KeyDown(EDITSTATE *es, INT key)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004097{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004098 BOOL shift;
4099 BOOL control;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004100
Alexandre Julliarda3960291999-02-26 11:11:13 +00004101 if (GetKeyState(VK_MENU) & 0x8000)
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004102 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004103
Alexandre Julliarda3960291999-02-26 11:11:13 +00004104 shift = GetKeyState(VK_SHIFT) & 0x8000;
4105 control = GetKeyState(VK_CONTROL) & 0x8000;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004106
Alexandre Julliard889f7421997-04-15 17:19:52 +00004107 switch (key) {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00004108 case VK_F4:
Alexandre Julliard329f0681996-04-14 13:21:20 +00004109 case VK_UP:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004110 if (EDIT_CheckCombo(es, WM_KEYDOWN, key) || key == VK_F4)
Alexandre Julliard889f7421997-04-15 17:19:52 +00004111 break;
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004112
Alexandre Julliard889f7421997-04-15 17:19:52 +00004113 /* fall through */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00004114 case VK_LEFT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00004115 if ((es->style & ES_MULTILINE) && (key == VK_UP))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004116 EDIT_MoveUp_ML(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004117 else
4118 if (control)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004119 EDIT_MoveWordBackward(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004120 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004121 EDIT_MoveBackward(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004122 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004123 case VK_DOWN:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004124 if (EDIT_CheckCombo(es, WM_KEYDOWN, key))
Alexandre Julliard889f7421997-04-15 17:19:52 +00004125 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00004126 /* fall through */
4127 case VK_RIGHT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00004128 if ((es->style & ES_MULTILINE) && (key == VK_DOWN))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004129 EDIT_MoveDown_ML(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004130 else if (control)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004131 EDIT_MoveWordForward(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004132 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004133 EDIT_MoveForward(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004134 break;
4135 case VK_HOME:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004136 EDIT_MoveHome(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004137 break;
4138 case VK_END:
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004139 EDIT_MoveEnd(es, shift);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004140 break;
4141 case VK_PRIOR:
Alexandre Julliard889f7421997-04-15 17:19:52 +00004142 if (es->style & ES_MULTILINE)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004143 EDIT_MovePageUp_ML(es, shift);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004144 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004145 EDIT_CheckCombo(es, WM_KEYDOWN, key);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004146 break;
4147 case VK_NEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00004148 if (es->style & ES_MULTILINE)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004149 EDIT_MovePageDown_ML(es, shift);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004150 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004151 EDIT_CheckCombo(es, WM_KEYDOWN, key);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004152 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004153 case VK_DELETE:
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00004154 if (!(es->style & ES_READONLY) && !(shift && control)) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00004155 if (es->selection_start != es->selection_end) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00004156 if (shift)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004157 EDIT_WM_Cut(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004158 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004159 EDIT_WM_Clear(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004160 } else {
Alexandre Julliard889f7421997-04-15 17:19:52 +00004161 if (shift) {
4162 /* delete character left of caret */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004163 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4164 EDIT_MoveBackward(es, TRUE);
4165 EDIT_WM_Clear(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004166 } else if (control) {
4167 /* delete to end of line */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004168 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4169 EDIT_MoveEnd(es, TRUE);
4170 EDIT_WM_Clear(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004171 } else {
4172 /* delete character right of caret */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004173 EDIT_EM_SetSel(es, (UINT)-1, 0, FALSE);
4174 EDIT_MoveForward(es, TRUE);
4175 EDIT_WM_Clear(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004176 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00004177 }
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00004178 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00004179 break;
4180 case VK_INSERT:
4181 if (shift) {
Alexandre Julliard889f7421997-04-15 17:19:52 +00004182 if (!(es->style & ES_READONLY))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004183 EDIT_WM_Paste(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004184 } else if (control)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004185 EDIT_WM_Copy(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004186 break;
Pascal Lessardaed79e51999-09-10 13:58:34 +00004187 case VK_RETURN:
4188 /* If the edit doesn't want the return send a message to the default object */
4189 if(!(es->style & ES_WANTRETURN))
4190 {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004191 HWND hwndParent = GetParent(es->hwndSelf);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004192 DWORD dw = SendMessageW( hwndParent, DM_GETDEFID, 0, 0 );
Pascal Lessardaed79e51999-09-10 13:58:34 +00004193 if (HIWORD(dw) == DC_HASDEFID)
4194 {
Vincent Béron9a624912002-05-31 23:06:46 +00004195 SendMessageW( hwndParent, WM_COMMAND,
Pascal Lessardaed79e51999-09-10 13:58:34 +00004196 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
4197 (LPARAM)GetDlgItem( hwndParent, LOWORD(dw) ) );
4198 }
4199 }
4200 break;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004201 }
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004202 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004203}
4204
4205
4206/*********************************************************************
4207 *
4208 * WM_KILLFOCUS
4209 *
4210 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004211static LRESULT EDIT_WM_KillFocus(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004212{
Alexandre Julliard889f7421997-04-15 17:19:52 +00004213 es->flags &= ~EF_FOCUSED;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004214 DestroyCaret();
Alexandre Julliard889f7421997-04-15 17:19:52 +00004215 if(!(es->style & ES_NOHIDESEL))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004216 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4217 EDIT_NOTIFY_PARENT(es, EN_KILLFOCUS, "EN_KILLFOCUS");
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004218 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004219}
4220
4221
4222/*********************************************************************
4223 *
4224 * WM_LBUTTONDBLCLK
4225 *
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00004226 * The caret position has been set on the WM_LBUTTONDOWN message
4227 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004228 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004229static LRESULT EDIT_WM_LButtonDblClk(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004230{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004231 INT s;
4232 INT e = es->selection_end;
4233 INT l;
4234 INT li;
4235 INT ll;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004236
Alexandre Julliard889f7421997-04-15 17:19:52 +00004237 if (!(es->flags & EF_FOCUSED))
4238 return 0;
4239
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00004240 l = EDIT_EM_LineFromChar(es, e);
4241 li = EDIT_EM_LineIndex(es, l);
4242 ll = EDIT_EM_LineLength(es, e);
Dmitry Timoshkov8058ead2000-12-21 20:19:21 +00004243 s = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_LEFT);
4244 e = li + EDIT_CallWordBreakProc(es, li, e - li, ll, WB_RIGHT);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004245 EDIT_EM_SetSel(es, s, e, FALSE);
4246 EDIT_EM_ScrollCaret(es);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004247 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004248}
4249
4250
4251/*********************************************************************
4252 *
4253 * WM_LBUTTONDOWN
4254 *
4255 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004256static LRESULT EDIT_WM_LButtonDown(EDITSTATE *es, DWORD keys, INT x, INT y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004257{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004258 INT e;
4259 BOOL after_wrap;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004260
Huw Davies137f41d2003-11-03 22:15:59 +00004261 SetFocus(es->hwndSelf);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004262 if (!(es->flags & EF_FOCUSED))
4263 return 0;
4264
Abey George6e013e51999-07-27 17:08:26 +00004265 es->bCaptureState = TRUE;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004266 SetCapture(es->hwndSelf);
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00004267 EDIT_ConfinePoint(es, &x, &y);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004268 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4269 EDIT_EM_SetSel(es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap);
4270 EDIT_EM_ScrollCaret(es);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00004271 es->region_posx = es->region_posy = 0;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004272 SetTimer(es->hwndSelf, 0, 100, NULL);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004273 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004274}
4275
4276
4277/*********************************************************************
4278 *
4279 * WM_LBUTTONUP
4280 *
4281 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004282static LRESULT EDIT_WM_LButtonUp(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004283{
Alexandre Julliard6356a442003-02-19 22:04:03 +00004284 if (es->bCaptureState) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004285 KillTimer(es->hwndSelf, 0);
Alexandre Julliard6356a442003-02-19 22:04:03 +00004286 if (GetCapture() == es->hwndSelf) ReleaseCapture();
Alexandre Julliard01d63461997-01-20 19:43:45 +00004287 }
Abey George6e013e51999-07-27 17:08:26 +00004288 es->bCaptureState = FALSE;
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004289 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004290}
4291
4292
4293/*********************************************************************
4294 *
Alexandre Julliardc6166252000-05-25 23:01:39 +00004295 * WM_MBUTTONDOWN
4296 *
4297 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004298static LRESULT EDIT_WM_MButtonDown(EDITSTATE *es)
Vincent Béron9a624912002-05-31 23:06:46 +00004299{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004300 SendMessageW(es->hwndSelf, WM_PASTE, 0, 0);
Alexandre Julliardc6166252000-05-25 23:01:39 +00004301 return 0;
4302}
4303
4304
4305/*********************************************************************
4306 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004307 * WM_MOUSEMOVE
4308 *
4309 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004310static LRESULT EDIT_WM_MouseMove(EDITSTATE *es, INT x, INT y)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004311{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004312 INT e;
4313 BOOL after_wrap;
4314 INT prex, prey;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004315
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004316 if (GetCapture() != es->hwndSelf)
Alexandre Julliard889f7421997-04-15 17:19:52 +00004317 return 0;
4318
Alexandre Julliard01d63461997-01-20 19:43:45 +00004319 /*
Alexandre Julliard889f7421997-04-15 17:19:52 +00004320 * FIXME: gotta do some scrolling if outside client
Alexandre Julliard01d63461997-01-20 19:43:45 +00004321 * area. Maybe reset the timer ?
4322 */
Alexandre Julliarde658d821997-11-30 17:45:40 +00004323 prex = x; prey = y;
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00004324 EDIT_ConfinePoint(es, &x, &y);
Alexandre Julliarde658d821997-11-30 17:45:40 +00004325 es->region_posx = (prex < x) ? -1 : ((prex > x) ? 1 : 0);
4326 es->region_posy = (prey < y) ? -1 : ((prey > y) ? 1 : 0);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004327 e = EDIT_CharFromPos(es, x, y, &after_wrap);
4328 EDIT_EM_SetSel(es, es->selection_start, e, after_wrap);
4329 EDIT_SetCaretPos(es,es->selection_end,es->flags & EF_AFTER_WRAP);
Alexandre Julliardc6c09441997-01-12 18:32:19 +00004330 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004331}
4332
4333
4334/*********************************************************************
4335 *
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004336 * WM_NCCREATE
4337 *
Bill Medland86bfa4c2001-06-28 18:01:00 +00004338 * See also EDIT_WM_StyleChanged
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004339 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004340static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs, BOOL unicode)
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004341{
4342 EDITSTATE *es;
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00004343 UINT alloc_size;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004344
Alexandre Julliardde424282001-08-10 22:51:42 +00004345 TRACE("Creating %s edit control, style = %08lx\n",
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004346 unicode ? "Unicode" : "ANSI", lpcs->style);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004347
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004348 if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es))))
4349 return FALSE;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004350 SetWindowLongW( hwnd, 0, (LONG)es );
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004351
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00004352 /*
4353 * Note: since the EDITSTATE has not been fully initialized yet,
4354 * we can't use any API calls that may send
4355 * WM_XXX messages before WM_NCCREATE is completed.
4356 */
4357
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004358 es->is_unicode = unicode;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004359 es->style = lpcs->style;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004360
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004361 es->bEnableState = !(es->style & WS_DISABLED);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004362
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004363 es->hwndSelf = hwnd;
Dmitry Timoshkova62f06d2001-03-13 23:31:08 +00004364 /* Save parent, which will be notified by EN_* messages */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004365 es->hwndParent = lpcs->hwndParent;
Dmitry Timoshkova62f06d2001-03-13 23:31:08 +00004366
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004367 if (es->style & ES_COMBO)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004368 es->hwndListBox = GetDlgItem(es->hwndParent, ID_CB_LISTBOX);
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004369
Bill Medland86bfa4c2001-06-28 18:01:00 +00004370 /* Number overrides lowercase overrides uppercase (at least it
4371 * does in Win95). However I'll bet that ES_NUMBER would be
4372 * invalid under Win 3.1.
4373 */
4374 if (es->style & ES_NUMBER) {
4375 ; /* do not override the ES_NUMBER */
4376 } else if (es->style & ES_LOWERCASE) {
4377 es->style &= ~ES_UPPERCASE;
4378 }
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004379 if (es->style & ES_MULTILINE) {
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004380 es->buffer_limit = BUFLIMIT_MULTI;
4381 if (es->style & WS_VSCROLL)
4382 es->style |= ES_AUTOVSCROLL;
4383 if (es->style & WS_HSCROLL)
4384 es->style |= ES_AUTOHSCROLL;
4385 es->style &= ~ES_PASSWORD;
4386 if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) {
Bill Medland86bfa4c2001-06-28 18:01:00 +00004387 /* Confirmed - RIGHT overrides CENTER */
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004388 if (es->style & ES_RIGHT)
4389 es->style &= ~ES_CENTER;
4390 es->style &= ~WS_HSCROLL;
4391 es->style &= ~ES_AUTOHSCROLL;
4392 }
4393
4394 /* FIXME: for now, all multi line controls are AUTOVSCROLL */
4395 es->style |= ES_AUTOVSCROLL;
4396 } else {
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004397 es->buffer_limit = BUFLIMIT_SINGLE;
Dimitrie O. Paunabe9c972004-04-01 21:06:14 +00004398 es->style &= ~ES_CENTER;
4399 es->style &= ~ES_RIGHT;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004400 es->style &= ~WS_HSCROLL;
4401 es->style &= ~WS_VSCROLL;
4402 es->style &= ~ES_AUTOVSCROLL;
4403 es->style &= ~ES_WANTRETURN;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004404 if (es->style & ES_PASSWORD)
4405 es->password_char = '*';
4406
4407 /* FIXME: for now, all single line controls are AUTOHSCROLL */
4408 es->style |= ES_AUTOHSCROLL;
4409 }
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004410
Dmitry Timoshkovdf793bc2001-01-15 20:20:31 +00004411 alloc_size = ROUND_TO_GROW((es->buffer_size + 1) * sizeof(WCHAR));
Dmitry Timoshkovf8b96e22000-12-20 18:39:14 +00004412 if(!(es->hloc32W = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004413 return FALSE;
4414 es->buffer_size = LocalSize(es->hloc32W)/sizeof(WCHAR) - 1;
4415
4416 if (!(es->undo_text = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (es->buffer_size + 1) * sizeof(WCHAR))))
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004417 return FALSE;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004418 es->undo_buffer_size = es->buffer_size;
4419
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004420 if (es->style & ES_MULTILINE)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004421 if (!(es->first_line_def = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINEDEF))))
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004422 return FALSE;
4423 es->line_count = 1;
4424
Dmitry Timoshkovb85a6e82001-10-08 20:33:08 +00004425 /*
Vincent Béron9a624912002-05-31 23:06:46 +00004426 * In Win95 look and feel, the WS_BORDER style is replaced by the
4427 * WS_EX_CLIENTEDGE style for the edit control. This gives the edit
Dmitry Timoshkovb85a6e82001-10-08 20:33:08 +00004428 * control a non client area. Not always. This coordinates in some
Vincent Béron9a624912002-05-31 23:06:46 +00004429 * way with the window creation code in dialog.c When making
Dmitry Timoshkovb85a6e82001-10-08 20:33:08 +00004430 * modifications please ensure that the code still works for edit
4431 * controls created directly with style 0x50800000, exStyle 0 (
4432 * which should have a single pixel border)
4433 */
Dimitrie O. Paun126227a2004-04-01 04:57:12 +00004434 es->style &= ~WS_BORDER;
Dmitry Timoshkovb85a6e82001-10-08 20:33:08 +00004435
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004436 return TRUE;
4437}
4438
4439/*********************************************************************
4440 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004441 * WM_PAINT
4442 *
4443 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004444static void EDIT_WM_Paint(EDITSTATE *es, WPARAM wParam)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004445{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004446 PAINTSTRUCT ps;
4447 INT i;
4448 HDC dc;
4449 HFONT old_font = 0;
4450 RECT rc;
Robert Shearman85703282004-08-17 22:09:16 +00004451 RECT rcClient;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004452 RECT rcLine;
4453 RECT rcRgn;
Robert Shearman85703282004-08-17 22:09:16 +00004454 HBRUSH brush;
Stephane Lussier93805341999-09-03 16:37:00 +00004455 BOOL rev = es->bEnableState &&
Alexandre Julliard889f7421997-04-15 17:19:52 +00004456 ((es->flags & EF_FOCUSED) ||
4457 (es->style & ES_NOHIDESEL));
Gerard Patel8e5c72e1999-09-03 12:23:52 +00004458 if (!wParam)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004459 dc = BeginPaint(es->hwndSelf, &ps);
Gerard Patel8e5c72e1999-09-03 12:23:52 +00004460 else
4461 dc = (HDC) wParam;
Robert Shearman85703282004-08-17 22:09:16 +00004462
4463 GetClientRect(es->hwndSelf, &rcClient);
4464
4465 /* paint the background */
4466 if (!(brush = EDIT_NotifyCtlColor(es, dc)))
4467 brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
4468 IntersectClipRect(dc, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
4469 GetClipBox(dc, &rc);
4470 FillRect(dc, &rc, brush);
4471
4472 /* draw the border */
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004473 if(es->style & WS_BORDER) {
Robert Shearman85703282004-08-17 22:09:16 +00004474 rc = rcClient;
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004475 if(es->style & ES_MULTILINE) {
4476 if(es->style & WS_HSCROLL) rc.bottom++;
4477 if(es->style & WS_VSCROLL) rc.right++;
4478 }
Francis Beaudet06e88861999-07-30 17:59:35 +00004479 Rectangle(dc, rc.left, rc.top, rc.right, rc.bottom);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004480 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00004481 IntersectClipRect(dc, es->format_rect.left,
Alexandre Julliard889f7421997-04-15 17:19:52 +00004482 es->format_rect.top,
4483 es->format_rect.right,
4484 es->format_rect.bottom);
4485 if (es->style & ES_MULTILINE) {
Robert Shearman85703282004-08-17 22:09:16 +00004486 rc = rcClient;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004487 IntersectClipRect(dc, rc.left, rc.top, rc.right, rc.bottom);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004488 }
4489 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00004490 old_font = SelectObject(dc, es->font);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004491 EDIT_NotifyCtlColor(es, dc);
Stephane Lussier93805341999-09-03 16:37:00 +00004492
4493 if (!es->bEnableState)
Alexandre Julliarda3960291999-02-26 11:11:13 +00004494 SetTextColor(dc, GetSysColor(COLOR_GRAYTEXT));
4495 GetClipBox(dc, &rcRgn);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004496 if (es->style & ES_MULTILINE) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004497 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
Francois Gouget6d77d3a2000-03-25 21:44:35 +00004498 for (i = es->y_offset ; i <= min(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004499 EDIT_GetLineRect(es, i, 0, -1, &rcLine);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004500 if (IntersectRect(&rc, &rcRgn, &rcLine))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004501 EDIT_PaintLine(es, dc, i, rev);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004502 }
4503 } else {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004504 EDIT_GetLineRect(es, 0, 0, -1, &rcLine);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004505 if (IntersectRect(&rc, &rcRgn, &rcLine))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004506 EDIT_PaintLine(es, dc, 0, rev);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004507 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00004508 if (es->font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00004509 SelectObject(dc, old_font);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00004510
Gerard Patel8e5c72e1999-09-03 12:23:52 +00004511 if (!wParam)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004512 EndPaint(es->hwndSelf, &ps);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004513}
4514
4515
4516/*********************************************************************
4517 *
4518 * WM_PASTE
4519 *
4520 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004521static void EDIT_WM_Paste(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004522{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004523 HGLOBAL hsrc;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004524 LPWSTR src;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004525
Dmitry Timoshkov9c446a12001-01-22 19:28:27 +00004526 /* Protect read-only edit control from modification */
4527 if(es->style & ES_READONLY)
4528 return;
4529
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004530 OpenClipboard(es->hwndSelf);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004531 if ((hsrc = GetClipboardData(CF_UNICODETEXT))) {
4532 src = (LPWSTR)GlobalLock(hsrc);
Carl Sopchak23b88ef2002-11-21 03:57:05 +00004533 EDIT_EM_ReplaceSel(es, TRUE, src, TRUE, TRUE);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004534 GlobalUnlock(hsrc);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004535 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00004536 CloseClipboard();
Alexandre Julliard329f0681996-04-14 13:21:20 +00004537}
4538
4539
4540/*********************************************************************
4541 *
4542 * WM_SETFOCUS
4543 *
4544 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004545static void EDIT_WM_SetFocus(EDITSTATE *es)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004546{
Alexandre Julliard889f7421997-04-15 17:19:52 +00004547 es->flags |= EF_FOCUSED;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004548 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4549 EDIT_SetCaretPos(es, es->selection_end,
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004550 es->flags & EF_AFTER_WRAP);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004551 if(!(es->style & ES_NOHIDESEL))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004552 EDIT_InvalidateText(es, es->selection_start, es->selection_end);
4553 ShowCaret(es->hwndSelf);
4554 EDIT_NOTIFY_PARENT(es, EN_SETFOCUS, "EN_SETFOCUS");
Alexandre Julliard329f0681996-04-14 13:21:20 +00004555}
4556
4557
4558/*********************************************************************
4559 *
4560 * WM_SETFONT
4561 *
Vincent Béron9a624912002-05-31 23:06:46 +00004562 * With Win95 look the margins are set to default font value unless
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004563 * the system font (font == 0) is being set, in which case they are left
4564 * unchanged.
4565 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004566 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004567static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004568{
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004569 TEXTMETRICW tm;
Alexandre Julliarda3960291999-02-26 11:11:13 +00004570 HDC dc;
4571 HFONT old_font = 0;
Pascal Lessard3405f5c1999-09-04 10:59:07 +00004572 RECT r;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004573
Alexandre Julliard889f7421997-04-15 17:19:52 +00004574 es->font = font;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004575 dc = GetDC(es->hwndSelf);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004576 if (font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00004577 old_font = SelectObject(dc, font);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004578 GetTextMetricsW(dc, &tm);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004579 es->line_height = tm.tmHeight;
4580 es->char_width = tm.tmAveCharWidth;
4581 if (font)
Alexandre Julliarda3960291999-02-26 11:11:13 +00004582 SelectObject(dc, old_font);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004583 ReleaseDC(es->hwndSelf, dc);
Dimitrie O. Paun126227a2004-04-01 04:57:12 +00004584 EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
4585 EC_USEFONTINFO, EC_USEFONTINFO);
Pascal Lessard3405f5c1999-09-04 10:59:07 +00004586
4587 /* Force the recalculation of the format rect for each font change */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004588 GetClientRect(es->hwndSelf, &r);
4589 EDIT_SetRectNP(es, &r);
Pascal Lessard3405f5c1999-09-04 10:59:07 +00004590
Alexandre Julliard889f7421997-04-15 17:19:52 +00004591 if (es->style & ES_MULTILINE)
Francois Gougetd2667a42002-12-02 18:10:57 +00004592 EDIT_BuildLineDefs_ML(es, 0, strlenW(es->text), 0, NULL);
Dmitry Timoshkov11dbda62001-01-05 03:40:35 +00004593 else
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004594 EDIT_CalcLineWidth_SL(es);
Pascal Lessard3405f5c1999-09-04 10:59:07 +00004595
Alexandre Julliarde658d821997-11-30 17:45:40 +00004596 if (redraw)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004597 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004598 if (es->flags & EF_FOCUSED) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004599 DestroyCaret();
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004600 CreateCaret(es->hwndSelf, 0, 2, es->line_height);
4601 EDIT_SetCaretPos(es, es->selection_end,
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004602 es->flags & EF_AFTER_WRAP);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004603 ShowCaret(es->hwndSelf);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004604 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00004605}
4606
4607
4608/*********************************************************************
4609 *
4610 * WM_SETTEXT
4611 *
Alexandre Julliardd30dfd21998-09-27 18:28:36 +00004612 * NOTES
4613 * For multiline controls (ES_MULTILINE), reception of WM_SETTEXT triggers:
4614 * The modified flag is reset. No notifications are sent.
4615 *
4616 * For single-line controls, reception of WM_SETTEXT triggers:
4617 * The modified flag is reset. EN_UPDATE and EN_CHANGE notifications are sent.
4618 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004619 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004620static void EDIT_WM_SetText(EDITSTATE *es, LPARAM lParam, BOOL unicode)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004621{
James Hathewayf3ea3452001-01-12 23:01:41 +00004622 LPWSTR text = NULL;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004623
4624 if(unicode)
4625 text = (LPWSTR)lParam;
James Hathewayf3ea3452001-01-12 23:01:41 +00004626 else if (lParam)
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004627 {
4628 LPCSTR textA = (LPCSTR)lParam;
4629 INT countW = MultiByteToWideChar(CP_ACP, 0, textA, -1, NULL, 0);
4630 if((text = HeapAlloc(GetProcessHeap(), 0, countW * sizeof(WCHAR))))
4631 MultiByteToWideChar(CP_ACP, 0, textA, -1, text, countW);
4632 }
4633
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004634 EDIT_EM_SetSel(es, 0, (UINT)-1, FALSE);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004635 if (text) {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004636 TRACE("%s\n", debugstr_w(text));
Carl Sopchak23b88ef2002-11-21 03:57:05 +00004637 EDIT_EM_ReplaceSel(es, FALSE, text, FALSE, FALSE);
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004638 if(!unicode)
4639 HeapFree(GetProcessHeap(), 0, text);
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004640 } else {
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004641 static const WCHAR empty_stringW[] = {0};
4642 TRACE("<NULL>\n");
Carl Sopchak23b88ef2002-11-21 03:57:05 +00004643 EDIT_EM_ReplaceSel(es, FALSE, empty_stringW, FALSE, FALSE);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00004644 }
Alexandre Julliardebfc0fe1998-06-28 18:40:26 +00004645 es->x_offset = 0;
Alexandre Julliard829fe321998-07-26 14:27:39 +00004646 es->flags &= ~EF_MODIFIED;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004647 EDIT_EM_SetSel(es, 0, 0, FALSE);
Rein Klazes9d4ae0e2001-04-02 19:13:24 +00004648 /* Send the notification after the selection start and end have been set
4649 * edit control doesn't send notification on WM_SETTEXT
4650 * if it is multiline, or it is part of combobox
4651 */
4652 if( !((es->style & ES_MULTILINE) || es->hwndListBox))
Rizsanyi Zsolt83d6efb2002-04-11 17:30:22 +00004653 {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004654 EDIT_NOTIFY_PARENT(es, EN_CHANGE, "EN_CHANGE");
4655 EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
Rizsanyi Zsolt83d6efb2002-04-11 17:30:22 +00004656 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004657 EDIT_EM_ScrollCaret(es);
Alexandre Julliard329f0681996-04-14 13:21:20 +00004658}
4659
4660
4661/*********************************************************************
4662 *
4663 * WM_SIZE
4664 *
4665 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004666static void EDIT_WM_Size(EDITSTATE *es, UINT action, INT width, INT height)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004667{
Alexandre Julliard889f7421997-04-15 17:19:52 +00004668 if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00004669 RECT rc;
Dmitry Timoshkov4e62b9d2000-12-19 19:36:49 +00004670 TRACE("width = %d, height = %d\n", width, height);
Alexandre Julliarda3960291999-02-26 11:11:13 +00004671 SetRect(&rc, 0, 0, width, height);
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004672 EDIT_SetRectNP(es, &rc);
4673 EDIT_UpdateText(es, NULL, TRUE);
Alexandre Julliardcdcdede1996-04-21 14:57:41 +00004674 }
Alexandre Julliard329f0681996-04-14 13:21:20 +00004675}
4676
4677
4678/*********************************************************************
4679 *
Bill Medland86bfa4c2001-06-28 18:01:00 +00004680 * WM_STYLECHANGED
4681 *
4682 * This message is sent by SetWindowLong on having changed either the Style
4683 * or the extended style.
4684 *
4685 * We ensure that the window's version of the styles and the EDITSTATE's agree.
4686 *
4687 * See also EDIT_WM_NCCreate
4688 *
4689 * It appears that the Windows version of the edit control allows the style
4690 * (as retrieved by GetWindowLong) to be any value and maintains an internal
Vincent Béron9a624912002-05-31 23:06:46 +00004691 * style variable which will generally be different. In this function we
Bill Medland86bfa4c2001-06-28 18:01:00 +00004692 * update the internal style based on what changed in the externally visible
4693 * style.
4694 *
4695 * Much of this content as based upon the MSDN, especially:
4696 * Platform SDK Documentation -> User Interface Services ->
4697 * Windows User Interface -> Edit Controls -> Edit Control Reference ->
4698 * Edit Control Styles
4699 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004700static LRESULT EDIT_WM_StyleChanged ( EDITSTATE *es, WPARAM which, const STYLESTRUCT *style)
Bill Medland86bfa4c2001-06-28 18:01:00 +00004701{
4702 if (GWL_STYLE == which) {
4703 DWORD style_change_mask;
4704 DWORD new_style;
4705 /* Only a subset of changes can be applied after the control
4706 * has been created.
4707 */
4708 style_change_mask = ES_UPPERCASE | ES_LOWERCASE |
4709 ES_NUMBER;
Vincent Béron9a624912002-05-31 23:06:46 +00004710 if (es->style & ES_MULTILINE)
Bill Medland86bfa4c2001-06-28 18:01:00 +00004711 style_change_mask |= ES_WANTRETURN;
4712
4713 new_style = style->styleNew & style_change_mask;
4714
4715 /* Number overrides lowercase overrides uppercase (at least it
4716 * does in Win95). However I'll bet that ES_NUMBER would be
4717 * invalid under Win 3.1.
4718 */
4719 if (new_style & ES_NUMBER) {
4720 ; /* do not override the ES_NUMBER */
4721 } else if (new_style & ES_LOWERCASE) {
4722 new_style &= ~ES_UPPERCASE;
4723 }
Vincent Béron9a624912002-05-31 23:06:46 +00004724
Bill Medland86bfa4c2001-06-28 18:01:00 +00004725 es->style = (es->style & ~style_change_mask) | new_style;
4726 } else if (GWL_EXSTYLE == which) {
4727 ; /* FIXME - what is needed here */
4728 } else {
4729 WARN ("Invalid style change %d\n",which);
4730 }
4731
4732 return 0;
4733}
4734
4735/*********************************************************************
4736 *
Alexandre Julliard01d63461997-01-20 19:43:45 +00004737 * WM_SYSKEYDOWN
4738 *
4739 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004740static LRESULT EDIT_WM_SysKeyDown(EDITSTATE *es, INT key, DWORD key_data)
Alexandre Julliard01d63461997-01-20 19:43:45 +00004741{
Alexandre Julliard889f7421997-04-15 17:19:52 +00004742 if ((key == VK_BACK) && (key_data & 0x2000)) {
Dmitry Timoshkov7a947b32000-11-27 01:34:25 +00004743 if (EDIT_EM_CanUndo(es))
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004744 EDIT_EM_Undo(es);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004745 return 0;
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004746 } else if (key == VK_UP || key == VK_DOWN) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004747 if (EDIT_CheckCombo(es, WM_SYSKEYDOWN, key))
Alexandre Julliard889f7421997-04-15 17:19:52 +00004748 return 0;
Serge Ivanov9eedcf52000-06-07 03:47:34 +00004749 }
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004750 return DefWindowProcW(es->hwndSelf, WM_SYSKEYDOWN, (WPARAM)key, (LPARAM)key_data);
Alexandre Julliard01d63461997-01-20 19:43:45 +00004751}
4752
4753
4754/*********************************************************************
4755 *
4756 * WM_TIMER
4757 *
4758 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004759static void EDIT_WM_Timer(EDITSTATE *es)
Alexandre Julliard01d63461997-01-20 19:43:45 +00004760{
Alexandre Julliarde658d821997-11-30 17:45:40 +00004761 if (es->region_posx < 0) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004762 EDIT_MoveBackward(es, TRUE);
Alexandre Julliarde658d821997-11-30 17:45:40 +00004763 } else if (es->region_posx > 0) {
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004764 EDIT_MoveForward(es, TRUE);
Alexandre Julliarde658d821997-11-30 17:45:40 +00004765 }
Alexandre Julliard01d63461997-01-20 19:43:45 +00004766/*
Alexandre Julliarde658d821997-11-30 17:45:40 +00004767 * FIXME: gotta do some vertical scrolling here, like
Alexandre Julliardde424282001-08-10 22:51:42 +00004768 * EDIT_EM_LineScroll(hwnd, 0, 1);
Alexandre Julliard01d63461997-01-20 19:43:45 +00004769 */
Alexandre Julliard889f7421997-04-15 17:19:52 +00004770}
4771
Alexandre Julliard01d63461997-01-20 19:43:45 +00004772/*********************************************************************
4773 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004774 * WM_VSCROLL
4775 *
Alexandre Julliard329f0681996-04-14 13:21:20 +00004776 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004777static LRESULT EDIT_WM_VScroll(EDITSTATE *es, INT action, INT pos)
Alexandre Julliard329f0681996-04-14 13:21:20 +00004778{
Alexandre Julliarda3960291999-02-26 11:11:13 +00004779 INT dy;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004780
Alexandre Julliard889f7421997-04-15 17:19:52 +00004781 if (!(es->style & ES_MULTILINE))
4782 return 0;
4783
4784 if (!(es->style & ES_AUTOVSCROLL))
4785 return 0;
4786
Alexandre Julliard889f7421997-04-15 17:19:52 +00004787 dy = 0;
4788 switch (action) {
Alexandre Julliard329f0681996-04-14 13:21:20 +00004789 case SB_LINEUP:
Alexandre Julliard329f0681996-04-14 13:21:20 +00004790 case SB_LINEDOWN:
Alexandre Julliard329f0681996-04-14 13:21:20 +00004791 case SB_PAGEUP:
Alexandre Julliard329f0681996-04-14 13:21:20 +00004792 case SB_PAGEDOWN:
Lionel Ulmer28d9aaf2004-03-29 22:54:05 +00004793 TRACE("action %d (%s)\n", action, (action == SB_LINEUP ? "SB_LINEUP" :
4794 (action == SB_LINEDOWN ? "SB_LINEDOWN" :
4795 (action == SB_PAGEUP ? "SB_PAGEUP" :
4796 "SB_PAGEDOWN"))));
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004797 EDIT_EM_Scroll(es, action);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004798 return 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004799 case SB_TOP:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004800 TRACE("SB_TOP\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00004801 dy = -es->y_offset;
4802 break;
4803 case SB_BOTTOM:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004804 TRACE("SB_BOTTOM\n");
Alexandre Julliard889f7421997-04-15 17:19:52 +00004805 dy = es->line_count - 1 - es->y_offset;
4806 break;
4807 case SB_THUMBTRACK:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004808 TRACE("SB_THUMBTRACK %d\n", pos);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004809 es->flags |= EF_VSCROLL_TRACK;
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004810 if(es->style & WS_VSCROLL)
4811 dy = pos - es->y_offset;
4812 else
4813 {
4814 /* Assume default scroll range 0-100 */
4815 INT vlc, new_y;
4816 /* Sanity check */
4817 if(pos < 0 || pos > 100) return 0;
4818 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4819 new_y = pos * (es->line_count - vlc) / 100;
4820 dy = es->line_count ? (new_y - es->y_offset) : 0;
4821 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4822 es->line_count, es->y_offset, pos, dy);
4823 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00004824 break;
4825 case SB_THUMBPOSITION:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004826 TRACE("SB_THUMBPOSITION %d\n", pos);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004827 es->flags &= ~EF_VSCROLL_TRACK;
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004828 if(es->style & WS_VSCROLL)
4829 dy = pos - es->y_offset;
4830 else
4831 {
4832 /* Assume default scroll range 0-100 */
4833 INT vlc, new_y;
4834 /* Sanity check */
4835 if(pos < 0 || pos > 100) return 0;
4836 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4837 new_y = pos * (es->line_count - vlc) / 100;
4838 dy = es->line_count ? (new_y - es->y_offset) : 0;
4839 TRACE("line_count=%d, y_offset=%d, pos=%d, dy = %d\n",
4840 es->line_count, es->y_offset, pos, dy);
4841 }
4842 if (!dy)
4843 {
4844 /* force scroll info update */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004845 EDIT_UpdateScrollInfo(es);
4846 EDIT_NOTIFY_PARENT(es, EN_VSCROLL, "EN_VSCROLL");
Alexandre Julliard889f7421997-04-15 17:19:52 +00004847 }
4848 break;
4849 case SB_ENDSCROLL:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004850 TRACE("SB_ENDSCROLL\n");
4851 break;
4852 /*
4853 * FIXME : the next two are undocumented !
4854 * Are we doing the right thing ?
4855 * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way,
4856 * although it's also a regular control message.
4857 */
4858 case EM_GETTHUMB: /* this one is used by NT notepad */
4859 case EM_GETTHUMB16:
4860 {
4861 LRESULT ret;
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004862 if(GetWindowLongW( es->hwndSelf, GWL_STYLE ) & WS_VSCROLL)
4863 ret = GetScrollPos(es->hwndSelf, SB_VERT);
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004864 else
4865 {
4866 /* Assume default scroll range 0-100 */
4867 INT vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height;
4868 ret = es->line_count ? es->y_offset * 100 / (es->line_count - vlc) : 0;
4869 }
4870 TRACE("EM_GETTHUMB: returning %ld\n", ret);
4871 return ret;
4872 }
4873 case EM_LINESCROLL16:
4874 TRACE("EM_LINESCROLL16 %d\n", pos);
4875 dy = pos;
Alexandre Julliard889f7421997-04-15 17:19:52 +00004876 break;
4877
Alexandre Julliard329f0681996-04-14 13:21:20 +00004878 default:
Dmitry Timoshkova234db82001-01-19 20:49:54 +00004879 ERR("undocumented WM_VSCROLL action %d (0x%04x), please report\n",
4880 action, action);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004881 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004882 }
Alexandre Julliard889f7421997-04-15 17:19:52 +00004883 if (dy)
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004884 EDIT_EM_LineScroll(es, 0, dy);
Alexandre Julliard889f7421997-04-15 17:19:52 +00004885 return 0;
Alexandre Julliard329f0681996-04-14 13:21:20 +00004886}
Ulrich Czekalla70d5a952000-05-26 01:17:34 +00004887
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00004888/*********************************************************************
4889 *
4890 * EDIT_UpdateText
4891 *
4892 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004893static void EDIT_UpdateTextRegion(EDITSTATE *es, HRGN hrgn, BOOL bErase)
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00004894{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004895 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4896 InvalidateRgn(es->hwndSelf, hrgn, bErase);
Ulrich Czekallaf11ff2a2001-03-31 00:51:10 +00004897}
4898
Ulrich Czekalla70d5a952000-05-26 01:17:34 +00004899
4900/*********************************************************************
4901 *
4902 * EDIT_UpdateText
4903 *
4904 */
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004905static void EDIT_UpdateText(EDITSTATE *es, LPRECT rc, BOOL bErase)
Ulrich Czekalla70d5a952000-05-26 01:17:34 +00004906{
Dimitrie O. Pauna4273ca2002-09-25 03:24:53 +00004907 if (es->flags & EF_UPDATE) EDIT_NOTIFY_PARENT(es, EN_UPDATE, "EN_UPDATE");
4908 InvalidateRect(es->hwndSelf, rc, bErase);
Ulrich Czekalla70d5a952000-05-26 01:17:34 +00004909}