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 | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 33 | static DWriteContext *s_dwc = NULL; |
| 34 | static int s_directx_enabled = 0; |
| 35 | static int s_directx_load_attempted = 0; |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 36 | # define IS_ENABLE_DIRECTX() (s_directx_enabled && s_dwc != NULL && enc_utf8) |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 37 | static int directx_enabled(void); |
| 38 | static void directx_binddc(void); |
Bram Moolenaar | b8e0bdb | 2014-11-12 16:10:48 +0100 | [diff] [blame] | 39 | #endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 40 | |
Bram Moolenaar | 065bbac | 2016-02-20 13:08:46 +0100 | [diff] [blame] | 41 | #ifdef FEAT_MENU |
| 42 | static int gui_mswin_get_menu_height(int fix_window); |
| 43 | #endif |
| 44 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 45 | #if defined(FEAT_RENDER_OPTIONS) || defined(PROTO) |
| 46 | int |
| 47 | gui_mch_set_rendering_options(char_u *s) |
| 48 | { |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 49 | # ifdef FEAT_DIRECTX |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 50 | char_u *p, *q; |
| 51 | |
| 52 | int dx_enable = 0; |
| 53 | int dx_flags = 0; |
| 54 | float dx_gamma = 0.0f; |
| 55 | float dx_contrast = 0.0f; |
| 56 | float dx_level = 0.0f; |
| 57 | int dx_geom = 0; |
| 58 | int dx_renmode = 0; |
| 59 | int dx_taamode = 0; |
| 60 | |
| 61 | /* parse string as rendering options. */ |
| 62 | for (p = s; p != NULL && *p != NUL; ) |
| 63 | { |
| 64 | char_u item[256]; |
| 65 | char_u name[128]; |
| 66 | char_u value[128]; |
| 67 | |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 68 | copy_option_part(&p, item, sizeof(item), ","); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 69 | if (p == NULL) |
| 70 | break; |
| 71 | q = &item[0]; |
| 72 | copy_option_part(&q, name, sizeof(name), ":"); |
| 73 | if (q == NULL) |
| 74 | return FAIL; |
| 75 | copy_option_part(&q, value, sizeof(value), ":"); |
| 76 | |
| 77 | if (STRCMP(name, "type") == 0) |
| 78 | { |
| 79 | if (STRCMP(value, "directx") == 0) |
| 80 | dx_enable = 1; |
| 81 | else |
| 82 | return FAIL; |
| 83 | } |
| 84 | else if (STRCMP(name, "gamma") == 0) |
| 85 | { |
| 86 | dx_flags |= 1 << 0; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 87 | dx_gamma = (float)atof((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 88 | } |
| 89 | else if (STRCMP(name, "contrast") == 0) |
| 90 | { |
| 91 | dx_flags |= 1 << 1; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 92 | dx_contrast = (float)atof((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 93 | } |
| 94 | else if (STRCMP(name, "level") == 0) |
| 95 | { |
| 96 | dx_flags |= 1 << 2; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 97 | dx_level = (float)atof((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 98 | } |
| 99 | else if (STRCMP(name, "geom") == 0) |
| 100 | { |
| 101 | dx_flags |= 1 << 3; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 102 | dx_geom = atoi((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 103 | if (dx_geom < 0 || dx_geom > 2) |
| 104 | return FAIL; |
| 105 | } |
| 106 | else if (STRCMP(name, "renmode") == 0) |
| 107 | { |
| 108 | dx_flags |= 1 << 4; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 109 | dx_renmode = atoi((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 110 | if (dx_renmode < 0 || dx_renmode > 6) |
| 111 | return FAIL; |
| 112 | } |
| 113 | else if (STRCMP(name, "taamode") == 0) |
| 114 | { |
| 115 | dx_flags |= 1 << 5; |
Bram Moolenaar | 7f0608f | 2016-02-18 20:46:39 +0100 | [diff] [blame] | 116 | dx_taamode = atoi((char *)value); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 117 | if (dx_taamode < 0 || dx_taamode > 3) |
| 118 | return FAIL; |
| 119 | } |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 120 | else if (STRCMP(name, "scrlines") == 0) |
| 121 | { |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 122 | /* Deprecated. Simply ignore it. */ |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 123 | } |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 124 | else |
| 125 | return FAIL; |
| 126 | } |
| 127 | |
Bram Moolenaar | 3767c6e | 2017-12-05 16:57:56 +0100 | [diff] [blame] | 128 | if (!gui.in_use) |
| 129 | return OK; /* only checking the syntax of the value */ |
| 130 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 131 | /* Enable DirectX/DirectWrite */ |
| 132 | if (dx_enable) |
| 133 | { |
| 134 | if (!directx_enabled()) |
| 135 | return FAIL; |
| 136 | DWriteContext_SetRenderingParams(s_dwc, NULL); |
| 137 | if (dx_flags) |
| 138 | { |
| 139 | DWriteRenderingParams param; |
| 140 | DWriteContext_GetRenderingParams(s_dwc, ¶m); |
| 141 | if (dx_flags & (1 << 0)) |
| 142 | param.gamma = dx_gamma; |
| 143 | if (dx_flags & (1 << 1)) |
| 144 | param.enhancedContrast = dx_contrast; |
| 145 | if (dx_flags & (1 << 2)) |
| 146 | param.clearTypeLevel = dx_level; |
| 147 | if (dx_flags & (1 << 3)) |
| 148 | param.pixelGeometry = dx_geom; |
| 149 | if (dx_flags & (1 << 4)) |
| 150 | param.renderingMode = dx_renmode; |
| 151 | if (dx_flags & (1 << 5)) |
| 152 | param.textAntialiasMode = dx_taamode; |
| 153 | DWriteContext_SetRenderingParams(s_dwc, ¶m); |
| 154 | } |
| 155 | } |
| 156 | s_directx_enabled = dx_enable; |
| 157 | |
| 158 | return OK; |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 159 | # else |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 160 | return FAIL; |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 161 | # endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 162 | } |
| 163 | #endif |
| 164 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 165 | /* |
| 166 | * These are new in Windows ME/XP, only defined in recent compilers. |
| 167 | */ |
| 168 | #ifndef HANDLE_WM_XBUTTONUP |
| 169 | # define HANDLE_WM_XBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 170 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 171 | #endif |
| 172 | #ifndef HANDLE_WM_XBUTTONDOWN |
| 173 | # define HANDLE_WM_XBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 174 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 175 | #endif |
| 176 | #ifndef HANDLE_WM_XBUTTONDBLCLK |
| 177 | # define HANDLE_WM_XBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 178 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 179 | #endif |
| 180 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 181 | |
| 182 | #include "version.h" /* used by dialog box routine for default title */ |
| 183 | #ifdef DEBUG |
| 184 | # include <tchar.h> |
| 185 | #endif |
| 186 | |
| 187 | /* cproto fails on missing include files */ |
| 188 | #ifndef PROTO |
| 189 | |
| 190 | #ifndef __MINGW32__ |
| 191 | # include <shellapi.h> |
| 192 | #endif |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 193 | #if defined(FEAT_TOOLBAR) || defined(FEAT_BEVAL_GUI) || defined(FEAT_GUI_TABLINE) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 194 | # include <commctrl.h> |
| 195 | #endif |
| 196 | #include <windowsx.h> |
| 197 | |
| 198 | #ifdef GLOBAL_IME |
| 199 | # include "glbl_ime.h" |
| 200 | #endif |
| 201 | |
| 202 | #endif /* PROTO */ |
| 203 | |
| 204 | #ifdef FEAT_MENU |
| 205 | # define MENUHINTS /* show menu hints in command line */ |
| 206 | #endif |
| 207 | |
| 208 | /* Some parameters for dialog boxes. All in pixels. */ |
| 209 | #define DLG_PADDING_X 10 |
| 210 | #define DLG_PADDING_Y 10 |
| 211 | #define DLG_OLD_STYLE_PADDING_X 5 |
| 212 | #define DLG_OLD_STYLE_PADDING_Y 5 |
| 213 | #define DLG_VERT_PADDING_X 4 /* For vertical buttons */ |
| 214 | #define DLG_VERT_PADDING_Y 4 |
| 215 | #define DLG_ICON_WIDTH 34 |
| 216 | #define DLG_ICON_HEIGHT 34 |
| 217 | #define DLG_MIN_WIDTH 150 |
| 218 | #define DLG_FONT_NAME "MS Sans Serif" |
| 219 | #define DLG_FONT_POINT_SIZE 8 |
| 220 | #define DLG_MIN_MAX_WIDTH 400 |
| 221 | #define DLG_MIN_MAX_HEIGHT 400 |
| 222 | |
| 223 | #define DLG_NONBUTTON_CONTROL 5000 /* First ID of non-button controls */ |
| 224 | |
| 225 | #ifndef WM_XBUTTONDOWN /* For Win2K / winME ONLY */ |
| 226 | # define WM_XBUTTONDOWN 0x020B |
| 227 | # define WM_XBUTTONUP 0x020C |
| 228 | # define WM_XBUTTONDBLCLK 0x020D |
| 229 | # define MK_XBUTTON1 0x0020 |
| 230 | # define MK_XBUTTON2 0x0040 |
| 231 | #endif |
| 232 | |
| 233 | #ifdef PROTO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 234 | /* |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 235 | * Define a few things for generating prototypes. This is just to avoid |
| 236 | * syntax errors, the defines do not need to be correct. |
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 APIENTRY |
| 239 | # define CALLBACK |
| 240 | # define CONST |
| 241 | # define FAR |
| 242 | # define NEAR |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 243 | # undef _cdecl |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 244 | # define _cdecl |
| 245 | typedef int BOOL; |
| 246 | typedef int BYTE; |
| 247 | typedef int DWORD; |
| 248 | typedef int WCHAR; |
| 249 | typedef int ENUMLOGFONT; |
| 250 | typedef int FINDREPLACE; |
| 251 | typedef int HANDLE; |
| 252 | typedef int HBITMAP; |
| 253 | typedef int HBRUSH; |
| 254 | typedef int HDROP; |
| 255 | typedef int INT; |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 256 | typedef int LOGFONTW[]; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 257 | typedef int LPARAM; |
| 258 | typedef int LPCREATESTRUCT; |
| 259 | typedef int LPCSTR; |
| 260 | typedef int LPCTSTR; |
| 261 | typedef int LPRECT; |
| 262 | typedef int LPSTR; |
| 263 | typedef int LPWINDOWPOS; |
| 264 | typedef int LPWORD; |
| 265 | typedef int LRESULT; |
| 266 | typedef int HRESULT; |
| 267 | # undef MSG |
| 268 | typedef int MSG; |
| 269 | typedef int NEWTEXTMETRIC; |
| 270 | typedef int OSVERSIONINFO; |
| 271 | typedef int PWORD; |
| 272 | typedef int RECT; |
| 273 | typedef int UINT; |
| 274 | typedef int WORD; |
| 275 | typedef int WPARAM; |
| 276 | typedef int POINT; |
| 277 | typedef void *HINSTANCE; |
| 278 | typedef void *HMENU; |
| 279 | typedef void *HWND; |
| 280 | typedef void *HDC; |
| 281 | typedef void VOID; |
| 282 | typedef int LPNMHDR; |
| 283 | typedef int LONG; |
| 284 | typedef int WNDPROC; |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 285 | typedef int UINT_PTR; |
Bram Moolenaar | b1c9198 | 2018-05-17 17:04:55 +0200 | [diff] [blame] | 286 | typedef int COLORREF; |
| 287 | typedef int HCURSOR; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 288 | #endif |
| 289 | |
| 290 | #ifndef GET_X_LPARAM |
| 291 | # define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) |
| 292 | #endif |
| 293 | |
| 294 | static void _OnPaint( HWND hwnd); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 295 | static void fill_rect(const RECT *rcp, HBRUSH hbr, COLORREF color); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 296 | static void clear_rect(RECT *rcp); |
| 297 | |
| 298 | static WORD s_dlgfntheight; /* height of the dialog font */ |
| 299 | static WORD s_dlgfntwidth; /* width of the dialog font */ |
| 300 | |
| 301 | #ifdef FEAT_MENU |
| 302 | static HMENU s_menuBar = NULL; |
| 303 | #endif |
| 304 | #ifdef FEAT_TEAROFF |
| 305 | static void rebuild_tearoff(vimmenu_T *menu); |
| 306 | static HBITMAP s_htearbitmap; /* bitmap used to indicate tearoff */ |
| 307 | #endif |
| 308 | |
| 309 | /* Flag that is set while processing a message that must not be interrupted by |
| 310 | * processing another message. */ |
| 311 | static int s_busy_processing = FALSE; |
| 312 | |
| 313 | static int destroying = FALSE; /* call DestroyWindow() ourselves */ |
| 314 | |
| 315 | #ifdef MSWIN_FIND_REPLACE |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 316 | static UINT s_findrep_msg = 0; // set in gui_w[16/32].c |
| 317 | static FINDREPLACEW s_findrep_struct; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 318 | static HWND s_findrep_hwnd = NULL; |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 319 | static int s_findrep_is_find; // TRUE for find dialog, FALSE |
| 320 | // for find/replace dialog |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 321 | #endif |
| 322 | |
Bram Moolenaar | 85b1176 | 2016-02-27 18:13:23 +0100 | [diff] [blame] | 323 | #if !defined(FEAT_GUI) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 324 | static |
| 325 | #endif |
| 326 | HWND s_hwnd = NULL; |
| 327 | static HDC s_hdc = NULL; |
Bram Moolenaar | ab85ca4 | 2019-11-15 22:41:14 +0100 | [diff] [blame] | 328 | static HBRUSH s_brush = NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 329 | |
| 330 | #ifdef FEAT_TOOLBAR |
| 331 | static HWND s_toolbarhwnd = NULL; |
| 332 | static WNDPROC s_toolbar_wndproc = NULL; |
| 333 | #endif |
| 334 | |
| 335 | #ifdef FEAT_GUI_TABLINE |
| 336 | static HWND s_tabhwnd = NULL; |
| 337 | static WNDPROC s_tabline_wndproc = NULL; |
| 338 | static int showing_tabline = 0; |
| 339 | #endif |
| 340 | |
| 341 | static WPARAM s_wParam = 0; |
| 342 | static LPARAM s_lParam = 0; |
| 343 | |
| 344 | static HWND s_textArea = NULL; |
| 345 | static UINT s_uMsg = 0; |
| 346 | |
| 347 | static char_u *s_textfield; /* Used by dialogs to pass back strings */ |
| 348 | |
| 349 | static int s_need_activate = FALSE; |
| 350 | |
| 351 | /* This variable is set when waiting for an event, which is the only moment |
| 352 | * scrollbar dragging can be done directly. It's not allowed while commands |
| 353 | * are executed, because it may move the cursor and that may cause unexpected |
| 354 | * problems (e.g., while ":s" is working). |
| 355 | */ |
| 356 | static int allow_scrollbar = FALSE; |
| 357 | |
| 358 | #ifdef GLOBAL_IME |
| 359 | # define MyTranslateMessage(x) global_ime_TranslateMessage(x) |
| 360 | #else |
| 361 | # define MyTranslateMessage(x) TranslateMessage(x) |
| 362 | #endif |
| 363 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 364 | #if defined(FEAT_DIRECTX) |
| 365 | static int |
| 366 | directx_enabled(void) |
| 367 | { |
| 368 | if (s_dwc != NULL) |
| 369 | return 1; |
| 370 | else if (s_directx_load_attempted) |
| 371 | return 0; |
| 372 | /* load DirectX */ |
| 373 | DWrite_Init(); |
| 374 | s_directx_load_attempted = 1; |
| 375 | s_dwc = DWriteContext_Open(); |
| 376 | directx_binddc(); |
| 377 | return s_dwc != NULL ? 1 : 0; |
| 378 | } |
| 379 | |
| 380 | static void |
| 381 | directx_binddc(void) |
| 382 | { |
| 383 | if (s_textArea != NULL) |
| 384 | { |
| 385 | RECT rect; |
| 386 | GetClientRect(s_textArea, &rect); |
| 387 | DWriteContext_BindDC(s_dwc, s_hdc, &rect); |
| 388 | } |
| 389 | } |
| 390 | #endif |
| 391 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 392 | /* use of WindowProc depends on Global IME */ |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 393 | #define MyWindowProc vim_WindowProc |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 394 | |
| 395 | extern int current_font_height; /* this is in os_mswin.c */ |
| 396 | |
| 397 | static struct |
| 398 | { |
| 399 | UINT key_sym; |
| 400 | char_u vim_code0; |
| 401 | char_u vim_code1; |
| 402 | } special_keys[] = |
| 403 | { |
| 404 | {VK_UP, 'k', 'u'}, |
| 405 | {VK_DOWN, 'k', 'd'}, |
| 406 | {VK_LEFT, 'k', 'l'}, |
| 407 | {VK_RIGHT, 'k', 'r'}, |
| 408 | |
| 409 | {VK_F1, 'k', '1'}, |
| 410 | {VK_F2, 'k', '2'}, |
| 411 | {VK_F3, 'k', '3'}, |
| 412 | {VK_F4, 'k', '4'}, |
| 413 | {VK_F5, 'k', '5'}, |
| 414 | {VK_F6, 'k', '6'}, |
| 415 | {VK_F7, 'k', '7'}, |
| 416 | {VK_F8, 'k', '8'}, |
| 417 | {VK_F9, 'k', '9'}, |
| 418 | {VK_F10, 'k', ';'}, |
| 419 | |
| 420 | {VK_F11, 'F', '1'}, |
| 421 | {VK_F12, 'F', '2'}, |
| 422 | {VK_F13, 'F', '3'}, |
| 423 | {VK_F14, 'F', '4'}, |
| 424 | {VK_F15, 'F', '5'}, |
| 425 | {VK_F16, 'F', '6'}, |
| 426 | {VK_F17, 'F', '7'}, |
| 427 | {VK_F18, 'F', '8'}, |
| 428 | {VK_F19, 'F', '9'}, |
| 429 | {VK_F20, 'F', 'A'}, |
| 430 | |
| 431 | {VK_F21, 'F', 'B'}, |
| 432 | #ifdef FEAT_NETBEANS_INTG |
| 433 | {VK_PAUSE, 'F', 'B'}, /* Pause == F21 (see gui_gtk_x11.c) */ |
| 434 | #endif |
| 435 | {VK_F22, 'F', 'C'}, |
| 436 | {VK_F23, 'F', 'D'}, |
| 437 | {VK_F24, 'F', 'E'}, /* winuser.h defines up to F24 */ |
| 438 | |
| 439 | {VK_HELP, '%', '1'}, |
| 440 | {VK_BACK, 'k', 'b'}, |
| 441 | {VK_INSERT, 'k', 'I'}, |
| 442 | {VK_DELETE, 'k', 'D'}, |
| 443 | {VK_HOME, 'k', 'h'}, |
| 444 | {VK_END, '@', '7'}, |
| 445 | {VK_PRIOR, 'k', 'P'}, |
| 446 | {VK_NEXT, 'k', 'N'}, |
| 447 | {VK_PRINT, '%', '9'}, |
| 448 | {VK_ADD, 'K', '6'}, |
| 449 | {VK_SUBTRACT, 'K', '7'}, |
| 450 | {VK_DIVIDE, 'K', '8'}, |
| 451 | {VK_MULTIPLY, 'K', '9'}, |
| 452 | {VK_SEPARATOR, 'K', 'A'}, /* Keypad Enter */ |
| 453 | {VK_DECIMAL, 'K', 'B'}, |
| 454 | |
| 455 | {VK_NUMPAD0, 'K', 'C'}, |
| 456 | {VK_NUMPAD1, 'K', 'D'}, |
| 457 | {VK_NUMPAD2, 'K', 'E'}, |
| 458 | {VK_NUMPAD3, 'K', 'F'}, |
| 459 | {VK_NUMPAD4, 'K', 'G'}, |
| 460 | {VK_NUMPAD5, 'K', 'H'}, |
| 461 | {VK_NUMPAD6, 'K', 'I'}, |
| 462 | {VK_NUMPAD7, 'K', 'J'}, |
| 463 | {VK_NUMPAD8, 'K', 'K'}, |
| 464 | {VK_NUMPAD9, 'K', 'L'}, |
| 465 | |
| 466 | /* Keys that we want to be able to use any modifier with: */ |
| 467 | {VK_SPACE, ' ', NUL}, |
| 468 | {VK_TAB, TAB, NUL}, |
| 469 | {VK_ESCAPE, ESC, NUL}, |
| 470 | {NL, NL, NUL}, |
| 471 | {CAR, CAR, NUL}, |
| 472 | |
| 473 | /* End of list marker: */ |
| 474 | {0, 0, 0} |
| 475 | }; |
| 476 | |
| 477 | /* Local variables */ |
| 478 | static int s_button_pending = -1; |
| 479 | |
| 480 | /* s_getting_focus is set when we got focus but didn't see mouse-up event yet, |
| 481 | * so don't reset s_button_pending. */ |
| 482 | static int s_getting_focus = FALSE; |
| 483 | |
| 484 | static int s_x_pending; |
| 485 | static int s_y_pending; |
| 486 | static UINT s_kFlags_pending; |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 487 | static UINT s_wait_timer = 0; // Timer for get char from user |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 488 | static int s_timed_out = FALSE; |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 489 | static int dead_key = 0; // 0: no dead key, 1: dead key pressed |
| 490 | static UINT surrogate_pending_ch = 0; // 0: no surrogate pending, |
| 491 | // else a high surrogate |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 492 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 493 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 494 | /* balloon-eval WM_NOTIFY_HANDLER */ |
| 495 | static void Handle_WM_Notify(HWND hwnd, LPNMHDR pnmh); |
| 496 | static void TrackUserActivity(UINT uMsg); |
| 497 | #endif |
| 498 | |
| 499 | /* |
| 500 | * For control IME. |
| 501 | * |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 502 | * These LOGFONTW used for IME. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 503 | */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 504 | #if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME) |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 505 | /* holds LOGFONTW for 'guifontwide' if available, otherwise 'guifont' */ |
| 506 | static LOGFONTW norm_logfont; |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 507 | #endif |
| 508 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 509 | /* holds LOGFONTW for 'guifont' always. */ |
| 510 | static LOGFONTW sub_logfont; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 511 | #endif |
| 512 | |
| 513 | #ifdef FEAT_MBYTE_IME |
| 514 | static LRESULT _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData); |
| 515 | #endif |
| 516 | |
| 517 | #if defined(FEAT_BROWSE) |
| 518 | static char_u *convert_filter(char_u *s); |
| 519 | #endif |
| 520 | |
| 521 | #ifdef DEBUG_PRINT_ERROR |
| 522 | /* |
| 523 | * Print out the last Windows error message |
| 524 | */ |
| 525 | static void |
| 526 | print_windows_error(void) |
| 527 | { |
| 528 | LPVOID lpMsgBuf; |
| 529 | |
| 530 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 531 | NULL, GetLastError(), |
| 532 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 533 | (LPTSTR) &lpMsgBuf, 0, NULL); |
| 534 | TRACE1("Error: %s\n", lpMsgBuf); |
| 535 | LocalFree(lpMsgBuf); |
| 536 | } |
| 537 | #endif |
| 538 | |
| 539 | /* |
| 540 | * Cursor blink functions. |
| 541 | * |
| 542 | * This is a simple state machine: |
| 543 | * BLINK_NONE not blinking at all |
| 544 | * BLINK_OFF blinking, cursor is not shown |
| 545 | * BLINK_ON blinking, cursor is shown |
| 546 | */ |
| 547 | |
| 548 | #define BLINK_NONE 0 |
| 549 | #define BLINK_OFF 1 |
| 550 | #define BLINK_ON 2 |
| 551 | |
| 552 | static int blink_state = BLINK_NONE; |
| 553 | static long_u blink_waittime = 700; |
| 554 | static long_u blink_ontime = 400; |
| 555 | static long_u blink_offtime = 250; |
| 556 | static UINT blink_timer = 0; |
| 557 | |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 558 | int |
| 559 | gui_mch_is_blinking(void) |
| 560 | { |
| 561 | return blink_state != BLINK_NONE; |
| 562 | } |
| 563 | |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 564 | int |
| 565 | gui_mch_is_blink_off(void) |
| 566 | { |
| 567 | return blink_state == BLINK_OFF; |
| 568 | } |
| 569 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 570 | void |
| 571 | gui_mch_set_blinking(long wait, long on, long off) |
| 572 | { |
| 573 | blink_waittime = wait; |
| 574 | blink_ontime = on; |
| 575 | blink_offtime = off; |
| 576 | } |
| 577 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 578 | static VOID CALLBACK |
| 579 | _OnBlinkTimer( |
| 580 | HWND hwnd, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 581 | UINT uMsg UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 582 | UINT idEvent, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 583 | DWORD dwTime UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 584 | { |
| 585 | MSG msg; |
| 586 | |
| 587 | /* |
| 588 | TRACE2("Got timer event, id %d, blink_timer %d\n", idEvent, blink_timer); |
| 589 | */ |
| 590 | |
| 591 | KillTimer(NULL, idEvent); |
| 592 | |
| 593 | /* Eat spurious WM_TIMER messages */ |
| 594 | while (pPeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 595 | ; |
| 596 | |
| 597 | if (blink_state == BLINK_ON) |
| 598 | { |
| 599 | gui_undraw_cursor(); |
| 600 | blink_state = BLINK_OFF; |
| 601 | blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_offtime, |
| 602 | (TIMERPROC)_OnBlinkTimer); |
| 603 | } |
| 604 | else |
| 605 | { |
| 606 | gui_update_cursor(TRUE, FALSE); |
| 607 | blink_state = BLINK_ON; |
| 608 | blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_ontime, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 609 | (TIMERPROC)_OnBlinkTimer); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 610 | } |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 611 | gui_mch_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | static void |
| 615 | gui_mswin_rm_blink_timer(void) |
| 616 | { |
| 617 | MSG msg; |
| 618 | |
| 619 | if (blink_timer != 0) |
| 620 | { |
| 621 | KillTimer(NULL, blink_timer); |
| 622 | /* Eat spurious WM_TIMER messages */ |
| 623 | while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 624 | ; |
| 625 | blink_timer = 0; |
| 626 | } |
| 627 | } |
| 628 | |
| 629 | /* |
| 630 | * Stop the cursor blinking. Show the cursor if it wasn't shown. |
| 631 | */ |
| 632 | void |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 633 | gui_mch_stop_blink(int may_call_gui_update_cursor) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 634 | { |
| 635 | gui_mswin_rm_blink_timer(); |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 636 | if (blink_state == BLINK_OFF && may_call_gui_update_cursor) |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 637 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 638 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 639 | gui_mch_flush(); |
| 640 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 641 | blink_state = BLINK_NONE; |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * Start the cursor blinking. If it was already blinking, this restarts the |
| 646 | * waiting time and shows the cursor. |
| 647 | */ |
| 648 | void |
| 649 | gui_mch_start_blink(void) |
| 650 | { |
| 651 | gui_mswin_rm_blink_timer(); |
| 652 | |
| 653 | /* Only switch blinking on if none of the times is zero */ |
| 654 | if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
| 655 | { |
| 656 | blink_timer = (UINT)SetTimer(NULL, 0, (UINT)blink_waittime, |
| 657 | (TIMERPROC)_OnBlinkTimer); |
| 658 | blink_state = BLINK_ON; |
| 659 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 660 | gui_mch_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 661 | } |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * Call-back routines. |
| 666 | */ |
| 667 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 668 | static VOID CALLBACK |
| 669 | _OnTimer( |
| 670 | HWND hwnd, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 671 | UINT uMsg UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 672 | UINT idEvent, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 673 | DWORD dwTime UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 674 | { |
| 675 | MSG msg; |
| 676 | |
| 677 | /* |
| 678 | TRACE2("Got timer event, id %d, s_wait_timer %d\n", idEvent, s_wait_timer); |
| 679 | */ |
| 680 | KillTimer(NULL, idEvent); |
| 681 | s_timed_out = TRUE; |
| 682 | |
| 683 | /* Eat spurious WM_TIMER messages */ |
| 684 | while (pPeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 685 | ; |
| 686 | if (idEvent == s_wait_timer) |
| 687 | s_wait_timer = 0; |
| 688 | } |
| 689 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 690 | static void |
| 691 | _OnDeadChar( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 692 | HWND hwnd UNUSED, |
| 693 | UINT ch UNUSED, |
| 694 | int cRepeat UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 695 | { |
| 696 | dead_key = 1; |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | * Convert Unicode character "ch" to bytes in "string[slen]". |
| 701 | * When "had_alt" is TRUE the ALT key was included in "ch". |
| 702 | * Return the length. |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 703 | * Because the Windows API uses UTF-16, we have to deal with surrogate |
| 704 | * pairs; this is where we choose to deal with them: if "ch" is a high |
| 705 | * surrogate, it will be stored, and the length returned will be zero; the next |
| 706 | * char_to_string call will then include the high surrogate, decoding the pair |
| 707 | * of UTF-16 code units to a single Unicode code point, presuming it is the |
| 708 | * matching low surrogate. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 709 | */ |
| 710 | static int |
| 711 | char_to_string(int ch, char_u *string, int slen, int had_alt) |
| 712 | { |
| 713 | int len; |
| 714 | int i; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 715 | WCHAR wstring[2]; |
Bram Moolenaar | 945ec09 | 2016-06-08 21:17:43 +0200 | [diff] [blame] | 716 | char_u *ws = NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 717 | |
Bram Moolenaar | f1f2f83 | 2018-04-24 16:04:57 +0200 | [diff] [blame] | 718 | if (surrogate_pending_ch != 0) |
| 719 | { |
| 720 | /* We don't guarantee ch is a low surrogate to match the high surrogate |
| 721 | * we already have; it should be, but if it isn't, tough luck. */ |
| 722 | wstring[0] = surrogate_pending_ch; |
| 723 | wstring[1] = ch; |
| 724 | surrogate_pending_ch = 0; |
| 725 | len = 2; |
| 726 | } |
| 727 | else if (ch >= 0xD800 && ch <= 0xDBFF) /* high surrogate */ |
| 728 | { |
| 729 | /* We don't have the entire code point yet, only the first UTF-16 code |
| 730 | * unit; so just remember it and use it in the next call. */ |
| 731 | surrogate_pending_ch = ch; |
| 732 | return 0; |
| 733 | } |
| 734 | else |
| 735 | { |
| 736 | wstring[0] = ch; |
| 737 | len = 1; |
| 738 | } |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 739 | |
| 740 | /* "ch" is a UTF-16 character. Convert it to a string of bytes. When |
| 741 | * "enc_codepage" is non-zero use the standard Win32 function, |
| 742 | * otherwise use our own conversion function (e.g., for UTF-8). */ |
| 743 | if (enc_codepage > 0) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 744 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 745 | len = WideCharToMultiByte(enc_codepage, 0, wstring, len, |
| 746 | (LPSTR)string, slen, 0, NULL); |
| 747 | /* If we had included the ALT key into the character but now the |
| 748 | * upper bit is no longer set, that probably means the conversion |
| 749 | * failed. Convert the original character and set the upper bit |
| 750 | * afterwards. */ |
| 751 | if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 752 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 753 | wstring[0] = ch & 0x7f; |
| 754 | len = WideCharToMultiByte(enc_codepage, 0, wstring, len, |
| 755 | (LPSTR)string, slen, 0, NULL); |
| 756 | if (len == 1) /* safety check */ |
| 757 | string[0] |= 0x80; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | else |
| 761 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 762 | ws = utf16_to_enc(wstring, &len); |
| 763 | if (ws == NULL) |
| 764 | len = 0; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 765 | else |
| 766 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 767 | if (len > slen) /* just in case */ |
| 768 | len = slen; |
| 769 | mch_memmove(string, ws, len); |
| 770 | vim_free(ws); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
| 774 | if (len == 0) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 775 | { |
| 776 | string[0] = ch; |
| 777 | len = 1; |
| 778 | } |
| 779 | |
| 780 | for (i = 0; i < len; ++i) |
| 781 | if (string[i] == CSI && len <= slen - 2) |
| 782 | { |
| 783 | /* Insert CSI as K_CSI. */ |
| 784 | mch_memmove(string + i + 3, string + i + 1, len - i - 1); |
| 785 | string[++i] = KS_EXTRA; |
| 786 | string[++i] = (int)KE_CSI; |
| 787 | len += 2; |
| 788 | } |
| 789 | |
| 790 | return len; |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | * Key hit, add it to the input buffer. |
| 795 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 796 | static void |
| 797 | _OnChar( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 798 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 799 | UINT ch, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 800 | int cRepeat UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 801 | { |
| 802 | char_u string[40]; |
| 803 | int len = 0; |
| 804 | |
| 805 | dead_key = 0; |
| 806 | |
| 807 | len = char_to_string(ch, string, 40, FALSE); |
| 808 | if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts) |
| 809 | { |
| 810 | trash_input_buf(); |
| 811 | got_int = TRUE; |
| 812 | } |
| 813 | |
| 814 | add_to_input_buf(string, len); |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | * Alt-Key hit, add it to the input buffer. |
| 819 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 820 | static void |
| 821 | _OnSysChar( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 822 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 823 | UINT cch, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 824 | int cRepeat UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 825 | { |
| 826 | char_u string[40]; /* Enough for multibyte character */ |
| 827 | int len; |
| 828 | int modifiers; |
| 829 | int ch = cch; /* special keys are negative */ |
| 830 | |
| 831 | dead_key = 0; |
| 832 | |
| 833 | /* TRACE("OnSysChar(%d, %c)\n", ch, ch); */ |
| 834 | |
| 835 | /* OK, we have a character key (given by ch) which was entered with the |
| 836 | * ALT key pressed. Eg, if the user presses Alt-A, then ch == 'A'. Note |
| 837 | * that the system distinguishes Alt-a and Alt-A (Alt-Shift-a unless |
| 838 | * CAPSLOCK is pressed) at this point. |
| 839 | */ |
| 840 | modifiers = MOD_MASK_ALT; |
| 841 | if (GetKeyState(VK_SHIFT) & 0x8000) |
| 842 | modifiers |= MOD_MASK_SHIFT; |
| 843 | if (GetKeyState(VK_CONTROL) & 0x8000) |
| 844 | modifiers |= MOD_MASK_CTRL; |
| 845 | |
| 846 | ch = simplify_key(ch, &modifiers); |
| 847 | /* remove the SHIFT modifier for keys where it's already included, e.g., |
| 848 | * '(' and '*' */ |
| 849 | if (ch < 0x100 && !isalpha(ch) && isprint(ch)) |
| 850 | modifiers &= ~MOD_MASK_SHIFT; |
| 851 | |
| 852 | /* Interpret the ALT key as making the key META, include SHIFT, etc. */ |
Bram Moolenaar | 459fd78 | 2019-10-13 16:43:39 +0200 | [diff] [blame] | 853 | ch = extract_modifiers(ch, &modifiers, TRUE, NULL); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 854 | if (ch == CSI) |
| 855 | ch = K_CSI; |
| 856 | |
| 857 | len = 0; |
| 858 | if (modifiers) |
| 859 | { |
| 860 | string[len++] = CSI; |
| 861 | string[len++] = KS_MODIFIER; |
| 862 | string[len++] = modifiers; |
| 863 | } |
| 864 | |
| 865 | if (IS_SPECIAL((int)ch)) |
| 866 | { |
| 867 | string[len++] = CSI; |
| 868 | string[len++] = K_SECOND((int)ch); |
| 869 | string[len++] = K_THIRD((int)ch); |
| 870 | } |
| 871 | else |
| 872 | { |
| 873 | /* Although the documentation isn't clear about it, we assume "ch" is |
| 874 | * a Unicode character. */ |
| 875 | len += char_to_string(ch, string + len, 40 - len, TRUE); |
| 876 | } |
| 877 | |
| 878 | add_to_input_buf(string, len); |
| 879 | } |
| 880 | |
| 881 | static void |
| 882 | _OnMouseEvent( |
| 883 | int button, |
| 884 | int x, |
| 885 | int y, |
| 886 | int repeated_click, |
| 887 | UINT keyFlags) |
| 888 | { |
| 889 | int vim_modifiers = 0x0; |
| 890 | |
| 891 | s_getting_focus = FALSE; |
| 892 | |
| 893 | if (keyFlags & MK_SHIFT) |
| 894 | vim_modifiers |= MOUSE_SHIFT; |
| 895 | if (keyFlags & MK_CONTROL) |
| 896 | vim_modifiers |= MOUSE_CTRL; |
| 897 | if (GetKeyState(VK_MENU) & 0x8000) |
| 898 | vim_modifiers |= MOUSE_ALT; |
| 899 | |
| 900 | gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers); |
| 901 | } |
| 902 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 903 | static void |
| 904 | _OnMouseButtonDown( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 905 | HWND hwnd UNUSED, |
| 906 | BOOL fDoubleClick UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 907 | int x, |
| 908 | int y, |
| 909 | UINT keyFlags) |
| 910 | { |
| 911 | static LONG s_prevTime = 0; |
| 912 | |
| 913 | LONG currentTime = GetMessageTime(); |
| 914 | int button = -1; |
| 915 | int repeated_click; |
| 916 | |
| 917 | /* Give main window the focus: this is so the cursor isn't hollow. */ |
| 918 | (void)SetFocus(s_hwnd); |
| 919 | |
| 920 | if (s_uMsg == WM_LBUTTONDOWN || s_uMsg == WM_LBUTTONDBLCLK) |
| 921 | button = MOUSE_LEFT; |
| 922 | else if (s_uMsg == WM_MBUTTONDOWN || s_uMsg == WM_MBUTTONDBLCLK) |
| 923 | button = MOUSE_MIDDLE; |
| 924 | else if (s_uMsg == WM_RBUTTONDOWN || s_uMsg == WM_RBUTTONDBLCLK) |
| 925 | button = MOUSE_RIGHT; |
| 926 | else if (s_uMsg == WM_XBUTTONDOWN || s_uMsg == WM_XBUTTONDBLCLK) |
| 927 | { |
| 928 | #ifndef GET_XBUTTON_WPARAM |
| 929 | # define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam)) |
| 930 | #endif |
| 931 | button = ((GET_XBUTTON_WPARAM(s_wParam) == 1) ? MOUSE_X1 : MOUSE_X2); |
| 932 | } |
| 933 | else if (s_uMsg == WM_CAPTURECHANGED) |
| 934 | { |
| 935 | /* on W95/NT4, somehow you get in here with an odd Msg |
| 936 | * if you press one button while holding down the other..*/ |
| 937 | if (s_button_pending == MOUSE_LEFT) |
| 938 | button = MOUSE_RIGHT; |
| 939 | else |
| 940 | button = MOUSE_LEFT; |
| 941 | } |
| 942 | if (button >= 0) |
| 943 | { |
| 944 | repeated_click = ((int)(currentTime - s_prevTime) < p_mouset); |
| 945 | |
| 946 | /* |
| 947 | * Holding down the left and right buttons simulates pushing the middle |
| 948 | * button. |
| 949 | */ |
| 950 | if (repeated_click |
| 951 | && ((button == MOUSE_LEFT && s_button_pending == MOUSE_RIGHT) |
| 952 | || (button == MOUSE_RIGHT |
| 953 | && s_button_pending == MOUSE_LEFT))) |
| 954 | { |
| 955 | /* |
| 956 | * Hmm, gui.c will ignore more than one button down at a time, so |
| 957 | * pretend we let go of it first. |
| 958 | */ |
| 959 | gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, 0x0); |
| 960 | button = MOUSE_MIDDLE; |
| 961 | repeated_click = FALSE; |
| 962 | s_button_pending = -1; |
| 963 | _OnMouseEvent(button, x, y, repeated_click, keyFlags); |
| 964 | } |
| 965 | else if ((repeated_click) |
| 966 | || (mouse_model_popup() && (button == MOUSE_RIGHT))) |
| 967 | { |
| 968 | if (s_button_pending > -1) |
| 969 | { |
| 970 | _OnMouseEvent(s_button_pending, x, y, FALSE, keyFlags); |
| 971 | s_button_pending = -1; |
| 972 | } |
| 973 | /* TRACE("Button down at x %d, y %d\n", x, y); */ |
| 974 | _OnMouseEvent(button, x, y, repeated_click, keyFlags); |
| 975 | } |
| 976 | else |
| 977 | { |
| 978 | /* |
| 979 | * If this is the first press (i.e. not a multiple click) don't |
| 980 | * action immediately, but store and wait for: |
| 981 | * i) button-up |
| 982 | * ii) mouse move |
| 983 | * iii) another button press |
| 984 | * before using it. |
| 985 | * This enables us to make left+right simulate middle button, |
| 986 | * without left or right being actioned first. The side-effect is |
| 987 | * that if you click and hold the mouse without dragging, the |
| 988 | * cursor doesn't move until you release the button. In practice |
| 989 | * this is hardly a problem. |
| 990 | */ |
| 991 | s_button_pending = button; |
| 992 | s_x_pending = x; |
| 993 | s_y_pending = y; |
| 994 | s_kFlags_pending = keyFlags; |
| 995 | } |
| 996 | |
| 997 | s_prevTime = currentTime; |
| 998 | } |
| 999 | } |
| 1000 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1001 | static void |
| 1002 | _OnMouseMoveOrRelease( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1003 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1004 | int x, |
| 1005 | int y, |
| 1006 | UINT keyFlags) |
| 1007 | { |
| 1008 | int button; |
| 1009 | |
| 1010 | s_getting_focus = FALSE; |
| 1011 | if (s_button_pending > -1) |
| 1012 | { |
| 1013 | /* Delayed action for mouse down event */ |
| 1014 | _OnMouseEvent(s_button_pending, s_x_pending, |
| 1015 | s_y_pending, FALSE, s_kFlags_pending); |
| 1016 | s_button_pending = -1; |
| 1017 | } |
| 1018 | if (s_uMsg == WM_MOUSEMOVE) |
| 1019 | { |
| 1020 | /* |
| 1021 | * It's only a MOUSE_DRAG if one or more mouse buttons are being held |
| 1022 | * down. |
| 1023 | */ |
| 1024 | if (!(keyFlags & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON |
| 1025 | | MK_XBUTTON1 | MK_XBUTTON2))) |
| 1026 | { |
| 1027 | gui_mouse_moved(x, y); |
| 1028 | return; |
| 1029 | } |
| 1030 | |
| 1031 | /* |
| 1032 | * While button is down, keep grabbing mouse move events when |
| 1033 | * the mouse goes outside the window |
| 1034 | */ |
| 1035 | SetCapture(s_textArea); |
| 1036 | button = MOUSE_DRAG; |
| 1037 | /* TRACE(" move at x %d, y %d\n", x, y); */ |
| 1038 | } |
| 1039 | else |
| 1040 | { |
| 1041 | ReleaseCapture(); |
| 1042 | button = MOUSE_RELEASE; |
| 1043 | /* TRACE(" up at x %d, y %d\n", x, y); */ |
| 1044 | } |
| 1045 | |
| 1046 | _OnMouseEvent(button, x, y, FALSE, keyFlags); |
| 1047 | } |
| 1048 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1049 | static void |
| 1050 | _OnSizeTextArea( |
| 1051 | HWND hwnd UNUSED, |
| 1052 | UINT state UNUSED, |
| 1053 | int cx UNUSED, |
| 1054 | int cy UNUSED) |
| 1055 | { |
| 1056 | #if defined(FEAT_DIRECTX) |
| 1057 | if (IS_ENABLE_DIRECTX()) |
| 1058 | directx_binddc(); |
| 1059 | #endif |
| 1060 | } |
| 1061 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1062 | #ifdef FEAT_MENU |
| 1063 | /* |
| 1064 | * Find the vimmenu_T with the given id |
| 1065 | */ |
| 1066 | static vimmenu_T * |
| 1067 | gui_mswin_find_menu( |
| 1068 | vimmenu_T *pMenu, |
| 1069 | int id) |
| 1070 | { |
| 1071 | vimmenu_T *pChildMenu; |
| 1072 | |
| 1073 | while (pMenu) |
| 1074 | { |
| 1075 | if (pMenu->id == (UINT)id) |
| 1076 | break; |
| 1077 | if (pMenu->children != NULL) |
| 1078 | { |
| 1079 | pChildMenu = gui_mswin_find_menu(pMenu->children, id); |
| 1080 | if (pChildMenu) |
| 1081 | { |
| 1082 | pMenu = pChildMenu; |
| 1083 | break; |
| 1084 | } |
| 1085 | } |
| 1086 | pMenu = pMenu->next; |
| 1087 | } |
| 1088 | return pMenu; |
| 1089 | } |
| 1090 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1091 | static void |
| 1092 | _OnMenu( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1093 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1094 | int id, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1095 | HWND hwndCtl UNUSED, |
| 1096 | UINT codeNotify UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1097 | { |
| 1098 | vimmenu_T *pMenu; |
| 1099 | |
| 1100 | pMenu = gui_mswin_find_menu(root_menu, id); |
| 1101 | if (pMenu) |
| 1102 | gui_menu_cb(pMenu); |
| 1103 | } |
| 1104 | #endif |
| 1105 | |
| 1106 | #ifdef MSWIN_FIND_REPLACE |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1107 | /* |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1108 | * Handle a Find/Replace window message. |
| 1109 | */ |
| 1110 | static void |
| 1111 | _OnFindRepl(void) |
| 1112 | { |
| 1113 | int flags = 0; |
| 1114 | int down; |
| 1115 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1116 | if (s_findrep_struct.Flags & FR_DIALOGTERM) |
| 1117 | /* Give main window the focus back. */ |
| 1118 | (void)SetFocus(s_hwnd); |
| 1119 | |
| 1120 | if (s_findrep_struct.Flags & FR_FINDNEXT) |
| 1121 | { |
| 1122 | flags = FRD_FINDNEXT; |
| 1123 | |
| 1124 | /* Give main window the focus back: this is so the cursor isn't |
| 1125 | * hollow. */ |
| 1126 | (void)SetFocus(s_hwnd); |
| 1127 | } |
| 1128 | else if (s_findrep_struct.Flags & FR_REPLACE) |
| 1129 | { |
| 1130 | flags = FRD_REPLACE; |
| 1131 | |
| 1132 | /* Give main window the focus back: this is so the cursor isn't |
| 1133 | * hollow. */ |
| 1134 | (void)SetFocus(s_hwnd); |
| 1135 | } |
| 1136 | else if (s_findrep_struct.Flags & FR_REPLACEALL) |
| 1137 | { |
| 1138 | flags = FRD_REPLACEALL; |
| 1139 | } |
| 1140 | |
| 1141 | if (flags != 0) |
| 1142 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 1143 | char_u *p, *q; |
| 1144 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1145 | /* Call the generic GUI function to do the actual work. */ |
| 1146 | if (s_findrep_struct.Flags & FR_WHOLEWORD) |
| 1147 | flags |= FRD_WHOLE_WORD; |
| 1148 | if (s_findrep_struct.Flags & FR_MATCHCASE) |
| 1149 | flags |= FRD_MATCH_CASE; |
| 1150 | down = (s_findrep_struct.Flags & FR_DOWN) != 0; |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 1151 | p = utf16_to_enc(s_findrep_struct.lpstrFindWhat, NULL); |
| 1152 | q = utf16_to_enc(s_findrep_struct.lpstrReplaceWith, NULL); |
| 1153 | if (p != NULL && q != NULL) |
| 1154 | gui_do_findrepl(flags, p, q, down); |
| 1155 | vim_free(p); |
| 1156 | vim_free(q); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1157 | } |
| 1158 | } |
| 1159 | #endif |
| 1160 | |
| 1161 | static void |
| 1162 | HandleMouseHide(UINT uMsg, LPARAM lParam) |
| 1163 | { |
| 1164 | static LPARAM last_lParam = 0L; |
| 1165 | |
| 1166 | /* We sometimes get a mousemove when the mouse didn't move... */ |
| 1167 | if (uMsg == WM_MOUSEMOVE || uMsg == WM_NCMOUSEMOVE) |
| 1168 | { |
| 1169 | if (lParam == last_lParam) |
| 1170 | return; |
| 1171 | last_lParam = lParam; |
| 1172 | } |
| 1173 | |
| 1174 | /* Handle specially, to centralise coding. We need to be sure we catch all |
| 1175 | * possible events which should cause us to restore the cursor (as it is a |
| 1176 | * shared resource, we take full responsibility for it). |
| 1177 | */ |
| 1178 | switch (uMsg) |
| 1179 | { |
| 1180 | case WM_KEYUP: |
| 1181 | case WM_CHAR: |
| 1182 | /* |
| 1183 | * blank out the pointer if necessary |
| 1184 | */ |
| 1185 | if (p_mh) |
| 1186 | gui_mch_mousehide(TRUE); |
| 1187 | break; |
| 1188 | |
| 1189 | case WM_SYSKEYUP: /* show the pointer when a system-key is pressed */ |
| 1190 | case WM_SYSCHAR: |
| 1191 | case WM_MOUSEMOVE: /* show the pointer on any mouse action */ |
| 1192 | case WM_LBUTTONDOWN: |
| 1193 | case WM_LBUTTONUP: |
| 1194 | case WM_MBUTTONDOWN: |
| 1195 | case WM_MBUTTONUP: |
| 1196 | case WM_RBUTTONDOWN: |
| 1197 | case WM_RBUTTONUP: |
| 1198 | case WM_XBUTTONDOWN: |
| 1199 | case WM_XBUTTONUP: |
| 1200 | case WM_NCMOUSEMOVE: |
| 1201 | case WM_NCLBUTTONDOWN: |
| 1202 | case WM_NCLBUTTONUP: |
| 1203 | case WM_NCMBUTTONDOWN: |
| 1204 | case WM_NCMBUTTONUP: |
| 1205 | case WM_NCRBUTTONDOWN: |
| 1206 | case WM_NCRBUTTONUP: |
| 1207 | case WM_KILLFOCUS: |
| 1208 | /* |
| 1209 | * if the pointer is currently hidden, then we should show it. |
| 1210 | */ |
| 1211 | gui_mch_mousehide(FALSE); |
| 1212 | break; |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | static LRESULT CALLBACK |
| 1217 | _TextAreaWndProc( |
| 1218 | HWND hwnd, |
| 1219 | UINT uMsg, |
| 1220 | WPARAM wParam, |
| 1221 | LPARAM lParam) |
| 1222 | { |
| 1223 | /* |
| 1224 | TRACE("TextAreaWndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n", |
| 1225 | hwnd, uMsg, wParam, lParam); |
| 1226 | */ |
| 1227 | |
| 1228 | HandleMouseHide(uMsg, lParam); |
| 1229 | |
| 1230 | s_uMsg = uMsg; |
| 1231 | s_wParam = wParam; |
| 1232 | s_lParam = lParam; |
| 1233 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1234 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1235 | TrackUserActivity(uMsg); |
| 1236 | #endif |
| 1237 | |
| 1238 | switch (uMsg) |
| 1239 | { |
| 1240 | HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK,_OnMouseButtonDown); |
| 1241 | HANDLE_MSG(hwnd, WM_LBUTTONDOWN,_OnMouseButtonDown); |
| 1242 | HANDLE_MSG(hwnd, WM_LBUTTONUP, _OnMouseMoveOrRelease); |
| 1243 | HANDLE_MSG(hwnd, WM_MBUTTONDBLCLK,_OnMouseButtonDown); |
| 1244 | HANDLE_MSG(hwnd, WM_MBUTTONDOWN,_OnMouseButtonDown); |
| 1245 | HANDLE_MSG(hwnd, WM_MBUTTONUP, _OnMouseMoveOrRelease); |
| 1246 | HANDLE_MSG(hwnd, WM_MOUSEMOVE, _OnMouseMoveOrRelease); |
| 1247 | HANDLE_MSG(hwnd, WM_PAINT, _OnPaint); |
| 1248 | HANDLE_MSG(hwnd, WM_RBUTTONDBLCLK,_OnMouseButtonDown); |
| 1249 | HANDLE_MSG(hwnd, WM_RBUTTONDOWN,_OnMouseButtonDown); |
| 1250 | HANDLE_MSG(hwnd, WM_RBUTTONUP, _OnMouseMoveOrRelease); |
| 1251 | HANDLE_MSG(hwnd, WM_XBUTTONDBLCLK,_OnMouseButtonDown); |
| 1252 | HANDLE_MSG(hwnd, WM_XBUTTONDOWN,_OnMouseButtonDown); |
| 1253 | HANDLE_MSG(hwnd, WM_XBUTTONUP, _OnMouseMoveOrRelease); |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1254 | HANDLE_MSG(hwnd, WM_SIZE, _OnSizeTextArea); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1255 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 1256 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1257 | case WM_NOTIFY: Handle_WM_Notify(hwnd, (LPNMHDR)lParam); |
| 1258 | return TRUE; |
| 1259 | #endif |
| 1260 | default: |
| 1261 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1262 | } |
| 1263 | } |
| 1264 | |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 1265 | #ifdef PROTO |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1266 | typedef int WINAPI; |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 1267 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1268 | |
| 1269 | LRESULT WINAPI |
| 1270 | vim_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 1271 | { |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 1272 | #ifdef GLOBAL_IME |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1273 | return global_ime_DefWindowProc(hwnd, message, wParam, lParam); |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 1274 | #else |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 1275 | return DefWindowProcW(hwnd, message, wParam, lParam); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1276 | #endif |
| 1277 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1278 | |
| 1279 | /* |
| 1280 | * Called when the foreground or background color has been changed. |
| 1281 | */ |
| 1282 | void |
| 1283 | gui_mch_new_colors(void) |
| 1284 | { |
Bram Moolenaar | ab85ca4 | 2019-11-15 22:41:14 +0100 | [diff] [blame] | 1285 | HBRUSH prevBrush; |
| 1286 | |
| 1287 | s_brush = CreateSolidBrush(gui.back_pixel); |
| 1288 | #ifdef SetClassLongPtr |
| 1289 | prevBrush = (HBRUSH)SetClassLongPtr( |
| 1290 | s_hwnd, GCLP_HBRBACKGROUND, (LONG_PTR)s_brush); |
| 1291 | #else |
| 1292 | prevBrush = (HBRUSH)SetClassLong( |
| 1293 | s_hwnd, GCL_HBRBACKGROUND, (long_u)s_brush); |
| 1294 | #endif |
| 1295 | InvalidateRect(s_hwnd, NULL, TRUE); |
| 1296 | DeleteObject(prevBrush); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /* |
| 1300 | * Set the colors to their default values. |
| 1301 | */ |
| 1302 | void |
| 1303 | gui_mch_def_colors(void) |
| 1304 | { |
| 1305 | gui.norm_pixel = GetSysColor(COLOR_WINDOWTEXT); |
| 1306 | gui.back_pixel = GetSysColor(COLOR_WINDOW); |
| 1307 | gui.def_norm_pixel = gui.norm_pixel; |
| 1308 | gui.def_back_pixel = gui.back_pixel; |
| 1309 | } |
| 1310 | |
| 1311 | /* |
| 1312 | * Open the GUI window which was created by a call to gui_mch_init(). |
| 1313 | */ |
| 1314 | int |
| 1315 | gui_mch_open(void) |
| 1316 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1317 | /* Actually open the window, if not already visible |
| 1318 | * (may be done already in gui_mch_set_shellsize) */ |
| 1319 | if (!IsWindowVisible(s_hwnd)) |
| 1320 | ShowWindow(s_hwnd, SW_SHOWDEFAULT); |
| 1321 | |
| 1322 | #ifdef MSWIN_FIND_REPLACE |
| 1323 | /* Init replace string here, so that we keep it when re-opening the |
| 1324 | * dialog. */ |
| 1325 | s_findrep_struct.lpstrReplaceWith[0] = NUL; |
| 1326 | #endif |
| 1327 | |
| 1328 | return OK; |
| 1329 | } |
| 1330 | |
| 1331 | /* |
| 1332 | * Get the position of the top left corner of the window. |
| 1333 | */ |
| 1334 | int |
| 1335 | gui_mch_get_winpos(int *x, int *y) |
| 1336 | { |
| 1337 | RECT rect; |
| 1338 | |
| 1339 | GetWindowRect(s_hwnd, &rect); |
| 1340 | *x = rect.left; |
| 1341 | *y = rect.top; |
| 1342 | return OK; |
| 1343 | } |
| 1344 | |
| 1345 | /* |
| 1346 | * Set the position of the top left corner of the window to the given |
| 1347 | * coordinates. |
| 1348 | */ |
| 1349 | void |
| 1350 | gui_mch_set_winpos(int x, int y) |
| 1351 | { |
| 1352 | SetWindowPos(s_hwnd, NULL, x, y, 0, 0, |
| 1353 | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); |
| 1354 | } |
| 1355 | void |
| 1356 | gui_mch_set_text_area_pos(int x, int y, int w, int h) |
| 1357 | { |
| 1358 | static int oldx = 0; |
| 1359 | static int oldy = 0; |
| 1360 | |
| 1361 | SetWindowPos(s_textArea, NULL, x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE); |
| 1362 | |
| 1363 | #ifdef FEAT_TOOLBAR |
| 1364 | if (vim_strchr(p_go, GO_TOOLBAR) != NULL) |
| 1365 | SendMessage(s_toolbarhwnd, WM_SIZE, |
| 1366 | (WPARAM)0, (LPARAM)(w + ((long)(TOOLBAR_BUTTON_HEIGHT+8)<<16))); |
| 1367 | #endif |
| 1368 | #if defined(FEAT_GUI_TABLINE) |
| 1369 | if (showing_tabline) |
| 1370 | { |
| 1371 | int top = 0; |
| 1372 | RECT rect; |
| 1373 | |
| 1374 | # ifdef FEAT_TOOLBAR |
| 1375 | if (vim_strchr(p_go, GO_TOOLBAR) != NULL) |
| 1376 | top = TOOLBAR_BUTTON_HEIGHT + TOOLBAR_BORDER_HEIGHT; |
| 1377 | # endif |
| 1378 | GetClientRect(s_hwnd, &rect); |
| 1379 | MoveWindow(s_tabhwnd, 0, top, rect.right, gui.tabline_height, TRUE); |
| 1380 | } |
| 1381 | #endif |
| 1382 | |
| 1383 | /* When side scroll bar is unshown, the size of window will change. |
| 1384 | * then, the text area move left or right. thus client rect should be |
| 1385 | * forcedly redrawn. (Yasuhiro Matsumoto) */ |
| 1386 | if (oldx != x || oldy != y) |
| 1387 | { |
| 1388 | InvalidateRect(s_hwnd, NULL, FALSE); |
| 1389 | oldx = x; |
| 1390 | oldy = y; |
| 1391 | } |
| 1392 | } |
| 1393 | |
| 1394 | |
| 1395 | /* |
| 1396 | * Scrollbar stuff: |
| 1397 | */ |
| 1398 | |
| 1399 | void |
| 1400 | gui_mch_enable_scrollbar( |
| 1401 | scrollbar_T *sb, |
| 1402 | int flag) |
| 1403 | { |
| 1404 | ShowScrollBar(sb->id, SB_CTL, flag); |
| 1405 | |
| 1406 | /* TODO: When the window is maximized, the size of the window stays the |
| 1407 | * same, thus the size of the text area changes. On Win98 it's OK, on Win |
| 1408 | * NT 4.0 it's not... */ |
| 1409 | } |
| 1410 | |
| 1411 | void |
| 1412 | gui_mch_set_scrollbar_pos( |
| 1413 | scrollbar_T *sb, |
| 1414 | int x, |
| 1415 | int y, |
| 1416 | int w, |
| 1417 | int h) |
| 1418 | { |
| 1419 | SetWindowPos(sb->id, NULL, x, y, w, h, |
| 1420 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW); |
| 1421 | } |
| 1422 | |
| 1423 | void |
| 1424 | gui_mch_create_scrollbar( |
| 1425 | scrollbar_T *sb, |
| 1426 | int orient) /* SBAR_VERT or SBAR_HORIZ */ |
| 1427 | { |
| 1428 | sb->id = CreateWindow( |
| 1429 | "SCROLLBAR", "Scrollbar", |
| 1430 | WS_CHILD | ((orient == SBAR_VERT) ? SBS_VERT : SBS_HORZ), 0, 0, |
| 1431 | 10, /* Any value will do for now */ |
| 1432 | 10, /* Any value will do for now */ |
| 1433 | s_hwnd, NULL, |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 1434 | g_hinst, NULL); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | /* |
| 1438 | * Find the scrollbar with the given hwnd. |
| 1439 | */ |
| 1440 | static scrollbar_T * |
| 1441 | gui_mswin_find_scrollbar(HWND hwnd) |
| 1442 | { |
| 1443 | win_T *wp; |
| 1444 | |
| 1445 | if (gui.bottom_sbar.id == hwnd) |
| 1446 | return &gui.bottom_sbar; |
| 1447 | FOR_ALL_WINDOWS(wp) |
| 1448 | { |
| 1449 | if (wp->w_scrollbars[SBAR_LEFT].id == hwnd) |
| 1450 | return &wp->w_scrollbars[SBAR_LEFT]; |
| 1451 | if (wp->w_scrollbars[SBAR_RIGHT].id == hwnd) |
| 1452 | return &wp->w_scrollbars[SBAR_RIGHT]; |
| 1453 | } |
| 1454 | return NULL; |
| 1455 | } |
| 1456 | |
| 1457 | /* |
| 1458 | * Get the character size of a font. |
| 1459 | */ |
| 1460 | static void |
| 1461 | GetFontSize(GuiFont font) |
| 1462 | { |
| 1463 | HWND hwnd = GetDesktopWindow(); |
| 1464 | HDC hdc = GetWindowDC(hwnd); |
| 1465 | HFONT hfntOld = SelectFont(hdc, (HFONT)font); |
Bram Moolenaar | 93d77b2 | 2019-05-07 22:52:50 +0200 | [diff] [blame] | 1466 | SIZE size; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1467 | TEXTMETRIC tm; |
| 1468 | |
| 1469 | GetTextMetrics(hdc, &tm); |
Bram Moolenaar | 93d77b2 | 2019-05-07 22:52:50 +0200 | [diff] [blame] | 1470 | // GetTextMetrics() may not return the right value in tmAveCharWidth |
| 1471 | // for some fonts. Do our own average computation. |
| 1472 | GetTextExtentPoint(hdc, |
| 1473 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", |
| 1474 | 52, &size); |
| 1475 | gui.char_width = (size.cx / 26 + 1) / 2 + tm.tmOverhang; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1476 | |
| 1477 | gui.char_height = tm.tmHeight + p_linespace; |
| 1478 | |
| 1479 | SelectFont(hdc, hfntOld); |
| 1480 | |
| 1481 | ReleaseDC(hwnd, hdc); |
| 1482 | } |
| 1483 | |
| 1484 | /* |
| 1485 | * Adjust gui.char_height (after 'linespace' was changed). |
| 1486 | */ |
| 1487 | int |
| 1488 | gui_mch_adjust_charheight(void) |
| 1489 | { |
| 1490 | GetFontSize(gui.norm_font); |
| 1491 | return OK; |
| 1492 | } |
| 1493 | |
| 1494 | static GuiFont |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 1495 | get_font_handle(LOGFONTW *lf) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1496 | { |
| 1497 | HFONT font = NULL; |
| 1498 | |
| 1499 | /* Load the font */ |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 1500 | font = CreateFontIndirectW(lf); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1501 | |
| 1502 | if (font == NULL) |
| 1503 | return NOFONT; |
| 1504 | |
| 1505 | return (GuiFont)font; |
| 1506 | } |
| 1507 | |
| 1508 | static int |
| 1509 | pixels_to_points(int pixels, int vertical) |
| 1510 | { |
| 1511 | int points; |
| 1512 | HWND hwnd; |
| 1513 | HDC hdc; |
| 1514 | |
| 1515 | hwnd = GetDesktopWindow(); |
| 1516 | hdc = GetWindowDC(hwnd); |
| 1517 | |
| 1518 | points = MulDiv(pixels, 72, |
| 1519 | GetDeviceCaps(hdc, vertical ? LOGPIXELSY : LOGPIXELSX)); |
| 1520 | |
| 1521 | ReleaseDC(hwnd, hdc); |
| 1522 | |
| 1523 | return points; |
| 1524 | } |
| 1525 | |
| 1526 | GuiFont |
| 1527 | gui_mch_get_font( |
| 1528 | char_u *name, |
| 1529 | int giveErrorIfMissing) |
| 1530 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 1531 | LOGFONTW lf; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1532 | GuiFont font = NOFONT; |
| 1533 | |
| 1534 | if (get_logfont(&lf, name, NULL, giveErrorIfMissing) == OK) |
| 1535 | font = get_font_handle(&lf); |
| 1536 | if (font == NOFONT && giveErrorIfMissing) |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 1537 | semsg(_(e_font), name); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1538 | return font; |
| 1539 | } |
| 1540 | |
| 1541 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 1542 | /* |
| 1543 | * Return the name of font "font" in allocated memory. |
| 1544 | * Don't know how to get the actual name, thus use the provided name. |
| 1545 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1546 | char_u * |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 1547 | gui_mch_get_fontname(GuiFont font UNUSED, char_u *name) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1548 | { |
| 1549 | if (name == NULL) |
| 1550 | return NULL; |
| 1551 | return vim_strsave(name); |
| 1552 | } |
| 1553 | #endif |
| 1554 | |
| 1555 | void |
| 1556 | gui_mch_free_font(GuiFont font) |
| 1557 | { |
| 1558 | if (font) |
| 1559 | DeleteObject((HFONT)font); |
| 1560 | } |
| 1561 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1562 | /* |
| 1563 | * Return the Pixel value (color) for the given color name. |
| 1564 | * Return INVALCOLOR for error. |
| 1565 | */ |
| 1566 | guicolor_T |
| 1567 | gui_mch_get_color(char_u *name) |
| 1568 | { |
Bram Moolenaar | c285fe7 | 2016-04-26 21:51:48 +0200 | [diff] [blame] | 1569 | int i; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1570 | |
| 1571 | typedef struct SysColorTable |
| 1572 | { |
| 1573 | char *name; |
| 1574 | int color; |
| 1575 | } SysColorTable; |
| 1576 | |
| 1577 | static SysColorTable sys_table[] = |
| 1578 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1579 | {"SYS_3DDKSHADOW", COLOR_3DDKSHADOW}, |
| 1580 | {"SYS_3DHILIGHT", COLOR_3DHILIGHT}, |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 1581 | #ifdef COLOR_3DHIGHLIGHT |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1582 | {"SYS_3DHIGHLIGHT", COLOR_3DHIGHLIGHT}, |
| 1583 | #endif |
| 1584 | {"SYS_BTNHILIGHT", COLOR_BTNHILIGHT}, |
| 1585 | {"SYS_BTNHIGHLIGHT", COLOR_BTNHIGHLIGHT}, |
| 1586 | {"SYS_3DLIGHT", COLOR_3DLIGHT}, |
| 1587 | {"SYS_3DSHADOW", COLOR_3DSHADOW}, |
| 1588 | {"SYS_DESKTOP", COLOR_DESKTOP}, |
| 1589 | {"SYS_INFOBK", COLOR_INFOBK}, |
| 1590 | {"SYS_INFOTEXT", COLOR_INFOTEXT}, |
| 1591 | {"SYS_3DFACE", COLOR_3DFACE}, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1592 | {"SYS_BTNFACE", COLOR_BTNFACE}, |
| 1593 | {"SYS_BTNSHADOW", COLOR_BTNSHADOW}, |
| 1594 | {"SYS_ACTIVEBORDER", COLOR_ACTIVEBORDER}, |
| 1595 | {"SYS_ACTIVECAPTION", COLOR_ACTIVECAPTION}, |
| 1596 | {"SYS_APPWORKSPACE", COLOR_APPWORKSPACE}, |
| 1597 | {"SYS_BACKGROUND", COLOR_BACKGROUND}, |
| 1598 | {"SYS_BTNTEXT", COLOR_BTNTEXT}, |
| 1599 | {"SYS_CAPTIONTEXT", COLOR_CAPTIONTEXT}, |
| 1600 | {"SYS_GRAYTEXT", COLOR_GRAYTEXT}, |
| 1601 | {"SYS_HIGHLIGHT", COLOR_HIGHLIGHT}, |
| 1602 | {"SYS_HIGHLIGHTTEXT", COLOR_HIGHLIGHTTEXT}, |
| 1603 | {"SYS_INACTIVEBORDER", COLOR_INACTIVEBORDER}, |
| 1604 | {"SYS_INACTIVECAPTION", COLOR_INACTIVECAPTION}, |
| 1605 | {"SYS_INACTIVECAPTIONTEXT", COLOR_INACTIVECAPTIONTEXT}, |
| 1606 | {"SYS_MENU", COLOR_MENU}, |
| 1607 | {"SYS_MENUTEXT", COLOR_MENUTEXT}, |
| 1608 | {"SYS_SCROLLBAR", COLOR_SCROLLBAR}, |
| 1609 | {"SYS_WINDOW", COLOR_WINDOW}, |
| 1610 | {"SYS_WINDOWFRAME", COLOR_WINDOWFRAME}, |
| 1611 | {"SYS_WINDOWTEXT", COLOR_WINDOWTEXT} |
| 1612 | }; |
| 1613 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1614 | /* |
| 1615 | * Try to look up a system colour. |
| 1616 | */ |
| 1617 | for (i = 0; i < sizeof(sys_table) / sizeof(sys_table[0]); i++) |
| 1618 | if (STRICMP(name, sys_table[i].name) == 0) |
| 1619 | return GetSysColor(sys_table[i].color); |
| 1620 | |
Bram Moolenaar | ab30221 | 2016-04-26 20:59:29 +0200 | [diff] [blame] | 1621 | return gui_get_color_cmn(name); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1622 | } |
Bram Moolenaar | c285fe7 | 2016-04-26 21:51:48 +0200 | [diff] [blame] | 1623 | |
Bram Moolenaar | 26af85d | 2017-07-23 16:45:10 +0200 | [diff] [blame] | 1624 | guicolor_T |
| 1625 | gui_mch_get_rgb_color(int r, int g, int b) |
| 1626 | { |
| 1627 | return gui_get_rgb_color_cmn(r, g, b); |
| 1628 | } |
| 1629 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1630 | /* |
| 1631 | * Return OK if the key with the termcap name "name" is supported. |
| 1632 | */ |
| 1633 | int |
| 1634 | gui_mch_haskey(char_u *name) |
| 1635 | { |
| 1636 | int i; |
| 1637 | |
| 1638 | for (i = 0; special_keys[i].vim_code1 != NUL; i++) |
| 1639 | if (name[0] == special_keys[i].vim_code0 && |
| 1640 | name[1] == special_keys[i].vim_code1) |
| 1641 | return OK; |
| 1642 | return FAIL; |
| 1643 | } |
| 1644 | |
| 1645 | void |
| 1646 | gui_mch_beep(void) |
| 1647 | { |
| 1648 | MessageBeep(MB_OK); |
| 1649 | } |
| 1650 | /* |
| 1651 | * Invert a rectangle from row r, column c, for nr rows and nc columns. |
| 1652 | */ |
| 1653 | void |
| 1654 | gui_mch_invert_rectangle( |
| 1655 | int r, |
| 1656 | int c, |
| 1657 | int nr, |
| 1658 | int nc) |
| 1659 | { |
| 1660 | RECT rc; |
| 1661 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1662 | #if defined(FEAT_DIRECTX) |
| 1663 | if (IS_ENABLE_DIRECTX()) |
| 1664 | DWriteContext_Flush(s_dwc); |
| 1665 | #endif |
| 1666 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1667 | /* |
| 1668 | * Note: InvertRect() excludes right and bottom of rectangle. |
| 1669 | */ |
| 1670 | rc.left = FILL_X(c); |
| 1671 | rc.top = FILL_Y(r); |
| 1672 | rc.right = rc.left + nc * gui.char_width; |
| 1673 | rc.bottom = rc.top + nr * gui.char_height; |
| 1674 | InvertRect(s_hdc, &rc); |
| 1675 | } |
| 1676 | |
| 1677 | /* |
| 1678 | * Iconify the GUI window. |
| 1679 | */ |
| 1680 | void |
| 1681 | gui_mch_iconify(void) |
| 1682 | { |
| 1683 | ShowWindow(s_hwnd, SW_MINIMIZE); |
| 1684 | } |
| 1685 | |
| 1686 | /* |
| 1687 | * Draw a cursor without focus. |
| 1688 | */ |
| 1689 | void |
| 1690 | gui_mch_draw_hollow_cursor(guicolor_T color) |
| 1691 | { |
| 1692 | HBRUSH hbr; |
| 1693 | RECT rc; |
| 1694 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1695 | #if defined(FEAT_DIRECTX) |
| 1696 | if (IS_ENABLE_DIRECTX()) |
| 1697 | DWriteContext_Flush(s_dwc); |
| 1698 | #endif |
| 1699 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1700 | /* |
| 1701 | * Note: FrameRect() excludes right and bottom of rectangle. |
| 1702 | */ |
| 1703 | rc.left = FILL_X(gui.col); |
| 1704 | rc.top = FILL_Y(gui.row); |
| 1705 | rc.right = rc.left + gui.char_width; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1706 | if (mb_lefthalve(gui.row, gui.col)) |
| 1707 | rc.right += gui.char_width; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1708 | rc.bottom = rc.top + gui.char_height; |
| 1709 | hbr = CreateSolidBrush(color); |
| 1710 | FrameRect(s_hdc, &rc, hbr); |
| 1711 | DeleteBrush(hbr); |
| 1712 | } |
| 1713 | /* |
| 1714 | * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using |
| 1715 | * color "color". |
| 1716 | */ |
| 1717 | void |
| 1718 | gui_mch_draw_part_cursor( |
| 1719 | int w, |
| 1720 | int h, |
| 1721 | guicolor_T color) |
| 1722 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1723 | RECT rc; |
| 1724 | |
| 1725 | /* |
| 1726 | * Note: FillRect() excludes right and bottom of rectangle. |
| 1727 | */ |
| 1728 | rc.left = |
| 1729 | #ifdef FEAT_RIGHTLEFT |
| 1730 | /* vertical line should be on the right of current point */ |
| 1731 | CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
| 1732 | #endif |
| 1733 | FILL_X(gui.col); |
| 1734 | rc.top = FILL_Y(gui.row) + gui.char_height - h; |
| 1735 | rc.right = rc.left + w; |
| 1736 | rc.bottom = rc.top + h; |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 1737 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 1738 | fill_rect(&rc, NULL, color); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | |
| 1742 | /* |
| 1743 | * Generates a VK_SPACE when the internal dead_key flag is set to output the |
| 1744 | * dead key's nominal character and re-post the original message. |
| 1745 | */ |
| 1746 | static void |
| 1747 | outputDeadKey_rePost(MSG originalMsg) |
| 1748 | { |
| 1749 | static MSG deadCharExpel; |
| 1750 | |
| 1751 | if (!dead_key) |
| 1752 | return; |
| 1753 | |
| 1754 | dead_key = 0; |
| 1755 | |
| 1756 | /* Make Windows generate the dead key's character */ |
| 1757 | deadCharExpel.message = originalMsg.message; |
| 1758 | deadCharExpel.hwnd = originalMsg.hwnd; |
| 1759 | deadCharExpel.wParam = VK_SPACE; |
| 1760 | |
| 1761 | MyTranslateMessage(&deadCharExpel); |
| 1762 | |
| 1763 | /* re-generate the current character free of the dead char influence */ |
| 1764 | PostMessage(originalMsg.hwnd, originalMsg.message, originalMsg.wParam, |
| 1765 | originalMsg.lParam); |
| 1766 | } |
| 1767 | |
| 1768 | |
| 1769 | /* |
| 1770 | * Process a single Windows message. |
| 1771 | * If one is not available we hang until one is. |
| 1772 | */ |
| 1773 | static void |
| 1774 | process_message(void) |
| 1775 | { |
| 1776 | MSG msg; |
| 1777 | UINT vk = 0; /* Virtual key */ |
| 1778 | char_u string[40]; |
| 1779 | int i; |
| 1780 | int modifiers = 0; |
| 1781 | int key; |
| 1782 | #ifdef FEAT_MENU |
| 1783 | static char_u k10[] = {K_SPECIAL, 'k', ';', 0}; |
| 1784 | #endif |
| 1785 | |
| 1786 | pGetMessage(&msg, NULL, 0, 0); |
| 1787 | |
| 1788 | #ifdef FEAT_OLE |
| 1789 | /* Look after OLE Automation commands */ |
| 1790 | if (msg.message == WM_OLE) |
| 1791 | { |
| 1792 | char_u *str = (char_u *)msg.lParam; |
| 1793 | if (str == NULL || *str == NUL) |
| 1794 | { |
| 1795 | /* Message can't be ours, forward it. Fixes problem with Ultramon |
| 1796 | * 3.0.4 */ |
| 1797 | pDispatchMessage(&msg); |
| 1798 | } |
| 1799 | else |
| 1800 | { |
| 1801 | add_to_input_buf(str, (int)STRLEN(str)); |
| 1802 | vim_free(str); /* was allocated in CVim::SendKeys() */ |
| 1803 | } |
| 1804 | return; |
| 1805 | } |
| 1806 | #endif |
| 1807 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1808 | #ifdef MSWIN_FIND_REPLACE |
| 1809 | /* Don't process messages used by the dialog */ |
| 1810 | if (s_findrep_hwnd != NULL && pIsDialogMessage(s_findrep_hwnd, &msg)) |
| 1811 | { |
| 1812 | HandleMouseHide(msg.message, msg.lParam); |
| 1813 | return; |
| 1814 | } |
| 1815 | #endif |
| 1816 | |
| 1817 | /* |
| 1818 | * Check if it's a special key that we recognise. If not, call |
| 1819 | * TranslateMessage(). |
| 1820 | */ |
| 1821 | if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) |
| 1822 | { |
| 1823 | vk = (int) msg.wParam; |
| 1824 | |
| 1825 | /* |
| 1826 | * Handle dead keys in special conditions in other cases we let Windows |
| 1827 | * handle them and do not interfere. |
| 1828 | * |
| 1829 | * The dead_key flag must be reset on several occasions: |
| 1830 | * - in _OnChar() (or _OnSysChar()) as any dead key was necessarily |
| 1831 | * consumed at that point (This is when we let Windows combine the |
| 1832 | * dead character on its own) |
| 1833 | * |
| 1834 | * - Before doing something special such as regenerating keypresses to |
| 1835 | * expel the dead character as this could trigger an infinite loop if |
| 1836 | * for some reason MyTranslateMessage() do not trigger a call |
| 1837 | * immediately to _OnChar() (or _OnSysChar()). |
| 1838 | */ |
| 1839 | if (dead_key) |
| 1840 | { |
| 1841 | /* |
| 1842 | * If a dead key was pressed and the user presses VK_SPACE, |
| 1843 | * VK_BACK, or VK_ESCAPE it means that he actually wants to deal |
| 1844 | * with the dead char now, so do nothing special and let Windows |
| 1845 | * handle it. |
| 1846 | * |
| 1847 | * Note that VK_SPACE combines with the dead_key's character and |
| 1848 | * only one WM_CHAR will be generated by TranslateMessage(), in |
| 1849 | * the two other cases two WM_CHAR will be generated: the dead |
| 1850 | * char and VK_BACK or VK_ESCAPE. That is most likely what the |
| 1851 | * user expects. |
| 1852 | */ |
| 1853 | if ((vk == VK_SPACE || vk == VK_BACK || vk == VK_ESCAPE)) |
| 1854 | { |
| 1855 | dead_key = 0; |
| 1856 | MyTranslateMessage(&msg); |
| 1857 | return; |
| 1858 | } |
| 1859 | /* In modes where we are not typing, dead keys should behave |
| 1860 | * normally */ |
| 1861 | else if (!(get_real_state() & (INSERT | CMDLINE | SELECTMODE))) |
| 1862 | { |
| 1863 | outputDeadKey_rePost(msg); |
| 1864 | return; |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | /* Check for CTRL-BREAK */ |
| 1869 | if (vk == VK_CANCEL) |
| 1870 | { |
| 1871 | trash_input_buf(); |
| 1872 | got_int = TRUE; |
Bram Moolenaar | 9698ad7 | 2017-08-12 14:52:15 +0200 | [diff] [blame] | 1873 | ctrl_break_was_pressed = TRUE; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 1874 | string[0] = Ctrl_C; |
| 1875 | add_to_input_buf(string, 1); |
| 1876 | } |
| 1877 | |
| 1878 | for (i = 0; special_keys[i].key_sym != 0; i++) |
| 1879 | { |
| 1880 | /* ignore VK_SPACE when ALT key pressed: system menu */ |
| 1881 | if (special_keys[i].key_sym == vk |
| 1882 | && (vk != VK_SPACE || !(GetKeyState(VK_MENU) & 0x8000))) |
| 1883 | { |
| 1884 | /* |
Bram Moolenaar | 945ec09 | 2016-06-08 21:17:43 +0200 | [diff] [blame] | 1885 | * 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] | 1886 | * is a key that would normally trigger the dead key nominal |
| 1887 | * character output (such as a NUMPAD printable character or |
| 1888 | * the TAB key, etc...). |
| 1889 | */ |
| 1890 | if (dead_key && (special_keys[i].vim_code0 == 'K' |
| 1891 | || vk == VK_TAB || vk == CAR)) |
| 1892 | { |
| 1893 | outputDeadKey_rePost(msg); |
| 1894 | return; |
| 1895 | } |
| 1896 | |
| 1897 | #ifdef FEAT_MENU |
| 1898 | /* Check for <F10>: Windows selects the menu. When <F10> is |
| 1899 | * mapped we want to use the mapping instead. */ |
| 1900 | if (vk == VK_F10 |
| 1901 | && gui.menu_is_active |
| 1902 | && check_map(k10, State, FALSE, TRUE, FALSE, |
| 1903 | NULL, NULL) == NULL) |
| 1904 | break; |
| 1905 | #endif |
| 1906 | if (GetKeyState(VK_SHIFT) & 0x8000) |
| 1907 | modifiers |= MOD_MASK_SHIFT; |
| 1908 | /* |
| 1909 | * Don't use caps-lock as shift, because these are special keys |
| 1910 | * being considered here, and we only want letters to get |
| 1911 | * shifted -- webb |
| 1912 | */ |
| 1913 | /* |
| 1914 | if (GetKeyState(VK_CAPITAL) & 0x0001) |
| 1915 | modifiers ^= MOD_MASK_SHIFT; |
| 1916 | */ |
| 1917 | if (GetKeyState(VK_CONTROL) & 0x8000) |
| 1918 | modifiers |= MOD_MASK_CTRL; |
| 1919 | if (GetKeyState(VK_MENU) & 0x8000) |
| 1920 | modifiers |= MOD_MASK_ALT; |
| 1921 | |
| 1922 | if (special_keys[i].vim_code1 == NUL) |
| 1923 | key = special_keys[i].vim_code0; |
| 1924 | else |
| 1925 | key = TO_SPECIAL(special_keys[i].vim_code0, |
| 1926 | special_keys[i].vim_code1); |
| 1927 | key = simplify_key(key, &modifiers); |
| 1928 | if (key == CSI) |
| 1929 | key = K_CSI; |
| 1930 | |
| 1931 | if (modifiers) |
| 1932 | { |
| 1933 | string[0] = CSI; |
| 1934 | string[1] = KS_MODIFIER; |
| 1935 | string[2] = modifiers; |
| 1936 | add_to_input_buf(string, 3); |
| 1937 | } |
| 1938 | |
| 1939 | if (IS_SPECIAL(key)) |
| 1940 | { |
| 1941 | string[0] = CSI; |
| 1942 | string[1] = K_SECOND(key); |
| 1943 | string[2] = K_THIRD(key); |
| 1944 | add_to_input_buf(string, 3); |
| 1945 | } |
| 1946 | else |
| 1947 | { |
| 1948 | int len; |
| 1949 | |
| 1950 | /* Handle "key" as a Unicode character. */ |
| 1951 | len = char_to_string(key, string, 40, FALSE); |
| 1952 | add_to_input_buf(string, len); |
| 1953 | } |
| 1954 | break; |
| 1955 | } |
| 1956 | } |
| 1957 | if (special_keys[i].key_sym == 0) |
| 1958 | { |
| 1959 | /* Some keys need C-S- where they should only need C-. |
| 1960 | * Ignore 0xff, Windows XP sends it when NUMLOCK has changed since |
| 1961 | * system startup (Helmut Stiegler, 2003 Oct 3). */ |
| 1962 | if (vk != 0xff |
| 1963 | && (GetKeyState(VK_CONTROL) & 0x8000) |
| 1964 | && !(GetKeyState(VK_SHIFT) & 0x8000) |
| 1965 | && !(GetKeyState(VK_MENU) & 0x8000)) |
| 1966 | { |
| 1967 | /* CTRL-6 is '^'; Japanese keyboard maps '^' to vk == 0xDE */ |
| 1968 | if (vk == '6' || MapVirtualKey(vk, 2) == (UINT)'^') |
| 1969 | { |
| 1970 | string[0] = Ctrl_HAT; |
| 1971 | add_to_input_buf(string, 1); |
| 1972 | } |
| 1973 | /* vk == 0xBD AZERTY for CTRL-'-', but CTRL-[ for * QWERTY! */ |
| 1974 | else if (vk == 0xBD) /* QWERTY for CTRL-'-' */ |
| 1975 | { |
| 1976 | string[0] = Ctrl__; |
| 1977 | add_to_input_buf(string, 1); |
| 1978 | } |
| 1979 | /* CTRL-2 is '@'; Japanese keyboard maps '@' to vk == 0xC0 */ |
| 1980 | else if (vk == '2' || MapVirtualKey(vk, 2) == (UINT)'@') |
| 1981 | { |
| 1982 | string[0] = Ctrl_AT; |
| 1983 | add_to_input_buf(string, 1); |
| 1984 | } |
| 1985 | else |
| 1986 | MyTranslateMessage(&msg); |
| 1987 | } |
| 1988 | else |
| 1989 | MyTranslateMessage(&msg); |
| 1990 | } |
| 1991 | } |
| 1992 | #ifdef FEAT_MBYTE_IME |
| 1993 | else if (msg.message == WM_IME_NOTIFY) |
| 1994 | _OnImeNotify(msg.hwnd, (DWORD)msg.wParam, (DWORD)msg.lParam); |
| 1995 | else if (msg.message == WM_KEYUP && im_get_status()) |
| 1996 | /* added for non-MS IME (Yasuhiro Matsumoto) */ |
| 1997 | MyTranslateMessage(&msg); |
| 1998 | #endif |
| 1999 | #if !defined(FEAT_MBYTE_IME) && defined(GLOBAL_IME) |
| 2000 | /* GIME_TEST */ |
| 2001 | else if (msg.message == WM_IME_STARTCOMPOSITION) |
| 2002 | { |
| 2003 | POINT point; |
| 2004 | |
| 2005 | global_ime_set_font(&norm_logfont); |
| 2006 | point.x = FILL_X(gui.col); |
| 2007 | point.y = FILL_Y(gui.row); |
| 2008 | MapWindowPoints(s_textArea, s_hwnd, &point, 1); |
| 2009 | global_ime_set_position(&point); |
| 2010 | } |
| 2011 | #endif |
| 2012 | |
| 2013 | #ifdef FEAT_MENU |
| 2014 | /* Check for <F10>: Default effect is to select the menu. When <F10> is |
| 2015 | * mapped we need to stop it here to avoid strange effects (e.g., for the |
| 2016 | * key-up event) */ |
| 2017 | if (vk != VK_F10 || check_map(k10, State, FALSE, TRUE, FALSE, |
| 2018 | NULL, NULL) == NULL) |
| 2019 | #endif |
| 2020 | pDispatchMessage(&msg); |
| 2021 | } |
| 2022 | |
| 2023 | /* |
| 2024 | * Catch up with any queued events. This may put keyboard input into the |
| 2025 | * input buffer, call resize call-backs, trigger timers etc. If there is |
| 2026 | * nothing in the event queue (& no timers pending), then we return |
| 2027 | * immediately. |
| 2028 | */ |
| 2029 | void |
| 2030 | gui_mch_update(void) |
| 2031 | { |
| 2032 | MSG msg; |
| 2033 | |
| 2034 | if (!s_busy_processing) |
| 2035 | while (pPeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) |
| 2036 | && !vim_is_input_buf_full()) |
| 2037 | process_message(); |
| 2038 | } |
| 2039 | |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2040 | static void |
| 2041 | remove_any_timer(void) |
| 2042 | { |
| 2043 | MSG msg; |
| 2044 | |
| 2045 | if (s_wait_timer != 0 && !s_timed_out) |
| 2046 | { |
| 2047 | KillTimer(NULL, s_wait_timer); |
| 2048 | |
| 2049 | /* Eat spurious WM_TIMER messages */ |
| 2050 | while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE)) |
| 2051 | ; |
| 2052 | s_wait_timer = 0; |
| 2053 | } |
| 2054 | } |
| 2055 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2056 | /* |
| 2057 | * GUI input routine called by gui_wait_for_chars(). Waits for a character |
| 2058 | * from the keyboard. |
| 2059 | * wtime == -1 Wait forever. |
| 2060 | * wtime == 0 This should never happen. |
| 2061 | * wtime > 0 Wait wtime milliseconds for a character. |
| 2062 | * Returns OK if a character was found to be available within the given time, |
| 2063 | * or FAIL otherwise. |
| 2064 | */ |
| 2065 | int |
| 2066 | gui_mch_wait_for_chars(int wtime) |
| 2067 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2068 | int focus; |
| 2069 | |
| 2070 | s_timed_out = FALSE; |
| 2071 | |
Bram Moolenaar | 12dfc9e | 2019-01-28 22:32:58 +0100 | [diff] [blame] | 2072 | if (wtime >= 0) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2073 | { |
Bram Moolenaar | 12dfc9e | 2019-01-28 22:32:58 +0100 | [diff] [blame] | 2074 | // Don't do anything while processing a (scroll) message. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2075 | if (s_busy_processing) |
| 2076 | return FAIL; |
Bram Moolenaar | 12dfc9e | 2019-01-28 22:32:58 +0100 | [diff] [blame] | 2077 | |
| 2078 | // When called with "wtime" zero, just want one msec. |
| 2079 | s_wait_timer = (UINT)SetTimer(NULL, 0, (UINT)(wtime == 0 ? 1 : wtime), |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2080 | (TIMERPROC)_OnTimer); |
| 2081 | } |
| 2082 | |
| 2083 | allow_scrollbar = TRUE; |
| 2084 | |
| 2085 | focus = gui.in_focus; |
| 2086 | while (!s_timed_out) |
| 2087 | { |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2088 | // Stop or start blinking when focus changes |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2089 | if (gui.in_focus != focus) |
| 2090 | { |
| 2091 | if (gui.in_focus) |
| 2092 | gui_mch_start_blink(); |
| 2093 | else |
Bram Moolenaar | 1dd45fb | 2018-01-31 21:10:01 +0100 | [diff] [blame] | 2094 | gui_mch_stop_blink(TRUE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2095 | focus = gui.in_focus; |
| 2096 | } |
| 2097 | |
| 2098 | if (s_need_activate) |
| 2099 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2100 | (void)SetForegroundWindow(s_hwnd); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2101 | s_need_activate = FALSE; |
| 2102 | } |
| 2103 | |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2104 | #ifdef FEAT_TIMERS |
| 2105 | did_add_timer = FALSE; |
| 2106 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2107 | #ifdef MESSAGE_QUEUE |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2108 | // Check channel I/O while waiting for a message. |
Bram Moolenaar | 9186a27 | 2016-02-23 19:34:01 +0100 | [diff] [blame] | 2109 | for (;;) |
| 2110 | { |
| 2111 | MSG msg; |
| 2112 | |
| 2113 | parse_queued_messages(); |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2114 | #ifdef FEAT_TIMERS |
| 2115 | if (did_add_timer) |
| 2116 | break; |
| 2117 | #endif |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2118 | if (pPeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) |
| 2119 | { |
| 2120 | process_message(); |
| 2121 | break; |
| 2122 | } |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2123 | else if (input_available() |
| 2124 | || MsgWaitForMultipleObjects(0, NULL, FALSE, 100, |
| 2125 | QS_ALLINPUT) != WAIT_TIMEOUT) |
Bram Moolenaar | 9186a27 | 2016-02-23 19:34:01 +0100 | [diff] [blame] | 2126 | break; |
| 2127 | } |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2128 | #else |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2129 | // Don't use gui_mch_update() because then we will spin-lock until a |
| 2130 | // char arrives, instead we use GetMessage() to hang until an |
| 2131 | // event arrives. No need to check for input_buf_full because we are |
| 2132 | // returning as soon as it contains a single char -- webb |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2133 | process_message(); |
Bram Moolenaar | 62426e1 | 2017-08-13 15:37:58 +0200 | [diff] [blame] | 2134 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2135 | |
| 2136 | if (input_available()) |
| 2137 | { |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2138 | remove_any_timer(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2139 | allow_scrollbar = FALSE; |
| 2140 | |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2141 | // Clear pending mouse button, the release event may have been |
| 2142 | // taken by the dialog window. But don't do this when getting |
| 2143 | // focus, we need the mouse-up event then. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2144 | if (!s_getting_focus) |
| 2145 | s_button_pending = -1; |
| 2146 | |
| 2147 | return OK; |
| 2148 | } |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2149 | |
| 2150 | #ifdef FEAT_TIMERS |
| 2151 | if (did_add_timer) |
| 2152 | { |
Bram Moolenaar | 89c0003 | 2019-09-04 13:53:21 +0200 | [diff] [blame] | 2153 | // Need to recompute the waiting time. |
Bram Moolenaar | 4231da4 | 2016-06-02 14:30:04 +0200 | [diff] [blame] | 2154 | remove_any_timer(); |
| 2155 | break; |
| 2156 | } |
| 2157 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2158 | } |
| 2159 | allow_scrollbar = FALSE; |
| 2160 | return FAIL; |
| 2161 | } |
| 2162 | |
| 2163 | /* |
| 2164 | * Clear a rectangular region of the screen from text pos (row1, col1) to |
| 2165 | * (row2, col2) inclusive. |
| 2166 | */ |
| 2167 | void |
| 2168 | gui_mch_clear_block( |
| 2169 | int row1, |
| 2170 | int col1, |
| 2171 | int row2, |
| 2172 | int col2) |
| 2173 | { |
| 2174 | RECT rc; |
| 2175 | |
| 2176 | /* |
| 2177 | * Clear one extra pixel at the far right, for when bold characters have |
| 2178 | * spilled over to the window border. |
| 2179 | * Note: FillRect() excludes right and bottom of rectangle. |
| 2180 | */ |
| 2181 | rc.left = FILL_X(col1); |
| 2182 | rc.top = FILL_Y(row1); |
| 2183 | rc.right = FILL_X(col2 + 1) + (col2 == Columns - 1); |
| 2184 | rc.bottom = FILL_Y(row2 + 1); |
| 2185 | clear_rect(&rc); |
| 2186 | } |
| 2187 | |
| 2188 | /* |
| 2189 | * Clear the whole text window. |
| 2190 | */ |
| 2191 | void |
| 2192 | gui_mch_clear_all(void) |
| 2193 | { |
| 2194 | RECT rc; |
| 2195 | |
| 2196 | rc.left = 0; |
| 2197 | rc.top = 0; |
| 2198 | rc.right = Columns * gui.char_width + 2 * gui.border_width; |
| 2199 | rc.bottom = Rows * gui.char_height + 2 * gui.border_width; |
| 2200 | clear_rect(&rc); |
| 2201 | } |
| 2202 | /* |
| 2203 | * Menu stuff. |
| 2204 | */ |
| 2205 | |
| 2206 | void |
| 2207 | gui_mch_enable_menu(int flag) |
| 2208 | { |
| 2209 | #ifdef FEAT_MENU |
| 2210 | SetMenu(s_hwnd, flag ? s_menuBar : NULL); |
| 2211 | #endif |
| 2212 | } |
| 2213 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2214 | void |
| 2215 | gui_mch_set_menu_pos( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2216 | int x UNUSED, |
| 2217 | int y UNUSED, |
| 2218 | int w UNUSED, |
| 2219 | int h UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2220 | { |
| 2221 | /* It will be in the right place anyway */ |
| 2222 | } |
| 2223 | |
| 2224 | #if defined(FEAT_MENU) || defined(PROTO) |
| 2225 | /* |
| 2226 | * Make menu item hidden or not hidden |
| 2227 | */ |
| 2228 | void |
| 2229 | gui_mch_menu_hidden( |
| 2230 | vimmenu_T *menu, |
| 2231 | int hidden) |
| 2232 | { |
| 2233 | /* |
| 2234 | * This doesn't do what we want. Hmm, just grey the menu items for now. |
| 2235 | */ |
| 2236 | /* |
| 2237 | if (hidden) |
| 2238 | EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_DISABLED); |
| 2239 | else |
| 2240 | EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_ENABLED); |
| 2241 | */ |
| 2242 | gui_mch_menu_grey(menu, hidden); |
| 2243 | } |
| 2244 | |
| 2245 | /* |
| 2246 | * This is called after setting all the menus to grey/hidden or not. |
| 2247 | */ |
| 2248 | void |
| 2249 | gui_mch_draw_menubar(void) |
| 2250 | { |
| 2251 | DrawMenuBar(s_hwnd); |
| 2252 | } |
| 2253 | #endif /*FEAT_MENU*/ |
| 2254 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2255 | /* |
| 2256 | * Return the RGB value of a pixel as a long. |
| 2257 | */ |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 2258 | guicolor_T |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2259 | gui_mch_get_rgb(guicolor_T pixel) |
| 2260 | { |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 2261 | return (guicolor_T)((GetRValue(pixel) << 16) + (GetGValue(pixel) << 8) |
| 2262 | + GetBValue(pixel)); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
| 2266 | /* Convert pixels in X to dialog units */ |
| 2267 | static WORD |
| 2268 | PixelToDialogX(int numPixels) |
| 2269 | { |
| 2270 | return (WORD)((numPixels * 4) / s_dlgfntwidth); |
| 2271 | } |
| 2272 | |
| 2273 | /* Convert pixels in Y to dialog units */ |
| 2274 | static WORD |
| 2275 | PixelToDialogY(int numPixels) |
| 2276 | { |
| 2277 | return (WORD)((numPixels * 8) / s_dlgfntheight); |
| 2278 | } |
| 2279 | |
| 2280 | /* Return the width in pixels of the given text in the given DC. */ |
| 2281 | static int |
| 2282 | GetTextWidth(HDC hdc, char_u *str, int len) |
| 2283 | { |
| 2284 | SIZE size; |
| 2285 | |
| 2286 | GetTextExtentPoint(hdc, (LPCSTR)str, len, &size); |
| 2287 | return size.cx; |
| 2288 | } |
| 2289 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2290 | /* |
| 2291 | * Return the width in pixels of the given text in the given DC, taking care |
| 2292 | * of 'encoding' to active codepage conversion. |
| 2293 | */ |
| 2294 | static int |
| 2295 | GetTextWidthEnc(HDC hdc, char_u *str, int len) |
| 2296 | { |
| 2297 | SIZE size; |
| 2298 | WCHAR *wstr; |
| 2299 | int n; |
| 2300 | int wlen = len; |
| 2301 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2302 | wstr = enc_to_utf16(str, &wlen); |
| 2303 | if (wstr == NULL) |
| 2304 | return 0; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2305 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2306 | n = GetTextExtentPointW(hdc, wstr, wlen, &size); |
| 2307 | vim_free(wstr); |
| 2308 | if (n) |
| 2309 | return size.cx; |
| 2310 | return 0; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2311 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2312 | |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2313 | static void get_work_area(RECT *spi_rect); |
| 2314 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2315 | /* |
| 2316 | * 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] | 2317 | * dialog boxes. Taken from the Win32SDK samples and modified for multiple |
| 2318 | * monitors. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2319 | */ |
| 2320 | static BOOL |
| 2321 | CenterWindow( |
| 2322 | HWND hwndChild, |
| 2323 | HWND hwndParent) |
| 2324 | { |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2325 | HMONITOR mon; |
| 2326 | MONITORINFO moninfo; |
| 2327 | RECT rChild, rParent, rScreen; |
| 2328 | int wChild, hChild, wParent, hParent; |
| 2329 | int xNew, yNew; |
| 2330 | HDC hdc; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2331 | |
| 2332 | GetWindowRect(hwndChild, &rChild); |
| 2333 | wChild = rChild.right - rChild.left; |
| 2334 | hChild = rChild.bottom - rChild.top; |
| 2335 | |
| 2336 | /* If Vim is minimized put the window in the middle of the screen. */ |
| 2337 | if (hwndParent == NULL || IsMinimized(hwndParent)) |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2338 | get_work_area(&rParent); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2339 | else |
| 2340 | GetWindowRect(hwndParent, &rParent); |
| 2341 | wParent = rParent.right - rParent.left; |
| 2342 | hParent = rParent.bottom - rParent.top; |
| 2343 | |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2344 | moninfo.cbSize = sizeof(MONITORINFO); |
| 2345 | mon = MonitorFromWindow(hwndChild, MONITOR_DEFAULTTOPRIMARY); |
| 2346 | if (mon != NULL && GetMonitorInfo(mon, &moninfo)) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2347 | { |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2348 | rScreen = moninfo.rcWork; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2349 | } |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2350 | else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2351 | { |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2352 | hdc = GetDC(hwndChild); |
| 2353 | rScreen.left = 0; |
| 2354 | rScreen.top = 0; |
| 2355 | rScreen.right = GetDeviceCaps(hdc, HORZRES); |
| 2356 | rScreen.bottom = GetDeviceCaps(hdc, VERTRES); |
| 2357 | ReleaseDC(hwndChild, hdc); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
Bram Moolenaar | 87f3d20 | 2016-12-01 20:18:50 +0100 | [diff] [blame] | 2360 | xNew = rParent.left + ((wParent - wChild) / 2); |
| 2361 | if (xNew < rScreen.left) |
| 2362 | xNew = rScreen.left; |
| 2363 | else if ((xNew + wChild) > rScreen.right) |
| 2364 | xNew = rScreen.right - wChild; |
| 2365 | |
| 2366 | yNew = rParent.top + ((hParent - hChild) / 2); |
| 2367 | if (yNew < rScreen.top) |
| 2368 | yNew = rScreen.top; |
| 2369 | else if ((yNew + hChild) > rScreen.bottom) |
| 2370 | yNew = rScreen.bottom - hChild; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2371 | |
| 2372 | return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0, |
| 2373 | SWP_NOSIZE | SWP_NOZORDER); |
| 2374 | } |
| 2375 | #endif /* FEAT_GUI_DIALOG */ |
| 2376 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2377 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 2378 | void |
| 2379 | gui_mch_show_toolbar(int showit) |
| 2380 | { |
| 2381 | if (s_toolbarhwnd == NULL) |
| 2382 | return; |
| 2383 | |
| 2384 | if (showit) |
| 2385 | { |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 2386 | # ifndef TB_SETUNICODEFORMAT |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2387 | // For older compilers. We assume this never changes. |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 2388 | # define TB_SETUNICODEFORMAT 0x2005 |
| 2389 | # endif |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2390 | // Enable unicode support |
| 2391 | SendMessage(s_toolbarhwnd, TB_SETUNICODEFORMAT, (WPARAM)TRUE, |
| 2392 | (LPARAM)0); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2393 | ShowWindow(s_toolbarhwnd, SW_SHOW); |
| 2394 | } |
| 2395 | else |
| 2396 | ShowWindow(s_toolbarhwnd, SW_HIDE); |
| 2397 | } |
| 2398 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2399 | /* The number of bitmaps is fixed. Exit is missing! */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2400 | #define TOOLBAR_BITMAP_COUNT 31 |
| 2401 | |
| 2402 | #endif |
| 2403 | |
| 2404 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
| 2405 | static void |
| 2406 | add_tabline_popup_menu_entry(HMENU pmenu, UINT item_id, char_u *item_text) |
| 2407 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2408 | WCHAR *wn; |
| 2409 | MENUITEMINFOW infow; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2410 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2411 | wn = enc_to_utf16(item_text, NULL); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2412 | if (wn == NULL) |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2413 | return; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2414 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2415 | infow.cbSize = sizeof(infow); |
| 2416 | infow.fMask = MIIM_TYPE | MIIM_ID; |
| 2417 | infow.wID = item_id; |
| 2418 | infow.fType = MFT_STRING; |
| 2419 | infow.dwTypeData = wn; |
| 2420 | infow.cch = (UINT)wcslen(wn); |
| 2421 | InsertMenuItemW(pmenu, item_id, FALSE, &infow); |
| 2422 | vim_free(wn); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | static void |
| 2426 | show_tabline_popup_menu(void) |
| 2427 | { |
| 2428 | HMENU tab_pmenu; |
| 2429 | long rval; |
| 2430 | POINT pt; |
| 2431 | |
| 2432 | /* When ignoring events don't show the menu. */ |
| 2433 | if (hold_gui_events |
| 2434 | # ifdef FEAT_CMDWIN |
| 2435 | || cmdwin_type != 0 |
| 2436 | # endif |
| 2437 | ) |
| 2438 | return; |
| 2439 | |
| 2440 | tab_pmenu = CreatePopupMenu(); |
| 2441 | if (tab_pmenu == NULL) |
| 2442 | return; |
| 2443 | |
| 2444 | if (first_tabpage->tp_next != NULL) |
| 2445 | add_tabline_popup_menu_entry(tab_pmenu, |
| 2446 | TABLINE_MENU_CLOSE, (char_u *)_("Close tab")); |
| 2447 | add_tabline_popup_menu_entry(tab_pmenu, |
| 2448 | TABLINE_MENU_NEW, (char_u *)_("New tab")); |
| 2449 | add_tabline_popup_menu_entry(tab_pmenu, |
| 2450 | TABLINE_MENU_OPEN, (char_u *)_("Open tab...")); |
| 2451 | |
| 2452 | GetCursorPos(&pt); |
| 2453 | rval = TrackPopupMenuEx(tab_pmenu, TPM_RETURNCMD, pt.x, pt.y, s_tabhwnd, |
| 2454 | NULL); |
| 2455 | |
| 2456 | DestroyMenu(tab_pmenu); |
| 2457 | |
| 2458 | /* Add the string cmd into input buffer */ |
| 2459 | if (rval > 0) |
| 2460 | { |
| 2461 | TCHITTESTINFO htinfo; |
| 2462 | int idx; |
| 2463 | |
| 2464 | if (ScreenToClient(s_tabhwnd, &pt) == 0) |
| 2465 | return; |
| 2466 | |
| 2467 | htinfo.pt.x = pt.x; |
| 2468 | htinfo.pt.y = pt.y; |
| 2469 | idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 2470 | if (idx == -1) |
| 2471 | idx = 0; |
| 2472 | else |
| 2473 | idx += 1; |
| 2474 | |
| 2475 | send_tabline_menu_event(idx, (int)rval); |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | /* |
| 2480 | * Show or hide the tabline. |
| 2481 | */ |
| 2482 | void |
| 2483 | gui_mch_show_tabline(int showit) |
| 2484 | { |
| 2485 | if (s_tabhwnd == NULL) |
| 2486 | return; |
| 2487 | |
| 2488 | if (!showit != !showing_tabline) |
| 2489 | { |
| 2490 | if (showit) |
| 2491 | ShowWindow(s_tabhwnd, SW_SHOW); |
| 2492 | else |
| 2493 | ShowWindow(s_tabhwnd, SW_HIDE); |
| 2494 | showing_tabline = showit; |
| 2495 | } |
| 2496 | } |
| 2497 | |
| 2498 | /* |
| 2499 | * Return TRUE when tabline is displayed. |
| 2500 | */ |
| 2501 | int |
| 2502 | gui_mch_showing_tabline(void) |
| 2503 | { |
| 2504 | return s_tabhwnd != NULL && showing_tabline; |
| 2505 | } |
| 2506 | |
| 2507 | /* |
| 2508 | * Update the labels of the tabline. |
| 2509 | */ |
| 2510 | void |
| 2511 | gui_mch_update_tabline(void) |
| 2512 | { |
| 2513 | tabpage_T *tp; |
| 2514 | TCITEM tie; |
| 2515 | int nr = 0; |
| 2516 | int curtabidx = 0; |
| 2517 | int tabadded = 0; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2518 | WCHAR *wstr = NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2519 | |
| 2520 | if (s_tabhwnd == NULL) |
| 2521 | return; |
| 2522 | |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 2523 | #ifndef CCM_SETUNICODEFORMAT |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2524 | /* For older compilers. We assume this never changes. */ |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 2525 | # define CCM_SETUNICODEFORMAT 0x2005 |
| 2526 | #endif |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2527 | // Enable unicode support |
| 2528 | SendMessage(s_tabhwnd, CCM_SETUNICODEFORMAT, (WPARAM)TRUE, (LPARAM)0); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2529 | |
| 2530 | tie.mask = TCIF_TEXT; |
| 2531 | tie.iImage = -1; |
| 2532 | |
| 2533 | /* Disable redraw for tab updates to eliminate O(N^2) draws. */ |
| 2534 | SendMessage(s_tabhwnd, WM_SETREDRAW, (WPARAM)FALSE, 0); |
| 2535 | |
| 2536 | /* Add a label for each tab page. They all contain the same text area. */ |
| 2537 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) |
| 2538 | { |
| 2539 | if (tp == curtab) |
| 2540 | curtabidx = nr; |
| 2541 | |
| 2542 | if (nr >= TabCtrl_GetItemCount(s_tabhwnd)) |
| 2543 | { |
| 2544 | /* Add the tab */ |
| 2545 | tie.pszText = "-Empty-"; |
| 2546 | TabCtrl_InsertItem(s_tabhwnd, nr, &tie); |
| 2547 | tabadded = 1; |
| 2548 | } |
| 2549 | |
| 2550 | get_tabline_label(tp, FALSE); |
| 2551 | tie.pszText = (LPSTR)NameBuff; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2552 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2553 | wstr = enc_to_utf16(NameBuff, NULL); |
| 2554 | if (wstr != NULL) |
| 2555 | { |
| 2556 | TCITEMW tiw; |
| 2557 | |
| 2558 | tiw.mask = TCIF_TEXT; |
| 2559 | tiw.iImage = -1; |
| 2560 | tiw.pszText = wstr; |
| 2561 | SendMessage(s_tabhwnd, TCM_SETITEMW, (WPARAM)nr, (LPARAM)&tiw); |
| 2562 | vim_free(wstr); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2563 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2564 | } |
| 2565 | |
| 2566 | /* Remove any old labels. */ |
| 2567 | while (nr < TabCtrl_GetItemCount(s_tabhwnd)) |
| 2568 | TabCtrl_DeleteItem(s_tabhwnd, nr); |
| 2569 | |
| 2570 | if (!tabadded && TabCtrl_GetCurSel(s_tabhwnd) != curtabidx) |
| 2571 | TabCtrl_SetCurSel(s_tabhwnd, curtabidx); |
| 2572 | |
| 2573 | /* Re-enable redraw and redraw. */ |
| 2574 | SendMessage(s_tabhwnd, WM_SETREDRAW, (WPARAM)TRUE, 0); |
| 2575 | RedrawWindow(s_tabhwnd, NULL, NULL, |
| 2576 | RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN); |
| 2577 | |
| 2578 | if (tabadded && TabCtrl_GetCurSel(s_tabhwnd) != curtabidx) |
| 2579 | TabCtrl_SetCurSel(s_tabhwnd, curtabidx); |
| 2580 | } |
| 2581 | |
| 2582 | /* |
| 2583 | * Set the current tab to "nr". First tab is 1. |
| 2584 | */ |
| 2585 | void |
| 2586 | gui_mch_set_curtab(int nr) |
| 2587 | { |
| 2588 | if (s_tabhwnd == NULL) |
| 2589 | return; |
| 2590 | |
| 2591 | if (TabCtrl_GetCurSel(s_tabhwnd) != nr - 1) |
| 2592 | TabCtrl_SetCurSel(s_tabhwnd, nr - 1); |
| 2593 | } |
| 2594 | |
| 2595 | #endif |
| 2596 | |
| 2597 | /* |
| 2598 | * ":simalt" command. |
| 2599 | */ |
| 2600 | void |
| 2601 | ex_simalt(exarg_T *eap) |
| 2602 | { |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2603 | char_u *keys = eap->arg; |
| 2604 | int fill_typebuf = FALSE; |
| 2605 | char_u key_name[4]; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2606 | |
| 2607 | PostMessage(s_hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)0); |
| 2608 | while (*keys) |
| 2609 | { |
| 2610 | if (*keys == '~') |
| 2611 | *keys = ' '; /* for showing system menu */ |
| 2612 | PostMessage(s_hwnd, WM_CHAR, (WPARAM)*keys, (LPARAM)0); |
| 2613 | keys++; |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2614 | fill_typebuf = TRUE; |
| 2615 | } |
| 2616 | if (fill_typebuf) |
| 2617 | { |
Bram Moolenaar | a21ccb7 | 2017-04-29 17:40:22 +0200 | [diff] [blame] | 2618 | /* 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] | 2619 | * processed. */ |
| 2620 | key_name[0] = K_SPECIAL; |
| 2621 | key_name[1] = KS_EXTRA; |
Bram Moolenaar | a21ccb7 | 2017-04-29 17:40:22 +0200 | [diff] [blame] | 2622 | key_name[2] = KE_NOP; |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2623 | key_name[3] = NUL; |
Bram Moolenaar | 93bbf33 | 2019-10-23 21:43:16 +0200 | [diff] [blame] | 2624 | #if defined(FEAT_CLIENTSERVER) || defined(FEAT_EVAL) |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2625 | typebuf_was_filled = TRUE; |
Bram Moolenaar | 93bbf33 | 2019-10-23 21:43:16 +0200 | [diff] [blame] | 2626 | #endif |
Bram Moolenaar | 7a85b0f | 2017-04-22 15:17:40 +0200 | [diff] [blame] | 2627 | (void)ins_typebuf(key_name, REMAP_NONE, 0, TRUE, FALSE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | /* |
| 2632 | * Create the find & replace dialogs. |
| 2633 | * You can't have both at once: ":find" when replace is showing, destroys |
| 2634 | * the replace dialog first, and the other way around. |
| 2635 | */ |
| 2636 | #ifdef MSWIN_FIND_REPLACE |
| 2637 | static void |
| 2638 | initialise_findrep(char_u *initial_string) |
| 2639 | { |
| 2640 | int wword = FALSE; |
| 2641 | int mcase = !p_ic; |
| 2642 | char_u *entry_text; |
| 2643 | |
| 2644 | /* Get the search string to use. */ |
| 2645 | entry_text = get_find_dialog_text(initial_string, &wword, &mcase); |
| 2646 | |
| 2647 | s_findrep_struct.hwndOwner = s_hwnd; |
| 2648 | s_findrep_struct.Flags = FR_DOWN; |
| 2649 | if (mcase) |
| 2650 | s_findrep_struct.Flags |= FR_MATCHCASE; |
| 2651 | if (wword) |
| 2652 | s_findrep_struct.Flags |= FR_WHOLEWORD; |
| 2653 | if (entry_text != NULL && *entry_text != NUL) |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2654 | { |
| 2655 | WCHAR *p = enc_to_utf16(entry_text, NULL); |
| 2656 | if (p != NULL) |
| 2657 | { |
| 2658 | int len = s_findrep_struct.wFindWhatLen - 1; |
| 2659 | |
| 2660 | wcsncpy(s_findrep_struct.lpstrFindWhat, p, len); |
| 2661 | s_findrep_struct.lpstrFindWhat[len] = NUL; |
| 2662 | vim_free(p); |
| 2663 | } |
| 2664 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2665 | vim_free(entry_text); |
| 2666 | } |
| 2667 | #endif |
| 2668 | |
| 2669 | static void |
| 2670 | set_window_title(HWND hwnd, char *title) |
| 2671 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2672 | if (title != NULL) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2673 | { |
| 2674 | WCHAR *wbuf; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2675 | |
| 2676 | /* Convert the title from 'encoding' to UTF-16. */ |
| 2677 | wbuf = (WCHAR *)enc_to_utf16((char_u *)title, NULL); |
| 2678 | if (wbuf != NULL) |
| 2679 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 2680 | SetWindowTextW(hwnd, wbuf); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2681 | vim_free(wbuf); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2682 | } |
| 2683 | } |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2684 | else |
| 2685 | (void)SetWindowTextW(hwnd, NULL); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | void |
| 2689 | gui_mch_find_dialog(exarg_T *eap) |
| 2690 | { |
| 2691 | #ifdef MSWIN_FIND_REPLACE |
| 2692 | if (s_findrep_msg != 0) |
| 2693 | { |
| 2694 | if (IsWindow(s_findrep_hwnd) && !s_findrep_is_find) |
| 2695 | DestroyWindow(s_findrep_hwnd); |
| 2696 | |
| 2697 | if (!IsWindow(s_findrep_hwnd)) |
| 2698 | { |
| 2699 | initialise_findrep(eap->arg); |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2700 | s_findrep_hwnd = FindTextW((LPFINDREPLACEW) &s_findrep_struct); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
Bram Moolenaar | 9e42c86 | 2018-07-20 05:03:16 +0200 | [diff] [blame] | 2703 | set_window_title(s_findrep_hwnd, _("Find string")); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2704 | (void)SetFocus(s_findrep_hwnd); |
| 2705 | |
| 2706 | s_findrep_is_find = TRUE; |
| 2707 | } |
| 2708 | #endif |
| 2709 | } |
| 2710 | |
| 2711 | |
| 2712 | void |
| 2713 | gui_mch_replace_dialog(exarg_T *eap) |
| 2714 | { |
| 2715 | #ifdef MSWIN_FIND_REPLACE |
| 2716 | if (s_findrep_msg != 0) |
| 2717 | { |
| 2718 | if (IsWindow(s_findrep_hwnd) && s_findrep_is_find) |
| 2719 | DestroyWindow(s_findrep_hwnd); |
| 2720 | |
| 2721 | if (!IsWindow(s_findrep_hwnd)) |
| 2722 | { |
| 2723 | initialise_findrep(eap->arg); |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 2724 | s_findrep_hwnd = ReplaceTextW((LPFINDREPLACEW) &s_findrep_struct); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2725 | } |
| 2726 | |
Bram Moolenaar | 9e42c86 | 2018-07-20 05:03:16 +0200 | [diff] [blame] | 2727 | set_window_title(s_findrep_hwnd, _("Find & Replace")); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2728 | (void)SetFocus(s_findrep_hwnd); |
| 2729 | |
| 2730 | s_findrep_is_find = FALSE; |
| 2731 | } |
| 2732 | #endif |
| 2733 | } |
| 2734 | |
| 2735 | |
| 2736 | /* |
| 2737 | * Set visibility of the pointer. |
| 2738 | */ |
| 2739 | void |
| 2740 | gui_mch_mousehide(int hide) |
| 2741 | { |
| 2742 | if (hide != gui.pointer_hidden) |
| 2743 | { |
| 2744 | ShowCursor(!hide); |
| 2745 | gui.pointer_hidden = hide; |
| 2746 | } |
| 2747 | } |
| 2748 | |
| 2749 | #ifdef FEAT_MENU |
| 2750 | static void |
| 2751 | gui_mch_show_popupmenu_at(vimmenu_T *menu, int x, int y) |
| 2752 | { |
| 2753 | /* Unhide the mouse, we don't get move events here. */ |
| 2754 | gui_mch_mousehide(FALSE); |
| 2755 | |
| 2756 | (void)TrackPopupMenu( |
| 2757 | (HMENU)menu->submenu_id, |
| 2758 | TPM_LEFTALIGN | TPM_LEFTBUTTON, |
| 2759 | x, y, |
| 2760 | (int)0, /*reserved param*/ |
| 2761 | s_hwnd, |
| 2762 | NULL); |
| 2763 | /* |
| 2764 | * NOTE: The pop-up menu can eat the mouse up event. |
| 2765 | * We deal with this in normal.c. |
| 2766 | */ |
| 2767 | } |
| 2768 | #endif |
| 2769 | |
| 2770 | /* |
| 2771 | * Got a message when the system will go down. |
| 2772 | */ |
| 2773 | static void |
| 2774 | _OnEndSession(void) |
| 2775 | { |
| 2776 | getout_preserve_modified(1); |
| 2777 | } |
| 2778 | |
| 2779 | /* |
| 2780 | * Get this message when the user clicks on the cross in the top right corner |
| 2781 | * of a Windows95 window. |
| 2782 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2783 | static void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2784 | _OnClose(HWND hwnd UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2785 | { |
| 2786 | gui_shell_closed(); |
| 2787 | } |
| 2788 | |
| 2789 | /* |
| 2790 | * Get a message when the window is being destroyed. |
| 2791 | */ |
| 2792 | static void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2793 | _OnDestroy(HWND hwnd) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2794 | { |
| 2795 | if (!destroying) |
| 2796 | _OnClose(hwnd); |
| 2797 | } |
| 2798 | |
| 2799 | static void |
| 2800 | _OnPaint( |
| 2801 | HWND hwnd) |
| 2802 | { |
| 2803 | if (!IsMinimized(hwnd)) |
| 2804 | { |
| 2805 | PAINTSTRUCT ps; |
| 2806 | |
| 2807 | out_flush(); /* make sure all output has been processed */ |
| 2808 | (void)BeginPaint(hwnd, &ps); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2809 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2810 | /* prevent multi-byte characters from misprinting on an invalid |
| 2811 | * rectangle */ |
| 2812 | if (has_mbyte) |
| 2813 | { |
| 2814 | RECT rect; |
| 2815 | |
| 2816 | GetClientRect(hwnd, &rect); |
| 2817 | ps.rcPaint.left = rect.left; |
| 2818 | ps.rcPaint.right = rect.right; |
| 2819 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2820 | |
| 2821 | if (!IsRectEmpty(&ps.rcPaint)) |
| 2822 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2823 | gui_redraw(ps.rcPaint.left, ps.rcPaint.top, |
| 2824 | ps.rcPaint.right - ps.rcPaint.left + 1, |
| 2825 | ps.rcPaint.bottom - ps.rcPaint.top + 1); |
| 2826 | } |
| 2827 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2828 | EndPaint(hwnd, &ps); |
| 2829 | } |
| 2830 | } |
| 2831 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2832 | static void |
| 2833 | _OnSize( |
| 2834 | HWND hwnd, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 2835 | UINT state UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2836 | int cx, |
| 2837 | int cy) |
| 2838 | { |
| 2839 | if (!IsMinimized(hwnd)) |
| 2840 | { |
| 2841 | gui_resize_shell(cx, cy); |
| 2842 | |
| 2843 | #ifdef FEAT_MENU |
| 2844 | /* Menu bar may wrap differently now */ |
| 2845 | gui_mswin_get_menu_height(TRUE); |
| 2846 | #endif |
| 2847 | } |
| 2848 | } |
| 2849 | |
| 2850 | static void |
| 2851 | _OnSetFocus( |
| 2852 | HWND hwnd, |
| 2853 | HWND hwndOldFocus) |
| 2854 | { |
| 2855 | gui_focus_change(TRUE); |
| 2856 | s_getting_focus = TRUE; |
| 2857 | (void)MyWindowProc(hwnd, WM_SETFOCUS, (WPARAM)hwndOldFocus, 0); |
| 2858 | } |
| 2859 | |
| 2860 | static void |
| 2861 | _OnKillFocus( |
| 2862 | HWND hwnd, |
| 2863 | HWND hwndNewFocus) |
| 2864 | { |
| 2865 | gui_focus_change(FALSE); |
| 2866 | s_getting_focus = FALSE; |
| 2867 | (void)MyWindowProc(hwnd, WM_KILLFOCUS, (WPARAM)hwndNewFocus, 0); |
| 2868 | } |
| 2869 | |
| 2870 | /* |
| 2871 | * Get a message when the user switches back to vim |
| 2872 | */ |
| 2873 | static LRESULT |
| 2874 | _OnActivateApp( |
| 2875 | HWND hwnd, |
| 2876 | BOOL fActivate, |
| 2877 | DWORD dwThreadId) |
| 2878 | { |
| 2879 | /* we call gui_focus_change() in _OnSetFocus() */ |
| 2880 | /* gui_focus_change((int)fActivate); */ |
| 2881 | return MyWindowProc(hwnd, WM_ACTIVATEAPP, fActivate, (DWORD)dwThreadId); |
| 2882 | } |
| 2883 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2884 | void |
| 2885 | gui_mch_destroy_scrollbar(scrollbar_T *sb) |
| 2886 | { |
| 2887 | DestroyWindow(sb->id); |
| 2888 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2889 | |
| 2890 | /* |
| 2891 | * Get current mouse coordinates in text window. |
| 2892 | */ |
| 2893 | void |
| 2894 | gui_mch_getmouse(int *x, int *y) |
| 2895 | { |
| 2896 | RECT rct; |
| 2897 | POINT mp; |
| 2898 | |
| 2899 | (void)GetWindowRect(s_textArea, &rct); |
| 2900 | (void)GetCursorPos((LPPOINT)&mp); |
| 2901 | *x = (int)(mp.x - rct.left); |
| 2902 | *y = (int)(mp.y - rct.top); |
| 2903 | } |
| 2904 | |
| 2905 | /* |
| 2906 | * Move mouse pointer to character at (x, y). |
| 2907 | */ |
| 2908 | void |
| 2909 | gui_mch_setmouse(int x, int y) |
| 2910 | { |
| 2911 | RECT rct; |
| 2912 | |
| 2913 | (void)GetWindowRect(s_textArea, &rct); |
| 2914 | (void)SetCursorPos(x + gui.border_offset + rct.left, |
| 2915 | y + gui.border_offset + rct.top); |
| 2916 | } |
| 2917 | |
| 2918 | static void |
| 2919 | gui_mswin_get_valid_dimensions( |
| 2920 | int w, |
| 2921 | int h, |
| 2922 | int *valid_w, |
| 2923 | int *valid_h) |
| 2924 | { |
| 2925 | int base_width, base_height; |
| 2926 | |
| 2927 | base_width = gui_get_base_width() |
| 2928 | + (GetSystemMetrics(SM_CXFRAME) + |
| 2929 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
| 2930 | base_height = gui_get_base_height() |
| 2931 | + (GetSystemMetrics(SM_CYFRAME) + |
| 2932 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
| 2933 | + GetSystemMetrics(SM_CYCAPTION) |
| 2934 | #ifdef FEAT_MENU |
| 2935 | + gui_mswin_get_menu_height(FALSE) |
| 2936 | #endif |
| 2937 | ; |
| 2938 | *valid_w = base_width + |
| 2939 | ((w - base_width) / gui.char_width) * gui.char_width; |
| 2940 | *valid_h = base_height + |
| 2941 | ((h - base_height) / gui.char_height) * gui.char_height; |
| 2942 | } |
| 2943 | |
| 2944 | void |
| 2945 | gui_mch_flash(int msec) |
| 2946 | { |
| 2947 | RECT rc; |
| 2948 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 2949 | #if defined(FEAT_DIRECTX) |
| 2950 | if (IS_ENABLE_DIRECTX()) |
| 2951 | DWriteContext_Flush(s_dwc); |
| 2952 | #endif |
| 2953 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 2954 | /* |
| 2955 | * Note: InvertRect() excludes right and bottom of rectangle. |
| 2956 | */ |
| 2957 | rc.left = 0; |
| 2958 | rc.top = 0; |
| 2959 | rc.right = gui.num_cols * gui.char_width; |
| 2960 | rc.bottom = gui.num_rows * gui.char_height; |
| 2961 | InvertRect(s_hdc, &rc); |
| 2962 | gui_mch_flush(); /* make sure it's displayed */ |
| 2963 | |
| 2964 | ui_delay((long)msec, TRUE); /* wait for a few msec */ |
| 2965 | |
| 2966 | InvertRect(s_hdc, &rc); |
| 2967 | } |
| 2968 | |
| 2969 | /* |
| 2970 | * Return flags used for scrolling. |
| 2971 | * The SW_INVALIDATE is required when part of the window is covered or |
| 2972 | * off-screen. Refer to MS KB Q75236. |
| 2973 | */ |
| 2974 | static int |
| 2975 | get_scroll_flags(void) |
| 2976 | { |
| 2977 | HWND hwnd; |
| 2978 | RECT rcVim, rcOther, rcDest; |
| 2979 | |
| 2980 | GetWindowRect(s_hwnd, &rcVim); |
| 2981 | |
| 2982 | /* Check if the window is partly above or below the screen. We don't care |
| 2983 | * about partly left or right of the screen, it is not relevant when |
| 2984 | * scrolling up or down. */ |
| 2985 | if (rcVim.top < 0 || rcVim.bottom > GetSystemMetrics(SM_CYFULLSCREEN)) |
| 2986 | return SW_INVALIDATE; |
| 2987 | |
| 2988 | /* Check if there is an window (partly) on top of us. */ |
| 2989 | for (hwnd = s_hwnd; (hwnd = GetWindow(hwnd, GW_HWNDPREV)) != (HWND)0; ) |
| 2990 | if (IsWindowVisible(hwnd)) |
| 2991 | { |
| 2992 | GetWindowRect(hwnd, &rcOther); |
| 2993 | if (IntersectRect(&rcDest, &rcVim, &rcOther)) |
| 2994 | return SW_INVALIDATE; |
| 2995 | } |
| 2996 | return 0; |
| 2997 | } |
| 2998 | |
| 2999 | /* |
| 3000 | * On some Intel GPUs, the regions drawn just prior to ScrollWindowEx() |
| 3001 | * may not be scrolled out properly. |
| 3002 | * For gVim, when _OnScroll() is repeated, the character at the |
| 3003 | * previous cursor position may be left drawn after scroll. |
| 3004 | * The problem can be avoided by calling GetPixel() to get a pixel in |
| 3005 | * the region before ScrollWindowEx(). |
| 3006 | */ |
| 3007 | static void |
| 3008 | intel_gpu_workaround(void) |
| 3009 | { |
| 3010 | GetPixel(s_hdc, FILL_X(gui.col), FILL_Y(gui.row)); |
| 3011 | } |
| 3012 | |
| 3013 | /* |
| 3014 | * Delete the given number of lines from the given row, scrolling up any |
| 3015 | * text further down within the scroll region. |
| 3016 | */ |
| 3017 | void |
| 3018 | gui_mch_delete_lines( |
| 3019 | int row, |
| 3020 | int num_lines) |
| 3021 | { |
| 3022 | RECT rc; |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 3023 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3024 | rc.left = FILL_X(gui.scroll_region_left); |
| 3025 | rc.right = FILL_X(gui.scroll_region_right + 1); |
| 3026 | rc.top = FILL_Y(row); |
| 3027 | rc.bottom = FILL_Y(gui.scroll_region_bot + 1); |
| 3028 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3029 | #if defined(FEAT_DIRECTX) |
| 3030 | if (IS_ENABLE_DIRECTX()) |
| 3031 | { |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3032 | DWriteContext_Scroll(s_dwc, 0, -num_lines * gui.char_height, &rc); |
| 3033 | DWriteContext_Flush(s_dwc); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3034 | } |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3035 | else |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3036 | #endif |
| 3037 | { |
| 3038 | intel_gpu_workaround(); |
| 3039 | ScrollWindowEx(s_textArea, 0, -num_lines * gui.char_height, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3040 | &rc, &rc, NULL, NULL, get_scroll_flags()); |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 3041 | UpdateWindow(s_textArea); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3042 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3043 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3044 | /* This seems to be required to avoid the cursor disappearing when |
| 3045 | * scrolling such that the cursor ends up in the top-left character on |
| 3046 | * the screen... But why? (Webb) */ |
| 3047 | /* It's probably fixed by disabling drawing the cursor while scrolling. */ |
| 3048 | /* gui.cursor_is_valid = FALSE; */ |
| 3049 | |
| 3050 | gui_clear_block(gui.scroll_region_bot - num_lines + 1, |
| 3051 | gui.scroll_region_left, |
| 3052 | gui.scroll_region_bot, gui.scroll_region_right); |
| 3053 | } |
| 3054 | |
| 3055 | /* |
| 3056 | * Insert the given number of lines before the given row, scrolling down any |
| 3057 | * following text within the scroll region. |
| 3058 | */ |
| 3059 | void |
| 3060 | gui_mch_insert_lines( |
| 3061 | int row, |
| 3062 | int num_lines) |
| 3063 | { |
| 3064 | RECT rc; |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 3065 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3066 | rc.left = FILL_X(gui.scroll_region_left); |
| 3067 | rc.right = FILL_X(gui.scroll_region_right + 1); |
| 3068 | rc.top = FILL_Y(row); |
| 3069 | rc.bottom = FILL_Y(gui.scroll_region_bot + 1); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3070 | |
| 3071 | #if defined(FEAT_DIRECTX) |
| 3072 | if (IS_ENABLE_DIRECTX()) |
| 3073 | { |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3074 | DWriteContext_Scroll(s_dwc, 0, num_lines * gui.char_height, &rc); |
| 3075 | DWriteContext_Flush(s_dwc); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3076 | } |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3077 | else |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3078 | #endif |
| 3079 | { |
| 3080 | intel_gpu_workaround(); |
| 3081 | /* The SW_INVALIDATE is required when part of the window is covered or |
| 3082 | * off-screen. How do we avoid it when it's not needed? */ |
| 3083 | ScrollWindowEx(s_textArea, 0, num_lines * gui.char_height, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3084 | &rc, &rc, NULL, NULL, get_scroll_flags()); |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 3085 | UpdateWindow(s_textArea); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 3086 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3087 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3088 | gui_clear_block(row, gui.scroll_region_left, |
| 3089 | row + num_lines - 1, gui.scroll_region_right); |
| 3090 | } |
| 3091 | |
| 3092 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3093 | void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3094 | gui_mch_exit(int rc UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3095 | { |
| 3096 | #if defined(FEAT_DIRECTX) |
| 3097 | DWriteContext_Close(s_dwc); |
| 3098 | DWrite_Final(); |
| 3099 | s_dwc = NULL; |
| 3100 | #endif |
| 3101 | |
| 3102 | ReleaseDC(s_textArea, s_hdc); |
| 3103 | DeleteObject(s_brush); |
| 3104 | |
| 3105 | #ifdef FEAT_TEAROFF |
| 3106 | /* Unload the tearoff bitmap */ |
| 3107 | (void)DeleteObject((HGDIOBJ)s_htearbitmap); |
| 3108 | #endif |
| 3109 | |
| 3110 | /* Destroy our window (if we have one). */ |
| 3111 | if (s_hwnd != NULL) |
| 3112 | { |
| 3113 | destroying = TRUE; /* ignore WM_DESTROY message now */ |
| 3114 | DestroyWindow(s_hwnd); |
| 3115 | } |
| 3116 | |
| 3117 | #ifdef GLOBAL_IME |
| 3118 | global_ime_end(); |
| 3119 | #endif |
| 3120 | } |
| 3121 | |
| 3122 | static char_u * |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3123 | logfont2name(LOGFONTW lf) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3124 | { |
| 3125 | char *p; |
| 3126 | char *res; |
| 3127 | char *charset_name; |
Bram Moolenaar | 7c1c6db | 2016-04-03 22:08:05 +0200 | [diff] [blame] | 3128 | char *quality_name; |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3129 | char *font_name; |
Bram Moolenaar | f720d0a | 2019-04-28 14:02:47 +0200 | [diff] [blame] | 3130 | int points; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3131 | |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3132 | font_name = (char *)utf16_to_enc(lf.lfFaceName, NULL); |
| 3133 | if (font_name == NULL) |
| 3134 | return NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3135 | charset_name = charset_id2name((int)lf.lfCharSet); |
Bram Moolenaar | 7c1c6db | 2016-04-03 22:08:05 +0200 | [diff] [blame] | 3136 | quality_name = quality_id2name((int)lf.lfQuality); |
| 3137 | |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 3138 | res = alloc(strlen(font_name) + 30 |
Bram Moolenaar | 2155a6a | 2019-04-27 19:15:45 +0200 | [diff] [blame] | 3139 | + (charset_name == NULL ? 0 : strlen(charset_name) + 2) |
Bram Moolenaar | 964b374 | 2019-05-24 18:54:09 +0200 | [diff] [blame] | 3140 | + (quality_name == NULL ? 0 : strlen(quality_name) + 2)); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3141 | if (res != NULL) |
| 3142 | { |
| 3143 | p = res; |
Bram Moolenaar | f720d0a | 2019-04-28 14:02:47 +0200 | [diff] [blame] | 3144 | // make a normal font string out of the lf thing: |
| 3145 | points = pixels_to_points( |
| 3146 | lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE); |
| 3147 | if (lf.lfWeight == FW_NORMAL || lf.lfWeight == FW_BOLD) |
| 3148 | sprintf((char *)p, "%s:h%d", font_name, points); |
| 3149 | else |
Bram Moolenaar | a0e67fc | 2019-04-29 21:46:26 +0200 | [diff] [blame] | 3150 | sprintf((char *)p, "%s:h%d:W%ld", font_name, points, lf.lfWeight); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3151 | while (*p) |
| 3152 | { |
| 3153 | if (*p == ' ') |
| 3154 | *p = '_'; |
| 3155 | ++p; |
| 3156 | } |
| 3157 | if (lf.lfItalic) |
| 3158 | STRCAT(p, ":i"); |
Bram Moolenaar | f720d0a | 2019-04-28 14:02:47 +0200 | [diff] [blame] | 3159 | if (lf.lfWeight == FW_BOLD) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3160 | STRCAT(p, ":b"); |
| 3161 | if (lf.lfUnderline) |
| 3162 | STRCAT(p, ":u"); |
| 3163 | if (lf.lfStrikeOut) |
| 3164 | STRCAT(p, ":s"); |
| 3165 | if (charset_name != NULL) |
| 3166 | { |
| 3167 | STRCAT(p, ":c"); |
| 3168 | STRCAT(p, charset_name); |
| 3169 | } |
Bram Moolenaar | 7c1c6db | 2016-04-03 22:08:05 +0200 | [diff] [blame] | 3170 | if (quality_name != NULL) |
| 3171 | { |
| 3172 | STRCAT(p, ":q"); |
| 3173 | STRCAT(p, quality_name); |
| 3174 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3175 | } |
| 3176 | |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3177 | vim_free(font_name); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3178 | return (char_u *)res; |
| 3179 | } |
| 3180 | |
| 3181 | |
| 3182 | #ifdef FEAT_MBYTE_IME |
| 3183 | /* |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3184 | * Set correct LOGFONTW to IME. Use 'guifontwide' if available, otherwise use |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3185 | * 'guifont' |
| 3186 | */ |
| 3187 | static void |
| 3188 | update_im_font(void) |
| 3189 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3190 | LOGFONTW lf_wide; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3191 | |
| 3192 | if (p_guifontwide != NULL && *p_guifontwide != NUL |
| 3193 | && gui.wide_font != NOFONT |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3194 | && GetObjectW((HFONT)gui.wide_font, sizeof(lf_wide), &lf_wide)) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3195 | norm_logfont = lf_wide; |
| 3196 | else |
| 3197 | norm_logfont = sub_logfont; |
| 3198 | im_set_font(&norm_logfont); |
| 3199 | } |
| 3200 | #endif |
| 3201 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3202 | /* |
| 3203 | * Handler of gui.wide_font (p_guifontwide) changed notification. |
| 3204 | */ |
| 3205 | void |
| 3206 | gui_mch_wide_font_changed(void) |
| 3207 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3208 | LOGFONTW lf; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3209 | |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 3210 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3211 | update_im_font(); |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 3212 | #endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3213 | |
| 3214 | gui_mch_free_font(gui.wide_ital_font); |
| 3215 | gui.wide_ital_font = NOFONT; |
| 3216 | gui_mch_free_font(gui.wide_bold_font); |
| 3217 | gui.wide_bold_font = NOFONT; |
| 3218 | gui_mch_free_font(gui.wide_boldital_font); |
| 3219 | gui.wide_boldital_font = NOFONT; |
| 3220 | |
| 3221 | if (gui.wide_font |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3222 | && GetObjectW((HFONT)gui.wide_font, sizeof(lf), &lf)) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3223 | { |
| 3224 | if (!lf.lfItalic) |
| 3225 | { |
| 3226 | lf.lfItalic = TRUE; |
| 3227 | gui.wide_ital_font = get_font_handle(&lf); |
| 3228 | lf.lfItalic = FALSE; |
| 3229 | } |
| 3230 | if (lf.lfWeight < FW_BOLD) |
| 3231 | { |
| 3232 | lf.lfWeight = FW_BOLD; |
| 3233 | gui.wide_bold_font = get_font_handle(&lf); |
| 3234 | if (!lf.lfItalic) |
| 3235 | { |
| 3236 | lf.lfItalic = TRUE; |
| 3237 | gui.wide_boldital_font = get_font_handle(&lf); |
| 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3242 | |
| 3243 | /* |
| 3244 | * Initialise vim to use the font with the given name. |
| 3245 | * Return FAIL if the font could not be loaded, OK otherwise. |
| 3246 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3247 | int |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3248 | gui_mch_init_font(char_u *font_name, int fontset UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3249 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 3250 | LOGFONTW lf; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3251 | GuiFont font = NOFONT; |
| 3252 | char_u *p; |
| 3253 | |
| 3254 | /* Load the font */ |
| 3255 | if (get_logfont(&lf, font_name, NULL, TRUE) == OK) |
| 3256 | font = get_font_handle(&lf); |
| 3257 | if (font == NOFONT) |
| 3258 | return FAIL; |
| 3259 | |
| 3260 | if (font_name == NULL) |
| 3261 | font_name = (char_u *)lf.lfFaceName; |
| 3262 | #if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME) |
| 3263 | norm_logfont = lf; |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 3264 | #endif |
| 3265 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3266 | sub_logfont = lf; |
| 3267 | #endif |
| 3268 | #ifdef FEAT_MBYTE_IME |
| 3269 | update_im_font(); |
| 3270 | #endif |
| 3271 | gui_mch_free_font(gui.norm_font); |
| 3272 | gui.norm_font = font; |
| 3273 | current_font_height = lf.lfHeight; |
| 3274 | GetFontSize(font); |
| 3275 | |
| 3276 | p = logfont2name(lf); |
| 3277 | if (p != NULL) |
| 3278 | { |
| 3279 | hl_set_font_name(p); |
| 3280 | |
| 3281 | /* When setting 'guifont' to "*" replace it with the actual font name. |
| 3282 | * */ |
| 3283 | if (STRCMP(font_name, "*") == 0 && STRCMP(p_guifont, "*") == 0) |
| 3284 | { |
| 3285 | vim_free(p_guifont); |
| 3286 | p_guifont = p; |
| 3287 | } |
| 3288 | else |
| 3289 | vim_free(p); |
| 3290 | } |
| 3291 | |
| 3292 | gui_mch_free_font(gui.ital_font); |
| 3293 | gui.ital_font = NOFONT; |
| 3294 | gui_mch_free_font(gui.bold_font); |
| 3295 | gui.bold_font = NOFONT; |
| 3296 | gui_mch_free_font(gui.boldital_font); |
| 3297 | gui.boldital_font = NOFONT; |
| 3298 | |
| 3299 | if (!lf.lfItalic) |
| 3300 | { |
| 3301 | lf.lfItalic = TRUE; |
| 3302 | gui.ital_font = get_font_handle(&lf); |
| 3303 | lf.lfItalic = FALSE; |
| 3304 | } |
| 3305 | if (lf.lfWeight < FW_BOLD) |
| 3306 | { |
| 3307 | lf.lfWeight = FW_BOLD; |
| 3308 | gui.bold_font = get_font_handle(&lf); |
| 3309 | if (!lf.lfItalic) |
| 3310 | { |
| 3311 | lf.lfItalic = TRUE; |
| 3312 | gui.boldital_font = get_font_handle(&lf); |
| 3313 | } |
| 3314 | } |
| 3315 | |
| 3316 | return OK; |
| 3317 | } |
| 3318 | |
| 3319 | #ifndef WPF_RESTORETOMAXIMIZED |
| 3320 | # define WPF_RESTORETOMAXIMIZED 2 /* just in case someone doesn't have it */ |
| 3321 | #endif |
| 3322 | |
| 3323 | /* |
| 3324 | * Return TRUE if the GUI window is maximized, filling the whole screen. |
| 3325 | */ |
| 3326 | int |
| 3327 | gui_mch_maximized(void) |
| 3328 | { |
| 3329 | WINDOWPLACEMENT wp; |
| 3330 | |
| 3331 | wp.length = sizeof(WINDOWPLACEMENT); |
| 3332 | if (GetWindowPlacement(s_hwnd, &wp)) |
| 3333 | return wp.showCmd == SW_SHOWMAXIMIZED |
| 3334 | || (wp.showCmd == SW_SHOWMINIMIZED |
| 3335 | && wp.flags == WPF_RESTORETOMAXIMIZED); |
| 3336 | |
| 3337 | return 0; |
| 3338 | } |
| 3339 | |
| 3340 | /* |
Bram Moolenaar | 8ac4415 | 2017-11-09 18:33:29 +0100 | [diff] [blame] | 3341 | * Called when the font changed while the window is maximized or GO_KEEPWINSIZE |
| 3342 | * is set. Compute the new Rows and Columns. This is like resizing the |
| 3343 | * window. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3344 | */ |
| 3345 | void |
| 3346 | gui_mch_newfont(void) |
| 3347 | { |
| 3348 | RECT rect; |
| 3349 | |
| 3350 | GetWindowRect(s_hwnd, &rect); |
| 3351 | if (win_socket_id == 0) |
| 3352 | { |
| 3353 | gui_resize_shell(rect.right - rect.left |
| 3354 | - (GetSystemMetrics(SM_CXFRAME) + |
| 3355 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2, |
| 3356 | rect.bottom - rect.top |
| 3357 | - (GetSystemMetrics(SM_CYFRAME) + |
| 3358 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
| 3359 | - GetSystemMetrics(SM_CYCAPTION) |
| 3360 | #ifdef FEAT_MENU |
| 3361 | - gui_mswin_get_menu_height(FALSE) |
| 3362 | #endif |
| 3363 | ); |
| 3364 | } |
| 3365 | else |
| 3366 | { |
| 3367 | /* Inside another window, don't use the frame and border. */ |
| 3368 | gui_resize_shell(rect.right - rect.left, |
| 3369 | rect.bottom - rect.top |
| 3370 | #ifdef FEAT_MENU |
| 3371 | - gui_mswin_get_menu_height(FALSE) |
| 3372 | #endif |
| 3373 | ); |
| 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | /* |
| 3378 | * Set the window title |
| 3379 | */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3380 | void |
| 3381 | gui_mch_settitle( |
| 3382 | char_u *title, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3383 | char_u *icon UNUSED) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3384 | { |
| 3385 | set_window_title(s_hwnd, (title == NULL ? "VIM" : (char *)title)); |
| 3386 | } |
| 3387 | |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 3388 | #if defined(FEAT_MOUSESHAPE) || defined(PROTO) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3389 | /* Table for shape IDCs. Keep in sync with the mshape_names[] table in |
| 3390 | * misc2.c! */ |
| 3391 | static LPCSTR mshape_idcs[] = |
| 3392 | { |
| 3393 | IDC_ARROW, /* arrow */ |
| 3394 | MAKEINTRESOURCE(0), /* blank */ |
| 3395 | IDC_IBEAM, /* beam */ |
| 3396 | IDC_SIZENS, /* updown */ |
| 3397 | IDC_SIZENS, /* udsizing */ |
| 3398 | IDC_SIZEWE, /* leftright */ |
| 3399 | IDC_SIZEWE, /* lrsizing */ |
| 3400 | IDC_WAIT, /* busy */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3401 | IDC_NO, /* no */ |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3402 | IDC_ARROW, /* crosshair */ |
| 3403 | IDC_ARROW, /* hand1 */ |
| 3404 | IDC_ARROW, /* hand2 */ |
| 3405 | IDC_ARROW, /* pencil */ |
| 3406 | IDC_ARROW, /* question */ |
| 3407 | IDC_ARROW, /* right-arrow */ |
| 3408 | IDC_UPARROW, /* up-arrow */ |
| 3409 | IDC_ARROW /* last one */ |
| 3410 | }; |
| 3411 | |
| 3412 | void |
| 3413 | mch_set_mouse_shape(int shape) |
| 3414 | { |
| 3415 | LPCSTR idc; |
| 3416 | |
| 3417 | if (shape == MSHAPE_HIDE) |
| 3418 | ShowCursor(FALSE); |
| 3419 | else |
| 3420 | { |
| 3421 | if (shape >= MSHAPE_NUMBERED) |
| 3422 | idc = IDC_ARROW; |
| 3423 | else |
| 3424 | idc = mshape_idcs[shape]; |
| 3425 | #ifdef SetClassLongPtr |
| 3426 | SetClassLongPtr(s_textArea, GCLP_HCURSOR, (__int3264)(LONG_PTR)LoadCursor(NULL, idc)); |
| 3427 | #else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3428 | SetClassLong(s_textArea, GCL_HCURSOR, (long_u)LoadCursor(NULL, idc)); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3429 | #endif |
| 3430 | if (!p_mh) |
| 3431 | { |
| 3432 | POINT mp; |
| 3433 | |
| 3434 | /* Set the position to make it redrawn with the new shape. */ |
| 3435 | (void)GetCursorPos((LPPOINT)&mp); |
| 3436 | (void)SetCursorPos(mp.x, mp.y); |
| 3437 | ShowCursor(TRUE); |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 | #endif |
| 3442 | |
Bram Moolenaar | a6b7a08 | 2016-08-10 20:53:05 +0200 | [diff] [blame] | 3443 | #if defined(FEAT_BROWSE) || defined(PROTO) |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3444 | /* |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3445 | * Wide version of convert_filter(). |
| 3446 | */ |
| 3447 | static WCHAR * |
| 3448 | convert_filterW(char_u *s) |
| 3449 | { |
| 3450 | char_u *tmp; |
| 3451 | int len; |
| 3452 | WCHAR *res; |
| 3453 | |
| 3454 | tmp = convert_filter(s); |
| 3455 | if (tmp == NULL) |
| 3456 | return NULL; |
| 3457 | len = (int)STRLEN(s) + 3; |
| 3458 | res = enc_to_utf16(tmp, &len); |
| 3459 | vim_free(tmp); |
| 3460 | return res; |
| 3461 | } |
| 3462 | |
| 3463 | /* |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 3464 | * Pop open a file browser and return the file selected, in allocated memory, |
| 3465 | * or NULL if Cancel is hit. |
| 3466 | * saving - TRUE if the file will be saved to, FALSE if it will be opened. |
| 3467 | * title - Title message for the file browser dialog. |
| 3468 | * dflt - Default name of file. |
| 3469 | * ext - Default extension to be added to files without extensions. |
| 3470 | * initdir - directory in which to open the browser (NULL = current dir) |
| 3471 | * filter - Filter for matched files to choose from. |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3472 | */ |
Bram Moolenaar | 091806d | 2019-01-24 16:27:46 +0100 | [diff] [blame] | 3473 | char_u * |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 3474 | gui_mch_browse( |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3475 | int saving, |
| 3476 | char_u *title, |
| 3477 | char_u *dflt, |
| 3478 | char_u *ext, |
| 3479 | char_u *initdir, |
| 3480 | char_u *filter) |
| 3481 | { |
| 3482 | /* We always use the wide function. This means enc_to_utf16() must work, |
| 3483 | * otherwise it fails miserably! */ |
| 3484 | OPENFILENAMEW fileStruct; |
| 3485 | WCHAR fileBuf[MAXPATHL]; |
| 3486 | WCHAR *wp; |
| 3487 | int i; |
| 3488 | WCHAR *titlep = NULL; |
| 3489 | WCHAR *extp = NULL; |
| 3490 | WCHAR *initdirp = NULL; |
| 3491 | WCHAR *filterp; |
Bram Moolenaar | 7ff8a3c | 2018-09-22 14:39:15 +0200 | [diff] [blame] | 3492 | char_u *p, *q; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3493 | |
| 3494 | if (dflt == NULL) |
| 3495 | fileBuf[0] = NUL; |
| 3496 | else |
| 3497 | { |
| 3498 | wp = enc_to_utf16(dflt, NULL); |
| 3499 | if (wp == NULL) |
| 3500 | fileBuf[0] = NUL; |
| 3501 | else |
| 3502 | { |
| 3503 | for (i = 0; wp[i] != NUL && i < MAXPATHL - 1; ++i) |
| 3504 | fileBuf[i] = wp[i]; |
| 3505 | fileBuf[i] = NUL; |
| 3506 | vim_free(wp); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | /* Convert the filter to Windows format. */ |
| 3511 | filterp = convert_filterW(filter); |
| 3512 | |
| 3513 | vim_memset(&fileStruct, 0, sizeof(OPENFILENAMEW)); |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3514 | # ifdef OPENFILENAME_SIZE_VERSION_400W |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3515 | /* be compatible with Windows NT 4.0 */ |
Bram Moolenaar | 89e375a | 2016-03-15 18:09:57 +0100 | [diff] [blame] | 3516 | fileStruct.lStructSize = OPENFILENAME_SIZE_VERSION_400W; |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3517 | # else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3518 | fileStruct.lStructSize = sizeof(fileStruct); |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3519 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3520 | |
| 3521 | if (title != NULL) |
| 3522 | titlep = enc_to_utf16(title, NULL); |
| 3523 | fileStruct.lpstrTitle = titlep; |
| 3524 | |
| 3525 | if (ext != NULL) |
| 3526 | extp = enc_to_utf16(ext, NULL); |
| 3527 | fileStruct.lpstrDefExt = extp; |
| 3528 | |
| 3529 | fileStruct.lpstrFile = fileBuf; |
| 3530 | fileStruct.nMaxFile = MAXPATHL; |
| 3531 | fileStruct.lpstrFilter = filterp; |
| 3532 | fileStruct.hwndOwner = s_hwnd; /* main Vim window is owner*/ |
| 3533 | /* has an initial dir been specified? */ |
| 3534 | if (initdir != NULL && *initdir != NUL) |
| 3535 | { |
| 3536 | /* Must have backslashes here, no matter what 'shellslash' says */ |
| 3537 | initdirp = enc_to_utf16(initdir, NULL); |
| 3538 | if (initdirp != NULL) |
| 3539 | { |
| 3540 | for (wp = initdirp; *wp != NUL; ++wp) |
| 3541 | if (*wp == '/') |
| 3542 | *wp = '\\'; |
| 3543 | } |
| 3544 | fileStruct.lpstrInitialDir = initdirp; |
| 3545 | } |
| 3546 | |
| 3547 | /* |
| 3548 | * TODO: Allow selection of multiple files. Needs another arg to this |
| 3549 | * function to ask for it, and need to use OFN_ALLOWMULTISELECT below. |
| 3550 | * Also, should we use OFN_FILEMUSTEXIST when opening? Vim can edit on |
| 3551 | * files that don't exist yet, so I haven't put it in. What about |
| 3552 | * OFN_PATHMUSTEXIST? |
| 3553 | * Don't use OFN_OVERWRITEPROMPT, Vim has its own ":confirm" dialog. |
| 3554 | */ |
| 3555 | fileStruct.Flags = (OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY); |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3556 | # ifdef FEAT_SHORTCUT |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3557 | if (curbuf->b_p_bin) |
| 3558 | fileStruct.Flags |= OFN_NODEREFERENCELINKS; |
Bram Moolenaar | b04a98f | 2016-12-01 20:32:29 +0100 | [diff] [blame] | 3559 | # endif |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3560 | if (saving) |
| 3561 | { |
| 3562 | if (!GetSaveFileNameW(&fileStruct)) |
| 3563 | return NULL; |
| 3564 | } |
| 3565 | else |
| 3566 | { |
| 3567 | if (!GetOpenFileNameW(&fileStruct)) |
| 3568 | return NULL; |
| 3569 | } |
| 3570 | |
| 3571 | vim_free(filterp); |
| 3572 | vim_free(initdirp); |
| 3573 | vim_free(titlep); |
| 3574 | vim_free(extp); |
| 3575 | |
| 3576 | /* Convert from UCS2 to 'encoding'. */ |
| 3577 | p = utf16_to_enc(fileBuf, NULL); |
Bram Moolenaar | 7ff8a3c | 2018-09-22 14:39:15 +0200 | [diff] [blame] | 3578 | if (p == NULL) |
| 3579 | return NULL; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3580 | |
| 3581 | /* Give focus back to main window (when using MDI). */ |
| 3582 | SetFocus(s_hwnd); |
| 3583 | |
| 3584 | /* Shorten the file name if possible */ |
Bram Moolenaar | 7ff8a3c | 2018-09-22 14:39:15 +0200 | [diff] [blame] | 3585 | q = vim_strsave(shorten_fname1(p)); |
| 3586 | vim_free(p); |
| 3587 | return q; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3588 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3589 | |
| 3590 | |
| 3591 | /* |
| 3592 | * Convert the string s to the proper format for a filter string by replacing |
| 3593 | * the \t and \n delimiters with \0. |
| 3594 | * Returns the converted string in allocated memory. |
| 3595 | * |
| 3596 | * Keep in sync with convert_filterW() above! |
| 3597 | */ |
| 3598 | static char_u * |
| 3599 | convert_filter(char_u *s) |
| 3600 | { |
| 3601 | char_u *res; |
| 3602 | unsigned s_len = (unsigned)STRLEN(s); |
| 3603 | unsigned i; |
| 3604 | |
| 3605 | res = alloc(s_len + 3); |
| 3606 | if (res != NULL) |
| 3607 | { |
| 3608 | for (i = 0; i < s_len; ++i) |
| 3609 | if (s[i] == '\t' || s[i] == '\n') |
| 3610 | res[i] = '\0'; |
| 3611 | else |
| 3612 | res[i] = s[i]; |
| 3613 | res[s_len] = NUL; |
| 3614 | /* Add two extra NULs to make sure it's properly terminated. */ |
| 3615 | res[s_len + 1] = NUL; |
| 3616 | res[s_len + 2] = NUL; |
| 3617 | } |
| 3618 | return res; |
| 3619 | } |
| 3620 | |
| 3621 | /* |
| 3622 | * Select a directory. |
| 3623 | */ |
| 3624 | char_u * |
| 3625 | gui_mch_browsedir(char_u *title, char_u *initdir) |
| 3626 | { |
| 3627 | /* We fake this: Use a filter that doesn't select anything and a default |
| 3628 | * file name that won't be used. */ |
| 3629 | return gui_mch_browse(0, title, (char_u *)_("Not Used"), NULL, |
| 3630 | initdir, (char_u *)_("Directory\t*.nothing\n")); |
| 3631 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3632 | #endif /* FEAT_BROWSE */ |
| 3633 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3634 | static void |
| 3635 | _OnDropFiles( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3636 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3637 | HDROP hDrop) |
| 3638 | { |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 3639 | #define BUFPATHLEN _MAX_PATH |
| 3640 | #define DRAGQVAL 0xFFFFFFFF |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3641 | WCHAR wszFile[BUFPATHLEN]; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3642 | char szFile[BUFPATHLEN]; |
| 3643 | UINT cFiles = DragQueryFile(hDrop, DRAGQVAL, NULL, 0); |
| 3644 | UINT i; |
| 3645 | char_u **fnames; |
| 3646 | POINT pt; |
| 3647 | int_u modifiers = 0; |
| 3648 | |
| 3649 | /* TRACE("_OnDropFiles: %d files dropped\n", cFiles); */ |
| 3650 | |
| 3651 | /* Obtain dropped position */ |
| 3652 | DragQueryPoint(hDrop, &pt); |
| 3653 | MapWindowPoints(s_hwnd, s_textArea, &pt, 1); |
| 3654 | |
| 3655 | reset_VIsual(); |
| 3656 | |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 3657 | fnames = ALLOC_MULT(char_u *, cFiles); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3658 | |
| 3659 | if (fnames != NULL) |
| 3660 | for (i = 0; i < cFiles; ++i) |
| 3661 | { |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3662 | if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0) |
| 3663 | fnames[i] = utf16_to_enc(wszFile, NULL); |
| 3664 | else |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3665 | { |
| 3666 | DragQueryFile(hDrop, i, szFile, BUFPATHLEN); |
| 3667 | fnames[i] = vim_strsave((char_u *)szFile); |
| 3668 | } |
| 3669 | } |
| 3670 | |
| 3671 | DragFinish(hDrop); |
| 3672 | |
| 3673 | if (fnames != NULL) |
| 3674 | { |
| 3675 | if ((GetKeyState(VK_SHIFT) & 0x8000) != 0) |
| 3676 | modifiers |= MOUSE_SHIFT; |
| 3677 | if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) |
| 3678 | modifiers |= MOUSE_CTRL; |
| 3679 | if ((GetKeyState(VK_MENU) & 0x8000) != 0) |
| 3680 | modifiers |= MOUSE_ALT; |
| 3681 | |
| 3682 | gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles); |
| 3683 | |
| 3684 | s_need_activate = TRUE; |
| 3685 | } |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3686 | } |
| 3687 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3688 | static int |
| 3689 | _OnScroll( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 3690 | HWND hwnd UNUSED, |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3691 | HWND hwndCtl, |
| 3692 | UINT code, |
| 3693 | int pos) |
| 3694 | { |
| 3695 | static UINT prev_code = 0; /* code of previous call */ |
| 3696 | scrollbar_T *sb, *sb_info; |
| 3697 | long val; |
| 3698 | int dragging = FALSE; |
| 3699 | int dont_scroll_save = dont_scroll; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3700 | SCROLLINFO si; |
| 3701 | |
| 3702 | si.cbSize = sizeof(si); |
| 3703 | si.fMask = SIF_POS; |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3704 | |
| 3705 | sb = gui_mswin_find_scrollbar(hwndCtl); |
| 3706 | if (sb == NULL) |
| 3707 | return 0; |
| 3708 | |
| 3709 | if (sb->wp != NULL) /* Left or right scrollbar */ |
| 3710 | { |
| 3711 | /* |
| 3712 | * Careful: need to get scrollbar info out of first (left) scrollbar |
| 3713 | * for window, but keep real scrollbar too because we must pass it to |
| 3714 | * gui_drag_scrollbar(). |
| 3715 | */ |
| 3716 | sb_info = &sb->wp->w_scrollbars[0]; |
| 3717 | } |
| 3718 | else /* Bottom scrollbar */ |
| 3719 | sb_info = sb; |
| 3720 | val = sb_info->value; |
| 3721 | |
| 3722 | switch (code) |
| 3723 | { |
| 3724 | case SB_THUMBTRACK: |
| 3725 | val = pos; |
| 3726 | dragging = TRUE; |
| 3727 | if (sb->scroll_shift > 0) |
| 3728 | val <<= sb->scroll_shift; |
| 3729 | break; |
| 3730 | case SB_LINEDOWN: |
| 3731 | val++; |
| 3732 | break; |
| 3733 | case SB_LINEUP: |
| 3734 | val--; |
| 3735 | break; |
| 3736 | case SB_PAGEDOWN: |
| 3737 | val += (sb_info->size > 2 ? sb_info->size - 2 : 1); |
| 3738 | break; |
| 3739 | case SB_PAGEUP: |
| 3740 | val -= (sb_info->size > 2 ? sb_info->size - 2 : 1); |
| 3741 | break; |
| 3742 | case SB_TOP: |
| 3743 | val = 0; |
| 3744 | break; |
| 3745 | case SB_BOTTOM: |
| 3746 | val = sb_info->max; |
| 3747 | break; |
| 3748 | case SB_ENDSCROLL: |
| 3749 | if (prev_code == SB_THUMBTRACK) |
| 3750 | { |
| 3751 | /* |
| 3752 | * "pos" only gives us 16-bit data. In case of large file, |
| 3753 | * use GetScrollPos() which returns 32-bit. Unfortunately it |
| 3754 | * is not valid while the scrollbar is being dragged. |
| 3755 | */ |
| 3756 | val = GetScrollPos(hwndCtl, SB_CTL); |
| 3757 | if (sb->scroll_shift > 0) |
| 3758 | val <<= sb->scroll_shift; |
| 3759 | } |
| 3760 | break; |
| 3761 | |
| 3762 | default: |
| 3763 | /* TRACE("Unknown scrollbar event %d\n", code); */ |
| 3764 | return 0; |
| 3765 | } |
| 3766 | prev_code = code; |
| 3767 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3768 | si.nPos = (sb->scroll_shift > 0) ? val >> sb->scroll_shift : val; |
| 3769 | SetScrollInfo(hwndCtl, SB_CTL, &si, TRUE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3770 | |
| 3771 | /* |
| 3772 | * When moving a vertical scrollbar, move the other vertical scrollbar too. |
| 3773 | */ |
| 3774 | if (sb->wp != NULL) |
| 3775 | { |
| 3776 | scrollbar_T *sba = sb->wp->w_scrollbars; |
| 3777 | HWND id = sba[ (sb == sba + SBAR_LEFT) ? SBAR_RIGHT : SBAR_LEFT].id; |
| 3778 | |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3779 | SetScrollInfo(id, SB_CTL, &si, TRUE); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3780 | } |
| 3781 | |
| 3782 | /* Don't let us be interrupted here by another message. */ |
| 3783 | s_busy_processing = TRUE; |
| 3784 | |
| 3785 | /* When "allow_scrollbar" is FALSE still need to remember the new |
| 3786 | * position, but don't actually scroll by setting "dont_scroll". */ |
| 3787 | dont_scroll = !allow_scrollbar; |
| 3788 | |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3789 | mch_disable_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3790 | gui_drag_scrollbar(sb, val, dragging); |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 3791 | mch_enable_flush(); |
| 3792 | gui_may_flush(); |
Bram Moolenaar | cf7164a | 2016-02-20 13:55:06 +0100 | [diff] [blame] | 3793 | |
| 3794 | s_busy_processing = FALSE; |
| 3795 | dont_scroll = dont_scroll_save; |
| 3796 | |
| 3797 | return 0; |
| 3798 | } |
| 3799 | |
| 3800 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3801 | #ifdef FEAT_XPM_W32 |
| 3802 | # include "xpm_w32.h" |
| 3803 | #endif |
| 3804 | |
| 3805 | #ifdef PROTO |
| 3806 | # define WINAPI |
| 3807 | #endif |
| 3808 | |
| 3809 | #ifdef __MINGW32__ |
| 3810 | /* |
| 3811 | * Add a lot of missing defines. |
| 3812 | * They are not always missing, we need the #ifndef's. |
| 3813 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3814 | # ifndef IsMinimized |
| 3815 | # define IsMinimized(hwnd) IsIconic(hwnd) |
| 3816 | # endif |
| 3817 | # ifndef IsMaximized |
| 3818 | # define IsMaximized(hwnd) IsZoomed(hwnd) |
| 3819 | # endif |
| 3820 | # ifndef SelectFont |
| 3821 | # define SelectFont(hdc, hfont) ((HFONT)SelectObject((hdc), (HGDIOBJ)(HFONT)(hfont))) |
| 3822 | # endif |
| 3823 | # ifndef GetStockBrush |
| 3824 | # define GetStockBrush(i) ((HBRUSH)GetStockObject(i)) |
| 3825 | # endif |
| 3826 | # ifndef DeleteBrush |
| 3827 | # define DeleteBrush(hbr) DeleteObject((HGDIOBJ)(HBRUSH)(hbr)) |
| 3828 | # endif |
| 3829 | |
| 3830 | # ifndef HANDLE_WM_RBUTTONDBLCLK |
| 3831 | # define HANDLE_WM_RBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 3832 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3833 | # endif |
| 3834 | # ifndef HANDLE_WM_MBUTTONUP |
| 3835 | # define HANDLE_WM_MBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 3836 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3837 | # endif |
| 3838 | # ifndef HANDLE_WM_MBUTTONDBLCLK |
| 3839 | # define HANDLE_WM_MBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 3840 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3841 | # endif |
| 3842 | # ifndef HANDLE_WM_LBUTTONDBLCLK |
| 3843 | # define HANDLE_WM_LBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 3844 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3845 | # endif |
| 3846 | # ifndef HANDLE_WM_RBUTTONDOWN |
| 3847 | # define HANDLE_WM_RBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 3848 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3849 | # endif |
| 3850 | # ifndef HANDLE_WM_MOUSEMOVE |
| 3851 | # define HANDLE_WM_MOUSEMOVE(hwnd, wParam, lParam, fn) \ |
| 3852 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3853 | # endif |
| 3854 | # ifndef HANDLE_WM_RBUTTONUP |
| 3855 | # define HANDLE_WM_RBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 3856 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3857 | # endif |
| 3858 | # ifndef HANDLE_WM_MBUTTONDOWN |
| 3859 | # define HANDLE_WM_MBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 3860 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3861 | # endif |
| 3862 | # ifndef HANDLE_WM_LBUTTONUP |
| 3863 | # define HANDLE_WM_LBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 3864 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3865 | # endif |
| 3866 | # ifndef HANDLE_WM_LBUTTONDOWN |
| 3867 | # define HANDLE_WM_LBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 3868 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 3869 | # endif |
| 3870 | # ifndef HANDLE_WM_SYSCHAR |
| 3871 | # define HANDLE_WM_SYSCHAR(hwnd, wParam, lParam, fn) \ |
| 3872 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 3873 | # endif |
| 3874 | # ifndef HANDLE_WM_ACTIVATEAPP |
| 3875 | # define HANDLE_WM_ACTIVATEAPP(hwnd, wParam, lParam, fn) \ |
| 3876 | ((fn)((hwnd), (BOOL)(wParam), (DWORD)(lParam)), 0L) |
| 3877 | # endif |
| 3878 | # ifndef HANDLE_WM_WINDOWPOSCHANGING |
| 3879 | # define HANDLE_WM_WINDOWPOSCHANGING(hwnd, wParam, lParam, fn) \ |
| 3880 | (LRESULT)(DWORD)(BOOL)(fn)((hwnd), (LPWINDOWPOS)(lParam)) |
| 3881 | # endif |
| 3882 | # ifndef HANDLE_WM_VSCROLL |
| 3883 | # define HANDLE_WM_VSCROLL(hwnd, wParam, lParam, fn) \ |
| 3884 | ((fn)((hwnd), (HWND)(lParam), (UINT)(LOWORD(wParam)), (int)(short)HIWORD(wParam)), 0L) |
| 3885 | # endif |
| 3886 | # ifndef HANDLE_WM_SETFOCUS |
| 3887 | # define HANDLE_WM_SETFOCUS(hwnd, wParam, lParam, fn) \ |
| 3888 | ((fn)((hwnd), (HWND)(wParam)), 0L) |
| 3889 | # endif |
| 3890 | # ifndef HANDLE_WM_KILLFOCUS |
| 3891 | # define HANDLE_WM_KILLFOCUS(hwnd, wParam, lParam, fn) \ |
| 3892 | ((fn)((hwnd), (HWND)(wParam)), 0L) |
| 3893 | # endif |
| 3894 | # ifndef HANDLE_WM_HSCROLL |
| 3895 | # define HANDLE_WM_HSCROLL(hwnd, wParam, lParam, fn) \ |
| 3896 | ((fn)((hwnd), (HWND)(lParam), (UINT)(LOWORD(wParam)), (int)(short)HIWORD(wParam)), 0L) |
| 3897 | # endif |
| 3898 | # ifndef HANDLE_WM_DROPFILES |
| 3899 | # define HANDLE_WM_DROPFILES(hwnd, wParam, lParam, fn) \ |
| 3900 | ((fn)((hwnd), (HDROP)(wParam)), 0L) |
| 3901 | # endif |
| 3902 | # ifndef HANDLE_WM_CHAR |
| 3903 | # define HANDLE_WM_CHAR(hwnd, wParam, lParam, fn) \ |
| 3904 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 3905 | # endif |
| 3906 | # ifndef HANDLE_WM_SYSDEADCHAR |
| 3907 | # define HANDLE_WM_SYSDEADCHAR(hwnd, wParam, lParam, fn) \ |
| 3908 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 3909 | # endif |
| 3910 | # ifndef HANDLE_WM_DEADCHAR |
| 3911 | # define HANDLE_WM_DEADCHAR(hwnd, wParam, lParam, fn) \ |
| 3912 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 3913 | # endif |
| 3914 | #endif /* __MINGW32__ */ |
| 3915 | |
| 3916 | |
| 3917 | /* Some parameters for tearoff menus. All in pixels. */ |
| 3918 | #define TEAROFF_PADDING_X 2 |
| 3919 | #define TEAROFF_BUTTON_PAD_X 8 |
| 3920 | #define TEAROFF_MIN_WIDTH 200 |
| 3921 | #define TEAROFF_SUBMENU_LABEL ">>" |
| 3922 | #define TEAROFF_COLUMN_PADDING 3 // # spaces to pad column with. |
| 3923 | |
| 3924 | |
| 3925 | /* For the Intellimouse: */ |
| 3926 | #ifndef WM_MOUSEWHEEL |
| 3927 | #define WM_MOUSEWHEEL 0x20a |
| 3928 | #endif |
| 3929 | |
| 3930 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 3931 | #ifdef FEAT_BEVAL_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3932 | # define ID_BEVAL_TOOLTIP 200 |
| 3933 | # define BEVAL_TEXT_LEN MAXPATHL |
| 3934 | |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 3935 | #if (defined(_MSC_VER) && _MSC_VER < 1300) || !defined(MAXULONG_PTR) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3936 | /* Work around old versions of basetsd.h which wrongly declares |
| 3937 | * UINT_PTR as unsigned long. */ |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 3938 | # undef UINT_PTR |
Bram Moolenaar | 8424a62 | 2006-04-19 21:23:36 +0000 | [diff] [blame] | 3939 | # define UINT_PTR UINT |
| 3940 | #endif |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3941 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3942 | static BalloonEval *cur_beval = NULL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3943 | static UINT_PTR BevalTimerId = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3944 | static DWORD LastActivity = 0; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3945 | |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 3946 | |
| 3947 | /* cproto fails on missing include files */ |
| 3948 | #ifndef PROTO |
| 3949 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3950 | /* |
| 3951 | * excerpts from headers since this may not be presented |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 3952 | * in the extremely old compilers |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3953 | */ |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 3954 | # include <pshpack1.h> |
| 3955 | |
| 3956 | #endif |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3957 | |
| 3958 | typedef struct _DllVersionInfo |
| 3959 | { |
| 3960 | DWORD cbSize; |
| 3961 | DWORD dwMajorVersion; |
| 3962 | DWORD dwMinorVersion; |
| 3963 | DWORD dwBuildNumber; |
| 3964 | DWORD dwPlatformID; |
| 3965 | } DLLVERSIONINFO; |
| 3966 | |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 3967 | #ifndef PROTO |
| 3968 | # include <poppack.h> |
| 3969 | #endif |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 3970 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3971 | typedef struct tagTOOLINFOA_NEW |
| 3972 | { |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 3973 | UINT cbSize; |
| 3974 | UINT uFlags; |
| 3975 | HWND hwnd; |
| 3976 | UINT_PTR uId; |
| 3977 | RECT rect; |
| 3978 | HINSTANCE hinst; |
| 3979 | LPSTR lpszText; |
| 3980 | LPARAM lParam; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3981 | } TOOLINFO_NEW; |
| 3982 | |
| 3983 | typedef struct tagNMTTDISPINFO_NEW |
| 3984 | { |
| 3985 | NMHDR hdr; |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 3986 | LPSTR lpszText; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 3987 | char szText[80]; |
| 3988 | HINSTANCE hinst; |
| 3989 | UINT uFlags; |
| 3990 | LPARAM lParam; |
| 3991 | } NMTTDISPINFO_NEW; |
| 3992 | |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 3993 | typedef struct tagTOOLINFOW_NEW |
| 3994 | { |
| 3995 | UINT cbSize; |
| 3996 | UINT uFlags; |
| 3997 | HWND hwnd; |
| 3998 | UINT_PTR uId; |
| 3999 | RECT rect; |
| 4000 | HINSTANCE hinst; |
| 4001 | LPWSTR lpszText; |
| 4002 | LPARAM lParam; |
| 4003 | void *lpReserved; |
| 4004 | } TOOLINFOW_NEW; |
| 4005 | |
| 4006 | typedef struct tagNMTTDISPINFOW_NEW |
| 4007 | { |
| 4008 | NMHDR hdr; |
| 4009 | LPWSTR lpszText; |
| 4010 | WCHAR szText[80]; |
| 4011 | HINSTANCE hinst; |
| 4012 | UINT uFlags; |
| 4013 | LPARAM lParam; |
| 4014 | } NMTTDISPINFOW_NEW; |
| 4015 | |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 4016 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4017 | typedef HRESULT (WINAPI* DLLGETVERSIONPROC)(DLLVERSIONINFO *); |
| 4018 | #ifndef TTM_SETMAXTIPWIDTH |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4019 | # define TTM_SETMAXTIPWIDTH (WM_USER+24) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4020 | #endif |
| 4021 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4022 | #ifndef TTF_DI_SETITEM |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4023 | # define TTF_DI_SETITEM 0x8000 |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4024 | #endif |
| 4025 | |
| 4026 | #ifndef TTN_GETDISPINFO |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4027 | # define TTN_GETDISPINFO (TTN_FIRST - 0) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4028 | #endif |
| 4029 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 4030 | #endif /* defined(FEAT_BEVAL_GUI) */ |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4031 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 4032 | #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
| 4033 | /* Older MSVC compilers don't have LPNMTTDISPINFO[AW] thus we need to define |
| 4034 | * it here if LPNMTTDISPINFO isn't defined. |
| 4035 | * MingW doesn't define LPNMTTDISPINFO but typedefs it. Thus we need to check |
| 4036 | * _MSC_VER. */ |
| 4037 | # if !defined(LPNMTTDISPINFO) && defined(_MSC_VER) |
| 4038 | typedef struct tagNMTTDISPINFOA { |
| 4039 | NMHDR hdr; |
| 4040 | LPSTR lpszText; |
| 4041 | char szText[80]; |
| 4042 | HINSTANCE hinst; |
| 4043 | UINT uFlags; |
| 4044 | LPARAM lParam; |
| 4045 | } NMTTDISPINFOA, *LPNMTTDISPINFOA; |
| 4046 | # define LPNMTTDISPINFO LPNMTTDISPINFOA |
| 4047 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 4048 | typedef struct tagNMTTDISPINFOW { |
| 4049 | NMHDR hdr; |
| 4050 | LPWSTR lpszText; |
| 4051 | WCHAR szText[80]; |
| 4052 | HINSTANCE hinst; |
| 4053 | UINT uFlags; |
| 4054 | LPARAM lParam; |
| 4055 | } NMTTDISPINFOW, *LPNMTTDISPINFOW; |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 4056 | # endif |
| 4057 | #endif |
| 4058 | |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 4059 | #ifndef TTN_GETDISPINFOW |
| 4060 | # define TTN_GETDISPINFOW (TTN_FIRST - 10) |
| 4061 | #endif |
| 4062 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4063 | /* Local variables: */ |
| 4064 | |
| 4065 | #ifdef FEAT_MENU |
| 4066 | static UINT s_menu_id = 100; |
Bram Moolenaar | 786989b | 2010-10-27 12:15:33 +0200 | [diff] [blame] | 4067 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4068 | |
| 4069 | /* |
| 4070 | * Use the system font for dialogs and tear-off menus. Remove this line to |
| 4071 | * use DLG_FONT_NAME. |
| 4072 | */ |
Bram Moolenaar | 786989b | 2010-10-27 12:15:33 +0200 | [diff] [blame] | 4073 | #define USE_SYSMENU_FONT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4074 | |
| 4075 | #define VIM_NAME "vim" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4076 | #define VIM_CLASSW L"Vim" |
| 4077 | |
| 4078 | /* Initial size for the dialog template. For gui_mch_dialog() it's fixed, |
| 4079 | * thus there should be room for every dialog. For tearoffs it's made bigger |
| 4080 | * when needed. */ |
| 4081 | #define DLG_ALLOC_SIZE 16 * 1024 |
| 4082 | |
| 4083 | /* |
| 4084 | * stuff for dialogs, menus, tearoffs etc. |
| 4085 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4086 | static PWORD |
| 4087 | add_dialog_element( |
| 4088 | PWORD p, |
| 4089 | DWORD lStyle, |
| 4090 | WORD x, |
| 4091 | WORD y, |
| 4092 | WORD w, |
| 4093 | WORD h, |
| 4094 | WORD Id, |
| 4095 | WORD clss, |
| 4096 | const char *caption); |
| 4097 | static LPWORD lpwAlign(LPWORD); |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 4098 | static int nCopyAnsiToWideChar(LPWORD, LPSTR, BOOL); |
Bram Moolenaar | 065bbac | 2016-02-20 13:08:46 +0100 | [diff] [blame] | 4099 | #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4100 | 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] | 4101 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4102 | static void get_dialog_font_metrics(void); |
| 4103 | |
| 4104 | static int dialog_default_button = -1; |
| 4105 | |
| 4106 | /* Intellimouse support */ |
| 4107 | static int mouse_scroll_lines = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4108 | |
| 4109 | static int s_usenewlook; /* emulate W95/NT4 non-bold dialogs */ |
| 4110 | #ifdef FEAT_TOOLBAR |
| 4111 | static void initialise_toolbar(void); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4112 | 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] | 4113 | static int get_toolbar_bitmap(vimmenu_T *menu); |
| 4114 | #endif |
| 4115 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4116 | #ifdef FEAT_GUI_TABLINE |
| 4117 | static void initialise_tabline(void); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4118 | 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] | 4119 | #endif |
| 4120 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4121 | #ifdef FEAT_MBYTE_IME |
| 4122 | static LRESULT _OnImeComposition(HWND hwnd, WPARAM dbcs, LPARAM param); |
| 4123 | static char_u *GetResultStr(HWND hwnd, int GCS, int *lenp); |
| 4124 | #endif |
| 4125 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 4126 | # ifdef NOIME |
| 4127 | typedef struct tagCOMPOSITIONFORM { |
| 4128 | DWORD dwStyle; |
| 4129 | POINT ptCurrentPos; |
| 4130 | RECT rcArea; |
| 4131 | } COMPOSITIONFORM, *PCOMPOSITIONFORM, NEAR *NPCOMPOSITIONFORM, FAR *LPCOMPOSITIONFORM; |
| 4132 | typedef HANDLE HIMC; |
| 4133 | # endif |
| 4134 | |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 4135 | static HINSTANCE hLibImm = NULL; |
| 4136 | static LONG (WINAPI *pImmGetCompositionStringA)(HIMC, DWORD, LPVOID, DWORD); |
| 4137 | static LONG (WINAPI *pImmGetCompositionStringW)(HIMC, DWORD, LPVOID, DWORD); |
| 4138 | static HIMC (WINAPI *pImmGetContext)(HWND); |
| 4139 | static HIMC (WINAPI *pImmAssociateContext)(HWND, HIMC); |
| 4140 | static BOOL (WINAPI *pImmReleaseContext)(HWND, HIMC); |
| 4141 | static BOOL (WINAPI *pImmGetOpenStatus)(HIMC); |
| 4142 | static BOOL (WINAPI *pImmSetOpenStatus)(HIMC, BOOL); |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4143 | static BOOL (WINAPI *pImmGetCompositionFontW)(HIMC, LPLOGFONTW); |
| 4144 | static BOOL (WINAPI *pImmSetCompositionFontW)(HIMC, LPLOGFONTW); |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 4145 | static BOOL (WINAPI *pImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM); |
| 4146 | static BOOL (WINAPI *pImmGetConversionStatus)(HIMC, LPDWORD, LPDWORD); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4147 | static BOOL (WINAPI *pImmSetConversionStatus)(HIMC, DWORD, DWORD); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4148 | static void dyn_imm_load(void); |
| 4149 | #else |
| 4150 | # define pImmGetCompositionStringA ImmGetCompositionStringA |
| 4151 | # define pImmGetCompositionStringW ImmGetCompositionStringW |
| 4152 | # define pImmGetContext ImmGetContext |
| 4153 | # define pImmAssociateContext ImmAssociateContext |
| 4154 | # define pImmReleaseContext ImmReleaseContext |
| 4155 | # define pImmGetOpenStatus ImmGetOpenStatus |
| 4156 | # define pImmSetOpenStatus ImmSetOpenStatus |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4157 | # define pImmGetCompositionFontW ImmGetCompositionFontW |
| 4158 | # define pImmSetCompositionFontW ImmSetCompositionFontW |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4159 | # define pImmSetCompositionWindow ImmSetCompositionWindow |
| 4160 | # define pImmGetConversionStatus ImmGetConversionStatus |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4161 | # define pImmSetConversionStatus ImmSetConversionStatus |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4162 | #endif |
| 4163 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4164 | #ifdef FEAT_MENU |
| 4165 | /* |
| 4166 | * Figure out how high the menu bar is at the moment. |
| 4167 | */ |
| 4168 | static int |
| 4169 | gui_mswin_get_menu_height( |
| 4170 | int fix_window) /* If TRUE, resize window if menu height changed */ |
| 4171 | { |
| 4172 | static int old_menu_height = -1; |
| 4173 | |
| 4174 | RECT rc1, rc2; |
| 4175 | int num; |
| 4176 | int menu_height; |
| 4177 | |
| 4178 | if (gui.menu_is_active) |
| 4179 | num = GetMenuItemCount(s_menuBar); |
| 4180 | else |
| 4181 | num = 0; |
| 4182 | |
| 4183 | if (num == 0) |
| 4184 | menu_height = 0; |
Bram Moolenaar | 71371b1 | 2015-03-24 17:57:12 +0100 | [diff] [blame] | 4185 | else if (IsMinimized(s_hwnd)) |
| 4186 | { |
| 4187 | /* The height of the menu cannot be determined while the window is |
| 4188 | * minimized. Take the previous height if the menu is changed in that |
| 4189 | * state, to avoid that Vim's vertical window size accidentally |
| 4190 | * increases due to the unaccounted-for menu height. */ |
| 4191 | menu_height = old_menu_height == -1 ? 0 : old_menu_height; |
| 4192 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4193 | else |
| 4194 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4195 | /* |
| 4196 | * In case 'lines' is set in _vimrc/_gvimrc window width doesn't |
| 4197 | * seem to have been set yet, so menu wraps in default window |
| 4198 | * width which is very narrow. Instead just return height of a |
| 4199 | * single menu item. Will still be wrong when the menu really |
| 4200 | * should wrap over more than one line. |
| 4201 | */ |
| 4202 | GetMenuItemRect(s_hwnd, s_menuBar, 0, &rc1); |
| 4203 | if (gui.starting) |
| 4204 | menu_height = rc1.bottom - rc1.top + 1; |
| 4205 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4206 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4207 | GetMenuItemRect(s_hwnd, s_menuBar, num - 1, &rc2); |
| 4208 | menu_height = rc2.bottom - rc1.top + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | if (fix_window && menu_height != old_menu_height) |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4213 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
Bram Moolenaar | 71371b1 | 2015-03-24 17:57:12 +0100 | [diff] [blame] | 4214 | old_menu_height = menu_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4215 | |
| 4216 | return menu_height; |
| 4217 | } |
| 4218 | #endif /*FEAT_MENU*/ |
| 4219 | |
| 4220 | |
| 4221 | /* |
| 4222 | * Setup for the Intellimouse |
| 4223 | */ |
| 4224 | static void |
| 4225 | init_mouse_wheel(void) |
| 4226 | { |
| 4227 | |
| 4228 | #ifndef SPI_GETWHEELSCROLLLINES |
| 4229 | # define SPI_GETWHEELSCROLLLINES 104 |
| 4230 | #endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4231 | #ifndef SPI_SETWHEELSCROLLLINES |
| 4232 | # define SPI_SETWHEELSCROLLLINES 105 |
| 4233 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4234 | |
| 4235 | #define VMOUSEZ_CLASSNAME "MouseZ" /* hidden wheel window class */ |
| 4236 | #define VMOUSEZ_TITLE "Magellan MSWHEEL" /* hidden wheel window title */ |
| 4237 | #define VMSH_MOUSEWHEEL "MSWHEEL_ROLLMSG" |
| 4238 | #define VMSH_SCROLL_LINES "MSH_SCROLL_LINES_MSG" |
| 4239 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4240 | mouse_scroll_lines = 3; /* reasonable default */ |
| 4241 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4242 | /* if NT 4.0+ (or Win98) get scroll lines directly from system */ |
| 4243 | SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, |
| 4244 | &mouse_scroll_lines, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4245 | } |
| 4246 | |
| 4247 | |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4248 | /* |
| 4249 | * Intellimouse wheel handler. |
| 4250 | * Treat a mouse wheel event as if it were a scroll request. |
| 4251 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4252 | static void |
| 4253 | _OnMouseWheel( |
| 4254 | HWND hwnd, |
| 4255 | short zDelta) |
| 4256 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4257 | int i; |
| 4258 | int size; |
| 4259 | HWND hwndCtl; |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4260 | win_T *wp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4261 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4262 | if (mouse_scroll_lines == 0) |
| 4263 | init_mouse_wheel(); |
| 4264 | |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4265 | wp = gui_mouse_window(FIND_POPUP); |
| 4266 | |
Bram Moolenaar | 0630bb6 | 2019-11-04 22:52:12 +0100 | [diff] [blame] | 4267 | #ifdef FEAT_TEXT_PROP |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4268 | if (wp != NULL && popup_is_popup(wp)) |
Bram Moolenaar | 0630bb6 | 2019-11-04 22:52:12 +0100 | [diff] [blame] | 4269 | { |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4270 | cmdarg_T cap; |
| 4271 | oparg_T oa; |
Bram Moolenaar | 0630bb6 | 2019-11-04 22:52:12 +0100 | [diff] [blame] | 4272 | |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4273 | // Mouse hovers over popup window, scroll it if possible. |
| 4274 | mouse_row = wp->w_winrow; |
| 4275 | mouse_col = wp->w_wincol; |
| 4276 | vim_memset(&cap, 0, sizeof(cap)); |
| 4277 | cap.arg = zDelta < 0 ? MSCR_UP : MSCR_DOWN; |
| 4278 | cap.cmdchar = zDelta < 0 ? K_MOUSEUP : K_MOUSEDOWN; |
| 4279 | clear_oparg(&oa); |
| 4280 | cap.oap = &oa; |
| 4281 | nv_mousescroll(&cap); |
| 4282 | update_screen(0); |
| 4283 | setcursor(); |
| 4284 | out_flush(); |
| 4285 | return; |
Bram Moolenaar | 0630bb6 | 2019-11-04 22:52:12 +0100 | [diff] [blame] | 4286 | } |
| 4287 | #endif |
| 4288 | |
Bram Moolenaar | ae20f34 | 2019-11-05 21:09:23 +0100 | [diff] [blame] | 4289 | if (wp == NULL || !p_scf) |
| 4290 | wp = curwin; |
| 4291 | |
| 4292 | if (wp->w_scrollbars[SBAR_RIGHT].id != 0) |
| 4293 | hwndCtl = wp->w_scrollbars[SBAR_RIGHT].id; |
| 4294 | else if (wp->w_scrollbars[SBAR_LEFT].id != 0) |
| 4295 | hwndCtl = wp->w_scrollbars[SBAR_LEFT].id; |
| 4296 | else |
| 4297 | return; |
| 4298 | size = wp->w_height; |
| 4299 | |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 4300 | mch_disable_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4301 | if (mouse_scroll_lines > 0 |
| 4302 | && mouse_scroll_lines < (size > 2 ? size - 2 : 1)) |
| 4303 | { |
| 4304 | for (i = mouse_scroll_lines; i > 0; --i) |
| 4305 | _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_LINEUP : SB_LINEDOWN, 0); |
| 4306 | } |
| 4307 | else |
| 4308 | _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_PAGEUP : SB_PAGEDOWN, 0); |
Bram Moolenaar | a338adc | 2018-01-31 20:51:47 +0100 | [diff] [blame] | 4309 | mch_enable_flush(); |
| 4310 | gui_may_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4311 | } |
| 4312 | |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4313 | #ifdef USE_SYSMENU_FONT |
| 4314 | /* |
| 4315 | * Get Menu Font. |
| 4316 | * Return OK or FAIL. |
| 4317 | */ |
| 4318 | static int |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4319 | gui_w32_get_menu_font(LOGFONTW *lf) |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4320 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4321 | NONCLIENTMETRICSW nm; |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4322 | |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4323 | nm.cbSize = sizeof(NONCLIENTMETRICSW); |
| 4324 | if (!SystemParametersInfoW( |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4325 | SPI_GETNONCLIENTMETRICS, |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4326 | sizeof(NONCLIENTMETRICSW), |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4327 | &nm, |
| 4328 | 0)) |
| 4329 | return FAIL; |
| 4330 | *lf = nm.lfMenuFont; |
| 4331 | return OK; |
| 4332 | } |
| 4333 | #endif |
| 4334 | |
| 4335 | |
| 4336 | #if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT) |
| 4337 | /* |
| 4338 | * Set the GUI tabline font to the system menu font |
| 4339 | */ |
| 4340 | static void |
| 4341 | set_tabline_font(void) |
| 4342 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4343 | LOGFONTW lfSysmenu; |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4344 | HFONT font; |
| 4345 | HWND hwnd; |
| 4346 | HDC hdc; |
| 4347 | HFONT hfntOld; |
| 4348 | TEXTMETRIC tm; |
| 4349 | |
| 4350 | if (gui_w32_get_menu_font(&lfSysmenu) != OK) |
| 4351 | return; |
| 4352 | |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 4353 | font = CreateFontIndirectW(&lfSysmenu); |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4354 | |
| 4355 | SendMessage(s_tabhwnd, WM_SETFONT, (WPARAM)font, TRUE); |
| 4356 | |
| 4357 | /* |
| 4358 | * Compute the height of the font used for the tab text |
| 4359 | */ |
| 4360 | hwnd = GetDesktopWindow(); |
| 4361 | hdc = GetWindowDC(hwnd); |
| 4362 | hfntOld = SelectFont(hdc, font); |
| 4363 | |
| 4364 | GetTextMetrics(hdc, &tm); |
| 4365 | |
| 4366 | SelectFont(hdc, hfntOld); |
| 4367 | ReleaseDC(hwnd, hdc); |
| 4368 | |
| 4369 | /* |
| 4370 | * The space used by the tab border and the space between the tab label |
| 4371 | * and the tab border is included as 7. |
| 4372 | */ |
| 4373 | gui.tabline_height = tm.tmHeight + tm.tmInternalLeading + 7; |
| 4374 | } |
| 4375 | #endif |
| 4376 | |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 4377 | /* |
| 4378 | * Invoked when a setting was changed. |
| 4379 | */ |
| 4380 | static LRESULT CALLBACK |
| 4381 | _OnSettingChange(UINT n) |
| 4382 | { |
| 4383 | if (n == SPI_SETWHEELSCROLLLINES) |
| 4384 | SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, |
| 4385 | &mouse_scroll_lines, 0); |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4386 | #if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT) |
| 4387 | if (n == SPI_SETNONCLIENTMETRICS) |
| 4388 | set_tabline_font(); |
| 4389 | #endif |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 4390 | return 0; |
| 4391 | } |
| 4392 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4393 | #ifdef FEAT_NETBEANS_INTG |
| 4394 | static void |
| 4395 | _OnWindowPosChanged( |
| 4396 | HWND hwnd, |
| 4397 | const LPWINDOWPOS lpwpos) |
| 4398 | { |
| 4399 | static int x = 0, y = 0, cx = 0, cy = 0; |
Bram Moolenaar | f12d983 | 2016-01-29 21:11:25 +0100 | [diff] [blame] | 4400 | extern int WSInitialized; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4401 | |
| 4402 | if (WSInitialized && (lpwpos->x != x || lpwpos->y != y |
| 4403 | || lpwpos->cx != cx || lpwpos->cy != cy)) |
| 4404 | { |
| 4405 | x = lpwpos->x; |
| 4406 | y = lpwpos->y; |
| 4407 | cx = lpwpos->cx; |
| 4408 | cy = lpwpos->cy; |
| 4409 | netbeans_frame_moved(x, y); |
| 4410 | } |
| 4411 | /* Allow to send WM_SIZE and WM_MOVE */ |
| 4412 | FORWARD_WM_WINDOWPOSCHANGED(hwnd, lpwpos, MyWindowProc); |
| 4413 | } |
| 4414 | #endif |
| 4415 | |
| 4416 | static int |
| 4417 | _DuringSizing( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4418 | UINT fwSide, |
| 4419 | LPRECT lprc) |
| 4420 | { |
| 4421 | int w, h; |
| 4422 | int valid_w, valid_h; |
| 4423 | int w_offset, h_offset; |
| 4424 | |
| 4425 | w = lprc->right - lprc->left; |
| 4426 | h = lprc->bottom - lprc->top; |
| 4427 | gui_mswin_get_valid_dimensions(w, h, &valid_w, &valid_h); |
| 4428 | w_offset = w - valid_w; |
| 4429 | h_offset = h - valid_h; |
| 4430 | |
| 4431 | if (fwSide == WMSZ_LEFT || fwSide == WMSZ_TOPLEFT |
| 4432 | || fwSide == WMSZ_BOTTOMLEFT) |
| 4433 | lprc->left += w_offset; |
| 4434 | else if (fwSide == WMSZ_RIGHT || fwSide == WMSZ_TOPRIGHT |
| 4435 | || fwSide == WMSZ_BOTTOMRIGHT) |
| 4436 | lprc->right -= w_offset; |
| 4437 | |
| 4438 | if (fwSide == WMSZ_TOP || fwSide == WMSZ_TOPLEFT |
| 4439 | || fwSide == WMSZ_TOPRIGHT) |
| 4440 | lprc->top += h_offset; |
| 4441 | else if (fwSide == WMSZ_BOTTOM || fwSide == WMSZ_BOTTOMLEFT |
| 4442 | || fwSide == WMSZ_BOTTOMRIGHT) |
| 4443 | lprc->bottom -= h_offset; |
| 4444 | return TRUE; |
| 4445 | } |
| 4446 | |
| 4447 | |
| 4448 | |
| 4449 | static LRESULT CALLBACK |
| 4450 | _WndProc( |
| 4451 | HWND hwnd, |
| 4452 | UINT uMsg, |
| 4453 | WPARAM wParam, |
| 4454 | LPARAM lParam) |
| 4455 | { |
| 4456 | /* |
| 4457 | TRACE("WndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n", |
| 4458 | hwnd, uMsg, wParam, lParam); |
| 4459 | */ |
| 4460 | |
| 4461 | HandleMouseHide(uMsg, lParam); |
| 4462 | |
| 4463 | s_uMsg = uMsg; |
| 4464 | s_wParam = wParam; |
| 4465 | s_lParam = lParam; |
| 4466 | |
| 4467 | switch (uMsg) |
| 4468 | { |
| 4469 | HANDLE_MSG(hwnd, WM_DEADCHAR, _OnDeadChar); |
| 4470 | HANDLE_MSG(hwnd, WM_SYSDEADCHAR, _OnDeadChar); |
| 4471 | /* HANDLE_MSG(hwnd, WM_ACTIVATE, _OnActivate); */ |
| 4472 | HANDLE_MSG(hwnd, WM_CLOSE, _OnClose); |
| 4473 | /* HANDLE_MSG(hwnd, WM_COMMAND, _OnCommand); */ |
| 4474 | HANDLE_MSG(hwnd, WM_DESTROY, _OnDestroy); |
| 4475 | HANDLE_MSG(hwnd, WM_DROPFILES, _OnDropFiles); |
| 4476 | HANDLE_MSG(hwnd, WM_HSCROLL, _OnScroll); |
| 4477 | HANDLE_MSG(hwnd, WM_KILLFOCUS, _OnKillFocus); |
| 4478 | #ifdef FEAT_MENU |
| 4479 | HANDLE_MSG(hwnd, WM_COMMAND, _OnMenu); |
| 4480 | #endif |
| 4481 | /* HANDLE_MSG(hwnd, WM_MOVE, _OnMove); */ |
| 4482 | /* HANDLE_MSG(hwnd, WM_NCACTIVATE, _OnNCActivate); */ |
| 4483 | HANDLE_MSG(hwnd, WM_SETFOCUS, _OnSetFocus); |
| 4484 | HANDLE_MSG(hwnd, WM_SIZE, _OnSize); |
| 4485 | /* HANDLE_MSG(hwnd, WM_SYSCOMMAND, _OnSysCommand); */ |
| 4486 | /* HANDLE_MSG(hwnd, WM_SYSKEYDOWN, _OnAltKey); */ |
| 4487 | HANDLE_MSG(hwnd, WM_VSCROLL, _OnScroll); |
| 4488 | // HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, _OnWindowPosChanging); |
| 4489 | HANDLE_MSG(hwnd, WM_ACTIVATEAPP, _OnActivateApp); |
| 4490 | #ifdef FEAT_NETBEANS_INTG |
| 4491 | HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGED, _OnWindowPosChanged); |
| 4492 | #endif |
| 4493 | |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4494 | #ifdef FEAT_GUI_TABLINE |
| 4495 | case WM_RBUTTONUP: |
| 4496 | { |
| 4497 | if (gui_mch_showing_tabline()) |
| 4498 | { |
| 4499 | POINT pt; |
| 4500 | RECT rect; |
| 4501 | |
| 4502 | /* |
| 4503 | * If the cursor is on the tabline, display the tab menu |
| 4504 | */ |
| 4505 | GetCursorPos((LPPOINT)&pt); |
| 4506 | GetWindowRect(s_textArea, &rect); |
| 4507 | if (pt.y < rect.top) |
| 4508 | { |
| 4509 | show_tabline_popup_menu(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4510 | return 0L; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4511 | } |
| 4512 | } |
| 4513 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4514 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4515 | case WM_LBUTTONDBLCLK: |
| 4516 | { |
| 4517 | /* |
| 4518 | * If the user double clicked the tabline, create a new tab |
| 4519 | */ |
| 4520 | if (gui_mch_showing_tabline()) |
| 4521 | { |
| 4522 | POINT pt; |
| 4523 | RECT rect; |
| 4524 | |
| 4525 | GetCursorPos((LPPOINT)&pt); |
| 4526 | GetWindowRect(s_textArea, &rect); |
| 4527 | if (pt.y < rect.top) |
Bram Moolenaar | c6fe919 | 2006-04-09 21:54:49 +0000 | [diff] [blame] | 4528 | send_tabline_menu_event(0, TABLINE_MENU_NEW); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4529 | } |
| 4530 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4531 | } |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4532 | #endif |
| 4533 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4534 | case WM_QUERYENDSESSION: /* System wants to go down. */ |
| 4535 | gui_shell_closed(); /* Will exit when no changed buffers. */ |
| 4536 | return FALSE; /* Do NOT allow system to go down. */ |
| 4537 | |
| 4538 | case WM_ENDSESSION: |
| 4539 | if (wParam) /* system only really goes down when wParam is TRUE */ |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4540 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4541 | _OnEndSession(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4542 | return 0L; |
| 4543 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4544 | break; |
| 4545 | |
| 4546 | case WM_CHAR: |
| 4547 | /* Don't use HANDLE_MSG() for WM_CHAR, it truncates wParam to a single |
| 4548 | * byte while we want the UTF-16 character value. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4549 | _OnChar(hwnd, (UINT)wParam, (int)(short)LOWORD(lParam)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4550 | return 0L; |
| 4551 | |
| 4552 | case WM_SYSCHAR: |
| 4553 | /* |
| 4554 | * if 'winaltkeys' is "no", or it's "menu" and it's not a menu |
| 4555 | * shortcut key, handle like a typed ALT key, otherwise call Windows |
| 4556 | * ALT key handling. |
| 4557 | */ |
| 4558 | #ifdef FEAT_MENU |
| 4559 | if ( !gui.menu_is_active |
| 4560 | || p_wak[0] == 'n' |
| 4561 | || (p_wak[0] == 'm' && !gui_is_menu_shortcut((int)wParam)) |
| 4562 | ) |
| 4563 | #endif |
| 4564 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4565 | _OnSysChar(hwnd, (UINT)wParam, (int)(short)LOWORD(lParam)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4566 | return 0L; |
| 4567 | } |
| 4568 | #ifdef FEAT_MENU |
| 4569 | else |
| 4570 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4571 | #endif |
| 4572 | |
| 4573 | case WM_SYSKEYUP: |
| 4574 | #ifdef FEAT_MENU |
| 4575 | /* This used to be done only when menu is active: ALT key is used for |
| 4576 | * that. But that caused problems when menu is disabled and using |
| 4577 | * Alt-Tab-Esc: get into a strange state where no mouse-moved events |
| 4578 | * are received, mouse pointer remains hidden. */ |
| 4579 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4580 | #else |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4581 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4582 | #endif |
| 4583 | |
| 4584 | case WM_SIZING: /* HANDLE_MSG doesn't seem to handle this one */ |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4585 | return _DuringSizing((UINT)wParam, (LPRECT)lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4586 | |
| 4587 | case WM_MOUSEWHEEL: |
| 4588 | _OnMouseWheel(hwnd, HIWORD(wParam)); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4589 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4590 | |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 4591 | /* Notification for change in SystemParametersInfo() */ |
| 4592 | case WM_SETTINGCHANGE: |
| 4593 | return _OnSettingChange((UINT)wParam); |
| 4594 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4595 | #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4596 | case WM_NOTIFY: |
| 4597 | switch (((LPNMHDR) lParam)->code) |
| 4598 | { |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4599 | case TTN_GETDISPINFOW: |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4600 | case TTN_GETDISPINFO: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4601 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4602 | LPNMHDR hdr = (LPNMHDR)lParam; |
| 4603 | char_u *str = NULL; |
| 4604 | static void *tt_text = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4605 | |
Bram Moolenaar | d23a823 | 2018-02-10 18:45:26 +0100 | [diff] [blame] | 4606 | VIM_CLEAR(tt_text); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4607 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4608 | # ifdef FEAT_GUI_TABLINE |
| 4609 | if (gui_mch_showing_tabline() |
| 4610 | && hdr->hwndFrom == TabCtrl_GetToolTips(s_tabhwnd)) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4611 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4612 | POINT pt; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4613 | /* |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4614 | * Mouse is over the GUI tabline. Display the |
| 4615 | * tooltip for the tab under the cursor |
| 4616 | * |
| 4617 | * Get the cursor position within the tab control |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4618 | */ |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4619 | GetCursorPos(&pt); |
| 4620 | if (ScreenToClient(s_tabhwnd, &pt) != 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4621 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4622 | TCHITTESTINFO htinfo; |
| 4623 | int idx; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4624 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4625 | /* |
| 4626 | * Get the tab under the cursor |
| 4627 | */ |
| 4628 | htinfo.pt.x = pt.x; |
| 4629 | htinfo.pt.y = pt.y; |
| 4630 | idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 4631 | if (idx != -1) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4632 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4633 | tabpage_T *tp; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4634 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4635 | tp = find_tabpage(idx + 1); |
| 4636 | if (tp != NULL) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4637 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4638 | get_tabline_label(tp, TRUE); |
| 4639 | str = NameBuff; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4640 | } |
| 4641 | } |
| 4642 | } |
| 4643 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4644 | # endif |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4645 | # ifdef FEAT_TOOLBAR |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4646 | # ifdef FEAT_GUI_TABLINE |
| 4647 | else |
| 4648 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4649 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4650 | UINT idButton; |
| 4651 | vimmenu_T *pMenu; |
| 4652 | |
| 4653 | idButton = (UINT) hdr->idFrom; |
| 4654 | pMenu = gui_mswin_find_menu(root_menu, idButton); |
| 4655 | if (pMenu) |
| 4656 | str = pMenu->strings[MENU_INDEX_TIP]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4657 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4658 | # endif |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4659 | if (str != NULL) |
| 4660 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4661 | if (hdr->code == TTN_GETDISPINFOW) |
| 4662 | { |
| 4663 | LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam; |
| 4664 | |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 4665 | /* Set the maximum width, this also enables using |
| 4666 | * \n for line break. */ |
| 4667 | SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, |
| 4668 | 0, 500); |
| 4669 | |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 4670 | tt_text = enc_to_utf16(str, NULL); |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4671 | lpdi->lpszText = tt_text; |
| 4672 | /* can't show tooltip if failed */ |
| 4673 | } |
| 4674 | else |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4675 | { |
| 4676 | LPNMTTDISPINFO lpdi = (LPNMTTDISPINFO)lParam; |
| 4677 | |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 4678 | /* Set the maximum width, this also enables using |
| 4679 | * \n for line break. */ |
| 4680 | SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, |
| 4681 | 0, 500); |
| 4682 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4683 | if (STRLEN(str) < sizeof(lpdi->szText) |
| 4684 | || ((tt_text = vim_strsave(str)) == NULL)) |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 4685 | vim_strncpy((char_u *)lpdi->szText, str, |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 4686 | sizeof(lpdi->szText) - 1); |
| 4687 | else |
| 4688 | lpdi->lpszText = tt_text; |
| 4689 | } |
| 4690 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4691 | } |
| 4692 | break; |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4693 | # ifdef FEAT_GUI_TABLINE |
| 4694 | case TCN_SELCHANGE: |
| 4695 | if (gui_mch_showing_tabline() |
| 4696 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4697 | { |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4698 | send_tabline_event(TabCtrl_GetCurSel(s_tabhwnd) + 1); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4699 | return 0L; |
| 4700 | } |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4701 | break; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4702 | |
| 4703 | case NM_RCLICK: |
| 4704 | if (gui_mch_showing_tabline() |
| 4705 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4706 | { |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4707 | show_tabline_popup_menu(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4708 | return 0L; |
| 4709 | } |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 4710 | break; |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4711 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4712 | default: |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4713 | # ifdef FEAT_GUI_TABLINE |
| 4714 | if (gui_mch_showing_tabline() |
| 4715 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
| 4716 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4717 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4718 | break; |
| 4719 | } |
| 4720 | break; |
| 4721 | #endif |
| 4722 | #if defined(MENUHINTS) && defined(FEAT_MENU) |
| 4723 | case WM_MENUSELECT: |
| 4724 | if (((UINT) HIWORD(wParam) |
| 4725 | & (0xffff ^ (MF_MOUSESELECT + MF_BITMAP + MF_POPUP))) |
| 4726 | == MF_HILITE |
| 4727 | && (State & CMDLINE) == 0) |
| 4728 | { |
| 4729 | UINT idButton; |
| 4730 | vimmenu_T *pMenu; |
| 4731 | static int did_menu_tip = FALSE; |
| 4732 | |
| 4733 | if (did_menu_tip) |
| 4734 | { |
| 4735 | msg_clr_cmdline(); |
| 4736 | setcursor(); |
| 4737 | out_flush(); |
| 4738 | did_menu_tip = FALSE; |
| 4739 | } |
| 4740 | |
| 4741 | idButton = (UINT)LOWORD(wParam); |
| 4742 | pMenu = gui_mswin_find_menu(root_menu, idButton); |
| 4743 | if (pMenu != NULL && pMenu->strings[MENU_INDEX_TIP] != 0 |
| 4744 | && GetMenuState(s_menuBar, pMenu->id, MF_BYCOMMAND) != -1) |
| 4745 | { |
Bram Moolenaar | 2d8ab99 | 2007-06-19 08:06:18 +0000 | [diff] [blame] | 4746 | ++msg_hist_off; |
Bram Moolenaar | 32526b3 | 2019-01-19 17:43:09 +0100 | [diff] [blame] | 4747 | msg((char *)pMenu->strings[MENU_INDEX_TIP]); |
Bram Moolenaar | 2d8ab99 | 2007-06-19 08:06:18 +0000 | [diff] [blame] | 4748 | --msg_hist_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4749 | setcursor(); |
| 4750 | out_flush(); |
| 4751 | did_menu_tip = TRUE; |
| 4752 | } |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4753 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4754 | } |
| 4755 | break; |
| 4756 | #endif |
| 4757 | case WM_NCHITTEST: |
| 4758 | { |
| 4759 | LRESULT result; |
| 4760 | int x, y; |
| 4761 | int xPos = GET_X_LPARAM(lParam); |
| 4762 | |
| 4763 | result = MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4764 | if (result == HTCLIENT) |
| 4765 | { |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4766 | #ifdef FEAT_GUI_TABLINE |
| 4767 | if (gui_mch_showing_tabline()) |
| 4768 | { |
| 4769 | int yPos = GET_Y_LPARAM(lParam); |
| 4770 | RECT rct; |
| 4771 | |
| 4772 | /* If the cursor is on the GUI tabline, don't process this |
| 4773 | * event */ |
| 4774 | GetWindowRect(s_textArea, &rct); |
| 4775 | if (yPos < rct.top) |
| 4776 | return result; |
| 4777 | } |
| 4778 | #endif |
Bram Moolenaar | cde8854 | 2015-08-11 19:14:00 +0200 | [diff] [blame] | 4779 | (void)gui_mch_get_winpos(&x, &y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4780 | xPos -= x; |
| 4781 | |
| 4782 | if (xPos < 48) /* <VN> TODO should use system metric? */ |
| 4783 | return HTBOTTOMLEFT; |
| 4784 | else |
| 4785 | return HTBOTTOMRIGHT; |
| 4786 | } |
| 4787 | else |
| 4788 | return result; |
| 4789 | } |
| 4790 | /* break; notreached */ |
| 4791 | |
| 4792 | #ifdef FEAT_MBYTE_IME |
| 4793 | case WM_IME_NOTIFY: |
| 4794 | if (!_OnImeNotify(hwnd, (DWORD)wParam, (DWORD)lParam)) |
| 4795 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4796 | return 1L; |
| 4797 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4798 | case WM_IME_COMPOSITION: |
| 4799 | if (!_OnImeComposition(hwnd, wParam, lParam)) |
| 4800 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 4801 | return 1L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4802 | #endif |
| 4803 | |
| 4804 | default: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4805 | #ifdef MSWIN_FIND_REPLACE |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 4806 | if (uMsg == s_findrep_msg && s_findrep_msg != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4807 | _OnFindRepl(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4808 | #endif |
| 4809 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 4810 | } |
| 4811 | |
Bram Moolenaar | 2787ab9 | 2011-12-14 15:23:59 +0100 | [diff] [blame] | 4812 | return DefWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4813 | } |
| 4814 | |
| 4815 | /* |
| 4816 | * End of call-back routines |
| 4817 | */ |
| 4818 | |
| 4819 | /* parent window, if specified with -P */ |
| 4820 | HWND vim_parent_hwnd = NULL; |
| 4821 | |
| 4822 | static BOOL CALLBACK |
| 4823 | FindWindowTitle(HWND hwnd, LPARAM lParam) |
| 4824 | { |
| 4825 | char buf[2048]; |
| 4826 | char *title = (char *)lParam; |
| 4827 | |
| 4828 | if (GetWindowText(hwnd, buf, sizeof(buf))) |
| 4829 | { |
| 4830 | if (strstr(buf, title) != NULL) |
| 4831 | { |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 4832 | /* Found it. Store the window ref. and quit searching if MDI |
| 4833 | * works. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4834 | vim_parent_hwnd = FindWindowEx(hwnd, NULL, "MDIClient", NULL); |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 4835 | if (vim_parent_hwnd != NULL) |
| 4836 | return FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | return TRUE; /* continue searching */ |
| 4840 | } |
| 4841 | |
| 4842 | /* |
| 4843 | * Invoked for '-P "title"' argument: search for parent application to open |
| 4844 | * our window in. |
| 4845 | */ |
| 4846 | void |
| 4847 | gui_mch_set_parent(char *title) |
| 4848 | { |
| 4849 | EnumWindows(FindWindowTitle, (LPARAM)title); |
| 4850 | if (vim_parent_hwnd == NULL) |
| 4851 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 4852 | semsg(_("E671: Cannot find window title \"%s\""), title); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4853 | mch_exit(2); |
| 4854 | } |
| 4855 | } |
| 4856 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4857 | #ifndef FEAT_OLE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4858 | static void |
| 4859 | ole_error(char *arg) |
| 4860 | { |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 4861 | char buf[IOSIZE]; |
| 4862 | |
Bram Moolenaar | 0b75f7c | 2019-05-08 22:28:46 +0200 | [diff] [blame] | 4863 | # ifdef VIMDLL |
| 4864 | gui.in_use = mch_is_gui_executable(); |
| 4865 | # endif |
| 4866 | |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 4867 | /* Can't use emsg() here, we have not finished initialisation yet. */ |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 4868 | vim_snprintf(buf, IOSIZE, |
| 4869 | _("E243: Argument not supported: \"-%s\"; Use the OLE version."), |
| 4870 | arg); |
| 4871 | mch_errmsg(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4872 | } |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4873 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4874 | |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 4875 | #if defined(GUI_MAY_SPAWN) || defined(PROTO) |
| 4876 | static char * |
| 4877 | gvim_error(void) |
| 4878 | { |
| 4879 | char *msg = _("E988: GUI cannot be used. Cannot execute gvim.exe."); |
| 4880 | |
| 4881 | if (starting) |
| 4882 | { |
| 4883 | mch_errmsg(msg); |
| 4884 | mch_errmsg("\n"); |
| 4885 | mch_exit(2); |
| 4886 | } |
| 4887 | return msg; |
| 4888 | } |
| 4889 | |
| 4890 | char * |
| 4891 | gui_mch_do_spawn(char_u *arg) |
| 4892 | { |
| 4893 | int len; |
| 4894 | # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) |
| 4895 | char_u *session = NULL; |
| 4896 | LPWSTR tofree1 = NULL; |
| 4897 | # endif |
| 4898 | WCHAR name[MAX_PATH]; |
| 4899 | LPWSTR cmd, newcmd = NULL, p, warg, tofree2 = NULL; |
| 4900 | STARTUPINFOW si = {sizeof(si)}; |
| 4901 | PROCESS_INFORMATION pi; |
| 4902 | |
| 4903 | if (!GetModuleFileNameW(g_hinst, name, MAX_PATH)) |
| 4904 | goto error; |
| 4905 | p = wcsrchr(name, L'\\'); |
| 4906 | if (p == NULL) |
| 4907 | goto error; |
| 4908 | // Replace the executable name from vim(d).exe to gvim(d).exe. |
| 4909 | # ifdef DEBUG |
| 4910 | wcscpy(p + 1, L"gvimd.exe"); |
| 4911 | # else |
| 4912 | wcscpy(p + 1, L"gvim.exe"); |
| 4913 | # endif |
| 4914 | |
| 4915 | # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) |
| 4916 | if (starting) |
| 4917 | # endif |
| 4918 | { |
| 4919 | // Pass the command line to the new process. |
| 4920 | p = GetCommandLineW(); |
| 4921 | // Skip 1st argument. |
| 4922 | while (*p && *p != L' ' && *p != L'\t') |
| 4923 | { |
| 4924 | if (*p == L'"') |
| 4925 | { |
| 4926 | while (*p && *p != L'"') |
| 4927 | ++p; |
| 4928 | if (*p) |
| 4929 | ++p; |
| 4930 | } |
| 4931 | else |
| 4932 | ++p; |
| 4933 | } |
| 4934 | cmd = p; |
| 4935 | } |
| 4936 | # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) |
| 4937 | else |
| 4938 | { |
| 4939 | // Create a session file and pass it to the new process. |
| 4940 | LPWSTR wsession; |
| 4941 | char_u *savebg; |
| 4942 | int ret; |
| 4943 | |
| 4944 | session = vim_tempname('s', FALSE); |
| 4945 | if (session == NULL) |
| 4946 | goto error; |
| 4947 | savebg = p_bg; |
| 4948 | p_bg = vim_strsave((char_u *)"light"); // Set 'bg' to "light". |
| 4949 | ret = write_session_file(session); |
| 4950 | vim_free(p_bg); |
| 4951 | p_bg = savebg; |
| 4952 | if (!ret) |
| 4953 | goto error; |
| 4954 | wsession = enc_to_utf16(session, NULL); |
| 4955 | if (wsession == NULL) |
| 4956 | goto error; |
| 4957 | len = (int)wcslen(wsession) * 2 + 27 + 1; |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 4958 | cmd = ALLOC_MULT(WCHAR, len); |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 4959 | if (cmd == NULL) |
| 4960 | { |
| 4961 | vim_free(wsession); |
| 4962 | goto error; |
| 4963 | } |
| 4964 | tofree1 = cmd; |
| 4965 | _snwprintf(cmd, len, L" -S \"%s\" -c \"call delete('%s')\"", |
| 4966 | wsession, wsession); |
| 4967 | vim_free(wsession); |
| 4968 | } |
| 4969 | # endif |
| 4970 | |
| 4971 | // Check additional arguments to the `:gui` command. |
| 4972 | if (arg != NULL) |
| 4973 | { |
| 4974 | warg = enc_to_utf16(arg, NULL); |
| 4975 | if (warg == NULL) |
| 4976 | goto error; |
| 4977 | tofree2 = warg; |
| 4978 | } |
| 4979 | else |
| 4980 | warg = L""; |
| 4981 | |
| 4982 | // Set up the new command line. |
| 4983 | len = (int)wcslen(name) + (int)wcslen(cmd) + (int)wcslen(warg) + 4; |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 4984 | newcmd = ALLOC_MULT(WCHAR, len); |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 4985 | if (newcmd == NULL) |
| 4986 | goto error; |
| 4987 | _snwprintf(newcmd, len, L"\"%s\"%s %s", name, cmd, warg); |
| 4988 | |
| 4989 | // Spawn a new GUI process. |
| 4990 | if (!CreateProcessW(NULL, newcmd, NULL, NULL, TRUE, 0, |
| 4991 | NULL, NULL, &si, &pi)) |
| 4992 | goto error; |
| 4993 | CloseHandle(pi.hProcess); |
| 4994 | CloseHandle(pi.hThread); |
| 4995 | mch_exit(0); |
| 4996 | |
| 4997 | error: |
| 4998 | # if defined(FEAT_SESSION) && defined(EXPERIMENTAL_GUI_CMD) |
| 4999 | if (session) |
| 5000 | mch_remove(session); |
| 5001 | vim_free(session); |
| 5002 | vim_free(tofree1); |
| 5003 | # endif |
| 5004 | vim_free(newcmd); |
| 5005 | vim_free(tofree2); |
| 5006 | return gvim_error(); |
| 5007 | } |
| 5008 | #endif |
| 5009 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5010 | /* |
| 5011 | * Parse the GUI related command-line arguments. Any arguments used are |
| 5012 | * deleted from argv, and *argc is decremented accordingly. This is called |
| 5013 | * when vim is started, whether or not the GUI has been started. |
| 5014 | */ |
| 5015 | void |
| 5016 | gui_mch_prepare(int *argc, char **argv) |
| 5017 | { |
| 5018 | int silent = FALSE; |
| 5019 | int idx; |
| 5020 | |
| 5021 | /* Check for special OLE command line parameters */ |
| 5022 | if ((*argc == 2 || *argc == 3) && (argv[1][0] == '-' || argv[1][0] == '/')) |
| 5023 | { |
| 5024 | /* Check for a "-silent" argument first. */ |
| 5025 | if (*argc == 3 && STRICMP(argv[1] + 1, "silent") == 0 |
| 5026 | && (argv[2][0] == '-' || argv[2][0] == '/')) |
| 5027 | { |
| 5028 | silent = TRUE; |
| 5029 | idx = 2; |
| 5030 | } |
| 5031 | else |
| 5032 | idx = 1; |
| 5033 | |
| 5034 | /* Register Vim as an OLE Automation server */ |
| 5035 | if (STRICMP(argv[idx] + 1, "register") == 0) |
| 5036 | { |
| 5037 | #ifdef FEAT_OLE |
| 5038 | RegisterMe(silent); |
| 5039 | mch_exit(0); |
| 5040 | #else |
| 5041 | if (!silent) |
| 5042 | ole_error("register"); |
| 5043 | mch_exit(2); |
| 5044 | #endif |
| 5045 | } |
| 5046 | |
| 5047 | /* Unregister Vim as an OLE Automation server */ |
| 5048 | if (STRICMP(argv[idx] + 1, "unregister") == 0) |
| 5049 | { |
| 5050 | #ifdef FEAT_OLE |
| 5051 | UnregisterMe(!silent); |
| 5052 | mch_exit(0); |
| 5053 | #else |
| 5054 | if (!silent) |
| 5055 | ole_error("unregister"); |
| 5056 | mch_exit(2); |
| 5057 | #endif |
| 5058 | } |
| 5059 | |
| 5060 | /* Ignore an -embedding argument. It is only relevant if the |
| 5061 | * application wants to treat the case when it is started manually |
| 5062 | * differently from the case where it is started via automation (and |
| 5063 | * we don't). |
| 5064 | */ |
| 5065 | if (STRICMP(argv[idx] + 1, "embedding") == 0) |
| 5066 | { |
| 5067 | #ifdef FEAT_OLE |
| 5068 | *argc = 1; |
| 5069 | #else |
| 5070 | ole_error("embedding"); |
| 5071 | mch_exit(2); |
| 5072 | #endif |
| 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | #ifdef FEAT_OLE |
| 5077 | { |
| 5078 | int bDoRestart = FALSE; |
| 5079 | |
| 5080 | InitOLE(&bDoRestart); |
| 5081 | /* automatically exit after registering */ |
| 5082 | if (bDoRestart) |
| 5083 | mch_exit(0); |
| 5084 | } |
| 5085 | #endif |
| 5086 | |
| 5087 | #ifdef FEAT_NETBEANS_INTG |
| 5088 | { |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 5089 | /* stolen from gui_x11.c */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5090 | int arg; |
| 5091 | |
| 5092 | for (arg = 1; arg < *argc; arg++) |
| 5093 | if (strncmp("-nb", argv[arg], 3) == 0) |
| 5094 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5095 | netbeansArg = argv[arg]; |
| 5096 | mch_memmove(&argv[arg], &argv[arg + 1], |
| 5097 | (--*argc - arg) * sizeof(char *)); |
| 5098 | argv[*argc] = NULL; |
| 5099 | break; /* enough? */ |
| 5100 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5101 | } |
| 5102 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5103 | } |
| 5104 | |
| 5105 | /* |
| 5106 | * Initialise the GUI. Create all the windows, set up all the call-backs |
| 5107 | * etc. |
| 5108 | */ |
| 5109 | int |
| 5110 | gui_mch_init(void) |
| 5111 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5112 | const WCHAR szVimWndClassW[] = VIM_CLASSW; |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 5113 | const WCHAR szTextAreaClassW[] = L"VimTextArea"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5114 | WNDCLASSW wndclassw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5115 | #ifdef GLOBAL_IME |
| 5116 | ATOM atom; |
| 5117 | #endif |
| 5118 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5119 | /* Return here if the window was already opened (happens when |
| 5120 | * gui_mch_dialog() is called early). */ |
| 5121 | if (s_hwnd != NULL) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 5122 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5123 | |
| 5124 | /* |
| 5125 | * Load the tearoff bitmap |
| 5126 | */ |
| 5127 | #ifdef FEAT_TEAROFF |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5128 | s_htearbitmap = LoadBitmap(g_hinst, "IDB_TEAROFF"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5129 | #endif |
| 5130 | |
| 5131 | gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); |
| 5132 | gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL); |
| 5133 | #ifdef FEAT_MENU |
| 5134 | gui.menu_height = 0; /* Windows takes care of this */ |
| 5135 | #endif |
| 5136 | gui.border_width = 0; |
| 5137 | |
| 5138 | s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); |
| 5139 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5140 | /* First try using the wide version, so that we can use any title. |
| 5141 | * Otherwise only characters in the active codepage will work. */ |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5142 | if (GetClassInfoW(g_hinst, szVimWndClassW, &wndclassw) == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5143 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5144 | wndclassw.style = CS_DBLCLKS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5145 | wndclassw.lpfnWndProc = _WndProc; |
| 5146 | wndclassw.cbClsExtra = 0; |
| 5147 | wndclassw.cbWndExtra = 0; |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5148 | wndclassw.hInstance = g_hinst; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5149 | wndclassw.hIcon = LoadIcon(wndclassw.hInstance, "IDR_VIM"); |
| 5150 | wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5151 | wndclassw.hbrBackground = s_brush; |
| 5152 | wndclassw.lpszMenuName = NULL; |
| 5153 | wndclassw.lpszClassName = szVimWndClassW; |
| 5154 | |
| 5155 | if (( |
| 5156 | #ifdef GLOBAL_IME |
| 5157 | atom = |
| 5158 | #endif |
| 5159 | RegisterClassW(&wndclassw)) == 0) |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5160 | return FAIL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5161 | } |
| 5162 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5163 | if (vim_parent_hwnd != NULL) |
| 5164 | { |
| 5165 | #ifdef HAVE_TRY_EXCEPT |
| 5166 | __try |
| 5167 | { |
| 5168 | #endif |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5169 | // Open inside the specified parent window. |
| 5170 | // TODO: last argument should point to a CLIENTCREATESTRUCT |
| 5171 | // structure. |
| 5172 | s_hwnd = CreateWindowExW( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5173 | WS_EX_MDICHILD, |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5174 | szVimWndClassW, L"Vim MSWindows GUI", |
Bram Moolenaar | e78c206 | 2011-08-10 15:56:27 +0200 | [diff] [blame] | 5175 | WS_OVERLAPPEDWINDOW | WS_CHILD |
| 5176 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 0xC000, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5177 | gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
| 5178 | gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5179 | 100, // Any value will do |
| 5180 | 100, // Any value will do |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5181 | vim_parent_hwnd, NULL, |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5182 | g_hinst, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5183 | #ifdef HAVE_TRY_EXCEPT |
| 5184 | } |
| 5185 | __except(EXCEPTION_EXECUTE_HANDLER) |
| 5186 | { |
| 5187 | /* NOP */ |
| 5188 | } |
| 5189 | #endif |
| 5190 | if (s_hwnd == NULL) |
| 5191 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 5192 | emsg(_("E672: Unable to open window inside MDI application")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5193 | mch_exit(2); |
| 5194 | } |
| 5195 | } |
| 5196 | else |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 5197 | { |
| 5198 | /* If the provided windowid is not valid reset it to zero, so that it |
| 5199 | * is ignored and we open our own window. */ |
| 5200 | if (IsWindow((HWND)win_socket_id) <= 0) |
| 5201 | win_socket_id = 0; |
| 5202 | |
| 5203 | /* Create a window. If win_socket_id is not zero without border and |
| 5204 | * titlebar, it will be reparented below. */ |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5205 | s_hwnd = CreateWindowW( |
| 5206 | szVimWndClassW, L"Vim MSWindows GUI", |
Bram Moolenaar | e78c206 | 2011-08-10 15:56:27 +0200 | [diff] [blame] | 5207 | (win_socket_id == 0 ? WS_OVERLAPPEDWINDOW : WS_POPUP) |
| 5208 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 5209 | gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
| 5210 | gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
| 5211 | 100, /* Any value will do */ |
| 5212 | 100, /* Any value will do */ |
| 5213 | NULL, NULL, |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5214 | g_hinst, NULL); |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 5215 | if (s_hwnd != NULL && win_socket_id != 0) |
| 5216 | { |
| 5217 | SetParent(s_hwnd, (HWND)win_socket_id); |
| 5218 | ShowWindow(s_hwnd, SW_SHOWMAXIMIZED); |
| 5219 | } |
| 5220 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5221 | |
| 5222 | if (s_hwnd == NULL) |
| 5223 | return FAIL; |
| 5224 | |
| 5225 | #ifdef GLOBAL_IME |
| 5226 | global_ime_init(atom, s_hwnd); |
| 5227 | #endif |
| 5228 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 5229 | dyn_imm_load(); |
| 5230 | #endif |
| 5231 | |
| 5232 | /* Create the text area window */ |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5233 | if (GetClassInfoW(g_hinst, szTextAreaClassW, &wndclassw) == 0) |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 5234 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5235 | wndclassw.style = CS_OWNDC; |
| 5236 | wndclassw.lpfnWndProc = _TextAreaWndProc; |
| 5237 | wndclassw.cbClsExtra = 0; |
| 5238 | wndclassw.cbWndExtra = 0; |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5239 | wndclassw.hInstance = g_hinst; |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5240 | wndclassw.hIcon = NULL; |
| 5241 | wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 5242 | wndclassw.hbrBackground = NULL; |
| 5243 | wndclassw.lpszMenuName = NULL; |
| 5244 | wndclassw.lpszClassName = szTextAreaClassW; |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 5245 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5246 | if (RegisterClassW(&wndclassw) == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5247 | return FAIL; |
| 5248 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5249 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5250 | s_textArea = CreateWindowExW( |
| 5251 | 0, |
| 5252 | szTextAreaClassW, L"Vim text area", |
| 5253 | WS_CHILD | WS_VISIBLE, 0, 0, |
| 5254 | 100, // Any value will do for now |
| 5255 | 100, // Any value will do for now |
| 5256 | s_hwnd, NULL, |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 5257 | g_hinst, NULL); |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 5258 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5259 | if (s_textArea == NULL) |
| 5260 | return FAIL; |
| 5261 | |
Bram Moolenaar | 2032190 | 2016-02-17 12:30:17 +0100 | [diff] [blame] | 5262 | #ifdef FEAT_LIBCALL |
Bram Moolenaar | cddc91c | 2014-09-23 21:53:41 +0200 | [diff] [blame] | 5263 | /* Try loading an icon from $RUNTIMEPATH/bitmaps/vim.ico. */ |
| 5264 | { |
| 5265 | HANDLE hIcon = NULL; |
| 5266 | |
| 5267 | if (mch_icon_load(&hIcon) == OK && hIcon != NULL) |
Bram Moolenaar | 0f519a0 | 2014-10-06 18:10:09 +0200 | [diff] [blame] | 5268 | SendMessage(s_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIcon); |
Bram Moolenaar | cddc91c | 2014-09-23 21:53:41 +0200 | [diff] [blame] | 5269 | } |
Bram Moolenaar | 2032190 | 2016-02-17 12:30:17 +0100 | [diff] [blame] | 5270 | #endif |
Bram Moolenaar | cddc91c | 2014-09-23 21:53:41 +0200 | [diff] [blame] | 5271 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5272 | #ifdef FEAT_MENU |
| 5273 | s_menuBar = CreateMenu(); |
| 5274 | #endif |
| 5275 | s_hdc = GetDC(s_textArea); |
| 5276 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5277 | DragAcceptFiles(s_hwnd, TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5278 | |
| 5279 | /* Do we need to bother with this? */ |
| 5280 | /* m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); */ |
| 5281 | |
| 5282 | /* Get background/foreground colors from the system */ |
| 5283 | gui_mch_def_colors(); |
| 5284 | |
| 5285 | /* Get the colors from the "Normal" group (set in syntax.c or in a vimrc |
| 5286 | * file) */ |
| 5287 | set_normal_colors(); |
| 5288 | |
| 5289 | /* |
| 5290 | * Check that none of the colors are the same as the background color. |
| 5291 | * Then store the current values as the defaults. |
| 5292 | */ |
| 5293 | gui_check_colors(); |
| 5294 | gui.def_norm_pixel = gui.norm_pixel; |
| 5295 | gui.def_back_pixel = gui.back_pixel; |
| 5296 | |
| 5297 | /* Get the colors for the highlight groups (gui_check_colors() might have |
| 5298 | * changed them) */ |
| 5299 | highlight_gui_started(); |
| 5300 | |
| 5301 | /* |
Bram Moolenaar | 97b0b0e | 2015-11-19 20:23:37 +0100 | [diff] [blame] | 5302 | * Start out by adding the configured border width into the border offset. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5303 | */ |
Bram Moolenaar | 97b0b0e | 2015-11-19 20:23:37 +0100 | [diff] [blame] | 5304 | gui.border_offset = gui.border_width; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5305 | |
| 5306 | /* |
| 5307 | * Set up for Intellimouse processing |
| 5308 | */ |
| 5309 | init_mouse_wheel(); |
| 5310 | |
| 5311 | /* |
| 5312 | * compute a couple of metrics used for the dialogs |
| 5313 | */ |
| 5314 | get_dialog_font_metrics(); |
| 5315 | #ifdef FEAT_TOOLBAR |
| 5316 | /* |
| 5317 | * Create the toolbar |
| 5318 | */ |
| 5319 | initialise_toolbar(); |
| 5320 | #endif |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 5321 | #ifdef FEAT_GUI_TABLINE |
| 5322 | /* |
| 5323 | * Create the tabline |
| 5324 | */ |
| 5325 | initialise_tabline(); |
| 5326 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5327 | #ifdef MSWIN_FIND_REPLACE |
| 5328 | /* |
| 5329 | * Initialise the dialog box stuff |
| 5330 | */ |
| 5331 | s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING); |
| 5332 | |
| 5333 | /* Initialise the struct */ |
| 5334 | s_findrep_struct.lStructSize = sizeof(s_findrep_struct); |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 5335 | s_findrep_struct.lpstrFindWhat = ALLOC_MULT(WCHAR, MSWIN_FR_BUFSIZE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5336 | s_findrep_struct.lpstrFindWhat[0] = NUL; |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 5337 | s_findrep_struct.lpstrReplaceWith = ALLOC_MULT(WCHAR, MSWIN_FR_BUFSIZE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5338 | s_findrep_struct.lpstrReplaceWith[0] = NUL; |
| 5339 | s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE; |
| 5340 | s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE; |
| 5341 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5342 | |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 5343 | #ifdef FEAT_EVAL |
Bram Moolenaar | f32c5cd | 2016-01-10 16:07:44 +0100 | [diff] [blame] | 5344 | # if !defined(_MSC_VER) || (_MSC_VER < 1400) |
| 5345 | /* Define HandleToLong for old MS and non-MS compilers if not defined. */ |
| 5346 | # ifndef HandleToLong |
Bram Moolenaar | a87e2c2 | 2016-02-17 20:48:19 +0100 | [diff] [blame] | 5347 | # define HandleToLong(h) ((long)(intptr_t)(h)) |
Bram Moolenaar | f32c5cd | 2016-01-10 16:07:44 +0100 | [diff] [blame] | 5348 | # endif |
Bram Moolenaar | 4da95d3 | 2011-07-07 17:43:41 +0200 | [diff] [blame] | 5349 | # endif |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 5350 | /* set the v:windowid variable */ |
Bram Moolenaar | 7154b32 | 2011-05-25 21:18:06 +0200 | [diff] [blame] | 5351 | set_vim_var_nr(VV_WINDOWID, HandleToLong(s_hwnd)); |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 5352 | #endif |
| 5353 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 5354 | #ifdef FEAT_RENDER_OPTIONS |
| 5355 | if (p_rop) |
| 5356 | (void)gui_mch_set_rendering_options(p_rop); |
| 5357 | #endif |
| 5358 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 5359 | theend: |
| 5360 | /* Display any pending error messages */ |
| 5361 | display_errors(); |
| 5362 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5363 | return OK; |
| 5364 | } |
| 5365 | |
| 5366 | /* |
| 5367 | * Get the size of the screen, taking position on multiple monitors into |
| 5368 | * account (if supported). |
| 5369 | */ |
| 5370 | static void |
| 5371 | get_work_area(RECT *spi_rect) |
| 5372 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5373 | HMONITOR mon; |
| 5374 | MONITORINFO moninfo; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5375 | |
Bram Moolenaar | c4568ab | 2018-11-16 16:21:05 +0100 | [diff] [blame] | 5376 | /* 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] | 5377 | mon = MonitorFromWindow(s_hwnd, MONITOR_DEFAULTTOPRIMARY); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5378 | if (mon != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5379 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5380 | moninfo.cbSize = sizeof(MONITORINFO); |
| 5381 | if (GetMonitorInfo(mon, &moninfo)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5382 | { |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5383 | *spi_rect = moninfo.rcWork; |
| 5384 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5385 | } |
| 5386 | } |
| 5387 | /* this is the old method... */ |
| 5388 | SystemParametersInfo(SPI_GETWORKAREA, 0, spi_rect, 0); |
| 5389 | } |
| 5390 | |
| 5391 | /* |
| 5392 | * Set the size of the window to the given width and height in pixels. |
| 5393 | */ |
| 5394 | void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 5395 | gui_mch_set_shellsize( |
| 5396 | int width, |
| 5397 | int height, |
| 5398 | int min_width UNUSED, |
| 5399 | int min_height UNUSED, |
| 5400 | int base_width UNUSED, |
| 5401 | int base_height UNUSED, |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5402 | int direction) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5403 | { |
| 5404 | RECT workarea_rect; |
| 5405 | int win_width, win_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5406 | WINDOWPLACEMENT wndpl; |
| 5407 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5408 | /* Try to keep window completely on screen. */ |
| 5409 | /* Get position of the screen work area. This is the part that is not |
| 5410 | * used by the taskbar or appbars. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5411 | get_work_area(&workarea_rect); |
| 5412 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 5413 | /* 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] | 5414 | * relative to the work area. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5415 | wndpl.length = sizeof(WINDOWPLACEMENT); |
| 5416 | GetWindowPlacement(s_hwnd, &wndpl); |
| 5417 | |
| 5418 | /* Resizing a maximized window looks very strange, unzoom it first. |
| 5419 | * But don't do it when still starting up, it may have been requested in |
| 5420 | * the shortcut. */ |
| 5421 | if (wndpl.showCmd == SW_SHOWMAXIMIZED && starting == 0) |
| 5422 | { |
| 5423 | ShowWindow(s_hwnd, SW_SHOWNORMAL); |
| 5424 | /* Need to get the settings of the normal window. */ |
| 5425 | GetWindowPlacement(s_hwnd, &wndpl); |
| 5426 | } |
| 5427 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5428 | /* compute the size of the outside of the window */ |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 5429 | win_width = width + (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 5430 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 5431 | win_height = height + (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 5432 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5433 | + GetSystemMetrics(SM_CYCAPTION) |
| 5434 | #ifdef FEAT_MENU |
| 5435 | + gui_mswin_get_menu_height(FALSE) |
| 5436 | #endif |
| 5437 | ; |
| 5438 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5439 | /* The following should take care of keeping Vim on the same monitor, no |
| 5440 | * matter if the secondary monitor is left or right of the primary |
| 5441 | * monitor. */ |
| 5442 | wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + win_width; |
| 5443 | wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + win_height; |
Bram Moolenaar | 56a907a | 2006-05-06 21:44:30 +0000 | [diff] [blame] | 5444 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5445 | /* 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] | 5446 | if ((direction & RESIZE_HOR) |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5447 | && wndpl.rcNormalPosition.right > workarea_rect.right) |
| 5448 | OffsetRect(&wndpl.rcNormalPosition, |
| 5449 | workarea_rect.right - wndpl.rcNormalPosition.right, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5450 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5451 | if ((direction & RESIZE_HOR) |
| 5452 | && wndpl.rcNormalPosition.left < workarea_rect.left) |
| 5453 | OffsetRect(&wndpl.rcNormalPosition, |
| 5454 | workarea_rect.left - wndpl.rcNormalPosition.left, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5455 | |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 5456 | if ((direction & RESIZE_VERT) |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5457 | && wndpl.rcNormalPosition.bottom > workarea_rect.bottom) |
| 5458 | OffsetRect(&wndpl.rcNormalPosition, |
| 5459 | 0, workarea_rect.bottom - wndpl.rcNormalPosition.bottom); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5460 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 5461 | if ((direction & RESIZE_VERT) |
| 5462 | && wndpl.rcNormalPosition.top < workarea_rect.top) |
| 5463 | OffsetRect(&wndpl.rcNormalPosition, |
| 5464 | 0, workarea_rect.top - wndpl.rcNormalPosition.top); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5465 | |
| 5466 | /* set window position - we should use SetWindowPlacement rather than |
| 5467 | * SetWindowPos as the MSDN docs say the coord systems returned by |
| 5468 | * these two are not compatible. */ |
| 5469 | SetWindowPlacement(s_hwnd, &wndpl); |
| 5470 | |
| 5471 | SetActiveWindow(s_hwnd); |
| 5472 | SetFocus(s_hwnd); |
| 5473 | |
| 5474 | #ifdef FEAT_MENU |
| 5475 | /* Menu may wrap differently now */ |
| 5476 | gui_mswin_get_menu_height(!gui.starting); |
| 5477 | #endif |
| 5478 | } |
| 5479 | |
| 5480 | |
| 5481 | void |
| 5482 | gui_mch_set_scrollbar_thumb( |
| 5483 | scrollbar_T *sb, |
| 5484 | long val, |
| 5485 | long size, |
| 5486 | long max) |
| 5487 | { |
| 5488 | SCROLLINFO info; |
| 5489 | |
| 5490 | sb->scroll_shift = 0; |
| 5491 | while (max > 32767) |
| 5492 | { |
| 5493 | max = (max + 1) >> 1; |
| 5494 | val >>= 1; |
| 5495 | size >>= 1; |
| 5496 | ++sb->scroll_shift; |
| 5497 | } |
| 5498 | |
| 5499 | if (sb->scroll_shift > 0) |
| 5500 | ++size; |
| 5501 | |
| 5502 | info.cbSize = sizeof(info); |
| 5503 | info.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; |
| 5504 | info.nPos = val; |
| 5505 | info.nMin = 0; |
| 5506 | info.nMax = max; |
| 5507 | info.nPage = size; |
| 5508 | SetScrollInfo(sb->id, SB_CTL, &info, TRUE); |
| 5509 | } |
| 5510 | |
| 5511 | |
| 5512 | /* |
| 5513 | * Set the current text font. |
| 5514 | */ |
| 5515 | void |
| 5516 | gui_mch_set_font(GuiFont font) |
| 5517 | { |
| 5518 | gui.currFont = font; |
| 5519 | } |
| 5520 | |
| 5521 | |
| 5522 | /* |
| 5523 | * Set the current text foreground color. |
| 5524 | */ |
| 5525 | void |
| 5526 | gui_mch_set_fg_color(guicolor_T color) |
| 5527 | { |
| 5528 | gui.currFgColor = color; |
| 5529 | } |
| 5530 | |
| 5531 | /* |
| 5532 | * Set the current text background color. |
| 5533 | */ |
| 5534 | void |
| 5535 | gui_mch_set_bg_color(guicolor_T color) |
| 5536 | { |
| 5537 | gui.currBgColor = color; |
| 5538 | } |
| 5539 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 5540 | /* |
| 5541 | * Set the current text special color. |
| 5542 | */ |
| 5543 | void |
| 5544 | gui_mch_set_sp_color(guicolor_T color) |
| 5545 | { |
| 5546 | gui.currSpColor = color; |
| 5547 | } |
| 5548 | |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5549 | #ifdef FEAT_MBYTE_IME |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5550 | /* |
| 5551 | * Multi-byte handling, originally by Sung-Hoon Baek. |
| 5552 | * First static functions (no prototypes generated). |
| 5553 | */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5554 | # ifdef _MSC_VER |
Bram Moolenaar | eae1b91 | 2019-05-09 15:12:55 +0200 | [diff] [blame] | 5555 | # include <ime.h> /* Apparently not needed for Cygwin or MinGW. */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5556 | # endif |
| 5557 | # include <imm.h> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5558 | |
| 5559 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5560 | * handle WM_IME_NOTIFY message |
| 5561 | */ |
| 5562 | static LRESULT |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 5563 | _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5564 | { |
| 5565 | LRESULT lResult = 0; |
| 5566 | HIMC hImc; |
| 5567 | |
| 5568 | if (!pImmGetContext || (hImc = pImmGetContext(hWnd)) == (HIMC)0) |
| 5569 | return lResult; |
| 5570 | switch (dwCommand) |
| 5571 | { |
| 5572 | case IMN_SETOPENSTATUS: |
| 5573 | if (pImmGetOpenStatus(hImc)) |
| 5574 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 5575 | pImmSetCompositionFontW(hImc, &norm_logfont); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5576 | im_set_position(gui.row, gui.col); |
| 5577 | |
| 5578 | /* Disable langmap */ |
| 5579 | State &= ~LANGMAP; |
| 5580 | if (State & INSERT) |
| 5581 | { |
Bram Moolenaar | 4033c55 | 2017-09-16 20:54:51 +0200 | [diff] [blame] | 5582 | #if defined(FEAT_KEYMAP) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5583 | /* Unshown 'keymap' in status lines */ |
| 5584 | if (curbuf->b_p_iminsert == B_IMODE_LMAP) |
| 5585 | { |
| 5586 | /* Save cursor position */ |
| 5587 | int old_row = gui.row; |
| 5588 | int old_col = gui.col; |
| 5589 | |
| 5590 | // This must be called here before |
| 5591 | // status_redraw_curbuf(), otherwise the mode |
| 5592 | // message may appear in the wrong position. |
| 5593 | showmode(); |
| 5594 | status_redraw_curbuf(); |
| 5595 | update_screen(0); |
| 5596 | /* Restore cursor position */ |
| 5597 | gui.row = old_row; |
| 5598 | gui.col = old_col; |
| 5599 | } |
| 5600 | #endif |
| 5601 | } |
| 5602 | } |
| 5603 | gui_update_cursor(TRUE, FALSE); |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 5604 | gui_mch_flush(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5605 | lResult = 0; |
| 5606 | break; |
| 5607 | } |
| 5608 | pImmReleaseContext(hWnd, hImc); |
| 5609 | return lResult; |
| 5610 | } |
| 5611 | |
| 5612 | static LRESULT |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 5613 | _OnImeComposition(HWND hwnd, WPARAM dbcs UNUSED, LPARAM param) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5614 | { |
| 5615 | char_u *ret; |
| 5616 | int len; |
| 5617 | |
| 5618 | if ((param & GCS_RESULTSTR) == 0) /* Composition unfinished. */ |
| 5619 | return 0; |
| 5620 | |
| 5621 | ret = GetResultStr(hwnd, GCS_RESULTSTR, &len); |
| 5622 | if (ret != NULL) |
| 5623 | { |
| 5624 | add_to_input_buf_csi(ret, len); |
| 5625 | vim_free(ret); |
| 5626 | return 1; |
| 5627 | } |
| 5628 | return 0; |
| 5629 | } |
| 5630 | |
| 5631 | /* |
| 5632 | * get the current composition string, in UCS-2; *lenp is the number of |
| 5633 | * *lenp is the number of Unicode characters. |
| 5634 | */ |
| 5635 | static short_u * |
| 5636 | GetCompositionString_inUCS2(HIMC hIMC, DWORD GCS, int *lenp) |
| 5637 | { |
| 5638 | LONG ret; |
| 5639 | LPWSTR wbuf = NULL; |
| 5640 | char_u *buf; |
| 5641 | |
| 5642 | if (!pImmGetContext) |
| 5643 | return NULL; /* no imm32.dll */ |
| 5644 | |
| 5645 | /* Try Unicode; this'll always work on NT regardless of codepage. */ |
| 5646 | ret = pImmGetCompositionStringW(hIMC, GCS, NULL, 0); |
| 5647 | if (ret == 0) |
| 5648 | return NULL; /* empty */ |
| 5649 | |
| 5650 | if (ret > 0) |
| 5651 | { |
| 5652 | /* Allocate the requested buffer plus space for the NUL character. */ |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 5653 | wbuf = alloc(ret + sizeof(WCHAR)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5654 | if (wbuf != NULL) |
| 5655 | { |
| 5656 | pImmGetCompositionStringW(hIMC, GCS, wbuf, ret); |
| 5657 | *lenp = ret / sizeof(WCHAR); |
| 5658 | } |
| 5659 | return (short_u *)wbuf; |
| 5660 | } |
| 5661 | |
| 5662 | /* ret < 0; we got an error, so try the ANSI version. This'll work |
| 5663 | * on 9x/ME, but only if the codepage happens to be set to whatever |
| 5664 | * we're inputting. */ |
| 5665 | ret = pImmGetCompositionStringA(hIMC, GCS, NULL, 0); |
| 5666 | if (ret <= 0) |
| 5667 | return NULL; /* empty or error */ |
| 5668 | |
| 5669 | buf = alloc(ret); |
| 5670 | if (buf == NULL) |
| 5671 | return NULL; |
| 5672 | pImmGetCompositionStringA(hIMC, GCS, buf, ret); |
| 5673 | |
| 5674 | /* convert from codepage to UCS-2 */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 5675 | MultiByteToWideChar_alloc(GetACP(), 0, (LPCSTR)buf, ret, &wbuf, lenp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5676 | vim_free(buf); |
| 5677 | |
| 5678 | return (short_u *)wbuf; |
| 5679 | } |
| 5680 | |
| 5681 | /* |
| 5682 | * void GetResultStr() |
| 5683 | * |
| 5684 | * This handles WM_IME_COMPOSITION with GCS_RESULTSTR flag on. |
| 5685 | * get complete composition string |
| 5686 | */ |
| 5687 | static char_u * |
| 5688 | GetResultStr(HWND hwnd, int GCS, int *lenp) |
| 5689 | { |
| 5690 | HIMC hIMC; /* Input context handle. */ |
| 5691 | short_u *buf = NULL; |
| 5692 | char_u *convbuf = NULL; |
| 5693 | |
| 5694 | if (!pImmGetContext || (hIMC = pImmGetContext(hwnd)) == (HIMC)0) |
| 5695 | return NULL; |
| 5696 | |
| 5697 | /* Reads in the composition string. */ |
| 5698 | buf = GetCompositionString_inUCS2(hIMC, GCS, lenp); |
| 5699 | if (buf == NULL) |
| 5700 | return NULL; |
| 5701 | |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 5702 | convbuf = utf16_to_enc(buf, lenp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5703 | pImmReleaseContext(hwnd, hIMC); |
| 5704 | vim_free(buf); |
| 5705 | return convbuf; |
| 5706 | } |
| 5707 | #endif |
| 5708 | |
| 5709 | /* For global functions we need prototypes. */ |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5710 | #if defined(FEAT_MBYTE_IME) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5711 | |
| 5712 | /* |
| 5713 | * set font to IM. |
| 5714 | */ |
| 5715 | void |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 5716 | im_set_font(LOGFONTW *lf) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5717 | { |
| 5718 | HIMC hImc; |
| 5719 | |
| 5720 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 5721 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 5722 | pImmSetCompositionFontW(hImc, lf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5723 | pImmReleaseContext(s_hwnd, hImc); |
| 5724 | } |
| 5725 | } |
| 5726 | |
| 5727 | /* |
| 5728 | * Notify cursor position to IM. |
| 5729 | */ |
| 5730 | void |
| 5731 | im_set_position(int row, int col) |
| 5732 | { |
| 5733 | HIMC hImc; |
| 5734 | |
| 5735 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 5736 | { |
| 5737 | COMPOSITIONFORM cfs; |
| 5738 | |
| 5739 | cfs.dwStyle = CFS_POINT; |
| 5740 | cfs.ptCurrentPos.x = FILL_X(col); |
| 5741 | cfs.ptCurrentPos.y = FILL_Y(row); |
| 5742 | MapWindowPoints(s_textArea, s_hwnd, &cfs.ptCurrentPos, 1); |
| 5743 | pImmSetCompositionWindow(hImc, &cfs); |
| 5744 | |
| 5745 | pImmReleaseContext(s_hwnd, hImc); |
| 5746 | } |
| 5747 | } |
| 5748 | |
| 5749 | /* |
| 5750 | * Set IM status on ("active" is TRUE) or off ("active" is FALSE). |
| 5751 | */ |
| 5752 | void |
| 5753 | im_set_active(int active) |
| 5754 | { |
| 5755 | HIMC hImc; |
| 5756 | static HIMC hImcOld = (HIMC)0; |
| 5757 | |
| 5758 | if (pImmGetContext) /* if NULL imm32.dll wasn't loaded (yet) */ |
| 5759 | { |
| 5760 | if (p_imdisable) |
| 5761 | { |
| 5762 | if (hImcOld == (HIMC)0) |
| 5763 | { |
| 5764 | hImcOld = pImmGetContext(s_hwnd); |
| 5765 | if (hImcOld) |
| 5766 | pImmAssociateContext(s_hwnd, (HIMC)0); |
| 5767 | } |
| 5768 | active = FALSE; |
| 5769 | } |
| 5770 | else if (hImcOld != (HIMC)0) |
| 5771 | { |
| 5772 | pImmAssociateContext(s_hwnd, hImcOld); |
| 5773 | hImcOld = (HIMC)0; |
| 5774 | } |
| 5775 | |
| 5776 | hImc = pImmGetContext(s_hwnd); |
| 5777 | if (hImc) |
| 5778 | { |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 5779 | /* |
| 5780 | * for Korean ime |
| 5781 | */ |
| 5782 | HKL hKL = GetKeyboardLayout(0); |
| 5783 | |
| 5784 | if (LOWORD(hKL) == MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN)) |
| 5785 | { |
| 5786 | static DWORD dwConversionSaved = 0, dwSentenceSaved = 0; |
| 5787 | static BOOL bSaved = FALSE; |
| 5788 | |
| 5789 | if (active) |
| 5790 | { |
| 5791 | /* if we have a saved conversion status, restore it */ |
| 5792 | if (bSaved) |
| 5793 | pImmSetConversionStatus(hImc, dwConversionSaved, |
| 5794 | dwSentenceSaved); |
| 5795 | bSaved = FALSE; |
| 5796 | } |
| 5797 | else |
| 5798 | { |
| 5799 | /* save conversion status and disable korean */ |
| 5800 | if (pImmGetConversionStatus(hImc, &dwConversionSaved, |
| 5801 | &dwSentenceSaved)) |
| 5802 | { |
| 5803 | bSaved = TRUE; |
| 5804 | pImmSetConversionStatus(hImc, |
| 5805 | dwConversionSaved & ~(IME_CMODE_NATIVE |
| 5806 | | IME_CMODE_FULLSHAPE), |
| 5807 | dwSentenceSaved); |
| 5808 | } |
| 5809 | } |
| 5810 | } |
| 5811 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5812 | pImmSetOpenStatus(hImc, active); |
| 5813 | pImmReleaseContext(s_hwnd, hImc); |
| 5814 | } |
| 5815 | } |
| 5816 | } |
| 5817 | |
| 5818 | /* |
| 5819 | * Get IM status. When IM is on, return not 0. Else return 0. |
| 5820 | */ |
| 5821 | int |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 5822 | im_get_status(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5823 | { |
| 5824 | int status = 0; |
| 5825 | HIMC hImc; |
| 5826 | |
| 5827 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 5828 | { |
| 5829 | status = pImmGetOpenStatus(hImc) ? 1 : 0; |
| 5830 | pImmReleaseContext(s_hwnd, hImc); |
| 5831 | } |
| 5832 | return status; |
| 5833 | } |
| 5834 | |
Bram Moolenaar | bdb8139 | 2017-11-27 23:24:08 +0100 | [diff] [blame] | 5835 | #endif /* FEAT_MBYTE_IME */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5836 | |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 5837 | #if !defined(FEAT_MBYTE_IME) && defined(GLOBAL_IME) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5838 | /* Win32 with GLOBAL IME */ |
| 5839 | |
| 5840 | /* |
| 5841 | * Notify cursor position to IM. |
| 5842 | */ |
| 5843 | void |
| 5844 | im_set_position(int row, int col) |
| 5845 | { |
| 5846 | /* Win32 with GLOBAL IME */ |
| 5847 | POINT p; |
| 5848 | |
| 5849 | p.x = FILL_X(col); |
| 5850 | p.y = FILL_Y(row); |
| 5851 | MapWindowPoints(s_textArea, s_hwnd, &p, 1); |
| 5852 | global_ime_set_position(&p); |
| 5853 | } |
| 5854 | |
| 5855 | /* |
| 5856 | * Set IM status on ("active" is TRUE) or off ("active" is FALSE). |
| 5857 | */ |
| 5858 | void |
| 5859 | im_set_active(int active) |
| 5860 | { |
| 5861 | global_ime_set_status(active); |
| 5862 | } |
| 5863 | |
| 5864 | /* |
| 5865 | * Get IM status. When IM is on, return not 0. Else return 0. |
| 5866 | */ |
| 5867 | int |
Bram Moolenaar | d14e00e | 2016-01-31 17:30:51 +0100 | [diff] [blame] | 5868 | im_get_status(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5869 | { |
| 5870 | return global_ime_get_status(); |
| 5871 | } |
| 5872 | #endif |
| 5873 | |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 5874 | /* |
Bram Moolenaar | 39f0563 | 2006-03-19 22:15:26 +0000 | [diff] [blame] | 5875 | * Convert latin9 text "text[len]" to ucs-2 in "unicodebuf". |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 5876 | */ |
| 5877 | static void |
| 5878 | latin9_to_ucs(char_u *text, int len, WCHAR *unicodebuf) |
| 5879 | { |
| 5880 | int c; |
| 5881 | |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 5882 | while (--len >= 0) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 5883 | { |
| 5884 | c = *text++; |
| 5885 | switch (c) |
| 5886 | { |
| 5887 | case 0xa4: c = 0x20ac; break; /* euro */ |
| 5888 | case 0xa6: c = 0x0160; break; /* S hat */ |
| 5889 | case 0xa8: c = 0x0161; break; /* S -hat */ |
| 5890 | case 0xb4: c = 0x017d; break; /* Z hat */ |
| 5891 | case 0xb8: c = 0x017e; break; /* Z -hat */ |
| 5892 | case 0xbc: c = 0x0152; break; /* OE */ |
| 5893 | case 0xbd: c = 0x0153; break; /* oe */ |
| 5894 | case 0xbe: c = 0x0178; break; /* Y */ |
| 5895 | } |
| 5896 | *unicodebuf++ = c; |
| 5897 | } |
| 5898 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5899 | |
| 5900 | #ifdef FEAT_RIGHTLEFT |
| 5901 | /* |
| 5902 | * What is this for? In the case where you are using Win98 or Win2K or later, |
| 5903 | * and you are using a Hebrew font (or Arabic!), Windows does you a favor and |
| 5904 | * reverses the string sent to the TextOut... family. This sucks, because we |
| 5905 | * go to a lot of effort to do the right thing, and there doesn't seem to be a |
| 5906 | * way to tell Windblows not to do this! |
| 5907 | * |
| 5908 | * The short of it is that this 'RevOut' only gets called if you are running |
| 5909 | * one of the new, "improved" MS OSes, and only if you are running in |
| 5910 | * 'rightleft' mode. It makes display take *slightly* longer, but not |
| 5911 | * noticeably so. |
| 5912 | */ |
| 5913 | static void |
| 5914 | RevOut( HDC s_hdc, |
| 5915 | int col, |
| 5916 | int row, |
| 5917 | UINT foptions, |
| 5918 | CONST RECT *pcliprect, |
| 5919 | LPCTSTR text, |
| 5920 | UINT len, |
| 5921 | CONST INT *padding) |
| 5922 | { |
| 5923 | int ix; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5924 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 5925 | for (ix = 0; ix < (int)len; ++ix) |
| 5926 | ExtTextOut(s_hdc, col + TEXT_X(ix), row, foptions, |
| 5927 | pcliprect, text + ix, 1, padding); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5928 | } |
| 5929 | #endif |
| 5930 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 5931 | static void |
| 5932 | draw_line( |
| 5933 | int x1, |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 5934 | int y1, |
| 5935 | int x2, |
| 5936 | int y2, |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 5937 | COLORREF color) |
| 5938 | { |
| 5939 | #if defined(FEAT_DIRECTX) |
| 5940 | if (IS_ENABLE_DIRECTX()) |
| 5941 | DWriteContext_DrawLine(s_dwc, x1, y1, x2, y2, color); |
| 5942 | else |
| 5943 | #endif |
| 5944 | { |
| 5945 | HPEN hpen = CreatePen(PS_SOLID, 1, color); |
| 5946 | HPEN old_pen = SelectObject(s_hdc, hpen); |
| 5947 | MoveToEx(s_hdc, x1, y1, NULL); |
| 5948 | /* Note: LineTo() excludes the last pixel in the line. */ |
| 5949 | LineTo(s_hdc, x2, y2); |
| 5950 | DeleteObject(SelectObject(s_hdc, old_pen)); |
| 5951 | } |
| 5952 | } |
| 5953 | |
| 5954 | static void |
| 5955 | set_pixel( |
| 5956 | int x, |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 5957 | int y, |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 5958 | COLORREF color) |
| 5959 | { |
| 5960 | #if defined(FEAT_DIRECTX) |
| 5961 | if (IS_ENABLE_DIRECTX()) |
| 5962 | DWriteContext_SetPixel(s_dwc, x, y, color); |
| 5963 | else |
| 5964 | #endif |
| 5965 | SetPixel(s_hdc, x, y, color); |
| 5966 | } |
| 5967 | |
| 5968 | static void |
| 5969 | fill_rect( |
| 5970 | const RECT *rcp, |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 5971 | HBRUSH hbr, |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 5972 | COLORREF color) |
| 5973 | { |
| 5974 | #if defined(FEAT_DIRECTX) |
| 5975 | if (IS_ENABLE_DIRECTX()) |
| 5976 | DWriteContext_FillRect(s_dwc, rcp, color); |
| 5977 | else |
| 5978 | #endif |
| 5979 | { |
| 5980 | HBRUSH hbr2; |
| 5981 | |
| 5982 | if (hbr == NULL) |
| 5983 | hbr2 = CreateSolidBrush(color); |
| 5984 | else |
| 5985 | hbr2 = hbr; |
| 5986 | FillRect(s_hdc, rcp, hbr2); |
| 5987 | if (hbr == NULL) |
| 5988 | DeleteBrush(hbr2); |
| 5989 | } |
| 5990 | } |
| 5991 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5992 | void |
| 5993 | gui_mch_draw_string( |
| 5994 | int row, |
| 5995 | int col, |
| 5996 | char_u *text, |
| 5997 | int len, |
| 5998 | int flags) |
| 5999 | { |
| 6000 | static int *padding = NULL; |
| 6001 | static int pad_size = 0; |
| 6002 | int i; |
| 6003 | const RECT *pcliprect = NULL; |
| 6004 | UINT foptions = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6005 | static WCHAR *unicodebuf = NULL; |
| 6006 | static int *unicodepdy = NULL; |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6007 | static int unibuflen = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6008 | int n = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6009 | int y; |
| 6010 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6011 | /* |
| 6012 | * Italic and bold text seems to have an extra row of pixels at the bottom |
| 6013 | * (below where the bottom of the character should be). If we draw the |
| 6014 | * characters with a solid background, the top row of pixels in the |
| 6015 | * character below will be overwritten. We can fix this by filling in the |
| 6016 | * background ourselves, to the correct character proportions, and then |
| 6017 | * writing the character in transparent mode. Still have a problem when |
| 6018 | * the character is "_", which gets written on to the character below. |
| 6019 | * New fix: set gui.char_ascent to -1. This shifts all characters up one |
| 6020 | * pixel in their slots, which fixes the problem with the bottom row of |
| 6021 | * pixels. We still need this code because otherwise the top row of pixels |
| 6022 | * becomes a problem. - webb. |
| 6023 | */ |
| 6024 | static HBRUSH hbr_cache[2] = {NULL, NULL}; |
| 6025 | static guicolor_T brush_color[2] = {INVALCOLOR, INVALCOLOR}; |
| 6026 | static int brush_lru = 0; |
| 6027 | HBRUSH hbr; |
| 6028 | RECT rc; |
| 6029 | |
| 6030 | if (!(flags & DRAW_TRANSP)) |
| 6031 | { |
| 6032 | /* |
| 6033 | * Clear background first. |
| 6034 | * Note: FillRect() excludes right and bottom of rectangle. |
| 6035 | */ |
| 6036 | rc.left = FILL_X(col); |
| 6037 | rc.top = FILL_Y(row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6038 | if (has_mbyte) |
| 6039 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6040 | /* Compute the length in display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6041 | rc.right = FILL_X(col + mb_string2cells(text, len)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6042 | } |
| 6043 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6044 | rc.right = FILL_X(col + len); |
| 6045 | rc.bottom = FILL_Y(row + 1); |
| 6046 | |
| 6047 | /* Cache the created brush, that saves a lot of time. We need two: |
| 6048 | * one for cursor background and one for the normal background. */ |
| 6049 | if (gui.currBgColor == brush_color[0]) |
| 6050 | { |
| 6051 | hbr = hbr_cache[0]; |
| 6052 | brush_lru = 1; |
| 6053 | } |
| 6054 | else if (gui.currBgColor == brush_color[1]) |
| 6055 | { |
| 6056 | hbr = hbr_cache[1]; |
| 6057 | brush_lru = 0; |
| 6058 | } |
| 6059 | else |
| 6060 | { |
| 6061 | if (hbr_cache[brush_lru] != NULL) |
| 6062 | DeleteBrush(hbr_cache[brush_lru]); |
| 6063 | hbr_cache[brush_lru] = CreateSolidBrush(gui.currBgColor); |
| 6064 | brush_color[brush_lru] = gui.currBgColor; |
| 6065 | hbr = hbr_cache[brush_lru]; |
| 6066 | brush_lru = !brush_lru; |
| 6067 | } |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6068 | |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6069 | fill_rect(&rc, hbr, gui.currBgColor); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6070 | |
| 6071 | SetBkMode(s_hdc, TRANSPARENT); |
| 6072 | |
| 6073 | /* |
| 6074 | * When drawing block cursor, prevent inverted character spilling |
| 6075 | * over character cell (can happen with bold/italic) |
| 6076 | */ |
| 6077 | if (flags & DRAW_CURSOR) |
| 6078 | { |
| 6079 | pcliprect = &rc; |
| 6080 | foptions = ETO_CLIPPED; |
| 6081 | } |
| 6082 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6083 | SetTextColor(s_hdc, gui.currFgColor); |
| 6084 | SelectFont(s_hdc, gui.currFont); |
| 6085 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6086 | #ifdef FEAT_DIRECTX |
| 6087 | if (IS_ENABLE_DIRECTX()) |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6088 | DWriteContext_SetFont(s_dwc, (HFONT)gui.currFont); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6089 | #endif |
| 6090 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6091 | if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width) |
| 6092 | { |
| 6093 | vim_free(padding); |
| 6094 | pad_size = Columns; |
| 6095 | |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 6096 | /* Don't give an out-of-memory message here, it would call us |
| 6097 | * recursively. */ |
Bram Moolenaar | 59edb00 | 2019-05-28 23:32:47 +0200 | [diff] [blame] | 6098 | padding = LALLOC_MULT(int, pad_size); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6099 | if (padding != NULL) |
| 6100 | for (i = 0; i < pad_size; i++) |
| 6101 | padding[i] = gui.char_width; |
| 6102 | } |
| 6103 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6104 | /* |
| 6105 | * We have to provide the padding argument because italic and bold versions |
| 6106 | * of fixed-width fonts are often one pixel or so wider than their normal |
| 6107 | * versions. |
| 6108 | * No check for DRAW_BOLD, Windows will have done it already. |
| 6109 | */ |
| 6110 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6111 | /* Check if there are any UTF-8 characters. If not, use normal text |
| 6112 | * output to speed up output. */ |
| 6113 | if (enc_utf8) |
| 6114 | for (n = 0; n < len; ++n) |
| 6115 | if (text[n] >= 0x80) |
| 6116 | break; |
| 6117 | |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 6118 | #if defined(FEAT_DIRECTX) |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6119 | /* Quick hack to enable DirectWrite. To use DirectWrite (antialias), it is |
| 6120 | * required that unicode drawing routine, currently. So this forces it |
| 6121 | * enabled. */ |
Bram Moolenaar | 7f88b65 | 2017-12-14 13:15:19 +0100 | [diff] [blame] | 6122 | if (IS_ENABLE_DIRECTX()) |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6123 | n = 0; /* Keep n < len, to enter block for unicode. */ |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 6124 | #endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6125 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6126 | /* Check if the Unicode buffer exists and is big enough. Create it |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 6127 | * 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] | 6128 | * characters is always equal or smaller. */ |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6129 | if ((enc_utf8 |
| 6130 | || (enc_codepage > 0 && (int)GetACP() != enc_codepage) |
| 6131 | || enc_latin9) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6132 | && (unicodebuf == NULL || len > unibuflen)) |
| 6133 | { |
| 6134 | vim_free(unicodebuf); |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6135 | unicodebuf = LALLOC_MULT(WCHAR, len); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6136 | |
| 6137 | vim_free(unicodepdy); |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6138 | unicodepdy = LALLOC_MULT(int, len); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6139 | |
| 6140 | unibuflen = len; |
| 6141 | } |
| 6142 | |
| 6143 | if (enc_utf8 && n < len && unicodebuf != NULL) |
| 6144 | { |
Bram Moolenaar | a6ce1cc | 2017-10-28 19:23:11 +0200 | [diff] [blame] | 6145 | /* Output UTF-8 characters. Composing characters should be |
| 6146 | * handled here. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6147 | int i; |
| 6148 | int wlen; /* string length in words */ |
| 6149 | int clen; /* string length in characters */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6150 | int cells; /* cell width of string up to composing char */ |
| 6151 | int cw; /* width of current cell */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6152 | int c; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6153 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 6154 | wlen = 0; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6155 | clen = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6156 | cells = 0; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6157 | for (i = 0; i < len; ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6158 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6159 | c = utf_ptr2char(text + i); |
| 6160 | if (c >= 0x10000) |
| 6161 | { |
| 6162 | /* Turn into UTF-16 encoding. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6163 | unicodebuf[wlen++] = ((c - 0x10000) >> 10) + 0xD800; |
| 6164 | unicodebuf[wlen++] = ((c - 0x10000) & 0x3ff) + 0xDC00; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6165 | } |
| 6166 | else |
| 6167 | { |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6168 | unicodebuf[wlen++] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6169 | } |
Bram Moolenaar | a6ce1cc | 2017-10-28 19:23:11 +0200 | [diff] [blame] | 6170 | |
| 6171 | if (utf_iscomposing(c)) |
| 6172 | cw = 0; |
| 6173 | else |
| 6174 | { |
| 6175 | cw = utf_char2cells(c); |
| 6176 | if (cw > 2) /* don't use 4 for unprintable char */ |
| 6177 | cw = 1; |
| 6178 | } |
| 6179 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6180 | if (unicodepdy != NULL) |
| 6181 | { |
| 6182 | /* Use unicodepdy to make characters fit as we expect, even |
| 6183 | * when the font uses different widths (e.g., bold character |
| 6184 | * is wider). */ |
Bram Moolenaar | d804fdf | 2016-02-27 16:04:58 +0100 | [diff] [blame] | 6185 | if (c >= 0x10000) |
| 6186 | { |
| 6187 | unicodepdy[wlen - 2] = cw * gui.char_width; |
| 6188 | unicodepdy[wlen - 1] = 0; |
| 6189 | } |
| 6190 | else |
| 6191 | unicodepdy[wlen - 1] = cw * gui.char_width; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6192 | } |
| 6193 | cells += cw; |
Bram Moolenaar | a6ce1cc | 2017-10-28 19:23:11 +0200 | [diff] [blame] | 6194 | i += utf_ptr2len_len(text + i, len - i); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 6195 | ++clen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6196 | } |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 6197 | #if defined(FEAT_DIRECTX) |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6198 | if (IS_ENABLE_DIRECTX()) |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6199 | { |
Bram Moolenaar | 9b352c4 | 2014-08-06 16:49:55 +0200 | [diff] [blame] | 6200 | /* Add one to "cells" for italics. */ |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6201 | DWriteContext_DrawText(s_dwc, unicodebuf, wlen, |
Bram Moolenaar | 60ebd52 | 2019-03-21 20:50:12 +0100 | [diff] [blame] | 6202 | TEXT_X(col), TEXT_Y(row), |
| 6203 | FILL_X(cells + 1), FILL_Y(1) - p_linespace, |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6204 | gui.char_width, gui.currFgColor, |
| 6205 | foptions, pcliprect, unicodepdy); |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6206 | } |
| 6207 | else |
Bram Moolenaar | fc3abf4 | 2019-01-24 15:54:21 +0100 | [diff] [blame] | 6208 | #endif |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6209 | ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 6210 | foptions, pcliprect, unicodebuf, wlen, unicodepdy); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6211 | len = cells; /* used for underlining */ |
| 6212 | } |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6213 | else if ((enc_codepage > 0 && (int)GetACP() != enc_codepage) || enc_latin9) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6214 | { |
| 6215 | /* If we want to display codepage data, and the current CP is not the |
| 6216 | * ANSI one, we need to go via Unicode. */ |
| 6217 | if (unicodebuf != NULL) |
| 6218 | { |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 6219 | if (enc_latin9) |
| 6220 | latin9_to_ucs(text, len, unicodebuf); |
| 6221 | else |
| 6222 | len = MultiByteToWideChar(enc_codepage, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6223 | MB_PRECOMPOSED, |
| 6224 | (char *)text, len, |
| 6225 | (LPWSTR)unicodebuf, unibuflen); |
| 6226 | if (len != 0) |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 6227 | { |
| 6228 | /* Use unicodepdy to make characters fit as we expect, even |
| 6229 | * when the font uses different widths (e.g., bold character |
| 6230 | * is wider). */ |
| 6231 | if (unicodepdy != NULL) |
| 6232 | { |
| 6233 | int i; |
| 6234 | int cw; |
| 6235 | |
| 6236 | for (i = 0; i < len; ++i) |
| 6237 | { |
| 6238 | cw = utf_char2cells(unicodebuf[i]); |
| 6239 | if (cw > 2) |
| 6240 | cw = 1; |
| 6241 | unicodepdy[i] = cw * gui.char_width; |
| 6242 | } |
| 6243 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6244 | ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row), |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 6245 | foptions, pcliprect, unicodebuf, len, unicodepdy); |
| 6246 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6247 | } |
| 6248 | } |
| 6249 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6250 | { |
| 6251 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4ee40b0 | 2014-09-19 16:13:53 +0200 | [diff] [blame] | 6252 | /* Windows will mess up RL text, so we have to draw it character by |
| 6253 | * character. Only do this if RL is on, since it's slow. */ |
| 6254 | if (curwin->w_p_rl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6255 | RevOut(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 6256 | foptions, pcliprect, (char *)text, len, padding); |
| 6257 | else |
| 6258 | #endif |
| 6259 | ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 6260 | foptions, pcliprect, (char *)text, len, padding); |
| 6261 | } |
| 6262 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6263 | /* Underline */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6264 | if (flags & DRAW_UNDERL) |
| 6265 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6266 | /* When p_linespace is 0, overwrite the bottom row of pixels. |
| 6267 | * Otherwise put the line just below the character. */ |
| 6268 | y = FILL_Y(row + 1) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6269 | if (p_linespace > 1) |
| 6270 | y -= p_linespace - 1; |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6271 | 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] | 6272 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6273 | |
Bram Moolenaar | cf4b00c | 2017-09-02 18:33:56 +0200 | [diff] [blame] | 6274 | /* Strikethrough */ |
| 6275 | if (flags & DRAW_STRIKE) |
| 6276 | { |
Bram Moolenaar | cf4b00c | 2017-09-02 18:33:56 +0200 | [diff] [blame] | 6277 | y = FILL_Y(row + 1) - gui.char_height/2; |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6278 | 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] | 6279 | } |
| 6280 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6281 | /* Undercurl */ |
| 6282 | if (flags & DRAW_UNDERC) |
| 6283 | { |
| 6284 | int x; |
| 6285 | int offset; |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 6286 | 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] | 6287 | |
| 6288 | y = FILL_Y(row + 1) - 1; |
| 6289 | for (x = FILL_X(col); x < FILL_X(col + len); ++x) |
| 6290 | { |
| 6291 | offset = val[x % 8]; |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6292 | set_pixel(x, y - offset, gui.currSpColor); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 6293 | } |
| 6294 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6295 | } |
| 6296 | |
| 6297 | |
| 6298 | /* |
| 6299 | * Output routines. |
| 6300 | */ |
| 6301 | |
| 6302 | /* Flush any output to the screen */ |
| 6303 | void |
| 6304 | gui_mch_flush(void) |
| 6305 | { |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 6306 | #if defined(FEAT_DIRECTX) |
| 6307 | if (IS_ENABLE_DIRECTX()) |
| 6308 | DWriteContext_Flush(s_dwc); |
| 6309 | #endif |
| 6310 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6311 | GdiFlush(); |
| 6312 | } |
| 6313 | |
| 6314 | static void |
| 6315 | clear_rect(RECT *rcp) |
| 6316 | { |
Bram Moolenaar | 92467d3 | 2017-12-05 13:22:16 +0100 | [diff] [blame] | 6317 | fill_rect(rcp, NULL, gui.back_pixel); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6318 | } |
| 6319 | |
| 6320 | |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6321 | void |
| 6322 | gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) |
| 6323 | { |
| 6324 | RECT workarea_rect; |
| 6325 | |
| 6326 | get_work_area(&workarea_rect); |
| 6327 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6328 | *screen_w = workarea_rect.right - workarea_rect.left |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 6329 | - (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6330 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6331 | |
| 6332 | /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include |
| 6333 | * the menubar for MSwin, we subtract it from the screen height, so that |
| 6334 | * the window size can be made to fit on the screen. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6335 | *screen_h = workarea_rect.bottom - workarea_rect.top |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 6336 | - (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6337 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6338 | - GetSystemMetrics(SM_CYCAPTION) |
| 6339 | #ifdef FEAT_MENU |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 6340 | - gui_mswin_get_menu_height(FALSE) |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6341 | #endif |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 6342 | ; |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6346 | #if defined(FEAT_MENU) || defined(PROTO) |
| 6347 | /* |
| 6348 | * Add a sub menu to the menu bar. |
| 6349 | */ |
| 6350 | void |
| 6351 | gui_mch_add_menu( |
| 6352 | vimmenu_T *menu, |
| 6353 | int pos) |
| 6354 | { |
| 6355 | vimmenu_T *parent = menu->parent; |
| 6356 | |
| 6357 | menu->submenu_id = CreatePopupMenu(); |
| 6358 | menu->id = s_menu_id++; |
| 6359 | |
| 6360 | if (menu_is_menubar(menu->name)) |
| 6361 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6362 | WCHAR *wn; |
| 6363 | MENUITEMINFOW infow; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6364 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6365 | wn = enc_to_utf16(menu->name, NULL); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 6366 | if (wn == NULL) |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6367 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6368 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6369 | infow.cbSize = sizeof(infow); |
| 6370 | infow.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID |
| 6371 | | MIIM_SUBMENU; |
| 6372 | infow.dwItemData = (long_u)menu; |
| 6373 | infow.wID = menu->id; |
| 6374 | infow.fType = MFT_STRING; |
| 6375 | infow.dwTypeData = wn; |
| 6376 | infow.cch = (UINT)wcslen(wn); |
| 6377 | infow.hSubMenu = menu->submenu_id; |
| 6378 | InsertMenuItemW((parent == NULL) |
| 6379 | ? s_menuBar : parent->submenu_id, |
| 6380 | (UINT)pos, TRUE, &infow); |
| 6381 | vim_free(wn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6382 | } |
| 6383 | |
| 6384 | /* Fix window size if menu may have wrapped */ |
| 6385 | if (parent == NULL) |
| 6386 | gui_mswin_get_menu_height(!gui.starting); |
| 6387 | #ifdef FEAT_TEAROFF |
| 6388 | else if (IsWindow(parent->tearoff_handle)) |
| 6389 | rebuild_tearoff(parent); |
| 6390 | #endif |
| 6391 | } |
| 6392 | |
| 6393 | void |
| 6394 | gui_mch_show_popupmenu(vimmenu_T *menu) |
| 6395 | { |
| 6396 | POINT mp; |
| 6397 | |
| 6398 | (void)GetCursorPos((LPPOINT)&mp); |
| 6399 | gui_mch_show_popupmenu_at(menu, (int)mp.x, (int)mp.y); |
| 6400 | } |
| 6401 | |
| 6402 | void |
Bram Moolenaar | 045e82d | 2005-07-08 22:25:33 +0000 | [diff] [blame] | 6403 | gui_make_popup(char_u *path_name, int mouse_pos) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6404 | { |
| 6405 | vimmenu_T *menu = gui_find_menu(path_name); |
| 6406 | |
| 6407 | if (menu != NULL) |
| 6408 | { |
| 6409 | POINT p; |
| 6410 | |
| 6411 | /* Find the position of the current cursor */ |
| 6412 | GetDCOrgEx(s_hdc, &p); |
Bram Moolenaar | 045e82d | 2005-07-08 22:25:33 +0000 | [diff] [blame] | 6413 | if (mouse_pos) |
| 6414 | { |
| 6415 | int mx, my; |
| 6416 | |
| 6417 | gui_mch_getmouse(&mx, &my); |
| 6418 | p.x += mx; |
| 6419 | p.y += my; |
| 6420 | } |
| 6421 | else if (curwin != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6422 | { |
Bram Moolenaar | 53f8174 | 2017-09-22 14:35:51 +0200 | [diff] [blame] | 6423 | p.x += TEXT_X(curwin->w_wincol + curwin->w_wcol + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6424 | p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1); |
| 6425 | } |
| 6426 | msg_scroll = FALSE; |
| 6427 | gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y); |
| 6428 | } |
| 6429 | } |
| 6430 | |
| 6431 | #if defined(FEAT_TEAROFF) || defined(PROTO) |
| 6432 | /* |
| 6433 | * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and |
| 6434 | * create it as a pseudo-"tearoff menu". |
| 6435 | */ |
| 6436 | void |
| 6437 | gui_make_tearoff(char_u *path_name) |
| 6438 | { |
| 6439 | vimmenu_T *menu = gui_find_menu(path_name); |
| 6440 | |
| 6441 | /* Found the menu, so tear it off. */ |
| 6442 | if (menu != NULL) |
| 6443 | gui_mch_tearoff(menu->dname, menu, 0xffffL, 0xffffL); |
| 6444 | } |
| 6445 | #endif |
| 6446 | |
| 6447 | /* |
| 6448 | * Add a menu item to a menu |
| 6449 | */ |
| 6450 | void |
| 6451 | gui_mch_add_menu_item( |
| 6452 | vimmenu_T *menu, |
| 6453 | int idx) |
| 6454 | { |
| 6455 | vimmenu_T *parent = menu->parent; |
| 6456 | |
| 6457 | menu->id = s_menu_id++; |
| 6458 | menu->submenu_id = NULL; |
| 6459 | |
| 6460 | #ifdef FEAT_TEAROFF |
| 6461 | if (STRNCMP(menu->name, TEAR_STRING, TEAR_LEN) == 0) |
| 6462 | { |
| 6463 | InsertMenu(parent->submenu_id, (UINT)idx, MF_BITMAP|MF_BYPOSITION, |
| 6464 | (UINT)menu->id, (LPCTSTR) s_htearbitmap); |
| 6465 | } |
| 6466 | else |
| 6467 | #endif |
| 6468 | #ifdef FEAT_TOOLBAR |
| 6469 | if (menu_is_toolbar(parent->name)) |
| 6470 | { |
| 6471 | TBBUTTON newtb; |
| 6472 | |
| 6473 | vim_memset(&newtb, 0, sizeof(newtb)); |
| 6474 | if (menu_is_separator(menu->name)) |
| 6475 | { |
| 6476 | newtb.iBitmap = 0; |
| 6477 | newtb.fsStyle = TBSTYLE_SEP; |
| 6478 | } |
| 6479 | else |
| 6480 | { |
| 6481 | newtb.iBitmap = get_toolbar_bitmap(menu); |
| 6482 | newtb.fsStyle = TBSTYLE_BUTTON; |
| 6483 | } |
| 6484 | newtb.idCommand = menu->id; |
| 6485 | newtb.fsState = TBSTATE_ENABLED; |
| 6486 | newtb.iString = 0; |
| 6487 | SendMessage(s_toolbarhwnd, TB_INSERTBUTTON, (WPARAM)idx, |
| 6488 | (LPARAM)&newtb); |
| 6489 | menu->submenu_id = (HMENU)-1; |
| 6490 | } |
| 6491 | else |
| 6492 | #endif |
| 6493 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6494 | WCHAR *wn; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6495 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6496 | wn = enc_to_utf16(menu->name, NULL); |
| 6497 | if (wn != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6498 | { |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6499 | InsertMenuW(parent->submenu_id, (UINT)idx, |
| 6500 | (menu_is_separator(menu->name) |
| 6501 | ? MF_SEPARATOR : MF_STRING) | MF_BYPOSITION, |
| 6502 | (UINT)menu->id, wn); |
| 6503 | vim_free(wn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6504 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6505 | #ifdef FEAT_TEAROFF |
| 6506 | if (IsWindow(parent->tearoff_handle)) |
| 6507 | rebuild_tearoff(parent); |
| 6508 | #endif |
| 6509 | } |
| 6510 | } |
| 6511 | |
| 6512 | /* |
| 6513 | * Destroy the machine specific menu widget. |
| 6514 | */ |
| 6515 | void |
| 6516 | gui_mch_destroy_menu(vimmenu_T *menu) |
| 6517 | { |
| 6518 | #ifdef FEAT_TOOLBAR |
| 6519 | /* |
| 6520 | * is this a toolbar button? |
| 6521 | */ |
| 6522 | if (menu->submenu_id == (HMENU)-1) |
| 6523 | { |
| 6524 | int iButton; |
| 6525 | |
| 6526 | iButton = (int)SendMessage(s_toolbarhwnd, TB_COMMANDTOINDEX, |
| 6527 | (WPARAM)menu->id, 0); |
| 6528 | SendMessage(s_toolbarhwnd, TB_DELETEBUTTON, (WPARAM)iButton, 0); |
| 6529 | } |
| 6530 | else |
| 6531 | #endif |
| 6532 | { |
| 6533 | if (menu->parent != NULL |
| 6534 | && menu_is_popup(menu->parent->dname) |
| 6535 | && menu->parent->submenu_id != NULL) |
| 6536 | RemoveMenu(menu->parent->submenu_id, menu->id, MF_BYCOMMAND); |
| 6537 | else |
| 6538 | RemoveMenu(s_menuBar, menu->id, MF_BYCOMMAND); |
| 6539 | if (menu->submenu_id != NULL) |
| 6540 | DestroyMenu(menu->submenu_id); |
| 6541 | #ifdef FEAT_TEAROFF |
| 6542 | if (IsWindow(menu->tearoff_handle)) |
| 6543 | DestroyWindow(menu->tearoff_handle); |
| 6544 | if (menu->parent != NULL |
| 6545 | && menu->parent->children != NULL |
| 6546 | && IsWindow(menu->parent->tearoff_handle)) |
| 6547 | { |
| 6548 | /* This menu must not show up when rebuilding the tearoff window. */ |
| 6549 | menu->modes = 0; |
| 6550 | rebuild_tearoff(menu->parent); |
| 6551 | } |
| 6552 | #endif |
| 6553 | } |
| 6554 | } |
| 6555 | |
| 6556 | #ifdef FEAT_TEAROFF |
| 6557 | static void |
| 6558 | rebuild_tearoff(vimmenu_T *menu) |
| 6559 | { |
| 6560 | /*hackish*/ |
| 6561 | char_u tbuf[128]; |
| 6562 | RECT trect; |
| 6563 | RECT rct; |
| 6564 | RECT roct; |
| 6565 | int x, y; |
| 6566 | |
| 6567 | HWND thwnd = menu->tearoff_handle; |
| 6568 | |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 6569 | GetWindowText(thwnd, (LPSTR)tbuf, 127); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6570 | if (GetWindowRect(thwnd, &trect) |
| 6571 | && GetWindowRect(s_hwnd, &rct) |
| 6572 | && GetClientRect(s_hwnd, &roct)) |
| 6573 | { |
| 6574 | x = trect.left - rct.left; |
| 6575 | y = (trect.top - rct.bottom + roct.bottom); |
| 6576 | } |
| 6577 | else |
| 6578 | { |
| 6579 | x = y = 0xffffL; |
| 6580 | } |
| 6581 | DestroyWindow(thwnd); |
| 6582 | if (menu->children != NULL) |
| 6583 | { |
| 6584 | gui_mch_tearoff(tbuf, menu, x, y); |
| 6585 | if (IsWindow(menu->tearoff_handle)) |
| 6586 | (void) SetWindowPos(menu->tearoff_handle, |
| 6587 | NULL, |
| 6588 | (int)trect.left, |
| 6589 | (int)trect.top, |
| 6590 | 0, 0, |
| 6591 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
| 6592 | } |
| 6593 | } |
| 6594 | #endif /* FEAT_TEAROFF */ |
| 6595 | |
| 6596 | /* |
| 6597 | * Make a menu either grey or not grey. |
| 6598 | */ |
| 6599 | void |
| 6600 | gui_mch_menu_grey( |
| 6601 | vimmenu_T *menu, |
| 6602 | int grey) |
| 6603 | { |
| 6604 | #ifdef FEAT_TOOLBAR |
| 6605 | /* |
| 6606 | * is this a toolbar button? |
| 6607 | */ |
| 6608 | if (menu->submenu_id == (HMENU)-1) |
| 6609 | { |
| 6610 | SendMessage(s_toolbarhwnd, TB_ENABLEBUTTON, |
| 6611 | (WPARAM)menu->id, (LPARAM) MAKELONG((grey ? FALSE : TRUE), 0) ); |
| 6612 | } |
| 6613 | else |
| 6614 | #endif |
Bram Moolenaar | 762f175 | 2016-06-04 22:36:17 +0200 | [diff] [blame] | 6615 | (void)EnableMenuItem(menu->parent ? menu->parent->submenu_id : s_menuBar, |
| 6616 | menu->id, MF_BYCOMMAND | (grey ? MF_GRAYED : MF_ENABLED)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6617 | |
| 6618 | #ifdef FEAT_TEAROFF |
| 6619 | if ((menu->parent != NULL) && (IsWindow(menu->parent->tearoff_handle))) |
| 6620 | { |
| 6621 | WORD menuID; |
| 6622 | HWND menuHandle; |
| 6623 | |
| 6624 | /* |
| 6625 | * A tearoff button has changed state. |
| 6626 | */ |
| 6627 | if (menu->children == NULL) |
| 6628 | menuID = (WORD)(menu->id); |
| 6629 | else |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 6630 | menuID = (WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6631 | menuHandle = GetDlgItem(menu->parent->tearoff_handle, menuID); |
| 6632 | if (menuHandle) |
| 6633 | EnableWindow(menuHandle, !grey); |
| 6634 | |
| 6635 | } |
| 6636 | #endif |
| 6637 | } |
| 6638 | |
| 6639 | #endif /* FEAT_MENU */ |
| 6640 | |
| 6641 | |
| 6642 | /* define some macros used to make the dialogue creation more readable */ |
| 6643 | |
| 6644 | #define add_string(s) strcpy((LPSTR)p, s); (LPSTR)p += (strlen((LPSTR)p) + 1) |
| 6645 | #define add_word(x) *p++ = (x) |
Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 6646 | #define add_long(x) dwp = (DWORD *)p; *dwp++ = (x); p = (WORD *)dwp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6647 | |
| 6648 | #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
| 6649 | /* |
| 6650 | * stuff for dialogs |
| 6651 | */ |
| 6652 | |
| 6653 | /* |
| 6654 | * The callback routine used by all the dialogs. Very simple. First, |
| 6655 | * acknowledges the INITDIALOG message so that Windows knows to do standard |
| 6656 | * dialog stuff (Return = default, Esc = cancel....) Second, if a button is |
| 6657 | * pressed, return that button's ID - IDCANCEL (2), which is the button's |
| 6658 | * number. |
| 6659 | */ |
| 6660 | static LRESULT CALLBACK |
| 6661 | dialog_callback( |
| 6662 | HWND hwnd, |
| 6663 | UINT message, |
| 6664 | WPARAM wParam, |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 6665 | LPARAM lParam UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6666 | { |
| 6667 | if (message == WM_INITDIALOG) |
| 6668 | { |
| 6669 | CenterWindow(hwnd, GetWindow(hwnd, GW_OWNER)); |
| 6670 | /* Set focus to the dialog. Set the default button, if specified. */ |
| 6671 | (void)SetFocus(hwnd); |
| 6672 | if (dialog_default_button > IDCANCEL) |
| 6673 | (void)SetFocus(GetDlgItem(hwnd, dialog_default_button)); |
Bram Moolenaar | 2b80e65 | 2007-08-14 14:57:55 +0000 | [diff] [blame] | 6674 | else |
| 6675 | /* We don't have a default, set focus on another element of the |
| 6676 | * dialog window, probably the icon */ |
| 6677 | (void)SetFocus(GetDlgItem(hwnd, DLG_NONBUTTON_CONTROL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6678 | return FALSE; |
| 6679 | } |
| 6680 | |
| 6681 | if (message == WM_COMMAND) |
| 6682 | { |
| 6683 | int button = LOWORD(wParam); |
| 6684 | |
| 6685 | /* Don't end the dialog if something was selected that was |
| 6686 | * not a button. |
| 6687 | */ |
| 6688 | if (button >= DLG_NONBUTTON_CONTROL) |
| 6689 | return TRUE; |
| 6690 | |
| 6691 | /* If the edit box exists, copy the string. */ |
| 6692 | if (s_textfield != NULL) |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 6693 | { |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6694 | WCHAR *wp = ALLOC_MULT(WCHAR, IOSIZE); |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6695 | char_u *p; |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 6696 | |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 6697 | GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE); |
| 6698 | p = utf16_to_enc(wp, NULL); |
| 6699 | vim_strncpy(s_textfield, p, IOSIZE); |
| 6700 | vim_free(p); |
| 6701 | vim_free(wp); |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 6702 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6703 | |
| 6704 | /* |
| 6705 | * Need to check for IDOK because if the user just hits Return to |
| 6706 | * accept the default value, some reason this is what we get. |
| 6707 | */ |
| 6708 | if (button == IDOK) |
| 6709 | { |
| 6710 | if (dialog_default_button > IDCANCEL) |
| 6711 | EndDialog(hwnd, dialog_default_button); |
| 6712 | } |
| 6713 | else |
| 6714 | EndDialog(hwnd, button - IDCANCEL); |
| 6715 | return TRUE; |
| 6716 | } |
| 6717 | |
| 6718 | if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) |
| 6719 | { |
| 6720 | EndDialog(hwnd, 0); |
| 6721 | return TRUE; |
| 6722 | } |
| 6723 | return FALSE; |
| 6724 | } |
| 6725 | |
| 6726 | /* |
| 6727 | * Create a dialog dynamically from the parameter strings. |
| 6728 | * type = type of dialog (question, alert, etc.) |
| 6729 | * title = dialog title. may be NULL for default title. |
| 6730 | * message = text to display. Dialog sizes to accommodate it. |
| 6731 | * buttons = '\n' separated list of button captions, default first. |
| 6732 | * dfltbutton = number of default button. |
| 6733 | * |
| 6734 | * This routine returns 1 if the first button is pressed, |
| 6735 | * 2 for the second, etc. |
| 6736 | * |
| 6737 | * 0 indicates Esc was pressed. |
| 6738 | * -1 for unexpected error |
| 6739 | * |
| 6740 | * If stubbing out this fn, return 1. |
| 6741 | */ |
| 6742 | |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 6743 | static const char *dlg_icons[] = /* must match names in resource file */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6744 | { |
| 6745 | "IDR_VIM", |
| 6746 | "IDR_VIM_ERROR", |
| 6747 | "IDR_VIM_ALERT", |
| 6748 | "IDR_VIM_INFO", |
| 6749 | "IDR_VIM_QUESTION" |
| 6750 | }; |
| 6751 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6752 | int |
| 6753 | gui_mch_dialog( |
| 6754 | int type, |
| 6755 | char_u *title, |
| 6756 | char_u *message, |
| 6757 | char_u *buttons, |
| 6758 | int dfltbutton, |
Bram Moolenaar | d2c340a | 2011-01-17 20:08:11 +0100 | [diff] [blame] | 6759 | char_u *textfield, |
Bram Moolenaar | bd67aac | 2019-09-21 23:09:04 +0200 | [diff] [blame] | 6760 | int ex_cmd UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6761 | { |
| 6762 | WORD *p, *pdlgtemplate, *pnumitems; |
Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 6763 | DWORD *dwp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6764 | int numButtons; |
| 6765 | int *buttonWidths, *buttonPositions; |
| 6766 | int buttonYpos; |
| 6767 | int nchar, i; |
| 6768 | DWORD lStyle; |
| 6769 | int dlgwidth = 0; |
| 6770 | int dlgheight; |
| 6771 | int editboxheight; |
| 6772 | int horizWidth = 0; |
| 6773 | int msgheight; |
| 6774 | char_u *pstart; |
| 6775 | char_u *pend; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6776 | char_u *last_white; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6777 | char_u *tbuffer; |
| 6778 | RECT rect; |
| 6779 | HWND hwnd; |
| 6780 | HDC hdc; |
| 6781 | HFONT font, oldFont; |
| 6782 | TEXTMETRIC fontInfo; |
| 6783 | int fontHeight; |
| 6784 | int textWidth, minButtonWidth, messageWidth; |
| 6785 | int maxDialogWidth; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6786 | int maxDialogHeight; |
| 6787 | int scroll_flag = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6788 | int vertical; |
| 6789 | int dlgPaddingX; |
| 6790 | int dlgPaddingY; |
| 6791 | #ifdef USE_SYSMENU_FONT |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 6792 | LOGFONTW lfSysmenu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6793 | int use_lfSysmenu = FALSE; |
| 6794 | #endif |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6795 | garray_T ga; |
| 6796 | int l; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6797 | |
| 6798 | #ifndef NO_CONSOLE |
| 6799 | /* Don't output anything in silent mode ("ex -s") */ |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 6800 | # ifdef VIMDLL |
| 6801 | if (!(gui.in_use || gui.starting)) |
| 6802 | # endif |
| 6803 | if (silent_mode) |
| 6804 | return dfltbutton; /* return default option */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6805 | #endif |
| 6806 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6807 | if (s_hwnd == NULL) |
| 6808 | get_dialog_font_metrics(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6809 | |
| 6810 | if ((type < 0) || (type > VIM_LAST_TYPE)) |
| 6811 | type = 0; |
| 6812 | |
| 6813 | /* allocate some memory for dialog template */ |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6814 | /* TODO should compute this really */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6815 | pdlgtemplate = p = (PWORD)LocalAlloc(LPTR, |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 6816 | DLG_ALLOC_SIZE + STRLEN(message) * 2); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6817 | |
| 6818 | if (p == NULL) |
| 6819 | return -1; |
| 6820 | |
| 6821 | /* |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 6822 | * make a copy of 'buttons' to fiddle with it. compiler grizzles because |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6823 | * vim_strsave() doesn't take a const arg (why not?), so cast away the |
| 6824 | * const. |
| 6825 | */ |
| 6826 | tbuffer = vim_strsave(buttons); |
| 6827 | if (tbuffer == NULL) |
| 6828 | return -1; |
| 6829 | |
| 6830 | --dfltbutton; /* Change from one-based to zero-based */ |
| 6831 | |
| 6832 | /* Count buttons */ |
| 6833 | numButtons = 1; |
| 6834 | for (i = 0; tbuffer[i] != '\0'; i++) |
| 6835 | { |
| 6836 | if (tbuffer[i] == DLG_BUTTON_SEP) |
| 6837 | numButtons++; |
| 6838 | } |
| 6839 | if (dfltbutton >= numButtons) |
| 6840 | dfltbutton = -1; |
| 6841 | |
| 6842 | /* Allocate array to hold the width of each button */ |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6843 | buttonWidths = ALLOC_MULT(int, numButtons); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6844 | if (buttonWidths == NULL) |
| 6845 | return -1; |
| 6846 | |
| 6847 | /* Allocate array to hold the X position of each button */ |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 6848 | buttonPositions = ALLOC_MULT(int, numButtons); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6849 | if (buttonPositions == NULL) |
| 6850 | return -1; |
| 6851 | |
| 6852 | /* |
| 6853 | * Calculate how big the dialog must be. |
| 6854 | */ |
| 6855 | hwnd = GetDesktopWindow(); |
| 6856 | hdc = GetWindowDC(hwnd); |
| 6857 | #ifdef USE_SYSMENU_FONT |
| 6858 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 6859 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 6860 | font = CreateFontIndirectW(&lfSysmenu); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6861 | use_lfSysmenu = TRUE; |
| 6862 | } |
| 6863 | else |
| 6864 | #endif |
| 6865 | font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 6866 | VARIABLE_PITCH , DLG_FONT_NAME); |
| 6867 | if (s_usenewlook) |
| 6868 | { |
| 6869 | oldFont = SelectFont(hdc, font); |
| 6870 | dlgPaddingX = DLG_PADDING_X; |
| 6871 | dlgPaddingY = DLG_PADDING_Y; |
| 6872 | } |
| 6873 | else |
| 6874 | { |
| 6875 | oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); |
| 6876 | dlgPaddingX = DLG_OLD_STYLE_PADDING_X; |
| 6877 | dlgPaddingY = DLG_OLD_STYLE_PADDING_Y; |
| 6878 | } |
| 6879 | GetTextMetrics(hdc, &fontInfo); |
| 6880 | fontHeight = fontInfo.tmHeight; |
| 6881 | |
| 6882 | /* Minimum width for horizontal button */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 6883 | minButtonWidth = GetTextWidth(hdc, (char_u *)"Cancel", 6); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6884 | |
| 6885 | /* Maximum width of a dialog, if possible */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6886 | if (s_hwnd == NULL) |
| 6887 | { |
| 6888 | RECT workarea_rect; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6889 | |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 6890 | /* We don't have a window, use the desktop area. */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6891 | get_work_area(&workarea_rect); |
| 6892 | maxDialogWidth = workarea_rect.right - workarea_rect.left - 100; |
| 6893 | if (maxDialogWidth > 600) |
| 6894 | maxDialogWidth = 600; |
Bram Moolenaar | 1b1b094 | 2013-08-01 13:20:42 +0200 | [diff] [blame] | 6895 | /* Leave some room for the taskbar. */ |
| 6896 | maxDialogHeight = workarea_rect.bottom - workarea_rect.top - 150; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6897 | } |
| 6898 | else |
| 6899 | { |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 6900 | /* Use our own window for the size, unless it's very small. */ |
| 6901 | GetWindowRect(s_hwnd, &rect); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6902 | maxDialogWidth = rect.right - rect.left |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 6903 | - (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6904 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6905 | if (maxDialogWidth < DLG_MIN_MAX_WIDTH) |
| 6906 | maxDialogWidth = DLG_MIN_MAX_WIDTH; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6907 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6908 | maxDialogHeight = rect.bottom - rect.top |
Bram Moolenaar | 1b1b094 | 2013-08-01 13:20:42 +0200 | [diff] [blame] | 6909 | - (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 6910 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 4 |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 6911 | - GetSystemMetrics(SM_CYCAPTION); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6912 | if (maxDialogHeight < DLG_MIN_MAX_HEIGHT) |
| 6913 | maxDialogHeight = DLG_MIN_MAX_HEIGHT; |
| 6914 | } |
| 6915 | |
| 6916 | /* Set dlgwidth to width of message. |
| 6917 | * Copy the message into "ga", changing NL to CR-NL and inserting line |
| 6918 | * breaks where needed. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6919 | pstart = message; |
| 6920 | messageWidth = 0; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6921 | msgheight = 0; |
| 6922 | ga_init2(&ga, sizeof(char), 500); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6923 | do |
| 6924 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6925 | msgheight += fontHeight; /* at least one line */ |
| 6926 | |
| 6927 | /* Need to figure out where to break the string. The system does it |
| 6928 | * at a word boundary, which would mean we can't compute the number of |
| 6929 | * wrapped lines. */ |
| 6930 | textWidth = 0; |
| 6931 | last_white = NULL; |
| 6932 | for (pend = pstart; *pend != NUL && *pend != '\n'; ) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6933 | { |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6934 | l = (*mb_ptr2len)(pend); |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 6935 | if (l == 1 && VIM_ISWHITE(*pend) |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6936 | && textWidth > maxDialogWidth * 3 / 4) |
| 6937 | last_white = pend; |
Bram Moolenaar | f05d811 | 2013-06-26 12:58:32 +0200 | [diff] [blame] | 6938 | textWidth += GetTextWidthEnc(hdc, pend, l); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6939 | if (textWidth >= maxDialogWidth) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6940 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6941 | /* Line will wrap. */ |
| 6942 | messageWidth = maxDialogWidth; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6943 | msgheight += fontHeight; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6944 | textWidth = 0; |
| 6945 | |
| 6946 | if (last_white != NULL) |
| 6947 | { |
| 6948 | /* break the line just after a space */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 6949 | ga.ga_len -= (int)(pend - (last_white + 1)); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6950 | pend = last_white + 1; |
| 6951 | last_white = NULL; |
| 6952 | } |
| 6953 | ga_append(&ga, '\r'); |
| 6954 | ga_append(&ga, '\n'); |
| 6955 | continue; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6956 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6957 | |
| 6958 | while (--l >= 0) |
| 6959 | ga_append(&ga, *pend++); |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6960 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6961 | if (textWidth > messageWidth) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6962 | messageWidth = textWidth; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6963 | |
| 6964 | ga_append(&ga, '\r'); |
| 6965 | ga_append(&ga, '\n'); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6966 | pstart = pend + 1; |
| 6967 | } while (*pend != NUL); |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6968 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 6969 | if (ga.ga_data != NULL) |
| 6970 | message = ga.ga_data; |
| 6971 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 6972 | messageWidth += 10; /* roundoff space */ |
| 6973 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6974 | /* Add width of icon to dlgwidth, and some space */ |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 6975 | dlgwidth = messageWidth + DLG_ICON_WIDTH + 3 * dlgPaddingX |
| 6976 | + GetSystemMetrics(SM_CXVSCROLL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6977 | |
| 6978 | if (msgheight < DLG_ICON_HEIGHT) |
| 6979 | msgheight = DLG_ICON_HEIGHT; |
| 6980 | |
| 6981 | /* |
| 6982 | * Check button names. A long one will make the dialog wider. |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 6983 | * When called early (-register error message) p_go isn't initialized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6984 | */ |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 6985 | vertical = (p_go != NULL && vim_strchr(p_go, GO_VERTICAL) != NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6986 | if (!vertical) |
| 6987 | { |
| 6988 | // Place buttons horizontally if they fit. |
| 6989 | horizWidth = dlgPaddingX; |
| 6990 | pstart = tbuffer; |
| 6991 | i = 0; |
| 6992 | do |
| 6993 | { |
| 6994 | pend = vim_strchr(pstart, DLG_BUTTON_SEP); |
| 6995 | if (pend == NULL) |
| 6996 | pend = pstart + STRLEN(pstart); // Last button name. |
Bram Moolenaar | b052fe0 | 2013-06-26 13:16:20 +0200 | [diff] [blame] | 6997 | textWidth = GetTextWidthEnc(hdc, pstart, (int)(pend - pstart)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6998 | if (textWidth < minButtonWidth) |
| 6999 | textWidth = minButtonWidth; |
| 7000 | textWidth += dlgPaddingX; /* Padding within button */ |
| 7001 | buttonWidths[i] = textWidth; |
| 7002 | buttonPositions[i++] = horizWidth; |
| 7003 | horizWidth += textWidth + dlgPaddingX; /* Pad between buttons */ |
| 7004 | pstart = pend + 1; |
| 7005 | } while (*pend != NUL); |
| 7006 | |
| 7007 | if (horizWidth > maxDialogWidth) |
| 7008 | vertical = TRUE; // Too wide to fit on the screen. |
| 7009 | else if (horizWidth > dlgwidth) |
| 7010 | dlgwidth = horizWidth; |
| 7011 | } |
| 7012 | |
| 7013 | if (vertical) |
| 7014 | { |
| 7015 | // Stack buttons vertically. |
| 7016 | pstart = tbuffer; |
| 7017 | do |
| 7018 | { |
| 7019 | pend = vim_strchr(pstart, DLG_BUTTON_SEP); |
| 7020 | if (pend == NULL) |
| 7021 | pend = pstart + STRLEN(pstart); // Last button name. |
Bram Moolenaar | b052fe0 | 2013-06-26 13:16:20 +0200 | [diff] [blame] | 7022 | textWidth = GetTextWidthEnc(hdc, pstart, (int)(pend - pstart)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7023 | textWidth += dlgPaddingX; /* Padding within button */ |
| 7024 | textWidth += DLG_VERT_PADDING_X * 2; /* Padding around button */ |
| 7025 | if (textWidth > dlgwidth) |
| 7026 | dlgwidth = textWidth; |
| 7027 | pstart = pend + 1; |
| 7028 | } while (*pend != NUL); |
| 7029 | } |
| 7030 | |
| 7031 | if (dlgwidth < DLG_MIN_WIDTH) |
| 7032 | dlgwidth = DLG_MIN_WIDTH; /* Don't allow a really thin dialog!*/ |
| 7033 | |
| 7034 | /* start to fill in the dlgtemplate information. addressing by WORDs */ |
| 7035 | if (s_usenewlook) |
| 7036 | lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE |DS_SETFONT; |
| 7037 | else |
| 7038 | lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE; |
| 7039 | |
| 7040 | add_long(lStyle); |
| 7041 | add_long(0); // (lExtendedStyle) |
| 7042 | pnumitems = p; /*save where the number of items must be stored*/ |
| 7043 | add_word(0); // NumberOfItems(will change later) |
| 7044 | add_word(10); // x |
| 7045 | add_word(10); // y |
| 7046 | add_word(PixelToDialogX(dlgwidth)); // cx |
| 7047 | |
| 7048 | // Dialog height. |
| 7049 | if (vertical) |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7050 | dlgheight = msgheight + 2 * dlgPaddingY |
| 7051 | + DLG_VERT_PADDING_Y + 2 * fontHeight * numButtons; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7052 | else |
| 7053 | dlgheight = msgheight + 3 * dlgPaddingY + 2 * fontHeight; |
| 7054 | |
| 7055 | // Dialog needs to be taller if contains an edit box. |
| 7056 | editboxheight = fontHeight + dlgPaddingY + 4 * DLG_VERT_PADDING_Y; |
| 7057 | if (textfield != NULL) |
| 7058 | dlgheight += editboxheight; |
| 7059 | |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7060 | /* Restrict the size to a maximum. Causes a scrollbar to show up. */ |
| 7061 | if (dlgheight > maxDialogHeight) |
| 7062 | { |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 7063 | msgheight = msgheight - (dlgheight - maxDialogHeight); |
| 7064 | dlgheight = maxDialogHeight; |
| 7065 | scroll_flag = WS_VSCROLL; |
| 7066 | /* Make sure scrollbar doesn't appear in the middle of the dialog */ |
| 7067 | messageWidth = dlgwidth - DLG_ICON_WIDTH - 3 * dlgPaddingX; |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 7068 | } |
| 7069 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7070 | add_word(PixelToDialogY(dlgheight)); |
| 7071 | |
| 7072 | add_word(0); // Menu |
| 7073 | add_word(0); // Class |
| 7074 | |
| 7075 | /* copy the title of the dialog */ |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7076 | nchar = nCopyAnsiToWideChar(p, (title ? (LPSTR)title |
| 7077 | : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7078 | p += nchar; |
| 7079 | |
| 7080 | if (s_usenewlook) |
| 7081 | { |
| 7082 | /* do the font, since DS_3DLOOK doesn't work properly */ |
| 7083 | #ifdef USE_SYSMENU_FONT |
| 7084 | if (use_lfSysmenu) |
| 7085 | { |
| 7086 | /* point size */ |
| 7087 | *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
| 7088 | GetDeviceCaps(hdc, LOGPIXELSY)); |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 7089 | wcscpy(p, lfSysmenu.lfFaceName); |
| 7090 | nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7091 | } |
| 7092 | else |
| 7093 | #endif |
| 7094 | { |
| 7095 | *p++ = DLG_FONT_POINT_SIZE; // point size |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7096 | nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7097 | } |
| 7098 | p += nchar; |
| 7099 | } |
| 7100 | |
| 7101 | buttonYpos = msgheight + 2 * dlgPaddingY; |
| 7102 | |
| 7103 | if (textfield != NULL) |
| 7104 | buttonYpos += editboxheight; |
| 7105 | |
| 7106 | pstart = tbuffer; |
| 7107 | if (!vertical) |
| 7108 | horizWidth = (dlgwidth - horizWidth) / 2; /* Now it's X offset */ |
| 7109 | for (i = 0; i < numButtons; i++) |
| 7110 | { |
| 7111 | /* get end of this button. */ |
| 7112 | for ( pend = pstart; |
| 7113 | *pend && (*pend != DLG_BUTTON_SEP); |
| 7114 | pend++) |
| 7115 | ; |
| 7116 | |
| 7117 | if (*pend) |
| 7118 | *pend = '\0'; |
| 7119 | |
| 7120 | /* |
| 7121 | * old NOTE: |
| 7122 | * setting the BS_DEFPUSHBUTTON style doesn't work because Windows sets |
| 7123 | * the focus to the first tab-able button and in so doing makes that |
| 7124 | * the default!! Grrr. Workaround: Make the default button the only |
| 7125 | * one with WS_TABSTOP style. Means user can't tab between buttons, but |
| 7126 | * he/she can use arrow keys. |
| 7127 | * |
| 7128 | * new NOTE: BS_DEFPUSHBUTTON is required to be able to select the |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 7129 | * right button when hitting <Enter>. E.g., for the ":confirm quit" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7130 | * dialog. Also needed for when the textfield is the default control. |
| 7131 | * It appears to work now (perhaps not on Win95?). |
| 7132 | */ |
| 7133 | if (vertical) |
| 7134 | { |
| 7135 | p = add_dialog_element(p, |
| 7136 | (i == dfltbutton |
| 7137 | ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, |
| 7138 | PixelToDialogX(DLG_VERT_PADDING_X), |
| 7139 | PixelToDialogY(buttonYpos /* TBK */ |
| 7140 | + 2 * fontHeight * i), |
| 7141 | PixelToDialogX(dlgwidth - 2 * DLG_VERT_PADDING_X), |
| 7142 | (WORD)(PixelToDialogY(2 * fontHeight) - 1), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7143 | (WORD)(IDCANCEL + 1 + i), (WORD)0x0080, (char *)pstart); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7144 | } |
| 7145 | else |
| 7146 | { |
| 7147 | p = add_dialog_element(p, |
| 7148 | (i == dfltbutton |
| 7149 | ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, |
| 7150 | PixelToDialogX(horizWidth + buttonPositions[i]), |
| 7151 | PixelToDialogY(buttonYpos), /* TBK */ |
| 7152 | PixelToDialogX(buttonWidths[i]), |
| 7153 | (WORD)(PixelToDialogY(2 * fontHeight) - 1), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7154 | (WORD)(IDCANCEL + 1 + i), (WORD)0x0080, (char *)pstart); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7155 | } |
| 7156 | pstart = pend + 1; /*next button*/ |
| 7157 | } |
| 7158 | *pnumitems += numButtons; |
| 7159 | |
| 7160 | /* Vim icon */ |
| 7161 | p = add_dialog_element(p, SS_ICON, |
| 7162 | PixelToDialogX(dlgPaddingX), |
| 7163 | PixelToDialogY(dlgPaddingY), |
| 7164 | PixelToDialogX(DLG_ICON_WIDTH), |
| 7165 | PixelToDialogY(DLG_ICON_HEIGHT), |
| 7166 | DLG_NONBUTTON_CONTROL + 0, (WORD)0x0082, |
| 7167 | dlg_icons[type]); |
| 7168 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 7169 | /* Dialog message */ |
| 7170 | p = add_dialog_element(p, ES_LEFT|scroll_flag|ES_MULTILINE|ES_READONLY, |
| 7171 | PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH), |
| 7172 | PixelToDialogY(dlgPaddingY), |
| 7173 | (WORD)(PixelToDialogX(messageWidth) + 1), |
| 7174 | PixelToDialogY(msgheight), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7175 | DLG_NONBUTTON_CONTROL + 1, (WORD)0x0081, (char *)message); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7176 | |
| 7177 | /* Edit box */ |
| 7178 | if (textfield != NULL) |
| 7179 | { |
| 7180 | p = add_dialog_element(p, ES_LEFT|ES_AUTOHSCROLL|WS_TABSTOP|WS_BORDER, |
| 7181 | PixelToDialogX(2 * dlgPaddingX), |
| 7182 | PixelToDialogY(2 * dlgPaddingY + msgheight), |
| 7183 | PixelToDialogX(dlgwidth - 4 * dlgPaddingX), |
| 7184 | PixelToDialogY(fontHeight + dlgPaddingY), |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7185 | DLG_NONBUTTON_CONTROL + 2, (WORD)0x0081, (char *)textfield); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7186 | *pnumitems += 1; |
| 7187 | } |
| 7188 | |
| 7189 | *pnumitems += 2; |
| 7190 | |
| 7191 | SelectFont(hdc, oldFont); |
| 7192 | DeleteObject(font); |
| 7193 | ReleaseDC(hwnd, hdc); |
| 7194 | |
| 7195 | /* Let the dialog_callback() function know which button to make default |
| 7196 | * If we have an edit box, make that the default. We also need to tell |
| 7197 | * dialog_callback() if this dialog contains an edit box or not. We do |
| 7198 | * this by setting s_textfield if it does. |
| 7199 | */ |
| 7200 | if (textfield != NULL) |
| 7201 | { |
| 7202 | dialog_default_button = DLG_NONBUTTON_CONTROL + 2; |
| 7203 | s_textfield = textfield; |
| 7204 | } |
| 7205 | else |
| 7206 | { |
| 7207 | dialog_default_button = IDCANCEL + 1 + dfltbutton; |
| 7208 | s_textfield = NULL; |
| 7209 | } |
| 7210 | |
| 7211 | /* show the dialog box modally and get a return value */ |
| 7212 | nchar = (int)DialogBoxIndirect( |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 7213 | g_hinst, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7214 | (LPDLGTEMPLATE)pdlgtemplate, |
| 7215 | s_hwnd, |
| 7216 | (DLGPROC)dialog_callback); |
| 7217 | |
| 7218 | LocalFree(LocalHandle(pdlgtemplate)); |
| 7219 | vim_free(tbuffer); |
| 7220 | vim_free(buttonWidths); |
| 7221 | vim_free(buttonPositions); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 7222 | vim_free(ga.ga_data); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7223 | |
| 7224 | /* Focus back to our window (for when MDI is used). */ |
| 7225 | (void)SetFocus(s_hwnd); |
| 7226 | |
| 7227 | return nchar; |
| 7228 | } |
| 7229 | |
| 7230 | #endif /* FEAT_GUI_DIALOG */ |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7231 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7232 | /* |
| 7233 | * Put a simple element (basic class) onto a dialog template in memory. |
| 7234 | * return a pointer to where the next item should be added. |
| 7235 | * |
| 7236 | * parameters: |
| 7237 | * lStyle = additional style flags |
| 7238 | * (be careful, NT3.51 & Win32s will ignore the new ones) |
| 7239 | * x,y = x & y positions IN DIALOG UNITS |
| 7240 | * w,h = width and height IN DIALOG UNITS |
| 7241 | * Id = ID used in messages |
| 7242 | * clss = class ID, e.g 0x0080 for a button, 0x0082 for a static |
| 7243 | * caption = usually text or resource name |
| 7244 | * |
| 7245 | * TODO: use the length information noted here to enable the dialog creation |
| 7246 | * routines to work out more exactly how much memory they need to alloc. |
| 7247 | */ |
| 7248 | static PWORD |
| 7249 | add_dialog_element( |
| 7250 | PWORD p, |
| 7251 | DWORD lStyle, |
| 7252 | WORD x, |
| 7253 | WORD y, |
| 7254 | WORD w, |
| 7255 | WORD h, |
| 7256 | WORD Id, |
| 7257 | WORD clss, |
| 7258 | const char *caption) |
| 7259 | { |
| 7260 | int nchar; |
| 7261 | |
| 7262 | p = lpwAlign(p); /* Align to dword boundary*/ |
| 7263 | lStyle = lStyle | WS_VISIBLE | WS_CHILD; |
| 7264 | *p++ = LOWORD(lStyle); |
| 7265 | *p++ = HIWORD(lStyle); |
| 7266 | *p++ = 0; // LOWORD (lExtendedStyle) |
| 7267 | *p++ = 0; // HIWORD (lExtendedStyle) |
| 7268 | *p++ = x; |
| 7269 | *p++ = y; |
| 7270 | *p++ = w; |
| 7271 | *p++ = h; |
| 7272 | *p++ = Id; //9 or 10 words in all |
| 7273 | |
| 7274 | *p++ = (WORD)0xffff; |
| 7275 | *p++ = clss; //2 more here |
| 7276 | |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7277 | nchar = nCopyAnsiToWideChar(p, (LPSTR)caption, TRUE); //strlen(caption)+1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7278 | p += nchar; |
| 7279 | |
| 7280 | *p++ = 0; // advance pointer over nExtraStuff WORD - 2 more |
| 7281 | |
| 7282 | return p; //total = 15+ (strlen(caption)) words |
| 7283 | // = 30 + 2(strlen(caption) bytes reqd |
| 7284 | } |
| 7285 | |
| 7286 | |
| 7287 | /* |
| 7288 | * Helper routine. Take an input pointer, return closest pointer that is |
| 7289 | * aligned on a DWORD (4 byte) boundary. Taken from the Win32SDK samples. |
| 7290 | */ |
| 7291 | static LPWORD |
| 7292 | lpwAlign( |
| 7293 | LPWORD lpIn) |
| 7294 | { |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7295 | long_u ul; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7296 | |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7297 | ul = (long_u)lpIn; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7298 | ul += 3; |
| 7299 | ul >>= 2; |
| 7300 | ul <<= 2; |
| 7301 | return (LPWORD)ul; |
| 7302 | } |
| 7303 | |
| 7304 | /* |
| 7305 | * Helper routine. Takes second parameter as Ansi string, copies it to first |
| 7306 | * parameter as wide character (16-bits / char) string, and returns integer |
| 7307 | * number of wide characters (words) in string (including the trailing wide |
| 7308 | * char NULL). Partly taken from the Win32SDK samples. |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7309 | * If "use_enc" is TRUE, 'encoding' is used for "lpAnsiIn". If FALSE, current |
| 7310 | * ACP is used for "lpAnsiIn". */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7311 | static int |
| 7312 | nCopyAnsiToWideChar( |
| 7313 | LPWORD lpWCStr, |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7314 | LPSTR lpAnsiIn, |
| 7315 | BOOL use_enc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7316 | { |
| 7317 | int nChar = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7318 | int len = lstrlen(lpAnsiIn) + 1; /* include NUL character */ |
| 7319 | int i; |
| 7320 | WCHAR *wn; |
| 7321 | |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7322 | if (use_enc && enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7323 | { |
| 7324 | /* Not a codepage, use our own conversion function. */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7325 | wn = enc_to_utf16((char_u *)lpAnsiIn, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7326 | if (wn != NULL) |
| 7327 | { |
| 7328 | wcscpy(lpWCStr, wn); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 7329 | nChar = (int)wcslen(wn) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7330 | vim_free(wn); |
| 7331 | } |
| 7332 | } |
| 7333 | if (nChar == 0) |
| 7334 | /* Use Win32 conversion function. */ |
| 7335 | nChar = MultiByteToWideChar( |
| 7336 | enc_codepage > 0 ? enc_codepage : CP_ACP, |
| 7337 | MB_PRECOMPOSED, |
| 7338 | lpAnsiIn, len, |
| 7339 | lpWCStr, len); |
| 7340 | for (i = 0; i < nChar; ++i) |
| 7341 | if (lpWCStr[i] == (WORD)'\t') /* replace tabs with spaces */ |
| 7342 | lpWCStr[i] = (WORD)' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7343 | |
| 7344 | return nChar; |
| 7345 | } |
| 7346 | |
| 7347 | |
| 7348 | #ifdef FEAT_TEAROFF |
| 7349 | /* |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7350 | * Lookup menu handle from "menu_id". |
| 7351 | */ |
| 7352 | static HMENU |
| 7353 | tearoff_lookup_menuhandle( |
| 7354 | vimmenu_T *menu, |
| 7355 | WORD menu_id) |
| 7356 | { |
| 7357 | for ( ; menu != NULL; menu = menu->next) |
| 7358 | { |
| 7359 | if (menu->modes == 0) /* this menu has just been deleted */ |
| 7360 | continue; |
| 7361 | if (menu_is_separator(menu->dname)) |
| 7362 | continue; |
| 7363 | if ((WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000) == menu_id) |
| 7364 | return menu->submenu_id; |
| 7365 | } |
| 7366 | return NULL; |
| 7367 | } |
| 7368 | |
| 7369 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7370 | * The callback function for all the modeless dialogs that make up the |
| 7371 | * "tearoff menus" Very simple - forward button presses (to fool Vim into |
| 7372 | * thinking its menus have been clicked), and go away when closed. |
| 7373 | */ |
| 7374 | static LRESULT CALLBACK |
| 7375 | tearoff_callback( |
| 7376 | HWND hwnd, |
| 7377 | UINT message, |
| 7378 | WPARAM wParam, |
| 7379 | LPARAM lParam) |
| 7380 | { |
| 7381 | if (message == WM_INITDIALOG) |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7382 | { |
| 7383 | SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7384 | return (TRUE); |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7385 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7386 | |
| 7387 | /* May show the mouse pointer again. */ |
| 7388 | HandleMouseHide(message, lParam); |
| 7389 | |
| 7390 | if (message == WM_COMMAND) |
| 7391 | { |
| 7392 | if ((WORD)(LOWORD(wParam)) & 0x8000) |
| 7393 | { |
| 7394 | POINT mp; |
| 7395 | RECT rect; |
| 7396 | |
| 7397 | if (GetCursorPos(&mp) && GetWindowRect(hwnd, &rect)) |
| 7398 | { |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7399 | vimmenu_T *menu; |
| 7400 | |
| 7401 | menu = (vimmenu_T*)GetWindowLongPtr(hwnd, DWLP_USER); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7402 | (void)TrackPopupMenu( |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7403 | tearoff_lookup_menuhandle(menu, LOWORD(wParam)), |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7404 | TPM_LEFTALIGN | TPM_LEFTBUTTON, |
| 7405 | (int)rect.right - 8, |
| 7406 | (int)mp.y, |
| 7407 | (int)0, /*reserved param*/ |
| 7408 | s_hwnd, |
| 7409 | NULL); |
| 7410 | /* |
| 7411 | * NOTE: The pop-up menu can eat the mouse up event. |
| 7412 | * We deal with this in normal.c. |
| 7413 | */ |
| 7414 | } |
| 7415 | } |
| 7416 | else |
| 7417 | /* Pass on messages to the main Vim window */ |
| 7418 | PostMessage(s_hwnd, WM_COMMAND, LOWORD(wParam), 0); |
| 7419 | /* |
| 7420 | * Give main window the focus back: this is so after |
| 7421 | * choosing a tearoff button you can start typing again |
| 7422 | * straight away. |
| 7423 | */ |
| 7424 | (void)SetFocus(s_hwnd); |
| 7425 | return TRUE; |
| 7426 | } |
| 7427 | if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) |
| 7428 | { |
| 7429 | DestroyWindow(hwnd); |
| 7430 | return TRUE; |
| 7431 | } |
| 7432 | |
| 7433 | /* When moved around, give main window the focus back. */ |
| 7434 | if (message == WM_EXITSIZEMOVE) |
| 7435 | (void)SetActiveWindow(s_hwnd); |
| 7436 | |
| 7437 | return FALSE; |
| 7438 | } |
| 7439 | #endif |
| 7440 | |
| 7441 | |
| 7442 | /* |
| 7443 | * Decide whether to use the "new look" (small, non-bold font) or the "old |
| 7444 | * look" (big, clanky font) for dialogs, and work out a few values for use |
| 7445 | * later accordingly. |
| 7446 | */ |
| 7447 | static void |
| 7448 | get_dialog_font_metrics(void) |
| 7449 | { |
| 7450 | HDC hdc; |
| 7451 | HFONT hfontTools = 0; |
| 7452 | DWORD dlgFontSize; |
| 7453 | SIZE size; |
| 7454 | #ifdef USE_SYSMENU_FONT |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 7455 | LOGFONTW lfSysmenu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7456 | #endif |
| 7457 | |
| 7458 | s_usenewlook = FALSE; |
| 7459 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7460 | #ifdef USE_SYSMENU_FONT |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7461 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 7462 | hfontTools = CreateFontIndirectW(&lfSysmenu); |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7463 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7464 | #endif |
| 7465 | hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, |
| 7466 | 0, 0, 0, 0, VARIABLE_PITCH , DLG_FONT_NAME); |
| 7467 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7468 | if (hfontTools) |
| 7469 | { |
| 7470 | hdc = GetDC(s_hwnd); |
| 7471 | SelectObject(hdc, hfontTools); |
| 7472 | /* |
| 7473 | * GetTextMetrics() doesn't return the right value in |
| 7474 | * tmAveCharWidth, so we have to figure out the dialog base units |
| 7475 | * ourselves. |
| 7476 | */ |
| 7477 | GetTextExtentPoint(hdc, |
| 7478 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", |
| 7479 | 52, &size); |
| 7480 | ReleaseDC(s_hwnd, hdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7481 | |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7482 | s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); |
| 7483 | s_dlgfntheight = (WORD)size.cy; |
| 7484 | s_usenewlook = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7485 | } |
| 7486 | |
| 7487 | if (!s_usenewlook) |
| 7488 | { |
| 7489 | dlgFontSize = GetDialogBaseUnits(); /* fall back to big old system*/ |
| 7490 | s_dlgfntwidth = LOWORD(dlgFontSize); |
| 7491 | s_dlgfntheight = HIWORD(dlgFontSize); |
| 7492 | } |
| 7493 | } |
| 7494 | |
| 7495 | #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
| 7496 | /* |
| 7497 | * Create a pseudo-"tearoff menu" based on the child |
| 7498 | * items of a given menu pointer. |
| 7499 | */ |
| 7500 | static void |
| 7501 | gui_mch_tearoff( |
| 7502 | char_u *title, |
| 7503 | vimmenu_T *menu, |
| 7504 | int initX, |
| 7505 | int initY) |
| 7506 | { |
| 7507 | WORD *p, *pdlgtemplate, *pnumitems, *ptrueheight; |
| 7508 | int template_len; |
| 7509 | int nchar, textWidth, submenuWidth; |
| 7510 | DWORD lStyle; |
| 7511 | DWORD lExtendedStyle; |
| 7512 | WORD dlgwidth; |
| 7513 | WORD menuID; |
| 7514 | vimmenu_T *pmenu; |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7515 | vimmenu_T *top_menu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7516 | vimmenu_T *the_menu = menu; |
| 7517 | HWND hwnd; |
| 7518 | HDC hdc; |
| 7519 | HFONT font, oldFont; |
| 7520 | int col, spaceWidth, len; |
| 7521 | int columnWidths[2]; |
| 7522 | char_u *label, *text; |
| 7523 | int acLen = 0; |
| 7524 | int nameLen; |
| 7525 | int padding0, padding1, padding2 = 0; |
| 7526 | int sepPadding=0; |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 7527 | int x; |
| 7528 | int y; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7529 | #ifdef USE_SYSMENU_FONT |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 7530 | LOGFONTW lfSysmenu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7531 | int use_lfSysmenu = FALSE; |
| 7532 | #endif |
| 7533 | |
| 7534 | /* |
| 7535 | * If this menu is already torn off, move it to the mouse position. |
| 7536 | */ |
| 7537 | if (IsWindow(menu->tearoff_handle)) |
| 7538 | { |
| 7539 | POINT mp; |
| 7540 | if (GetCursorPos((LPPOINT)&mp)) |
| 7541 | { |
| 7542 | SetWindowPos(menu->tearoff_handle, NULL, mp.x, mp.y, 0, 0, |
| 7543 | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); |
| 7544 | } |
| 7545 | return; |
| 7546 | } |
| 7547 | |
| 7548 | /* |
| 7549 | * Create a new tearoff. |
| 7550 | */ |
| 7551 | if (*title == MNU_HIDDEN_CHAR) |
| 7552 | title++; |
| 7553 | |
| 7554 | /* Allocate memory to store the dialog template. It's made bigger when |
| 7555 | * needed. */ |
| 7556 | template_len = DLG_ALLOC_SIZE; |
| 7557 | pdlgtemplate = p = (WORD *)LocalAlloc(LPTR, template_len); |
| 7558 | if (p == NULL) |
| 7559 | return; |
| 7560 | |
| 7561 | hwnd = GetDesktopWindow(); |
| 7562 | hdc = GetWindowDC(hwnd); |
| 7563 | #ifdef USE_SYSMENU_FONT |
| 7564 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 7565 | { |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 7566 | font = CreateFontIndirectW(&lfSysmenu); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7567 | use_lfSysmenu = TRUE; |
| 7568 | } |
| 7569 | else |
| 7570 | #endif |
| 7571 | font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 7572 | VARIABLE_PITCH , DLG_FONT_NAME); |
| 7573 | if (s_usenewlook) |
| 7574 | oldFont = SelectFont(hdc, font); |
| 7575 | else |
| 7576 | oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); |
| 7577 | |
| 7578 | /* Calculate width of a single space. Used for padding columns to the |
| 7579 | * right width. */ |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7580 | spaceWidth = GetTextWidth(hdc, (char_u *)" ", 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7581 | |
| 7582 | /* Figure out max width of the text column, the accelerator column and the |
| 7583 | * optional submenu column. */ |
| 7584 | submenuWidth = 0; |
| 7585 | for (col = 0; col < 2; col++) |
| 7586 | { |
| 7587 | columnWidths[col] = 0; |
| 7588 | for (pmenu = menu->children; pmenu != NULL; pmenu = pmenu->next) |
| 7589 | { |
| 7590 | /* Use "dname" here to compute the width of the visible text. */ |
| 7591 | text = (col == 0) ? pmenu->dname : pmenu->actext; |
| 7592 | if (text != NULL && *text != NUL) |
| 7593 | { |
| 7594 | textWidth = GetTextWidthEnc(hdc, text, (int)STRLEN(text)); |
| 7595 | if (textWidth > columnWidths[col]) |
| 7596 | columnWidths[col] = textWidth; |
| 7597 | } |
| 7598 | if (pmenu->children != NULL) |
| 7599 | submenuWidth = TEAROFF_COLUMN_PADDING * spaceWidth; |
| 7600 | } |
| 7601 | } |
| 7602 | if (columnWidths[1] == 0) |
| 7603 | { |
| 7604 | /* no accelerators */ |
| 7605 | if (submenuWidth != 0) |
| 7606 | columnWidths[0] += submenuWidth; |
| 7607 | else |
| 7608 | columnWidths[0] += spaceWidth; |
| 7609 | } |
| 7610 | else |
| 7611 | { |
| 7612 | /* there is an accelerator column */ |
| 7613 | columnWidths[0] += TEAROFF_COLUMN_PADDING * spaceWidth; |
| 7614 | columnWidths[1] += submenuWidth; |
| 7615 | } |
| 7616 | |
| 7617 | /* |
| 7618 | * Now find the total width of our 'menu'. |
| 7619 | */ |
| 7620 | textWidth = columnWidths[0] + columnWidths[1]; |
| 7621 | if (submenuWidth != 0) |
| 7622 | { |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7623 | submenuWidth = GetTextWidth(hdc, (char_u *)TEAROFF_SUBMENU_LABEL, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7624 | (int)STRLEN(TEAROFF_SUBMENU_LABEL)); |
| 7625 | textWidth += submenuWidth; |
| 7626 | } |
| 7627 | dlgwidth = GetTextWidthEnc(hdc, title, (int)STRLEN(title)); |
| 7628 | if (textWidth > dlgwidth) |
| 7629 | dlgwidth = textWidth; |
| 7630 | dlgwidth += 2 * TEAROFF_PADDING_X + TEAROFF_BUTTON_PAD_X; |
| 7631 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7632 | /* start to fill in the dlgtemplate information. addressing by WORDs */ |
| 7633 | if (s_usenewlook) |
| 7634 | lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU |DS_SETFONT| WS_VISIBLE; |
| 7635 | else |
| 7636 | lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU | WS_VISIBLE; |
| 7637 | |
| 7638 | lExtendedStyle = WS_EX_TOOLWINDOW|WS_EX_STATICEDGE; |
| 7639 | *p++ = LOWORD(lStyle); |
| 7640 | *p++ = HIWORD(lStyle); |
| 7641 | *p++ = LOWORD(lExtendedStyle); |
| 7642 | *p++ = HIWORD(lExtendedStyle); |
| 7643 | pnumitems = p; /* save where the number of items must be stored */ |
| 7644 | *p++ = 0; // NumberOfItems(will change later) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 7645 | gui_mch_getmouse(&x, &y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7646 | if (initX == 0xffffL) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 7647 | *p++ = PixelToDialogX(x); // x |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7648 | else |
| 7649 | *p++ = PixelToDialogX(initX); // x |
| 7650 | if (initY == 0xffffL) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 7651 | *p++ = PixelToDialogY(y); // y |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7652 | else |
| 7653 | *p++ = PixelToDialogY(initY); // y |
| 7654 | *p++ = PixelToDialogX(dlgwidth); // cx |
| 7655 | ptrueheight = p; |
| 7656 | *p++ = 0; // dialog height: changed later anyway |
| 7657 | *p++ = 0; // Menu |
| 7658 | *p++ = 0; // Class |
| 7659 | |
| 7660 | /* copy the title of the dialog */ |
| 7661 | nchar = nCopyAnsiToWideChar(p, ((*title) |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7662 | ? (LPSTR)title |
| 7663 | : (LPSTR)("Vim "VIM_VERSION_MEDIUM)), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7664 | p += nchar; |
| 7665 | |
| 7666 | if (s_usenewlook) |
| 7667 | { |
| 7668 | /* do the font, since DS_3DLOOK doesn't work properly */ |
| 7669 | #ifdef USE_SYSMENU_FONT |
| 7670 | if (use_lfSysmenu) |
| 7671 | { |
| 7672 | /* point size */ |
| 7673 | *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
| 7674 | GetDeviceCaps(hdc, LOGPIXELSY)); |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 7675 | wcscpy(p, lfSysmenu.lfFaceName); |
| 7676 | nchar = (int)wcslen(lfSysmenu.lfFaceName) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7677 | } |
| 7678 | else |
| 7679 | #endif |
| 7680 | { |
| 7681 | *p++ = DLG_FONT_POINT_SIZE; // point size |
Bram Moolenaar | 6edeaf3 | 2017-09-26 14:46:04 +0200 | [diff] [blame] | 7682 | nchar = nCopyAnsiToWideChar(p, DLG_FONT_NAME, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7683 | } |
| 7684 | p += nchar; |
| 7685 | } |
| 7686 | |
| 7687 | /* |
| 7688 | * Loop over all the items in the menu. |
| 7689 | * But skip over the tearbar. |
| 7690 | */ |
| 7691 | if (STRCMP(menu->children->name, TEAR_STRING) == 0) |
| 7692 | menu = menu->children->next; |
| 7693 | else |
| 7694 | menu = menu->children; |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7695 | top_menu = menu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7696 | for ( ; menu != NULL; menu = menu->next) |
| 7697 | { |
| 7698 | if (menu->modes == 0) /* this menu has just been deleted */ |
| 7699 | continue; |
| 7700 | if (menu_is_separator(menu->dname)) |
| 7701 | { |
| 7702 | sepPadding += 3; |
| 7703 | continue; |
| 7704 | } |
| 7705 | |
| 7706 | /* Check if there still is plenty of room in the template. Make it |
| 7707 | * larger when needed. */ |
| 7708 | if (((char *)p - (char *)pdlgtemplate) + 1000 > template_len) |
| 7709 | { |
| 7710 | WORD *newp; |
| 7711 | |
| 7712 | newp = (WORD *)LocalAlloc(LPTR, template_len + 4096); |
| 7713 | if (newp != NULL) |
| 7714 | { |
| 7715 | template_len += 4096; |
| 7716 | mch_memmove(newp, pdlgtemplate, |
| 7717 | (char *)p - (char *)pdlgtemplate); |
| 7718 | p = newp + (p - pdlgtemplate); |
| 7719 | pnumitems = newp + (pnumitems - pdlgtemplate); |
| 7720 | ptrueheight = newp + (ptrueheight - pdlgtemplate); |
| 7721 | LocalFree(LocalHandle(pdlgtemplate)); |
| 7722 | pdlgtemplate = newp; |
| 7723 | } |
| 7724 | } |
| 7725 | |
| 7726 | /* Figure out minimal length of this menu label. Use "name" for the |
| 7727 | * actual text, "dname" for estimating the displayed size. "name" |
| 7728 | * has "&a" for mnemonic and includes the accelerator. */ |
| 7729 | len = nameLen = (int)STRLEN(menu->name); |
| 7730 | padding0 = (columnWidths[0] - GetTextWidthEnc(hdc, menu->dname, |
| 7731 | (int)STRLEN(menu->dname))) / spaceWidth; |
| 7732 | len += padding0; |
| 7733 | |
| 7734 | if (menu->actext != NULL) |
| 7735 | { |
| 7736 | acLen = (int)STRLEN(menu->actext); |
| 7737 | len += acLen; |
| 7738 | textWidth = GetTextWidthEnc(hdc, menu->actext, acLen); |
| 7739 | } |
| 7740 | else |
| 7741 | textWidth = 0; |
| 7742 | padding1 = (columnWidths[1] - textWidth) / spaceWidth; |
| 7743 | len += padding1; |
| 7744 | |
| 7745 | if (menu->children == NULL) |
| 7746 | { |
| 7747 | padding2 = submenuWidth / spaceWidth; |
| 7748 | len += padding2; |
| 7749 | menuID = (WORD)(menu->id); |
| 7750 | } |
| 7751 | else |
| 7752 | { |
| 7753 | len += (int)STRLEN(TEAROFF_SUBMENU_LABEL); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7754 | menuID = (WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7755 | } |
| 7756 | |
| 7757 | /* Allocate menu label and fill it in */ |
Bram Moolenaar | 964b374 | 2019-05-24 18:54:09 +0200 | [diff] [blame] | 7758 | text = label = alloc(len + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7759 | if (label == NULL) |
| 7760 | break; |
| 7761 | |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 7762 | vim_strncpy(text, menu->name, nameLen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7763 | text = vim_strchr(text, TAB); /* stop at TAB before actext */ |
| 7764 | if (text == NULL) |
| 7765 | text = label + nameLen; /* no actext, use whole name */ |
| 7766 | while (padding0-- > 0) |
| 7767 | *text++ = ' '; |
| 7768 | if (menu->actext != NULL) |
| 7769 | { |
| 7770 | STRNCPY(text, menu->actext, acLen); |
| 7771 | text += acLen; |
| 7772 | } |
| 7773 | while (padding1-- > 0) |
| 7774 | *text++ = ' '; |
| 7775 | if (menu->children != NULL) |
| 7776 | { |
| 7777 | STRCPY(text, TEAROFF_SUBMENU_LABEL); |
| 7778 | text += STRLEN(TEAROFF_SUBMENU_LABEL); |
| 7779 | } |
| 7780 | else |
| 7781 | { |
| 7782 | while (padding2-- > 0) |
| 7783 | *text++ = ' '; |
| 7784 | } |
| 7785 | *text = NUL; |
| 7786 | |
| 7787 | /* |
| 7788 | * BS_LEFT will just be ignored on Win32s/NT3.5x - on |
| 7789 | * W95/NT4 it makes the tear-off look more like a menu. |
| 7790 | */ |
| 7791 | p = add_dialog_element(p, |
| 7792 | BS_PUSHBUTTON|BS_LEFT, |
| 7793 | (WORD)PixelToDialogX(TEAROFF_PADDING_X), |
| 7794 | (WORD)(sepPadding + 1 + 13 * (*pnumitems)), |
| 7795 | (WORD)PixelToDialogX(dlgwidth - 2 * TEAROFF_PADDING_X), |
| 7796 | (WORD)12, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7797 | menuID, (WORD)0x0080, (char *)label); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7798 | vim_free(label); |
| 7799 | (*pnumitems)++; |
| 7800 | } |
| 7801 | |
| 7802 | *ptrueheight = (WORD)(sepPadding + 1 + 13 * (*pnumitems)); |
| 7803 | |
| 7804 | |
| 7805 | /* show modelessly */ |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7806 | the_menu->tearoff_handle = CreateDialogIndirectParam( |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 7807 | g_hinst, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7808 | (LPDLGTEMPLATE)pdlgtemplate, |
| 7809 | s_hwnd, |
Bram Moolenaar | 66857f4 | 2017-10-22 16:43:20 +0200 | [diff] [blame] | 7810 | (DLGPROC)tearoff_callback, |
| 7811 | (LPARAM)top_menu); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7812 | |
| 7813 | LocalFree(LocalHandle(pdlgtemplate)); |
| 7814 | SelectFont(hdc, oldFont); |
| 7815 | DeleteObject(font); |
| 7816 | ReleaseDC(hwnd, hdc); |
| 7817 | |
| 7818 | /* |
| 7819 | * Reassert ourselves as the active window. This is so that after creating |
| 7820 | * a tearoff, the user doesn't have to click with the mouse just to start |
| 7821 | * typing again! |
| 7822 | */ |
| 7823 | (void)SetActiveWindow(s_hwnd); |
| 7824 | |
| 7825 | /* make sure the right buttons are enabled */ |
| 7826 | force_menu_update = TRUE; |
| 7827 | } |
| 7828 | #endif |
| 7829 | |
| 7830 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 7831 | #include "gui_w32_rc.h" |
| 7832 | |
| 7833 | /* This not defined in older SDKs */ |
| 7834 | # ifndef TBSTYLE_FLAT |
| 7835 | # define TBSTYLE_FLAT 0x0800 |
| 7836 | # endif |
| 7837 | |
| 7838 | /* |
| 7839 | * Create the toolbar, initially unpopulated. |
| 7840 | * (just like the menu, there are no defaults, it's all |
| 7841 | * set up through menu.vim) |
| 7842 | */ |
| 7843 | static void |
| 7844 | initialise_toolbar(void) |
| 7845 | { |
| 7846 | InitCommonControls(); |
| 7847 | s_toolbarhwnd = CreateToolbarEx( |
| 7848 | s_hwnd, |
| 7849 | WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT, |
| 7850 | 4000, //any old big number |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 7851 | 31, //number of images in initial bitmap |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 7852 | g_hinst, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7853 | IDR_TOOLBAR1, // id of initial bitmap |
| 7854 | NULL, |
| 7855 | 0, // initial number of buttons |
| 7856 | TOOLBAR_BUTTON_WIDTH, //api guide is wrong! |
| 7857 | TOOLBAR_BUTTON_HEIGHT, |
| 7858 | TOOLBAR_BUTTON_WIDTH, |
| 7859 | TOOLBAR_BUTTON_HEIGHT, |
| 7860 | sizeof(TBBUTTON) |
| 7861 | ); |
Bram Moolenaar | 5f76334 | 2019-11-17 22:54:10 +0100 | [diff] [blame] | 7862 | |
| 7863 | // Remove transparency from the toolbar to prevent the main window |
| 7864 | // background colour showing through |
| 7865 | SendMessage(s_toolbarhwnd, TB_SETSTYLE, 0, |
| 7866 | SendMessage(s_toolbarhwnd, TB_GETSTYLE, 0, 0) & ~TBSTYLE_TRANSPARENT); |
| 7867 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 7868 | s_toolbar_wndproc = SubclassWindow(s_toolbarhwnd, toolbar_wndproc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7869 | |
| 7870 | gui_mch_show_toolbar(vim_strchr(p_go, GO_TOOLBAR) != NULL); |
| 7871 | } |
| 7872 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 7873 | static LRESULT CALLBACK |
| 7874 | toolbar_wndproc( |
| 7875 | HWND hwnd, |
| 7876 | UINT uMsg, |
| 7877 | WPARAM wParam, |
| 7878 | LPARAM lParam) |
| 7879 | { |
| 7880 | HandleMouseHide(uMsg, lParam); |
| 7881 | return CallWindowProc(s_toolbar_wndproc, hwnd, uMsg, wParam, lParam); |
| 7882 | } |
| 7883 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7884 | static int |
| 7885 | get_toolbar_bitmap(vimmenu_T *menu) |
| 7886 | { |
| 7887 | int i = -1; |
| 7888 | |
| 7889 | /* |
| 7890 | * Check user bitmaps first, unless builtin is specified. |
| 7891 | */ |
Bram Moolenaar | cea912a | 2016-10-12 14:20:24 +0200 | [diff] [blame] | 7892 | if (!menu->icon_builtin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7893 | { |
| 7894 | char_u fname[MAXPATHL]; |
| 7895 | HANDLE hbitmap = NULL; |
| 7896 | |
| 7897 | if (menu->iconfile != NULL) |
| 7898 | { |
| 7899 | gui_find_iconfile(menu->iconfile, fname, "bmp"); |
| 7900 | hbitmap = LoadImage( |
| 7901 | NULL, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7902 | (LPCSTR)fname, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7903 | IMAGE_BITMAP, |
| 7904 | TOOLBAR_BUTTON_WIDTH, |
| 7905 | TOOLBAR_BUTTON_HEIGHT, |
| 7906 | LR_LOADFROMFILE | |
| 7907 | LR_LOADMAP3DCOLORS |
| 7908 | ); |
| 7909 | } |
| 7910 | |
| 7911 | /* |
| 7912 | * If the LoadImage call failed, or the "icon=" file |
| 7913 | * didn't exist or wasn't specified, try the menu name |
| 7914 | */ |
| 7915 | if (hbitmap == NULL |
Bram Moolenaar | a5f5c8b | 2013-06-27 22:29:38 +0200 | [diff] [blame] | 7916 | && (gui_find_bitmap( |
| 7917 | #ifdef FEAT_MULTI_LANG |
| 7918 | menu->en_dname != NULL ? menu->en_dname : |
| 7919 | #endif |
| 7920 | menu->dname, fname, "bmp") == OK)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7921 | hbitmap = LoadImage( |
| 7922 | NULL, |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 7923 | (LPCSTR)fname, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7924 | IMAGE_BITMAP, |
| 7925 | TOOLBAR_BUTTON_WIDTH, |
| 7926 | TOOLBAR_BUTTON_HEIGHT, |
| 7927 | LR_LOADFROMFILE | |
| 7928 | LR_LOADMAP3DCOLORS |
| 7929 | ); |
| 7930 | |
| 7931 | if (hbitmap != NULL) |
| 7932 | { |
| 7933 | TBADDBITMAP tbAddBitmap; |
| 7934 | |
| 7935 | tbAddBitmap.hInst = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7936 | tbAddBitmap.nID = (long_u)hbitmap; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7937 | |
| 7938 | i = (int)SendMessage(s_toolbarhwnd, TB_ADDBITMAP, |
| 7939 | (WPARAM)1, (LPARAM)&tbAddBitmap); |
| 7940 | /* i will be set to -1 if it fails */ |
| 7941 | } |
| 7942 | } |
| 7943 | if (i == -1 && menu->iconidx >= 0 && menu->iconidx < TOOLBAR_BITMAP_COUNT) |
| 7944 | i = menu->iconidx; |
| 7945 | |
| 7946 | return i; |
| 7947 | } |
| 7948 | #endif |
| 7949 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 7950 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
| 7951 | static void |
| 7952 | initialise_tabline(void) |
| 7953 | { |
| 7954 | InitCommonControls(); |
| 7955 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7956 | s_tabhwnd = CreateWindow(WC_TABCONTROL, "Vim tabline", |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 7957 | WS_CHILD|TCS_FOCUSNEVER|TCS_TOOLTIPS, |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 7958 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 7959 | CW_USEDEFAULT, s_hwnd, NULL, g_hinst, NULL); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 7960 | s_tabline_wndproc = SubclassWindow(s_tabhwnd, tabline_wndproc); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7961 | |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 7962 | gui.tabline_height = TABLINE_HEIGHT; |
| 7963 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7964 | # ifdef USE_SYSMENU_FONT |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 7965 | set_tabline_font(); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 7966 | # endif |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 7967 | } |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 7968 | |
Bram Moolenaar | ca05aa2 | 2017-10-22 15:36:14 +0200 | [diff] [blame] | 7969 | /* |
| 7970 | * Get tabpage_T from POINT. |
| 7971 | */ |
| 7972 | static tabpage_T * |
| 7973 | GetTabFromPoint( |
| 7974 | HWND hWnd, |
| 7975 | POINT pt) |
| 7976 | { |
| 7977 | tabpage_T *ptp = NULL; |
| 7978 | |
| 7979 | if (gui_mch_showing_tabline()) |
| 7980 | { |
| 7981 | TCHITTESTINFO htinfo; |
| 7982 | htinfo.pt = pt; |
| 7983 | /* ignore if a window under cusor is not tabcontrol. */ |
| 7984 | if (s_tabhwnd == hWnd) |
| 7985 | { |
| 7986 | int idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 7987 | if (idx != -1) |
| 7988 | ptp = find_tabpage(idx + 1); |
| 7989 | } |
| 7990 | } |
| 7991 | return ptp; |
| 7992 | } |
| 7993 | |
| 7994 | static POINT s_pt = {0, 0}; |
| 7995 | static HCURSOR s_hCursor = NULL; |
| 7996 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 7997 | static LRESULT CALLBACK |
| 7998 | tabline_wndproc( |
| 7999 | HWND hwnd, |
| 8000 | UINT uMsg, |
| 8001 | WPARAM wParam, |
| 8002 | LPARAM lParam) |
| 8003 | { |
Bram Moolenaar | ca05aa2 | 2017-10-22 15:36:14 +0200 | [diff] [blame] | 8004 | POINT pt; |
| 8005 | tabpage_T *tp; |
| 8006 | RECT rect; |
| 8007 | int nCenter; |
| 8008 | int idx0; |
| 8009 | int idx1; |
| 8010 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8011 | HandleMouseHide(uMsg, lParam); |
Bram Moolenaar | ca05aa2 | 2017-10-22 15:36:14 +0200 | [diff] [blame] | 8012 | |
| 8013 | switch (uMsg) |
| 8014 | { |
| 8015 | case WM_LBUTTONDOWN: |
| 8016 | { |
| 8017 | s_pt.x = GET_X_LPARAM(lParam); |
| 8018 | s_pt.y = GET_Y_LPARAM(lParam); |
| 8019 | SetCapture(hwnd); |
| 8020 | s_hCursor = GetCursor(); /* backup default cursor */ |
| 8021 | break; |
| 8022 | } |
| 8023 | case WM_MOUSEMOVE: |
| 8024 | if (GetCapture() == hwnd |
| 8025 | && ((wParam & MK_LBUTTON)) != 0) |
| 8026 | { |
| 8027 | pt.x = GET_X_LPARAM(lParam); |
| 8028 | pt.y = s_pt.y; |
| 8029 | if (abs(pt.x - s_pt.x) > GetSystemMetrics(SM_CXDRAG)) |
| 8030 | { |
| 8031 | SetCursor(LoadCursor(NULL, IDC_SIZEWE)); |
| 8032 | |
| 8033 | tp = GetTabFromPoint(hwnd, pt); |
| 8034 | if (tp != NULL) |
| 8035 | { |
| 8036 | idx0 = tabpage_index(curtab) - 1; |
| 8037 | idx1 = tabpage_index(tp) - 1; |
| 8038 | |
| 8039 | TabCtrl_GetItemRect(hwnd, idx1, &rect); |
| 8040 | nCenter = rect.left + (rect.right - rect.left) / 2; |
| 8041 | |
| 8042 | /* Check if the mouse cursor goes over the center of |
| 8043 | * the next tab to prevent "flickering". */ |
| 8044 | if ((idx0 < idx1) && (nCenter < pt.x)) |
| 8045 | { |
| 8046 | tabpage_move(idx1 + 1); |
| 8047 | update_screen(0); |
| 8048 | } |
| 8049 | else if ((idx1 < idx0) && (pt.x < nCenter)) |
| 8050 | { |
| 8051 | tabpage_move(idx1); |
| 8052 | update_screen(0); |
| 8053 | } |
| 8054 | } |
| 8055 | } |
| 8056 | } |
| 8057 | break; |
| 8058 | case WM_LBUTTONUP: |
| 8059 | { |
| 8060 | if (GetCapture() == hwnd) |
| 8061 | { |
| 8062 | SetCursor(s_hCursor); |
| 8063 | ReleaseCapture(); |
| 8064 | } |
| 8065 | break; |
| 8066 | } |
| 8067 | default: |
| 8068 | break; |
| 8069 | } |
| 8070 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 8071 | return CallWindowProc(s_tabline_wndproc, hwnd, uMsg, wParam, lParam); |
| 8072 | } |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 8073 | #endif |
| 8074 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8075 | #if defined(FEAT_OLE) || defined(FEAT_EVAL) || defined(PROTO) |
| 8076 | /* |
| 8077 | * Make the GUI window come to the foreground. |
| 8078 | */ |
| 8079 | void |
| 8080 | gui_mch_set_foreground(void) |
| 8081 | { |
| 8082 | if (IsIconic(s_hwnd)) |
| 8083 | SendMessage(s_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); |
| 8084 | SetForegroundWindow(s_hwnd); |
| 8085 | } |
| 8086 | #endif |
| 8087 | |
| 8088 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 8089 | static void |
| 8090 | dyn_imm_load(void) |
| 8091 | { |
Bram Moolenaar | ebbcb82 | 2010-10-23 14:02:54 +0200 | [diff] [blame] | 8092 | hLibImm = vimLoadLib("imm32.dll"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8093 | if (hLibImm == NULL) |
| 8094 | return; |
| 8095 | |
| 8096 | pImmGetCompositionStringA |
| 8097 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringA"); |
| 8098 | pImmGetCompositionStringW |
| 8099 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringW"); |
| 8100 | pImmGetContext |
| 8101 | = (void *)GetProcAddress(hLibImm, "ImmGetContext"); |
| 8102 | pImmAssociateContext |
| 8103 | = (void *)GetProcAddress(hLibImm, "ImmAssociateContext"); |
| 8104 | pImmReleaseContext |
| 8105 | = (void *)GetProcAddress(hLibImm, "ImmReleaseContext"); |
| 8106 | pImmGetOpenStatus |
| 8107 | = (void *)GetProcAddress(hLibImm, "ImmGetOpenStatus"); |
| 8108 | pImmSetOpenStatus |
| 8109 | = (void *)GetProcAddress(hLibImm, "ImmSetOpenStatus"); |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 8110 | pImmGetCompositionFontW |
| 8111 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionFontW"); |
| 8112 | pImmSetCompositionFontW |
| 8113 | = (void *)GetProcAddress(hLibImm, "ImmSetCompositionFontW"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8114 | pImmSetCompositionWindow |
| 8115 | = (void *)GetProcAddress(hLibImm, "ImmSetCompositionWindow"); |
| 8116 | pImmGetConversionStatus |
| 8117 | = (void *)GetProcAddress(hLibImm, "ImmGetConversionStatus"); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 8118 | pImmSetConversionStatus |
| 8119 | = (void *)GetProcAddress(hLibImm, "ImmSetConversionStatus"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8120 | |
| 8121 | if ( pImmGetCompositionStringA == NULL |
| 8122 | || pImmGetCompositionStringW == NULL |
| 8123 | || pImmGetContext == NULL |
| 8124 | || pImmAssociateContext == NULL |
| 8125 | || pImmReleaseContext == NULL |
| 8126 | || pImmGetOpenStatus == NULL |
| 8127 | || pImmSetOpenStatus == NULL |
Bram Moolenaar | 433a5eb | 2019-03-30 16:24:16 +0100 | [diff] [blame] | 8128 | || pImmGetCompositionFontW == NULL |
| 8129 | || pImmSetCompositionFontW == NULL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8130 | || pImmSetCompositionWindow == NULL |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 8131 | || pImmGetConversionStatus == NULL |
| 8132 | || pImmSetConversionStatus == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8133 | { |
| 8134 | FreeLibrary(hLibImm); |
| 8135 | hLibImm = NULL; |
| 8136 | pImmGetContext = NULL; |
| 8137 | return; |
| 8138 | } |
| 8139 | |
| 8140 | return; |
| 8141 | } |
| 8142 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8143 | #endif |
| 8144 | |
| 8145 | #if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
| 8146 | |
| 8147 | # ifdef FEAT_XPM_W32 |
| 8148 | # define IMAGE_XPM 100 |
| 8149 | # endif |
| 8150 | |
| 8151 | typedef struct _signicon_t |
| 8152 | { |
| 8153 | HANDLE hImage; |
| 8154 | UINT uType; |
| 8155 | #ifdef FEAT_XPM_W32 |
| 8156 | HANDLE hShape; /* Mask bitmap handle */ |
| 8157 | #endif |
| 8158 | } signicon_t; |
| 8159 | |
| 8160 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8161 | gui_mch_drawsign(int row, int col, int typenr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8162 | { |
| 8163 | signicon_t *sign; |
| 8164 | int x, y, w, h; |
| 8165 | |
| 8166 | if (!gui.in_use || (sign = (signicon_t *)sign_get_image(typenr)) == NULL) |
| 8167 | return; |
| 8168 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 8169 | #if defined(FEAT_DIRECTX) |
| 8170 | if (IS_ENABLE_DIRECTX()) |
| 8171 | DWriteContext_Flush(s_dwc); |
| 8172 | #endif |
| 8173 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8174 | x = TEXT_X(col); |
| 8175 | y = TEXT_Y(row); |
| 8176 | w = gui.char_width * 2; |
| 8177 | h = gui.char_height; |
| 8178 | switch (sign->uType) |
| 8179 | { |
| 8180 | case IMAGE_BITMAP: |
| 8181 | { |
| 8182 | HDC hdcMem; |
| 8183 | HBITMAP hbmpOld; |
| 8184 | |
| 8185 | hdcMem = CreateCompatibleDC(s_hdc); |
| 8186 | hbmpOld = (HBITMAP)SelectObject(hdcMem, sign->hImage); |
| 8187 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCCOPY); |
| 8188 | SelectObject(hdcMem, hbmpOld); |
| 8189 | DeleteDC(hdcMem); |
| 8190 | } |
| 8191 | break; |
| 8192 | case IMAGE_ICON: |
| 8193 | case IMAGE_CURSOR: |
| 8194 | DrawIconEx(s_hdc, x, y, (HICON)sign->hImage, w, h, 0, NULL, DI_NORMAL); |
| 8195 | break; |
| 8196 | #ifdef FEAT_XPM_W32 |
| 8197 | case IMAGE_XPM: |
| 8198 | { |
| 8199 | HDC hdcMem; |
| 8200 | HBITMAP hbmpOld; |
| 8201 | |
| 8202 | hdcMem = CreateCompatibleDC(s_hdc); |
| 8203 | hbmpOld = (HBITMAP)SelectObject(hdcMem, sign->hShape); |
| 8204 | /* Make hole */ |
| 8205 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCAND); |
| 8206 | |
| 8207 | SelectObject(hdcMem, sign->hImage); |
| 8208 | /* Paint sign */ |
| 8209 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCPAINT); |
| 8210 | SelectObject(hdcMem, hbmpOld); |
| 8211 | DeleteDC(hdcMem); |
| 8212 | } |
| 8213 | break; |
| 8214 | #endif |
| 8215 | } |
| 8216 | } |
| 8217 | |
| 8218 | static void |
| 8219 | close_signicon_image(signicon_t *sign) |
| 8220 | { |
| 8221 | if (sign) |
| 8222 | switch (sign->uType) |
| 8223 | { |
| 8224 | case IMAGE_BITMAP: |
| 8225 | DeleteObject((HGDIOBJ)sign->hImage); |
| 8226 | break; |
| 8227 | case IMAGE_CURSOR: |
| 8228 | DestroyCursor((HCURSOR)sign->hImage); |
| 8229 | break; |
| 8230 | case IMAGE_ICON: |
| 8231 | DestroyIcon((HICON)sign->hImage); |
| 8232 | break; |
| 8233 | #ifdef FEAT_XPM_W32 |
| 8234 | case IMAGE_XPM: |
| 8235 | DeleteObject((HBITMAP)sign->hImage); |
| 8236 | DeleteObject((HBITMAP)sign->hShape); |
| 8237 | break; |
| 8238 | #endif |
| 8239 | } |
| 8240 | } |
| 8241 | |
| 8242 | void * |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8243 | gui_mch_register_sign(char_u *signfile) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8244 | { |
| 8245 | signicon_t sign, *psign; |
| 8246 | char_u *ext; |
| 8247 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8248 | sign.hImage = NULL; |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 8249 | ext = signfile + STRLEN(signfile) - 4; /* get extension */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8250 | if (ext > signfile) |
| 8251 | { |
| 8252 | int do_load = 1; |
| 8253 | |
| 8254 | if (!STRICMP(ext, ".bmp")) |
| 8255 | sign.uType = IMAGE_BITMAP; |
| 8256 | else if (!STRICMP(ext, ".ico")) |
| 8257 | sign.uType = IMAGE_ICON; |
| 8258 | else if (!STRICMP(ext, ".cur") || !STRICMP(ext, ".ani")) |
| 8259 | sign.uType = IMAGE_CURSOR; |
| 8260 | else |
| 8261 | do_load = 0; |
| 8262 | |
| 8263 | if (do_load) |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8264 | sign.hImage = (HANDLE)LoadImage(NULL, (LPCSTR)signfile, sign.uType, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8265 | gui.char_width * 2, gui.char_height, |
| 8266 | LR_LOADFROMFILE | LR_CREATEDIBSECTION); |
| 8267 | #ifdef FEAT_XPM_W32 |
| 8268 | if (!STRICMP(ext, ".xpm")) |
| 8269 | { |
| 8270 | sign.uType = IMAGE_XPM; |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8271 | LoadXpmImage((char *)signfile, (HBITMAP *)&sign.hImage, |
| 8272 | (HBITMAP *)&sign.hShape); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8273 | } |
| 8274 | #endif |
| 8275 | } |
| 8276 | |
| 8277 | psign = NULL; |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 8278 | if (sign.hImage && (psign = ALLOC_ONE(signicon_t)) != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8279 | *psign = sign; |
| 8280 | |
| 8281 | if (!psign) |
| 8282 | { |
| 8283 | if (sign.hImage) |
| 8284 | close_signicon_image(&sign); |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 8285 | emsg(_(e_signdata)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8286 | } |
| 8287 | return (void *)psign; |
| 8288 | |
| 8289 | } |
| 8290 | |
| 8291 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8292 | gui_mch_destroy_sign(void *sign) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8293 | { |
| 8294 | if (sign) |
| 8295 | { |
| 8296 | close_signicon_image((signicon_t *)sign); |
| 8297 | vim_free(sign); |
| 8298 | } |
| 8299 | } |
Bram Moolenaar | 5c06f8b | 2005-05-31 22:14:58 +0000 | [diff] [blame] | 8300 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8301 | |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 8302 | #if defined(FEAT_BEVAL_GUI) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8303 | |
| 8304 | /* BALLOON-EVAL IMPLEMENTATION FOR WINDOWS. |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 8305 | * Added by Sergey Khorev <sergey.khorev@gmail.com> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8306 | * |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 8307 | * The only reused thing is beval.h and get_beval_info() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8308 | * from gui_beval.c (note it uses x and y of the BalloonEval struct |
| 8309 | * to get current mouse position). |
| 8310 | * |
| 8311 | * Trying to use as more Windows services as possible, and as less |
| 8312 | * IE version as possible :)). |
| 8313 | * |
| 8314 | * 1) Don't create ToolTip in gui_mch_create_beval_area, only initialize |
| 8315 | * BalloonEval struct. |
| 8316 | * 2) Enable/Disable simply create/kill BalloonEval Timer |
| 8317 | * 3) When there was enough inactivity, timer procedure posts |
| 8318 | * async request to debugger |
| 8319 | * 4) gui_mch_post_balloon (invoked from netbeans.c) creates tooltip control |
| 8320 | * and performs some actions to show it ASAP |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 8321 | * 5) WM_NOTIFY:TTN_POP destroys created tooltip |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8322 | */ |
| 8323 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8324 | /* |
| 8325 | * determine whether installed Common Controls support multiline tooltips |
| 8326 | * (i.e. their version is >= 4.70 |
| 8327 | */ |
| 8328 | int |
| 8329 | multiline_balloon_available(void) |
| 8330 | { |
| 8331 | HINSTANCE hDll; |
| 8332 | static char comctl_dll[] = "comctl32.dll"; |
| 8333 | static int multiline_tip = MAYBE; |
| 8334 | |
| 8335 | if (multiline_tip != MAYBE) |
| 8336 | return multiline_tip; |
| 8337 | |
| 8338 | hDll = GetModuleHandle(comctl_dll); |
| 8339 | if (hDll != NULL) |
| 8340 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8341 | DLLGETVERSIONPROC pGetVer; |
| 8342 | pGetVer = (DLLGETVERSIONPROC)GetProcAddress(hDll, "DllGetVersion"); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8343 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8344 | if (pGetVer != NULL) |
| 8345 | { |
| 8346 | DLLVERSIONINFO dvi; |
| 8347 | HRESULT hr; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8348 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8349 | ZeroMemory(&dvi, sizeof(dvi)); |
| 8350 | dvi.cbSize = sizeof(dvi); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8351 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8352 | hr = (*pGetVer)(&dvi); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8353 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8354 | if (SUCCEEDED(hr) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8355 | && (dvi.dwMajorVersion > 4 |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8356 | || (dvi.dwMajorVersion == 4 |
| 8357 | && dvi.dwMinorVersion >= 70))) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8358 | { |
| 8359 | multiline_tip = TRUE; |
| 8360 | return multiline_tip; |
| 8361 | } |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 8362 | } |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8363 | else |
| 8364 | { |
| 8365 | /* there is chance we have ancient CommCtl 4.70 |
| 8366 | which doesn't export DllGetVersion */ |
| 8367 | DWORD dwHandle = 0; |
| 8368 | DWORD len = GetFileVersionInfoSize(comctl_dll, &dwHandle); |
| 8369 | if (len > 0) |
| 8370 | { |
| 8371 | VS_FIXEDFILEINFO *ver; |
| 8372 | UINT vlen = 0; |
| 8373 | void *data = alloc(len); |
| 8374 | |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8375 | if ((data != NULL |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8376 | && GetFileVersionInfo(comctl_dll, 0, len, data) |
| 8377 | && VerQueryValue(data, "\\", (void **)&ver, &vlen) |
| 8378 | && vlen |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8379 | && HIWORD(ver->dwFileVersionMS) > 4) |
| 8380 | || ((HIWORD(ver->dwFileVersionMS) == 4 |
| 8381 | && LOWORD(ver->dwFileVersionMS) >= 70))) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8382 | { |
| 8383 | vim_free(data); |
| 8384 | multiline_tip = TRUE; |
| 8385 | return multiline_tip; |
| 8386 | } |
| 8387 | vim_free(data); |
| 8388 | } |
| 8389 | } |
| 8390 | } |
| 8391 | multiline_tip = FALSE; |
| 8392 | return multiline_tip; |
| 8393 | } |
| 8394 | |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8395 | static void |
Bram Moolenaar | 0eb035c | 2019-04-02 22:15:55 +0200 | [diff] [blame] | 8396 | make_tooltip(BalloonEval *beval, char *text, POINT pt) |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8397 | { |
| 8398 | TOOLINFOW *pti; |
| 8399 | int ToolInfoSize; |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8400 | |
| 8401 | if (multiline_balloon_available() == TRUE) |
| 8402 | ToolInfoSize = sizeof(TOOLINFOW_NEW); |
| 8403 | else |
| 8404 | ToolInfoSize = sizeof(TOOLINFOW); |
| 8405 | |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 8406 | pti = alloc(ToolInfoSize); |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8407 | if (pti == NULL) |
| 8408 | return; |
| 8409 | |
| 8410 | beval->balloon = CreateWindowExW(WS_EX_TOPMOST, TOOLTIPS_CLASSW, |
| 8411 | NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, |
| 8412 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
Bram Moolenaar | afde13b | 2019-04-28 19:46:49 +0200 | [diff] [blame] | 8413 | beval->target, NULL, g_hinst, NULL); |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8414 | |
| 8415 | SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0, |
| 8416 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
| 8417 | |
| 8418 | pti->cbSize = ToolInfoSize; |
| 8419 | pti->uFlags = TTF_SUBCLASS; |
| 8420 | pti->hwnd = beval->target; |
| 8421 | pti->hinst = 0; // Don't use string resources |
| 8422 | pti->uId = ID_BEVAL_TOOLTIP; |
| 8423 | |
| 8424 | if (multiline_balloon_available() == TRUE) |
| 8425 | { |
| 8426 | RECT rect; |
| 8427 | TOOLINFOW_NEW *ptin = (TOOLINFOW_NEW *)pti; |
| 8428 | pti->lpszText = LPSTR_TEXTCALLBACKW; |
Bram Moolenaar | 6d9e71a | 2018-12-28 19:13:34 +0100 | [diff] [blame] | 8429 | beval->tofree = enc_to_utf16((char_u*)text, NULL); |
| 8430 | ptin->lParam = (LPARAM)beval->tofree; |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8431 | // switch multiline tooltips on |
| 8432 | if (GetClientRect(s_textArea, &rect)) |
| 8433 | SendMessageW(beval->balloon, TTM_SETMAXTIPWIDTH, 0, |
| 8434 | (LPARAM)rect.right); |
| 8435 | } |
| 8436 | else |
| 8437 | { |
| 8438 | // do this old way |
Bram Moolenaar | 6d9e71a | 2018-12-28 19:13:34 +0100 | [diff] [blame] | 8439 | beval->tofree = enc_to_utf16((char_u*)text, NULL); |
| 8440 | pti->lpszText = (LPWSTR)beval->tofree; |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8441 | } |
| 8442 | |
| 8443 | // Limit ballooneval bounding rect to CursorPos neighbourhood. |
| 8444 | pti->rect.left = pt.x - 3; |
| 8445 | pti->rect.top = pt.y - 3; |
| 8446 | pti->rect.right = pt.x + 3; |
| 8447 | pti->rect.bottom = pt.y + 3; |
| 8448 | |
| 8449 | SendMessageW(beval->balloon, TTM_ADDTOOLW, 0, (LPARAM)pti); |
| 8450 | // Make tooltip appear sooner. |
| 8451 | SendMessageW(beval->balloon, TTM_SETDELAYTIME, TTDT_INITIAL, 10); |
| 8452 | // I've performed some tests and it seems the longest possible life time |
| 8453 | // of tooltip is 30 seconds. |
| 8454 | SendMessageW(beval->balloon, TTM_SETDELAYTIME, TTDT_AUTOPOP, 30000); |
| 8455 | /* |
| 8456 | * HACK: force tooltip to appear, because it'll not appear until |
| 8457 | * first mouse move. D*mn M$ |
| 8458 | * Amazingly moving (2, 2) and then (-1, -1) the mouse doesn't move. |
| 8459 | */ |
| 8460 | mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0); |
| 8461 | mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0); |
| 8462 | vim_free(pti); |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8463 | } |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8464 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8465 | static void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8466 | delete_tooltip(BalloonEval *beval) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8467 | { |
Bram Moolenaar | 8e5f5b4 | 2015-08-26 23:12:38 +0200 | [diff] [blame] | 8468 | PostMessage(beval->balloon, WM_CLOSE, 0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8469 | } |
| 8470 | |
| 8471 | static VOID CALLBACK |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8472 | BevalTimerProc( |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 8473 | HWND hwnd UNUSED, |
| 8474 | UINT uMsg UNUSED, |
| 8475 | UINT_PTR idEvent UNUSED, |
| 8476 | DWORD dwTime) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8477 | { |
| 8478 | POINT pt; |
| 8479 | RECT rect; |
| 8480 | |
| 8481 | if (cur_beval == NULL || cur_beval->showState == ShS_SHOWING || !p_beval) |
| 8482 | return; |
| 8483 | |
| 8484 | GetCursorPos(&pt); |
| 8485 | if (WindowFromPoint(pt) != s_textArea) |
| 8486 | return; |
| 8487 | |
| 8488 | ScreenToClient(s_textArea, &pt); |
| 8489 | GetClientRect(s_textArea, &rect); |
| 8490 | if (!PtInRect(&rect, pt)) |
| 8491 | return; |
| 8492 | |
| 8493 | if (LastActivity > 0 |
| 8494 | && (dwTime - LastActivity) >= (DWORD)p_bdlay |
| 8495 | && (cur_beval->showState != ShS_PENDING |
| 8496 | || abs(cur_beval->x - pt.x) > 3 |
| 8497 | || abs(cur_beval->y - pt.y) > 3)) |
| 8498 | { |
| 8499 | /* Pointer resting in one place long enough, it's time to show |
| 8500 | * the tooltip. */ |
| 8501 | cur_beval->showState = ShS_PENDING; |
| 8502 | cur_beval->x = pt.x; |
| 8503 | cur_beval->y = pt.y; |
| 8504 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8505 | // TRACE0("BevalTimerProc: sending request"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8506 | |
| 8507 | if (cur_beval->msgCB != NULL) |
| 8508 | (*cur_beval->msgCB)(cur_beval, 0); |
| 8509 | } |
| 8510 | } |
| 8511 | |
| 8512 | void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 8513 | gui_mch_disable_beval_area(BalloonEval *beval UNUSED) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8514 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8515 | // TRACE0("gui_mch_disable_beval_area {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8516 | KillTimer(s_textArea, BevalTimerId); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8517 | // TRACE0("gui_mch_disable_beval_area }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8518 | } |
| 8519 | |
| 8520 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8521 | gui_mch_enable_beval_area(BalloonEval *beval) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8522 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8523 | // TRACE0("gui_mch_enable_beval_area |||"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8524 | if (beval == NULL) |
| 8525 | return; |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8526 | // TRACE0("gui_mch_enable_beval_area {{{"); |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 8527 | BevalTimerId = SetTimer(s_textArea, 0, (UINT)(p_bdlay / 2), BevalTimerProc); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8528 | // TRACE0("gui_mch_enable_beval_area }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8529 | } |
| 8530 | |
| 8531 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8532 | gui_mch_post_balloon(BalloonEval *beval, char_u *mesg) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8533 | { |
| 8534 | POINT pt; |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 8535 | |
Bram Moolenaar | be0a259 | 2019-05-09 13:50:16 +0200 | [diff] [blame] | 8536 | vim_free(beval->msg); |
| 8537 | beval->msg = mesg == NULL ? NULL : vim_strsave(mesg); |
| 8538 | if (beval->msg == NULL) |
| 8539 | { |
| 8540 | delete_tooltip(beval); |
| 8541 | beval->showState = ShS_NEUTRAL; |
| 8542 | return; |
| 8543 | } |
| 8544 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8545 | // TRACE0("gui_mch_post_balloon {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8546 | if (beval->showState == ShS_SHOWING) |
| 8547 | return; |
| 8548 | GetCursorPos(&pt); |
| 8549 | ScreenToClient(s_textArea, &pt); |
| 8550 | |
| 8551 | 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] | 8552 | { |
Bram Moolenaar | 1c46544 | 2017-03-12 20:10:05 +0100 | [diff] [blame] | 8553 | /* cursor is still here */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8554 | gui_mch_disable_beval_area(cur_beval); |
| 8555 | beval->showState = ShS_SHOWING; |
Bram Moolenaar | 418f81b | 2016-02-16 20:12:02 +0100 | [diff] [blame] | 8556 | make_tooltip(beval, (char *)mesg, pt); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8557 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8558 | // TRACE0("gui_mch_post_balloon }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8559 | } |
| 8560 | |
| 8561 | BalloonEval * |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8562 | gui_mch_create_beval_area( |
Bram Moolenaar | bd67aac | 2019-09-21 23:09:04 +0200 | [diff] [blame] | 8563 | void *target UNUSED, /* ignored, always use s_textArea */ |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8564 | char_u *mesg, |
| 8565 | void (*mesgCB)(BalloonEval *, int), |
| 8566 | void *clientData) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8567 | { |
| 8568 | /* partially stolen from gui_beval.c */ |
| 8569 | BalloonEval *beval; |
| 8570 | |
| 8571 | if (mesg != NULL && mesgCB != NULL) |
| 8572 | { |
Bram Moolenaar | f9e3e09 | 2019-01-13 23:38:42 +0100 | [diff] [blame] | 8573 | iemsg(_("E232: Cannot create BalloonEval with both message and callback")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8574 | return NULL; |
| 8575 | } |
| 8576 | |
Bram Moolenaar | c799fe2 | 2019-05-28 23:08:19 +0200 | [diff] [blame] | 8577 | beval = ALLOC_CLEAR_ONE(BalloonEval); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8578 | if (beval != NULL) |
| 8579 | { |
| 8580 | beval->target = s_textArea; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8581 | |
| 8582 | beval->showState = ShS_NEUTRAL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8583 | beval->msg = mesg; |
| 8584 | beval->msgCB = mesgCB; |
| 8585 | beval->clientData = clientData; |
| 8586 | |
| 8587 | InitCommonControls(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8588 | cur_beval = beval; |
| 8589 | |
| 8590 | if (p_beval) |
| 8591 | gui_mch_enable_beval_area(beval); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8592 | } |
| 8593 | return beval; |
| 8594 | } |
| 8595 | |
| 8596 | static void |
Bram Moolenaar | 1266d67 | 2017-02-01 13:43:36 +0100 | [diff] [blame] | 8597 | Handle_WM_Notify(HWND hwnd UNUSED, LPNMHDR pnmh) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8598 | { |
| 8599 | if (pnmh->idFrom != ID_BEVAL_TOOLTIP) /* it is not our tooltip */ |
| 8600 | return; |
| 8601 | |
| 8602 | if (cur_beval != NULL) |
| 8603 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8604 | switch (pnmh->code) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8605 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8606 | case TTN_SHOW: |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8607 | // TRACE0("TTN_SHOW {{{"); |
| 8608 | // TRACE0("TTN_SHOW }}}"); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8609 | break; |
| 8610 | case TTN_POP: /* Before tooltip disappear */ |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8611 | // TRACE0("TTN_POP {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8612 | delete_tooltip(cur_beval); |
| 8613 | gui_mch_enable_beval_area(cur_beval); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8614 | // TRACE0("TTN_POP }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8615 | |
| 8616 | cur_beval->showState = ShS_NEUTRAL; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8617 | break; |
| 8618 | case TTN_GETDISPINFO: |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 8619 | { |
| 8620 | /* if you get there then we have new common controls */ |
| 8621 | NMTTDISPINFO_NEW *info = (NMTTDISPINFO_NEW *)pnmh; |
| 8622 | info->lpszText = (LPSTR)info->lParam; |
| 8623 | info->uFlags |= TTF_DI_SETITEM; |
| 8624 | } |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 8625 | break; |
Bram Moolenaar | d385b5d | 2018-12-27 22:43:08 +0100 | [diff] [blame] | 8626 | case TTN_GETDISPINFOW: |
| 8627 | { |
| 8628 | // if we get here then we have new common controls |
| 8629 | NMTTDISPINFOW_NEW *info = (NMTTDISPINFOW_NEW *)pnmh; |
| 8630 | info->lpszText = (LPWSTR)info->lParam; |
| 8631 | info->uFlags |= TTF_DI_SETITEM; |
| 8632 | } |
| 8633 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8634 | } |
| 8635 | } |
| 8636 | } |
| 8637 | |
| 8638 | static void |
| 8639 | TrackUserActivity(UINT uMsg) |
| 8640 | { |
| 8641 | if ((uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST) |
| 8642 | || (uMsg >= WM_KEYFIRST && uMsg <= WM_KEYLAST)) |
| 8643 | LastActivity = GetTickCount(); |
| 8644 | } |
| 8645 | |
| 8646 | void |
Bram Moolenaar | 68c2f63 | 2016-01-30 17:24:07 +0100 | [diff] [blame] | 8647 | gui_mch_destroy_beval_area(BalloonEval *beval) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8648 | { |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 8649 | #ifdef FEAT_VARTABS |
Bram Moolenaar | 6d9e71a | 2018-12-28 19:13:34 +0100 | [diff] [blame] | 8650 | vim_free(beval->vts); |
Bram Moolenaar | 04958cb | 2018-06-23 19:23:02 +0200 | [diff] [blame] | 8651 | #endif |
Bram Moolenaar | 6d9e71a | 2018-12-28 19:13:34 +0100 | [diff] [blame] | 8652 | vim_free(beval->tofree); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8653 | vim_free(beval); |
| 8654 | } |
Bram Moolenaar | c3719bd | 2017-11-18 22:13:31 +0100 | [diff] [blame] | 8655 | #endif /* FEAT_BEVAL_GUI */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8656 | |
| 8657 | #if defined(FEAT_NETBEANS_INTG) || defined(PROTO) |
| 8658 | /* |
| 8659 | * We have multiple signs to draw at the same location. Draw the |
| 8660 | * multi-sign indicator (down-arrow) instead. This is the Win32 version. |
| 8661 | */ |
| 8662 | void |
| 8663 | netbeans_draw_multisign_indicator(int row) |
| 8664 | { |
| 8665 | int i; |
| 8666 | int y; |
| 8667 | int x; |
| 8668 | |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 8669 | if (!netbeans_active()) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 8670 | return; |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 8671 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8672 | x = 0; |
| 8673 | y = TEXT_Y(row); |
| 8674 | |
Bram Moolenaar | d7ccc4d | 2017-11-26 14:29:32 +0100 | [diff] [blame] | 8675 | #if defined(FEAT_DIRECTX) |
| 8676 | if (IS_ENABLE_DIRECTX()) |
| 8677 | DWriteContext_Flush(s_dwc); |
| 8678 | #endif |
| 8679 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8680 | for (i = 0; i < gui.char_height - 3; i++) |
| 8681 | SetPixel(s_hdc, x+2, y++, gui.currFgColor); |
| 8682 | |
| 8683 | SetPixel(s_hdc, x+0, y, gui.currFgColor); |
| 8684 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 8685 | SetPixel(s_hdc, x+4, y++, gui.currFgColor); |
| 8686 | SetPixel(s_hdc, x+1, y, gui.currFgColor); |
| 8687 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 8688 | SetPixel(s_hdc, x+3, y++, gui.currFgColor); |
| 8689 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 8690 | } |
Bram Moolenaar | e0874f8 | 2016-01-24 20:36:41 +0100 | [diff] [blame] | 8691 | #endif |