Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1 | /* |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2 | * Edit control |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 3 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 4 | * Copyright David W. Metcalfe, 1994 |
| 5 | * Copyright William Magro, 1995, 1996 |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 6 | * Copyright Frans van Dorsselaer, 1996, 1997 |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 7 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /* |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 11 | * please read EDIT.TODO (and update it when you change things) |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 12 | */ |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 13 | |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 14 | #include <stdio.h> |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 15 | #include "windows.h" |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 16 | #include "winnt.h" |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 17 | #include "win.h" |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 18 | #include "combo.h" |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 19 | #include "local.h" |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 20 | #include "resource.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 21 | #include "stddebug.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 22 | #include "debug.h" |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 23 | #include "callback.h" |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 24 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 25 | #define BUFLIMIT_MULTI 65534 /* maximum buffer size (not including '\0') |
| 26 | FIXME: BTW, new specs say 65535 (do you dare ???) */ |
| 27 | #define BUFLIMIT_SINGLE 32766 /* maximum buffer size (not including '\0') */ |
| 28 | #define BUFSTART_MULTI 1024 /* starting size */ |
| 29 | #define BUFSTART_SINGLE 256 /* starting size */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 30 | #define GROWLENGTH 64 /* buffers grow by this much */ |
| 31 | #define HSCROLL_FRACTION 3 /* scroll window by 1/3 width */ |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 32 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 33 | /* |
| 34 | * extra flags for EDITSTATE.flags field |
| 35 | */ |
| 36 | #define EF_MODIFIED 0x0001 /* text has been modified */ |
| 37 | #define EF_FOCUSED 0x0002 /* we have input focus */ |
| 38 | #define EF_UPDATE 0x0004 /* notify parent of changed state on next WM_PAINT */ |
| 39 | #define EF_VSCROLL_TRACK 0x0008 /* don't SetScrollPos() since we are tracking the thumb */ |
| 40 | #define EF_HSCROLL_TRACK 0x0010 /* don't SetScrollPos() since we are tracking the thumb */ |
| 41 | #define EF_VSCROLL_HACK 0x0020 /* we already have informed the user of the hacked handler */ |
| 42 | #define EF_HSCROLL_HACK 0x0040 /* we already have informed the user of the hacked handler */ |
| 43 | #define EF_AFTER_WRAP 0x0080 /* the caret is displayed after the last character of a |
| 44 | wrapped line, instead of in front of the next character */ |
| 45 | |
| 46 | typedef BOOL32 *LPBOOL32; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 47 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 48 | typedef enum |
| 49 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 50 | END_0 = 0, /* line ends with terminating '\0' character */ |
| 51 | END_WRAP, /* line is wrapped */ |
| 52 | END_HARD, /* line ends with a hard return '\r\n' */ |
| 53 | END_SOFT, /* line ends with a soft return '\r\r\n' */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 54 | } LINE_END; |
| 55 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 56 | typedef struct tagLINEDEF { |
| 57 | INT32 length; /* bruto length of a line in bytes */ |
| 58 | INT32 net_length; /* netto length of a line in visible characters */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 59 | LINE_END ending; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 60 | INT32 width; /* width of the line in pixels */ |
| 61 | struct tagLINEDEF *next; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 62 | } LINEDEF; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 63 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 64 | typedef struct |
| 65 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 66 | HANDLE32 heap; /* our own heap */ |
| 67 | LPSTR text; /* the actual contents of the control */ |
| 68 | INT32 buffer_size; /* the size of the buffer */ |
| 69 | INT32 buffer_limit; /* the maximum size to which the buffer may grow */ |
| 70 | HFONT32 font; /* NULL means standard system font */ |
| 71 | INT32 x_offset; /* scroll offset for multi lines this is in pixels |
| 72 | for single lines it's in characters */ |
| 73 | INT32 line_height; /* height of a screen line in pixels */ |
| 74 | INT32 char_width; /* average character width in pixels */ |
| 75 | DWORD style; /* sane version of wnd->dwStyle */ |
| 76 | WORD flags; /* flags that are not in es->style or wnd->flags (EF_XXX) */ |
| 77 | INT32 undo_insert_count; /* number of characters inserted in sequence */ |
| 78 | INT32 undo_position; /* character index of the insertion and deletion */ |
| 79 | LPSTR undo_text; /* deleted text */ |
| 80 | INT32 undo_buffer_size; /* size of the deleted text buffer */ |
| 81 | INT32 selection_start; /* == selection_end if no selection */ |
| 82 | INT32 selection_end; /* == current caret position */ |
| 83 | CHAR password_char; /* == 0 if no password char, and for multi line controls */ |
| 84 | INT32 left_margin; /* in pixels */ |
| 85 | INT32 right_margin; /* in pixels */ |
| 86 | RECT32 format_rect; |
| 87 | EDITWORDBREAKPROC16 word_break_proc16; |
| 88 | EDITWORDBREAKPROC32A word_break_proc32A; |
| 89 | INT32 line_count; /* number of lines */ |
| 90 | INT32 y_offset; /* scroll offset in number of lines */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 91 | /* |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 92 | * only for multi line controls |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 93 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 94 | INT32 lock_count; /* amount of re-entries in the EditWndProc */ |
| 95 | INT32 tabs_count; |
| 96 | LPINT32 tabs; |
| 97 | INT32 text_width; /* width of the widest line in pixels */ |
| 98 | LINEDEF *first_line_def; /* linked list of (soft) linebreaks */ |
| 99 | HLOCAL16 hloc16; /* for controls receiving EM_GETHANDLE16 */ |
| 100 | HLOCAL32 hloc32; /* for controls receiving EM_GETHANDLE */ |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 101 | } EDITSTATE; |
| 102 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 103 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 104 | #define SWAP_INT32(x,y) do { INT32 temp = (INT32)(x); (x) = (INT32)(y); (y) = temp; } while(0) |
| 105 | #define ORDER_INT32(x,y) do { if ((INT32)(y) < (INT32)(x)) SWAP_INT32((x),(y)); } while(0) |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 106 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 107 | #define SWAP_UINT32(x,y) do { UINT32 temp = (UINT32)(x); (x) = (UINT32)(y); (y) = temp; } while(0) |
| 108 | #define ORDER_UINT32(x,y) do { if ((UINT32)(y) < (UINT32)(x)) SWAP_UINT32((x),(y)); } while(0) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 109 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 110 | #define DPRINTF_EDIT_NOTIFY(hwnd, str) \ |
| 111 | ({dprintf_edit(stddeb, \ |
| 112 | "edit: notification " str " sent to hwnd=%08x\n", \ |
| 113 | (UINT32)(hwnd));}) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 114 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 115 | #define EDIT_SEND_CTLCOLOR(wnd,hdc) \ |
| 116 | (SendMessage32A((wnd)->parent->hwndSelf, WM_CTLCOLOREDIT, \ |
| 117 | (WPARAM32)(hdc), (LPARAM)(wnd)->hwndSelf)) |
| 118 | #define EDIT_NOTIFY_PARENT(wnd, wNotifyCode, str) \ |
| 119 | (DPRINTF_EDIT_NOTIFY((wnd)->parent->hwndSelf, str), \ |
| 120 | SendMessage32A((wnd)->parent->hwndSelf, WM_COMMAND, \ |
| 121 | MAKEWPARAM((wnd)->wIDmenu, wNotifyCode), \ |
| 122 | (LPARAM)(wnd)->hwndSelf)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 123 | #define DPRINTF_EDIT_MSG16(str) \ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 124 | dprintf_edit(stddeb, \ |
| 125 | "edit: 16 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \ |
| 126 | (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 127 | #define DPRINTF_EDIT_MSG32(str) \ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 128 | dprintf_edit(stddeb, \ |
| 129 | "edit: 32 bit : " str ": hwnd=%08x, wParam=%08x, lParam=%08x\n", \ |
| 130 | (UINT32)hwnd, (UINT32)wParam, (UINT32)lParam) |
| 131 | |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 132 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 133 | /********************************************************************* |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 134 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 135 | * Declarations |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 136 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 137 | */ |
| 138 | |
| 139 | /* |
| 140 | * These functions have trivial implementations |
| 141 | * We still like to call them internally |
| 142 | * "static __inline__" makes them more like macro's |
| 143 | */ |
| 144 | static __inline__ BOOL32 EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es); |
| 145 | static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es); |
| 146 | static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es); |
| 147 | static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es); |
| 148 | /* |
| 149 | * This is the only exported function |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 150 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame^] | 151 | LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg, |
| 152 | WPARAM32 wParam, LPARAM lParam ); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 153 | /* |
| 154 | * Helper functions only valid for one type of control |
| 155 | */ |
| 156 | static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es); |
| 157 | static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es); |
| 158 | static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 159 | static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 160 | static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 161 | static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 162 | /* |
| 163 | * Helper functions valid for both single line _and_ multi line controls |
| 164 | */ |
| 165 | static INT32 EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT32 start, INT32 index, INT32 count, INT32 action); |
| 166 | static INT32 EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y, LPBOOL32 after_wrap); |
| 167 | static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT32 x, LPINT32 y); |
| 168 | static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT32 line, INT32 scol, INT32 ecol, LPRECT32 rc); |
| 169 | static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end); |
| 170 | static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es); |
| 171 | static BOOL32 EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT32 size); |
| 172 | static BOOL32 EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT32 size); |
| 173 | static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 174 | static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 175 | static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 176 | static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 177 | static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 178 | static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL32 extend); |
| 179 | static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC32 hdc, INT32 line, BOOL32 rev); |
| 180 | static INT32 EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC32 hdc, INT32 x, INT32 y, INT32 line, INT32 col, INT32 count, BOOL32 rev); |
| 181 | static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT32 lprc); |
| 182 | static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL32 force); |
| 183 | static INT32 EDIT_WordBreakProc(LPSTR s, INT32 index, INT32 count, INT32 action); |
| 184 | /* |
| 185 | * EM_XXX message handlers |
| 186 | */ |
| 187 | static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y); |
| 188 | static BOOL32 EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL32 add_eol); |
| 189 | static HLOCAL32 EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es); |
| 190 | static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es); |
| 191 | static INT32 EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT32 line, LPSTR lpch); |
| 192 | static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT32 start, LPUINT32 end); |
| 193 | static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es); |
| 194 | static INT32 EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT32 index); |
| 195 | static INT32 EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT32 line); |
| 196 | static INT32 EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT32 index); |
| 197 | static BOOL32 EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT32 dx, INT32 dy); |
| 198 | static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT32 index, BOOL32 after_wrap); |
| 199 | static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL32 can_undo, LPCSTR lpsz_replace); |
| 200 | static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT32 action); |
| 201 | static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es); |
| 202 | static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL32 hloc); |
| 203 | static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc); |
| 204 | static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT32 limit); |
| 205 | static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT32 action, INT32 left, INT32 right); |
| 206 | static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c); |
| 207 | static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT32 start, UINT32 end, BOOL32 after_wrap); |
| 208 | static BOOL32 EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT32 count, LPINT32 tabs); |
| 209 | static BOOL32 EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT32 count, LPINT16 tabs); |
| 210 | static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC32A wbp); |
| 211 | static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp); |
| 212 | static BOOL32 EDIT_EM_Undo(WND *wnd, EDITSTATE *es); |
| 213 | /* |
| 214 | * WM_XXX message handlers |
| 215 | */ |
| 216 | static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data); |
| 217 | static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT32 code, INT32 id, HWND32 conrtol); |
| 218 | static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND32 hwnd, INT32 x, INT32 y); |
| 219 | static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es); |
| 220 | static LRESULT EDIT_WM_Create(WND *wnd, LPCREATESTRUCT32A cs); |
| 221 | static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es); |
| 222 | static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC32 dc); |
| 223 | static INT32 EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT32 count, LPSTR text); |
| 224 | static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar); |
| 225 | static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data); |
| 226 | static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND32 window_getting_focus); |
| 227 | static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y); |
| 228 | static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y); |
| 229 | static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y); |
| 230 | static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y); |
| 231 | static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es); |
| 232 | static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es); |
| 233 | static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND32 window_losing_focus); |
| 234 | static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT32 font, BOOL32 redraw); |
| 235 | static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text); |
| 236 | static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT32 action, INT32 width, INT32 height); |
| 237 | static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data); |
| 238 | static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT32 id, TIMERPROC32 timer_proc); |
| 239 | static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar); |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 240 | |
| 241 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 242 | /********************************************************************* |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 243 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 244 | * EM_CANUNDO |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 245 | * |
| 246 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 247 | static __inline__ BOOL32 EDIT_EM_CanUndo(WND *wnd, EDITSTATE *es) |
| 248 | { |
| 249 | return (es->undo_insert_count || lstrlen32A(es->undo_text)); |
| 250 | } |
| 251 | |
| 252 | |
| 253 | /********************************************************************* |
| 254 | * |
| 255 | * EM_EMPTYUNDOBUFFER |
| 256 | * |
| 257 | */ |
| 258 | static __inline__ void EDIT_EM_EmptyUndoBuffer(WND *wnd, EDITSTATE *es) |
| 259 | { |
| 260 | es->undo_insert_count = 0; |
| 261 | *es->undo_text = '\0'; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | /********************************************************************* |
| 266 | * |
| 267 | * WM_CLEAR |
| 268 | * |
| 269 | */ |
| 270 | static __inline__ void EDIT_WM_Clear(WND *wnd, EDITSTATE *es) |
| 271 | { |
| 272 | EDIT_EM_ReplaceSel(wnd, es, TRUE, ""); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | /********************************************************************* |
| 277 | * |
| 278 | * WM_CUT |
| 279 | * |
| 280 | */ |
| 281 | static __inline__ void EDIT_WM_Cut(WND *wnd, EDITSTATE *es) |
| 282 | { |
| 283 | EDIT_WM_Copy(wnd, es); |
| 284 | EDIT_WM_Clear(wnd, es); |
| 285 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 286 | |
| 287 | |
| 288 | /********************************************************************* |
| 289 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 290 | * EditWndProc() |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 291 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 292 | * The messages are in the order of the actual integer values |
| 293 | * (which can be found in include/windows.h) |
| 294 | * Whereever possible the 16 bit versions are converted to |
| 295 | * the 32 bit ones, so that we can 'fall through' to the |
| 296 | * helper functions. These are mostly 32 bit (with a few |
| 297 | * exceptions, clearly indicated by a '16' extension to their |
| 298 | * names). |
| 299 | * |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 300 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame^] | 301 | LRESULT WINAPI EditWndProc( HWND32 hwnd, UINT32 msg, |
| 302 | WPARAM32 wParam, LPARAM lParam ) |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 303 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 304 | WND *wnd = WIN_FindWndPtr(hwnd); |
| 305 | EDITSTATE *es = *(EDITSTATE **)((wnd)->wExtra); |
| 306 | LRESULT result = 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 307 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 308 | switch (msg) { |
| 309 | case WM_CREATE: |
| 310 | DPRINTF_EDIT_MSG32("WM_CREATE"); |
| 311 | return EDIT_WM_Create(wnd, (LPCREATESTRUCT32A)lParam); |
| 312 | |
| 313 | case WM_DESTROY: |
| 314 | DPRINTF_EDIT_MSG32("WM_DESTROY"); |
| 315 | EDIT_WM_Destroy(wnd, es); |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | if (!es) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 320 | return DefWindowProc32A(hwnd, msg, wParam, lParam); |
Alexandre Julliard | bf9130a | 1996-10-13 17:45:47 +0000 | [diff] [blame] | 321 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 322 | EDIT_LockBuffer(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 323 | switch (msg) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 324 | case EM_GETSEL16: |
| 325 | DPRINTF_EDIT_MSG16("EM_GETSEL"); |
| 326 | wParam = 0; |
| 327 | lParam = 0; |
| 328 | /* fall through */ |
| 329 | case EM_GETSEL32: |
| 330 | DPRINTF_EDIT_MSG32("EM_GETSEL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 331 | result = EDIT_EM_GetSel(wnd, es, (LPUINT32)wParam, (LPUINT32)lParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 332 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 333 | |
| 334 | case EM_SETSEL16: |
| 335 | DPRINTF_EDIT_MSG16("EM_SETSEL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 336 | if (SLOWORD(lParam) == -1) |
| 337 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 338 | else |
| 339 | EDIT_EM_SetSel(wnd, es, LOWORD(lParam), HIWORD(lParam), FALSE); |
| 340 | if (!wParam) |
| 341 | EDIT_EM_ScrollCaret(wnd, es); |
| 342 | result = 1; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 343 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 344 | case EM_SETSEL32: |
| 345 | DPRINTF_EDIT_MSG32("EM_SETSEL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 346 | EDIT_EM_SetSel(wnd, es, wParam, lParam, FALSE); |
| 347 | result = 1; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 348 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 349 | |
| 350 | case EM_GETRECT16: |
| 351 | DPRINTF_EDIT_MSG16("EM_GETRECT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 352 | if (lParam) |
| 353 | CONV_RECT32TO16(&es->format_rect, (LPRECT16)PTR_SEG_TO_LIN(lParam)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 354 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 355 | case EM_GETRECT32: |
| 356 | DPRINTF_EDIT_MSG32("EM_GETRECT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 357 | if (lParam) |
| 358 | CopyRect32((LPRECT32)lParam, &es->format_rect); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 359 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 360 | |
| 361 | case EM_SETRECT16: |
| 362 | DPRINTF_EDIT_MSG16("EM_SETRECT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 363 | if ((es->style & ES_MULTILINE) && lParam) { |
| 364 | RECT32 rc; |
| 365 | CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc); |
| 366 | EDIT_SetRectNP(wnd, es, &rc); |
| 367 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 368 | } |
| 369 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 370 | case EM_SETRECT32: |
| 371 | DPRINTF_EDIT_MSG32("EM_SETRECT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 372 | if ((es->style & ES_MULTILINE) && lParam) { |
| 373 | EDIT_SetRectNP(wnd, es, (LPRECT32)lParam); |
| 374 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 375 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 376 | break; |
| 377 | |
| 378 | case EM_SETRECTNP16: |
| 379 | DPRINTF_EDIT_MSG16("EM_SETRECTNP"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 380 | if ((es->style & ES_MULTILINE) && lParam) { |
| 381 | RECT32 rc; |
| 382 | CONV_RECT16TO32((LPRECT16)PTR_SEG_TO_LIN(lParam), &rc); |
| 383 | EDIT_SetRectNP(wnd, es, &rc); |
| 384 | } |
| 385 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 386 | case EM_SETRECTNP32: |
| 387 | DPRINTF_EDIT_MSG32("EM_SETRECTNP"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 388 | if ((es->style & ES_MULTILINE) && lParam) |
| 389 | EDIT_SetRectNP(wnd, es, (LPRECT32)lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 390 | break; |
| 391 | |
| 392 | case EM_SCROLL16: |
| 393 | DPRINTF_EDIT_MSG16("EM_SCROLL"); |
| 394 | /* fall through */ |
| 395 | case EM_SCROLL32: |
| 396 | DPRINTF_EDIT_MSG32("EM_SCROLL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 397 | result = EDIT_EM_Scroll(wnd, es, (INT32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 398 | break; |
| 399 | |
| 400 | case EM_LINESCROLL16: |
| 401 | DPRINTF_EDIT_MSG16("EM_LINESCROLL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 402 | wParam = (WPARAM32)(INT32)SHIWORD(lParam); |
| 403 | lParam = (LPARAM)(INT32)SLOWORD(lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 404 | /* fall through */ |
| 405 | case EM_LINESCROLL32: |
| 406 | DPRINTF_EDIT_MSG32("EM_LINESCROLL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 407 | result = (LRESULT)EDIT_EM_LineScroll(wnd, es, (INT32)wParam, (INT32)lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 408 | break; |
| 409 | |
| 410 | case EM_SCROLLCARET16: |
| 411 | DPRINTF_EDIT_MSG16("EM_SCROLLCARET"); |
| 412 | /* fall through */ |
| 413 | case EM_SCROLLCARET32: |
| 414 | DPRINTF_EDIT_MSG32("EM_SCROLLCARET"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 415 | EDIT_EM_ScrollCaret(wnd, es); |
| 416 | result = 1; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 417 | break; |
| 418 | |
| 419 | case EM_GETMODIFY16: |
| 420 | DPRINTF_EDIT_MSG16("EM_GETMODIFY"); |
| 421 | /* fall through */ |
| 422 | case EM_GETMODIFY32: |
| 423 | DPRINTF_EDIT_MSG32("EM_GETMODIFY"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 424 | return ((es->flags & EF_MODIFIED) != 0); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 425 | break; |
| 426 | |
| 427 | case EM_SETMODIFY16: |
| 428 | DPRINTF_EDIT_MSG16("EM_SETMODIFY"); |
| 429 | /* fall through */ |
| 430 | case EM_SETMODIFY32: |
| 431 | DPRINTF_EDIT_MSG32("EM_SETMODIFY"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 432 | if (wParam) |
| 433 | es->flags |= EF_MODIFIED; |
| 434 | else |
| 435 | es->flags &= ~EF_MODIFIED; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 436 | break; |
| 437 | |
| 438 | case EM_GETLINECOUNT16: |
| 439 | DPRINTF_EDIT_MSG16("EM_GETLINECOUNT"); |
| 440 | /* fall through */ |
| 441 | case EM_GETLINECOUNT32: |
| 442 | DPRINTF_EDIT_MSG32("EM_GETLINECOUNT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 443 | result = (es->style & ES_MULTILINE) ? es->line_count : 1; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 444 | break; |
| 445 | |
| 446 | case EM_LINEINDEX16: |
| 447 | DPRINTF_EDIT_MSG16("EM_LINEINDEX"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 448 | if ((INT16)wParam == -1) |
| 449 | wParam = (WPARAM32)-1; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 450 | /* fall through */ |
| 451 | case EM_LINEINDEX32: |
| 452 | DPRINTF_EDIT_MSG32("EM_LINEINDEX"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 453 | result = (LRESULT)EDIT_EM_LineIndex(wnd, es, (INT32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 454 | break; |
| 455 | |
| 456 | case EM_SETHANDLE16: |
| 457 | DPRINTF_EDIT_MSG16("EM_SETHANDLE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 458 | EDIT_EM_SetHandle16(wnd, es, (HLOCAL16)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 459 | break; |
| 460 | case EM_SETHANDLE32: |
| 461 | DPRINTF_EDIT_MSG32("EM_SETHANDLE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 462 | EDIT_EM_SetHandle(wnd, es, (HLOCAL32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 463 | break; |
| 464 | |
| 465 | case EM_GETHANDLE16: |
| 466 | DPRINTF_EDIT_MSG16("EM_GETHANDLE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 467 | result = (LRESULT)EDIT_EM_GetHandle16(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 468 | break; |
| 469 | case EM_GETHANDLE32: |
| 470 | DPRINTF_EDIT_MSG32("EM_GETHANDLE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 471 | result = (LRESULT)EDIT_EM_GetHandle(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 472 | break; |
| 473 | |
| 474 | case EM_GETTHUMB16: |
| 475 | DPRINTF_EDIT_MSG16("EM_GETTHUMB"); |
| 476 | /* fall through */ |
| 477 | case EM_GETTHUMB32: |
| 478 | DPRINTF_EDIT_MSG32("EM_GETTHUMB"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 479 | result = EDIT_EM_GetThumb(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 480 | break; |
| 481 | |
| 482 | /* messages 0x00bf and 0x00c0 missing from specs */ |
| 483 | |
| 484 | case WM_USER+15: |
| 485 | DPRINTF_EDIT_MSG16("undocumented WM_USER+15, please report"); |
| 486 | /* fall through */ |
| 487 | case 0x00bf: |
| 488 | DPRINTF_EDIT_MSG32("undocumented 0x00bf, please report"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 489 | result = DefWindowProc32A(hwnd, msg, wParam, lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 490 | break; |
| 491 | |
| 492 | case WM_USER+16: |
| 493 | DPRINTF_EDIT_MSG16("undocumented WM_USER+16, please report"); |
| 494 | /* fall through */ |
| 495 | case 0x00c0: |
| 496 | DPRINTF_EDIT_MSG32("undocumented 0x00c0, please report"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 497 | result = DefWindowProc32A(hwnd, msg, wParam, lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 498 | break; |
| 499 | |
| 500 | case EM_LINELENGTH16: |
| 501 | DPRINTF_EDIT_MSG16("EM_LINELENGTH"); |
| 502 | /* fall through */ |
| 503 | case EM_LINELENGTH32: |
| 504 | DPRINTF_EDIT_MSG32("EM_LINELENGTH"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 505 | result = (LRESULT)EDIT_EM_LineLength(wnd, es, (INT32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 506 | break; |
| 507 | |
| 508 | case EM_REPLACESEL16: |
| 509 | DPRINTF_EDIT_MSG16("EM_REPLACESEL"); |
| 510 | lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam); |
| 511 | /* fall through */ |
| 512 | case EM_REPLACESEL32: |
| 513 | DPRINTF_EDIT_MSG32("EM_REPLACESEL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 514 | EDIT_EM_ReplaceSel(wnd, es, (BOOL32)wParam, (LPCSTR)lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 515 | break; |
| 516 | |
| 517 | /* message 0x00c3 missing from specs */ |
| 518 | |
| 519 | case WM_USER+19: |
| 520 | DPRINTF_EDIT_MSG16("undocumented WM_USER+19, please report"); |
| 521 | /* fall through */ |
| 522 | case 0x00c3: |
| 523 | DPRINTF_EDIT_MSG32("undocumented 0x00c3, please report"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 524 | result = DefWindowProc32A(hwnd, msg, wParam, lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 525 | break; |
| 526 | |
| 527 | case EM_GETLINE16: |
| 528 | DPRINTF_EDIT_MSG16("EM_GETLINE"); |
| 529 | lParam = (LPARAM)PTR_SEG_TO_LIN((SEGPTR)lParam); |
| 530 | /* fall through */ |
| 531 | case EM_GETLINE32: |
| 532 | DPRINTF_EDIT_MSG32("EM_GETLINE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 533 | result = (LRESULT)EDIT_EM_GetLine(wnd, es, (INT32)wParam, (LPSTR)lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 534 | break; |
| 535 | |
| 536 | case EM_LIMITTEXT16: |
| 537 | DPRINTF_EDIT_MSG16("EM_LIMITTEXT"); |
| 538 | /* fall through */ |
| 539 | case EM_SETLIMITTEXT32: |
| 540 | DPRINTF_EDIT_MSG32("EM_SETLIMITTEXT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 541 | EDIT_EM_SetLimitText(wnd, es, (INT32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 542 | break; |
| 543 | |
| 544 | case EM_CANUNDO16: |
| 545 | DPRINTF_EDIT_MSG16("EM_CANUNDO"); |
| 546 | /* fall through */ |
| 547 | case EM_CANUNDO32: |
| 548 | DPRINTF_EDIT_MSG32("EM_CANUNDO"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 549 | result = (LRESULT)EDIT_EM_CanUndo(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 550 | break; |
| 551 | |
| 552 | case EM_UNDO16: |
| 553 | DPRINTF_EDIT_MSG16("EM_UNDO"); |
| 554 | /* fall through */ |
| 555 | case EM_UNDO32: |
| 556 | /* fall through */ |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 557 | case WM_UNDO: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 558 | DPRINTF_EDIT_MSG32("EM_UNDO / WM_UNDO"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 559 | result = (LRESULT)EDIT_EM_Undo(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 560 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 561 | |
| 562 | case EM_FMTLINES16: |
| 563 | DPRINTF_EDIT_MSG16("EM_FMTLINES"); |
| 564 | /* fall through */ |
| 565 | case EM_FMTLINES32: |
| 566 | DPRINTF_EDIT_MSG32("EM_FMTLINES"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 567 | result = (LRESULT)EDIT_EM_FmtLines(wnd, es, (BOOL32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 568 | break; |
| 569 | |
| 570 | case EM_LINEFROMCHAR16: |
| 571 | DPRINTF_EDIT_MSG16("EM_LINEFROMCHAR"); |
| 572 | /* fall through */ |
| 573 | case EM_LINEFROMCHAR32: |
| 574 | DPRINTF_EDIT_MSG32("EM_LINEFROMCHAR"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 575 | result = (LRESULT)EDIT_EM_LineFromChar(wnd, es, (INT32)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 576 | break; |
| 577 | |
| 578 | /* message 0x00ca missing from specs */ |
| 579 | |
| 580 | case WM_USER+26: |
| 581 | DPRINTF_EDIT_MSG16("undocumented WM_USER+26, please report"); |
| 582 | /* fall through */ |
| 583 | case 0x00ca: |
| 584 | DPRINTF_EDIT_MSG32("undocumented 0x00ca, please report"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 585 | result = DefWindowProc32A(hwnd, msg, wParam, lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 586 | break; |
| 587 | |
| 588 | case EM_SETTABSTOPS16: |
| 589 | DPRINTF_EDIT_MSG16("EM_SETTABSTOPS"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 590 | result = (LRESULT)EDIT_EM_SetTabStops16(wnd, es, (INT32)wParam, (LPINT16)PTR_SEG_TO_LIN((SEGPTR)lParam)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 591 | break; |
| 592 | case EM_SETTABSTOPS32: |
| 593 | DPRINTF_EDIT_MSG32("EM_SETTABSTOPS"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 594 | result = (LRESULT)EDIT_EM_SetTabStops(wnd, es, (INT32)wParam, (LPINT32)lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 595 | break; |
| 596 | |
| 597 | case EM_SETPASSWORDCHAR16: |
| 598 | DPRINTF_EDIT_MSG16("EM_SETPASSWORDCHAR"); |
| 599 | /* fall through */ |
| 600 | case EM_SETPASSWORDCHAR32: |
| 601 | DPRINTF_EDIT_MSG32("EM_SETPASSWORDCHAR"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 602 | EDIT_EM_SetPasswordChar(wnd, es, (CHAR)wParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 603 | break; |
| 604 | |
| 605 | case EM_EMPTYUNDOBUFFER16: |
| 606 | DPRINTF_EDIT_MSG16("EM_EMPTYUNDOBUFFER"); |
| 607 | /* fall through */ |
| 608 | case EM_EMPTYUNDOBUFFER32: |
| 609 | DPRINTF_EDIT_MSG32("EM_EMPTYUNDOBUFFER"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 610 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 611 | break; |
| 612 | |
| 613 | case EM_GETFIRSTVISIBLELINE16: |
| 614 | DPRINTF_EDIT_MSG16("EM_GETFIRSTVISIBLELINE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 615 | result = es->y_offset; |
| 616 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 617 | case EM_GETFIRSTVISIBLELINE32: |
| 618 | DPRINTF_EDIT_MSG32("EM_GETFIRSTVISIBLELINE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 619 | result = (es->style & ES_MULTILINE) ? es->y_offset : es->x_offset; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 620 | break; |
| 621 | |
| 622 | case EM_SETREADONLY16: |
| 623 | DPRINTF_EDIT_MSG16("EM_SETREADONLY"); |
| 624 | /* fall through */ |
| 625 | case EM_SETREADONLY32: |
| 626 | DPRINTF_EDIT_MSG32("EM_SETREADONLY"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 627 | if (wParam) { |
| 628 | wnd->dwStyle |= ES_READONLY; |
| 629 | es->style |= ES_READONLY; |
| 630 | } else { |
| 631 | wnd->dwStyle &= ~ES_READONLY; |
| 632 | es->style &= ~ES_READONLY; |
| 633 | } |
| 634 | return 1; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 635 | break; |
| 636 | |
| 637 | case EM_SETWORDBREAKPROC16: |
| 638 | DPRINTF_EDIT_MSG16("EM_SETWORDBREAKPROC"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 639 | EDIT_EM_SetWordBreakProc16(wnd, es, (EDITWORDBREAKPROC16)lParam); |
| 640 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 641 | case EM_SETWORDBREAKPROC32: |
| 642 | DPRINTF_EDIT_MSG32("EM_SETWORDBREAKPROC"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 643 | EDIT_EM_SetWordBreakProc(wnd, es, (EDITWORDBREAKPROC32A)lParam); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 644 | break; |
| 645 | |
| 646 | case EM_GETWORDBREAKPROC16: |
| 647 | DPRINTF_EDIT_MSG16("EM_GETWORDBREAKPROC"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 648 | result = (LRESULT)es->word_break_proc16; |
| 649 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 650 | case EM_GETWORDBREAKPROC32: |
| 651 | DPRINTF_EDIT_MSG32("EM_GETWORDBREAKPROC"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 652 | result = (LRESULT)es->word_break_proc32A; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 653 | break; |
| 654 | |
| 655 | case EM_GETPASSWORDCHAR16: |
| 656 | DPRINTF_EDIT_MSG16("EM_GETPASSWORDCHAR"); |
| 657 | /* fall through */ |
| 658 | case EM_GETPASSWORDCHAR32: |
| 659 | DPRINTF_EDIT_MSG32("EM_GETPASSWORDCHAR"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 660 | result = es->password_char; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 661 | break; |
| 662 | |
| 663 | /* The following EM_xxx are new to win95 and don't exist for 16 bit */ |
| 664 | |
| 665 | case EM_SETMARGINS32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 666 | DPRINTF_EDIT_MSG32("EM_SETMARGINS"); |
| 667 | EDIT_EM_SetMargins(wnd, es, (INT32)wParam, SLOWORD(lParam), SHIWORD(lParam)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 668 | break; |
| 669 | |
| 670 | case EM_GETMARGINS32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 671 | DPRINTF_EDIT_MSG32("EM_GETMARGINS"); |
| 672 | result = MAKELONG(es->left_margin, es->right_margin); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 673 | break; |
| 674 | |
| 675 | case EM_GETLIMITTEXT32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 676 | DPRINTF_EDIT_MSG32("EM_GETLIMITTEXT"); |
| 677 | result = es->buffer_limit; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case EM_POSFROMCHAR32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 681 | DPRINTF_EDIT_MSG32("EM_POSFROMCHAR"); |
| 682 | result = EDIT_EM_PosFromChar(wnd, es, (INT32)wParam, FALSE); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | case EM_CHARFROMPOS32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 686 | DPRINTF_EDIT_MSG32("EM_CHARFROMPOS"); |
| 687 | result = EDIT_EM_CharFromPos(wnd, es, SLOWORD(lParam), SHIWORD(lParam)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 688 | break; |
| 689 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 690 | case WM_GETDLGCODE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 691 | DPRINTF_EDIT_MSG32("WM_GETDLGCODE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 692 | result = (es->style & ES_MULTILINE) ? |
| 693 | DLGC_WANTALLKEYS | DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS : |
| 694 | DLGC_HASSETSEL | DLGC_WANTCHARS | DLGC_WANTARROWS; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 695 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 696 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 697 | case WM_CHAR: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 698 | DPRINTF_EDIT_MSG32("WM_CHAR"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 699 | EDIT_WM_Char(wnd, es, (CHAR)wParam, (DWORD)lParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 700 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 701 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 702 | case WM_CLEAR: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 703 | DPRINTF_EDIT_MSG32("WM_CLEAR"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 704 | EDIT_WM_Clear(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 705 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 706 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 707 | case WM_COMMAND: |
| 708 | DPRINTF_EDIT_MSG32("WM_COMMAND"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 709 | EDIT_WM_Command(wnd, es, HIWORD(wParam), LOWORD(wParam), (HWND32)lParam); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 710 | break; |
| 711 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 712 | case WM_CONTEXTMENU: |
| 713 | DPRINTF_EDIT_MSG32("WM_CONTEXTMENU"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 714 | EDIT_WM_ContextMenu(wnd, es, (HWND32)wParam, SLOWORD(lParam), SHIWORD(lParam)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 715 | break; |
| 716 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 717 | case WM_COPY: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 718 | DPRINTF_EDIT_MSG32("WM_COPY"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 719 | EDIT_WM_Copy(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 720 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 721 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 722 | case WM_CUT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 723 | DPRINTF_EDIT_MSG32("WM_CUT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 724 | EDIT_WM_Cut(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 725 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 726 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 727 | case WM_ENABLE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 728 | DPRINTF_EDIT_MSG32("WM_ENABLE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 729 | InvalidateRect32(hwnd, NULL, TRUE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 730 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 731 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 732 | case WM_ERASEBKGND: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 733 | DPRINTF_EDIT_MSG32("WM_ERASEBKGND"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 734 | result = EDIT_WM_EraseBkGnd(wnd, es, (HDC32)wParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 735 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 736 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 737 | case WM_GETFONT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 738 | DPRINTF_EDIT_MSG32("WM_GETFONT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 739 | result = (LRESULT)es->font; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 740 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 741 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 742 | case WM_GETTEXT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 743 | DPRINTF_EDIT_MSG32("WM_GETTEXT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 744 | result = (LRESULT)EDIT_WM_GetText(wnd, es, (INT32)wParam, (LPSTR)lParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 745 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 746 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 747 | case WM_GETTEXTLENGTH: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 748 | DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 749 | result = lstrlen32A(es->text); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 750 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 751 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 752 | case WM_HSCROLL: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 753 | DPRINTF_EDIT_MSG32("WM_HSCROLL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 754 | result = EDIT_WM_HScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND32)lParam); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 755 | break; |
| 756 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 757 | case WM_KEYDOWN: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 758 | DPRINTF_EDIT_MSG32("WM_KEYDOWN"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 759 | result = EDIT_WM_KeyDown(wnd, es, (INT32)wParam, (DWORD)lParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 760 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 761 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 762 | case WM_KILLFOCUS: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 763 | DPRINTF_EDIT_MSG32("WM_KILLFOCUS"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 764 | result = EDIT_WM_KillFocus(wnd, es, (HWND32)wParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 765 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 766 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 767 | case WM_LBUTTONDBLCLK: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 768 | DPRINTF_EDIT_MSG32("WM_LBUTTONDBLCLK"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 769 | result = EDIT_WM_LButtonDblClk(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 770 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 771 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 772 | case WM_LBUTTONDOWN: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 773 | DPRINTF_EDIT_MSG32("WM_LBUTTONDOWN"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 774 | result = EDIT_WM_LButtonDown(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 775 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 776 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 777 | case WM_LBUTTONUP: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 778 | DPRINTF_EDIT_MSG32("WM_LBUTTONUP"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 779 | result = EDIT_WM_LButtonUp(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); |
| 780 | break; |
| 781 | |
| 782 | case WM_MOUSEACTIVATE: |
| 783 | /* |
| 784 | * FIXME: maybe DefWindowProc() screws up, but it seems that |
| 785 | * modalless dialog boxes need this. If we don't do this, the focus |
| 786 | * will _not_ be set by DefWindowProc() for edit controls in a |
| 787 | * modalless dialog box ??? |
| 788 | */ |
| 789 | DPRINTF_EDIT_MSG32("WM_MOUSEACTIVATE"); |
| 790 | SetFocus32(wnd->hwndSelf); |
| 791 | result = MA_ACTIVATE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 792 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 793 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 794 | case WM_MOUSEMOVE: |
| 795 | /* |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 796 | * DPRINTF_EDIT_MSG32("WM_MOUSEMOVE"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 797 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 798 | result = EDIT_WM_MouseMove(wnd, es, (DWORD)wParam, SLOWORD(lParam), SHIWORD(lParam)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 799 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 800 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 801 | case WM_PAINT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 802 | DPRINTF_EDIT_MSG32("WM_PAINT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 803 | EDIT_WM_Paint(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 804 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 805 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 806 | case WM_PASTE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 807 | DPRINTF_EDIT_MSG32("WM_PASTE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 808 | EDIT_WM_Paste(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 809 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 810 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 811 | case WM_SETFOCUS: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 812 | DPRINTF_EDIT_MSG32("WM_SETFOCUS"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 813 | EDIT_WM_SetFocus(wnd, es, (HWND32)wParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 814 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 815 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 816 | case WM_SETFONT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 817 | DPRINTF_EDIT_MSG32("WM_SETFONT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 818 | EDIT_WM_SetFont(wnd, es, (HFONT32)wParam, LOWORD(lParam) != 0); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 819 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 820 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 821 | case WM_SETTEXT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 822 | DPRINTF_EDIT_MSG32("WM_SETTEXT"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 823 | EDIT_WM_SetText(wnd, es, (LPCSTR)lParam); |
| 824 | result = TRUE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 825 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 826 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 827 | case WM_SIZE: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 828 | DPRINTF_EDIT_MSG32("WM_SIZE"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 829 | EDIT_WM_Size(wnd, es, (UINT32)wParam, LOWORD(lParam), HIWORD(lParam)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 830 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 831 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 832 | case WM_SYSKEYDOWN: |
| 833 | DPRINTF_EDIT_MSG32("WM_SYSKEYDOWN"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 834 | result = EDIT_WM_SysKeyDown(wnd, es, (INT32)wParam, (DWORD)lParam); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 835 | break; |
| 836 | |
| 837 | case WM_TIMER: |
| 838 | DPRINTF_EDIT_MSG32("WM_TIMER"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 839 | EDIT_WM_Timer(wnd, es, (INT32)wParam, (TIMERPROC32)lParam); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 840 | break; |
| 841 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 842 | case WM_VSCROLL: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 843 | DPRINTF_EDIT_MSG32("WM_VSCROLL"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 844 | result = EDIT_WM_VScroll(wnd, es, LOWORD(wParam), SHIWORD(wParam), (HWND32)(lParam)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 845 | break; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 846 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 847 | default: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 848 | result = DefWindowProc32A(hwnd, msg, wParam, lParam); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 849 | break; |
| 850 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 851 | EDIT_UnlockBuffer(wnd, es, FALSE); |
| 852 | return result; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 853 | } |
| 854 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 855 | |
| 856 | /********************************************************************* |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 857 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 858 | * EDIT_BuildLineDefs_ML |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 859 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 860 | * Build linked list of text lines. |
| 861 | * Lines can end with '\0' (last line), a character (if it is wrapped), |
| 862 | * a soft return '\r\r\n' or a hard return '\r\n' |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 863 | * |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 864 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 865 | static void EDIT_BuildLineDefs_ML(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 866 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 867 | HDC32 dc; |
| 868 | HFONT32 old_font = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 869 | LPSTR start, cp; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 870 | INT32 fw; |
| 871 | LINEDEF *current_def; |
| 872 | LINEDEF **previous_next; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 873 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 874 | current_def = es->first_line_def; |
| 875 | do { |
| 876 | LINEDEF *next_def = current_def->next; |
| 877 | HeapFree(es->heap, 0, current_def); |
| 878 | current_def = next_def; |
| 879 | } while (current_def); |
| 880 | es->line_count = 0; |
| 881 | es->text_width = 0; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 882 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 883 | dc = GetDC32(wnd->hwndSelf); |
| 884 | if (es->font) |
| 885 | old_font = SelectObject32(dc, es->font); |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 886 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 887 | fw = es->format_rect.right - es->format_rect.left; |
| 888 | start = es->text; |
| 889 | previous_next = &es->first_line_def; |
| 890 | do { |
| 891 | current_def = HeapAlloc(es->heap, 0, sizeof(LINEDEF)); |
| 892 | current_def->next = NULL; |
| 893 | cp = start; |
| 894 | while (*cp) { |
| 895 | if ((*cp == '\r') && (*(cp + 1) == '\n')) |
| 896 | break; |
| 897 | cp++; |
| 898 | } |
| 899 | if (!(*cp)) { |
| 900 | current_def->ending = END_0; |
| 901 | current_def->net_length = lstrlen32A(start); |
| 902 | } else if ((cp > start) && (*(cp - 1) == '\r')) { |
| 903 | current_def->ending = END_SOFT; |
| 904 | current_def->net_length = cp - start - 1; |
| 905 | } else { |
| 906 | current_def->ending = END_HARD; |
| 907 | current_def->net_length = cp - start; |
| 908 | } |
| 909 | current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc, |
| 910 | start, current_def->net_length, |
| 911 | es->tabs_count, es->tabs)); |
| 912 | /* FIXME: check here for lines that are too wide even in AUTOHSCROLL (> 32767 ???) */ |
| 913 | if ((!(es->style & ES_AUTOHSCROLL)) && (current_def->width > fw)) { |
| 914 | INT32 next = 0; |
| 915 | INT32 prev; |
| 916 | do { |
| 917 | prev = next; |
| 918 | next = EDIT_CallWordBreakProc(wnd, es, start - es->text, |
| 919 | prev + 1, current_def->net_length, WB_RIGHT); |
| 920 | current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc, |
| 921 | start, next, es->tabs_count, es->tabs)); |
| 922 | } while (current_def->width <= fw); |
| 923 | if (!prev) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 924 | next = 0; |
| 925 | do { |
| 926 | prev = next; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 927 | next++; |
| 928 | current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc, |
| 929 | start, next, es->tabs_count, es->tabs)); |
| 930 | } while (current_def->width <= fw); |
| 931 | if (!prev) |
| 932 | prev = 1; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 933 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 934 | current_def->net_length = prev; |
| 935 | current_def->ending = END_WRAP; |
| 936 | current_def->width = (INT32)LOWORD(GetTabbedTextExtent32A(dc, start, |
| 937 | current_def->net_length, es->tabs_count, es->tabs)); |
| 938 | } |
| 939 | switch (current_def->ending) { |
| 940 | case END_SOFT: |
| 941 | current_def->length = current_def->net_length + 3; |
| 942 | break; |
| 943 | case END_HARD: |
| 944 | current_def->length = current_def->net_length + 2; |
| 945 | break; |
| 946 | case END_WRAP: |
| 947 | case END_0: |
| 948 | current_def->length = current_def->net_length; |
| 949 | break; |
| 950 | } |
| 951 | es->text_width = MAX(es->text_width, current_def->width); |
| 952 | start += current_def->length; |
| 953 | *previous_next = current_def; |
| 954 | previous_next = ¤t_def->next; |
| 955 | es->line_count++; |
| 956 | } while (current_def->ending != END_0); |
| 957 | if (es->font) |
| 958 | SelectObject32(dc, old_font); |
| 959 | ReleaseDC32(wnd->hwndSelf, dc); |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 962 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 963 | /********************************************************************* |
| 964 | * |
| 965 | * EDIT_CallWordBreakProc |
| 966 | * |
| 967 | * Call appropriate WordBreakProc (internal or external). |
| 968 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 969 | * Note: The "start" argument should always be an index refering |
| 970 | * to es->text. The actual wordbreak proc might be |
| 971 | * 16 bit, so we can't always pass any 32 bit LPSTR. |
| 972 | * Hence we assume that es->text is the buffer that holds |
| 973 | * the string under examination (we can decide this for ourselves). |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 974 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 975 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 976 | static INT32 EDIT_CallWordBreakProc(WND *wnd, EDITSTATE *es, INT32 start, INT32 index, INT32 count, INT32 action) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 977 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 978 | if (es->word_break_proc16) { |
| 979 | HLOCAL16 hloc16 = EDIT_EM_GetHandle16(wnd, es); |
| 980 | SEGPTR segptr = LocalLock16(hloc16); |
| 981 | INT32 ret = (INT32)CallWordBreakProc16((FARPROC16)es->word_break_proc16, |
| 982 | segptr + start, index, count, action); |
| 983 | LocalUnlock16(hloc16); |
| 984 | return ret; |
| 985 | } else if (es->word_break_proc32A) |
| 986 | return (INT32)CallWordBreakProc32A((FARPROC32)es->word_break_proc32A, |
| 987 | es->text + start, index, count, action); |
| 988 | else |
| 989 | return EDIT_WordBreakProc(es->text + start, index, count, action); |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 990 | } |
| 991 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 992 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 993 | /********************************************************************* |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 994 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 995 | * EDIT_CharFromPos |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 996 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 997 | * Beware: This is not the function called on EM_CHARFROMPOS |
| 998 | * The position _can_ be outside the formatting / client |
| 999 | * rectangle |
| 1000 | * The return value is only the character index |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1001 | * |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1002 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1003 | static INT32 EDIT_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y, LPBOOL32 after_wrap) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1004 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1005 | INT32 index; |
| 1006 | HDC32 dc; |
| 1007 | HFONT32 old_font = 0; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1008 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1009 | if (es->style & ES_MULTILINE) { |
| 1010 | INT32 line = (y - es->format_rect.top) / es->line_height + es->y_offset; |
| 1011 | INT32 line_index = 0; |
| 1012 | LINEDEF *line_def = es->first_line_def; |
| 1013 | while ((line > 0) && line_def->next) { |
| 1014 | line_index += line_def->length; |
| 1015 | line_def = line_def->next; |
| 1016 | line--; |
| 1017 | } |
| 1018 | x += es->x_offset - es->format_rect.left; |
| 1019 | if (x >= line_def->width) { |
| 1020 | if (after_wrap) |
| 1021 | *after_wrap = (line_def->ending == END_WRAP); |
| 1022 | return line_index + line_def->net_length; |
| 1023 | } |
| 1024 | if (x <= 0) { |
| 1025 | if (after_wrap) |
| 1026 | *after_wrap = FALSE; |
| 1027 | return line_index; |
| 1028 | } |
| 1029 | dc = GetDC32(wnd->hwndSelf); |
| 1030 | if (es->font) |
| 1031 | old_font = SelectObject32(dc, es->font); |
| 1032 | /* FIXME: inefficient algorithm */ |
| 1033 | for (index = line_index + 1 ; index < line_index + line_def->net_length ; index++) |
| 1034 | if (LOWORD(GetTabbedTextExtent32A(dc, es->text + line_index, |
| 1035 | index - line_index, es->tabs_count, es->tabs)) >= x) |
| 1036 | break; |
| 1037 | if (after_wrap) |
| 1038 | *after_wrap = ((index == line_index + line_def->net_length) && |
| 1039 | (line_def->ending == END_WRAP)); |
| 1040 | } else { |
| 1041 | LPSTR text; |
| 1042 | SIZE32 size; |
| 1043 | if (after_wrap) |
| 1044 | *after_wrap = FALSE; |
| 1045 | x -= es->format_rect.left; |
| 1046 | if (!x) |
| 1047 | return es->x_offset; |
| 1048 | text = EDIT_GetPasswordPointer_SL(wnd, es); |
| 1049 | dc = GetDC32(wnd->hwndSelf); |
| 1050 | if (es->font) |
| 1051 | old_font = SelectObject32(dc, es->font); |
| 1052 | if (x < 0) { |
| 1053 | x = -x; |
| 1054 | /* FIXME: inefficient algorithm */ |
| 1055 | for (index = es->x_offset ; index ; index--) { |
| 1056 | GetTextExtentPoint32A(dc, text + index, |
| 1057 | es->x_offset - index, &size); |
| 1058 | if (size.cx > x) |
| 1059 | break; |
| 1060 | } |
| 1061 | } else { |
| 1062 | INT32 len = lstrlen32A(es->text); |
| 1063 | /* FIXME: inefficient algorithm */ |
| 1064 | for (index = es->x_offset ; index < len ; index++) { |
| 1065 | GetTextExtentPoint32A(dc, text + es->x_offset, |
| 1066 | index - es->x_offset, &size); |
| 1067 | if (size.cx >= x) |
| 1068 | break; |
| 1069 | } |
| 1070 | } |
| 1071 | if (es->style & ES_PASSWORD) |
| 1072 | HeapFree(es->heap, 0 ,text); |
| 1073 | } |
| 1074 | if (es->font) |
| 1075 | SelectObject32(dc, old_font); |
| 1076 | ReleaseDC32(wnd->hwndSelf, dc); |
| 1077 | return index; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1078 | } |
| 1079 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1080 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1081 | /********************************************************************* |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1082 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1083 | * EDIT_ConfinePoint |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1084 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1085 | * adjusts the point to be within the formatting rectangle |
| 1086 | * (so CharFromPos returns the nearest _visible_ character) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1087 | * |
| 1088 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1089 | static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT32 x, LPINT32 y) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1090 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1091 | *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1); |
| 1092 | *y = MIN(MAX(*y, es->format_rect.top), es->format_rect.bottom - 1); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | |
| 1096 | /********************************************************************* |
| 1097 | * |
| 1098 | * EDIT_GetLineRect |
| 1099 | * |
| 1100 | * Calculates the bounding rectangle for a line from a starting |
| 1101 | * column to an ending column. |
| 1102 | * |
| 1103 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1104 | static void EDIT_GetLineRect(WND *wnd, EDITSTATE *es, INT32 line, INT32 scol, INT32 ecol, LPRECT32 rc) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1105 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1106 | INT32 line_index = EDIT_EM_LineIndex(wnd, es, line); |
| 1107 | |
| 1108 | if (es->style & ES_MULTILINE) |
| 1109 | rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height; |
| 1110 | else |
| 1111 | rc->top = es->format_rect.top; |
| 1112 | rc->bottom = rc->top + es->line_height; |
| 1113 | rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE)); |
| 1114 | rc->right = (ecol == -1) ? es->format_rect.right : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + ecol, TRUE)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | /********************************************************************* |
| 1119 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1120 | * EDIT_GetPasswordPointer_SL |
| 1121 | * |
| 1122 | * note: caller should free the (optionally) allocated buffer |
| 1123 | * |
| 1124 | */ |
| 1125 | static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es) |
| 1126 | { |
| 1127 | if (es->style & ES_PASSWORD) { |
| 1128 | INT32 len = lstrlen32A(es->text); |
| 1129 | LPSTR text = HeapAlloc(es->heap, 0, len + 1); |
| 1130 | RtlFillMemory(text, len, es->password_char); |
| 1131 | text[len] = '\0'; |
| 1132 | return text; |
| 1133 | } else |
| 1134 | return es->text; |
| 1135 | } |
| 1136 | |
| 1137 | |
| 1138 | /********************************************************************* |
| 1139 | * |
| 1140 | * EDIT_LockBuffer |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1141 | * |
| 1142 | * This acts as a LOCAL_Lock(), but it locks only once. This way |
| 1143 | * you can call it whenever you like, without unlocking. |
| 1144 | * |
| 1145 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1146 | static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1147 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1148 | if (!es) { |
| 1149 | fprintf(stderr, "edit: LockBuffer() without an EDITSTATE ... please report\n"); |
| 1150 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1151 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1152 | if (!(es->style & ES_MULTILINE)) |
| 1153 | return; |
| 1154 | if (!es->text) { |
| 1155 | if (es->hloc32) |
| 1156 | es->text = LocalLock32(es->hloc32); |
| 1157 | else if (es->hloc16) |
| 1158 | es->text = LOCAL_Lock(wnd->hInstance, es->hloc16); |
| 1159 | else { |
| 1160 | fprintf(stderr, "edit: LockBuffer() without a buffer ... please report\n"); |
| 1161 | return; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1162 | } |
| 1163 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1164 | es->lock_count++; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | |
| 1168 | /********************************************************************* |
| 1169 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1170 | * EDIT_SL_InvalidateText |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 1171 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1172 | * Called from EDIT_InvalidateText(). |
| 1173 | * Does the job for single-line controls only. |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 1174 | * |
| 1175 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1176 | static void EDIT_SL_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end) |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 1177 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1178 | RECT32 line_rect; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1179 | RECT32 rc; |
| 1180 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1181 | EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect); |
| 1182 | if (IntersectRect32(&rc, &line_rect, &es->format_rect)) |
| 1183 | InvalidateRect32(wnd->hwndSelf, &rc, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | /********************************************************************* |
| 1188 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1189 | * EDIT_ML_InvalidateText |
| 1190 | * |
| 1191 | * Called from EDIT_InvalidateText(). |
| 1192 | * Does the job for multi-line controls only. |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1193 | * |
| 1194 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1195 | static void EDIT_ML_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1196 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1197 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 1198 | INT32 sl = EDIT_EM_LineFromChar(wnd, es, start); |
| 1199 | INT32 el = EDIT_EM_LineFromChar(wnd, es, end); |
| 1200 | INT32 sc; |
| 1201 | INT32 ec; |
| 1202 | RECT32 rc1; |
| 1203 | RECT32 rcWnd; |
| 1204 | RECT32 rcLine; |
| 1205 | RECT32 rcUpdate; |
| 1206 | INT32 l; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1207 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1208 | if ((el < es->y_offset) || (sl > es->y_offset + vlc)) |
| 1209 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1210 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1211 | sc = start - EDIT_EM_LineIndex(wnd, es, sl); |
| 1212 | ec = end - EDIT_EM_LineIndex(wnd, es, el); |
| 1213 | if (sl < es->y_offset) { |
| 1214 | sl = es->y_offset; |
| 1215 | sc = 0; |
| 1216 | } |
| 1217 | if (el > es->y_offset + vlc) { |
| 1218 | el = es->y_offset + vlc; |
| 1219 | ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el)); |
| 1220 | } |
| 1221 | GetClientRect32(wnd->hwndSelf, &rc1); |
| 1222 | IntersectRect32(&rcWnd, &rc1, &es->format_rect); |
| 1223 | if (sl == el) { |
| 1224 | EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine); |
| 1225 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1226 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1227 | } else { |
| 1228 | EDIT_GetLineRect(wnd, es, sl, sc, |
| 1229 | EDIT_EM_LineLength(wnd, es, |
| 1230 | EDIT_EM_LineIndex(wnd, es, sl)), |
| 1231 | &rcLine); |
| 1232 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1233 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1234 | for (l = sl + 1 ; l < el ; l++) { |
| 1235 | EDIT_GetLineRect(wnd, es, l, 0, |
| 1236 | EDIT_EM_LineLength(wnd, es, |
| 1237 | EDIT_EM_LineIndex(wnd, es, l)), |
| 1238 | &rcLine); |
| 1239 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1240 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1241 | } |
| 1242 | EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine); |
| 1243 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1244 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1245 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | |
| 1249 | /********************************************************************* |
| 1250 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1251 | * EDIT_InvalidateText |
| 1252 | * |
| 1253 | * Invalidate the text from offset start upto, but not including, |
| 1254 | * offset end. Useful for (re)painting the selection. |
| 1255 | * Regions outside the linewidth are not invalidated. |
| 1256 | * end == -1 means end == TextLength. |
| 1257 | * start and end need not be ordered. |
| 1258 | * |
| 1259 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1260 | static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end) |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1261 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1262 | if (end == start) |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1263 | return; |
| 1264 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1265 | if (end == -1) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1266 | end = lstrlen32A(es->text); |
| 1267 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1268 | ORDER_INT32(start, end); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1269 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1270 | if (es->style & ES_MULTILINE) |
| 1271 | EDIT_ML_InvalidateText(wnd, es, start, end); |
| 1272 | else |
| 1273 | EDIT_SL_InvalidateText(wnd, es, start, end); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | /********************************************************************* |
| 1278 | * |
| 1279 | * EDIT_MakeFit |
| 1280 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1281 | * Try to fit size + 1 bytes in the buffer. Constrain to limits. |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1282 | * |
| 1283 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1284 | static BOOL32 EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT32 size) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1285 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1286 | HLOCAL32 hNew32; |
| 1287 | HLOCAL16 hNew16; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1288 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1289 | if (size <= es->buffer_size) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1290 | return TRUE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1291 | if (size > es->buffer_limit) { |
| 1292 | EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1293 | return FALSE; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1294 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1295 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1296 | if (size > es->buffer_limit) |
| 1297 | size = es->buffer_limit; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1298 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1299 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: trying to ReAlloc to %d+1\n", size); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1300 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1301 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 1302 | if (es->text) { |
| 1303 | if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1))) |
| 1304 | es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit); |
| 1305 | else |
| 1306 | es->buffer_size = 0; |
| 1307 | } else if (es->hloc32) { |
| 1308 | if ((hNew32 = LocalReAlloc32(es->hloc32, size + 1, 0))) { |
| 1309 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32); |
| 1310 | es->hloc32 = hNew32; |
| 1311 | es->buffer_size = MIN(LocalSize32(es->hloc32) - 1, es->buffer_limit); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1312 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1313 | } else if (es->hloc16) { |
| 1314 | if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) { |
| 1315 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16); |
| 1316 | es->hloc16 = hNew16; |
| 1317 | es->buffer_size = MIN(LOCAL_Size(wnd->hInstance, es->hloc16) - 1, es->buffer_limit); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1318 | } |
| 1319 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1320 | if (es->buffer_size < size) { |
| 1321 | EDIT_LockBuffer(wnd, es); |
| 1322 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: FAILED ! We now have %d+1\n", es->buffer_size); |
| 1323 | EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE"); |
| 1324 | return FALSE; |
| 1325 | } else { |
| 1326 | EDIT_LockBuffer(wnd, es); |
| 1327 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: We now have %d+1\n", es->buffer_size); |
| 1328 | return TRUE; |
| 1329 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | /********************************************************************* |
| 1334 | * |
| 1335 | * EDIT_MakeUndoFit |
| 1336 | * |
| 1337 | * Try to fit size + 1 bytes in the undo buffer. |
| 1338 | * |
| 1339 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1340 | static BOOL32 EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT32 size) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1341 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1342 | if (size <= es->undo_buffer_size) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1343 | return TRUE; |
| 1344 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH; |
| 1345 | |
| 1346 | dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: trying to ReAlloc to %d+1\n", size); |
| 1347 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1348 | if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) { |
| 1349 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; |
| 1350 | if (es->undo_buffer_size < size) { |
| 1351 | dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: FAILED ! We now have %d+1\n", es->undo_buffer_size); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1352 | return FALSE; |
| 1353 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1354 | return TRUE; |
| 1355 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1356 | return FALSE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | /********************************************************************* |
| 1361 | * |
| 1362 | * EDIT_MoveBackward |
| 1363 | * |
| 1364 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1365 | static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1366 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1367 | INT32 e = es->selection_end; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1368 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1369 | if (e) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1370 | e--; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1371 | if ((es->style & ES_MULTILINE) && e && |
| 1372 | (es->text[e - 1] == '\r') && (es->text[e] == '\n')) { |
| 1373 | e--; |
| 1374 | if (e && (es->text[e - 1] == '\r')) |
| 1375 | e--; |
| 1376 | } |
| 1377 | } |
| 1378 | EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE); |
| 1379 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | /********************************************************************* |
| 1384 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1385 | * EDIT_MoveDown_ML |
| 1386 | * |
| 1387 | * Only for multi line controls |
| 1388 | * Move the caret one line down, on a column with the nearest |
| 1389 | * x coordinate on the screen (might be a different column). |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1390 | * |
| 1391 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1392 | static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1393 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1394 | INT32 s = es->selection_start; |
| 1395 | INT32 e = es->selection_end; |
| 1396 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1397 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1398 | INT32 x = SLOWORD(pos); |
| 1399 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1400 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1401 | e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1402 | if (!extend) |
| 1403 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1404 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1405 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | |
| 1409 | /********************************************************************* |
| 1410 | * |
| 1411 | * EDIT_MoveEnd |
| 1412 | * |
| 1413 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1414 | static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1415 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1416 | BOOL32 after_wrap = FALSE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1417 | INT32 e; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1418 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1419 | if (es->style & ES_MULTILINE) |
| 1420 | e = EDIT_CharFromPos(wnd, es, 0x7fffffff, |
| 1421 | HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap); |
| 1422 | else |
| 1423 | e = lstrlen32A(es->text); |
| 1424 | EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap); |
| 1425 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | |
| 1429 | /********************************************************************* |
| 1430 | * |
| 1431 | * EDIT_MoveForward |
| 1432 | * |
| 1433 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1434 | static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1435 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1436 | INT32 e = es->selection_end; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1437 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1438 | if (es->text[e]) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1439 | e++; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1440 | if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) { |
| 1441 | if (es->text[e] == '\n') |
| 1442 | e++; |
| 1443 | else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n')) |
| 1444 | e += 2; |
| 1445 | } |
| 1446 | } |
| 1447 | EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE); |
| 1448 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | /********************************************************************* |
| 1453 | * |
| 1454 | * EDIT_MoveHome |
| 1455 | * |
| 1456 | * Home key: move to beginning of line. |
| 1457 | * |
| 1458 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1459 | static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1460 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1461 | INT32 e; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1462 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1463 | if (es->style & ES_MULTILINE) |
| 1464 | e = EDIT_CharFromPos(wnd, es, 0x80000000, |
| 1465 | HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL); |
| 1466 | else |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1467 | e = 0; |
| 1468 | EDIT_EM_SetSel(wnd, es, e, extend ? es->selection_start : e, FALSE); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1469 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | |
| 1473 | /********************************************************************* |
| 1474 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1475 | * EDIT_MovePageDown_ML |
| 1476 | * |
| 1477 | * Only for multi line controls |
| 1478 | * Move the caret one page down, on a column with the nearest |
| 1479 | * x coordinate on the screen (might be a different column). |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1480 | * |
| 1481 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1482 | static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1483 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1484 | INT32 s = es->selection_start; |
| 1485 | INT32 e = es->selection_end; |
| 1486 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1487 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1488 | INT32 x = SLOWORD(pos); |
| 1489 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1490 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1491 | e = EDIT_CharFromPos(wnd, es, x, |
| 1492 | y + (es->format_rect.bottom - es->format_rect.top), |
| 1493 | &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1494 | if (!extend) |
| 1495 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1496 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1497 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | |
| 1501 | /********************************************************************* |
| 1502 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1503 | * EDIT_MovePageUp_ML |
| 1504 | * |
| 1505 | * Only for multi line controls |
| 1506 | * Move the caret one page up, on a column with the nearest |
| 1507 | * x coordinate on the screen (might be a different column). |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1508 | * |
| 1509 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1510 | static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1511 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1512 | INT32 s = es->selection_start; |
| 1513 | INT32 e = es->selection_end; |
| 1514 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1515 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1516 | INT32 x = SLOWORD(pos); |
| 1517 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1518 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1519 | e = EDIT_CharFromPos(wnd, es, x, |
| 1520 | y - (es->format_rect.bottom - es->format_rect.top), |
| 1521 | &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1522 | if (!extend) |
| 1523 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1524 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1525 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | |
| 1529 | /********************************************************************* |
| 1530 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1531 | * EDIT_MoveUp_ML |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1532 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1533 | * Only for multi line controls |
| 1534 | * Move the caret one line up, on a column with the nearest |
| 1535 | * x coordinate on the screen (might be a different column). |
| 1536 | * |
| 1537 | */ |
| 1538 | static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1539 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1540 | INT32 s = es->selection_start; |
| 1541 | INT32 e = es->selection_end; |
| 1542 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1543 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1544 | INT32 x = SLOWORD(pos); |
| 1545 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1546 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1547 | e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1548 | if (!extend) |
| 1549 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1550 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1551 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | /********************************************************************* |
| 1556 | * |
| 1557 | * EDIT_MoveWordBackward |
| 1558 | * |
| 1559 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1560 | static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1561 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1562 | INT32 s = es->selection_start; |
| 1563 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1564 | INT32 l; |
| 1565 | INT32 ll; |
| 1566 | INT32 li; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1567 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1568 | l = EDIT_EM_LineFromChar(wnd, es, e); |
| 1569 | ll = EDIT_EM_LineLength(wnd, es, e); |
| 1570 | li = EDIT_EM_LineIndex(wnd, es, l); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1571 | if (e - li == 0) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1572 | if (l) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1573 | li = EDIT_EM_LineIndex(wnd, es, l - 1); |
| 1574 | e = li + EDIT_EM_LineLength(wnd, es, li); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1575 | } |
| 1576 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1577 | e = li + (INT32)EDIT_CallWordBreakProc(wnd, es, |
| 1578 | li, e - li, ll, WB_LEFT); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1579 | } |
| 1580 | if (!extend) |
| 1581 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1582 | EDIT_EM_SetSel(wnd, es, s, e, FALSE); |
| 1583 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | |
| 1587 | /********************************************************************* |
| 1588 | * |
| 1589 | * EDIT_MoveWordForward |
| 1590 | * |
| 1591 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1592 | static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1593 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1594 | INT32 s = es->selection_start; |
| 1595 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1596 | INT32 l; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1597 | INT32 ll; |
| 1598 | INT32 li; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1599 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1600 | l = EDIT_EM_LineFromChar(wnd, es, e); |
| 1601 | ll = EDIT_EM_LineLength(wnd, es, e); |
| 1602 | li = EDIT_EM_LineIndex(wnd, es, l); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1603 | if (e - li == ll) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1604 | if ((es->style & ES_MULTILINE) && (l != es->line_count - 1)) |
| 1605 | e = EDIT_EM_LineIndex(wnd, es, l + 1); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1606 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1607 | e = li + EDIT_CallWordBreakProc(wnd, es, |
| 1608 | li, e - li + 1, ll, WB_RIGHT); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1609 | } |
| 1610 | if (!extend) |
| 1611 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1612 | EDIT_EM_SetSel(wnd, es, s, e, FALSE); |
| 1613 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | |
| 1617 | /********************************************************************* |
| 1618 | * |
| 1619 | * EDIT_PaintLine |
| 1620 | * |
| 1621 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1622 | static void EDIT_PaintLine(WND *wnd, EDITSTATE *es, HDC32 dc, INT32 line, BOOL32 rev) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1623 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1624 | INT32 s = es->selection_start; |
| 1625 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1626 | INT32 li; |
| 1627 | INT32 ll; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1628 | INT32 x; |
| 1629 | INT32 y; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1630 | LRESULT pos; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1631 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1632 | if (es->style & ES_MULTILINE) { |
| 1633 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 1634 | if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count)) |
| 1635 | return; |
| 1636 | } else if (line) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1637 | return; |
| 1638 | |
| 1639 | dprintf_edit(stddeb, "edit: EDIT_PaintLine: line=%d\n", line); |
| 1640 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1641 | pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE); |
| 1642 | x = SLOWORD(pos); |
| 1643 | y = SHIWORD(pos); |
| 1644 | li = EDIT_EM_LineIndex(wnd, es, line); |
| 1645 | ll = EDIT_EM_LineLength(wnd, es, li); |
| 1646 | s = es->selection_start; |
| 1647 | e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1648 | ORDER_INT32(s, e); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1649 | s = MIN(li + ll, MAX(li, s)); |
| 1650 | e = MIN(li + ll, MAX(li, e)); |
| 1651 | if (rev && (s != e) && |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1652 | ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) { |
| 1653 | x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE); |
| 1654 | x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE); |
| 1655 | x += EDIT_PaintText(wnd, es, dc, x, y, line, e - li, li + ll - e, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1656 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1657 | x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | |
| 1661 | /********************************************************************* |
| 1662 | * |
| 1663 | * EDIT_PaintText |
| 1664 | * |
| 1665 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1666 | static INT32 EDIT_PaintText(WND *wnd, EDITSTATE *es, HDC32 dc, INT32 x, INT32 y, INT32 line, INT32 col, INT32 count, BOOL32 rev) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1667 | { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1668 | COLORREF BkColor; |
| 1669 | COLORREF TextColor; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1670 | INT32 ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1671 | INT32 li; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1672 | SIZE32 size; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1673 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1674 | if (!count) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1675 | return 0; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1676 | BkColor = GetBkColor32(dc); |
| 1677 | TextColor = GetTextColor32(dc); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1678 | if (rev) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1679 | SetBkColor32(dc, GetSysColor32(COLOR_HIGHLIGHT)); |
| 1680 | SetTextColor32(dc, GetSysColor32(COLOR_HIGHLIGHTTEXT)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1681 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1682 | li = EDIT_EM_LineIndex(wnd, es, line); |
| 1683 | if (es->style & ES_MULTILINE) { |
| 1684 | ret = (INT32)LOWORD(TabbedTextOut32A(dc, x, y, es->text + li + col, count, |
| 1685 | es->tabs_count, es->tabs, es->format_rect.left - es->x_offset)); |
| 1686 | } else { |
| 1687 | LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es); |
| 1688 | TextOut32A(dc, x, y, text + li + col, count); |
| 1689 | GetTextExtentPoint32A(dc, text + li + col, count, &size); |
| 1690 | ret = size.cx; |
| 1691 | if (es->style & ES_PASSWORD) |
| 1692 | HeapFree(es->heap, 0, text); |
| 1693 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1694 | if (rev) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1695 | SetBkColor32(dc, BkColor); |
| 1696 | SetTextColor32(dc, TextColor); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1697 | } |
| 1698 | return ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1699 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1700 | |
| 1701 | |
| 1702 | /********************************************************************* |
| 1703 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1704 | * EM_SCROLLCARET |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1705 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1706 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1707 | static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1708 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1709 | if (es->style & ES_MULTILINE) { |
| 1710 | INT32 l; |
| 1711 | INT32 li; |
| 1712 | INT32 vlc; |
| 1713 | INT32 ww; |
| 1714 | INT32 cw = es->char_width; |
| 1715 | INT32 x; |
| 1716 | INT32 dy = 0; |
| 1717 | INT32 dx = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1718 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1719 | l = EDIT_EM_LineFromChar(wnd, es, es->selection_end); |
| 1720 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 1721 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)); |
| 1722 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 1723 | if (l >= es->y_offset + vlc) |
| 1724 | dy = l - vlc + 1 - es->y_offset; |
| 1725 | if (l < es->y_offset) |
| 1726 | dy = l - es->y_offset; |
| 1727 | ww = es->format_rect.right - es->format_rect.left; |
| 1728 | if (x < es->format_rect.left) |
| 1729 | dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw; |
| 1730 | if (x > es->format_rect.right) |
| 1731 | dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw; |
| 1732 | if (dy || dx) |
| 1733 | EDIT_EM_LineScroll(wnd, es, dx, dy); |
| 1734 | } else { |
| 1735 | INT32 x; |
| 1736 | INT32 goal; |
| 1737 | INT32 format_width; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1738 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1739 | if (!(es->style & ES_AUTOHSCROLL)) |
| 1740 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1741 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1742 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); |
| 1743 | format_width = es->format_rect.right - es->format_rect.left; |
| 1744 | if (x < es->format_rect.left) { |
| 1745 | goal = es->format_rect.left + format_width / HSCROLL_FRACTION; |
| 1746 | do { |
| 1747 | es->x_offset--; |
| 1748 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); |
| 1749 | } while ((x < goal) && es->x_offset); |
| 1750 | /* FIXME: use ScrollWindow() somehow to improve performance */ |
| 1751 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 1752 | } else if (x > es->format_rect.right) { |
| 1753 | INT32 x_last; |
| 1754 | INT32 len = lstrlen32A(es->text); |
| 1755 | goal = es->format_rect.right - format_width / HSCROLL_FRACTION; |
| 1756 | do { |
| 1757 | es->x_offset++; |
| 1758 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); |
| 1759 | x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE)); |
| 1760 | } while ((x > goal) && (x_last > es->format_rect.right)); |
| 1761 | /* FIXME: use ScrollWindow() somehow to improve performance */ |
| 1762 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1763 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1764 | } |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | /********************************************************************* |
| 1769 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1770 | * EDIT_SetRectNP |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1771 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1772 | * note: this is not (exactly) the handler called on EM_SETRECTNP |
| 1773 | * it is also used to set the rect of a single line control |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1774 | * |
| 1775 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1776 | static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT32 rc) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1777 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1778 | CopyRect32(&es->format_rect, rc); |
| 1779 | if (es->style & WS_BORDER) { |
| 1780 | INT32 bw = GetSystemMetrics32(SM_CXBORDER) + 1; |
| 1781 | es->format_rect.left += bw; |
| 1782 | es->format_rect.top += bw; |
| 1783 | es->format_rect.right -= bw; |
| 1784 | es->format_rect.bottom -= bw; |
| 1785 | } |
| 1786 | es->format_rect.left += es->left_margin; |
| 1787 | es->format_rect.right -= es->right_margin; |
| 1788 | es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width); |
| 1789 | if (es->style & ES_MULTILINE) |
| 1790 | es->format_rect.bottom = es->format_rect.top + |
| 1791 | MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height; |
| 1792 | else |
| 1793 | es->format_rect.bottom = es->format_rect.top + es->line_height; |
| 1794 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) |
| 1795 | EDIT_BuildLineDefs_ML(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | |
| 1799 | /********************************************************************* |
| 1800 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1801 | * EDIT_UnlockBuffer |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1802 | * |
| 1803 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1804 | static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL32 force) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1805 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1806 | if (!es) { |
| 1807 | fprintf(stderr, "edit: UnlockBuffer() without an EDITSTATE ... please report\n"); |
| 1808 | return; |
| 1809 | } |
| 1810 | if (!(es->style & ES_MULTILINE)) |
| 1811 | return; |
| 1812 | if (!es->lock_count) { |
| 1813 | fprintf(stderr, "edit: UnlockBuffer() with lock_count == 0 ... please report\n"); |
| 1814 | return; |
| 1815 | } |
| 1816 | if (!es->text) { |
| 1817 | fprintf(stderr, "edit: UnlockBuffer() with es->text == 0 ... please report\n"); |
| 1818 | return; |
| 1819 | } |
| 1820 | if (force || (es->lock_count == 1)) { |
| 1821 | if (es->hloc32) { |
| 1822 | LocalUnlock32(es->hloc32); |
| 1823 | es->text = NULL; |
| 1824 | } else if (es->hloc16) { |
| 1825 | LOCAL_Unlock(wnd->hInstance, es->hloc16); |
| 1826 | es->text = NULL; |
| 1827 | } |
| 1828 | } |
| 1829 | es->lock_count--; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | |
| 1833 | /********************************************************************* |
| 1834 | * |
| 1835 | * EDIT_WordBreakProc |
| 1836 | * |
| 1837 | * Find the beginning of words. |
| 1838 | * Note: unlike the specs for a WordBreakProc, this function only |
| 1839 | * allows to be called without linebreaks between s[0] upto |
| 1840 | * s[count - 1]. Remember it is only called |
| 1841 | * internally, so we can decide this for ourselves. |
| 1842 | * |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1843 | */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1844 | static INT32 EDIT_WordBreakProc(LPSTR s, INT32 index, INT32 count, INT32 action) |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1845 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1846 | INT32 ret = 0; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1847 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1848 | dprintf_edit(stddeb, "edit: EDIT_WordBreakProc: s=%p, index=%u" |
| 1849 | ", count=%u, action=%d\n", s, index, count, action); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1850 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1851 | switch (action) { |
| 1852 | case WB_LEFT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1853 | if (!count) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1854 | break; |
| 1855 | if (index) |
| 1856 | index--; |
| 1857 | if (s[index] == ' ') { |
| 1858 | while (index && (s[index] == ' ')) |
| 1859 | index--; |
| 1860 | if (index) { |
| 1861 | while (index && (s[index] != ' ')) |
| 1862 | index--; |
| 1863 | if (s[index] == ' ') |
| 1864 | index++; |
| 1865 | } |
| 1866 | } else { |
| 1867 | while (index && (s[index] != ' ')) |
| 1868 | index--; |
| 1869 | if (s[index] == ' ') |
| 1870 | index++; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1871 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1872 | ret = index; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1873 | break; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1874 | case WB_RIGHT: |
| 1875 | if (!count) |
| 1876 | break; |
| 1877 | if (index) |
| 1878 | index--; |
| 1879 | if (s[index] == ' ') |
| 1880 | while ((index < count) && (s[index] == ' ')) index++; |
| 1881 | else { |
| 1882 | while (s[index] && (s[index] != ' ') && (index < count)) |
| 1883 | index++; |
| 1884 | while ((s[index] == ' ') && (index < count)) index++; |
| 1885 | } |
| 1886 | ret = index; |
| 1887 | break; |
| 1888 | case WB_ISDELIMITER: |
| 1889 | ret = (s[index] == ' '); |
| 1890 | break; |
| 1891 | default: |
| 1892 | fprintf(stderr, "edit: EDIT_WordBreakProc: unknown action code, please report !\n"); |
| 1893 | break; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1894 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1895 | return ret; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1896 | } |
| 1897 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1898 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1899 | /********************************************************************* |
| 1900 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1901 | * EM_CHARFROMPOS |
| 1902 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1903 | * FIXME: do the specs mean to return LineIndex or LineNumber ??? |
| 1904 | * Let's assume LineIndex is meant |
| 1905 | * FIXME: do the specs mean to return -1 if outside client area or |
| 1906 | * if outside formatting rectangle ??? |
| 1907 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1908 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1909 | static LRESULT EDIT_EM_CharFromPos(WND *wnd, EDITSTATE *es, INT32 x, INT32 y) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1910 | { |
| 1911 | POINT32 pt; |
| 1912 | RECT32 rc; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1913 | INT32 index; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1914 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1915 | pt.x = x; |
| 1916 | pt.y = y; |
| 1917 | GetClientRect32(wnd->hwndSelf, &rc); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1918 | if (!PtInRect32(&rc, pt)) |
| 1919 | return -1; |
| 1920 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1921 | index = EDIT_CharFromPos(wnd, es, x, y, NULL); |
| 1922 | return MAKELONG(index, EDIT_EM_LineIndex(wnd, es, |
| 1923 | EDIT_EM_LineFromChar(wnd, es, index))); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1926 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1927 | /********************************************************************* |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1928 | * |
| 1929 | * EM_FMTLINES |
| 1930 | * |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1931 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1932 | static BOOL32 EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL32 add_eol) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1933 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1934 | fprintf(stdnimp, "edit: EM_FMTLINES: message not implemented\n"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1935 | return add_eol; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1936 | } |
Alexandre Julliard | 988ca97 | 1994-06-21 16:15:21 +0000 | [diff] [blame] | 1937 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1938 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1939 | /********************************************************************* |
| 1940 | * |
| 1941 | * EM_GETHANDLE |
| 1942 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1943 | * Hopefully this won't fire back at us. |
| 1944 | * We always start with a fixed buffer in our own heap. |
| 1945 | * However, with this message a 32 bit application requests |
| 1946 | * a handle to 32 bit moveable local heap memory, where it expects |
| 1947 | * to find the text. |
| 1948 | * It's a pitty that from this moment on we have to use this |
| 1949 | * local heap, because applications may rely on the handle |
| 1950 | * in the future. |
| 1951 | * |
| 1952 | * In this function we'll try to switch to local heap. |
| 1953 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1954 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1955 | static HLOCAL32 EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1956 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1957 | HLOCAL32 newBuf; |
| 1958 | LPSTR newText; |
| 1959 | INT32 newSize; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1960 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1961 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1962 | return 0; |
| 1963 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1964 | if (es->hloc32) |
| 1965 | return es->hloc32; |
| 1966 | else if (es->hloc16) |
| 1967 | return (HLOCAL32)es->hloc16; |
| 1968 | |
| 1969 | if (!(newBuf = LocalAlloc32(LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) { |
| 1970 | fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 32 bit buffer\n"); |
| 1971 | return 0; |
| 1972 | } |
| 1973 | newSize = MIN(LocalSize32(newBuf) - 1, es->buffer_limit); |
| 1974 | if (!(newText = LocalLock32(newBuf))) { |
| 1975 | fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 32 bit buffer\n"); |
| 1976 | LocalFree32(newBuf); |
| 1977 | return 0; |
| 1978 | } |
| 1979 | lstrcpy32A(newText, es->text); |
| 1980 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 1981 | if (es->text) |
| 1982 | HeapFree(es->heap, 0, es->text); |
| 1983 | es->hloc32 = newBuf; |
| 1984 | es->hloc16 = (HLOCAL16)NULL; |
| 1985 | es->buffer_size = newSize; |
| 1986 | es->text = newText; |
| 1987 | EDIT_LockBuffer(wnd, es); |
| 1988 | dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 32 bit local heap\n"); |
| 1989 | |
| 1990 | return es->hloc32; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1991 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1992 | |
| 1993 | |
| 1994 | /********************************************************************* |
| 1995 | * |
| 1996 | * EM_GETHANDLE16 |
| 1997 | * |
| 1998 | * Hopefully this won't fire back at us. |
| 1999 | * We always start with a buffer in 32 bit linear memory. |
| 2000 | * However, with this message a 16 bit application requests |
| 2001 | * a handle of 16 bit local heap memory, where it expects to find |
| 2002 | * the text. |
| 2003 | * It's a pitty that from this moment on we have to use this |
| 2004 | * local heap, because applications may rely on the handle |
| 2005 | * in the future. |
| 2006 | * |
| 2007 | * In this function we'll try to switch to local heap. |
| 2008 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2009 | static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2010 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2011 | HLOCAL16 newBuf; |
| 2012 | LPSTR newText; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2013 | INT32 newSize; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2014 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2015 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2016 | return 0; |
| 2017 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2018 | if (es->hloc16) |
| 2019 | return es->hloc16; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2020 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2021 | if (!LOCAL_HeapSize(wnd->hInstance)) { |
| 2022 | if (!LocalInit(wnd->hInstance, 0, |
| 2023 | GlobalSize16(wnd->hInstance))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2024 | fprintf(stderr, "edit: EM_GETHANDLE: could not initialize local heap\n"); |
| 2025 | return 0; |
| 2026 | } |
| 2027 | dprintf_edit(stddeb, "edit: EM_GETHANDLE: local heap initialized\n"); |
| 2028 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2029 | if (!(newBuf = LOCAL_Alloc(wnd->hInstance, LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2030 | fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 16 bit buffer\n"); |
| 2031 | return 0; |
| 2032 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2033 | newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit); |
| 2034 | if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2035 | fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 16 bit buffer\n"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2036 | LOCAL_Free(wnd->hInstance, newBuf); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2037 | return 0; |
| 2038 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2039 | lstrcpy32A(newText, es->text); |
| 2040 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 2041 | if (es->text) |
| 2042 | HeapFree(es->heap, 0, es->text); |
| 2043 | else if (es->hloc32) { |
| 2044 | while (LocalFree32(es->hloc32)) ; |
| 2045 | LocalFree32(es->hloc32); |
| 2046 | } |
| 2047 | es->hloc32 = (HLOCAL32)NULL; |
| 2048 | es->hloc16 = newBuf; |
| 2049 | es->buffer_size = newSize; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2050 | es->text = newText; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2051 | EDIT_LockBuffer(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2052 | dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 16 bit buffer\n"); |
| 2053 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2054 | return es->hloc16; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2057 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2058 | /********************************************************************* |
| 2059 | * |
| 2060 | * EM_GETLINE |
| 2061 | * |
| 2062 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2063 | static INT32 EDIT_EM_GetLine(WND *wnd, EDITSTATE *es, INT32 line, LPSTR lpch) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2064 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2065 | LPSTR src; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2066 | INT32 len; |
| 2067 | INT32 i; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2068 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2069 | if (es->style & ES_MULTILINE) { |
| 2070 | if (line >= es->line_count) |
| 2071 | return 0; |
| 2072 | } else |
| 2073 | line = 0; |
| 2074 | src = es->text + EDIT_EM_LineIndex(wnd, es, line); |
| 2075 | len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, line)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2076 | for (i = 0 ; i < len ; i++) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2077 | *lpch = *src; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2078 | src++; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2079 | lpch++; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2080 | } |
| 2081 | return (LRESULT)len; |
| 2082 | } |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2083 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2084 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2085 | /********************************************************************* |
| 2086 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2087 | * EM_GETSEL |
| 2088 | * |
| 2089 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2090 | static LRESULT EDIT_EM_GetSel(WND *wnd, EDITSTATE *es, LPUINT32 start, LPUINT32 end) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2091 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2092 | UINT32 s = es->selection_start; |
| 2093 | UINT32 e = es->selection_end; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2094 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2095 | ORDER_UINT32(s, e); |
| 2096 | if (start) |
| 2097 | *start = s; |
| 2098 | if (end) |
| 2099 | *end = e; |
| 2100 | return MAKELONG(s, e); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | |
| 2104 | /********************************************************************* |
| 2105 | * |
| 2106 | * EM_GETTHUMB |
| 2107 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2108 | * FIXME: is this right ? (or should it be only VSCROLL) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2109 | * (and maybe only for edit controls that really have their |
| 2110 | * own scrollbars) (and maybe only for multiline controls ?) |
| 2111 | * All in all: very poorly documented |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2112 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2113 | * FIXME: now it's also broken, because of the new WM_HSCROLL / |
| 2114 | * WM_VSCROLL handlers |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2115 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2116 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2117 | static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2118 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2119 | return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB16, 0, 0), |
| 2120 | EDIT_WM_HScroll(wnd, es, EM_GETTHUMB16, 0, 0)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | |
| 2124 | /********************************************************************* |
| 2125 | * |
| 2126 | * EM_LINEFROMCHAR |
| 2127 | * |
| 2128 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2129 | static INT32 EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT32 index) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2130 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2131 | INT32 line; |
| 2132 | LINEDEF *line_def; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2133 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2134 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2135 | return 0; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2136 | if (index > lstrlen32A(es->text)) |
| 2137 | return es->line_count - 1; |
| 2138 | if (index == -1) |
| 2139 | index = MIN(es->selection_start, es->selection_end); |
| 2140 | |
| 2141 | line = 0; |
| 2142 | line_def = es->first_line_def; |
| 2143 | index -= line_def->length; |
| 2144 | while ((index >= 0) && line_def->next) { |
| 2145 | line++; |
| 2146 | line_def = line_def->next; |
| 2147 | index -= line_def->length; |
| 2148 | } |
| 2149 | return line; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | |
| 2153 | /********************************************************************* |
| 2154 | * |
| 2155 | * EM_LINEINDEX |
| 2156 | * |
| 2157 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2158 | static INT32 EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT32 line) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2159 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2160 | INT32 line_index; |
| 2161 | LINEDEF *line_def; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2162 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2163 | if (!(es->style & ES_MULTILINE)) |
| 2164 | return 0; |
| 2165 | if (line >= es->line_count) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2166 | return -1; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2167 | |
| 2168 | line_index = 0; |
| 2169 | line_def = es->first_line_def; |
| 2170 | if (line == -1) { |
| 2171 | INT32 index = es->selection_end - line_def->length; |
| 2172 | while ((index >= 0) && line_def->next) { |
| 2173 | line_index += line_def->length; |
| 2174 | line_def = line_def->next; |
| 2175 | index -= line_def->length; |
| 2176 | } |
| 2177 | } else { |
| 2178 | while (line > 0) { |
| 2179 | line_index += line_def->length; |
| 2180 | line_def = line_def->next; |
| 2181 | line--; |
| 2182 | } |
| 2183 | } |
| 2184 | return line_index; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | |
| 2188 | /********************************************************************* |
| 2189 | * |
| 2190 | * EM_LINELENGTH |
| 2191 | * |
| 2192 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2193 | static INT32 EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT32 index) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2194 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2195 | LINEDEF *line_def; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2196 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2197 | if (!(es->style & ES_MULTILINE)) |
| 2198 | return lstrlen32A(es->text); |
| 2199 | |
| 2200 | if (index == -1) { |
| 2201 | /* FIXME: broken |
| 2202 | INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start); |
| 2203 | INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end); |
| 2204 | return es->selection_start - es->line_defs[sl].offset + |
| 2205 | es->line_defs[el].offset + |
| 2206 | es->line_defs[el].length - es->selection_end; |
| 2207 | */ |
| 2208 | return 0; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 2209 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2210 | line_def = es->first_line_def; |
| 2211 | index -= line_def->length; |
| 2212 | while ((index >= 0) && line_def->next) { |
| 2213 | line_def = line_def->next; |
| 2214 | index -= line_def->length; |
| 2215 | } |
| 2216 | return line_def->net_length; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2217 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2218 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2219 | |
| 2220 | /********************************************************************* |
| 2221 | * |
| 2222 | * EM_LINESCROLL |
| 2223 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2224 | * FIXME: dx is in average character widths |
| 2225 | * However, we assume it is in pixels when we use this |
| 2226 | * function internally |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2227 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2228 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2229 | static BOOL32 EDIT_EM_LineScroll(WND *wnd, EDITSTATE *es, INT32 dx, INT32 dy) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2230 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2231 | INT32 nyoff; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2232 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2233 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2234 | return FALSE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2235 | |
| 2236 | if (-dx > es->x_offset) |
| 2237 | dx = -es->x_offset; |
| 2238 | if (dx > es->text_width - es->x_offset) |
| 2239 | dx = es->text_width - es->x_offset; |
| 2240 | nyoff = MAX(0, es->y_offset + dy); |
| 2241 | if (nyoff >= es->line_count) |
| 2242 | nyoff = es->line_count - 1; |
| 2243 | dy = (es->y_offset - nyoff) * es->line_height; |
| 2244 | if (dx || dy) { |
| 2245 | if (!(wnd->flags & WIN_NO_REDRAW)) { |
| 2246 | RECT32 rc1; |
| 2247 | RECT32 rc; |
| 2248 | GetClientRect32(wnd->hwndSelf, &rc1); |
| 2249 | IntersectRect32(&rc, &rc1, &es->format_rect); |
| 2250 | ScrollWindowEx32(wnd->hwndSelf, -dx, dy, |
| 2251 | NULL, &rc, (HRGN32)NULL, NULL, SW_INVALIDATE); |
| 2252 | } |
| 2253 | es->y_offset = nyoff; |
| 2254 | es->x_offset += dx; |
| 2255 | } |
| 2256 | if (dx && !(es->flags & EF_HSCROLL_TRACK)) |
| 2257 | EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); |
| 2258 | if (dy && !(es->flags & EF_VSCROLL_TRACK)) |
| 2259 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
| 2260 | return TRUE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2261 | } |
| 2262 | |
| 2263 | |
| 2264 | /********************************************************************* |
| 2265 | * |
| 2266 | * EM_POSFROMCHAR |
| 2267 | * |
| 2268 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2269 | static LRESULT EDIT_EM_PosFromChar(WND *wnd, EDITSTATE *es, INT32 index, BOOL32 after_wrap) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2270 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2271 | INT32 len = lstrlen32A(es->text); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2272 | INT32 l; |
| 2273 | INT32 li; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2274 | INT32 x; |
| 2275 | INT32 y = 0; |
| 2276 | HDC32 dc; |
| 2277 | HFONT32 old_font = 0; |
| 2278 | SIZE32 size; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2279 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2280 | index = MIN(index, len); |
| 2281 | dc = GetDC32(wnd->hwndSelf); |
| 2282 | if (es->font) |
| 2283 | old_font = SelectObject32(dc, es->font); |
| 2284 | if (es->style & ES_MULTILINE) { |
| 2285 | l = EDIT_EM_LineFromChar(wnd, es, index); |
| 2286 | y = (l - es->y_offset) * es->line_height; |
| 2287 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 2288 | if (after_wrap && (li == index) && l) { |
| 2289 | INT32 l2 = l - 1; |
| 2290 | LINEDEF *line_def = es->first_line_def; |
| 2291 | while (l2) { |
| 2292 | line_def = line_def->next; |
| 2293 | l2--; |
| 2294 | } |
| 2295 | if (line_def->ending == END_WRAP) { |
| 2296 | l--; |
| 2297 | y -= es->line_height; |
| 2298 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 2299 | } |
| 2300 | } |
| 2301 | x = LOWORD(GetTabbedTextExtent32A(dc, es->text + li, index - li, |
| 2302 | es->tabs_count, es->tabs)) - es->x_offset; |
| 2303 | } else { |
| 2304 | LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es); |
| 2305 | if (index < es->x_offset) { |
| 2306 | GetTextExtentPoint32A(dc, text + index, |
| 2307 | es->x_offset - index, &size); |
| 2308 | x = -size.cx; |
| 2309 | } else { |
| 2310 | GetTextExtentPoint32A(dc, text + es->x_offset, |
| 2311 | index - es->x_offset, &size); |
| 2312 | x = size.cx; |
| 2313 | } |
| 2314 | y = 0; |
| 2315 | if (es->style & ES_PASSWORD) |
| 2316 | HeapFree(es->heap, 0 ,text); |
| 2317 | } |
| 2318 | x += es->format_rect.left; |
| 2319 | y += es->format_rect.top; |
| 2320 | if (es->font) |
| 2321 | SelectObject32(dc, old_font); |
| 2322 | ReleaseDC32(wnd->hwndSelf, dc); |
| 2323 | return MAKELONG((INT16)x, (INT16)y); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | |
| 2327 | /********************************************************************* |
| 2328 | * |
| 2329 | * EM_REPLACESEL |
| 2330 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2331 | * FIXME: handle ES_NUMBER and ES_OEMCONVERT here |
| 2332 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2333 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2334 | static void EDIT_EM_ReplaceSel(WND *wnd, EDITSTATE *es, BOOL32 can_undo, LPCSTR lpsz_replace) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2335 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2336 | INT32 strl = lstrlen32A(lpsz_replace); |
| 2337 | INT32 tl = lstrlen32A(es->text); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2338 | INT32 utl; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2339 | UINT32 s; |
| 2340 | UINT32 e; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2341 | INT32 i; |
| 2342 | LPSTR p; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2343 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2344 | s = es->selection_start; |
| 2345 | e = es->selection_end; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2346 | |
| 2347 | if ((s == e) && !strl) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2348 | return; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2349 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2350 | ORDER_UINT32(s, e); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2351 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2352 | if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl)) |
| 2353 | return; |
| 2354 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2355 | if (e != s) { |
| 2356 | /* there is something to be deleted */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2357 | if (can_undo) { |
| 2358 | utl = lstrlen32A(es->undo_text); |
| 2359 | if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2360 | /* undo-buffer is extended to the right */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2361 | EDIT_MakeUndoFit(wnd, es, utl + e - s); |
| 2362 | lstrcpyn32A(es->undo_text + utl, es->text + s, e - s + 1); |
| 2363 | } else if (!es->undo_insert_count && (*es->undo_text && (e == es->undo_position))) { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2364 | /* undo-buffer is extended to the left */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2365 | EDIT_MakeUndoFit(wnd, es, utl + e - s); |
| 2366 | for (p = es->undo_text + utl ; p >= es->undo_text ; p--) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2367 | p[e - s] = p[0]; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2368 | for (i = 0 , p = es->undo_text ; i < e - s ; i++) |
| 2369 | p[i] = (es->text + s)[i]; |
| 2370 | es->undo_position = s; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2371 | } else { |
| 2372 | /* new undo-buffer */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2373 | EDIT_MakeUndoFit(wnd, es, e - s); |
| 2374 | lstrcpyn32A(es->undo_text, es->text + s, e - s + 1); |
| 2375 | es->undo_position = s; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2376 | } |
| 2377 | /* any deletion makes the old insertion-undo invalid */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2378 | es->undo_insert_count = 0; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2379 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2380 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2381 | |
| 2382 | /* now delete */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2383 | lstrcpy32A(es->text + s, es->text + e); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2384 | } |
| 2385 | if (strl) { |
| 2386 | /* there is an insertion */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2387 | if (can_undo) { |
| 2388 | if ((s == es->undo_position) || |
| 2389 | ((es->undo_insert_count) && |
| 2390 | (s == es->undo_position + es->undo_insert_count))) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2391 | /* |
| 2392 | * insertion is new and at delete position or |
| 2393 | * an extension to either left or right |
| 2394 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2395 | es->undo_insert_count += strl; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2396 | else { |
| 2397 | /* new insertion undo */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2398 | es->undo_position = s; |
| 2399 | es->undo_insert_count = strl; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2400 | /* new insertion makes old delete-buffer invalid */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2401 | *es->undo_text = '\0'; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2402 | } |
| 2403 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2404 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2405 | |
| 2406 | /* now insert */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2407 | tl = lstrlen32A(es->text); |
| 2408 | for (p = es->text + tl ; p >= es->text + s ; p--) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2409 | p[strl] = p[0]; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2410 | for (i = 0 , p = es->text + s ; i < strl ; i++) |
| 2411 | p[i] = lpsz_replace[i]; |
| 2412 | if(es->style & ES_UPPERCASE) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2413 | CharUpperBuff32A(p, strl); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2414 | else if(es->style & ES_LOWERCASE) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2415 | CharLowerBuff32A(p, strl); |
| 2416 | s += strl; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2417 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2418 | /* FIXME: really inefficient */ |
| 2419 | if (es->style & ES_MULTILINE) |
| 2420 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2421 | |
| 2422 | EDIT_EM_SetSel(wnd, es, s, s, FALSE); |
| 2423 | es->flags |= EF_MODIFIED; |
| 2424 | es->flags |= EF_UPDATE; |
| 2425 | EDIT_EM_ScrollCaret(wnd, es); |
| 2426 | |
| 2427 | /* FIXME: really inefficient */ |
| 2428 | if (!(wnd->flags & WIN_NO_REDRAW)) |
| 2429 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2430 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2431 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2432 | |
| 2433 | /********************************************************************* |
| 2434 | * |
| 2435 | * EM_SCROLL |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2436 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2437 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2438 | static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT32 action) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2439 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2440 | INT32 dy; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2441 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2442 | if (!(es->style & ES_MULTILINE)) |
| 2443 | return (LRESULT)FALSE; |
| 2444 | |
| 2445 | dy = 0; |
| 2446 | |
| 2447 | switch (action) { |
| 2448 | case SB_LINEUP: |
| 2449 | if (es->y_offset) |
| 2450 | dy = -1; |
| 2451 | break; |
| 2452 | case SB_LINEDOWN: |
| 2453 | if (es->y_offset < es->line_count - 1) |
| 2454 | dy = 1; |
| 2455 | break; |
| 2456 | case SB_PAGEUP: |
| 2457 | if (es->y_offset) |
| 2458 | dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 2459 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2460 | case SB_PAGEDOWN: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2461 | if (es->y_offset < es->line_count - 1) |
| 2462 | dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 2463 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2464 | default: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2465 | return (LRESULT)FALSE; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2466 | } |
| 2467 | if (dy) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2468 | EDIT_EM_LineScroll(wnd, es, 0, dy); |
| 2469 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2470 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2471 | return MAKELONG((INT16)dy, (BOOL16)TRUE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | |
| 2475 | /********************************************************************* |
| 2476 | * |
| 2477 | * EM_SETHANDLE |
| 2478 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2479 | * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? |
| 2480 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2481 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2482 | static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL32 hloc) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2483 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2484 | if (!(es->style & ES_MULTILINE)) |
| 2485 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2486 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2487 | if (!hloc) { |
| 2488 | fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n"); |
| 2489 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2490 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2491 | |
| 2492 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 2493 | /* |
| 2494 | * old buffer is freed by caller, unless |
| 2495 | * it is still in our own heap. (in that case |
| 2496 | * we free it, correcting the buggy caller.) |
| 2497 | */ |
| 2498 | if (es->text) |
| 2499 | HeapFree(es->heap, 0, es->text); |
| 2500 | |
| 2501 | es->hloc16 = (HLOCAL16)NULL; |
| 2502 | es->hloc32 = hloc; |
| 2503 | es->text = NULL; |
| 2504 | es->buffer_size = LocalSize32(es->hloc32) - 1; |
| 2505 | EDIT_LockBuffer(wnd, es); |
| 2506 | |
| 2507 | es->x_offset = es->y_offset = 0; |
| 2508 | es->selection_start = es->selection_end = 0; |
| 2509 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
| 2510 | es->flags &= ~EF_MODIFIED; |
| 2511 | es->flags &= ~EF_UPDATE; |
| 2512 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2513 | if (!(wnd->flags & WIN_NO_REDRAW)) |
| 2514 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2515 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | |
| 2519 | /********************************************************************* |
| 2520 | * |
| 2521 | * EM_SETHANDLE16 |
| 2522 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2523 | * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? |
| 2524 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2525 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2526 | static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2527 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2528 | if (!(es->style & ES_MULTILINE)) |
| 2529 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2530 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2531 | if (!hloc) { |
| 2532 | fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n"); |
| 2533 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2534 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2535 | |
| 2536 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 2537 | /* |
| 2538 | * old buffer is freed by caller, unless |
| 2539 | * it is still in our own heap. (in that case |
| 2540 | * we free it, correcting the buggy caller.) |
| 2541 | */ |
| 2542 | if (es->text) |
| 2543 | HeapFree(es->heap, 0, es->text); |
| 2544 | |
| 2545 | es->hloc16 = hloc; |
| 2546 | es->hloc32 = (HLOCAL32)NULL; |
| 2547 | es->text = NULL; |
| 2548 | es->buffer_size = LOCAL_Size(wnd->hInstance, es->hloc16) - 1; |
| 2549 | EDIT_LockBuffer(wnd, es); |
| 2550 | |
| 2551 | es->x_offset = es->y_offset = 0; |
| 2552 | es->selection_start = es->selection_end = 0; |
| 2553 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
| 2554 | es->flags &= ~EF_MODIFIED; |
| 2555 | es->flags &= ~EF_UPDATE; |
| 2556 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2557 | if (!(wnd->flags & WIN_NO_REDRAW)) |
| 2558 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2559 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | |
| 2563 | /********************************************************************* |
| 2564 | * |
| 2565 | * EM_SETLIMITTEXT |
| 2566 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2567 | * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF |
| 2568 | * However, the windows version is not complied to yet in all of edit.c |
| 2569 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2570 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2571 | static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT32 limit) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2572 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2573 | if (es->style & ES_MULTILINE) { |
| 2574 | if (limit) |
| 2575 | es->buffer_limit = MIN(limit, BUFLIMIT_MULTI); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2576 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2577 | es->buffer_limit = BUFLIMIT_MULTI; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2578 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2579 | if (limit) |
| 2580 | es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2581 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2582 | es->buffer_limit = BUFLIMIT_SINGLE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2583 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | |
| 2587 | /********************************************************************* |
| 2588 | * |
| 2589 | * EM_SETMARGINS |
| 2590 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2591 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2592 | static void EDIT_EM_SetMargins(WND *wnd, EDITSTATE *es, INT32 action, INT32 left, INT32 right) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2593 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2594 | if (action & EC_USEFONTINFO) { |
| 2595 | if (es->style & ES_MULTILINE) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2596 | /* |
| 2597 | * FIXME: do some GetABCCharWidth, or so |
| 2598 | * This is just preliminary |
| 2599 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2600 | es->left_margin = es->right_margin = es->char_width; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2601 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2602 | es->left_margin = es->right_margin = es->char_width; |
| 2603 | return; |
| 2604 | } else { |
| 2605 | if (action & EC_LEFTMARGIN) |
| 2606 | es->left_margin = left; |
| 2607 | if (action & EC_RIGHTMARGIN) |
| 2608 | es->right_margin = right; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2609 | } |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2610 | } |
| 2611 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2612 | |
| 2613 | /********************************************************************* |
| 2614 | * |
| 2615 | * EM_SETPASSWORDCHAR |
| 2616 | * |
| 2617 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2618 | static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2619 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2620 | if (es->style & ES_MULTILINE) |
| 2621 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2622 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2623 | if (es->password_char == c) |
| 2624 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2625 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2626 | es->password_char = c; |
| 2627 | if (c) { |
| 2628 | wnd->dwStyle |= ES_PASSWORD; |
| 2629 | es->style |= ES_PASSWORD; |
| 2630 | } else { |
| 2631 | wnd->dwStyle &= ~ES_PASSWORD; |
| 2632 | es->style &= ~ES_PASSWORD; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2633 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2634 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | /********************************************************************* |
| 2639 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2640 | * EDIT_EM_SetSel |
| 2641 | * |
| 2642 | * note: unlike the specs say: the order of start and end |
| 2643 | * _is_ preserved in Windows. (i.e. start can be > end) |
| 2644 | * In other words: this handler is OK |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2645 | * |
| 2646 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2647 | static void EDIT_EM_SetSel(WND *wnd, EDITSTATE *es, UINT32 start, UINT32 end, BOOL32 after_wrap) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2648 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2649 | UINT32 old_start = es->selection_start; |
| 2650 | UINT32 old_end = es->selection_end; |
| 2651 | UINT32 len = lstrlen32A(es->text); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2652 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2653 | if (start == -1) { |
| 2654 | start = es->selection_end; |
| 2655 | end = es->selection_end; |
| 2656 | } else { |
| 2657 | start = MIN(start, len); |
| 2658 | end = MIN(end, len); |
| 2659 | } |
| 2660 | es->selection_start = start; |
| 2661 | es->selection_end = end; |
| 2662 | if (after_wrap) |
| 2663 | es->flags |= EF_AFTER_WRAP; |
| 2664 | else |
| 2665 | es->flags &= ~EF_AFTER_WRAP; |
| 2666 | if (!(wnd->flags & WIN_NO_REDRAW)) { |
| 2667 | if (es->flags & EF_FOCUSED) { |
| 2668 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, end, after_wrap); |
| 2669 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
| 2670 | } |
| 2671 | /* FIXME: little efficiency, could be better */ |
| 2672 | ORDER_UINT32(start, end); |
| 2673 | ORDER_UINT32(start, old_start); |
| 2674 | ORDER_UINT32(start, old_end); |
| 2675 | ORDER_UINT32(end, old_start); |
| 2676 | ORDER_UINT32(end, old_end); |
| 2677 | ORDER_UINT32(old_start, old_end); |
| 2678 | if (end != old_start) { |
| 2679 | EDIT_InvalidateText(wnd, es, start, end); |
| 2680 | EDIT_InvalidateText(wnd, es, old_start, old_end); |
| 2681 | } else |
| 2682 | EDIT_InvalidateText(wnd, es, start, old_end); |
| 2683 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | |
| 2687 | /********************************************************************* |
| 2688 | * |
| 2689 | * EM_SETTABSTOPS |
| 2690 | * |
| 2691 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2692 | static BOOL32 EDIT_EM_SetTabStops(WND *wnd, EDITSTATE *es, INT32 count, LPINT32 tabs) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2693 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2694 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2695 | return FALSE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2696 | if (es->tabs) |
| 2697 | HeapFree(es->heap, 0, es->tabs); |
| 2698 | es->tabs_count = count; |
| 2699 | if (!count) |
| 2700 | es->tabs = NULL; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2701 | else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2702 | es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32)); |
| 2703 | memcpy(es->tabs, tabs, count * sizeof(INT32)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2704 | } |
| 2705 | return TRUE; |
| 2706 | } |
| 2707 | |
| 2708 | |
| 2709 | /********************************************************************* |
| 2710 | * |
| 2711 | * EM_SETTABSTOPS16 |
| 2712 | * |
| 2713 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2714 | static BOOL32 EDIT_EM_SetTabStops16(WND *wnd, EDITSTATE *es, INT32 count, LPINT16 tabs) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2715 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2716 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2717 | return FALSE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2718 | if (es->tabs) |
| 2719 | HeapFree(es->heap, 0, es->tabs); |
| 2720 | es->tabs_count = count; |
| 2721 | if (!count) |
| 2722 | es->tabs = NULL; |
| 2723 | else { |
| 2724 | INT32 i; |
| 2725 | es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32)); |
| 2726 | for (i = 0 ; i < count ; i++) |
| 2727 | es->tabs[i] = *tabs++; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2728 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2729 | return TRUE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | |
| 2733 | /********************************************************************* |
| 2734 | * |
| 2735 | * EM_SETWORDBREAKPROC |
| 2736 | * |
| 2737 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2738 | static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC32A wbp) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2739 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2740 | if (es->word_break_proc32A == wbp) |
| 2741 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2742 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2743 | es->word_break_proc32A = wbp; |
| 2744 | es->word_break_proc16 = NULL; |
| 2745 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { |
| 2746 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2747 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | |
| 2752 | /********************************************************************* |
| 2753 | * |
| 2754 | * EM_SETWORDBREAKPROC16 |
| 2755 | * |
| 2756 | */ |
| 2757 | static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp) |
| 2758 | { |
| 2759 | if (es->word_break_proc16 == wbp) |
| 2760 | return; |
| 2761 | |
| 2762 | es->word_break_proc32A = NULL; |
| 2763 | es->word_break_proc16 = wbp; |
| 2764 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { |
| 2765 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2766 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2767 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | |
| 2771 | /********************************************************************* |
| 2772 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2773 | * EM_UNDO / WM_UNDO |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2774 | * |
| 2775 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2776 | static BOOL32 EDIT_EM_Undo(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2777 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2778 | INT32 ulength = lstrlen32A(es->undo_text); |
| 2779 | LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1); |
| 2780 | |
| 2781 | lstrcpy32A(utext, es->undo_text); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2782 | |
| 2783 | dprintf_edit(stddeb, "edit: before UNDO:insertion length = %d, deletion buffer = %s\n", |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2784 | es->undo_insert_count, utext); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2785 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2786 | EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); |
| 2787 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
| 2788 | EDIT_EM_ReplaceSel(wnd, es, TRUE, utext); |
| 2789 | EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); |
| 2790 | HeapFree(es->heap, 0, utext); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2791 | |
| 2792 | dprintf_edit(stddeb, "edit: after UNDO: insertion length = %d, deletion buffer = %s\n", |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2793 | es->undo_insert_count, es->undo_text); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2794 | |
| 2795 | return TRUE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | |
| 2799 | /********************************************************************* |
| 2800 | * |
| 2801 | * WM_CHAR |
| 2802 | * |
| 2803 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2804 | static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, CHAR c, DWORD key_data) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2805 | { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2806 | switch (c) { |
| 2807 | case '\r': |
| 2808 | case '\n': |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2809 | if (es->style & ES_MULTILINE) { |
| 2810 | if (es->style & ES_READONLY) { |
| 2811 | EDIT_MoveHome(wnd, es, FALSE); |
| 2812 | EDIT_MoveDown_ML(wnd, es, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2813 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2814 | EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2815 | } |
| 2816 | break; |
| 2817 | case '\t': |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2818 | if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) |
| 2819 | EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2820 | break; |
| 2821 | default: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2822 | if (!(es->style & ES_READONLY) && (c >= ' ') && (c != 127)) { |
| 2823 | char str[2]; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2824 | str[0] = c; |
| 2825 | str[1] = '\0'; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2826 | EDIT_EM_ReplaceSel(wnd, es, TRUE, str); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2827 | } |
| 2828 | break; |
| 2829 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | /********************************************************************* |
| 2834 | * |
| 2835 | * WM_COMMAND |
| 2836 | * |
| 2837 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2838 | static void EDIT_WM_Command(WND *wnd, EDITSTATE *es, INT32 code, INT32 id, HWND32 control) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2839 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2840 | if (code || control) |
| 2841 | return; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2842 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2843 | switch (id) { |
| 2844 | case EM_UNDO32: |
| 2845 | EDIT_EM_Undo(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2846 | break; |
| 2847 | case WM_CUT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2848 | EDIT_WM_Cut(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2849 | break; |
| 2850 | case WM_COPY: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2851 | EDIT_WM_Copy(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | case WM_PASTE: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2854 | EDIT_WM_Paste(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2855 | break; |
| 2856 | case WM_CLEAR: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2857 | EDIT_WM_Clear(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2858 | break; |
| 2859 | case EM_SETSEL32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2860 | EDIT_EM_SetSel(wnd, es, 0, -1, FALSE); |
| 2861 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2862 | break; |
| 2863 | default: |
| 2864 | dprintf_edit(stddeb, "edit: unknown menu item, please report\n"); |
| 2865 | break; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2866 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | |
| 2870 | /********************************************************************* |
| 2871 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2872 | * WM_CONTEXTMENU |
| 2873 | * |
| 2874 | * Note: the resource files resource/sysres_??.rc cannot define a |
| 2875 | * single popup menu. Hence we use a (dummy) menubar |
| 2876 | * containing the single popup menu as its first item. |
| 2877 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2878 | * FIXME: the message identifiers have been chosen arbitrarily, |
| 2879 | * hence we use MF_BYPOSITION. |
| 2880 | * We might as well use the "real" values (anybody knows ?) |
| 2881 | * The menu definition is in resources/sysres_??.rc. |
| 2882 | * Once these are OK, we better use MF_BYCOMMAND here |
| 2883 | * (as we do in EDIT_WM_Command()). |
| 2884 | * |
| 2885 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2886 | static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, HWND32 hwnd, INT32 x, INT32 y) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2887 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2888 | HMENU32 menu = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU)); |
| 2889 | HMENU32 popup = GetSubMenu32(menu, 0); |
| 2890 | UINT32 start = es->selection_start; |
| 2891 | UINT32 end = es->selection_end; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2892 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2893 | ORDER_UINT32(start, end); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2894 | |
| 2895 | /* undo */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2896 | EnableMenuItem32(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(wnd, es) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2897 | /* cut */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2898 | EnableMenuItem32(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2899 | /* copy */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2900 | EnableMenuItem32(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2901 | /* paste */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2902 | EnableMenuItem32(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable32(CF_TEXT) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2903 | /* delete */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2904 | EnableMenuItem32(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2905 | /* select all */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2906 | EnableMenuItem32(popup, 7, MF_BYPOSITION | (start || (end != lstrlen32A(es->text)) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2907 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2908 | TrackPopupMenu32(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL); |
| 2909 | DestroyMenu32(menu); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2910 | } |
| 2911 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2912 | |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2913 | /********************************************************************* |
| 2914 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2915 | * WM_COPY |
| 2916 | * |
| 2917 | * FIXME: replace with 32 bit calls as soon as they are implemented |
| 2918 | * in the clipboard code |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2919 | * |
| 2920 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2921 | static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2922 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2923 | INT32 s = es->selection_start; |
| 2924 | INT32 e = es->selection_end; |
| 2925 | HGLOBAL16 hdst; |
| 2926 | LPSTR dst; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2927 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2928 | if (e == s) |
| 2929 | return; |
| 2930 | ORDER_INT32(s, e); |
| 2931 | hdst = GlobalAlloc16(GMEM_MOVEABLE, (DWORD)(e - s + 1)); |
| 2932 | dst = GlobalLock16(hdst); |
| 2933 | lstrcpyn32A(dst, es->text + s, e - s + 1); |
| 2934 | GlobalUnlock16(hdst); |
| 2935 | OpenClipboard32(wnd->hwndSelf); |
| 2936 | EmptyClipboard32(); |
| 2937 | SetClipboardData16(CF_TEXT, hdst); |
| 2938 | CloseClipboard32(); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2939 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2940 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2941 | |
| 2942 | /********************************************************************* |
| 2943 | * |
| 2944 | * WM_CREATE |
| 2945 | * |
| 2946 | */ |
| 2947 | static LRESULT EDIT_WM_Create(WND *wnd, LPCREATESTRUCT32A cs) |
| 2948 | { |
| 2949 | EDITSTATE *es; |
| 2950 | |
| 2951 | if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es)))) |
| 2952 | return -1; |
| 2953 | *(EDITSTATE **)wnd->wExtra = es; |
| 2954 | if (!(es->heap = HeapCreate(0, 0x10000, 0))) |
| 2955 | return -1; |
| 2956 | es->style = cs->style; |
| 2957 | |
| 2958 | /* remove the WS_CAPTION style if it has been set - this is really a */ |
| 2959 | /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */ |
| 2960 | if ((es->style & WS_BORDER) && (es->style & WS_DLGFRAME)) |
| 2961 | es->style ^= WS_DLGFRAME; |
| 2962 | |
| 2963 | if (es->style & ES_MULTILINE) { |
| 2964 | es->buffer_size = BUFSTART_MULTI; |
| 2965 | es->buffer_limit = BUFLIMIT_MULTI; |
| 2966 | if (es->style & WS_VSCROLL) |
| 2967 | es->style |= ES_AUTOVSCROLL; |
| 2968 | if (es->style & WS_HSCROLL) |
| 2969 | es->style |= ES_AUTOHSCROLL; |
| 2970 | es->style &= ~ES_PASSWORD; |
| 2971 | if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) { |
| 2972 | if (es->style & ES_RIGHT) |
| 2973 | es->style &= ~ES_CENTER; |
| 2974 | es->style &= ~WS_HSCROLL; |
| 2975 | es->style &= ~ES_AUTOHSCROLL; |
| 2976 | } |
| 2977 | |
| 2978 | /* FIXME: for now, all multi line controls are AUTOVSCROLL */ |
| 2979 | es->style |= ES_AUTOVSCROLL; |
| 2980 | } else { |
| 2981 | es->buffer_size = BUFSTART_SINGLE; |
| 2982 | es->buffer_limit = BUFLIMIT_SINGLE; |
| 2983 | es->style &= ~ES_CENTER; |
| 2984 | es->style &= ~ES_RIGHT; |
| 2985 | es->style &= ~WS_HSCROLL; |
| 2986 | es->style &= ~WS_VSCROLL; |
| 2987 | es->style &= ~ES_AUTOVSCROLL; |
| 2988 | es->style &= ~ES_WANTRETURN; |
| 2989 | if (es->style & ES_UPPERCASE) { |
| 2990 | es->style &= ~ES_LOWERCASE; |
| 2991 | es->style &= ~ES_NUMBER; |
| 2992 | } else if (es->style & ES_LOWERCASE) |
| 2993 | es->style &= ~ES_NUMBER; |
| 2994 | if (es->style & ES_PASSWORD) |
| 2995 | es->password_char = '*'; |
| 2996 | |
| 2997 | /* FIXME: for now, all single line controls are AUTOHSCROLL */ |
| 2998 | es->style |= ES_AUTOHSCROLL; |
| 2999 | } |
| 3000 | if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1))) |
| 3001 | return -1; |
| 3002 | es->buffer_size = HeapSize(es->heap, 0, es->text) - 1; |
| 3003 | if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1))) |
| 3004 | return -1; |
| 3005 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; |
| 3006 | *es->text = '\0'; |
| 3007 | if (es->style & ES_MULTILINE) |
| 3008 | if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF)))) |
| 3009 | return -1; |
| 3010 | es->line_count = 1; |
| 3011 | /* |
| 3012 | * To initialize some final structure members, we call some helper |
| 3013 | * functions. However, since the EDITSTATE is not consistent (i.e. |
| 3014 | * not fully initialized), we should be very careful which |
| 3015 | * functions can be called, and in what order. |
| 3016 | */ |
| 3017 | EDIT_WM_SetFont(wnd, es, 0, FALSE); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 3018 | if (cs->lpszName && *(cs->lpszName) != '\0') { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3019 | EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 3020 | /* if we insert text to the editline, the text scrolls out of the window, as the caret is placed after the insert pos normally; thus we reset es->selection... to 0 and update caret */ |
| 3021 | es->selection_start = es->selection_end = 0; |
| 3022 | EDIT_EM_ScrollCaret(wnd, es); |
| 3023 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3024 | return 0; |
| 3025 | } |
| 3026 | |
| 3027 | |
| 3028 | /********************************************************************* |
| 3029 | * |
| 3030 | * WM_DESTROY |
| 3031 | * |
| 3032 | */ |
| 3033 | static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es) |
| 3034 | { |
| 3035 | if (es->hloc32) { |
| 3036 | while (LocalUnlock32(es->hloc32)) ; |
| 3037 | LocalFree32(es->hloc32); |
| 3038 | } |
| 3039 | if (es->hloc16) { |
| 3040 | while (LOCAL_Unlock(wnd->hInstance, es->hloc16)) ; |
| 3041 | LOCAL_Free(wnd->hInstance, es->hloc16); |
| 3042 | } |
| 3043 | HeapDestroy(es->heap); |
| 3044 | HeapFree(GetProcessHeap(), 0, es); |
| 3045 | *(EDITSTATE **)wnd->wExtra = NULL; |
| 3046 | } |
| 3047 | |
| 3048 | |
| 3049 | /********************************************************************* |
| 3050 | * |
| 3051 | * WM_ERASEBKGND |
| 3052 | * |
| 3053 | */ |
| 3054 | static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC32 dc) |
| 3055 | { |
| 3056 | HBRUSH32 brush; |
| 3057 | RECT32 rc; |
| 3058 | |
| 3059 | if (!(brush = (HBRUSH32)EDIT_SEND_CTLCOLOR(wnd, dc))) |
| 3060 | brush = (HBRUSH32)GetStockObject32(WHITE_BRUSH); |
| 3061 | |
| 3062 | GetClientRect32(wnd->hwndSelf, &rc); |
| 3063 | IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom); |
| 3064 | GetClipBox32(dc, &rc); |
| 3065 | /* |
| 3066 | * FIXME: specs say that we should UnrealizeObject() the brush, |
| 3067 | * but the specs of UnrealizeObject() say that we shouldn't |
| 3068 | * unrealize a stock object. The default brush that |
| 3069 | * DefWndProc() returns is ... a stock object. |
| 3070 | */ |
| 3071 | FillRect32(dc, &rc, brush); |
| 3072 | return -1; |
| 3073 | } |
| 3074 | |
| 3075 | |
| 3076 | /********************************************************************* |
| 3077 | * |
| 3078 | * WM_GETTEXT |
| 3079 | * |
| 3080 | */ |
| 3081 | static INT32 EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT32 count, LPSTR text) |
| 3082 | { |
| 3083 | INT32 len = lstrlen32A(es->text); |
| 3084 | |
| 3085 | if (count > len) { |
| 3086 | lstrcpy32A(text, es->text); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 3087 | return len; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3088 | } else |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 3089 | return -1; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3090 | } |
| 3091 | |
| 3092 | |
| 3093 | /********************************************************************* |
| 3094 | * |
| 3095 | * EDIT_HScroll_Hack |
| 3096 | * |
| 3097 | * 16 bit notepad needs this. Actually it is not _our_ hack, |
| 3098 | * it is notepad's. Notepad is sending us scrollbar messages with |
| 3099 | * undocumented parameters without us even having a scrollbar ... !?!? |
| 3100 | * |
| 3101 | */ |
| 3102 | static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
| 3103 | { |
| 3104 | INT32 dx = 0; |
| 3105 | INT32 fw = es->format_rect.right - es->format_rect.left; |
| 3106 | LRESULT ret = 0; |
| 3107 | |
| 3108 | if (!(es->flags & EF_HSCROLL_HACK)) { |
| 3109 | fprintf(stderr, "edit: hacked WM_HSCROLL handler invoked\n"); |
| 3110 | fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n"); |
| 3111 | fprintf(stderr, " (this message is only displayed once per edit control)\n"); |
| 3112 | es->flags |= EF_HSCROLL_HACK; |
| 3113 | } |
| 3114 | |
| 3115 | switch (action) { |
| 3116 | case SB_LINELEFT: |
| 3117 | if (es->x_offset) |
| 3118 | dx = -es->char_width; |
| 3119 | break; |
| 3120 | case SB_LINERIGHT: |
| 3121 | if (es->x_offset < es->text_width) |
| 3122 | dx = es->char_width; |
| 3123 | break; |
| 3124 | case SB_PAGELEFT: |
| 3125 | if (es->x_offset) |
| 3126 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3127 | break; |
| 3128 | case SB_PAGERIGHT: |
| 3129 | if (es->x_offset < es->text_width) |
| 3130 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3131 | break; |
| 3132 | case SB_LEFT: |
| 3133 | if (es->x_offset) |
| 3134 | dx = -es->x_offset; |
| 3135 | break; |
| 3136 | case SB_RIGHT: |
| 3137 | if (es->x_offset < es->text_width) |
| 3138 | dx = es->text_width - es->x_offset; |
| 3139 | break; |
| 3140 | case SB_THUMBTRACK: |
| 3141 | es->flags |= EF_HSCROLL_TRACK; |
| 3142 | dx = pos * es->text_width / 100 - es->x_offset; |
| 3143 | break; |
| 3144 | case SB_THUMBPOSITION: |
| 3145 | es->flags &= ~EF_HSCROLL_TRACK; |
| 3146 | if (!(dx = pos * es->text_width / 100 - es->x_offset)) |
| 3147 | EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); |
| 3148 | break; |
| 3149 | case SB_ENDSCROLL: |
| 3150 | break; |
| 3151 | |
| 3152 | /* |
| 3153 | * FIXME : the next two are undocumented ! |
| 3154 | * Are we doing the right thing ? |
| 3155 | * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, |
| 3156 | * although it's also a regular control message. |
| 3157 | */ |
| 3158 | case EM_GETTHUMB16: |
| 3159 | ret = es->text_width ? es->x_offset * 100 / es->text_width : 0; |
| 3160 | break; |
| 3161 | case EM_LINESCROLL16: |
| 3162 | dx = pos; |
| 3163 | break; |
| 3164 | |
| 3165 | default: |
| 3166 | dprintf_edit(stddeb, "edit: undocumented (hacked) WM_HSCROLL parameter, please report\n"); |
| 3167 | return 0; |
| 3168 | } |
| 3169 | if (dx) |
| 3170 | EDIT_EM_LineScroll(wnd, es, dx, 0); |
| 3171 | return ret; |
| 3172 | } |
| 3173 | |
| 3174 | |
| 3175 | /********************************************************************* |
| 3176 | * |
| 3177 | * WM_HSCROLL |
| 3178 | * |
| 3179 | */ |
| 3180 | static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
| 3181 | { |
| 3182 | INT32 dx; |
| 3183 | INT32 fw; |
| 3184 | |
| 3185 | if (!(es->style & ES_MULTILINE)) |
| 3186 | return 0; |
| 3187 | |
| 3188 | if (!(es->style & ES_AUTOHSCROLL)) |
| 3189 | return 0; |
| 3190 | |
| 3191 | if (!(es->style & WS_HSCROLL)) |
| 3192 | return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar); |
| 3193 | |
| 3194 | dx = 0; |
| 3195 | fw = es->format_rect.right - es->format_rect.left; |
| 3196 | switch (action) { |
| 3197 | case SB_LINELEFT: |
| 3198 | if (es->x_offset) |
| 3199 | dx = -es->char_width; |
| 3200 | break; |
| 3201 | case SB_LINERIGHT: |
| 3202 | if (es->x_offset < es->text_width) |
| 3203 | dx = es->char_width; |
| 3204 | break; |
| 3205 | case SB_PAGELEFT: |
| 3206 | if (es->x_offset) |
| 3207 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3208 | break; |
| 3209 | case SB_PAGERIGHT: |
| 3210 | if (es->x_offset < es->text_width) |
| 3211 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3212 | break; |
| 3213 | case SB_LEFT: |
| 3214 | if (es->x_offset) |
| 3215 | dx = -es->x_offset; |
| 3216 | break; |
| 3217 | case SB_RIGHT: |
| 3218 | if (es->x_offset < es->text_width) |
| 3219 | dx = es->text_width - es->x_offset; |
| 3220 | break; |
| 3221 | case SB_THUMBTRACK: |
| 3222 | es->flags |= EF_HSCROLL_TRACK; |
| 3223 | dx = pos - es->x_offset; |
| 3224 | break; |
| 3225 | case SB_THUMBPOSITION: |
| 3226 | es->flags &= ~EF_HSCROLL_TRACK; |
| 3227 | if (!(dx = pos - es->x_offset)) { |
| 3228 | SetScrollPos32(wnd->hwndSelf, SB_HORZ, pos, TRUE); |
| 3229 | EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); |
| 3230 | } |
| 3231 | break; |
| 3232 | case SB_ENDSCROLL: |
| 3233 | break; |
| 3234 | |
| 3235 | default: |
| 3236 | fprintf(stderr, "edit: undocumented WM_HSCROLL parameter, please report\n"); |
| 3237 | return 0; |
| 3238 | } |
| 3239 | if (dx) |
| 3240 | EDIT_EM_LineScroll(wnd, es, dx, 0); |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
| 3244 | |
| 3245 | /********************************************************************* |
| 3246 | * |
| 3247 | * EDIT_CheckCombo |
| 3248 | * |
| 3249 | */ |
| 3250 | static BOOL32 EDIT_CheckCombo(WND *wnd, UINT32 msg, INT32 key, DWORD key_data) |
| 3251 | { |
| 3252 | HWND32 hLBox; |
| 3253 | |
| 3254 | if (WIDGETS_IsControl32(wnd->parent, BIC32_COMBO) && |
| 3255 | (hLBox = COMBO_GetLBWindow(wnd->parent))) { |
| 3256 | HWND32 hCombo = wnd->parent->hwndSelf; |
| 3257 | BOOL32 bUIFlip = TRUE; |
| 3258 | |
| 3259 | dprintf_combo(stddeb, "EDIT_CheckCombo [%04x]: handling msg %04x (%04x)\n", |
| 3260 | wnd->hwndSelf, (UINT16)msg, (UINT16)key); |
| 3261 | |
| 3262 | switch (msg) { |
| 3263 | case WM_KEYDOWN: /* Handle F4 and arrow keys */ |
| 3264 | if (key != VK_F4) { |
| 3265 | bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0); |
| 3266 | if (SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0)) |
| 3267 | bUIFlip = FALSE; |
| 3268 | } |
| 3269 | if (!bUIFlip) |
| 3270 | SendMessage32A(hLBox, WM_KEYDOWN, (WPARAM32)key, 0); |
| 3271 | else { |
| 3272 | /* make sure ComboLBox pops up */ |
| 3273 | SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 0, 0); |
| 3274 | SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0); |
| 3275 | SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 1, 0); |
| 3276 | } |
| 3277 | break; |
| 3278 | case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */ |
| 3279 | bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0); |
| 3280 | if (bUIFlip) { |
| 3281 | bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0); |
| 3282 | SendMessage32A(hCombo, CB_SHOWDROPDOWN32, (bUIFlip) ? FALSE : TRUE, 0); |
| 3283 | } else |
| 3284 | SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0); |
| 3285 | break; |
| 3286 | } |
| 3287 | return TRUE; |
| 3288 | } |
| 3289 | return FALSE; |
| 3290 | } |
| 3291 | |
| 3292 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3293 | /********************************************************************* |
| 3294 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3295 | * WM_KEYDOWN |
| 3296 | * |
| 3297 | * Handling of special keys that don't produce a WM_CHAR |
| 3298 | * (i.e. non-printable keys) & Backspace & Delete |
| 3299 | * |
| 3300 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3301 | static LRESULT EDIT_WM_KeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3302 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3303 | BOOL32 shift; |
| 3304 | BOOL32 control; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3305 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 3306 | if (GetKeyState32(VK_MENU) & 0x8000) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3307 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3308 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 3309 | shift = GetKeyState32(VK_SHIFT) & 0x8000; |
| 3310 | control = GetKeyState32(VK_CONTROL) & 0x8000; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3311 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3312 | switch (key) { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3313 | case VK_F4: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3314 | case VK_UP: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3315 | if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data)) |
| 3316 | break; |
| 3317 | if (key == VK_F4) |
| 3318 | break; |
| 3319 | /* fall through */ |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3320 | case VK_LEFT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3321 | if ((es->style & ES_MULTILINE) && (key == VK_UP)) |
| 3322 | EDIT_MoveUp_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3323 | else |
| 3324 | if (control) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3325 | EDIT_MoveWordBackward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3326 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3327 | EDIT_MoveBackward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3328 | break; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3329 | case VK_DOWN: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3330 | if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data)) |
| 3331 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3332 | /* fall through */ |
| 3333 | case VK_RIGHT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3334 | if ((es->style & ES_MULTILINE) && (key == VK_DOWN)) |
| 3335 | EDIT_MoveDown_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3336 | else if (control) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3337 | EDIT_MoveWordForward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3338 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3339 | EDIT_MoveForward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3340 | break; |
| 3341 | case VK_HOME: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3342 | EDIT_MoveHome(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3343 | break; |
| 3344 | case VK_END: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3345 | EDIT_MoveEnd(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3346 | break; |
| 3347 | case VK_PRIOR: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3348 | if (es->style & ES_MULTILINE) |
| 3349 | EDIT_MovePageUp_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3350 | break; |
| 3351 | case VK_NEXT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3352 | if (es->style & ES_MULTILINE) |
| 3353 | EDIT_MovePageDown_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3354 | break; |
| 3355 | case VK_BACK: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3356 | if (!(es->style & ES_READONLY) && !control) |
| 3357 | if (es->selection_start != es->selection_end) |
| 3358 | EDIT_WM_Clear(wnd, es); |
| 3359 | else { |
| 3360 | /* delete character left of caret */ |
| 3361 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3362 | EDIT_MoveBackward(wnd, es, TRUE); |
| 3363 | EDIT_WM_Clear(wnd, es); |
| 3364 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3365 | break; |
| 3366 | case VK_DELETE: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3367 | if (!(es->style & ES_READONLY) && !(shift && control)) |
| 3368 | if (es->selection_start != es->selection_end) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3369 | if (shift) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3370 | EDIT_WM_Cut(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3371 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3372 | EDIT_WM_Clear(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3373 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3374 | if (shift) { |
| 3375 | /* delete character left of caret */ |
| 3376 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3377 | EDIT_MoveBackward(wnd, es, TRUE); |
| 3378 | EDIT_WM_Clear(wnd, es); |
| 3379 | } else if (control) { |
| 3380 | /* delete to end of line */ |
| 3381 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3382 | EDIT_MoveEnd(wnd, es, TRUE); |
| 3383 | EDIT_WM_Clear(wnd, es); |
| 3384 | } else { |
| 3385 | /* delete character right of caret */ |
| 3386 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3387 | EDIT_MoveForward(wnd, es, TRUE); |
| 3388 | EDIT_WM_Clear(wnd, es); |
| 3389 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3390 | } |
| 3391 | break; |
| 3392 | case VK_INSERT: |
| 3393 | if (shift) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3394 | if (!(es->style & ES_READONLY)) |
| 3395 | EDIT_WM_Paste(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3396 | } else if (control) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3397 | EDIT_WM_Copy(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3398 | break; |
| 3399 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3400 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | |
| 3404 | /********************************************************************* |
| 3405 | * |
| 3406 | * WM_KILLFOCUS |
| 3407 | * |
| 3408 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3409 | static LRESULT EDIT_WM_KillFocus(WND *wnd, EDITSTATE *es, HWND32 window_getting_focus) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3410 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3411 | es->flags &= ~EF_FOCUSED; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 3412 | DestroyCaret32(); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3413 | if(!(es->style & ES_NOHIDESEL)) |
| 3414 | EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end); |
| 3415 | EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3416 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3417 | } |
| 3418 | |
| 3419 | |
| 3420 | /********************************************************************* |
| 3421 | * |
| 3422 | * WM_LBUTTONDBLCLK |
| 3423 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 3424 | * The caret position has been set on the WM_LBUTTONDOWN message |
| 3425 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3426 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3427 | static LRESULT EDIT_WM_LButtonDblClk(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3428 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3429 | INT32 s; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3430 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3431 | INT32 l; |
| 3432 | INT32 li; |
| 3433 | INT32 ll; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3434 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3435 | if (!(es->flags & EF_FOCUSED)) |
| 3436 | return 0; |
| 3437 | |
| 3438 | l = EDIT_EM_LineFromChar(wnd, es, e); |
| 3439 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 3440 | ll = EDIT_EM_LineLength(wnd, es, e); |
| 3441 | s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT); |
| 3442 | e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT); |
| 3443 | EDIT_EM_SetSel(wnd, es, s, e, FALSE); |
| 3444 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3445 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | |
| 3449 | /********************************************************************* |
| 3450 | * |
| 3451 | * WM_LBUTTONDOWN |
| 3452 | * |
| 3453 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3454 | static LRESULT EDIT_WM_LButtonDown(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3455 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3456 | INT32 e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3457 | BOOL32 after_wrap; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3458 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3459 | if (!(es->flags & EF_FOCUSED)) |
| 3460 | return 0; |
| 3461 | |
| 3462 | SetCapture32(wnd->hwndSelf); |
| 3463 | EDIT_ConfinePoint(wnd, es, &x, &y); |
| 3464 | e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap); |
| 3465 | EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap); |
| 3466 | EDIT_EM_ScrollCaret(wnd, es); |
| 3467 | SetTimer32(wnd->hwndSelf, 0, 100, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3468 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | |
| 3472 | /********************************************************************* |
| 3473 | * |
| 3474 | * WM_LBUTTONUP |
| 3475 | * |
| 3476 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3477 | static LRESULT EDIT_WM_LButtonUp(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3478 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3479 | if (GetCapture32() == wnd->hwndSelf) { |
| 3480 | KillTimer32(wnd->hwndSelf, 0); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3481 | ReleaseCapture(); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3482 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3483 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3484 | } |
| 3485 | |
| 3486 | |
| 3487 | /********************************************************************* |
| 3488 | * |
| 3489 | * WM_MOUSEMOVE |
| 3490 | * |
| 3491 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3492 | static LRESULT EDIT_WM_MouseMove(WND *wnd, EDITSTATE *es, DWORD keys, INT32 x, INT32 y) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3493 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3494 | INT32 e; |
| 3495 | BOOL32 after_wrap; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3496 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3497 | if (GetCapture32() != wnd->hwndSelf) |
| 3498 | return 0; |
| 3499 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3500 | /* |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3501 | * FIXME: gotta do some scrolling if outside client |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3502 | * area. Maybe reset the timer ? |
| 3503 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3504 | EDIT_ConfinePoint(wnd, es, &x, &y); |
| 3505 | e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap); |
| 3506 | EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3507 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | |
| 3511 | /********************************************************************* |
| 3512 | * |
| 3513 | * WM_PAINT |
| 3514 | * |
| 3515 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3516 | static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3517 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3518 | PAINTSTRUCT32 ps; |
| 3519 | INT32 i; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3520 | HDC32 dc; |
| 3521 | HFONT32 old_font = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3522 | RECT32 rc; |
| 3523 | RECT32 rcLine; |
| 3524 | RECT32 rcRgn; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3525 | LRESULT pos; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3526 | BOOL32 rev = IsWindowEnabled32(wnd->hwndSelf) && |
| 3527 | ((es->flags & EF_FOCUSED) || |
| 3528 | (es->style & ES_NOHIDESEL)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3529 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3530 | if (es->flags & EF_UPDATE) |
| 3531 | EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE"); |
| 3532 | |
| 3533 | dc = BeginPaint32(wnd->hwndSelf, &ps); |
| 3534 | IntersectClipRect32(dc, es->format_rect.left, |
| 3535 | es->format_rect.top, |
| 3536 | es->format_rect.right, |
| 3537 | es->format_rect.bottom); |
| 3538 | if (es->style & ES_MULTILINE) { |
| 3539 | GetClientRect32(wnd->hwndSelf, &rc); |
| 3540 | IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom); |
| 3541 | } |
| 3542 | if (es->font) |
| 3543 | old_font = SelectObject32(dc, es->font); |
| 3544 | EDIT_SEND_CTLCOLOR(wnd, dc); |
| 3545 | if (!IsWindowEnabled32(wnd->hwndSelf)) |
| 3546 | SetTextColor32(dc, GetSysColor32(COLOR_GRAYTEXT)); |
| 3547 | GetClipBox32(dc, &rcRgn); |
| 3548 | if (es->style & ES_MULTILINE) { |
| 3549 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 3550 | for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) { |
| 3551 | EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine); |
| 3552 | if (IntersectRect32(&rc, &rcRgn, &rcLine)) |
| 3553 | EDIT_PaintLine(wnd, es, dc, i, rev); |
| 3554 | } |
| 3555 | } else { |
| 3556 | EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3557 | if (IntersectRect32(&rc, &rcRgn, &rcLine)) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3558 | EDIT_PaintLine(wnd, es, dc, 0, rev); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3559 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3560 | if (es->font) |
| 3561 | SelectObject32(dc, old_font); |
| 3562 | if (es->flags & EF_FOCUSED) { |
| 3563 | pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); |
| 3564 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3565 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3566 | EndPaint32(wnd->hwndSelf, &ps); |
| 3567 | if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) { |
| 3568 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 3569 | SCROLLINFO si; |
| 3570 | si.cbSize = sizeof(SCROLLINFO); |
| 3571 | si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; |
| 3572 | si.nMin = 0; |
| 3573 | si.nMax = es->line_count + vlc - 2; |
| 3574 | si.nPage = vlc; |
| 3575 | si.nPos = es->y_offset; |
| 3576 | SetScrollInfo32(wnd->hwndSelf, SB_VERT, &si, TRUE); |
| 3577 | } |
| 3578 | if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) { |
| 3579 | SCROLLINFO si; |
| 3580 | INT32 fw = es->format_rect.right - es->format_rect.left; |
| 3581 | si.cbSize = sizeof(SCROLLINFO); |
| 3582 | si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; |
| 3583 | si.nMin = 0; |
| 3584 | si.nMax = es->text_width + fw - 1; |
| 3585 | si.nPage = fw; |
| 3586 | si.nPos = es->x_offset; |
| 3587 | SetScrollInfo32(wnd->hwndSelf, SB_HORZ, &si, TRUE); |
| 3588 | } |
| 3589 | |
| 3590 | if (es->flags & EF_UPDATE) { |
| 3591 | es->flags &= ~EF_UPDATE; |
| 3592 | EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE"); |
| 3593 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | |
| 3597 | /********************************************************************* |
| 3598 | * |
| 3599 | * WM_PASTE |
| 3600 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3601 | * FIXME: replace with 32 bit handler once GetClipboardData32() is |
| 3602 | * implemented in misc/clipboard.c |
| 3603 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3604 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3605 | static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3606 | { |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 3607 | HGLOBAL16 hsrc; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3608 | LPSTR src; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3609 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3610 | OpenClipboard32(wnd->hwndSelf); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3611 | if ((hsrc = GetClipboardData16(CF_TEXT))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3612 | src = (LPSTR)GlobalLock16(hsrc); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3613 | EDIT_EM_ReplaceSel(wnd, es, TRUE, src); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 3614 | GlobalUnlock16(hsrc); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3615 | } |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 3616 | CloseClipboard32(); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3617 | } |
| 3618 | |
| 3619 | |
| 3620 | /********************************************************************* |
| 3621 | * |
| 3622 | * WM_SETFOCUS |
| 3623 | * |
| 3624 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3625 | static void EDIT_WM_SetFocus(WND *wnd, EDITSTATE *es, HWND32 window_losing_focus) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3626 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3627 | LRESULT pos; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3628 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3629 | es->flags |= EF_FOCUSED; |
| 3630 | CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height); |
| 3631 | pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); |
| 3632 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
| 3633 | if(!(es->style & ES_NOHIDESEL)) |
| 3634 | EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end); |
| 3635 | ShowCaret32(wnd->hwndSelf); |
| 3636 | EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3637 | } |
| 3638 | |
| 3639 | |
| 3640 | /********************************************************************* |
| 3641 | * |
| 3642 | * WM_SETFONT |
| 3643 | * |
| 3644 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3645 | static void EDIT_WM_SetFont(WND *wnd, EDITSTATE *es, HFONT32 font, BOOL32 redraw) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3646 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3647 | TEXTMETRIC32A tm; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3648 | HDC32 dc; |
| 3649 | HFONT32 old_font = 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3650 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3651 | es->font = font; |
| 3652 | dc = GetDC32(wnd->hwndSelf); |
| 3653 | if (font) |
| 3654 | old_font = SelectObject32(dc, font); |
| 3655 | GetTextMetrics32A(dc, &tm); |
| 3656 | es->line_height = tm.tmHeight; |
| 3657 | es->char_width = tm.tmAveCharWidth; |
| 3658 | if (font) |
| 3659 | SelectObject32(dc, old_font); |
| 3660 | ReleaseDC32(wnd->hwndSelf, dc); |
| 3661 | if (wnd->flags & WIN_ISWIN32) |
| 3662 | EDIT_EM_SetMargins(wnd, es, EC_USEFONTINFO, 0, 0); |
| 3663 | if (es->style & ES_MULTILINE) |
| 3664 | EDIT_BuildLineDefs_ML(wnd, es); |
| 3665 | if (redraw && !(wnd->flags & WIN_NO_REDRAW)) |
| 3666 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 3667 | if (es->flags & EF_FOCUSED) { |
| 3668 | LRESULT pos; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 3669 | DestroyCaret32(); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3670 | CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height); |
| 3671 | pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); |
| 3672 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
| 3673 | ShowCaret32(wnd->hwndSelf); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3674 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | |
| 3678 | /********************************************************************* |
| 3679 | * |
| 3680 | * WM_SETTEXT |
| 3681 | * |
| 3682 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3683 | static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3684 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3685 | EDIT_EM_SetSel(wnd, es, 0, -1, FALSE); |
| 3686 | if (text) { |
| 3687 | dprintf_edit(stddeb, "\t'%s'\n", text); |
| 3688 | EDIT_EM_ReplaceSel(wnd, es, FALSE, text); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3689 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3690 | es->flags |= EF_MODIFIED; |
| 3691 | es->flags |= EF_UPDATE; |
| 3692 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | |
| 3696 | /********************************************************************* |
| 3697 | * |
| 3698 | * WM_SIZE |
| 3699 | * |
| 3700 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3701 | static void EDIT_WM_Size(WND *wnd, EDITSTATE *es, UINT32 action, INT32 width, INT32 height) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3702 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3703 | if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) { |
| 3704 | RECT32 rc; |
| 3705 | SetRect32(&rc, 0, 0, width, height); |
| 3706 | EDIT_SetRectNP(wnd, es, &rc); |
| 3707 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 3708 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3709 | } |
| 3710 | |
| 3711 | |
| 3712 | /********************************************************************* |
| 3713 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3714 | * WM_SYSKEYDOWN |
| 3715 | * |
| 3716 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3717 | static LRESULT EDIT_WM_SysKeyDown(WND *wnd, EDITSTATE *es, INT32 key, DWORD key_data) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3718 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3719 | if ((key == VK_BACK) && (key_data & 0x2000)) { |
| 3720 | if (EDIT_EM_CanUndo(wnd, es)) |
| 3721 | EDIT_EM_Undo(wnd, es); |
| 3722 | return 0; |
| 3723 | } else if (key == VK_UP || key == VK_DOWN) |
| 3724 | if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data)) |
| 3725 | return 0; |
| 3726 | return DefWindowProc32A(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM32)key, (LPARAM)key_data); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
| 3729 | |
| 3730 | /********************************************************************* |
| 3731 | * |
| 3732 | * WM_TIMER |
| 3733 | * |
| 3734 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3735 | static void EDIT_WM_Timer(WND *wnd, EDITSTATE *es, INT32 id, TIMERPROC32 timer_proc) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3736 | { |
| 3737 | /* |
| 3738 | * FIXME: gotta do some scrolling here, like |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3739 | * EDIT_EM_LineScroll(wnd, 0, 1); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3740 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | |
| 3744 | /********************************************************************* |
| 3745 | * |
| 3746 | * EDIT_VScroll_Hack |
| 3747 | * |
| 3748 | * 16 bit notepad needs this. Actually it is not _our_ hack, |
| 3749 | * it is notepad's. Notepad is sending us scrollbar messages with |
| 3750 | * undocumented parameters without us even having a scrollbar ... !?!? |
| 3751 | * |
| 3752 | */ |
| 3753 | static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
| 3754 | { |
| 3755 | INT32 dy = 0; |
| 3756 | LRESULT ret = 0; |
| 3757 | |
| 3758 | if (!(es->flags & EF_VSCROLL_HACK)) { |
| 3759 | fprintf(stderr, "edit: hacked WM_VSCROLL handler invoked\n"); |
| 3760 | fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n"); |
| 3761 | fprintf(stderr, " (this message is only displayed once per edit control)\n"); |
| 3762 | es->flags |= EF_VSCROLL_HACK; |
| 3763 | } |
| 3764 | |
| 3765 | switch (action) { |
| 3766 | case SB_LINEUP: |
| 3767 | case SB_LINEDOWN: |
| 3768 | case SB_PAGEUP: |
| 3769 | case SB_PAGEDOWN: |
| 3770 | EDIT_EM_Scroll(wnd, es, action); |
| 3771 | return 0; |
| 3772 | case SB_TOP: |
| 3773 | dy = -es->y_offset; |
| 3774 | break; |
| 3775 | case SB_BOTTOM: |
| 3776 | dy = es->line_count - 1 - es->y_offset; |
| 3777 | break; |
| 3778 | case SB_THUMBTRACK: |
| 3779 | es->flags |= EF_VSCROLL_TRACK; |
| 3780 | dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset; |
| 3781 | break; |
| 3782 | case SB_THUMBPOSITION: |
| 3783 | es->flags &= ~EF_VSCROLL_TRACK; |
| 3784 | if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset)) |
| 3785 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
| 3786 | break; |
| 3787 | case SB_ENDSCROLL: |
| 3788 | break; |
| 3789 | |
| 3790 | /* |
| 3791 | * FIXME : the next two are undocumented ! |
| 3792 | * Are we doing the right thing ? |
| 3793 | * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, |
| 3794 | * although it's also a regular control message. |
| 3795 | */ |
| 3796 | case EM_GETTHUMB16: |
| 3797 | ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0; |
| 3798 | break; |
| 3799 | case EM_LINESCROLL16: |
| 3800 | dy = pos; |
| 3801 | break; |
| 3802 | |
| 3803 | default: |
| 3804 | fprintf(stderr, "edit: undocumented (hacked) WM_VSCROLL parameter, please report\n"); |
| 3805 | return 0; |
| 3806 | } |
| 3807 | if (dy) |
| 3808 | EDIT_EM_LineScroll(wnd, es, 0, dy); |
| 3809 | return ret; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3810 | } |
| 3811 | |
| 3812 | |
| 3813 | /********************************************************************* |
| 3814 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3815 | * WM_VSCROLL |
| 3816 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3817 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3818 | static LRESULT EDIT_WM_VScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3819 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3820 | INT32 dy; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3821 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3822 | if (!(es->style & ES_MULTILINE)) |
| 3823 | return 0; |
| 3824 | |
| 3825 | if (!(es->style & ES_AUTOVSCROLL)) |
| 3826 | return 0; |
| 3827 | |
| 3828 | if (!(es->style & WS_VSCROLL)) |
| 3829 | return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar); |
| 3830 | |
| 3831 | dy = 0; |
| 3832 | switch (action) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3833 | case SB_LINEUP: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3834 | case SB_LINEDOWN: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3835 | case SB_PAGEUP: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3836 | case SB_PAGEDOWN: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3837 | EDIT_EM_Scroll(wnd, es, action); |
| 3838 | return 0; |
| 3839 | |
| 3840 | case SB_TOP: |
| 3841 | dy = -es->y_offset; |
| 3842 | break; |
| 3843 | case SB_BOTTOM: |
| 3844 | dy = es->line_count - 1 - es->y_offset; |
| 3845 | break; |
| 3846 | case SB_THUMBTRACK: |
| 3847 | es->flags |= EF_VSCROLL_TRACK; |
| 3848 | dy = pos - es->y_offset; |
| 3849 | break; |
| 3850 | case SB_THUMBPOSITION: |
| 3851 | es->flags &= ~EF_VSCROLL_TRACK; |
| 3852 | if (!(dy = pos - es->y_offset)) { |
| 3853 | SetScrollPos32(wnd->hwndSelf, SB_VERT, pos, TRUE); |
| 3854 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
| 3855 | } |
| 3856 | break; |
| 3857 | case SB_ENDSCROLL: |
| 3858 | break; |
| 3859 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3860 | default: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3861 | fprintf(stderr, "edit: undocumented WM_VSCROLL parameter, please report\n"); |
| 3862 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3863 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3864 | if (dy) |
| 3865 | EDIT_EM_LineScroll(wnd, es, 0, dy); |
| 3866 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3867 | } |