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