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