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