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