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