Bram Moolenaar | 060f1f0 | 2007-05-10 20:17:29 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
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 | * |
| 13 | * GUI support for Microsoft Windows. Win32 initially; maybe Win16 later |
| 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 |
| 20 | * os_win32.c. (It can also be done from the terminal version). |
| 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 | |
| 32 | #if defined(FEAT_DIRECTX) || defined(PROTO) |
| 33 | static DWriteContext *s_dwc = NULL; |
| 34 | static int s_directx_enabled = 0; |
| 35 | static int s_directx_load_attempted = 0; |
| 36 | # define IS_ENABLE_DIRECTX() (s_directx_enabled && s_dwc != NULL) |
| 37 | |
| 38 | int |
| 39 | directx_enabled(void) |
| 40 | { |
| 41 | if (s_dwc != NULL) |
| 42 | return 1; |
| 43 | else if (s_directx_load_attempted) |
| 44 | return 0; |
| 45 | /* load DirectX */ |
| 46 | DWrite_Init(); |
| 47 | s_directx_load_attempted = 1; |
| 48 | s_dwc = DWriteContext_Open(); |
| 49 | return s_dwc != NULL ? 1 : 0; |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | #if defined(FEAT_RENDER_OPTIONS) || defined(PROTO) |
| 54 | int |
| 55 | gui_mch_set_rendering_options(char_u *s) |
| 56 | { |
| 57 | #ifdef FEAT_DIRECTX |
| 58 | int retval = FAIL; |
| 59 | char_u *p, *q; |
| 60 | |
| 61 | int dx_enable = 0; |
| 62 | int dx_flags = 0; |
| 63 | float dx_gamma = 0.0f; |
| 64 | float dx_contrast = 0.0f; |
| 65 | float dx_level = 0.0f; |
| 66 | int dx_geom = 0; |
| 67 | int dx_renmode = 0; |
| 68 | int dx_taamode = 0; |
| 69 | |
| 70 | /* parse string as rendering options. */ |
| 71 | for (p = s; p != NULL && *p != NUL; ) |
| 72 | { |
| 73 | char_u item[256]; |
| 74 | char_u name[128]; |
| 75 | char_u value[128]; |
| 76 | |
| 77 | copy_option_part(&p, item, sizeof(item), ","); |
| 78 | if (p == NULL) |
| 79 | break; |
| 80 | q = &item[0]; |
| 81 | copy_option_part(&q, name, sizeof(name), ":"); |
| 82 | if (q == NULL) |
| 83 | return FAIL; |
| 84 | copy_option_part(&q, value, sizeof(value), ":"); |
| 85 | |
| 86 | if (STRCMP(name, "type") == 0) |
| 87 | { |
| 88 | if (STRCMP(value, "directx") == 0) |
| 89 | dx_enable = 1; |
| 90 | else |
| 91 | return FAIL; |
| 92 | } |
| 93 | else if (STRCMP(name, "gamma") == 0) |
| 94 | { |
| 95 | dx_flags |= 1 << 0; |
| 96 | dx_gamma = (float)atof(value); |
| 97 | } |
| 98 | else if (STRCMP(name, "contrast") == 0) |
| 99 | { |
| 100 | dx_flags |= 1 << 1; |
| 101 | dx_contrast = (float)atof(value); |
| 102 | } |
| 103 | else if (STRCMP(name, "level") == 0) |
| 104 | { |
| 105 | dx_flags |= 1 << 2; |
| 106 | dx_level = (float)atof(value); |
| 107 | } |
| 108 | else if (STRCMP(name, "geom") == 0) |
| 109 | { |
| 110 | dx_flags |= 1 << 3; |
| 111 | dx_geom = atoi(value); |
| 112 | if (dx_geom < 0 || dx_geom > 2) |
| 113 | return FAIL; |
| 114 | } |
| 115 | else if (STRCMP(name, "renmode") == 0) |
| 116 | { |
| 117 | dx_flags |= 1 << 4; |
| 118 | dx_renmode = atoi(value); |
| 119 | if (dx_renmode < 0 || dx_renmode > 6) |
| 120 | return FAIL; |
| 121 | } |
| 122 | else if (STRCMP(name, "taamode") == 0) |
| 123 | { |
| 124 | dx_flags |= 1 << 5; |
| 125 | dx_taamode = atoi(value); |
| 126 | if (dx_taamode < 0 || dx_taamode > 3) |
| 127 | return FAIL; |
| 128 | } |
| 129 | else |
| 130 | return FAIL; |
| 131 | } |
| 132 | |
| 133 | /* Enable DirectX/DirectWrite */ |
| 134 | if (dx_enable) |
| 135 | { |
| 136 | if (!directx_enabled()) |
| 137 | return FAIL; |
| 138 | DWriteContext_SetRenderingParams(s_dwc, NULL); |
| 139 | if (dx_flags) |
| 140 | { |
| 141 | DWriteRenderingParams param; |
| 142 | DWriteContext_GetRenderingParams(s_dwc, ¶m); |
| 143 | if (dx_flags & (1 << 0)) |
| 144 | param.gamma = dx_gamma; |
| 145 | if (dx_flags & (1 << 1)) |
| 146 | param.enhancedContrast = dx_contrast; |
| 147 | if (dx_flags & (1 << 2)) |
| 148 | param.clearTypeLevel = dx_level; |
| 149 | if (dx_flags & (1 << 3)) |
| 150 | param.pixelGeometry = dx_geom; |
| 151 | if (dx_flags & (1 << 4)) |
| 152 | param.renderingMode = dx_renmode; |
| 153 | if (dx_flags & (1 << 5)) |
| 154 | param.textAntialiasMode = dx_taamode; |
| 155 | DWriteContext_SetRenderingParams(s_dwc, ¶m); |
| 156 | } |
| 157 | } |
| 158 | s_directx_enabled = dx_enable; |
| 159 | |
| 160 | return OK; |
| 161 | #else |
| 162 | return FAIL; |
| 163 | #endif |
| 164 | } |
| 165 | #endif |
| 166 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 167 | /* |
| 168 | * These are new in Windows ME/XP, only defined in recent compilers. |
| 169 | */ |
| 170 | #ifndef HANDLE_WM_XBUTTONUP |
| 171 | # define HANDLE_WM_XBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 172 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 173 | #endif |
| 174 | #ifndef HANDLE_WM_XBUTTONDOWN |
| 175 | # define HANDLE_WM_XBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 176 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 177 | #endif |
| 178 | #ifndef HANDLE_WM_XBUTTONDBLCLK |
| 179 | # define HANDLE_WM_XBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 180 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 181 | #endif |
| 182 | |
| 183 | /* |
| 184 | * Include the common stuff for MS-Windows GUI. |
| 185 | */ |
| 186 | #include "gui_w48.c" |
| 187 | |
| 188 | #ifdef FEAT_XPM_W32 |
| 189 | # include "xpm_w32.h" |
| 190 | #endif |
| 191 | |
| 192 | #ifdef PROTO |
| 193 | # define WINAPI |
| 194 | #endif |
| 195 | |
| 196 | #ifdef __MINGW32__ |
| 197 | /* |
| 198 | * Add a lot of missing defines. |
| 199 | * They are not always missing, we need the #ifndef's. |
| 200 | */ |
| 201 | # ifndef _cdecl |
| 202 | # define _cdecl |
| 203 | # endif |
| 204 | # ifndef IsMinimized |
| 205 | # define IsMinimized(hwnd) IsIconic(hwnd) |
| 206 | # endif |
| 207 | # ifndef IsMaximized |
| 208 | # define IsMaximized(hwnd) IsZoomed(hwnd) |
| 209 | # endif |
| 210 | # ifndef SelectFont |
| 211 | # define SelectFont(hdc, hfont) ((HFONT)SelectObject((hdc), (HGDIOBJ)(HFONT)(hfont))) |
| 212 | # endif |
| 213 | # ifndef GetStockBrush |
| 214 | # define GetStockBrush(i) ((HBRUSH)GetStockObject(i)) |
| 215 | # endif |
| 216 | # ifndef DeleteBrush |
| 217 | # define DeleteBrush(hbr) DeleteObject((HGDIOBJ)(HBRUSH)(hbr)) |
| 218 | # endif |
| 219 | |
| 220 | # ifndef HANDLE_WM_RBUTTONDBLCLK |
| 221 | # define HANDLE_WM_RBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 222 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 223 | # endif |
| 224 | # ifndef HANDLE_WM_MBUTTONUP |
| 225 | # define HANDLE_WM_MBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 226 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 227 | # endif |
| 228 | # ifndef HANDLE_WM_MBUTTONDBLCLK |
| 229 | # define HANDLE_WM_MBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 230 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 231 | # endif |
| 232 | # ifndef HANDLE_WM_LBUTTONDBLCLK |
| 233 | # define HANDLE_WM_LBUTTONDBLCLK(hwnd, wParam, lParam, fn) \ |
| 234 | ((fn)((hwnd), TRUE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 235 | # endif |
| 236 | # ifndef HANDLE_WM_RBUTTONDOWN |
| 237 | # define HANDLE_WM_RBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 238 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 239 | # endif |
| 240 | # ifndef HANDLE_WM_MOUSEMOVE |
| 241 | # define HANDLE_WM_MOUSEMOVE(hwnd, wParam, lParam, fn) \ |
| 242 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 243 | # endif |
| 244 | # ifndef HANDLE_WM_RBUTTONUP |
| 245 | # define HANDLE_WM_RBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 246 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 247 | # endif |
| 248 | # ifndef HANDLE_WM_MBUTTONDOWN |
| 249 | # define HANDLE_WM_MBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 250 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 251 | # endif |
| 252 | # ifndef HANDLE_WM_LBUTTONUP |
| 253 | # define HANDLE_WM_LBUTTONUP(hwnd, wParam, lParam, fn) \ |
| 254 | ((fn)((hwnd), (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 255 | # endif |
| 256 | # ifndef HANDLE_WM_LBUTTONDOWN |
| 257 | # define HANDLE_WM_LBUTTONDOWN(hwnd, wParam, lParam, fn) \ |
| 258 | ((fn)((hwnd), FALSE, (int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam), (UINT)(wParam)), 0L) |
| 259 | # endif |
| 260 | # ifndef HANDLE_WM_SYSCHAR |
| 261 | # define HANDLE_WM_SYSCHAR(hwnd, wParam, lParam, fn) \ |
| 262 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 263 | # endif |
| 264 | # ifndef HANDLE_WM_ACTIVATEAPP |
| 265 | # define HANDLE_WM_ACTIVATEAPP(hwnd, wParam, lParam, fn) \ |
| 266 | ((fn)((hwnd), (BOOL)(wParam), (DWORD)(lParam)), 0L) |
| 267 | # endif |
| 268 | # ifndef HANDLE_WM_WINDOWPOSCHANGING |
| 269 | # define HANDLE_WM_WINDOWPOSCHANGING(hwnd, wParam, lParam, fn) \ |
| 270 | (LRESULT)(DWORD)(BOOL)(fn)((hwnd), (LPWINDOWPOS)(lParam)) |
| 271 | # endif |
| 272 | # ifndef HANDLE_WM_VSCROLL |
| 273 | # define HANDLE_WM_VSCROLL(hwnd, wParam, lParam, fn) \ |
| 274 | ((fn)((hwnd), (HWND)(lParam), (UINT)(LOWORD(wParam)), (int)(short)HIWORD(wParam)), 0L) |
| 275 | # endif |
| 276 | # ifndef HANDLE_WM_SETFOCUS |
| 277 | # define HANDLE_WM_SETFOCUS(hwnd, wParam, lParam, fn) \ |
| 278 | ((fn)((hwnd), (HWND)(wParam)), 0L) |
| 279 | # endif |
| 280 | # ifndef HANDLE_WM_KILLFOCUS |
| 281 | # define HANDLE_WM_KILLFOCUS(hwnd, wParam, lParam, fn) \ |
| 282 | ((fn)((hwnd), (HWND)(wParam)), 0L) |
| 283 | # endif |
| 284 | # ifndef HANDLE_WM_HSCROLL |
| 285 | # define HANDLE_WM_HSCROLL(hwnd, wParam, lParam, fn) \ |
| 286 | ((fn)((hwnd), (HWND)(lParam), (UINT)(LOWORD(wParam)), (int)(short)HIWORD(wParam)), 0L) |
| 287 | # endif |
| 288 | # ifndef HANDLE_WM_DROPFILES |
| 289 | # define HANDLE_WM_DROPFILES(hwnd, wParam, lParam, fn) \ |
| 290 | ((fn)((hwnd), (HDROP)(wParam)), 0L) |
| 291 | # endif |
| 292 | # ifndef HANDLE_WM_CHAR |
| 293 | # define HANDLE_WM_CHAR(hwnd, wParam, lParam, fn) \ |
| 294 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 295 | # endif |
| 296 | # ifndef HANDLE_WM_SYSDEADCHAR |
| 297 | # define HANDLE_WM_SYSDEADCHAR(hwnd, wParam, lParam, fn) \ |
| 298 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 299 | # endif |
| 300 | # ifndef HANDLE_WM_DEADCHAR |
| 301 | # define HANDLE_WM_DEADCHAR(hwnd, wParam, lParam, fn) \ |
| 302 | ((fn)((hwnd), (TCHAR)(wParam), (int)(short)LOWORD(lParam)), 0L) |
| 303 | # endif |
| 304 | #endif /* __MINGW32__ */ |
| 305 | |
| 306 | |
| 307 | /* Some parameters for tearoff menus. All in pixels. */ |
| 308 | #define TEAROFF_PADDING_X 2 |
| 309 | #define TEAROFF_BUTTON_PAD_X 8 |
| 310 | #define TEAROFF_MIN_WIDTH 200 |
| 311 | #define TEAROFF_SUBMENU_LABEL ">>" |
| 312 | #define TEAROFF_COLUMN_PADDING 3 // # spaces to pad column with. |
| 313 | |
| 314 | |
| 315 | /* For the Intellimouse: */ |
| 316 | #ifndef WM_MOUSEWHEEL |
| 317 | #define WM_MOUSEWHEEL 0x20a |
| 318 | #endif |
| 319 | |
| 320 | |
| 321 | #ifdef FEAT_BEVAL |
| 322 | # define ID_BEVAL_TOOLTIP 200 |
| 323 | # define BEVAL_TEXT_LEN MAXPATHL |
| 324 | |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 325 | #if (defined(_MSC_VER) && _MSC_VER < 1300) || !defined(MAXULONG_PTR) |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 326 | /* Work around old versions of basetsd.h which wrongly declares |
| 327 | * UINT_PTR as unsigned long. */ |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 328 | # undef UINT_PTR |
Bram Moolenaar | 8424a62 | 2006-04-19 21:23:36 +0000 | [diff] [blame] | 329 | # define UINT_PTR UINT |
| 330 | #endif |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 331 | |
| 332 | static void make_tooltip __ARGS((BalloonEval *beval, char *text, POINT pt)); |
| 333 | static void delete_tooltip __ARGS((BalloonEval *beval)); |
| 334 | static VOID CALLBACK BevalTimerProc __ARGS((HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)); |
| 335 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 336 | static BalloonEval *cur_beval = NULL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 337 | static UINT_PTR BevalTimerId = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 338 | static DWORD LastActivity = 0; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 339 | |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 340 | |
| 341 | /* cproto fails on missing include files */ |
| 342 | #ifndef PROTO |
| 343 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 344 | /* |
| 345 | * excerpts from headers since this may not be presented |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 346 | * in the extremely old compilers |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 347 | */ |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 348 | # include <pshpack1.h> |
| 349 | |
| 350 | #endif |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 351 | |
| 352 | typedef struct _DllVersionInfo |
| 353 | { |
| 354 | DWORD cbSize; |
| 355 | DWORD dwMajorVersion; |
| 356 | DWORD dwMinorVersion; |
| 357 | DWORD dwBuildNumber; |
| 358 | DWORD dwPlatformID; |
| 359 | } DLLVERSIONINFO; |
| 360 | |
Bram Moolenaar | 8288149 | 2012-11-20 16:53:39 +0100 | [diff] [blame] | 361 | #ifndef PROTO |
| 362 | # include <poppack.h> |
| 363 | #endif |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 364 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 365 | typedef struct tagTOOLINFOA_NEW |
| 366 | { |
| 367 | UINT cbSize; |
| 368 | UINT uFlags; |
| 369 | HWND hwnd; |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 370 | UINT_PTR uId; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 371 | RECT rect; |
| 372 | HINSTANCE hinst; |
| 373 | LPSTR lpszText; |
| 374 | LPARAM lParam; |
| 375 | } TOOLINFO_NEW; |
| 376 | |
| 377 | typedef struct tagNMTTDISPINFO_NEW |
| 378 | { |
| 379 | NMHDR hdr; |
Bram Moolenaar | 281daf6 | 2009-12-24 15:11:40 +0000 | [diff] [blame] | 380 | LPSTR lpszText; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 381 | char szText[80]; |
| 382 | HINSTANCE hinst; |
| 383 | UINT uFlags; |
| 384 | LPARAM lParam; |
| 385 | } NMTTDISPINFO_NEW; |
| 386 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 387 | typedef HRESULT (WINAPI* DLLGETVERSIONPROC)(DLLVERSIONINFO *); |
| 388 | #ifndef TTM_SETMAXTIPWIDTH |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 389 | # define TTM_SETMAXTIPWIDTH (WM_USER+24) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 390 | #endif |
| 391 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 392 | #ifndef TTF_DI_SETITEM |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 393 | # define TTF_DI_SETITEM 0x8000 |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 394 | #endif |
| 395 | |
| 396 | #ifndef TTN_GETDISPINFO |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 397 | # define TTN_GETDISPINFO (TTN_FIRST - 0) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 398 | #endif |
| 399 | |
| 400 | #endif /* defined(FEAT_BEVAL) */ |
| 401 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 402 | #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
| 403 | /* Older MSVC compilers don't have LPNMTTDISPINFO[AW] thus we need to define |
| 404 | * it here if LPNMTTDISPINFO isn't defined. |
| 405 | * MingW doesn't define LPNMTTDISPINFO but typedefs it. Thus we need to check |
| 406 | * _MSC_VER. */ |
| 407 | # if !defined(LPNMTTDISPINFO) && defined(_MSC_VER) |
| 408 | typedef struct tagNMTTDISPINFOA { |
| 409 | NMHDR hdr; |
| 410 | LPSTR lpszText; |
| 411 | char szText[80]; |
| 412 | HINSTANCE hinst; |
| 413 | UINT uFlags; |
| 414 | LPARAM lParam; |
| 415 | } NMTTDISPINFOA, *LPNMTTDISPINFOA; |
| 416 | # define LPNMTTDISPINFO LPNMTTDISPINFOA |
| 417 | |
| 418 | # ifdef FEAT_MBYTE |
| 419 | typedef struct tagNMTTDISPINFOW { |
| 420 | NMHDR hdr; |
| 421 | LPWSTR lpszText; |
| 422 | WCHAR szText[80]; |
| 423 | HINSTANCE hinst; |
| 424 | UINT uFlags; |
| 425 | LPARAM lParam; |
| 426 | } NMTTDISPINFOW, *LPNMTTDISPINFOW; |
| 427 | # endif |
| 428 | # endif |
| 429 | #endif |
| 430 | |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 431 | #ifndef TTN_GETDISPINFOW |
| 432 | # define TTN_GETDISPINFOW (TTN_FIRST - 10) |
| 433 | #endif |
| 434 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 435 | /* Local variables: */ |
| 436 | |
| 437 | #ifdef FEAT_MENU |
| 438 | static UINT s_menu_id = 100; |
Bram Moolenaar | 786989b | 2010-10-27 12:15:33 +0200 | [diff] [blame] | 439 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 440 | |
| 441 | /* |
| 442 | * Use the system font for dialogs and tear-off menus. Remove this line to |
| 443 | * use DLG_FONT_NAME. |
| 444 | */ |
Bram Moolenaar | 786989b | 2010-10-27 12:15:33 +0200 | [diff] [blame] | 445 | #define USE_SYSMENU_FONT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 446 | |
| 447 | #define VIM_NAME "vim" |
| 448 | #define VIM_CLASS "Vim" |
| 449 | #define VIM_CLASSW L"Vim" |
| 450 | |
| 451 | /* Initial size for the dialog template. For gui_mch_dialog() it's fixed, |
| 452 | * thus there should be room for every dialog. For tearoffs it's made bigger |
| 453 | * when needed. */ |
| 454 | #define DLG_ALLOC_SIZE 16 * 1024 |
| 455 | |
| 456 | /* |
| 457 | * stuff for dialogs, menus, tearoffs etc. |
| 458 | */ |
| 459 | static LRESULT APIENTRY dialog_callback(HWND, UINT, WPARAM, LPARAM); |
| 460 | static LRESULT APIENTRY tearoff_callback(HWND, UINT, WPARAM, LPARAM); |
| 461 | static PWORD |
| 462 | add_dialog_element( |
| 463 | PWORD p, |
| 464 | DWORD lStyle, |
| 465 | WORD x, |
| 466 | WORD y, |
| 467 | WORD w, |
| 468 | WORD h, |
| 469 | WORD Id, |
| 470 | WORD clss, |
| 471 | const char *caption); |
| 472 | static LPWORD lpwAlign(LPWORD); |
| 473 | static int nCopyAnsiToWideChar(LPWORD, LPSTR); |
| 474 | static void gui_mch_tearoff(char_u *title, vimmenu_T *menu, int initX, int initY); |
| 475 | static void get_dialog_font_metrics(void); |
| 476 | |
| 477 | static int dialog_default_button = -1; |
| 478 | |
| 479 | /* Intellimouse support */ |
| 480 | static int mouse_scroll_lines = 0; |
| 481 | static UINT msh_msgmousewheel = 0; |
| 482 | |
| 483 | static int s_usenewlook; /* emulate W95/NT4 non-bold dialogs */ |
| 484 | #ifdef FEAT_TOOLBAR |
| 485 | static void initialise_toolbar(void); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 486 | 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] | 487 | static int get_toolbar_bitmap(vimmenu_T *menu); |
| 488 | #endif |
| 489 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 490 | #ifdef FEAT_GUI_TABLINE |
| 491 | static void initialise_tabline(void); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 492 | 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] | 493 | #endif |
| 494 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 495 | #ifdef FEAT_MBYTE_IME |
| 496 | static LRESULT _OnImeComposition(HWND hwnd, WPARAM dbcs, LPARAM param); |
| 497 | static char_u *GetResultStr(HWND hwnd, int GCS, int *lenp); |
| 498 | #endif |
| 499 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 500 | # ifdef NOIME |
| 501 | typedef struct tagCOMPOSITIONFORM { |
| 502 | DWORD dwStyle; |
| 503 | POINT ptCurrentPos; |
| 504 | RECT rcArea; |
| 505 | } COMPOSITIONFORM, *PCOMPOSITIONFORM, NEAR *NPCOMPOSITIONFORM, FAR *LPCOMPOSITIONFORM; |
| 506 | typedef HANDLE HIMC; |
| 507 | # endif |
| 508 | |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 509 | static HINSTANCE hLibImm = NULL; |
| 510 | static LONG (WINAPI *pImmGetCompositionStringA)(HIMC, DWORD, LPVOID, DWORD); |
| 511 | static LONG (WINAPI *pImmGetCompositionStringW)(HIMC, DWORD, LPVOID, DWORD); |
| 512 | static HIMC (WINAPI *pImmGetContext)(HWND); |
| 513 | static HIMC (WINAPI *pImmAssociateContext)(HWND, HIMC); |
| 514 | static BOOL (WINAPI *pImmReleaseContext)(HWND, HIMC); |
| 515 | static BOOL (WINAPI *pImmGetOpenStatus)(HIMC); |
| 516 | static BOOL (WINAPI *pImmSetOpenStatus)(HIMC, BOOL); |
| 517 | static BOOL (WINAPI *pImmGetCompositionFont)(HIMC, LPLOGFONTA); |
| 518 | static BOOL (WINAPI *pImmSetCompositionFont)(HIMC, LPLOGFONTA); |
| 519 | static BOOL (WINAPI *pImmSetCompositionWindow)(HIMC, LPCOMPOSITIONFORM); |
| 520 | static BOOL (WINAPI *pImmGetConversionStatus)(HIMC, LPDWORD, LPDWORD); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 521 | static BOOL (WINAPI *pImmSetConversionStatus)(HIMC, DWORD, DWORD); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 522 | static void dyn_imm_load(void); |
| 523 | #else |
| 524 | # define pImmGetCompositionStringA ImmGetCompositionStringA |
| 525 | # define pImmGetCompositionStringW ImmGetCompositionStringW |
| 526 | # define pImmGetContext ImmGetContext |
| 527 | # define pImmAssociateContext ImmAssociateContext |
| 528 | # define pImmReleaseContext ImmReleaseContext |
| 529 | # define pImmGetOpenStatus ImmGetOpenStatus |
| 530 | # define pImmSetOpenStatus ImmSetOpenStatus |
| 531 | # define pImmGetCompositionFont ImmGetCompositionFontA |
| 532 | # define pImmSetCompositionFont ImmSetCompositionFontA |
| 533 | # define pImmSetCompositionWindow ImmSetCompositionWindow |
| 534 | # define pImmGetConversionStatus ImmGetConversionStatus |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 535 | # define pImmSetConversionStatus ImmSetConversionStatus |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 536 | #endif |
| 537 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 538 | /* multi monitor support */ |
| 539 | typedef struct _MONITORINFOstruct |
| 540 | { |
| 541 | DWORD cbSize; |
| 542 | RECT rcMonitor; |
| 543 | RECT rcWork; |
| 544 | DWORD dwFlags; |
| 545 | } _MONITORINFO; |
| 546 | |
| 547 | typedef HANDLE _HMONITOR; |
| 548 | typedef _HMONITOR (WINAPI *TMonitorFromWindow)(HWND, DWORD); |
| 549 | typedef BOOL (WINAPI *TGetMonitorInfo)(_HMONITOR, _MONITORINFO *); |
| 550 | |
| 551 | static TMonitorFromWindow pMonitorFromWindow = NULL; |
| 552 | static TGetMonitorInfo pGetMonitorInfo = NULL; |
| 553 | static HANDLE user32_lib = NULL; |
| 554 | #ifdef FEAT_NETBEANS_INTG |
| 555 | int WSInitialized = FALSE; /* WinSock is initialized */ |
| 556 | #endif |
| 557 | /* |
| 558 | * Return TRUE when running under Windows NT 3.x or Win32s, both of which have |
| 559 | * less fancy GUI APIs. |
| 560 | */ |
| 561 | static int |
| 562 | is_winnt_3(void) |
| 563 | { |
| 564 | return ((os_version.dwPlatformId == VER_PLATFORM_WIN32_NT |
| 565 | && os_version.dwMajorVersion == 3) |
| 566 | || (os_version.dwPlatformId == VER_PLATFORM_WIN32s)); |
| 567 | } |
| 568 | |
| 569 | /* |
| 570 | * Return TRUE when running under Win32s. |
| 571 | */ |
| 572 | int |
| 573 | gui_is_win32s(void) |
| 574 | { |
| 575 | return (os_version.dwPlatformId == VER_PLATFORM_WIN32s); |
| 576 | } |
| 577 | |
| 578 | #ifdef FEAT_MENU |
| 579 | /* |
| 580 | * Figure out how high the menu bar is at the moment. |
| 581 | */ |
| 582 | static int |
| 583 | gui_mswin_get_menu_height( |
| 584 | int fix_window) /* If TRUE, resize window if menu height changed */ |
| 585 | { |
| 586 | static int old_menu_height = -1; |
| 587 | |
| 588 | RECT rc1, rc2; |
| 589 | int num; |
| 590 | int menu_height; |
| 591 | |
| 592 | if (gui.menu_is_active) |
| 593 | num = GetMenuItemCount(s_menuBar); |
| 594 | else |
| 595 | num = 0; |
| 596 | |
| 597 | if (num == 0) |
| 598 | menu_height = 0; |
| 599 | else |
| 600 | { |
| 601 | if (is_winnt_3()) /* for NT 3.xx */ |
| 602 | { |
| 603 | if (gui.starting) |
| 604 | menu_height = GetSystemMetrics(SM_CYMENU); |
| 605 | else |
| 606 | { |
| 607 | RECT r1, r2; |
| 608 | int frameht = GetSystemMetrics(SM_CYFRAME); |
| 609 | int capht = GetSystemMetrics(SM_CYCAPTION); |
| 610 | |
| 611 | /* get window rect of s_hwnd |
| 612 | * get client rect of s_hwnd |
| 613 | * get cap height |
| 614 | * subtract from window rect, the sum of client height, |
| 615 | * (if not maximized)frame thickness, and caption height. |
| 616 | */ |
| 617 | GetWindowRect(s_hwnd, &r1); |
| 618 | GetClientRect(s_hwnd, &r2); |
| 619 | menu_height = r1.bottom - r1.top - (r2.bottom - r2.top |
| 620 | + 2 * frameht * (!IsZoomed(s_hwnd)) + capht); |
| 621 | } |
| 622 | } |
| 623 | else /* win95 and variants (NT 4.0, I guess) */ |
| 624 | { |
| 625 | /* |
| 626 | * In case 'lines' is set in _vimrc/_gvimrc window width doesn't |
| 627 | * seem to have been set yet, so menu wraps in default window |
| 628 | * width which is very narrow. Instead just return height of a |
| 629 | * single menu item. Will still be wrong when the menu really |
| 630 | * should wrap over more than one line. |
| 631 | */ |
| 632 | GetMenuItemRect(s_hwnd, s_menuBar, 0, &rc1); |
| 633 | if (gui.starting) |
| 634 | menu_height = rc1.bottom - rc1.top + 1; |
| 635 | else |
| 636 | { |
| 637 | GetMenuItemRect(s_hwnd, s_menuBar, num - 1, &rc2); |
| 638 | menu_height = rc2.bottom - rc1.top + 1; |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | if (fix_window && menu_height != old_menu_height) |
| 644 | { |
| 645 | old_menu_height = menu_height; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 646 | gui_set_shellsize(FALSE, FALSE, RESIZE_VERT); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | return menu_height; |
| 650 | } |
| 651 | #endif /*FEAT_MENU*/ |
| 652 | |
| 653 | |
| 654 | /* |
| 655 | * Setup for the Intellimouse |
| 656 | */ |
| 657 | static void |
| 658 | init_mouse_wheel(void) |
| 659 | { |
| 660 | |
| 661 | #ifndef SPI_GETWHEELSCROLLLINES |
| 662 | # define SPI_GETWHEELSCROLLLINES 104 |
| 663 | #endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 664 | #ifndef SPI_SETWHEELSCROLLLINES |
| 665 | # define SPI_SETWHEELSCROLLLINES 105 |
| 666 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 667 | |
| 668 | #define VMOUSEZ_CLASSNAME "MouseZ" /* hidden wheel window class */ |
| 669 | #define VMOUSEZ_TITLE "Magellan MSWHEEL" /* hidden wheel window title */ |
| 670 | #define VMSH_MOUSEWHEEL "MSWHEEL_ROLLMSG" |
| 671 | #define VMSH_SCROLL_LINES "MSH_SCROLL_LINES_MSG" |
| 672 | |
| 673 | HWND hdl_mswheel; |
| 674 | UINT msh_msgscrolllines; |
| 675 | |
| 676 | msh_msgmousewheel = 0; |
| 677 | mouse_scroll_lines = 3; /* reasonable default */ |
| 678 | |
| 679 | if ((os_version.dwPlatformId == VER_PLATFORM_WIN32_NT |
| 680 | && os_version.dwMajorVersion >= 4) |
| 681 | || (os_version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS |
| 682 | && ((os_version.dwMajorVersion == 4 |
| 683 | && os_version.dwMinorVersion >= 10) |
| 684 | || os_version.dwMajorVersion >= 5))) |
| 685 | { |
| 686 | /* if NT 4.0+ (or Win98) get scroll lines directly from system */ |
| 687 | SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, |
| 688 | &mouse_scroll_lines, 0); |
| 689 | } |
| 690 | else if (os_version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS |
| 691 | || (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT |
| 692 | && os_version.dwMajorVersion < 4)) |
| 693 | { /* |
| 694 | * If Win95 or NT 3.51, |
| 695 | * try to find the hidden point32 window. |
| 696 | */ |
| 697 | hdl_mswheel = FindWindow(VMOUSEZ_CLASSNAME, VMOUSEZ_TITLE); |
| 698 | if (hdl_mswheel) |
| 699 | { |
| 700 | msh_msgscrolllines = RegisterWindowMessage(VMSH_SCROLL_LINES); |
| 701 | if (msh_msgscrolllines) |
| 702 | { |
| 703 | mouse_scroll_lines = (int)SendMessage(hdl_mswheel, |
| 704 | msh_msgscrolllines, 0, 0); |
| 705 | msh_msgmousewheel = RegisterWindowMessage(VMSH_MOUSEWHEEL); |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /* Intellimouse wheel handler */ |
| 713 | static void |
| 714 | _OnMouseWheel( |
| 715 | HWND hwnd, |
| 716 | short zDelta) |
| 717 | { |
| 718 | /* Treat a mouse wheel event as if it were a scroll request */ |
| 719 | int i; |
| 720 | int size; |
| 721 | HWND hwndCtl; |
| 722 | |
| 723 | if (curwin->w_scrollbars[SBAR_RIGHT].id != 0) |
| 724 | { |
| 725 | hwndCtl = curwin->w_scrollbars[SBAR_RIGHT].id; |
| 726 | size = curwin->w_scrollbars[SBAR_RIGHT].size; |
| 727 | } |
| 728 | else if (curwin->w_scrollbars[SBAR_LEFT].id != 0) |
| 729 | { |
| 730 | hwndCtl = curwin->w_scrollbars[SBAR_LEFT].id; |
| 731 | size = curwin->w_scrollbars[SBAR_LEFT].size; |
| 732 | } |
| 733 | else |
| 734 | return; |
| 735 | |
| 736 | size = curwin->w_height; |
| 737 | if (mouse_scroll_lines == 0) |
| 738 | init_mouse_wheel(); |
| 739 | |
| 740 | if (mouse_scroll_lines > 0 |
| 741 | && mouse_scroll_lines < (size > 2 ? size - 2 : 1)) |
| 742 | { |
| 743 | for (i = mouse_scroll_lines; i > 0; --i) |
| 744 | _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_LINEUP : SB_LINEDOWN, 0); |
| 745 | } |
| 746 | else |
| 747 | _OnScroll(hwnd, hwndCtl, zDelta >= 0 ? SB_PAGEUP : SB_PAGEDOWN, 0); |
| 748 | } |
| 749 | |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 750 | #ifdef USE_SYSMENU_FONT |
| 751 | /* |
| 752 | * Get Menu Font. |
| 753 | * Return OK or FAIL. |
| 754 | */ |
| 755 | static int |
| 756 | gui_w32_get_menu_font(LOGFONT *lf) |
| 757 | { |
| 758 | NONCLIENTMETRICS nm; |
| 759 | |
| 760 | nm.cbSize = sizeof(NONCLIENTMETRICS); |
| 761 | if (!SystemParametersInfo( |
| 762 | SPI_GETNONCLIENTMETRICS, |
| 763 | sizeof(NONCLIENTMETRICS), |
| 764 | &nm, |
| 765 | 0)) |
| 766 | return FAIL; |
| 767 | *lf = nm.lfMenuFont; |
| 768 | return OK; |
| 769 | } |
| 770 | #endif |
| 771 | |
| 772 | |
| 773 | #if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT) |
| 774 | /* |
| 775 | * Set the GUI tabline font to the system menu font |
| 776 | */ |
| 777 | static void |
| 778 | set_tabline_font(void) |
| 779 | { |
| 780 | LOGFONT lfSysmenu; |
| 781 | HFONT font; |
| 782 | HWND hwnd; |
| 783 | HDC hdc; |
| 784 | HFONT hfntOld; |
| 785 | TEXTMETRIC tm; |
| 786 | |
| 787 | if (gui_w32_get_menu_font(&lfSysmenu) != OK) |
| 788 | return; |
| 789 | |
| 790 | font = CreateFontIndirect(&lfSysmenu); |
| 791 | |
| 792 | SendMessage(s_tabhwnd, WM_SETFONT, (WPARAM)font, TRUE); |
| 793 | |
| 794 | /* |
| 795 | * Compute the height of the font used for the tab text |
| 796 | */ |
| 797 | hwnd = GetDesktopWindow(); |
| 798 | hdc = GetWindowDC(hwnd); |
| 799 | hfntOld = SelectFont(hdc, font); |
| 800 | |
| 801 | GetTextMetrics(hdc, &tm); |
| 802 | |
| 803 | SelectFont(hdc, hfntOld); |
| 804 | ReleaseDC(hwnd, hdc); |
| 805 | |
| 806 | /* |
| 807 | * The space used by the tab border and the space between the tab label |
| 808 | * and the tab border is included as 7. |
| 809 | */ |
| 810 | gui.tabline_height = tm.tmHeight + tm.tmInternalLeading + 7; |
| 811 | } |
| 812 | #endif |
| 813 | |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 814 | /* |
| 815 | * Invoked when a setting was changed. |
| 816 | */ |
| 817 | static LRESULT CALLBACK |
| 818 | _OnSettingChange(UINT n) |
| 819 | { |
| 820 | if (n == SPI_SETWHEELSCROLLLINES) |
| 821 | SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, |
| 822 | &mouse_scroll_lines, 0); |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 823 | #if defined(FEAT_GUI_TABLINE) && defined(USE_SYSMENU_FONT) |
| 824 | if (n == SPI_SETNONCLIENTMETRICS) |
| 825 | set_tabline_font(); |
| 826 | #endif |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 830 | #ifdef FEAT_NETBEANS_INTG |
| 831 | static void |
| 832 | _OnWindowPosChanged( |
| 833 | HWND hwnd, |
| 834 | const LPWINDOWPOS lpwpos) |
| 835 | { |
| 836 | static int x = 0, y = 0, cx = 0, cy = 0; |
| 837 | |
| 838 | if (WSInitialized && (lpwpos->x != x || lpwpos->y != y |
| 839 | || lpwpos->cx != cx || lpwpos->cy != cy)) |
| 840 | { |
| 841 | x = lpwpos->x; |
| 842 | y = lpwpos->y; |
| 843 | cx = lpwpos->cx; |
| 844 | cy = lpwpos->cy; |
| 845 | netbeans_frame_moved(x, y); |
| 846 | } |
| 847 | /* Allow to send WM_SIZE and WM_MOVE */ |
| 848 | FORWARD_WM_WINDOWPOSCHANGED(hwnd, lpwpos, MyWindowProc); |
| 849 | } |
| 850 | #endif |
| 851 | |
| 852 | static int |
| 853 | _DuringSizing( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 854 | UINT fwSide, |
| 855 | LPRECT lprc) |
| 856 | { |
| 857 | int w, h; |
| 858 | int valid_w, valid_h; |
| 859 | int w_offset, h_offset; |
| 860 | |
| 861 | w = lprc->right - lprc->left; |
| 862 | h = lprc->bottom - lprc->top; |
| 863 | gui_mswin_get_valid_dimensions(w, h, &valid_w, &valid_h); |
| 864 | w_offset = w - valid_w; |
| 865 | h_offset = h - valid_h; |
| 866 | |
| 867 | if (fwSide == WMSZ_LEFT || fwSide == WMSZ_TOPLEFT |
| 868 | || fwSide == WMSZ_BOTTOMLEFT) |
| 869 | lprc->left += w_offset; |
| 870 | else if (fwSide == WMSZ_RIGHT || fwSide == WMSZ_TOPRIGHT |
| 871 | || fwSide == WMSZ_BOTTOMRIGHT) |
| 872 | lprc->right -= w_offset; |
| 873 | |
| 874 | if (fwSide == WMSZ_TOP || fwSide == WMSZ_TOPLEFT |
| 875 | || fwSide == WMSZ_TOPRIGHT) |
| 876 | lprc->top += h_offset; |
| 877 | else if (fwSide == WMSZ_BOTTOM || fwSide == WMSZ_BOTTOMLEFT |
| 878 | || fwSide == WMSZ_BOTTOMRIGHT) |
| 879 | lprc->bottom -= h_offset; |
| 880 | return TRUE; |
| 881 | } |
| 882 | |
| 883 | |
| 884 | |
| 885 | static LRESULT CALLBACK |
| 886 | _WndProc( |
| 887 | HWND hwnd, |
| 888 | UINT uMsg, |
| 889 | WPARAM wParam, |
| 890 | LPARAM lParam) |
| 891 | { |
| 892 | /* |
| 893 | TRACE("WndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n", |
| 894 | hwnd, uMsg, wParam, lParam); |
| 895 | */ |
| 896 | |
| 897 | HandleMouseHide(uMsg, lParam); |
| 898 | |
| 899 | s_uMsg = uMsg; |
| 900 | s_wParam = wParam; |
| 901 | s_lParam = lParam; |
| 902 | |
| 903 | switch (uMsg) |
| 904 | { |
| 905 | HANDLE_MSG(hwnd, WM_DEADCHAR, _OnDeadChar); |
| 906 | HANDLE_MSG(hwnd, WM_SYSDEADCHAR, _OnDeadChar); |
| 907 | /* HANDLE_MSG(hwnd, WM_ACTIVATE, _OnActivate); */ |
| 908 | HANDLE_MSG(hwnd, WM_CLOSE, _OnClose); |
| 909 | /* HANDLE_MSG(hwnd, WM_COMMAND, _OnCommand); */ |
| 910 | HANDLE_MSG(hwnd, WM_DESTROY, _OnDestroy); |
| 911 | HANDLE_MSG(hwnd, WM_DROPFILES, _OnDropFiles); |
| 912 | HANDLE_MSG(hwnd, WM_HSCROLL, _OnScroll); |
| 913 | HANDLE_MSG(hwnd, WM_KILLFOCUS, _OnKillFocus); |
| 914 | #ifdef FEAT_MENU |
| 915 | HANDLE_MSG(hwnd, WM_COMMAND, _OnMenu); |
| 916 | #endif |
| 917 | /* HANDLE_MSG(hwnd, WM_MOVE, _OnMove); */ |
| 918 | /* HANDLE_MSG(hwnd, WM_NCACTIVATE, _OnNCActivate); */ |
| 919 | HANDLE_MSG(hwnd, WM_SETFOCUS, _OnSetFocus); |
| 920 | HANDLE_MSG(hwnd, WM_SIZE, _OnSize); |
| 921 | /* HANDLE_MSG(hwnd, WM_SYSCOMMAND, _OnSysCommand); */ |
| 922 | /* HANDLE_MSG(hwnd, WM_SYSKEYDOWN, _OnAltKey); */ |
| 923 | HANDLE_MSG(hwnd, WM_VSCROLL, _OnScroll); |
| 924 | // HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, _OnWindowPosChanging); |
| 925 | HANDLE_MSG(hwnd, WM_ACTIVATEAPP, _OnActivateApp); |
| 926 | #ifdef FEAT_NETBEANS_INTG |
| 927 | HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGED, _OnWindowPosChanged); |
| 928 | #endif |
| 929 | |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 930 | #ifdef FEAT_GUI_TABLINE |
| 931 | case WM_RBUTTONUP: |
| 932 | { |
| 933 | if (gui_mch_showing_tabline()) |
| 934 | { |
| 935 | POINT pt; |
| 936 | RECT rect; |
| 937 | |
| 938 | /* |
| 939 | * If the cursor is on the tabline, display the tab menu |
| 940 | */ |
| 941 | GetCursorPos((LPPOINT)&pt); |
| 942 | GetWindowRect(s_textArea, &rect); |
| 943 | if (pt.y < rect.top) |
| 944 | { |
| 945 | show_tabline_popup_menu(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 946 | return 0L; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 947 | } |
| 948 | } |
| 949 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 950 | } |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 951 | case WM_LBUTTONDBLCLK: |
| 952 | { |
| 953 | /* |
| 954 | * If the user double clicked the tabline, create a new tab |
| 955 | */ |
| 956 | if (gui_mch_showing_tabline()) |
| 957 | { |
| 958 | POINT pt; |
| 959 | RECT rect; |
| 960 | |
| 961 | GetCursorPos((LPPOINT)&pt); |
| 962 | GetWindowRect(s_textArea, &rect); |
| 963 | if (pt.y < rect.top) |
Bram Moolenaar | c6fe919 | 2006-04-09 21:54:49 +0000 | [diff] [blame] | 964 | send_tabline_menu_event(0, TABLINE_MENU_NEW); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 965 | } |
| 966 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 967 | } |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 968 | #endif |
| 969 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 970 | case WM_QUERYENDSESSION: /* System wants to go down. */ |
| 971 | gui_shell_closed(); /* Will exit when no changed buffers. */ |
| 972 | return FALSE; /* Do NOT allow system to go down. */ |
| 973 | |
| 974 | case WM_ENDSESSION: |
| 975 | if (wParam) /* system only really goes down when wParam is TRUE */ |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 976 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 977 | _OnEndSession(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 978 | return 0L; |
| 979 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 980 | break; |
| 981 | |
| 982 | case WM_CHAR: |
| 983 | /* Don't use HANDLE_MSG() for WM_CHAR, it truncates wParam to a single |
| 984 | * byte while we want the UTF-16 character value. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 985 | _OnChar(hwnd, (UINT)wParam, (int)(short)LOWORD(lParam)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 986 | return 0L; |
| 987 | |
| 988 | case WM_SYSCHAR: |
| 989 | /* |
| 990 | * if 'winaltkeys' is "no", or it's "menu" and it's not a menu |
| 991 | * shortcut key, handle like a typed ALT key, otherwise call Windows |
| 992 | * ALT key handling. |
| 993 | */ |
| 994 | #ifdef FEAT_MENU |
| 995 | if ( !gui.menu_is_active |
| 996 | || p_wak[0] == 'n' |
| 997 | || (p_wak[0] == 'm' && !gui_is_menu_shortcut((int)wParam)) |
| 998 | ) |
| 999 | #endif |
| 1000 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 1001 | _OnSysChar(hwnd, (UINT)wParam, (int)(short)LOWORD(lParam)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1002 | return 0L; |
| 1003 | } |
| 1004 | #ifdef FEAT_MENU |
| 1005 | else |
| 1006 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1007 | #endif |
| 1008 | |
| 1009 | case WM_SYSKEYUP: |
| 1010 | #ifdef FEAT_MENU |
| 1011 | /* This used to be done only when menu is active: ALT key is used for |
| 1012 | * that. But that caused problems when menu is disabled and using |
| 1013 | * Alt-Tab-Esc: get into a strange state where no mouse-moved events |
| 1014 | * are received, mouse pointer remains hidden. */ |
| 1015 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1016 | #else |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1017 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1018 | #endif |
| 1019 | |
| 1020 | case WM_SIZING: /* HANDLE_MSG doesn't seem to handle this one */ |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 1021 | return _DuringSizing((UINT)wParam, (LPRECT)lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1022 | |
| 1023 | case WM_MOUSEWHEEL: |
| 1024 | _OnMouseWheel(hwnd, HIWORD(wParam)); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1025 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1026 | |
Bram Moolenaar | 520470a | 2005-06-16 21:59:56 +0000 | [diff] [blame] | 1027 | /* Notification for change in SystemParametersInfo() */ |
| 1028 | case WM_SETTINGCHANGE: |
| 1029 | return _OnSettingChange((UINT)wParam); |
| 1030 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1031 | #if defined(FEAT_TOOLBAR) || defined(FEAT_GUI_TABLINE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1032 | case WM_NOTIFY: |
| 1033 | switch (((LPNMHDR) lParam)->code) |
| 1034 | { |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1035 | # ifdef FEAT_MBYTE |
| 1036 | case TTN_GETDISPINFOW: |
| 1037 | # endif |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1038 | case TTN_GETDISPINFO: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1039 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1040 | LPNMHDR hdr = (LPNMHDR)lParam; |
| 1041 | char_u *str = NULL; |
| 1042 | static void *tt_text = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1043 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1044 | vim_free(tt_text); |
| 1045 | tt_text = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1046 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1047 | # ifdef FEAT_GUI_TABLINE |
| 1048 | if (gui_mch_showing_tabline() |
| 1049 | && hdr->hwndFrom == TabCtrl_GetToolTips(s_tabhwnd)) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1050 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1051 | POINT pt; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1052 | /* |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1053 | * Mouse is over the GUI tabline. Display the |
| 1054 | * tooltip for the tab under the cursor |
| 1055 | * |
| 1056 | * Get the cursor position within the tab control |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1057 | */ |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1058 | GetCursorPos(&pt); |
| 1059 | if (ScreenToClient(s_tabhwnd, &pt) != 0) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1060 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1061 | TCHITTESTINFO htinfo; |
| 1062 | int idx; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1063 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1064 | /* |
| 1065 | * Get the tab under the cursor |
| 1066 | */ |
| 1067 | htinfo.pt.x = pt.x; |
| 1068 | htinfo.pt.y = pt.y; |
| 1069 | idx = TabCtrl_HitTest(s_tabhwnd, &htinfo); |
| 1070 | if (idx != -1) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1071 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1072 | tabpage_T *tp; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1073 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1074 | tp = find_tabpage(idx + 1); |
| 1075 | if (tp != NULL) |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1076 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1077 | get_tabline_label(tp, TRUE); |
| 1078 | str = NameBuff; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1083 | # endif |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1084 | # ifdef FEAT_TOOLBAR |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1085 | # ifdef FEAT_GUI_TABLINE |
| 1086 | else |
| 1087 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1088 | { |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1089 | UINT idButton; |
| 1090 | vimmenu_T *pMenu; |
| 1091 | |
| 1092 | idButton = (UINT) hdr->idFrom; |
| 1093 | pMenu = gui_mswin_find_menu(root_menu, idButton); |
| 1094 | if (pMenu) |
| 1095 | str = pMenu->strings[MENU_INDEX_TIP]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1096 | } |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 1097 | # endif |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1098 | if (str != NULL) |
| 1099 | { |
| 1100 | # ifdef FEAT_MBYTE |
| 1101 | if (hdr->code == TTN_GETDISPINFOW) |
| 1102 | { |
| 1103 | LPNMTTDISPINFOW lpdi = (LPNMTTDISPINFOW)lParam; |
| 1104 | |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 1105 | /* Set the maximum width, this also enables using |
| 1106 | * \n for line break. */ |
| 1107 | SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, |
| 1108 | 0, 500); |
| 1109 | |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 1110 | tt_text = enc_to_utf16(str, NULL); |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1111 | lpdi->lpszText = tt_text; |
| 1112 | /* can't show tooltip if failed */ |
| 1113 | } |
| 1114 | else |
| 1115 | # endif |
| 1116 | { |
| 1117 | LPNMTTDISPINFO lpdi = (LPNMTTDISPINFO)lParam; |
| 1118 | |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 1119 | /* Set the maximum width, this also enables using |
| 1120 | * \n for line break. */ |
| 1121 | SendMessage(lpdi->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, |
| 1122 | 0, 500); |
| 1123 | |
Bram Moolenaar | 8f2ff9f | 2006-08-29 19:26:50 +0000 | [diff] [blame] | 1124 | if (STRLEN(str) < sizeof(lpdi->szText) |
| 1125 | || ((tt_text = vim_strsave(str)) == NULL)) |
| 1126 | vim_strncpy(lpdi->szText, str, |
| 1127 | sizeof(lpdi->szText) - 1); |
| 1128 | else |
| 1129 | lpdi->lpszText = tt_text; |
| 1130 | } |
| 1131 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1132 | } |
| 1133 | break; |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1134 | # ifdef FEAT_GUI_TABLINE |
| 1135 | case TCN_SELCHANGE: |
| 1136 | if (gui_mch_showing_tabline() |
| 1137 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1138 | { |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1139 | send_tabline_event(TabCtrl_GetCurSel(s_tabhwnd) + 1); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1140 | return 0L; |
| 1141 | } |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1142 | break; |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 1143 | |
| 1144 | case NM_RCLICK: |
| 1145 | if (gui_mch_showing_tabline() |
| 1146 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1147 | { |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 1148 | show_tabline_popup_menu(); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1149 | return 0L; |
| 1150 | } |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 1151 | break; |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1152 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1153 | default: |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1154 | # ifdef FEAT_GUI_TABLINE |
| 1155 | if (gui_mch_showing_tabline() |
| 1156 | && ((LPNMHDR)lParam)->hwndFrom == s_tabhwnd) |
| 1157 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1158 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1159 | break; |
| 1160 | } |
| 1161 | break; |
| 1162 | #endif |
| 1163 | #if defined(MENUHINTS) && defined(FEAT_MENU) |
| 1164 | case WM_MENUSELECT: |
| 1165 | if (((UINT) HIWORD(wParam) |
| 1166 | & (0xffff ^ (MF_MOUSESELECT + MF_BITMAP + MF_POPUP))) |
| 1167 | == MF_HILITE |
| 1168 | && (State & CMDLINE) == 0) |
| 1169 | { |
| 1170 | UINT idButton; |
| 1171 | vimmenu_T *pMenu; |
| 1172 | static int did_menu_tip = FALSE; |
| 1173 | |
| 1174 | if (did_menu_tip) |
| 1175 | { |
| 1176 | msg_clr_cmdline(); |
| 1177 | setcursor(); |
| 1178 | out_flush(); |
| 1179 | did_menu_tip = FALSE; |
| 1180 | } |
| 1181 | |
| 1182 | idButton = (UINT)LOWORD(wParam); |
| 1183 | pMenu = gui_mswin_find_menu(root_menu, idButton); |
| 1184 | if (pMenu != NULL && pMenu->strings[MENU_INDEX_TIP] != 0 |
| 1185 | && GetMenuState(s_menuBar, pMenu->id, MF_BYCOMMAND) != -1) |
| 1186 | { |
Bram Moolenaar | 2d8ab99 | 2007-06-19 08:06:18 +0000 | [diff] [blame] | 1187 | ++msg_hist_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1188 | msg(pMenu->strings[MENU_INDEX_TIP]); |
Bram Moolenaar | 2d8ab99 | 2007-06-19 08:06:18 +0000 | [diff] [blame] | 1189 | --msg_hist_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1190 | setcursor(); |
| 1191 | out_flush(); |
| 1192 | did_menu_tip = TRUE; |
| 1193 | } |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1194 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1195 | } |
| 1196 | break; |
| 1197 | #endif |
| 1198 | case WM_NCHITTEST: |
| 1199 | { |
| 1200 | LRESULT result; |
| 1201 | int x, y; |
| 1202 | int xPos = GET_X_LPARAM(lParam); |
| 1203 | |
| 1204 | result = MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1205 | if (result == HTCLIENT) |
| 1206 | { |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1207 | #ifdef FEAT_GUI_TABLINE |
| 1208 | if (gui_mch_showing_tabline()) |
| 1209 | { |
| 1210 | int yPos = GET_Y_LPARAM(lParam); |
| 1211 | RECT rct; |
| 1212 | |
| 1213 | /* If the cursor is on the GUI tabline, don't process this |
| 1214 | * event */ |
| 1215 | GetWindowRect(s_textArea, &rct); |
| 1216 | if (yPos < rct.top) |
| 1217 | return result; |
| 1218 | } |
| 1219 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1220 | gui_mch_get_winpos(&x, &y); |
| 1221 | xPos -= x; |
| 1222 | |
| 1223 | if (xPos < 48) /* <VN> TODO should use system metric? */ |
| 1224 | return HTBOTTOMLEFT; |
| 1225 | else |
| 1226 | return HTBOTTOMRIGHT; |
| 1227 | } |
| 1228 | else |
| 1229 | return result; |
| 1230 | } |
| 1231 | /* break; notreached */ |
| 1232 | |
| 1233 | #ifdef FEAT_MBYTE_IME |
| 1234 | case WM_IME_NOTIFY: |
| 1235 | if (!_OnImeNotify(hwnd, (DWORD)wParam, (DWORD)lParam)) |
| 1236 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1237 | return 1L; |
| 1238 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1239 | case WM_IME_COMPOSITION: |
| 1240 | if (!_OnImeComposition(hwnd, wParam, lParam)) |
| 1241 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1242 | return 1L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1243 | #endif |
| 1244 | |
| 1245 | default: |
| 1246 | if (uMsg == msh_msgmousewheel && msh_msgmousewheel != 0) |
| 1247 | { /* handle MSH_MOUSEWHEEL messages for Intellimouse */ |
| 1248 | _OnMouseWheel(hwnd, HIWORD(wParam)); |
Bram Moolenaar | 213ae48 | 2011-12-15 21:51:36 +0100 | [diff] [blame] | 1249 | return 0L; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1250 | } |
| 1251 | #ifdef MSWIN_FIND_REPLACE |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1252 | else if (uMsg == s_findrep_msg && s_findrep_msg != 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1253 | { |
| 1254 | _OnFindRepl(); |
| 1255 | } |
| 1256 | #endif |
| 1257 | return MyWindowProc(hwnd, uMsg, wParam, lParam); |
| 1258 | } |
| 1259 | |
Bram Moolenaar | 2787ab9 | 2011-12-14 15:23:59 +0100 | [diff] [blame] | 1260 | return DefWindowProc(hwnd, uMsg, wParam, lParam); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /* |
| 1264 | * End of call-back routines |
| 1265 | */ |
| 1266 | |
| 1267 | /* parent window, if specified with -P */ |
| 1268 | HWND vim_parent_hwnd = NULL; |
| 1269 | |
| 1270 | static BOOL CALLBACK |
| 1271 | FindWindowTitle(HWND hwnd, LPARAM lParam) |
| 1272 | { |
| 1273 | char buf[2048]; |
| 1274 | char *title = (char *)lParam; |
| 1275 | |
| 1276 | if (GetWindowText(hwnd, buf, sizeof(buf))) |
| 1277 | { |
| 1278 | if (strstr(buf, title) != NULL) |
| 1279 | { |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1280 | /* Found it. Store the window ref. and quit searching if MDI |
| 1281 | * works. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1282 | vim_parent_hwnd = FindWindowEx(hwnd, NULL, "MDIClient", NULL); |
Bram Moolenaar | 69a7cb4 | 2004-06-20 12:51:53 +0000 | [diff] [blame] | 1283 | if (vim_parent_hwnd != NULL) |
| 1284 | return FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | return TRUE; /* continue searching */ |
| 1288 | } |
| 1289 | |
| 1290 | /* |
| 1291 | * Invoked for '-P "title"' argument: search for parent application to open |
| 1292 | * our window in. |
| 1293 | */ |
| 1294 | void |
| 1295 | gui_mch_set_parent(char *title) |
| 1296 | { |
| 1297 | EnumWindows(FindWindowTitle, (LPARAM)title); |
| 1298 | if (vim_parent_hwnd == NULL) |
| 1299 | { |
| 1300 | EMSG2(_("E671: Cannot find window title \"%s\""), title); |
| 1301 | mch_exit(2); |
| 1302 | } |
| 1303 | } |
| 1304 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 1305 | #ifndef FEAT_OLE |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1306 | static void |
| 1307 | ole_error(char *arg) |
| 1308 | { |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 1309 | char buf[IOSIZE]; |
| 1310 | |
| 1311 | /* Can't use EMSG() here, we have not finished initialisation yet. */ |
| 1312 | vim_snprintf(buf, IOSIZE, |
| 1313 | _("E243: Argument not supported: \"-%s\"; Use the OLE version."), |
| 1314 | arg); |
| 1315 | mch_errmsg(buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1316 | } |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 1317 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1318 | |
| 1319 | /* |
| 1320 | * Parse the GUI related command-line arguments. Any arguments used are |
| 1321 | * deleted from argv, and *argc is decremented accordingly. This is called |
| 1322 | * when vim is started, whether or not the GUI has been started. |
| 1323 | */ |
| 1324 | void |
| 1325 | gui_mch_prepare(int *argc, char **argv) |
| 1326 | { |
| 1327 | int silent = FALSE; |
| 1328 | int idx; |
| 1329 | |
| 1330 | /* Check for special OLE command line parameters */ |
| 1331 | if ((*argc == 2 || *argc == 3) && (argv[1][0] == '-' || argv[1][0] == '/')) |
| 1332 | { |
| 1333 | /* Check for a "-silent" argument first. */ |
| 1334 | if (*argc == 3 && STRICMP(argv[1] + 1, "silent") == 0 |
| 1335 | && (argv[2][0] == '-' || argv[2][0] == '/')) |
| 1336 | { |
| 1337 | silent = TRUE; |
| 1338 | idx = 2; |
| 1339 | } |
| 1340 | else |
| 1341 | idx = 1; |
| 1342 | |
| 1343 | /* Register Vim as an OLE Automation server */ |
| 1344 | if (STRICMP(argv[idx] + 1, "register") == 0) |
| 1345 | { |
| 1346 | #ifdef FEAT_OLE |
| 1347 | RegisterMe(silent); |
| 1348 | mch_exit(0); |
| 1349 | #else |
| 1350 | if (!silent) |
| 1351 | ole_error("register"); |
| 1352 | mch_exit(2); |
| 1353 | #endif |
| 1354 | } |
| 1355 | |
| 1356 | /* Unregister Vim as an OLE Automation server */ |
| 1357 | if (STRICMP(argv[idx] + 1, "unregister") == 0) |
| 1358 | { |
| 1359 | #ifdef FEAT_OLE |
| 1360 | UnregisterMe(!silent); |
| 1361 | mch_exit(0); |
| 1362 | #else |
| 1363 | if (!silent) |
| 1364 | ole_error("unregister"); |
| 1365 | mch_exit(2); |
| 1366 | #endif |
| 1367 | } |
| 1368 | |
| 1369 | /* Ignore an -embedding argument. It is only relevant if the |
| 1370 | * application wants to treat the case when it is started manually |
| 1371 | * differently from the case where it is started via automation (and |
| 1372 | * we don't). |
| 1373 | */ |
| 1374 | if (STRICMP(argv[idx] + 1, "embedding") == 0) |
| 1375 | { |
| 1376 | #ifdef FEAT_OLE |
| 1377 | *argc = 1; |
| 1378 | #else |
| 1379 | ole_error("embedding"); |
| 1380 | mch_exit(2); |
| 1381 | #endif |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | #ifdef FEAT_OLE |
| 1386 | { |
| 1387 | int bDoRestart = FALSE; |
| 1388 | |
| 1389 | InitOLE(&bDoRestart); |
| 1390 | /* automatically exit after registering */ |
| 1391 | if (bDoRestart) |
| 1392 | mch_exit(0); |
| 1393 | } |
| 1394 | #endif |
| 1395 | |
| 1396 | #ifdef FEAT_NETBEANS_INTG |
| 1397 | { |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 1398 | /* stolen from gui_x11.c */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1399 | int arg; |
| 1400 | |
| 1401 | for (arg = 1; arg < *argc; arg++) |
| 1402 | if (strncmp("-nb", argv[arg], 3) == 0) |
| 1403 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1404 | netbeansArg = argv[arg]; |
| 1405 | mch_memmove(&argv[arg], &argv[arg + 1], |
| 1406 | (--*argc - arg) * sizeof(char *)); |
| 1407 | argv[*argc] = NULL; |
| 1408 | break; /* enough? */ |
| 1409 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1410 | } |
| 1411 | #endif |
| 1412 | |
| 1413 | /* get the OS version info */ |
| 1414 | os_version.dwOSVersionInfoSize = sizeof(os_version); |
| 1415 | GetVersionEx(&os_version); /* this call works on Win32s, Win95 and WinNT */ |
| 1416 | |
| 1417 | /* try and load the user32.dll library and get the entry points for |
| 1418 | * multi-monitor-support. */ |
Bram Moolenaar | ebbcb82 | 2010-10-23 14:02:54 +0200 | [diff] [blame] | 1419 | if ((user32_lib = vimLoadLib("User32.dll")) != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1420 | { |
| 1421 | pMonitorFromWindow = (TMonitorFromWindow)GetProcAddress(user32_lib, |
| 1422 | "MonitorFromWindow"); |
| 1423 | |
| 1424 | /* there are ...A and ...W version of GetMonitorInfo - looking at |
| 1425 | * winuser.h, they have exactly the same declaration. */ |
| 1426 | pGetMonitorInfo = (TGetMonitorInfo)GetProcAddress(user32_lib, |
| 1427 | "GetMonitorInfoA"); |
| 1428 | } |
Bram Moolenaar | 8c85fa3 | 2011-08-10 17:08:03 +0200 | [diff] [blame] | 1429 | |
| 1430 | #ifdef FEAT_MBYTE |
| 1431 | /* If the OS is Windows NT, use wide functions; |
| 1432 | * this enables common dialogs input unicode from IME. */ |
| 1433 | if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT) |
| 1434 | { |
| 1435 | pDispatchMessage = DispatchMessageW; |
| 1436 | pGetMessage = GetMessageW; |
| 1437 | pIsDialogMessage = IsDialogMessageW; |
| 1438 | pPeekMessage = PeekMessageW; |
| 1439 | } |
| 1440 | else |
| 1441 | { |
| 1442 | pDispatchMessage = DispatchMessageA; |
| 1443 | pGetMessage = GetMessageA; |
| 1444 | pIsDialogMessage = IsDialogMessageA; |
| 1445 | pPeekMessage = PeekMessageA; |
| 1446 | } |
| 1447 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | /* |
| 1451 | * Initialise the GUI. Create all the windows, set up all the call-backs |
| 1452 | * etc. |
| 1453 | */ |
| 1454 | int |
| 1455 | gui_mch_init(void) |
| 1456 | { |
| 1457 | const char szVimWndClass[] = VIM_CLASS; |
| 1458 | const char szTextAreaClass[] = "VimTextArea"; |
| 1459 | WNDCLASS wndclass; |
| 1460 | #ifdef FEAT_MBYTE |
| 1461 | const WCHAR szVimWndClassW[] = VIM_CLASSW; |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 1462 | const WCHAR szTextAreaClassW[] = L"VimTextArea"; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1463 | WNDCLASSW wndclassw; |
| 1464 | #endif |
| 1465 | #ifdef GLOBAL_IME |
| 1466 | ATOM atom; |
| 1467 | #endif |
| 1468 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1469 | /* Return here if the window was already opened (happens when |
| 1470 | * gui_mch_dialog() is called early). */ |
| 1471 | if (s_hwnd != NULL) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 1472 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1473 | |
| 1474 | /* |
| 1475 | * Load the tearoff bitmap |
| 1476 | */ |
| 1477 | #ifdef FEAT_TEAROFF |
| 1478 | s_htearbitmap = LoadBitmap(s_hinst, "IDB_TEAROFF"); |
| 1479 | #endif |
| 1480 | |
| 1481 | gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL); |
| 1482 | gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL); |
| 1483 | #ifdef FEAT_MENU |
| 1484 | gui.menu_height = 0; /* Windows takes care of this */ |
| 1485 | #endif |
| 1486 | gui.border_width = 0; |
| 1487 | |
| 1488 | s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); |
| 1489 | |
| 1490 | #ifdef FEAT_MBYTE |
| 1491 | /* First try using the wide version, so that we can use any title. |
| 1492 | * Otherwise only characters in the active codepage will work. */ |
| 1493 | if (GetClassInfoW(s_hinst, szVimWndClassW, &wndclassw) == 0) |
| 1494 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 1495 | wndclassw.style = CS_DBLCLKS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1496 | wndclassw.lpfnWndProc = _WndProc; |
| 1497 | wndclassw.cbClsExtra = 0; |
| 1498 | wndclassw.cbWndExtra = 0; |
| 1499 | wndclassw.hInstance = s_hinst; |
| 1500 | wndclassw.hIcon = LoadIcon(wndclassw.hInstance, "IDR_VIM"); |
| 1501 | wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 1502 | wndclassw.hbrBackground = s_brush; |
| 1503 | wndclassw.lpszMenuName = NULL; |
| 1504 | wndclassw.lpszClassName = szVimWndClassW; |
| 1505 | |
| 1506 | if (( |
| 1507 | #ifdef GLOBAL_IME |
| 1508 | atom = |
| 1509 | #endif |
| 1510 | RegisterClassW(&wndclassw)) == 0) |
| 1511 | { |
| 1512 | if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED) |
| 1513 | return FAIL; |
| 1514 | |
| 1515 | /* Must be Windows 98, fall back to non-wide function. */ |
| 1516 | } |
| 1517 | else |
| 1518 | wide_WindowProc = TRUE; |
| 1519 | } |
| 1520 | |
| 1521 | if (!wide_WindowProc) |
| 1522 | #endif |
| 1523 | |
| 1524 | if (GetClassInfo(s_hinst, szVimWndClass, &wndclass) == 0) |
| 1525 | { |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 1526 | wndclass.style = CS_DBLCLKS; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1527 | wndclass.lpfnWndProc = _WndProc; |
| 1528 | wndclass.cbClsExtra = 0; |
| 1529 | wndclass.cbWndExtra = 0; |
| 1530 | wndclass.hInstance = s_hinst; |
| 1531 | wndclass.hIcon = LoadIcon(wndclass.hInstance, "IDR_VIM"); |
| 1532 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 1533 | wndclass.hbrBackground = s_brush; |
| 1534 | wndclass.lpszMenuName = NULL; |
| 1535 | wndclass.lpszClassName = szVimWndClass; |
| 1536 | |
| 1537 | if (( |
| 1538 | #ifdef GLOBAL_IME |
| 1539 | atom = |
| 1540 | #endif |
| 1541 | RegisterClass(&wndclass)) == 0) |
| 1542 | return FAIL; |
| 1543 | } |
| 1544 | |
| 1545 | if (vim_parent_hwnd != NULL) |
| 1546 | { |
| 1547 | #ifdef HAVE_TRY_EXCEPT |
| 1548 | __try |
| 1549 | { |
| 1550 | #endif |
| 1551 | /* Open inside the specified parent window. |
| 1552 | * TODO: last argument should point to a CLIENTCREATESTRUCT |
| 1553 | * structure. */ |
| 1554 | s_hwnd = CreateWindowEx( |
| 1555 | WS_EX_MDICHILD, |
| 1556 | szVimWndClass, "Vim MSWindows GUI", |
Bram Moolenaar | e78c206 | 2011-08-10 15:56:27 +0200 | [diff] [blame] | 1557 | WS_OVERLAPPEDWINDOW | WS_CHILD |
| 1558 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 0xC000, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1559 | gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
| 1560 | gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
| 1561 | 100, /* Any value will do */ |
| 1562 | 100, /* Any value will do */ |
| 1563 | vim_parent_hwnd, NULL, |
| 1564 | s_hinst, NULL); |
| 1565 | #ifdef HAVE_TRY_EXCEPT |
| 1566 | } |
| 1567 | __except(EXCEPTION_EXECUTE_HANDLER) |
| 1568 | { |
| 1569 | /* NOP */ |
| 1570 | } |
| 1571 | #endif |
| 1572 | if (s_hwnd == NULL) |
| 1573 | { |
| 1574 | EMSG(_("E672: Unable to open window inside MDI application")); |
| 1575 | mch_exit(2); |
| 1576 | } |
| 1577 | } |
| 1578 | else |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 1579 | { |
| 1580 | /* If the provided windowid is not valid reset it to zero, so that it |
| 1581 | * is ignored and we open our own window. */ |
| 1582 | if (IsWindow((HWND)win_socket_id) <= 0) |
| 1583 | win_socket_id = 0; |
| 1584 | |
| 1585 | /* Create a window. If win_socket_id is not zero without border and |
| 1586 | * titlebar, it will be reparented below. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1587 | s_hwnd = CreateWindow( |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 1588 | szVimWndClass, "Vim MSWindows GUI", |
Bram Moolenaar | e78c206 | 2011-08-10 15:56:27 +0200 | [diff] [blame] | 1589 | (win_socket_id == 0 ? WS_OVERLAPPEDWINDOW : WS_POPUP) |
| 1590 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
Bram Moolenaar | 78e1762 | 2007-08-30 10:26:19 +0000 | [diff] [blame] | 1591 | gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x, |
| 1592 | gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y, |
| 1593 | 100, /* Any value will do */ |
| 1594 | 100, /* Any value will do */ |
| 1595 | NULL, NULL, |
| 1596 | s_hinst, NULL); |
| 1597 | if (s_hwnd != NULL && win_socket_id != 0) |
| 1598 | { |
| 1599 | SetParent(s_hwnd, (HWND)win_socket_id); |
| 1600 | ShowWindow(s_hwnd, SW_SHOWMAXIMIZED); |
| 1601 | } |
| 1602 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1603 | |
| 1604 | if (s_hwnd == NULL) |
| 1605 | return FAIL; |
| 1606 | |
| 1607 | #ifdef GLOBAL_IME |
| 1608 | global_ime_init(atom, s_hwnd); |
| 1609 | #endif |
| 1610 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 1611 | dyn_imm_load(); |
| 1612 | #endif |
| 1613 | |
| 1614 | /* Create the text area window */ |
Bram Moolenaar | 33d0b69 | 2010-02-17 16:31:32 +0100 | [diff] [blame] | 1615 | #ifdef FEAT_MBYTE |
| 1616 | if (wide_WindowProc) |
| 1617 | { |
| 1618 | if (GetClassInfoW(s_hinst, szTextAreaClassW, &wndclassw) == 0) |
| 1619 | { |
| 1620 | wndclassw.style = CS_OWNDC; |
| 1621 | wndclassw.lpfnWndProc = _TextAreaWndProc; |
| 1622 | wndclassw.cbClsExtra = 0; |
| 1623 | wndclassw.cbWndExtra = 0; |
| 1624 | wndclassw.hInstance = s_hinst; |
| 1625 | wndclassw.hIcon = NULL; |
| 1626 | wndclassw.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 1627 | wndclassw.hbrBackground = NULL; |
| 1628 | wndclassw.lpszMenuName = NULL; |
| 1629 | wndclassw.lpszClassName = szTextAreaClassW; |
| 1630 | |
| 1631 | if (RegisterClassW(&wndclassw) == 0) |
| 1632 | return FAIL; |
| 1633 | } |
| 1634 | } |
| 1635 | else |
| 1636 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1637 | if (GetClassInfo(s_hinst, szTextAreaClass, &wndclass) == 0) |
| 1638 | { |
| 1639 | wndclass.style = CS_OWNDC; |
| 1640 | wndclass.lpfnWndProc = _TextAreaWndProc; |
| 1641 | wndclass.cbClsExtra = 0; |
| 1642 | wndclass.cbWndExtra = 0; |
| 1643 | wndclass.hInstance = s_hinst; |
| 1644 | wndclass.hIcon = NULL; |
| 1645 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 1646 | wndclass.hbrBackground = NULL; |
| 1647 | wndclass.lpszMenuName = NULL; |
| 1648 | wndclass.lpszClassName = szTextAreaClass; |
| 1649 | |
| 1650 | if (RegisterClass(&wndclass) == 0) |
| 1651 | return FAIL; |
| 1652 | } |
| 1653 | s_textArea = CreateWindowEx( |
| 1654 | WS_EX_CLIENTEDGE, |
| 1655 | szTextAreaClass, "Vim text area", |
| 1656 | WS_CHILD | WS_VISIBLE, 0, 0, |
| 1657 | 100, /* Any value will do for now */ |
| 1658 | 100, /* Any value will do for now */ |
| 1659 | s_hwnd, NULL, |
| 1660 | s_hinst, NULL); |
| 1661 | |
| 1662 | if (s_textArea == NULL) |
| 1663 | return FAIL; |
| 1664 | |
| 1665 | #ifdef FEAT_MENU |
| 1666 | s_menuBar = CreateMenu(); |
| 1667 | #endif |
| 1668 | s_hdc = GetDC(s_textArea); |
| 1669 | |
| 1670 | #ifdef MSWIN16_FASTTEXT |
| 1671 | SetBkMode(s_hdc, OPAQUE); |
| 1672 | #endif |
| 1673 | |
| 1674 | #ifdef FEAT_WINDOWS |
| 1675 | DragAcceptFiles(s_hwnd, TRUE); |
| 1676 | #endif |
| 1677 | |
| 1678 | /* Do we need to bother with this? */ |
| 1679 | /* m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); */ |
| 1680 | |
| 1681 | /* Get background/foreground colors from the system */ |
| 1682 | gui_mch_def_colors(); |
| 1683 | |
| 1684 | /* Get the colors from the "Normal" group (set in syntax.c or in a vimrc |
| 1685 | * file) */ |
| 1686 | set_normal_colors(); |
| 1687 | |
| 1688 | /* |
| 1689 | * Check that none of the colors are the same as the background color. |
| 1690 | * Then store the current values as the defaults. |
| 1691 | */ |
| 1692 | gui_check_colors(); |
| 1693 | gui.def_norm_pixel = gui.norm_pixel; |
| 1694 | gui.def_back_pixel = gui.back_pixel; |
| 1695 | |
| 1696 | /* Get the colors for the highlight groups (gui_check_colors() might have |
| 1697 | * changed them) */ |
| 1698 | highlight_gui_started(); |
| 1699 | |
| 1700 | /* |
| 1701 | * Start out by adding the configured border width into the border offset |
| 1702 | */ |
| 1703 | gui.border_offset = gui.border_width + 2; /*CLIENT EDGE*/ |
| 1704 | |
| 1705 | /* |
| 1706 | * Set up for Intellimouse processing |
| 1707 | */ |
| 1708 | init_mouse_wheel(); |
| 1709 | |
| 1710 | /* |
| 1711 | * compute a couple of metrics used for the dialogs |
| 1712 | */ |
| 1713 | get_dialog_font_metrics(); |
| 1714 | #ifdef FEAT_TOOLBAR |
| 1715 | /* |
| 1716 | * Create the toolbar |
| 1717 | */ |
| 1718 | initialise_toolbar(); |
| 1719 | #endif |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 1720 | #ifdef FEAT_GUI_TABLINE |
| 1721 | /* |
| 1722 | * Create the tabline |
| 1723 | */ |
| 1724 | initialise_tabline(); |
| 1725 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1726 | #ifdef MSWIN_FIND_REPLACE |
| 1727 | /* |
| 1728 | * Initialise the dialog box stuff |
| 1729 | */ |
| 1730 | s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING); |
| 1731 | |
| 1732 | /* Initialise the struct */ |
| 1733 | s_findrep_struct.lStructSize = sizeof(s_findrep_struct); |
| 1734 | s_findrep_struct.lpstrFindWhat = alloc(MSWIN_FR_BUFSIZE); |
| 1735 | s_findrep_struct.lpstrFindWhat[0] = NUL; |
| 1736 | s_findrep_struct.lpstrReplaceWith = alloc(MSWIN_FR_BUFSIZE); |
| 1737 | s_findrep_struct.lpstrReplaceWith[0] = NUL; |
| 1738 | s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE; |
| 1739 | s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE; |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 1740 | # if defined(FEAT_MBYTE) && defined(WIN3264) |
| 1741 | s_findrep_struct_w.lStructSize = sizeof(s_findrep_struct_w); |
| 1742 | s_findrep_struct_w.lpstrFindWhat = |
| 1743 | (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR)); |
| 1744 | s_findrep_struct_w.lpstrFindWhat[0] = NUL; |
| 1745 | s_findrep_struct_w.lpstrReplaceWith = |
| 1746 | (LPWSTR)alloc(MSWIN_FR_BUFSIZE * sizeof(WCHAR)); |
| 1747 | s_findrep_struct_w.lpstrReplaceWith[0] = NUL; |
| 1748 | s_findrep_struct_w.wFindWhatLen = MSWIN_FR_BUFSIZE; |
| 1749 | s_findrep_struct_w.wReplaceWithLen = MSWIN_FR_BUFSIZE; |
| 1750 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1751 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1752 | |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 1753 | #ifdef FEAT_EVAL |
Bram Moolenaar | af62ff3 | 2013-03-19 14:48:29 +0100 | [diff] [blame] | 1754 | # ifndef HandleToLong |
Bram Moolenaar | 4da95d3 | 2011-07-07 17:43:41 +0200 | [diff] [blame] | 1755 | /* HandleToLong() only exists in compilers that can do 64 bit builds */ |
| 1756 | # define HandleToLong(h) ((long)(h)) |
| 1757 | # endif |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 1758 | /* set the v:windowid variable */ |
Bram Moolenaar | 7154b32 | 2011-05-25 21:18:06 +0200 | [diff] [blame] | 1759 | set_vim_var_nr(VV_WINDOWID, HandleToLong(s_hwnd)); |
Bram Moolenaar | 264e9fd | 2010-10-27 12:33:17 +0200 | [diff] [blame] | 1760 | #endif |
| 1761 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 1762 | #ifdef FEAT_RENDER_OPTIONS |
| 1763 | if (p_rop) |
| 1764 | (void)gui_mch_set_rendering_options(p_rop); |
| 1765 | #endif |
| 1766 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 1767 | theend: |
| 1768 | /* Display any pending error messages */ |
| 1769 | display_errors(); |
| 1770 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1771 | return OK; |
| 1772 | } |
| 1773 | |
| 1774 | /* |
| 1775 | * Get the size of the screen, taking position on multiple monitors into |
| 1776 | * account (if supported). |
| 1777 | */ |
| 1778 | static void |
| 1779 | get_work_area(RECT *spi_rect) |
| 1780 | { |
| 1781 | _HMONITOR mon; |
| 1782 | _MONITORINFO moninfo; |
| 1783 | |
| 1784 | /* use these functions only if available */ |
| 1785 | if (pMonitorFromWindow != NULL && pGetMonitorInfo != NULL) |
| 1786 | { |
| 1787 | /* work out which monitor the window is on, and get *it's* work area */ |
| 1788 | mon = pMonitorFromWindow(s_hwnd, 1 /*MONITOR_DEFAULTTOPRIMARY*/); |
| 1789 | if (mon != NULL) |
| 1790 | { |
| 1791 | moninfo.cbSize = sizeof(_MONITORINFO); |
| 1792 | if (pGetMonitorInfo(mon, &moninfo)) |
| 1793 | { |
| 1794 | *spi_rect = moninfo.rcWork; |
| 1795 | return; |
| 1796 | } |
| 1797 | } |
| 1798 | } |
| 1799 | /* this is the old method... */ |
| 1800 | SystemParametersInfo(SPI_GETWORKAREA, 0, spi_rect, 0); |
| 1801 | } |
| 1802 | |
| 1803 | /* |
| 1804 | * Set the size of the window to the given width and height in pixels. |
| 1805 | */ |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 1806 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1807 | void |
| 1808 | gui_mch_set_shellsize(int width, int height, |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 1809 | int min_width, int min_height, int base_width, int base_height, |
| 1810 | int direction) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1811 | { |
| 1812 | RECT workarea_rect; |
| 1813 | int win_width, win_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1814 | WINDOWPLACEMENT wndpl; |
| 1815 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 1816 | /* Try to keep window completely on screen. */ |
| 1817 | /* Get position of the screen work area. This is the part that is not |
| 1818 | * used by the taskbar or appbars. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1819 | get_work_area(&workarea_rect); |
| 1820 | |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 1821 | /* 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] | 1822 | * relative to the work area. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1823 | wndpl.length = sizeof(WINDOWPLACEMENT); |
| 1824 | GetWindowPlacement(s_hwnd, &wndpl); |
| 1825 | |
| 1826 | /* Resizing a maximized window looks very strange, unzoom it first. |
| 1827 | * But don't do it when still starting up, it may have been requested in |
| 1828 | * the shortcut. */ |
| 1829 | if (wndpl.showCmd == SW_SHOWMAXIMIZED && starting == 0) |
| 1830 | { |
| 1831 | ShowWindow(s_hwnd, SW_SHOWNORMAL); |
| 1832 | /* Need to get the settings of the normal window. */ |
| 1833 | GetWindowPlacement(s_hwnd, &wndpl); |
| 1834 | } |
| 1835 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1836 | /* compute the size of the outside of the window */ |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 1837 | win_width = width + (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 1838 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 1839 | win_height = height + (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 1840 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1841 | + GetSystemMetrics(SM_CYCAPTION) |
| 1842 | #ifdef FEAT_MENU |
| 1843 | + gui_mswin_get_menu_height(FALSE) |
| 1844 | #endif |
| 1845 | ; |
| 1846 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 1847 | /* The following should take care of keeping Vim on the same monitor, no |
| 1848 | * matter if the secondary monitor is left or right of the primary |
| 1849 | * monitor. */ |
| 1850 | wndpl.rcNormalPosition.right = wndpl.rcNormalPosition.left + win_width; |
| 1851 | wndpl.rcNormalPosition.bottom = wndpl.rcNormalPosition.top + win_height; |
Bram Moolenaar | 56a907a | 2006-05-06 21:44:30 +0000 | [diff] [blame] | 1852 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 1853 | /* 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] | 1854 | if ((direction & RESIZE_HOR) |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 1855 | && wndpl.rcNormalPosition.right > workarea_rect.right) |
| 1856 | OffsetRect(&wndpl.rcNormalPosition, |
| 1857 | workarea_rect.right - wndpl.rcNormalPosition.right, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1858 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 1859 | if ((direction & RESIZE_HOR) |
| 1860 | && wndpl.rcNormalPosition.left < workarea_rect.left) |
| 1861 | OffsetRect(&wndpl.rcNormalPosition, |
| 1862 | workarea_rect.left - wndpl.rcNormalPosition.left, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1863 | |
Bram Moolenaar | afa2499 | 2006-03-27 20:58:26 +0000 | [diff] [blame] | 1864 | if ((direction & RESIZE_VERT) |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 1865 | && wndpl.rcNormalPosition.bottom > workarea_rect.bottom) |
| 1866 | OffsetRect(&wndpl.rcNormalPosition, |
| 1867 | 0, workarea_rect.bottom - wndpl.rcNormalPosition.bottom); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1868 | |
Bram Moolenaar | 6ef47c2 | 2012-01-04 20:29:22 +0100 | [diff] [blame] | 1869 | if ((direction & RESIZE_VERT) |
| 1870 | && wndpl.rcNormalPosition.top < workarea_rect.top) |
| 1871 | OffsetRect(&wndpl.rcNormalPosition, |
| 1872 | 0, workarea_rect.top - wndpl.rcNormalPosition.top); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1873 | |
| 1874 | /* set window position - we should use SetWindowPlacement rather than |
| 1875 | * SetWindowPos as the MSDN docs say the coord systems returned by |
| 1876 | * these two are not compatible. */ |
| 1877 | SetWindowPlacement(s_hwnd, &wndpl); |
| 1878 | |
| 1879 | SetActiveWindow(s_hwnd); |
| 1880 | SetFocus(s_hwnd); |
| 1881 | |
| 1882 | #ifdef FEAT_MENU |
| 1883 | /* Menu may wrap differently now */ |
| 1884 | gui_mswin_get_menu_height(!gui.starting); |
| 1885 | #endif |
| 1886 | } |
| 1887 | |
| 1888 | |
| 1889 | void |
| 1890 | gui_mch_set_scrollbar_thumb( |
| 1891 | scrollbar_T *sb, |
| 1892 | long val, |
| 1893 | long size, |
| 1894 | long max) |
| 1895 | { |
| 1896 | SCROLLINFO info; |
| 1897 | |
| 1898 | sb->scroll_shift = 0; |
| 1899 | while (max > 32767) |
| 1900 | { |
| 1901 | max = (max + 1) >> 1; |
| 1902 | val >>= 1; |
| 1903 | size >>= 1; |
| 1904 | ++sb->scroll_shift; |
| 1905 | } |
| 1906 | |
| 1907 | if (sb->scroll_shift > 0) |
| 1908 | ++size; |
| 1909 | |
| 1910 | info.cbSize = sizeof(info); |
| 1911 | info.fMask = SIF_POS | SIF_RANGE | SIF_PAGE; |
| 1912 | info.nPos = val; |
| 1913 | info.nMin = 0; |
| 1914 | info.nMax = max; |
| 1915 | info.nPage = size; |
| 1916 | SetScrollInfo(sb->id, SB_CTL, &info, TRUE); |
| 1917 | } |
| 1918 | |
| 1919 | |
| 1920 | /* |
| 1921 | * Set the current text font. |
| 1922 | */ |
| 1923 | void |
| 1924 | gui_mch_set_font(GuiFont font) |
| 1925 | { |
| 1926 | gui.currFont = font; |
| 1927 | } |
| 1928 | |
| 1929 | |
| 1930 | /* |
| 1931 | * Set the current text foreground color. |
| 1932 | */ |
| 1933 | void |
| 1934 | gui_mch_set_fg_color(guicolor_T color) |
| 1935 | { |
| 1936 | gui.currFgColor = color; |
| 1937 | } |
| 1938 | |
| 1939 | /* |
| 1940 | * Set the current text background color. |
| 1941 | */ |
| 1942 | void |
| 1943 | gui_mch_set_bg_color(guicolor_T color) |
| 1944 | { |
| 1945 | gui.currBgColor = color; |
| 1946 | } |
| 1947 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 1948 | /* |
| 1949 | * Set the current text special color. |
| 1950 | */ |
| 1951 | void |
| 1952 | gui_mch_set_sp_color(guicolor_T color) |
| 1953 | { |
| 1954 | gui.currSpColor = color; |
| 1955 | } |
| 1956 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1957 | #if defined(FEAT_MBYTE) && defined(FEAT_MBYTE_IME) |
| 1958 | /* |
| 1959 | * Multi-byte handling, originally by Sung-Hoon Baek. |
| 1960 | * First static functions (no prototypes generated). |
| 1961 | */ |
| 1962 | #ifdef _MSC_VER |
| 1963 | # include <ime.h> /* Apparently not needed for Cygwin, MingW or Borland. */ |
| 1964 | #endif |
| 1965 | #include <imm.h> |
| 1966 | |
| 1967 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1968 | * handle WM_IME_NOTIFY message |
| 1969 | */ |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 1970 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1971 | static LRESULT |
| 1972 | _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData) |
| 1973 | { |
| 1974 | LRESULT lResult = 0; |
| 1975 | HIMC hImc; |
| 1976 | |
| 1977 | if (!pImmGetContext || (hImc = pImmGetContext(hWnd)) == (HIMC)0) |
| 1978 | return lResult; |
| 1979 | switch (dwCommand) |
| 1980 | { |
| 1981 | case IMN_SETOPENSTATUS: |
| 1982 | if (pImmGetOpenStatus(hImc)) |
| 1983 | { |
| 1984 | pImmSetCompositionFont(hImc, &norm_logfont); |
| 1985 | im_set_position(gui.row, gui.col); |
| 1986 | |
| 1987 | /* Disable langmap */ |
| 1988 | State &= ~LANGMAP; |
| 1989 | if (State & INSERT) |
| 1990 | { |
| 1991 | #if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP) |
| 1992 | /* Unshown 'keymap' in status lines */ |
| 1993 | if (curbuf->b_p_iminsert == B_IMODE_LMAP) |
| 1994 | { |
| 1995 | /* Save cursor position */ |
| 1996 | int old_row = gui.row; |
| 1997 | int old_col = gui.col; |
| 1998 | |
| 1999 | // This must be called here before |
| 2000 | // status_redraw_curbuf(), otherwise the mode |
| 2001 | // message may appear in the wrong position. |
| 2002 | showmode(); |
| 2003 | status_redraw_curbuf(); |
| 2004 | update_screen(0); |
| 2005 | /* Restore cursor position */ |
| 2006 | gui.row = old_row; |
| 2007 | gui.col = old_col; |
| 2008 | } |
| 2009 | #endif |
| 2010 | } |
| 2011 | } |
| 2012 | gui_update_cursor(TRUE, FALSE); |
| 2013 | lResult = 0; |
| 2014 | break; |
| 2015 | } |
| 2016 | pImmReleaseContext(hWnd, hImc); |
| 2017 | return lResult; |
| 2018 | } |
| 2019 | |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 2020 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2021 | static LRESULT |
| 2022 | _OnImeComposition(HWND hwnd, WPARAM dbcs, LPARAM param) |
| 2023 | { |
| 2024 | char_u *ret; |
| 2025 | int len; |
| 2026 | |
| 2027 | if ((param & GCS_RESULTSTR) == 0) /* Composition unfinished. */ |
| 2028 | return 0; |
| 2029 | |
| 2030 | ret = GetResultStr(hwnd, GCS_RESULTSTR, &len); |
| 2031 | if (ret != NULL) |
| 2032 | { |
| 2033 | add_to_input_buf_csi(ret, len); |
| 2034 | vim_free(ret); |
| 2035 | return 1; |
| 2036 | } |
| 2037 | return 0; |
| 2038 | } |
| 2039 | |
| 2040 | /* |
| 2041 | * get the current composition string, in UCS-2; *lenp is the number of |
| 2042 | * *lenp is the number of Unicode characters. |
| 2043 | */ |
| 2044 | static short_u * |
| 2045 | GetCompositionString_inUCS2(HIMC hIMC, DWORD GCS, int *lenp) |
| 2046 | { |
| 2047 | LONG ret; |
| 2048 | LPWSTR wbuf = NULL; |
| 2049 | char_u *buf; |
| 2050 | |
| 2051 | if (!pImmGetContext) |
| 2052 | return NULL; /* no imm32.dll */ |
| 2053 | |
| 2054 | /* Try Unicode; this'll always work on NT regardless of codepage. */ |
| 2055 | ret = pImmGetCompositionStringW(hIMC, GCS, NULL, 0); |
| 2056 | if (ret == 0) |
| 2057 | return NULL; /* empty */ |
| 2058 | |
| 2059 | if (ret > 0) |
| 2060 | { |
| 2061 | /* Allocate the requested buffer plus space for the NUL character. */ |
| 2062 | wbuf = (LPWSTR)alloc(ret + sizeof(WCHAR)); |
| 2063 | if (wbuf != NULL) |
| 2064 | { |
| 2065 | pImmGetCompositionStringW(hIMC, GCS, wbuf, ret); |
| 2066 | *lenp = ret / sizeof(WCHAR); |
| 2067 | } |
| 2068 | return (short_u *)wbuf; |
| 2069 | } |
| 2070 | |
| 2071 | /* ret < 0; we got an error, so try the ANSI version. This'll work |
| 2072 | * on 9x/ME, but only if the codepage happens to be set to whatever |
| 2073 | * we're inputting. */ |
| 2074 | ret = pImmGetCompositionStringA(hIMC, GCS, NULL, 0); |
| 2075 | if (ret <= 0) |
| 2076 | return NULL; /* empty or error */ |
| 2077 | |
| 2078 | buf = alloc(ret); |
| 2079 | if (buf == NULL) |
| 2080 | return NULL; |
| 2081 | pImmGetCompositionStringA(hIMC, GCS, buf, ret); |
| 2082 | |
| 2083 | /* convert from codepage to UCS-2 */ |
| 2084 | MultiByteToWideChar_alloc(GetACP(), 0, buf, ret, &wbuf, lenp); |
| 2085 | vim_free(buf); |
| 2086 | |
| 2087 | return (short_u *)wbuf; |
| 2088 | } |
| 2089 | |
| 2090 | /* |
| 2091 | * void GetResultStr() |
| 2092 | * |
| 2093 | * This handles WM_IME_COMPOSITION with GCS_RESULTSTR flag on. |
| 2094 | * get complete composition string |
| 2095 | */ |
| 2096 | static char_u * |
| 2097 | GetResultStr(HWND hwnd, int GCS, int *lenp) |
| 2098 | { |
| 2099 | HIMC hIMC; /* Input context handle. */ |
| 2100 | short_u *buf = NULL; |
| 2101 | char_u *convbuf = NULL; |
| 2102 | |
| 2103 | if (!pImmGetContext || (hIMC = pImmGetContext(hwnd)) == (HIMC)0) |
| 2104 | return NULL; |
| 2105 | |
| 2106 | /* Reads in the composition string. */ |
| 2107 | buf = GetCompositionString_inUCS2(hIMC, GCS, lenp); |
| 2108 | if (buf == NULL) |
| 2109 | return NULL; |
| 2110 | |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 2111 | convbuf = utf16_to_enc(buf, lenp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2112 | pImmReleaseContext(hwnd, hIMC); |
| 2113 | vim_free(buf); |
| 2114 | return convbuf; |
| 2115 | } |
| 2116 | #endif |
| 2117 | |
| 2118 | /* For global functions we need prototypes. */ |
| 2119 | #if (defined(FEAT_MBYTE) && defined(FEAT_MBYTE_IME)) || defined(PROTO) |
| 2120 | |
| 2121 | /* |
| 2122 | * set font to IM. |
| 2123 | */ |
| 2124 | void |
| 2125 | im_set_font(LOGFONT *lf) |
| 2126 | { |
| 2127 | HIMC hImc; |
| 2128 | |
| 2129 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 2130 | { |
| 2131 | pImmSetCompositionFont(hImc, lf); |
| 2132 | pImmReleaseContext(s_hwnd, hImc); |
| 2133 | } |
| 2134 | } |
| 2135 | |
| 2136 | /* |
| 2137 | * Notify cursor position to IM. |
| 2138 | */ |
| 2139 | void |
| 2140 | im_set_position(int row, int col) |
| 2141 | { |
| 2142 | HIMC hImc; |
| 2143 | |
| 2144 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 2145 | { |
| 2146 | COMPOSITIONFORM cfs; |
| 2147 | |
| 2148 | cfs.dwStyle = CFS_POINT; |
| 2149 | cfs.ptCurrentPos.x = FILL_X(col); |
| 2150 | cfs.ptCurrentPos.y = FILL_Y(row); |
| 2151 | MapWindowPoints(s_textArea, s_hwnd, &cfs.ptCurrentPos, 1); |
| 2152 | pImmSetCompositionWindow(hImc, &cfs); |
| 2153 | |
| 2154 | pImmReleaseContext(s_hwnd, hImc); |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | /* |
| 2159 | * Set IM status on ("active" is TRUE) or off ("active" is FALSE). |
| 2160 | */ |
| 2161 | void |
| 2162 | im_set_active(int active) |
| 2163 | { |
| 2164 | HIMC hImc; |
| 2165 | static HIMC hImcOld = (HIMC)0; |
| 2166 | |
| 2167 | if (pImmGetContext) /* if NULL imm32.dll wasn't loaded (yet) */ |
| 2168 | { |
| 2169 | if (p_imdisable) |
| 2170 | { |
| 2171 | if (hImcOld == (HIMC)0) |
| 2172 | { |
| 2173 | hImcOld = pImmGetContext(s_hwnd); |
| 2174 | if (hImcOld) |
| 2175 | pImmAssociateContext(s_hwnd, (HIMC)0); |
| 2176 | } |
| 2177 | active = FALSE; |
| 2178 | } |
| 2179 | else if (hImcOld != (HIMC)0) |
| 2180 | { |
| 2181 | pImmAssociateContext(s_hwnd, hImcOld); |
| 2182 | hImcOld = (HIMC)0; |
| 2183 | } |
| 2184 | |
| 2185 | hImc = pImmGetContext(s_hwnd); |
| 2186 | if (hImc) |
| 2187 | { |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2188 | /* |
| 2189 | * for Korean ime |
| 2190 | */ |
| 2191 | HKL hKL = GetKeyboardLayout(0); |
| 2192 | |
| 2193 | if (LOWORD(hKL) == MAKELANGID(LANG_KOREAN, SUBLANG_KOREAN)) |
| 2194 | { |
| 2195 | static DWORD dwConversionSaved = 0, dwSentenceSaved = 0; |
| 2196 | static BOOL bSaved = FALSE; |
| 2197 | |
| 2198 | if (active) |
| 2199 | { |
| 2200 | /* if we have a saved conversion status, restore it */ |
| 2201 | if (bSaved) |
| 2202 | pImmSetConversionStatus(hImc, dwConversionSaved, |
| 2203 | dwSentenceSaved); |
| 2204 | bSaved = FALSE; |
| 2205 | } |
| 2206 | else |
| 2207 | { |
| 2208 | /* save conversion status and disable korean */ |
| 2209 | if (pImmGetConversionStatus(hImc, &dwConversionSaved, |
| 2210 | &dwSentenceSaved)) |
| 2211 | { |
| 2212 | bSaved = TRUE; |
| 2213 | pImmSetConversionStatus(hImc, |
| 2214 | dwConversionSaved & ~(IME_CMODE_NATIVE |
| 2215 | | IME_CMODE_FULLSHAPE), |
| 2216 | dwSentenceSaved); |
| 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2221 | pImmSetOpenStatus(hImc, active); |
| 2222 | pImmReleaseContext(s_hwnd, hImc); |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | /* |
| 2228 | * Get IM status. When IM is on, return not 0. Else return 0. |
| 2229 | */ |
| 2230 | int |
| 2231 | im_get_status() |
| 2232 | { |
| 2233 | int status = 0; |
| 2234 | HIMC hImc; |
| 2235 | |
| 2236 | if (pImmGetContext && (hImc = pImmGetContext(s_hwnd)) != (HIMC)0) |
| 2237 | { |
| 2238 | status = pImmGetOpenStatus(hImc) ? 1 : 0; |
| 2239 | pImmReleaseContext(s_hwnd, hImc); |
| 2240 | } |
| 2241 | return status; |
| 2242 | } |
| 2243 | |
| 2244 | #endif /* FEAT_MBYTE && FEAT_MBYTE_IME */ |
| 2245 | |
| 2246 | #if defined(FEAT_MBYTE) && !defined(FEAT_MBYTE_IME) && defined(GLOBAL_IME) |
| 2247 | /* Win32 with GLOBAL IME */ |
| 2248 | |
| 2249 | /* |
| 2250 | * Notify cursor position to IM. |
| 2251 | */ |
| 2252 | void |
| 2253 | im_set_position(int row, int col) |
| 2254 | { |
| 2255 | /* Win32 with GLOBAL IME */ |
| 2256 | POINT p; |
| 2257 | |
| 2258 | p.x = FILL_X(col); |
| 2259 | p.y = FILL_Y(row); |
| 2260 | MapWindowPoints(s_textArea, s_hwnd, &p, 1); |
| 2261 | global_ime_set_position(&p); |
| 2262 | } |
| 2263 | |
| 2264 | /* |
| 2265 | * Set IM status on ("active" is TRUE) or off ("active" is FALSE). |
| 2266 | */ |
| 2267 | void |
| 2268 | im_set_active(int active) |
| 2269 | { |
| 2270 | global_ime_set_status(active); |
| 2271 | } |
| 2272 | |
| 2273 | /* |
| 2274 | * Get IM status. When IM is on, return not 0. Else return 0. |
| 2275 | */ |
| 2276 | int |
| 2277 | im_get_status() |
| 2278 | { |
| 2279 | return global_ime_get_status(); |
| 2280 | } |
| 2281 | #endif |
| 2282 | |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 2283 | #ifdef FEAT_MBYTE |
| 2284 | /* |
Bram Moolenaar | 39f0563 | 2006-03-19 22:15:26 +0000 | [diff] [blame] | 2285 | * Convert latin9 text "text[len]" to ucs-2 in "unicodebuf". |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 2286 | */ |
| 2287 | static void |
| 2288 | latin9_to_ucs(char_u *text, int len, WCHAR *unicodebuf) |
| 2289 | { |
| 2290 | int c; |
| 2291 | |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2292 | while (--len >= 0) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 2293 | { |
| 2294 | c = *text++; |
| 2295 | switch (c) |
| 2296 | { |
| 2297 | case 0xa4: c = 0x20ac; break; /* euro */ |
| 2298 | case 0xa6: c = 0x0160; break; /* S hat */ |
| 2299 | case 0xa8: c = 0x0161; break; /* S -hat */ |
| 2300 | case 0xb4: c = 0x017d; break; /* Z hat */ |
| 2301 | case 0xb8: c = 0x017e; break; /* Z -hat */ |
| 2302 | case 0xbc: c = 0x0152; break; /* OE */ |
| 2303 | case 0xbd: c = 0x0153; break; /* oe */ |
| 2304 | case 0xbe: c = 0x0178; break; /* Y */ |
| 2305 | } |
| 2306 | *unicodebuf++ = c; |
| 2307 | } |
| 2308 | } |
| 2309 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2310 | |
| 2311 | #ifdef FEAT_RIGHTLEFT |
| 2312 | /* |
| 2313 | * What is this for? In the case where you are using Win98 or Win2K or later, |
| 2314 | * and you are using a Hebrew font (or Arabic!), Windows does you a favor and |
| 2315 | * reverses the string sent to the TextOut... family. This sucks, because we |
| 2316 | * go to a lot of effort to do the right thing, and there doesn't seem to be a |
| 2317 | * way to tell Windblows not to do this! |
| 2318 | * |
| 2319 | * The short of it is that this 'RevOut' only gets called if you are running |
| 2320 | * one of the new, "improved" MS OSes, and only if you are running in |
| 2321 | * 'rightleft' mode. It makes display take *slightly* longer, but not |
| 2322 | * noticeably so. |
| 2323 | */ |
| 2324 | static void |
| 2325 | RevOut( HDC s_hdc, |
| 2326 | int col, |
| 2327 | int row, |
| 2328 | UINT foptions, |
| 2329 | CONST RECT *pcliprect, |
| 2330 | LPCTSTR text, |
| 2331 | UINT len, |
| 2332 | CONST INT *padding) |
| 2333 | { |
| 2334 | int ix; |
| 2335 | static int special = -1; |
| 2336 | |
| 2337 | if (special == -1) |
| 2338 | { |
| 2339 | /* Check windows version: special treatment is needed if it is NT 5 or |
| 2340 | * Win98 or higher. */ |
| 2341 | if ((os_version.dwPlatformId == VER_PLATFORM_WIN32_NT |
| 2342 | && os_version.dwMajorVersion >= 5) |
| 2343 | || (os_version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS |
| 2344 | && (os_version.dwMajorVersion > 4 |
| 2345 | || (os_version.dwMajorVersion == 4 |
| 2346 | && os_version.dwMinorVersion > 0)))) |
| 2347 | special = 1; |
| 2348 | else |
| 2349 | special = 0; |
| 2350 | } |
| 2351 | |
| 2352 | if (special) |
| 2353 | for (ix = 0; ix < (int)len; ++ix) |
| 2354 | ExtTextOut(s_hdc, col + TEXT_X(ix), row, foptions, |
| 2355 | pcliprect, text + ix, 1, padding); |
| 2356 | else |
| 2357 | ExtTextOut(s_hdc, col, row, foptions, pcliprect, text, len, padding); |
| 2358 | } |
| 2359 | #endif |
| 2360 | |
| 2361 | void |
| 2362 | gui_mch_draw_string( |
| 2363 | int row, |
| 2364 | int col, |
| 2365 | char_u *text, |
| 2366 | int len, |
| 2367 | int flags) |
| 2368 | { |
| 2369 | static int *padding = NULL; |
| 2370 | static int pad_size = 0; |
| 2371 | int i; |
| 2372 | const RECT *pcliprect = NULL; |
| 2373 | UINT foptions = 0; |
| 2374 | #ifdef FEAT_MBYTE |
| 2375 | static WCHAR *unicodebuf = NULL; |
| 2376 | static int *unicodepdy = NULL; |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 2377 | static int unibuflen = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2378 | int n = 0; |
| 2379 | #endif |
| 2380 | HPEN hpen, old_pen; |
| 2381 | int y; |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2382 | #ifdef FEAT_DIRECTX |
| 2383 | int font_is_ttf_or_vector = 0; |
| 2384 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2385 | |
| 2386 | #ifndef MSWIN16_FASTTEXT |
| 2387 | /* |
| 2388 | * Italic and bold text seems to have an extra row of pixels at the bottom |
| 2389 | * (below where the bottom of the character should be). If we draw the |
| 2390 | * characters with a solid background, the top row of pixels in the |
| 2391 | * character below will be overwritten. We can fix this by filling in the |
| 2392 | * background ourselves, to the correct character proportions, and then |
| 2393 | * writing the character in transparent mode. Still have a problem when |
| 2394 | * the character is "_", which gets written on to the character below. |
| 2395 | * New fix: set gui.char_ascent to -1. This shifts all characters up one |
| 2396 | * pixel in their slots, which fixes the problem with the bottom row of |
| 2397 | * pixels. We still need this code because otherwise the top row of pixels |
| 2398 | * becomes a problem. - webb. |
| 2399 | */ |
| 2400 | static HBRUSH hbr_cache[2] = {NULL, NULL}; |
| 2401 | static guicolor_T brush_color[2] = {INVALCOLOR, INVALCOLOR}; |
| 2402 | static int brush_lru = 0; |
| 2403 | HBRUSH hbr; |
| 2404 | RECT rc; |
| 2405 | |
| 2406 | if (!(flags & DRAW_TRANSP)) |
| 2407 | { |
| 2408 | /* |
| 2409 | * Clear background first. |
| 2410 | * Note: FillRect() excludes right and bottom of rectangle. |
| 2411 | */ |
| 2412 | rc.left = FILL_X(col); |
| 2413 | rc.top = FILL_Y(row); |
| 2414 | #ifdef FEAT_MBYTE |
| 2415 | if (has_mbyte) |
| 2416 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2417 | /* Compute the length in display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 2418 | rc.right = FILL_X(col + mb_string2cells(text, len)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2419 | } |
| 2420 | else |
| 2421 | #endif |
| 2422 | rc.right = FILL_X(col + len); |
| 2423 | rc.bottom = FILL_Y(row + 1); |
| 2424 | |
| 2425 | /* Cache the created brush, that saves a lot of time. We need two: |
| 2426 | * one for cursor background and one for the normal background. */ |
| 2427 | if (gui.currBgColor == brush_color[0]) |
| 2428 | { |
| 2429 | hbr = hbr_cache[0]; |
| 2430 | brush_lru = 1; |
| 2431 | } |
| 2432 | else if (gui.currBgColor == brush_color[1]) |
| 2433 | { |
| 2434 | hbr = hbr_cache[1]; |
| 2435 | brush_lru = 0; |
| 2436 | } |
| 2437 | else |
| 2438 | { |
| 2439 | if (hbr_cache[brush_lru] != NULL) |
| 2440 | DeleteBrush(hbr_cache[brush_lru]); |
| 2441 | hbr_cache[brush_lru] = CreateSolidBrush(gui.currBgColor); |
| 2442 | brush_color[brush_lru] = gui.currBgColor; |
| 2443 | hbr = hbr_cache[brush_lru]; |
| 2444 | brush_lru = !brush_lru; |
| 2445 | } |
| 2446 | FillRect(s_hdc, &rc, hbr); |
| 2447 | |
| 2448 | SetBkMode(s_hdc, TRANSPARENT); |
| 2449 | |
| 2450 | /* |
| 2451 | * When drawing block cursor, prevent inverted character spilling |
| 2452 | * over character cell (can happen with bold/italic) |
| 2453 | */ |
| 2454 | if (flags & DRAW_CURSOR) |
| 2455 | { |
| 2456 | pcliprect = &rc; |
| 2457 | foptions = ETO_CLIPPED; |
| 2458 | } |
| 2459 | } |
| 2460 | #else |
| 2461 | /* |
| 2462 | * The alternative would be to write the characters in opaque mode, but |
| 2463 | * when the text is not exactly the same proportions as normal text, too |
| 2464 | * big or too little a rectangle gets drawn for the background. |
| 2465 | */ |
| 2466 | SetBkMode(s_hdc, OPAQUE); |
| 2467 | SetBkColor(s_hdc, gui.currBgColor); |
| 2468 | #endif |
| 2469 | SetTextColor(s_hdc, gui.currFgColor); |
| 2470 | SelectFont(s_hdc, gui.currFont); |
| 2471 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2472 | #ifdef FEAT_DIRECTX |
| 2473 | if (IS_ENABLE_DIRECTX()) |
| 2474 | { |
| 2475 | TEXTMETRIC tm; |
| 2476 | |
| 2477 | GetTextMetrics(s_hdc, &tm); |
| 2478 | if (tm.tmPitchAndFamily & (TMPF_TRUETYPE | TMPF_VECTOR)) |
| 2479 | { |
| 2480 | font_is_ttf_or_vector = 1; |
| 2481 | DWriteContext_SetFont(s_dwc, (HFONT)gui.currFont); |
| 2482 | } |
| 2483 | } |
| 2484 | #endif |
| 2485 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2486 | if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width) |
| 2487 | { |
| 2488 | vim_free(padding); |
| 2489 | pad_size = Columns; |
| 2490 | |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 2491 | /* Don't give an out-of-memory message here, it would call us |
| 2492 | * recursively. */ |
| 2493 | padding = (int *)lalloc(pad_size * sizeof(int), FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2494 | if (padding != NULL) |
| 2495 | for (i = 0; i < pad_size; i++) |
| 2496 | padding[i] = gui.char_width; |
| 2497 | } |
| 2498 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2499 | /* |
| 2500 | * We have to provide the padding argument because italic and bold versions |
| 2501 | * of fixed-width fonts are often one pixel or so wider than their normal |
| 2502 | * versions. |
| 2503 | * No check for DRAW_BOLD, Windows will have done it already. |
| 2504 | */ |
| 2505 | |
| 2506 | #ifdef FEAT_MBYTE |
| 2507 | /* Check if there are any UTF-8 characters. If not, use normal text |
| 2508 | * output to speed up output. */ |
| 2509 | if (enc_utf8) |
| 2510 | for (n = 0; n < len; ++n) |
| 2511 | if (text[n] >= 0x80) |
| 2512 | break; |
| 2513 | |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2514 | #if defined(FEAT_DIRECTX) |
| 2515 | /* Quick hack to enable DirectWrite. To use DirectWrite (antialias), it is |
| 2516 | * required that unicode drawing routine, currently. So this forces it |
| 2517 | * enabled. */ |
| 2518 | if (enc_utf8 && IS_ENABLE_DIRECTX()) |
| 2519 | n = 0; /* Keep n < len, to enter block for unicode. */ |
| 2520 | #endif |
| 2521 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2522 | /* Check if the Unicode buffer exists and is big enough. Create it |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 2523 | * 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] | 2524 | * characters is always equal or smaller. */ |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 2525 | if ((enc_utf8 |
| 2526 | || (enc_codepage > 0 && (int)GetACP() != enc_codepage) |
| 2527 | || enc_latin9) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2528 | && (unicodebuf == NULL || len > unibuflen)) |
| 2529 | { |
| 2530 | vim_free(unicodebuf); |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 2531 | unicodebuf = (WCHAR *)lalloc(len * sizeof(WCHAR), FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2532 | |
| 2533 | vim_free(unicodepdy); |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 2534 | unicodepdy = (int *)lalloc(len * sizeof(int), FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2535 | |
| 2536 | unibuflen = len; |
| 2537 | } |
| 2538 | |
| 2539 | if (enc_utf8 && n < len && unicodebuf != NULL) |
| 2540 | { |
| 2541 | /* Output UTF-8 characters. Caller has already separated |
| 2542 | * composing characters. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2543 | int i; |
| 2544 | int wlen; /* string length in words */ |
| 2545 | int clen; /* string length in characters */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2546 | int cells; /* cell width of string up to composing char */ |
| 2547 | int cw; /* width of current cell */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2548 | int c; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2549 | |
Bram Moolenaar | 97b2ad3 | 2006-03-18 21:40:56 +0000 | [diff] [blame] | 2550 | wlen = 0; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2551 | clen = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2552 | cells = 0; |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2553 | for (i = 0; i < len; ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2554 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2555 | c = utf_ptr2char(text + i); |
| 2556 | if (c >= 0x10000) |
| 2557 | { |
| 2558 | /* Turn into UTF-16 encoding. */ |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2559 | unicodebuf[wlen++] = ((c - 0x10000) >> 10) + 0xD800; |
| 2560 | unicodebuf[wlen++] = ((c - 0x10000) & 0x3ff) + 0xDC00; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2561 | } |
| 2562 | else |
| 2563 | { |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2564 | unicodebuf[wlen++] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2565 | } |
| 2566 | cw = utf_char2cells(c); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2567 | if (cw > 2) /* don't use 4 for unprintable char */ |
| 2568 | cw = 1; |
| 2569 | if (unicodepdy != NULL) |
| 2570 | { |
| 2571 | /* Use unicodepdy to make characters fit as we expect, even |
| 2572 | * when the font uses different widths (e.g., bold character |
| 2573 | * is wider). */ |
| 2574 | unicodepdy[clen] = cw * gui.char_width; |
| 2575 | } |
| 2576 | cells += cw; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2577 | i += utfc_ptr2len_len(text + i, len - i); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 2578 | ++clen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2579 | } |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2580 | #if defined(FEAT_DIRECTX) |
| 2581 | if (IS_ENABLE_DIRECTX() && font_is_ttf_or_vector) |
| 2582 | { |
Bram Moolenaar | 9b352c4 | 2014-08-06 16:49:55 +0200 | [diff] [blame] | 2583 | /* Add one to "cells" for italics. */ |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2584 | DWriteContext_DrawText(s_dwc, s_hdc, unicodebuf, wlen, |
Bram Moolenaar | 9b352c4 | 2014-08-06 16:49:55 +0200 | [diff] [blame] | 2585 | TEXT_X(col), TEXT_Y(row), FILL_X(cells + 1), FILL_Y(1), |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2586 | gui.char_width, gui.currFgColor); |
| 2587 | } |
| 2588 | else |
| 2589 | #endif |
| 2590 | ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 2591 | foptions, pcliprect, unicodebuf, wlen, unicodepdy); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2592 | len = cells; /* used for underlining */ |
| 2593 | } |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 2594 | else if ((enc_codepage > 0 && (int)GetACP() != enc_codepage) || enc_latin9) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2595 | { |
| 2596 | /* If we want to display codepage data, and the current CP is not the |
| 2597 | * ANSI one, we need to go via Unicode. */ |
| 2598 | if (unicodebuf != NULL) |
| 2599 | { |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 2600 | if (enc_latin9) |
| 2601 | latin9_to_ucs(text, len, unicodebuf); |
| 2602 | else |
| 2603 | len = MultiByteToWideChar(enc_codepage, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2604 | MB_PRECOMPOSED, |
| 2605 | (char *)text, len, |
| 2606 | (LPWSTR)unicodebuf, unibuflen); |
| 2607 | if (len != 0) |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2608 | { |
| 2609 | /* Use unicodepdy to make characters fit as we expect, even |
| 2610 | * when the font uses different widths (e.g., bold character |
| 2611 | * is wider). */ |
| 2612 | if (unicodepdy != NULL) |
| 2613 | { |
| 2614 | int i; |
| 2615 | int cw; |
| 2616 | |
| 2617 | for (i = 0; i < len; ++i) |
| 2618 | { |
| 2619 | cw = utf_char2cells(unicodebuf[i]); |
| 2620 | if (cw > 2) |
| 2621 | cw = 1; |
| 2622 | unicodepdy[i] = cw * gui.char_width; |
| 2623 | } |
| 2624 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2625 | ExtTextOutW(s_hdc, TEXT_X(col), TEXT_Y(row), |
Bram Moolenaar | 19a09a1 | 2005-03-04 23:39:37 +0000 | [diff] [blame] | 2626 | foptions, pcliprect, unicodebuf, len, unicodepdy); |
| 2627 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2628 | } |
| 2629 | } |
| 2630 | else |
| 2631 | #endif |
| 2632 | { |
| 2633 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4ee40b0 | 2014-09-19 16:13:53 +0200 | [diff] [blame] | 2634 | /* Windows will mess up RL text, so we have to draw it character by |
| 2635 | * character. Only do this if RL is on, since it's slow. */ |
| 2636 | if (curwin->w_p_rl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2637 | RevOut(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 2638 | foptions, pcliprect, (char *)text, len, padding); |
| 2639 | else |
| 2640 | #endif |
| 2641 | ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), |
| 2642 | foptions, pcliprect, (char *)text, len, padding); |
| 2643 | } |
| 2644 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 2645 | /* Underline */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2646 | if (flags & DRAW_UNDERL) |
| 2647 | { |
| 2648 | hpen = CreatePen(PS_SOLID, 1, gui.currFgColor); |
| 2649 | old_pen = SelectObject(s_hdc, hpen); |
| 2650 | /* When p_linespace is 0, overwrite the bottom row of pixels. |
| 2651 | * Otherwise put the line just below the character. */ |
| 2652 | y = FILL_Y(row + 1) - 1; |
| 2653 | #ifndef MSWIN16_FASTTEXT |
| 2654 | if (p_linespace > 1) |
| 2655 | y -= p_linespace - 1; |
| 2656 | #endif |
| 2657 | MoveToEx(s_hdc, FILL_X(col), y, NULL); |
| 2658 | /* Note: LineTo() excludes the last pixel in the line. */ |
| 2659 | LineTo(s_hdc, FILL_X(col + len), y); |
| 2660 | DeleteObject(SelectObject(s_hdc, old_pen)); |
| 2661 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 2662 | |
| 2663 | /* Undercurl */ |
| 2664 | if (flags & DRAW_UNDERC) |
| 2665 | { |
| 2666 | int x; |
| 2667 | int offset; |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 2668 | 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] | 2669 | |
| 2670 | y = FILL_Y(row + 1) - 1; |
| 2671 | for (x = FILL_X(col); x < FILL_X(col + len); ++x) |
| 2672 | { |
| 2673 | offset = val[x % 8]; |
| 2674 | SetPixel(s_hdc, x, y - offset, gui.currSpColor); |
| 2675 | } |
| 2676 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2677 | } |
| 2678 | |
| 2679 | |
| 2680 | /* |
| 2681 | * Output routines. |
| 2682 | */ |
| 2683 | |
| 2684 | /* Flush any output to the screen */ |
| 2685 | void |
| 2686 | gui_mch_flush(void) |
| 2687 | { |
| 2688 | # if defined(__BORLANDC__) |
| 2689 | /* |
| 2690 | * The GdiFlush declaration (in Borland C 5.01 <wingdi.h>) is not a |
| 2691 | * prototype declaration. |
| 2692 | * The compiler complains if __stdcall is not used in both declarations. |
| 2693 | */ |
| 2694 | BOOL __stdcall GdiFlush(void); |
| 2695 | # endif |
| 2696 | |
| 2697 | GdiFlush(); |
| 2698 | } |
| 2699 | |
| 2700 | static void |
| 2701 | clear_rect(RECT *rcp) |
| 2702 | { |
| 2703 | HBRUSH hbr; |
| 2704 | |
| 2705 | hbr = CreateSolidBrush(gui.back_pixel); |
| 2706 | FillRect(s_hdc, rcp, hbr); |
| 2707 | DeleteBrush(hbr); |
| 2708 | } |
| 2709 | |
| 2710 | |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 2711 | void |
| 2712 | gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) |
| 2713 | { |
| 2714 | RECT workarea_rect; |
| 2715 | |
| 2716 | get_work_area(&workarea_rect); |
| 2717 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 2718 | *screen_w = workarea_rect.right - workarea_rect.left |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 2719 | - (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2720 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 2721 | |
| 2722 | /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include |
| 2723 | * the menubar for MSwin, we subtract it from the screen height, so that |
| 2724 | * the window size can be made to fit on the screen. */ |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 2725 | *screen_h = workarea_rect.bottom - workarea_rect.top |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 2726 | - (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 2727 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2 |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 2728 | - GetSystemMetrics(SM_CYCAPTION) |
| 2729 | #ifdef FEAT_MENU |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 2730 | - gui_mswin_get_menu_height(FALSE) |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 2731 | #endif |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 2732 | ; |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2736 | #if defined(FEAT_MENU) || defined(PROTO) |
| 2737 | /* |
| 2738 | * Add a sub menu to the menu bar. |
| 2739 | */ |
| 2740 | void |
| 2741 | gui_mch_add_menu( |
| 2742 | vimmenu_T *menu, |
| 2743 | int pos) |
| 2744 | { |
| 2745 | vimmenu_T *parent = menu->parent; |
| 2746 | |
| 2747 | menu->submenu_id = CreatePopupMenu(); |
| 2748 | menu->id = s_menu_id++; |
| 2749 | |
| 2750 | if (menu_is_menubar(menu->name)) |
| 2751 | { |
| 2752 | if (is_winnt_3()) |
| 2753 | { |
| 2754 | InsertMenu((parent == NULL) ? s_menuBar : parent->submenu_id, |
| 2755 | (UINT)pos, MF_POPUP | MF_STRING | MF_BYPOSITION, |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 2756 | (long_u)menu->submenu_id, (LPCTSTR) menu->name); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2757 | } |
| 2758 | else |
| 2759 | { |
| 2760 | #ifdef FEAT_MBYTE |
| 2761 | WCHAR *wn = NULL; |
| 2762 | int n; |
| 2763 | |
| 2764 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 2765 | { |
| 2766 | /* 'encoding' differs from active codepage: convert menu name |
| 2767 | * and use wide function */ |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 2768 | wn = enc_to_utf16(menu->name, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2769 | if (wn != NULL) |
| 2770 | { |
| 2771 | MENUITEMINFOW infow; |
| 2772 | |
| 2773 | infow.cbSize = sizeof(infow); |
| 2774 | infow.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID |
| 2775 | | MIIM_SUBMENU; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 2776 | infow.dwItemData = (long_u)menu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2777 | infow.wID = menu->id; |
| 2778 | infow.fType = MFT_STRING; |
| 2779 | infow.dwTypeData = wn; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 2780 | infow.cch = (UINT)wcslen(wn); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2781 | infow.hSubMenu = menu->submenu_id; |
| 2782 | n = InsertMenuItemW((parent == NULL) |
| 2783 | ? s_menuBar : parent->submenu_id, |
| 2784 | (UINT)pos, TRUE, &infow); |
| 2785 | vim_free(wn); |
| 2786 | if (n == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) |
| 2787 | /* Failed, try using non-wide function. */ |
| 2788 | wn = NULL; |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | if (wn == NULL) |
| 2793 | #endif |
| 2794 | { |
| 2795 | MENUITEMINFO info; |
| 2796 | |
| 2797 | info.cbSize = sizeof(info); |
| 2798 | info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID | MIIM_SUBMENU; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 2799 | info.dwItemData = (long_u)menu; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2800 | info.wID = menu->id; |
| 2801 | info.fType = MFT_STRING; |
| 2802 | info.dwTypeData = (LPTSTR)menu->name; |
| 2803 | info.cch = (UINT)STRLEN(menu->name); |
| 2804 | info.hSubMenu = menu->submenu_id; |
| 2805 | InsertMenuItem((parent == NULL) |
| 2806 | ? s_menuBar : parent->submenu_id, |
| 2807 | (UINT)pos, TRUE, &info); |
| 2808 | } |
| 2809 | } |
| 2810 | } |
| 2811 | |
| 2812 | /* Fix window size if menu may have wrapped */ |
| 2813 | if (parent == NULL) |
| 2814 | gui_mswin_get_menu_height(!gui.starting); |
| 2815 | #ifdef FEAT_TEAROFF |
| 2816 | else if (IsWindow(parent->tearoff_handle)) |
| 2817 | rebuild_tearoff(parent); |
| 2818 | #endif |
| 2819 | } |
| 2820 | |
| 2821 | void |
| 2822 | gui_mch_show_popupmenu(vimmenu_T *menu) |
| 2823 | { |
| 2824 | POINT mp; |
| 2825 | |
| 2826 | (void)GetCursorPos((LPPOINT)&mp); |
| 2827 | gui_mch_show_popupmenu_at(menu, (int)mp.x, (int)mp.y); |
| 2828 | } |
| 2829 | |
| 2830 | void |
Bram Moolenaar | 045e82d | 2005-07-08 22:25:33 +0000 | [diff] [blame] | 2831 | gui_make_popup(char_u *path_name, int mouse_pos) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2832 | { |
| 2833 | vimmenu_T *menu = gui_find_menu(path_name); |
| 2834 | |
| 2835 | if (menu != NULL) |
| 2836 | { |
| 2837 | POINT p; |
| 2838 | |
| 2839 | /* Find the position of the current cursor */ |
| 2840 | GetDCOrgEx(s_hdc, &p); |
Bram Moolenaar | 045e82d | 2005-07-08 22:25:33 +0000 | [diff] [blame] | 2841 | if (mouse_pos) |
| 2842 | { |
| 2843 | int mx, my; |
| 2844 | |
| 2845 | gui_mch_getmouse(&mx, &my); |
| 2846 | p.x += mx; |
| 2847 | p.y += my; |
| 2848 | } |
| 2849 | else if (curwin != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2850 | { |
| 2851 | p.x += TEXT_X(W_WINCOL(curwin) + curwin->w_wcol + 1); |
| 2852 | p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1); |
| 2853 | } |
| 2854 | msg_scroll = FALSE; |
| 2855 | gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y); |
| 2856 | } |
| 2857 | } |
| 2858 | |
| 2859 | #if defined(FEAT_TEAROFF) || defined(PROTO) |
| 2860 | /* |
| 2861 | * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and |
| 2862 | * create it as a pseudo-"tearoff menu". |
| 2863 | */ |
| 2864 | void |
| 2865 | gui_make_tearoff(char_u *path_name) |
| 2866 | { |
| 2867 | vimmenu_T *menu = gui_find_menu(path_name); |
| 2868 | |
| 2869 | /* Found the menu, so tear it off. */ |
| 2870 | if (menu != NULL) |
| 2871 | gui_mch_tearoff(menu->dname, menu, 0xffffL, 0xffffL); |
| 2872 | } |
| 2873 | #endif |
| 2874 | |
| 2875 | /* |
| 2876 | * Add a menu item to a menu |
| 2877 | */ |
| 2878 | void |
| 2879 | gui_mch_add_menu_item( |
| 2880 | vimmenu_T *menu, |
| 2881 | int idx) |
| 2882 | { |
| 2883 | vimmenu_T *parent = menu->parent; |
| 2884 | |
| 2885 | menu->id = s_menu_id++; |
| 2886 | menu->submenu_id = NULL; |
| 2887 | |
| 2888 | #ifdef FEAT_TEAROFF |
| 2889 | if (STRNCMP(menu->name, TEAR_STRING, TEAR_LEN) == 0) |
| 2890 | { |
| 2891 | InsertMenu(parent->submenu_id, (UINT)idx, MF_BITMAP|MF_BYPOSITION, |
| 2892 | (UINT)menu->id, (LPCTSTR) s_htearbitmap); |
| 2893 | } |
| 2894 | else |
| 2895 | #endif |
| 2896 | #ifdef FEAT_TOOLBAR |
| 2897 | if (menu_is_toolbar(parent->name)) |
| 2898 | { |
| 2899 | TBBUTTON newtb; |
| 2900 | |
| 2901 | vim_memset(&newtb, 0, sizeof(newtb)); |
| 2902 | if (menu_is_separator(menu->name)) |
| 2903 | { |
| 2904 | newtb.iBitmap = 0; |
| 2905 | newtb.fsStyle = TBSTYLE_SEP; |
| 2906 | } |
| 2907 | else |
| 2908 | { |
| 2909 | newtb.iBitmap = get_toolbar_bitmap(menu); |
| 2910 | newtb.fsStyle = TBSTYLE_BUTTON; |
| 2911 | } |
| 2912 | newtb.idCommand = menu->id; |
| 2913 | newtb.fsState = TBSTATE_ENABLED; |
| 2914 | newtb.iString = 0; |
| 2915 | SendMessage(s_toolbarhwnd, TB_INSERTBUTTON, (WPARAM)idx, |
| 2916 | (LPARAM)&newtb); |
| 2917 | menu->submenu_id = (HMENU)-1; |
| 2918 | } |
| 2919 | else |
| 2920 | #endif |
| 2921 | { |
| 2922 | #ifdef FEAT_MBYTE |
| 2923 | WCHAR *wn = NULL; |
| 2924 | int n; |
| 2925 | |
| 2926 | if (enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
| 2927 | { |
| 2928 | /* 'encoding' differs from active codepage: convert menu item name |
| 2929 | * and use wide function */ |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 2930 | wn = enc_to_utf16(menu->name, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2931 | if (wn != NULL) |
| 2932 | { |
| 2933 | n = InsertMenuW(parent->submenu_id, (UINT)idx, |
| 2934 | (menu_is_separator(menu->name) |
| 2935 | ? MF_SEPARATOR : MF_STRING) | MF_BYPOSITION, |
| 2936 | (UINT)menu->id, wn); |
| 2937 | vim_free(wn); |
| 2938 | if (n == 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) |
| 2939 | /* Failed, try using non-wide function. */ |
| 2940 | wn = NULL; |
| 2941 | } |
| 2942 | } |
| 2943 | if (wn == NULL) |
| 2944 | #endif |
| 2945 | InsertMenu(parent->submenu_id, (UINT)idx, |
| 2946 | (menu_is_separator(menu->name) ? MF_SEPARATOR : MF_STRING) |
| 2947 | | MF_BYPOSITION, |
| 2948 | (UINT)menu->id, (LPCTSTR)menu->name); |
| 2949 | #ifdef FEAT_TEAROFF |
| 2950 | if (IsWindow(parent->tearoff_handle)) |
| 2951 | rebuild_tearoff(parent); |
| 2952 | #endif |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | /* |
| 2957 | * Destroy the machine specific menu widget. |
| 2958 | */ |
| 2959 | void |
| 2960 | gui_mch_destroy_menu(vimmenu_T *menu) |
| 2961 | { |
| 2962 | #ifdef FEAT_TOOLBAR |
| 2963 | /* |
| 2964 | * is this a toolbar button? |
| 2965 | */ |
| 2966 | if (menu->submenu_id == (HMENU)-1) |
| 2967 | { |
| 2968 | int iButton; |
| 2969 | |
| 2970 | iButton = (int)SendMessage(s_toolbarhwnd, TB_COMMANDTOINDEX, |
| 2971 | (WPARAM)menu->id, 0); |
| 2972 | SendMessage(s_toolbarhwnd, TB_DELETEBUTTON, (WPARAM)iButton, 0); |
| 2973 | } |
| 2974 | else |
| 2975 | #endif |
| 2976 | { |
| 2977 | if (menu->parent != NULL |
| 2978 | && menu_is_popup(menu->parent->dname) |
| 2979 | && menu->parent->submenu_id != NULL) |
| 2980 | RemoveMenu(menu->parent->submenu_id, menu->id, MF_BYCOMMAND); |
| 2981 | else |
| 2982 | RemoveMenu(s_menuBar, menu->id, MF_BYCOMMAND); |
| 2983 | if (menu->submenu_id != NULL) |
| 2984 | DestroyMenu(menu->submenu_id); |
| 2985 | #ifdef FEAT_TEAROFF |
| 2986 | if (IsWindow(menu->tearoff_handle)) |
| 2987 | DestroyWindow(menu->tearoff_handle); |
| 2988 | if (menu->parent != NULL |
| 2989 | && menu->parent->children != NULL |
| 2990 | && IsWindow(menu->parent->tearoff_handle)) |
| 2991 | { |
| 2992 | /* This menu must not show up when rebuilding the tearoff window. */ |
| 2993 | menu->modes = 0; |
| 2994 | rebuild_tearoff(menu->parent); |
| 2995 | } |
| 2996 | #endif |
| 2997 | } |
| 2998 | } |
| 2999 | |
| 3000 | #ifdef FEAT_TEAROFF |
| 3001 | static void |
| 3002 | rebuild_tearoff(vimmenu_T *menu) |
| 3003 | { |
| 3004 | /*hackish*/ |
| 3005 | char_u tbuf[128]; |
| 3006 | RECT trect; |
| 3007 | RECT rct; |
| 3008 | RECT roct; |
| 3009 | int x, y; |
| 3010 | |
| 3011 | HWND thwnd = menu->tearoff_handle; |
| 3012 | |
| 3013 | GetWindowText(thwnd, tbuf, 127); |
| 3014 | if (GetWindowRect(thwnd, &trect) |
| 3015 | && GetWindowRect(s_hwnd, &rct) |
| 3016 | && GetClientRect(s_hwnd, &roct)) |
| 3017 | { |
| 3018 | x = trect.left - rct.left; |
| 3019 | y = (trect.top - rct.bottom + roct.bottom); |
| 3020 | } |
| 3021 | else |
| 3022 | { |
| 3023 | x = y = 0xffffL; |
| 3024 | } |
| 3025 | DestroyWindow(thwnd); |
| 3026 | if (menu->children != NULL) |
| 3027 | { |
| 3028 | gui_mch_tearoff(tbuf, menu, x, y); |
| 3029 | if (IsWindow(menu->tearoff_handle)) |
| 3030 | (void) SetWindowPos(menu->tearoff_handle, |
| 3031 | NULL, |
| 3032 | (int)trect.left, |
| 3033 | (int)trect.top, |
| 3034 | 0, 0, |
| 3035 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); |
| 3036 | } |
| 3037 | } |
| 3038 | #endif /* FEAT_TEAROFF */ |
| 3039 | |
| 3040 | /* |
| 3041 | * Make a menu either grey or not grey. |
| 3042 | */ |
| 3043 | void |
| 3044 | gui_mch_menu_grey( |
| 3045 | vimmenu_T *menu, |
| 3046 | int grey) |
| 3047 | { |
| 3048 | #ifdef FEAT_TOOLBAR |
| 3049 | /* |
| 3050 | * is this a toolbar button? |
| 3051 | */ |
| 3052 | if (menu->submenu_id == (HMENU)-1) |
| 3053 | { |
| 3054 | SendMessage(s_toolbarhwnd, TB_ENABLEBUTTON, |
| 3055 | (WPARAM)menu->id, (LPARAM) MAKELONG((grey ? FALSE : TRUE), 0) ); |
| 3056 | } |
| 3057 | else |
| 3058 | #endif |
| 3059 | if (grey) |
| 3060 | EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_GRAYED); |
| 3061 | else |
| 3062 | EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_ENABLED); |
| 3063 | |
| 3064 | #ifdef FEAT_TEAROFF |
| 3065 | if ((menu->parent != NULL) && (IsWindow(menu->parent->tearoff_handle))) |
| 3066 | { |
| 3067 | WORD menuID; |
| 3068 | HWND menuHandle; |
| 3069 | |
| 3070 | /* |
| 3071 | * A tearoff button has changed state. |
| 3072 | */ |
| 3073 | if (menu->children == NULL) |
| 3074 | menuID = (WORD)(menu->id); |
| 3075 | else |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3076 | menuID = (WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3077 | menuHandle = GetDlgItem(menu->parent->tearoff_handle, menuID); |
| 3078 | if (menuHandle) |
| 3079 | EnableWindow(menuHandle, !grey); |
| 3080 | |
| 3081 | } |
| 3082 | #endif |
| 3083 | } |
| 3084 | |
| 3085 | #endif /* FEAT_MENU */ |
| 3086 | |
| 3087 | |
| 3088 | /* define some macros used to make the dialogue creation more readable */ |
| 3089 | |
| 3090 | #define add_string(s) strcpy((LPSTR)p, s); (LPSTR)p += (strlen((LPSTR)p) + 1) |
| 3091 | #define add_word(x) *p++ = (x) |
Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 3092 | #define add_long(x) dwp = (DWORD *)p; *dwp++ = (x); p = (WORD *)dwp |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3093 | |
| 3094 | #if defined(FEAT_GUI_DIALOG) || defined(PROTO) |
| 3095 | /* |
| 3096 | * stuff for dialogs |
| 3097 | */ |
| 3098 | |
| 3099 | /* |
| 3100 | * The callback routine used by all the dialogs. Very simple. First, |
| 3101 | * acknowledges the INITDIALOG message so that Windows knows to do standard |
| 3102 | * dialog stuff (Return = default, Esc = cancel....) Second, if a button is |
| 3103 | * pressed, return that button's ID - IDCANCEL (2), which is the button's |
| 3104 | * number. |
| 3105 | */ |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 3106 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3107 | static LRESULT CALLBACK |
| 3108 | dialog_callback( |
| 3109 | HWND hwnd, |
| 3110 | UINT message, |
| 3111 | WPARAM wParam, |
| 3112 | LPARAM lParam) |
| 3113 | { |
| 3114 | if (message == WM_INITDIALOG) |
| 3115 | { |
| 3116 | CenterWindow(hwnd, GetWindow(hwnd, GW_OWNER)); |
| 3117 | /* Set focus to the dialog. Set the default button, if specified. */ |
| 3118 | (void)SetFocus(hwnd); |
| 3119 | if (dialog_default_button > IDCANCEL) |
| 3120 | (void)SetFocus(GetDlgItem(hwnd, dialog_default_button)); |
Bram Moolenaar | 2b80e65 | 2007-08-14 14:57:55 +0000 | [diff] [blame] | 3121 | else |
| 3122 | /* We don't have a default, set focus on another element of the |
| 3123 | * dialog window, probably the icon */ |
| 3124 | (void)SetFocus(GetDlgItem(hwnd, DLG_NONBUTTON_CONTROL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3125 | return FALSE; |
| 3126 | } |
| 3127 | |
| 3128 | if (message == WM_COMMAND) |
| 3129 | { |
| 3130 | int button = LOWORD(wParam); |
| 3131 | |
| 3132 | /* Don't end the dialog if something was selected that was |
| 3133 | * not a button. |
| 3134 | */ |
| 3135 | if (button >= DLG_NONBUTTON_CONTROL) |
| 3136 | return TRUE; |
| 3137 | |
| 3138 | /* If the edit box exists, copy the string. */ |
| 3139 | if (s_textfield != NULL) |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 3140 | { |
| 3141 | # if defined(FEAT_MBYTE) && defined(WIN3264) |
| 3142 | /* If the OS is Windows NT, and 'encoding' differs from active |
| 3143 | * codepage: use wide function and convert text. */ |
| 3144 | if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT |
| 3145 | && enc_codepage >= 0 && (int)GetACP() != enc_codepage) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 3146 | { |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 3147 | WCHAR *wp = (WCHAR *)alloc(IOSIZE * sizeof(WCHAR)); |
| 3148 | char_u *p; |
| 3149 | |
| 3150 | GetDlgItemTextW(hwnd, DLG_NONBUTTON_CONTROL + 2, wp, IOSIZE); |
| 3151 | p = utf16_to_enc(wp, NULL); |
| 3152 | vim_strncpy(s_textfield, p, IOSIZE); |
| 3153 | vim_free(p); |
| 3154 | vim_free(wp); |
| 3155 | } |
| 3156 | else |
| 3157 | # endif |
| 3158 | GetDlgItemText(hwnd, DLG_NONBUTTON_CONTROL + 2, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3159 | s_textfield, IOSIZE); |
Bram Moolenaar | 3ca9a8a | 2009-01-28 20:23:17 +0000 | [diff] [blame] | 3160 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3161 | |
| 3162 | /* |
| 3163 | * Need to check for IDOK because if the user just hits Return to |
| 3164 | * accept the default value, some reason this is what we get. |
| 3165 | */ |
| 3166 | if (button == IDOK) |
| 3167 | { |
| 3168 | if (dialog_default_button > IDCANCEL) |
| 3169 | EndDialog(hwnd, dialog_default_button); |
| 3170 | } |
| 3171 | else |
| 3172 | EndDialog(hwnd, button - IDCANCEL); |
| 3173 | return TRUE; |
| 3174 | } |
| 3175 | |
| 3176 | if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) |
| 3177 | { |
| 3178 | EndDialog(hwnd, 0); |
| 3179 | return TRUE; |
| 3180 | } |
| 3181 | return FALSE; |
| 3182 | } |
| 3183 | |
| 3184 | /* |
| 3185 | * Create a dialog dynamically from the parameter strings. |
| 3186 | * type = type of dialog (question, alert, etc.) |
| 3187 | * title = dialog title. may be NULL for default title. |
| 3188 | * message = text to display. Dialog sizes to accommodate it. |
| 3189 | * buttons = '\n' separated list of button captions, default first. |
| 3190 | * dfltbutton = number of default button. |
| 3191 | * |
| 3192 | * This routine returns 1 if the first button is pressed, |
| 3193 | * 2 for the second, etc. |
| 3194 | * |
| 3195 | * 0 indicates Esc was pressed. |
| 3196 | * -1 for unexpected error |
| 3197 | * |
| 3198 | * If stubbing out this fn, return 1. |
| 3199 | */ |
| 3200 | |
| 3201 | static const char_u *dlg_icons[] = /* must match names in resource file */ |
| 3202 | { |
| 3203 | "IDR_VIM", |
| 3204 | "IDR_VIM_ERROR", |
| 3205 | "IDR_VIM_ALERT", |
| 3206 | "IDR_VIM_INFO", |
| 3207 | "IDR_VIM_QUESTION" |
| 3208 | }; |
| 3209 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3210 | int |
| 3211 | gui_mch_dialog( |
| 3212 | int type, |
| 3213 | char_u *title, |
| 3214 | char_u *message, |
| 3215 | char_u *buttons, |
| 3216 | int dfltbutton, |
Bram Moolenaar | d2c340a | 2011-01-17 20:08:11 +0100 | [diff] [blame] | 3217 | char_u *textfield, |
| 3218 | int ex_cmd) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3219 | { |
| 3220 | WORD *p, *pdlgtemplate, *pnumitems; |
Bram Moolenaar | f4cd3e8 | 2005-12-22 22:47:02 +0000 | [diff] [blame] | 3221 | DWORD *dwp; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3222 | int numButtons; |
| 3223 | int *buttonWidths, *buttonPositions; |
| 3224 | int buttonYpos; |
| 3225 | int nchar, i; |
| 3226 | DWORD lStyle; |
| 3227 | int dlgwidth = 0; |
| 3228 | int dlgheight; |
| 3229 | int editboxheight; |
| 3230 | int horizWidth = 0; |
| 3231 | int msgheight; |
| 3232 | char_u *pstart; |
| 3233 | char_u *pend; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3234 | char_u *last_white; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3235 | char_u *tbuffer; |
| 3236 | RECT rect; |
| 3237 | HWND hwnd; |
| 3238 | HDC hdc; |
| 3239 | HFONT font, oldFont; |
| 3240 | TEXTMETRIC fontInfo; |
| 3241 | int fontHeight; |
| 3242 | int textWidth, minButtonWidth, messageWidth; |
| 3243 | int maxDialogWidth; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3244 | int maxDialogHeight; |
| 3245 | int scroll_flag = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3246 | int vertical; |
| 3247 | int dlgPaddingX; |
| 3248 | int dlgPaddingY; |
| 3249 | #ifdef USE_SYSMENU_FONT |
| 3250 | LOGFONT lfSysmenu; |
| 3251 | int use_lfSysmenu = FALSE; |
| 3252 | #endif |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3253 | garray_T ga; |
| 3254 | int l; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3255 | |
| 3256 | #ifndef NO_CONSOLE |
| 3257 | /* Don't output anything in silent mode ("ex -s") */ |
| 3258 | if (silent_mode) |
| 3259 | return dfltbutton; /* return default option */ |
| 3260 | #endif |
| 3261 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3262 | if (s_hwnd == NULL) |
| 3263 | get_dialog_font_metrics(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3264 | |
| 3265 | if ((type < 0) || (type > VIM_LAST_TYPE)) |
| 3266 | type = 0; |
| 3267 | |
| 3268 | /* allocate some memory for dialog template */ |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3269 | /* TODO should compute this really */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3270 | pdlgtemplate = p = (PWORD)LocalAlloc(LPTR, |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3271 | DLG_ALLOC_SIZE + STRLEN(message) * 2); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3272 | |
| 3273 | if (p == NULL) |
| 3274 | return -1; |
| 3275 | |
| 3276 | /* |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 3277 | * make a copy of 'buttons' to fiddle with it. compiler grizzles because |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3278 | * vim_strsave() doesn't take a const arg (why not?), so cast away the |
| 3279 | * const. |
| 3280 | */ |
| 3281 | tbuffer = vim_strsave(buttons); |
| 3282 | if (tbuffer == NULL) |
| 3283 | return -1; |
| 3284 | |
| 3285 | --dfltbutton; /* Change from one-based to zero-based */ |
| 3286 | |
| 3287 | /* Count buttons */ |
| 3288 | numButtons = 1; |
| 3289 | for (i = 0; tbuffer[i] != '\0'; i++) |
| 3290 | { |
| 3291 | if (tbuffer[i] == DLG_BUTTON_SEP) |
| 3292 | numButtons++; |
| 3293 | } |
| 3294 | if (dfltbutton >= numButtons) |
| 3295 | dfltbutton = -1; |
| 3296 | |
| 3297 | /* Allocate array to hold the width of each button */ |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 3298 | buttonWidths = (int *)lalloc(numButtons * sizeof(int), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3299 | if (buttonWidths == NULL) |
| 3300 | return -1; |
| 3301 | |
| 3302 | /* Allocate array to hold the X position of each button */ |
Bram Moolenaar | c54b8a7 | 2005-09-30 21:20:29 +0000 | [diff] [blame] | 3303 | buttonPositions = (int *)lalloc(numButtons * sizeof(int), TRUE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3304 | if (buttonPositions == NULL) |
| 3305 | return -1; |
| 3306 | |
| 3307 | /* |
| 3308 | * Calculate how big the dialog must be. |
| 3309 | */ |
| 3310 | hwnd = GetDesktopWindow(); |
| 3311 | hdc = GetWindowDC(hwnd); |
| 3312 | #ifdef USE_SYSMENU_FONT |
| 3313 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 3314 | { |
| 3315 | font = CreateFontIndirect(&lfSysmenu); |
| 3316 | use_lfSysmenu = TRUE; |
| 3317 | } |
| 3318 | else |
| 3319 | #endif |
| 3320 | font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 3321 | VARIABLE_PITCH , DLG_FONT_NAME); |
| 3322 | if (s_usenewlook) |
| 3323 | { |
| 3324 | oldFont = SelectFont(hdc, font); |
| 3325 | dlgPaddingX = DLG_PADDING_X; |
| 3326 | dlgPaddingY = DLG_PADDING_Y; |
| 3327 | } |
| 3328 | else |
| 3329 | { |
| 3330 | oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); |
| 3331 | dlgPaddingX = DLG_OLD_STYLE_PADDING_X; |
| 3332 | dlgPaddingY = DLG_OLD_STYLE_PADDING_Y; |
| 3333 | } |
| 3334 | GetTextMetrics(hdc, &fontInfo); |
| 3335 | fontHeight = fontInfo.tmHeight; |
| 3336 | |
| 3337 | /* Minimum width for horizontal button */ |
| 3338 | minButtonWidth = GetTextWidth(hdc, "Cancel", 6); |
| 3339 | |
| 3340 | /* Maximum width of a dialog, if possible */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3341 | if (s_hwnd == NULL) |
| 3342 | { |
| 3343 | RECT workarea_rect; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3344 | |
Bram Moolenaar | c716c30 | 2006-01-21 22:12:51 +0000 | [diff] [blame] | 3345 | /* We don't have a window, use the desktop area. */ |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3346 | get_work_area(&workarea_rect); |
| 3347 | maxDialogWidth = workarea_rect.right - workarea_rect.left - 100; |
| 3348 | if (maxDialogWidth > 600) |
| 3349 | maxDialogWidth = 600; |
Bram Moolenaar | 1b1b094 | 2013-08-01 13:20:42 +0200 | [diff] [blame] | 3350 | /* Leave some room for the taskbar. */ |
| 3351 | maxDialogHeight = workarea_rect.bottom - workarea_rect.top - 150; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3352 | } |
| 3353 | else |
| 3354 | { |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 3355 | /* Use our own window for the size, unless it's very small. */ |
| 3356 | GetWindowRect(s_hwnd, &rect); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3357 | maxDialogWidth = rect.right - rect.left |
Bram Moolenaar | 9d48895 | 2013-07-21 17:53:58 +0200 | [diff] [blame] | 3358 | - (GetSystemMetrics(SM_CXFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 3359 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 2; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3360 | if (maxDialogWidth < DLG_MIN_MAX_WIDTH) |
| 3361 | maxDialogWidth = DLG_MIN_MAX_WIDTH; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3362 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3363 | maxDialogHeight = rect.bottom - rect.top |
Bram Moolenaar | 1b1b094 | 2013-08-01 13:20:42 +0200 | [diff] [blame] | 3364 | - (GetSystemMetrics(SM_CYFRAME) + |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 3365 | GetSystemMetrics(SM_CXPADDEDBORDER)) * 4 |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 3366 | - GetSystemMetrics(SM_CYCAPTION); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3367 | if (maxDialogHeight < DLG_MIN_MAX_HEIGHT) |
| 3368 | maxDialogHeight = DLG_MIN_MAX_HEIGHT; |
| 3369 | } |
| 3370 | |
| 3371 | /* Set dlgwidth to width of message. |
| 3372 | * Copy the message into "ga", changing NL to CR-NL and inserting line |
| 3373 | * breaks where needed. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3374 | pstart = message; |
| 3375 | messageWidth = 0; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3376 | msgheight = 0; |
| 3377 | ga_init2(&ga, sizeof(char), 500); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3378 | do |
| 3379 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3380 | msgheight += fontHeight; /* at least one line */ |
| 3381 | |
| 3382 | /* Need to figure out where to break the string. The system does it |
| 3383 | * at a word boundary, which would mean we can't compute the number of |
| 3384 | * wrapped lines. */ |
| 3385 | textWidth = 0; |
| 3386 | last_white = NULL; |
| 3387 | for (pend = pstart; *pend != NUL && *pend != '\n'; ) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3388 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3389 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3390 | l = (*mb_ptr2len)(pend); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3391 | #else |
| 3392 | l = 1; |
| 3393 | #endif |
| 3394 | if (l == 1 && vim_iswhite(*pend) |
| 3395 | && textWidth > maxDialogWidth * 3 / 4) |
| 3396 | last_white = pend; |
Bram Moolenaar | f05d811 | 2013-06-26 12:58:32 +0200 | [diff] [blame] | 3397 | textWidth += GetTextWidthEnc(hdc, pend, l); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3398 | if (textWidth >= maxDialogWidth) |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3399 | { |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3400 | /* Line will wrap. */ |
| 3401 | messageWidth = maxDialogWidth; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3402 | msgheight += fontHeight; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3403 | textWidth = 0; |
| 3404 | |
| 3405 | if (last_white != NULL) |
| 3406 | { |
| 3407 | /* break the line just after a space */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3408 | ga.ga_len -= (int)(pend - (last_white + 1)); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3409 | pend = last_white + 1; |
| 3410 | last_white = NULL; |
| 3411 | } |
| 3412 | ga_append(&ga, '\r'); |
| 3413 | ga_append(&ga, '\n'); |
| 3414 | continue; |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3415 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3416 | |
| 3417 | while (--l >= 0) |
| 3418 | ga_append(&ga, *pend++); |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3419 | } |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3420 | if (textWidth > messageWidth) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3421 | messageWidth = textWidth; |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3422 | |
| 3423 | ga_append(&ga, '\r'); |
| 3424 | ga_append(&ga, '\n'); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3425 | pstart = pend + 1; |
| 3426 | } while (*pend != NUL); |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3427 | |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3428 | if (ga.ga_data != NULL) |
| 3429 | message = ga.ga_data; |
| 3430 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3431 | messageWidth += 10; /* roundoff space */ |
| 3432 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3433 | /* Add width of icon to dlgwidth, and some space */ |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 3434 | dlgwidth = messageWidth + DLG_ICON_WIDTH + 3 * dlgPaddingX |
| 3435 | + GetSystemMetrics(SM_CXVSCROLL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3436 | |
| 3437 | if (msgheight < DLG_ICON_HEIGHT) |
| 3438 | msgheight = DLG_ICON_HEIGHT; |
| 3439 | |
| 3440 | /* |
| 3441 | * Check button names. A long one will make the dialog wider. |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 3442 | * When called early (-register error message) p_go isn't initialized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3443 | */ |
Bram Moolenaar | aea02fa | 2007-05-04 20:29:09 +0000 | [diff] [blame] | 3444 | vertical = (p_go != NULL && vim_strchr(p_go, GO_VERTICAL) != NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3445 | if (!vertical) |
| 3446 | { |
| 3447 | // Place buttons horizontally if they fit. |
| 3448 | horizWidth = dlgPaddingX; |
| 3449 | pstart = tbuffer; |
| 3450 | i = 0; |
| 3451 | do |
| 3452 | { |
| 3453 | pend = vim_strchr(pstart, DLG_BUTTON_SEP); |
| 3454 | if (pend == NULL) |
| 3455 | pend = pstart + STRLEN(pstart); // Last button name. |
Bram Moolenaar | b052fe0 | 2013-06-26 13:16:20 +0200 | [diff] [blame] | 3456 | textWidth = GetTextWidthEnc(hdc, pstart, (int)(pend - pstart)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3457 | if (textWidth < minButtonWidth) |
| 3458 | textWidth = minButtonWidth; |
| 3459 | textWidth += dlgPaddingX; /* Padding within button */ |
| 3460 | buttonWidths[i] = textWidth; |
| 3461 | buttonPositions[i++] = horizWidth; |
| 3462 | horizWidth += textWidth + dlgPaddingX; /* Pad between buttons */ |
| 3463 | pstart = pend + 1; |
| 3464 | } while (*pend != NUL); |
| 3465 | |
| 3466 | if (horizWidth > maxDialogWidth) |
| 3467 | vertical = TRUE; // Too wide to fit on the screen. |
| 3468 | else if (horizWidth > dlgwidth) |
| 3469 | dlgwidth = horizWidth; |
| 3470 | } |
| 3471 | |
| 3472 | if (vertical) |
| 3473 | { |
| 3474 | // Stack buttons vertically. |
| 3475 | pstart = tbuffer; |
| 3476 | do |
| 3477 | { |
| 3478 | pend = vim_strchr(pstart, DLG_BUTTON_SEP); |
| 3479 | if (pend == NULL) |
| 3480 | pend = pstart + STRLEN(pstart); // Last button name. |
Bram Moolenaar | b052fe0 | 2013-06-26 13:16:20 +0200 | [diff] [blame] | 3481 | textWidth = GetTextWidthEnc(hdc, pstart, (int)(pend - pstart)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3482 | textWidth += dlgPaddingX; /* Padding within button */ |
| 3483 | textWidth += DLG_VERT_PADDING_X * 2; /* Padding around button */ |
| 3484 | if (textWidth > dlgwidth) |
| 3485 | dlgwidth = textWidth; |
| 3486 | pstart = pend + 1; |
| 3487 | } while (*pend != NUL); |
| 3488 | } |
| 3489 | |
| 3490 | if (dlgwidth < DLG_MIN_WIDTH) |
| 3491 | dlgwidth = DLG_MIN_WIDTH; /* Don't allow a really thin dialog!*/ |
| 3492 | |
| 3493 | /* start to fill in the dlgtemplate information. addressing by WORDs */ |
| 3494 | if (s_usenewlook) |
| 3495 | lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE |DS_SETFONT; |
| 3496 | else |
| 3497 | lStyle = DS_MODALFRAME | WS_CAPTION |DS_3DLOOK| WS_VISIBLE; |
| 3498 | |
| 3499 | add_long(lStyle); |
| 3500 | add_long(0); // (lExtendedStyle) |
| 3501 | pnumitems = p; /*save where the number of items must be stored*/ |
| 3502 | add_word(0); // NumberOfItems(will change later) |
| 3503 | add_word(10); // x |
| 3504 | add_word(10); // y |
| 3505 | add_word(PixelToDialogX(dlgwidth)); // cx |
| 3506 | |
| 3507 | // Dialog height. |
| 3508 | if (vertical) |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 3509 | dlgheight = msgheight + 2 * dlgPaddingY |
| 3510 | + DLG_VERT_PADDING_Y + 2 * fontHeight * numButtons; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3511 | else |
| 3512 | dlgheight = msgheight + 3 * dlgPaddingY + 2 * fontHeight; |
| 3513 | |
| 3514 | // Dialog needs to be taller if contains an edit box. |
| 3515 | editboxheight = fontHeight + dlgPaddingY + 4 * DLG_VERT_PADDING_Y; |
| 3516 | if (textfield != NULL) |
| 3517 | dlgheight += editboxheight; |
| 3518 | |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 3519 | /* Restrict the size to a maximum. Causes a scrollbar to show up. */ |
| 3520 | if (dlgheight > maxDialogHeight) |
| 3521 | { |
Bram Moolenaar | b5a7a8b | 2014-08-06 14:52:30 +0200 | [diff] [blame] | 3522 | msgheight = msgheight - (dlgheight - maxDialogHeight); |
| 3523 | dlgheight = maxDialogHeight; |
| 3524 | scroll_flag = WS_VSCROLL; |
| 3525 | /* Make sure scrollbar doesn't appear in the middle of the dialog */ |
| 3526 | messageWidth = dlgwidth - DLG_ICON_WIDTH - 3 * dlgPaddingX; |
Bram Moolenaar | a95d823 | 2013-08-07 15:27:11 +0200 | [diff] [blame] | 3527 | } |
| 3528 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3529 | add_word(PixelToDialogY(dlgheight)); |
| 3530 | |
| 3531 | add_word(0); // Menu |
| 3532 | add_word(0); // Class |
| 3533 | |
| 3534 | /* copy the title of the dialog */ |
| 3535 | nchar = nCopyAnsiToWideChar(p, (title ? |
| 3536 | (LPSTR)title : |
| 3537 | (LPSTR)("Vim "VIM_VERSION_MEDIUM))); |
| 3538 | p += nchar; |
| 3539 | |
| 3540 | if (s_usenewlook) |
| 3541 | { |
| 3542 | /* do the font, since DS_3DLOOK doesn't work properly */ |
| 3543 | #ifdef USE_SYSMENU_FONT |
| 3544 | if (use_lfSysmenu) |
| 3545 | { |
| 3546 | /* point size */ |
| 3547 | *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
| 3548 | GetDeviceCaps(hdc, LOGPIXELSY)); |
| 3549 | nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName)); |
| 3550 | } |
| 3551 | else |
| 3552 | #endif |
| 3553 | { |
| 3554 | *p++ = DLG_FONT_POINT_SIZE; // point size |
| 3555 | nchar = nCopyAnsiToWideChar(p, TEXT(DLG_FONT_NAME)); |
| 3556 | } |
| 3557 | p += nchar; |
| 3558 | } |
| 3559 | |
| 3560 | buttonYpos = msgheight + 2 * dlgPaddingY; |
| 3561 | |
| 3562 | if (textfield != NULL) |
| 3563 | buttonYpos += editboxheight; |
| 3564 | |
| 3565 | pstart = tbuffer; |
| 3566 | if (!vertical) |
| 3567 | horizWidth = (dlgwidth - horizWidth) / 2; /* Now it's X offset */ |
| 3568 | for (i = 0; i < numButtons; i++) |
| 3569 | { |
| 3570 | /* get end of this button. */ |
| 3571 | for ( pend = pstart; |
| 3572 | *pend && (*pend != DLG_BUTTON_SEP); |
| 3573 | pend++) |
| 3574 | ; |
| 3575 | |
| 3576 | if (*pend) |
| 3577 | *pend = '\0'; |
| 3578 | |
| 3579 | /* |
| 3580 | * old NOTE: |
| 3581 | * setting the BS_DEFPUSHBUTTON style doesn't work because Windows sets |
| 3582 | * the focus to the first tab-able button and in so doing makes that |
| 3583 | * the default!! Grrr. Workaround: Make the default button the only |
| 3584 | * one with WS_TABSTOP style. Means user can't tab between buttons, but |
| 3585 | * he/she can use arrow keys. |
| 3586 | * |
| 3587 | * new NOTE: BS_DEFPUSHBUTTON is required to be able to select the |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 3588 | * right button when hitting <Enter>. E.g., for the ":confirm quit" |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3589 | * dialog. Also needed for when the textfield is the default control. |
| 3590 | * It appears to work now (perhaps not on Win95?). |
| 3591 | */ |
| 3592 | if (vertical) |
| 3593 | { |
| 3594 | p = add_dialog_element(p, |
| 3595 | (i == dfltbutton |
| 3596 | ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, |
| 3597 | PixelToDialogX(DLG_VERT_PADDING_X), |
| 3598 | PixelToDialogY(buttonYpos /* TBK */ |
| 3599 | + 2 * fontHeight * i), |
| 3600 | PixelToDialogX(dlgwidth - 2 * DLG_VERT_PADDING_X), |
| 3601 | (WORD)(PixelToDialogY(2 * fontHeight) - 1), |
| 3602 | (WORD)(IDCANCEL + 1 + i), (WORD)0x0080, pstart); |
| 3603 | } |
| 3604 | else |
| 3605 | { |
| 3606 | p = add_dialog_element(p, |
| 3607 | (i == dfltbutton |
| 3608 | ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP, |
| 3609 | PixelToDialogX(horizWidth + buttonPositions[i]), |
| 3610 | PixelToDialogY(buttonYpos), /* TBK */ |
| 3611 | PixelToDialogX(buttonWidths[i]), |
| 3612 | (WORD)(PixelToDialogY(2 * fontHeight) - 1), |
| 3613 | (WORD)(IDCANCEL + 1 + i), (WORD)0x0080, pstart); |
| 3614 | } |
| 3615 | pstart = pend + 1; /*next button*/ |
| 3616 | } |
| 3617 | *pnumitems += numButtons; |
| 3618 | |
| 3619 | /* Vim icon */ |
| 3620 | p = add_dialog_element(p, SS_ICON, |
| 3621 | PixelToDialogX(dlgPaddingX), |
| 3622 | PixelToDialogY(dlgPaddingY), |
| 3623 | PixelToDialogX(DLG_ICON_WIDTH), |
| 3624 | PixelToDialogY(DLG_ICON_HEIGHT), |
| 3625 | DLG_NONBUTTON_CONTROL + 0, (WORD)0x0082, |
| 3626 | dlg_icons[type]); |
| 3627 | |
Bram Moolenaar | 748bf03 | 2005-02-02 23:04:36 +0000 | [diff] [blame] | 3628 | /* Dialog message */ |
| 3629 | p = add_dialog_element(p, ES_LEFT|scroll_flag|ES_MULTILINE|ES_READONLY, |
| 3630 | PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH), |
| 3631 | PixelToDialogY(dlgPaddingY), |
| 3632 | (WORD)(PixelToDialogX(messageWidth) + 1), |
| 3633 | PixelToDialogY(msgheight), |
| 3634 | DLG_NONBUTTON_CONTROL + 1, (WORD)0x0081, message); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3635 | |
| 3636 | /* Edit box */ |
| 3637 | if (textfield != NULL) |
| 3638 | { |
| 3639 | p = add_dialog_element(p, ES_LEFT|ES_AUTOHSCROLL|WS_TABSTOP|WS_BORDER, |
| 3640 | PixelToDialogX(2 * dlgPaddingX), |
| 3641 | PixelToDialogY(2 * dlgPaddingY + msgheight), |
| 3642 | PixelToDialogX(dlgwidth - 4 * dlgPaddingX), |
| 3643 | PixelToDialogY(fontHeight + dlgPaddingY), |
| 3644 | DLG_NONBUTTON_CONTROL + 2, (WORD)0x0081, textfield); |
| 3645 | *pnumitems += 1; |
| 3646 | } |
| 3647 | |
| 3648 | *pnumitems += 2; |
| 3649 | |
| 3650 | SelectFont(hdc, oldFont); |
| 3651 | DeleteObject(font); |
| 3652 | ReleaseDC(hwnd, hdc); |
| 3653 | |
| 3654 | /* Let the dialog_callback() function know which button to make default |
| 3655 | * If we have an edit box, make that the default. We also need to tell |
| 3656 | * dialog_callback() if this dialog contains an edit box or not. We do |
| 3657 | * this by setting s_textfield if it does. |
| 3658 | */ |
| 3659 | if (textfield != NULL) |
| 3660 | { |
| 3661 | dialog_default_button = DLG_NONBUTTON_CONTROL + 2; |
| 3662 | s_textfield = textfield; |
| 3663 | } |
| 3664 | else |
| 3665 | { |
| 3666 | dialog_default_button = IDCANCEL + 1 + dfltbutton; |
| 3667 | s_textfield = NULL; |
| 3668 | } |
| 3669 | |
| 3670 | /* show the dialog box modally and get a return value */ |
| 3671 | nchar = (int)DialogBoxIndirect( |
| 3672 | s_hinst, |
| 3673 | (LPDLGTEMPLATE)pdlgtemplate, |
| 3674 | s_hwnd, |
| 3675 | (DLGPROC)dialog_callback); |
| 3676 | |
| 3677 | LocalFree(LocalHandle(pdlgtemplate)); |
| 3678 | vim_free(tbuffer); |
| 3679 | vim_free(buttonWidths); |
| 3680 | vim_free(buttonPositions); |
Bram Moolenaar | 3a7c85b | 2005-02-05 21:39:53 +0000 | [diff] [blame] | 3681 | vim_free(ga.ga_data); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3682 | |
| 3683 | /* Focus back to our window (for when MDI is used). */ |
| 3684 | (void)SetFocus(s_hwnd); |
| 3685 | |
| 3686 | return nchar; |
| 3687 | } |
| 3688 | |
| 3689 | #endif /* FEAT_GUI_DIALOG */ |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3690 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3691 | /* |
| 3692 | * Put a simple element (basic class) onto a dialog template in memory. |
| 3693 | * return a pointer to where the next item should be added. |
| 3694 | * |
| 3695 | * parameters: |
| 3696 | * lStyle = additional style flags |
| 3697 | * (be careful, NT3.51 & Win32s will ignore the new ones) |
| 3698 | * x,y = x & y positions IN DIALOG UNITS |
| 3699 | * w,h = width and height IN DIALOG UNITS |
| 3700 | * Id = ID used in messages |
| 3701 | * clss = class ID, e.g 0x0080 for a button, 0x0082 for a static |
| 3702 | * caption = usually text or resource name |
| 3703 | * |
| 3704 | * TODO: use the length information noted here to enable the dialog creation |
| 3705 | * routines to work out more exactly how much memory they need to alloc. |
| 3706 | */ |
| 3707 | static PWORD |
| 3708 | add_dialog_element( |
| 3709 | PWORD p, |
| 3710 | DWORD lStyle, |
| 3711 | WORD x, |
| 3712 | WORD y, |
| 3713 | WORD w, |
| 3714 | WORD h, |
| 3715 | WORD Id, |
| 3716 | WORD clss, |
| 3717 | const char *caption) |
| 3718 | { |
| 3719 | int nchar; |
| 3720 | |
| 3721 | p = lpwAlign(p); /* Align to dword boundary*/ |
| 3722 | lStyle = lStyle | WS_VISIBLE | WS_CHILD; |
| 3723 | *p++ = LOWORD(lStyle); |
| 3724 | *p++ = HIWORD(lStyle); |
| 3725 | *p++ = 0; // LOWORD (lExtendedStyle) |
| 3726 | *p++ = 0; // HIWORD (lExtendedStyle) |
| 3727 | *p++ = x; |
| 3728 | *p++ = y; |
| 3729 | *p++ = w; |
| 3730 | *p++ = h; |
| 3731 | *p++ = Id; //9 or 10 words in all |
| 3732 | |
| 3733 | *p++ = (WORD)0xffff; |
| 3734 | *p++ = clss; //2 more here |
| 3735 | |
| 3736 | nchar = nCopyAnsiToWideChar(p, (LPSTR)caption); //strlen(caption)+1 |
| 3737 | p += nchar; |
| 3738 | |
| 3739 | *p++ = 0; // advance pointer over nExtraStuff WORD - 2 more |
| 3740 | |
| 3741 | return p; //total = 15+ (strlen(caption)) words |
| 3742 | // = 30 + 2(strlen(caption) bytes reqd |
| 3743 | } |
| 3744 | |
| 3745 | |
| 3746 | /* |
| 3747 | * Helper routine. Take an input pointer, return closest pointer that is |
| 3748 | * aligned on a DWORD (4 byte) boundary. Taken from the Win32SDK samples. |
| 3749 | */ |
| 3750 | static LPWORD |
| 3751 | lpwAlign( |
| 3752 | LPWORD lpIn) |
| 3753 | { |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3754 | long_u ul; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3755 | |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3756 | ul = (long_u)lpIn; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3757 | ul += 3; |
| 3758 | ul >>= 2; |
| 3759 | ul <<= 2; |
| 3760 | return (LPWORD)ul; |
| 3761 | } |
| 3762 | |
| 3763 | /* |
| 3764 | * Helper routine. Takes second parameter as Ansi string, copies it to first |
| 3765 | * parameter as wide character (16-bits / char) string, and returns integer |
| 3766 | * number of wide characters (words) in string (including the trailing wide |
| 3767 | * char NULL). Partly taken from the Win32SDK samples. |
| 3768 | */ |
| 3769 | static int |
| 3770 | nCopyAnsiToWideChar( |
| 3771 | LPWORD lpWCStr, |
| 3772 | LPSTR lpAnsiIn) |
| 3773 | { |
| 3774 | int nChar = 0; |
| 3775 | #ifdef FEAT_MBYTE |
| 3776 | int len = lstrlen(lpAnsiIn) + 1; /* include NUL character */ |
| 3777 | int i; |
| 3778 | WCHAR *wn; |
| 3779 | |
| 3780 | if (enc_codepage == 0 && (int)GetACP() != enc_codepage) |
| 3781 | { |
| 3782 | /* Not a codepage, use our own conversion function. */ |
Bram Moolenaar | 36f692d | 2008-11-20 16:10:17 +0000 | [diff] [blame] | 3783 | wn = enc_to_utf16(lpAnsiIn, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3784 | if (wn != NULL) |
| 3785 | { |
| 3786 | wcscpy(lpWCStr, wn); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3787 | nChar = (int)wcslen(wn) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3788 | vim_free(wn); |
| 3789 | } |
| 3790 | } |
| 3791 | if (nChar == 0) |
| 3792 | /* Use Win32 conversion function. */ |
| 3793 | nChar = MultiByteToWideChar( |
| 3794 | enc_codepage > 0 ? enc_codepage : CP_ACP, |
| 3795 | MB_PRECOMPOSED, |
| 3796 | lpAnsiIn, len, |
| 3797 | lpWCStr, len); |
| 3798 | for (i = 0; i < nChar; ++i) |
| 3799 | if (lpWCStr[i] == (WORD)'\t') /* replace tabs with spaces */ |
| 3800 | lpWCStr[i] = (WORD)' '; |
| 3801 | #else |
| 3802 | do |
| 3803 | { |
| 3804 | if (*lpAnsiIn == '\t') |
| 3805 | *lpWCStr++ = (WORD)' '; |
| 3806 | else |
| 3807 | *lpWCStr++ = (WORD)*lpAnsiIn; |
| 3808 | nChar++; |
| 3809 | } while (*lpAnsiIn++); |
| 3810 | #endif |
| 3811 | |
| 3812 | return nChar; |
| 3813 | } |
| 3814 | |
| 3815 | |
| 3816 | #ifdef FEAT_TEAROFF |
| 3817 | /* |
| 3818 | * The callback function for all the modeless dialogs that make up the |
| 3819 | * "tearoff menus" Very simple - forward button presses (to fool Vim into |
| 3820 | * thinking its menus have been clicked), and go away when closed. |
| 3821 | */ |
| 3822 | static LRESULT CALLBACK |
| 3823 | tearoff_callback( |
| 3824 | HWND hwnd, |
| 3825 | UINT message, |
| 3826 | WPARAM wParam, |
| 3827 | LPARAM lParam) |
| 3828 | { |
| 3829 | if (message == WM_INITDIALOG) |
| 3830 | return (TRUE); |
| 3831 | |
| 3832 | /* May show the mouse pointer again. */ |
| 3833 | HandleMouseHide(message, lParam); |
| 3834 | |
| 3835 | if (message == WM_COMMAND) |
| 3836 | { |
| 3837 | if ((WORD)(LOWORD(wParam)) & 0x8000) |
| 3838 | { |
| 3839 | POINT mp; |
| 3840 | RECT rect; |
| 3841 | |
| 3842 | if (GetCursorPos(&mp) && GetWindowRect(hwnd, &rect)) |
| 3843 | { |
| 3844 | (void)TrackPopupMenu( |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 3845 | (HMENU)(long_u)(LOWORD(wParam) ^ 0x8000), |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3846 | TPM_LEFTALIGN | TPM_LEFTBUTTON, |
| 3847 | (int)rect.right - 8, |
| 3848 | (int)mp.y, |
| 3849 | (int)0, /*reserved param*/ |
| 3850 | s_hwnd, |
| 3851 | NULL); |
| 3852 | /* |
| 3853 | * NOTE: The pop-up menu can eat the mouse up event. |
| 3854 | * We deal with this in normal.c. |
| 3855 | */ |
| 3856 | } |
| 3857 | } |
| 3858 | else |
| 3859 | /* Pass on messages to the main Vim window */ |
| 3860 | PostMessage(s_hwnd, WM_COMMAND, LOWORD(wParam), 0); |
| 3861 | /* |
| 3862 | * Give main window the focus back: this is so after |
| 3863 | * choosing a tearoff button you can start typing again |
| 3864 | * straight away. |
| 3865 | */ |
| 3866 | (void)SetFocus(s_hwnd); |
| 3867 | return TRUE; |
| 3868 | } |
| 3869 | if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE)) |
| 3870 | { |
| 3871 | DestroyWindow(hwnd); |
| 3872 | return TRUE; |
| 3873 | } |
| 3874 | |
| 3875 | /* When moved around, give main window the focus back. */ |
| 3876 | if (message == WM_EXITSIZEMOVE) |
| 3877 | (void)SetActiveWindow(s_hwnd); |
| 3878 | |
| 3879 | return FALSE; |
| 3880 | } |
| 3881 | #endif |
| 3882 | |
| 3883 | |
| 3884 | /* |
| 3885 | * Decide whether to use the "new look" (small, non-bold font) or the "old |
| 3886 | * look" (big, clanky font) for dialogs, and work out a few values for use |
| 3887 | * later accordingly. |
| 3888 | */ |
| 3889 | static void |
| 3890 | get_dialog_font_metrics(void) |
| 3891 | { |
| 3892 | HDC hdc; |
| 3893 | HFONT hfontTools = 0; |
| 3894 | DWORD dlgFontSize; |
| 3895 | SIZE size; |
| 3896 | #ifdef USE_SYSMENU_FONT |
| 3897 | LOGFONT lfSysmenu; |
| 3898 | #endif |
| 3899 | |
| 3900 | s_usenewlook = FALSE; |
| 3901 | |
| 3902 | /* |
| 3903 | * For NT3.51 and Win32s, we stick with the old look |
| 3904 | * because it matches everything else. |
| 3905 | */ |
| 3906 | if (!is_winnt_3()) |
| 3907 | { |
| 3908 | #ifdef USE_SYSMENU_FONT |
| 3909 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 3910 | hfontTools = CreateFontIndirect(&lfSysmenu); |
| 3911 | else |
| 3912 | #endif |
| 3913 | hfontTools = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, |
| 3914 | 0, 0, 0, 0, VARIABLE_PITCH , DLG_FONT_NAME); |
| 3915 | |
| 3916 | if (hfontTools) |
| 3917 | { |
| 3918 | hdc = GetDC(s_hwnd); |
| 3919 | SelectObject(hdc, hfontTools); |
| 3920 | /* |
| 3921 | * GetTextMetrics() doesn't return the right value in |
| 3922 | * tmAveCharWidth, so we have to figure out the dialog base units |
| 3923 | * ourselves. |
| 3924 | */ |
| 3925 | GetTextExtentPoint(hdc, |
| 3926 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", |
| 3927 | 52, &size); |
| 3928 | ReleaseDC(s_hwnd, hdc); |
| 3929 | |
| 3930 | s_dlgfntwidth = (WORD)((size.cx / 26 + 1) / 2); |
| 3931 | s_dlgfntheight = (WORD)size.cy; |
| 3932 | s_usenewlook = TRUE; |
| 3933 | } |
| 3934 | } |
| 3935 | |
| 3936 | if (!s_usenewlook) |
| 3937 | { |
| 3938 | dlgFontSize = GetDialogBaseUnits(); /* fall back to big old system*/ |
| 3939 | s_dlgfntwidth = LOWORD(dlgFontSize); |
| 3940 | s_dlgfntheight = HIWORD(dlgFontSize); |
| 3941 | } |
| 3942 | } |
| 3943 | |
| 3944 | #if defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
| 3945 | /* |
| 3946 | * Create a pseudo-"tearoff menu" based on the child |
| 3947 | * items of a given menu pointer. |
| 3948 | */ |
| 3949 | static void |
| 3950 | gui_mch_tearoff( |
| 3951 | char_u *title, |
| 3952 | vimmenu_T *menu, |
| 3953 | int initX, |
| 3954 | int initY) |
| 3955 | { |
| 3956 | WORD *p, *pdlgtemplate, *pnumitems, *ptrueheight; |
| 3957 | int template_len; |
| 3958 | int nchar, textWidth, submenuWidth; |
| 3959 | DWORD lStyle; |
| 3960 | DWORD lExtendedStyle; |
| 3961 | WORD dlgwidth; |
| 3962 | WORD menuID; |
| 3963 | vimmenu_T *pmenu; |
| 3964 | vimmenu_T *the_menu = menu; |
| 3965 | HWND hwnd; |
| 3966 | HDC hdc; |
| 3967 | HFONT font, oldFont; |
| 3968 | int col, spaceWidth, len; |
| 3969 | int columnWidths[2]; |
| 3970 | char_u *label, *text; |
| 3971 | int acLen = 0; |
| 3972 | int nameLen; |
| 3973 | int padding0, padding1, padding2 = 0; |
| 3974 | int sepPadding=0; |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 3975 | int x; |
| 3976 | int y; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3977 | #ifdef USE_SYSMENU_FONT |
| 3978 | LOGFONT lfSysmenu; |
| 3979 | int use_lfSysmenu = FALSE; |
| 3980 | #endif |
| 3981 | |
| 3982 | /* |
| 3983 | * If this menu is already torn off, move it to the mouse position. |
| 3984 | */ |
| 3985 | if (IsWindow(menu->tearoff_handle)) |
| 3986 | { |
| 3987 | POINT mp; |
| 3988 | if (GetCursorPos((LPPOINT)&mp)) |
| 3989 | { |
| 3990 | SetWindowPos(menu->tearoff_handle, NULL, mp.x, mp.y, 0, 0, |
| 3991 | SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); |
| 3992 | } |
| 3993 | return; |
| 3994 | } |
| 3995 | |
| 3996 | /* |
| 3997 | * Create a new tearoff. |
| 3998 | */ |
| 3999 | if (*title == MNU_HIDDEN_CHAR) |
| 4000 | title++; |
| 4001 | |
| 4002 | /* Allocate memory to store the dialog template. It's made bigger when |
| 4003 | * needed. */ |
| 4004 | template_len = DLG_ALLOC_SIZE; |
| 4005 | pdlgtemplate = p = (WORD *)LocalAlloc(LPTR, template_len); |
| 4006 | if (p == NULL) |
| 4007 | return; |
| 4008 | |
| 4009 | hwnd = GetDesktopWindow(); |
| 4010 | hdc = GetWindowDC(hwnd); |
| 4011 | #ifdef USE_SYSMENU_FONT |
| 4012 | if (gui_w32_get_menu_font(&lfSysmenu) == OK) |
| 4013 | { |
| 4014 | font = CreateFontIndirect(&lfSysmenu); |
| 4015 | use_lfSysmenu = TRUE; |
| 4016 | } |
| 4017 | else |
| 4018 | #endif |
| 4019 | font = CreateFont(-DLG_FONT_POINT_SIZE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 4020 | VARIABLE_PITCH , DLG_FONT_NAME); |
| 4021 | if (s_usenewlook) |
| 4022 | oldFont = SelectFont(hdc, font); |
| 4023 | else |
| 4024 | oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT)); |
| 4025 | |
| 4026 | /* Calculate width of a single space. Used for padding columns to the |
| 4027 | * right width. */ |
| 4028 | spaceWidth = GetTextWidth(hdc, " ", 1); |
| 4029 | |
| 4030 | /* Figure out max width of the text column, the accelerator column and the |
| 4031 | * optional submenu column. */ |
| 4032 | submenuWidth = 0; |
| 4033 | for (col = 0; col < 2; col++) |
| 4034 | { |
| 4035 | columnWidths[col] = 0; |
| 4036 | for (pmenu = menu->children; pmenu != NULL; pmenu = pmenu->next) |
| 4037 | { |
| 4038 | /* Use "dname" here to compute the width of the visible text. */ |
| 4039 | text = (col == 0) ? pmenu->dname : pmenu->actext; |
| 4040 | if (text != NULL && *text != NUL) |
| 4041 | { |
| 4042 | textWidth = GetTextWidthEnc(hdc, text, (int)STRLEN(text)); |
| 4043 | if (textWidth > columnWidths[col]) |
| 4044 | columnWidths[col] = textWidth; |
| 4045 | } |
| 4046 | if (pmenu->children != NULL) |
| 4047 | submenuWidth = TEAROFF_COLUMN_PADDING * spaceWidth; |
| 4048 | } |
| 4049 | } |
| 4050 | if (columnWidths[1] == 0) |
| 4051 | { |
| 4052 | /* no accelerators */ |
| 4053 | if (submenuWidth != 0) |
| 4054 | columnWidths[0] += submenuWidth; |
| 4055 | else |
| 4056 | columnWidths[0] += spaceWidth; |
| 4057 | } |
| 4058 | else |
| 4059 | { |
| 4060 | /* there is an accelerator column */ |
| 4061 | columnWidths[0] += TEAROFF_COLUMN_PADDING * spaceWidth; |
| 4062 | columnWidths[1] += submenuWidth; |
| 4063 | } |
| 4064 | |
| 4065 | /* |
| 4066 | * Now find the total width of our 'menu'. |
| 4067 | */ |
| 4068 | textWidth = columnWidths[0] + columnWidths[1]; |
| 4069 | if (submenuWidth != 0) |
| 4070 | { |
| 4071 | submenuWidth = GetTextWidth(hdc, TEAROFF_SUBMENU_LABEL, |
| 4072 | (int)STRLEN(TEAROFF_SUBMENU_LABEL)); |
| 4073 | textWidth += submenuWidth; |
| 4074 | } |
| 4075 | dlgwidth = GetTextWidthEnc(hdc, title, (int)STRLEN(title)); |
| 4076 | if (textWidth > dlgwidth) |
| 4077 | dlgwidth = textWidth; |
| 4078 | dlgwidth += 2 * TEAROFF_PADDING_X + TEAROFF_BUTTON_PAD_X; |
| 4079 | |
| 4080 | /* W95 can't do thin dialogs, they look v. weird! */ |
| 4081 | if (mch_windows95() && dlgwidth < TEAROFF_MIN_WIDTH) |
| 4082 | dlgwidth = TEAROFF_MIN_WIDTH; |
| 4083 | |
| 4084 | /* start to fill in the dlgtemplate information. addressing by WORDs */ |
| 4085 | if (s_usenewlook) |
| 4086 | lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU |DS_SETFONT| WS_VISIBLE; |
| 4087 | else |
| 4088 | lStyle = DS_MODALFRAME | WS_CAPTION| WS_SYSMENU | WS_VISIBLE; |
| 4089 | |
| 4090 | lExtendedStyle = WS_EX_TOOLWINDOW|WS_EX_STATICEDGE; |
| 4091 | *p++ = LOWORD(lStyle); |
| 4092 | *p++ = HIWORD(lStyle); |
| 4093 | *p++ = LOWORD(lExtendedStyle); |
| 4094 | *p++ = HIWORD(lExtendedStyle); |
| 4095 | pnumitems = p; /* save where the number of items must be stored */ |
| 4096 | *p++ = 0; // NumberOfItems(will change later) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 4097 | gui_mch_getmouse(&x, &y); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4098 | if (initX == 0xffffL) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 4099 | *p++ = PixelToDialogX(x); // x |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4100 | else |
| 4101 | *p++ = PixelToDialogX(initX); // x |
| 4102 | if (initY == 0xffffL) |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 4103 | *p++ = PixelToDialogY(y); // y |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4104 | else |
| 4105 | *p++ = PixelToDialogY(initY); // y |
| 4106 | *p++ = PixelToDialogX(dlgwidth); // cx |
| 4107 | ptrueheight = p; |
| 4108 | *p++ = 0; // dialog height: changed later anyway |
| 4109 | *p++ = 0; // Menu |
| 4110 | *p++ = 0; // Class |
| 4111 | |
| 4112 | /* copy the title of the dialog */ |
| 4113 | nchar = nCopyAnsiToWideChar(p, ((*title) |
| 4114 | ? (LPSTR)title |
| 4115 | : (LPSTR)("Vim "VIM_VERSION_MEDIUM))); |
| 4116 | p += nchar; |
| 4117 | |
| 4118 | if (s_usenewlook) |
| 4119 | { |
| 4120 | /* do the font, since DS_3DLOOK doesn't work properly */ |
| 4121 | #ifdef USE_SYSMENU_FONT |
| 4122 | if (use_lfSysmenu) |
| 4123 | { |
| 4124 | /* point size */ |
| 4125 | *p++ = -MulDiv(lfSysmenu.lfHeight, 72, |
| 4126 | GetDeviceCaps(hdc, LOGPIXELSY)); |
| 4127 | nchar = nCopyAnsiToWideChar(p, TEXT(lfSysmenu.lfFaceName)); |
| 4128 | } |
| 4129 | else |
| 4130 | #endif |
| 4131 | { |
| 4132 | *p++ = DLG_FONT_POINT_SIZE; // point size |
| 4133 | nchar = nCopyAnsiToWideChar (p, TEXT(DLG_FONT_NAME)); |
| 4134 | } |
| 4135 | p += nchar; |
| 4136 | } |
| 4137 | |
| 4138 | /* |
| 4139 | * Loop over all the items in the menu. |
| 4140 | * But skip over the tearbar. |
| 4141 | */ |
| 4142 | if (STRCMP(menu->children->name, TEAR_STRING) == 0) |
| 4143 | menu = menu->children->next; |
| 4144 | else |
| 4145 | menu = menu->children; |
| 4146 | for ( ; menu != NULL; menu = menu->next) |
| 4147 | { |
| 4148 | if (menu->modes == 0) /* this menu has just been deleted */ |
| 4149 | continue; |
| 4150 | if (menu_is_separator(menu->dname)) |
| 4151 | { |
| 4152 | sepPadding += 3; |
| 4153 | continue; |
| 4154 | } |
| 4155 | |
| 4156 | /* Check if there still is plenty of room in the template. Make it |
| 4157 | * larger when needed. */ |
| 4158 | if (((char *)p - (char *)pdlgtemplate) + 1000 > template_len) |
| 4159 | { |
| 4160 | WORD *newp; |
| 4161 | |
| 4162 | newp = (WORD *)LocalAlloc(LPTR, template_len + 4096); |
| 4163 | if (newp != NULL) |
| 4164 | { |
| 4165 | template_len += 4096; |
| 4166 | mch_memmove(newp, pdlgtemplate, |
| 4167 | (char *)p - (char *)pdlgtemplate); |
| 4168 | p = newp + (p - pdlgtemplate); |
| 4169 | pnumitems = newp + (pnumitems - pdlgtemplate); |
| 4170 | ptrueheight = newp + (ptrueheight - pdlgtemplate); |
| 4171 | LocalFree(LocalHandle(pdlgtemplate)); |
| 4172 | pdlgtemplate = newp; |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | /* Figure out minimal length of this menu label. Use "name" for the |
| 4177 | * actual text, "dname" for estimating the displayed size. "name" |
| 4178 | * has "&a" for mnemonic and includes the accelerator. */ |
| 4179 | len = nameLen = (int)STRLEN(menu->name); |
| 4180 | padding0 = (columnWidths[0] - GetTextWidthEnc(hdc, menu->dname, |
| 4181 | (int)STRLEN(menu->dname))) / spaceWidth; |
| 4182 | len += padding0; |
| 4183 | |
| 4184 | if (menu->actext != NULL) |
| 4185 | { |
| 4186 | acLen = (int)STRLEN(menu->actext); |
| 4187 | len += acLen; |
| 4188 | textWidth = GetTextWidthEnc(hdc, menu->actext, acLen); |
| 4189 | } |
| 4190 | else |
| 4191 | textWidth = 0; |
| 4192 | padding1 = (columnWidths[1] - textWidth) / spaceWidth; |
| 4193 | len += padding1; |
| 4194 | |
| 4195 | if (menu->children == NULL) |
| 4196 | { |
| 4197 | padding2 = submenuWidth / spaceWidth; |
| 4198 | len += padding2; |
| 4199 | menuID = (WORD)(menu->id); |
| 4200 | } |
| 4201 | else |
| 4202 | { |
| 4203 | len += (int)STRLEN(TEAROFF_SUBMENU_LABEL); |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4204 | menuID = (WORD)((long_u)(menu->submenu_id) | (DWORD)0x8000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | /* Allocate menu label and fill it in */ |
| 4208 | text = label = alloc((unsigned)len + 1); |
| 4209 | if (label == NULL) |
| 4210 | break; |
| 4211 | |
Bram Moolenaar | ce0842a | 2005-07-18 21:58:11 +0000 | [diff] [blame] | 4212 | vim_strncpy(text, menu->name, nameLen); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4213 | text = vim_strchr(text, TAB); /* stop at TAB before actext */ |
| 4214 | if (text == NULL) |
| 4215 | text = label + nameLen; /* no actext, use whole name */ |
| 4216 | while (padding0-- > 0) |
| 4217 | *text++ = ' '; |
| 4218 | if (menu->actext != NULL) |
| 4219 | { |
| 4220 | STRNCPY(text, menu->actext, acLen); |
| 4221 | text += acLen; |
| 4222 | } |
| 4223 | while (padding1-- > 0) |
| 4224 | *text++ = ' '; |
| 4225 | if (menu->children != NULL) |
| 4226 | { |
| 4227 | STRCPY(text, TEAROFF_SUBMENU_LABEL); |
| 4228 | text += STRLEN(TEAROFF_SUBMENU_LABEL); |
| 4229 | } |
| 4230 | else |
| 4231 | { |
| 4232 | while (padding2-- > 0) |
| 4233 | *text++ = ' '; |
| 4234 | } |
| 4235 | *text = NUL; |
| 4236 | |
| 4237 | /* |
| 4238 | * BS_LEFT will just be ignored on Win32s/NT3.5x - on |
| 4239 | * W95/NT4 it makes the tear-off look more like a menu. |
| 4240 | */ |
| 4241 | p = add_dialog_element(p, |
| 4242 | BS_PUSHBUTTON|BS_LEFT, |
| 4243 | (WORD)PixelToDialogX(TEAROFF_PADDING_X), |
| 4244 | (WORD)(sepPadding + 1 + 13 * (*pnumitems)), |
| 4245 | (WORD)PixelToDialogX(dlgwidth - 2 * TEAROFF_PADDING_X), |
| 4246 | (WORD)12, |
| 4247 | menuID, (WORD)0x0080, label); |
| 4248 | vim_free(label); |
| 4249 | (*pnumitems)++; |
| 4250 | } |
| 4251 | |
| 4252 | *ptrueheight = (WORD)(sepPadding + 1 + 13 * (*pnumitems)); |
| 4253 | |
| 4254 | |
| 4255 | /* show modelessly */ |
| 4256 | the_menu->tearoff_handle = CreateDialogIndirect( |
| 4257 | s_hinst, |
| 4258 | (LPDLGTEMPLATE)pdlgtemplate, |
| 4259 | s_hwnd, |
| 4260 | (DLGPROC)tearoff_callback); |
| 4261 | |
| 4262 | LocalFree(LocalHandle(pdlgtemplate)); |
| 4263 | SelectFont(hdc, oldFont); |
| 4264 | DeleteObject(font); |
| 4265 | ReleaseDC(hwnd, hdc); |
| 4266 | |
| 4267 | /* |
| 4268 | * Reassert ourselves as the active window. This is so that after creating |
| 4269 | * a tearoff, the user doesn't have to click with the mouse just to start |
| 4270 | * typing again! |
| 4271 | */ |
| 4272 | (void)SetActiveWindow(s_hwnd); |
| 4273 | |
| 4274 | /* make sure the right buttons are enabled */ |
| 4275 | force_menu_update = TRUE; |
| 4276 | } |
| 4277 | #endif |
| 4278 | |
| 4279 | #if defined(FEAT_TOOLBAR) || defined(PROTO) |
| 4280 | #include "gui_w32_rc.h" |
| 4281 | |
| 4282 | /* This not defined in older SDKs */ |
| 4283 | # ifndef TBSTYLE_FLAT |
| 4284 | # define TBSTYLE_FLAT 0x0800 |
| 4285 | # endif |
| 4286 | |
| 4287 | /* |
| 4288 | * Create the toolbar, initially unpopulated. |
| 4289 | * (just like the menu, there are no defaults, it's all |
| 4290 | * set up through menu.vim) |
| 4291 | */ |
| 4292 | static void |
| 4293 | initialise_toolbar(void) |
| 4294 | { |
| 4295 | InitCommonControls(); |
| 4296 | s_toolbarhwnd = CreateToolbarEx( |
| 4297 | s_hwnd, |
| 4298 | WS_CHILD | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT, |
| 4299 | 4000, //any old big number |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 4300 | 31, //number of images in initial bitmap |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4301 | s_hinst, |
| 4302 | IDR_TOOLBAR1, // id of initial bitmap |
| 4303 | NULL, |
| 4304 | 0, // initial number of buttons |
| 4305 | TOOLBAR_BUTTON_WIDTH, //api guide is wrong! |
| 4306 | TOOLBAR_BUTTON_HEIGHT, |
| 4307 | TOOLBAR_BUTTON_WIDTH, |
| 4308 | TOOLBAR_BUTTON_HEIGHT, |
| 4309 | sizeof(TBBUTTON) |
| 4310 | ); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4311 | s_toolbar_wndproc = SubclassWindow(s_toolbarhwnd, toolbar_wndproc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4312 | |
| 4313 | gui_mch_show_toolbar(vim_strchr(p_go, GO_TOOLBAR) != NULL); |
| 4314 | } |
| 4315 | |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4316 | static LRESULT CALLBACK |
| 4317 | toolbar_wndproc( |
| 4318 | HWND hwnd, |
| 4319 | UINT uMsg, |
| 4320 | WPARAM wParam, |
| 4321 | LPARAM lParam) |
| 4322 | { |
| 4323 | HandleMouseHide(uMsg, lParam); |
| 4324 | return CallWindowProc(s_toolbar_wndproc, hwnd, uMsg, wParam, lParam); |
| 4325 | } |
| 4326 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4327 | static int |
| 4328 | get_toolbar_bitmap(vimmenu_T *menu) |
| 4329 | { |
| 4330 | int i = -1; |
| 4331 | |
| 4332 | /* |
| 4333 | * Check user bitmaps first, unless builtin is specified. |
| 4334 | */ |
| 4335 | if (!is_winnt_3() && !menu->icon_builtin) |
| 4336 | { |
| 4337 | char_u fname[MAXPATHL]; |
| 4338 | HANDLE hbitmap = NULL; |
| 4339 | |
| 4340 | if (menu->iconfile != NULL) |
| 4341 | { |
| 4342 | gui_find_iconfile(menu->iconfile, fname, "bmp"); |
| 4343 | hbitmap = LoadImage( |
| 4344 | NULL, |
| 4345 | fname, |
| 4346 | IMAGE_BITMAP, |
| 4347 | TOOLBAR_BUTTON_WIDTH, |
| 4348 | TOOLBAR_BUTTON_HEIGHT, |
| 4349 | LR_LOADFROMFILE | |
| 4350 | LR_LOADMAP3DCOLORS |
| 4351 | ); |
| 4352 | } |
| 4353 | |
| 4354 | /* |
| 4355 | * If the LoadImage call failed, or the "icon=" file |
| 4356 | * didn't exist or wasn't specified, try the menu name |
| 4357 | */ |
| 4358 | if (hbitmap == NULL |
Bram Moolenaar | a5f5c8b | 2013-06-27 22:29:38 +0200 | [diff] [blame] | 4359 | && (gui_find_bitmap( |
| 4360 | #ifdef FEAT_MULTI_LANG |
| 4361 | menu->en_dname != NULL ? menu->en_dname : |
| 4362 | #endif |
| 4363 | menu->dname, fname, "bmp") == OK)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4364 | hbitmap = LoadImage( |
| 4365 | NULL, |
| 4366 | fname, |
| 4367 | IMAGE_BITMAP, |
| 4368 | TOOLBAR_BUTTON_WIDTH, |
| 4369 | TOOLBAR_BUTTON_HEIGHT, |
| 4370 | LR_LOADFROMFILE | |
| 4371 | LR_LOADMAP3DCOLORS |
| 4372 | ); |
| 4373 | |
| 4374 | if (hbitmap != NULL) |
| 4375 | { |
| 4376 | TBADDBITMAP tbAddBitmap; |
| 4377 | |
| 4378 | tbAddBitmap.hInst = NULL; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4379 | tbAddBitmap.nID = (long_u)hbitmap; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4380 | |
| 4381 | i = (int)SendMessage(s_toolbarhwnd, TB_ADDBITMAP, |
| 4382 | (WPARAM)1, (LPARAM)&tbAddBitmap); |
| 4383 | /* i will be set to -1 if it fails */ |
| 4384 | } |
| 4385 | } |
| 4386 | if (i == -1 && menu->iconidx >= 0 && menu->iconidx < TOOLBAR_BITMAP_COUNT) |
| 4387 | i = menu->iconidx; |
| 4388 | |
| 4389 | return i; |
| 4390 | } |
| 4391 | #endif |
| 4392 | |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4393 | #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
| 4394 | static void |
| 4395 | initialise_tabline(void) |
| 4396 | { |
| 4397 | InitCommonControls(); |
| 4398 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4399 | s_tabhwnd = CreateWindow(WC_TABCONTROL, "Vim tabline", |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4400 | WS_CHILD|TCS_FOCUSNEVER|TCS_TOOLTIPS, |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4401 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 4402 | CW_USEDEFAULT, s_hwnd, NULL, s_hinst, NULL); |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4403 | s_tabline_wndproc = SubclassWindow(s_tabhwnd, tabline_wndproc); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4404 | |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4405 | gui.tabline_height = TABLINE_HEIGHT; |
| 4406 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4407 | # ifdef USE_SYSMENU_FONT |
Bram Moolenaar | 551dbcc | 2006-04-25 22:13:59 +0000 | [diff] [blame] | 4408 | set_tabline_font(); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4409 | # endif |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4410 | } |
Bram Moolenaar | 5f919ee | 2013-07-21 17:46:43 +0200 | [diff] [blame] | 4411 | |
| 4412 | static LRESULT CALLBACK |
| 4413 | tabline_wndproc( |
| 4414 | HWND hwnd, |
| 4415 | UINT uMsg, |
| 4416 | WPARAM wParam, |
| 4417 | LPARAM lParam) |
| 4418 | { |
| 4419 | HandleMouseHide(uMsg, lParam); |
| 4420 | return CallWindowProc(s_tabline_wndproc, hwnd, uMsg, wParam, lParam); |
| 4421 | } |
Bram Moolenaar | 3991dab | 2006-03-27 17:01:56 +0000 | [diff] [blame] | 4422 | #endif |
| 4423 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4424 | #if defined(FEAT_OLE) || defined(FEAT_EVAL) || defined(PROTO) |
| 4425 | /* |
| 4426 | * Make the GUI window come to the foreground. |
| 4427 | */ |
| 4428 | void |
| 4429 | gui_mch_set_foreground(void) |
| 4430 | { |
| 4431 | if (IsIconic(s_hwnd)) |
| 4432 | SendMessage(s_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); |
| 4433 | SetForegroundWindow(s_hwnd); |
| 4434 | } |
| 4435 | #endif |
| 4436 | |
| 4437 | #if defined(FEAT_MBYTE_IME) && defined(DYNAMIC_IME) |
| 4438 | static void |
| 4439 | dyn_imm_load(void) |
| 4440 | { |
Bram Moolenaar | ebbcb82 | 2010-10-23 14:02:54 +0200 | [diff] [blame] | 4441 | hLibImm = vimLoadLib("imm32.dll"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4442 | if (hLibImm == NULL) |
| 4443 | return; |
| 4444 | |
| 4445 | pImmGetCompositionStringA |
| 4446 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringA"); |
| 4447 | pImmGetCompositionStringW |
| 4448 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionStringW"); |
| 4449 | pImmGetContext |
| 4450 | = (void *)GetProcAddress(hLibImm, "ImmGetContext"); |
| 4451 | pImmAssociateContext |
| 4452 | = (void *)GetProcAddress(hLibImm, "ImmAssociateContext"); |
| 4453 | pImmReleaseContext |
| 4454 | = (void *)GetProcAddress(hLibImm, "ImmReleaseContext"); |
| 4455 | pImmGetOpenStatus |
| 4456 | = (void *)GetProcAddress(hLibImm, "ImmGetOpenStatus"); |
| 4457 | pImmSetOpenStatus |
| 4458 | = (void *)GetProcAddress(hLibImm, "ImmSetOpenStatus"); |
| 4459 | pImmGetCompositionFont |
| 4460 | = (void *)GetProcAddress(hLibImm, "ImmGetCompositionFontA"); |
| 4461 | pImmSetCompositionFont |
| 4462 | = (void *)GetProcAddress(hLibImm, "ImmSetCompositionFontA"); |
| 4463 | pImmSetCompositionWindow |
| 4464 | = (void *)GetProcAddress(hLibImm, "ImmSetCompositionWindow"); |
| 4465 | pImmGetConversionStatus |
| 4466 | = (void *)GetProcAddress(hLibImm, "ImmGetConversionStatus"); |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4467 | pImmSetConversionStatus |
| 4468 | = (void *)GetProcAddress(hLibImm, "ImmSetConversionStatus"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4469 | |
| 4470 | if ( pImmGetCompositionStringA == NULL |
| 4471 | || pImmGetCompositionStringW == NULL |
| 4472 | || pImmGetContext == NULL |
| 4473 | || pImmAssociateContext == NULL |
| 4474 | || pImmReleaseContext == NULL |
| 4475 | || pImmGetOpenStatus == NULL |
| 4476 | || pImmSetOpenStatus == NULL |
| 4477 | || pImmGetCompositionFont == NULL |
| 4478 | || pImmSetCompositionFont == NULL |
| 4479 | || pImmSetCompositionWindow == NULL |
Bram Moolenaar | ca003e1 | 2006-03-17 23:19:38 +0000 | [diff] [blame] | 4480 | || pImmGetConversionStatus == NULL |
| 4481 | || pImmSetConversionStatus == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4482 | { |
| 4483 | FreeLibrary(hLibImm); |
| 4484 | hLibImm = NULL; |
| 4485 | pImmGetContext = NULL; |
| 4486 | return; |
| 4487 | } |
| 4488 | |
| 4489 | return; |
| 4490 | } |
| 4491 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4492 | #endif |
| 4493 | |
| 4494 | #if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
| 4495 | |
| 4496 | # ifdef FEAT_XPM_W32 |
| 4497 | # define IMAGE_XPM 100 |
| 4498 | # endif |
| 4499 | |
| 4500 | typedef struct _signicon_t |
| 4501 | { |
| 4502 | HANDLE hImage; |
| 4503 | UINT uType; |
| 4504 | #ifdef FEAT_XPM_W32 |
| 4505 | HANDLE hShape; /* Mask bitmap handle */ |
| 4506 | #endif |
| 4507 | } signicon_t; |
| 4508 | |
| 4509 | void |
| 4510 | gui_mch_drawsign(row, col, typenr) |
| 4511 | int row; |
| 4512 | int col; |
| 4513 | int typenr; |
| 4514 | { |
| 4515 | signicon_t *sign; |
| 4516 | int x, y, w, h; |
| 4517 | |
| 4518 | if (!gui.in_use || (sign = (signicon_t *)sign_get_image(typenr)) == NULL) |
| 4519 | return; |
| 4520 | |
| 4521 | x = TEXT_X(col); |
| 4522 | y = TEXT_Y(row); |
| 4523 | w = gui.char_width * 2; |
| 4524 | h = gui.char_height; |
| 4525 | switch (sign->uType) |
| 4526 | { |
| 4527 | case IMAGE_BITMAP: |
| 4528 | { |
| 4529 | HDC hdcMem; |
| 4530 | HBITMAP hbmpOld; |
| 4531 | |
| 4532 | hdcMem = CreateCompatibleDC(s_hdc); |
| 4533 | hbmpOld = (HBITMAP)SelectObject(hdcMem, sign->hImage); |
| 4534 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCCOPY); |
| 4535 | SelectObject(hdcMem, hbmpOld); |
| 4536 | DeleteDC(hdcMem); |
| 4537 | } |
| 4538 | break; |
| 4539 | case IMAGE_ICON: |
| 4540 | case IMAGE_CURSOR: |
| 4541 | DrawIconEx(s_hdc, x, y, (HICON)sign->hImage, w, h, 0, NULL, DI_NORMAL); |
| 4542 | break; |
| 4543 | #ifdef FEAT_XPM_W32 |
| 4544 | case IMAGE_XPM: |
| 4545 | { |
| 4546 | HDC hdcMem; |
| 4547 | HBITMAP hbmpOld; |
| 4548 | |
| 4549 | hdcMem = CreateCompatibleDC(s_hdc); |
| 4550 | hbmpOld = (HBITMAP)SelectObject(hdcMem, sign->hShape); |
| 4551 | /* Make hole */ |
| 4552 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCAND); |
| 4553 | |
| 4554 | SelectObject(hdcMem, sign->hImage); |
| 4555 | /* Paint sign */ |
| 4556 | BitBlt(s_hdc, x, y, w, h, hdcMem, 0, 0, SRCPAINT); |
| 4557 | SelectObject(hdcMem, hbmpOld); |
| 4558 | DeleteDC(hdcMem); |
| 4559 | } |
| 4560 | break; |
| 4561 | #endif |
| 4562 | } |
| 4563 | } |
| 4564 | |
| 4565 | static void |
| 4566 | close_signicon_image(signicon_t *sign) |
| 4567 | { |
| 4568 | if (sign) |
| 4569 | switch (sign->uType) |
| 4570 | { |
| 4571 | case IMAGE_BITMAP: |
| 4572 | DeleteObject((HGDIOBJ)sign->hImage); |
| 4573 | break; |
| 4574 | case IMAGE_CURSOR: |
| 4575 | DestroyCursor((HCURSOR)sign->hImage); |
| 4576 | break; |
| 4577 | case IMAGE_ICON: |
| 4578 | DestroyIcon((HICON)sign->hImage); |
| 4579 | break; |
| 4580 | #ifdef FEAT_XPM_W32 |
| 4581 | case IMAGE_XPM: |
| 4582 | DeleteObject((HBITMAP)sign->hImage); |
| 4583 | DeleteObject((HBITMAP)sign->hShape); |
| 4584 | break; |
| 4585 | #endif |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | void * |
| 4590 | gui_mch_register_sign(signfile) |
| 4591 | char_u *signfile; |
| 4592 | { |
| 4593 | signicon_t sign, *psign; |
| 4594 | char_u *ext; |
| 4595 | |
| 4596 | if (is_winnt_3()) |
| 4597 | { |
| 4598 | EMSG(_(e_signdata)); |
| 4599 | return NULL; |
| 4600 | } |
| 4601 | |
| 4602 | sign.hImage = NULL; |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4603 | ext = signfile + STRLEN(signfile) - 4; /* get extension */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4604 | if (ext > signfile) |
| 4605 | { |
| 4606 | int do_load = 1; |
| 4607 | |
| 4608 | if (!STRICMP(ext, ".bmp")) |
| 4609 | sign.uType = IMAGE_BITMAP; |
| 4610 | else if (!STRICMP(ext, ".ico")) |
| 4611 | sign.uType = IMAGE_ICON; |
| 4612 | else if (!STRICMP(ext, ".cur") || !STRICMP(ext, ".ani")) |
| 4613 | sign.uType = IMAGE_CURSOR; |
| 4614 | else |
| 4615 | do_load = 0; |
| 4616 | |
| 4617 | if (do_load) |
| 4618 | sign.hImage = (HANDLE)LoadImage(NULL, signfile, sign.uType, |
| 4619 | gui.char_width * 2, gui.char_height, |
| 4620 | LR_LOADFROMFILE | LR_CREATEDIBSECTION); |
| 4621 | #ifdef FEAT_XPM_W32 |
| 4622 | if (!STRICMP(ext, ".xpm")) |
| 4623 | { |
| 4624 | sign.uType = IMAGE_XPM; |
| 4625 | LoadXpmImage(signfile, (HBITMAP *)&sign.hImage, (HBITMAP *)&sign.hShape); |
| 4626 | } |
| 4627 | #endif |
| 4628 | } |
| 4629 | |
| 4630 | psign = NULL; |
| 4631 | if (sign.hImage && (psign = (signicon_t *)alloc(sizeof(signicon_t))) |
| 4632 | != NULL) |
| 4633 | *psign = sign; |
| 4634 | |
| 4635 | if (!psign) |
| 4636 | { |
| 4637 | if (sign.hImage) |
| 4638 | close_signicon_image(&sign); |
| 4639 | EMSG(_(e_signdata)); |
| 4640 | } |
| 4641 | return (void *)psign; |
| 4642 | |
| 4643 | } |
| 4644 | |
| 4645 | void |
| 4646 | gui_mch_destroy_sign(sign) |
| 4647 | void *sign; |
| 4648 | { |
| 4649 | if (sign) |
| 4650 | { |
| 4651 | close_signicon_image((signicon_t *)sign); |
| 4652 | vim_free(sign); |
| 4653 | } |
| 4654 | } |
Bram Moolenaar | 5c06f8b | 2005-05-31 22:14:58 +0000 | [diff] [blame] | 4655 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4656 | |
| 4657 | #if defined(FEAT_BEVAL) || defined(PROTO) |
| 4658 | |
| 4659 | /* BALLOON-EVAL IMPLEMENTATION FOR WINDOWS. |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 4660 | * Added by Sergey Khorev <sergey.khorev@gmail.com> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4661 | * |
Bram Moolenaar | e4efc3b | 2005-03-07 23:16:51 +0000 | [diff] [blame] | 4662 | * The only reused thing is gui_beval.h and get_beval_info() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4663 | * from gui_beval.c (note it uses x and y of the BalloonEval struct |
| 4664 | * to get current mouse position). |
| 4665 | * |
| 4666 | * Trying to use as more Windows services as possible, and as less |
| 4667 | * IE version as possible :)). |
| 4668 | * |
| 4669 | * 1) Don't create ToolTip in gui_mch_create_beval_area, only initialize |
| 4670 | * BalloonEval struct. |
| 4671 | * 2) Enable/Disable simply create/kill BalloonEval Timer |
| 4672 | * 3) When there was enough inactivity, timer procedure posts |
| 4673 | * async request to debugger |
| 4674 | * 4) gui_mch_post_balloon (invoked from netbeans.c) creates tooltip control |
| 4675 | * and performs some actions to show it ASAP |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 4676 | * 5) WM_NOTIFY:TTN_POP destroys created tooltip |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4677 | */ |
| 4678 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4679 | /* |
| 4680 | * determine whether installed Common Controls support multiline tooltips |
| 4681 | * (i.e. their version is >= 4.70 |
| 4682 | */ |
| 4683 | int |
| 4684 | multiline_balloon_available(void) |
| 4685 | { |
| 4686 | HINSTANCE hDll; |
| 4687 | static char comctl_dll[] = "comctl32.dll"; |
| 4688 | static int multiline_tip = MAYBE; |
| 4689 | |
| 4690 | if (multiline_tip != MAYBE) |
| 4691 | return multiline_tip; |
| 4692 | |
| 4693 | hDll = GetModuleHandle(comctl_dll); |
| 4694 | if (hDll != NULL) |
| 4695 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4696 | DLLGETVERSIONPROC pGetVer; |
| 4697 | pGetVer = (DLLGETVERSIONPROC)GetProcAddress(hDll, "DllGetVersion"); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4698 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4699 | if (pGetVer != NULL) |
| 4700 | { |
| 4701 | DLLVERSIONINFO dvi; |
| 4702 | HRESULT hr; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4703 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4704 | ZeroMemory(&dvi, sizeof(dvi)); |
| 4705 | dvi.cbSize = sizeof(dvi); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4706 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4707 | hr = (*pGetVer)(&dvi); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4708 | |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4709 | if (SUCCEEDED(hr) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4710 | && (dvi.dwMajorVersion > 4 |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4711 | || (dvi.dwMajorVersion == 4 |
| 4712 | && dvi.dwMinorVersion >= 70))) |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4713 | { |
| 4714 | multiline_tip = TRUE; |
| 4715 | return multiline_tip; |
| 4716 | } |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 4717 | } |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4718 | else |
| 4719 | { |
| 4720 | /* there is chance we have ancient CommCtl 4.70 |
| 4721 | which doesn't export DllGetVersion */ |
| 4722 | DWORD dwHandle = 0; |
| 4723 | DWORD len = GetFileVersionInfoSize(comctl_dll, &dwHandle); |
| 4724 | if (len > 0) |
| 4725 | { |
| 4726 | VS_FIXEDFILEINFO *ver; |
| 4727 | UINT vlen = 0; |
| 4728 | void *data = alloc(len); |
| 4729 | |
| 4730 | if (data != NULL |
| 4731 | && GetFileVersionInfo(comctl_dll, 0, len, data) |
| 4732 | && VerQueryValue(data, "\\", (void **)&ver, &vlen) |
| 4733 | && vlen |
| 4734 | && HIWORD(ver->dwFileVersionMS) > 4 |
| 4735 | || (HIWORD(ver->dwFileVersionMS) == 4 |
| 4736 | && LOWORD(ver->dwFileVersionMS) >= 70)) |
| 4737 | { |
| 4738 | vim_free(data); |
| 4739 | multiline_tip = TRUE; |
| 4740 | return multiline_tip; |
| 4741 | } |
| 4742 | vim_free(data); |
| 4743 | } |
| 4744 | } |
| 4745 | } |
| 4746 | multiline_tip = FALSE; |
| 4747 | return multiline_tip; |
| 4748 | } |
| 4749 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4750 | static void |
| 4751 | make_tooltip(beval, text, pt) |
| 4752 | BalloonEval *beval; |
| 4753 | char *text; |
| 4754 | POINT pt; |
| 4755 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4756 | TOOLINFO *pti; |
| 4757 | int ToolInfoSize; |
| 4758 | |
| 4759 | if (multiline_balloon_available() == TRUE) |
| 4760 | ToolInfoSize = sizeof(TOOLINFO_NEW); |
| 4761 | else |
| 4762 | ToolInfoSize = sizeof(TOOLINFO); |
| 4763 | |
| 4764 | pti = (TOOLINFO *)alloc(ToolInfoSize); |
| 4765 | if (pti == NULL) |
| 4766 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4767 | |
| 4768 | beval->balloon = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, |
| 4769 | NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, |
| 4770 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
| 4771 | beval->target, NULL, s_hinst, NULL); |
| 4772 | |
| 4773 | SetWindowPos(beval->balloon, HWND_TOPMOST, 0, 0, 0, 0, |
| 4774 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); |
| 4775 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4776 | pti->cbSize = ToolInfoSize; |
| 4777 | pti->uFlags = TTF_SUBCLASS; |
| 4778 | pti->hwnd = beval->target; |
| 4779 | pti->hinst = 0; /* Don't use string resources */ |
| 4780 | pti->uId = ID_BEVAL_TOOLTIP; |
| 4781 | |
| 4782 | if (multiline_balloon_available() == TRUE) |
| 4783 | { |
| 4784 | RECT rect; |
| 4785 | TOOLINFO_NEW *ptin = (TOOLINFO_NEW *)pti; |
| 4786 | pti->lpszText = LPSTR_TEXTCALLBACK; |
| 4787 | ptin->lParam = (LPARAM)text; |
| 4788 | if (GetClientRect(s_textArea, &rect)) /* switch multiline tooltips on */ |
| 4789 | SendMessage(beval->balloon, TTM_SETMAXTIPWIDTH, 0, |
| 4790 | (LPARAM)rect.right); |
| 4791 | } |
| 4792 | else |
| 4793 | pti->lpszText = text; /* do this old way */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4794 | |
| 4795 | /* Limit ballooneval bounding rect to CursorPos neighbourhood */ |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4796 | pti->rect.left = pt.x - 3; |
| 4797 | pti->rect.top = pt.y - 3; |
| 4798 | pti->rect.right = pt.x + 3; |
| 4799 | pti->rect.bottom = pt.y + 3; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4800 | |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4801 | SendMessage(beval->balloon, TTM_ADDTOOL, 0, (LPARAM)pti); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4802 | /* Make tooltip appear sooner */ |
| 4803 | SendMessage(beval->balloon, TTM_SETDELAYTIME, TTDT_INITIAL, 10); |
Bram Moolenaar | b52e532 | 2008-01-05 12:15:52 +0000 | [diff] [blame] | 4804 | /* I've performed some tests and it seems the longest possible life time |
| 4805 | * of tooltip is 30 seconds */ |
| 4806 | SendMessage(beval->balloon, TTM_SETDELAYTIME, TTDT_AUTOPOP, 30000); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4807 | /* |
| 4808 | * HACK: force tooltip to appear, because it'll not appear until |
| 4809 | * first mouse move. D*mn M$ |
Bram Moolenaar | b52e532 | 2008-01-05 12:15:52 +0000 | [diff] [blame] | 4810 | * Amazingly moving (2, 2) and then (-1, -1) the mouse doesn't move. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4811 | */ |
Bram Moolenaar | b52e532 | 2008-01-05 12:15:52 +0000 | [diff] [blame] | 4812 | mouse_event(MOUSEEVENTF_MOVE, 2, 2, 0, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4813 | mouse_event(MOUSEEVENTF_MOVE, (DWORD)-1, (DWORD)-1, 0, 0); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4814 | vim_free(pti); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | static void |
| 4818 | delete_tooltip(beval) |
| 4819 | BalloonEval *beval; |
| 4820 | { |
| 4821 | DestroyWindow(beval->balloon); |
| 4822 | } |
| 4823 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4824 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4825 | static VOID CALLBACK |
| 4826 | BevalTimerProc(hwnd, uMsg, idEvent, dwTime) |
| 4827 | HWND hwnd; |
| 4828 | UINT uMsg; |
Bram Moolenaar | eb3593b | 2006-04-22 22:33:57 +0000 | [diff] [blame] | 4829 | UINT_PTR idEvent; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4830 | DWORD dwTime; |
| 4831 | { |
| 4832 | POINT pt; |
| 4833 | RECT rect; |
| 4834 | |
| 4835 | if (cur_beval == NULL || cur_beval->showState == ShS_SHOWING || !p_beval) |
| 4836 | return; |
| 4837 | |
| 4838 | GetCursorPos(&pt); |
| 4839 | if (WindowFromPoint(pt) != s_textArea) |
| 4840 | return; |
| 4841 | |
| 4842 | ScreenToClient(s_textArea, &pt); |
| 4843 | GetClientRect(s_textArea, &rect); |
| 4844 | if (!PtInRect(&rect, pt)) |
| 4845 | return; |
| 4846 | |
| 4847 | if (LastActivity > 0 |
| 4848 | && (dwTime - LastActivity) >= (DWORD)p_bdlay |
| 4849 | && (cur_beval->showState != ShS_PENDING |
| 4850 | || abs(cur_beval->x - pt.x) > 3 |
| 4851 | || abs(cur_beval->y - pt.y) > 3)) |
| 4852 | { |
| 4853 | /* Pointer resting in one place long enough, it's time to show |
| 4854 | * the tooltip. */ |
| 4855 | cur_beval->showState = ShS_PENDING; |
| 4856 | cur_beval->x = pt.x; |
| 4857 | cur_beval->y = pt.y; |
| 4858 | |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4859 | // TRACE0("BevalTimerProc: sending request"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4860 | |
| 4861 | if (cur_beval->msgCB != NULL) |
| 4862 | (*cur_beval->msgCB)(cur_beval, 0); |
| 4863 | } |
| 4864 | } |
| 4865 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4866 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4867 | void |
| 4868 | gui_mch_disable_beval_area(beval) |
| 4869 | BalloonEval *beval; |
| 4870 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4871 | // TRACE0("gui_mch_disable_beval_area {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4872 | KillTimer(s_textArea, BevalTimerId); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4873 | // TRACE0("gui_mch_disable_beval_area }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4876 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4877 | void |
| 4878 | gui_mch_enable_beval_area(beval) |
| 4879 | BalloonEval *beval; |
| 4880 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4881 | // TRACE0("gui_mch_enable_beval_area |||"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4882 | if (beval == NULL) |
| 4883 | return; |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4884 | // TRACE0("gui_mch_enable_beval_area {{{"); |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 4885 | BevalTimerId = SetTimer(s_textArea, 0, (UINT)(p_bdlay / 2), BevalTimerProc); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4886 | // TRACE0("gui_mch_enable_beval_area }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4887 | } |
| 4888 | |
| 4889 | void |
| 4890 | gui_mch_post_balloon(beval, mesg) |
| 4891 | BalloonEval *beval; |
| 4892 | char_u *mesg; |
| 4893 | { |
| 4894 | POINT pt; |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4895 | // TRACE0("gui_mch_post_balloon {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4896 | if (beval->showState == ShS_SHOWING) |
| 4897 | return; |
| 4898 | GetCursorPos(&pt); |
| 4899 | ScreenToClient(s_textArea, &pt); |
| 4900 | |
| 4901 | if (abs(beval->x - pt.x) < 3 && abs(beval->y - pt.y) < 3) |
| 4902 | /* cursor is still here */ |
| 4903 | { |
| 4904 | gui_mch_disable_beval_area(cur_beval); |
| 4905 | beval->showState = ShS_SHOWING; |
| 4906 | make_tooltip(beval, mesg, pt); |
| 4907 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4908 | // TRACE0("gui_mch_post_balloon }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4909 | } |
| 4910 | |
Bram Moolenaar | d857f0e | 2005-06-21 22:37:39 +0000 | [diff] [blame] | 4911 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4912 | BalloonEval * |
| 4913 | gui_mch_create_beval_area(target, mesg, mesgCB, clientData) |
| 4914 | void *target; /* ignored, always use s_textArea */ |
| 4915 | char_u *mesg; |
| 4916 | void (*mesgCB)__ARGS((BalloonEval *, int)); |
| 4917 | void *clientData; |
| 4918 | { |
| 4919 | /* partially stolen from gui_beval.c */ |
| 4920 | BalloonEval *beval; |
| 4921 | |
| 4922 | if (mesg != NULL && mesgCB != NULL) |
| 4923 | { |
| 4924 | EMSG(_("E232: Cannot create BalloonEval with both message and callback")); |
| 4925 | return NULL; |
| 4926 | } |
| 4927 | |
| 4928 | beval = (BalloonEval *)alloc(sizeof(BalloonEval)); |
| 4929 | if (beval != NULL) |
| 4930 | { |
| 4931 | beval->target = s_textArea; |
| 4932 | beval->balloon = NULL; |
| 4933 | |
| 4934 | beval->showState = ShS_NEUTRAL; |
| 4935 | beval->x = 0; |
| 4936 | beval->y = 0; |
| 4937 | beval->msg = mesg; |
| 4938 | beval->msgCB = mesgCB; |
| 4939 | beval->clientData = clientData; |
| 4940 | |
| 4941 | InitCommonControls(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4942 | cur_beval = beval; |
| 4943 | |
| 4944 | if (p_beval) |
| 4945 | gui_mch_enable_beval_area(beval); |
| 4946 | |
| 4947 | } |
| 4948 | return beval; |
| 4949 | } |
| 4950 | |
Bram Moolenaar | 9ba0eb8 | 2005-06-13 22:28:56 +0000 | [diff] [blame] | 4951 | /*ARGSUSED*/ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4952 | static void |
Bram Moolenaar | 442b422 | 2010-05-24 21:34:22 +0200 | [diff] [blame] | 4953 | Handle_WM_Notify(HWND hwnd, LPNMHDR pnmh) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4954 | { |
| 4955 | if (pnmh->idFrom != ID_BEVAL_TOOLTIP) /* it is not our tooltip */ |
| 4956 | return; |
| 4957 | |
| 4958 | if (cur_beval != NULL) |
| 4959 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4960 | switch (pnmh->code) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4961 | { |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4962 | case TTN_SHOW: |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4963 | // TRACE0("TTN_SHOW {{{"); |
| 4964 | // TRACE0("TTN_SHOW }}}"); |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4965 | break; |
| 4966 | case TTN_POP: /* Before tooltip disappear */ |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4967 | // TRACE0("TTN_POP {{{"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4968 | delete_tooltip(cur_beval); |
| 4969 | gui_mch_enable_beval_area(cur_beval); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 4970 | // TRACE0("TTN_POP }}}"); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4971 | |
| 4972 | cur_beval->showState = ShS_NEUTRAL; |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4973 | break; |
| 4974 | case TTN_GETDISPINFO: |
Bram Moolenaar | 6c9176d | 2008-01-03 19:45:15 +0000 | [diff] [blame] | 4975 | { |
| 4976 | /* if you get there then we have new common controls */ |
| 4977 | NMTTDISPINFO_NEW *info = (NMTTDISPINFO_NEW *)pnmh; |
| 4978 | info->lpszText = (LPSTR)info->lParam; |
| 4979 | info->uFlags |= TTF_DI_SETITEM; |
| 4980 | } |
Bram Moolenaar | 4536002 | 2005-07-21 21:08:21 +0000 | [diff] [blame] | 4981 | break; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4982 | } |
| 4983 | } |
| 4984 | } |
| 4985 | |
| 4986 | static void |
| 4987 | TrackUserActivity(UINT uMsg) |
| 4988 | { |
| 4989 | if ((uMsg >= WM_MOUSEFIRST && uMsg <= WM_MOUSELAST) |
| 4990 | || (uMsg >= WM_KEYFIRST && uMsg <= WM_KEYLAST)) |
| 4991 | LastActivity = GetTickCount(); |
| 4992 | } |
| 4993 | |
| 4994 | void |
| 4995 | gui_mch_destroy_beval_area(beval) |
| 4996 | BalloonEval *beval; |
| 4997 | { |
| 4998 | vim_free(beval); |
| 4999 | } |
| 5000 | #endif /* FEAT_BEVAL */ |
| 5001 | |
| 5002 | #if defined(FEAT_NETBEANS_INTG) || defined(PROTO) |
| 5003 | /* |
| 5004 | * We have multiple signs to draw at the same location. Draw the |
| 5005 | * multi-sign indicator (down-arrow) instead. This is the Win32 version. |
| 5006 | */ |
| 5007 | void |
| 5008 | netbeans_draw_multisign_indicator(int row) |
| 5009 | { |
| 5010 | int i; |
| 5011 | int y; |
| 5012 | int x; |
| 5013 | |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 5014 | if (!netbeans_active()) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 5015 | return; |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 5016 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5017 | x = 0; |
| 5018 | y = TEXT_Y(row); |
| 5019 | |
| 5020 | for (i = 0; i < gui.char_height - 3; i++) |
| 5021 | SetPixel(s_hdc, x+2, y++, gui.currFgColor); |
| 5022 | |
| 5023 | SetPixel(s_hdc, x+0, y, gui.currFgColor); |
| 5024 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 5025 | SetPixel(s_hdc, x+4, y++, gui.currFgColor); |
| 5026 | SetPixel(s_hdc, x+1, y, gui.currFgColor); |
| 5027 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 5028 | SetPixel(s_hdc, x+3, y++, gui.currFgColor); |
| 5029 | SetPixel(s_hdc, x+2, y, gui.currFgColor); |
| 5030 | } |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 5031 | |
| 5032 | /* |
| 5033 | * Initialize the Winsock dll. |
| 5034 | */ |
| 5035 | void |
| 5036 | netbeans_init_winsock() |
| 5037 | { |
| 5038 | WSADATA wsaData; |
| 5039 | int wsaerr; |
| 5040 | |
| 5041 | if (WSInitialized) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 5042 | return; |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 5043 | |
| 5044 | wsaerr = WSAStartup(MAKEWORD(2, 2), &wsaData); |
| 5045 | if (wsaerr == 0) |
Bram Moolenaar | cc448b3 | 2010-07-14 16:52:17 +0200 | [diff] [blame] | 5046 | WSInitialized = TRUE; |
Bram Moolenaar | b26e632 | 2010-05-22 21:34:09 +0200 | [diff] [blame] | 5047 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5048 | #endif |