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