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; |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 985 | } |
| 986 | else if (es->word_break_proc32A) |
| 987 | { |
| 988 | dprintf_relay( stddeb, "CallTo32(wordbrk=%p,str='%s',idx=%d,cnt=%d,act=%d)\n", |
| 989 | es->word_break_proc32A, es->text + start, index, |
| 990 | count, action ); |
| 991 | return (INT32)es->word_break_proc32A( es->text + start, index, |
| 992 | count, action ); |
| 993 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 994 | else |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 995 | return EDIT_WordBreakProc(es->text + start, index, count, action); |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 996 | } |
| 997 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 998 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 999 | /********************************************************************* |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1000 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1001 | * EDIT_CharFromPos |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1002 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1003 | * Beware: This is not the function called on EM_CHARFROMPOS |
| 1004 | * The position _can_ be outside the formatting / client |
| 1005 | * rectangle |
| 1006 | * The return value is only the character index |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1007 | * |
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 | 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] | 1010 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1011 | INT32 index; |
| 1012 | HDC32 dc; |
| 1013 | HFONT32 old_font = 0; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1014 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1015 | if (es->style & ES_MULTILINE) { |
| 1016 | INT32 line = (y - es->format_rect.top) / es->line_height + es->y_offset; |
| 1017 | INT32 line_index = 0; |
| 1018 | LINEDEF *line_def = es->first_line_def; |
| 1019 | while ((line > 0) && line_def->next) { |
| 1020 | line_index += line_def->length; |
| 1021 | line_def = line_def->next; |
| 1022 | line--; |
| 1023 | } |
| 1024 | x += es->x_offset - es->format_rect.left; |
| 1025 | if (x >= line_def->width) { |
| 1026 | if (after_wrap) |
| 1027 | *after_wrap = (line_def->ending == END_WRAP); |
| 1028 | return line_index + line_def->net_length; |
| 1029 | } |
| 1030 | if (x <= 0) { |
| 1031 | if (after_wrap) |
| 1032 | *after_wrap = FALSE; |
| 1033 | return line_index; |
| 1034 | } |
| 1035 | dc = GetDC32(wnd->hwndSelf); |
| 1036 | if (es->font) |
| 1037 | old_font = SelectObject32(dc, es->font); |
| 1038 | /* FIXME: inefficient algorithm */ |
| 1039 | for (index = line_index + 1 ; index < line_index + line_def->net_length ; index++) |
| 1040 | if (LOWORD(GetTabbedTextExtent32A(dc, es->text + line_index, |
| 1041 | index - line_index, es->tabs_count, es->tabs)) >= x) |
| 1042 | break; |
| 1043 | if (after_wrap) |
| 1044 | *after_wrap = ((index == line_index + line_def->net_length) && |
| 1045 | (line_def->ending == END_WRAP)); |
| 1046 | } else { |
| 1047 | LPSTR text; |
| 1048 | SIZE32 size; |
| 1049 | if (after_wrap) |
| 1050 | *after_wrap = FALSE; |
| 1051 | x -= es->format_rect.left; |
| 1052 | if (!x) |
| 1053 | return es->x_offset; |
| 1054 | text = EDIT_GetPasswordPointer_SL(wnd, es); |
| 1055 | dc = GetDC32(wnd->hwndSelf); |
| 1056 | if (es->font) |
| 1057 | old_font = SelectObject32(dc, es->font); |
| 1058 | if (x < 0) { |
| 1059 | x = -x; |
| 1060 | /* FIXME: inefficient algorithm */ |
| 1061 | for (index = es->x_offset ; index ; index--) { |
| 1062 | GetTextExtentPoint32A(dc, text + index, |
| 1063 | es->x_offset - index, &size); |
| 1064 | if (size.cx > x) |
| 1065 | break; |
| 1066 | } |
| 1067 | } else { |
| 1068 | INT32 len = lstrlen32A(es->text); |
| 1069 | /* FIXME: inefficient algorithm */ |
| 1070 | for (index = es->x_offset ; index < len ; index++) { |
| 1071 | GetTextExtentPoint32A(dc, text + es->x_offset, |
| 1072 | index - es->x_offset, &size); |
| 1073 | if (size.cx >= x) |
| 1074 | break; |
| 1075 | } |
| 1076 | } |
| 1077 | if (es->style & ES_PASSWORD) |
| 1078 | HeapFree(es->heap, 0 ,text); |
| 1079 | } |
| 1080 | if (es->font) |
| 1081 | SelectObject32(dc, old_font); |
| 1082 | ReleaseDC32(wnd->hwndSelf, dc); |
| 1083 | return index; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1086 | |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1087 | /********************************************************************* |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1088 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1089 | * EDIT_ConfinePoint |
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 | * adjusts the point to be within the formatting rectangle |
| 1092 | * (so CharFromPos returns the nearest _visible_ character) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1093 | * |
| 1094 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1095 | static void EDIT_ConfinePoint(WND *wnd, EDITSTATE *es, LPINT32 x, LPINT32 y) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1096 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1097 | *x = MIN(MAX(*x, es->format_rect.left), es->format_rect.right - 1); |
| 1098 | *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] | 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | /********************************************************************* |
| 1103 | * |
| 1104 | * EDIT_GetLineRect |
| 1105 | * |
| 1106 | * Calculates the bounding rectangle for a line from a starting |
| 1107 | * column to an ending column. |
| 1108 | * |
| 1109 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1110 | 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] | 1111 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1112 | INT32 line_index = EDIT_EM_LineIndex(wnd, es, line); |
| 1113 | |
| 1114 | if (es->style & ES_MULTILINE) |
| 1115 | rc->top = es->format_rect.top + (line - es->y_offset) * es->line_height; |
| 1116 | else |
| 1117 | rc->top = es->format_rect.top; |
| 1118 | rc->bottom = rc->top + es->line_height; |
| 1119 | rc->left = (scol == 0) ? es->format_rect.left : SLOWORD(EDIT_EM_PosFromChar(wnd, es, line_index + scol, TRUE)); |
| 1120 | 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] | 1121 | } |
| 1122 | |
| 1123 | |
| 1124 | /********************************************************************* |
| 1125 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1126 | * EDIT_GetPasswordPointer_SL |
| 1127 | * |
| 1128 | * note: caller should free the (optionally) allocated buffer |
| 1129 | * |
| 1130 | */ |
| 1131 | static LPSTR EDIT_GetPasswordPointer_SL(WND *wnd, EDITSTATE *es) |
| 1132 | { |
| 1133 | if (es->style & ES_PASSWORD) { |
| 1134 | INT32 len = lstrlen32A(es->text); |
| 1135 | LPSTR text = HeapAlloc(es->heap, 0, len + 1); |
| 1136 | RtlFillMemory(text, len, es->password_char); |
| 1137 | text[len] = '\0'; |
| 1138 | return text; |
| 1139 | } else |
| 1140 | return es->text; |
| 1141 | } |
| 1142 | |
| 1143 | |
| 1144 | /********************************************************************* |
| 1145 | * |
| 1146 | * EDIT_LockBuffer |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1147 | * |
| 1148 | * This acts as a LOCAL_Lock(), but it locks only once. This way |
| 1149 | * you can call it whenever you like, without unlocking. |
| 1150 | * |
| 1151 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1152 | static void EDIT_LockBuffer(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1153 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1154 | if (!es) { |
| 1155 | fprintf(stderr, "edit: LockBuffer() without an EDITSTATE ... please report\n"); |
| 1156 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1157 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1158 | if (!(es->style & ES_MULTILINE)) |
| 1159 | return; |
| 1160 | if (!es->text) { |
| 1161 | if (es->hloc32) |
| 1162 | es->text = LocalLock32(es->hloc32); |
| 1163 | else if (es->hloc16) |
| 1164 | es->text = LOCAL_Lock(wnd->hInstance, es->hloc16); |
| 1165 | else { |
| 1166 | fprintf(stderr, "edit: LockBuffer() without a buffer ... please report\n"); |
| 1167 | return; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1170 | es->lock_count++; |
Alexandre Julliard | 3051b64 | 1996-07-05 17:14:13 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | |
| 1174 | /********************************************************************* |
| 1175 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1176 | * EDIT_SL_InvalidateText |
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 | * Called from EDIT_InvalidateText(). |
| 1179 | * Does the job for single-line controls only. |
Alexandre Julliard | 139a4b1 | 1996-11-02 14:24:07 +0000 | [diff] [blame] | 1180 | * |
| 1181 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1182 | 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] | 1183 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1184 | RECT32 line_rect; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1185 | RECT32 rc; |
| 1186 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1187 | EDIT_GetLineRect(wnd, es, 0, start, end, &line_rect); |
| 1188 | if (IntersectRect32(&rc, &line_rect, &es->format_rect)) |
| 1189 | InvalidateRect32(wnd->hwndSelf, &rc, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | |
| 1193 | /********************************************************************* |
| 1194 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1195 | * EDIT_ML_InvalidateText |
| 1196 | * |
| 1197 | * Called from EDIT_InvalidateText(). |
| 1198 | * Does the job for multi-line controls only. |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1199 | * |
| 1200 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1201 | 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] | 1202 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1203 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 1204 | INT32 sl = EDIT_EM_LineFromChar(wnd, es, start); |
| 1205 | INT32 el = EDIT_EM_LineFromChar(wnd, es, end); |
| 1206 | INT32 sc; |
| 1207 | INT32 ec; |
| 1208 | RECT32 rc1; |
| 1209 | RECT32 rcWnd; |
| 1210 | RECT32 rcLine; |
| 1211 | RECT32 rcUpdate; |
| 1212 | INT32 l; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1213 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1214 | if ((el < es->y_offset) || (sl > es->y_offset + vlc)) |
| 1215 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1216 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1217 | sc = start - EDIT_EM_LineIndex(wnd, es, sl); |
| 1218 | ec = end - EDIT_EM_LineIndex(wnd, es, el); |
| 1219 | if (sl < es->y_offset) { |
| 1220 | sl = es->y_offset; |
| 1221 | sc = 0; |
| 1222 | } |
| 1223 | if (el > es->y_offset + vlc) { |
| 1224 | el = es->y_offset + vlc; |
| 1225 | ec = EDIT_EM_LineLength(wnd, es, EDIT_EM_LineIndex(wnd, es, el)); |
| 1226 | } |
| 1227 | GetClientRect32(wnd->hwndSelf, &rc1); |
| 1228 | IntersectRect32(&rcWnd, &rc1, &es->format_rect); |
| 1229 | if (sl == el) { |
| 1230 | EDIT_GetLineRect(wnd, es, sl, sc, ec, &rcLine); |
| 1231 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1232 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1233 | } else { |
| 1234 | EDIT_GetLineRect(wnd, es, sl, sc, |
| 1235 | EDIT_EM_LineLength(wnd, es, |
| 1236 | EDIT_EM_LineIndex(wnd, es, sl)), |
| 1237 | &rcLine); |
| 1238 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1239 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1240 | for (l = sl + 1 ; l < el ; l++) { |
| 1241 | EDIT_GetLineRect(wnd, es, l, 0, |
| 1242 | EDIT_EM_LineLength(wnd, es, |
| 1243 | EDIT_EM_LineIndex(wnd, es, l)), |
| 1244 | &rcLine); |
| 1245 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1246 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1247 | } |
| 1248 | EDIT_GetLineRect(wnd, es, el, 0, ec, &rcLine); |
| 1249 | if (IntersectRect32(&rcUpdate, &rcWnd, &rcLine)) |
| 1250 | InvalidateRect32(wnd->hwndSelf, &rcUpdate, FALSE); |
| 1251 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | /********************************************************************* |
| 1256 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1257 | * EDIT_InvalidateText |
| 1258 | * |
| 1259 | * Invalidate the text from offset start upto, but not including, |
| 1260 | * offset end. Useful for (re)painting the selection. |
| 1261 | * Regions outside the linewidth are not invalidated. |
| 1262 | * end == -1 means end == TextLength. |
| 1263 | * start and end need not be ordered. |
| 1264 | * |
| 1265 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1266 | static void EDIT_InvalidateText(WND *wnd, EDITSTATE *es, INT32 start, INT32 end) |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1267 | { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1268 | if (end == start) |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1269 | return; |
| 1270 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1271 | if (end == -1) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1272 | end = lstrlen32A(es->text); |
| 1273 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1274 | ORDER_INT32(start, end); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1275 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1276 | if (es->style & ES_MULTILINE) |
| 1277 | EDIT_ML_InvalidateText(wnd, es, start, end); |
| 1278 | else |
| 1279 | EDIT_SL_InvalidateText(wnd, es, start, end); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | /********************************************************************* |
| 1284 | * |
| 1285 | * EDIT_MakeFit |
| 1286 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1287 | * Try to fit size + 1 bytes in the buffer. Constrain to limits. |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1288 | * |
| 1289 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1290 | static BOOL32 EDIT_MakeFit(WND *wnd, EDITSTATE *es, INT32 size) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1291 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1292 | HLOCAL32 hNew32; |
| 1293 | HLOCAL16 hNew16; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1294 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1295 | if (size <= es->buffer_size) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1296 | return TRUE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1297 | if (size > es->buffer_limit) { |
| 1298 | EDIT_NOTIFY_PARENT(wnd, EN_MAXTEXT, "EN_MAXTEXT"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1299 | return FALSE; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1300 | } |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1301 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1302 | if (size > es->buffer_limit) |
| 1303 | size = es->buffer_limit; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1304 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1305 | 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] | 1306 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1307 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 1308 | if (es->text) { |
| 1309 | if ((es->text = HeapReAlloc(es->heap, 0, es->text, size + 1))) |
| 1310 | es->buffer_size = MIN(HeapSize(es->heap, 0, es->text) - 1, es->buffer_limit); |
| 1311 | else |
| 1312 | es->buffer_size = 0; |
| 1313 | } else if (es->hloc32) { |
| 1314 | if ((hNew32 = LocalReAlloc32(es->hloc32, size + 1, 0))) { |
| 1315 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 32 bit handle %08x, new handle %08x\n", es->hloc32, hNew32); |
| 1316 | es->hloc32 = hNew32; |
| 1317 | es->buffer_size = MIN(LocalSize32(es->hloc32) - 1, es->buffer_limit); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1318 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1319 | } else if (es->hloc16) { |
| 1320 | if ((hNew16 = LOCAL_ReAlloc(wnd->hInstance, es->hloc16, size + 1, LMEM_MOVEABLE))) { |
| 1321 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: Old 16 bit handle %08x, new handle %08x\n", es->hloc16, hNew16); |
| 1322 | es->hloc16 = hNew16; |
| 1323 | 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] | 1324 | } |
| 1325 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1326 | if (es->buffer_size < size) { |
| 1327 | EDIT_LockBuffer(wnd, es); |
| 1328 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: FAILED ! We now have %d+1\n", es->buffer_size); |
| 1329 | EDIT_NOTIFY_PARENT(wnd, EN_ERRSPACE, "EN_ERRSPACE"); |
| 1330 | return FALSE; |
| 1331 | } else { |
| 1332 | EDIT_LockBuffer(wnd, es); |
| 1333 | dprintf_edit(stddeb, "edit: EDIT_MakeFit: We now have %d+1\n", es->buffer_size); |
| 1334 | return TRUE; |
| 1335 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | |
| 1339 | /********************************************************************* |
| 1340 | * |
| 1341 | * EDIT_MakeUndoFit |
| 1342 | * |
| 1343 | * Try to fit size + 1 bytes in the undo buffer. |
| 1344 | * |
| 1345 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1346 | static BOOL32 EDIT_MakeUndoFit(WND *wnd, EDITSTATE *es, INT32 size) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1347 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1348 | if (size <= es->undo_buffer_size) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1349 | return TRUE; |
| 1350 | size = ((size / GROWLENGTH) + 1) * GROWLENGTH; |
| 1351 | |
| 1352 | dprintf_edit(stddeb, "edit: EDIT_MakeUndoFit: trying to ReAlloc to %d+1\n", size); |
| 1353 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1354 | if ((es->undo_text = HeapReAlloc(es->heap, 0, es->undo_text, size + 1))) { |
| 1355 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; |
| 1356 | if (es->undo_buffer_size < size) { |
| 1357 | 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] | 1358 | return FALSE; |
| 1359 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1360 | return TRUE; |
| 1361 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1362 | return FALSE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | |
| 1366 | /********************************************************************* |
| 1367 | * |
| 1368 | * EDIT_MoveBackward |
| 1369 | * |
| 1370 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1371 | static void EDIT_MoveBackward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1372 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1373 | INT32 e = es->selection_end; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1374 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1375 | if (e) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1376 | e--; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1377 | if ((es->style & ES_MULTILINE) && e && |
| 1378 | (es->text[e - 1] == '\r') && (es->text[e] == '\n')) { |
| 1379 | e--; |
| 1380 | if (e && (es->text[e - 1] == '\r')) |
| 1381 | e--; |
| 1382 | } |
| 1383 | } |
| 1384 | EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE); |
| 1385 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | |
| 1389 | /********************************************************************* |
| 1390 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1391 | * EDIT_MoveDown_ML |
| 1392 | * |
| 1393 | * Only for multi line controls |
| 1394 | * Move the caret one line down, on a column with the nearest |
| 1395 | * x coordinate on the screen (might be a different column). |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1396 | * |
| 1397 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1398 | static void EDIT_MoveDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1399 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1400 | INT32 s = es->selection_start; |
| 1401 | INT32 e = es->selection_end; |
| 1402 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1403 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1404 | INT32 x = SLOWORD(pos); |
| 1405 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1406 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1407 | e = EDIT_CharFromPos(wnd, es, x, y + es->line_height, &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1408 | if (!extend) |
| 1409 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1410 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1411 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | |
| 1415 | /********************************************************************* |
| 1416 | * |
| 1417 | * EDIT_MoveEnd |
| 1418 | * |
| 1419 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1420 | static void EDIT_MoveEnd(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1421 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1422 | BOOL32 after_wrap = FALSE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1423 | INT32 e; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1424 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1425 | if (es->style & ES_MULTILINE) |
| 1426 | e = EDIT_CharFromPos(wnd, es, 0x7fffffff, |
| 1427 | HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), &after_wrap); |
| 1428 | else |
| 1429 | e = lstrlen32A(es->text); |
| 1430 | EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, after_wrap); |
| 1431 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | /********************************************************************* |
| 1436 | * |
| 1437 | * EDIT_MoveForward |
| 1438 | * |
| 1439 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1440 | static void EDIT_MoveForward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1441 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1442 | INT32 e = es->selection_end; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1443 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1444 | if (es->text[e]) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1445 | e++; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1446 | if ((es->style & ES_MULTILINE) && (es->text[e - 1] == '\r')) { |
| 1447 | if (es->text[e] == '\n') |
| 1448 | e++; |
| 1449 | else if ((es->text[e] == '\r') && (es->text[e + 1] == '\n')) |
| 1450 | e += 2; |
| 1451 | } |
| 1452 | } |
| 1453 | EDIT_EM_SetSel(wnd, es, extend ? es->selection_start : e, e, FALSE); |
| 1454 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | |
| 1458 | /********************************************************************* |
| 1459 | * |
| 1460 | * EDIT_MoveHome |
| 1461 | * |
| 1462 | * Home key: move to beginning of line. |
| 1463 | * |
| 1464 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1465 | static void EDIT_MoveHome(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1466 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1467 | INT32 e; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1468 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1469 | if (es->style & ES_MULTILINE) |
| 1470 | e = EDIT_CharFromPos(wnd, es, 0x80000000, |
| 1471 | HIWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)), NULL); |
| 1472 | else |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 1473 | e = 0; |
| 1474 | EDIT_EM_SetSel(wnd, es, e, extend ? es->selection_start : e, FALSE); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1475 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | /********************************************************************* |
| 1480 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1481 | * EDIT_MovePageDown_ML |
| 1482 | * |
| 1483 | * Only for multi line controls |
| 1484 | * Move the caret one page down, on a column with the nearest |
| 1485 | * x coordinate on the screen (might be a different column). |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1486 | * |
| 1487 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1488 | static void EDIT_MovePageDown_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1489 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1490 | INT32 s = es->selection_start; |
| 1491 | INT32 e = es->selection_end; |
| 1492 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1493 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1494 | INT32 x = SLOWORD(pos); |
| 1495 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1496 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1497 | e = EDIT_CharFromPos(wnd, es, x, |
| 1498 | y + (es->format_rect.bottom - es->format_rect.top), |
| 1499 | &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1500 | if (!extend) |
| 1501 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1502 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1503 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
| 1506 | |
| 1507 | /********************************************************************* |
| 1508 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1509 | * EDIT_MovePageUp_ML |
| 1510 | * |
| 1511 | * Only for multi line controls |
| 1512 | * Move the caret one page up, on a column with the nearest |
| 1513 | * x coordinate on the screen (might be a different column). |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1514 | * |
| 1515 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1516 | static void EDIT_MovePageUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1517 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1518 | INT32 s = es->selection_start; |
| 1519 | INT32 e = es->selection_end; |
| 1520 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1521 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1522 | INT32 x = SLOWORD(pos); |
| 1523 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1524 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1525 | e = EDIT_CharFromPos(wnd, es, x, |
| 1526 | y - (es->format_rect.bottom - es->format_rect.top), |
| 1527 | &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1528 | if (!extend) |
| 1529 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1530 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1531 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | |
| 1535 | /********************************************************************* |
| 1536 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1537 | * EDIT_MoveUp_ML |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1538 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1539 | * Only for multi line controls |
| 1540 | * Move the caret one line up, on a column with the nearest |
| 1541 | * x coordinate on the screen (might be a different column). |
| 1542 | * |
| 1543 | */ |
| 1544 | static void EDIT_MoveUp_ML(WND *wnd, EDITSTATE *es, BOOL32 extend) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1545 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1546 | INT32 s = es->selection_start; |
| 1547 | INT32 e = es->selection_end; |
| 1548 | BOOL32 after_wrap = (es->flags & EF_AFTER_WRAP); |
| 1549 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, e, after_wrap); |
| 1550 | INT32 x = SLOWORD(pos); |
| 1551 | INT32 y = SHIWORD(pos); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1552 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1553 | e = EDIT_CharFromPos(wnd, es, x, y - es->line_height, &after_wrap); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1554 | if (!extend) |
| 1555 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1556 | EDIT_EM_SetSel(wnd, es, s, e, after_wrap); |
| 1557 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | |
| 1561 | /********************************************************************* |
| 1562 | * |
| 1563 | * EDIT_MoveWordBackward |
| 1564 | * |
| 1565 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1566 | static void EDIT_MoveWordBackward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
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 | INT32 s = es->selection_start; |
| 1569 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1570 | INT32 l; |
| 1571 | INT32 ll; |
| 1572 | INT32 li; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1573 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1574 | l = EDIT_EM_LineFromChar(wnd, es, e); |
| 1575 | ll = EDIT_EM_LineLength(wnd, es, e); |
| 1576 | li = EDIT_EM_LineIndex(wnd, es, l); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1577 | if (e - li == 0) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1578 | if (l) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1579 | li = EDIT_EM_LineIndex(wnd, es, l - 1); |
| 1580 | e = li + EDIT_EM_LineLength(wnd, es, li); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1581 | } |
| 1582 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1583 | e = li + (INT32)EDIT_CallWordBreakProc(wnd, es, |
| 1584 | li, e - li, ll, WB_LEFT); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1585 | } |
| 1586 | if (!extend) |
| 1587 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1588 | EDIT_EM_SetSel(wnd, es, s, e, FALSE); |
| 1589 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | /********************************************************************* |
| 1594 | * |
| 1595 | * EDIT_MoveWordForward |
| 1596 | * |
| 1597 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1598 | static void EDIT_MoveWordForward(WND *wnd, EDITSTATE *es, BOOL32 extend) |
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 | INT32 s = es->selection_start; |
| 1601 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1602 | INT32 l; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1603 | INT32 ll; |
| 1604 | INT32 li; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1605 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1606 | l = EDIT_EM_LineFromChar(wnd, es, e); |
| 1607 | ll = EDIT_EM_LineLength(wnd, es, e); |
| 1608 | li = EDIT_EM_LineIndex(wnd, es, l); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1609 | if (e - li == ll) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1610 | if ((es->style & ES_MULTILINE) && (l != es->line_count - 1)) |
| 1611 | e = EDIT_EM_LineIndex(wnd, es, l + 1); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1612 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1613 | e = li + EDIT_CallWordBreakProc(wnd, es, |
| 1614 | li, e - li + 1, ll, WB_RIGHT); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1615 | } |
| 1616 | if (!extend) |
| 1617 | s = e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1618 | EDIT_EM_SetSel(wnd, es, s, e, FALSE); |
| 1619 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | |
| 1623 | /********************************************************************* |
| 1624 | * |
| 1625 | * EDIT_PaintLine |
| 1626 | * |
| 1627 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1628 | 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] | 1629 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1630 | INT32 s = es->selection_start; |
| 1631 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1632 | INT32 li; |
| 1633 | INT32 ll; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1634 | INT32 x; |
| 1635 | INT32 y; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1636 | LRESULT pos; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1637 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1638 | if (es->style & ES_MULTILINE) { |
| 1639 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 1640 | if ((line < es->y_offset) || (line > es->y_offset + vlc) || (line >= es->line_count)) |
| 1641 | return; |
| 1642 | } else if (line) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1643 | return; |
| 1644 | |
| 1645 | dprintf_edit(stddeb, "edit: EDIT_PaintLine: line=%d\n", line); |
| 1646 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1647 | pos = EDIT_EM_PosFromChar(wnd, es, EDIT_EM_LineIndex(wnd, es, line), FALSE); |
| 1648 | x = SLOWORD(pos); |
| 1649 | y = SHIWORD(pos); |
| 1650 | li = EDIT_EM_LineIndex(wnd, es, line); |
| 1651 | ll = EDIT_EM_LineLength(wnd, es, li); |
| 1652 | s = es->selection_start; |
| 1653 | e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1654 | ORDER_INT32(s, e); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1655 | s = MIN(li + ll, MAX(li, s)); |
| 1656 | e = MIN(li + ll, MAX(li, e)); |
| 1657 | if (rev && (s != e) && |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1658 | ((es->flags & EF_FOCUSED) || (es->style & ES_NOHIDESEL))) { |
| 1659 | x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, s - li, FALSE); |
| 1660 | x += EDIT_PaintText(wnd, es, dc, x, y, line, s - li, e - s, TRUE); |
| 1661 | 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] | 1662 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1663 | x += EDIT_PaintText(wnd, es, dc, x, y, line, 0, ll, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | |
| 1667 | /********************************************************************* |
| 1668 | * |
| 1669 | * EDIT_PaintText |
| 1670 | * |
| 1671 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1672 | 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] | 1673 | { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1674 | COLORREF BkColor; |
| 1675 | COLORREF TextColor; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1676 | INT32 ret; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1677 | INT32 li; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1678 | SIZE32 size; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1679 | |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 1680 | if (!count) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1681 | return 0; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1682 | BkColor = GetBkColor32(dc); |
| 1683 | TextColor = GetTextColor32(dc); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1684 | if (rev) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1685 | SetBkColor32(dc, GetSysColor32(COLOR_HIGHLIGHT)); |
| 1686 | SetTextColor32(dc, GetSysColor32(COLOR_HIGHLIGHTTEXT)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1687 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1688 | li = EDIT_EM_LineIndex(wnd, es, line); |
| 1689 | if (es->style & ES_MULTILINE) { |
| 1690 | ret = (INT32)LOWORD(TabbedTextOut32A(dc, x, y, es->text + li + col, count, |
| 1691 | es->tabs_count, es->tabs, es->format_rect.left - es->x_offset)); |
| 1692 | } else { |
| 1693 | LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es); |
| 1694 | TextOut32A(dc, x, y, text + li + col, count); |
| 1695 | GetTextExtentPoint32A(dc, text + li + col, count, &size); |
| 1696 | ret = size.cx; |
| 1697 | if (es->style & ES_PASSWORD) |
| 1698 | HeapFree(es->heap, 0, text); |
| 1699 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1700 | if (rev) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1701 | SetBkColor32(dc, BkColor); |
| 1702 | SetTextColor32(dc, TextColor); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1703 | } |
| 1704 | return ret; |
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 | |
| 1707 | |
| 1708 | /********************************************************************* |
| 1709 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1710 | * EM_SCROLLCARET |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1711 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1712 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1713 | static void EDIT_EM_ScrollCaret(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1714 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1715 | if (es->style & ES_MULTILINE) { |
| 1716 | INT32 l; |
| 1717 | INT32 li; |
| 1718 | INT32 vlc; |
| 1719 | INT32 ww; |
| 1720 | INT32 cw = es->char_width; |
| 1721 | INT32 x; |
| 1722 | INT32 dy = 0; |
| 1723 | INT32 dx = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1724 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1725 | l = EDIT_EM_LineFromChar(wnd, es, es->selection_end); |
| 1726 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 1727 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP)); |
| 1728 | vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 1729 | if (l >= es->y_offset + vlc) |
| 1730 | dy = l - vlc + 1 - es->y_offset; |
| 1731 | if (l < es->y_offset) |
| 1732 | dy = l - es->y_offset; |
| 1733 | ww = es->format_rect.right - es->format_rect.left; |
| 1734 | if (x < es->format_rect.left) |
| 1735 | dx = x - es->format_rect.left - ww / HSCROLL_FRACTION / cw * cw; |
| 1736 | if (x > es->format_rect.right) |
| 1737 | dx = x - es->format_rect.left - (HSCROLL_FRACTION - 1) * ww / HSCROLL_FRACTION / cw * cw; |
| 1738 | if (dy || dx) |
| 1739 | EDIT_EM_LineScroll(wnd, es, dx, dy); |
| 1740 | } else { |
| 1741 | INT32 x; |
| 1742 | INT32 goal; |
| 1743 | INT32 format_width; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1744 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1745 | if (!(es->style & ES_AUTOHSCROLL)) |
| 1746 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1747 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1748 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); |
| 1749 | format_width = es->format_rect.right - es->format_rect.left; |
| 1750 | if (x < es->format_rect.left) { |
| 1751 | goal = es->format_rect.left + format_width / HSCROLL_FRACTION; |
| 1752 | do { |
| 1753 | es->x_offset--; |
| 1754 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); |
| 1755 | } while ((x < goal) && es->x_offset); |
| 1756 | /* FIXME: use ScrollWindow() somehow to improve performance */ |
| 1757 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 1758 | } else if (x > es->format_rect.right) { |
| 1759 | INT32 x_last; |
| 1760 | INT32 len = lstrlen32A(es->text); |
| 1761 | goal = es->format_rect.right - format_width / HSCROLL_FRACTION; |
| 1762 | do { |
| 1763 | es->x_offset++; |
| 1764 | x = SLOWORD(EDIT_EM_PosFromChar(wnd, es, es->selection_end, FALSE)); |
| 1765 | x_last = SLOWORD(EDIT_EM_PosFromChar(wnd, es, len, FALSE)); |
| 1766 | } while ((x > goal) && (x_last > es->format_rect.right)); |
| 1767 | /* FIXME: use ScrollWindow() somehow to improve performance */ |
| 1768 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1769 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | |
| 1774 | /********************************************************************* |
| 1775 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1776 | * EDIT_SetRectNP |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1777 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1778 | * note: this is not (exactly) the handler called on EM_SETRECTNP |
| 1779 | * 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] | 1780 | * |
| 1781 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1782 | static void EDIT_SetRectNP(WND *wnd, EDITSTATE *es, LPRECT32 rc) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1783 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1784 | CopyRect32(&es->format_rect, rc); |
| 1785 | if (es->style & WS_BORDER) { |
| 1786 | INT32 bw = GetSystemMetrics32(SM_CXBORDER) + 1; |
| 1787 | es->format_rect.left += bw; |
| 1788 | es->format_rect.top += bw; |
| 1789 | es->format_rect.right -= bw; |
| 1790 | es->format_rect.bottom -= bw; |
| 1791 | } |
| 1792 | es->format_rect.left += es->left_margin; |
| 1793 | es->format_rect.right -= es->right_margin; |
| 1794 | es->format_rect.right = MAX(es->format_rect.right, es->format_rect.left + es->char_width); |
| 1795 | if (es->style & ES_MULTILINE) |
| 1796 | es->format_rect.bottom = es->format_rect.top + |
| 1797 | MAX(1, (es->format_rect.bottom - es->format_rect.top) / es->line_height) * es->line_height; |
| 1798 | else |
| 1799 | es->format_rect.bottom = es->format_rect.top + es->line_height; |
| 1800 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) |
| 1801 | EDIT_BuildLineDefs_ML(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | |
| 1805 | /********************************************************************* |
| 1806 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1807 | * EDIT_UnlockBuffer |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1808 | * |
| 1809 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1810 | static void EDIT_UnlockBuffer(WND *wnd, EDITSTATE *es, BOOL32 force) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1811 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1812 | if (!es) { |
| 1813 | fprintf(stderr, "edit: UnlockBuffer() without an EDITSTATE ... please report\n"); |
| 1814 | return; |
| 1815 | } |
| 1816 | if (!(es->style & ES_MULTILINE)) |
| 1817 | return; |
| 1818 | if (!es->lock_count) { |
| 1819 | fprintf(stderr, "edit: UnlockBuffer() with lock_count == 0 ... please report\n"); |
| 1820 | return; |
| 1821 | } |
| 1822 | if (!es->text) { |
| 1823 | fprintf(stderr, "edit: UnlockBuffer() with es->text == 0 ... please report\n"); |
| 1824 | return; |
| 1825 | } |
| 1826 | if (force || (es->lock_count == 1)) { |
| 1827 | if (es->hloc32) { |
| 1828 | LocalUnlock32(es->hloc32); |
| 1829 | es->text = NULL; |
| 1830 | } else if (es->hloc16) { |
| 1831 | LOCAL_Unlock(wnd->hInstance, es->hloc16); |
| 1832 | es->text = NULL; |
| 1833 | } |
| 1834 | } |
| 1835 | es->lock_count--; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | |
| 1839 | /********************************************************************* |
| 1840 | * |
| 1841 | * EDIT_WordBreakProc |
| 1842 | * |
| 1843 | * Find the beginning of words. |
| 1844 | * Note: unlike the specs for a WordBreakProc, this function only |
| 1845 | * allows to be called without linebreaks between s[0] upto |
| 1846 | * s[count - 1]. Remember it is only called |
| 1847 | * internally, so we can decide this for ourselves. |
| 1848 | * |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1849 | */ |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1850 | static INT32 EDIT_WordBreakProc(LPSTR s, INT32 index, INT32 count, INT32 action) |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1851 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1852 | INT32 ret = 0; |
Alexandre Julliard | 02ed4c2 | 1996-03-02 19:34:10 +0000 | [diff] [blame] | 1853 | |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1854 | dprintf_edit(stddeb, "edit: EDIT_WordBreakProc: s=%p, index=%u" |
| 1855 | ", count=%u, action=%d\n", s, index, count, action); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1856 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1857 | switch (action) { |
| 1858 | case WB_LEFT: |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1859 | if (!count) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1860 | break; |
| 1861 | if (index) |
| 1862 | index--; |
| 1863 | if (s[index] == ' ') { |
| 1864 | while (index && (s[index] == ' ')) |
| 1865 | index--; |
| 1866 | if (index) { |
| 1867 | while (index && (s[index] != ' ')) |
| 1868 | index--; |
| 1869 | if (s[index] == ' ') |
| 1870 | index++; |
| 1871 | } |
| 1872 | } else { |
| 1873 | while (index && (s[index] != ' ')) |
| 1874 | index--; |
| 1875 | if (s[index] == ' ') |
| 1876 | index++; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1877 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1878 | ret = index; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1879 | break; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1880 | case WB_RIGHT: |
| 1881 | if (!count) |
| 1882 | break; |
| 1883 | if (index) |
| 1884 | index--; |
| 1885 | if (s[index] == ' ') |
| 1886 | while ((index < count) && (s[index] == ' ')) index++; |
| 1887 | else { |
| 1888 | while (s[index] && (s[index] != ' ') && (index < count)) |
| 1889 | index++; |
| 1890 | while ((s[index] == ' ') && (index < count)) index++; |
| 1891 | } |
| 1892 | ret = index; |
| 1893 | break; |
| 1894 | case WB_ISDELIMITER: |
| 1895 | ret = (s[index] == ' '); |
| 1896 | break; |
| 1897 | default: |
| 1898 | fprintf(stderr, "edit: EDIT_WordBreakProc: unknown action code, please report !\n"); |
| 1899 | break; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1900 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1901 | return ret; |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1904 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1905 | /********************************************************************* |
| 1906 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1907 | * EM_CHARFROMPOS |
| 1908 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1909 | * FIXME: do the specs mean to return LineIndex or LineNumber ??? |
| 1910 | * Let's assume LineIndex is meant |
| 1911 | * FIXME: do the specs mean to return -1 if outside client area or |
| 1912 | * if outside formatting rectangle ??? |
| 1913 | * |
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 | 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] | 1916 | { |
| 1917 | POINT32 pt; |
| 1918 | RECT32 rc; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1919 | INT32 index; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1920 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1921 | pt.x = x; |
| 1922 | pt.y = y; |
| 1923 | GetClientRect32(wnd->hwndSelf, &rc); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1924 | if (!PtInRect32(&rc, pt)) |
| 1925 | return -1; |
| 1926 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1927 | index = EDIT_CharFromPos(wnd, es, x, y, NULL); |
| 1928 | return MAKELONG(index, EDIT_EM_LineIndex(wnd, es, |
| 1929 | EDIT_EM_LineFromChar(wnd, es, index))); |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1932 | |
Alexandre Julliard | d2e1c1a | 1996-03-09 16:12:43 +0000 | [diff] [blame] | 1933 | /********************************************************************* |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1934 | * |
| 1935 | * EM_FMTLINES |
| 1936 | * |
Alexandre Julliard | bd34d4f | 1995-06-20 19:08:12 +0000 | [diff] [blame] | 1937 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1938 | static BOOL32 EDIT_EM_FmtLines(WND *wnd, EDITSTATE *es, BOOL32 add_eol) |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1939 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1940 | fprintf(stdnimp, "edit: EM_FMTLINES: message not implemented\n"); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1941 | return add_eol; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1942 | } |
Alexandre Julliard | 988ca97 | 1994-06-21 16:15:21 +0000 | [diff] [blame] | 1943 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1944 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1945 | /********************************************************************* |
| 1946 | * |
| 1947 | * EM_GETHANDLE |
| 1948 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1949 | * Hopefully this won't fire back at us. |
| 1950 | * We always start with a fixed buffer in our own heap. |
| 1951 | * However, with this message a 32 bit application requests |
| 1952 | * a handle to 32 bit moveable local heap memory, where it expects |
| 1953 | * to find the text. |
| 1954 | * It's a pitty that from this moment on we have to use this |
| 1955 | * local heap, because applications may rely on the handle |
| 1956 | * in the future. |
| 1957 | * |
| 1958 | * In this function we'll try to switch to local heap. |
| 1959 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1960 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1961 | static HLOCAL32 EDIT_EM_GetHandle(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1962 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1963 | HLOCAL32 newBuf; |
| 1964 | LPSTR newText; |
| 1965 | INT32 newSize; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 1966 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1967 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1968 | return 0; |
| 1969 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1970 | if (es->hloc32) |
| 1971 | return es->hloc32; |
| 1972 | else if (es->hloc16) |
| 1973 | return (HLOCAL32)es->hloc16; |
| 1974 | |
| 1975 | if (!(newBuf = LocalAlloc32(LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) { |
| 1976 | fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 32 bit buffer\n"); |
| 1977 | return 0; |
| 1978 | } |
| 1979 | newSize = MIN(LocalSize32(newBuf) - 1, es->buffer_limit); |
| 1980 | if (!(newText = LocalLock32(newBuf))) { |
| 1981 | fprintf(stderr, "edit: EM_GETHANDLE: could not lock new 32 bit buffer\n"); |
| 1982 | LocalFree32(newBuf); |
| 1983 | return 0; |
| 1984 | } |
| 1985 | lstrcpy32A(newText, es->text); |
| 1986 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 1987 | if (es->text) |
| 1988 | HeapFree(es->heap, 0, es->text); |
| 1989 | es->hloc32 = newBuf; |
| 1990 | es->hloc16 = (HLOCAL16)NULL; |
| 1991 | es->buffer_size = newSize; |
| 1992 | es->text = newText; |
| 1993 | EDIT_LockBuffer(wnd, es); |
| 1994 | dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 32 bit local heap\n"); |
| 1995 | |
| 1996 | return es->hloc32; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 1997 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 1998 | |
| 1999 | |
| 2000 | /********************************************************************* |
| 2001 | * |
| 2002 | * EM_GETHANDLE16 |
| 2003 | * |
| 2004 | * Hopefully this won't fire back at us. |
| 2005 | * We always start with a buffer in 32 bit linear memory. |
| 2006 | * However, with this message a 16 bit application requests |
| 2007 | * a handle of 16 bit local heap memory, where it expects to find |
| 2008 | * the text. |
| 2009 | * It's a pitty that from this moment on we have to use this |
| 2010 | * local heap, because applications may rely on the handle |
| 2011 | * in the future. |
| 2012 | * |
| 2013 | * In this function we'll try to switch to local heap. |
| 2014 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2015 | static HLOCAL16 EDIT_EM_GetHandle16(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2016 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2017 | HLOCAL16 newBuf; |
| 2018 | LPSTR newText; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2019 | INT32 newSize; |
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 (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2022 | return 0; |
| 2023 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2024 | if (es->hloc16) |
| 2025 | return es->hloc16; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2026 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2027 | if (!LOCAL_HeapSize(wnd->hInstance)) { |
| 2028 | if (!LocalInit(wnd->hInstance, 0, |
| 2029 | GlobalSize16(wnd->hInstance))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2030 | fprintf(stderr, "edit: EM_GETHANDLE: could not initialize local heap\n"); |
| 2031 | return 0; |
| 2032 | } |
| 2033 | dprintf_edit(stddeb, "edit: EM_GETHANDLE: local heap initialized\n"); |
| 2034 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2035 | if (!(newBuf = LOCAL_Alloc(wnd->hInstance, LMEM_MOVEABLE, lstrlen32A(es->text) + 1))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2036 | fprintf(stderr, "edit: EM_GETHANDLE: could not allocate new 16 bit buffer\n"); |
| 2037 | return 0; |
| 2038 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2039 | newSize = MIN(LOCAL_Size(wnd->hInstance, newBuf) - 1, es->buffer_limit); |
| 2040 | if (!(newText = LOCAL_Lock(wnd->hInstance, newBuf))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2041 | 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] | 2042 | LOCAL_Free(wnd->hInstance, newBuf); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2043 | return 0; |
| 2044 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2045 | lstrcpy32A(newText, es->text); |
| 2046 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 2047 | if (es->text) |
| 2048 | HeapFree(es->heap, 0, es->text); |
| 2049 | else if (es->hloc32) { |
| 2050 | while (LocalFree32(es->hloc32)) ; |
| 2051 | LocalFree32(es->hloc32); |
| 2052 | } |
| 2053 | es->hloc32 = (HLOCAL32)NULL; |
| 2054 | es->hloc16 = newBuf; |
| 2055 | es->buffer_size = newSize; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2056 | es->text = newText; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2057 | EDIT_LockBuffer(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2058 | dprintf_edit(stddeb, "edit: EM_GETHANDLE: switched to 16 bit buffer\n"); |
| 2059 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2060 | return es->hloc16; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2063 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2064 | /********************************************************************* |
| 2065 | * |
| 2066 | * EM_GETLINE |
| 2067 | * |
| 2068 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2069 | 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] | 2070 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2071 | LPSTR src; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2072 | INT32 len; |
| 2073 | INT32 i; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2074 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2075 | if (es->style & ES_MULTILINE) { |
| 2076 | if (line >= es->line_count) |
| 2077 | return 0; |
| 2078 | } else |
| 2079 | line = 0; |
| 2080 | src = es->text + EDIT_EM_LineIndex(wnd, es, line); |
| 2081 | len = MIN(*(WORD *)lpch, EDIT_EM_LineLength(wnd, es, line)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2082 | for (i = 0 ; i < len ; i++) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2083 | *lpch = *src; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2084 | src++; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2085 | lpch++; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2086 | } |
| 2087 | return (LRESULT)len; |
| 2088 | } |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2089 | |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2090 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2091 | /********************************************************************* |
| 2092 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2093 | * EM_GETSEL |
| 2094 | * |
| 2095 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2096 | 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] | 2097 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2098 | UINT32 s = es->selection_start; |
| 2099 | UINT32 e = es->selection_end; |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2100 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2101 | ORDER_UINT32(s, e); |
| 2102 | if (start) |
| 2103 | *start = s; |
| 2104 | if (end) |
| 2105 | *end = e; |
| 2106 | return MAKELONG(s, e); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | /********************************************************************* |
| 2111 | * |
| 2112 | * EM_GETTHUMB |
| 2113 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2114 | * FIXME: is this right ? (or should it be only VSCROLL) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2115 | * (and maybe only for edit controls that really have their |
| 2116 | * own scrollbars) (and maybe only for multiline controls ?) |
| 2117 | * All in all: very poorly documented |
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 | * FIXME: now it's also broken, because of the new WM_HSCROLL / |
| 2120 | * WM_VSCROLL handlers |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2121 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2122 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2123 | static LRESULT EDIT_EM_GetThumb(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2124 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2125 | return MAKELONG(EDIT_WM_VScroll(wnd, es, EM_GETTHUMB16, 0, 0), |
| 2126 | EDIT_WM_HScroll(wnd, es, EM_GETTHUMB16, 0, 0)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | |
| 2130 | /********************************************************************* |
| 2131 | * |
| 2132 | * EM_LINEFROMCHAR |
| 2133 | * |
| 2134 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2135 | static INT32 EDIT_EM_LineFromChar(WND *wnd, EDITSTATE *es, INT32 index) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2136 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2137 | INT32 line; |
| 2138 | LINEDEF *line_def; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2139 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2140 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2141 | return 0; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2142 | if (index > lstrlen32A(es->text)) |
| 2143 | return es->line_count - 1; |
| 2144 | if (index == -1) |
| 2145 | index = MIN(es->selection_start, es->selection_end); |
| 2146 | |
| 2147 | line = 0; |
| 2148 | line_def = es->first_line_def; |
| 2149 | index -= line_def->length; |
| 2150 | while ((index >= 0) && line_def->next) { |
| 2151 | line++; |
| 2152 | line_def = line_def->next; |
| 2153 | index -= line_def->length; |
| 2154 | } |
| 2155 | return line; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | |
| 2159 | /********************************************************************* |
| 2160 | * |
| 2161 | * EM_LINEINDEX |
| 2162 | * |
| 2163 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2164 | static INT32 EDIT_EM_LineIndex(WND *wnd, EDITSTATE *es, INT32 line) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2165 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2166 | INT32 line_index; |
| 2167 | LINEDEF *line_def; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2168 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2169 | if (!(es->style & ES_MULTILINE)) |
| 2170 | return 0; |
| 2171 | if (line >= es->line_count) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2172 | return -1; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2173 | |
| 2174 | line_index = 0; |
| 2175 | line_def = es->first_line_def; |
| 2176 | if (line == -1) { |
| 2177 | INT32 index = es->selection_end - line_def->length; |
| 2178 | while ((index >= 0) && line_def->next) { |
| 2179 | line_index += line_def->length; |
| 2180 | line_def = line_def->next; |
| 2181 | index -= line_def->length; |
| 2182 | } |
| 2183 | } else { |
| 2184 | while (line > 0) { |
| 2185 | line_index += line_def->length; |
| 2186 | line_def = line_def->next; |
| 2187 | line--; |
| 2188 | } |
| 2189 | } |
| 2190 | return line_index; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | |
| 2194 | /********************************************************************* |
| 2195 | * |
| 2196 | * EM_LINELENGTH |
| 2197 | * |
| 2198 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2199 | static INT32 EDIT_EM_LineLength(WND *wnd, EDITSTATE *es, INT32 index) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2200 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2201 | LINEDEF *line_def; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2202 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2203 | if (!(es->style & ES_MULTILINE)) |
| 2204 | return lstrlen32A(es->text); |
| 2205 | |
| 2206 | if (index == -1) { |
| 2207 | /* FIXME: broken |
| 2208 | INT32 sl = EDIT_EM_LineFromChar(wnd, es, es->selection_start); |
| 2209 | INT32 el = EDIT_EM_LineFromChar(wnd, es, es->selection_end); |
| 2210 | return es->selection_start - es->line_defs[sl].offset + |
| 2211 | es->line_defs[el].offset + |
| 2212 | es->line_defs[el].length - es->selection_end; |
| 2213 | */ |
| 2214 | return 0; |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 2215 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2216 | line_def = es->first_line_def; |
| 2217 | index -= line_def->length; |
| 2218 | while ((index >= 0) && line_def->next) { |
| 2219 | line_def = line_def->next; |
| 2220 | index -= line_def->length; |
| 2221 | } |
| 2222 | return line_def->net_length; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2223 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2224 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2225 | |
| 2226 | /********************************************************************* |
| 2227 | * |
| 2228 | * EM_LINESCROLL |
| 2229 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2230 | * FIXME: dx is in average character widths |
| 2231 | * However, we assume it is in pixels when we use this |
| 2232 | * function internally |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2233 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2234 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2235 | 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] | 2236 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2237 | INT32 nyoff; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2238 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2239 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2240 | return FALSE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2241 | |
| 2242 | if (-dx > es->x_offset) |
| 2243 | dx = -es->x_offset; |
| 2244 | if (dx > es->text_width - es->x_offset) |
| 2245 | dx = es->text_width - es->x_offset; |
| 2246 | nyoff = MAX(0, es->y_offset + dy); |
| 2247 | if (nyoff >= es->line_count) |
| 2248 | nyoff = es->line_count - 1; |
| 2249 | dy = (es->y_offset - nyoff) * es->line_height; |
| 2250 | if (dx || dy) { |
| 2251 | if (!(wnd->flags & WIN_NO_REDRAW)) { |
| 2252 | RECT32 rc1; |
| 2253 | RECT32 rc; |
| 2254 | GetClientRect32(wnd->hwndSelf, &rc1); |
| 2255 | IntersectRect32(&rc, &rc1, &es->format_rect); |
| 2256 | ScrollWindowEx32(wnd->hwndSelf, -dx, dy, |
| 2257 | NULL, &rc, (HRGN32)NULL, NULL, SW_INVALIDATE); |
| 2258 | } |
| 2259 | es->y_offset = nyoff; |
| 2260 | es->x_offset += dx; |
| 2261 | } |
| 2262 | if (dx && !(es->flags & EF_HSCROLL_TRACK)) |
| 2263 | EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); |
| 2264 | if (dy && !(es->flags & EF_VSCROLL_TRACK)) |
| 2265 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
| 2266 | return TRUE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
| 2269 | |
| 2270 | /********************************************************************* |
| 2271 | * |
| 2272 | * EM_POSFROMCHAR |
| 2273 | * |
| 2274 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2275 | 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] | 2276 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2277 | INT32 len = lstrlen32A(es->text); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2278 | INT32 l; |
| 2279 | INT32 li; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2280 | INT32 x; |
| 2281 | INT32 y = 0; |
| 2282 | HDC32 dc; |
| 2283 | HFONT32 old_font = 0; |
| 2284 | SIZE32 size; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2285 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2286 | index = MIN(index, len); |
| 2287 | dc = GetDC32(wnd->hwndSelf); |
| 2288 | if (es->font) |
| 2289 | old_font = SelectObject32(dc, es->font); |
| 2290 | if (es->style & ES_MULTILINE) { |
| 2291 | l = EDIT_EM_LineFromChar(wnd, es, index); |
| 2292 | y = (l - es->y_offset) * es->line_height; |
| 2293 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 2294 | if (after_wrap && (li == index) && l) { |
| 2295 | INT32 l2 = l - 1; |
| 2296 | LINEDEF *line_def = es->first_line_def; |
| 2297 | while (l2) { |
| 2298 | line_def = line_def->next; |
| 2299 | l2--; |
| 2300 | } |
| 2301 | if (line_def->ending == END_WRAP) { |
| 2302 | l--; |
| 2303 | y -= es->line_height; |
| 2304 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 2305 | } |
| 2306 | } |
| 2307 | x = LOWORD(GetTabbedTextExtent32A(dc, es->text + li, index - li, |
| 2308 | es->tabs_count, es->tabs)) - es->x_offset; |
| 2309 | } else { |
| 2310 | LPSTR text = EDIT_GetPasswordPointer_SL(wnd, es); |
| 2311 | if (index < es->x_offset) { |
| 2312 | GetTextExtentPoint32A(dc, text + index, |
| 2313 | es->x_offset - index, &size); |
| 2314 | x = -size.cx; |
| 2315 | } else { |
| 2316 | GetTextExtentPoint32A(dc, text + es->x_offset, |
| 2317 | index - es->x_offset, &size); |
| 2318 | x = size.cx; |
| 2319 | } |
| 2320 | y = 0; |
| 2321 | if (es->style & ES_PASSWORD) |
| 2322 | HeapFree(es->heap, 0 ,text); |
| 2323 | } |
| 2324 | x += es->format_rect.left; |
| 2325 | y += es->format_rect.top; |
| 2326 | if (es->font) |
| 2327 | SelectObject32(dc, old_font); |
| 2328 | ReleaseDC32(wnd->hwndSelf, dc); |
| 2329 | return MAKELONG((INT16)x, (INT16)y); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
| 2332 | |
| 2333 | /********************************************************************* |
| 2334 | * |
| 2335 | * EM_REPLACESEL |
| 2336 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2337 | * FIXME: handle ES_NUMBER and ES_OEMCONVERT here |
| 2338 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2339 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2340 | 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] | 2341 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2342 | INT32 strl = lstrlen32A(lpsz_replace); |
| 2343 | INT32 tl = lstrlen32A(es->text); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2344 | INT32 utl; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2345 | UINT32 s; |
| 2346 | UINT32 e; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2347 | INT32 i; |
| 2348 | LPSTR p; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2349 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2350 | s = es->selection_start; |
| 2351 | e = es->selection_end; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2352 | |
| 2353 | if ((s == e) && !strl) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2354 | return; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2355 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2356 | ORDER_UINT32(s, e); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2357 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2358 | if (!EDIT_MakeFit(wnd, es, tl - (e - s) + strl)) |
| 2359 | return; |
| 2360 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2361 | if (e != s) { |
| 2362 | /* there is something to be deleted */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2363 | if (can_undo) { |
| 2364 | utl = lstrlen32A(es->undo_text); |
| 2365 | if (!es->undo_insert_count && (*es->undo_text && (s == es->undo_position))) { |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2366 | /* undo-buffer is extended to the right */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2367 | EDIT_MakeUndoFit(wnd, es, utl + e - s); |
| 2368 | lstrcpyn32A(es->undo_text + utl, es->text + s, e - s + 1); |
| 2369 | } 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] | 2370 | /* undo-buffer is extended to the left */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2371 | EDIT_MakeUndoFit(wnd, es, utl + e - s); |
| 2372 | for (p = es->undo_text + utl ; p >= es->undo_text ; p--) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2373 | p[e - s] = p[0]; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2374 | for (i = 0 , p = es->undo_text ; i < e - s ; i++) |
| 2375 | p[i] = (es->text + s)[i]; |
| 2376 | es->undo_position = s; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2377 | } else { |
| 2378 | /* new undo-buffer */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2379 | EDIT_MakeUndoFit(wnd, es, e - s); |
| 2380 | lstrcpyn32A(es->undo_text, es->text + s, e - s + 1); |
| 2381 | es->undo_position = s; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2382 | } |
| 2383 | /* any deletion makes the old insertion-undo invalid */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2384 | es->undo_insert_count = 0; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2385 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2386 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2387 | |
| 2388 | /* now delete */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2389 | lstrcpy32A(es->text + s, es->text + e); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2390 | } |
| 2391 | if (strl) { |
| 2392 | /* there is an insertion */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2393 | if (can_undo) { |
| 2394 | if ((s == es->undo_position) || |
| 2395 | ((es->undo_insert_count) && |
| 2396 | (s == es->undo_position + es->undo_insert_count))) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2397 | /* |
| 2398 | * insertion is new and at delete position or |
| 2399 | * an extension to either left or right |
| 2400 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2401 | es->undo_insert_count += strl; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2402 | else { |
| 2403 | /* new insertion undo */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2404 | es->undo_position = s; |
| 2405 | es->undo_insert_count = strl; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2406 | /* new insertion makes old delete-buffer invalid */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2407 | *es->undo_text = '\0'; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2408 | } |
| 2409 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2410 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2411 | |
| 2412 | /* now insert */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2413 | tl = lstrlen32A(es->text); |
| 2414 | for (p = es->text + tl ; p >= es->text + s ; p--) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2415 | p[strl] = p[0]; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2416 | for (i = 0 , p = es->text + s ; i < strl ; i++) |
| 2417 | p[i] = lpsz_replace[i]; |
| 2418 | if(es->style & ES_UPPERCASE) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2419 | CharUpperBuff32A(p, strl); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2420 | else if(es->style & ES_LOWERCASE) |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2421 | CharLowerBuff32A(p, strl); |
| 2422 | s += strl; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2423 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2424 | /* FIXME: really inefficient */ |
| 2425 | if (es->style & ES_MULTILINE) |
| 2426 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2427 | |
| 2428 | EDIT_EM_SetSel(wnd, es, s, s, FALSE); |
| 2429 | es->flags |= EF_MODIFIED; |
| 2430 | es->flags |= EF_UPDATE; |
| 2431 | EDIT_EM_ScrollCaret(wnd, es); |
| 2432 | |
| 2433 | /* FIXME: really inefficient */ |
| 2434 | if (!(wnd->flags & WIN_NO_REDRAW)) |
| 2435 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2436 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2437 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2438 | |
| 2439 | /********************************************************************* |
| 2440 | * |
| 2441 | * EM_SCROLL |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2442 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2443 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2444 | static LRESULT EDIT_EM_Scroll(WND *wnd, EDITSTATE *es, INT32 action) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2445 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2446 | INT32 dy; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2447 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2448 | if (!(es->style & ES_MULTILINE)) |
| 2449 | return (LRESULT)FALSE; |
| 2450 | |
| 2451 | dy = 0; |
| 2452 | |
| 2453 | switch (action) { |
| 2454 | case SB_LINEUP: |
| 2455 | if (es->y_offset) |
| 2456 | dy = -1; |
| 2457 | break; |
| 2458 | case SB_LINEDOWN: |
| 2459 | if (es->y_offset < es->line_count - 1) |
| 2460 | dy = 1; |
| 2461 | break; |
| 2462 | case SB_PAGEUP: |
| 2463 | if (es->y_offset) |
| 2464 | dy = -(es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 2465 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2466 | case SB_PAGEDOWN: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2467 | if (es->y_offset < es->line_count - 1) |
| 2468 | dy = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 2469 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2470 | default: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2471 | return (LRESULT)FALSE; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2472 | } |
| 2473 | if (dy) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2474 | EDIT_EM_LineScroll(wnd, es, 0, dy); |
| 2475 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2476 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2477 | return MAKELONG((INT16)dy, (BOOL16)TRUE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
| 2480 | |
| 2481 | /********************************************************************* |
| 2482 | * |
| 2483 | * EM_SETHANDLE |
| 2484 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2485 | * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? |
| 2486 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2487 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2488 | static void EDIT_EM_SetHandle(WND *wnd, EDITSTATE *es, HLOCAL32 hloc) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2489 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2490 | if (!(es->style & ES_MULTILINE)) |
| 2491 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2492 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2493 | if (!hloc) { |
| 2494 | fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n"); |
| 2495 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2496 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2497 | |
| 2498 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 2499 | /* |
| 2500 | * old buffer is freed by caller, unless |
| 2501 | * it is still in our own heap. (in that case |
| 2502 | * we free it, correcting the buggy caller.) |
| 2503 | */ |
| 2504 | if (es->text) |
| 2505 | HeapFree(es->heap, 0, es->text); |
| 2506 | |
| 2507 | es->hloc16 = (HLOCAL16)NULL; |
| 2508 | es->hloc32 = hloc; |
| 2509 | es->text = NULL; |
| 2510 | es->buffer_size = LocalSize32(es->hloc32) - 1; |
| 2511 | EDIT_LockBuffer(wnd, es); |
| 2512 | |
| 2513 | es->x_offset = es->y_offset = 0; |
| 2514 | es->selection_start = es->selection_end = 0; |
| 2515 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
| 2516 | es->flags &= ~EF_MODIFIED; |
| 2517 | es->flags &= ~EF_UPDATE; |
| 2518 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2519 | if (!(wnd->flags & WIN_NO_REDRAW)) |
| 2520 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2521 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | /********************************************************************* |
| 2526 | * |
| 2527 | * EM_SETHANDLE16 |
| 2528 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2529 | * FIXME: ES_LOWERCASE, ES_UPPERCASE, ES_OEMCONVERT, ES_NUMBER ??? |
| 2530 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2531 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2532 | static void EDIT_EM_SetHandle16(WND *wnd, EDITSTATE *es, HLOCAL16 hloc) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2533 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2534 | if (!(es->style & ES_MULTILINE)) |
| 2535 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2536 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2537 | if (!hloc) { |
| 2538 | fprintf(stderr, "edit: EM_SETHANDLE called with NULL handle\n"); |
| 2539 | return; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2540 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2541 | |
| 2542 | EDIT_UnlockBuffer(wnd, es, TRUE); |
| 2543 | /* |
| 2544 | * old buffer is freed by caller, unless |
| 2545 | * it is still in our own heap. (in that case |
| 2546 | * we free it, correcting the buggy caller.) |
| 2547 | */ |
| 2548 | if (es->text) |
| 2549 | HeapFree(es->heap, 0, es->text); |
| 2550 | |
| 2551 | es->hloc16 = hloc; |
| 2552 | es->hloc32 = (HLOCAL32)NULL; |
| 2553 | es->text = NULL; |
| 2554 | es->buffer_size = LOCAL_Size(wnd->hInstance, es->hloc16) - 1; |
| 2555 | EDIT_LockBuffer(wnd, es); |
| 2556 | |
| 2557 | es->x_offset = es->y_offset = 0; |
| 2558 | es->selection_start = es->selection_end = 0; |
| 2559 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
| 2560 | es->flags &= ~EF_MODIFIED; |
| 2561 | es->flags &= ~EF_UPDATE; |
| 2562 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2563 | if (!(wnd->flags & WIN_NO_REDRAW)) |
| 2564 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2565 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | |
| 2569 | /********************************************************************* |
| 2570 | * |
| 2571 | * EM_SETLIMITTEXT |
| 2572 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2573 | * FIXME: in WinNT maxsize is 0x7FFFFFFF / 0xFFFFFFFF |
| 2574 | * However, the windows version is not complied to yet in all of edit.c |
| 2575 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2576 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2577 | static void EDIT_EM_SetLimitText(WND *wnd, EDITSTATE *es, INT32 limit) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2578 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2579 | if (es->style & ES_MULTILINE) { |
| 2580 | if (limit) |
| 2581 | es->buffer_limit = MIN(limit, BUFLIMIT_MULTI); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2582 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2583 | es->buffer_limit = BUFLIMIT_MULTI; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2584 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2585 | if (limit) |
| 2586 | es->buffer_limit = MIN(limit, BUFLIMIT_SINGLE); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2587 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2588 | es->buffer_limit = BUFLIMIT_SINGLE; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2589 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | |
| 2593 | /********************************************************************* |
| 2594 | * |
| 2595 | * EM_SETMARGINS |
| 2596 | * |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2597 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2598 | 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] | 2599 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2600 | if (action & EC_USEFONTINFO) { |
| 2601 | if (es->style & ES_MULTILINE) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2602 | /* |
| 2603 | * FIXME: do some GetABCCharWidth, or so |
| 2604 | * This is just preliminary |
| 2605 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2606 | es->left_margin = es->right_margin = es->char_width; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2607 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2608 | es->left_margin = es->right_margin = es->char_width; |
| 2609 | return; |
| 2610 | } else { |
| 2611 | if (action & EC_LEFTMARGIN) |
| 2612 | es->left_margin = left; |
| 2613 | if (action & EC_RIGHTMARGIN) |
| 2614 | es->right_margin = right; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2615 | } |
Alexandre Julliard | 5819953 | 1994-04-21 01:20:00 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2618 | |
| 2619 | /********************************************************************* |
| 2620 | * |
| 2621 | * EM_SETPASSWORDCHAR |
| 2622 | * |
| 2623 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2624 | static void EDIT_EM_SetPasswordChar(WND *wnd, EDITSTATE *es, CHAR c) |
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 | if (es->style & ES_MULTILINE) |
| 2627 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2628 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2629 | if (es->password_char == c) |
| 2630 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2631 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2632 | es->password_char = c; |
| 2633 | if (c) { |
| 2634 | wnd->dwStyle |= ES_PASSWORD; |
| 2635 | es->style |= ES_PASSWORD; |
| 2636 | } else { |
| 2637 | wnd->dwStyle &= ~ES_PASSWORD; |
| 2638 | es->style &= ~ES_PASSWORD; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2639 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2640 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | |
| 2644 | /********************************************************************* |
| 2645 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2646 | * EDIT_EM_SetSel |
| 2647 | * |
| 2648 | * note: unlike the specs say: the order of start and end |
| 2649 | * _is_ preserved in Windows. (i.e. start can be > end) |
| 2650 | * In other words: this handler is OK |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2651 | * |
| 2652 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2653 | 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] | 2654 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2655 | UINT32 old_start = es->selection_start; |
| 2656 | UINT32 old_end = es->selection_end; |
| 2657 | UINT32 len = lstrlen32A(es->text); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2658 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2659 | if (start == -1) { |
| 2660 | start = es->selection_end; |
| 2661 | end = es->selection_end; |
| 2662 | } else { |
| 2663 | start = MIN(start, len); |
| 2664 | end = MIN(end, len); |
| 2665 | } |
| 2666 | es->selection_start = start; |
| 2667 | es->selection_end = end; |
| 2668 | if (after_wrap) |
| 2669 | es->flags |= EF_AFTER_WRAP; |
| 2670 | else |
| 2671 | es->flags &= ~EF_AFTER_WRAP; |
| 2672 | if (!(wnd->flags & WIN_NO_REDRAW)) { |
| 2673 | if (es->flags & EF_FOCUSED) { |
| 2674 | LRESULT pos = EDIT_EM_PosFromChar(wnd, es, end, after_wrap); |
| 2675 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
| 2676 | } |
| 2677 | /* FIXME: little efficiency, could be better */ |
| 2678 | ORDER_UINT32(start, end); |
| 2679 | ORDER_UINT32(start, old_start); |
| 2680 | ORDER_UINT32(start, old_end); |
| 2681 | ORDER_UINT32(end, old_start); |
| 2682 | ORDER_UINT32(end, old_end); |
| 2683 | ORDER_UINT32(old_start, old_end); |
| 2684 | if (end != old_start) { |
| 2685 | EDIT_InvalidateText(wnd, es, start, end); |
| 2686 | EDIT_InvalidateText(wnd, es, old_start, old_end); |
| 2687 | } else |
| 2688 | EDIT_InvalidateText(wnd, es, start, old_end); |
| 2689 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | |
| 2693 | /********************************************************************* |
| 2694 | * |
| 2695 | * EM_SETTABSTOPS |
| 2696 | * |
| 2697 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2698 | 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] | 2699 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2700 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2701 | return FALSE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2702 | if (es->tabs) |
| 2703 | HeapFree(es->heap, 0, es->tabs); |
| 2704 | es->tabs_count = count; |
| 2705 | if (!count) |
| 2706 | es->tabs = NULL; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2707 | else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2708 | es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32)); |
| 2709 | memcpy(es->tabs, tabs, count * sizeof(INT32)); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2710 | } |
| 2711 | return TRUE; |
| 2712 | } |
| 2713 | |
| 2714 | |
| 2715 | /********************************************************************* |
| 2716 | * |
| 2717 | * EM_SETTABSTOPS16 |
| 2718 | * |
| 2719 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2720 | 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] | 2721 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2722 | if (!(es->style & ES_MULTILINE)) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2723 | return FALSE; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2724 | if (es->tabs) |
| 2725 | HeapFree(es->heap, 0, es->tabs); |
| 2726 | es->tabs_count = count; |
| 2727 | if (!count) |
| 2728 | es->tabs = NULL; |
| 2729 | else { |
| 2730 | INT32 i; |
| 2731 | es->tabs = HeapAlloc(es->heap, 0, count * sizeof(INT32)); |
| 2732 | for (i = 0 ; i < count ; i++) |
| 2733 | es->tabs[i] = *tabs++; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2734 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 2735 | return TRUE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2736 | } |
| 2737 | |
| 2738 | |
| 2739 | /********************************************************************* |
| 2740 | * |
| 2741 | * EM_SETWORDBREAKPROC |
| 2742 | * |
| 2743 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2744 | static void EDIT_EM_SetWordBreakProc(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC32A wbp) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2745 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2746 | if (es->word_break_proc32A == wbp) |
| 2747 | return; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2748 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2749 | es->word_break_proc32A = wbp; |
| 2750 | es->word_break_proc16 = NULL; |
| 2751 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { |
| 2752 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2753 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2754 | } |
| 2755 | } |
| 2756 | |
| 2757 | |
| 2758 | /********************************************************************* |
| 2759 | * |
| 2760 | * EM_SETWORDBREAKPROC16 |
| 2761 | * |
| 2762 | */ |
| 2763 | static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPROC16 wbp) |
| 2764 | { |
| 2765 | if (es->word_break_proc16 == wbp) |
| 2766 | return; |
| 2767 | |
| 2768 | es->word_break_proc32A = NULL; |
| 2769 | es->word_break_proc16 = wbp; |
| 2770 | if ((es->style & ES_MULTILINE) && !(es->style & ES_AUTOHSCROLL)) { |
| 2771 | EDIT_BuildLineDefs_ML(wnd, es); |
| 2772 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 2773 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | |
| 2777 | /********************************************************************* |
| 2778 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2779 | * EM_UNDO / WM_UNDO |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2780 | * |
| 2781 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2782 | static BOOL32 EDIT_EM_Undo(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2783 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2784 | INT32 ulength = lstrlen32A(es->undo_text); |
| 2785 | LPSTR utext = HeapAlloc(es->heap, 0, ulength + 1); |
| 2786 | |
| 2787 | lstrcpy32A(utext, es->undo_text); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2788 | |
| 2789 | 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] | 2790 | es->undo_insert_count, utext); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2791 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2792 | EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); |
| 2793 | EDIT_EM_EmptyUndoBuffer(wnd, es); |
| 2794 | EDIT_EM_ReplaceSel(wnd, es, TRUE, utext); |
| 2795 | EDIT_EM_SetSel(wnd, es, es->undo_position, es->undo_position + es->undo_insert_count, FALSE); |
| 2796 | HeapFree(es->heap, 0, utext); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2797 | |
| 2798 | 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] | 2799 | es->undo_insert_count, es->undo_text); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2800 | |
| 2801 | return TRUE; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | |
| 2805 | /********************************************************************* |
| 2806 | * |
| 2807 | * WM_CHAR |
| 2808 | * |
| 2809 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2810 | 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] | 2811 | { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2812 | switch (c) { |
| 2813 | case '\r': |
| 2814 | case '\n': |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2815 | if (es->style & ES_MULTILINE) { |
| 2816 | if (es->style & ES_READONLY) { |
| 2817 | EDIT_MoveHome(wnd, es, FALSE); |
| 2818 | EDIT_MoveDown_ML(wnd, es, FALSE); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2819 | } else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2820 | EDIT_EM_ReplaceSel(wnd, es, TRUE, "\r\n"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2821 | } |
| 2822 | break; |
| 2823 | case '\t': |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2824 | if ((es->style & ES_MULTILINE) && !(es->style & ES_READONLY)) |
| 2825 | EDIT_EM_ReplaceSel(wnd, es, TRUE, "\t"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2826 | break; |
| 2827 | default: |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 2828 | if (!(es->style & ES_READONLY) && ((BYTE)c >= ' ') && (c != 127)) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2829 | char str[2]; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2830 | str[0] = c; |
| 2831 | str[1] = '\0'; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2832 | EDIT_EM_ReplaceSel(wnd, es, TRUE, str); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2833 | } |
| 2834 | break; |
| 2835 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2836 | } |
| 2837 | |
| 2838 | |
| 2839 | /********************************************************************* |
| 2840 | * |
| 2841 | * WM_COMMAND |
| 2842 | * |
| 2843 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2844 | 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] | 2845 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2846 | if (code || control) |
| 2847 | return; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2848 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2849 | switch (id) { |
| 2850 | case EM_UNDO32: |
| 2851 | EDIT_EM_Undo(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2852 | break; |
| 2853 | case WM_CUT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2854 | EDIT_WM_Cut(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2855 | break; |
| 2856 | case WM_COPY: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2857 | EDIT_WM_Copy(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2858 | break; |
| 2859 | case WM_PASTE: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2860 | EDIT_WM_Paste(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2861 | break; |
| 2862 | case WM_CLEAR: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2863 | EDIT_WM_Clear(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2864 | break; |
| 2865 | case EM_SETSEL32: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2866 | EDIT_EM_SetSel(wnd, es, 0, -1, FALSE); |
| 2867 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | default: |
| 2870 | dprintf_edit(stddeb, "edit: unknown menu item, please report\n"); |
| 2871 | break; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2872 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 2873 | } |
| 2874 | |
| 2875 | |
| 2876 | /********************************************************************* |
| 2877 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2878 | * WM_CONTEXTMENU |
| 2879 | * |
| 2880 | * Note: the resource files resource/sysres_??.rc cannot define a |
| 2881 | * single popup menu. Hence we use a (dummy) menubar |
| 2882 | * containing the single popup menu as its first item. |
| 2883 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2884 | * FIXME: the message identifiers have been chosen arbitrarily, |
| 2885 | * hence we use MF_BYPOSITION. |
| 2886 | * We might as well use the "real" values (anybody knows ?) |
| 2887 | * The menu definition is in resources/sysres_??.rc. |
| 2888 | * Once these are OK, we better use MF_BYCOMMAND here |
| 2889 | * (as we do in EDIT_WM_Command()). |
| 2890 | * |
| 2891 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2892 | 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] | 2893 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2894 | HMENU32 menu = LoadMenuIndirect32A(SYSRES_GetResPtr(SYSRES_MENU_EDITMENU)); |
| 2895 | HMENU32 popup = GetSubMenu32(menu, 0); |
| 2896 | UINT32 start = es->selection_start; |
| 2897 | UINT32 end = es->selection_end; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2898 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2899 | ORDER_UINT32(start, end); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2900 | |
| 2901 | /* undo */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2902 | 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] | 2903 | /* cut */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2904 | 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] | 2905 | /* copy */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2906 | 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] | 2907 | /* paste */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2908 | EnableMenuItem32(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable32(CF_TEXT) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2909 | /* delete */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2910 | EnableMenuItem32(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2911 | /* select all */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2912 | 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] | 2913 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2914 | TrackPopupMenu32(popup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, 0, wnd->hwndSelf, NULL); |
| 2915 | DestroyMenu32(menu); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2918 | |
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 | * WM_COPY |
| 2922 | * |
| 2923 | * FIXME: replace with 32 bit calls as soon as they are implemented |
| 2924 | * in the clipboard code |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2925 | * |
| 2926 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2927 | static void EDIT_WM_Copy(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2928 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2929 | INT32 s = es->selection_start; |
| 2930 | INT32 e = es->selection_end; |
| 2931 | HGLOBAL16 hdst; |
| 2932 | LPSTR dst; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2933 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2934 | if (e == s) |
| 2935 | return; |
| 2936 | ORDER_INT32(s, e); |
| 2937 | hdst = GlobalAlloc16(GMEM_MOVEABLE, (DWORD)(e - s + 1)); |
| 2938 | dst = GlobalLock16(hdst); |
| 2939 | lstrcpyn32A(dst, es->text + s, e - s + 1); |
| 2940 | GlobalUnlock16(hdst); |
| 2941 | OpenClipboard32(wnd->hwndSelf); |
| 2942 | EmptyClipboard32(); |
| 2943 | SetClipboardData16(CF_TEXT, hdst); |
| 2944 | CloseClipboard32(); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 2945 | } |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 2946 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 2947 | |
| 2948 | /********************************************************************* |
| 2949 | * |
| 2950 | * WM_CREATE |
| 2951 | * |
| 2952 | */ |
| 2953 | static LRESULT EDIT_WM_Create(WND *wnd, LPCREATESTRUCT32A cs) |
| 2954 | { |
| 2955 | EDITSTATE *es; |
| 2956 | |
| 2957 | if (!(es = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*es)))) |
| 2958 | return -1; |
| 2959 | *(EDITSTATE **)wnd->wExtra = es; |
| 2960 | if (!(es->heap = HeapCreate(0, 0x10000, 0))) |
| 2961 | return -1; |
| 2962 | es->style = cs->style; |
| 2963 | |
| 2964 | /* remove the WS_CAPTION style if it has been set - this is really a */ |
| 2965 | /* pseudo option made from a combination of WS_BORDER and WS_DLGFRAME */ |
| 2966 | if ((es->style & WS_BORDER) && (es->style & WS_DLGFRAME)) |
| 2967 | es->style ^= WS_DLGFRAME; |
| 2968 | |
| 2969 | if (es->style & ES_MULTILINE) { |
| 2970 | es->buffer_size = BUFSTART_MULTI; |
| 2971 | es->buffer_limit = BUFLIMIT_MULTI; |
| 2972 | if (es->style & WS_VSCROLL) |
| 2973 | es->style |= ES_AUTOVSCROLL; |
| 2974 | if (es->style & WS_HSCROLL) |
| 2975 | es->style |= ES_AUTOHSCROLL; |
| 2976 | es->style &= ~ES_PASSWORD; |
| 2977 | if ((es->style & ES_CENTER) || (es->style & ES_RIGHT)) { |
| 2978 | if (es->style & ES_RIGHT) |
| 2979 | es->style &= ~ES_CENTER; |
| 2980 | es->style &= ~WS_HSCROLL; |
| 2981 | es->style &= ~ES_AUTOHSCROLL; |
| 2982 | } |
| 2983 | |
| 2984 | /* FIXME: for now, all multi line controls are AUTOVSCROLL */ |
| 2985 | es->style |= ES_AUTOVSCROLL; |
| 2986 | } else { |
| 2987 | es->buffer_size = BUFSTART_SINGLE; |
| 2988 | es->buffer_limit = BUFLIMIT_SINGLE; |
| 2989 | es->style &= ~ES_CENTER; |
| 2990 | es->style &= ~ES_RIGHT; |
| 2991 | es->style &= ~WS_HSCROLL; |
| 2992 | es->style &= ~WS_VSCROLL; |
| 2993 | es->style &= ~ES_AUTOVSCROLL; |
| 2994 | es->style &= ~ES_WANTRETURN; |
| 2995 | if (es->style & ES_UPPERCASE) { |
| 2996 | es->style &= ~ES_LOWERCASE; |
| 2997 | es->style &= ~ES_NUMBER; |
| 2998 | } else if (es->style & ES_LOWERCASE) |
| 2999 | es->style &= ~ES_NUMBER; |
| 3000 | if (es->style & ES_PASSWORD) |
| 3001 | es->password_char = '*'; |
| 3002 | |
| 3003 | /* FIXME: for now, all single line controls are AUTOHSCROLL */ |
| 3004 | es->style |= ES_AUTOHSCROLL; |
| 3005 | } |
| 3006 | if (!(es->text = HeapAlloc(es->heap, 0, es->buffer_size + 1))) |
| 3007 | return -1; |
| 3008 | es->buffer_size = HeapSize(es->heap, 0, es->text) - 1; |
| 3009 | if (!(es->undo_text = HeapAlloc(es->heap, 0, es->buffer_size + 1))) |
| 3010 | return -1; |
| 3011 | es->undo_buffer_size = HeapSize(es->heap, 0, es->undo_text) - 1; |
| 3012 | *es->text = '\0'; |
| 3013 | if (es->style & ES_MULTILINE) |
| 3014 | if (!(es->first_line_def = HeapAlloc(es->heap, HEAP_ZERO_MEMORY, sizeof(LINEDEF)))) |
| 3015 | return -1; |
| 3016 | es->line_count = 1; |
| 3017 | /* |
| 3018 | * To initialize some final structure members, we call some helper |
| 3019 | * functions. However, since the EDITSTATE is not consistent (i.e. |
| 3020 | * not fully initialized), we should be very careful which |
| 3021 | * functions can be called, and in what order. |
| 3022 | */ |
| 3023 | EDIT_WM_SetFont(wnd, es, 0, FALSE); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 3024 | if (cs->lpszName && *(cs->lpszName) != '\0') { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3025 | EDIT_EM_ReplaceSel(wnd, es, FALSE, cs->lpszName); |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 3026 | /* 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 */ |
| 3027 | es->selection_start = es->selection_end = 0; |
| 3028 | EDIT_EM_ScrollCaret(wnd, es); |
| 3029 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3030 | return 0; |
| 3031 | } |
| 3032 | |
| 3033 | |
| 3034 | /********************************************************************* |
| 3035 | * |
| 3036 | * WM_DESTROY |
| 3037 | * |
| 3038 | */ |
| 3039 | static void EDIT_WM_Destroy(WND *wnd, EDITSTATE *es) |
| 3040 | { |
| 3041 | if (es->hloc32) { |
| 3042 | while (LocalUnlock32(es->hloc32)) ; |
| 3043 | LocalFree32(es->hloc32); |
| 3044 | } |
| 3045 | if (es->hloc16) { |
| 3046 | while (LOCAL_Unlock(wnd->hInstance, es->hloc16)) ; |
| 3047 | LOCAL_Free(wnd->hInstance, es->hloc16); |
| 3048 | } |
| 3049 | HeapDestroy(es->heap); |
| 3050 | HeapFree(GetProcessHeap(), 0, es); |
| 3051 | *(EDITSTATE **)wnd->wExtra = NULL; |
| 3052 | } |
| 3053 | |
| 3054 | |
| 3055 | /********************************************************************* |
| 3056 | * |
| 3057 | * WM_ERASEBKGND |
| 3058 | * |
| 3059 | */ |
| 3060 | static LRESULT EDIT_WM_EraseBkGnd(WND *wnd, EDITSTATE *es, HDC32 dc) |
| 3061 | { |
| 3062 | HBRUSH32 brush; |
| 3063 | RECT32 rc; |
| 3064 | |
| 3065 | if (!(brush = (HBRUSH32)EDIT_SEND_CTLCOLOR(wnd, dc))) |
| 3066 | brush = (HBRUSH32)GetStockObject32(WHITE_BRUSH); |
| 3067 | |
| 3068 | GetClientRect32(wnd->hwndSelf, &rc); |
| 3069 | IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom); |
| 3070 | GetClipBox32(dc, &rc); |
| 3071 | /* |
| 3072 | * FIXME: specs say that we should UnrealizeObject() the brush, |
| 3073 | * but the specs of UnrealizeObject() say that we shouldn't |
| 3074 | * unrealize a stock object. The default brush that |
| 3075 | * DefWndProc() returns is ... a stock object. |
| 3076 | */ |
| 3077 | FillRect32(dc, &rc, brush); |
| 3078 | return -1; |
| 3079 | } |
| 3080 | |
| 3081 | |
| 3082 | /********************************************************************* |
| 3083 | * |
| 3084 | * WM_GETTEXT |
| 3085 | * |
| 3086 | */ |
| 3087 | static INT32 EDIT_WM_GetText(WND *wnd, EDITSTATE *es, INT32 count, LPSTR text) |
| 3088 | { |
| 3089 | INT32 len = lstrlen32A(es->text); |
| 3090 | |
| 3091 | if (count > len) { |
| 3092 | lstrcpy32A(text, es->text); |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 3093 | return len; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3094 | } else |
Alexandre Julliard | 33072e1 | 1997-06-29 18:08:02 +0000 | [diff] [blame] | 3095 | return -1; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3096 | } |
| 3097 | |
| 3098 | |
| 3099 | /********************************************************************* |
| 3100 | * |
| 3101 | * EDIT_HScroll_Hack |
| 3102 | * |
| 3103 | * 16 bit notepad needs this. Actually it is not _our_ hack, |
| 3104 | * it is notepad's. Notepad is sending us scrollbar messages with |
| 3105 | * undocumented parameters without us even having a scrollbar ... !?!? |
| 3106 | * |
| 3107 | */ |
| 3108 | static LRESULT EDIT_HScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
| 3109 | { |
| 3110 | INT32 dx = 0; |
| 3111 | INT32 fw = es->format_rect.right - es->format_rect.left; |
| 3112 | LRESULT ret = 0; |
| 3113 | |
| 3114 | if (!(es->flags & EF_HSCROLL_HACK)) { |
| 3115 | fprintf(stderr, "edit: hacked WM_HSCROLL handler invoked\n"); |
| 3116 | fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n"); |
| 3117 | fprintf(stderr, " (this message is only displayed once per edit control)\n"); |
| 3118 | es->flags |= EF_HSCROLL_HACK; |
| 3119 | } |
| 3120 | |
| 3121 | switch (action) { |
| 3122 | case SB_LINELEFT: |
| 3123 | if (es->x_offset) |
| 3124 | dx = -es->char_width; |
| 3125 | break; |
| 3126 | case SB_LINERIGHT: |
| 3127 | if (es->x_offset < es->text_width) |
| 3128 | dx = es->char_width; |
| 3129 | break; |
| 3130 | case SB_PAGELEFT: |
| 3131 | if (es->x_offset) |
| 3132 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3133 | break; |
| 3134 | case SB_PAGERIGHT: |
| 3135 | if (es->x_offset < es->text_width) |
| 3136 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3137 | break; |
| 3138 | case SB_LEFT: |
| 3139 | if (es->x_offset) |
| 3140 | dx = -es->x_offset; |
| 3141 | break; |
| 3142 | case SB_RIGHT: |
| 3143 | if (es->x_offset < es->text_width) |
| 3144 | dx = es->text_width - es->x_offset; |
| 3145 | break; |
| 3146 | case SB_THUMBTRACK: |
| 3147 | es->flags |= EF_HSCROLL_TRACK; |
| 3148 | dx = pos * es->text_width / 100 - es->x_offset; |
| 3149 | break; |
| 3150 | case SB_THUMBPOSITION: |
| 3151 | es->flags &= ~EF_HSCROLL_TRACK; |
| 3152 | if (!(dx = pos * es->text_width / 100 - es->x_offset)) |
| 3153 | EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); |
| 3154 | break; |
| 3155 | case SB_ENDSCROLL: |
| 3156 | break; |
| 3157 | |
| 3158 | /* |
| 3159 | * FIXME : the next two are undocumented ! |
| 3160 | * Are we doing the right thing ? |
| 3161 | * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, |
| 3162 | * although it's also a regular control message. |
| 3163 | */ |
| 3164 | case EM_GETTHUMB16: |
| 3165 | ret = es->text_width ? es->x_offset * 100 / es->text_width : 0; |
| 3166 | break; |
| 3167 | case EM_LINESCROLL16: |
| 3168 | dx = pos; |
| 3169 | break; |
| 3170 | |
| 3171 | default: |
| 3172 | dprintf_edit(stddeb, "edit: undocumented (hacked) WM_HSCROLL parameter, please report\n"); |
| 3173 | return 0; |
| 3174 | } |
| 3175 | if (dx) |
| 3176 | EDIT_EM_LineScroll(wnd, es, dx, 0); |
| 3177 | return ret; |
| 3178 | } |
| 3179 | |
| 3180 | |
| 3181 | /********************************************************************* |
| 3182 | * |
| 3183 | * WM_HSCROLL |
| 3184 | * |
| 3185 | */ |
| 3186 | static LRESULT EDIT_WM_HScroll(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
| 3187 | { |
| 3188 | INT32 dx; |
| 3189 | INT32 fw; |
| 3190 | |
| 3191 | if (!(es->style & ES_MULTILINE)) |
| 3192 | return 0; |
| 3193 | |
| 3194 | if (!(es->style & ES_AUTOHSCROLL)) |
| 3195 | return 0; |
| 3196 | |
| 3197 | if (!(es->style & WS_HSCROLL)) |
| 3198 | return EDIT_HScroll_Hack(wnd, es, action, pos, scroll_bar); |
| 3199 | |
| 3200 | dx = 0; |
| 3201 | fw = es->format_rect.right - es->format_rect.left; |
| 3202 | switch (action) { |
| 3203 | case SB_LINELEFT: |
| 3204 | if (es->x_offset) |
| 3205 | dx = -es->char_width; |
| 3206 | break; |
| 3207 | case SB_LINERIGHT: |
| 3208 | if (es->x_offset < es->text_width) |
| 3209 | dx = es->char_width; |
| 3210 | break; |
| 3211 | case SB_PAGELEFT: |
| 3212 | if (es->x_offset) |
| 3213 | dx = -fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3214 | break; |
| 3215 | case SB_PAGERIGHT: |
| 3216 | if (es->x_offset < es->text_width) |
| 3217 | dx = fw / HSCROLL_FRACTION / es->char_width * es->char_width; |
| 3218 | break; |
| 3219 | case SB_LEFT: |
| 3220 | if (es->x_offset) |
| 3221 | dx = -es->x_offset; |
| 3222 | break; |
| 3223 | case SB_RIGHT: |
| 3224 | if (es->x_offset < es->text_width) |
| 3225 | dx = es->text_width - es->x_offset; |
| 3226 | break; |
| 3227 | case SB_THUMBTRACK: |
| 3228 | es->flags |= EF_HSCROLL_TRACK; |
| 3229 | dx = pos - es->x_offset; |
| 3230 | break; |
| 3231 | case SB_THUMBPOSITION: |
| 3232 | es->flags &= ~EF_HSCROLL_TRACK; |
| 3233 | if (!(dx = pos - es->x_offset)) { |
| 3234 | SetScrollPos32(wnd->hwndSelf, SB_HORZ, pos, TRUE); |
| 3235 | EDIT_NOTIFY_PARENT(wnd, EN_HSCROLL, "EN_HSCROLL"); |
| 3236 | } |
| 3237 | break; |
| 3238 | case SB_ENDSCROLL: |
| 3239 | break; |
| 3240 | |
| 3241 | default: |
| 3242 | fprintf(stderr, "edit: undocumented WM_HSCROLL parameter, please report\n"); |
| 3243 | return 0; |
| 3244 | } |
| 3245 | if (dx) |
| 3246 | EDIT_EM_LineScroll(wnd, es, dx, 0); |
| 3247 | return 0; |
| 3248 | } |
| 3249 | |
| 3250 | |
| 3251 | /********************************************************************* |
| 3252 | * |
| 3253 | * EDIT_CheckCombo |
| 3254 | * |
| 3255 | */ |
| 3256 | static BOOL32 EDIT_CheckCombo(WND *wnd, UINT32 msg, INT32 key, DWORD key_data) |
| 3257 | { |
| 3258 | HWND32 hLBox; |
| 3259 | |
| 3260 | if (WIDGETS_IsControl32(wnd->parent, BIC32_COMBO) && |
| 3261 | (hLBox = COMBO_GetLBWindow(wnd->parent))) { |
| 3262 | HWND32 hCombo = wnd->parent->hwndSelf; |
| 3263 | BOOL32 bUIFlip = TRUE; |
| 3264 | |
| 3265 | dprintf_combo(stddeb, "EDIT_CheckCombo [%04x]: handling msg %04x (%04x)\n", |
| 3266 | wnd->hwndSelf, (UINT16)msg, (UINT16)key); |
| 3267 | |
| 3268 | switch (msg) { |
| 3269 | case WM_KEYDOWN: /* Handle F4 and arrow keys */ |
| 3270 | if (key != VK_F4) { |
| 3271 | bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0); |
| 3272 | if (SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0)) |
| 3273 | bUIFlip = FALSE; |
| 3274 | } |
| 3275 | if (!bUIFlip) |
| 3276 | SendMessage32A(hLBox, WM_KEYDOWN, (WPARAM32)key, 0); |
| 3277 | else { |
| 3278 | /* make sure ComboLBox pops up */ |
| 3279 | SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 0, 0); |
| 3280 | SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0); |
| 3281 | SendMessage32A(hCombo, CB_SETEXTENDEDUI32, 1, 0); |
| 3282 | } |
| 3283 | break; |
| 3284 | case WM_SYSKEYDOWN: /* Handle Alt+up/down arrows */ |
| 3285 | bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETEXTENDEDUI32, 0, 0); |
| 3286 | if (bUIFlip) { |
| 3287 | bUIFlip = (BOOL32)SendMessage32A(hCombo, CB_GETDROPPEDSTATE32, 0, 0); |
| 3288 | SendMessage32A(hCombo, CB_SHOWDROPDOWN32, (bUIFlip) ? FALSE : TRUE, 0); |
| 3289 | } else |
| 3290 | SendMessage32A(hLBox, WM_KEYDOWN, VK_F4, 0); |
| 3291 | break; |
| 3292 | } |
| 3293 | return TRUE; |
| 3294 | } |
| 3295 | return FALSE; |
| 3296 | } |
| 3297 | |
| 3298 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3299 | /********************************************************************* |
| 3300 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3301 | * WM_KEYDOWN |
| 3302 | * |
| 3303 | * Handling of special keys that don't produce a WM_CHAR |
| 3304 | * (i.e. non-printable keys) & Backspace & Delete |
| 3305 | * |
| 3306 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3307 | 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] | 3308 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3309 | BOOL32 shift; |
| 3310 | BOOL32 control; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3311 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 3312 | if (GetKeyState32(VK_MENU) & 0x8000) |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3313 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3314 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 3315 | shift = GetKeyState32(VK_SHIFT) & 0x8000; |
| 3316 | control = GetKeyState32(VK_CONTROL) & 0x8000; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3317 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3318 | switch (key) { |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3319 | case VK_F4: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3320 | case VK_UP: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3321 | if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data)) |
| 3322 | break; |
| 3323 | if (key == VK_F4) |
| 3324 | break; |
| 3325 | /* fall through */ |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3326 | case VK_LEFT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3327 | if ((es->style & ES_MULTILINE) && (key == VK_UP)) |
| 3328 | EDIT_MoveUp_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3329 | else |
| 3330 | if (control) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3331 | EDIT_MoveWordBackward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3332 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3333 | EDIT_MoveBackward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3334 | break; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3335 | case VK_DOWN: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3336 | if (EDIT_CheckCombo(wnd, WM_KEYDOWN, key, key_data)) |
| 3337 | break; |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3338 | /* fall through */ |
| 3339 | case VK_RIGHT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3340 | if ((es->style & ES_MULTILINE) && (key == VK_DOWN)) |
| 3341 | EDIT_MoveDown_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3342 | else if (control) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3343 | EDIT_MoveWordForward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3344 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3345 | EDIT_MoveForward(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3346 | break; |
| 3347 | case VK_HOME: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3348 | EDIT_MoveHome(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3349 | break; |
| 3350 | case VK_END: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3351 | EDIT_MoveEnd(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3352 | break; |
| 3353 | case VK_PRIOR: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3354 | if (es->style & ES_MULTILINE) |
| 3355 | EDIT_MovePageUp_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3356 | break; |
| 3357 | case VK_NEXT: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3358 | if (es->style & ES_MULTILINE) |
| 3359 | EDIT_MovePageDown_ML(wnd, es, shift); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3360 | break; |
| 3361 | case VK_BACK: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3362 | if (!(es->style & ES_READONLY) && !control) |
| 3363 | if (es->selection_start != es->selection_end) |
| 3364 | EDIT_WM_Clear(wnd, es); |
| 3365 | else { |
| 3366 | /* delete character left of caret */ |
| 3367 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3368 | EDIT_MoveBackward(wnd, es, TRUE); |
| 3369 | EDIT_WM_Clear(wnd, es); |
| 3370 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3371 | break; |
| 3372 | case VK_DELETE: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3373 | if (!(es->style & ES_READONLY) && !(shift && control)) |
| 3374 | if (es->selection_start != es->selection_end) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3375 | if (shift) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3376 | EDIT_WM_Cut(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3377 | else |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3378 | EDIT_WM_Clear(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3379 | } else { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3380 | if (shift) { |
| 3381 | /* delete character left of caret */ |
| 3382 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3383 | EDIT_MoveBackward(wnd, es, TRUE); |
| 3384 | EDIT_WM_Clear(wnd, es); |
| 3385 | } else if (control) { |
| 3386 | /* delete to end of line */ |
| 3387 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3388 | EDIT_MoveEnd(wnd, es, TRUE); |
| 3389 | EDIT_WM_Clear(wnd, es); |
| 3390 | } else { |
| 3391 | /* delete character right of caret */ |
| 3392 | EDIT_EM_SetSel(wnd, es, -1, 0, FALSE); |
| 3393 | EDIT_MoveForward(wnd, es, TRUE); |
| 3394 | EDIT_WM_Clear(wnd, es); |
| 3395 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3396 | } |
| 3397 | break; |
| 3398 | case VK_INSERT: |
| 3399 | if (shift) { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3400 | if (!(es->style & ES_READONLY)) |
| 3401 | EDIT_WM_Paste(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3402 | } else if (control) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3403 | EDIT_WM_Copy(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3404 | break; |
| 3405 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3406 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | |
| 3410 | /********************************************************************* |
| 3411 | * |
| 3412 | * WM_KILLFOCUS |
| 3413 | * |
| 3414 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3415 | 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] | 3416 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3417 | es->flags &= ~EF_FOCUSED; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 3418 | DestroyCaret32(); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3419 | if(!(es->style & ES_NOHIDESEL)) |
| 3420 | EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end); |
| 3421 | EDIT_NOTIFY_PARENT(wnd, EN_KILLFOCUS, "EN_KILLFOCUS"); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3422 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3423 | } |
| 3424 | |
| 3425 | |
| 3426 | /********************************************************************* |
| 3427 | * |
| 3428 | * WM_LBUTTONDBLCLK |
| 3429 | * |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 3430 | * The caret position has been set on the WM_LBUTTONDOWN message |
| 3431 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3432 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3433 | 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] | 3434 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3435 | INT32 s; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3436 | INT32 e = es->selection_end; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3437 | INT32 l; |
| 3438 | INT32 li; |
| 3439 | INT32 ll; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3440 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3441 | if (!(es->flags & EF_FOCUSED)) |
| 3442 | return 0; |
| 3443 | |
| 3444 | l = EDIT_EM_LineFromChar(wnd, es, e); |
| 3445 | li = EDIT_EM_LineIndex(wnd, es, l); |
| 3446 | ll = EDIT_EM_LineLength(wnd, es, e); |
| 3447 | s = li + EDIT_CallWordBreakProc (wnd, es, li, e - li, ll, WB_LEFT); |
| 3448 | e = li + EDIT_CallWordBreakProc(wnd, es, li, e - li, ll, WB_RIGHT); |
| 3449 | EDIT_EM_SetSel(wnd, es, s, e, FALSE); |
| 3450 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3451 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
| 3454 | |
| 3455 | /********************************************************************* |
| 3456 | * |
| 3457 | * WM_LBUTTONDOWN |
| 3458 | * |
| 3459 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3460 | 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] | 3461 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3462 | INT32 e; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3463 | BOOL32 after_wrap; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3464 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3465 | if (!(es->flags & EF_FOCUSED)) |
| 3466 | return 0; |
| 3467 | |
| 3468 | SetCapture32(wnd->hwndSelf); |
| 3469 | EDIT_ConfinePoint(wnd, es, &x, &y); |
| 3470 | e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap); |
| 3471 | EDIT_EM_SetSel(wnd, es, (keys & MK_SHIFT) ? es->selection_start : e, e, after_wrap); |
| 3472 | EDIT_EM_ScrollCaret(wnd, es); |
| 3473 | SetTimer32(wnd->hwndSelf, 0, 100, NULL); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3474 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
| 3477 | |
| 3478 | /********************************************************************* |
| 3479 | * |
| 3480 | * WM_LBUTTONUP |
| 3481 | * |
| 3482 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3483 | 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] | 3484 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3485 | if (GetCapture32() == wnd->hwndSelf) { |
| 3486 | KillTimer32(wnd->hwndSelf, 0); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3487 | ReleaseCapture(); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3488 | } |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3489 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3490 | } |
| 3491 | |
| 3492 | |
| 3493 | /********************************************************************* |
| 3494 | * |
| 3495 | * WM_MOUSEMOVE |
| 3496 | * |
| 3497 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3498 | 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] | 3499 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3500 | INT32 e; |
| 3501 | BOOL32 after_wrap; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3502 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3503 | if (GetCapture32() != wnd->hwndSelf) |
| 3504 | return 0; |
| 3505 | |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3506 | /* |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3507 | * FIXME: gotta do some scrolling if outside client |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3508 | * area. Maybe reset the timer ? |
| 3509 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3510 | EDIT_ConfinePoint(wnd, es, &x, &y); |
| 3511 | e = EDIT_CharFromPos(wnd, es, x, y, &after_wrap); |
| 3512 | EDIT_EM_SetSel(wnd, es, es->selection_start, e, after_wrap); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3513 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | |
| 3517 | /********************************************************************* |
| 3518 | * |
| 3519 | * WM_PAINT |
| 3520 | * |
| 3521 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3522 | static void EDIT_WM_Paint(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3523 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3524 | PAINTSTRUCT32 ps; |
| 3525 | INT32 i; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3526 | HDC32 dc; |
| 3527 | HFONT32 old_font = 0; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3528 | RECT32 rc; |
| 3529 | RECT32 rcLine; |
| 3530 | RECT32 rcRgn; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3531 | LRESULT pos; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3532 | BOOL32 rev = IsWindowEnabled32(wnd->hwndSelf) && |
| 3533 | ((es->flags & EF_FOCUSED) || |
| 3534 | (es->style & ES_NOHIDESEL)); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3535 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3536 | if (es->flags & EF_UPDATE) |
| 3537 | EDIT_NOTIFY_PARENT(wnd, EN_UPDATE, "EN_UPDATE"); |
| 3538 | |
| 3539 | dc = BeginPaint32(wnd->hwndSelf, &ps); |
| 3540 | IntersectClipRect32(dc, es->format_rect.left, |
| 3541 | es->format_rect.top, |
| 3542 | es->format_rect.right, |
| 3543 | es->format_rect.bottom); |
| 3544 | if (es->style & ES_MULTILINE) { |
| 3545 | GetClientRect32(wnd->hwndSelf, &rc); |
| 3546 | IntersectClipRect32(dc, rc.left, rc.top, rc.right, rc.bottom); |
| 3547 | } |
| 3548 | if (es->font) |
| 3549 | old_font = SelectObject32(dc, es->font); |
| 3550 | EDIT_SEND_CTLCOLOR(wnd, dc); |
| 3551 | if (!IsWindowEnabled32(wnd->hwndSelf)) |
| 3552 | SetTextColor32(dc, GetSysColor32(COLOR_GRAYTEXT)); |
| 3553 | GetClipBox32(dc, &rcRgn); |
| 3554 | if (es->style & ES_MULTILINE) { |
| 3555 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 3556 | for (i = es->y_offset ; i <= MIN(es->y_offset + vlc, es->y_offset + es->line_count - 1) ; i++) { |
| 3557 | EDIT_GetLineRect(wnd, es, i, 0, -1, &rcLine); |
| 3558 | if (IntersectRect32(&rc, &rcRgn, &rcLine)) |
| 3559 | EDIT_PaintLine(wnd, es, dc, i, rev); |
| 3560 | } |
| 3561 | } else { |
| 3562 | EDIT_GetLineRect(wnd, es, 0, 0, -1, &rcLine); |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3563 | if (IntersectRect32(&rc, &rcRgn, &rcLine)) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3564 | EDIT_PaintLine(wnd, es, dc, 0, rev); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3565 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3566 | if (es->font) |
| 3567 | SelectObject32(dc, old_font); |
| 3568 | if (es->flags & EF_FOCUSED) { |
| 3569 | pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); |
| 3570 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3571 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3572 | EndPaint32(wnd->hwndSelf, &ps); |
| 3573 | if ((es->style & WS_VSCROLL) && !(es->flags & EF_VSCROLL_TRACK)) { |
| 3574 | INT32 vlc = (es->format_rect.bottom - es->format_rect.top) / es->line_height; |
| 3575 | SCROLLINFO si; |
| 3576 | si.cbSize = sizeof(SCROLLINFO); |
| 3577 | si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; |
| 3578 | si.nMin = 0; |
| 3579 | si.nMax = es->line_count + vlc - 2; |
| 3580 | si.nPage = vlc; |
| 3581 | si.nPos = es->y_offset; |
| 3582 | SetScrollInfo32(wnd->hwndSelf, SB_VERT, &si, TRUE); |
| 3583 | } |
| 3584 | if ((es->style & WS_HSCROLL) && !(es->flags & EF_HSCROLL_TRACK)) { |
| 3585 | SCROLLINFO si; |
| 3586 | INT32 fw = es->format_rect.right - es->format_rect.left; |
| 3587 | si.cbSize = sizeof(SCROLLINFO); |
| 3588 | si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL; |
| 3589 | si.nMin = 0; |
| 3590 | si.nMax = es->text_width + fw - 1; |
| 3591 | si.nPage = fw; |
| 3592 | si.nPos = es->x_offset; |
| 3593 | SetScrollInfo32(wnd->hwndSelf, SB_HORZ, &si, TRUE); |
| 3594 | } |
| 3595 | |
| 3596 | if (es->flags & EF_UPDATE) { |
| 3597 | es->flags &= ~EF_UPDATE; |
| 3598 | EDIT_NOTIFY_PARENT(wnd, EN_CHANGE, "EN_CHANGE"); |
| 3599 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | |
| 3603 | /********************************************************************* |
| 3604 | * |
| 3605 | * WM_PASTE |
| 3606 | * |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3607 | * FIXME: replace with 32 bit handler once GetClipboardData32() is |
| 3608 | * implemented in misc/clipboard.c |
| 3609 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3610 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3611 | static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3612 | { |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 3613 | HGLOBAL16 hsrc; |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3614 | LPSTR src; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3615 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3616 | OpenClipboard32(wnd->hwndSelf); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3617 | if ((hsrc = GetClipboardData16(CF_TEXT))) { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3618 | src = (LPSTR)GlobalLock16(hsrc); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3619 | EDIT_EM_ReplaceSel(wnd, es, TRUE, src); |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 3620 | GlobalUnlock16(hsrc); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3621 | } |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 3622 | CloseClipboard32(); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | |
| 3626 | /********************************************************************* |
| 3627 | * |
| 3628 | * WM_SETFOCUS |
| 3629 | * |
| 3630 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3631 | 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] | 3632 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3633 | LRESULT pos; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3634 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3635 | es->flags |= EF_FOCUSED; |
| 3636 | CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height); |
| 3637 | pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); |
| 3638 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
| 3639 | if(!(es->style & ES_NOHIDESEL)) |
| 3640 | EDIT_InvalidateText(wnd, es, es->selection_start, es->selection_end); |
| 3641 | ShowCaret32(wnd->hwndSelf); |
| 3642 | EDIT_NOTIFY_PARENT(wnd, EN_SETFOCUS, "EN_SETFOCUS"); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | |
| 3646 | /********************************************************************* |
| 3647 | * |
| 3648 | * WM_SETFONT |
| 3649 | * |
| 3650 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3651 | 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] | 3652 | { |
Alexandre Julliard | c6c0944 | 1997-01-12 18:32:19 +0000 | [diff] [blame] | 3653 | TEXTMETRIC32A tm; |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3654 | HDC32 dc; |
| 3655 | HFONT32 old_font = 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3656 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3657 | es->font = font; |
| 3658 | dc = GetDC32(wnd->hwndSelf); |
| 3659 | if (font) |
| 3660 | old_font = SelectObject32(dc, font); |
| 3661 | GetTextMetrics32A(dc, &tm); |
| 3662 | es->line_height = tm.tmHeight; |
| 3663 | es->char_width = tm.tmAveCharWidth; |
| 3664 | if (font) |
| 3665 | SelectObject32(dc, old_font); |
| 3666 | ReleaseDC32(wnd->hwndSelf, dc); |
| 3667 | if (wnd->flags & WIN_ISWIN32) |
| 3668 | EDIT_EM_SetMargins(wnd, es, EC_USEFONTINFO, 0, 0); |
| 3669 | if (es->style & ES_MULTILINE) |
| 3670 | EDIT_BuildLineDefs_ML(wnd, es); |
| 3671 | if (redraw && !(wnd->flags & WIN_NO_REDRAW)) |
| 3672 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
| 3673 | if (es->flags & EF_FOCUSED) { |
| 3674 | LRESULT pos; |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 3675 | DestroyCaret32(); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3676 | CreateCaret32(wnd->hwndSelf, 0, 2, es->line_height); |
| 3677 | pos = EDIT_EM_PosFromChar(wnd, es, es->selection_end, es->flags & EF_AFTER_WRAP); |
| 3678 | SetCaretPos32(SLOWORD(pos), SHIWORD(pos)); |
| 3679 | ShowCaret32(wnd->hwndSelf); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3680 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | |
| 3684 | /********************************************************************* |
| 3685 | * |
| 3686 | * WM_SETTEXT |
| 3687 | * |
| 3688 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3689 | static void EDIT_WM_SetText(WND *wnd, EDITSTATE *es, LPCSTR text) |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3690 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3691 | EDIT_EM_SetSel(wnd, es, 0, -1, FALSE); |
| 3692 | if (text) { |
| 3693 | dprintf_edit(stddeb, "\t'%s'\n", text); |
| 3694 | EDIT_EM_ReplaceSel(wnd, es, FALSE, text); |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 3695 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3696 | es->flags |= EF_MODIFIED; |
| 3697 | es->flags |= EF_UPDATE; |
| 3698 | EDIT_EM_ScrollCaret(wnd, es); |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3699 | } |
| 3700 | |
| 3701 | |
| 3702 | /********************************************************************* |
| 3703 | * |
| 3704 | * WM_SIZE |
| 3705 | * |
| 3706 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3707 | 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] | 3708 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3709 | if ((action == SIZE_MAXIMIZED) || (action == SIZE_RESTORED)) { |
| 3710 | RECT32 rc; |
| 3711 | SetRect32(&rc, 0, 0, width, height); |
| 3712 | EDIT_SetRectNP(wnd, es, &rc); |
| 3713 | InvalidateRect32(wnd->hwndSelf, NULL, TRUE); |
Alexandre Julliard | cdcdede | 1996-04-21 14:57:41 +0000 | [diff] [blame] | 3714 | } |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | |
| 3718 | /********************************************************************* |
| 3719 | * |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3720 | * WM_SYSKEYDOWN |
| 3721 | * |
| 3722 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3723 | 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] | 3724 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3725 | if ((key == VK_BACK) && (key_data & 0x2000)) { |
| 3726 | if (EDIT_EM_CanUndo(wnd, es)) |
| 3727 | EDIT_EM_Undo(wnd, es); |
| 3728 | return 0; |
| 3729 | } else if (key == VK_UP || key == VK_DOWN) |
| 3730 | if (EDIT_CheckCombo(wnd, WM_SYSKEYDOWN, key, key_data)) |
| 3731 | return 0; |
| 3732 | return DefWindowProc32A(wnd->hwndSelf, WM_SYSKEYDOWN, (WPARAM32)key, (LPARAM)key_data); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3733 | } |
| 3734 | |
| 3735 | |
| 3736 | /********************************************************************* |
| 3737 | * |
| 3738 | * WM_TIMER |
| 3739 | * |
| 3740 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3741 | 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] | 3742 | { |
| 3743 | /* |
| 3744 | * FIXME: gotta do some scrolling here, like |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3745 | * EDIT_EM_LineScroll(wnd, 0, 1); |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3746 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | |
| 3750 | /********************************************************************* |
| 3751 | * |
| 3752 | * EDIT_VScroll_Hack |
| 3753 | * |
| 3754 | * 16 bit notepad needs this. Actually it is not _our_ hack, |
| 3755 | * it is notepad's. Notepad is sending us scrollbar messages with |
| 3756 | * undocumented parameters without us even having a scrollbar ... !?!? |
| 3757 | * |
| 3758 | */ |
| 3759 | static LRESULT EDIT_VScroll_Hack(WND *wnd, EDITSTATE *es, INT32 action, INT32 pos, HWND32 scroll_bar) |
| 3760 | { |
| 3761 | INT32 dy = 0; |
| 3762 | LRESULT ret = 0; |
| 3763 | |
| 3764 | if (!(es->flags & EF_VSCROLL_HACK)) { |
| 3765 | fprintf(stderr, "edit: hacked WM_VSCROLL handler invoked\n"); |
| 3766 | fprintf(stderr, " if you are _not_ running 16 bit notepad, please report\n"); |
| 3767 | fprintf(stderr, " (this message is only displayed once per edit control)\n"); |
| 3768 | es->flags |= EF_VSCROLL_HACK; |
| 3769 | } |
| 3770 | |
| 3771 | switch (action) { |
| 3772 | case SB_LINEUP: |
| 3773 | case SB_LINEDOWN: |
| 3774 | case SB_PAGEUP: |
| 3775 | case SB_PAGEDOWN: |
| 3776 | EDIT_EM_Scroll(wnd, es, action); |
| 3777 | return 0; |
| 3778 | case SB_TOP: |
| 3779 | dy = -es->y_offset; |
| 3780 | break; |
| 3781 | case SB_BOTTOM: |
| 3782 | dy = es->line_count - 1 - es->y_offset; |
| 3783 | break; |
| 3784 | case SB_THUMBTRACK: |
| 3785 | es->flags |= EF_VSCROLL_TRACK; |
| 3786 | dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset; |
| 3787 | break; |
| 3788 | case SB_THUMBPOSITION: |
| 3789 | es->flags &= ~EF_VSCROLL_TRACK; |
| 3790 | if (!(dy = (pos * (es->line_count - 1) + 50) / 100 - es->y_offset)) |
| 3791 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
| 3792 | break; |
| 3793 | case SB_ENDSCROLL: |
| 3794 | break; |
| 3795 | |
| 3796 | /* |
| 3797 | * FIXME : the next two are undocumented ! |
| 3798 | * Are we doing the right thing ? |
| 3799 | * At least Win 3.1 Notepad makes use of EM_GETTHUMB this way, |
| 3800 | * although it's also a regular control message. |
| 3801 | */ |
| 3802 | case EM_GETTHUMB16: |
| 3803 | ret = (es->line_count > 1) ? es->y_offset * 100 / (es->line_count - 1) : 0; |
| 3804 | break; |
| 3805 | case EM_LINESCROLL16: |
| 3806 | dy = pos; |
| 3807 | break; |
| 3808 | |
| 3809 | default: |
| 3810 | fprintf(stderr, "edit: undocumented (hacked) WM_VSCROLL parameter, please report\n"); |
| 3811 | return 0; |
| 3812 | } |
| 3813 | if (dy) |
| 3814 | EDIT_EM_LineScroll(wnd, es, 0, dy); |
| 3815 | return ret; |
Alexandre Julliard | 01d6346 | 1997-01-20 19:43:45 +0000 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | |
| 3819 | /********************************************************************* |
| 3820 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3821 | * WM_VSCROLL |
| 3822 | * |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3823 | */ |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3824 | 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] | 3825 | { |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3826 | INT32 dy; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3827 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3828 | if (!(es->style & ES_MULTILINE)) |
| 3829 | return 0; |
| 3830 | |
| 3831 | if (!(es->style & ES_AUTOVSCROLL)) |
| 3832 | return 0; |
| 3833 | |
| 3834 | if (!(es->style & WS_VSCROLL)) |
| 3835 | return EDIT_VScroll_Hack(wnd, es, action, pos, scroll_bar); |
| 3836 | |
| 3837 | dy = 0; |
| 3838 | switch (action) { |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3839 | case SB_LINEUP: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3840 | case SB_LINEDOWN: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3841 | case SB_PAGEUP: |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3842 | case SB_PAGEDOWN: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3843 | EDIT_EM_Scroll(wnd, es, action); |
| 3844 | return 0; |
| 3845 | |
| 3846 | case SB_TOP: |
| 3847 | dy = -es->y_offset; |
| 3848 | break; |
| 3849 | case SB_BOTTOM: |
| 3850 | dy = es->line_count - 1 - es->y_offset; |
| 3851 | break; |
| 3852 | case SB_THUMBTRACK: |
| 3853 | es->flags |= EF_VSCROLL_TRACK; |
| 3854 | dy = pos - es->y_offset; |
| 3855 | break; |
| 3856 | case SB_THUMBPOSITION: |
| 3857 | es->flags &= ~EF_VSCROLL_TRACK; |
| 3858 | if (!(dy = pos - es->y_offset)) { |
| 3859 | SetScrollPos32(wnd->hwndSelf, SB_VERT, pos, TRUE); |
| 3860 | EDIT_NOTIFY_PARENT(wnd, EN_VSCROLL, "EN_VSCROLL"); |
| 3861 | } |
| 3862 | break; |
| 3863 | case SB_ENDSCROLL: |
| 3864 | break; |
| 3865 | |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3866 | default: |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3867 | fprintf(stderr, "edit: undocumented WM_VSCROLL parameter, please report\n"); |
| 3868 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3869 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 3870 | if (dy) |
| 3871 | EDIT_EM_LineScroll(wnd, es, 0, dy); |
| 3872 | return 0; |
Alexandre Julliard | 329f068 | 1996-04-14 13:21:20 +0000 | [diff] [blame] | 3873 | } |