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