Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | * |
| 3 | * VIM - Vi IMproved by Bram Moolenaar |
| 4 | * GUI support by Robert Webb |
| 5 | * |
| 6 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 7 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 8 | * See README.txt for an overview of the Vim source code. |
| 9 | */ |
| 10 | /* |
| 11 | * Windows GUI. |
| 12 | * |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 13 | * GUI support for Microsoft Windows, aka Win32. Also for Win64. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 14 | * |
| 15 | * George V. Reilly <george@reilly.org> wrote the original Win32 GUI. |
| 16 | * Robert Webb reworked it to use the existing GUI stuff and added menu, |
| 17 | * scrollbars, etc. |
| 18 | * |
| 19 | * Note: Clipboard stuff, for cutting and pasting text to other windows, is in |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 20 | * winclip.c. (It can also be done from the terminal version). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 21 | * |
| 22 | * TODO: Some of the function signatures ought to be updated for Win64; |
| 23 | * e.g., replace LONG with LONG_PTR, etc. |
| 24 | */ |
| 25 | |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 26 | #include "vim.h" |
| 27 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 28 | #if defined(FEAT_DIRECTX) |
| 29 | # include "gui_dwrite.h" |
| 30 | #endif |
| 31 | |
Bram Moolenaar | b8e0bdb | 2014-11-12 16:10:48 +0100 | [diff] [blame] | 32 | #if defined(FEAT_DIRECTX) |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 33 | # ifndef FEAT_MBYTE |
| 34 | # error FEAT_MBYTE is required for FEAT_DIRECTX. |
| 35 | # endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 36 | static DWriteContext *s_dwc = NULL; |
| 37 | static int s_directx_enabled = 0; |
| 38 | static int s_directx_load_attempted = 0; |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 39 | # define IS_ENABLE_DIRECTX() (s_directx_enabled && s_dwc != NULL && enc_utf8) |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 40 | static int directx_enabled(void); |
| 41 | static void directx_binddc(void); |
Bram Moolenaar | b8e0bdb | 2014-11-12 16:10:48 +0100 | [diff] [blame] | 42 | #endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 43 | |
Bram Moolenaar | 065bbac | 2016-02-20 13:08:46 +0100 | [diff] [blame] | 44 | #ifdef FEAT_MENU |
| 45 | static int gui_mswin_get_menu_height(int fix_window); |
| 46 | #endif |
| 47 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 48 | #if defined(FEAT_RENDER_OPTIONS) || defined(PROTO) |
| 49 | int |
| 50 | gui_mch_set_rendering_options(char_u *s) |
| 51 | { |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 52 | # ifdef FEAT_DIRECTX |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 53 | char_u *p, *q; |
| 54 | |
| 55 | int dx_enable = 0; |
| 56 | int dx_flags = 0; |
| 57 | float dx_gamma = 0.0f; |
| 58 | float dx_contrast = 0.0f; |
| 59 | float dx_level = 0.0f; |
| 60 | int dx_geom = 0; |
| 61 | int dx_renmode = 0; |
| 62 | int dx_taamode = 0; |
| 63 | |
| 64 | /* parse string as rendering options. */ |
| 65 | for (p = s; p != NULL && *p != NUL; ) |
| 66 | { |
| 67 | char_u item[256]; |
| 68 | char_u name[128]; |
| 69 | char_u value[128]; |
| 70 | |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 71 | copy_option_part(&p, item, sizeof(item), ","); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 72 | if (p == NULL) |
| 73 | break; |
| 74 | q = &item[0]; |
| 75 | copy_option_part(&q, name, sizeof(name), ":"); |
| 76 | if (q == NULL) |
| 77 | return FAIL; |
| 78 | copy_option_part(&q, value, sizeof(value), ":"); |
| 79 | |
| 80 | if (STRCMP(name, "type") == 0) |
| 81 | { |
| 82 | if (STRCMP(value, "directx") == 0) |
| 83 | dx_enable = 1; |
| 84 | else |
| 85 | return FAIL; |
| 86 | } |
| 87 | else if (STRCMP(name, "gamma") == 0) |
| 88 | { |
| 89 | dx_flags |= 1 << 0; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 90 | dx_gamma = (float)atof((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 91 | } |
| 92 | else if (STRCMP(name, "contrast") == 0) |
| 93 | { |
| 94 | dx_flags |= 1 << 1; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 95 | dx_contrast = (float)atof((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 96 | } |
| 97 | else if (STRCMP(name, "level") == 0) |
| 98 | { |
| 99 | dx_flags |= 1 << 2; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 100 | dx_level = (float)atof((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 101 | } |
| 102 | else if (STRCMP(name, "geom") == 0) |
| 103 | { |
| 104 | dx_flags |= 1 << 3; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 105 | dx_geom = atoi((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 106 | if (dx_geom < 0 || dx_geom > 2) |
| 107 | return FAIL; |
| 108 | } |
| 109 | else if (STRCMP(name, "renmode") == 0) |
| 110 | { |
| 111 | dx_flags |= 1 << 4; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 112 | dx_renmode = atoi((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 113 | if (dx_renmode < 0 || dx_renmode > 6) |
| 114 | return FAIL; |
| 115 | } |
| 116 | else if (STRCMP(name, "taamode") == 0) |
| 117 | { |
| 118 | dx_flags |= 1 << 5; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 119 | dx_taamode = atoi((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 120 | if (dx_taamode < 0 || dx_taamode > 3) |
| 121 | return FAIL; |
| 122 | } |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 123 | else if (STRCMP(name, "scrlines") == 0) |
| 124 | { |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 125 | /* Deprecated. Simply ignore it. */ |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 126 | } |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 127 | else |
| 128 | return FAIL; |
| 129 | } |
| 130 | |
Bram Moolenaar | 3767c6e | 2017-12-05 16:57:56 +0100 | [diff] [blame] | 131 | if (!gui.in_use) |
| 132 | return OK; /* only checking the syntax of the value */ |
| 133 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 134 | /* Enable DirectX/DirectWrite */ |
| 135 | if (dx_enable) |
| 136 | { |
| 137 | if (!directx_enabled()) |
| 138 | return FAIL; |
| 139 | DWriteContext_SetRenderingParams(s_dwc, NULL); |
| 140 | if (dx_flags) |
| 141 | { |
| 142 | DWriteRenderingParams param; |
| 143 | DWriteContext_GetRenderingParams(s_dwc, ¶m); |
| 144 | if (dx_flags & (1 << 0)) |
| 145 | param.gamma = dx_gamma; |
| 146 | if (dx_flags & (1 << 1)) |
| 147 | param.enhancedContrast = dx_contrast; |
| 148 | if (dx_flags & (1 << 2)) |
| 149 | param.clearTypeLevel = dx_level; |
| 150 | if (dx_flags & (1 << 3)) |
| 151 | param.pixelGeometry = dx_geom; |
| 152 | if (dx_flags & (1 << 4)) |
| 153 | param.renderingMode = dx_renmode; |
| 154 | if (dx_flags & (1 << 5)) |
| 155 | param.textAntialiasMode = dx_taamode; |
| 156 | DWriteContext_SetRenderingParams(s_dwc, ¶m); |
| 157 | } |
| 158 | } |
| 159 | s_directx_enabled = dx_enable; |
| 160 | |
| 161 | return OK; |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 162 | # else |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 163 | return FAIL; |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 164 | # endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 165 | } |
| 166 | #endif |
| 167 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 168 | /* |
| 169 | * These are new in Windows ME/XP, only defined in recent compilers. |
| 170 | */ |
| 171 | #ifndef HANDLE_WM_XBUTTONUP |
| 172 | # define HANDLE_WM_XBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 173 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 174 | #endif |
| 175 | #ifndef HANDLE_WM_XBUTTONDOWN |
| 176 | # define HANDLE_WM_XBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 177 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 178 | #endif |
| 179 | #ifndef HANDLE_WM_XBUTTONDBLCLK |
| 180 | # define HANDLE_WM_XBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 181 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 182 | #endif |
| 183 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 184 | |
| 185 | #include "version.h" /* used by dialog box routine for default title */ |
| 186 | #ifdef DEBUG |
| 187 | # include <tchar.h> |
| 188 | #endif |
| 189 | |
| 190 | /* cproto fails on missing include files */ |
| 191 | #ifndef PROTO |
| 192 | |
| 193 | #ifndef __MINGW32__ |
| 194 | # include <shellapi.h> |
| 195 | #endif |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 196 | #if defined(FEAT_TOOLBAR) || defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_TABLINE) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 197 | # include <commctrl.h> |
| 198 | #endif |
| 199 | #include <windowsx.h> |
| 200 | |
| 201 | #ifdef GLOBAL_IME |
| 202 | # include "glbl_ime.h" |
| 203 | #endif |
| 204 | |
| 205 | #endif /* PROTO */ |
| 206 | |
| 207 | #ifdef FEAT_MENU |
| 208 | # define MENUHINTS /* show menu hints in command line */ |
| 209 | #endif |
| 210 | |
| 211 | /* Some parameters for dialog boxes. All in pixels. */ |
| 212 | #define DLG_PADDING_X 10 |
| 213 | #define DLG_PADDING_Y 10 |
| 214 | #define DLG_OLD_STYLE_PADDING_X 5 |
| 215 | #define DLG_OLD_STYLE_PADDING_Y 5 |
| 216 | #define DLG_VERT_PADDING_X 4 /* For vertical buttons */ |
| 217 | #define DLG_VERT_PADDING_Y 4 |
| 218 | #define DLG_ICON_WIDTH 34 |
| 219 | #define DLG_ICON_HEIGHT 34 |
| 220 | #define DLG_MIN_WIDTH 150 |
| 221 | #define DLG_FONT_NAME "MS Sans Serif" |
| 222 | #define DLG_FONT_POINT_SIZE 8 |
| 223 | #define DLG_MIN_MAX_WIDTH 400 |
| 224 | #define DLG_MIN_MAX_HEIGHT 400 |
| 225 | |
| 226 | #define DLG_NONBUTTON_CONTROL 5000 /* First ID of non-button controls */ |
| 227 | |
| 228 | #ifndef WM_XBUTTONDOWN /* For Win2K / winME ONLY */ |
| 229 | # define WM_XBUTTONDOWN 0x020B |
| 230 | # define WM_XBUTTONUP 0x020C |
| 231 | # define WM_XBUTTONDBLCLK 0x020D |
| 232 | # define MK_XBUTTON1 0x0020 |
| 233 | # define MK_XBUTTON2 0x0040 |
| 234 | #endif |
| 235 | |
| 236 | #ifdef PROTO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 237 | /* |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 238 | * Define a few things for generating prototypes. This is just to avoid |
| 239 | * syntax errors, the defines do not need to be correct. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 240 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 241 | # define APIENTRY |
| 242 | # define CALLBACK |
| 243 | # define CONST |
| 244 | # define FAR |
| 245 | # define NEAR |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 246 | # undef _cdecl |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 247 | # define _cdecl |
| 248 | typedef int BOOL; |
| 249 | typedef int BYTE; |
| 250 | typedef int DWORD; |
| 251 | typedef int WCHAR; |
| 252 | typedef int ENUMLOGFONT; |
| 253 | typedef int FINDREPLACE; |
| 254 | typedef int HANDLE; |
| 255 | typedef int HBITMAP; |
| 256 | typedef int HBRUSH; |
| 257 | typedef int HDROP; |
| 258 | typedef int INT; |
| 259 | typedef int LOGFONT[]; |
| 260 | typedef int LPARAM; |
| 261 | typedef int LPCREATESTRUCT; |
| 262 | typedef int LPCSTR; |
| 263 | typedef int LPCTSTR; |
| 264 | typedef int LPRECT; |
| 265 | typedef int LPSTR; |
| 266 | typedef int LPWINDOWPOS; |
| 267 | typedef int LPWORD; |
| 268 | typedef int LRESULT; |
| 269 | typedef int HRESULT; |
| 270 | # undef MSG |
| 271 | typedef int MSG; |
| 272 | typedef int NEWTEXTMETRIC; |
| 273 | typedef int OSVERSIONINFO; |
| 274 | typedef int PWORD; |
| 275 | typedef int RECT; |
| 276 | typedef int UINT; |
| 277 | typedef int WORD; |
| 278 | typedef int WPARAM; |
| 279 | typedef int POINT; |
| 280 | typedef void *HINSTANCE; |
| 281 | typedef void *HMENU; |
| 282 | typedef void *HWND; |
| 283 | typedef void *HDC; |
| 284 | typedef void VOID; |
| 285 | typedef int LPNMHDR; |
| 286 | typedef int LONG; |
| 287 | typedef int WNDPROC; |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 288 | typedef int UINT_PTR; |
Bram Moolenaar | b1c9198 | 2018-05-17 17:04:55 +0200 | [diff] [blame] | 289 | typedef int COLORREF; |
| 290 | typedef int HCURSOR; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 291 | #endif |
| 292 | |
| 293 | #ifndef GET_X_LPARAM |
| 294 | # define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) |
| 295 | #endif |
| 296 | |
| 297 | static void _OnPaint( HWND hwnd); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 298 | static void fill_rect(const RECT *rcp, HBRUSH hbr, COLORREF color); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 299 | static void clear_rect(RECT *rcp); |
| 300 | |
| 301 | static WORD s_dlgfntheight; /* height of the dialog font */ |
| 302 | static WORD s_dlgfntwidth; /* width of the dialog font */ |
| 303 | |
| 304 | #ifdef FEAT_MENU |
| 305 | static HMENU s_menuBar = NULL; |
| 306 | #endif |
| 307 | #ifdef FEAT_TEAROFF |
| 308 | static void rebuild_tearoff(vimmenu_T *menu); |
| 309 | static HBITMAP s_htearbitmap; /* bitmap used to indicate tearoff */ |
| 310 | #endif |
| 311 | |
| 312 | /* Flag that is set while processing a message that must not be interrupted by |
| 313 | * processing another message. */ |
| 314 | static int s_busy_processing = FALSE; |
| 315 | |
| 316 | static int destroying = FALSE; /* call DestroyWindow() ourselves */ |
| 317 | |
| 318 | #ifdef MSWIN_FIND_REPLACE |
| 319 | static UINT s_findrep_msg = 0; /* set in gui_w[16/32].c */ |
| 320 | static FINDREPLACE s_findrep_struct; |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 321 | # ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 322 | static FINDREPLACEW s_findrep_struct_w; |
| 323 | # endif |
| 324 | static HWND s_findrep_hwnd = NULL; |
| 325 | static int s_findrep_is_find; /* TRUE for find dialog, FALSE |
| 326 | for find/replace dialog */ |
| 327 | #endif |
| 328 | |
| 329 | static HINSTANCE s_hinst = NULL; |
Bram Moolenaar | 85b1176 | 2016-02-27 18:13:23 +0100 | [diff] [blame] | 330 | #if !defined(FEAT_GUI) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 331 | static |
| 332 | #endif |
| 333 | HWND s_hwnd = NULL; |
| 334 | static HDC s_hdc = NULL; |
| 335 | static HBRUSH s_brush = NULL; |
| 336 | |
| 337 | #ifdef FEAT_TOOLBAR |
| 338 | static HWND s_toolbarhwnd = NULL; |
| 339 | static WNDPROC s_toolbar_wndproc = NULL; |
| 340 | #endif |
| 341 | |
| 342 | #ifdef FEAT_GUI_TABLINE |
| 343 | static HWND s_tabhwnd = NULL; |
| 344 | static WNDPROC s_tabline_wndproc = NULL; |
| 345 | static int showing_tabline = 0; |
| 346 | #endif |
| 347 | |
| 348 | static WPARAM s_wParam = 0; |
| 349 | static LPARAM s_lParam = 0; |
| 350 | |
| 351 | static HWND s_textArea = NULL; |
| 352 | static UINT s_uMsg = 0; |
| 353 | |
| 354 | static char_u *s_textfield; /* Used by dialogs to pass back strings */ |
| 355 | |
| 356 | static int s_need_activate = FALSE; |
| 357 | |
| 358 | /* This variable is set when waiting for an event, which is the only moment |
| 359 | * scrollbar dragging can be done directly. It's not allowed while commands |
| 360 | * are executed, because it may move the cursor and that may cause unexpected |
| 361 | * problems (e.g., while ":s" is working). |
| 362 | */ |
| 363 | static int allow_scrollbar = FALSE; |
| 364 | |
| 365 | #ifdef GLOBAL_IME |
| 366 | # define MyTranslateMessage(x) global_ime_TranslateMessage(x) |
| 367 | #else |
| 368 | # define MyTranslateMessage(x) TranslateMessage(x) |
| 369 | #endif |
| 370 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 371 | #if defined(FEAT_DIRECTX) |
| 372 | static int |
| 373 | directx_enabled(void) |
| 374 | { |
| 375 | if (s_dwc != NULL) |
| 376 | return 1; |
| 377 | else if (s_directx_load_attempted) |
| 378 | return 0; |
| 379 | /* load DirectX */ |
| 380 | DWrite_Init(); |
| 381 | s_directx_load_attempted = 1; |
| 382 | s_dwc = DWriteContext_Open(); |
| 383 | directx_binddc(); |
| 384 | return s_dwc != NULL ? 1 : 0; |
| 385 | } |
| 386 | |
| 387 | static void |
| 388 | directx_binddc(void) |
| 389 | { |
| 390 | if (s_textArea != NULL) |
| 391 | { |
| 392 | RECT rect; |
| 393 | GetClientRect(s_textArea, &rect); |
| 394 | DWriteContext_BindDC(s_dwc, s_hdc, &rect); |
| 395 | } |
| 396 | } |
| 397 | #endif |
| 398 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 399 | #if defined(FEAT_MBYTE) || defined(GLOBAL_IME) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 400 | /* use of WindowProc depends on wide_WindowProc */ |
| 401 | # define MyWindowProc vim_WindowProc |
| 402 | #else |
| 403 | /* use ordinary WindowProc */ |
| 404 | # define MyWindowProc DefWindowProc |
| 405 | #endif |
| 406 | |
| 407 | extern int current_font_height; /* this is in os_mswin.c */ |
| 408 | |
| 409 | static struct |
| 410 | { |
| 411 | UINT key_sym; |
| 412 | char_u vim_code0; |
| 413 | char_u vim_code1; |
| 414 | } special_keys[] = |
| 415 | { |
| 416 | {VK_UP, 'k', 'u'}, |
| 417 | {VK_DOWN, 'k', 'd'}, |
| 418 | {VK_LEFT, 'k', 'l'}, |
| 419 | {VK_RIGHT, 'k', 'r'}, |
| 420 | |
| 421 | {VK_F1, 'k', '1'}, |
| 422 | {VK_F2, 'k', '2'}, |
| 423 | {VK_F3, 'k', '3'}, |
| 424 | {VK_F4, 'k', '4'}, |
| 425 | {VK_F5, 'k', '5'}, |
| 426 | {VK_F6, 'k', '6'}, |
| 427 | {VK_F7, 'k', '7'}, |
| 428 | {VK_F8, 'k', '8'}, |
| 429 | {VK_F9, 'k', '9'}, |
| 430 | {VK_F10, 'k', ';'}, |
| 431 | |
| 432 | {VK_F11, 'F', '1'}, |
| 433 | {VK_F12, 'F', '2'}, |
| 434 | {VK_F13, 'F', '3'}, |
| 435 | {VK_F14, 'F', '4'}, |
| 436 | {VK_F15, 'F', '5'}, |
| 437 | {VK_F16, 'F', '6'}, |
| 438 | {VK_F17, 'F', '7'}, |
| 439 | {VK_F18, 'F', '8'}, |
| 440 | {VK_F19, 'F', '9'}, |
| 441 | {VK_F20, 'F', 'A'}, |
| 442 | |
| 443 | {VK_F21, 'F', 'B'}, |
| 444 | #ifdef FEAT_NETBEANS_INTG |
| 445 | {VK_PAUSE, 'F', 'B'}, /* Pause == F21 (see gui_gtk_x11.c) */ |
| 446 | #endif |
| 447 | {VK_F22, 'F', 'C'}, |
| 448 | {VK_F23, 'F', 'D'}, |
| 449 | {VK_F24, 'F', 'E'}, /* winuser.h defines up to F24 */ |
| 450 | |
| 451 | {VK_HELP, '%', '1'}, |
| 452 | {VK_BACK, 'k', 'b'}, |
| 453 | {VK_INSERT, 'k', 'I'}, |
| 454 | {VK_DELETE, 'k', 'D'}, |
| 455 | {VK_HOME, 'k', 'h'}, |
| 456 | {VK_END, '@', '7'}, |
| 457 | {VK_PRIOR, 'k', 'P'}, |
| 458 | {VK_NEXT, 'k', 'N'}, |
| 459 | {VK_PRINT, '%', '9'}, |
| 460 | {VK_ADD, 'K', '6'}, |
| 461 | {VK_SUBTRACT, 'K', '7'}, |
| 462 | {VK_DIVIDE, 'K', '8'}, |
| 463 | {VK_MULTIPLY, 'K', '9'}, |
| 464 | {VK_SEPARATOR, 'K', 'A'}, /* Keypad Enter */ |
| 465 | {VK_DECIMAL, 'K', 'B'}, |
| 466 | |
| 467 | {VK_NUMPAD0, 'K', 'C'}, |
| 468 | {VK_NUMPAD1, 'K', 'D'}, |
| 469 | {VK_NUMPAD2, 'K', 'E'}, |
| 470 | {VK_NUMPAD3, 'K', 'F'}, |
| 471 | {VK_NUMPAD4, 'K', 'G'}, |
| 472 | {VK_NUMPAD5, 'K', 'H'}, |
| 473 | {VK_NUMPAD6, 'K', 'I'}, |
| 474 | {VK_NUMPAD7, 'K', 'J'}, |
| 475 | {VK_NUMPAD8, 'K', 'K'}, |
| 476 | {VK_NUMPAD9, 'K', 'L'}, |
| 477 | |
| 478 | /* Keys that we want to be able to use any modifier with: */ |
| 479 | {VK_SPACE, ' ', NUL}, |
| 480 | {VK_TAB, TAB, NUL}, |
| 481 | {VK_ESCAPE, ESC, NUL}, |
| 482 | {NL, NL, NUL}, |
| 483 | {CAR, CAR, NUL}, |
| 484 | |
| 485 | /* End of list marker: */ |
| 486 | {0, 0, 0} |
| 487 | }; |
| 488 | |
| 489 | /* Local variables */ |
| 490 | static int s_button_pending = -1; |
| 491 | |
| 492 | /* s_getting_focus is set when we got focus but didn't see mouse-up event yet, |
| 493 | * so don't reset s_button_pending. */ |
| 494 | static int s_getting_focus = FALSE; |
| 495 | |
| 496 | static int s_x_pending; |
| 497 | static int s_y_pending; |
| 498 | static UINT s_kFlags_pending; |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 499 | static UINT s_wait_timer = 0; // Timer for get char from user |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 500 | static int s_timed_out = FALSE; |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 501 | static int dead_key = 0; // 0: no dead key, 1: dead key pressed |
| 502 | static UINT surrogate_pending_ch = 0; // 0: no surrogate pending, |
| 503 | // else a high surrogate |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 504 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 505 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 506 | /* balloon-eval WM_NOTIFY_HANDLER */ |
| 507 | static void Handle_WM_Notify(HWND hwnd, LPNMHDR pnmh); |
| 508 | static void TrackUserActivity(UINT uMsg); |
| 509 | #endif |
| 510 | |
| 511 | /* |
| 512 | * For control IME. |
| 513 | * |
| 514 | * These LOGFONT used for IME. |
| 515 | */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 516 | #if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 517 | /* holds LOGFONT for 'guifontwide' if available, otherwise 'guifont' */ |
| 518 | static LOGFONT norm_logfont; |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 519 | #endif |
| 520 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 521 | /* holds LOGFONT for 'guifont' always. */ |
| 522 | static LOGFONT sub_logfont; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 523 | #endif |
| 524 | |
| 525 | #ifdef FEAT_MBYTE_IME |
| 526 | static LRESULT _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData); |
| 527 | #endif |
| 528 | |
| 529 | #if defined(FEAT_BROWSE) |
| 530 | static char_u *convert_filter(char_u *s); |
| 531 | #endif |
| 532 | |
| 533 | #ifdef DEBUG_PRINT_ERROR |
| 534 | /* |
| 535 | * Print out the last Windows error message |
| 536 | */ |
| 537 | static void |
| 538 | print_windows_error(void) |
| 539 | { |
| 540 | LPVOID lpMsgBuf; |
| 541 | |
| 542 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 543 | NULL, GetLastError(), |
| 544 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 545 | (LPTSTR) &lpMsgBuf, 0, NULL); |
| 546 | TRACE1("Error: %s\n", lpMsgBuf); |
| 547 | LocalFree(lpMsgBuf); |
| 548 | } |
| 549 | #endif |
| 550 | |
| 551 | /* |
| 552 | * Cursor blink functions. |
| 553 | * |
| 554 | * This is a simple state machine: |
| 555 | * BLINK_NONE not blinking at all |
| 556 | * BLINK_OFF blinking, cursor is not shown |
| 557 | * BLINK_ON blinking, cursor is shown |
| 558 | */ |
| 559 | |
| 560 | #define BLINK_NONE 0 |
| 561 | #define BLINK_OFF 1 |
| 562 | #define BLINK_ON 2 |
| 563 | |
| 564 | static int blink_state = BLINK_NONE; |
| 565 | static long_u blink_waittime = 700; |
| 566 | static long_u blink_ontime = 400; |
| 567 | static long_u blink_offtime = 250; |
| 568 | static UINT blink_timer = 0; |
| 569 | |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 570 | int |
| 571 | gui_mch_is_blinking(void) |
| 572 | { |
| 573 | return blink_state != BLINK_NONE; |
| 574 | } |
| 575 | |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 576 | int |
| 577 | gui_mch_is_blink_off(void) |
| 578 | { |
| 579 | return blink_state == BLINK_OFF; |
| 580 | } |
| 581 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 582 | void |
| 583 | gui_mch_set_blinking(long wait, long on, long off) |
| 584 | { |
| 585 | blink_waittime = wait; |
| 586 | blink_ontime = on; |
| 587 | blink_offtime = off; |
| 588 | } |
| 589 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 590 | static VOID CALLBACK |
| 591 | _OnBlinkTimer( |
| 592 | HWND hwnd, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 593 | UINT uMsg UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 594 | UINT idEvent, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 595 | DWORD dwTime UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 596 | { |
| 597 | MSG msg; |
| 598 | |
| 599 | /* |
| 600 | TRACE2("Got timer event, id %d, blink_timer %d\n", idEvent, blink_timer); |
| 601 | */ |
| 602 | |
| 603 | KillTimer(NULL, idEvent); |
| 604 | |
| 605 | /* Eat spurious WM_TIMER messages */ |
| 606 | while (pPeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 607 | ; |
| 608 | |
| 609 | if (blink_state == BLINK_ON) |
| 610 | { |
| 611 | gui_undraw_cursor(); |
| 612 | blink_state = BLINK_OFF; |
| 613 | blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_offtime, |
| 614 | (TIMERPROC)_OnBlinkTimer); |
| 615 | } |
| 616 | else |
| 617 | { |
| 618 | gui_update_cursor(TRUE, FALSE); |
| 619 | blink_state = BLINK_ON; |
| 620 | blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_ontime, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 621 | (TIMERPROC)_OnBlinkTimer); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 622 | } |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 623 | gui_mch_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static void |
| 627 | gui_mswin_rm_blink_timer(void) |
| 628 | { |
| 629 | MSG msg; |
| 630 | |
| 631 | if (blink_timer != 0) |
| 632 | { |
| 633 | KillTimer(NULL, blink_timer); |
| 634 | /* Eat spurious WM_TIMER messages */ |
| 635 | while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 636 | ; |
| 637 | blink_timer = 0; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | /* |
| 642 | * Stop the cursor blinking. Show the cursor if it wasn't shown. |
| 643 | */ |
| 644 | void |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 645 | gui_mch_stop_blink(int may_call_gui_update_cursor) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 646 | { |
| 647 | gui_mswin_rm_blink_timer(); |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 648 | if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 649 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 650 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 651 | gui_mch_flush(); |
| 652 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 653 | blink_state = BLINK_NONE; |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * Start the cursor blinking. If it was already blinking, this restarts the |
| 658 | * waiting time and shows the cursor. |
| 659 | */ |
| 660 | void |
| 661 | gui_mch_start_blink(void) |
| 662 | { |
| 663 | gui_mswin_rm_blink_timer(); |
| 664 | |
| 665 | /* Only switch blinking on if none of the times is zero */ |
| 666 | if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
| 667 | { |
| 668 | blink_timer = (UINT)SetTimer(NULL, 0, (UINT)blink_waittime, |
| 669 | (TIMERPROC)_OnBlinkTimer); |
| 670 | blink_state = BLINK_ON; |
| 671 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 672 | gui_mch_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
| 676 | /* |
| 677 | * Call-back routines. |
| 678 | */ |
| 679 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 680 | static VOID CALLBACK |
| 681 | _OnTimer( |
| 682 | HWND hwnd, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 683 | UINT uMsg UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 684 | UINT idEvent, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 685 | DWORD dwTime UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 686 | { |
| 687 | MSG msg; |
| 688 | |
| 689 | /* |
| 690 | TRACE2("Got timer event, id %d, s_wait_timer %d\n", idEvent, s_wait_timer); |
| 691 | */ |
| 692 | KillTimer(NULL, idEvent); |
| 693 | s_timed_out = TRUE; |
| 694 | |
| 695 | /* Eat spurious WM_TIMER messages */ |
| 696 | while (pPeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 697 | ; |
| 698 | if (idEvent == s_wait_timer) |
| 699 | s_wait_timer = 0; |
| 700 | } |
| 701 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 702 | static void |
| 703 | _OnDeadChar( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 704 | HWND hwnd UNUSED, |
| 705 | UINT ch UNUSED, |
| 706 | int cRepeat UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 707 | { |
| 708 | dead_key = 1; |
| 709 | } |
| 710 | |
| 711 | /* |
| 712 | * Convert Unicode character "ch" to bytes in "string[slen]". |
| 713 | * When "had_alt" is TRUE the ALT key was included in "ch". |
| 714 | * Return the length. |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 715 | * Because the Windows API uses UTF-16, we have to deal with surrogate |
| 716 | * pairs; this is where we choose to deal with them: if "ch" is a high |
| 717 | * surrogate, it will be stored, and the length returned will be zero; the next |
| 718 | * char_to_string call will then include the high surrogate, decoding the pair |
| 719 | * of UTF-16 code units to a single Unicode code point, presuming it is the |
| 720 | * matching low surrogate. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 721 | */ |
| 722 | static int |
| 723 | char_to_string(int ch, char_u *string, int slen, int had_alt) |
| 724 | { |
| 725 | int len; |
| 726 | int i; |
| 727 | #ifdef FEAT_MBYTE |
| 728 | WCHAR wstring[2]; |
Bram Moolenaar | 945ec09 | 2016-06-08 21:17:43 +0200 | [diff] [blame] | 729 | char_u *ws = NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 730 | |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 731 | if (surrogate_pending_ch != 0) |
| 732 | { |
| 733 | /* We don't guarantee ch is a low surrogate to match the high surrogate |
| 734 | * we already have; it should be, but if it isn't, tough luck. */ |
| 735 | wstring[0] = surrogate_pending_ch; |
| 736 | wstring[1] = ch; |
| 737 | surrogate_pending_ch = 0; |
| 738 | len = 2; |
| 739 | } |
| 740 | else if (ch >= 0xD800 && ch <= 0xDBFF) /* high surrogate */ |
| 741 | { |
| 742 | /* We don't have the entire code point yet, only the first UTF-16 code |
| 743 | * unit; so just remember it and use it in the next call. */ |
| 744 | surrogate_pending_ch = ch; |
| 745 | return 0; |
| 746 | } |
| 747 | else |
| 748 | { |
| 749 | wstring[0] = ch; |
| 750 | len = 1; |
| 751 | } |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 752 | |
| 753 | /* "ch" is a UTF-16 character. Convert it to a string of bytes. When |
| 754 | * "enc_codepage" is non-zero use the standard Win32 function, |
| 755 | * otherwise use our own conversion function (e.g., for UTF-8). */ |
| 756 | if (enc_codepage > 0) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 757 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 758 | len = WideCharToMultiByte(enc_codepage, 0, wstring, len, |
| 759 | (LPSTR)string, slen, 0, NULL); |
| 760 | /* If we had included the ALT key into the character but now the |
| 761 | * upper bit is no longer set, that probably means the conversion |
| 762 | * failed. Convert the original character and set the upper bit |
| 763 | * afterwards. */ |
| 764 | if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 765 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 766 | wstring[0] = ch & 0x7f; |
| 767 | len = WideCharToMultiByte(enc_codepage, 0, wstring, len, |
| 768 | (LPSTR)string, slen, 0, NULL); |
| 769 | if (len == 1) /* safety check */ |
| 770 | string[0] |= 0x80; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | else |
| 774 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 775 | ws = utf16_to_enc(wstring, &len); |
| 776 | if (ws == NULL) |
| 777 | len = 0; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 778 | else |
| 779 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 780 | if (len > slen) /* just in case */ |
| 781 | len = slen; |
| 782 | mch_memmove(string, ws, len); |
| 783 | vim_free(ws); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | |
| 787 | if (len == 0) |
| 788 | #endif |
| 789 | { |
| 790 | string[0] = ch; |
| 791 | len = 1; |
| 792 | } |
| 793 | |
| 794 | for (i = 0; i < len; ++i) |
| 795 | if (string[i] == CSI && len <= slen - 2) |
| 796 | { |
| 797 | /* Insert CSI as K_CSI. */ |
| 798 | mch_memmove(string + i + 3, string + i + 1, len - i - 1); |
| 799 | string[++i] = KS_EXTRA; |
| 800 | string[++i] = (int)KE_CSI; |
| 801 | len += 2; |
| 802 | } |
| 803 | |
| 804 | return len; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Key hit, add it to the input buffer. |
| 809 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 810 | static void |
| 811 | _OnChar( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 812 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 813 | UINT ch, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 814 | int cRepeat UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 815 | { |
| 816 | char_u string[40]; |
| 817 | int len = 0; |
| 818 | |
| 819 | dead_key = 0; |
| 820 | |
| 821 | len = char_to_string(ch, string, 40, FALSE); |
| 822 | if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts) |
| 823 | { |
| 824 | trash_input_buf(); |
| 825 | got_int = TRUE; |
| 826 | } |
| 827 | |
| 828 | add_to_input_buf(string, len); |
| 829 | } |
| 830 | |
| 831 | /* |
| 832 | * Alt-Key hit, add it to the input buffer. |
| 833 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 834 | static void |
| 835 | _OnSysChar( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 836 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 837 | UINT cch, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 838 | int cRepeat UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 839 | { |
| 840 | char_u string[40]; /* Enough for multibyte character */ |
| 841 | int len; |
| 842 | int modifiers; |
| 843 | int ch = cch; /* special keys are negative */ |
| 844 | |
| 845 | dead_key = 0; |
| 846 | |
| 847 | /* TRACE("OnSysChar(%d, %c)\n", ch, ch); */ |
| 848 | |
| 849 | /* OK, we have a character key (given by ch) which was entered with the |
| 850 | * ALT key pressed. Eg, if the user presses Alt-A, then ch == 'A'. Note |
| 851 | * that the system distinguishes Alt-a and Alt-A (Alt-Shift-a unless |
| 852 | * CAPSLOCK is pressed) at this point. |
| 853 | */ |
| 854 | modifiers = MOD_MASK_ALT; |
| 855 | if (GetKeyState(VK_SHIFT) & 0x8000) |
| 856 | modifiers |= MOD_MASK_SHIFT; |
| 857 | if (GetKeyState(VK_CONTROL) & 0x8000) |
| 858 | modifiers |= MOD_MASK_CTRL; |
| 859 | |
| 860 | ch = simplify_key(ch, &modifiers); |
| 861 | /* remove the SHIFT modifier for keys where it's already included, e.g., |
| 862 | * '(' and '*' */ |
| 863 | if (ch < 0x100 && !isalpha(ch) && isprint(ch)) |
| 864 | modifiers &= ~MOD_MASK_SHIFT; |
| 865 | |
| 866 | /* Interpret the ALT key as making the key META, include SHIFT, etc. */ |
| 867 | ch = extract_modifiers(ch, &modifiers); |
| 868 | if (ch == CSI) |
| 869 | ch = K_CSI; |
| 870 | |
| 871 | len = 0; |
| 872 | if (modifiers) |
| 873 | { |
| 874 | string[len++] = CSI; |
| 875 | string[len++] = KS_MODIFIER; |
| 876 | string[len++] = modifiers; |
| 877 | } |
| 878 | |
| 879 | if (IS_SPECIAL((int)ch)) |
| 880 | { |
| 881 | string[len++] = CSI; |
| 882 | string[len++] = K_SECOND((int)ch); |
| 883 | string[len++] = K_THIRD((int)ch); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | /* Although the documentation isn't clear about it, we assume "ch" is |
| 888 | * a Unicode character. */ |
| 889 | len += char_to_string(ch, string + len, 40 - len, TRUE); |
| 890 | } |
| 891 | |
| 892 | add_to_input_buf(string, len); |
| 893 | } |
| 894 | |
| 895 | static void |
| 896 | _OnMouseEvent( |
| 897 | int button, |
| 898 | int x, |
| 899 | int y, |
| 900 | int repeated_click, |
| 901 | UINT keyFlags) |
| 902 | { |
| 903 | int vim_modifiers = 0x0; |
| 904 | |
| 905 | s_getting_focus = FALSE; |
| 906 | |
| 907 | if (keyFlags & MK_SHIFT) |
| 908 | vim_modifiers |= MOUSE_SHIFT; |
| 909 | if (keyFlags & MK_CONTROL) |
| 910 | vim_modifiers |= MOUSE_CTRL; |
| 911 | if (GetKeyState(VK_MENU) & 0x8000) |
| 912 | vim_modifiers |= MOUSE_ALT; |
| 913 | |
| 914 | gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); |
| 915 | } |
| 916 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 917 | static void |
| 918 | _OnMouseButtonDown( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 919 | HWND hwnd UNUSED, |
| 920 | BOOL fDoubleClick UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 921 | int x, |
| 922 | int y, |
| 923 | UINT keyFlags) |
| 924 | { |
| 925 | static LONG s_prevTime = 0; |
| 926 | |
| 927 | LONG currentTime = GetMessageTime(); |
| 928 | int button = -1; |
| 929 | int repeated_click; |
| 930 | |
| 931 | /* Give main window the focus: this is so the cursor isn't hollow. */ |
| 932 | (void)SetFocus(s_hwnd); |
| 933 | |
| 934 | if (s_uMsg == WM_LBUTTONDOWN || s_uMsg == WM_LBUTTONDBLCLK) |
| 935 | button = MOUSE_LEFT; |
| 936 | else if (s_uMsg == WM_MBUTTONDOWN || s_uMsg == WM_MBUTTONDBLCLK) |
| 937 | button = MOUSE_MIDDLE; |
| 938 | else if (s_uMsg == WM_RBUTTONDOWN || s_uMsg == WM_RBUTTONDBLCLK) |
| 939 | button = MOUSE_RIGHT; |
| 940 | else if (s_uMsg == WM_XBUTTONDOWN || s_uMsg == WM_XBUTTONDBLCLK) |
| 941 | { |
| 942 | #ifndef GET_XBUTTON_WPARAM |
| 943 | # define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam)) |
| 944 | #endif |
| 945 | button = ((GET_XBUTTON_WPARAM(s_wParam) == 1) ? MOUSE_X1 : MOUSE_X2); |
| 946 | } |
| 947 | else if (s_uMsg == WM_CAPTURECHANGED) |
| 948 | { |
| 949 | /* on W95/NT4, somehow you get in here with an odd Msg |
| 950 | * if you press one button while holding down the other..*/ |
| 951 | if (s_button_pending == MOUSE_LEFT) |
| 952 | button = MOUSE_RIGHT; |
| 953 | else |
| 954 | button = MOUSE_LEFT; |
| 955 | } |
| 956 | if (button >= 0) |
| 957 | { |
| 958 | repeated_click = ((int)(currentTime - s_prevTime) < p_mouset); |
| 959 | |
| 960 | /* |
| 961 | * Holding down the left and right buttons simulates pushing the middle |
| 962 | * button. |
| 963 | */ |
| 964 | if (repeated_click |
| 965 | && ((button == MOUSE_LEFT && s_button_pending == MOUSE_RIGHT) |
| 966 | || (button == MOUSE_RIGHT |
| 967 | && s_button_pending == MOUSE_LEFT))) |
| 968 | { |
| 969 | /* |
| 970 | * Hmm, gui.c will ignore more than one button down at a time, so |
| 971 | * pretend we let go of it first. |
| 972 | */ |
| 973 | gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, 0x0); |
| 974 | button = MOUSE_MIDDLE; |
| 975 | repeated_click = FALSE; |
| 976 | s_button_pending = -1; |
| 977 | _OnMouseEvent(button, x, y, repeated_click, keyFlags); |
| 978 | } |
| 979 | else if ((repeated_click) |
| 980 | || (mouse_model_popup() && (button == MOUSE_RIGHT))) |
| 981 | { |
| 982 | if (s_button_pending > -1) |
| 983 | { |
| 984 | _OnMouseEvent(s_button_pending, x, y, FALSE, keyFlags); |
| 985 | s_button_pending = -1; |
| 986 | } |
| 987 | /* TRACE("Button down at x %d, y %d\n", x, y); */ |
| 988 | _OnMouseEvent(button, x, y, repeated_click, keyFlags); |
| 989 | } |
| 990 | else |
| 991 | { |
| 992 | /* |
| 993 | * If this is the first press (i.e. not a multiple click) don't |
| 994 | * action immediately, but store and wait for: |
| 995 | * i) button-up |
| 996 | * ii) mouse move |
| 997 | * iii) another button press |
| 998 | * before using it. |
| 999 | * This enables us to make left+right simulate middle button, |
| 1000 | * without left or right being actioned first. The side-effect is |
| 1001 | * that if you click and hold the mouse without dragging, the |
| 1002 | * cursor doesn't move until you release the button. In practice |
| 1003 | * this is hardly a problem. |
| 1004 | */ |
| 1005 | s_button_pending = button; |
| 1006 | s_x_pending = x; |
| 1007 | s_y_pending = y; |
| 1008 | s_kFlags_pending = keyFlags; |
| 1009 | } |
| 1010 | |
| 1011 | s_prevTime = currentTime; |
| 1012 | } |
| 1013 | } |
| 1014 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1015 | static void |
| 1016 | _OnMouseMoveOrRelease( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1017 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1018 | int x, |
| 1019 | int y, |
| 1020 | UINT keyFlags) |
| 1021 | { |
| 1022 | int button; |
| 1023 | |
| 1024 | s_getting_focus = FALSE; |
| 1025 | if (s_button_pending > -1) |
| 1026 | { |
| 1027 | /* Delayed action for mouse down event */ |
| 1028 | _OnMouseEvent(s_button_pending, s_x_pending, |
| 1029 | s_y_pending, FALSE, s_kFlags_pending); |
| 1030 | s_button_pending = -1; |
| 1031 | } |
| 1032 | if (s_uMsg == WM_MOUSEMOVE) |
| 1033 | { |
| 1034 | /* |
| 1035 | * It's only a MOUSE_DRAG if one or more mouse buttons are being held |
| 1036 | * down. |
| 1037 | */ |
| 1038 | if (!(keyFlags & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON |
| 1039 | | MK_XBUTTON1 | MK_XBUTTON2))) |
| 1040 | { |
| 1041 | gui_mouse_moved(x, y); |
| 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | /* |
| 1046 | * While button is down, keep grabbing mouse move events when |
| 1047 | * the mouse goes outside the window |
| 1048 | */ |
| 1049 | SetCapture(s_textArea); |
| 1050 | button = MOUSE_DRAG; |
| 1051 | /* TRACE(" move at x %d, y %d\n", x, y); */ |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | ReleaseCapture(); |
| 1056 | button = MOUSE_RELEASE; |
| 1057 | /* TRACE(" up at x %d, y %d\n", x, y); */ |
| 1058 | } |
| 1059 | |
| 1060 | _OnMouseEvent(button, x, y, FALSE, keyFlags); |
| 1061 | } |
| 1062 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1063 | static void |
| 1064 | _OnSizeTextArea( |
| 1065 | HWND hwnd UNUSED, |
| 1066 | UINT state UNUSED, |
| 1067 | int cx UNUSED, |
| 1068 | int cy UNUSED) |
| 1069 | { |
| 1070 | #if defined(FEAT_DIRECTX) |
| 1071 | if (IS_ENABLE_DIRECTX()) |
| 1072 | directx_binddc(); |
| 1073 | #endif |
| 1074 | } |
| 1075 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1076 | #ifdef FEAT_MENU |
| 1077 | /* |
| 1078 | * Find the vimmenu_T with the given id |
| 1079 | */ |
| 1080 | static vimmenu_T * |
| 1081 | gui_mswin_find_menu( |
| 1082 | vimmenu_T *pMenu, |
| 1083 | int id) |
| 1084 | { |
| 1085 | vimmenu_T *pChildMenu; |
| 1086 | |
| 1087 | while (pMenu) |
| 1088 | { |
| 1089 | if (pMenu->id == (UINT)id) |
| 1090 | break; |
| 1091 | if (pMenu->children != NULL) |
| 1092 | { |
| 1093 | pChildMenu = gui_mswin_find_menu(pMenu->children, id); |
| 1094 | if (pChildMenu) |
| 1095 | { |
| 1096 | pMenu = pChildMenu; |
| 1097 | break; |
| 1098 | } |
| 1099 | } |
| 1100 | pMenu = pMenu->next; |
| 1101 | } |
| 1102 | return pMenu; |
| 1103 | } |
| 1104 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1105 | static void |
| 1106 | _OnMenu( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1107 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1108 | int id, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1109 | HWND hwndCtl UNUSED, |
| 1110 | UINT codeNotify UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1111 | { |
| 1112 | vimmenu_T *pMenu; |
| 1113 | |
| 1114 | pMenu = gui_mswin_find_menu(root_menu, id); |
| 1115 | if (pMenu) |
| 1116 | gui_menu_cb(pMenu); |
| 1117 | } |
| 1118 | #endif |
| 1119 | |
| 1120 | #ifdef MSWIN_FIND_REPLACE |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 1121 | # ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1122 | /* |
| 1123 | * copy useful data from structure LPFINDREPLACE to structure LPFINDREPLACEW |
| 1124 | */ |
| 1125 | static void |
| 1126 | findrep_atow(LPFINDREPLACEW lpfrw, LPFINDREPLACE lpfr) |
| 1127 | { |
| 1128 | WCHAR *wp; |
| 1129 | |
| 1130 | lpfrw->hwndOwner = lpfr->hwndOwner; |
| 1131 | lpfrw->Flags = lpfr->Flags; |
| 1132 | |
| 1133 | wp = enc_to_utf16((char_u *)lpfr->lpstrFindWhat, NULL); |
| 1134 | wcsncpy(lpfrw->lpstrFindWhat, wp, lpfrw->wFindWhatLen - 1); |
| 1135 | vim_free(wp); |
| 1136 | |
| 1137 | /* the field "lpstrReplaceWith" doesn't need to be copied */ |
| 1138 | } |
| 1139 | |
| 1140 | /* |
| 1141 | * copy useful data from structure LPFINDREPLACEW to structure LPFINDREPLACE |
| 1142 | */ |
| 1143 | static void |
| 1144 | findrep_wtoa(LPFINDREPLACE lpfr, LPFINDREPLACEW lpfrw) |
| 1145 | { |
| 1146 | char_u *p; |
| 1147 | |
| 1148 | lpfr->Flags = lpfrw->Flags; |
| 1149 | |
| 1150 | p = utf16_to_enc((short_u*)lpfrw->lpstrFindWhat, NULL); |
| 1151 | vim_strncpy((char_u *)lpfr->lpstrFindWhat, p, lpfr->wFindWhatLen - 1); |
| 1152 | vim_free(p); |
| 1153 | |
| 1154 | p = utf16_to_enc((short_u*)lpfrw->lpstrReplaceWith, NULL); |
| 1155 | vim_strncpy((char_u *)lpfr->lpstrReplaceWith, p, lpfr->wReplaceWithLen - 1); |
| 1156 | vim_free(p); |
| 1157 | } |
| 1158 | # endif |
| 1159 | |
| 1160 | /* |
| 1161 | * Handle a Find/Replace window message. |
| 1162 | */ |
| 1163 | static void |
| 1164 | _OnFindRepl(void) |
| 1165 | { |
| 1166 | int flags = 0; |
| 1167 | int down; |
| 1168 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 1169 | # ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1170 | /* If the OS is Windows NT, and 'encoding' differs from active codepage: |
| 1171 | * convert text from wide string. */ |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 1172 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1173 | { |
| 1174 | findrep_wtoa(&s_findrep_struct, &s_findrep_struct_w); |
| 1175 | } |
| 1176 | # endif |
| 1177 | |
| 1178 | if (s_findrep_struct.Flags & FR_DIALOGTERM) |
| 1179 | /* Give main window the focus back. */ |
| 1180 | (void)SetFocus(s_hwnd); |
| 1181 | |
| 1182 | if (s_findrep_struct.Flags & FR_FINDNEXT) |
| 1183 | { |
| 1184 | flags = FRD_FINDNEXT; |
| 1185 | |
| 1186 | /* Give main window the focus back: this is so the cursor isn't |
| 1187 | * hollow. */ |
| 1188 | (void)SetFocus(s_hwnd); |
| 1189 | } |
| 1190 | else if (s_findrep_struct.Flags & FR_REPLACE) |
| 1191 | { |
| 1192 | flags = FRD_REPLACE; |
| 1193 | |
| 1194 | /* Give main window the focus back: this is so the cursor isn't |
| 1195 | * hollow. */ |
| 1196 | (void)SetFocus(s_hwnd); |
| 1197 | } |
| 1198 | else if (s_findrep_struct.Flags & FR_REPLACEALL) |
| 1199 | { |
| 1200 | flags = FRD_REPLACEALL; |
| 1201 | } |
| 1202 | |
| 1203 | if (flags != 0) |
| 1204 | { |
| 1205 | /* Call the generic GUI function to do the actual work. */ |
| 1206 | if (s_findrep_struct.Flags & FR_WHOLEWORD) |
| 1207 | flags |= FRD_WHOLE_WORD; |
| 1208 | if (s_findrep_struct.Flags & FR_MATCHCASE) |
| 1209 | flags |= FRD_MATCH_CASE; |
| 1210 | down = (s_findrep_struct.Flags & FR_DOWN) != 0; |
| 1211 | gui_do_findrepl(flags, (char_u *)s_findrep_struct.lpstrFindWhat, |
| 1212 | (char_u *)s_findrep_struct.lpstrReplaceWith, down); |
| 1213 | } |
| 1214 | } |
| 1215 | #endif |
| 1216 | |
| 1217 | static void |
| 1218 | HandleMouseHide(UINT uMsg, LPARAM lParam) |
| 1219 | { |
| 1220 | static LPARAM last_lParam = 0L; |
| 1221 | |
| 1222 | /* We sometimes get a mousemove when the mouse didn't move... */ |
| 1223 | if (uMsg == WM_MOUSEMOVE || uMsg == WM_NCMOUSEMOVE) |
| 1224 | { |
| 1225 | if (lParam == last_lParam) |
| 1226 | return; |
| 1227 | last_lParam = lParam; |
| 1228 | } |
| 1229 | |
| 1230 | /* Handle specially, to centralise coding. We need to be sure we catch all |
| 1231 | * possible events which should cause us to restore the cursor (as it is a |
| 1232 | * shared resource, we take full responsibility for it). |
| 1233 | */ |
| 1234 | switch (uMsg) |
| 1235 | { |
| 1236 | case WM_KEYUP: |
| 1237 | case WM_CHAR: |
| 1238 | /* |
| 1239 | * blank out the pointer if necessary |
| 1240 | */ |
| 1241 | if (p_mh) |
| 1242 | gui_mch_mousehide(TRUE); |
| 1243 | break; |
| 1244 | |
| 1245 | case WM_SYSKEYUP: /* show the pointer when a system-key is pressed */ |
| 1246 | case WM_SYSCHAR: |
| 1247 | case WM_MOUSEMOVE: /* show the pointer on any mouse action */ |
| 1248 | case WM_LBUTTONDOWN: |
| 1249 | case WM_LBUTTONUP: |
| 1250 | case WM_MBUTTONDOWN: |
| 1251 | case WM_MBUTTONUP: |
| 1252 | case WM_RBUTTONDOWN: |
| 1253 | case WM_RBUTTONUP: |
| 1254 | case WM_XBUTTONDOWN: |
| 1255 | case WM_XBUTTONUP: |
| 1256 | case WM_NCMOUSEMOVE: |
| 1257 | case WM_NCLBUTTONDOWN: |
| 1258 | case WM_NCLBUTTONUP: |
| 1259 | case WM_NCMBUTTONDOWN: |
| 1260 | case WM_NCMBUTTONUP: |
| 1261 | case WM_NCRBUTTONDOWN: |
| 1262 | case WM_NCRBUTTONUP: |
| 1263 | case WM_KILLFOCUS: |
| 1264 | /* |
| 1265 | * if the pointer is currently hidden, then we should show it. |
| 1266 | */ |
| 1267 | gui_mch_mousehide(FALSE); |
| 1268 | break; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | static LRESULT CALLBACK |
| 1273 | _TextAreaWndProc( |
| 1274 | HWND hwnd, |
| 1275 | UINT uMsg, |
| 1276 | WPARAM wParam, |
| 1277 | LPARAM lParam) |
| 1278 | { |
| 1279 | /* |
| 1280 | TRACE("TextAreaWndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n", |
| 1281 | hwnd, uMsg, wParam, lParam); |
| 1282 | */ |
| 1283 | |
| 1284 | HandleMouseHide(uMsg, lParam); |
| 1285 | |
| 1286 | s_uMsg = uMsg; |
| 1287 | s_wParam = wParam; |
| 1288 | s_lParam = lParam; |
| 1289 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1290 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1291 | TrackUserActivity(uMsg); |
| 1292 | #endif |
| 1293 | |
| 1294 | switch (uMsg) |
| 1295 | { |
| 1296 | HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK,_OnMouseButtonDown); |
| 1297 | HANDLE_MSG(hwnd, WM_LBUTTONDOWN,_OnMouseButtonDown); |
| 1298 | HANDLE_MSG(hwnd, WM_LBUTTONUP, _OnMouseMoveOrRelease); |
| 1299 | HANDLE_MSG(hwnd, WM_MBUTTONDBLCLK,_OnMouseButtonDown); |
| 1300 | HANDLE_MSG(hwnd, WM_MBUTTONDOWN,_OnMouseButtonDown); |
| 1301 | HANDLE_MSG(hwnd, WM_MBUTTONUP, _OnMouseMoveOrRelease); |
| 1302 | HANDLE_MSG(hwnd, WM_MOUSEMOVE, _OnMouseMoveOrRelease); |
| 1303 | HANDLE_MSG(hwnd, WM_PAINT, _OnPaint); |
| 1304 | HANDLE_MSG(hwnd, WM_RBUTTONDBLCLK,_OnMouseButtonDown); |
| 1305 | HANDLE_MSG(hwnd, WM_RBUTTONDOWN,_OnMouseButtonDown); |
| 1306 | HANDLE_MSG(hwnd, WM_RBUTTONUP, _OnMouseMoveOrRelease); |
| 1307 | HANDLE_MSG(hwnd, WM_XBUTTONDBLCLK,_OnMouseButtonDown); |
| 1308 | HANDLE_MSG(hwnd, WM_XBUTTONDOWN,_OnMouseButtonDown); |
| 1309 | HANDLE_MSG(hwnd, WM_XBUTTONUP, _OnMouseMoveOrRelease); |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1310 | HANDLE_MSG(hwnd, WM_SIZE, _OnSizeTextArea); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1311 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1312 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1313 | case WM_NOTIFY: Handle_WM_Notify(hwnd, (LPNMHDR)lParam); |
| 1314 | return TRUE; |
| 1315 | #endif |
| 1316 | default: |
| 1317 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1318 | } |
| 1319 | } |
| 1320 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 1321 | #if defined(FEAT_MBYTE) \ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1322 | || defined(GLOBAL_IME) \ |
| 1323 | || defined(PROTO) |
| 1324 | # ifdef PROTO |
| 1325 | typedef int WINAPI; |
| 1326 | # endif |
| 1327 | |
| 1328 | LRESULT WINAPI |
| 1329 | vim_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 1330 | { |
| 1331 | # ifdef GLOBAL_IME |
| 1332 | return global_ime_DefWindowProc(hwnd, message, wParam, lParam); |
| 1333 | # else |
| 1334 | if (wide_WindowProc) |
| 1335 | return DefWindowProcW(hwnd, message, wParam, lParam); |
| 1336 | return DefWindowProc(hwnd, message, wParam, lParam); |
| 1337 | #endif |
| 1338 | } |
| 1339 | #endif |
| 1340 | |
| 1341 | /* |
| 1342 | * Called when the foreground or background color has been changed. |
| 1343 | */ |
| 1344 | void |
| 1345 | gui_mch_new_colors(void) |
| 1346 | { |
| 1347 | /* nothing to do? */ |
| 1348 | } |
| 1349 | |
| 1350 | /* |
| 1351 | * Set the colors to their default values. |
| 1352 | */ |
| 1353 | void |
| 1354 | gui_mch_def_colors(void) |
| 1355 | { |
| 1356 | gui.norm_pixel = GetSysColor(COLOR_WINDOWTEXT); |
| 1357 | gui.back_pixel = GetSysColor(COLOR_WINDOW); |
| 1358 | gui.def_norm_pixel = gui.norm_pixel; |
| 1359 | gui.def_back_pixel = gui.back_pixel; |
| 1360 | } |
| 1361 | |
| 1362 | /* |
| 1363 | * Open the GUI window which was created by a call to gui_mch_init(). |
| 1364 | */ |
| 1365 | int |
| 1366 | gui_mch_open(void) |
| 1367 | { |
| 1368 | #ifndef SW_SHOWDEFAULT |
| 1369 | # define SW_SHOWDEFAULT 10 /* Borland 5.0 doesn't have it */ |
| 1370 | #endif |
| 1371 | /* Actually open the window, if not already visible |
| 1372 | * (may be done already in gui_mch_set_shellsize) */ |
| 1373 | if (!IsWindowVisible(s_hwnd)) |
| 1374 | ShowWindow(s_hwnd, SW_SHOWDEFAULT); |
| 1375 | |
| 1376 | #ifdef MSWIN_FIND_REPLACE |
| 1377 | /* Init replace string here, so that we keep it when re-opening the |
| 1378 | * dialog. */ |
| 1379 | s_findrep_struct.lpstrReplaceWith[0] = NUL; |
| 1380 | #endif |
| 1381 | |
| 1382 | return OK; |
| 1383 | } |
| 1384 | |
| 1385 | /* |
| 1386 | * Get the position of the top left corner of the window. |
| 1387 | */ |
| 1388 | int |
| 1389 | gui_mch_get_winpos(int *x, int *y) |
| 1390 | { |
| 1391 | RECT rect; |
| 1392 | |
| 1393 | GetWindowRect(s_hwnd, &rect); |
| 1394 | *x = rect.left; |
| 1395 | *y = rect.top; |
| 1396 | return OK; |
| 1397 | } |
| 1398 | |
| 1399 | /* |
| 1400 | * Set the position of the top left corner of the window to the given |
| 1401 | * coordinates. |
| 1402 | */ |
| 1403 | void |
| 1404 | gui_mch_set_winpos(int x, int y) |
| 1405 | { |
| 1406 | SetWindowPos(s_hwnd, NULL, x, y, 0, 0, |
| 1407 | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); |
| 1408 | } |
| 1409 | void |
| 1410 | gui_mch_set_text_area_pos(int x, int y, int w, int h) |
| 1411 | { |
| 1412 | static int oldx = 0; |
| 1413 | static int oldy = 0; |
| 1414 | |
| 1415 | SetWindowPos(s_textArea, NULL, x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE); |
| 1416 | |
| 1417 | #ifdef FEAT_TOOLBAR |
| 1418 | if (vim_strchr(p_go, GO_TOOLBAR) != NULL) |
| 1419 | SendMessage(s_toolbarhwnd, WM_SIZE, |
| 1420 | (WPARAM)0, (LPARAM)(w + ((long)(TOOLBAR_BUTTON_HEIGHT+8)<<16))); |
| 1421 | #endif |
| 1422 | #if defined(FEAT_GUI_TABLINE) |
| 1423 | if (showing_tabline) |
| 1424 | { |
| 1425 | int top = 0; |
| 1426 | RECT rect; |
| 1427 | |
| 1428 | # ifdef FEAT_TOOLBAR |
| 1429 | if (vim_strchr(p_go, GO_TOOLBAR) != NULL) |
| 1430 | top = TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT; |
| 1431 | # endif |
| 1432 | GetClientRect(s_hwnd, &rect); |
| 1433 | MoveWindow(s_tabhwnd, 0, top, rect.right, gui.tabline_height, TRUE); |
| 1434 | } |
| 1435 | #endif |
| 1436 | |
| 1437 | /* When side scroll bar is unshown, the size of window will change. |
| 1438 | * then, the text area move left or right. thus client rect should be |
| 1439 | * forcedly redrawn. (Yasuhiro Matsumoto) */ |
| 1440 | if (oldx != x || oldy != y) |
| 1441 | { |
| 1442 | InvalidateRect(s_hwnd, NULL, FALSE); |
| 1443 | oldx = x; |
| 1444 | oldy = y; |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | |
| 1449 | /* |
| 1450 | * Scrollbar stuff: |
| 1451 | */ |
| 1452 | |
| 1453 | void |
| 1454 | gui_mch_enable_scrollbar( |
| 1455 | scrollbar_T *sb, |
| 1456 | int flag) |
| 1457 | { |
| 1458 | ShowScrollBar(sb->id, SB_CTL, flag); |
| 1459 | |
| 1460 | /* TODO: When the window is maximized, the size of the window stays the |
| 1461 | * same, thus the size of the text area changes. On Win98 it's OK, on Win |
| 1462 | * NT 4.0 it's not... */ |
| 1463 | } |
| 1464 | |
| 1465 | void |
| 1466 | gui_mch_set_scrollbar_pos( |
| 1467 | scrollbar_T *sb, |
| 1468 | int x, |
| 1469 | int y, |
| 1470 | int w, |
| 1471 | int h) |
| 1472 | { |
| 1473 | SetWindowPos(sb->id, NULL, x, y, w, h, |
| 1474 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW); |
| 1475 | } |
| 1476 | |
| 1477 | void |
| 1478 | gui_mch_create_scrollbar( |
| 1479 | scrollbar_T *sb, |
| 1480 | int orient) /* SBAR_VERT or SBAR_HORIZ */ |
| 1481 | { |
| 1482 | sb->id = CreateWindow( |
| 1483 | "SCROLLBAR", "Scrollbar", |
| 1484 | WS_CHILD | ((orient == SBAR_VERT) ? SBS_VERT : SBS_HORZ), 0, 0, |
| 1485 | 10, /* Any value will do for now */ |
| 1486 | 10, /* Any value will do for now */ |
| 1487 | s_hwnd, NULL, |
| 1488 | s_hinst, NULL); |
| 1489 | } |
| 1490 | |
| 1491 | /* |
| 1492 | * Find the scrollbar with the given hwnd. |
| 1493 | */ |
| 1494 | static scrollbar_T * |
| 1495 | gui_mswin_find_scrollbar(HWND hwnd) |
| 1496 | { |
| 1497 | win_T *wp; |
| 1498 | |
| 1499 | if (gui.bottom_sbar.id == hwnd) |
| 1500 | return &gui.bottom_sbar; |
| 1501 | FOR_ALL_WINDOWS(wp) |
| 1502 | { |
| 1503 | if (wp->w_scrollbars[SBAR_LEFT].id == hwnd) |
| 1504 | return &wp->w_scrollbars[SBAR_LEFT]; |
| 1505 | if (wp->w_scrollbars[SBAR_RIGHT].id == hwnd) |
| 1506 | return &wp->w_scrollbars[SBAR_RIGHT]; |
| 1507 | } |
| 1508 | return NULL; |
| 1509 | } |
| 1510 | |
| 1511 | /* |
| 1512 | * Get the character size of a font. |
| 1513 | */ |
| 1514 | static void |
| 1515 | GetFontSize(GuiFont font) |
| 1516 | { |
| 1517 | HWND hwnd = GetDesktopWindow(); |
| 1518 | HDC hdc = GetWindowDC(hwnd); |
| 1519 | HFONT hfntOld = SelectFont(hdc, (HFONT)font); |
| 1520 | TEXTMETRIC tm; |
| 1521 | |
| 1522 | GetTextMetrics(hdc, &tm); |
| 1523 | gui.char_width = tm.tmAveCharWidth + tm.tmOverhang; |
| 1524 | |
| 1525 | gui.char_height = tm.tmHeight + p_linespace; |
| 1526 | |
| 1527 | SelectFont(hdc, hfntOld); |
| 1528 | |
| 1529 | ReleaseDC(hwnd, hdc); |
| 1530 | } |
| 1531 | |
| 1532 | /* |
| 1533 | * Adjust gui.char_height (after 'linespace' was changed). |
| 1534 | */ |
| 1535 | int |
| 1536 | gui_mch_adjust_charheight(void) |
| 1537 | { |
| 1538 | GetFontSize(gui.norm_font); |
| 1539 | return OK; |
| 1540 | } |
| 1541 | |
| 1542 | static GuiFont |
| 1543 | get_font_handle(LOGFONT *lf) |
| 1544 | { |
| 1545 | HFONT font = NULL; |
| 1546 | |
| 1547 | /* Load the font */ |
| 1548 | font = CreateFontIndirect(lf); |
| 1549 | |
| 1550 | if (font == NULL) |
| 1551 | return NOFONT; |
| 1552 | |
| 1553 | return (GuiFont)font; |
| 1554 | } |
| 1555 | |
| 1556 | static int |
| 1557 | pixels_to_points(int pixels, int vertical) |
| 1558 | { |
| 1559 | int points; |
| 1560 | HWND hwnd; |
| 1561 | HDC hdc; |
| 1562 | |
| 1563 | hwnd = GetDesktopWindow(); |
| 1564 | hdc = GetWindowDC(hwnd); |
| 1565 | |
| 1566 | points = MulDiv(pixels, 72, |
| 1567 | GetDeviceCaps(hdc, vertical ? LOGPIXELSY : LOGPIXELSX)); |
| 1568 | |
| 1569 | ReleaseDC(hwnd, hdc); |
| 1570 | |
| 1571 | return points; |
| 1572 | } |
| 1573 | |
| 1574 | GuiFont |
| 1575 | gui_mch_get_font( |
| 1576 | char_u *name, |
| 1577 | int giveErrorIfMissing) |
| 1578 | { |
| 1579 | LOGFONT lf; |
| 1580 | GuiFont font = NOFONT; |
| 1581 | |
| 1582 | if (get_logfont(&lf, name, NULL, giveErrorIfMissing) == OK) |
| 1583 | font = get_font_handle(&lf); |
| 1584 | if (font == NOFONT && giveErrorIfMissing) |
| 1585 | EMSG2(_(e_font), name); |
| 1586 | return font; |
| 1587 | } |
| 1588 | |
| 1589 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 1590 | /* |
| 1591 | * Return the name of font "font" in allocated memory. |
| 1592 | * Don't know how to get the actual name, thus use the provided name. |
| 1593 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1594 | char_u * |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1595 | gui_mch_get_fontname(GuiFont font UNUSED, char_u *name) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1596 | { |
| 1597 | if (name == NULL) |
| 1598 | return NULL; |
| 1599 | return vim_strsave(name); |
| 1600 | } |
| 1601 | #endif |
| 1602 | |
| 1603 | void |
| 1604 | gui_mch_free_font(GuiFont font) |
| 1605 | { |
| 1606 | if (font) |
| 1607 | DeleteObject((HFONT)font); |
| 1608 | } |
| 1609 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1610 | /* |
| 1611 | * Return the Pixel value (color) for the given color name. |
| 1612 | * Return INVALCOLOR for error. |
| 1613 | */ |
| 1614 | guicolor_T |
| 1615 | gui_mch_get_color(char_u *name) |
| 1616 | { |
Bram Moolenaar | c285fe7 | 2016-04-26 21:51:48 +0200 | [diff] [blame] | 1617 | int i; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1618 | |
| 1619 | typedef struct SysColorTable |
| 1620 | { |
| 1621 | char *name; |
| 1622 | int color; |
| 1623 | } SysColorTable; |
| 1624 | |
| 1625 | static SysColorTable sys_table[] = |
| 1626 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1627 | {"SYS_3DDKSHADOW", COLOR_3DDKSHADOW}, |
| 1628 | {"SYS_3DHILIGHT", COLOR_3DHILIGHT}, |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 1629 | #ifdef COLOR_3DHIGHLIGHT |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1630 | {"SYS_3DHIGHLIGHT", COLOR_3DHIGHLIGHT}, |
| 1631 | #endif |
| 1632 | {"SYS_BTNHILIGHT", COLOR_BTNHILIGHT}, |
| 1633 | {"SYS_BTNHIGHLIGHT", COLOR_BTNHIGHLIGHT}, |
| 1634 | {"SYS_3DLIGHT", COLOR_3DLIGHT}, |
| 1635 | {"SYS_3DSHADOW", COLOR_3DSHADOW}, |
| 1636 | {"SYS_DESKTOP", COLOR_DESKTOP}, |
| 1637 | {"SYS_INFOBK", COLOR_INFOBK}, |
| 1638 | {"SYS_INFOTEXT", COLOR_INFOTEXT}, |
| 1639 | {"SYS_3DFACE", COLOR_3DFACE}, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1640 | {"SYS_BTNFACE", COLOR_BTNFACE}, |
| 1641 | {"SYS_BTNSHADOW", COLOR_BTNSHADOW}, |
| 1642 | {"SYS_ACTIVEBORDER", COLOR_ACTIVEBORDER}, |
| 1643 | {"SYS_ACTIVECAPTION", COLOR_ACTIVECAPTION}, |
| 1644 | {"SYS_APPWORKSPACE", COLOR_APPWORKSPACE}, |
| 1645 | {"SYS_BACKGROUND", COLOR_BACKGROUND}, |
| 1646 | {"SYS_BTNTEXT", COLOR_BTNTEXT}, |
| 1647 | {"SYS_CAPTIONTEXT", COLOR_CAPTIONTEXT}, |
| 1648 | {"SYS_GRAYTEXT", COLOR_GRAYTEXT}, |
| 1649 | {"SYS_HIGHLIGHT", COLOR_HIGHLIGHT}, |
| 1650 | {"SYS_HIGHLIGHTTEXT", COLOR_HIGHLIGHTTEXT}, |
| 1651 | {"SYS_INACTIVEBORDER", COLOR_INACTIVEBORDER}, |
| 1652 | {"SYS_INACTIVECAPTION", COLOR_INACTIVECAPTION}, |
| 1653 | {"SYS_INACTIVECAPTIONTEXT", COLOR_INACTIVECAPTIONTEXT}, |
| 1654 | {"SYS_MENU", COLOR_MENU}, |
| 1655 | {"SYS_MENUTEXT", COLOR_MENUTEXT}, |
| 1656 | {"SYS_SCROLLBAR", COLOR_SCROLLBAR}, |
| 1657 | {"SYS_WINDOW", COLOR_WINDOW}, |
| 1658 | {"SYS_WINDOWFRAME", COLOR_WINDOWFRAME}, |
| 1659 | {"SYS_WINDOWTEXT", COLOR_WINDOWTEXT} |
| 1660 | }; |
| 1661 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1662 | /* |
| 1663 | * Try to look up a system colour. |
| 1664 | */ |
| 1665 | for (i = 0; i < sizeof(sys_table) / sizeof(sys_table[0]); i++) |
| 1666 | if (STRICMP(name, sys_table[i].name) == 0) |
| 1667 | return GetSysColor(sys_table[i].color); |
| 1668 | |
Bram Moolenaar | ab30221 | 2016-04-26 20:59:29 +0200 | [diff] [blame] | 1669 | return gui_get_color_cmn(name); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1670 | } |
Bram Moolenaar | c285fe7 | 2016-04-26 21:51:48 +0200 | [diff] [blame] | 1671 | |
Bram Moolenaar | 26af85d | 2017-07-23 16:45:10 +0200 | [diff] [blame] | 1672 | guicolor_T |
| 1673 | gui_mch_get_rgb_color(int r, int g, int b) |
| 1674 | { |
| 1675 | return gui_get_rgb_color_cmn(r, g, b); |
| 1676 | } |
| 1677 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1678 | /* |
| 1679 | * Return OK if the key with the termcap name "name" is supported. |
| 1680 | */ |
| 1681 | int |
| 1682 | gui_mch_haskey(char_u *name) |
| 1683 | { |
| 1684 | int i; |
| 1685 | |
| 1686 | for (i = 0; special_keys[i].vim_code1 != NUL; i++) |
| 1687 | if (name[0] == special_keys[i].vim_code0 && |
| 1688 | name[1] == special_keys[i].vim_code1) |
| 1689 | return OK; |
| 1690 | return FAIL; |
| 1691 | } |
| 1692 | |
| 1693 | void |
| 1694 | gui_mch_beep(void) |
| 1695 | { |
| 1696 | MessageBeep(MB_OK); |
| 1697 | } |
| 1698 | /* |
| 1699 | * Invert a rectangle from row r, column c, for nr rows and nc columns. |
| 1700 | */ |
| 1701 | void |
| 1702 | gui_mch_invert_rectangle( |
| 1703 | int r, |
| 1704 | int c, |
| 1705 | int nr, |
| 1706 | int nc) |
| 1707 | { |
| 1708 | RECT rc; |
| 1709 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1710 | #if defined(FEAT_DIRECTX) |
| 1711 | if (IS_ENABLE_DIRECTX()) |
| 1712 | DWriteContext_Flush(s_dwc); |
| 1713 | #endif |
| 1714 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1715 | /* |
| 1716 | * Note: InvertRect() excludes right and bottom of rectangle. |
| 1717 | */ |
| 1718 | rc.left = FILL_X(c); |
| 1719 | rc.top = FILL_Y(r); |
| 1720 | rc.right = rc.left + nc * gui.char_width; |
| 1721 | rc.bottom = rc.top + nr * gui.char_height; |
| 1722 | InvertRect(s_hdc, &rc); |
| 1723 | } |
| 1724 | |
| 1725 | /* |
| 1726 | * Iconify the GUI window. |
| 1727 | */ |
| 1728 | void |
| 1729 | gui_mch_iconify(void) |
| 1730 | { |
| 1731 | ShowWindow(s_hwnd, SW_MINIMIZE); |
| 1732 | } |
| 1733 | |
| 1734 | /* |
| 1735 | * Draw a cursor without focus. |
| 1736 | */ |
| 1737 | void |
| 1738 | gui_mch_draw_hollow_cursor(guicolor_T color) |
| 1739 | { |
| 1740 | HBRUSH hbr; |
| 1741 | RECT rc; |
| 1742 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1743 | #if defined(FEAT_DIRECTX) |
| 1744 | if (IS_ENABLE_DIRECTX()) |
| 1745 | DWriteContext_Flush(s_dwc); |
| 1746 | #endif |
| 1747 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1748 | /* |
| 1749 | * Note: FrameRect() excludes right and bottom of rectangle. |
| 1750 | */ |
| 1751 | rc.left = FILL_X(gui.col); |
| 1752 | rc.top = FILL_Y(gui.row); |
| 1753 | rc.right = rc.left + gui.char_width; |
| 1754 | #ifdef FEAT_MBYTE |
| 1755 | if (mb_lefthalve(gui.row, gui.col)) |
| 1756 | rc.right += gui.char_width; |
| 1757 | #endif |
| 1758 | rc.bottom = rc.top + gui.char_height; |
| 1759 | hbr = CreateSolidBrush(color); |
| 1760 | FrameRect(s_hdc, &rc, hbr); |
| 1761 | DeleteBrush(hbr); |
| 1762 | } |
| 1763 | /* |
| 1764 | * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using |
| 1765 | * color "color". |
| 1766 | */ |
| 1767 | void |
| 1768 | gui_mch_draw_part_cursor( |
| 1769 | int w, |
| 1770 | int h, |
| 1771 | guicolor_T color) |
| 1772 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1773 | RECT rc; |
| 1774 | |
| 1775 | /* |
| 1776 | * Note: FillRect() excludes right and bottom of rectangle. |
| 1777 | */ |
| 1778 | rc.left = |
| 1779 | #ifdef FEAT_RIGHTLEFT |
| 1780 | /* vertical line should be on the right of current point */ |
| 1781 | CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
| 1782 | #endif |
| 1783 | FILL_X(gui.col); |
| 1784 | rc.top = FILL_Y(gui.row) + gui.char_height - h; |
| 1785 | rc.right = rc.left + w; |
| 1786 | rc.bottom = rc.top + h; |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1787 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 1788 | fill_rect(&rc, NULL, color); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | /* |
| 1793 | * Generates a VK_SPACE when the internal dead_key flag is set to output the |
| 1794 | * dead key's nominal character and re-post the original message. |
| 1795 | */ |
| 1796 | static void |
| 1797 | outputDeadKey_rePost(MSG originalMsg) |
| 1798 | { |
| 1799 | static MSG deadCharExpel; |
| 1800 | |
| 1801 | if (!dead_key) |
| 1802 | return; |
| 1803 | |
| 1804 | dead_key = 0; |
| 1805 | |
| 1806 | /* Make Windows generate the dead key's character */ |
| 1807 | deadCharExpel.message = originalMsg.message; |
| 1808 | deadCharExpel.hwnd = originalMsg.hwnd; |
| 1809 | deadCharExpel.wParam = VK_SPACE; |
| 1810 | |
| 1811 | MyTranslateMessage(&deadCharExpel); |
| 1812 | |
| 1813 | /* re-generate the current character free of the dead char influence */ |
| 1814 | PostMessage(originalMsg.hwnd, originalMsg.message, originalMsg.wParam, |
| 1815 | originalMsg.lParam); |
| 1816 | } |
| 1817 | |
| 1818 | |
| 1819 | /* |
| 1820 | * Process a single Windows message. |
| 1821 | * If one is not available we hang until one is. |
| 1822 | */ |
| 1823 | static void |
| 1824 | process_message(void) |
| 1825 | { |
| 1826 | MSG msg; |
| 1827 | UINT vk = 0; /* Virtual key */ |
| 1828 | char_u string[40]; |
| 1829 | int i; |
| 1830 | int modifiers = 0; |
| 1831 | int key; |
| 1832 | #ifdef FEAT_MENU |
| 1833 | static char_u k10[] = {K_SPECIAL, 'k', ';', 0}; |
| 1834 | #endif |
| 1835 | |
| 1836 | pGetMessage(&msg, NULL, 0, 0); |
| 1837 | |
| 1838 | #ifdef FEAT_OLE |
| 1839 | /* Look after OLE Automation commands */ |
| 1840 | if (msg.message == WM_OLE) |
| 1841 | { |
| 1842 | char_u *str = (char_u *)msg.lParam; |
| 1843 | if (str == NULL || *str == NUL) |
| 1844 | { |
| 1845 | /* Message can't be ours, forward it. Fixes problem with Ultramon |
| 1846 | * 3.0.4 */ |
| 1847 | pDispatchMessage(&msg); |
| 1848 | } |
| 1849 | else |
| 1850 | { |
| 1851 | add_to_input_buf(str, (int)STRLEN(str)); |
| 1852 | vim_free(str); /* was allocated in CVim::SendKeys() */ |
| 1853 | } |
| 1854 | return; |
| 1855 | } |
| 1856 | #endif |
| 1857 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1858 | #ifdef MSWIN_FIND_REPLACE |
| 1859 | /* Don't process messages used by the dialog */ |
| 1860 | if (s_findrep_hwnd != NULL && pIsDialogMessage(s_findrep_hwnd, &msg)) |
| 1861 | { |
| 1862 | HandleMouseHide(msg.message, msg.lParam); |
| 1863 | return; |
| 1864 | } |
| 1865 | #endif |
| 1866 | |
| 1867 | /* |
| 1868 | * Check if it's a special key that we recognise. If not, call |
| 1869 | * TranslateMessage(). |
| 1870 | */ |
| 1871 | if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) |
| 1872 | { |
| 1873 | vk = (int) msg.wParam; |
| 1874 | |
| 1875 | /* |
| 1876 | * Handle dead keys in special conditions in other cases we let Windows |
| 1877 | * handle them and do not interfere. |
| 1878 | * |
| 1879 | * The dead_key flag must be reset on several occasions: |
| 1880 | * - in _OnChar() (or _OnSysChar()) as any dead key was necessarily |
| 1881 | * consumed at that point (This is when we let Windows combine the |
| 1882 | * dead character on its own) |
| 1883 | * |
| 1884 | * - Before doing something special such as regenerating keypresses to |
| 1885 | * expel the dead character as this could trigger an infinite loop if |
| 1886 | * for some reason MyTranslateMessage() do not trigger a call |
| 1887 | * immediately to _OnChar() (or _OnSysChar()). |
| 1888 | */ |
| 1889 | if (dead_key) |
| 1890 | { |
| 1891 | /* |
| 1892 | * If a dead key was pressed and the user presses VK_SPACE, |
| 1893 | * VK_BACK, or VK_ESCAPE it means that he actually wants to deal |
| 1894 | * with the dead char now, so do nothing special and let Windows |
| 1895 | * handle it. |
| 1896 | * |
| 1897 | * Note that VK_SPACE combines with the dead_key's character and |
| 1898 | * only one WM_CHAR will be generated by TranslateMessage(), in |
| 1899 | * the two other cases two WM_CHAR will be generated: the dead |
| 1900 | * char and VK_BACK or VK_ESCAPE. That is most likely what the |
| 1901 | * user expects. |
| 1902 | */ |
| 1903 | if ((vk == VK_SPACE || vk == VK_BACK || vk == VK_ESCAPE)) |
| 1904 | { |
| 1905 | dead_key = 0; |
| 1906 | MyTranslateMessage(&msg); |
| 1907 | return; |
| 1908 | } |
| 1909 | /* In modes where we are not typing, dead keys should behave |
| 1910 | * normally */ |
| 1911 | else if (!(get_real_state() & (INSERT | CMDLINE | SELECTMODE))) |
| 1912 | { |
| 1913 | outputDeadKey_rePost(msg); |
| 1914 | return; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | /* Check for CTRL-BREAK */ |
| 1919 | if (vk == VK_CANCEL) |
| 1920 | { |
| 1921 | trash_input_buf(); |
| 1922 | got_int = TRUE; |
Bram Moolenaar | 9698ad7 | 2017-08-12 14:52:15 +0200 | [diff] [blame] | 1923 | ctrl_break_was_pressed = TRUE; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1924 | string[0] = Ctrl_C; |
| 1925 | add_to_input_buf(string, 1); |
| 1926 | } |
| 1927 | |
| 1928 | for (i = 0; special_keys[i].key_sym != 0; i++) |
| 1929 | { |
| 1930 | /* ignore VK_SPACE when ALT key pressed: system menu */ |
| 1931 | if (special_keys[i].key_sym == vk |
| 1932 | && (vk != VK_SPACE || !(GetKeyState(VK_MENU) & 0x8000))) |
| 1933 | { |
| 1934 | /* |
Bram Moolenaar | 945ec09 | 2016-06-08 21:17:43 +0200 | [diff] [blame] | 1935 | * Behave as expected if we have a dead key and the special key |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1936 | * is a key that would normally trigger the dead key nominal |
| 1937 | * character output (such as a NUMPAD printable character or |
| 1938 | * the TAB key, etc...). |
| 1939 | */ |
| 1940 | if (dead_key && (special_keys[i].vim_code0 == 'K' |
| 1941 | || vk == VK_TAB || vk == CAR)) |
| 1942 | { |
| 1943 | outputDeadKey_rePost(msg); |
| 1944 | return; |
| 1945 | } |
| 1946 | |
| 1947 | #ifdef FEAT_MENU |
| 1948 | /* Check for <F10>: Windows selects the menu. When <F10> is |
| 1949 | * mapped we want to use the mapping instead. */ |
| 1950 | if (vk == VK_F10 |
| 1951 | && gui.menu_is_active |
| 1952 | && check_map(k10, State, FALSE, TRUE, FALSE, |
| 1953 | NULL, NULL) == NULL) |
| 1954 | break; |
| 1955 | #endif |
| 1956 | if (GetKeyState(VK_SHIFT) & 0x8000) |
| 1957 | modifiers |= MOD_MASK_SHIFT; |
| 1958 | /* |
| 1959 | * Don't use caps-lock as shift, because these are special keys |
| 1960 | * being considered here, and we only want letters to get |
| 1961 | * shifted -- webb |
| 1962 | */ |
| 1963 | /* |
| 1964 | if (GetKeyState(VK_CAPITAL) & 0x0001) |
| 1965 | modifiers ^= MOD_MASK_SHIFT; |
| 1966 | */ |
| 1967 | if (GetKeyState(VK_CONTROL) & 0x8000) |
| 1968 | modifiers |= MOD_MASK_CTRL; |
| 1969 | if (GetKeyState(VK_MENU) & 0x8000) |
| 1970 | modifiers |= MOD_MASK_ALT; |
| 1971 | |
| 1972 | if (special_keys[i].vim_code1 == NUL) |
| 1973 | key = special_keys[i].vim_code0; |
| 1974 | else |
| 1975 | key = TO_SPECIAL(special_keys[i].vim_code0, |
| 1976 | special_keys[i].vim_code1); |
| 1977 | key = simplify_key(key, &modifiers); |
| 1978 | if (key == CSI) |
| 1979 | key = K_CSI; |
| 1980 | |
| 1981 | if (modifiers) |
| 1982 | { |
| 1983 | string[0] = CSI; |
| 1984 | string[1] = KS_MODIFIER; |
| 1985 | string[2] = modifiers; |
| 1986 | add_to_input_buf(string, 3); |
| 1987 | } |
| 1988 | |
| 1989 | if (IS_SPECIAL(key)) |
| 1990 | { |
| 1991 | string[0] = CSI; |
| 1992 | string[1] = K_SECOND(key); |
| 1993 | string[2] = K_THIRD(key); |
| 1994 | add_to_input_buf(string, 3); |
| 1995 | } |
| 1996 | else |
| 1997 | { |
| 1998 | int len; |
| 1999 | |
| 2000 | /* Handle "key" as a Unicode character. */ |
| 2001 | len = char_to_string(key, string, 40, FALSE); |
| 2002 | add_to_input_buf(string, len); |
| 2003 | } |
| 2004 | break; |
| 2005 | } |
| 2006 | } |
| 2007 | if (special_keys[i].key_sym == 0) |
| 2008 | { |
| 2009 | /* Some keys need C-S- where they should only need C-. |
| 2010 | * Ignore 0xff, Windows XP sends it when NUMLOCK has changed since |
| 2011 | * system startup (Helmut Stiegler, 2003 Oct 3). */ |
| 2012 | if (vk != 0xff |
| 2013 | && (GetKeyState(VK_CONTROL) & 0x8000) |
| 2014 | && !(GetKeyState(VK_SHIFT) & 0x8000) |
| 2015 | && !(GetKeyState(VK_MENU) & 0x8000)) |
| 2016 | { |
| 2017 | /* CTRL-6 is '^'; Japanese keyboard maps '^' to vk == 0xDE */ |
| 2018 | if (vk == '6' || MapVirtualKey(vk, 2) == (UINT)'^') |
| 2019 | { |
| 2020 | string[0] = Ctrl_HAT; |
| 2021 | add_to_input_buf(string, 1); |
| 2022 | } |
| 2023 | /* vk == 0xBD AZERTY for CTRL-'-', but CTRL-[ for * QWERTY! */ |
| 2024 | else if (vk == 0xBD) /* QWERTY for CTRL-'-' */ |
| 2025 | { |
| 2026 | string[0] = Ctrl__; |
| 2027 | add_to_input_buf(string, 1); |
| 2028 | } |
| 2029 | /* CTRL-2 is '@'; Japanese keyboard maps '@' to vk == 0xC0 */ |
| 2030 | else if (vk == '2' || MapVirtualKey(vk, 2) == (UINT)'@') |
| 2031 | { |
| 2032 | string[0] = Ctrl_AT; |
| 2033 | add_to_input_buf(string, 1); |
| 2034 | } |
| 2035 | else |
| 2036 | MyTranslateMessage(&msg); |
| 2037 | } |
| 2038 | else |
| 2039 | MyTranslateMessage(&msg); |
| 2040 | } |
| 2041 | } |
| 2042 | #ifdef FEAT_MBYTE_IME |
| 2043 | else if (msg.message == WM_IME_NOTIFY) |
| 2044 | _OnImeNotify(msg.hwnd, (DWORD)msg.wParam, (DWORD)msg.lParam); |
| 2045 | else if (msg.message == WM_KEYUP && im_get_status()) |
| 2046 | /* added for non-MS IME (Yasuhiro Matsumoto) */ |
| 2047 | MyTranslateMessage(&msg); |
| 2048 | #endif |
| 2049 | #if !defined(FEAT_MBYTE_IME) && defined(GLOBAL_IME) |
| 2050 | /* GIME_TEST */ |
| 2051 | else if (msg.message == WM_IME_STARTCOMPOSITION) |
| 2052 | { |
| 2053 | POINT point; |
| 2054 | |
| 2055 | global_ime_set_font(&norm_logfont); |
| 2056 | point.x = FILL_X(gui.col); |
| 2057 | point.y = FILL_Y(gui.row); |
| 2058 | MapWindowPoints(s_textArea, s_hwnd, &point, 1); |
| 2059 | global_ime_set_position(&point); |
| 2060 | } |
| 2061 | #endif |
| 2062 | |
| 2063 | #ifdef FEAT_MENU |
| 2064 | /* Check for <F10>: Default effect is to select the menu. When <F10> is |
| 2065 | * mapped we need to stop it here to avoid strange effects (e.g., for the |
| 2066 | * key-up event) */ |
| 2067 | if (vk != VK_F10 || check_map(k10, State, FALSE, TRUE, FALSE, |
| 2068 | NULL, NULL) == NULL) |
| 2069 | #endif |
| 2070 | pDispatchMessage(&msg); |
| 2071 | } |
| 2072 | |
| 2073 | /* |
| 2074 | * Catch up with any queued events. This may put keyboard input into the |
| 2075 | * input buffer, call resize call-backs, trigger timers etc. If there is |
| 2076 | * nothing in the event queue (& no timers pending), then we return |
| 2077 | * immediately. |
| 2078 | */ |
| 2079 | void |
| 2080 | gui_mch_update(void) |
| 2081 | { |
| 2082 | MSG msg; |
| 2083 | |
| 2084 | if (!s_busy_processing) |
| 2085 | while (pPeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) |
| 2086 | && !vim_is_input_buf_full()) |
| 2087 | process_message(); |
| 2088 | } |
| 2089 | |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2090 | static void |
| 2091 | remove_any_timer(void) |
| 2092 | { |
| 2093 | MSG msg; |
| 2094 | |
| 2095 | if (s_wait_timer != 0 && !s_timed_out) |
| 2096 | { |
| 2097 | KillTimer(NULL, s_wait_timer); |
| 2098 | |
| 2099 | /* Eat spurious WM_TIMER messages */ |
| 2100 | while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 2101 | ; |
| 2102 | s_wait_timer = 0; |
| 2103 | } |
| 2104 | } |
| 2105 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2106 | /* |
| 2107 | * GUI input routine called by gui_wait_for_chars(). Waits for a character |
| 2108 | * from the keyboard. |
| 2109 | * wtime == -1 Wait forever. |
| 2110 | * wtime == 0 This should never happen. |
| 2111 | * wtime > 0 Wait wtime milliseconds for a character. |
| 2112 | * Returns OK if a character was found to be available within the given time, |
| 2113 | * or FAIL otherwise. |
| 2114 | */ |
| 2115 | int |
| 2116 | gui_mch_wait_for_chars(int wtime) |
| 2117 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2118 | int focus; |
| 2119 | |
| 2120 | s_timed_out = FALSE; |
| 2121 | |
| 2122 | if (wtime > 0) |
| 2123 | { |
| 2124 | /* Don't do anything while processing a (scroll) message. */ |
| 2125 | if (s_busy_processing) |
| 2126 | return FAIL; |
| 2127 | s_wait_timer = (UINT)SetTimer(NULL, 0, (UINT)wtime, |
| 2128 | (TIMERPROC)_OnTimer); |
| 2129 | } |
| 2130 | |
| 2131 | allow_scrollbar = TRUE; |
| 2132 | |
| 2133 | focus = gui.in_focus; |
| 2134 | while (!s_timed_out) |
| 2135 | { |
| 2136 | /* Stop or start blinking when focus changes */ |
| 2137 | if (gui.in_focus != focus) |
| 2138 | { |
| 2139 | if (gui.in_focus) |
| 2140 | gui_mch_start_blink(); |
| 2141 | else |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 2142 | gui_mch_stop_blink(TRUE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2143 | focus = gui.in_focus; |
| 2144 | } |
| 2145 | |
| 2146 | if (s_need_activate) |
| 2147 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2148 | (void)SetForegroundWindow(s_hwnd); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2149 | s_need_activate = FALSE; |
| 2150 | } |
| 2151 | |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2152 | #ifdef FEAT_TIMERS |
| 2153 | did_add_timer = FALSE; |
| 2154 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2155 | #ifdef MESSAGE_QUEUE |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2156 | /* Check channel I/O while waiting for a message. */ |
Bram Moolenaar | 9186a27 | 2016-02-23 19:34:01 +0100 | [diff] [blame] | 2157 | for (;;) |
| 2158 | { |
| 2159 | MSG msg; |
| 2160 | |
| 2161 | parse_queued_messages(); |
| 2162 | |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2163 | if (pPeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) |
| 2164 | { |
| 2165 | process_message(); |
| 2166 | break; |
| 2167 | } |
| 2168 | else if (MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT) |
| 2169 | != WAIT_TIMEOUT) |
Bram Moolenaar | 9186a27 | 2016-02-23 19:34:01 +0100 | [diff] [blame] | 2170 | break; |
| 2171 | } |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2172 | #else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2173 | /* |
| 2174 | * Don't use gui_mch_update() because then we will spin-lock until a |
| 2175 | * char arrives, instead we use GetMessage() to hang until an |
| 2176 | * event arrives. No need to check for input_buf_full because we are |
| 2177 | * returning as soon as it contains a single char -- webb |
| 2178 | */ |
| 2179 | process_message(); |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2180 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2181 | |
| 2182 | if (input_available()) |
| 2183 | { |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2184 | remove_any_timer(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2185 | allow_scrollbar = FALSE; |
| 2186 | |
| 2187 | /* Clear pending mouse button, the release event may have been |
| 2188 | * taken by the dialog window. But don't do this when getting |
| 2189 | * focus, we need the mouse-up event then. */ |
| 2190 | if (!s_getting_focus) |
| 2191 | s_button_pending = -1; |
| 2192 | |
| 2193 | return OK; |
| 2194 | } |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2195 | |
| 2196 | #ifdef FEAT_TIMERS |
| 2197 | if (did_add_timer) |
| 2198 | { |
| 2199 | /* Need to recompute the waiting time. */ |
| 2200 | remove_any_timer(); |
| 2201 | break; |
| 2202 | } |
| 2203 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2204 | } |
| 2205 | allow_scrollbar = FALSE; |
| 2206 | return FAIL; |
| 2207 | } |
| 2208 | |
| 2209 | /* |
| 2210 | * Clear a rectangular region of the screen from text pos (row1, col1) to |
| 2211 | * (row2, col2) inclusive. |
| 2212 | */ |
| 2213 | void |
| 2214 | gui_mch_clear_block( |
| 2215 | int row1, |
| 2216 | int col1, |
| 2217 | int row2, |
| 2218 | int col2) |
| 2219 | { |
| 2220 | RECT rc; |
| 2221 | |
| 2222 | /* |
| 2223 | * Clear one extra pixel at the far right, for when bold characters have |
| 2224 | * spilled over to the window border. |
| 2225 | * Note: FillRect() excludes right and bottom of rectangle. |
| 2226 | */ |
| 2227 | rc.left = FILL_X(col1); |
| 2228 | rc.top = FILL_Y(row1); |
| 2229 | rc.right = FILL_X(col2 + 1) + (col2 == Columns - 1); |
| 2230 | rc.bottom = FILL_Y(row2 + 1); |
| 2231 | clear_rect(&rc); |
| 2232 | } |
| 2233 | |
| 2234 | /* |
| 2235 | * Clear the whole text window. |
| 2236 | */ |
| 2237 | void |
| 2238 | gui_mch_clear_all(void) |
| 2239 | { |
| 2240 | RECT rc; |
| 2241 | |
| 2242 | rc.left = 0; |
| 2243 | rc.top = 0; |
| 2244 | rc.right = Columns * gui.char_width + 2 * gui.border_width; |
| 2245 | rc.bottom = Rows * gui.char_height + 2 * gui.border_width; |
| 2246 | clear_rect(&rc); |
| 2247 | } |
| 2248 | /* |
| 2249 | * Menu stuff. |
| 2250 | */ |
| 2251 | |
| 2252 | void |
| 2253 | gui_mch_enable_menu(int flag) |
| 2254 | { |
| 2255 | #ifdef FEAT_MENU |
| 2256 | SetMenu(s_hwnd, flag ? s_menuBar : NULL); |
| 2257 | #endif |
| 2258 | } |
| 2259 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2260 | void |
| 2261 | gui_mch_set_menu_pos( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2262 | int x UNUSED, |
| 2263 | int y UNUSED, |
| 2264 | int w UNUSED, |
| 2265 | int h UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2266 | { |
| 2267 | /* It will be in the right place anyway */ |
| 2268 | } |
| 2269 | |
| 2270 | #if defined(FEAT_MENU) || defined(PROTO) |
| 2271 | /* |
| 2272 | * Make menu item hidden or not hidden |
| 2273 | */ |
| 2274 | void |
| 2275 | gui_mch_menu_hidden( |
| 2276 | vimmenu_T *menu, |
| 2277 | int hidden) |
| 2278 | { |
| 2279 | /* |
| 2280 | * This doesn't do what we want. Hmm, just grey the menu items for now. |
| 2281 | */ |
| 2282 | /* |
| 2283 | if (hidden) |
| 2284 | EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_DISABLED); |
| 2285 | else |
| 2286 | EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_ENABLED); |
| 2287 | */ |
| 2288 | gui_mch_menu_grey(menu, hidden); |
| 2289 | } |
| 2290 | |
| 2291 | /* |
| 2292 | * This is called after setting all the menus to grey/hidden or not. |
| 2293 | */ |
| 2294 | void |
| 2295 | gui_mch_draw_menubar(void) |
| 2296 | { |
| 2297 | DrawMenuBar(s_hwnd); |
| 2298 | } |
| 2299 | #endif /*FEAT_MENU*/ |
| 2300 | |
| 2301 | #ifndef PROTO |
| 2302 | void |
| 2303 | #ifdef VIMDLL |
| 2304 | _export |
| 2305 | #endif |
| 2306 | _cdecl |
| 2307 | SaveInst(HINSTANCE hInst) |
| 2308 | { |
| 2309 | s_hinst = hInst; |
| 2310 | } |
| 2311 | #endif |
| 2312 | |
| 2313 | /* |
| 2314 | * Return the RGB value of a pixel as a long. |
| 2315 | */ |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 2316 | guicolor_T |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2317 | gui_mch_get_rgb(guicolor_T pixel) |
| 2318 | { |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 2319 | return (guicolor_T)((GetRValue(pixel) << 16) + (GetGValue(pixel) << 8) |
| 2320 | + GetBValue(pixel)); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
| 2324 | /* Convert pixels in X to dialog units */ |
| 2325 | static WORD |
| 2326 | PixelToDialogX(int numPixels) |
| 2327 | { |
| 2328 | return (WORD)((numPixels * 4) / s_dlgfntwidth); |
| 2329 | } |
| 2330 | |
| 2331 | /* Convert pixels in Y to dialog units */ |
| 2332 | static WORD |
| 2333 | PixelToDialogY(int numPixels) |
| 2334 | { |
| 2335 | return (WORD)((numPixels * 8) / s_dlgfntheight); |
| 2336 | } |
| 2337 | |
| 2338 | /* Return the width in pixels of the given text in the given DC. */ |
| 2339 | static int |
| 2340 | GetTextWidth(HDC hdc, char_u *str, int len) |
| 2341 | { |
| 2342 | SIZE size; |
| 2343 | |
| 2344 | GetTextExtentPoint(hdc, (LPCSTR)str, len, &size); |
| 2345 | return size.cx; |
| 2346 | } |
| 2347 | |
| 2348 | #ifdef FEAT_MBYTE |
| 2349 | /* |
| 2350 | * Return the width in pixels of the given text in the given DC, taking care |
| 2351 | * of 'encoding' to active codepage conversion. |
| 2352 | */ |
| 2353 | static int |
| 2354 | GetTextWidthEnc(HDC hdc, char_u *str, int len) |
| 2355 | { |
| 2356 | SIZE size; |
| 2357 | WCHAR *wstr; |
| 2358 | int n; |
| 2359 | int wlen = len; |
| 2360 | |
| 2361 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 2362 | { |
| 2363 | /* 'encoding' differs from active codepage: convert text and use wide |
| 2364 | * function */ |
| 2365 | wstr = enc_to_utf16(str, &wlen); |
| 2366 | if (wstr != NULL) |
| 2367 | { |
| 2368 | n = GetTextExtentPointW(hdc, wstr, wlen, &size); |
| 2369 | vim_free(wstr); |
| 2370 | if (n) |
| 2371 | return size.cx; |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | return GetTextWidth(hdc, str, len); |
| 2376 | } |
| 2377 | #else |
| 2378 | # define GetTextWidthEnc(h, s, l) GetTextWidth((h), (s), (l)) |
| 2379 | #endif |
| 2380 | |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2381 | static void get_work_area(RECT *spi_rect); |
| 2382 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2383 | /* |
| 2384 | * A quick little routine that will center one window over another, handy for |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2385 | * dialog boxes. Taken from the Win32SDK samples and modified for multiple |
| 2386 | * monitors. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2387 | */ |
| 2388 | static BOOL |
| 2389 | CenterWindow( |
| 2390 | HWND hwndChild, |
| 2391 | HWND hwndParent) |
| 2392 | { |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2393 | HMONITOR mon; |
| 2394 | MONITORINFO moninfo; |
| 2395 | RECT rChild, rParent, rScreen; |
| 2396 | int wChild, hChild, wParent, hParent; |
| 2397 | int xNew, yNew; |
| 2398 | HDC hdc; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2399 | |
| 2400 | GetWindowRect(hwndChild, &rChild); |
| 2401 | wChild = rChild.right - rChild.left; |
| 2402 | hChild = rChild.bottom - rChild.top; |
| 2403 | |
| 2404 | /* If Vim is minimized put the window in the middle of the screen. */ |
| 2405 | if (hwndParent == NULL || IsMinimized(hwndParent)) |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2406 | get_work_area(&rParent); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2407 | else |
| 2408 | GetWindowRect(hwndParent, &rParent); |
| 2409 | wParent = rParent.right - rParent.left; |
| 2410 | hParent = rParent.bottom - rParent.top; |
| 2411 | |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2412 | moninfo.cbSize = sizeof(MONITORINFO); |
| 2413 | mon = MonitorFromWindow(hwndChild, MONITOR_DEFAULTTOPRIMARY); |
| 2414 | if (mon != NULL && GetMonitorInfo(mon, &moninfo)) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2415 | { |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2416 | rScreen = moninfo.rcWork; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2417 | } |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2418 | else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2419 | { |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2420 | hdc = GetDC(hwndChild); |
| 2421 | rScreen.left = 0; |
| 2422 | rScreen.top = 0; |
| 2423 | rScreen.right = GetDeviceCaps(hdc, HORZRES); |
| 2424 | rScreen.bottom = GetDeviceCaps(hdc, VERTRES); |
| 2425 | ReleaseDC(hwndChild, hdc); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2426 | } |
| 2427 | |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2428 | xNew = rParent.left + ((wParent - wChild) / 2); |
| 2429 | if (xNew < rScreen.left) |
| 2430 | xNew = rScreen.left; |
| 2431 | else if ((xNew + wChild) > rScreen.right) |
| 2432 | xNew = rScreen.right - wChild; |
| 2433 | |
| 2434 | yNew = rParent.top + ((hParent - hChild) / 2); |
| 2435 | if (yNew < rScreen.top) |
| 2436 | yNew = rScreen.top; |
| 2437 | else if ((yNew + hChild) > rScreen.bottom) |
| 2438 | yNew = rScreen.bottom - hChild; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2439 | |
| 2440 | return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0, |
| 2441 | SWP_NOSIZE | SWP_NOZORDER); |
| 2442 | } |
| 2443 | #endif /* FEAT_GUI_DIALOG */ |
| 2444 | |
| 2445 | void |
| 2446 | gui_mch_activate_window(void) |
| 2447 | { |
| 2448 | (void)SetActiveWindow(s_hwnd); |
| 2449 | } |
| 2450 | |
| 2451 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 2452 | void |
| 2453 | gui_mch_show_toolbar(int showit) |
| 2454 | { |
| 2455 | if (s_toolbarhwnd == NULL) |
| 2456 | return; |
| 2457 | |
| 2458 | if (showit) |
| 2459 | { |
| 2460 | # ifdef FEAT_MBYTE |
| 2461 | # ifndef TB_SETUNICODEFORMAT |
| 2462 | /* For older compilers. We assume this never changes. */ |
| 2463 | # define TB_SETUNICODEFORMAT 0x2005 |
| 2464 | # endif |
| 2465 | /* Enable/disable unicode support */ |
| 2466 | int uu = (enc_codepage >= 0 && (int)GetACP() != enc_codepage); |
| 2467 | SendMessage(s_toolbarhwnd, TB_SETUNICODEFORMAT, (WPARAM)uu, (LPARAM)0); |
| 2468 | # endif |
| 2469 | ShowWindow(s_toolbarhwnd, SW_SHOW); |
| 2470 | } |
| 2471 | else |
| 2472 | ShowWindow(s_toolbarhwnd, SW_HIDE); |
| 2473 | } |
| 2474 | |
| 2475 | /* Then number of bitmaps is fixed. Exit is missing! */ |
| 2476 | #define TOOLBAR_BITMAP_COUNT 31 |
| 2477 | |
| 2478 | #endif |
| 2479 | |
| 2480 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
| 2481 | static void |
| 2482 | add_tabline_popup_menu_entry(HMENU pmenu, UINT item_id, char_u *item_text) |
| 2483 | { |
| 2484 | #ifdef FEAT_MBYTE |
| 2485 | WCHAR *wn = NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2486 | |
| 2487 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 2488 | { |
| 2489 | /* 'encoding' differs from active codepage: convert menu name |
| 2490 | * and use wide function */ |
| 2491 | wn = enc_to_utf16(item_text, NULL); |
| 2492 | if (wn != NULL) |
| 2493 | { |
| 2494 | MENUITEMINFOW infow; |
| 2495 | |
| 2496 | infow.cbSize = sizeof(infow); |
| 2497 | infow.fMask = MIIM_TYPE | MIIM_ID; |
| 2498 | infow.wID = item_id; |
| 2499 | infow.fType = MFT_STRING; |
| 2500 | infow.dwTypeData = wn; |
| 2501 | infow.cch = (UINT)wcslen(wn); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2502 | InsertMenuItemW(pmenu, item_id, FALSE, &infow); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2503 | vim_free(wn); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | if (wn == NULL) |
| 2508 | #endif |
| 2509 | { |
| 2510 | MENUITEMINFO info; |
| 2511 | |
| 2512 | info.cbSize = sizeof(info); |
| 2513 | info.fMask = MIIM_TYPE | MIIM_ID; |
| 2514 | info.wID = item_id; |
| 2515 | info.fType = MFT_STRING; |
| 2516 | info.dwTypeData = (LPTSTR)item_text; |
| 2517 | info.cch = (UINT)STRLEN(item_text); |
| 2518 | InsertMenuItem(pmenu, item_id, FALSE, &info); |
| 2519 | } |
| 2520 | } |
| 2521 | |
| 2522 | static void |
| 2523 | show_tabline_popup_menu(void) |
| 2524 | { |
| 2525 | HMENU tab_pmenu; |
| 2526 | long rval; |
| 2527 | POINT pt; |
| 2528 | |
| 2529 | /* When ignoring events don't show the menu. */ |
| 2530 | if (hold_gui_events |
| 2531 | # ifdef FEAT_CMDWIN |
| 2532 | || cmdwin_type != 0 |
| 2533 | # endif |
| 2534 | ) |
| 2535 | return; |
| 2536 | |
| 2537 | tab_pmenu = CreatePopupMenu(); |
| 2538 | if (tab_pmenu == NULL) |
| 2539 | return; |
| 2540 | |
| 2541 | if (first_tabpage->tp_next != NULL) |
| 2542 | add_tabline_popup_menu_entry(tab_pmenu, |
| 2543 | TABLINE_MENU_CLOSE, (char_u *)_("Close tab")); |
| 2544 | add_tabline_popup_menu_entry(tab_pmenu, |
| 2545 | TABLINE_MENU_NEW, (char_u *)_("New tab")); |
| 2546 | add_tabline_popup_menu_entry(tab_pmenu, |
| 2547 | TABLINE_MENU_OPEN, (char_u *)_("Open tab...")); |
| 2548 | |
| 2549 | GetCursorPos(&pt); |
| 2550 | rval = TrackPopupMenuEx(tab_pmenu, TPM_RETURNCMD, pt.x, pt.y, s_tabhwnd, |
| 2551 | NULL); |
| 2552 | |
| 2553 | DestroyMenu(tab_pmenu); |
| 2554 | |
| 2555 | /* Add the string cmd into input buffer */ |
| 2556 | if (rval > 0) |
| 2557 | { |
| 2558 | TCHITTESTINFO htinfo; |
| 2559 | int idx; |
| 2560 | |
| 2561 | if (ScreenToClient(s_tabhwnd, &pt) == 0) |
| 2562 | return; |
| 2563 | |
| 2564 | htinfo.pt.x = pt.x; |
| 2565 | htinfo.pt.y = pt.y; |
| 2566 | idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 2567 | if (idx == -1) |
| 2568 | idx = 0; |
| 2569 | else |
| 2570 | idx += 1; |
| 2571 | |
| 2572 | send_tabline_menu_event(idx, (int)rval); |
| 2573 | } |
| 2574 | } |
| 2575 | |
| 2576 | /* |
| 2577 | * Show or hide the tabline. |
| 2578 | */ |
| 2579 | void |
| 2580 | gui_mch_show_tabline(int showit) |
| 2581 | { |
| 2582 | if (s_tabhwnd == NULL) |
| 2583 | return; |
| 2584 | |
| 2585 | if (!showit != !showing_tabline) |
| 2586 | { |
| 2587 | if (showit) |
| 2588 | ShowWindow(s_tabhwnd, SW_SHOW); |
| 2589 | else |
| 2590 | ShowWindow(s_tabhwnd, SW_HIDE); |
| 2591 | showing_tabline = showit; |
| 2592 | } |
| 2593 | } |
| 2594 | |
| 2595 | /* |
| 2596 | * Return TRUE when tabline is displayed. |
| 2597 | */ |
| 2598 | int |
| 2599 | gui_mch_showing_tabline(void) |
| 2600 | { |
| 2601 | return s_tabhwnd != NULL && showing_tabline; |
| 2602 | } |
| 2603 | |
| 2604 | /* |
| 2605 | * Update the labels of the tabline. |
| 2606 | */ |
| 2607 | void |
| 2608 | gui_mch_update_tabline(void) |
| 2609 | { |
| 2610 | tabpage_T *tp; |
| 2611 | TCITEM tie; |
| 2612 | int nr = 0; |
| 2613 | int curtabidx = 0; |
| 2614 | int tabadded = 0; |
| 2615 | #ifdef FEAT_MBYTE |
| 2616 | static int use_unicode = FALSE; |
| 2617 | int uu; |
| 2618 | WCHAR *wstr = NULL; |
| 2619 | #endif |
| 2620 | |
| 2621 | if (s_tabhwnd == NULL) |
| 2622 | return; |
| 2623 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2624 | #ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2625 | # ifndef CCM_SETUNICODEFORMAT |
| 2626 | /* For older compilers. We assume this never changes. */ |
| 2627 | # define CCM_SETUNICODEFORMAT 0x2005 |
| 2628 | # endif |
| 2629 | uu = (enc_codepage >= 0 && (int)GetACP() != enc_codepage); |
| 2630 | if (uu != use_unicode) |
| 2631 | { |
| 2632 | /* Enable/disable unicode support */ |
| 2633 | SendMessage(s_tabhwnd, CCM_SETUNICODEFORMAT, (WPARAM)uu, (LPARAM)0); |
| 2634 | use_unicode = uu; |
| 2635 | } |
| 2636 | #endif |
| 2637 | |
| 2638 | tie.mask = TCIF_TEXT; |
| 2639 | tie.iImage = -1; |
| 2640 | |
| 2641 | /* Disable redraw for tab updates to eliminate O(N^2) draws. */ |
| 2642 | SendMessage(s_tabhwnd, WM_SETREDRAW, (WPARAM)FALSE, 0); |
| 2643 | |
| 2644 | /* Add a label for each tab page. They all contain the same text area. */ |
| 2645 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) |
| 2646 | { |
| 2647 | if (tp == curtab) |
| 2648 | curtabidx = nr; |
| 2649 | |
| 2650 | if (nr >= TabCtrl_GetItemCount(s_tabhwnd)) |
| 2651 | { |
| 2652 | /* Add the tab */ |
| 2653 | tie.pszText = "-Empty-"; |
| 2654 | TabCtrl_InsertItem(s_tabhwnd, nr, &tie); |
| 2655 | tabadded = 1; |
| 2656 | } |
| 2657 | |
| 2658 | get_tabline_label(tp, FALSE); |
| 2659 | tie.pszText = (LPSTR)NameBuff; |
| 2660 | #ifdef FEAT_MBYTE |
| 2661 | wstr = NULL; |
| 2662 | if (use_unicode) |
| 2663 | { |
| 2664 | /* Need to go through Unicode. */ |
| 2665 | wstr = enc_to_utf16(NameBuff, NULL); |
| 2666 | if (wstr != NULL) |
| 2667 | { |
| 2668 | TCITEMW tiw; |
| 2669 | |
| 2670 | tiw.mask = TCIF_TEXT; |
| 2671 | tiw.iImage = -1; |
| 2672 | tiw.pszText = wstr; |
| 2673 | SendMessage(s_tabhwnd, TCM_SETITEMW, (WPARAM)nr, (LPARAM)&tiw); |
| 2674 | vim_free(wstr); |
| 2675 | } |
| 2676 | } |
| 2677 | if (wstr == NULL) |
| 2678 | #endif |
| 2679 | { |
| 2680 | TabCtrl_SetItem(s_tabhwnd, nr, &tie); |
| 2681 | } |
| 2682 | } |
| 2683 | |
| 2684 | /* Remove any old labels. */ |
| 2685 | while (nr < TabCtrl_GetItemCount(s_tabhwnd)) |
| 2686 | TabCtrl_DeleteItem(s_tabhwnd, nr); |
| 2687 | |
| 2688 | if (!tabadded && TabCtrl_GetCurSel(s_tabhwnd) != curtabidx) |
| 2689 | TabCtrl_SetCurSel(s_tabhwnd, curtabidx); |
| 2690 | |
| 2691 | /* Re-enable redraw and redraw. */ |
| 2692 | SendMessage(s_tabhwnd, WM_SETREDRAW, (WPARAM)TRUE, 0); |
| 2693 | RedrawWindow(s_tabhwnd, NULL, NULL, |
| 2694 | RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); |
| 2695 | |
| 2696 | if (tabadded && TabCtrl_GetCurSel(s_tabhwnd) != curtabidx) |
| 2697 | TabCtrl_SetCurSel(s_tabhwnd, curtabidx); |
| 2698 | } |
| 2699 | |
| 2700 | /* |
| 2701 | * Set the current tab to "nr". First tab is 1. |
| 2702 | */ |
| 2703 | void |
| 2704 | gui_mch_set_curtab(int nr) |
| 2705 | { |
| 2706 | if (s_tabhwnd == NULL) |
| 2707 | return; |
| 2708 | |
| 2709 | if (TabCtrl_GetCurSel(s_tabhwnd) != nr - 1) |
| 2710 | TabCtrl_SetCurSel(s_tabhwnd, nr - 1); |
| 2711 | } |
| 2712 | |
| 2713 | #endif |
| 2714 | |
| 2715 | /* |
| 2716 | * ":simalt" command. |
| 2717 | */ |
| 2718 | void |
| 2719 | ex_simalt(exarg_T *eap) |
| 2720 | { |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2721 | char_u *keys = eap->arg; |
| 2722 | int fill_typebuf = FALSE; |
| 2723 | char_u key_name[4]; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2724 | |
| 2725 | PostMessage(s_hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)0); |
| 2726 | while (*keys) |
| 2727 | { |
| 2728 | if (*keys == '~') |
| 2729 | *keys = ' '; /* for showing system menu */ |
| 2730 | PostMessage(s_hwnd, WM_CHAR, (WPARAM)*keys, (LPARAM)0); |
| 2731 | keys++; |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2732 | fill_typebuf = TRUE; |
| 2733 | } |
| 2734 | if (fill_typebuf) |
| 2735 | { |
Bram Moolenaar | a21ccb7 | 2017-04-29 17:40:22 +0200 | [diff] [blame] | 2736 | /* Put a NOP in the typeahead buffer so that the message will get |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2737 | * processed. */ |
| 2738 | key_name[0] = K_SPECIAL; |
| 2739 | key_name[1] = KS_EXTRA; |
Bram Moolenaar | a21ccb7 | 2017-04-29 17:40:22 +0200 | [diff] [blame] | 2740 | key_name[2] = KE_NOP; |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2741 | key_name[3] = NUL; |
| 2742 | typebuf_was_filled = TRUE; |
| 2743 | (void)ins_typebuf(key_name, REMAP_NONE, 0, TRUE, FALSE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | /* |
| 2748 | * Create the find & replace dialogs. |
| 2749 | * You can't have both at once: ":find" when replace is showing, destroys |
| 2750 | * the replace dialog first, and the other way around. |
| 2751 | */ |
| 2752 | #ifdef MSWIN_FIND_REPLACE |
| 2753 | static void |
| 2754 | initialise_findrep(char_u *initial_string) |
| 2755 | { |
| 2756 | int wword = FALSE; |
| 2757 | int mcase = !p_ic; |
| 2758 | char_u *entry_text; |
| 2759 | |
| 2760 | /* Get the search string to use. */ |
| 2761 | entry_text = get_find_dialog_text(initial_string, &wword, &mcase); |
| 2762 | |
| 2763 | s_findrep_struct.hwndOwner = s_hwnd; |
| 2764 | s_findrep_struct.Flags = FR_DOWN; |
| 2765 | if (mcase) |
| 2766 | s_findrep_struct.Flags |= FR_MATCHCASE; |
| 2767 | if (wword) |
| 2768 | s_findrep_struct.Flags |= FR_WHOLEWORD; |
| 2769 | if (entry_text != NULL && *entry_text != NUL) |
| 2770 | vim_strncpy((char_u *)s_findrep_struct.lpstrFindWhat, entry_text, |
| 2771 | s_findrep_struct.wFindWhatLen - 1); |
| 2772 | vim_free(entry_text); |
| 2773 | } |
| 2774 | #endif |
| 2775 | |
| 2776 | static void |
| 2777 | set_window_title(HWND hwnd, char *title) |
| 2778 | { |
| 2779 | #ifdef FEAT_MBYTE |
| 2780 | if (title != NULL && enc_codepage >= 0 && enc_codepage != (int)GetACP()) |
| 2781 | { |
| 2782 | WCHAR *wbuf; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2783 | |
| 2784 | /* Convert the title from 'encoding' to UTF-16. */ |
| 2785 | wbuf = (WCHAR *)enc_to_utf16((char_u *)title, NULL); |
| 2786 | if (wbuf != NULL) |
| 2787 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2788 | SetWindowTextW(hwnd, wbuf); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2789 | vim_free(wbuf); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2790 | } |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2791 | return; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2792 | } |
| 2793 | #endif |
| 2794 | (void)SetWindowText(hwnd, (LPCSTR)title); |
| 2795 | } |
| 2796 | |
| 2797 | void |
| 2798 | gui_mch_find_dialog(exarg_T *eap) |
| 2799 | { |
| 2800 | #ifdef MSWIN_FIND_REPLACE |
| 2801 | if (s_findrep_msg != 0) |
| 2802 | { |
| 2803 | if (IsWindow(s_findrep_hwnd) && !s_findrep_is_find) |
| 2804 | DestroyWindow(s_findrep_hwnd); |
| 2805 | |
| 2806 | if (!IsWindow(s_findrep_hwnd)) |
| 2807 | { |
| 2808 | initialise_findrep(eap->arg); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2809 | # ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2810 | /* If the OS is Windows NT, and 'encoding' differs from active |
| 2811 | * codepage: convert text and use wide function. */ |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2812 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2813 | { |
| 2814 | findrep_atow(&s_findrep_struct_w, &s_findrep_struct); |
| 2815 | s_findrep_hwnd = FindTextW( |
| 2816 | (LPFINDREPLACEW) &s_findrep_struct_w); |
| 2817 | } |
| 2818 | else |
| 2819 | # endif |
| 2820 | s_findrep_hwnd = FindText((LPFINDREPLACE) &s_findrep_struct); |
| 2821 | } |
| 2822 | |
Bram Moolenaar | 9e42c86 | 2018-07-20 05:03:16 +0200 | [diff] [blame] | 2823 | set_window_title(s_findrep_hwnd, _("Find string")); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2824 | (void)SetFocus(s_findrep_hwnd); |
| 2825 | |
| 2826 | s_findrep_is_find = TRUE; |
| 2827 | } |
| 2828 | #endif |
| 2829 | } |
| 2830 | |
| 2831 | |
| 2832 | void |
| 2833 | gui_mch_replace_dialog(exarg_T *eap) |
| 2834 | { |
| 2835 | #ifdef MSWIN_FIND_REPLACE |
| 2836 | if (s_findrep_msg != 0) |
| 2837 | { |
| 2838 | if (IsWindow(s_findrep_hwnd) && s_findrep_is_find) |
| 2839 | DestroyWindow(s_findrep_hwnd); |
| 2840 | |
| 2841 | if (!IsWindow(s_findrep_hwnd)) |
| 2842 | { |
| 2843 | initialise_findrep(eap->arg); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2844 | # ifdef FEAT_MBYTE |
| 2845 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2846 | { |
| 2847 | findrep_atow(&s_findrep_struct_w, &s_findrep_struct); |
| 2848 | s_findrep_hwnd = ReplaceTextW( |
| 2849 | (LPFINDREPLACEW) &s_findrep_struct_w); |
| 2850 | } |
| 2851 | else |
| 2852 | # endif |
| 2853 | s_findrep_hwnd = ReplaceText( |
| 2854 | (LPFINDREPLACE) &s_findrep_struct); |
| 2855 | } |
| 2856 | |
Bram Moolenaar | 9e42c86 | 2018-07-20 05:03:16 +0200 | [diff] [blame] | 2857 | set_window_title(s_findrep_hwnd, _("Find & Replace")); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2858 | (void)SetFocus(s_findrep_hwnd); |
| 2859 | |
| 2860 | s_findrep_is_find = FALSE; |
| 2861 | } |
| 2862 | #endif |
| 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | /* |
| 2867 | * Set visibility of the pointer. |
| 2868 | */ |
| 2869 | void |
| 2870 | gui_mch_mousehide(int hide) |
| 2871 | { |
| 2872 | if (hide != gui.pointer_hidden) |
| 2873 | { |
| 2874 | ShowCursor(!hide); |
| 2875 | gui.pointer_hidden = hide; |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | #ifdef FEAT_MENU |
| 2880 | static void |
| 2881 | gui_mch_show_popupmenu_at(vimmenu_T *menu, int x, int y) |
| 2882 | { |
| 2883 | /* Unhide the mouse, we don't get move events here. */ |
| 2884 | gui_mch_mousehide(FALSE); |
| 2885 | |
| 2886 | (void)TrackPopupMenu( |
| 2887 | (HMENU)menu->submenu_id, |
| 2888 | TPM_LEFTALIGN | TPM_LEFTBUTTON, |
| 2889 | x, y, |
| 2890 | (int)0, /*reserved param*/ |
| 2891 | s_hwnd, |
| 2892 | NULL); |
| 2893 | /* |
| 2894 | * NOTE: The pop-up menu can eat the mouse up event. |
| 2895 | * We deal with this in normal.c. |
| 2896 | */ |
| 2897 | } |
| 2898 | #endif |
| 2899 | |
| 2900 | /* |
| 2901 | * Got a message when the system will go down. |
| 2902 | */ |
| 2903 | static void |
| 2904 | _OnEndSession(void) |
| 2905 | { |
| 2906 | getout_preserve_modified(1); |
| 2907 | } |
| 2908 | |
| 2909 | /* |
| 2910 | * Get this message when the user clicks on the cross in the top right corner |
| 2911 | * of a Windows95 window. |
| 2912 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2913 | static void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2914 | _OnClose(HWND hwnd UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2915 | { |
| 2916 | gui_shell_closed(); |
| 2917 | } |
| 2918 | |
| 2919 | /* |
| 2920 | * Get a message when the window is being destroyed. |
| 2921 | */ |
| 2922 | static void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2923 | _OnDestroy(HWND hwnd) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2924 | { |
| 2925 | if (!destroying) |
| 2926 | _OnClose(hwnd); |
| 2927 | } |
| 2928 | |
| 2929 | static void |
| 2930 | _OnPaint( |
| 2931 | HWND hwnd) |
| 2932 | { |
| 2933 | if (!IsMinimized(hwnd)) |
| 2934 | { |
| 2935 | PAINTSTRUCT ps; |
| 2936 | |
| 2937 | out_flush(); /* make sure all output has been processed */ |
| 2938 | (void)BeginPaint(hwnd, &ps); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2939 | |
| 2940 | #ifdef FEAT_MBYTE |
| 2941 | /* prevent multi-byte characters from misprinting on an invalid |
| 2942 | * rectangle */ |
| 2943 | if (has_mbyte) |
| 2944 | { |
| 2945 | RECT rect; |
| 2946 | |
| 2947 | GetClientRect(hwnd, &rect); |
| 2948 | ps.rcPaint.left = rect.left; |
| 2949 | ps.rcPaint.right = rect.right; |
| 2950 | } |
| 2951 | #endif |
| 2952 | |
| 2953 | if (!IsRectEmpty(&ps.rcPaint)) |
| 2954 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2955 | gui_redraw(ps.rcPaint.left, ps.rcPaint.top, |
| 2956 | ps.rcPaint.right - ps.rcPaint.left + 1, |
| 2957 | ps.rcPaint.bottom - ps.rcPaint.top + 1); |
| 2958 | } |
| 2959 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2960 | EndPaint(hwnd, &ps); |
| 2961 | } |
| 2962 | } |
| 2963 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2964 | static void |
| 2965 | _OnSize( |
| 2966 | HWND hwnd, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2967 | UINT state UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2968 | int cx, |
| 2969 | int cy) |
| 2970 | { |
| 2971 | if (!IsMinimized(hwnd)) |
| 2972 | { |
| 2973 | gui_resize_shell(cx, cy); |
| 2974 | |
| 2975 | #ifdef FEAT_MENU |
| 2976 | /* Menu bar may wrap differently now */ |
| 2977 | gui_mswin_get_menu_height(TRUE); |
| 2978 | #endif |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | static void |
| 2983 | _OnSetFocus( |
| 2984 | HWND hwnd, |
| 2985 | HWND hwndOldFocus) |
| 2986 | { |
| 2987 | gui_focus_change(TRUE); |
| 2988 | s_getting_focus = TRUE; |
| 2989 | (void)MyWindowProc(hwnd, WM_SETFOCUS, (WPARAM)hwndOldFocus, 0); |
| 2990 | } |
| 2991 | |
| 2992 | static void |
| 2993 | _OnKillFocus( |
| 2994 | HWND hwnd, |
| 2995 | HWND hwndNewFocus) |
| 2996 | { |
| 2997 | gui_focus_change(FALSE); |
| 2998 | s_getting_focus = FALSE; |
| 2999 | (void)MyWindowProc(hwnd, WM_KILLFOCUS, (WPARAM)hwndNewFocus, 0); |
| 3000 | } |
| 3001 | |
| 3002 | /* |
| 3003 | * Get a message when the user switches back to vim |
| 3004 | */ |
| 3005 | static LRESULT |
| 3006 | _OnActivateApp( |
| 3007 | HWND hwnd, |
| 3008 | BOOL fActivate, |
| 3009 | DWORD dwThreadId) |
| 3010 | { |
| 3011 | /* we call gui_focus_change() in _OnSetFocus() */ |
| 3012 | /* gui_focus_change((int)fActivate); */ |
| 3013 | return MyWindowProc(hwnd, WM_ACTIVATEAPP, fActivate, (DWORD)dwThreadId); |
| 3014 | } |
| 3015 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3016 | void |
| 3017 | gui_mch_destroy_scrollbar(scrollbar_T *sb) |
| 3018 | { |
| 3019 | DestroyWindow(sb->id); |
| 3020 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3021 | |
| 3022 | /* |
| 3023 | * Get current mouse coordinates in text window. |
| 3024 | */ |
| 3025 | void |
| 3026 | gui_mch_getmouse(int *x, int *y) |
| 3027 | { |
| 3028 | RECT rct; |
| 3029 | POINT mp; |
| 3030 | |
| 3031 | (void)GetWindowRect(s_textArea, &rct); |
| 3032 | (void)GetCursorPos((LPPOINT)&mp); |
| 3033 | *x = (int)(mp.x - rct.left); |
| 3034 | *y = (int)(mp.y - rct.top); |
| 3035 | } |
| 3036 | |
| 3037 | /* |
| 3038 | * Move mouse pointer to character at (x, y). |
| 3039 | */ |
| 3040 | void |
| 3041 | gui_mch_setmouse(int x, int y) |
| 3042 | { |
| 3043 | RECT rct; |
| 3044 | |
| 3045 | (void)GetWindowRect(s_textArea, &rct); |
| 3046 | (void)SetCursorPos(x + gui.border_offset + rct.left, |
| 3047 | y + gui.border_offset + rct.top); |
| 3048 | } |
| 3049 | |
| 3050 | static void |
| 3051 | gui_mswin_get_valid_dimensions( |
| 3052 | int w, |
| 3053 | int h, |
| 3054 | int *valid_w, |
| 3055 | int *valid_h) |
| 3056 | { |
| 3057 | int base_width, base_height; |
| 3058 | |
| 3059 | base_width = gui_get_base_width() |
| 3060 | + (GetSystemMetrics(SM_CXFRAME) + |
| 3061 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
| 3062 | base_height = gui_get_base_height() |
| 3063 | + (GetSystemMetrics(SM_CYFRAME) + |
| 3064 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
| 3065 | + GetSystemMetrics(SM_CYCAPTION) |
| 3066 | #ifdef FEAT_MENU |
| 3067 | + gui_mswin_get_menu_height(FALSE) |
| 3068 | #endif |
| 3069 | ; |
| 3070 | *valid_w = base_width + |
| 3071 | ((w - base_width) / gui.char_width) * gui.char_width; |
| 3072 | *valid_h = base_height + |
| 3073 | ((h - base_height) / gui.char_height) * gui.char_height; |
| 3074 | } |
| 3075 | |
| 3076 | void |
| 3077 | gui_mch_flash(int msec) |
| 3078 | { |
| 3079 | RECT rc; |
| 3080 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 3081 | #if defined(FEAT_DIRECTX) |
| 3082 | if (IS_ENABLE_DIRECTX()) |
| 3083 | DWriteContext_Flush(s_dwc); |
| 3084 | #endif |
| 3085 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3086 | /* |
| 3087 | * Note: InvertRect() excludes right and bottom of rectangle. |
| 3088 | */ |
| 3089 | rc.left = 0; |
| 3090 | rc.top = 0; |
| 3091 | rc.right = gui.num_cols * gui.char_width; |
| 3092 | rc.bottom = gui.num_rows * gui.char_height; |
| 3093 | InvertRect(s_hdc, &rc); |
| 3094 | gui_mch_flush(); /* make sure it's displayed */ |
| 3095 | |
| 3096 | ui_delay((long)msec, TRUE); /* wait for a few msec */ |
| 3097 | |
| 3098 | InvertRect(s_hdc, &rc); |
| 3099 | } |
| 3100 | |
| 3101 | /* |
| 3102 | * Return flags used for scrolling. |
| 3103 | * The SW_INVALIDATE is required when part of the window is covered or |
| 3104 | * off-screen. Refer to MS KB Q75236. |
| 3105 | */ |
| 3106 | static int |
| 3107 | get_scroll_flags(void) |
| 3108 | { |
| 3109 | HWND hwnd; |
| 3110 | RECT rcVim, rcOther, rcDest; |
| 3111 | |
| 3112 | GetWindowRect(s_hwnd, &rcVim); |
| 3113 | |
| 3114 | /* Check if the window is partly above or below the screen. We don't care |
| 3115 | * about partly left or right of the screen, it is not relevant when |
| 3116 | * scrolling up or down. */ |
| 3117 | if (rcVim.top < 0 || rcVim.bottom > GetSystemMetrics(SM_CYFULLSCREEN)) |
| 3118 | return SW_INVALIDATE; |
| 3119 | |
| 3120 | /* Check if there is an window (partly) on top of us. */ |
| 3121 | for (hwnd = s_hwnd; (hwnd = GetWindow(hwnd, GW_HWNDPREV)) != (HWND)0; ) |
| 3122 | if (IsWindowVisible(hwnd)) |
| 3123 | { |
| 3124 | GetWindowRect(hwnd, &rcOther); |
| 3125 | if (IntersectRect(&rcDest, &rcVim, &rcOther)) |
| 3126 | return SW_INVALIDATE; |
| 3127 | } |
| 3128 | return 0; |
| 3129 | } |
| 3130 | |
| 3131 | /* |
| 3132 | * On some Intel GPUs, the regions drawn just prior to ScrollWindowEx() |
| 3133 | * may not be scrolled out properly. |
| 3134 | * For gVim, when _OnScroll() is repeated, the character at the |
| 3135 | * previous cursor position may be left drawn after scroll. |
| 3136 | * The problem can be avoided by calling GetPixel() to get a pixel in |
| 3137 | * the region before ScrollWindowEx(). |
| 3138 | */ |
| 3139 | static void |
| 3140 | intel_gpu_workaround(void) |
| 3141 | { |
| 3142 | GetPixel(s_hdc, FILL_X(gui.col), FILL_Y(gui.row)); |
| 3143 | } |
| 3144 | |
| 3145 | /* |
| 3146 | * Delete the given number of lines from the given row, scrolling up any |
| 3147 | * text further down within the scroll region. |
| 3148 | */ |
| 3149 | void |
| 3150 | gui_mch_delete_lines( |
| 3151 | int row, |
| 3152 | int num_lines) |
| 3153 | { |
| 3154 | RECT rc; |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 3155 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3156 | rc.left = FILL_X(gui.scroll_region_left); |
| 3157 | rc.right = FILL_X(gui.scroll_region_right + 1); |
| 3158 | rc.top = FILL_Y(row); |
| 3159 | rc.bottom = FILL_Y(gui.scroll_region_bot + 1); |
| 3160 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3161 | #if defined(FEAT_DIRECTX) |
| 3162 | if (IS_ENABLE_DIRECTX()) |
| 3163 | { |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3164 | DWriteContext_Scroll(s_dwc, 0, -num_lines * gui.char_height, &rc); |
| 3165 | DWriteContext_Flush(s_dwc); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3166 | } |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3167 | else |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3168 | #endif |
| 3169 | { |
| 3170 | intel_gpu_workaround(); |
| 3171 | ScrollWindowEx(s_textArea, 0, -num_lines * gui.char_height, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3172 | &rc, &rc, NULL, NULL, get_scroll_flags()); |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 3173 | UpdateWindow(s_textArea); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3174 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3175 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3176 | /* This seems to be required to avoid the cursor disappearing when |
| 3177 | * scrolling such that the cursor ends up in the top-left character on |
| 3178 | * the screen... But why? (Webb) */ |
| 3179 | /* It's probably fixed by disabling drawing the cursor while scrolling. */ |
| 3180 | /* gui.cursor_is_valid = FALSE; */ |
| 3181 | |
| 3182 | gui_clear_block(gui.scroll_region_bot - num_lines + 1, |
| 3183 | gui.scroll_region_left, |
| 3184 | gui.scroll_region_bot, gui.scroll_region_right); |
| 3185 | } |
| 3186 | |
| 3187 | /* |
| 3188 | * Insert the given number of lines before the given row, scrolling down any |
| 3189 | * following text within the scroll region. |
| 3190 | */ |
| 3191 | void |
| 3192 | gui_mch_insert_lines( |
| 3193 | int row, |
| 3194 | int num_lines) |
| 3195 | { |
| 3196 | RECT rc; |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 3197 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3198 | rc.left = FILL_X(gui.scroll_region_left); |
| 3199 | rc.right = FILL_X(gui.scroll_region_right + 1); |
| 3200 | rc.top = FILL_Y(row); |
| 3201 | rc.bottom = FILL_Y(gui.scroll_region_bot + 1); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3202 | |
| 3203 | #if defined(FEAT_DIRECTX) |
| 3204 | if (IS_ENABLE_DIRECTX()) |
| 3205 | { |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3206 | DWriteContext_Scroll(s_dwc, 0, num_lines * gui.char_height, &rc); |
| 3207 | DWriteContext_Flush(s_dwc); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3208 | } |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3209 | else |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3210 | #endif |
| 3211 | { |
| 3212 | intel_gpu_workaround(); |
| 3213 | /* The SW_INVALIDATE is required when part of the window is covered or |
| 3214 | * off-screen. How do we avoid it when it's not needed? */ |
| 3215 | ScrollWindowEx(s_textArea, 0, num_lines * gui.char_height, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3216 | &rc, &rc, NULL, NULL, get_scroll_flags()); |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 3217 | UpdateWindow(s_textArea); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3218 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3219 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3220 | gui_clear_block(row, gui.scroll_region_left, |
| 3221 | row + num_lines - 1, gui.scroll_region_right); |
| 3222 | } |
| 3223 | |
| 3224 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3225 | void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3226 | gui_mch_exit(int rc UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3227 | { |
| 3228 | #if defined(FEAT_DIRECTX) |
| 3229 | DWriteContext_Close(s_dwc); |
| 3230 | DWrite_Final(); |
| 3231 | s_dwc = NULL; |
| 3232 | #endif |
| 3233 | |
| 3234 | ReleaseDC(s_textArea, s_hdc); |
| 3235 | DeleteObject(s_brush); |
| 3236 | |
| 3237 | #ifdef FEAT_TEAROFF |
| 3238 | /* Unload the tearoff bitmap */ |
| 3239 | (void)DeleteObject((HGDIOBJ)s_htearbitmap); |
| 3240 | #endif |
| 3241 | |
| 3242 | /* Destroy our window (if we have one). */ |
| 3243 | if (s_hwnd != NULL) |
| 3244 | { |
| 3245 | destroying = TRUE; /* ignore WM_DESTROY message now */ |
| 3246 | DestroyWindow(s_hwnd); |
| 3247 | } |
| 3248 | |
| 3249 | #ifdef GLOBAL_IME |
| 3250 | global_ime_end(); |
| 3251 | #endif |
| 3252 | } |
| 3253 | |
| 3254 | static char_u * |
| 3255 | logfont2name(LOGFONT lf) |
| 3256 | { |
| 3257 | char *p; |
| 3258 | char *res; |
| 3259 | char *charset_name; |
Bram Moolenaar | 7c1c6db | 2016-04-03 22:08:05 +0200 | [diff] [blame] | 3260 | char *quality_name; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3261 | char *font_name = lf.lfFaceName; |
| 3262 | |
| 3263 | charset_name = charset_id2name((int)lf.lfCharSet); |
| 3264 | #ifdef FEAT_MBYTE |
| 3265 | /* Convert a font name from the current codepage to 'encoding'. |
| 3266 | * TODO: Use Wide APIs (including LOGFONTW) instead of ANSI APIs. */ |
| 3267 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 3268 | { |
| 3269 | int len; |
| 3270 | acp_to_enc((char_u *)lf.lfFaceName, (int)strlen(lf.lfFaceName), |
| 3271 | (char_u **)&font_name, &len); |
| 3272 | } |
| 3273 | #endif |
Bram Moolenaar | 7c1c6db | 2016-04-03 22:08:05 +0200 | [diff] [blame] | 3274 | quality_name = quality_id2name((int)lf.lfQuality); |
| 3275 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3276 | res = (char *)alloc((unsigned)(strlen(font_name) + 20 |
| 3277 | + (charset_name == NULL ? 0 : strlen(charset_name) + 2))); |
| 3278 | if (res != NULL) |
| 3279 | { |
| 3280 | p = res; |
| 3281 | /* make a normal font string out of the lf thing:*/ |
| 3282 | sprintf((char *)p, "%s:h%d", font_name, pixels_to_points( |
| 3283 | lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE)); |
| 3284 | while (*p) |
| 3285 | { |
| 3286 | if (*p == ' ') |
| 3287 | *p = '_'; |
| 3288 | ++p; |
| 3289 | } |
| 3290 | if (lf.lfItalic) |
| 3291 | STRCAT(p, ":i"); |
| 3292 | if (lf.lfWeight >= FW_BOLD) |
| 3293 | STRCAT(p, ":b"); |
| 3294 | if (lf.lfUnderline) |
| 3295 | STRCAT(p, ":u"); |
| 3296 | if (lf.lfStrikeOut) |
| 3297 | STRCAT(p, ":s"); |
| 3298 | if (charset_name != NULL) |
| 3299 | { |
| 3300 | STRCAT(p, ":c"); |
| 3301 | STRCAT(p, charset_name); |
| 3302 | } |
Bram Moolenaar | 7c1c6db | 2016-04-03 22:08:05 +0200 | [diff] [blame] | 3303 | if (quality_name != NULL) |
| 3304 | { |
| 3305 | STRCAT(p, ":q"); |
| 3306 | STRCAT(p, quality_name); |
| 3307 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | #ifdef FEAT_MBYTE |
| 3311 | if (font_name != lf.lfFaceName) |
| 3312 | vim_free(font_name); |
| 3313 | #endif |
| 3314 | return (char_u *)res; |
| 3315 | } |
| 3316 | |
| 3317 | |
| 3318 | #ifdef FEAT_MBYTE_IME |
| 3319 | /* |
| 3320 | * Set correct LOGFONT to IME. Use 'guifontwide' if available, otherwise use |
| 3321 | * 'guifont' |
| 3322 | */ |
| 3323 | static void |
| 3324 | update_im_font(void) |
| 3325 | { |
| 3326 | LOGFONT lf_wide; |
| 3327 | |
| 3328 | if (p_guifontwide != NULL && *p_guifontwide != NUL |
| 3329 | && gui.wide_font != NOFONT |
| 3330 | && GetObject((HFONT)gui.wide_font, sizeof(lf_wide), &lf_wide)) |
| 3331 | norm_logfont = lf_wide; |
| 3332 | else |
| 3333 | norm_logfont = sub_logfont; |
| 3334 | im_set_font(&norm_logfont); |
| 3335 | } |
| 3336 | #endif |
| 3337 | |
| 3338 | #ifdef FEAT_MBYTE |
| 3339 | /* |
| 3340 | * Handler of gui.wide_font (p_guifontwide) changed notification. |
| 3341 | */ |
| 3342 | void |
| 3343 | gui_mch_wide_font_changed(void) |
| 3344 | { |
| 3345 | LOGFONT lf; |
| 3346 | |
| 3347 | # ifdef FEAT_MBYTE_IME |
| 3348 | update_im_font(); |
| 3349 | # endif |
| 3350 | |
| 3351 | gui_mch_free_font(gui.wide_ital_font); |
| 3352 | gui.wide_ital_font = NOFONT; |
| 3353 | gui_mch_free_font(gui.wide_bold_font); |
| 3354 | gui.wide_bold_font = NOFONT; |
| 3355 | gui_mch_free_font(gui.wide_boldital_font); |
| 3356 | gui.wide_boldital_font = NOFONT; |
| 3357 | |
| 3358 | if (gui.wide_font |
| 3359 | && GetObject((HFONT)gui.wide_font, sizeof(lf), &lf)) |
| 3360 | { |
| 3361 | if (!lf.lfItalic) |
| 3362 | { |
| 3363 | lf.lfItalic = TRUE; |
| 3364 | gui.wide_ital_font = get_font_handle(&lf); |
| 3365 | lf.lfItalic = FALSE; |
| 3366 | } |
| 3367 | if (lf.lfWeight < FW_BOLD) |
| 3368 | { |
| 3369 | lf.lfWeight = FW_BOLD; |
| 3370 | gui.wide_bold_font = get_font_handle(&lf); |
| 3371 | if (!lf.lfItalic) |
| 3372 | { |
| 3373 | lf.lfItalic = TRUE; |
| 3374 | gui.wide_boldital_font = get_font_handle(&lf); |
| 3375 | } |
| 3376 | } |
| 3377 | } |
| 3378 | } |
| 3379 | #endif |
| 3380 | |
| 3381 | /* |
| 3382 | * Initialise vim to use the font with the given name. |
| 3383 | * Return FAIL if the font could not be loaded, OK otherwise. |
| 3384 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3385 | int |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3386 | gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3387 | { |
| 3388 | LOGFONT lf; |
| 3389 | GuiFont font = NOFONT; |
| 3390 | char_u *p; |
| 3391 | |
| 3392 | /* Load the font */ |
| 3393 | if (get_logfont(&lf, font_name, NULL, TRUE) == OK) |
| 3394 | font = get_font_handle(&lf); |
| 3395 | if (font == NOFONT) |
| 3396 | return FAIL; |
| 3397 | |
| 3398 | if (font_name == NULL) |
| 3399 | font_name = (char_u *)lf.lfFaceName; |
| 3400 | #if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME) |
| 3401 | norm_logfont = lf; |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 3402 | #endif |
| 3403 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3404 | sub_logfont = lf; |
| 3405 | #endif |
| 3406 | #ifdef FEAT_MBYTE_IME |
| 3407 | update_im_font(); |
| 3408 | #endif |
| 3409 | gui_mch_free_font(gui.norm_font); |
| 3410 | gui.norm_font = font; |
| 3411 | current_font_height = lf.lfHeight; |
| 3412 | GetFontSize(font); |
| 3413 | |
| 3414 | p = logfont2name(lf); |
| 3415 | if (p != NULL) |
| 3416 | { |
| 3417 | hl_set_font_name(p); |
| 3418 | |
| 3419 | /* When setting 'guifont' to "*" replace it with the actual font name. |
| 3420 | * */ |
| 3421 | if (STRCMP(font_name, "*") == 0 && STRCMP(p_guifont, "*") == 0) |
| 3422 | { |
| 3423 | vim_free(p_guifont); |
| 3424 | p_guifont = p; |
| 3425 | } |
| 3426 | else |
| 3427 | vim_free(p); |
| 3428 | } |
| 3429 | |
| 3430 | gui_mch_free_font(gui.ital_font); |
| 3431 | gui.ital_font = NOFONT; |
| 3432 | gui_mch_free_font(gui.bold_font); |
| 3433 | gui.bold_font = NOFONT; |
| 3434 | gui_mch_free_font(gui.boldital_font); |
| 3435 | gui.boldital_font = NOFONT; |
| 3436 | |
| 3437 | if (!lf.lfItalic) |
| 3438 | { |
| 3439 | lf.lfItalic = TRUE; |
| 3440 | gui.ital_font = get_font_handle(&lf); |
| 3441 | lf.lfItalic = FALSE; |
| 3442 | } |
| 3443 | if (lf.lfWeight < FW_BOLD) |
| 3444 | { |
| 3445 | lf.lfWeight = FW_BOLD; |
| 3446 | gui.bold_font = get_font_handle(&lf); |
| 3447 | if (!lf.lfItalic) |
| 3448 | { |
| 3449 | lf.lfItalic = TRUE; |
| 3450 | gui.boldital_font = get_font_handle(&lf); |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | return OK; |
| 3455 | } |
| 3456 | |
| 3457 | #ifndef WPF_RESTORETOMAXIMIZED |
| 3458 | # define WPF_RESTORETOMAXIMIZED 2 /* just in case someone doesn't have it */ |
| 3459 | #endif |
| 3460 | |
| 3461 | /* |
| 3462 | * Return TRUE if the GUI window is maximized, filling the whole screen. |
| 3463 | */ |
| 3464 | int |
| 3465 | gui_mch_maximized(void) |
| 3466 | { |
| 3467 | WINDOWPLACEMENT wp; |
| 3468 | |
| 3469 | wp.length = sizeof(WINDOWPLACEMENT); |
| 3470 | if (GetWindowPlacement(s_hwnd, &wp)) |
| 3471 | return wp.showCmd == SW_SHOWMAXIMIZED |
| 3472 | || (wp.showCmd == SW_SHOWMINIMIZED |
| 3473 | && wp.flags == WPF_RESTORETOMAXIMIZED); |
| 3474 | |
| 3475 | return 0; |
| 3476 | } |
| 3477 | |
| 3478 | /* |
Bram Moolenaar | 8ac4415 | 2017-11-09 18:33:29 +0100 | [diff] [blame] | 3479 | * Called when the font changed while the window is maximized or GO_KEEPWINSIZE |
| 3480 | * is set. Compute the new Rows and Columns. This is like resizing the |
| 3481 | * window. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3482 | */ |
| 3483 | void |
| 3484 | gui_mch_newfont(void) |
| 3485 | { |
| 3486 | RECT rect; |
| 3487 | |
| 3488 | GetWindowRect(s_hwnd, &rect); |
| 3489 | if (win_socket_id == 0) |
| 3490 | { |
| 3491 | gui_resize_shell(rect.right - rect.left |
| 3492 | - (GetSystemMetrics(SM_CXFRAME) + |
| 3493 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2, |
| 3494 | rect.bottom - rect.top |
| 3495 | - (GetSystemMetrics(SM_CYFRAME) + |
| 3496 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
| 3497 | - GetSystemMetrics(SM_CYCAPTION) |
| 3498 | #ifdef FEAT_MENU |
| 3499 | - gui_mswin_get_menu_height(FALSE) |
| 3500 | #endif |
| 3501 | ); |
| 3502 | } |
| 3503 | else |
| 3504 | { |
| 3505 | /* Inside another window, don't use the frame and border. */ |
| 3506 | gui_resize_shell(rect.right - rect.left, |
| 3507 | rect.bottom - rect.top |
| 3508 | #ifdef FEAT_MENU |
| 3509 | - gui_mswin_get_menu_height(FALSE) |
| 3510 | #endif |
| 3511 | ); |
| 3512 | } |
| 3513 | } |
| 3514 | |
| 3515 | /* |
| 3516 | * Set the window title |
| 3517 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3518 | void |
| 3519 | gui_mch_settitle( |
| 3520 | char_u *title, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3521 | char_u *icon UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3522 | { |
| 3523 | set_window_title(s_hwnd, (title == NULL ? "VIM" : (char *)title)); |
| 3524 | } |
| 3525 | |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 3526 | #if defined(FEAT_MOUSESHAPE) || defined(PROTO) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3527 | /* Table for shape IDCs. Keep in sync with the mshape_names[] table in |
| 3528 | * misc2.c! */ |
| 3529 | static LPCSTR mshape_idcs[] = |
| 3530 | { |
| 3531 | IDC_ARROW, /* arrow */ |
| 3532 | MAKEINTRESOURCE(0), /* blank */ |
| 3533 | IDC_IBEAM, /* beam */ |
| 3534 | IDC_SIZENS, /* updown */ |
| 3535 | IDC_SIZENS, /* udsizing */ |
| 3536 | IDC_SIZEWE, /* leftright */ |
| 3537 | IDC_SIZEWE, /* lrsizing */ |
| 3538 | IDC_WAIT, /* busy */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3539 | IDC_NO, /* no */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3540 | IDC_ARROW, /* crosshair */ |
| 3541 | IDC_ARROW, /* hand1 */ |
| 3542 | IDC_ARROW, /* hand2 */ |
| 3543 | IDC_ARROW, /* pencil */ |
| 3544 | IDC_ARROW, /* question */ |
| 3545 | IDC_ARROW, /* right-arrow */ |
| 3546 | IDC_UPARROW, /* up-arrow */ |
| 3547 | IDC_ARROW /* last one */ |
| 3548 | }; |
| 3549 | |
| 3550 | void |
| 3551 | mch_set_mouse_shape(int shape) |
| 3552 | { |
| 3553 | LPCSTR idc; |
| 3554 | |
| 3555 | if (shape == MSHAPE_HIDE) |
| 3556 | ShowCursor(FALSE); |
| 3557 | else |
| 3558 | { |
| 3559 | if (shape >= MSHAPE_NUMBERED) |
| 3560 | idc = IDC_ARROW; |
| 3561 | else |
| 3562 | idc = mshape_idcs[shape]; |
| 3563 | #ifdef SetClassLongPtr |
| 3564 | SetClassLongPtr(s_textArea, GCLP_HCURSOR, (__int3264)(LONG_PTR)LoadCursor(NULL, idc)); |
| 3565 | #else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3566 | SetClassLong(s_textArea, GCL_HCURSOR, (long_u)LoadCursor(NULL, idc)); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3567 | #endif |
| 3568 | if (!p_mh) |
| 3569 | { |
| 3570 | POINT mp; |
| 3571 | |
| 3572 | /* Set the position to make it redrawn with the new shape. */ |
| 3573 | (void)GetCursorPos((LPPOINT)&mp); |
| 3574 | (void)SetCursorPos(mp.x, mp.y); |
| 3575 | ShowCursor(TRUE); |
| 3576 | } |
| 3577 | } |
| 3578 | } |
| 3579 | #endif |
| 3580 | |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 3581 | #if defined(FEAT_BROWSE) || defined(PROTO) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3582 | /* |
| 3583 | * The file browser exists in two versions: with "W" uses wide characters, |
| 3584 | * without "W" the current codepage. When FEAT_MBYTE is defined and on |
| 3585 | * Windows NT/2000/XP the "W" functions are used. |
| 3586 | */ |
| 3587 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3588 | # ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3589 | /* |
| 3590 | * Wide version of convert_filter(). |
| 3591 | */ |
| 3592 | static WCHAR * |
| 3593 | convert_filterW(char_u *s) |
| 3594 | { |
| 3595 | char_u *tmp; |
| 3596 | int len; |
| 3597 | WCHAR *res; |
| 3598 | |
| 3599 | tmp = convert_filter(s); |
| 3600 | if (tmp == NULL) |
| 3601 | return NULL; |
| 3602 | len = (int)STRLEN(s) + 3; |
| 3603 | res = enc_to_utf16(tmp, &len); |
| 3604 | vim_free(tmp); |
| 3605 | return res; |
| 3606 | } |
| 3607 | |
| 3608 | /* |
| 3609 | * Wide version of gui_mch_browse(). Keep in sync! |
| 3610 | */ |
| 3611 | static char_u * |
| 3612 | gui_mch_browseW( |
| 3613 | int saving, |
| 3614 | char_u *title, |
| 3615 | char_u *dflt, |
| 3616 | char_u *ext, |
| 3617 | char_u *initdir, |
| 3618 | char_u *filter) |
| 3619 | { |
| 3620 | /* We always use the wide function. This means enc_to_utf16() must work, |
| 3621 | * otherwise it fails miserably! */ |
| 3622 | OPENFILENAMEW fileStruct; |
| 3623 | WCHAR fileBuf[MAXPATHL]; |
| 3624 | WCHAR *wp; |
| 3625 | int i; |
| 3626 | WCHAR *titlep = NULL; |
| 3627 | WCHAR *extp = NULL; |
| 3628 | WCHAR *initdirp = NULL; |
| 3629 | WCHAR *filterp; |
Bram Moolenaar | 7ff8a3c | 2018-09-22 14:39:15 +0200 | [diff] [blame] | 3630 | char_u *p, *q; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3631 | |
| 3632 | if (dflt == NULL) |
| 3633 | fileBuf[0] = NUL; |
| 3634 | else |
| 3635 | { |
| 3636 | wp = enc_to_utf16(dflt, NULL); |
| 3637 | if (wp == NULL) |
| 3638 | fileBuf[0] = NUL; |
| 3639 | else |
| 3640 | { |
| 3641 | for (i = 0; wp[i] != NUL && i < MAXPATHL - 1; ++i) |
| 3642 | fileBuf[i] = wp[i]; |
| 3643 | fileBuf[i] = NUL; |
| 3644 | vim_free(wp); |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | /* Convert the filter to Windows format. */ |
| 3649 | filterp = convert_filterW(filter); |
| 3650 | |
| 3651 | vim_memset(&fileStruct, 0, sizeof(OPENFILENAMEW)); |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3652 | # ifdef OPENFILENAME_SIZE_VERSION_400W |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3653 | /* be compatible with Windows NT 4.0 */ |
Bram Moolenaar | 89e375a | 2016-03-15 18:09:57 +0100 | [diff] [blame] | 3654 | fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400W; |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3655 | # else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3656 | fileStruct.lStructSize = sizeof(fileStruct); |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3657 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3658 | |
| 3659 | if (title != NULL) |
| 3660 | titlep = enc_to_utf16(title, NULL); |
| 3661 | fileStruct.lpstrTitle = titlep; |
| 3662 | |
| 3663 | if (ext != NULL) |
| 3664 | extp = enc_to_utf16(ext, NULL); |
| 3665 | fileStruct.lpstrDefExt = extp; |
| 3666 | |
| 3667 | fileStruct.lpstrFile = fileBuf; |
| 3668 | fileStruct.nMaxFile = MAXPATHL; |
| 3669 | fileStruct.lpstrFilter = filterp; |
| 3670 | fileStruct.hwndOwner = s_hwnd; /* main Vim window is owner*/ |
| 3671 | /* has an initial dir been specified? */ |
| 3672 | if (initdir != NULL && *initdir != NUL) |
| 3673 | { |
| 3674 | /* Must have backslashes here, no matter what 'shellslash' says */ |
| 3675 | initdirp = enc_to_utf16(initdir, NULL); |
| 3676 | if (initdirp != NULL) |
| 3677 | { |
| 3678 | for (wp = initdirp; *wp != NUL; ++wp) |
| 3679 | if (*wp == '/') |
| 3680 | *wp = '\\'; |
| 3681 | } |
| 3682 | fileStruct.lpstrInitialDir = initdirp; |
| 3683 | } |
| 3684 | |
| 3685 | /* |
| 3686 | * TODO: Allow selection of multiple files. Needs another arg to this |
| 3687 | * function to ask for it, and need to use OFN_ALLOWMULTISELECT below. |
| 3688 | * Also, should we use OFN_FILEMUSTEXIST when opening? Vim can edit on |
| 3689 | * files that don't exist yet, so I haven't put it in. What about |
| 3690 | * OFN_PATHMUSTEXIST? |
| 3691 | * Don't use OFN_OVERWRITEPROMPT, Vim has its own ":confirm" dialog. |
| 3692 | */ |
| 3693 | fileStruct.Flags = (OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY); |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3694 | # ifdef FEAT_SHORTCUT |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3695 | if (curbuf->b_p_bin) |
| 3696 | fileStruct.Flags |= OFN_NODEREFERENCELINKS; |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3697 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3698 | if (saving) |
| 3699 | { |
| 3700 | if (!GetSaveFileNameW(&fileStruct)) |
| 3701 | return NULL; |
| 3702 | } |
| 3703 | else |
| 3704 | { |
| 3705 | if (!GetOpenFileNameW(&fileStruct)) |
| 3706 | return NULL; |
| 3707 | } |
| 3708 | |
| 3709 | vim_free(filterp); |
| 3710 | vim_free(initdirp); |
| 3711 | vim_free(titlep); |
| 3712 | vim_free(extp); |
| 3713 | |
| 3714 | /* Convert from UCS2 to 'encoding'. */ |
| 3715 | p = utf16_to_enc(fileBuf, NULL); |
Bram Moolenaar | 7ff8a3c | 2018-09-22 14:39:15 +0200 | [diff] [blame] | 3716 | if (p == NULL) |
| 3717 | return NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3718 | |
| 3719 | /* Give focus back to main window (when using MDI). */ |
| 3720 | SetFocus(s_hwnd); |
| 3721 | |
| 3722 | /* Shorten the file name if possible */ |
Bram Moolenaar | 7ff8a3c | 2018-09-22 14:39:15 +0200 | [diff] [blame] | 3723 | q = vim_strsave(shorten_fname1(p)); |
| 3724 | vim_free(p); |
| 3725 | return q; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3726 | } |
| 3727 | # endif /* FEAT_MBYTE */ |
| 3728 | |
| 3729 | |
| 3730 | /* |
| 3731 | * Convert the string s to the proper format for a filter string by replacing |
| 3732 | * the \t and \n delimiters with \0. |
| 3733 | * Returns the converted string in allocated memory. |
| 3734 | * |
| 3735 | * Keep in sync with convert_filterW() above! |
| 3736 | */ |
| 3737 | static char_u * |
| 3738 | convert_filter(char_u *s) |
| 3739 | { |
| 3740 | char_u *res; |
| 3741 | unsigned s_len = (unsigned)STRLEN(s); |
| 3742 | unsigned i; |
| 3743 | |
| 3744 | res = alloc(s_len + 3); |
| 3745 | if (res != NULL) |
| 3746 | { |
| 3747 | for (i = 0; i < s_len; ++i) |
| 3748 | if (s[i] == '\t' || s[i] == '\n') |
| 3749 | res[i] = '\0'; |
| 3750 | else |
| 3751 | res[i] = s[i]; |
| 3752 | res[s_len] = NUL; |
| 3753 | /* Add two extra NULs to make sure it's properly terminated. */ |
| 3754 | res[s_len + 1] = NUL; |
| 3755 | res[s_len + 2] = NUL; |
| 3756 | } |
| 3757 | return res; |
| 3758 | } |
| 3759 | |
| 3760 | /* |
| 3761 | * Select a directory. |
| 3762 | */ |
| 3763 | char_u * |
| 3764 | gui_mch_browsedir(char_u *title, char_u *initdir) |
| 3765 | { |
| 3766 | /* We fake this: Use a filter that doesn't select anything and a default |
| 3767 | * file name that won't be used. */ |
| 3768 | return gui_mch_browse(0, title, (char_u *)_("Not Used"), NULL, |
| 3769 | initdir, (char_u *)_("Directory\t*.nothing\n")); |
| 3770 | } |
| 3771 | |
| 3772 | /* |
| 3773 | * Pop open a file browser and return the file selected, in allocated memory, |
| 3774 | * or NULL if Cancel is hit. |
| 3775 | * saving - TRUE if the file will be saved to, FALSE if it will be opened. |
| 3776 | * title - Title message for the file browser dialog. |
| 3777 | * dflt - Default name of file. |
| 3778 | * ext - Default extension to be added to files without extensions. |
| 3779 | * initdir - directory in which to open the browser (NULL = current dir) |
| 3780 | * filter - Filter for matched files to choose from. |
| 3781 | * |
| 3782 | * Keep in sync with gui_mch_browseW() above! |
| 3783 | */ |
| 3784 | char_u * |
| 3785 | gui_mch_browse( |
| 3786 | int saving, |
| 3787 | char_u *title, |
| 3788 | char_u *dflt, |
| 3789 | char_u *ext, |
| 3790 | char_u *initdir, |
| 3791 | char_u *filter) |
| 3792 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3793 | # ifdef FEAT_MBYTE |
| 3794 | return gui_mch_browseW(saving, title, dflt, ext, initdir, filter); |
| 3795 | # else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3796 | OPENFILENAME fileStruct; |
| 3797 | char_u fileBuf[MAXPATHL]; |
| 3798 | char_u *initdirp = NULL; |
| 3799 | char_u *filterp; |
| 3800 | char_u *p; |
| 3801 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3802 | if (dflt == NULL) |
| 3803 | fileBuf[0] = NUL; |
| 3804 | else |
| 3805 | vim_strncpy(fileBuf, dflt, MAXPATHL - 1); |
| 3806 | |
| 3807 | /* Convert the filter to Windows format. */ |
| 3808 | filterp = convert_filter(filter); |
| 3809 | |
| 3810 | vim_memset(&fileStruct, 0, sizeof(OPENFILENAME)); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3811 | # ifdef OPENFILENAME_SIZE_VERSION_400 |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3812 | /* be compatible with Windows NT 4.0 */ |
| 3813 | fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400; |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3814 | # else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3815 | fileStruct.lStructSize = sizeof(fileStruct); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3816 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3817 | |
| 3818 | fileStruct.lpstrTitle = (LPSTR)title; |
| 3819 | fileStruct.lpstrDefExt = (LPSTR)ext; |
| 3820 | |
| 3821 | fileStruct.lpstrFile = (LPSTR)fileBuf; |
| 3822 | fileStruct.nMaxFile = MAXPATHL; |
| 3823 | fileStruct.lpstrFilter = (LPSTR)filterp; |
| 3824 | fileStruct.hwndOwner = s_hwnd; /* main Vim window is owner*/ |
| 3825 | /* has an initial dir been specified? */ |
| 3826 | if (initdir != NULL && *initdir != NUL) |
| 3827 | { |
| 3828 | /* Must have backslashes here, no matter what 'shellslash' says */ |
| 3829 | initdirp = vim_strsave(initdir); |
| 3830 | if (initdirp != NULL) |
| 3831 | for (p = initdirp; *p != NUL; ++p) |
| 3832 | if (*p == '/') |
| 3833 | *p = '\\'; |
| 3834 | fileStruct.lpstrInitialDir = (LPSTR)initdirp; |
| 3835 | } |
| 3836 | |
| 3837 | /* |
| 3838 | * TODO: Allow selection of multiple files. Needs another arg to this |
| 3839 | * function to ask for it, and need to use OFN_ALLOWMULTISELECT below. |
| 3840 | * Also, should we use OFN_FILEMUSTEXIST when opening? Vim can edit on |
| 3841 | * files that don't exist yet, so I haven't put it in. What about |
| 3842 | * OFN_PATHMUSTEXIST? |
| 3843 | * Don't use OFN_OVERWRITEPROMPT, Vim has its own ":confirm" dialog. |
| 3844 | */ |
| 3845 | fileStruct.Flags = (OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3846 | # ifdef FEAT_SHORTCUT |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3847 | if (curbuf->b_p_bin) |
| 3848 | fileStruct.Flags |= OFN_NODEREFERENCELINKS; |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3849 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3850 | if (saving) |
| 3851 | { |
| 3852 | if (!GetSaveFileName(&fileStruct)) |
| 3853 | return NULL; |
| 3854 | } |
| 3855 | else |
| 3856 | { |
| 3857 | if (!GetOpenFileName(&fileStruct)) |
| 3858 | return NULL; |
| 3859 | } |
| 3860 | |
| 3861 | vim_free(filterp); |
| 3862 | vim_free(initdirp); |
| 3863 | |
| 3864 | /* Give focus back to main window (when using MDI). */ |
| 3865 | SetFocus(s_hwnd); |
| 3866 | |
| 3867 | /* Shorten the file name if possible */ |
| 3868 | return vim_strsave(shorten_fname1((char_u *)fileBuf)); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 3869 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3870 | } |
| 3871 | #endif /* FEAT_BROWSE */ |
| 3872 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3873 | static void |
| 3874 | _OnDropFiles( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3875 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3876 | HDROP hDrop) |
| 3877 | { |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3878 | #define BUFPATHLEN _MAX_PATH |
| 3879 | #define DRAGQVAL 0xFFFFFFFF |
| 3880 | #ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3881 | WCHAR wszFile[BUFPATHLEN]; |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3882 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3883 | char szFile[BUFPATHLEN]; |
| 3884 | UINT cFiles = DragQueryFile(hDrop, DRAGQVAL, NULL, 0); |
| 3885 | UINT i; |
| 3886 | char_u **fnames; |
| 3887 | POINT pt; |
| 3888 | int_u modifiers = 0; |
| 3889 | |
| 3890 | /* TRACE("_OnDropFiles: %d files dropped\n", cFiles); */ |
| 3891 | |
| 3892 | /* Obtain dropped position */ |
| 3893 | DragQueryPoint(hDrop, &pt); |
| 3894 | MapWindowPoints(s_hwnd, s_textArea, &pt, 1); |
| 3895 | |
| 3896 | reset_VIsual(); |
| 3897 | |
| 3898 | fnames = (char_u **)alloc(cFiles * sizeof(char_u *)); |
| 3899 | |
| 3900 | if (fnames != NULL) |
| 3901 | for (i = 0; i < cFiles; ++i) |
| 3902 | { |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3903 | #ifdef FEAT_MBYTE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3904 | if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0) |
| 3905 | fnames[i] = utf16_to_enc(wszFile, NULL); |
| 3906 | else |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3907 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3908 | { |
| 3909 | DragQueryFile(hDrop, i, szFile, BUFPATHLEN); |
| 3910 | fnames[i] = vim_strsave((char_u *)szFile); |
| 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | DragFinish(hDrop); |
| 3915 | |
| 3916 | if (fnames != NULL) |
| 3917 | { |
| 3918 | if ((GetKeyState(VK_SHIFT) & 0x8000) != 0) |
| 3919 | modifiers |= MOUSE_SHIFT; |
| 3920 | if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) |
| 3921 | modifiers |= MOUSE_CTRL; |
| 3922 | if ((GetKeyState(VK_MENU) & 0x8000) != 0) |
| 3923 | modifiers |= MOUSE_ALT; |
| 3924 | |
| 3925 | gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles); |
| 3926 | |
| 3927 | s_need_activate = TRUE; |
| 3928 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3929 | } |
| 3930 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3931 | static int |
| 3932 | _OnScroll( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3933 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3934 | HWND hwndCtl, |
| 3935 | UINT code, |
| 3936 | int pos) |
| 3937 | { |
| 3938 | static UINT prev_code = 0; /* code of previous call */ |
| 3939 | scrollbar_T *sb, *sb_info; |
| 3940 | long val; |
| 3941 | int dragging = FALSE; |
| 3942 | int dont_scroll_save = dont_scroll; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3943 | SCROLLINFO si; |
| 3944 | |
| 3945 | si.cbSize = sizeof(si); |
| 3946 | si.fMask = SIF_POS; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3947 | |
| 3948 | sb = gui_mswin_find_scrollbar(hwndCtl); |
| 3949 | if (sb == NULL) |
| 3950 | return 0; |
| 3951 | |
| 3952 | if (sb->wp != NULL) /* Left or right scrollbar */ |
| 3953 | { |
| 3954 | /* |
| 3955 | * Careful: need to get scrollbar info out of first (left) scrollbar |
| 3956 | * for window, but keep real scrollbar too because we must pass it to |
| 3957 | * gui_drag_scrollbar(). |
| 3958 | */ |
| 3959 | sb_info = &sb->wp->w_scrollbars[0]; |
| 3960 | } |
| 3961 | else /* Bottom scrollbar */ |
| 3962 | sb_info = sb; |
| 3963 | val = sb_info->value; |
| 3964 | |
| 3965 | switch (code) |
| 3966 | { |
| 3967 | case SB_THUMBTRACK: |
| 3968 | val = pos; |
| 3969 | dragging = TRUE; |
| 3970 | if (sb->scroll_shift > 0) |
| 3971 | val <<= sb->scroll_shift; |
| 3972 | break; |
| 3973 | case SB_LINEDOWN: |
| 3974 | val++; |
| 3975 | break; |
| 3976 | case SB_LINEUP: |
| 3977 | val--; |
| 3978 | break; |
| 3979 | case SB_PAGEDOWN: |
| 3980 | val += (sb_info->size > 2 ? sb_info->size - 2 : 1); |
| 3981 | break; |
| 3982 | case SB_PAGEUP: |
| 3983 | val -= (sb_info->size > 2 ? sb_info->size - 2 : 1); |
| 3984 | break; |
| 3985 | case SB_TOP: |
| 3986 | val = 0; |
| 3987 | break; |
| 3988 | case SB_BOTTOM: |
| 3989 | val = sb_info->max; |
| 3990 | break; |
| 3991 | case SB_ENDSCROLL: |
| 3992 | if (prev_code == SB_THUMBTRACK) |
| 3993 | { |
| 3994 | /* |
| 3995 | * "pos" only gives us 16-bit data. In case of large file, |
| 3996 | * use GetScrollPos() which returns 32-bit. Unfortunately it |
| 3997 | * is not valid while the scrollbar is being dragged. |
| 3998 | */ |
| 3999 | val = GetScrollPos(hwndCtl, SB_CTL); |
| 4000 | if (sb->scroll_shift > 0) |
| 4001 | val <<= sb->scroll_shift; |
| 4002 | } |
| 4003 | break; |
| 4004 | |
| 4005 | default: |
| 4006 | /* TRACE("Unknown scrollbar event %d\n", code); */ |
| 4007 | return 0; |
| 4008 | } |
| 4009 | prev_code = code; |
| 4010 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4011 | si.nPos = (sb->scroll_shift > 0) ? val >> sb->scroll_shift : val; |
| 4012 | SetScrollInfo(hwndCtl, SB_CTL, &si, TRUE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4013 | |
| 4014 | /* |
| 4015 | * When moving a vertical scrollbar, move the other vertical scrollbar too. |
| 4016 | */ |
| 4017 | if (sb->wp != NULL) |
| 4018 | { |
| 4019 | scrollbar_T *sba = sb->wp->w_scrollbars; |
| 4020 | HWND id = sba[ (sb == sba + SBAR_LEFT) ? SBAR_RIGHT : SBAR_LEFT].id; |
| 4021 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4022 | SetScrollInfo(id, SB_CTL, &si, TRUE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4023 | } |
| 4024 | |
| 4025 | /* Don't let us be interrupted here by another message. */ |
| 4026 | s_busy_processing = TRUE; |
| 4027 | |
| 4028 | /* When "allow_scrollbar" is FALSE still need to remember the new |
| 4029 | * position, but don't actually scroll by setting "dont_scroll". */ |
| 4030 | dont_scroll = !allow_scrollbar; |
| 4031 | |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 4032 | mch_disable_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4033 | gui_drag_scrollbar(sb, val, dragging); |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 4034 | mch_enable_flush(); |
| 4035 | gui_may_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4036 | |
| 4037 | s_busy_processing = FALSE; |
| 4038 | dont_scroll = dont_scroll_save; |
| 4039 | |
| 4040 | return 0; |
| 4041 | } |
| 4042 | |
| 4043 | |
| 4044 | /* |
| 4045 | * Get command line arguments. |
| 4046 | * Use "prog" as the name of the program and "cmdline" as the arguments. |
| 4047 | * Copy the arguments to allocated memory. |
| 4048 | * Return the number of arguments (including program name). |
| 4049 | * Return pointers to the arguments in "argvp". Memory is allocated with |
| 4050 | * malloc(), use free() instead of vim_free(). |
| 4051 | * Return pointer to buffer in "tofree". |
| 4052 | * Returns zero when out of memory. |
| 4053 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 4054 | int |
| 4055 | get_cmd_args(char *prog, char *cmdline, char ***argvp, char **tofree) |
| 4056 | { |
| 4057 | int i; |
| 4058 | char *p; |
| 4059 | char *progp; |
| 4060 | char *pnew = NULL; |
| 4061 | char *newcmdline; |
| 4062 | int inquote; |
| 4063 | int argc; |
| 4064 | char **argv = NULL; |
| 4065 | int round; |
| 4066 | |
| 4067 | *tofree = NULL; |
| 4068 | |
| 4069 | #ifdef FEAT_MBYTE |
| 4070 | /* Try using the Unicode version first, it takes care of conversion when |
| 4071 | * 'encoding' is changed. */ |
| 4072 | argc = get_cmd_argsW(&argv); |
| 4073 | if (argc != 0) |
| 4074 | goto done; |
| 4075 | #endif |
| 4076 | |
| 4077 | /* Handle the program name. Remove the ".exe" extension, and find the 1st |
| 4078 | * non-space. */ |
| 4079 | p = strrchr(prog, '.'); |
| 4080 | if (p != NULL) |
| 4081 | *p = NUL; |
| 4082 | for (progp = prog; *progp == ' '; ++progp) |
| 4083 | ; |
| 4084 | |
| 4085 | /* The command line is copied to allocated memory, so that we can change |
| 4086 | * it. Add the size of the string, the separating NUL and a terminating |
| 4087 | * NUL. */ |
| 4088 | newcmdline = malloc(STRLEN(cmdline) + STRLEN(progp) + 2); |
| 4089 | if (newcmdline == NULL) |
| 4090 | return 0; |
| 4091 | |
| 4092 | /* |
| 4093 | * First round: count the number of arguments ("pnew" == NULL). |
| 4094 | * Second round: produce the arguments. |
| 4095 | */ |
| 4096 | for (round = 1; round <= 2; ++round) |
| 4097 | { |
| 4098 | /* First argument is the program name. */ |
| 4099 | if (pnew != NULL) |
| 4100 | { |
| 4101 | argv[0] = pnew; |
| 4102 | strcpy(pnew, progp); |
| 4103 | pnew += strlen(pnew); |
| 4104 | *pnew++ = NUL; |
| 4105 | } |
| 4106 | |
| 4107 | /* |
| 4108 | * Isolate each argument and put it in argv[]. |
| 4109 | */ |
| 4110 | p = cmdline; |
| 4111 | argc = 1; |
| 4112 | while (*p != NUL) |
| 4113 | { |
| 4114 | inquote = FALSE; |
| 4115 | if (pnew != NULL) |
| 4116 | argv[argc] = pnew; |
| 4117 | ++argc; |
| 4118 | while (*p != NUL && (inquote || (*p != ' ' && *p != '\t'))) |
| 4119 | { |
| 4120 | /* Backslashes are only special when followed by a double |
| 4121 | * quote. */ |
| 4122 | i = (int)strspn(p, "\\"); |
| 4123 | if (p[i] == '"') |
| 4124 | { |
| 4125 | /* Halve the number of backslashes. */ |
| 4126 | if (i > 1 && pnew != NULL) |
| 4127 | { |
| 4128 | vim_memset(pnew, '\\', i / 2); |
| 4129 | pnew += i / 2; |
| 4130 | } |
| 4131 | |
| 4132 | /* Even nr of backslashes toggles quoting, uneven copies |
| 4133 | * the double quote. */ |
| 4134 | if ((i & 1) == 0) |
| 4135 | inquote = !inquote; |
| 4136 | else if (pnew != NULL) |
| 4137 | *pnew++ = '"'; |
| 4138 | p += i + 1; |
| 4139 | } |
| 4140 | else if (i > 0) |
| 4141 | { |
| 4142 | /* Copy span of backslashes unmodified. */ |
| 4143 | if (pnew != NULL) |
| 4144 | { |
| 4145 | vim_memset(pnew, '\\', i); |
| 4146 | pnew += i; |
| 4147 | } |
| 4148 | p += i; |
| 4149 | } |
| 4150 | else |
| 4151 | { |
| 4152 | if (pnew != NULL) |
| 4153 | *pnew++ = *p; |
| 4154 | #ifdef FEAT_MBYTE |
| 4155 | /* Can't use mb_* functions, because 'encoding' is not |
| 4156 | * initialized yet here. */ |
| 4157 | if (IsDBCSLeadByte(*p)) |
| 4158 | { |
| 4159 | ++p; |
| 4160 | if (pnew != NULL) |
| 4161 | *pnew++ = *p; |
| 4162 | } |
| 4163 | #endif |
| 4164 | ++p; |
| 4165 | } |
| 4166 | } |
| 4167 | |
| 4168 | if (pnew != NULL) |
| 4169 | *pnew++ = NUL; |
| 4170 | while (*p == ' ' || *p == '\t') |
| 4171 | ++p; /* advance until a non-space */ |
| 4172 | } |
| 4173 | |
| 4174 | if (round == 1) |
| 4175 | { |
| 4176 | argv = (char **)malloc((argc + 1) * sizeof(char *)); |
| 4177 | if (argv == NULL ) |
| 4178 | { |
| 4179 | free(newcmdline); |
| 4180 | return 0; /* malloc error */ |
| 4181 | } |
| 4182 | pnew = newcmdline; |
| 4183 | *tofree = newcmdline; |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | #ifdef FEAT_MBYTE |
| 4188 | done: |
| 4189 | #endif |
| 4190 | argv[argc] = NULL; /* NULL-terminated list */ |
| 4191 | *argvp = argv; |
| 4192 | return argc; |
| 4193 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4194 | |
| 4195 | #ifdef FEAT_XPM_W32 |
| 4196 | # include "xpm_w32.h" |
| 4197 | #endif |
| 4198 | |
| 4199 | #ifdef PROTO |
| 4200 | # define WINAPI |
| 4201 | #endif |
| 4202 | |
| 4203 | #ifdef __MINGW32__ |
| 4204 | /* |
| 4205 | * Add a lot of missing defines. |
| 4206 | * They are not always missing, we need the #ifndef's. |
| 4207 | */ |
| 4208 | # ifndef _cdecl |
| 4209 | # define _cdecl |
| 4210 | # endif |
| 4211 | # ifndef IsMinimized |
| 4212 | # define IsMinimized(hwnd) IsIconic(hwnd) |
| 4213 | # endif |
| 4214 | # ifndef IsMaximized |
| 4215 | # define IsMaximized(hwnd) IsZoomed(hwnd) |
| 4216 | # endif |
| 4217 | # ifndef SelectFont |
| 4218 | # define SelectFont(hdc, hfont) ((HFONT)SelectObject((hdc), (HGDIOBJ)(HFONT)(hfont))) |
| 4219 | # endif |
| 4220 | # ifndef GetStockBrush |
| 4221 | # define GetStockBrush(i) ((HBRUSH)GetStockObject(i)) |
| 4222 | # endif |
| 4223 | # ifndef DeleteBrush |
| 4224 | # define DeleteBrush(hbr) DeleteObject((HGDIOBJ)(HBRUSH)(hbr)) |
| 4225 | # endif |
| 4226 | |
| 4227 | # ifndef HANDLE_WM_RBUTTONDBLCLK |
| 4228 | # define HANDLE_WM_RBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 4229 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4230 | # endif |
| 4231 | # ifndef HANDLE_WM_MBUTTONUP |
| 4232 | # define HANDLE_WM_MBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 4233 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4234 | # endif |
| 4235 | # ifndef HANDLE_WM_MBUTTONDBLCLK |
| 4236 | # define HANDLE_WM_MBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 4237 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4238 | # endif |
| 4239 | # ifndef HANDLE_WM_LBUTTONDBLCLK |
| 4240 | # define HANDLE_WM_LBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 4241 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4242 | # endif |
| 4243 | # ifndef HANDLE_WM_RBUTTONDOWN |
| 4244 | # define HANDLE_WM_RBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 4245 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4246 | # endif |
| 4247 | # ifndef HANDLE_WM_MOUSEMOVE |
| 4248 | # define HANDLE_WM_MOUSEMOVE(hwnd, wParam, lParam, fn) \ |
| 4249 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4250 | # endif |
| 4251 | # ifndef HANDLE_WM_RBUTTONUP |
| 4252 | # define HANDLE_WM_RBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 4253 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4254 | # endif |
| 4255 | # ifndef HANDLE_WM_MBUTTONDOWN |
| 4256 | # define HANDLE_WM_MBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 4257 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4258 | # endif |
| 4259 | # ifndef HANDLE_WM_LBUTTONUP |
| 4260 | # define HANDLE_WM_LBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 4261 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4262 | # endif |
| 4263 | # ifndef HANDLE_WM_LBUTTONDOWN |
| 4264 | # define HANDLE_WM_LBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 4265 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 4266 | # endif |
| 4267 | # ifndef HANDLE_WM_SYSCHAR |
| 4268 | # define HANDLE_WM_SYSCHAR(hwnd, wParam, lParam, fn) \ |
| 4269 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 4270 | # endif |
| 4271 | # ifndef HANDLE_WM_ACTIVATEAPP |
| 4272 | # define HANDLE_WM_ACTIVATEAPP(hwnd, wParam, lParam, fn) \ |
| 4273 | ((fn)((hwnd), (BOOL)(wParam), (DWORD)(lParam)), 0L) |
| 4274 | # endif |
| 4275 | # ifndef HANDLE_WM_WINDOWPOSCHANGING |
| 4276 | # define HANDLE_WM_WINDOWPOSCHANGING(hwnd, wParam, lParam, fn) \ |
| 4277 | (LRESULT)(DWORD)(BOOL)(fn)((hwnd), (LPWINDOWPOS)(lParam)) |
| 4278 | # endif |
| 4279 | # ifndef HANDLE_WM_VSCROLL |
| 4280 | # define HANDLE_WM_VSCROLL(hwnd, wParam, lParam, fn) \ |
| 4281 | ((fn)((hwnd), (HWND)(lParam), (UINT)(LOWORD(wParam)), (int)(short)HIWORD(wParam)), 0L) |
| 4282 | # endif |
| 4283 | # ifndef HANDLE_WM_SETFOCUS |
| 4284 | # define HANDLE_WM_SETFOCUS(hwnd, wParam, lParam, fn) \ |
| 4285 | ((fn)((hwnd), (HWND)(wParam)), 0L) |
| 4286 | # endif |
| 4287 | # ifndef HANDLE_WM_KILLFOCUS |
| 4288 | # define HANDLE_WM_KILLFOCUS(hwnd, wParam, lParam, fn) \ |
| 4289 | ((fn)((hwnd), (HWND)(wParam)), 0L) |
| 4290 | # endif |
| 4291 | # ifndef HANDLE_WM_HSCROLL |
| 4292 | # define HANDLE_WM_HSCROLL(hwnd, wParam, lParam, fn) \ |
| 4293 | ((fn)((hwnd), (HWND)(lParam), (UINT)(LOWORD(wParam)), (int)(short)HIWORD(wParam)), 0L) |
| 4294 | # endif |
| 4295 | # ifndef HANDLE_WM_DROPFILES |
| 4296 | # define HANDLE_WM_DROPFILES(hwnd, wParam, lParam, fn) \ |
| 4297 | ((fn)((hwnd), (HDROP)(wParam)), 0L) |
| 4298 | # endif |
| 4299 | # ifndef HANDLE_WM_CHAR |
| 4300 | # define HANDLE_WM_CHAR(hwnd, wParam, lParam, fn) \ |
| 4301 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 4302 | # endif |
| 4303 | # ifndef HANDLE_WM_SYSDEADCHAR |
| 4304 | # define HANDLE_WM_SYSDEADCHAR(hwnd, wParam, lParam, fn) \ |
| 4305 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 4306 | # endif |
| 4307 | # ifndef HANDLE_WM_DEADCHAR |
| 4308 | # define HANDLE_WM_DEADCHAR(hwnd, wParam, lParam, fn) \ |
| 4309 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 4310 | # endif |
| 4311 | #endif /* __MINGW32__ */ |
| 4312 | |
| 4313 | |
| 4314 | /* Some parameters for tearoff menus. All in pixels. */ |
| 4315 | #define TEAROFF_PADDING_X 2 |
| 4316 | #define TEAROFF_BUTTON_PAD_X 8 |
| 4317 | #define TEAROFF_MIN_WIDTH 200 |
| 4318 | #define TEAROFF_SUBMENU_LABEL ">>" |
| 4319 | #define TEAROFF_COLUMN_PADDING 3 // # spaces to pad column with. |
| 4320 | |
| 4321 | |
| 4322 | /* For the Intellimouse: */ |
| 4323 | #ifndef WM_MOUSEWHEEL |
| 4324 | #define WM_MOUSEWHEEL 0x20a |
| 4325 | #endif |
| 4326 | |
| 4327 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 4328 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4329 | # define ID_BEVAL_TOOLTIP 200 |
| 4330 | # define BEVAL_TEXT_LEN MAXPATHL |
| 4331 | |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 4332 | #if (defined(_MSC_VER) && _MSC_VER < 1300) || !defined(MAXULONG_PTR) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4333 | /* Work around old versions of basetsd.h which wrongly declares |
| 4334 | * UINT_PTR as unsigned long. */ |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 4335 | # undef UINT_PTR |
Bram Moolenaar | 8424a62 | 2006-04-19 21:23:36 +0000 | [diff] [blame] | 4336 | # define UINT_PTR UINT |
| 4337 | #endif |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4338 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4339 | static BalloonEval *cur_beval = NULL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4340 | static UINT_PTR BevalTimerId = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4341 | static DWORD LastActivity = 0; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4342 | |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 4343 | |
| 4344 | /* cproto fails on missing include files */ |
| 4345 | #ifndef PROTO |
| 4346 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4347 | /* |
| 4348 | * excerpts from headers since this may not be presented |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4349 | * in the extremely old compilers |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4350 | */ |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 4351 | # include <pshpack1.h> |
| 4352 | |
| 4353 | #endif |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4354 | |
| 4355 | typedef struct _DllVersionInfo |
| 4356 | { |
| 4357 | DWORD cbSize; |
| 4358 | DWORD dwMajorVersion; |
| 4359 | DWORD dwMinorVersion; |
| 4360 | DWORD dwBuildNumber; |
| 4361 | DWORD dwPlatformID; |
| 4362 | } DLLVERSIONINFO; |
| 4363 | |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 4364 | #ifndef PROTO |
| 4365 | # include <poppack.h> |
| 4366 | #endif |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 4367 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4368 | typedef struct tagTOOLINFOA_NEW |
| 4369 | { |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 4370 | UINT cbSize; |
| 4371 | UINT uFlags; |
| 4372 | HWND hwnd; |
| 4373 | UINT_PTR uId; |
| 4374 | RECT rect; |
| 4375 | HINSTANCE hinst; |
| 4376 | LPSTR lpszText; |
| 4377 | LPARAM lParam; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4378 | } TOOLINFO_NEW; |
| 4379 | |
| 4380 | typedef struct tagNMTTDISPINFO_NEW |
| 4381 | { |
| 4382 | NMHDR hdr; |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 4383 | LPSTR lpszText; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4384 | char szText[80]; |
| 4385 | HINSTANCE hinst; |
| 4386 | UINT uFlags; |
| 4387 | LPARAM lParam; |
| 4388 | } NMTTDISPINFO_NEW; |
| 4389 | |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 4390 | #ifdef FEAT_MBYTE |
| 4391 | typedef struct tagTOOLINFOW_NEW |
| 4392 | { |
| 4393 | UINT cbSize; |
| 4394 | UINT uFlags; |
| 4395 | HWND hwnd; |
| 4396 | UINT_PTR uId; |
| 4397 | RECT rect; |
| 4398 | HINSTANCE hinst; |
| 4399 | LPWSTR lpszText; |
| 4400 | LPARAM lParam; |
| 4401 | void *lpReserved; |
| 4402 | } TOOLINFOW_NEW; |
| 4403 | |
| 4404 | typedef struct tagNMTTDISPINFOW_NEW |
| 4405 | { |
| 4406 | NMHDR hdr; |
| 4407 | LPWSTR lpszText; |
| 4408 | WCHAR szText[80]; |
| 4409 | HINSTANCE hinst; |
| 4410 | UINT uFlags; |
| 4411 | LPARAM lParam; |
| 4412 | } NMTTDISPINFOW_NEW; |
| 4413 | |
| 4414 | #endif |
| 4415 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4416 | typedef HRESULT (WINAPI* DLLGETVERSIONPROC)(DLLVERSIONINFO *); |
| 4417 | #ifndef TTM_SETMAXTIPWIDTH |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4418 | # define TTM_SETMAXTIPWIDTH (WM_USER+24) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4419 | #endif |
| 4420 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4421 | #ifndef TTF_DI_SETITEM |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4422 | # define TTF_DI_SETITEM 0x8000 |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4423 | #endif |
| 4424 | |
| 4425 | #ifndef TTN_GETDISPINFO |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4426 | # define TTN_GETDISPINFO (TTN_FIRST - 0) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4427 | #endif |
| 4428 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 4429 | #endif /* defined(FEAT_BEVAL_GUI) */ |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4430 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 4431 | #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
| 4432 | /* Older MSVC compilers don't have LPNMTTDISPINFO[AW] thus we need to define |
| 4433 | * it here if LPNMTTDISPINFO isn't defined. |
| 4434 | * MingW doesn't define LPNMTTDISPINFO but typedefs it. Thus we need to check |
| 4435 | * _MSC_VER. */ |
| 4436 | # if !defined(LPNMTTDISPINFO) && defined(_MSC_VER) |
| 4437 | typedef struct tagNMTTDISPINFOA { |
| 4438 | NMHDR hdr; |
| 4439 | LPSTR lpszText; |
| 4440 | char szText[80]; |
| 4441 | HINSTANCE hinst; |
| 4442 | UINT uFlags; |
| 4443 | LPARAM lParam; |
| 4444 | } NMTTDISPINFOA, *LPNMTTDISPINFOA; |
| 4445 | # define LPNMTTDISPINFO LPNMTTDISPINFOA |
| 4446 | |
| 4447 | # ifdef FEAT_MBYTE |
| 4448 | typedef struct tagNMTTDISPINFOW { |
| 4449 | NMHDR hdr; |
| 4450 | LPWSTR lpszText; |
| 4451 | WCHAR szText[80]; |
| 4452 | HINSTANCE hinst; |
| 4453 | UINT uFlags; |
| 4454 | LPARAM lParam; |
| 4455 | } NMTTDISPINFOW, *LPNMTTDISPINFOW; |
| 4456 | # endif |
| 4457 | # endif |
| 4458 | #endif |
| 4459 | |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4460 | #ifndef TTN_GETDISPINFOW |
| 4461 | # define TTN_GETDISPINFOW (TTN_FIRST - 10) |
| 4462 | #endif |
| 4463 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4464 | /* Local variables: */ |
| 4465 | |
| 4466 | #ifdef FEAT_MENU |
| 4467 | static UINT s_menu_id = 100; |
Bram Moolenaar | 786989b | 2010-10-27 12:15:33 +0200 | [diff] [blame] | 4468 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4469 | |
| 4470 | /* |
| 4471 | * Use the system font for dialogs and tear-off menus. Remove this line to |
| 4472 | * use DLG_FONT_NAME. |
| 4473 | */ |
Bram Moolenaar | 786989b | 2010-10-27 12:15:33 +0200 | [diff] [blame] | 4474 | #define USE_SYSMENU_FONT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4475 | |
| 4476 | #define VIM_NAME "vim" |
| 4477 | #define VIM_CLASS "Vim" |
| 4478 | #define VIM_CLASSW L"Vim" |
| 4479 | |
| 4480 | /* Initial size for the dialog template. For gui_mch_dialog() it's fixed, |
| 4481 | * thus there should be room for every dialog. For tearoffs it's made bigger |
| 4482 | * when needed. */ |
| 4483 | #define DLG_ALLOC_SIZE 16 * 1024 |
| 4484 | |
| 4485 | /* |
| 4486 | * stuff for dialogs, menus, tearoffs etc. |
| 4487 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4488 | static PWORD |
| 4489 | add_dialog_element( |
| 4490 | PWORD p, |
| 4491 | DWORD lStyle, |
| 4492 | WORD x, |
| 4493 | WORD y, |
| 4494 | WORD w, |
| 4495 | WORD h, |
| 4496 | WORD Id, |
| 4497 | WORD clss, |
| 4498 | const char *caption); |
| 4499 | static LPWORD lpwAlign(LPWORD); |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 4500 | static int nCopyAnsiToWideChar(LPWORD, LPSTR, BOOL); |
Bram Moolenaar | 065bbac | 2016-02-20 13:08:46 +0100 | [diff] [blame] | 4501 | #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4502 | static void gui_mch_tearoff(char_u *title, vimmenu_T *menu, int initX, int initY); |
Bram Moolenaar | 065bbac | 2016-02-20 13:08:46 +0100 | [diff] [blame] | 4503 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4504 | static void get_dialog_font_metrics(void); |
| 4505 | |
| 4506 | static int dialog_default_button = -1; |
| 4507 | |
| 4508 | /* Intellimouse support */ |
| 4509 | static int mouse_scroll_lines = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4510 | |
| 4511 | static int s_usenewlook; /* emulate W95/NT4 non-bold dialogs */ |
| 4512 | #ifdef FEAT_TOOLBAR |
| 4513 | static void initialise_toolbar(void); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4514 | static LRESULT CALLBACK toolbar_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4515 | static int get_toolbar_bitmap(vimmenu_T *menu); |
| 4516 | #endif |
| 4517 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4518 | #ifdef FEAT_GUI_TABLINE |
| 4519 | static void initialise_tabline(void); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4520 | static LRESULT CALLBACK tabline_wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4521 | #endif |
| 4522 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4523 | #ifdef FEAT_MBYTE_IME |
| 4524 | static LRESULT _OnImeComposition(HWND hwnd, WPARAM dbcs, LPARAM param); |
| 4525 | static char_u *GetResultStr(HWND hwnd, int GCS, int *lenp); |
| 4526 | #endif |
| 4527 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 4528 | # ifdef NOIME |
| 4529 | typedef struct tagCOMPOSITIONFORM { |
| 4530 | DWORD dwStyle; |
| 4531 | POINT ptCurrentPos; |
| 4532 | RECT rcArea; |
| 4533 | } COMPOSITIONFORM, *PCOMPOSITIONFORM, NEAR *NPCOMPOSITIONFORM, FAR *LPCOMPOSITIONFORM; |
| 4534 | typedef HANDLE HIMC; |
| 4535 | # endif |
| 4536 | |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 4537 | static HINSTANCE hLibImm = NULL; |
| 4538 | static LONG (WINAPI *pImmGetCompositionStringA)(HIMC, DWORD, LPVOID, DWORD); |
| 4539 | static LONG (WINAPI *pImmGetCompositionStringW)(HIMC, DWORD, LPVOID, DWORD); |
| 4540 | static HIMC (WINAPI *pImmGetContext)(HWND); |
| 4541 | static HIMC (WINAPI *pImmAssociateContext)(HWND, HIMC); |
| 4542 | static BOOL (WINAPI *pImmReleaseContext)(HWND, HIMC); |
| 4543 | static BOOL (WINAPI *pImmGetOpenStatus)(HIMC); |
| 4544 | static BOOL (WINAPI *pImmSetOpenStatus)(HIMC, BOOL); |
| 4545 | static BOOL (WINAPI *pImmGetCompositionFont)(HIMC, LPLOGFONTA); |
| 4546 | static BOOL (WINAPI *pImmSetCompositionFont)(HIMC, LPLOGFONTA); |
| 4547 | static BOOL (WINAPI *pImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM); |
| 4548 | static BOOL (WINAPI *pImmGetConversionStatus)(HIMC, LPDWORD, LPDWORD); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4549 | static BOOL (WINAPI *pImmSetConversionStatus)(HIMC, DWORD, DWORD); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4550 | static void dyn_imm_load(void); |
| 4551 | #else |
| 4552 | # define pImmGetCompositionStringA ImmGetCompositionStringA |
| 4553 | # define pImmGetCompositionStringW ImmGetCompositionStringW |
| 4554 | # define pImmGetContext ImmGetContext |
| 4555 | # define pImmAssociateContext ImmAssociateContext |
| 4556 | # define pImmReleaseContext ImmReleaseContext |
| 4557 | # define pImmGetOpenStatus ImmGetOpenStatus |
| 4558 | # define pImmSetOpenStatus ImmSetOpenStatus |
| 4559 | # define pImmGetCompositionFont ImmGetCompositionFontA |
| 4560 | # define pImmSetCompositionFont ImmSetCompositionFontA |
| 4561 | # define pImmSetCompositionWindow ImmSetCompositionWindow |
| 4562 | # define pImmGetConversionStatus ImmGetConversionStatus |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4563 | # define pImmSetConversionStatus ImmSetConversionStatus |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4564 | #endif |
| 4565 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4566 | #ifdef FEAT_MENU |
| 4567 | /* |
| 4568 | * Figure out how high the menu bar is at the moment. |
| 4569 | */ |
| 4570 | static int |
| 4571 | gui_mswin_get_menu_height( |
| 4572 | int fix_window) /* If TRUE, resize window if menu height changed */ |
| 4573 | { |
| 4574 | static int old_menu_height = -1; |
| 4575 | |
| 4576 | RECT rc1, rc2; |
| 4577 | int num; |
| 4578 | int menu_height; |
| 4579 | |
| 4580 | if (gui.menu_is_active) |
| 4581 | num = GetMenuItemCount(s_menuBar); |
| 4582 | else |
| 4583 | num = 0; |
| 4584 | |
| 4585 | if (num == 0) |
| 4586 | menu_height = 0; |
Bram Moolenaar | 71371b1 | 2015-03-24 17:57:12 +0100 | [diff] [blame] | 4587 | else if (IsMinimized(s_hwnd)) |
| 4588 | { |
| 4589 | /* The height of the menu cannot be determined while the window is |
| 4590 | * minimized. Take the previous height if the menu is changed in that |
| 4591 | * state, to avoid that Vim's vertical window size accidentally |
| 4592 | * increases due to the unaccounted-for menu height. */ |
| 4593 | menu_height = old_menu_height == -1 ? 0 : old_menu_height; |
| 4594 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4595 | else |
| 4596 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4597 | /* |
| 4598 | * In case 'lines' is set in _vimrc/_gvimrc window width doesn't |
| 4599 | * seem to have been set yet, so menu wraps in default window |
| 4600 | * width which is very narrow. Instead just return height of a |
| 4601 | * single menu item. Will still be wrong when the menu really |
| 4602 | * should wrap over more than one line. |
| 4603 | */ |
| 4604 | GetMenuItemRect(s_hwnd, s_menuBar, 0, &rc1); |
| 4605 | if (gui.starting) |
| 4606 | menu_height = rc1.bottom - rc1.top + 1; |
| 4607 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4608 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4609 | GetMenuItemRect(s_hwnd, s_menuBar, num - 1, &rc2); |
| 4610 | menu_height = rc2.bottom - rc1.top + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | if (fix_window && menu_height != old_menu_height) |
| 4615 | { |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4616 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4617 | } |
Bram Moolenaar | 71371b1 | 2015-03-24 17:57:12 +0100 | [diff] [blame] | 4618 | old_menu_height = menu_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4619 | |
| 4620 | return menu_height; |
| 4621 | } |
| 4622 | #endif /*FEAT_MENU*/ |
| 4623 | |
| 4624 | |
| 4625 | /* |
| 4626 | * Setup for the Intellimouse |
| 4627 | */ |
| 4628 | static void |
| 4629 | init_mouse_wheel(void) |
| 4630 | { |
| 4631 | |
| 4632 | #ifndef SPI_GETWHEELSCROLLLINES |
| 4633 | # define SPI_GETWHEELSCROLLLINES 104 |
| 4634 | #endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4635 | #ifndef SPI_SETWHEELSCROLLLINES |
| 4636 | # define SPI_SETWHEELSCROLLLINES 105 |
| 4637 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4638 | |
| 4639 | #define VMOUSEZ_CLASSNAME "MouseZ" /* hidden wheel window class */ |
| 4640 | #define VMOUSEZ_TITLE "Magellan MSWHEEL" /* hidden wheel window title */ |
| 4641 | #define VMSH_MOUSEWHEEL "MSWHEEL_ROLLMSG" |
| 4642 | #define VMSH_SCROLL_LINES "MSH_SCROLL_LINES_MSG" |
| 4643 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4644 | mouse_scroll_lines = 3; /* reasonable default */ |
| 4645 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4646 | /* if NT 4.0+ (or Win98) get scroll lines directly from system */ |
| 4647 | SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, |
| 4648 | &mouse_scroll_lines, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | |
| 4652 | /* Intellimouse wheel handler */ |
| 4653 | static void |
| 4654 | _OnMouseWheel( |
| 4655 | HWND hwnd, |
| 4656 | short zDelta) |
| 4657 | { |
| 4658 | /* Treat a mouse wheel event as if it were a scroll request */ |
| 4659 | int i; |
| 4660 | int size; |
| 4661 | HWND hwndCtl; |
| 4662 | |
| 4663 | if (curwin->w_scrollbars[SBAR_RIGHT].id != 0) |
| 4664 | { |
| 4665 | hwndCtl = curwin->w_scrollbars[SBAR_RIGHT].id; |
| 4666 | size = curwin->w_scrollbars[SBAR_RIGHT].size; |
| 4667 | } |
| 4668 | else if (curwin->w_scrollbars[SBAR_LEFT].id != 0) |
| 4669 | { |
| 4670 | hwndCtl = curwin->w_scrollbars[SBAR_LEFT].id; |
| 4671 | size = curwin->w_scrollbars[SBAR_LEFT].size; |
| 4672 | } |
| 4673 | else |
| 4674 | return; |
| 4675 | |
| 4676 | size = curwin->w_height; |
| 4677 | if (mouse_scroll_lines == 0) |
| 4678 | init_mouse_wheel(); |
| 4679 | |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 4680 | mch_disable_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4681 | if (mouse_scroll_lines > 0 |
| 4682 | && mouse_scroll_lines < (size > 2 ? size - 2 : 1)) |
| 4683 | { |
| 4684 | for (i = mouse_scroll_lines; i > 0; --i) |
| 4685 | _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_LINEUP : SB_LINEDOWN, 0); |
| 4686 | } |
| 4687 | else |
| 4688 | _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_PAGEUP : SB_PAGEDOWN, 0); |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 4689 | mch_enable_flush(); |
| 4690 | gui_may_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4691 | } |
| 4692 | |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4693 | #ifdef USE_SYSMENU_FONT |
| 4694 | /* |
| 4695 | * Get Menu Font. |
| 4696 | * Return OK or FAIL. |
| 4697 | */ |
| 4698 | static int |
| 4699 | gui_w32_get_menu_font(LOGFONT *lf) |
| 4700 | { |
| 4701 | NONCLIENTMETRICS nm; |
| 4702 | |
| 4703 | nm.cbSize = sizeof(NONCLIENTMETRICS); |
| 4704 | if (!SystemParametersInfo( |
| 4705 | SPI_GETNONCLIENTMETRICS, |
| 4706 | sizeof(NONCLIENTMETRICS), |
| 4707 | &nm, |
| 4708 | 0)) |
| 4709 | return FAIL; |
| 4710 | *lf = nm.lfMenuFont; |
| 4711 | return OK; |
| 4712 | } |
| 4713 | #endif |
| 4714 | |
| 4715 | |
| 4716 | #if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT) |
| 4717 | /* |
| 4718 | * Set the GUI tabline font to the system menu font |
| 4719 | */ |
| 4720 | static void |
| 4721 | set_tabline_font(void) |
| 4722 | { |
| 4723 | LOGFONT lfSysmenu; |
| 4724 | HFONT font; |
| 4725 | HWND hwnd; |
| 4726 | HDC hdc; |
| 4727 | HFONT hfntOld; |
| 4728 | TEXTMETRIC tm; |
| 4729 | |
| 4730 | if (gui_w32_get_menu_font(&lfSysmenu) != OK) |
| 4731 | return; |
| 4732 | |
| 4733 | font = CreateFontIndirect(&lfSysmenu); |
| 4734 | |
| 4735 | SendMessage(s_tabhwnd, WM_SETFONT, (WPARAM)font, TRUE); |
| 4736 | |
| 4737 | /* |
| 4738 | * Compute the height of the font used for the tab text |
| 4739 | */ |
| 4740 | hwnd = GetDesktopWindow(); |
| 4741 | hdc = GetWindowDC(hwnd); |
| 4742 | hfntOld = SelectFont(hdc, font); |
| 4743 | |
| 4744 | GetTextMetrics(hdc, &tm); |
| 4745 | |
| 4746 | SelectFont(hdc, hfntOld); |
| 4747 | ReleaseDC(hwnd, hdc); |
| 4748 | |
| 4749 | /* |
| 4750 | * The space used by the tab border and the space between the tab label |
| 4751 | * and the tab border is included as 7. |
| 4752 | */ |
| 4753 | gui.tabline_height = tm.tmHeight + tm.tmInternalLeading + 7; |
| 4754 | } |
| 4755 | #endif |
| 4756 | |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 4757 | /* |
| 4758 | * Invoked when a setting was changed. |
| 4759 | */ |
| 4760 | static LRESULT CALLBACK |
| 4761 | _OnSettingChange(UINT n) |
| 4762 | { |
| 4763 | if (n == SPI_SETWHEELSCROLLLINES) |
| 4764 | SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, |
| 4765 | &mouse_scroll_lines, 0); |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4766 | #if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT) |
| 4767 | if (n == SPI_SETNONCLIENTMETRICS) |
| 4768 | set_tabline_font(); |
| 4769 | #endif |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 4770 | return 0; |
| 4771 | } |
| 4772 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4773 | #ifdef FEAT_NETBEANS_INTG |
| 4774 | static void |
| 4775 | _OnWindowPosChanged( |
| 4776 | HWND hwnd, |
| 4777 | const LPWINDOWPOS lpwpos) |
| 4778 | { |
| 4779 | static int x = 0, y = 0, cx = 0, cy = 0; |
Bram Moolenaar | f12d983 | 2016-01-29 21:11:25 +0100 | [diff] [blame] | 4780 | extern int WSInitialized; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4781 | |
| 4782 | if (WSInitialized && (lpwpos->x != x || lpwpos->y != y |
| 4783 | || lpwpos->cx != cx || lpwpos->cy != cy)) |
| 4784 | { |
| 4785 | x = lpwpos->x; |
| 4786 | y = lpwpos->y; |
| 4787 | cx = lpwpos->cx; |
| 4788 | cy = lpwpos->cy; |
| 4789 | netbeans_frame_moved(x, y); |
| 4790 | } |
| 4791 | /* Allow to send WM_SIZE and WM_MOVE */ |
| 4792 | FORWARD_WM_WINDOWPOSCHANGED(hwnd, lpwpos, MyWindowProc); |
| 4793 | } |
| 4794 | #endif |
| 4795 | |
| 4796 | static int |
| 4797 | _DuringSizing( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4798 | UINT fwSide, |
| 4799 | LPRECT lprc) |
| 4800 | { |
| 4801 | int w, h; |
| 4802 | int valid_w, valid_h; |
| 4803 | int w_offset, h_offset; |
| 4804 | |
| 4805 | w = lprc->right - lprc->left; |
| 4806 | h = lprc->bottom - lprc->top; |
| 4807 | gui_mswin_get_valid_dimensions(w, h, &valid_w, &valid_h); |
| 4808 | w_offset = w - valid_w; |
| 4809 | h_offset = h - valid_h; |
| 4810 | |
| 4811 | if (fwSide == WMSZ_LEFT || fwSide == WMSZ_TOPLEFT |
| 4812 | || fwSide == WMSZ_BOTTOMLEFT) |
| 4813 | lprc->left += w_offset; |
| 4814 | else if (fwSide == WMSZ_RIGHT || fwSide == WMSZ_TOPRIGHT |
| 4815 | || fwSide == WMSZ_BOTTOMRIGHT) |
| 4816 | lprc->right -= w_offset; |
| 4817 | |
| 4818 | if (fwSide == WMSZ_TOP || fwSide == WMSZ_TOPLEFT |
| 4819 | || fwSide == WMSZ_TOPRIGHT) |
| 4820 | lprc->top += h_offset; |
| 4821 | else if (fwSide == WMSZ_BOTTOM || fwSide == WMSZ_BOTTOMLEFT |
| 4822 | || fwSide == WMSZ_BOTTOMRIGHT) |
| 4823 | lprc->bottom -= h_offset; |
| 4824 | return TRUE; |
| 4825 | } |
| 4826 | |
| 4827 | |
| 4828 | |
| 4829 | static LRESULT CALLBACK |
| 4830 | _WndProc( |
| 4831 | HWND hwnd, |
| 4832 | UINT uMsg, |
| 4833 | WPARAM wParam, |
| 4834 | LPARAM lParam) |
| 4835 | { |
| 4836 | /* |
| 4837 | TRACE("WndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n", |
| 4838 | hwnd, uMsg, wParam, lParam); |
| 4839 | */ |
| 4840 | |
| 4841 | HandleMouseHide(uMsg, lParam); |
| 4842 | |
| 4843 | s_uMsg = uMsg; |
| 4844 | s_wParam = wParam; |
| 4845 | s_lParam = lParam; |
| 4846 | |
| 4847 | switch (uMsg) |
| 4848 | { |
| 4849 | HANDLE_MSG(hwnd, WM_DEADCHAR, _OnDeadChar); |
| 4850 | HANDLE_MSG(hwnd, WM_SYSDEADCHAR, _OnDeadChar); |
| 4851 | /* HANDLE_MSG(hwnd, WM_ACTIVATE, _OnActivate); */ |
| 4852 | HANDLE_MSG(hwnd, WM_CLOSE, _OnClose); |
| 4853 | /* HANDLE_MSG(hwnd, WM_COMMAND, _OnCommand); */ |
| 4854 | HANDLE_MSG(hwnd, WM_DESTROY, _OnDestroy); |
| 4855 | HANDLE_MSG(hwnd, WM_DROPFILES, _OnDropFiles); |
| 4856 | HANDLE_MSG(hwnd, WM_HSCROLL, _OnScroll); |
| 4857 | HANDLE_MSG(hwnd, WM_KILLFOCUS, _OnKillFocus); |
| 4858 | #ifdef FEAT_MENU |
| 4859 | HANDLE_MSG(hwnd, WM_COMMAND, _OnMenu); |
| 4860 | #endif |
| 4861 | /* HANDLE_MSG(hwnd, WM_MOVE, _OnMove); */ |
| 4862 | /* HANDLE_MSG(hwnd, WM_NCACTIVATE, _OnNCActivate); */ |
| 4863 | HANDLE_MSG(hwnd, WM_SETFOCUS, _OnSetFocus); |
| 4864 | HANDLE_MSG(hwnd, WM_SIZE, _OnSize); |
| 4865 | /* HANDLE_MSG(hwnd, WM_SYSCOMMAND, _OnSysCommand); */ |
| 4866 | /* HANDLE_MSG(hwnd, WM_SYSKEYDOWN, _OnAltKey); */ |
| 4867 | HANDLE_MSG(hwnd, WM_VSCROLL, _OnScroll); |
| 4868 | // HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, _OnWindowPosChanging); |
| 4869 | HANDLE_MSG(hwnd, WM_ACTIVATEAPP, _OnActivateApp); |
| 4870 | #ifdef FEAT_NETBEANS_INTG |
| 4871 | HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGED, _OnWindowPosChanged); |
| 4872 | #endif |
| 4873 | |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4874 | #ifdef FEAT_GUI_TABLINE |
| 4875 | case WM_RBUTTONUP: |
| 4876 | { |
| 4877 | if (gui_mch_showing_tabline()) |
| 4878 | { |
| 4879 | POINT pt; |
| 4880 | RECT rect; |
| 4881 | |
| 4882 | /* |
| 4883 | * If the cursor is on the tabline, display the tab menu |
| 4884 | */ |
| 4885 | GetCursorPos((LPPOINT)&pt); |
| 4886 | GetWindowRect(s_textArea, &rect); |
| 4887 | if (pt.y < rect.top) |
| 4888 | { |
| 4889 | show_tabline_popup_menu(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4890 | return 0L; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4891 | } |
| 4892 | } |
| 4893 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4894 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4895 | case WM_LBUTTONDBLCLK: |
| 4896 | { |
| 4897 | /* |
| 4898 | * If the user double clicked the tabline, create a new tab |
| 4899 | */ |
| 4900 | if (gui_mch_showing_tabline()) |
| 4901 | { |
| 4902 | POINT pt; |
| 4903 | RECT rect; |
| 4904 | |
| 4905 | GetCursorPos((LPPOINT)&pt); |
| 4906 | GetWindowRect(s_textArea, &rect); |
| 4907 | if (pt.y < rect.top) |
Bram Moolenaar | c6fe919 | 2006-04-09 21:54:49 +0000 | [diff] [blame] | 4908 | send_tabline_menu_event(0, TABLINE_MENU_NEW); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4909 | } |
| 4910 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4911 | } |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4912 | #endif |
| 4913 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4914 | case WM_QUERYENDSESSION: /* System wants to go down. */ |
| 4915 | gui_shell_closed(); /* Will exit when no changed buffers. */ |
| 4916 | return FALSE; /* Do NOT allow system to go down. */ |
| 4917 | |
| 4918 | case WM_ENDSESSION: |
| 4919 | if (wParam) /* system only really goes down when wParam is TRUE */ |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4920 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4921 | _OnEndSession(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4922 | return 0L; |
| 4923 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4924 | break; |
| 4925 | |
| 4926 | case WM_CHAR: |
| 4927 | /* Don't use HANDLE_MSG() for WM_CHAR, it truncates wParam to a single |
| 4928 | * byte while we want the UTF-16 character value. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4929 | _OnChar(hwnd, (UINT)wParam, (int)(short)LOWORD(lParam)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4930 | return 0L; |
| 4931 | |
| 4932 | case WM_SYSCHAR: |
| 4933 | /* |
| 4934 | * if 'winaltkeys' is "no", or it's "menu" and it's not a menu |
| 4935 | * shortcut key, handle like a typed ALT key, otherwise call Windows |
| 4936 | * ALT key handling. |
| 4937 | */ |
| 4938 | #ifdef FEAT_MENU |
| 4939 | if ( !gui.menu_is_active |
| 4940 | || p_wak[0] == 'n' |
| 4941 | || (p_wak[0] == 'm' && !gui_is_menu_shortcut((int)wParam)) |
| 4942 | ) |
| 4943 | #endif |
| 4944 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4945 | _OnSysChar(hwnd, (UINT)wParam, (int)(short)LOWORD(lParam)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4946 | return 0L; |
| 4947 | } |
| 4948 | #ifdef FEAT_MENU |
| 4949 | else |
| 4950 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4951 | #endif |
| 4952 | |
| 4953 | case WM_SYSKEYUP: |
| 4954 | #ifdef FEAT_MENU |
| 4955 | /* This used to be done only when menu is active: ALT key is used for |
| 4956 | * that. But that caused problems when menu is disabled and using |
| 4957 | * Alt-Tab-Esc: get into a strange state where no mouse-moved events |
| 4958 | * are received, mouse pointer remains hidden. */ |
| 4959 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4960 | #else |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4961 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4962 | #endif |
| 4963 | |
| 4964 | case WM_SIZING: /* HANDLE_MSG doesn't seem to handle this one */ |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4965 | return _DuringSizing((UINT)wParam, (LPRECT)lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4966 | |
| 4967 | case WM_MOUSEWHEEL: |
| 4968 | _OnMouseWheel(hwnd, HIWORD(wParam)); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4969 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4970 | |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 4971 | /* Notification for change in SystemParametersInfo() */ |
| 4972 | case WM_SETTINGCHANGE: |
| 4973 | return _OnSettingChange((UINT)wParam); |
| 4974 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4975 | #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4976 | case WM_NOTIFY: |
| 4977 | switch (((LPNMHDR) lParam)->code) |
| 4978 | { |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4979 | # ifdef FEAT_MBYTE |
| 4980 | case TTN_GETDISPINFOW: |
| 4981 | # endif |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4982 | case TTN_GETDISPINFO: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4983 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4984 | LPNMHDR hdr = (LPNMHDR)lParam; |
| 4985 | char_u *str = NULL; |
| 4986 | static void *tt_text = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4987 | |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 4988 | VIM_CLEAR(tt_text); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4989 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4990 | # ifdef FEAT_GUI_TABLINE |
| 4991 | if (gui_mch_showing_tabline() |
| 4992 | && hdr->hwndFrom == TabCtrl_GetToolTips(s_tabhwnd)) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4993 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4994 | POINT pt; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4995 | /* |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4996 | * Mouse is over the GUI tabline. Display the |
| 4997 | * tooltip for the tab under the cursor |
| 4998 | * |
| 4999 | * Get the cursor position within the tab control |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5000 | */ |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5001 | GetCursorPos(&pt); |
| 5002 | if (ScreenToClient(s_tabhwnd, &pt) != 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5003 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5004 | TCHITTESTINFO htinfo; |
| 5005 | int idx; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5006 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5007 | /* |
| 5008 | * Get the tab under the cursor |
| 5009 | */ |
| 5010 | htinfo.pt.x = pt.x; |
| 5011 | htinfo.pt.y = pt.y; |
| 5012 | idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 5013 | if (idx != -1) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5014 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5015 | tabpage_T *tp; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5016 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5017 | tp = find_tabpage(idx + 1); |
| 5018 | if (tp != NULL) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5019 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5020 | get_tabline_label(tp, TRUE); |
| 5021 | str = NameBuff; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5022 | } |
| 5023 | } |
| 5024 | } |
| 5025 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5026 | # endif |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5027 | # ifdef FEAT_TOOLBAR |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5028 | # ifdef FEAT_GUI_TABLINE |
| 5029 | else |
| 5030 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5031 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5032 | UINT idButton; |
| 5033 | vimmenu_T *pMenu; |
| 5034 | |
| 5035 | idButton = (UINT) hdr->idFrom; |
| 5036 | pMenu = gui_mswin_find_menu(root_menu, idButton); |
| 5037 | if (pMenu) |
| 5038 | str = pMenu->strings[MENU_INDEX_TIP]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5039 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 5040 | # endif |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5041 | if (str != NULL) |
| 5042 | { |
| 5043 | # ifdef FEAT_MBYTE |
| 5044 | if (hdr->code == TTN_GETDISPINFOW) |
| 5045 | { |
| 5046 | LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam; |
| 5047 | |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 5048 | /* Set the maximum width, this also enables using |
| 5049 | * \n for line break. */ |
| 5050 | SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, |
| 5051 | 0, 500); |
| 5052 | |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 5053 | tt_text = enc_to_utf16(str, NULL); |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5054 | lpdi->lpszText = tt_text; |
| 5055 | /* can't show tooltip if failed */ |
| 5056 | } |
| 5057 | else |
| 5058 | # endif |
| 5059 | { |
| 5060 | LPNMTTDISPINFO lpdi = (LPNMTTDISPINFO)lParam; |
| 5061 | |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 5062 | /* Set the maximum width, this also enables using |
| 5063 | * \n for line break. */ |
| 5064 | SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, |
| 5065 | 0, 500); |
| 5066 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5067 | if (STRLEN(str) < sizeof(lpdi->szText) |
| 5068 | || ((tt_text = vim_strsave(str)) == NULL)) |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 5069 | vim_strncpy((char_u *)lpdi->szText, str, |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 5070 | sizeof(lpdi->szText) - 1); |
| 5071 | else |
| 5072 | lpdi->lpszText = tt_text; |
| 5073 | } |
| 5074 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5075 | } |
| 5076 | break; |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5077 | # ifdef FEAT_GUI_TABLINE |
| 5078 | case TCN_SELCHANGE: |
| 5079 | if (gui_mch_showing_tabline() |
| 5080 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5081 | { |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5082 | send_tabline_event(TabCtrl_GetCurSel(s_tabhwnd) + 1); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5083 | return 0L; |
| 5084 | } |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5085 | break; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5086 | |
| 5087 | case NM_RCLICK: |
| 5088 | if (gui_mch_showing_tabline() |
| 5089 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5090 | { |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5091 | show_tabline_popup_menu(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5092 | return 0L; |
| 5093 | } |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5094 | break; |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5095 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5096 | default: |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5097 | # ifdef FEAT_GUI_TABLINE |
| 5098 | if (gui_mch_showing_tabline() |
| 5099 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
| 5100 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 5101 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5102 | break; |
| 5103 | } |
| 5104 | break; |
| 5105 | #endif |
| 5106 | #if defined(MENUHINTS) && defined(FEAT_MENU) |
| 5107 | case WM_MENUSELECT: |
| 5108 | if (((UINT) HIWORD(wParam) |
| 5109 | & (0xffff ^ (MF_MOUSESELECT + MF_BITMAP + MF_POPUP))) |
| 5110 | == MF_HILITE |
| 5111 | && (State & CMDLINE) == 0) |
| 5112 | { |
| 5113 | UINT idButton; |
| 5114 | vimmenu_T *pMenu; |
| 5115 | static int did_menu_tip = FALSE; |
| 5116 | |
| 5117 | if (did_menu_tip) |
| 5118 | { |
| 5119 | msg_clr_cmdline(); |
| 5120 | setcursor(); |
| 5121 | out_flush(); |
| 5122 | did_menu_tip = FALSE; |
| 5123 | } |
| 5124 | |
| 5125 | idButton = (UINT)LOWORD(wParam); |
| 5126 | pMenu = gui_mswin_find_menu(root_menu, idButton); |
| 5127 | if (pMenu != NULL && pMenu->strings[MENU_INDEX_TIP] != 0 |
| 5128 | && GetMenuState(s_menuBar, pMenu->id, MF_BYCOMMAND) != -1) |
| 5129 | { |
Bram Moolenaar | 2d8ab99 | 2007-06-19 08:06:18 +0000 | [diff] [blame] | 5130 | ++msg_hist_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5131 | msg(pMenu->strings[MENU_INDEX_TIP]); |
Bram Moolenaar | 2d8ab99 | 2007-06-19 08:06:18 +0000 | [diff] [blame] | 5132 | --msg_hist_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5133 | setcursor(); |
| 5134 | out_flush(); |
| 5135 | did_menu_tip = TRUE; |
| 5136 | } |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5137 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5138 | } |
| 5139 | break; |
| 5140 | #endif |
| 5141 | case WM_NCHITTEST: |
| 5142 | { |
| 5143 | LRESULT result; |
| 5144 | int x, y; |
| 5145 | int xPos = GET_X_LPARAM(lParam); |
| 5146 | |
| 5147 | result = MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 5148 | if (result == HTCLIENT) |
| 5149 | { |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5150 | #ifdef FEAT_GUI_TABLINE |
| 5151 | if (gui_mch_showing_tabline()) |
| 5152 | { |
| 5153 | int yPos = GET_Y_LPARAM(lParam); |
| 5154 | RECT rct; |
| 5155 | |
| 5156 | /* If the cursor is on the GUI tabline, don't process this |
| 5157 | * event */ |
| 5158 | GetWindowRect(s_textArea, &rct); |
| 5159 | if (yPos < rct.top) |
| 5160 | return result; |
| 5161 | } |
| 5162 | #endif |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 5163 | (void)gui_mch_get_winpos(&x, &y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5164 | xPos -= x; |
| 5165 | |
| 5166 | if (xPos < 48) /* <VN> TODO should use system metric? */ |
| 5167 | return HTBOTTOMLEFT; |
| 5168 | else |
| 5169 | return HTBOTTOMRIGHT; |
| 5170 | } |
| 5171 | else |
| 5172 | return result; |
| 5173 | } |
| 5174 | /* break; notreached */ |
| 5175 | |
| 5176 | #ifdef FEAT_MBYTE_IME |
| 5177 | case WM_IME_NOTIFY: |
| 5178 | if (!_OnImeNotify(hwnd, (DWORD)wParam, (DWORD)lParam)) |
| 5179 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5180 | return 1L; |
| 5181 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5182 | case WM_IME_COMPOSITION: |
| 5183 | if (!_OnImeComposition(hwnd, wParam, lParam)) |
| 5184 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 5185 | return 1L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5186 | #endif |
| 5187 | |
| 5188 | default: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5189 | #ifdef MSWIN_FIND_REPLACE |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5190 | if (uMsg == s_findrep_msg && s_findrep_msg != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5191 | { |
| 5192 | _OnFindRepl(); |
| 5193 | } |
| 5194 | #endif |
| 5195 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 5196 | } |
| 5197 | |
Bram Moolenaar | 2787ab9 | 2011-12-14 15:23:59 +0100 | [diff] [blame] | 5198 | return DefWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5199 | } |
| 5200 | |
| 5201 | /* |
| 5202 | * End of call-back routines |
| 5203 | */ |
| 5204 | |
| 5205 | /* parent window, if specified with -P */ |
| 5206 | HWND vim_parent_hwnd = NULL; |
| 5207 | |
| 5208 | static BOOL CALLBACK |
| 5209 | FindWindowTitle(HWND hwnd, LPARAM lParam) |
| 5210 | { |
| 5211 | char buf[2048]; |
| 5212 | char *title = (char *)lParam; |
| 5213 | |
| 5214 | if (GetWindowText(hwnd, buf, sizeof(buf))) |
| 5215 | { |
| 5216 | if (strstr(buf, title) != NULL) |
| 5217 | { |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5218 | /* Found it. Store the window ref. and quit searching if MDI |
| 5219 | * works. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5220 | vim_parent_hwnd = FindWindowEx(hwnd, NULL, "MDIClient", NULL); |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 5221 | if (vim_parent_hwnd != NULL) |
| 5222 | return FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5223 | } |
| 5224 | } |
| 5225 | return TRUE; /* continue searching */ |
| 5226 | } |
| 5227 | |
| 5228 | /* |
| 5229 | * Invoked for '-P "title"' argument: search for parent application to open |
| 5230 | * our window in. |
| 5231 | */ |
| 5232 | void |
| 5233 | gui_mch_set_parent(char *title) |
| 5234 | { |
| 5235 | EnumWindows(FindWindowTitle, (LPARAM)title); |
| 5236 | if (vim_parent_hwnd == NULL) |
| 5237 | { |
| 5238 | EMSG2(_("E671: Cannot find window title \"%s\""), title); |
| 5239 | mch_exit(2); |
| 5240 | } |
| 5241 | } |
| 5242 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 5243 | #ifndef FEAT_OLE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5244 | static void |
| 5245 | ole_error(char *arg) |
| 5246 | { |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 5247 | char buf[IOSIZE]; |
| 5248 | |
| 5249 | /* Can't use EMSG() here, we have not finished initialisation yet. */ |
| 5250 | vim_snprintf(buf, IOSIZE, |
| 5251 | _("E243: Argument not supported: \"-%s\"; Use the OLE version."), |
| 5252 | arg); |
| 5253 | mch_errmsg(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5254 | } |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 5255 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5256 | |
| 5257 | /* |
| 5258 | * Parse the GUI related command-line arguments. Any arguments used are |
| 5259 | * deleted from argv, and *argc is decremented accordingly. This is called |
| 5260 | * when vim is started, whether or not the GUI has been started. |
| 5261 | */ |
| 5262 | void |
| 5263 | gui_mch_prepare(int *argc, char **argv) |
| 5264 | { |
| 5265 | int silent = FALSE; |
| 5266 | int idx; |
| 5267 | |
| 5268 | /* Check for special OLE command line parameters */ |
| 5269 | if ((*argc == 2 || *argc == 3) && (argv[1][0] == '-' || argv[1][0] == '/')) |
| 5270 | { |
| 5271 | /* Check for a "-silent" argument first. */ |
| 5272 | if (*argc == 3 && STRICMP(argv[1] + 1, "silent") == 0 |
| 5273 | && (argv[2][0] == '-' || argv[2][0] == '/')) |
| 5274 | { |
| 5275 | silent = TRUE; |
| 5276 | idx = 2; |
| 5277 | } |
| 5278 | else |
| 5279 | idx = 1; |
| 5280 | |
| 5281 | /* Register Vim as an OLE Automation server */ |
| 5282 | if (STRICMP(argv[idx] + 1, "register") == 0) |
| 5283 | { |
| 5284 | #ifdef FEAT_OLE |
| 5285 | RegisterMe(silent); |
| 5286 | mch_exit(0); |
| 5287 | #else |
| 5288 | if (!silent) |
| 5289 | ole_error("register"); |
| 5290 | mch_exit(2); |
| 5291 | #endif |
| 5292 | } |
| 5293 | |
| 5294 | /* Unregister Vim as an OLE Automation server */ |
| 5295 | if (STRICMP(argv[idx] + 1, "unregister") == 0) |
| 5296 | { |
| 5297 | #ifdef FEAT_OLE |
| 5298 | UnregisterMe(!silent); |
| 5299 | mch_exit(0); |
| 5300 | #else |
| 5301 | if (!silent) |
| 5302 | ole_error("unregister"); |
| 5303 | mch_exit(2); |
| 5304 | #endif |
| 5305 | } |
| 5306 | |
| 5307 | /* Ignore an -embedding argument. It is only relevant if the |
| 5308 | * application wants to treat the case when it is started manually |
| 5309 | * differently from the case where it is started via automation (and |
| 5310 | * we don't). |
| 5311 | */ |
| 5312 | if (STRICMP(argv[idx] + 1, "embedding") == 0) |
| 5313 | { |
| 5314 | #ifdef FEAT_OLE |
| 5315 | *argc = 1; |
| 5316 | #else |
| 5317 | ole_error("embedding"); |
| 5318 | mch_exit(2); |
| 5319 | #endif |
| 5320 | } |
| 5321 | } |
| 5322 | |
| 5323 | #ifdef FEAT_OLE |
| 5324 | { |
| 5325 | int bDoRestart = FALSE; |
| 5326 | |
| 5327 | InitOLE(&bDoRestart); |
| 5328 | /* automatically exit after registering */ |
| 5329 | if (bDoRestart) |
| 5330 | mch_exit(0); |
| 5331 | } |
| 5332 | #endif |
| 5333 | |
| 5334 | #ifdef FEAT_NETBEANS_INTG |
| 5335 | { |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 5336 | /* stolen from gui_x11.c */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5337 | int arg; |
| 5338 | |
| 5339 | for (arg = 1; arg < *argc; arg++) |
| 5340 | if (strncmp("-nb", argv[arg], 3) == 0) |
| 5341 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5342 | netbeansArg = argv[arg]; |
| 5343 | mch_memmove(&argv[arg], &argv[arg + 1], |
| 5344 | (--*argc - arg) * sizeof(char *)); |
| 5345 | argv[*argc] = NULL; |
| 5346 | break; /* enough? */ |
| 5347 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5348 | } |
| 5349 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | /* |
| 5353 | * Initialise the GUI. Create all the windows, set up all the call-backs |
| 5354 | * etc. |
| 5355 | */ |
| 5356 | int |
| 5357 | gui_mch_init(void) |
| 5358 | { |
| 5359 | const char szVimWndClass[] = VIM_CLASS; |
| 5360 | const char szTextAreaClass[] = "VimTextArea"; |
| 5361 | WNDCLASS wndclass; |
| 5362 | #ifdef FEAT_MBYTE |
| 5363 | const WCHAR szVimWndClassW[] = VIM_CLASSW; |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 5364 | const WCHAR szTextAreaClassW[] = L"VimTextArea"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5365 | WNDCLASSW wndclassw; |
| 5366 | #endif |
| 5367 | #ifdef GLOBAL_IME |
| 5368 | ATOM atom; |
| 5369 | #endif |
| 5370 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5371 | /* Return here if the window was already opened (happens when |
| 5372 | * gui_mch_dialog() is called early). */ |
| 5373 | if (s_hwnd != NULL) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 5374 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5375 | |
| 5376 | /* |
| 5377 | * Load the tearoff bitmap |
| 5378 | */ |
| 5379 | #ifdef FEAT_TEAROFF |
| 5380 | s_htearbitmap = LoadBitmap(s_hinst, "IDB_TEAROFF"); |
| 5381 | #endif |
| 5382 | |
| 5383 | gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); |
| 5384 | gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL); |
| 5385 | #ifdef FEAT_MENU |
| 5386 | gui.menu_height = 0; /* Windows takes care of this */ |
| 5387 | #endif |
| 5388 | gui.border_width = 0; |
| 5389 | |
| 5390 | s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); |
| 5391 | |
| 5392 | #ifdef FEAT_MBYTE |
| 5393 | /* First try using the wide version, so that we can use any title. |
| 5394 | * Otherwise only characters in the active codepage will work. */ |
| 5395 | if (GetClassInfoW(s_hinst, szVimWndClassW, &wndclassw) == 0) |
| 5396 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5397 | wndclassw.style = CS_DBLCLKS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5398 | wndclassw.lpfnWndProc = _WndProc; |
| 5399 | wndclassw.cbClsExtra = 0; |
| 5400 | wndclassw.cbWndExtra = 0; |
| 5401 | wndclassw.hInstance = s_hinst; |
| 5402 | wndclassw.hIcon = LoadIcon(wndclassw.hInstance, "IDR_VIM"); |
| 5403 | wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5404 | wndclassw.hbrBackground = s_brush; |
| 5405 | wndclassw.lpszMenuName = NULL; |
| 5406 | wndclassw.lpszClassName = szVimWndClassW; |
| 5407 | |
| 5408 | if (( |
| 5409 | #ifdef GLOBAL_IME |
| 5410 | atom = |
| 5411 | #endif |
| 5412 | RegisterClassW(&wndclassw)) == 0) |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5413 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5414 | else |
| 5415 | wide_WindowProc = TRUE; |
| 5416 | } |
| 5417 | |
| 5418 | if (!wide_WindowProc) |
| 5419 | #endif |
| 5420 | |
| 5421 | if (GetClassInfo(s_hinst, szVimWndClass, &wndclass) == 0) |
| 5422 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5423 | wndclass.style = CS_DBLCLKS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5424 | wndclass.lpfnWndProc = _WndProc; |
| 5425 | wndclass.cbClsExtra = 0; |
| 5426 | wndclass.cbWndExtra = 0; |
| 5427 | wndclass.hInstance = s_hinst; |
| 5428 | wndclass.hIcon = LoadIcon(wndclass.hInstance, "IDR_VIM"); |
| 5429 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5430 | wndclass.hbrBackground = s_brush; |
| 5431 | wndclass.lpszMenuName = NULL; |
| 5432 | wndclass.lpszClassName = szVimWndClass; |
| 5433 | |
| 5434 | if (( |
| 5435 | #ifdef GLOBAL_IME |
| 5436 | atom = |
| 5437 | #endif |
| 5438 | RegisterClass(&wndclass)) == 0) |
| 5439 | return FAIL; |
| 5440 | } |
| 5441 | |
| 5442 | if (vim_parent_hwnd != NULL) |
| 5443 | { |
| 5444 | #ifdef HAVE_TRY_EXCEPT |
| 5445 | __try |
| 5446 | { |
| 5447 | #endif |
| 5448 | /* Open inside the specified parent window. |
| 5449 | * TODO: last argument should point to a CLIENTCREATESTRUCT |
| 5450 | * structure. */ |
| 5451 | s_hwnd = CreateWindowEx( |
| 5452 | WS_EX_MDICHILD, |
| 5453 | szVimWndClass, "Vim MSWindows GUI", |
Bram Moolenaar | e78c206 | 2011-08-10 15:56:27 +0200 | [diff] [blame] | 5454 | WS_OVERLAPPEDWINDOW | WS_CHILD |
| 5455 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 0xC000, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5456 | gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
| 5457 | gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
| 5458 | 100, /* Any value will do */ |
| 5459 | 100, /* Any value will do */ |
| 5460 | vim_parent_hwnd, NULL, |
| 5461 | s_hinst, NULL); |
| 5462 | #ifdef HAVE_TRY_EXCEPT |
| 5463 | } |
| 5464 | __except(EXCEPTION_EXECUTE_HANDLER) |
| 5465 | { |
| 5466 | /* NOP */ |
| 5467 | } |
| 5468 | #endif |
| 5469 | if (s_hwnd == NULL) |
| 5470 | { |
| 5471 | EMSG(_("E672: Unable to open window inside MDI application")); |
| 5472 | mch_exit(2); |
| 5473 | } |
| 5474 | } |
| 5475 | else |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 5476 | { |
| 5477 | /* If the provided windowid is not valid reset it to zero, so that it |
| 5478 | * is ignored and we open our own window. */ |
| 5479 | if (IsWindow((HWND)win_socket_id) <= 0) |
| 5480 | win_socket_id = 0; |
| 5481 | |
| 5482 | /* Create a window. If win_socket_id is not zero without border and |
| 5483 | * titlebar, it will be reparented below. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5484 | s_hwnd = CreateWindow( |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 5485 | szVimWndClass, "Vim MSWindows GUI", |
Bram Moolenaar | e78c206 | 2011-08-10 15:56:27 +0200 | [diff] [blame] | 5486 | (win_socket_id == 0 ? WS_OVERLAPPEDWINDOW : WS_POPUP) |
| 5487 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 5488 | gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
| 5489 | gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
| 5490 | 100, /* Any value will do */ |
| 5491 | 100, /* Any value will do */ |
| 5492 | NULL, NULL, |
| 5493 | s_hinst, NULL); |
| 5494 | if (s_hwnd != NULL && win_socket_id != 0) |
| 5495 | { |
| 5496 | SetParent(s_hwnd, (HWND)win_socket_id); |
| 5497 | ShowWindow(s_hwnd, SW_SHOWMAXIMIZED); |
| 5498 | } |
| 5499 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5500 | |
| 5501 | if (s_hwnd == NULL) |
| 5502 | return FAIL; |
| 5503 | |
| 5504 | #ifdef GLOBAL_IME |
| 5505 | global_ime_init(atom, s_hwnd); |
| 5506 | #endif |
| 5507 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 5508 | dyn_imm_load(); |
| 5509 | #endif |
| 5510 | |
| 5511 | /* Create the text area window */ |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 5512 | #ifdef FEAT_MBYTE |
| 5513 | if (wide_WindowProc) |
| 5514 | { |
| 5515 | if (GetClassInfoW(s_hinst, szTextAreaClassW, &wndclassw) == 0) |
| 5516 | { |
| 5517 | wndclassw.style = CS_OWNDC; |
| 5518 | wndclassw.lpfnWndProc = _TextAreaWndProc; |
| 5519 | wndclassw.cbClsExtra = 0; |
| 5520 | wndclassw.cbWndExtra = 0; |
| 5521 | wndclassw.hInstance = s_hinst; |
| 5522 | wndclassw.hIcon = NULL; |
| 5523 | wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5524 | wndclassw.hbrBackground = NULL; |
| 5525 | wndclassw.lpszMenuName = NULL; |
| 5526 | wndclassw.lpszClassName = szTextAreaClassW; |
| 5527 | |
| 5528 | if (RegisterClassW(&wndclassw) == 0) |
| 5529 | return FAIL; |
| 5530 | } |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 5531 | |
| 5532 | s_textArea = CreateWindowExW( |
| 5533 | 0, |
| 5534 | szTextAreaClassW, L"Vim text area", |
| 5535 | WS_CHILD | WS_VISIBLE, 0, 0, |
| 5536 | 100, // Any value will do for now |
| 5537 | 100, // Any value will do for now |
| 5538 | s_hwnd, NULL, |
| 5539 | s_hinst, NULL); |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 5540 | } |
| 5541 | else |
| 5542 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5543 | if (GetClassInfo(s_hinst, szTextAreaClass, &wndclass) == 0) |
| 5544 | { |
| 5545 | wndclass.style = CS_OWNDC; |
| 5546 | wndclass.lpfnWndProc = _TextAreaWndProc; |
| 5547 | wndclass.cbClsExtra = 0; |
| 5548 | wndclass.cbWndExtra = 0; |
| 5549 | wndclass.hInstance = s_hinst; |
| 5550 | wndclass.hIcon = NULL; |
| 5551 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5552 | wndclass.hbrBackground = NULL; |
| 5553 | wndclass.lpszMenuName = NULL; |
| 5554 | wndclass.lpszClassName = szTextAreaClass; |
| 5555 | |
| 5556 | if (RegisterClass(&wndclass) == 0) |
| 5557 | return FAIL; |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 5558 | |
| 5559 | s_textArea = CreateWindowEx( |
| 5560 | 0, |
| 5561 | szTextAreaClass, "Vim text area", |
| 5562 | WS_CHILD | WS_VISIBLE, 0, 0, |
| 5563 | 100, // Any value will do for now |
| 5564 | 100, // Any value will do for now |
| 5565 | s_hwnd, NULL, |
| 5566 | s_hinst, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5567 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5568 | |
| 5569 | if (s_textArea == NULL) |
| 5570 | return FAIL; |
| 5571 | |
Bram Moolenaar | 2032190 | 2016-02-17 12:30:17 +0100 | [diff] [blame] | 5572 | #ifdef FEAT_LIBCALL |
Bram Moolenaar | cddc91c | 2014-09-23 21:53:41 +0200 | [diff] [blame] | 5573 | /* Try loading an icon from $RUNTIMEPATH/bitmaps/vim.ico. */ |
| 5574 | { |
| 5575 | HANDLE hIcon = NULL; |
| 5576 | |
| 5577 | if (mch_icon_load(&hIcon) == OK && hIcon != NULL) |
Bram Moolenaar | 0f519a0 | 2014-10-06 18:10:09 +0200 | [diff] [blame] | 5578 | SendMessage(s_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); |
Bram Moolenaar | cddc91c | 2014-09-23 21:53:41 +0200 | [diff] [blame] | 5579 | } |
Bram Moolenaar | 2032190 | 2016-02-17 12:30:17 +0100 | [diff] [blame] | 5580 | #endif |
Bram Moolenaar | cddc91c | 2014-09-23 21:53:41 +0200 | [diff] [blame] | 5581 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5582 | #ifdef FEAT_MENU |
| 5583 | s_menuBar = CreateMenu(); |
| 5584 | #endif |
| 5585 | s_hdc = GetDC(s_textArea); |
| 5586 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5587 | DragAcceptFiles(s_hwnd, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5588 | |
| 5589 | /* Do we need to bother with this? */ |
| 5590 | /* m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); */ |
| 5591 | |
| 5592 | /* Get background/foreground colors from the system */ |
| 5593 | gui_mch_def_colors(); |
| 5594 | |
| 5595 | /* Get the colors from the "Normal" group (set in syntax.c or in a vimrc |
| 5596 | * file) */ |
| 5597 | set_normal_colors(); |
| 5598 | |
| 5599 | /* |
| 5600 | * Check that none of the colors are the same as the background color. |
| 5601 | * Then store the current values as the defaults. |
| 5602 | */ |
| 5603 | gui_check_colors(); |
| 5604 | gui.def_norm_pixel = gui.norm_pixel; |
| 5605 | gui.def_back_pixel = gui.back_pixel; |
| 5606 | |
| 5607 | /* Get the colors for the highlight groups (gui_check_colors() might have |
| 5608 | * changed them) */ |
| 5609 | highlight_gui_started(); |
| 5610 | |
| 5611 | /* |
Bram Moolenaar | 97b0b0e | 2015-11-19 20:23:37 +0100 | [diff] [blame] | 5612 | * Start out by adding the configured border width into the border offset. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5613 | */ |
Bram Moolenaar | 97b0b0e | 2015-11-19 20:23:37 +0100 | [diff] [blame] | 5614 | gui.border_offset = gui.border_width; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5615 | |
| 5616 | /* |
| 5617 | * Set up for Intellimouse processing |
| 5618 | */ |
| 5619 | init_mouse_wheel(); |
| 5620 | |
| 5621 | /* |
| 5622 | * compute a couple of metrics used for the dialogs |
| 5623 | */ |
| 5624 | get_dialog_font_metrics(); |
| 5625 | #ifdef FEAT_TOOLBAR |
| 5626 | /* |
| 5627 | * Create the toolbar |
| 5628 | */ |
| 5629 | initialise_toolbar(); |
| 5630 | #endif |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5631 | #ifdef FEAT_GUI_TABLINE |
| 5632 | /* |
| 5633 | * Create the tabline |
| 5634 | */ |
| 5635 | initialise_tabline(); |
| 5636 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5637 | #ifdef MSWIN_FIND_REPLACE |
| 5638 | /* |
| 5639 | * Initialise the dialog box stuff |
| 5640 | */ |
| 5641 | s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING); |
| 5642 | |
| 5643 | /* Initialise the struct */ |
| 5644 | s_findrep_struct.lStructSize = sizeof(s_findrep_struct); |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 5645 | s_findrep_struct.lpstrFindWhat = (LPSTR)alloc(MSWIN_FR_BUFSIZE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5646 | s_findrep_struct.lpstrFindWhat[0] = NUL; |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 5647 | s_findrep_struct.lpstrReplaceWith = (LPSTR)alloc(MSWIN_FR_BUFSIZE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5648 | s_findrep_struct.lpstrReplaceWith[0] = NUL; |
| 5649 | s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE; |
| 5650 | s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE; |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5651 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 5652 | s_findrep_struct_w.lStructSize = sizeof(s_findrep_struct_w); |
| 5653 | s_findrep_struct_w.lpstrFindWhat = |
| 5654 | (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR)); |
| 5655 | s_findrep_struct_w.lpstrFindWhat[0] = NUL; |
| 5656 | s_findrep_struct_w.lpstrReplaceWith = |
| 5657 | (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR)); |
| 5658 | s_findrep_struct_w.lpstrReplaceWith[0] = NUL; |
| 5659 | s_findrep_struct_w.wFindWhatLen = MSWIN_FR_BUFSIZE; |
| 5660 | s_findrep_struct_w.wReplaceWithLen = MSWIN_FR_BUFSIZE; |
| 5661 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5662 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5663 | |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 5664 | #ifdef FEAT_EVAL |
Bram Moolenaar | f32c5cd | 2016-01-10 16:07:44 +0100 | [diff] [blame] | 5665 | # if !defined(_MSC_VER) || (_MSC_VER < 1400) |
| 5666 | /* Define HandleToLong for old MS and non-MS compilers if not defined. */ |
| 5667 | # ifndef HandleToLong |
Bram Moolenaar | a87e2c2 | 2016-02-17 20:48:19 +0100 | [diff] [blame] | 5668 | # define HandleToLong(h) ((long)(intptr_t)(h)) |
Bram Moolenaar | f32c5cd | 2016-01-10 16:07:44 +0100 | [diff] [blame] | 5669 | # endif |
Bram Moolenaar | 4da95d3 | 2011-07-07 17:43:41 +0200 | [diff] [blame] | 5670 | # endif |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 5671 | /* set the v:windowid variable */ |
Bram Moolenaar | 7154b32 | 2011-05-25 21:18:06 +0200 | [diff] [blame] | 5672 | set_vim_var_nr(VV_WINDOWID, HandleToLong(s_hwnd)); |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 5673 | #endif |
| 5674 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 5675 | #ifdef FEAT_RENDER_OPTIONS |
| 5676 | if (p_rop) |
| 5677 | (void)gui_mch_set_rendering_options(p_rop); |
| 5678 | #endif |
| 5679 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 5680 | theend: |
| 5681 | /* Display any pending error messages */ |
| 5682 | display_errors(); |
| 5683 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5684 | return OK; |
| 5685 | } |
| 5686 | |
| 5687 | /* |
| 5688 | * Get the size of the screen, taking position on multiple monitors into |
| 5689 | * account (if supported). |
| 5690 | */ |
| 5691 | static void |
| 5692 | get_work_area(RECT *spi_rect) |
| 5693 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5694 | HMONITOR mon; |
| 5695 | MONITORINFO moninfo; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5696 | |
Bram Moolenaar | c4568ab | 2018-11-16 16:21:05 +0100 | [diff] [blame] | 5697 | /* work out which monitor the window is on, and get *its* work area */ |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 5698 | mon = MonitorFromWindow(s_hwnd, MONITOR_DEFAULTTOPRIMARY); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5699 | if (mon != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5700 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5701 | moninfo.cbSize = sizeof(MONITORINFO); |
| 5702 | if (GetMonitorInfo(mon, &moninfo)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5703 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5704 | *spi_rect = moninfo.rcWork; |
| 5705 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5706 | } |
| 5707 | } |
| 5708 | /* this is the old method... */ |
| 5709 | SystemParametersInfo(SPI_GETWORKAREA, 0, spi_rect, 0); |
| 5710 | } |
| 5711 | |
| 5712 | /* |
| 5713 | * Set the size of the window to the given width and height in pixels. |
| 5714 | */ |
| 5715 | void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 5716 | gui_mch_set_shellsize( |
| 5717 | int width, |
| 5718 | int height, |
| 5719 | int min_width UNUSED, |
| 5720 | int min_height UNUSED, |
| 5721 | int base_width UNUSED, |
| 5722 | int base_height UNUSED, |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5723 | int direction) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5724 | { |
| 5725 | RECT workarea_rect; |
| 5726 | int win_width, win_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5727 | WINDOWPLACEMENT wndpl; |
| 5728 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5729 | /* Try to keep window completely on screen. */ |
| 5730 | /* Get position of the screen work area. This is the part that is not |
| 5731 | * used by the taskbar or appbars. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5732 | get_work_area(&workarea_rect); |
| 5733 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 5734 | /* Get current position of our window. Note that the .left and .top are |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5735 | * relative to the work area. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5736 | wndpl.length = sizeof(WINDOWPLACEMENT); |
| 5737 | GetWindowPlacement(s_hwnd, &wndpl); |
| 5738 | |
| 5739 | /* Resizing a maximized window looks very strange, unzoom it first. |
| 5740 | * But don't do it when still starting up, it may have been requested in |
| 5741 | * the shortcut. */ |
| 5742 | if (wndpl.showCmd == SW_SHOWMAXIMIZED && starting == 0) |
| 5743 | { |
| 5744 | ShowWindow(s_hwnd, SW_SHOWNORMAL); |
| 5745 | /* Need to get the settings of the normal window. */ |
| 5746 | GetWindowPlacement(s_hwnd, &wndpl); |
| 5747 | } |
| 5748 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5749 | /* compute the size of the outside of the window */ |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 5750 | win_width = width + (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 5751 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 5752 | win_height = height + (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 5753 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5754 | + GetSystemMetrics(SM_CYCAPTION) |
| 5755 | #ifdef FEAT_MENU |
| 5756 | + gui_mswin_get_menu_height(FALSE) |
| 5757 | #endif |
| 5758 | ; |
| 5759 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5760 | /* The following should take care of keeping Vim on the same monitor, no |
| 5761 | * matter if the secondary monitor is left or right of the primary |
| 5762 | * monitor. */ |
| 5763 | wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + win_width; |
| 5764 | wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + win_height; |
Bram Moolenaar | 56a907a | 2006-05-06 21:44:30 +0000 | [diff] [blame] | 5765 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5766 | /* If the window is going off the screen, move it on to the screen. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5767 | if ((direction & RESIZE_HOR) |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5768 | && wndpl.rcNormalPosition.right > workarea_rect.right) |
| 5769 | OffsetRect(&wndpl.rcNormalPosition, |
| 5770 | workarea_rect.right - wndpl.rcNormalPosition.right, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5771 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5772 | if ((direction & RESIZE_HOR) |
| 5773 | && wndpl.rcNormalPosition.left < workarea_rect.left) |
| 5774 | OffsetRect(&wndpl.rcNormalPosition, |
| 5775 | workarea_rect.left - wndpl.rcNormalPosition.left, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5776 | |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5777 | if ((direction & RESIZE_VERT) |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5778 | && wndpl.rcNormalPosition.bottom > workarea_rect.bottom) |
| 5779 | OffsetRect(&wndpl.rcNormalPosition, |
| 5780 | 0, workarea_rect.bottom - wndpl.rcNormalPosition.bottom); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5781 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5782 | if ((direction & RESIZE_VERT) |
| 5783 | && wndpl.rcNormalPosition.top < workarea_rect.top) |
| 5784 | OffsetRect(&wndpl.rcNormalPosition, |
| 5785 | 0, workarea_rect.top - wndpl.rcNormalPosition.top); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5786 | |
| 5787 | /* set window position - we should use SetWindowPlacement rather than |
| 5788 | * SetWindowPos as the MSDN docs say the coord systems returned by |
| 5789 | * these two are not compatible. */ |
| 5790 | SetWindowPlacement(s_hwnd, &wndpl); |
| 5791 | |
| 5792 | SetActiveWindow(s_hwnd); |
| 5793 | SetFocus(s_hwnd); |
| 5794 | |
| 5795 | #ifdef FEAT_MENU |
| 5796 | /* Menu may wrap differently now */ |
| 5797 | gui_mswin_get_menu_height(!gui.starting); |
| 5798 | #endif |
| 5799 | } |
| 5800 | |
| 5801 | |
| 5802 | void |
| 5803 | gui_mch_set_scrollbar_thumb( |
| 5804 | scrollbar_T *sb, |
| 5805 | long val, |
| 5806 | long size, |
| 5807 | long max) |
| 5808 | { |
| 5809 | SCROLLINFO info; |
| 5810 | |
| 5811 | sb->scroll_shift = 0; |
| 5812 | while (max > 32767) |
| 5813 | { |
| 5814 | max = (max + 1) >> 1; |
| 5815 | val >>= 1; |
| 5816 | size >>= 1; |
| 5817 | ++sb->scroll_shift; |
| 5818 | } |
| 5819 | |
| 5820 | if (sb->scroll_shift > 0) |
| 5821 | ++size; |
| 5822 | |
| 5823 | info.cbSize = sizeof(info); |
| 5824 | info.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; |
| 5825 | info.nPos = val; |
| 5826 | info.nMin = 0; |
| 5827 | info.nMax = max; |
| 5828 | info.nPage = size; |
| 5829 | SetScrollInfo(sb->id, SB_CTL, &info, TRUE); |
| 5830 | } |
| 5831 | |
| 5832 | |
| 5833 | /* |
| 5834 | * Set the current text font. |
| 5835 | */ |
| 5836 | void |
| 5837 | gui_mch_set_font(GuiFont font) |
| 5838 | { |
| 5839 | gui.currFont = font; |
| 5840 | } |
| 5841 | |
| 5842 | |
| 5843 | /* |
| 5844 | * Set the current text foreground color. |
| 5845 | */ |
| 5846 | void |
| 5847 | gui_mch_set_fg_color(guicolor_T color) |
| 5848 | { |
| 5849 | gui.currFgColor = color; |
| 5850 | } |
| 5851 | |
| 5852 | /* |
| 5853 | * Set the current text background color. |
| 5854 | */ |
| 5855 | void |
| 5856 | gui_mch_set_bg_color(guicolor_T color) |
| 5857 | { |
| 5858 | gui.currBgColor = color; |
| 5859 | } |
| 5860 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 5861 | /* |
| 5862 | * Set the current text special color. |
| 5863 | */ |
| 5864 | void |
| 5865 | gui_mch_set_sp_color(guicolor_T color) |
| 5866 | { |
| 5867 | gui.currSpColor = color; |
| 5868 | } |
| 5869 | |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5870 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5871 | /* |
| 5872 | * Multi-byte handling, originally by Sung-Hoon Baek. |
| 5873 | * First static functions (no prototypes generated). |
| 5874 | */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5875 | # ifdef _MSC_VER |
| 5876 | # include <ime.h> /* Apparently not needed for Cygwin, MingW or Borland. */ |
| 5877 | # endif |
| 5878 | # include <imm.h> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5879 | |
| 5880 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5881 | * handle WM_IME_NOTIFY message |
| 5882 | */ |
| 5883 | static LRESULT |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 5884 | _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5885 | { |
| 5886 | LRESULT lResult = 0; |
| 5887 | HIMC hImc; |
| 5888 | |
| 5889 | if (!pImmGetContext || (hImc = pImmGetContext(hWnd)) == (HIMC)0) |
| 5890 | return lResult; |
| 5891 | switch (dwCommand) |
| 5892 | { |
| 5893 | case IMN_SETOPENSTATUS: |
| 5894 | if (pImmGetOpenStatus(hImc)) |
| 5895 | { |
| 5896 | pImmSetCompositionFont(hImc, &norm_logfont); |
| 5897 | im_set_position(gui.row, gui.col); |
| 5898 | |
| 5899 | /* Disable langmap */ |
| 5900 | State &= ~LANGMAP; |
| 5901 | if (State & INSERT) |
| 5902 | { |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 5903 | #if defined(FEAT_KEYMAP) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5904 | /* Unshown 'keymap' in status lines */ |
| 5905 | if (curbuf->b_p_iminsert == B_IMODE_LMAP) |
| 5906 | { |
| 5907 | /* Save cursor position */ |
| 5908 | int old_row = gui.row; |
| 5909 | int old_col = gui.col; |
| 5910 | |
| 5911 | // This must be called here before |
| 5912 | // status_redraw_curbuf(), otherwise the mode |
| 5913 | // message may appear in the wrong position. |
| 5914 | showmode(); |
| 5915 | status_redraw_curbuf(); |
| 5916 | update_screen(0); |
| 5917 | /* Restore cursor position */ |
| 5918 | gui.row = old_row; |
| 5919 | gui.col = old_col; |
| 5920 | } |
| 5921 | #endif |
| 5922 | } |
| 5923 | } |
| 5924 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 5925 | gui_mch_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5926 | lResult = 0; |
| 5927 | break; |
| 5928 | } |
| 5929 | pImmReleaseContext(hWnd, hImc); |
| 5930 | return lResult; |
| 5931 | } |
| 5932 | |
| 5933 | static LRESULT |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 5934 | _OnImeComposition(HWND hwnd, WPARAM dbcs UNUSED, LPARAM param) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5935 | { |
| 5936 | char_u *ret; |
| 5937 | int len; |
| 5938 | |
| 5939 | if ((param & GCS_RESULTSTR) == 0) /* Composition unfinished. */ |
| 5940 | return 0; |
| 5941 | |
| 5942 | ret = GetResultStr(hwnd, GCS_RESULTSTR, &len); |
| 5943 | if (ret != NULL) |
| 5944 | { |
| 5945 | add_to_input_buf_csi(ret, len); |
| 5946 | vim_free(ret); |
| 5947 | return 1; |
| 5948 | } |
| 5949 | return 0; |
| 5950 | } |
| 5951 | |
| 5952 | /* |
| 5953 | * get the current composition string, in UCS-2; *lenp is the number of |
| 5954 | * *lenp is the number of Unicode characters. |
| 5955 | */ |
| 5956 | static short_u * |
| 5957 | GetCompositionString_inUCS2(HIMC hIMC, DWORD GCS, int *lenp) |
| 5958 | { |
| 5959 | LONG ret; |
| 5960 | LPWSTR wbuf = NULL; |
| 5961 | char_u *buf; |
| 5962 | |
| 5963 | if (!pImmGetContext) |
| 5964 | return NULL; /* no imm32.dll */ |
| 5965 | |
| 5966 | /* Try Unicode; this'll always work on NT regardless of codepage. */ |
| 5967 | ret = pImmGetCompositionStringW(hIMC, GCS, NULL, 0); |
| 5968 | if (ret == 0) |
| 5969 | return NULL; /* empty */ |
| 5970 | |
| 5971 | if (ret > 0) |
| 5972 | { |
| 5973 | /* Allocate the requested buffer plus space for the NUL character. */ |
| 5974 | wbuf = (LPWSTR)alloc(ret + sizeof(WCHAR)); |
| 5975 | if (wbuf != NULL) |
| 5976 | { |
| 5977 | pImmGetCompositionStringW(hIMC, GCS, wbuf, ret); |
| 5978 | *lenp = ret / sizeof(WCHAR); |
| 5979 | } |
| 5980 | return (short_u *)wbuf; |
| 5981 | } |
| 5982 | |
| 5983 | /* ret < 0; we got an error, so try the ANSI version. This'll work |
| 5984 | * on 9x/ME, but only if the codepage happens to be set to whatever |
| 5985 | * we're inputting. */ |
| 5986 | ret = pImmGetCompositionStringA(hIMC, GCS, NULL, 0); |
| 5987 | if (ret <= 0) |
| 5988 | return NULL; /* empty or error */ |
| 5989 | |
| 5990 | buf = alloc(ret); |
| 5991 | if (buf == NULL) |
| 5992 | return NULL; |
| 5993 | pImmGetCompositionStringA(hIMC, GCS, buf, ret); |
| 5994 | |
| 5995 | /* convert from codepage to UCS-2 */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 5996 | MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)buf, ret, &wbuf, lenp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5997 | vim_free(buf); |
| 5998 | |
| 5999 | return (short_u *)wbuf; |
| 6000 | } |
| 6001 | |
| 6002 | /* |
| 6003 | * void GetResultStr() |
| 6004 | * |
| 6005 | * This handles WM_IME_COMPOSITION with GCS_RESULTSTR flag on. |
| 6006 | * get complete composition string |
| 6007 | */ |
| 6008 | static char_u * |
| 6009 | GetResultStr(HWND hwnd, int GCS, int *lenp) |
| 6010 | { |
| 6011 | HIMC hIMC; /* Input context handle. */ |
| 6012 | short_u *buf = NULL; |
| 6013 | char_u *convbuf = NULL; |
| 6014 | |
| 6015 | if (!pImmGetContext || (hIMC = pImmGetContext(hwnd)) == (HIMC)0) |
| 6016 | return NULL; |
| 6017 | |
| 6018 | /* Reads in the composition string. */ |
| 6019 | buf = GetCompositionString_inUCS2(hIMC, GCS, lenp); |
| 6020 | if (buf == NULL) |
| 6021 | return NULL; |
| 6022 | |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 6023 | convbuf = utf16_to_enc(buf, lenp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6024 | pImmReleaseContext(hwnd, hIMC); |
| 6025 | vim_free(buf); |
| 6026 | return convbuf; |
| 6027 | } |
| 6028 | #endif |
| 6029 | |
| 6030 | /* For global functions we need prototypes. */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 6031 | #if defined(FEAT_MBYTE_IME) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6032 | |
| 6033 | /* |
| 6034 | * set font to IM. |
| 6035 | */ |
| 6036 | void |
| 6037 | im_set_font(LOGFONT *lf) |
| 6038 | { |
| 6039 | HIMC hImc; |
| 6040 | |
| 6041 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 6042 | { |
| 6043 | pImmSetCompositionFont(hImc, lf); |
| 6044 | pImmReleaseContext(s_hwnd, hImc); |
| 6045 | } |
| 6046 | } |
| 6047 | |
| 6048 | /* |
| 6049 | * Notify cursor position to IM. |
| 6050 | */ |
| 6051 | void |
| 6052 | im_set_position(int row, int col) |
| 6053 | { |
| 6054 | HIMC hImc; |
| 6055 | |
| 6056 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 6057 | { |
| 6058 | COMPOSITIONFORM cfs; |
| 6059 | |
| 6060 | cfs.dwStyle = CFS_POINT; |
| 6061 | cfs.ptCurrentPos.x = FILL_X(col); |
| 6062 | cfs.ptCurrentPos.y = FILL_Y(row); |
| 6063 | MapWindowPoints(s_textArea, s_hwnd, &cfs.ptCurrentPos, 1); |
| 6064 | pImmSetCompositionWindow(hImc, &cfs); |
| 6065 | |
| 6066 | pImmReleaseContext(s_hwnd, hImc); |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | /* |
| 6071 | * Set IM status on ("active" is TRUE) or off ("active" is FALSE). |
| 6072 | */ |
| 6073 | void |
| 6074 | im_set_active(int active) |
| 6075 | { |
| 6076 | HIMC hImc; |
| 6077 | static HIMC hImcOld = (HIMC)0; |
| 6078 | |
| 6079 | if (pImmGetContext) /* if NULL imm32.dll wasn't loaded (yet) */ |
| 6080 | { |
| 6081 | if (p_imdisable) |
| 6082 | { |
| 6083 | if (hImcOld == (HIMC)0) |
| 6084 | { |
| 6085 | hImcOld = pImmGetContext(s_hwnd); |
| 6086 | if (hImcOld) |
| 6087 | pImmAssociateContext(s_hwnd, (HIMC)0); |
| 6088 | } |
| 6089 | active = FALSE; |
| 6090 | } |
| 6091 | else if (hImcOld != (HIMC)0) |
| 6092 | { |
| 6093 | pImmAssociateContext(s_hwnd, hImcOld); |
| 6094 | hImcOld = (HIMC)0; |
| 6095 | } |
| 6096 | |
| 6097 | hImc = pImmGetContext(s_hwnd); |
| 6098 | if (hImc) |
| 6099 | { |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6100 | /* |
| 6101 | * for Korean ime |
| 6102 | */ |
| 6103 | HKL hKL = GetKeyboardLayout(0); |
| 6104 | |
| 6105 | if (LOWORD(hKL) == MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN)) |
| 6106 | { |
| 6107 | static DWORD dwConversionSaved = 0, dwSentenceSaved = 0; |
| 6108 | static BOOL bSaved = FALSE; |
| 6109 | |
| 6110 | if (active) |
| 6111 | { |
| 6112 | /* if we have a saved conversion status, restore it */ |
| 6113 | if (bSaved) |
| 6114 | pImmSetConversionStatus(hImc, dwConversionSaved, |
| 6115 | dwSentenceSaved); |
| 6116 | bSaved = FALSE; |
| 6117 | } |
| 6118 | else |
| 6119 | { |
| 6120 | /* save conversion status and disable korean */ |
| 6121 | if (pImmGetConversionStatus(hImc, &dwConversionSaved, |
| 6122 | &dwSentenceSaved)) |
| 6123 | { |
| 6124 | bSaved = TRUE; |
| 6125 | pImmSetConversionStatus(hImc, |
| 6126 | dwConversionSaved & ~(IME_CMODE_NATIVE |
| 6127 | | IME_CMODE_FULLSHAPE), |
| 6128 | dwSentenceSaved); |
| 6129 | } |
| 6130 | } |
| 6131 | } |
| 6132 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6133 | pImmSetOpenStatus(hImc, active); |
| 6134 | pImmReleaseContext(s_hwnd, hImc); |
| 6135 | } |
| 6136 | } |
| 6137 | } |
| 6138 | |
| 6139 | /* |
| 6140 | * Get IM status. When IM is on, return not 0. Else return 0. |
| 6141 | */ |
| 6142 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 6143 | im_get_status(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6144 | { |
| 6145 | int status = 0; |
| 6146 | HIMC hImc; |
| 6147 | |
| 6148 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 6149 | { |
| 6150 | status = pImmGetOpenStatus(hImc) ? 1 : 0; |
| 6151 | pImmReleaseContext(s_hwnd, hImc); |
| 6152 | } |
| 6153 | return status; |
| 6154 | } |
| 6155 | |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 6156 | #endif /* FEAT_MBYTE_IME */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6157 | |
| 6158 | #if defined(FEAT_MBYTE) && !defined(FEAT_MBYTE_IME) && defined(GLOBAL_IME) |
| 6159 | /* Win32 with GLOBAL IME */ |
| 6160 | |
| 6161 | /* |
| 6162 | * Notify cursor position to IM. |
| 6163 | */ |
| 6164 | void |
| 6165 | im_set_position(int row, int col) |
| 6166 | { |
| 6167 | /* Win32 with GLOBAL IME */ |
| 6168 | POINT p; |
| 6169 | |
| 6170 | p.x = FILL_X(col); |
| 6171 | p.y = FILL_Y(row); |
| 6172 | MapWindowPoints(s_textArea, s_hwnd, &p, 1); |
| 6173 | global_ime_set_position(&p); |
| 6174 | } |
| 6175 | |
| 6176 | /* |
| 6177 | * Set IM status on ("active" is TRUE) or off ("active" is FALSE). |
| 6178 | */ |
| 6179 | void |
| 6180 | im_set_active(int active) |
| 6181 | { |
| 6182 | global_ime_set_status(active); |
| 6183 | } |
| 6184 | |
| 6185 | /* |
| 6186 | * Get IM status. When IM is on, return not 0. Else return 0. |
| 6187 | */ |
| 6188 | int |
Bram Moolenaar | d14e00e | 2016-01-31 17:30:51 +0100 | [diff] [blame] | 6189 | im_get_status(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6190 | { |
| 6191 | return global_ime_get_status(); |
| 6192 | } |
| 6193 | #endif |
| 6194 | |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6195 | #ifdef FEAT_MBYTE |
| 6196 | /* |
Bram Moolenaar | 39f0563 | 2006-03-19 22:15:26 +0000 | [diff] [blame] | 6197 | * Convert latin9 text "text[len]" to ucs-2 in "unicodebuf". |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6198 | */ |
| 6199 | static void |
| 6200 | latin9_to_ucs(char_u *text, int len, WCHAR *unicodebuf) |
| 6201 | { |
| 6202 | int c; |
| 6203 | |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6204 | while (--len >= 0) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6205 | { |
| 6206 | c = *text++; |
| 6207 | switch (c) |
| 6208 | { |
| 6209 | case 0xa4: c = 0x20ac; break; /* euro */ |
| 6210 | case 0xa6: c = 0x0160; break; /* S hat */ |
| 6211 | case 0xa8: c = 0x0161; break; /* S -hat */ |
| 6212 | case 0xb4: c = 0x017d; break; /* Z hat */ |
| 6213 | case 0xb8: c = 0x017e; break; /* Z -hat */ |
| 6214 | case 0xbc: c = 0x0152; break; /* OE */ |
| 6215 | case 0xbd: c = 0x0153; break; /* oe */ |
| 6216 | case 0xbe: c = 0x0178; break; /* Y */ |
| 6217 | } |
| 6218 | *unicodebuf++ = c; |
| 6219 | } |
| 6220 | } |
| 6221 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6222 | |
| 6223 | #ifdef FEAT_RIGHTLEFT |
| 6224 | /* |
| 6225 | * What is this for? In the case where you are using Win98 or Win2K or later, |
| 6226 | * and you are using a Hebrew font (or Arabic!), Windows does you a favor and |
| 6227 | * reverses the string sent to the TextOut... family. This sucks, because we |
| 6228 | * go to a lot of effort to do the right thing, and there doesn't seem to be a |
| 6229 | * way to tell Windblows not to do this! |
| 6230 | * |
| 6231 | * The short of it is that this 'RevOut' only gets called if you are running |
| 6232 | * one of the new, "improved" MS OSes, and only if you are running in |
| 6233 | * 'rightleft' mode. It makes display take *slightly* longer, but not |
| 6234 | * noticeably so. |
| 6235 | */ |
| 6236 | static void |
| 6237 | RevOut( HDC s_hdc, |
| 6238 | int col, |
| 6239 | int row, |
| 6240 | UINT foptions, |
| 6241 | CONST RECT *pcliprect, |
| 6242 | LPCTSTR text, |
| 6243 | UINT len, |
| 6244 | CONST INT *padding) |
| 6245 | { |
| 6246 | int ix; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6247 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6248 | for (ix = 0; ix < (int)len; ++ix) |
| 6249 | ExtTextOut(s_hdc, col + TEXT_X(ix), row, foptions, |
| 6250 | pcliprect, text + ix, 1, padding); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6251 | } |
| 6252 | #endif |
| 6253 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6254 | static void |
| 6255 | draw_line( |
| 6256 | int x1, |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 6257 | int y1, |
| 6258 | int x2, |
| 6259 | int y2, |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6260 | COLORREF color) |
| 6261 | { |
| 6262 | #if defined(FEAT_DIRECTX) |
| 6263 | if (IS_ENABLE_DIRECTX()) |
| 6264 | DWriteContext_DrawLine(s_dwc, x1, y1, x2, y2, color); |
| 6265 | else |
| 6266 | #endif |
| 6267 | { |
| 6268 | HPEN hpen = CreatePen(PS_SOLID, 1, color); |
| 6269 | HPEN old_pen = SelectObject(s_hdc, hpen); |
| 6270 | MoveToEx(s_hdc, x1, y1, NULL); |
| 6271 | /* Note: LineTo() excludes the last pixel in the line. */ |
| 6272 | LineTo(s_hdc, x2, y2); |
| 6273 | DeleteObject(SelectObject(s_hdc, old_pen)); |
| 6274 | } |
| 6275 | } |
| 6276 | |
| 6277 | static void |
| 6278 | set_pixel( |
| 6279 | int x, |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 6280 | int y, |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6281 | COLORREF color) |
| 6282 | { |
| 6283 | #if defined(FEAT_DIRECTX) |
| 6284 | if (IS_ENABLE_DIRECTX()) |
| 6285 | DWriteContext_SetPixel(s_dwc, x, y, color); |
| 6286 | else |
| 6287 | #endif |
| 6288 | SetPixel(s_hdc, x, y, color); |
| 6289 | } |
| 6290 | |
| 6291 | static void |
| 6292 | fill_rect( |
| 6293 | const RECT *rcp, |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 6294 | HBRUSH hbr, |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6295 | COLORREF color) |
| 6296 | { |
| 6297 | #if defined(FEAT_DIRECTX) |
| 6298 | if (IS_ENABLE_DIRECTX()) |
| 6299 | DWriteContext_FillRect(s_dwc, rcp, color); |
| 6300 | else |
| 6301 | #endif |
| 6302 | { |
| 6303 | HBRUSH hbr2; |
| 6304 | |
| 6305 | if (hbr == NULL) |
| 6306 | hbr2 = CreateSolidBrush(color); |
| 6307 | else |
| 6308 | hbr2 = hbr; |
| 6309 | FillRect(s_hdc, rcp, hbr2); |
| 6310 | if (hbr == NULL) |
| 6311 | DeleteBrush(hbr2); |
| 6312 | } |
| 6313 | } |
| 6314 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6315 | void |
| 6316 | gui_mch_draw_string( |
| 6317 | int row, |
| 6318 | int col, |
| 6319 | char_u *text, |
| 6320 | int len, |
| 6321 | int flags) |
| 6322 | { |
| 6323 | static int *padding = NULL; |
| 6324 | static int pad_size = 0; |
| 6325 | int i; |
| 6326 | const RECT *pcliprect = NULL; |
| 6327 | UINT foptions = 0; |
| 6328 | #ifdef FEAT_MBYTE |
| 6329 | static WCHAR *unicodebuf = NULL; |
| 6330 | static int *unicodepdy = NULL; |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6331 | static int unibuflen = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6332 | int n = 0; |
| 6333 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6334 | int y; |
| 6335 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6336 | /* |
| 6337 | * Italic and bold text seems to have an extra row of pixels at the bottom |
| 6338 | * (below where the bottom of the character should be). If we draw the |
| 6339 | * characters with a solid background, the top row of pixels in the |
| 6340 | * character below will be overwritten. We can fix this by filling in the |
| 6341 | * background ourselves, to the correct character proportions, and then |
| 6342 | * writing the character in transparent mode. Still have a problem when |
| 6343 | * the character is "_", which gets written on to the character below. |
| 6344 | * New fix: set gui.char_ascent to -1. This shifts all characters up one |
| 6345 | * pixel in their slots, which fixes the problem with the bottom row of |
| 6346 | * pixels. We still need this code because otherwise the top row of pixels |
| 6347 | * becomes a problem. - webb. |
| 6348 | */ |
| 6349 | static HBRUSH hbr_cache[2] = {NULL, NULL}; |
| 6350 | static guicolor_T brush_color[2] = {INVALCOLOR, INVALCOLOR}; |
| 6351 | static int brush_lru = 0; |
| 6352 | HBRUSH hbr; |
| 6353 | RECT rc; |
| 6354 | |
| 6355 | if (!(flags & DRAW_TRANSP)) |
| 6356 | { |
| 6357 | /* |
| 6358 | * Clear background first. |
| 6359 | * Note: FillRect() excludes right and bottom of rectangle. |
| 6360 | */ |
| 6361 | rc.left = FILL_X(col); |
| 6362 | rc.top = FILL_Y(row); |
| 6363 | #ifdef FEAT_MBYTE |
| 6364 | if (has_mbyte) |
| 6365 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6366 | /* Compute the length in display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6367 | rc.right = FILL_X(col + mb_string2cells(text, len)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6368 | } |
| 6369 | else |
| 6370 | #endif |
| 6371 | rc.right = FILL_X(col + len); |
| 6372 | rc.bottom = FILL_Y(row + 1); |
| 6373 | |
| 6374 | /* Cache the created brush, that saves a lot of time. We need two: |
| 6375 | * one for cursor background and one for the normal background. */ |
| 6376 | if (gui.currBgColor == brush_color[0]) |
| 6377 | { |
| 6378 | hbr = hbr_cache[0]; |
| 6379 | brush_lru = 1; |
| 6380 | } |
| 6381 | else if (gui.currBgColor == brush_color[1]) |
| 6382 | { |
| 6383 | hbr = hbr_cache[1]; |
| 6384 | brush_lru = 0; |
| 6385 | } |
| 6386 | else |
| 6387 | { |
| 6388 | if (hbr_cache[brush_lru] != NULL) |
| 6389 | DeleteBrush(hbr_cache[brush_lru]); |
| 6390 | hbr_cache[brush_lru] = CreateSolidBrush(gui.currBgColor); |
| 6391 | brush_color[brush_lru] = gui.currBgColor; |
| 6392 | hbr = hbr_cache[brush_lru]; |
| 6393 | brush_lru = !brush_lru; |
| 6394 | } |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6395 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6396 | fill_rect(&rc, hbr, gui.currBgColor); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6397 | |
| 6398 | SetBkMode(s_hdc, TRANSPARENT); |
| 6399 | |
| 6400 | /* |
| 6401 | * When drawing block cursor, prevent inverted character spilling |
| 6402 | * over character cell (can happen with bold/italic) |
| 6403 | */ |
| 6404 | if (flags & DRAW_CURSOR) |
| 6405 | { |
| 6406 | pcliprect = &rc; |
| 6407 | foptions = ETO_CLIPPED; |
| 6408 | } |
| 6409 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6410 | SetTextColor(s_hdc, gui.currFgColor); |
| 6411 | SelectFont(s_hdc, gui.currFont); |
| 6412 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6413 | #ifdef FEAT_DIRECTX |
| 6414 | if (IS_ENABLE_DIRECTX()) |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6415 | DWriteContext_SetFont(s_dwc, (HFONT)gui.currFont); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6416 | #endif |
| 6417 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6418 | if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width) |
| 6419 | { |
| 6420 | vim_free(padding); |
| 6421 | pad_size = Columns; |
| 6422 | |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 6423 | /* Don't give an out-of-memory message here, it would call us |
| 6424 | * recursively. */ |
| 6425 | padding = (int *)lalloc(pad_size * sizeof(int), FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6426 | if (padding != NULL) |
| 6427 | for (i = 0; i < pad_size; i++) |
| 6428 | padding[i] = gui.char_width; |
| 6429 | } |
| 6430 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6431 | /* |
| 6432 | * We have to provide the padding argument because italic and bold versions |
| 6433 | * of fixed-width fonts are often one pixel or so wider than their normal |
| 6434 | * versions. |
| 6435 | * No check for DRAW_BOLD, Windows will have done it already. |
| 6436 | */ |
| 6437 | |
| 6438 | #ifdef FEAT_MBYTE |
| 6439 | /* Check if there are any UTF-8 characters. If not, use normal text |
| 6440 | * output to speed up output. */ |
| 6441 | if (enc_utf8) |
| 6442 | for (n = 0; n < len; ++n) |
| 6443 | if (text[n] >= 0x80) |
| 6444 | break; |
| 6445 | |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 6446 | # if defined(FEAT_DIRECTX) |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6447 | /* Quick hack to enable DirectWrite. To use DirectWrite (antialias), it is |
| 6448 | * required that unicode drawing routine, currently. So this forces it |
| 6449 | * enabled. */ |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 6450 | if (IS_ENABLE_DIRECTX()) |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6451 | n = 0; /* Keep n < len, to enter block for unicode. */ |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 6452 | # endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6453 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6454 | /* Check if the Unicode buffer exists and is big enough. Create it |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6455 | * with the same length as the multi-byte string, the number of wide |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6456 | * characters is always equal or smaller. */ |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6457 | if ((enc_utf8 |
| 6458 | || (enc_codepage > 0 && (int)GetACP() != enc_codepage) |
| 6459 | || enc_latin9) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6460 | && (unicodebuf == NULL || len > unibuflen)) |
| 6461 | { |
| 6462 | vim_free(unicodebuf); |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 6463 | unicodebuf = (WCHAR *)lalloc(len * sizeof(WCHAR), FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6464 | |
| 6465 | vim_free(unicodepdy); |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 6466 | unicodepdy = (int *)lalloc(len * sizeof(int), FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6467 | |
| 6468 | unibuflen = len; |
| 6469 | } |
| 6470 | |
| 6471 | if (enc_utf8 && n < len && unicodebuf != NULL) |
| 6472 | { |
Bram Moolenaar | a6ce1cc | 2017-10-28 19:23:11 +0200 | [diff] [blame] | 6473 | /* Output UTF-8 characters. Composing characters should be |
| 6474 | * handled here. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6475 | int i; |
| 6476 | int wlen; /* string length in words */ |
| 6477 | int clen; /* string length in characters */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6478 | int cells; /* cell width of string up to composing char */ |
| 6479 | int cw; /* width of current cell */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6480 | int c; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6481 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 6482 | wlen = 0; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6483 | clen = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6484 | cells = 0; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6485 | for (i = 0; i < len; ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6486 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6487 | c = utf_ptr2char(text + i); |
| 6488 | if (c >= 0x10000) |
| 6489 | { |
| 6490 | /* Turn into UTF-16 encoding. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6491 | unicodebuf[wlen++] = ((c - 0x10000) >> 10) + 0xD800; |
| 6492 | unicodebuf[wlen++] = ((c - 0x10000) & 0x3ff) + 0xDC00; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6493 | } |
| 6494 | else |
| 6495 | { |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6496 | unicodebuf[wlen++] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6497 | } |
Bram Moolenaar | a6ce1cc | 2017-10-28 19:23:11 +0200 | [diff] [blame] | 6498 | |
| 6499 | if (utf_iscomposing(c)) |
| 6500 | cw = 0; |
| 6501 | else |
| 6502 | { |
| 6503 | cw = utf_char2cells(c); |
| 6504 | if (cw > 2) /* don't use 4 for unprintable char */ |
| 6505 | cw = 1; |
| 6506 | } |
| 6507 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6508 | if (unicodepdy != NULL) |
| 6509 | { |
| 6510 | /* Use unicodepdy to make characters fit as we expect, even |
| 6511 | * when the font uses different widths (e.g., bold character |
| 6512 | * is wider). */ |
Bram Moolenaar | d804fdf | 2016-02-27 16:04:58 +0100 | [diff] [blame] | 6513 | if (c >= 0x10000) |
| 6514 | { |
| 6515 | unicodepdy[wlen - 2] = cw * gui.char_width; |
| 6516 | unicodepdy[wlen - 1] = 0; |
| 6517 | } |
| 6518 | else |
| 6519 | unicodepdy[wlen - 1] = cw * gui.char_width; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6520 | } |
| 6521 | cells += cw; |
Bram Moolenaar | a6ce1cc | 2017-10-28 19:23:11 +0200 | [diff] [blame] | 6522 | i += utf_ptr2len_len(text + i, len - i); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6523 | ++clen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6524 | } |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 6525 | # if defined(FEAT_DIRECTX) |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6526 | if (IS_ENABLE_DIRECTX()) |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6527 | { |
Bram Moolenaar | 9b352c4 | 2014-08-06 16:49:55 +0200 | [diff] [blame] | 6528 | /* Add one to "cells" for italics. */ |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6529 | DWriteContext_DrawText(s_dwc, unicodebuf, wlen, |
Bram Moolenaar | 9b352c4 | 2014-08-06 16:49:55 +0200 | [diff] [blame] | 6530 | TEXT_X(col), TEXT_Y(row), FILL_X(cells + 1), FILL_Y(1), |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6531 | gui.char_width, gui.currFgColor, |
| 6532 | foptions, pcliprect, unicodepdy); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6533 | } |
| 6534 | else |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 6535 | # endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6536 | ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 6537 | foptions, pcliprect, unicodebuf, wlen, unicodepdy); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6538 | len = cells; /* used for underlining */ |
| 6539 | } |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6540 | else if ((enc_codepage > 0 && (int)GetACP() != enc_codepage) || enc_latin9) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6541 | { |
| 6542 | /* If we want to display codepage data, and the current CP is not the |
| 6543 | * ANSI one, we need to go via Unicode. */ |
| 6544 | if (unicodebuf != NULL) |
| 6545 | { |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6546 | if (enc_latin9) |
| 6547 | latin9_to_ucs(text, len, unicodebuf); |
| 6548 | else |
| 6549 | len = MultiByteToWideChar(enc_codepage, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6550 | MB_PRECOMPOSED, |
| 6551 | (char *)text, len, |
| 6552 | (LPWSTR)unicodebuf, unibuflen); |
| 6553 | if (len != 0) |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 6554 | { |
| 6555 | /* Use unicodepdy to make characters fit as we expect, even |
| 6556 | * when the font uses different widths (e.g., bold character |
| 6557 | * is wider). */ |
| 6558 | if (unicodepdy != NULL) |
| 6559 | { |
| 6560 | int i; |
| 6561 | int cw; |
| 6562 | |
| 6563 | for (i = 0; i < len; ++i) |
| 6564 | { |
| 6565 | cw = utf_char2cells(unicodebuf[i]); |
| 6566 | if (cw > 2) |
| 6567 | cw = 1; |
| 6568 | unicodepdy[i] = cw * gui.char_width; |
| 6569 | } |
| 6570 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6571 | ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row), |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 6572 | foptions, pcliprect, unicodebuf, len, unicodepdy); |
| 6573 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6574 | } |
| 6575 | } |
| 6576 | else |
| 6577 | #endif |
| 6578 | { |
| 6579 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4ee40b0 | 2014-09-19 16:13:53 +0200 | [diff] [blame] | 6580 | /* Windows will mess up RL text, so we have to draw it character by |
| 6581 | * character. Only do this if RL is on, since it's slow. */ |
| 6582 | if (curwin->w_p_rl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6583 | RevOut(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 6584 | foptions, pcliprect, (char *)text, len, padding); |
| 6585 | else |
| 6586 | #endif |
| 6587 | ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 6588 | foptions, pcliprect, (char *)text, len, padding); |
| 6589 | } |
| 6590 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6591 | /* Underline */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6592 | if (flags & DRAW_UNDERL) |
| 6593 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6594 | /* When p_linespace is 0, overwrite the bottom row of pixels. |
| 6595 | * Otherwise put the line just below the character. */ |
| 6596 | y = FILL_Y(row + 1) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6597 | if (p_linespace > 1) |
| 6598 | y -= p_linespace - 1; |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6599 | draw_line(FILL_X(col), y, FILL_X(col + len), y, gui.currFgColor); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6600 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6601 | |
Bram Moolenaar | cf4b00c | 2017-09-02 18:33:56 +0200 | [diff] [blame] | 6602 | /* Strikethrough */ |
| 6603 | if (flags & DRAW_STRIKE) |
| 6604 | { |
Bram Moolenaar | cf4b00c | 2017-09-02 18:33:56 +0200 | [diff] [blame] | 6605 | y = FILL_Y(row + 1) - gui.char_height/2; |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6606 | draw_line(FILL_X(col), y, FILL_X(col + len), y, gui.currSpColor); |
Bram Moolenaar | cf4b00c | 2017-09-02 18:33:56 +0200 | [diff] [blame] | 6607 | } |
| 6608 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6609 | /* Undercurl */ |
| 6610 | if (flags & DRAW_UNDERC) |
| 6611 | { |
| 6612 | int x; |
| 6613 | int offset; |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 6614 | static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6615 | |
| 6616 | y = FILL_Y(row + 1) - 1; |
| 6617 | for (x = FILL_X(col); x < FILL_X(col + len); ++x) |
| 6618 | { |
| 6619 | offset = val[x % 8]; |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6620 | set_pixel(x, y - offset, gui.currSpColor); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6621 | } |
| 6622 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6623 | } |
| 6624 | |
| 6625 | |
| 6626 | /* |
| 6627 | * Output routines. |
| 6628 | */ |
| 6629 | |
| 6630 | /* Flush any output to the screen */ |
| 6631 | void |
| 6632 | gui_mch_flush(void) |
| 6633 | { |
| 6634 | # if defined(__BORLANDC__) |
| 6635 | /* |
| 6636 | * The GdiFlush declaration (in Borland C 5.01 <wingdi.h>) is not a |
| 6637 | * prototype declaration. |
| 6638 | * The compiler complains if __stdcall is not used in both declarations. |
| 6639 | */ |
| 6640 | BOOL __stdcall GdiFlush(void); |
| 6641 | # endif |
| 6642 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6643 | #if defined(FEAT_DIRECTX) |
| 6644 | if (IS_ENABLE_DIRECTX()) |
| 6645 | DWriteContext_Flush(s_dwc); |
| 6646 | #endif |
| 6647 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6648 | GdiFlush(); |
| 6649 | } |
| 6650 | |
| 6651 | static void |
| 6652 | clear_rect(RECT *rcp) |
| 6653 | { |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6654 | fill_rect(rcp, NULL, gui.back_pixel); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6658 | void |
| 6659 | gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) |
| 6660 | { |
| 6661 | RECT workarea_rect; |
| 6662 | |
| 6663 | get_work_area(&workarea_rect); |
| 6664 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6665 | *screen_w = workarea_rect.right - workarea_rect.left |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 6666 | - (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6667 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6668 | |
| 6669 | /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include |
| 6670 | * the menubar for MSwin, we subtract it from the screen height, so that |
| 6671 | * the window size can be made to fit on the screen. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6672 | *screen_h = workarea_rect.bottom - workarea_rect.top |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 6673 | - (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6674 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6675 | - GetSystemMetrics(SM_CYCAPTION) |
| 6676 | #ifdef FEAT_MENU |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 6677 | - gui_mswin_get_menu_height(FALSE) |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6678 | #endif |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 6679 | ; |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6680 | } |
| 6681 | |
| 6682 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6683 | #if defined(FEAT_MENU) || defined(PROTO) |
| 6684 | /* |
| 6685 | * Add a sub menu to the menu bar. |
| 6686 | */ |
| 6687 | void |
| 6688 | gui_mch_add_menu( |
| 6689 | vimmenu_T *menu, |
| 6690 | int pos) |
| 6691 | { |
| 6692 | vimmenu_T *parent = menu->parent; |
| 6693 | |
| 6694 | menu->submenu_id = CreatePopupMenu(); |
| 6695 | menu->id = s_menu_id++; |
| 6696 | |
| 6697 | if (menu_is_menubar(menu->name)) |
| 6698 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6699 | #ifdef FEAT_MBYTE |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6700 | WCHAR *wn = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6701 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6702 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 6703 | { |
| 6704 | /* 'encoding' differs from active codepage: convert menu name |
| 6705 | * and use wide function */ |
| 6706 | wn = enc_to_utf16(menu->name, NULL); |
| 6707 | if (wn != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6708 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6709 | MENUITEMINFOW infow; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6710 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6711 | infow.cbSize = sizeof(infow); |
| 6712 | infow.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID |
| 6713 | | MIIM_SUBMENU; |
| 6714 | infow.dwItemData = (long_u)menu; |
| 6715 | infow.wID = menu->id; |
| 6716 | infow.fType = MFT_STRING; |
| 6717 | infow.dwTypeData = wn; |
| 6718 | infow.cch = (UINT)wcslen(wn); |
| 6719 | infow.hSubMenu = menu->submenu_id; |
| 6720 | InsertMenuItemW((parent == NULL) |
| 6721 | ? s_menuBar : parent->submenu_id, |
| 6722 | (UINT)pos, TRUE, &infow); |
| 6723 | vim_free(wn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6724 | } |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6725 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6726 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6727 | if (wn == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6728 | #endif |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6729 | { |
| 6730 | MENUITEMINFO info; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6731 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6732 | info.cbSize = sizeof(info); |
| 6733 | info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID | MIIM_SUBMENU; |
| 6734 | info.dwItemData = (long_u)menu; |
| 6735 | info.wID = menu->id; |
| 6736 | info.fType = MFT_STRING; |
| 6737 | info.dwTypeData = (LPTSTR)menu->name; |
| 6738 | info.cch = (UINT)STRLEN(menu->name); |
| 6739 | info.hSubMenu = menu->submenu_id; |
| 6740 | InsertMenuItem((parent == NULL) |
| 6741 | ? s_menuBar : parent->submenu_id, |
| 6742 | (UINT)pos, TRUE, &info); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6743 | } |
| 6744 | } |
| 6745 | |
| 6746 | /* Fix window size if menu may have wrapped */ |
| 6747 | if (parent == NULL) |
| 6748 | gui_mswin_get_menu_height(!gui.starting); |
| 6749 | #ifdef FEAT_TEAROFF |
| 6750 | else if (IsWindow(parent->tearoff_handle)) |
| 6751 | rebuild_tearoff(parent); |
| 6752 | #endif |
| 6753 | } |
| 6754 | |
| 6755 | void |
| 6756 | gui_mch_show_popupmenu(vimmenu_T *menu) |
| 6757 | { |
| 6758 | POINT mp; |
| 6759 | |
| 6760 | (void)GetCursorPos((LPPOINT)&mp); |
| 6761 | gui_mch_show_popupmenu_at(menu, (int)mp.x, (int)mp.y); |
| 6762 | } |
| 6763 | |
| 6764 | void |
Bram Moolenaar | 045e82d | 2005-07-08 22:25:33 +0000 | [diff] [blame] | 6765 | gui_make_popup(char_u *path_name, int mouse_pos) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6766 | { |
| 6767 | vimmenu_T *menu = gui_find_menu(path_name); |
| 6768 | |
| 6769 | if (menu != NULL) |
| 6770 | { |
| 6771 | POINT p; |
| 6772 | |
| 6773 | /* Find the position of the current cursor */ |
| 6774 | GetDCOrgEx(s_hdc, &p); |
Bram Moolenaar | 045e82d | 2005-07-08 22:25:33 +0000 | [diff] [blame] | 6775 | if (mouse_pos) |
| 6776 | { |
| 6777 | int mx, my; |
| 6778 | |
| 6779 | gui_mch_getmouse(&mx, &my); |
| 6780 | p.x += mx; |
| 6781 | p.y += my; |
| 6782 | } |
| 6783 | else if (curwin != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6784 | { |
Bram Moolenaar | 53f8174 | 2017-09-22 14:35:51 +0200 | [diff] [blame] | 6785 | p.x += TEXT_X(curwin->w_wincol + curwin->w_wcol + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6786 | p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1); |
| 6787 | } |
| 6788 | msg_scroll = FALSE; |
| 6789 | gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y); |
| 6790 | } |
| 6791 | } |
| 6792 | |
| 6793 | #if defined(FEAT_TEAROFF) || defined(PROTO) |
| 6794 | /* |
| 6795 | * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and |
| 6796 | * create it as a pseudo-"tearoff menu". |
| 6797 | */ |
| 6798 | void |
| 6799 | gui_make_tearoff(char_u *path_name) |
| 6800 | { |
| 6801 | vimmenu_T *menu = gui_find_menu(path_name); |
| 6802 | |
| 6803 | /* Found the menu, so tear it off. */ |
| 6804 | if (menu != NULL) |
| 6805 | gui_mch_tearoff(menu->dname, menu, 0xffffL, 0xffffL); |
| 6806 | } |
| 6807 | #endif |
| 6808 | |
| 6809 | /* |
| 6810 | * Add a menu item to a menu |
| 6811 | */ |
| 6812 | void |
| 6813 | gui_mch_add_menu_item( |
| 6814 | vimmenu_T *menu, |
| 6815 | int idx) |
| 6816 | { |
| 6817 | vimmenu_T *parent = menu->parent; |
| 6818 | |
| 6819 | menu->id = s_menu_id++; |
| 6820 | menu->submenu_id = NULL; |
| 6821 | |
| 6822 | #ifdef FEAT_TEAROFF |
| 6823 | if (STRNCMP(menu->name, TEAR_STRING, TEAR_LEN) == 0) |
| 6824 | { |
| 6825 | InsertMenu(parent->submenu_id, (UINT)idx, MF_BITMAP|MF_BYPOSITION, |
| 6826 | (UINT)menu->id, (LPCTSTR) s_htearbitmap); |
| 6827 | } |
| 6828 | else |
| 6829 | #endif |
| 6830 | #ifdef FEAT_TOOLBAR |
| 6831 | if (menu_is_toolbar(parent->name)) |
| 6832 | { |
| 6833 | TBBUTTON newtb; |
| 6834 | |
| 6835 | vim_memset(&newtb, 0, sizeof(newtb)); |
| 6836 | if (menu_is_separator(menu->name)) |
| 6837 | { |
| 6838 | newtb.iBitmap = 0; |
| 6839 | newtb.fsStyle = TBSTYLE_SEP; |
| 6840 | } |
| 6841 | else |
| 6842 | { |
| 6843 | newtb.iBitmap = get_toolbar_bitmap(menu); |
| 6844 | newtb.fsStyle = TBSTYLE_BUTTON; |
| 6845 | } |
| 6846 | newtb.idCommand = menu->id; |
| 6847 | newtb.fsState = TBSTATE_ENABLED; |
| 6848 | newtb.iString = 0; |
| 6849 | SendMessage(s_toolbarhwnd, TB_INSERTBUTTON, (WPARAM)idx, |
| 6850 | (LPARAM)&newtb); |
| 6851 | menu->submenu_id = (HMENU)-1; |
| 6852 | } |
| 6853 | else |
| 6854 | #endif |
| 6855 | { |
| 6856 | #ifdef FEAT_MBYTE |
| 6857 | WCHAR *wn = NULL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6858 | |
| 6859 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 6860 | { |
| 6861 | /* 'encoding' differs from active codepage: convert menu item name |
| 6862 | * and use wide function */ |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 6863 | wn = enc_to_utf16(menu->name, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6864 | if (wn != NULL) |
| 6865 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6866 | InsertMenuW(parent->submenu_id, (UINT)idx, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6867 | (menu_is_separator(menu->name) |
| 6868 | ? MF_SEPARATOR : MF_STRING) | MF_BYPOSITION, |
| 6869 | (UINT)menu->id, wn); |
| 6870 | vim_free(wn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6871 | } |
| 6872 | } |
| 6873 | if (wn == NULL) |
| 6874 | #endif |
| 6875 | InsertMenu(parent->submenu_id, (UINT)idx, |
| 6876 | (menu_is_separator(menu->name) ? MF_SEPARATOR : MF_STRING) |
| 6877 | | MF_BYPOSITION, |
| 6878 | (UINT)menu->id, (LPCTSTR)menu->name); |
| 6879 | #ifdef FEAT_TEAROFF |
| 6880 | if (IsWindow(parent->tearoff_handle)) |
| 6881 | rebuild_tearoff(parent); |
| 6882 | #endif |
| 6883 | } |
| 6884 | } |
| 6885 | |
| 6886 | /* |
| 6887 | * Destroy the machine specific menu widget. |
| 6888 | */ |
| 6889 | void |
| 6890 | gui_mch_destroy_menu(vimmenu_T *menu) |
| 6891 | { |
| 6892 | #ifdef FEAT_TOOLBAR |
| 6893 | /* |
| 6894 | * is this a toolbar button? |
| 6895 | */ |
| 6896 | if (menu->submenu_id == (HMENU)-1) |
| 6897 | { |
| 6898 | int iButton; |
| 6899 | |
| 6900 | iButton = (int)SendMessage(s_toolbarhwnd, TB_COMMANDTOINDEX, |
| 6901 | (WPARAM)menu->id, 0); |
| 6902 | SendMessage(s_toolbarhwnd, TB_DELETEBUTTON, (WPARAM)iButton, 0); |
| 6903 | } |
| 6904 | else |
| 6905 | #endif |
| 6906 | { |
| 6907 | if (menu->parent != NULL |
| 6908 | && menu_is_popup(menu->parent->dname) |
| 6909 | && menu->parent->submenu_id != NULL) |
| 6910 | RemoveMenu(menu->parent->submenu_id, menu->id, MF_BYCOMMAND); |
| 6911 | else |
| 6912 | RemoveMenu(s_menuBar, menu->id, MF_BYCOMMAND); |
| 6913 | if (menu->submenu_id != NULL) |
| 6914 | DestroyMenu(menu->submenu_id); |
| 6915 | #ifdef FEAT_TEAROFF |
| 6916 | if (IsWindow(menu->tearoff_handle)) |
| 6917 | DestroyWindow(menu->tearoff_handle); |
| 6918 | if (menu->parent != NULL |
| 6919 | && menu->parent->children != NULL |
| 6920 | && IsWindow(menu->parent->tearoff_handle)) |
| 6921 | { |
| 6922 | /* This menu must not show up when rebuilding the tearoff window. */ |
| 6923 | menu->modes = 0; |
| 6924 | rebuild_tearoff(menu->parent); |
| 6925 | } |
| 6926 | #endif |
| 6927 | } |
| 6928 | } |
| 6929 | |
| 6930 | #ifdef FEAT_TEAROFF |
| 6931 | static void |
| 6932 | rebuild_tearoff(vimmenu_T *menu) |
| 6933 | { |
| 6934 | /*hackish*/ |
| 6935 | char_u tbuf[128]; |
| 6936 | RECT trect; |
| 6937 | RECT rct; |
| 6938 | RECT roct; |
| 6939 | int x, y; |
| 6940 | |
| 6941 | HWND thwnd = menu->tearoff_handle; |
| 6942 | |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 6943 | GetWindowText(thwnd, (LPSTR)tbuf, 127); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6944 | if (GetWindowRect(thwnd, &trect) |
| 6945 | && GetWindowRect(s_hwnd, &rct) |
| 6946 | && GetClientRect(s_hwnd, &roct)) |
| 6947 | { |
| 6948 | x = trect.left - rct.left; |
| 6949 | y = (trect.top - rct.bottom + roct.bottom); |
| 6950 | } |
| 6951 | else |
| 6952 | { |
| 6953 | x = y = 0xffffL; |
| 6954 | } |
| 6955 | DestroyWindow(thwnd); |
| 6956 | if (menu->children != NULL) |
| 6957 | { |
| 6958 | gui_mch_tearoff(tbuf, menu, x, y); |
| 6959 | if (IsWindow(menu->tearoff_handle)) |
| 6960 | (void) SetWindowPos(menu->tearoff_handle, |
| 6961 | NULL, |
| 6962 | (int)trect.left, |
| 6963 | (int)trect.top, |
| 6964 | 0, 0, |
| 6965 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
| 6966 | } |
| 6967 | } |
| 6968 | #endif /* FEAT_TEAROFF */ |
| 6969 | |
| 6970 | /* |
| 6971 | * Make a menu either grey or not grey. |
| 6972 | */ |
| 6973 | void |
| 6974 | gui_mch_menu_grey( |
| 6975 | vimmenu_T *menu, |
| 6976 | int grey) |
| 6977 | { |
| 6978 | #ifdef FEAT_TOOLBAR |
| 6979 | /* |
| 6980 | * is this a toolbar button? |
| 6981 | */ |
| 6982 | if (menu->submenu_id == (HMENU)-1) |
| 6983 | { |
| 6984 | SendMessage(s_toolbarhwnd, TB_ENABLEBUTTON, |
| 6985 | (WPARAM)menu->id, (LPARAM) MAKELONG((grey ? FALSE : TRUE), 0) ); |
| 6986 | } |
| 6987 | else |
| 6988 | #endif |
Bram Moolenaar | 762f175 | 2016-06-04 22:36:17 +0200 | [diff] [blame] | 6989 | (void)EnableMenuItem(menu->parent ? menu->parent->submenu_id : s_menuBar, |
| 6990 | menu->id, MF_BYCOMMAND | (grey ? MF_GRAYED : MF_ENABLED)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6991 | |
| 6992 | #ifdef FEAT_TEAROFF |
| 6993 | if ((menu->parent != NULL) && (IsWindow(menu->parent->tearoff_handle))) |
| 6994 | { |
| 6995 | WORD menuID; |
| 6996 | HWND menuHandle; |
| 6997 | |
| 6998 | /* |
| 6999 | * A tearoff button has changed state. |
| 7000 | */ |
| 7001 | if (menu->children == NULL) |
| 7002 | menuID = (WORD)(menu->id); |
| 7003 | else |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7004 | menuID = (WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7005 | menuHandle = GetDlgItem(menu->parent->tearoff_handle, menuID); |
| 7006 | if (menuHandle) |
| 7007 | EnableWindow(menuHandle, !grey); |
| 7008 | |
| 7009 | } |
| 7010 | #endif |
| 7011 | } |
| 7012 | |
| 7013 | #endif /* FEAT_MENU */ |
| 7014 | |
| 7015 | |
| 7016 | /* define some macros used to make the dialogue creation more readable */ |
| 7017 | |
| 7018 | #define add_string(s) strcpy((LPSTR)p, s); (LPSTR)p += (strlen((LPSTR)p) + 1) |
| 7019 | #define add_word(x) *p++ = (x) |
Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 7020 | #define add_long(x) dwp = (DWORD *)p; *dwp++ = (x); p = (WORD *)dwp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7021 | |
| 7022 | #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
| 7023 | /* |
| 7024 | * stuff for dialogs |
| 7025 | */ |
| 7026 | |
| 7027 | /* |
| 7028 | * The callback routine used by all the dialogs. Very simple. First, |
| 7029 | * acknowledges the INITDIALOG message so that Windows knows to do standard |
| 7030 | * dialog stuff (Return = default, Esc = cancel....) Second, if a button is |
| 7031 | * pressed, return that button's ID - IDCANCEL (2), which is the button's |
| 7032 | * number. |
| 7033 | */ |
| 7034 | static LRESULT CALLBACK |
| 7035 | dialog_callback( |
| 7036 | HWND hwnd, |
| 7037 | UINT message, |
| 7038 | WPARAM wParam, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 7039 | LPARAM lParam UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7040 | { |
| 7041 | if (message == WM_INITDIALOG) |
| 7042 | { |
| 7043 | CenterWindow(hwnd, GetWindow(hwnd, GW_OWNER)); |
| 7044 | /* Set focus to the dialog. Set the default button, if specified. */ |
| 7045 | (void)SetFocus(hwnd); |
| 7046 | if (dialog_default_button > IDCANCEL) |
| 7047 | (void)SetFocus(GetDlgItem(hwnd, dialog_default_button)); |
Bram Moolenaar | 2b80e65 | 2007-08-14 14:57:55 +0000 | [diff] [blame] | 7048 | else |
| 7049 | /* We don't have a default, set focus on another element of the |
| 7050 | * dialog window, probably the icon */ |
| 7051 | (void)SetFocus(GetDlgItem(hwnd, DLG_NONBUTTON_CONTROL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7052 | return FALSE; |
| 7053 | } |
| 7054 | |
| 7055 | if (message == WM_COMMAND) |
| 7056 | { |
| 7057 | int button = LOWORD(wParam); |
| 7058 | |
| 7059 | /* Don't end the dialog if something was selected that was |
| 7060 | * not a button. |
| 7061 | */ |
| 7062 | if (button >= DLG_NONBUTTON_CONTROL) |
| 7063 | return TRUE; |
| 7064 | |
| 7065 | /* If the edit box exists, copy the string. */ |
| 7066 | if (s_textfield != NULL) |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 7067 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7068 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 7069 | /* If the OS is Windows NT, and 'encoding' differs from active |
| 7070 | * codepage: use wide function and convert text. */ |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7071 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 7072 | { |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 7073 | WCHAR *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR)); |
| 7074 | char_u *p; |
| 7075 | |
| 7076 | GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE); |
| 7077 | p = utf16_to_enc(wp, NULL); |
| 7078 | vim_strncpy(s_textfield, p, IOSIZE); |
| 7079 | vim_free(p); |
| 7080 | vim_free(wp); |
| 7081 | } |
| 7082 | else |
| 7083 | # endif |
| 7084 | GetDlgItemText(hwnd, DLG_NONBUTTON_CONTROL + 2, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7085 | (LPSTR)s_textfield, IOSIZE); |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 7086 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7087 | |
| 7088 | /* |
| 7089 | * Need to check for IDOK because if the user just hits Return to |
| 7090 | * accept the default value, some reason this is what we get. |
| 7091 | */ |
| 7092 | if (button == IDOK) |
| 7093 | { |
| 7094 | if (dialog_default_button > IDCANCEL) |
| 7095 | EndDialog(hwnd, dialog_default_button); |
| 7096 | } |
| 7097 | else |
| 7098 | EndDialog(hwnd, button - IDCANCEL); |
| 7099 | return TRUE; |
| 7100 | } |
| 7101 | |
| 7102 | if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) |
| 7103 | { |
| 7104 | EndDialog(hwnd, 0); |
| 7105 | return TRUE; |
| 7106 | } |
| 7107 | return FALSE; |
| 7108 | } |
| 7109 | |
| 7110 | /* |
| 7111 | * Create a dialog dynamically from the parameter strings. |
| 7112 | * type = type of dialog (question, alert, etc.) |
| 7113 | * title = dialog title. may be NULL for default title. |
| 7114 | * message = text to display. Dialog sizes to accommodate it. |
| 7115 | * buttons = '\n' separated list of button captions, default first. |
| 7116 | * dfltbutton = number of default button. |
| 7117 | * |
| 7118 | * This routine returns 1 if the first button is pressed, |
| 7119 | * 2 for the second, etc. |
| 7120 | * |
| 7121 | * 0 indicates Esc was pressed. |
| 7122 | * -1 for unexpected error |
| 7123 | * |
| 7124 | * If stubbing out this fn, return 1. |
| 7125 | */ |
| 7126 | |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7127 | static const char *dlg_icons[] = /* must match names in resource file */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7128 | { |
| 7129 | "IDR_VIM", |
| 7130 | "IDR_VIM_ERROR", |
| 7131 | "IDR_VIM_ALERT", |
| 7132 | "IDR_VIM_INFO", |
| 7133 | "IDR_VIM_QUESTION" |
| 7134 | }; |
| 7135 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7136 | int |
| 7137 | gui_mch_dialog( |
| 7138 | int type, |
| 7139 | char_u *title, |
| 7140 | char_u *message, |
| 7141 | char_u *buttons, |
| 7142 | int dfltbutton, |
Bram Moolenaar | d2c340a | 2011-01-17 20:08:11 +0100 | [diff] [blame] | 7143 | char_u *textfield, |
| 7144 | int ex_cmd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7145 | { |
| 7146 | WORD *p, *pdlgtemplate, *pnumitems; |
Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 7147 | DWORD *dwp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7148 | int numButtons; |
| 7149 | int *buttonWidths, *buttonPositions; |
| 7150 | int buttonYpos; |
| 7151 | int nchar, i; |
| 7152 | DWORD lStyle; |
| 7153 | int dlgwidth = 0; |
| 7154 | int dlgheight; |
| 7155 | int editboxheight; |
| 7156 | int horizWidth = 0; |
| 7157 | int msgheight; |
| 7158 | char_u *pstart; |
| 7159 | char_u *pend; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7160 | char_u *last_white; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7161 | char_u *tbuffer; |
| 7162 | RECT rect; |
| 7163 | HWND hwnd; |
| 7164 | HDC hdc; |
| 7165 | HFONT font, oldFont; |
| 7166 | TEXTMETRIC fontInfo; |
| 7167 | int fontHeight; |
| 7168 | int textWidth, minButtonWidth, messageWidth; |
| 7169 | int maxDialogWidth; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7170 | int maxDialogHeight; |
| 7171 | int scroll_flag = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7172 | int vertical; |
| 7173 | int dlgPaddingX; |
| 7174 | int dlgPaddingY; |
| 7175 | #ifdef USE_SYSMENU_FONT |
| 7176 | LOGFONT lfSysmenu; |
| 7177 | int use_lfSysmenu = FALSE; |
| 7178 | #endif |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7179 | garray_T ga; |
| 7180 | int l; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7181 | |
| 7182 | #ifndef NO_CONSOLE |
| 7183 | /* Don't output anything in silent mode ("ex -s") */ |
| 7184 | if (silent_mode) |
| 7185 | return dfltbutton; /* return default option */ |
| 7186 | #endif |
| 7187 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7188 | if (s_hwnd == NULL) |
| 7189 | get_dialog_font_metrics(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7190 | |
| 7191 | if ((type < 0) || (type > VIM_LAST_TYPE)) |
| 7192 | type = 0; |
| 7193 | |
| 7194 | /* allocate some memory for dialog template */ |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 7195 | /* TODO should compute this really */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7196 | pdlgtemplate = p = (PWORD)LocalAlloc(LPTR, |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7197 | DLG_ALLOC_SIZE + STRLEN(message) * 2); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7198 | |
| 7199 | if (p == NULL) |
| 7200 | return -1; |
| 7201 | |
| 7202 | /* |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 7203 | * make a copy of 'buttons' to fiddle with it. compiler grizzles because |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7204 | * vim_strsave() doesn't take a const arg (why not?), so cast away the |
| 7205 | * const. |
| 7206 | */ |
| 7207 | tbuffer = vim_strsave(buttons); |
| 7208 | if (tbuffer == NULL) |
| 7209 | return -1; |
| 7210 | |
| 7211 | --dfltbutton; /* Change from one-based to zero-based */ |
| 7212 | |
| 7213 | /* Count buttons */ |
| 7214 | numButtons = 1; |
| 7215 | for (i = 0; tbuffer[i] != '\0'; i++) |
| 7216 | { |
| 7217 | if (tbuffer[i] == DLG_BUTTON_SEP) |
| 7218 | numButtons++; |
| 7219 | } |
| 7220 | if (dfltbutton >= numButtons) |
| 7221 | dfltbutton = -1; |
| 7222 | |
| 7223 | /* Allocate array to hold the width of each button */ |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 7224 | buttonWidths = (int *)lalloc(numButtons * sizeof(int), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7225 | if (buttonWidths == NULL) |
| 7226 | return -1; |
| 7227 | |
| 7228 | /* Allocate array to hold the X position of each button */ |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 7229 | buttonPositions = (int *)lalloc(numButtons * sizeof(int), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7230 | if (buttonPositions == NULL) |
| 7231 | return -1; |
| 7232 | |
| 7233 | /* |
| 7234 | * Calculate how big the dialog must be. |
| 7235 | */ |
| 7236 | hwnd = GetDesktopWindow(); |
| 7237 | hdc = GetWindowDC(hwnd); |
| 7238 | #ifdef USE_SYSMENU_FONT |
| 7239 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 7240 | { |
| 7241 | font = CreateFontIndirect(&lfSysmenu); |
| 7242 | use_lfSysmenu = TRUE; |
| 7243 | } |
| 7244 | else |
| 7245 | #endif |
| 7246 | font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 7247 | VARIABLE_PITCH , DLG_FONT_NAME); |
| 7248 | if (s_usenewlook) |
| 7249 | { |
| 7250 | oldFont = SelectFont(hdc, font); |
| 7251 | dlgPaddingX = DLG_PADDING_X; |
| 7252 | dlgPaddingY = DLG_PADDING_Y; |
| 7253 | } |
| 7254 | else |
| 7255 | { |
| 7256 | oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); |
| 7257 | dlgPaddingX = DLG_OLD_STYLE_PADDING_X; |
| 7258 | dlgPaddingY = DLG_OLD_STYLE_PADDING_Y; |
| 7259 | } |
| 7260 | GetTextMetrics(hdc, &fontInfo); |
| 7261 | fontHeight = fontInfo.tmHeight; |
| 7262 | |
| 7263 | /* Minimum width for horizontal button */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7264 | minButtonWidth = GetTextWidth(hdc, (char_u *)"Cancel", 6); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7265 | |
| 7266 | /* Maximum width of a dialog, if possible */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7267 | if (s_hwnd == NULL) |
| 7268 | { |
| 7269 | RECT workarea_rect; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7270 | |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 7271 | /* We don't have a window, use the desktop area. */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7272 | get_work_area(&workarea_rect); |
| 7273 | maxDialogWidth = workarea_rect.right - workarea_rect.left - 100; |
| 7274 | if (maxDialogWidth > 600) |
| 7275 | maxDialogWidth = 600; |
Bram Moolenaar | 1b1b094 | 2013-08-01 13:20:42 +0200 | [diff] [blame] | 7276 | /* Leave some room for the taskbar. */ |
| 7277 | maxDialogHeight = workarea_rect.bottom - workarea_rect.top - 150; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7278 | } |
| 7279 | else |
| 7280 | { |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7281 | /* Use our own window for the size, unless it's very small. */ |
| 7282 | GetWindowRect(s_hwnd, &rect); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7283 | maxDialogWidth = rect.right - rect.left |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 7284 | - (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 7285 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7286 | if (maxDialogWidth < DLG_MIN_MAX_WIDTH) |
| 7287 | maxDialogWidth = DLG_MIN_MAX_WIDTH; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7288 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7289 | maxDialogHeight = rect.bottom - rect.top |
Bram Moolenaar | 1b1b094 | 2013-08-01 13:20:42 +0200 | [diff] [blame] | 7290 | - (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 7291 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 4 |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7292 | - GetSystemMetrics(SM_CYCAPTION); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7293 | if (maxDialogHeight < DLG_MIN_MAX_HEIGHT) |
| 7294 | maxDialogHeight = DLG_MIN_MAX_HEIGHT; |
| 7295 | } |
| 7296 | |
| 7297 | /* Set dlgwidth to width of message. |
| 7298 | * Copy the message into "ga", changing NL to CR-NL and inserting line |
| 7299 | * breaks where needed. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7300 | pstart = message; |
| 7301 | messageWidth = 0; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7302 | msgheight = 0; |
| 7303 | ga_init2(&ga, sizeof(char), 500); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7304 | do |
| 7305 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7306 | msgheight += fontHeight; /* at least one line */ |
| 7307 | |
| 7308 | /* Need to figure out where to break the string. The system does it |
| 7309 | * at a word boundary, which would mean we can't compute the number of |
| 7310 | * wrapped lines. */ |
| 7311 | textWidth = 0; |
| 7312 | last_white = NULL; |
| 7313 | for (pend = pstart; *pend != NUL && *pend != '\n'; ) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7314 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7315 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7316 | l = (*mb_ptr2len)(pend); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7317 | #else |
| 7318 | l = 1; |
| 7319 | #endif |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 7320 | if (l == 1 && VIM_ISWHITE(*pend) |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7321 | && textWidth > maxDialogWidth * 3 / 4) |
| 7322 | last_white = pend; |
Bram Moolenaar | f05d811 | 2013-06-26 12:58:32 +0200 | [diff] [blame] | 7323 | textWidth += GetTextWidthEnc(hdc, pend, l); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7324 | if (textWidth >= maxDialogWidth) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7325 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7326 | /* Line will wrap. */ |
| 7327 | messageWidth = maxDialogWidth; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7328 | msgheight += fontHeight; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7329 | textWidth = 0; |
| 7330 | |
| 7331 | if (last_white != NULL) |
| 7332 | { |
| 7333 | /* break the line just after a space */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 7334 | ga.ga_len -= (int)(pend - (last_white + 1)); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7335 | pend = last_white + 1; |
| 7336 | last_white = NULL; |
| 7337 | } |
| 7338 | ga_append(&ga, '\r'); |
| 7339 | ga_append(&ga, '\n'); |
| 7340 | continue; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7341 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7342 | |
| 7343 | while (--l >= 0) |
| 7344 | ga_append(&ga, *pend++); |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7345 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7346 | if (textWidth > messageWidth) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7347 | messageWidth = textWidth; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7348 | |
| 7349 | ga_append(&ga, '\r'); |
| 7350 | ga_append(&ga, '\n'); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7351 | pstart = pend + 1; |
| 7352 | } while (*pend != NUL); |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7353 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7354 | if (ga.ga_data != NULL) |
| 7355 | message = ga.ga_data; |
| 7356 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7357 | messageWidth += 10; /* roundoff space */ |
| 7358 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7359 | /* Add width of icon to dlgwidth, and some space */ |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7360 | dlgwidth = messageWidth + DLG_ICON_WIDTH + 3 * dlgPaddingX |
| 7361 | + GetSystemMetrics(SM_CXVSCROLL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7362 | |
| 7363 | if (msgheight < DLG_ICON_HEIGHT) |
| 7364 | msgheight = DLG_ICON_HEIGHT; |
| 7365 | |
| 7366 | /* |
| 7367 | * Check button names. A long one will make the dialog wider. |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 7368 | * When called early (-register error message) p_go isn't initialized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7369 | */ |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 7370 | vertical = (p_go != NULL && vim_strchr(p_go, GO_VERTICAL) != NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7371 | if (!vertical) |
| 7372 | { |
| 7373 | // Place buttons horizontally if they fit. |
| 7374 | horizWidth = dlgPaddingX; |
| 7375 | pstart = tbuffer; |
| 7376 | i = 0; |
| 7377 | do |
| 7378 | { |
| 7379 | pend = vim_strchr(pstart, DLG_BUTTON_SEP); |
| 7380 | if (pend == NULL) |
| 7381 | pend = pstart + STRLEN(pstart); // Last button name. |
Bram Moolenaar | b052fe0 | 2013-06-26 13:16:20 +0200 | [diff] [blame] | 7382 | textWidth = GetTextWidthEnc(hdc, pstart, (int)(pend - pstart)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7383 | if (textWidth < minButtonWidth) |
| 7384 | textWidth = minButtonWidth; |
| 7385 | textWidth += dlgPaddingX; /* Padding within button */ |
| 7386 | buttonWidths[i] = textWidth; |
| 7387 | buttonPositions[i++] = horizWidth; |
| 7388 | horizWidth += textWidth + dlgPaddingX; /* Pad between buttons */ |
| 7389 | pstart = pend + 1; |
| 7390 | } while (*pend != NUL); |
| 7391 | |
| 7392 | if (horizWidth > maxDialogWidth) |
| 7393 | vertical = TRUE; // Too wide to fit on the screen. |
| 7394 | else if (horizWidth > dlgwidth) |
| 7395 | dlgwidth = horizWidth; |
| 7396 | } |
| 7397 | |
| 7398 | if (vertical) |
| 7399 | { |
| 7400 | // Stack buttons vertically. |
| 7401 | pstart = tbuffer; |
| 7402 | do |
| 7403 | { |
| 7404 | pend = vim_strchr(pstart, DLG_BUTTON_SEP); |
| 7405 | if (pend == NULL) |
| 7406 | pend = pstart + STRLEN(pstart); // Last button name. |
Bram Moolenaar | b052fe0 | 2013-06-26 13:16:20 +0200 | [diff] [blame] | 7407 | textWidth = GetTextWidthEnc(hdc, pstart, (int)(pend - pstart)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7408 | textWidth += dlgPaddingX; /* Padding within button */ |
| 7409 | textWidth += DLG_VERT_PADDING_X * 2; /* Padding around button */ |
| 7410 | if (textWidth > dlgwidth) |
| 7411 | dlgwidth = textWidth; |
| 7412 | pstart = pend + 1; |
| 7413 | } while (*pend != NUL); |
| 7414 | } |
| 7415 | |
| 7416 | if (dlgwidth < DLG_MIN_WIDTH) |
| 7417 | dlgwidth = DLG_MIN_WIDTH; /* Don't allow a really thin dialog!*/ |
| 7418 | |
| 7419 | /* start to fill in the dlgtemplate information. addressing by WORDs */ |
| 7420 | if (s_usenewlook) |
| 7421 | lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE |DS_SETFONT; |
| 7422 | else |
| 7423 | lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE; |
| 7424 | |
| 7425 | add_long(lStyle); |
| 7426 | add_long(0); // (lExtendedStyle) |
| 7427 | pnumitems = p; /*save where the number of items must be stored*/ |
| 7428 | add_word(0); // NumberOfItems(will change later) |
| 7429 | add_word(10); // x |
| 7430 | add_word(10); // y |
| 7431 | add_word(PixelToDialogX(dlgwidth)); // cx |
| 7432 | |
| 7433 | // Dialog height. |
| 7434 | if (vertical) |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7435 | dlgheight = msgheight + 2 * dlgPaddingY |
| 7436 | + DLG_VERT_PADDING_Y + 2 * fontHeight * numButtons; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7437 | else |
| 7438 | dlgheight = msgheight + 3 * dlgPaddingY + 2 * fontHeight; |
| 7439 | |
| 7440 | // Dialog needs to be taller if contains an edit box. |
| 7441 | editboxheight = fontHeight + dlgPaddingY + 4 * DLG_VERT_PADDING_Y; |
| 7442 | if (textfield != NULL) |
| 7443 | dlgheight += editboxheight; |
| 7444 | |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7445 | /* Restrict the size to a maximum. Causes a scrollbar to show up. */ |
| 7446 | if (dlgheight > maxDialogHeight) |
| 7447 | { |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 7448 | msgheight = msgheight - (dlgheight - maxDialogHeight); |
| 7449 | dlgheight = maxDialogHeight; |
| 7450 | scroll_flag = WS_VSCROLL; |
| 7451 | /* Make sure scrollbar doesn't appear in the middle of the dialog */ |
| 7452 | messageWidth = dlgwidth - DLG_ICON_WIDTH - 3 * dlgPaddingX; |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7453 | } |
| 7454 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7455 | add_word(PixelToDialogY(dlgheight)); |
| 7456 | |
| 7457 | add_word(0); // Menu |
| 7458 | add_word(0); // Class |
| 7459 | |
| 7460 | /* copy the title of the dialog */ |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7461 | nchar = nCopyAnsiToWideChar(p, (title ? (LPSTR)title |
| 7462 | : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7463 | p += nchar; |
| 7464 | |
| 7465 | if (s_usenewlook) |
| 7466 | { |
| 7467 | /* do the font, since DS_3DLOOK doesn't work properly */ |
| 7468 | #ifdef USE_SYSMENU_FONT |
| 7469 | if (use_lfSysmenu) |
| 7470 | { |
| 7471 | /* point size */ |
| 7472 | *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
| 7473 | GetDeviceCaps(hdc, LOGPIXELSY)); |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7474 | nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7475 | } |
| 7476 | else |
| 7477 | #endif |
| 7478 | { |
| 7479 | *p++ = DLG_FONT_POINT_SIZE; // point size |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7480 | nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7481 | } |
| 7482 | p += nchar; |
| 7483 | } |
| 7484 | |
| 7485 | buttonYpos = msgheight + 2 * dlgPaddingY; |
| 7486 | |
| 7487 | if (textfield != NULL) |
| 7488 | buttonYpos += editboxheight; |
| 7489 | |
| 7490 | pstart = tbuffer; |
| 7491 | if (!vertical) |
| 7492 | horizWidth = (dlgwidth - horizWidth) / 2; /* Now it's X offset */ |
| 7493 | for (i = 0; i < numButtons; i++) |
| 7494 | { |
| 7495 | /* get end of this button. */ |
| 7496 | for ( pend = pstart; |
| 7497 | *pend && (*pend != DLG_BUTTON_SEP); |
| 7498 | pend++) |
| 7499 | ; |
| 7500 | |
| 7501 | if (*pend) |
| 7502 | *pend = '\0'; |
| 7503 | |
| 7504 | /* |
| 7505 | * old NOTE: |
| 7506 | * setting the BS_DEFPUSHBUTTON style doesn't work because Windows sets |
| 7507 | * the focus to the first tab-able button and in so doing makes that |
| 7508 | * the default!! Grrr. Workaround: Make the default button the only |
| 7509 | * one with WS_TABSTOP style. Means user can't tab between buttons, but |
| 7510 | * he/she can use arrow keys. |
| 7511 | * |
| 7512 | * new NOTE: BS_DEFPUSHBUTTON is required to be able to select the |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 7513 | * right button when hitting <Enter>. E.g., for the ":confirm quit" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7514 | * dialog. Also needed for when the textfield is the default control. |
| 7515 | * It appears to work now (perhaps not on Win95?). |
| 7516 | */ |
| 7517 | if (vertical) |
| 7518 | { |
| 7519 | p = add_dialog_element(p, |
| 7520 | (i == dfltbutton |
| 7521 | ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, |
| 7522 | PixelToDialogX(DLG_VERT_PADDING_X), |
| 7523 | PixelToDialogY(buttonYpos /* TBK */ |
| 7524 | + 2 * fontHeight * i), |
| 7525 | PixelToDialogX(dlgwidth - 2 * DLG_VERT_PADDING_X), |
| 7526 | (WORD)(PixelToDialogY(2 * fontHeight) - 1), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7527 | (WORD)(IDCANCEL + 1 + i), (WORD)0x0080, (char *)pstart); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7528 | } |
| 7529 | else |
| 7530 | { |
| 7531 | p = add_dialog_element(p, |
| 7532 | (i == dfltbutton |
| 7533 | ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, |
| 7534 | PixelToDialogX(horizWidth + buttonPositions[i]), |
| 7535 | PixelToDialogY(buttonYpos), /* TBK */ |
| 7536 | PixelToDialogX(buttonWidths[i]), |
| 7537 | (WORD)(PixelToDialogY(2 * fontHeight) - 1), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7538 | (WORD)(IDCANCEL + 1 + i), (WORD)0x0080, (char *)pstart); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7539 | } |
| 7540 | pstart = pend + 1; /*next button*/ |
| 7541 | } |
| 7542 | *pnumitems += numButtons; |
| 7543 | |
| 7544 | /* Vim icon */ |
| 7545 | p = add_dialog_element(p, SS_ICON, |
| 7546 | PixelToDialogX(dlgPaddingX), |
| 7547 | PixelToDialogY(dlgPaddingY), |
| 7548 | PixelToDialogX(DLG_ICON_WIDTH), |
| 7549 | PixelToDialogY(DLG_ICON_HEIGHT), |
| 7550 | DLG_NONBUTTON_CONTROL + 0, (WORD)0x0082, |
| 7551 | dlg_icons[type]); |
| 7552 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7553 | /* Dialog message */ |
| 7554 | p = add_dialog_element(p, ES_LEFT|scroll_flag|ES_MULTILINE|ES_READONLY, |
| 7555 | PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH), |
| 7556 | PixelToDialogY(dlgPaddingY), |
| 7557 | (WORD)(PixelToDialogX(messageWidth) + 1), |
| 7558 | PixelToDialogY(msgheight), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7559 | DLG_NONBUTTON_CONTROL + 1, (WORD)0x0081, (char *)message); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7560 | |
| 7561 | /* Edit box */ |
| 7562 | if (textfield != NULL) |
| 7563 | { |
| 7564 | p = add_dialog_element(p, ES_LEFT|ES_AUTOHSCROLL|WS_TABSTOP|WS_BORDER, |
| 7565 | PixelToDialogX(2 * dlgPaddingX), |
| 7566 | PixelToDialogY(2 * dlgPaddingY + msgheight), |
| 7567 | PixelToDialogX(dlgwidth - 4 * dlgPaddingX), |
| 7568 | PixelToDialogY(fontHeight + dlgPaddingY), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7569 | DLG_NONBUTTON_CONTROL + 2, (WORD)0x0081, (char *)textfield); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7570 | *pnumitems += 1; |
| 7571 | } |
| 7572 | |
| 7573 | *pnumitems += 2; |
| 7574 | |
| 7575 | SelectFont(hdc, oldFont); |
| 7576 | DeleteObject(font); |
| 7577 | ReleaseDC(hwnd, hdc); |
| 7578 | |
| 7579 | /* Let the dialog_callback() function know which button to make default |
| 7580 | * If we have an edit box, make that the default. We also need to tell |
| 7581 | * dialog_callback() if this dialog contains an edit box or not. We do |
| 7582 | * this by setting s_textfield if it does. |
| 7583 | */ |
| 7584 | if (textfield != NULL) |
| 7585 | { |
| 7586 | dialog_default_button = DLG_NONBUTTON_CONTROL + 2; |
| 7587 | s_textfield = textfield; |
| 7588 | } |
| 7589 | else |
| 7590 | { |
| 7591 | dialog_default_button = IDCANCEL + 1 + dfltbutton; |
| 7592 | s_textfield = NULL; |
| 7593 | } |
| 7594 | |
| 7595 | /* show the dialog box modally and get a return value */ |
| 7596 | nchar = (int)DialogBoxIndirect( |
| 7597 | s_hinst, |
| 7598 | (LPDLGTEMPLATE)pdlgtemplate, |
| 7599 | s_hwnd, |
| 7600 | (DLGPROC)dialog_callback); |
| 7601 | |
| 7602 | LocalFree(LocalHandle(pdlgtemplate)); |
| 7603 | vim_free(tbuffer); |
| 7604 | vim_free(buttonWidths); |
| 7605 | vim_free(buttonPositions); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7606 | vim_free(ga.ga_data); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7607 | |
| 7608 | /* Focus back to our window (for when MDI is used). */ |
| 7609 | (void)SetFocus(s_hwnd); |
| 7610 | |
| 7611 | return nchar; |
| 7612 | } |
| 7613 | |
| 7614 | #endif /* FEAT_GUI_DIALOG */ |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7615 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7616 | /* |
| 7617 | * Put a simple element (basic class) onto a dialog template in memory. |
| 7618 | * return a pointer to where the next item should be added. |
| 7619 | * |
| 7620 | * parameters: |
| 7621 | * lStyle = additional style flags |
| 7622 | * (be careful, NT3.51 & Win32s will ignore the new ones) |
| 7623 | * x,y = x & y positions IN DIALOG UNITS |
| 7624 | * w,h = width and height IN DIALOG UNITS |
| 7625 | * Id = ID used in messages |
| 7626 | * clss = class ID, e.g 0x0080 for a button, 0x0082 for a static |
| 7627 | * caption = usually text or resource name |
| 7628 | * |
| 7629 | * TODO: use the length information noted here to enable the dialog creation |
| 7630 | * routines to work out more exactly how much memory they need to alloc. |
| 7631 | */ |
| 7632 | static PWORD |
| 7633 | add_dialog_element( |
| 7634 | PWORD p, |
| 7635 | DWORD lStyle, |
| 7636 | WORD x, |
| 7637 | WORD y, |
| 7638 | WORD w, |
| 7639 | WORD h, |
| 7640 | WORD Id, |
| 7641 | WORD clss, |
| 7642 | const char *caption) |
| 7643 | { |
| 7644 | int nchar; |
| 7645 | |
| 7646 | p = lpwAlign(p); /* Align to dword boundary*/ |
| 7647 | lStyle = lStyle | WS_VISIBLE | WS_CHILD; |
| 7648 | *p++ = LOWORD(lStyle); |
| 7649 | *p++ = HIWORD(lStyle); |
| 7650 | *p++ = 0; // LOWORD (lExtendedStyle) |
| 7651 | *p++ = 0; // HIWORD (lExtendedStyle) |
| 7652 | *p++ = x; |
| 7653 | *p++ = y; |
| 7654 | *p++ = w; |
| 7655 | *p++ = h; |
| 7656 | *p++ = Id; //9 or 10 words in all |
| 7657 | |
| 7658 | *p++ = (WORD)0xffff; |
| 7659 | *p++ = clss; //2 more here |
| 7660 | |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7661 | nchar = nCopyAnsiToWideChar(p, (LPSTR)caption, TRUE); //strlen(caption)+1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7662 | p += nchar; |
| 7663 | |
| 7664 | *p++ = 0; // advance pointer over nExtraStuff WORD - 2 more |
| 7665 | |
| 7666 | return p; //total = 15+ (strlen(caption)) words |
| 7667 | // = 30 + 2(strlen(caption) bytes reqd |
| 7668 | } |
| 7669 | |
| 7670 | |
| 7671 | /* |
| 7672 | * Helper routine. Take an input pointer, return closest pointer that is |
| 7673 | * aligned on a DWORD (4 byte) boundary. Taken from the Win32SDK samples. |
| 7674 | */ |
| 7675 | static LPWORD |
| 7676 | lpwAlign( |
| 7677 | LPWORD lpIn) |
| 7678 | { |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7679 | long_u ul; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7680 | |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7681 | ul = (long_u)lpIn; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7682 | ul += 3; |
| 7683 | ul >>= 2; |
| 7684 | ul <<= 2; |
| 7685 | return (LPWORD)ul; |
| 7686 | } |
| 7687 | |
| 7688 | /* |
| 7689 | * Helper routine. Takes second parameter as Ansi string, copies it to first |
| 7690 | * parameter as wide character (16-bits / char) string, and returns integer |
| 7691 | * number of wide characters (words) in string (including the trailing wide |
| 7692 | * char NULL). Partly taken from the Win32SDK samples. |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7693 | * If "use_enc" is TRUE, 'encoding' is used for "lpAnsiIn". If FALSE, current |
| 7694 | * ACP is used for "lpAnsiIn". */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7695 | static int |
| 7696 | nCopyAnsiToWideChar( |
| 7697 | LPWORD lpWCStr, |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7698 | LPSTR lpAnsiIn, |
| 7699 | BOOL use_enc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7700 | { |
| 7701 | int nChar = 0; |
| 7702 | #ifdef FEAT_MBYTE |
| 7703 | int len = lstrlen(lpAnsiIn) + 1; /* include NUL character */ |
| 7704 | int i; |
| 7705 | WCHAR *wn; |
| 7706 | |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7707 | if (use_enc && enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7708 | { |
| 7709 | /* Not a codepage, use our own conversion function. */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7710 | wn = enc_to_utf16((char_u *)lpAnsiIn, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7711 | if (wn != NULL) |
| 7712 | { |
| 7713 | wcscpy(lpWCStr, wn); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 7714 | nChar = (int)wcslen(wn) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7715 | vim_free(wn); |
| 7716 | } |
| 7717 | } |
| 7718 | if (nChar == 0) |
| 7719 | /* Use Win32 conversion function. */ |
| 7720 | nChar = MultiByteToWideChar( |
| 7721 | enc_codepage > 0 ? enc_codepage : CP_ACP, |
| 7722 | MB_PRECOMPOSED, |
| 7723 | lpAnsiIn, len, |
| 7724 | lpWCStr, len); |
| 7725 | for (i = 0; i < nChar; ++i) |
| 7726 | if (lpWCStr[i] == (WORD)'\t') /* replace tabs with spaces */ |
| 7727 | lpWCStr[i] = (WORD)' '; |
| 7728 | #else |
| 7729 | do |
| 7730 | { |
| 7731 | if (*lpAnsiIn == '\t') |
| 7732 | *lpWCStr++ = (WORD)' '; |
| 7733 | else |
| 7734 | *lpWCStr++ = (WORD)*lpAnsiIn; |
| 7735 | nChar++; |
| 7736 | } while (*lpAnsiIn++); |
| 7737 | #endif |
| 7738 | |
| 7739 | return nChar; |
| 7740 | } |
| 7741 | |
| 7742 | |
| 7743 | #ifdef FEAT_TEAROFF |
| 7744 | /* |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7745 | * Lookup menu handle from "menu_id". |
| 7746 | */ |
| 7747 | static HMENU |
| 7748 | tearoff_lookup_menuhandle( |
| 7749 | vimmenu_T *menu, |
| 7750 | WORD menu_id) |
| 7751 | { |
| 7752 | for ( ; menu != NULL; menu = menu->next) |
| 7753 | { |
| 7754 | if (menu->modes == 0) /* this menu has just been deleted */ |
| 7755 | continue; |
| 7756 | if (menu_is_separator(menu->dname)) |
| 7757 | continue; |
| 7758 | if ((WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000) == menu_id) |
| 7759 | return menu->submenu_id; |
| 7760 | } |
| 7761 | return NULL; |
| 7762 | } |
| 7763 | |
| 7764 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7765 | * The callback function for all the modeless dialogs that make up the |
| 7766 | * "tearoff menus" Very simple - forward button presses (to fool Vim into |
| 7767 | * thinking its menus have been clicked), and go away when closed. |
| 7768 | */ |
| 7769 | static LRESULT CALLBACK |
| 7770 | tearoff_callback( |
| 7771 | HWND hwnd, |
| 7772 | UINT message, |
| 7773 | WPARAM wParam, |
| 7774 | LPARAM lParam) |
| 7775 | { |
| 7776 | if (message == WM_INITDIALOG) |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7777 | { |
| 7778 | SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7779 | return (TRUE); |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7780 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7781 | |
| 7782 | /* May show the mouse pointer again. */ |
| 7783 | HandleMouseHide(message, lParam); |
| 7784 | |
| 7785 | if (message == WM_COMMAND) |
| 7786 | { |
| 7787 | if ((WORD)(LOWORD(wParam)) & 0x8000) |
| 7788 | { |
| 7789 | POINT mp; |
| 7790 | RECT rect; |
| 7791 | |
| 7792 | if (GetCursorPos(&mp) && GetWindowRect(hwnd, &rect)) |
| 7793 | { |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7794 | vimmenu_T *menu; |
| 7795 | |
| 7796 | menu = (vimmenu_T*)GetWindowLongPtr(hwnd, DWLP_USER); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7797 | (void)TrackPopupMenu( |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7798 | tearoff_lookup_menuhandle(menu, LOWORD(wParam)), |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7799 | TPM_LEFTALIGN | TPM_LEFTBUTTON, |
| 7800 | (int)rect.right - 8, |
| 7801 | (int)mp.y, |
| 7802 | (int)0, /*reserved param*/ |
| 7803 | s_hwnd, |
| 7804 | NULL); |
| 7805 | /* |
| 7806 | * NOTE: The pop-up menu can eat the mouse up event. |
| 7807 | * We deal with this in normal.c. |
| 7808 | */ |
| 7809 | } |
| 7810 | } |
| 7811 | else |
| 7812 | /* Pass on messages to the main Vim window */ |
| 7813 | PostMessage(s_hwnd, WM_COMMAND, LOWORD(wParam), 0); |
| 7814 | /* |
| 7815 | * Give main window the focus back: this is so after |
| 7816 | * choosing a tearoff button you can start typing again |
| 7817 | * straight away. |
| 7818 | */ |
| 7819 | (void)SetFocus(s_hwnd); |
| 7820 | return TRUE; |
| 7821 | } |
| 7822 | if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) |
| 7823 | { |
| 7824 | DestroyWindow(hwnd); |
| 7825 | return TRUE; |
| 7826 | } |
| 7827 | |
| 7828 | /* When moved around, give main window the focus back. */ |
| 7829 | if (message == WM_EXITSIZEMOVE) |
| 7830 | (void)SetActiveWindow(s_hwnd); |
| 7831 | |
| 7832 | return FALSE; |
| 7833 | } |
| 7834 | #endif |
| 7835 | |
| 7836 | |
| 7837 | /* |
| 7838 | * Decide whether to use the "new look" (small, non-bold font) or the "old |
| 7839 | * look" (big, clanky font) for dialogs, and work out a few values for use |
| 7840 | * later accordingly. |
| 7841 | */ |
| 7842 | static void |
| 7843 | get_dialog_font_metrics(void) |
| 7844 | { |
| 7845 | HDC hdc; |
| 7846 | HFONT hfontTools = 0; |
| 7847 | DWORD dlgFontSize; |
| 7848 | SIZE size; |
| 7849 | #ifdef USE_SYSMENU_FONT |
| 7850 | LOGFONT lfSysmenu; |
| 7851 | #endif |
| 7852 | |
| 7853 | s_usenewlook = FALSE; |
| 7854 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7855 | #ifdef USE_SYSMENU_FONT |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7856 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 7857 | hfontTools = CreateFontIndirect(&lfSysmenu); |
| 7858 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7859 | #endif |
| 7860 | hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, |
| 7861 | 0, 0, 0, 0, VARIABLE_PITCH , DLG_FONT_NAME); |
| 7862 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7863 | if (hfontTools) |
| 7864 | { |
| 7865 | hdc = GetDC(s_hwnd); |
| 7866 | SelectObject(hdc, hfontTools); |
| 7867 | /* |
| 7868 | * GetTextMetrics() doesn't return the right value in |
| 7869 | * tmAveCharWidth, so we have to figure out the dialog base units |
| 7870 | * ourselves. |
| 7871 | */ |
| 7872 | GetTextExtentPoint(hdc, |
| 7873 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", |
| 7874 | 52, &size); |
| 7875 | ReleaseDC(s_hwnd, hdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7876 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7877 | s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); |
| 7878 | s_dlgfntheight = (WORD)size.cy; |
| 7879 | s_usenewlook = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7880 | } |
| 7881 | |
| 7882 | if (!s_usenewlook) |
| 7883 | { |
| 7884 | dlgFontSize = GetDialogBaseUnits(); /* fall back to big old system*/ |
| 7885 | s_dlgfntwidth = LOWORD(dlgFontSize); |
| 7886 | s_dlgfntheight = HIWORD(dlgFontSize); |
| 7887 | } |
| 7888 | } |
| 7889 | |
| 7890 | #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
| 7891 | /* |
| 7892 | * Create a pseudo-"tearoff menu" based on the child |
| 7893 | * items of a given menu pointer. |
| 7894 | */ |
| 7895 | static void |
| 7896 | gui_mch_tearoff( |
| 7897 | char_u *title, |
| 7898 | vimmenu_T *menu, |
| 7899 | int initX, |
| 7900 | int initY) |
| 7901 | { |
| 7902 | WORD *p, *pdlgtemplate, *pnumitems, *ptrueheight; |
| 7903 | int template_len; |
| 7904 | int nchar, textWidth, submenuWidth; |
| 7905 | DWORD lStyle; |
| 7906 | DWORD lExtendedStyle; |
| 7907 | WORD dlgwidth; |
| 7908 | WORD menuID; |
| 7909 | vimmenu_T *pmenu; |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7910 | vimmenu_T *top_menu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7911 | vimmenu_T *the_menu = menu; |
| 7912 | HWND hwnd; |
| 7913 | HDC hdc; |
| 7914 | HFONT font, oldFont; |
| 7915 | int col, spaceWidth, len; |
| 7916 | int columnWidths[2]; |
| 7917 | char_u *label, *text; |
| 7918 | int acLen = 0; |
| 7919 | int nameLen; |
| 7920 | int padding0, padding1, padding2 = 0; |
| 7921 | int sepPadding=0; |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 7922 | int x; |
| 7923 | int y; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7924 | #ifdef USE_SYSMENU_FONT |
| 7925 | LOGFONT lfSysmenu; |
| 7926 | int use_lfSysmenu = FALSE; |
| 7927 | #endif |
| 7928 | |
| 7929 | /* |
| 7930 | * If this menu is already torn off, move it to the mouse position. |
| 7931 | */ |
| 7932 | if (IsWindow(menu->tearoff_handle)) |
| 7933 | { |
| 7934 | POINT mp; |
| 7935 | if (GetCursorPos((LPPOINT)&mp)) |
| 7936 | { |
| 7937 | SetWindowPos(menu->tearoff_handle, NULL, mp.x, mp.y, 0, 0, |
| 7938 | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); |
| 7939 | } |
| 7940 | return; |
| 7941 | } |
| 7942 | |
| 7943 | /* |
| 7944 | * Create a new tearoff. |
| 7945 | */ |
| 7946 | if (*title == MNU_HIDDEN_CHAR) |
| 7947 | title++; |
| 7948 | |
| 7949 | /* Allocate memory to store the dialog template. It's made bigger when |
| 7950 | * needed. */ |
| 7951 | template_len = DLG_ALLOC_SIZE; |
| 7952 | pdlgtemplate = p = (WORD *)LocalAlloc(LPTR, template_len); |
| 7953 | if (p == NULL) |
| 7954 | return; |
| 7955 | |
| 7956 | hwnd = GetDesktopWindow(); |
| 7957 | hdc = GetWindowDC(hwnd); |
| 7958 | #ifdef USE_SYSMENU_FONT |
| 7959 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 7960 | { |
| 7961 | font = CreateFontIndirect(&lfSysmenu); |
| 7962 | use_lfSysmenu = TRUE; |
| 7963 | } |
| 7964 | else |
| 7965 | #endif |
| 7966 | font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 7967 | VARIABLE_PITCH , DLG_FONT_NAME); |
| 7968 | if (s_usenewlook) |
| 7969 | oldFont = SelectFont(hdc, font); |
| 7970 | else |
| 7971 | oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); |
| 7972 | |
| 7973 | /* Calculate width of a single space. Used for padding columns to the |
| 7974 | * right width. */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7975 | spaceWidth = GetTextWidth(hdc, (char_u *)" ", 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7976 | |
| 7977 | /* Figure out max width of the text column, the accelerator column and the |
| 7978 | * optional submenu column. */ |
| 7979 | submenuWidth = 0; |
| 7980 | for (col = 0; col < 2; col++) |
| 7981 | { |
| 7982 | columnWidths[col] = 0; |
| 7983 | for (pmenu = menu->children; pmenu != NULL; pmenu = pmenu->next) |
| 7984 | { |
| 7985 | /* Use "dname" here to compute the width of the visible text. */ |
| 7986 | text = (col == 0) ? pmenu->dname : pmenu->actext; |
| 7987 | if (text != NULL && *text != NUL) |
| 7988 | { |
| 7989 | textWidth = GetTextWidthEnc(hdc, text, (int)STRLEN(text)); |
| 7990 | if (textWidth > columnWidths[col]) |
| 7991 | columnWidths[col] = textWidth; |
| 7992 | } |
| 7993 | if (pmenu->children != NULL) |
| 7994 | submenuWidth = TEAROFF_COLUMN_PADDING * spaceWidth; |
| 7995 | } |
| 7996 | } |
| 7997 | if (columnWidths[1] == 0) |
| 7998 | { |
| 7999 | /* no accelerators */ |
| 8000 | if (submenuWidth != 0) |
| 8001 | columnWidths[0] += submenuWidth; |
| 8002 | else |
| 8003 | columnWidths[0] += spaceWidth; |
| 8004 | } |
| 8005 | else |
| 8006 | { |
| 8007 | /* there is an accelerator column */ |
| 8008 | columnWidths[0] += TEAROFF_COLUMN_PADDING * spaceWidth; |
| 8009 | columnWidths[1] += submenuWidth; |
| 8010 | } |
| 8011 | |
| 8012 | /* |
| 8013 | * Now find the total width of our 'menu'. |
| 8014 | */ |
| 8015 | textWidth = columnWidths[0] + columnWidths[1]; |
| 8016 | if (submenuWidth != 0) |
| 8017 | { |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8018 | submenuWidth = GetTextWidth(hdc, (char_u *)TEAROFF_SUBMENU_LABEL, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8019 | (int)STRLEN(TEAROFF_SUBMENU_LABEL)); |
| 8020 | textWidth += submenuWidth; |
| 8021 | } |
| 8022 | dlgwidth = GetTextWidthEnc(hdc, title, (int)STRLEN(title)); |
| 8023 | if (textWidth > dlgwidth) |
| 8024 | dlgwidth = textWidth; |
| 8025 | dlgwidth += 2 * TEAROFF_PADDING_X + TEAROFF_BUTTON_PAD_X; |
| 8026 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8027 | /* start to fill in the dlgtemplate information. addressing by WORDs */ |
| 8028 | if (s_usenewlook) |
| 8029 | lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU |DS_SETFONT| WS_VISIBLE; |
| 8030 | else |
| 8031 | lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU | WS_VISIBLE; |
| 8032 | |
| 8033 | lExtendedStyle = WS_EX_TOOLWINDOW|WS_EX_STATICEDGE; |
| 8034 | *p++ = LOWORD(lStyle); |
| 8035 | *p++ = HIWORD(lStyle); |
| 8036 | *p++ = LOWORD(lExtendedStyle); |
| 8037 | *p++ = HIWORD(lExtendedStyle); |
| 8038 | pnumitems = p; /* save where the number of items must be stored */ |
| 8039 | *p++ = 0; // NumberOfItems(will change later) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 8040 | gui_mch_getmouse(&x, &y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8041 | if (initX == 0xffffL) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 8042 | *p++ = PixelToDialogX(x); // x |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8043 | else |
| 8044 | *p++ = PixelToDialogX(initX); // x |
| 8045 | if (initY == 0xffffL) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 8046 | *p++ = PixelToDialogY(y); // y |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8047 | else |
| 8048 | *p++ = PixelToDialogY(initY); // y |
| 8049 | *p++ = PixelToDialogX(dlgwidth); // cx |
| 8050 | ptrueheight = p; |
| 8051 | *p++ = 0; // dialog height: changed later anyway |
| 8052 | *p++ = 0; // Menu |
| 8053 | *p++ = 0; // Class |
| 8054 | |
| 8055 | /* copy the title of the dialog */ |
| 8056 | nchar = nCopyAnsiToWideChar(p, ((*title) |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 8057 | ? (LPSTR)title |
| 8058 | : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8059 | p += nchar; |
| 8060 | |
| 8061 | if (s_usenewlook) |
| 8062 | { |
| 8063 | /* do the font, since DS_3DLOOK doesn't work properly */ |
| 8064 | #ifdef USE_SYSMENU_FONT |
| 8065 | if (use_lfSysmenu) |
| 8066 | { |
| 8067 | /* point size */ |
| 8068 | *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
| 8069 | GetDeviceCaps(hdc, LOGPIXELSY)); |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 8070 | nchar = nCopyAnsiToWideChar(p, lfSysmenu.lfFaceName, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8071 | } |
| 8072 | else |
| 8073 | #endif |
| 8074 | { |
| 8075 | *p++ = DLG_FONT_POINT_SIZE; // point size |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 8076 | nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8077 | } |
| 8078 | p += nchar; |
| 8079 | } |
| 8080 | |
| 8081 | /* |
| 8082 | * Loop over all the items in the menu. |
| 8083 | * But skip over the tearbar. |
| 8084 | */ |
| 8085 | if (STRCMP(menu->children->name, TEAR_STRING) == 0) |
| 8086 | menu = menu->children->next; |
| 8087 | else |
| 8088 | menu = menu->children; |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 8089 | top_menu = menu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8090 | for ( ; menu != NULL; menu = menu->next) |
| 8091 | { |
| 8092 | if (menu->modes == 0) /* this menu has just been deleted */ |
| 8093 | continue; |
| 8094 | if (menu_is_separator(menu->dname)) |
| 8095 | { |
| 8096 | sepPadding += 3; |
| 8097 | continue; |
| 8098 | } |
| 8099 | |
| 8100 | /* Check if there still is plenty of room in the template. Make it |
| 8101 | * larger when needed. */ |
| 8102 | if (((char *)p - (char *)pdlgtemplate) + 1000 > template_len) |
| 8103 | { |
| 8104 | WORD *newp; |
| 8105 | |
| 8106 | newp = (WORD *)LocalAlloc(LPTR, template_len + 4096); |
| 8107 | if (newp != NULL) |
| 8108 | { |
| 8109 | template_len += 4096; |
| 8110 | mch_memmove(newp, pdlgtemplate, |
| 8111 | (char *)p - (char *)pdlgtemplate); |
| 8112 | p = newp + (p - pdlgtemplate); |
| 8113 | pnumitems = newp + (pnumitems - pdlgtemplate); |
| 8114 | ptrueheight = newp + (ptrueheight - pdlgtemplate); |
| 8115 | LocalFree(LocalHandle(pdlgtemplate)); |
| 8116 | pdlgtemplate = newp; |
| 8117 | } |
| 8118 | } |
| 8119 | |
| 8120 | /* Figure out minimal length of this menu label. Use "name" for the |
| 8121 | * actual text, "dname" for estimating the displayed size. "name" |
| 8122 | * has "&a" for mnemonic and includes the accelerator. */ |
| 8123 | len = nameLen = (int)STRLEN(menu->name); |
| 8124 | padding0 = (columnWidths[0] - GetTextWidthEnc(hdc, menu->dname, |
| 8125 | (int)STRLEN(menu->dname))) / spaceWidth; |
| 8126 | len += padding0; |
| 8127 | |
| 8128 | if (menu->actext != NULL) |
| 8129 | { |
| 8130 | acLen = (int)STRLEN(menu->actext); |
| 8131 | len += acLen; |
| 8132 | textWidth = GetTextWidthEnc(hdc, menu->actext, acLen); |
| 8133 | } |
| 8134 | else |
| 8135 | textWidth = 0; |
| 8136 | padding1 = (columnWidths[1] - textWidth) / spaceWidth; |
| 8137 | len += padding1; |
| 8138 | |
| 8139 | if (menu->children == NULL) |
| 8140 | { |
| 8141 | padding2 = submenuWidth / spaceWidth; |
| 8142 | len += padding2; |
| 8143 | menuID = (WORD)(menu->id); |
| 8144 | } |
| 8145 | else |
| 8146 | { |
| 8147 | len += (int)STRLEN(TEAROFF_SUBMENU_LABEL); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 8148 | menuID = (WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8149 | } |
| 8150 | |
| 8151 | /* Allocate menu label and fill it in */ |
| 8152 | text = label = alloc((unsigned)len + 1); |
| 8153 | if (label == NULL) |
| 8154 | break; |
| 8155 | |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 8156 | vim_strncpy(text, menu->name, nameLen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8157 | text = vim_strchr(text, TAB); /* stop at TAB before actext */ |
| 8158 | if (text == NULL) |
| 8159 | text = label + nameLen; /* no actext, use whole name */ |
| 8160 | while (padding0-- > 0) |
| 8161 | *text++ = ' '; |
| 8162 | if (menu->actext != NULL) |
| 8163 | { |
| 8164 | STRNCPY(text, menu->actext, acLen); |
| 8165 | text += acLen; |
| 8166 | } |
| 8167 | while (padding1-- > 0) |
| 8168 | *text++ = ' '; |
| 8169 | if (menu->children != NULL) |
| 8170 | { |
| 8171 | STRCPY(text, TEAROFF_SUBMENU_LABEL); |
| 8172 | text += STRLEN(TEAROFF_SUBMENU_LABEL); |
| 8173 | } |
| 8174 | else |
| 8175 | { |
| 8176 | while (padding2-- > 0) |
| 8177 | *text++ = ' '; |
| 8178 | } |
| 8179 | *text = NUL; |
| 8180 | |
| 8181 | /* |
| 8182 | * BS_LEFT will just be ignored on Win32s/NT3.5x - on |
| 8183 | * W95/NT4 it makes the tear-off look more like a menu. |
| 8184 | */ |
| 8185 | p = add_dialog_element(p, |
| 8186 | BS_PUSHBUTTON|BS_LEFT, |
| 8187 | (WORD)PixelToDialogX(TEAROFF_PADDING_X), |
| 8188 | (WORD)(sepPadding + 1 + 13 * (*pnumitems)), |
| 8189 | (WORD)PixelToDialogX(dlgwidth - 2 * TEAROFF_PADDING_X), |
| 8190 | (WORD)12, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8191 | menuID, (WORD)0x0080, (char *)label); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8192 | vim_free(label); |
| 8193 | (*pnumitems)++; |
| 8194 | } |
| 8195 | |
| 8196 | *ptrueheight = (WORD)(sepPadding + 1 + 13 * (*pnumitems)); |
| 8197 | |
| 8198 | |
| 8199 | /* show modelessly */ |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 8200 | the_menu->tearoff_handle = CreateDialogIndirectParam( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8201 | s_hinst, |
| 8202 | (LPDLGTEMPLATE)pdlgtemplate, |
| 8203 | s_hwnd, |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 8204 | (DLGPROC)tearoff_callback, |
| 8205 | (LPARAM)top_menu); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8206 | |
| 8207 | LocalFree(LocalHandle(pdlgtemplate)); |
| 8208 | SelectFont(hdc, oldFont); |
| 8209 | DeleteObject(font); |
| 8210 | ReleaseDC(hwnd, hdc); |
| 8211 | |
| 8212 | /* |
| 8213 | * Reassert ourselves as the active window. This is so that after creating |
| 8214 | * a tearoff, the user doesn't have to click with the mouse just to start |
| 8215 | * typing again! |
| 8216 | */ |
| 8217 | (void)SetActiveWindow(s_hwnd); |
| 8218 | |
| 8219 | /* make sure the right buttons are enabled */ |
| 8220 | force_menu_update = TRUE; |
| 8221 | } |
| 8222 | #endif |
| 8223 | |
| 8224 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 8225 | #include "gui_w32_rc.h" |
| 8226 | |
| 8227 | /* This not defined in older SDKs */ |
| 8228 | # ifndef TBSTYLE_FLAT |
| 8229 | # define TBSTYLE_FLAT 0x0800 |
| 8230 | # endif |
| 8231 | |
| 8232 | /* |
| 8233 | * Create the toolbar, initially unpopulated. |
| 8234 | * (just like the menu, there are no defaults, it's all |
| 8235 | * set up through menu.vim) |
| 8236 | */ |
| 8237 | static void |
| 8238 | initialise_toolbar(void) |
| 8239 | { |
| 8240 | InitCommonControls(); |
| 8241 | s_toolbarhwnd = CreateToolbarEx( |
| 8242 | s_hwnd, |
| 8243 | WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT, |
| 8244 | 4000, //any old big number |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8245 | 31, //number of images in initial bitmap |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8246 | s_hinst, |
| 8247 | IDR_TOOLBAR1, // id of initial bitmap |
| 8248 | NULL, |
| 8249 | 0, // initial number of buttons |
| 8250 | TOOLBAR_BUTTON_WIDTH, //api guide is wrong! |
| 8251 | TOOLBAR_BUTTON_HEIGHT, |
| 8252 | TOOLBAR_BUTTON_WIDTH, |
| 8253 | TOOLBAR_BUTTON_HEIGHT, |
| 8254 | sizeof(TBBUTTON) |
| 8255 | ); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8256 | s_toolbar_wndproc = SubclassWindow(s_toolbarhwnd, toolbar_wndproc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8257 | |
| 8258 | gui_mch_show_toolbar(vim_strchr(p_go, GO_TOOLBAR) != NULL); |
| 8259 | } |
| 8260 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8261 | static LRESULT CALLBACK |
| 8262 | toolbar_wndproc( |
| 8263 | HWND hwnd, |
| 8264 | UINT uMsg, |
| 8265 | WPARAM wParam, |
| 8266 | LPARAM lParam) |
| 8267 | { |
| 8268 | HandleMouseHide(uMsg, lParam); |
| 8269 | return CallWindowProc(s_toolbar_wndproc, hwnd, uMsg, wParam, lParam); |
| 8270 | } |
| 8271 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8272 | static int |
| 8273 | get_toolbar_bitmap(vimmenu_T *menu) |
| 8274 | { |
| 8275 | int i = -1; |
| 8276 | |
| 8277 | /* |
| 8278 | * Check user bitmaps first, unless builtin is specified. |
| 8279 | */ |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 8280 | if (!menu->icon_builtin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8281 | { |
| 8282 | char_u fname[MAXPATHL]; |
| 8283 | HANDLE hbitmap = NULL; |
| 8284 | |
| 8285 | if (menu->iconfile != NULL) |
| 8286 | { |
| 8287 | gui_find_iconfile(menu->iconfile, fname, "bmp"); |
| 8288 | hbitmap = LoadImage( |
| 8289 | NULL, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8290 | (LPCSTR)fname, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8291 | IMAGE_BITMAP, |
| 8292 | TOOLBAR_BUTTON_WIDTH, |
| 8293 | TOOLBAR_BUTTON_HEIGHT, |
| 8294 | LR_LOADFROMFILE | |
| 8295 | LR_LOADMAP3DCOLORS |
| 8296 | ); |
| 8297 | } |
| 8298 | |
| 8299 | /* |
| 8300 | * If the LoadImage call failed, or the "icon=" file |
| 8301 | * didn't exist or wasn't specified, try the menu name |
| 8302 | */ |
| 8303 | if (hbitmap == NULL |
Bram Moolenaar | a5f5c8b | 2013-06-27 22:29:38 +0200 | [diff] [blame] | 8304 | && (gui_find_bitmap( |
| 8305 | #ifdef FEAT_MULTI_LANG |
| 8306 | menu->en_dname != NULL ? menu->en_dname : |
| 8307 | #endif |
| 8308 | menu->dname, fname, "bmp") == OK)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8309 | hbitmap = LoadImage( |
| 8310 | NULL, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8311 | (LPCSTR)fname, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8312 | IMAGE_BITMAP, |
| 8313 | TOOLBAR_BUTTON_WIDTH, |
| 8314 | TOOLBAR_BUTTON_HEIGHT, |
| 8315 | LR_LOADFROMFILE | |
| 8316 | LR_LOADMAP3DCOLORS |
| 8317 | ); |
| 8318 | |
| 8319 | if (hbitmap != NULL) |
| 8320 | { |
| 8321 | TBADDBITMAP tbAddBitmap; |
| 8322 | |
| 8323 | tbAddBitmap.hInst = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 8324 | tbAddBitmap.nID = (long_u)hbitmap; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8325 | |
| 8326 | i = (int)SendMessage(s_toolbarhwnd, TB_ADDBITMAP, |
| 8327 | (WPARAM)1, (LPARAM)&tbAddBitmap); |
| 8328 | /* i will be set to -1 if it fails */ |
| 8329 | } |
| 8330 | } |
| 8331 | if (i == -1 && menu->iconidx >= 0 && menu->iconidx < TOOLBAR_BITMAP_COUNT) |
| 8332 | i = menu->iconidx; |
| 8333 | |
| 8334 | return i; |
| 8335 | } |
| 8336 | #endif |
| 8337 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 8338 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
| 8339 | static void |
| 8340 | initialise_tabline(void) |
| 8341 | { |
| 8342 | InitCommonControls(); |
| 8343 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8344 | s_tabhwnd = CreateWindow(WC_TABCONTROL, "Vim tabline", |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 8345 | WS_CHILD|TCS_FOCUSNEVER|TCS_TOOLTIPS, |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 8346 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 8347 | CW_USEDEFAULT, s_hwnd, NULL, s_hinst, NULL); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8348 | s_tabline_wndproc = SubclassWindow(s_tabhwnd, tabline_wndproc); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8349 | |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 8350 | gui.tabline_height = TABLINE_HEIGHT; |
| 8351 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8352 | # ifdef USE_SYSMENU_FONT |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 8353 | set_tabline_font(); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 8354 | # endif |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 8355 | } |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8356 | |
Bram Moolenaar | ca05aa2 | 2017-10-22 15:36:14 +0200 | [diff] [blame] | 8357 | /* |
| 8358 | * Get tabpage_T from POINT. |
| 8359 | */ |
| 8360 | static tabpage_T * |
| 8361 | GetTabFromPoint( |
| 8362 | HWND hWnd, |
| 8363 | POINT pt) |
| 8364 | { |
| 8365 | tabpage_T *ptp = NULL; |
| 8366 | |
| 8367 | if (gui_mch_showing_tabline()) |
| 8368 | { |
| 8369 | TCHITTESTINFO htinfo; |
| 8370 | htinfo.pt = pt; |
| 8371 | /* ignore if a window under cusor is not tabcontrol. */ |
| 8372 | if (s_tabhwnd == hWnd) |
| 8373 | { |
| 8374 | int idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 8375 | if (idx != -1) |
| 8376 | ptp = find_tabpage(idx + 1); |
| 8377 | } |
| 8378 | } |
| 8379 | return ptp; |
| 8380 | } |
| 8381 | |
| 8382 | static POINT s_pt = {0, 0}; |
| 8383 | static HCURSOR s_hCursor = NULL; |
| 8384 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8385 | static LRESULT CALLBACK |
| 8386 | tabline_wndproc( |
| 8387 | HWND hwnd, |
| 8388 | UINT uMsg, |
| 8389 | WPARAM wParam, |
| 8390 | LPARAM lParam) |
| 8391 | { |
Bram Moolenaar | ca05aa2 | 2017-10-22 15:36:14 +0200 | [diff] [blame] | 8392 | POINT pt; |
| 8393 | tabpage_T *tp; |
| 8394 | RECT rect; |
| 8395 | int nCenter; |
| 8396 | int idx0; |
| 8397 | int idx1; |
| 8398 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8399 | HandleMouseHide(uMsg, lParam); |
Bram Moolenaar | ca05aa2 | 2017-10-22 15:36:14 +0200 | [diff] [blame] | 8400 | |
| 8401 | switch (uMsg) |
| 8402 | { |
| 8403 | case WM_LBUTTONDOWN: |
| 8404 | { |
| 8405 | s_pt.x = GET_X_LPARAM(lParam); |
| 8406 | s_pt.y = GET_Y_LPARAM(lParam); |
| 8407 | SetCapture(hwnd); |
| 8408 | s_hCursor = GetCursor(); /* backup default cursor */ |
| 8409 | break; |
| 8410 | } |
| 8411 | case WM_MOUSEMOVE: |
| 8412 | if (GetCapture() == hwnd |
| 8413 | && ((wParam & MK_LBUTTON)) != 0) |
| 8414 | { |
| 8415 | pt.x = GET_X_LPARAM(lParam); |
| 8416 | pt.y = s_pt.y; |
| 8417 | if (abs(pt.x - s_pt.x) > GetSystemMetrics(SM_CXDRAG)) |
| 8418 | { |
| 8419 | SetCursor(LoadCursor(NULL, IDC_SIZEWE)); |
| 8420 | |
| 8421 | tp = GetTabFromPoint(hwnd, pt); |
| 8422 | if (tp != NULL) |
| 8423 | { |
| 8424 | idx0 = tabpage_index(curtab) - 1; |
| 8425 | idx1 = tabpage_index(tp) - 1; |
| 8426 | |
| 8427 | TabCtrl_GetItemRect(hwnd, idx1, &rect); |
| 8428 | nCenter = rect.left + (rect.right - rect.left) / 2; |
| 8429 | |
| 8430 | /* Check if the mouse cursor goes over the center of |
| 8431 | * the next tab to prevent "flickering". */ |
| 8432 | if ((idx0 < idx1) && (nCenter < pt.x)) |
| 8433 | { |
| 8434 | tabpage_move(idx1 + 1); |
| 8435 | update_screen(0); |
| 8436 | } |
| 8437 | else if ((idx1 < idx0) && (pt.x < nCenter)) |
| 8438 | { |
| 8439 | tabpage_move(idx1); |
| 8440 | update_screen(0); |
| 8441 | } |
| 8442 | } |
| 8443 | } |
| 8444 | } |
| 8445 | break; |
| 8446 | case WM_LBUTTONUP: |
| 8447 | { |
| 8448 | if (GetCapture() == hwnd) |
| 8449 | { |
| 8450 | SetCursor(s_hCursor); |
| 8451 | ReleaseCapture(); |
| 8452 | } |
| 8453 | break; |
| 8454 | } |
| 8455 | default: |
| 8456 | break; |
| 8457 | } |
| 8458 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8459 | return CallWindowProc(s_tabline_wndproc, hwnd, uMsg, wParam, lParam); |
| 8460 | } |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 8461 | #endif |
| 8462 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8463 | #if defined(FEAT_OLE) || defined(FEAT_EVAL) || defined(PROTO) |
| 8464 | /* |
| 8465 | * Make the GUI window come to the foreground. |
| 8466 | */ |
| 8467 | void |
| 8468 | gui_mch_set_foreground(void) |
| 8469 | { |
| 8470 | if (IsIconic(s_hwnd)) |
| 8471 | SendMessage(s_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); |
| 8472 | SetForegroundWindow(s_hwnd); |
| 8473 | } |
| 8474 | #endif |
| 8475 | |
| 8476 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 8477 | static void |
| 8478 | dyn_imm_load(void) |
| 8479 | { |
Bram Moolenaar | ebbcb82 | 2010-10-23 14:02:54 +0200 | [diff] [blame] | 8480 | hLibImm = vimLoadLib("imm32.dll"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8481 | if (hLibImm == NULL) |
| 8482 | return; |
| 8483 | |
| 8484 | pImmGetCompositionStringA |
| 8485 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringA"); |
| 8486 | pImmGetCompositionStringW |
| 8487 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringW"); |
| 8488 | pImmGetContext |
| 8489 | = (void *)GetProcAddress(hLibImm, "ImmGetContext"); |
| 8490 | pImmAssociateContext |
| 8491 | = (void *)GetProcAddress(hLibImm, "ImmAssociateContext"); |
| 8492 | pImmReleaseContext |
| 8493 | = (void *)GetProcAddress(hLibImm, "ImmReleaseContext"); |
| 8494 | pImmGetOpenStatus |
| 8495 | = (void *)GetProcAddress(hLibImm, "ImmGetOpenStatus"); |
| 8496 | pImmSetOpenStatus |
| 8497 | = (void *)GetProcAddress(hLibImm, "ImmSetOpenStatus"); |
| 8498 | pImmGetCompositionFont |
| 8499 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionFontA"); |
| 8500 | pImmSetCompositionFont |
| 8501 | = (void *)GetProcAddress(hLibImm, "ImmSetCompositionFontA"); |
| 8502 | pImmSetCompositionWindow |
| 8503 | = (void *)GetProcAddress(hLibImm, "ImmSetCompositionWindow"); |
| 8504 | pImmGetConversionStatus |
| 8505 | = (void *)GetProcAddress(hLibImm, "ImmGetConversionStatus"); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 8506 | pImmSetConversionStatus |
| 8507 | = (void *)GetProcAddress(hLibImm, "ImmSetConversionStatus"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8508 | |
| 8509 | if ( pImmGetCompositionStringA == NULL |
| 8510 | || pImmGetCompositionStringW == NULL |
| 8511 | || pImmGetContext == NULL |
| 8512 | || pImmAssociateContext == NULL |
| 8513 | || pImmReleaseContext == NULL |
| 8514 | || pImmGetOpenStatus == NULL |
| 8515 | || pImmSetOpenStatus == NULL |
| 8516 | || pImmGetCompositionFont == NULL |
| 8517 | || pImmSetCompositionFont == NULL |
| 8518 | || pImmSetCompositionWindow == NULL |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 8519 | || pImmGetConversionStatus == NULL |
| 8520 | || pImmSetConversionStatus == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8521 | { |
| 8522 | FreeLibrary(hLibImm); |
| 8523 | hLibImm = NULL; |
| 8524 | pImmGetContext = NULL; |
| 8525 | return; |
| 8526 | } |
| 8527 | |
| 8528 | return; |
| 8529 | } |
| 8530 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8531 | #endif |
| 8532 | |
| 8533 | #if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
| 8534 | |
| 8535 | # ifdef FEAT_XPM_W32 |
| 8536 | # define IMAGE_XPM 100 |
| 8537 | # endif |
| 8538 | |
| 8539 | typedef struct _signicon_t |
| 8540 | { |
| 8541 | HANDLE hImage; |
| 8542 | UINT uType; |
| 8543 | #ifdef FEAT_XPM_W32 |
| 8544 | HANDLE hShape; /* Mask bitmap handle */ |
| 8545 | #endif |
| 8546 | } signicon_t; |
| 8547 | |
| 8548 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8549 | gui_mch_drawsign(int row, int col, int typenr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8550 | { |
| 8551 | signicon_t *sign; |
| 8552 | int x, y, w, h; |
| 8553 | |
| 8554 | if (!gui.in_use || (sign = (signicon_t *)sign_get_image(typenr)) == NULL) |
| 8555 | return; |
| 8556 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 8557 | #if defined(FEAT_DIRECTX) |
| 8558 | if (IS_ENABLE_DIRECTX()) |
| 8559 | DWriteContext_Flush(s_dwc); |
| 8560 | #endif |
| 8561 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8562 | x = TEXT_X(col); |
| 8563 | y = TEXT_Y(row); |
| 8564 | w = gui.char_width * 2; |
| 8565 | h = gui.char_height; |
| 8566 | switch (sign->uType) |
| 8567 | { |
| 8568 | case IMAGE_BITMAP: |
| 8569 | { |
| 8570 | HDC hdcMem; |
| 8571 | HBITMAP hbmpOld; |
| 8572 | |
| 8573 | hdcMem = CreateCompatibleDC(s_hdc); |
| 8574 | hbmpOld = (HBITMAP)SelectObject(hdcMem, sign->hImage); |
| 8575 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCCOPY); |
| 8576 | SelectObject(hdcMem, hbmpOld); |
| 8577 | DeleteDC(hdcMem); |
| 8578 | } |
| 8579 | break; |
| 8580 | case IMAGE_ICON: |
| 8581 | case IMAGE_CURSOR: |
| 8582 | DrawIconEx(s_hdc, x, y, (HICON)sign->hImage, w, h, 0, NULL, DI_NORMAL); |
| 8583 | break; |
| 8584 | #ifdef FEAT_XPM_W32 |
| 8585 | case IMAGE_XPM: |
| 8586 | { |
| 8587 | HDC hdcMem; |
| 8588 | HBITMAP hbmpOld; |
| 8589 | |
| 8590 | hdcMem = CreateCompatibleDC(s_hdc); |
| 8591 | hbmpOld = (HBITMAP)SelectObject(hdcMem, sign->hShape); |
| 8592 | /* Make hole */ |
| 8593 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCAND); |
| 8594 | |
| 8595 | SelectObject(hdcMem, sign->hImage); |
| 8596 | /* Paint sign */ |
| 8597 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCPAINT); |
| 8598 | SelectObject(hdcMem, hbmpOld); |
| 8599 | DeleteDC(hdcMem); |
| 8600 | } |
| 8601 | break; |
| 8602 | #endif |
| 8603 | } |
| 8604 | } |
| 8605 | |
| 8606 | static void |
| 8607 | close_signicon_image(signicon_t *sign) |
| 8608 | { |
| 8609 | if (sign) |
| 8610 | switch (sign->uType) |
| 8611 | { |
| 8612 | case IMAGE_BITMAP: |
| 8613 | DeleteObject((HGDIOBJ)sign->hImage); |
| 8614 | break; |
| 8615 | case IMAGE_CURSOR: |
| 8616 | DestroyCursor((HCURSOR)sign->hImage); |
| 8617 | break; |
| 8618 | case IMAGE_ICON: |
| 8619 | DestroyIcon((HICON)sign->hImage); |
| 8620 | break; |
| 8621 | #ifdef FEAT_XPM_W32 |
| 8622 | case IMAGE_XPM: |
| 8623 | DeleteObject((HBITMAP)sign->hImage); |
| 8624 | DeleteObject((HBITMAP)sign->hShape); |
| 8625 | break; |
| 8626 | #endif |
| 8627 | } |
| 8628 | } |
| 8629 | |
| 8630 | void * |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8631 | gui_mch_register_sign(char_u *signfile) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8632 | { |
| 8633 | signicon_t sign, *psign; |
| 8634 | char_u *ext; |
| 8635 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8636 | sign.hImage = NULL; |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 8637 | ext = signfile + STRLEN(signfile) - 4; /* get extension */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8638 | if (ext > signfile) |
| 8639 | { |
| 8640 | int do_load = 1; |
| 8641 | |
| 8642 | if (!STRICMP(ext, ".bmp")) |
| 8643 | sign.uType = IMAGE_BITMAP; |
| 8644 | else if (!STRICMP(ext, ".ico")) |
| 8645 | sign.uType = IMAGE_ICON; |
| 8646 | else if (!STRICMP(ext, ".cur") || !STRICMP(ext, ".ani")) |
| 8647 | sign.uType = IMAGE_CURSOR; |
| 8648 | else |
| 8649 | do_load = 0; |
| 8650 | |
| 8651 | if (do_load) |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8652 | sign.hImage = (HANDLE)LoadImage(NULL, (LPCSTR)signfile, sign.uType, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8653 | gui.char_width * 2, gui.char_height, |
| 8654 | LR_LOADFROMFILE | LR_CREATEDIBSECTION); |
| 8655 | #ifdef FEAT_XPM_W32 |
| 8656 | if (!STRICMP(ext, ".xpm")) |
| 8657 | { |
| 8658 | sign.uType = IMAGE_XPM; |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8659 | LoadXpmImage((char *)signfile, (HBITMAP *)&sign.hImage, |
| 8660 | (HBITMAP *)&sign.hShape); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8661 | } |
| 8662 | #endif |
| 8663 | } |
| 8664 | |
| 8665 | psign = NULL; |
| 8666 | if (sign.hImage && (psign = (signicon_t *)alloc(sizeof(signicon_t))) |
| 8667 | != NULL) |
| 8668 | *psign = sign; |
| 8669 | |
| 8670 | if (!psign) |
| 8671 | { |
| 8672 | if (sign.hImage) |
| 8673 | close_signicon_image(&sign); |
| 8674 | EMSG(_(e_signdata)); |
| 8675 | } |
| 8676 | return (void *)psign; |
| 8677 | |
| 8678 | } |
| 8679 | |
| 8680 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8681 | gui_mch_destroy_sign(void *sign) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8682 | { |
| 8683 | if (sign) |
| 8684 | { |
| 8685 | close_signicon_image((signicon_t *)sign); |
| 8686 | vim_free(sign); |
| 8687 | } |
| 8688 | } |
Bram Moolenaar | 5c06f8b | 2005-05-31 22:14:58 +0000 | [diff] [blame] | 8689 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8690 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 8691 | #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8692 | |
| 8693 | /* BALLOON-EVAL IMPLEMENTATION FOR WINDOWS. |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 8694 | * Added by Sergey Khorev <sergey.khorev@gmail.com> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8695 | * |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 8696 | * The only reused thing is beval.h and get_beval_info() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8697 | * from gui_beval.c (note it uses x and y of the BalloonEval struct |
| 8698 | * to get current mouse position). |
| 8699 | * |
| 8700 | * Trying to use as more Windows services as possible, and as less |
| 8701 | * IE version as possible :)). |
| 8702 | * |
| 8703 | * 1) Don't create ToolTip in gui_mch_create_beval_area, only initialize |
| 8704 | * BalloonEval struct. |
| 8705 | * 2) Enable/Disable simply create/kill BalloonEval Timer |
| 8706 | * 3) When there was enough inactivity, timer procedure posts |
| 8707 | * async request to debugger |
| 8708 | * 4) gui_mch_post_balloon (invoked from netbeans.c) creates tooltip control |
| 8709 | * and performs some actions to show it ASAP |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8710 | * 5) WM_NOTIFY:TTN_POP destroys created tooltip |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8711 | */ |
| 8712 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8713 | /* |
| 8714 | * determine whether installed Common Controls support multiline tooltips |
| 8715 | * (i.e. their version is >= 4.70 |
| 8716 | */ |
| 8717 | int |
| 8718 | multiline_balloon_available(void) |
| 8719 | { |
| 8720 | HINSTANCE hDll; |
| 8721 | static char comctl_dll[] = "comctl32.dll"; |
| 8722 | static int multiline_tip = MAYBE; |
| 8723 | |
| 8724 | if (multiline_tip != MAYBE) |
| 8725 | return multiline_tip; |
| 8726 | |
| 8727 | hDll = GetModuleHandle(comctl_dll); |
| 8728 | if (hDll != NULL) |
| 8729 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8730 | DLLGETVERSIONPROC pGetVer; |
| 8731 | pGetVer = (DLLGETVERSIONPROC)GetProcAddress(hDll, "DllGetVersion"); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8732 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8733 | if (pGetVer != NULL) |
| 8734 | { |
| 8735 | DLLVERSIONINFO dvi; |
| 8736 | HRESULT hr; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8737 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8738 | ZeroMemory(&dvi, sizeof(dvi)); |
| 8739 | dvi.cbSize = sizeof(dvi); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8740 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8741 | hr = (*pGetVer)(&dvi); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8742 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8743 | if (SUCCEEDED(hr) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8744 | && (dvi.dwMajorVersion > 4 |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8745 | || (dvi.dwMajorVersion == 4 |
| 8746 | && dvi.dwMinorVersion >= 70))) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8747 | { |
| 8748 | multiline_tip = TRUE; |
| 8749 | return multiline_tip; |
| 8750 | } |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8751 | } |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8752 | else |
| 8753 | { |
| 8754 | /* there is chance we have ancient CommCtl 4.70 |
| 8755 | which doesn't export DllGetVersion */ |
| 8756 | DWORD dwHandle = 0; |
| 8757 | DWORD len = GetFileVersionInfoSize(comctl_dll, &dwHandle); |
| 8758 | if (len > 0) |
| 8759 | { |
| 8760 | VS_FIXEDFILEINFO *ver; |
| 8761 | UINT vlen = 0; |
| 8762 | void *data = alloc(len); |
| 8763 | |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8764 | if ((data != NULL |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8765 | && GetFileVersionInfo(comctl_dll, 0, len, data) |
| 8766 | && VerQueryValue(data, "\\", (void **)&ver, &vlen) |
| 8767 | && vlen |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8768 | && HIWORD(ver->dwFileVersionMS) > 4) |
| 8769 | || ((HIWORD(ver->dwFileVersionMS) == 4 |
| 8770 | && LOWORD(ver->dwFileVersionMS) >= 70))) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8771 | { |
| 8772 | vim_free(data); |
| 8773 | multiline_tip = TRUE; |
| 8774 | return multiline_tip; |
| 8775 | } |
| 8776 | vim_free(data); |
| 8777 | } |
| 8778 | } |
| 8779 | } |
| 8780 | multiline_tip = FALSE; |
| 8781 | return multiline_tip; |
| 8782 | } |
| 8783 | |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8784 | #ifdef FEAT_MBYTE |
| 8785 | static void |
| 8786 | make_tooltipw(BalloonEval *beval, char *text, POINT pt) |
| 8787 | { |
| 8788 | TOOLINFOW *pti; |
| 8789 | int ToolInfoSize; |
| 8790 | WCHAR *tofree = NULL; |
| 8791 | |
| 8792 | if (multiline_balloon_available() == TRUE) |
| 8793 | ToolInfoSize = sizeof(TOOLINFOW_NEW); |
| 8794 | else |
| 8795 | ToolInfoSize = sizeof(TOOLINFOW); |
| 8796 | |
| 8797 | pti = (TOOLINFOW *)alloc(ToolInfoSize); |
| 8798 | if (pti == NULL) |
| 8799 | return; |
| 8800 | |
| 8801 | beval->balloon = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, |
| 8802 | NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, |
| 8803 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 8804 | beval->target, NULL, s_hinst, NULL); |
| 8805 | |
| 8806 | SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0, |
| 8807 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
| 8808 | |
| 8809 | pti->cbSize = ToolInfoSize; |
| 8810 | pti->uFlags = TTF_SUBCLASS; |
| 8811 | pti->hwnd = beval->target; |
| 8812 | pti->hinst = 0; // Don't use string resources |
| 8813 | pti->uId = ID_BEVAL_TOOLTIP; |
| 8814 | |
| 8815 | if (multiline_balloon_available() == TRUE) |
| 8816 | { |
| 8817 | RECT rect; |
| 8818 | TOOLINFOW_NEW *ptin = (TOOLINFOW_NEW *)pti; |
| 8819 | pti->lpszText = LPSTR_TEXTCALLBACKW; |
| 8820 | tofree = enc_to_utf16((char_u*)text, NULL); |
| 8821 | ptin->lParam = (LPARAM)tofree; |
| 8822 | // switch multiline tooltips on |
| 8823 | if (GetClientRect(s_textArea, &rect)) |
| 8824 | SendMessageW(beval->balloon, TTM_SETMAXTIPWIDTH, 0, |
| 8825 | (LPARAM)rect.right); |
| 8826 | } |
| 8827 | else |
| 8828 | { |
| 8829 | // do this old way |
| 8830 | tofree = enc_to_utf16((char_u*)text, NULL); |
| 8831 | pti->lpszText = tofree; |
| 8832 | } |
| 8833 | |
| 8834 | // Limit ballooneval bounding rect to CursorPos neighbourhood. |
| 8835 | pti->rect.left = pt.x - 3; |
| 8836 | pti->rect.top = pt.y - 3; |
| 8837 | pti->rect.right = pt.x + 3; |
| 8838 | pti->rect.bottom = pt.y + 3; |
| 8839 | |
| 8840 | SendMessageW(beval->balloon, TTM_ADDTOOLW, 0, (LPARAM)pti); |
| 8841 | // Make tooltip appear sooner. |
| 8842 | SendMessageW(beval->balloon, TTM_SETDELAYTIME, TTDT_INITIAL, 10); |
| 8843 | // I've performed some tests and it seems the longest possible life time |
| 8844 | // of tooltip is 30 seconds. |
| 8845 | SendMessageW(beval->balloon, TTM_SETDELAYTIME, TTDT_AUTOPOP, 30000); |
| 8846 | /* |
| 8847 | * HACK: force tooltip to appear, because it'll not appear until |
| 8848 | * first mouse move. D*mn M$ |
| 8849 | * Amazingly moving (2, 2) and then (-1, -1) the mouse doesn't move. |
| 8850 | */ |
| 8851 | mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0); |
| 8852 | mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0); |
| 8853 | vim_free(pti); |
| 8854 | if (tofree != NULL) |
| 8855 | vim_free(tofree); |
| 8856 | } |
| 8857 | #endif |
| 8858 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8859 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8860 | make_tooltip(BalloonEval *beval, char *text, POINT pt) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8861 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8862 | TOOLINFO *pti; |
| 8863 | int ToolInfoSize; |
| 8864 | |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8865 | #ifdef FEAT_MBYTE |
| 8866 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 8867 | { |
| 8868 | make_tooltipw(beval, text, pt); |
| 8869 | return; |
| 8870 | } |
| 8871 | #endif |
| 8872 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8873 | if (multiline_balloon_available() == TRUE) |
| 8874 | ToolInfoSize = sizeof(TOOLINFO_NEW); |
| 8875 | else |
| 8876 | ToolInfoSize = sizeof(TOOLINFO); |
| 8877 | |
| 8878 | pti = (TOOLINFO *)alloc(ToolInfoSize); |
| 8879 | if (pti == NULL) |
| 8880 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8881 | |
| 8882 | beval->balloon = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, |
| 8883 | NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, |
| 8884 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 8885 | beval->target, NULL, s_hinst, NULL); |
| 8886 | |
| 8887 | SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0, |
| 8888 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
| 8889 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8890 | pti->cbSize = ToolInfoSize; |
| 8891 | pti->uFlags = TTF_SUBCLASS; |
| 8892 | pti->hwnd = beval->target; |
| 8893 | pti->hinst = 0; /* Don't use string resources */ |
| 8894 | pti->uId = ID_BEVAL_TOOLTIP; |
| 8895 | |
| 8896 | if (multiline_balloon_available() == TRUE) |
| 8897 | { |
| 8898 | RECT rect; |
| 8899 | TOOLINFO_NEW *ptin = (TOOLINFO_NEW *)pti; |
| 8900 | pti->lpszText = LPSTR_TEXTCALLBACK; |
| 8901 | ptin->lParam = (LPARAM)text; |
| 8902 | if (GetClientRect(s_textArea, &rect)) /* switch multiline tooltips on */ |
| 8903 | SendMessage(beval->balloon, TTM_SETMAXTIPWIDTH, 0, |
| 8904 | (LPARAM)rect.right); |
| 8905 | } |
| 8906 | else |
| 8907 | pti->lpszText = text; /* do this old way */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8908 | |
| 8909 | /* Limit ballooneval bounding rect to CursorPos neighbourhood */ |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8910 | pti->rect.left = pt.x - 3; |
| 8911 | pti->rect.top = pt.y - 3; |
| 8912 | pti->rect.right = pt.x + 3; |
| 8913 | pti->rect.bottom = pt.y + 3; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8914 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8915 | SendMessage(beval->balloon, TTM_ADDTOOL, 0, (LPARAM)pti); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8916 | /* Make tooltip appear sooner */ |
| 8917 | SendMessage(beval->balloon, TTM_SETDELAYTIME, TTDT_INITIAL, 10); |
Bram Moolenaar | b52e532 | 2008-01-05 12:15:52 +0000 | [diff] [blame] | 8918 | /* I've performed some tests and it seems the longest possible life time |
| 8919 | * of tooltip is 30 seconds */ |
| 8920 | SendMessage(beval->balloon, TTM_SETDELAYTIME, TTDT_AUTOPOP, 30000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8921 | /* |
| 8922 | * HACK: force tooltip to appear, because it'll not appear until |
| 8923 | * first mouse move. D*mn M$ |
Bram Moolenaar | b52e532 | 2008-01-05 12:15:52 +0000 | [diff] [blame] | 8924 | * Amazingly moving (2, 2) and then (-1, -1) the mouse doesn't move. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8925 | */ |
Bram Moolenaar | b52e532 | 2008-01-05 12:15:52 +0000 | [diff] [blame] | 8926 | mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8927 | mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8928 | vim_free(pti); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8929 | } |
| 8930 | |
| 8931 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8932 | delete_tooltip(BalloonEval *beval) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8933 | { |
Bram Moolenaar | 8e5f5b4 | 2015-08-26 23:12:38 +0200 | [diff] [blame] | 8934 | PostMessage(beval->balloon, WM_CLOSE, 0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8935 | } |
| 8936 | |
| 8937 | static VOID CALLBACK |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8938 | BevalTimerProc( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 8939 | HWND hwnd UNUSED, |
| 8940 | UINT uMsg UNUSED, |
| 8941 | UINT_PTR idEvent UNUSED, |
| 8942 | DWORD dwTime) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8943 | { |
| 8944 | POINT pt; |
| 8945 | RECT rect; |
| 8946 | |
| 8947 | if (cur_beval == NULL || cur_beval->showState == ShS_SHOWING || !p_beval) |
| 8948 | return; |
| 8949 | |
| 8950 | GetCursorPos(&pt); |
| 8951 | if (WindowFromPoint(pt) != s_textArea) |
| 8952 | return; |
| 8953 | |
| 8954 | ScreenToClient(s_textArea, &pt); |
| 8955 | GetClientRect(s_textArea, &rect); |
| 8956 | if (!PtInRect(&rect, pt)) |
| 8957 | return; |
| 8958 | |
| 8959 | if (LastActivity > 0 |
| 8960 | && (dwTime - LastActivity) >= (DWORD)p_bdlay |
| 8961 | && (cur_beval->showState != ShS_PENDING |
| 8962 | || abs(cur_beval->x - pt.x) > 3 |
| 8963 | || abs(cur_beval->y - pt.y) > 3)) |
| 8964 | { |
| 8965 | /* Pointer resting in one place long enough, it's time to show |
| 8966 | * the tooltip. */ |
| 8967 | cur_beval->showState = ShS_PENDING; |
| 8968 | cur_beval->x = pt.x; |
| 8969 | cur_beval->y = pt.y; |
| 8970 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8971 | // TRACE0("BevalTimerProc: sending request"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8972 | |
| 8973 | if (cur_beval->msgCB != NULL) |
| 8974 | (*cur_beval->msgCB)(cur_beval, 0); |
| 8975 | } |
| 8976 | } |
| 8977 | |
| 8978 | void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 8979 | gui_mch_disable_beval_area(BalloonEval *beval UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8980 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8981 | // TRACE0("gui_mch_disable_beval_area {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8982 | KillTimer(s_textArea, BevalTimerId); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8983 | // TRACE0("gui_mch_disable_beval_area }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8984 | } |
| 8985 | |
| 8986 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8987 | gui_mch_enable_beval_area(BalloonEval *beval) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8988 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8989 | // TRACE0("gui_mch_enable_beval_area |||"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8990 | if (beval == NULL) |
| 8991 | return; |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8992 | // TRACE0("gui_mch_enable_beval_area {{{"); |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 8993 | BevalTimerId = SetTimer(s_textArea, 0, (UINT)(p_bdlay / 2), BevalTimerProc); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8994 | // TRACE0("gui_mch_enable_beval_area }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8995 | } |
| 8996 | |
| 8997 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8998 | gui_mch_post_balloon(BalloonEval *beval, char_u *mesg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8999 | { |
| 9000 | POINT pt; |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 9001 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9002 | // TRACE0("gui_mch_post_balloon {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9003 | if (beval->showState == ShS_SHOWING) |
| 9004 | return; |
| 9005 | GetCursorPos(&pt); |
| 9006 | ScreenToClient(s_textArea, &pt); |
| 9007 | |
| 9008 | if (abs(beval->x - pt.x) < 3 && abs(beval->y - pt.y) < 3) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9009 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 9010 | /* cursor is still here */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9011 | gui_mch_disable_beval_area(cur_beval); |
| 9012 | beval->showState = ShS_SHOWING; |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 9013 | make_tooltip(beval, (char *)mesg, pt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9014 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9015 | // TRACE0("gui_mch_post_balloon }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9016 | } |
| 9017 | |
| 9018 | BalloonEval * |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 9019 | gui_mch_create_beval_area( |
| 9020 | void *target, /* ignored, always use s_textArea */ |
| 9021 | char_u *mesg, |
| 9022 | void (*mesgCB)(BalloonEval *, int), |
| 9023 | void *clientData) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9024 | { |
| 9025 | /* partially stolen from gui_beval.c */ |
| 9026 | BalloonEval *beval; |
| 9027 | |
| 9028 | if (mesg != NULL && mesgCB != NULL) |
| 9029 | { |
Bram Moolenaar | 95f0960 | 2016-11-10 20:01:45 +0100 | [diff] [blame] | 9030 | IEMSG(_("E232: Cannot create BalloonEval with both message and callback")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9031 | return NULL; |
| 9032 | } |
| 9033 | |
Bram Moolenaar | ca4b613 | 2018-06-28 12:05:11 +0200 | [diff] [blame] | 9034 | beval = (BalloonEval *)alloc_clear(sizeof(BalloonEval)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9035 | if (beval != NULL) |
| 9036 | { |
| 9037 | beval->target = s_textArea; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9038 | |
| 9039 | beval->showState = ShS_NEUTRAL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9040 | beval->msg = mesg; |
| 9041 | beval->msgCB = mesgCB; |
| 9042 | beval->clientData = clientData; |
| 9043 | |
| 9044 | InitCommonControls(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9045 | cur_beval = beval; |
| 9046 | |
| 9047 | if (p_beval) |
| 9048 | gui_mch_enable_beval_area(beval); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9049 | } |
| 9050 | return beval; |
| 9051 | } |
| 9052 | |
| 9053 | static void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 9054 | Handle_WM_Notify(HWND hwnd UNUSED, LPNMHDR pnmh) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9055 | { |
| 9056 | if (pnmh->idFrom != ID_BEVAL_TOOLTIP) /* it is not our tooltip */ |
| 9057 | return; |
| 9058 | |
| 9059 | if (cur_beval != NULL) |
| 9060 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 9061 | switch (pnmh->code) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9062 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 9063 | case TTN_SHOW: |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9064 | // TRACE0("TTN_SHOW {{{"); |
| 9065 | // TRACE0("TTN_SHOW }}}"); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 9066 | break; |
| 9067 | case TTN_POP: /* Before tooltip disappear */ |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9068 | // TRACE0("TTN_POP {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9069 | delete_tooltip(cur_beval); |
| 9070 | gui_mch_enable_beval_area(cur_beval); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9071 | // TRACE0("TTN_POP }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9072 | |
| 9073 | cur_beval->showState = ShS_NEUTRAL; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 9074 | break; |
| 9075 | case TTN_GETDISPINFO: |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 9076 | { |
| 9077 | /* if you get there then we have new common controls */ |
| 9078 | NMTTDISPINFO_NEW *info = (NMTTDISPINFO_NEW *)pnmh; |
| 9079 | info->lpszText = (LPSTR)info->lParam; |
| 9080 | info->uFlags |= TTF_DI_SETITEM; |
| 9081 | } |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 9082 | break; |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 9083 | #ifdef FEAT_MBYTE |
| 9084 | case TTN_GETDISPINFOW: |
| 9085 | { |
| 9086 | // if we get here then we have new common controls |
| 9087 | NMTTDISPINFOW_NEW *info = (NMTTDISPINFOW_NEW *)pnmh; |
| 9088 | info->lpszText = (LPWSTR)info->lParam; |
| 9089 | info->uFlags |= TTF_DI_SETITEM; |
| 9090 | } |
| 9091 | break; |
| 9092 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9093 | } |
| 9094 | } |
| 9095 | } |
| 9096 | |
| 9097 | static void |
| 9098 | TrackUserActivity(UINT uMsg) |
| 9099 | { |
| 9100 | if ((uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST) |
| 9101 | || (uMsg >= WM_KEYFIRST && uMsg <= WM_KEYLAST)) |
| 9102 | LastActivity = GetTickCount(); |
| 9103 | } |
| 9104 | |
| 9105 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 9106 | gui_mch_destroy_beval_area(BalloonEval *beval) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9107 | { |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 9108 | #ifdef FEAT_VARTABS |
| 9109 | if (beval->vts) |
| 9110 | vim_free(beval->vts); |
| 9111 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9112 | vim_free(beval); |
| 9113 | } |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 9114 | #endif /* FEAT_BEVAL_GUI */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9115 | |
| 9116 | #if defined(FEAT_NETBEANS_INTG) || defined(PROTO) |
| 9117 | /* |
| 9118 | * We have multiple signs to draw at the same location. Draw the |
| 9119 | * multi-sign indicator (down-arrow) instead. This is the Win32 version. |
| 9120 | */ |
| 9121 | void |
| 9122 | netbeans_draw_multisign_indicator(int row) |
| 9123 | { |
| 9124 | int i; |
| 9125 | int y; |
| 9126 | int x; |
| 9127 | |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 9128 | if (!netbeans_active()) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 9129 | return; |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 9130 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9131 | x = 0; |
| 9132 | y = TEXT_Y(row); |
| 9133 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 9134 | #if defined(FEAT_DIRECTX) |
| 9135 | if (IS_ENABLE_DIRECTX()) |
| 9136 | DWriteContext_Flush(s_dwc); |
| 9137 | #endif |
| 9138 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9139 | for (i = 0; i < gui.char_height - 3; i++) |
| 9140 | SetPixel(s_hdc, x+2, y++, gui.currFgColor); |
| 9141 | |
| 9142 | SetPixel(s_hdc, x+0, y, gui.currFgColor); |
| 9143 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 9144 | SetPixel(s_hdc, x+4, y++, gui.currFgColor); |
| 9145 | SetPixel(s_hdc, x+1, y, gui.currFgColor); |
| 9146 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 9147 | SetPixel(s_hdc, x+3, y++, gui.currFgColor); |
| 9148 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 9149 | } |
Bram Moolenaar | e0874f8 | 2016-01-24 20:36:41 +0100 | [diff] [blame] | 9150 | #endif |