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