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