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