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