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