blob: b3948ce317b63e3cc5ce1ccce722d3308cfd76fd [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001/* 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 * gui_w48.c: This file is included in gui_w16.c and gui_w32.c.
12 *
13 * GUI support for Microsoft Windows (Win16 + Win32 = Win48 :-)
14 *
15 * The combined efforts of:
16 * George V. Reilly <george@reilly.org>
17 * Robert Webb
18 * Vince Negri
19 * ...and contributions from many others
20 *
21 */
22
23#include "vim.h"
24#include "version.h" /* used by dialog box routine for default title */
25#ifdef DEBUG
26# include <tchar.h>
27#endif
28#ifndef __MINGW32__
29# include <shellapi.h>
30#endif
31#if defined(FEAT_TOOLBAR) || defined(FEAT_BEVAL)
32# include <commctrl.h>
33#endif
34#ifdef WIN16
35# include <commdlg.h>
36# include <shellapi.h>
37# ifdef WIN16_3DLOOK
38# include <ctl3d.h>
39# endif
40#endif
41#include <windowsx.h>
42
43#ifdef GLOBAL_IME
44# include "glbl_ime.h"
45#endif
46
47#ifdef FEAT_MENU
48# define MENUHINTS /* show menu hints in command line */
49#endif
50
51/* Some parameters for dialog boxes. All in pixels. */
52#define DLG_PADDING_X 10
53#define DLG_PADDING_Y 10
54#define DLG_OLD_STYLE_PADDING_X 5
55#define DLG_OLD_STYLE_PADDING_Y 5
56#define DLG_VERT_PADDING_X 4 /* For vertical buttons */
57#define DLG_VERT_PADDING_Y 4
58#define DLG_ICON_WIDTH 34
59#define DLG_ICON_HEIGHT 34
60#define DLG_MIN_WIDTH 150
61#define DLG_FONT_NAME "MS Sans Serif"
62#define DLG_FONT_POINT_SIZE 8
63#define DLG_MIN_MAX_WIDTH 400
64
65#define DLG_NONBUTTON_CONTROL 5000 /* First ID of non-button controls */
66
67#ifndef WM_XBUTTONDOWN /* For Win2K / winME ONLY */
68# define WM_XBUTTONDOWN 0x020B
69# define WM_XBUTTONUP 0x020C
70# define WM_XBUTTONDBLCLK 0x020D
71# define MK_XBUTTON1 0x0020
72# define MK_XBUTTON2 0x0040
73#endif
74
75#ifdef PROTO
76/*
77 * Define a few things for generating prototypes. This is just to avoid
78 * syntax errors, the defines do not need to be correct.
79 */
80# define APIENTRY
81# define CALLBACK
82# define CONST
83# define FAR
84# define NEAR
85# define _cdecl
86typedef int BOOL;
87typedef int BYTE;
88typedef int DWORD;
89typedef int WCHAR;
90typedef int ENUMLOGFONT;
91typedef int FINDREPLACE;
92typedef int HANDLE;
93typedef int HBITMAP;
94typedef int HBRUSH;
95typedef int HDROP;
96typedef int INT;
97typedef int LOGFONT[];
98typedef int LPARAM;
99typedef int LPCREATESTRUCT;
100typedef int LPCSTR;
101typedef int LPCTSTR;
102typedef int LPRECT;
103typedef int LPSTR;
104typedef int LPWINDOWPOS;
105typedef int LPWORD;
106typedef int LRESULT;
107# undef MSG
108typedef int MSG;
109typedef int NEWTEXTMETRIC;
110typedef int OSVERSIONINFO;
111typedef int PWORD;
112typedef int RECT;
113typedef int UINT;
114typedef int WORD;
115typedef int WPARAM;
116typedef int POINT;
117typedef void *HINSTANCE;
118typedef void *HMENU;
119typedef void *HWND;
120typedef void *HDC;
121typedef void VOID;
122typedef int LPNMHDR;
123typedef int LONG;
124#endif
125
126#ifndef GET_X_LPARAM
127# define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
128#endif
129
130static void _OnPaint( HWND hwnd);
131static void clear_rect(RECT *rcp);
132static int gui_mswin_get_menu_height(int fix_window);
133
134static WORD s_dlgfntheight; /* height of the dialog font */
135static WORD s_dlgfntwidth; /* width of the dialog font */
136
137#ifdef FEAT_MENU
138static HMENU s_menuBar = NULL;
139#endif
140#ifdef FEAT_TEAROFF
141static void rebuild_tearoff(vimmenu_T *menu);
142static HBITMAP s_htearbitmap; /* bitmap used to indicate tearoff */
143#endif
144
145/* Flag that is set while processing a message that must not be interupted by
146 * processing another message. */
147static int s_busy_processing = FALSE;
148
149static int destroying = FALSE; /* call DestroyWindow() ourselves */
150
151#ifdef MSWIN_FIND_REPLACE
152static UINT s_findrep_msg = 0; /* set in gui_w[16/32].c */
153static FINDREPLACE s_findrep_struct;
154static HWND s_findrep_hwnd = NULL;
155static int s_findrep_is_find; /* TRUE for find dialog, FALSE
156 for find/replace dialog */
157#endif
158
159static HINSTANCE s_hinst = NULL;
160#if !defined(FEAT_SNIFF) && !defined(FEAT_GUI)
161static
162#endif
163HWND s_hwnd = NULL;
164static HDC s_hdc = NULL;
165static HBRUSH s_brush = NULL;
166
167#ifdef FEAT_TOOLBAR
168static HWND s_toolbarhwnd = NULL;
169#endif
170
171static WPARAM s_wParam = 0;
172static LPARAM s_lParam = 0;
173
174static HWND s_textArea = NULL;
175static UINT s_uMsg = 0;
176
177static char_u *s_textfield; /* Used by dialogs to pass back strings */
178
179static int s_need_activate = FALSE;
180
181/* This variable is set when waiting for an event, which is the only moment
182 * scrollbar dragging can be done directly. It's not allowed while commands
183 * are executed, because it may move the cursor and that may cause unexpected
184 * problems (e.g., while ":s" is working).
185 */
186static int allow_scrollbar = FALSE;
187
188#ifdef GLOBAL_IME
189# define MyTranslateMessage(x) global_ime_TranslateMessage(x)
190#else
191# define MyTranslateMessage(x) TranslateMessage(x)
192#endif
193
194#if (defined(WIN3264) && defined(FEAT_MBYTE)) || defined(GLOBAL_IME)
195 /* use of WindowProc depends on wide_WindowProc */
196# define MyWindowProc vim_WindowProc
197#else
198 /* use ordinary WindowProc */
199# define MyWindowProc DefWindowProc
200#endif
201
202extern int current_font_height; /* this is in os_mswin.c */
203
204static struct
205{
206 UINT key_sym;
207 char_u vim_code0;
208 char_u vim_code1;
209} special_keys[] =
210{
211 {VK_UP, 'k', 'u'},
212 {VK_DOWN, 'k', 'd'},
213 {VK_LEFT, 'k', 'l'},
214 {VK_RIGHT, 'k', 'r'},
215
216 {VK_F1, 'k', '1'},
217 {VK_F2, 'k', '2'},
218 {VK_F3, 'k', '3'},
219 {VK_F4, 'k', '4'},
220 {VK_F5, 'k', '5'},
221 {VK_F6, 'k', '6'},
222 {VK_F7, 'k', '7'},
223 {VK_F8, 'k', '8'},
224 {VK_F9, 'k', '9'},
225 {VK_F10, 'k', ';'},
226
227 {VK_F11, 'F', '1'},
228 {VK_F12, 'F', '2'},
229 {VK_F13, 'F', '3'},
230 {VK_F14, 'F', '4'},
231 {VK_F15, 'F', '5'},
232 {VK_F16, 'F', '6'},
233 {VK_F17, 'F', '7'},
234 {VK_F18, 'F', '8'},
235 {VK_F19, 'F', '9'},
236 {VK_F20, 'F', 'A'},
237
238 {VK_F21, 'F', 'B'},
239#ifdef FEAT_NETBEANS_INTG
240 {VK_PAUSE, 'F', 'B'}, /* Pause == F21 (see gui_gtk_x11.c) */
241#endif
242 {VK_F22, 'F', 'C'},
243 {VK_F23, 'F', 'D'},
244 {VK_F24, 'F', 'E'}, /* winuser.h defines up to F24 */
245
246 {VK_HELP, '%', '1'},
247 {VK_BACK, 'k', 'b'},
248 {VK_INSERT, 'k', 'I'},
249 {VK_DELETE, 'k', 'D'},
250 {VK_HOME, 'k', 'h'},
251 {VK_END, '@', '7'},
252 {VK_PRIOR, 'k', 'P'},
253 {VK_NEXT, 'k', 'N'},
254 {VK_PRINT, '%', '9'},
255 {VK_ADD, 'K', '6'},
256 {VK_SUBTRACT, 'K', '7'},
257 {VK_DIVIDE, 'K', '8'},
258 {VK_MULTIPLY, 'K', '9'},
259 {VK_SEPARATOR, 'K', 'A'}, /* Keypad Enter */
260 {VK_DECIMAL, 'K', 'B'},
261
262 {VK_NUMPAD0, 'K', 'C'},
263 {VK_NUMPAD1, 'K', 'D'},
264 {VK_NUMPAD2, 'K', 'E'},
265 {VK_NUMPAD3, 'K', 'F'},
266 {VK_NUMPAD4, 'K', 'G'},
267 {VK_NUMPAD5, 'K', 'H'},
268 {VK_NUMPAD6, 'K', 'I'},
269 {VK_NUMPAD7, 'K', 'J'},
270 {VK_NUMPAD8, 'K', 'K'},
271 {VK_NUMPAD9, 'K', 'L'},
272
273 /* Keys that we want to be able to use any modifier with: */
274 {VK_SPACE, ' ', NUL},
275 {VK_TAB, TAB, NUL},
276 {VK_ESCAPE, ESC, NUL},
277 {NL, NL, NUL},
278 {CAR, CAR, NUL},
279
280 /* End of list marker: */
281 {0, 0, 0}
282};
283
284/* Local variables */
285static int s_button_pending = -1;
286static int s_x_pending;
287static int s_y_pending;
288static UINT s_kFlags_pending;
289static UINT s_wait_timer = 0; /* Timer for get char from user */
290static int s_timed_out = FALSE;
291static int dead_key = 0; /* 0 - no dead key, 1 - dead key pressed */
292
293#ifdef WIN3264
294static OSVERSIONINFO os_version; /* like it says. Init in gui_mch_init() */
295#endif
296
297#ifdef FEAT_BEVAL
298/* balloon-eval WM_NOTIFY_HANDLER */
299static void Handle_WM_Notify __ARGS((HWND hwnd, LPNMHDR pnmh));
300static void TrackUserActivity __ARGS((UINT uMsg));
301#endif
302
303/*
304 * For control IME.
305 */
306#ifdef FEAT_MBYTE
307# ifdef USE_IM_CONTROL
308static LOGFONT norm_logfont;
309# endif
310#endif
311
312#ifdef FEAT_MBYTE_IME
313static LRESULT _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData);
314#endif
315
316#ifdef DEBUG
317/*
318 * Print out the last Windows error message
319 */
320 static void
321print_windows_error(void)
322{
323 LPVOID lpMsgBuf;
324
325 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
326 NULL, GetLastError(),
327 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
328 (LPTSTR) &lpMsgBuf, 0, NULL);
329 TRACE1("Error: %s\n", lpMsgBuf);
330 LocalFree(lpMsgBuf);
331}
332#endif /* DEBUG */
333
334/*
335 * Cursor blink functions.
336 *
337 * This is a simple state machine:
338 * BLINK_NONE not blinking at all
339 * BLINK_OFF blinking, cursor is not shown
340 * BLINK_ON blinking, cursor is shown
341 */
342
343#define BLINK_NONE 0
344#define BLINK_OFF 1
345#define BLINK_ON 2
346
347static int blink_state = BLINK_NONE;
348static long_u blink_waittime = 700;
349static long_u blink_ontime = 400;
350static long_u blink_offtime = 250;
351static UINT blink_timer = 0;
352
353 void
354gui_mch_set_blinking(long wait, long on, long off)
355{
356 blink_waittime = wait;
357 blink_ontime = on;
358 blink_offtime = off;
359}
360
361/* ARGSUSED */
362 static VOID CALLBACK
363_OnBlinkTimer(
364 HWND hwnd,
365 UINT uMsg,
366 UINT idEvent,
367 DWORD dwTime)
368{
369 MSG msg;
370
371 /*
372 TRACE2("Got timer event, id %d, blink_timer %d\n", idEvent, blink_timer);
373 */
374
375 KillTimer(NULL, idEvent);
376
377 /* Eat spurious WM_TIMER messages */
378 while (PeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
379 ;
380
381 if (blink_state == BLINK_ON)
382 {
383 gui_undraw_cursor();
384 blink_state = BLINK_OFF;
385 blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_offtime,
386 (TIMERPROC)_OnBlinkTimer);
387 }
388 else
389 {
390 gui_update_cursor(TRUE, FALSE);
391 blink_state = BLINK_ON;
392 blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_ontime,
393 (TIMERPROC)_OnBlinkTimer);
394 }
395}
396
397 static void
398gui_mswin_rm_blink_timer(void)
399{
400 MSG msg;
401
402 if (blink_timer != 0)
403 {
404 KillTimer(NULL, blink_timer);
405 /* Eat spurious WM_TIMER messages */
406 while (PeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
407 ;
408 blink_timer = 0;
409 }
410}
411
412/*
413 * Stop the cursor blinking. Show the cursor if it wasn't shown.
414 */
415 void
416gui_mch_stop_blink(void)
417{
418 gui_mswin_rm_blink_timer();
419 if (blink_state == BLINK_OFF)
420 gui_update_cursor(TRUE, FALSE);
421 blink_state = BLINK_NONE;
422}
423
424/*
425 * Start the cursor blinking. If it was already blinking, this restarts the
426 * waiting time and shows the cursor.
427 */
428 void
429gui_mch_start_blink(void)
430{
431 gui_mswin_rm_blink_timer();
432
433 /* Only switch blinking on if none of the times is zero */
434 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus)
435 {
436 blink_timer = (UINT)SetTimer(NULL, 0, (UINT)blink_waittime,
437 (TIMERPROC)_OnBlinkTimer);
438 blink_state = BLINK_ON;
439 gui_update_cursor(TRUE, FALSE);
440 }
441}
442
443/*
444 * Call-back routines.
445 */
446
447 static VOID CALLBACK
448_OnTimer(
449 HWND hwnd,
450 UINT uMsg,
451 UINT idEvent,
452 DWORD dwTime)
453{
454 MSG msg;
455
456 /*
457 TRACE2("Got timer event, id %d, s_wait_timer %d\n", idEvent, s_wait_timer);
458 */
459 KillTimer(NULL, idEvent);
460 s_timed_out = TRUE;
461
462 /* Eat spurious WM_TIMER messages */
463 while (PeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
464 ;
465 if (idEvent == s_wait_timer)
466 s_wait_timer = 0;
467}
468
469 static void
470_OnDeadChar(
471 HWND hwnd,
472 UINT ch,
473 int cRepeat)
474{
475 dead_key = 1;
476}
477
478/*
479 * Convert Unicode character "ch" to bytes in "string[slen]".
480 * Return the length.
481 */
482 static int
483char_to_string(int ch, char_u *string, int slen)
484{
485 int len;
486 int i;
487#ifdef FEAT_MBYTE
488 WCHAR wstring[2];
489 char_u *ws = NULL;;
490
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000491 if (os_version.dwPlatformId != VER_PLATFORM_WIN32_NT)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000492 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000493 /* On Windows 95/98 we apparently get the character in the active
494 * codepage, not in UCS-2. If conversion is needed convert it to
495 * UCS-2 first. */
496 if ((int)GetACP() == enc_codepage)
497 len = 0; /* no conversion required */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498 else
499 {
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000500 string[0] = ch;
501 len = MultiByteToWideChar(GetACP(), 0, string, 1, wstring, 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502 }
503 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000504 else
505 {
506 wstring[0] = ch;
507 len = 1;
508 }
509
510 if (len > 0)
511 {
512 /* "ch" is a UTF-16 character. Convert it to a string of bytes. When
513 * "enc_codepage" is non-zero use the standard Win32 function,
514 * otherwise use our own conversion function (e.g., for UTF-8). */
515 if (enc_codepage > 0)
516 len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
517 string, slen, 0, NULL);
518 else
519 {
520 len = 1;
521 ws = ucs2_to_enc(wstring, &len);
522 if (ws == NULL)
523 len = 0;
524 else
525 {
526 if (len > slen) /* just in case */
527 len = slen;
528 mch_memmove(string, ws, len);
529 vim_free(ws);
530 }
531 }
532 }
533
Bram Moolenaar071d4272004-06-13 20:20:40 +0000534 if (len == 0)
535#endif
536 {
537 string[0] = ch;
538 len = 1;
539 }
540
541 for (i = 0; i < len; ++i)
542 if (string[i] == CSI && len <= slen - 2)
543 {
544 /* Insert CSI as K_CSI. */
545 mch_memmove(string + i + 3, string + i + 1, len - i - 1);
546 string[++i] = KS_EXTRA;
547 string[++i] = (int)KE_CSI;
548 len += 2;
549 }
550
551 return len;
552}
553
554/*
555 * Key hit, add it to the input buffer.
556 */
557 static void
558_OnChar(
559 HWND hwnd,
560 UINT ch,
561 int cRepeat)
562{
563 char_u string[40];
564 int len = 0;
565
566 len = char_to_string(ch, string, 40);
567 if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
568 {
569 trash_input_buf();
570 got_int = TRUE;
571 }
572
573 add_to_input_buf(string, len);
574}
575
576/*
577 * Alt-Key hit, add it to the input buffer.
578 */
579 static void
580_OnSysChar(
581 HWND hwnd,
582 UINT cch,
583 int cRepeat)
584{
585 char_u string[40]; /* Enough for multibyte character */
586 int len;
587 int modifiers;
588 int ch = cch; /* special keys are negative */
589
590 /* TRACE("OnSysChar(%d, %c)\n", ch, ch); */
591
592 /* OK, we have a character key (given by ch) which was entered with the
593 * ALT key pressed. Eg, if the user presses Alt-A, then ch == 'A'. Note
594 * that the system distinguishes Alt-a and Alt-A (Alt-Shift-a unless
595 * CAPSLOCK is pressed) at this point.
596 */
597 modifiers = MOD_MASK_ALT;
598 if (GetKeyState(VK_SHIFT) & 0x8000)
599 modifiers |= MOD_MASK_SHIFT;
600 if (GetKeyState(VK_CONTROL) & 0x8000)
601 modifiers |= MOD_MASK_CTRL;
602
603 ch = simplify_key(ch, &modifiers);
604 /* remove the SHIFT modifier for keys where it's already included, e.g.,
605 * '(' and '*' */
606 if (ch < 0x100 && !isalpha(ch) && isprint(ch))
607 modifiers &= ~MOD_MASK_SHIFT;
608
609 /* Interpret the ALT key as making the key META, include SHIFT, etc. */
610 ch = extract_modifiers(ch, &modifiers);
611 if (ch == CSI)
612 ch = K_CSI;
613
614 len = 0;
615 if (modifiers)
616 {
617 string[len++] = CSI;
618 string[len++] = KS_MODIFIER;
619 string[len++] = modifiers;
620 }
621
622 if (IS_SPECIAL((int)ch))
623 {
624 string[len++] = CSI;
625 string[len++] = K_SECOND((int)ch);
626 string[len++] = K_THIRD((int)ch);
627 }
628 else
629 {
630 /* Although the documentation isn't clear about it, we assume "ch" is
631 * a Unicode character. */
632 len += char_to_string(ch, string + len, 40 - len);
633 }
634
635 add_to_input_buf(string, len);
636}
637
638 static void
639_OnMouseEvent(
640 int button,
641 int x,
642 int y,
643 int repeated_click,
644 UINT keyFlags)
645{
646 int vim_modifiers = 0x0;
647
648 if (keyFlags & MK_SHIFT)
649 vim_modifiers |= MOUSE_SHIFT;
650 if (keyFlags & MK_CONTROL)
651 vim_modifiers |= MOUSE_CTRL;
652 if (GetKeyState(VK_MENU) & 0x8000)
653 vim_modifiers |= MOUSE_ALT;
654
655 gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers);
656}
657
658 static void
659_OnMouseButtonDown(
660 HWND hwnd,
661 BOOL fDoubleClick,
662 int x,
663 int y,
664 UINT keyFlags)
665{
666 static LONG s_prevTime = 0;
667
668 LONG currentTime = GetMessageTime();
669 int button = -1;
670 int repeated_click;
671
672 /* Give main window the focus: this is so the cursor isn't hollow. */
673 (void)SetFocus(s_hwnd);
674
675 if (s_uMsg == WM_LBUTTONDOWN || s_uMsg == WM_LBUTTONDBLCLK)
676 button = MOUSE_LEFT;
677 else if (s_uMsg == WM_MBUTTONDOWN || s_uMsg == WM_MBUTTONDBLCLK)
678 button = MOUSE_MIDDLE;
679 else if (s_uMsg == WM_RBUTTONDOWN || s_uMsg == WM_RBUTTONDBLCLK)
680 button = MOUSE_RIGHT;
681#ifndef WIN16 /*<VN>*/
682 else if (s_uMsg == WM_XBUTTONDOWN || s_uMsg == WM_XBUTTONDBLCLK)
683 {
684#ifndef GET_XBUTTON_WPARAM
685# define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam))
686#endif
687 button = ((GET_XBUTTON_WPARAM(s_wParam) == 1) ? MOUSE_X1 : MOUSE_X2);
688 }
689 else if (s_uMsg == WM_CAPTURECHANGED)
690 {
691 /* on W95/NT4, somehow you get in here with an odd Msg
692 * if you press one button while holding down the other..*/
693 if (s_button_pending == MOUSE_LEFT)
694 button = MOUSE_RIGHT;
695 else
696 button = MOUSE_LEFT;
697 }
698#endif
699 if (button >= 0)
700 {
701 repeated_click = ((int)(currentTime - s_prevTime) < p_mouset);
702
703 /*
704 * Holding down the left and right buttons simulates pushing the middle
705 * button.
706 */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000707 if (repeated_click
708 && ((button == MOUSE_LEFT && s_button_pending == MOUSE_RIGHT)
709 || (button == MOUSE_RIGHT
710 && s_button_pending == MOUSE_LEFT)))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 {
712 /*
713 * Hmm, gui.c will ignore more than one button down at a time, so
714 * pretend we let go of it first.
715 */
716 gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, 0x0);
717 button = MOUSE_MIDDLE;
718 repeated_click = FALSE;
719 s_button_pending = -1;
720 _OnMouseEvent(button, x, y, repeated_click, keyFlags);
721 }
722 else if ((repeated_click)
723 || (mouse_model_popup() && (button == MOUSE_RIGHT)))
724 {
725 if (s_button_pending > -1)
726 {
727 _OnMouseEvent(s_button_pending, x, y, FALSE, keyFlags);
728 s_button_pending = -1;
729 }
730 /* TRACE("Button down at x %d, y %d\n", x, y); */
731 _OnMouseEvent(button, x, y, repeated_click, keyFlags);
732 }
733 else
734 {
735 /*
736 * If this is the first press (i.e. not a multiple click) don't
737 * action immediately, but store and wait for:
738 * i) button-up
739 * ii) mouse move
740 * iii) another button press
741 * before using it.
742 * This enables us to make left+right simulate middle button,
743 * without left or right being actioned first. The side-effect is
744 * that if you click and hold the mouse without dragging, the
745 * cursor doesn't move until you release the button. In practice
746 * this is hardly a problem.
747 */
748 s_button_pending = button;
749 s_x_pending = x;
750 s_y_pending = y;
751 s_kFlags_pending = keyFlags;
752 }
753
754 s_prevTime = currentTime;
755 }
756}
757
758 static void
759_OnMouseMoveOrRelease(
760 HWND hwnd,
761 int x,
762 int y,
763 UINT keyFlags)
764{
765 int button;
766
767 if (s_button_pending > -1)
768 {
769 /* Delayed action for mouse down event */
770 _OnMouseEvent(s_button_pending, s_x_pending,
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000771 s_y_pending, FALSE, s_kFlags_pending);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772 s_button_pending = -1;
773 }
774 if (s_uMsg == WM_MOUSEMOVE)
775 {
776 /*
777 * It's only a MOUSE_DRAG if one or more mouse buttons are being held
778 * down.
779 */
780 if (!(keyFlags & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON
781 | MK_XBUTTON1 | MK_XBUTTON2)))
782 {
783 gui_mouse_moved(x, y);
784 return;
785 }
786
787 /*
788 * While button is down, keep grabbing mouse move events when
789 * the mouse goes outside the window
790 */
791 SetCapture(s_textArea);
792 button = MOUSE_DRAG;
793 /* TRACE(" move at x %d, y %d\n", x, y); */
794 }
795 else
796 {
797 ReleaseCapture();
798 button = MOUSE_RELEASE;
799 /* TRACE(" up at x %d, y %d\n", x, y); */
800 }
801
802 _OnMouseEvent(button, x, y, FALSE, keyFlags);
803}
804
805#ifdef FEAT_MENU
806/*
807 * Find the vimmenu_T with the given id
808 */
809 static vimmenu_T *
810gui_mswin_find_menu(
811 vimmenu_T *pMenu,
812 int id)
813{
814 vimmenu_T *pChildMenu;
815
816 while (pMenu)
817 {
818 if (pMenu->id == (UINT)id)
819 break;
820 if (pMenu->children != NULL)
821 {
822 pChildMenu = gui_mswin_find_menu(pMenu->children, id);
823 if (pChildMenu)
824 {
825 pMenu = pChildMenu;
826 break;
827 }
828 }
829 pMenu = pMenu->next;
830 }
831 return pMenu;
832}
833
834 static void
835_OnMenu(
836 HWND hwnd,
837 int id,
838 HWND hwndCtl,
839 UINT codeNotify)
840{
841 vimmenu_T *pMenu;
842
843 pMenu = gui_mswin_find_menu(root_menu, id);
844 if (pMenu)
845 gui_menu_cb(pMenu);
846}
847#endif
848
849#ifdef MSWIN_FIND_REPLACE
850/*
851 * Handle a Find/Replace window message.
852 */
853 static void
854_OnFindRepl(void)
855{
856 int flags = 0;
857 int down;
858
859 if (s_findrep_struct.Flags & FR_DIALOGTERM)
860 /* Give main window the focus back. */
861 (void)SetFocus(s_hwnd);
862
863 if (s_findrep_struct.Flags & FR_FINDNEXT)
864 {
865 flags = FRD_FINDNEXT;
866
867 /* Give main window the focus back: this is so the cursor isn't
868 * hollow. */
869 (void)SetFocus(s_hwnd);
870 }
871 else if (s_findrep_struct.Flags & FR_REPLACE)
872 {
873 flags = FRD_REPLACE;
874
875 /* Give main window the focus back: this is so the cursor isn't
876 * hollow. */
877 (void)SetFocus(s_hwnd);
878 }
879 else if (s_findrep_struct.Flags & FR_REPLACEALL)
880 {
881 flags = FRD_REPLACEALL;
882 }
883
884 if (flags != 0)
885 {
886 /* Call the generic GUI function to do the actual work. */
887 if (s_findrep_struct.Flags & FR_WHOLEWORD)
888 flags |= FRD_WHOLE_WORD;
889 if (s_findrep_struct.Flags & FR_MATCHCASE)
890 flags |= FRD_MATCH_CASE;
891 down = (s_findrep_struct.Flags & FR_DOWN) != 0;
892 gui_do_findrepl(flags, s_findrep_struct.lpstrFindWhat,
893 s_findrep_struct.lpstrReplaceWith, down);
894 }
895}
896#endif
897
898 static void
899HandleMouseHide(UINT uMsg, LPARAM lParam)
900{
901 static LPARAM last_lParam = 0L;
902
903 /* We sometimes get a mousemove when the mouse didn't move... */
904 if (uMsg == WM_MOUSEMOVE)
905 {
906 if (lParam == last_lParam)
907 return;
908 last_lParam = lParam;
909 }
910
911 /* Handle specially, to centralise coding. We need to be sure we catch all
912 * possible events which should cause us to restore the cursor (as it is a
913 * shared resource, we take full responsibility for it).
914 */
915 switch (uMsg)
916 {
917 case WM_KEYUP:
918 case WM_CHAR:
919 /*
920 * blank out the pointer if necessary
921 */
922 if (p_mh)
923 gui_mch_mousehide(TRUE);
924 break;
925
926 case WM_SYSKEYUP: /* show the pointer when a system-key is pressed */
927 case WM_SYSCHAR:
928 case WM_MOUSEMOVE: /* show the pointer on any mouse action */
929 case WM_LBUTTONDOWN:
930 case WM_LBUTTONUP:
931 case WM_MBUTTONDOWN:
932 case WM_MBUTTONUP:
933 case WM_RBUTTONDOWN:
934 case WM_RBUTTONUP:
935 case WM_XBUTTONDOWN:
936 case WM_XBUTTONUP:
937 case WM_NCMOUSEMOVE:
938 case WM_NCLBUTTONDOWN:
939 case WM_NCLBUTTONUP:
940 case WM_NCMBUTTONDOWN:
941 case WM_NCMBUTTONUP:
942 case WM_NCRBUTTONDOWN:
943 case WM_NCRBUTTONUP:
944 case WM_KILLFOCUS:
945 /*
946 * if the pointer is currently hidden, then we should show it.
947 */
948 gui_mch_mousehide(FALSE);
949 break;
950 }
951}
952
953 static LRESULT CALLBACK
954_TextAreaWndProc(
955 HWND hwnd,
956 UINT uMsg,
957 WPARAM wParam,
958 LPARAM lParam)
959{
960 /*
961 TRACE("TextAreaWndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n",
962 hwnd, uMsg, wParam, lParam);
963 */
964
965 HandleMouseHide(uMsg, lParam);
966
967 s_uMsg = uMsg;
968 s_wParam = wParam;
969 s_lParam = lParam;
970
971#ifdef FEAT_BEVAL
972 TrackUserActivity(uMsg);
973#endif
974
975 switch (uMsg)
976 {
977 HANDLE_MSG(hwnd, WM_LBUTTONDBLCLK,_OnMouseButtonDown);
978 HANDLE_MSG(hwnd, WM_LBUTTONDOWN,_OnMouseButtonDown);
979 HANDLE_MSG(hwnd, WM_LBUTTONUP, _OnMouseMoveOrRelease);
980 HANDLE_MSG(hwnd, WM_MBUTTONDBLCLK,_OnMouseButtonDown);
981 HANDLE_MSG(hwnd, WM_MBUTTONDOWN,_OnMouseButtonDown);
982 HANDLE_MSG(hwnd, WM_MBUTTONUP, _OnMouseMoveOrRelease);
983 HANDLE_MSG(hwnd, WM_MOUSEMOVE, _OnMouseMoveOrRelease);
984 HANDLE_MSG(hwnd, WM_PAINT, _OnPaint);
985 HANDLE_MSG(hwnd, WM_RBUTTONDBLCLK,_OnMouseButtonDown);
986 HANDLE_MSG(hwnd, WM_RBUTTONDOWN,_OnMouseButtonDown);
987 HANDLE_MSG(hwnd, WM_RBUTTONUP, _OnMouseMoveOrRelease);
988#ifndef WIN16 /*<VN>*/
989 HANDLE_MSG(hwnd, WM_XBUTTONDBLCLK,_OnMouseButtonDown);
990 HANDLE_MSG(hwnd, WM_XBUTTONDOWN,_OnMouseButtonDown);
991 HANDLE_MSG(hwnd, WM_XBUTTONUP, _OnMouseMoveOrRelease);
992#endif
993
994#ifdef FEAT_BEVAL
995 case WM_NOTIFY: Handle_WM_Notify(hwnd, (LPNMHDR)lParam);
996 return TRUE;
997#endif
998
999 default:
1000 return MyWindowProc(hwnd, uMsg, wParam, lParam);
1001 }
1002}
1003
1004#if (defined(WIN3264) && defined(FEAT_MBYTE)) \
1005 || defined(GLOBAL_IME) \
1006 || defined(PROTO)
1007# ifdef PROTO
1008typedef int WINAPI;
1009# endif
1010
1011 LRESULT WINAPI
1012vim_WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1013{
1014# ifdef GLOBAL_IME
1015 return global_ime_DefWindowProc(hwnd, message, wParam, lParam);
1016# else
1017 if (wide_WindowProc)
1018 return DefWindowProcW(hwnd, message, wParam, lParam);
1019 return DefWindowProc(hwnd, message, wParam, lParam);
1020#endif
1021}
1022#endif
1023
1024/*
1025 * Called when the foreground or background color has been changed.
1026 */
1027 void
1028gui_mch_new_colors(void)
1029{
1030 /* nothing to do? */
1031}
1032
1033/*
1034 * Set the colors to their default values.
1035 */
1036 void
1037gui_mch_def_colors()
1038{
1039 gui.norm_pixel = GetSysColor(COLOR_WINDOWTEXT);
1040 gui.back_pixel = GetSysColor(COLOR_WINDOW);
1041 gui.def_norm_pixel = gui.norm_pixel;
1042 gui.def_back_pixel = gui.back_pixel;
1043}
1044
1045/*
1046 * Open the GUI window which was created by a call to gui_mch_init().
1047 */
1048 int
1049gui_mch_open(void)
1050{
1051#ifndef SW_SHOWDEFAULT
1052# define SW_SHOWDEFAULT 10 /* Borland 5.0 doesn't have it */
1053#endif
1054 /* Actually open the window, if not already visible
1055 * (may be done already in gui_mch_set_shellsize) */
1056 if (!IsWindowVisible(s_hwnd))
1057 ShowWindow(s_hwnd, SW_SHOWDEFAULT);
1058
1059 return OK;
1060}
1061
1062/*
1063 * Get the position of the top left corner of the window.
1064 */
1065 int
1066gui_mch_get_winpos(int *x, int *y)
1067{
1068 RECT rect;
1069
1070 GetWindowRect(s_hwnd, &rect);
1071 *x = rect.left;
1072 *y = rect.top;
1073 return OK;
1074}
1075
1076/*
1077 * Set the position of the top left corner of the window to the given
1078 * coordinates.
1079 */
1080 void
1081gui_mch_set_winpos(int x, int y)
1082{
1083 SetWindowPos(s_hwnd, NULL, x, y, 0, 0,
1084 SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
1085}
1086 void
1087gui_mch_set_text_area_pos(int x, int y, int w, int h)
1088{
1089 static int oldx = 0;
1090 static int oldy = 0;
1091
1092 SetWindowPos(s_textArea, NULL, x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE);
1093
1094#ifdef FEAT_TOOLBAR
1095 if (vim_strchr(p_go, GO_TOOLBAR) != NULL)
1096 SendMessage(s_toolbarhwnd, WM_SIZE,
1097 (WPARAM)0, (LPARAM)(w + ((long)(TOOLBAR_BUTTON_HEIGHT+8)<<16)));
1098#endif
1099 /* When side scroll bar is unshown, the size of window will change.
1100 * then, the text area move left or right. thus client rect should be
1101 * forcely redraw. (Yasuhiro Matsumoto) */
1102 if (oldx != x || oldy != y)
1103 {
1104 InvalidateRect(s_hwnd, NULL, FALSE);
1105 oldx = x;
1106 oldy = y;
1107 }
1108
1109}
1110
1111
1112/*
1113 * Scrollbar stuff:
1114 */
1115
1116 void
1117gui_mch_enable_scrollbar(
1118 scrollbar_T *sb,
1119 int flag)
1120{
1121 ShowScrollBar(sb->id, SB_CTL, flag);
1122
1123 /* TODO: When the window is maximized, the size of the window stays the
1124 * same, thus the size of the text area changes. On Win98 it's OK, on Win
1125 * NT 4.0 it's not... */
1126}
1127
1128 void
1129gui_mch_set_scrollbar_pos(
1130 scrollbar_T *sb,
1131 int x,
1132 int y,
1133 int w,
1134 int h)
1135{
1136 SetWindowPos(sb->id, NULL, x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
1137}
1138
1139 void
1140gui_mch_create_scrollbar(
1141 scrollbar_T *sb,
1142 int orient) /* SBAR_VERT or SBAR_HORIZ */
1143{
1144 sb->id = CreateWindow(
1145 "SCROLLBAR", "Scrollbar",
1146 WS_CHILD | ((orient == SBAR_VERT) ? SBS_VERT : SBS_HORZ), 0, 0,
1147 10, /* Any value will do for now */
1148 10, /* Any value will do for now */
1149 s_hwnd, NULL,
1150 s_hinst, NULL);
1151}
1152
1153/*
1154 * Find the scrollbar with the given hwnd.
1155 */
1156 static scrollbar_T *
1157gui_mswin_find_scrollbar(HWND hwnd)
1158{
1159 win_T *wp;
1160
1161 if (gui.bottom_sbar.id == hwnd)
1162 return &gui.bottom_sbar;
1163 FOR_ALL_WINDOWS(wp)
1164 {
1165 if (wp->w_scrollbars[SBAR_LEFT].id == hwnd)
1166 return &wp->w_scrollbars[SBAR_LEFT];
1167 if (wp->w_scrollbars[SBAR_RIGHT].id == hwnd)
1168 return &wp->w_scrollbars[SBAR_RIGHT];
1169 }
1170 return NULL;
1171}
1172
1173/*
1174 * Get the character size of a font.
1175 */
1176 static void
1177GetFontSize(GuiFont font)
1178{
1179 HWND hwnd = GetDesktopWindow();
1180 HDC hdc = GetWindowDC(hwnd);
1181 HFONT hfntOld = SelectFont(hdc, (HFONT)font);
1182 TEXTMETRIC tm;
1183
1184 GetTextMetrics(hdc, &tm);
1185 gui.char_width = tm.tmAveCharWidth + tm.tmOverhang;
1186
1187 gui.char_height = tm.tmHeight
1188#ifndef MSWIN16_FASTTEXT
1189 + p_linespace
1190#endif
1191 ;
1192
1193 SelectFont(hdc, hfntOld);
1194
1195 ReleaseDC(hwnd, hdc);
1196}
1197
1198 int
1199gui_mch_adjust_charsize(void)
1200{
1201 GetFontSize(gui.norm_font);
1202 return OK;
1203}
1204
1205 static GuiFont
1206get_font_handle(LOGFONT *lf)
1207{
1208 HFONT font = NULL;
1209
1210 /* Load the font */
1211 font = CreateFontIndirect(lf);
1212
1213 if (font == NULL)
1214 return NOFONT;
1215
1216 return (GuiFont)font;
1217}
1218
1219 static int
1220pixels_to_points(int pixels, int vertical)
1221{
1222 int points;
1223 HWND hwnd;
1224 HDC hdc;
1225
1226 hwnd = GetDesktopWindow();
1227 hdc = GetWindowDC(hwnd);
1228
1229 points = MulDiv(pixels, 72,
1230 GetDeviceCaps(hdc, vertical ? LOGPIXELSY : LOGPIXELSX));
1231
1232 ReleaseDC(hwnd, hdc);
1233
1234 return points;
1235}
1236
1237 GuiFont
1238gui_mch_get_font(
1239 char_u *name,
1240 int giveErrorIfMissing)
1241{
1242 LOGFONT lf;
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00001243 GuiFont font = NOFONT;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001244
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00001245 if (get_logfont(&lf, name, NULL, giveErrorIfMissing) == OK)
1246 font = get_font_handle(&lf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001247 if (font == NOFONT && giveErrorIfMissing)
1248 EMSG2(_(e_font), name);
1249 return font;
1250}
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00001251
1252/*
1253 * Return the name of font "font" in allocated memory.
1254 * Don't know how to get the actual name, thus use the provided name.
1255 */
1256 char_u *
1257gui_mch_get_fontname(font, name)
1258 GuiFont font;
1259 char_u *name;
1260{
1261 if (name == NULL)
1262 return NULL;
1263 return vim_strsave(name);
1264}
1265
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266 void
1267gui_mch_free_font(GuiFont font)
1268{
1269 if (font)
1270 DeleteObject((HFONT)font);
1271}
1272
1273 static int
1274hex_digit(int c)
1275{
1276 if (VIM_ISDIGIT(c))
1277 return c - '0';
1278 c = TOLOWER_ASC(c);
1279 if (c >= 'a' && c <= 'f')
1280 return c - 'a' + 10;
1281 return -1000;
1282}
1283/*
1284 * Return the Pixel value (color) for the given color name.
1285 * Return INVALCOLOR for error.
1286 */
1287 guicolor_T
1288gui_mch_get_color(char_u *name)
1289{
1290 typedef struct guicolor_tTable
1291 {
1292 char *name;
1293 COLORREF color;
1294 } guicolor_tTable;
1295
1296 static guicolor_tTable table[] =
1297 {
1298 {"Black", RGB(0x00, 0x00, 0x00)},
1299 {"DarkGray", RGB(0x80, 0x80, 0x80)},
1300 {"DarkGrey", RGB(0x80, 0x80, 0x80)},
1301 {"Gray", RGB(0xC0, 0xC0, 0xC0)},
1302 {"Grey", RGB(0xC0, 0xC0, 0xC0)},
1303 {"LightGray", RGB(0xE0, 0xE0, 0xE0)},
1304 {"LightGrey", RGB(0xE0, 0xE0, 0xE0)},
1305 {"White", RGB(0xFF, 0xFF, 0xFF)},
1306 {"DarkRed", RGB(0x80, 0x00, 0x00)},
1307 {"Red", RGB(0xFF, 0x00, 0x00)},
1308 {"LightRed", RGB(0xFF, 0xA0, 0xA0)},
1309 {"DarkBlue", RGB(0x00, 0x00, 0x80)},
1310 {"Blue", RGB(0x00, 0x00, 0xFF)},
1311 {"LightBlue", RGB(0xA0, 0xA0, 0xFF)},
1312 {"DarkGreen", RGB(0x00, 0x80, 0x00)},
1313 {"Green", RGB(0x00, 0xFF, 0x00)},
1314 {"LightGreen", RGB(0xA0, 0xFF, 0xA0)},
1315 {"DarkCyan", RGB(0x00, 0x80, 0x80)},
1316 {"Cyan", RGB(0x00, 0xFF, 0xFF)},
1317 {"LightCyan", RGB(0xA0, 0xFF, 0xFF)},
1318 {"DarkMagenta", RGB(0x80, 0x00, 0x80)},
1319 {"Magenta", RGB(0xFF, 0x00, 0xFF)},
1320 {"LightMagenta", RGB(0xFF, 0xA0, 0xFF)},
1321 {"Brown", RGB(0x80, 0x40, 0x40)},
1322 {"Yellow", RGB(0xFF, 0xFF, 0x00)},
1323 {"LightYellow", RGB(0xFF, 0xFF, 0xA0)},
1324 {"DarkYellow", RGB(0xBB, 0xBB, 0x00)},
1325 {"SeaGreen", RGB(0x2E, 0x8B, 0x57)},
1326 {"Orange", RGB(0xFF, 0xA5, 0x00)},
1327 {"Purple", RGB(0xA0, 0x20, 0xF0)},
1328 {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)},
1329 {"Violet", RGB(0xEE, 0x82, 0xEE)},
1330 };
1331
1332 typedef struct SysColorTable
1333 {
1334 char *name;
1335 int color;
1336 } SysColorTable;
1337
1338 static SysColorTable sys_table[] =
1339 {
1340#ifdef WIN3264
1341 {"SYS_3DDKSHADOW", COLOR_3DDKSHADOW},
1342 {"SYS_3DHILIGHT", COLOR_3DHILIGHT},
1343#ifndef __MINGW32__
1344 {"SYS_3DHIGHLIGHT", COLOR_3DHIGHLIGHT},
1345#endif
1346 {"SYS_BTNHILIGHT", COLOR_BTNHILIGHT},
1347 {"SYS_BTNHIGHLIGHT", COLOR_BTNHIGHLIGHT},
1348 {"SYS_3DLIGHT", COLOR_3DLIGHT},
1349 {"SYS_3DSHADOW", COLOR_3DSHADOW},
1350 {"SYS_DESKTOP", COLOR_DESKTOP},
1351 {"SYS_INFOBK", COLOR_INFOBK},
1352 {"SYS_INFOTEXT", COLOR_INFOTEXT},
1353 {"SYS_3DFACE", COLOR_3DFACE},
1354#endif
1355 {"SYS_BTNFACE", COLOR_BTNFACE},
1356 {"SYS_BTNSHADOW", COLOR_BTNSHADOW},
1357 {"SYS_ACTIVEBORDER", COLOR_ACTIVEBORDER},
1358 {"SYS_ACTIVECAPTION", COLOR_ACTIVECAPTION},
1359 {"SYS_APPWORKSPACE", COLOR_APPWORKSPACE},
1360 {"SYS_BACKGROUND", COLOR_BACKGROUND},
1361 {"SYS_BTNTEXT", COLOR_BTNTEXT},
1362 {"SYS_CAPTIONTEXT", COLOR_CAPTIONTEXT},
1363 {"SYS_GRAYTEXT", COLOR_GRAYTEXT},
1364 {"SYS_HIGHLIGHT", COLOR_HIGHLIGHT},
1365 {"SYS_HIGHLIGHTTEXT", COLOR_HIGHLIGHTTEXT},
1366 {"SYS_INACTIVEBORDER", COLOR_INACTIVEBORDER},
1367 {"SYS_INACTIVECAPTION", COLOR_INACTIVECAPTION},
1368 {"SYS_INACTIVECAPTIONTEXT", COLOR_INACTIVECAPTIONTEXT},
1369 {"SYS_MENU", COLOR_MENU},
1370 {"SYS_MENUTEXT", COLOR_MENUTEXT},
1371 {"SYS_SCROLLBAR", COLOR_SCROLLBAR},
1372 {"SYS_WINDOW", COLOR_WINDOW},
1373 {"SYS_WINDOWFRAME", COLOR_WINDOWFRAME},
1374 {"SYS_WINDOWTEXT", COLOR_WINDOWTEXT}
1375 };
1376
1377 int r, g, b;
1378 int i;
1379
1380 if (name[0] == '#' && strlen(name) == 7)
1381 {
1382 /* Name is in "#rrggbb" format */
1383 r = hex_digit(name[1]) * 16 + hex_digit(name[2]);
1384 g = hex_digit(name[3]) * 16 + hex_digit(name[4]);
1385 b = hex_digit(name[5]) * 16 + hex_digit(name[6]);
1386 if (r < 0 || g < 0 || b < 0)
1387 return INVALCOLOR;
1388 return RGB(r, g, b);
1389 }
1390 else
1391 {
1392 /* Check if the name is one of the colors we know */
1393 for (i = 0; i < sizeof(table) / sizeof(table[0]); i++)
1394 if (STRICMP(name, table[i].name) == 0)
1395 return table[i].color;
1396 }
1397
1398 /*
1399 * Try to look up a system colour.
1400 */
1401 for (i = 0; i < sizeof(sys_table) / sizeof(sys_table[0]); i++)
1402 if (STRICMP(name, sys_table[i].name) == 0)
1403 return GetSysColor(sys_table[i].color);
1404
1405 /*
1406 * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt".
1407 */
1408 {
1409#define LINE_LEN 100
1410 FILE *fd;
1411 char line[LINE_LEN];
1412 char_u *fname;
1413
1414 fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt");
1415 if (fname == NULL)
1416 return INVALCOLOR;
1417
1418 fd = fopen((char *)fname, "rt");
1419 vim_free(fname);
1420 if (fd == NULL)
1421 return INVALCOLOR;
1422
1423 while (!feof(fd))
1424 {
1425 int len;
1426 int pos;
1427 char *color;
1428
1429 fgets(line, LINE_LEN, fd);
1430 len = (int)STRLEN(line);
1431
1432 if (len <= 1 || line[len-1] != '\n')
1433 continue;
1434
1435 line[len-1] = '\0';
1436
1437 i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos);
1438 if (i != 3)
1439 continue;
1440
1441 color = line + pos;
1442
1443 if (STRICMP(color, name) == 0)
1444 {
1445 fclose(fd);
1446 return (guicolor_T) RGB(r, g, b);
1447 }
1448 }
1449
1450 fclose(fd);
1451 }
1452
1453 return INVALCOLOR;
1454}
1455/*
1456 * Return OK if the key with the termcap name "name" is supported.
1457 */
1458 int
1459gui_mch_haskey(char_u *name)
1460{
1461 int i;
1462
1463 for (i = 0; special_keys[i].vim_code1 != NUL; i++)
1464 if (name[0] == special_keys[i].vim_code0 &&
1465 name[1] == special_keys[i].vim_code1)
1466 return OK;
1467 return FAIL;
1468}
1469
1470 void
1471gui_mch_beep(void)
1472{
1473 MessageBeep(MB_OK);
1474}
1475/*
1476 * Invert a rectangle from row r, column c, for nr rows and nc columns.
1477 */
1478 void
1479gui_mch_invert_rectangle(
1480 int r,
1481 int c,
1482 int nr,
1483 int nc)
1484{
1485 RECT rc;
1486
1487 /*
1488 * Note: InvertRect() excludes right and bottom of rectangle.
1489 */
1490 rc.left = FILL_X(c);
1491 rc.top = FILL_Y(r);
1492 rc.right = rc.left + nc * gui.char_width;
1493 rc.bottom = rc.top + nr * gui.char_height;
1494 InvertRect(s_hdc, &rc);
1495}
1496
1497/*
1498 * Iconify the GUI window.
1499 */
1500 void
1501gui_mch_iconify(void)
1502{
1503 ShowWindow(s_hwnd, SW_MINIMIZE);
1504}
1505
1506/*
1507 * Draw a cursor without focus.
1508 */
1509 void
1510gui_mch_draw_hollow_cursor(guicolor_T color)
1511{
1512 HBRUSH hbr;
1513 RECT rc;
1514
1515 /*
1516 * Note: FrameRect() excludes right and bottom of rectangle.
1517 */
1518 rc.left = FILL_X(gui.col);
1519 rc.top = FILL_Y(gui.row);
1520 rc.right = rc.left + gui.char_width;
1521#ifdef FEAT_MBYTE
1522 if (mb_lefthalve(gui.row, gui.col))
1523 rc.right += gui.char_width;
1524#endif
1525 rc.bottom = rc.top + gui.char_height;
1526 hbr = CreateSolidBrush(color);
1527 FrameRect(s_hdc, &rc, hbr);
1528 DeleteBrush(hbr);
1529}
1530/*
1531 * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using
1532 * color "color".
1533 */
1534 void
1535gui_mch_draw_part_cursor(
1536 int w,
1537 int h,
1538 guicolor_T color)
1539{
1540 HBRUSH hbr;
1541 RECT rc;
1542
1543 /*
1544 * Note: FillRect() excludes right and bottom of rectangle.
1545 */
1546 rc.left =
1547#ifdef FEAT_RIGHTLEFT
1548 /* vertical line should be on the right of current point */
1549 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w :
1550#endif
1551 FILL_X(gui.col);
1552 rc.top = FILL_Y(gui.row) + gui.char_height - h;
1553 rc.right = rc.left + w;
1554 rc.bottom = rc.top + h;
1555 hbr = CreateSolidBrush(color);
1556 FillRect(s_hdc, &rc, hbr);
1557 DeleteBrush(hbr);
1558}
1559
1560/*
1561 * Process a single Windows message.
1562 * If one is not available we hang until one is.
1563 */
1564 static void
1565process_message(void)
1566{
1567 MSG msg;
1568 UINT vk = 0; /* Virtual key */
1569 char_u string[40];
1570 int i;
1571 int modifiers = 0;
1572 int key;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001573#ifdef FEAT_MENU
1574 static char_u k10[] = {K_SPECIAL, 'k', ';', 0};
1575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576
1577 GetMessage(&msg, NULL, 0, 0);
1578
1579#ifdef FEAT_OLE
1580 /* Look after OLE Automation commands */
1581 if (msg.message == WM_OLE)
1582 {
1583 char_u *str = (char_u *)msg.lParam;
1584 add_to_input_buf(str, (int)STRLEN(str));
1585 vim_free(str);
1586 return;
1587 }
1588#endif
1589
1590#ifdef FEAT_NETBEANS_INTG
1591 if (msg.message == WM_NETBEANS)
1592 {
1593 messageFromNetbeansW32();
1594 return;
1595 }
1596#endif
1597
1598#ifdef FEAT_SNIFF
1599 if (sniff_request_waiting && want_sniff_request)
1600 {
1601 static char_u bytes[3] = {CSI, (char_u)KS_EXTRA, (char_u)KE_SNIFF};
1602 add_to_input_buf(bytes, 3); /* K_SNIFF */
1603 sniff_request_waiting = 0;
1604 want_sniff_request = 0;
1605 /* request is handled in normal.c */
1606 }
1607 if (msg.message == WM_USER)
1608 return;
1609#endif
1610
1611#ifdef MSWIN_FIND_REPLACE
1612 /* Don't process messages used by the dialog */
1613 if (s_findrep_hwnd != NULL && IsDialogMessage(s_findrep_hwnd, &msg))
1614 {
1615 HandleMouseHide(msg.message, msg.lParam);
1616 return;
1617 }
1618#endif
1619
1620 /*
1621 * Check if it's a special key that we recognise. If not, call
1622 * TranslateMessage().
1623 */
1624 if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN)
1625 {
1626 vk = (int) msg.wParam;
1627 /* handle key after dead key, but ignore shift, alt and control */
1628 if (dead_key && vk != VK_SHIFT && vk != VK_MENU && vk != VK_CONTROL)
1629 {
1630 dead_key = 0;
1631 /* handle non-alphabetic keys (ones that hopefully cannot generate
1632 * umlaut-characters), unless when control is down */
1633 if (vk < 'A' || vk > 'Z' || (GetKeyState(VK_CONTROL) & 0x8000))
1634 {
1635 MSG dm;
1636
1637 dm.message = msg.message;
1638 dm.hwnd = msg.hwnd;
1639 dm.wParam = VK_SPACE;
1640 MyTranslateMessage(&dm); /* generate dead character */
1641 if (vk != VK_SPACE) /* and send current character once more */
1642 PostMessage(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1643 return;
1644 }
1645 }
1646
1647 /* Check for CTRL-BREAK */
1648 if (vk == VK_CANCEL)
1649 {
1650 trash_input_buf();
1651 got_int = TRUE;
1652 string[0] = Ctrl_C;
1653 add_to_input_buf(string, 1);
1654 }
1655
1656 for (i = 0; special_keys[i].key_sym != 0; i++)
1657 {
1658 /* ignore VK_SPACE when ALT key pressed: system menu */
1659 if (special_keys[i].key_sym == vk
1660 && (vk != VK_SPACE || !(GetKeyState(VK_MENU) & 0x8000)))
1661 {
1662#ifdef FEAT_MENU
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001663 /* Check for <F10>: Windows selects the menu. When <F10> is
1664 * mapped we want to use the mapping instead. */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 if (vk == VK_F10
1666 && gui.menu_is_active
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001667 && check_map(k10, State, FALSE) == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 break;
1669#endif
1670 if (GetKeyState(VK_SHIFT) & 0x8000)
1671 modifiers |= MOD_MASK_SHIFT;
1672 /*
1673 * Don't use caps-lock as shift, because these are special keys
1674 * being considered here, and we only want letters to get
1675 * shifted -- webb
1676 */
1677 /*
1678 if (GetKeyState(VK_CAPITAL) & 0x0001)
1679 modifiers ^= MOD_MASK_SHIFT;
1680 */
1681 if (GetKeyState(VK_CONTROL) & 0x8000)
1682 modifiers |= MOD_MASK_CTRL;
1683 if (GetKeyState(VK_MENU) & 0x8000)
1684 modifiers |= MOD_MASK_ALT;
1685
1686 if (special_keys[i].vim_code1 == NUL)
1687 key = special_keys[i].vim_code0;
1688 else
1689 key = TO_SPECIAL(special_keys[i].vim_code0,
1690 special_keys[i].vim_code1);
1691 key = simplify_key(key, &modifiers);
1692 if (key == CSI)
1693 key = K_CSI;
1694
1695 if (modifiers)
1696 {
1697 string[0] = CSI;
1698 string[1] = KS_MODIFIER;
1699 string[2] = modifiers;
1700 add_to_input_buf(string, 3);
1701 }
1702
1703 if (IS_SPECIAL(key))
1704 {
1705 string[0] = CSI;
1706 string[1] = K_SECOND(key);
1707 string[2] = K_THIRD(key);
1708 add_to_input_buf(string, 3);
1709 }
1710 else
1711 {
1712 int len;
1713
1714 /* Handle "key" as a Unicode character. */
1715 len = char_to_string(key, string, 40);
1716 add_to_input_buf(string, len);
1717 }
1718 break;
1719 }
1720 }
1721 if (special_keys[i].key_sym == 0)
1722 {
1723 /* Some keys need C-S- where they should only need C-.
1724 * Ignore 0xff, Windows XP sends it when NUMLOCK has changed since
1725 * system startup (Helmut Stiegler, 2003 Oct 3). */
1726 if (vk != 0xff
1727 && (GetKeyState(VK_CONTROL) & 0x8000)
1728 && !(GetKeyState(VK_SHIFT) & 0x8000)
1729 && !(GetKeyState(VK_MENU) & 0x8000))
1730 {
1731 /* CTRL-6 is '^'; Japanese keyboard maps '^' to vk == 0xDE */
1732 if (vk == '6' || MapVirtualKey(vk, 2) == (UINT)'^')
1733 {
1734 string[0] = Ctrl_HAT;
1735 add_to_input_buf(string, 1);
1736 }
1737 /* vk == 0xBD AZERTY for CTRL-'-', but CTRL-[ for * QWERTY! */
1738 else if (vk == 0xBD) /* QWERTY for CTRL-'-' */
1739 {
1740 string[0] = Ctrl__;
1741 add_to_input_buf(string, 1);
1742 }
1743 /* CTRL-2 is '@'; Japanese keyboard maps '@' to vk == 0xC0 */
1744 else if (vk == '2' || MapVirtualKey(vk, 2) == (UINT)'@')
1745 {
1746 string[0] = Ctrl_AT;
1747 add_to_input_buf(string, 1);
1748 }
1749 else
1750 MyTranslateMessage(&msg);
1751 }
1752 else
1753 MyTranslateMessage(&msg);
1754 }
1755 }
1756#ifdef FEAT_MBYTE_IME
1757 else if (msg.message == WM_IME_NOTIFY)
1758 _OnImeNotify(msg.hwnd, (DWORD)msg.wParam, (DWORD)msg.lParam);
1759 else if (msg.message == WM_KEYUP && im_get_status())
1760 /* added for non-MS IME (Yasuhiro Matsumoto) */
1761 MyTranslateMessage(&msg);
1762#endif
1763#if !defined(FEAT_MBYTE_IME) && defined(GLOBAL_IME)
1764/* GIME_TEST */
1765 else if (msg.message == WM_IME_STARTCOMPOSITION)
1766 {
1767 POINT point;
1768
1769 global_ime_set_font(&norm_logfont);
1770 point.x = FILL_X(gui.col);
1771 point.y = FILL_Y(gui.row);
1772 MapWindowPoints(s_textArea, s_hwnd, &point, 1);
1773 global_ime_set_position(&point);
1774 }
1775#endif
1776
1777#ifdef FEAT_MENU
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001778 /* Check for <F10>: Default effect is to select the menu. When <F10> is
1779 * mapped we need to stop it here to avoid strange effects (e.g., for the
1780 * key-up event) */
1781 if (vk != VK_F10 || check_map(k10, State, FALSE) == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782#endif
1783 DispatchMessage(&msg);
1784}
1785
1786/*
1787 * Catch up with any queued events. This may put keyboard input into the
1788 * input buffer, call resize call-backs, trigger timers etc. If there is
1789 * nothing in the event queue (& no timers pending), then we return
1790 * immediately.
1791 */
1792 void
1793gui_mch_update(void)
1794{
1795 MSG msg;
1796
1797 if (!s_busy_processing)
1798 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)
1799 && !vim_is_input_buf_full())
1800 process_message();
1801}
1802
1803/*
1804 * GUI input routine called by gui_wait_for_chars(). Waits for a character
1805 * from the keyboard.
1806 * wtime == -1 Wait forever.
1807 * wtime == 0 This should never happen.
1808 * wtime > 0 Wait wtime milliseconds for a character.
1809 * Returns OK if a character was found to be available within the given time,
1810 * or FAIL otherwise.
1811 */
1812 int
1813gui_mch_wait_for_chars(int wtime)
1814{
1815 MSG msg;
1816 int focus;
1817
1818 s_timed_out = FALSE;
1819
1820 if (wtime > 0)
1821 {
1822 /* Don't do anything while processing a (scroll) message. */
1823 if (s_busy_processing)
1824 return FAIL;
1825 s_wait_timer = (UINT)SetTimer(NULL, 0, (UINT)wtime,
1826 (TIMERPROC)_OnTimer);
1827 }
1828
1829 allow_scrollbar = TRUE;
1830
1831 focus = gui.in_focus;
1832 while (!s_timed_out)
1833 {
1834 /* Stop or start blinking when focus changes */
1835 if (gui.in_focus != focus)
1836 {
1837 if (gui.in_focus)
1838 gui_mch_start_blink();
1839 else
1840 gui_mch_stop_blink();
1841 focus = gui.in_focus;
1842 }
1843
1844 if (s_need_activate)
1845 {
1846#ifdef WIN32
1847 (void)SetForegroundWindow(s_hwnd);
1848#else
1849 (void)SetActiveWindow(s_hwnd);
1850#endif
1851 s_need_activate = FALSE;
1852 }
1853
1854 /*
1855 * Don't use gui_mch_update() because then we will spin-lock until a
1856 * char arrives, instead we use GetMessage() to hang until an
1857 * event arrives. No need to check for input_buf_full because we are
1858 * returning as soon as it contains a single char -- webb
1859 */
1860 process_message();
1861
1862 if (input_available())
1863 {
1864 if (s_wait_timer != 0 && !s_timed_out)
1865 {
1866 KillTimer(NULL, s_wait_timer);
1867
1868 /* Eat spurious WM_TIMER messages */
1869 while (PeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
1870 ;
1871 s_wait_timer = 0;
1872 }
1873 allow_scrollbar = FALSE;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001874
1875 /* Clear pending mouse button, the release event may have been
1876 * taken by the dialog window. */
1877 s_button_pending = -1;
1878
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 return OK;
1880 }
1881 }
1882 allow_scrollbar = FALSE;
1883 return FAIL;
1884}
1885
1886/*
1887 * Clear a rectangular region of the screen from text pos (row1, col1) to
1888 * (row2, col2) inclusive.
1889 */
1890 void
1891gui_mch_clear_block(
1892 int row1,
1893 int col1,
1894 int row2,
1895 int col2)
1896{
1897 RECT rc;
1898
1899 /*
1900 * Clear one extra pixel at the far right, for when bold characters have
1901 * spilled over to the window border.
1902 * Note: FillRect() excludes right and bottom of rectangle.
1903 */
1904 rc.left = FILL_X(col1);
1905 rc.top = FILL_Y(row1);
1906 rc.right = FILL_X(col2 + 1) + (col2 == Columns - 1);
1907 rc.bottom = FILL_Y(row2 + 1);
1908 clear_rect(&rc);
1909}
1910
1911/*
1912 * Clear the whole text window.
1913 */
1914 void
1915gui_mch_clear_all(void)
1916{
1917 RECT rc;
1918
1919 rc.left = 0;
1920 rc.top = 0;
1921 rc.right = Columns * gui.char_width + 2 * gui.border_width;
1922 rc.bottom = Rows * gui.char_height + 2 * gui.border_width;
1923 clear_rect(&rc);
1924}
1925/*
1926 * Menu stuff.
1927 */
1928
1929 void
1930gui_mch_enable_menu(int flag)
1931{
1932#ifdef FEAT_MENU
1933 SetMenu(s_hwnd, flag ? s_menuBar : NULL);
1934#endif
1935}
1936
1937 void
1938gui_mch_set_menu_pos(
1939 int x,
1940 int y,
1941 int w,
1942 int h)
1943{
1944 /* It will be in the right place anyway */
1945}
1946
1947#if defined(FEAT_MENU) || defined(PROTO)
1948/*
1949 * Make menu item hidden or not hidden
1950 */
1951 void
1952gui_mch_menu_hidden(
1953 vimmenu_T *menu,
1954 int hidden)
1955{
1956 /*
1957 * This doesn't do what we want. Hmm, just grey the menu items for now.
1958 */
1959 /*
1960 if (hidden)
1961 EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_DISABLED);
1962 else
1963 EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_ENABLED);
1964 */
1965 gui_mch_menu_grey(menu, hidden);
1966}
1967
1968/*
1969 * This is called after setting all the menus to grey/hidden or not.
1970 */
1971 void
1972gui_mch_draw_menubar(void)
1973{
1974 DrawMenuBar(s_hwnd);
1975}
1976#endif /*FEAT_MENU*/
1977
1978#ifndef PROTO
1979void
1980#ifdef VIMDLL
1981_export
1982#endif
1983_cdecl
1984SaveInst(HINSTANCE hInst)
1985{
1986 s_hinst = hInst;
1987}
1988#endif
1989
1990/*
1991 * Return the RGB value of a pixel as a long.
1992 */
1993 long_u
1994gui_mch_get_rgb(guicolor_T pixel)
1995{
1996 return (GetRValue(pixel) << 16) + (GetGValue(pixel) << 8)
1997 + GetBValue(pixel);
1998}
1999
2000#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
2001/* Convert pixels in X to dialog units */
2002 static WORD
2003PixelToDialogX(int numPixels)
2004{
2005 return (WORD)((numPixels * 4) / s_dlgfntwidth);
2006}
2007
2008/* Convert pixels in Y to dialog units */
2009 static WORD
2010PixelToDialogY(int numPixels)
2011{
2012 return (WORD)((numPixels * 8) / s_dlgfntheight);
2013}
2014
2015/* Return the width in pixels of the given text in the given DC. */
2016 static int
2017GetTextWidth(HDC hdc, char_u *str, int len)
2018{
2019 SIZE size;
2020
2021 GetTextExtentPoint(hdc, str, len, &size);
2022 return size.cx;
2023}
2024
2025#ifdef FEAT_MBYTE
2026/*
2027 * Return the width in pixels of the given text in the given DC, taking care
2028 * of 'encoding' to active codepage conversion.
2029 */
2030 static int
2031GetTextWidthEnc(HDC hdc, char_u *str, int len)
2032{
2033 SIZE size;
2034 WCHAR *wstr;
2035 int n;
2036 int wlen = len;
2037
2038 if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
2039 {
2040 /* 'encoding' differs from active codepage: convert text and use wide
2041 * function */
2042 wstr = enc_to_ucs2(str, &wlen);
2043 if (wstr != NULL)
2044 {
2045 n = GetTextExtentPointW(hdc, wstr, wlen, &size);
2046 vim_free(wstr);
2047 if (n)
2048 return size.cx;
2049 }
2050 }
2051
2052 return GetTextWidth(hdc, str, len);
2053}
2054#else
2055# define GetTextWidthEnc(h, s, l) GetTextWidth((h), (s), (l))
2056#endif
2057
2058/*
2059 * A quick little routine that will center one window over another, handy for
2060 * dialog boxes. Taken from the Win32SDK samples.
2061 */
2062 static BOOL
2063CenterWindow(
2064 HWND hwndChild,
2065 HWND hwndParent)
2066{
2067 RECT rChild, rParent;
2068 int wChild, hChild, wParent, hParent;
2069 int wScreen, hScreen, xNew, yNew;
2070 HDC hdc;
2071
2072 GetWindowRect(hwndChild, &rChild);
2073 wChild = rChild.right - rChild.left;
2074 hChild = rChild.bottom - rChild.top;
2075
2076 /* If Vim is minimized put the window in the middle of the screen. */
2077 if (IsMinimized(hwndParent))
2078 {
2079#ifdef WIN16
2080 rParent.left = 0;
2081 rParent.top = 0;
2082 rParent.right = GetSystemMetrics(SM_CXSCREEN);
2083 rParent.bottom = GetSystemMetrics(SM_CYFULLSCREEN);
2084#else
2085 SystemParametersInfo(SPI_GETWORKAREA, 0, &rParent, 0);
2086#endif
2087 }
2088 else
2089 GetWindowRect(hwndParent, &rParent);
2090 wParent = rParent.right - rParent.left;
2091 hParent = rParent.bottom - rParent.top;
2092
2093 hdc = GetDC(hwndChild);
2094 wScreen = GetDeviceCaps (hdc, HORZRES);
2095 hScreen = GetDeviceCaps (hdc, VERTRES);
2096 ReleaseDC(hwndChild, hdc);
2097
2098 xNew = rParent.left + ((wParent - wChild) /2);
2099 if (xNew < 0)
2100 {
2101 xNew = 0;
2102 }
2103 else if ((xNew+wChild) > wScreen)
2104 {
2105 xNew = wScreen - wChild;
2106 }
2107
2108 yNew = rParent.top + ((hParent - hChild) /2);
2109 if (yNew < 0)
2110 yNew = 0;
2111 else if ((yNew+hChild) > hScreen)
2112 yNew = hScreen - hChild;
2113
2114 return SetWindowPos(hwndChild, NULL, xNew, yNew, 0, 0,
2115 SWP_NOSIZE | SWP_NOZORDER);
2116}
2117#endif /* FEAT_GUI_DIALOG */
2118
2119void
2120gui_mch_activate_window(void)
2121{
2122 (void)SetActiveWindow(s_hwnd);
2123}
2124
2125#if defined(FEAT_TOOLBAR) || defined(PROTO)
2126 void
2127gui_mch_show_toolbar(int showit)
2128{
2129 if (s_toolbarhwnd == NULL)
2130 return;
2131
2132 if (showit)
2133 ShowWindow(s_toolbarhwnd, SW_SHOW);
2134 else
2135 ShowWindow(s_toolbarhwnd, SW_HIDE);
2136}
2137
2138/* Then number of bitmaps is fixed. Exit is missing! */
2139#define TOOLBAR_BITMAP_COUNT 31
2140
2141#endif
2142
2143/*
2144 * ":simalt" command.
2145 */
2146 void
2147ex_simalt(exarg_T *eap)
2148{
2149 char_u *keys = eap->arg;
2150
2151 PostMessage(s_hwnd, WM_SYSCOMMAND, (WPARAM)SC_KEYMENU, (LPARAM)0);
2152 while (*keys)
2153 {
2154 if (*keys == '~')
2155 *keys = ' '; /* for showing system menu */
2156 PostMessage(s_hwnd, WM_CHAR, (WPARAM)*keys, (LPARAM)0);
2157 keys++;
2158 }
2159}
2160
2161/*
2162 * Create the find & replace dialogs.
2163 * You can't have both at once: ":find" when replace is showing, destroys
2164 * the replace dialog first, and the other way around.
2165 */
2166#ifdef MSWIN_FIND_REPLACE
2167 static void
2168initialise_findrep(char_u *initial_string)
2169{
2170 int wword = FALSE;
2171 int mcase = !p_ic;
2172 char_u *entry_text;
2173
2174 /* Get the search string to use. */
2175 entry_text = get_find_dialog_text(initial_string, &wword, &mcase);
2176
2177 s_findrep_struct.hwndOwner = s_hwnd;
2178 s_findrep_struct.Flags = FR_DOWN;
2179 if (mcase)
2180 s_findrep_struct.Flags |= FR_MATCHCASE;
2181 if (wword)
2182 s_findrep_struct.Flags |= FR_WHOLEWORD;
2183 if (entry_text != NULL && *entry_text != NUL)
2184 {
2185 STRNCPY(s_findrep_struct.lpstrFindWhat, entry_text,
2186 s_findrep_struct.wFindWhatLen);
2187 s_findrep_struct.lpstrFindWhat[s_findrep_struct.wFindWhatLen - 1] = NUL;
2188 s_findrep_struct.lpstrReplaceWith[0] = NUL;
2189 }
2190 vim_free(entry_text);
2191}
2192#endif
2193
2194 void
2195gui_mch_find_dialog(exarg_T *eap)
2196{
2197#ifdef MSWIN_FIND_REPLACE
2198 if (s_findrep_msg != 0)
2199 {
2200 if (IsWindow(s_findrep_hwnd) && !s_findrep_is_find)
2201 DestroyWindow(s_findrep_hwnd);
2202
2203 if (!IsWindow(s_findrep_hwnd))
2204 {
2205 initialise_findrep(eap->arg);
2206 s_findrep_hwnd = FindText((LPFINDREPLACE) &s_findrep_struct);
2207 }
2208
2209 (void)SetWindowText(s_findrep_hwnd,
2210 (LPCSTR)_("Find string (use '\\\\' to find a '\\')"));
2211 (void)SetFocus(s_findrep_hwnd);
2212
2213 s_findrep_is_find = TRUE;
2214 }
2215#endif
2216}
2217
2218
2219 void
2220gui_mch_replace_dialog(exarg_T *eap)
2221{
2222#ifdef MSWIN_FIND_REPLACE
2223 if (s_findrep_msg != 0)
2224 {
2225 if (IsWindow(s_findrep_hwnd) && s_findrep_is_find)
2226 DestroyWindow(s_findrep_hwnd);
2227
2228 if (!IsWindow(s_findrep_hwnd))
2229 {
2230 initialise_findrep(eap->arg);
2231 s_findrep_hwnd = ReplaceText((LPFINDREPLACE) &s_findrep_struct);
2232 }
2233
2234 (void)SetWindowText(s_findrep_hwnd,
2235 (LPCSTR)_("Find & Replace (use '\\\\' to find a '\\')"));
2236 (void)SetFocus(s_findrep_hwnd);
2237
2238 s_findrep_is_find = FALSE;
2239 }
2240#endif
2241}
2242
2243
2244/*
2245 * Set visibility of the pointer.
2246 */
2247 void
2248gui_mch_mousehide(int hide)
2249{
2250 if (hide != gui.pointer_hidden)
2251 {
2252 ShowCursor(!hide);
2253 gui.pointer_hidden = hide;
2254 }
2255}
2256
2257#ifdef FEAT_MENU
2258 static void
2259gui_mch_show_popupmenu_at(vimmenu_T *menu, int x, int y)
2260{
2261 /* Unhide the mouse, we don't get move events here. */
2262 gui_mch_mousehide(FALSE);
2263
2264 (void)TrackPopupMenu(
2265 (HMENU)menu->submenu_id,
2266 TPM_LEFTALIGN | TPM_LEFTBUTTON,
2267 x, y,
2268 (int)0, /*reserved param*/
2269 s_hwnd,
2270 NULL);
2271 /*
2272 * NOTE: The pop-up menu can eat the mouse up event.
2273 * We deal with this in normal.c.
2274 */
2275}
2276#endif
2277
2278/*
2279 * Got a message when the system will go down.
2280 */
2281 static void
2282_OnEndSession(void)
2283{
2284 getout_preserve_modified(1);
2285}
2286
2287/*
2288 * Get this message when the user clicks on the cross in the top right corner
2289 * of a Windows95 window.
2290 */
2291 static void
2292_OnClose(
2293 HWND hwnd)
2294{
2295 gui_shell_closed();
2296}
2297
2298/*
2299 * Get a message when the window is being destroyed.
2300 */
2301 static void
2302_OnDestroy(
2303 HWND hwnd)
2304{
2305#ifdef WIN16_3DLOOK
2306 Ctl3dUnregister(s_hinst);
2307#endif
2308 if (!destroying)
2309 _OnClose(hwnd);
2310}
2311
2312 static void
2313_OnPaint(
2314 HWND hwnd)
2315{
2316 if (!IsMinimized(hwnd))
2317 {
2318 PAINTSTRUCT ps;
2319
2320 out_flush(); /* make sure all output has been processed */
2321 (void)BeginPaint(hwnd, &ps);
2322
2323#ifdef FEAT_MBYTE
2324 /* prevent multi-byte characters from misprinting on an invalid
2325 * rectangle */
2326 if (has_mbyte)
2327 {
2328 RECT rect;
2329
2330 GetClientRect(hwnd, &rect);
2331 ps.rcPaint.left = rect.left;
2332 ps.rcPaint.right = rect.right;
2333 }
2334#endif
2335
2336 if (!IsRectEmpty(&ps.rcPaint))
2337 gui_redraw(ps.rcPaint.left, ps.rcPaint.top,
2338 ps.rcPaint.right - ps.rcPaint.left + 1,
2339 ps.rcPaint.bottom - ps.rcPaint.top + 1);
2340 EndPaint(hwnd, &ps);
2341 }
2342}
2343
2344 static void
2345_OnSize(
2346 HWND hwnd,
2347 UINT state,
2348 int cx,
2349 int cy)
2350{
2351 if (!IsMinimized(hwnd))
2352 {
2353 gui_resize_shell(cx, cy);
2354
2355#ifdef FEAT_MENU
2356 /* Menu bar may wrap differently now */
2357 gui_mswin_get_menu_height(TRUE);
2358#endif
2359 }
2360}
2361
2362 static void
2363_OnSetFocus(
2364 HWND hwnd,
2365 HWND hwndOldFocus)
2366{
2367 gui_focus_change(TRUE);
2368 (void)MyWindowProc(hwnd, WM_SETFOCUS, (WPARAM)hwndOldFocus, 0);
2369}
2370
2371 static void
2372_OnKillFocus(
2373 HWND hwnd,
2374 HWND hwndNewFocus)
2375{
2376 gui_focus_change(FALSE);
2377 (void)MyWindowProc(hwnd, WM_KILLFOCUS, (WPARAM)hwndNewFocus, 0);
2378}
2379
2380/*
2381 * Get a message when the user switches back to vim
2382 */
2383#ifdef WIN16
2384 static BOOL
2385#else
2386 static LRESULT
2387#endif
2388_OnActivateApp(
2389 HWND hwnd,
2390 BOOL fActivate,
2391#ifdef WIN16
2392 HTASK dwThreadId
2393#else
2394 DWORD dwThreadId
2395#endif
2396 )
2397{
2398 /* we call gui_focus_change() in _OnSetFocus() */
2399 /* gui_focus_change((int)fActivate); */
2400 return MyWindowProc(hwnd, WM_ACTIVATEAPP, fActivate, (DWORD)dwThreadId);
2401}
2402
2403#if defined(FEAT_WINDOWS) || defined(PROTO)
2404 void
2405gui_mch_destroy_scrollbar(scrollbar_T *sb)
2406{
2407 DestroyWindow(sb->id);
2408}
2409#endif
2410
2411/*
2412 * Get current x mouse coordinate in text window.
2413 * Return -1 when unknown.
2414 */
2415 int
2416gui_mch_get_mouse_x(void)
2417{
2418 RECT rct;
2419 POINT mp;
2420
2421 (void)GetWindowRect(s_textArea, &rct);
2422 (void)GetCursorPos((LPPOINT)&mp);
2423 return (int)(mp.x - rct.left);
2424}
2425
2426/*
2427 * Get current y mouse coordinate in text window.
2428 * Return -1 when unknown.
2429 */
2430 int
2431gui_mch_get_mouse_y(void)
2432{
2433 RECT rct;
2434 POINT mp;
2435
2436 (void)GetWindowRect(s_textArea, &rct);
2437 (void)GetCursorPos((LPPOINT)&mp);
2438 return (int)(mp.y - rct.top);
2439}
2440
2441/*
2442 * Move mouse pointer to character at (x, y).
2443 */
2444 void
2445gui_mch_setmouse(int x, int y)
2446{
2447 RECT rct;
2448
2449 (void)GetWindowRect(s_textArea, &rct);
2450 (void)SetCursorPos(x + gui.border_offset + rct.left,
2451 y + gui.border_offset + rct.top);
2452}
2453
2454 static void
2455gui_mswin_get_valid_dimensions(
2456 int w,
2457 int h,
2458 int *valid_w,
2459 int *valid_h)
2460{
2461 int base_width, base_height;
2462
2463 base_width = gui_get_base_width()
2464 + GetSystemMetrics(SM_CXFRAME) * 2;
2465 base_height = gui_get_base_height()
2466 + GetSystemMetrics(SM_CYFRAME) * 2
2467 + GetSystemMetrics(SM_CYCAPTION)
2468#ifdef FEAT_MENU
2469 + gui_mswin_get_menu_height(FALSE)
2470#endif
2471 ;
2472 *valid_w = base_width +
2473 ((w - base_width) / gui.char_width) * gui.char_width;
2474 *valid_h = base_height +
2475 ((h - base_height) / gui.char_height) * gui.char_height;
2476}
2477
2478 void
2479gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
2480{
2481
2482 *screen_w = GetSystemMetrics(SM_CXFULLSCREEN)
2483 - GetSystemMetrics(SM_CXFRAME) * 2;
2484 /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include
2485 * the menubar for MSwin, we subtract it from the screen height, so that
2486 * the window size can be made to fit on the screen. */
2487 *screen_h = GetSystemMetrics(SM_CYFULLSCREEN)
2488 - GetSystemMetrics(SM_CYFRAME) * 2
2489#ifdef FEAT_MENU
2490 - gui_mswin_get_menu_height(FALSE)
2491#endif
2492 ;
2493}
2494
2495 void
2496gui_mch_flash(int msec)
2497{
2498 RECT rc;
2499
2500 /*
2501 * Note: InvertRect() excludes right and bottom of rectangle.
2502 */
2503 rc.left = 0;
2504 rc.top = 0;
2505 rc.right = gui.num_cols * gui.char_width;
2506 rc.bottom = gui.num_rows * gui.char_height;
2507 InvertRect(s_hdc, &rc);
2508 gui_mch_flush(); /* make sure it's displayed */
2509
2510 ui_delay((long)msec, TRUE); /* wait for a few msec */
2511
2512 InvertRect(s_hdc, &rc);
2513}
2514
2515/*
2516 * Return flags used for scrolling.
2517 * The SW_INVALIDATE is required when part of the window is covered or
2518 * off-screen. Refer to MS KB Q75236.
2519 */
2520 static int
2521get_scroll_flags(void)
2522{
2523 HWND hwnd;
2524 RECT rcVim, rcOther, rcDest;
2525
2526 GetWindowRect(s_hwnd, &rcVim);
2527 for (hwnd = s_hwnd; (hwnd = GetWindow(hwnd, GW_HWNDPREV)) != (HWND)0; )
2528 if (IsWindowVisible(hwnd))
2529 {
2530 GetWindowRect(hwnd, &rcOther);
2531 if (IntersectRect(&rcDest, &rcVim, &rcOther))
2532 return SW_INVALIDATE;
2533 }
2534 return 0;
2535}
2536
2537/*
2538 * Delete the given number of lines from the given row, scrolling up any
2539 * text further down within the scroll region.
2540 */
2541 void
2542gui_mch_delete_lines(
2543 int row,
2544 int num_lines)
2545{
2546 RECT rc;
2547
2548 rc.left = FILL_X(gui.scroll_region_left);
2549 rc.right = FILL_X(gui.scroll_region_right + 1);
2550 rc.top = FILL_Y(row);
2551 rc.bottom = FILL_Y(gui.scroll_region_bot + 1);
2552
2553 ScrollWindowEx(s_textArea, 0, -num_lines * gui.char_height,
2554 &rc, &rc, NULL, NULL, get_scroll_flags());
2555
2556 UpdateWindow(s_textArea);
2557 /* This seems to be required to avoid the cursor disappearing when
2558 * scrolling such that the cursor ends up in the top-left character on
2559 * the screen... But why? (Webb) */
2560 /* It's probably fixed by disabling drawing the cursor while scrolling. */
2561 /* gui.cursor_is_valid = FALSE; */
2562
2563 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
2564 gui.scroll_region_left,
2565 gui.scroll_region_bot, gui.scroll_region_right);
2566}
2567
2568/*
2569 * Insert the given number of lines before the given row, scrolling down any
2570 * following text within the scroll region.
2571 */
2572 void
2573gui_mch_insert_lines(
2574 int row,
2575 int num_lines)
2576{
2577 RECT rc;
2578
2579 rc.left = FILL_X(gui.scroll_region_left);
2580 rc.right = FILL_X(gui.scroll_region_right + 1);
2581 rc.top = FILL_Y(row);
2582 rc.bottom = FILL_Y(gui.scroll_region_bot + 1);
2583 /* The SW_INVALIDATE is required when part of the window is covered or
2584 * off-screen. How do we avoid it when it's not needed? */
2585 ScrollWindowEx(s_textArea, 0, num_lines * gui.char_height,
2586 &rc, &rc, NULL, NULL, get_scroll_flags());
2587
2588 UpdateWindow(s_textArea);
2589
2590 gui_clear_block(row, gui.scroll_region_left,
2591 row + num_lines - 1, gui.scroll_region_right);
2592}
2593
2594
2595 void
2596gui_mch_exit(int rc)
2597{
2598 ReleaseDC(s_textArea, s_hdc);
2599 DeleteObject(s_brush);
2600
2601#ifdef FEAT_TEAROFF
2602 /* Unload the tearoff bitmap */
2603 (void)DeleteObject((HGDIOBJ)s_htearbitmap);
2604#endif
2605
2606 /* Destroy our window (if we have one). */
2607 if (s_hwnd != NULL)
2608 {
2609 destroying = TRUE; /* ignore WM_DESTROY message now */
2610 DestroyWindow(s_hwnd);
2611 }
2612
2613#ifdef GLOBAL_IME
2614 global_ime_end();
2615#endif
2616}
2617
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002618 static char_u *
2619logfont2name(LOGFONT lf)
2620{
2621 char *p;
2622 char *res;
2623 char *charset_name;
2624
2625 charset_name = charset_id2name((int)lf.lfCharSet);
2626 res = alloc((unsigned)(strlen(lf.lfFaceName) + 20
2627 + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
2628 if (res != NULL)
2629 {
2630 p = res;
2631 /* make a normal font string out of the lf thing:*/
2632 sprintf((char *)p, "%s:h%d", lf.lfFaceName, pixels_to_points(
2633 lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
2634 while (*p)
2635 {
2636 if (*p == ' ')
2637 *p = '_';
2638 ++p;
2639 }
2640#ifndef MSWIN16_FASTTEXT
2641 if (lf.lfItalic)
2642 STRCAT(p, ":i");
2643 if (lf.lfWeight >= FW_BOLD)
2644 STRCAT(p, ":b");
2645#endif
2646 if (lf.lfUnderline)
2647 STRCAT(p, ":u");
2648 if (lf.lfStrikeOut)
2649 STRCAT(p, ":s");
2650 if (charset_name != NULL)
2651 {
2652 STRCAT(p, ":c");
2653 STRCAT(p, charset_name);
2654 }
2655 }
2656
2657 return res;
2658}
2659
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660/*
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002661 * Initialise vim to use the font with the given name.
2662 * Return FAIL if the font could not be loaded, OK otherwise.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 */
2664 int
2665gui_mch_init_font(char_u *font_name, int fontset)
2666{
2667 LOGFONT lf;
2668 GuiFont font = NOFONT;
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002669 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670
2671 /* Load the font */
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002672 if (get_logfont(&lf, font_name, NULL, TRUE) == OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 font = get_font_handle(&lf);
2674 if (font == NOFONT)
2675 return FAIL;
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002676
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 if (font_name == NULL)
2678 font_name = lf.lfFaceName;
2679#if defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME)
2680 norm_logfont = lf;
2681#endif
2682#ifdef FEAT_MBYTE_IME
2683 im_set_font(&lf);
2684#endif
2685 gui_mch_free_font(gui.norm_font);
2686 gui.norm_font = font;
2687 current_font_height = lf.lfHeight;
2688 GetFontSize(font);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002690 p = logfont2name(lf);
2691 if (p != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002692 {
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002693 hl_set_font_name(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002695 /* When setting 'guifont' to "*" replace it with the actual font name.
2696 * */
2697 if (STRCMP(font_name, "*") == 0 && STRCMP(p_guifont, "*") == 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 vim_free(p_guifont);
2700 p_guifont = p;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 }
Bram Moolenaard8b0cf12004-12-12 11:33:30 +00002702 else
2703 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 }
2705
2706#ifndef MSWIN16_FASTTEXT
2707 gui_mch_free_font(gui.ital_font);
2708 gui.ital_font = NOFONT;
2709 gui_mch_free_font(gui.bold_font);
2710 gui.bold_font = NOFONT;
2711 gui_mch_free_font(gui.boldital_font);
2712 gui.boldital_font = NOFONT;
2713
2714 if (!lf.lfItalic)
2715 {
2716 lf.lfItalic = TRUE;
2717 gui.ital_font = get_font_handle(&lf);
2718 lf.lfItalic = FALSE;
2719 }
2720 if (lf.lfWeight < FW_BOLD)
2721 {
2722 lf.lfWeight = FW_BOLD;
2723 gui.bold_font = get_font_handle(&lf);
2724 if (!lf.lfItalic)
2725 {
2726 lf.lfItalic = TRUE;
2727 gui.boldital_font = get_font_handle(&lf);
2728 }
2729 }
2730#endif
2731
2732 return OK;
2733}
2734
2735/*
2736 * Return TRUE if the GUI window is maximized, filling the whole screen.
2737 */
2738 int
2739gui_mch_maximized()
2740{
2741 return IsZoomed(s_hwnd);
2742}
2743
2744/*
2745 * Called when the font changed while the window is maximized. Compute the
2746 * new Rows and Columns. This is like resizing the window.
2747 */
2748 void
2749gui_mch_newfont()
2750{
2751 RECT rect;
2752
2753 GetWindowRect(s_hwnd, &rect);
2754 gui_resize_shell(rect.right - rect.left
2755 - GetSystemMetrics(SM_CXFRAME) * 2,
2756 rect.bottom - rect.top
2757 - GetSystemMetrics(SM_CYFRAME) * 2
2758 - GetSystemMetrics(SM_CYCAPTION)
2759#ifdef FEAT_MENU
2760 - gui_mswin_get_menu_height(FALSE)
2761#endif
2762 );
2763}
2764
2765/*
2766 * Set the window title
2767 */
2768 void
2769gui_mch_settitle(
2770 char_u *title,
2771 char_u *icon)
2772{
2773#ifdef FEAT_MBYTE
2774 if (title != NULL && enc_codepage >= 0 && enc_codepage != (int)GetACP())
2775 {
2776 WCHAR *wbuf;
2777 int n;
2778
2779 /* Convert the title from 'encoding' to ucs2. */
2780 wbuf = (WCHAR *)enc_to_ucs2(title, NULL);
2781 if (wbuf != NULL)
2782 {
2783 n = SetWindowTextW(s_hwnd, wbuf);
2784 vim_free(wbuf);
2785 if (n != 0 || GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
2786 return;
2787 /* Retry with non-wide function (for Windows 98). */
2788 }
2789 }
2790#endif
2791 SetWindowText(s_hwnd, (LPCSTR)(title == NULL ? "VIM" : (char *)title));
2792}
2793
2794#ifdef FEAT_MOUSESHAPE
2795/* Table for shape IDCs. Keep in sync with the mshape_names[] table in
2796 * misc2.c! */
2797static LPCSTR mshape_idcs[] =
2798{
2799 MAKEINTRESOURCE(IDC_ARROW), /* arrow */
2800 MAKEINTRESOURCE(0), /* blank */
2801 MAKEINTRESOURCE(IDC_IBEAM), /* beam */
2802 MAKEINTRESOURCE(IDC_SIZENS), /* updown */
2803 MAKEINTRESOURCE(IDC_SIZENS), /* udsizing */
2804 MAKEINTRESOURCE(IDC_SIZEWE), /* leftright */
2805 MAKEINTRESOURCE(IDC_SIZEWE), /* lrsizing */
2806 MAKEINTRESOURCE(IDC_WAIT), /* busy */
2807#ifdef WIN3264
2808 MAKEINTRESOURCE(IDC_NO), /* no */
2809#else
2810 MAKEINTRESOURCE(IDC_ICON), /* no */
2811#endif
2812 MAKEINTRESOURCE(IDC_ARROW), /* crosshair */
2813 MAKEINTRESOURCE(IDC_ARROW), /* hand1 */
2814 MAKEINTRESOURCE(IDC_ARROW), /* hand2 */
2815 MAKEINTRESOURCE(IDC_ARROW), /* pencil */
2816 MAKEINTRESOURCE(IDC_ARROW), /* question */
2817 MAKEINTRESOURCE(IDC_ARROW), /* right-arrow */
2818 MAKEINTRESOURCE(IDC_UPARROW), /* up-arrow */
2819 MAKEINTRESOURCE(IDC_ARROW) /* last one */
2820};
2821
2822 void
2823mch_set_mouse_shape(int shape)
2824{
2825 LPCSTR idc;
2826
2827 if (shape == MSHAPE_HIDE)
2828 ShowCursor(FALSE);
2829 else
2830 {
2831 if (shape >= MSHAPE_NUMBERED)
2832 idc = MAKEINTRESOURCE(IDC_ARROW);
2833 else
2834 idc = mshape_idcs[shape];
2835#ifdef _WIN64
2836 SetClassLongPtr(s_textArea, GCLP_HCURSOR, (LONG_PTR)LoadCursor(NULL, idc));
2837#else
2838# ifdef WIN32
2839 SetClassLong(s_textArea, GCL_HCURSOR, (LONG)LoadCursor(NULL, idc));
2840# else
2841 SetClassWord(s_textArea, GCW_HCURSOR, (WORD)LoadCursor(NULL, idc));
2842# endif
2843#endif
2844 if (!p_mh)
2845 {
2846 POINT mp;
2847
2848 /* Set the position to make it redrawn with the new shape. */
2849 (void)GetCursorPos((LPPOINT)&mp);
2850 (void)SetCursorPos(mp.x, mp.y);
2851 ShowCursor(TRUE);
2852 }
2853 }
2854}
2855#endif
2856
2857#ifdef FEAT_BROWSE
2858/*
2859 * The file browser exists in two versions: with "W" uses wide characters,
2860 * without "W" the current codepage. When FEAT_MBYTE is defined and on
2861 * Windows NT/2000/XP the "W" functions are used.
2862 */
2863
2864# if defined(FEAT_MBYTE) && defined(WIN3264)
2865/*
2866 * Wide version of convert_filter(). Keep in sync!
2867 */
2868 static WCHAR *
2869convert_filterW(char_u *s)
2870{
2871 WCHAR *res;
2872 unsigned s_len = (unsigned)STRLEN(s);
2873 unsigned i;
2874
2875 res = (WCHAR *)alloc((s_len + 3) * sizeof(WCHAR));
2876 if (res != NULL)
2877 {
2878 for (i = 0; i < s_len; ++i)
2879 if (s[i] == '\t' || s[i] == '\n')
2880 res[i] = '\0';
2881 else
2882 res[i] = s[i];
2883 res[s_len] = NUL;
2884 /* Add two extra NULs to make sure it's properly terminated. */
2885 res[s_len + 1] = NUL;
2886 res[s_len + 2] = NUL;
2887 }
2888 return res;
2889}
2890
2891/*
2892 * Wide version of gui_mch_browse(). Keep in sync!
2893 */
2894 static char_u *
2895gui_mch_browseW(
2896 int saving,
2897 char_u *title,
2898 char_u *dflt,
2899 char_u *ext,
2900 char_u *initdir,
2901 char_u *filter)
2902{
2903 /* We always use the wide function. This means enc_to_ucs2() must work,
2904 * otherwise it fails miserably! */
2905 OPENFILENAMEW fileStruct;
2906 WCHAR fileBuf[MAXPATHL];
2907 WCHAR *wp;
2908 int i;
2909 WCHAR *titlep = NULL;
2910 WCHAR *extp = NULL;
2911 WCHAR *initdirp = NULL;
2912 WCHAR *filterp;
2913 char_u *p;
2914
2915 if (dflt == NULL)
2916 fileBuf[0] = NUL;
2917 else
2918 {
2919 wp = enc_to_ucs2(dflt, NULL);
2920 if (wp == NULL)
2921 fileBuf[0] = NUL;
2922 else
2923 {
2924 for (i = 0; wp[i] != NUL && i < MAXPATHL - 1; ++i)
2925 fileBuf[i] = wp[i];
2926 fileBuf[i] = NUL;
2927 vim_free(wp);
2928 }
2929 }
2930
2931 /* Convert the filter to Windows format. */
2932 filterp = convert_filterW(filter);
2933
2934 memset(&fileStruct, 0, sizeof(OPENFILENAMEW));
2935#ifdef OPENFILENAME_SIZE_VERSION_400
2936 /* be compatible with Windows NT 4.0 */
2937 /* TODO: what to use for OPENFILENAMEW??? */
2938 fileStruct.lStructSize = sizeof(OPENFILENAME_SIZE_VERSION_400);
2939#else
2940 fileStruct.lStructSize = sizeof(fileStruct);
2941#endif
2942
2943 if (title != NULL)
2944 titlep = enc_to_ucs2(title, NULL);
2945 fileStruct.lpstrTitle = titlep;
2946
2947 if (ext != NULL)
2948 extp = enc_to_ucs2(ext, NULL);
2949 fileStruct.lpstrDefExt = extp;
2950
2951 fileStruct.lpstrFile = fileBuf;
2952 fileStruct.nMaxFile = MAXPATHL;
2953 fileStruct.lpstrFilter = filterp;
2954 fileStruct.hwndOwner = s_hwnd; /* main Vim window is owner*/
2955 /* has an initial dir been specified? */
2956 if (initdir != NULL && *initdir != NUL)
2957 {
2958 /* Must have backslashes here, no matter what 'shellslash' says */
2959 initdirp = enc_to_ucs2(initdir, NULL);
2960 if (initdirp != NULL)
2961 {
2962 for (wp = initdirp; *wp != NUL; ++wp)
2963 if (*wp == '/')
2964 *wp = '\\';
2965 }
2966 fileStruct.lpstrInitialDir = initdirp;
2967 }
2968
2969 /*
2970 * TODO: Allow selection of multiple files. Needs another arg to this
2971 * function to ask for it, and need to use OFN_ALLOWMULTISELECT below.
2972 * Also, should we use OFN_FILEMUSTEXIST when opening? Vim can edit on
2973 * files that don't exist yet, so I haven't put it in. What about
2974 * OFN_PATHMUSTEXIST?
2975 * Don't use OFN_OVERWRITEPROMPT, Vim has its own ":confirm" dialog.
2976 */
2977 fileStruct.Flags = (OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY);
2978#ifdef FEAT_SHORTCUT
2979 if (curbuf->b_p_bin)
2980 fileStruct.Flags |= OFN_NODEREFERENCELINKS;
2981#endif
2982 if (saving)
2983 {
2984 if (!GetSaveFileNameW(&fileStruct))
2985 return NULL;
2986 }
2987 else
2988 {
2989 if (!GetOpenFileNameW(&fileStruct))
2990 return NULL;
2991 }
2992
2993 vim_free(filterp);
2994 vim_free(initdirp);
2995 vim_free(titlep);
2996 vim_free(extp);
2997
2998 /* Convert from UCS2 to 'encoding'. */
2999 p = ucs2_to_enc(fileBuf, NULL);
3000 if (p != NULL)
3001 /* when out of memory we get garbage for non-ASCII chars */
3002 STRCPY(fileBuf, p);
3003 vim_free(p);
3004
3005 /* Give focus back to main window (when using MDI). */
3006 SetFocus(s_hwnd);
3007
3008 /* Shorten the file name if possible */
3009 mch_dirname(IObuff, IOSIZE);
3010 p = shorten_fname((char_u *)fileBuf, IObuff);
3011 if (p == NULL)
3012 p = (char_u *)fileBuf;
3013 return vim_strsave(p);
3014}
3015# endif /* FEAT_MBYTE */
3016
3017
3018/*
3019 * Convert the string s to the proper format for a filter string by replacing
3020 * the \t and \n delimeters with \0.
3021 * Returns the converted string in allocated memory.
3022 *
3023 * Keep in sync with convert_filterW() above!
3024 */
3025 static char_u *
3026convert_filter(char_u *s)
3027{
3028 char_u *res;
3029 unsigned s_len = (unsigned)STRLEN(s);
3030 unsigned i;
3031
3032 res = alloc(s_len + 3);
3033 if (res != NULL)
3034 {
3035 for (i = 0; i < s_len; ++i)
3036 if (s[i] == '\t' || s[i] == '\n')
3037 res[i] = '\0';
3038 else
3039 res[i] = s[i];
3040 res[s_len] = NUL;
3041 /* Add two extra NULs to make sure it's properly terminated. */
3042 res[s_len + 1] = NUL;
3043 res[s_len + 2] = NUL;
3044 }
3045 return res;
3046}
3047
3048/*
Bram Moolenaar7171abe2004-10-11 10:06:20 +00003049 * Select a directory.
3050 */
3051 char_u *
3052gui_mch_browsedir(char_u *title, char_u *initdir)
3053{
3054 /* We fake this: Use a filter that doesn't select anything and a default
3055 * file name that won't be used. */
3056 return gui_mch_browse(0, title, (char_u *)_("Not Used"), NULL,
3057 initdir, (char_u *)_("Directory\t*.nothing\n"));
3058}
3059
3060/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 * Pop open a file browser and return the file selected, in allocated memory,
3062 * or NULL if Cancel is hit.
3063 * saving - TRUE if the file will be saved to, FALSE if it will be opened.
3064 * title - Title message for the file browser dialog.
3065 * dflt - Default name of file.
3066 * ext - Default extension to be added to files without extensions.
3067 * initdir - directory in which to open the browser (NULL = current dir)
3068 * filter - Filter for matched files to choose from.
3069 *
3070 * Keep in sync with gui_mch_browseW() above!
3071 */
3072 char_u *
3073gui_mch_browse(
3074 int saving,
3075 char_u *title,
3076 char_u *dflt,
3077 char_u *ext,
3078 char_u *initdir,
3079 char_u *filter)
3080{
3081 OPENFILENAME fileStruct;
3082 char_u fileBuf[MAXPATHL];
3083 char_u *initdirp = NULL;
3084 char_u *filterp;
3085 char_u *p;
3086
3087# if defined(FEAT_MBYTE) && defined(WIN3264)
3088 if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT)
3089 return gui_mch_browseW(saving, title, dflt, ext, initdir, filter);
3090# endif
3091
3092 if (dflt == NULL)
3093 fileBuf[0] = NUL;
3094 else
3095 {
3096 STRNCPY(fileBuf, dflt, MAXPATHL - 1);
3097 fileBuf[MAXPATHL - 1] = NUL;
3098 }
3099
3100 /* Convert the filter to Windows format. */
3101 filterp = convert_filter(filter);
3102
3103 memset(&fileStruct, 0, sizeof(OPENFILENAME));
3104#ifdef OPENFILENAME_SIZE_VERSION_400
3105 /* be compatible with Windows NT 4.0 */
3106 fileStruct.lStructSize = sizeof(OPENFILENAME_SIZE_VERSION_400);
3107#else
3108 fileStruct.lStructSize = sizeof(fileStruct);
3109#endif
3110
3111 fileStruct.lpstrTitle = title;
3112 fileStruct.lpstrDefExt = ext;
3113
3114 fileStruct.lpstrFile = fileBuf;
3115 fileStruct.nMaxFile = MAXPATHL;
3116 fileStruct.lpstrFilter = filterp;
3117 fileStruct.hwndOwner = s_hwnd; /* main Vim window is owner*/
3118 /* has an initial dir been specified? */
3119 if (initdir != NULL && *initdir != NUL)
3120 {
3121 /* Must have backslashes here, no matter what 'shellslash' says */
3122 initdirp = vim_strsave(initdir);
3123 if (initdirp != NULL)
3124 for (p = initdirp; *p != NUL; ++p)
3125 if (*p == '/')
3126 *p = '\\';
3127 fileStruct.lpstrInitialDir = initdirp;
3128 }
3129
3130 /*
3131 * TODO: Allow selection of multiple files. Needs another arg to this
3132 * function to ask for it, and need to use OFN_ALLOWMULTISELECT below.
3133 * Also, should we use OFN_FILEMUSTEXIST when opening? Vim can edit on
3134 * files that don't exist yet, so I haven't put it in. What about
3135 * OFN_PATHMUSTEXIST?
3136 * Don't use OFN_OVERWRITEPROMPT, Vim has its own ":confirm" dialog.
3137 */
3138 fileStruct.Flags = (OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY);
3139#ifdef FEAT_SHORTCUT
3140 if (curbuf->b_p_bin)
3141 fileStruct.Flags |= OFN_NODEREFERENCELINKS;
3142#endif
3143 if (saving)
3144 {
3145 if (!GetSaveFileName(&fileStruct))
3146 return NULL;
3147 }
3148 else
3149 {
3150 if (!GetOpenFileName(&fileStruct))
3151 return NULL;
3152 }
3153
3154 vim_free(filterp);
3155 vim_free(initdirp);
3156
3157 /* Give focus back to main window (when using MDI). */
3158 SetFocus(s_hwnd);
3159
3160 /* Shorten the file name if possible */
3161 mch_dirname(IObuff, IOSIZE);
3162 p = shorten_fname((char_u *)fileBuf, IObuff);
3163 if (p == NULL)
3164 p = (char_u *)fileBuf;
3165 return vim_strsave(p);
3166}
3167#endif /* FEAT_BROWSE */
3168
3169 static void
3170_OnDropFiles(
3171 HWND hwnd,
3172 HDROP hDrop)
3173{
3174#ifdef FEAT_WINDOWS
3175#ifdef WIN3264
3176# define BUFPATHLEN _MAX_PATH
3177# define DRAGQVAL 0xFFFFFFFF
3178#else
3179# define BUFPATHLEN MAXPATHL
3180# define DRAGQVAL 0xFFFF
3181#endif
3182#ifdef FEAT_MBYTE
3183 WCHAR wszFile[BUFPATHLEN];
3184#endif
3185 char szFile[BUFPATHLEN];
3186 UINT cFiles = DragQueryFile(hDrop, DRAGQVAL, NULL, 0);
3187 UINT i;
3188 char_u **fnames;
3189 POINT pt;
3190 int_u modifiers = 0;
3191
3192 /* TRACE("_OnDropFiles: %d files dropped\n", cFiles); */
3193
3194 /* Obtain dropped position */
3195 DragQueryPoint(hDrop, &pt);
3196 MapWindowPoints(s_hwnd, s_textArea, &pt, 1);
3197
3198# ifdef FEAT_VISUAL
3199 reset_VIsual();
3200# endif
3201
3202 fnames = (char_u **)alloc(cFiles * sizeof(char_u *));
3203
3204 if (fnames != NULL)
3205 for (i = 0; i < cFiles; ++i)
3206 {
3207#ifdef FEAT_MBYTE
3208 if (DragQueryFileW(hDrop, i, wszFile, BUFPATHLEN) > 0)
3209 fnames[i] = ucs2_to_enc(wszFile, NULL);
3210 else
3211#endif
3212 {
3213 DragQueryFile(hDrop, i, szFile, BUFPATHLEN);
3214 fnames[i] = vim_strsave(szFile);
3215 }
3216 }
3217
3218 DragFinish(hDrop);
3219
3220 if (fnames != NULL)
3221 {
3222 if ((GetKeyState(VK_SHIFT) & 0x8000) != 0)
3223 modifiers |= MOUSE_SHIFT;
3224 if ((GetKeyState(VK_CONTROL) & 0x8000) != 0)
3225 modifiers |= MOUSE_CTRL;
3226 if ((GetKeyState(VK_MENU) & 0x8000) != 0)
3227 modifiers |= MOUSE_ALT;
3228
3229 gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles);
3230
3231 s_need_activate = TRUE;
3232 }
3233#endif
3234}
3235
3236 static int
3237_OnScroll(
3238 HWND hwnd,
3239 HWND hwndCtl,
3240 UINT code,
3241 int pos)
3242{
3243 static UINT prev_code = 0; /* code of previous call */
3244 scrollbar_T *sb, *sb_info;
3245 long val;
3246 int dragging = FALSE;
3247 int dont_scroll_save = dont_scroll;
3248#ifndef WIN3264
3249 int nPos;
3250#else
3251 SCROLLINFO si;
3252
3253 si.cbSize = sizeof(si);
3254 si.fMask = SIF_POS;
3255#endif
3256
3257 sb = gui_mswin_find_scrollbar(hwndCtl);
3258 if (sb == NULL)
3259 return 0;
3260
3261 if (sb->wp != NULL) /* Left or right scrollbar */
3262 {
3263 /*
3264 * Careful: need to get scrollbar info out of first (left) scrollbar
3265 * for window, but keep real scrollbar too because we must pass it to
3266 * gui_drag_scrollbar().
3267 */
3268 sb_info = &sb->wp->w_scrollbars[0];
3269 }
3270 else /* Bottom scrollbar */
3271 sb_info = sb;
3272 val = sb_info->value;
3273
3274 switch (code)
3275 {
3276 case SB_THUMBTRACK:
3277 val = pos;
3278 dragging = TRUE;
3279 if (sb->scroll_shift > 0)
3280 val <<= sb->scroll_shift;
3281 break;
3282 case SB_LINEDOWN:
3283 val++;
3284 break;
3285 case SB_LINEUP:
3286 val--;
3287 break;
3288 case SB_PAGEDOWN:
3289 val += (sb_info->size > 2 ? sb_info->size - 2 : 1);
3290 break;
3291 case SB_PAGEUP:
3292 val -= (sb_info->size > 2 ? sb_info->size - 2 : 1);
3293 break;
3294 case SB_TOP:
3295 val = 0;
3296 break;
3297 case SB_BOTTOM:
3298 val = sb_info->max;
3299 break;
3300 case SB_ENDSCROLL:
3301 if (prev_code == SB_THUMBTRACK)
3302 {
3303 /*
3304 * "pos" only gives us 16-bit data. In case of large file,
3305 * use GetScrollPos() which returns 32-bit. Unfortunately it
3306 * is not valid while the scrollbar is being dragged.
3307 */
3308 val = GetScrollPos(hwndCtl, SB_CTL);
3309 if (sb->scroll_shift > 0)
3310 val <<= sb->scroll_shift;
3311 }
3312 break;
3313
3314 default:
3315 /* TRACE("Unknown scrollbar event %d\n", code); */
3316 return 0;
3317 }
3318 prev_code = code;
3319
3320#ifdef WIN3264
3321 si.nPos = (sb->scroll_shift > 0) ? val >> sb->scroll_shift : val;
3322 SetScrollInfo(hwndCtl, SB_CTL, &si, TRUE);
3323#else
3324 nPos = (sb->scroll_shift > 0) ? val >> sb->scroll_shift : val;
3325 SetScrollPos(hwndCtl, SB_CTL, nPos, TRUE);
3326#endif
3327
3328 /*
3329 * When moving a vertical scrollbar, move the other vertical scrollbar too.
3330 */
3331 if (sb->wp != NULL)
3332 {
3333 scrollbar_T *sba = sb->wp->w_scrollbars;
3334 HWND id = sba[ (sb == sba + SBAR_LEFT) ? SBAR_RIGHT : SBAR_LEFT].id;
3335
3336#ifdef WIN3264
3337 SetScrollInfo(id, SB_CTL, &si, TRUE);
3338#else
3339 SetScrollPos(id, SB_CTL, nPos, TRUE);
3340#endif
3341 }
3342
3343 /* Don't let us be interrupted here by another message. */
3344 s_busy_processing = TRUE;
3345
3346 /* When "allow_scrollbar" is FALSE still need to remember the new
3347 * position, but don't actually scroll by setting "dont_scroll". */
3348 dont_scroll = !allow_scrollbar;
3349
3350 gui_drag_scrollbar(sb, val, dragging);
3351
3352 s_busy_processing = FALSE;
3353 dont_scroll = dont_scroll_save;
3354
3355 return 0;
3356}
3357
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003358
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359/*
3360 * Get command line arguments.
3361 * Use "prog" as the name of the program and "cmdline" as the arguments.
3362 * Copy the arguments to allocated memory.
3363 * Return the number of arguments (including program name).
3364 * Return pointers to the arguments in "argvp".
3365 * Return pointer to buffer in "tofree".
3366 * Returns zero when out of memory.
3367 */
3368 int
3369get_cmd_args(char *prog, char *cmdline, char ***argvp, char **tofree)
3370{
3371 int i;
3372 char *p;
3373 char *progp;
3374 char *pnew = NULL;
3375 char *newcmdline;
3376 int inquote;
3377 int argc;
3378 char **argv = NULL;
3379 int round;
3380
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003381#ifdef FEAT_MBYTE
3382 /* Try using the Unicode version first, it takes care of conversion when
3383 * 'encoding' is changed. */
3384 argc = get_cmd_argsW(&argv);
3385 if (argc != 0)
3386 goto done;
3387#endif
3388
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389 /* Handle the program name. Remove the ".exe" extension, and find the 1st
3390 * non-space. */
3391 p = strrchr(prog, '.');
3392 if (p != NULL)
3393 *p = NUL;
3394 for (progp = prog; *progp == ' '; ++progp)
3395 ;
3396
3397 /* The command line is copied to allocated memory, so that we can change
3398 * it. Add the size of the string, the separating NUL and a terminating
3399 * NUL. */
3400 newcmdline = malloc(STRLEN(cmdline) + STRLEN(progp) + 2);
3401 if (newcmdline == NULL)
3402 return 0;
3403
3404 /*
3405 * First round: count the number of arguments ("pnew" == NULL).
3406 * Second round: produce the arguments.
3407 */
3408 for (round = 1; round <= 2; ++round)
3409 {
3410 /* First argument is the program name. */
3411 if (pnew != NULL)
3412 {
3413 argv[0] = pnew;
3414 strcpy(pnew, progp);
3415 pnew += strlen(pnew);
3416 *pnew++ = NUL;
3417 }
3418
3419 /*
3420 * Isolate each argument and put it in argv[].
3421 */
3422 p = cmdline;
3423 argc = 1;
3424 while (*p != NUL)
3425 {
3426 inquote = FALSE;
3427 if (pnew != NULL)
3428 argv[argc] = pnew;
3429 ++argc;
3430 while (*p != NUL && (inquote || (*p != ' ' && *p != '\t')))
3431 {
3432 /* Backslashes are only special when followed by a double
3433 * quote. */
3434 i = strspn(p, "\\");
3435 if (p[i] == '"')
3436 {
3437 /* Halve the number of backslashes. */
3438 if (i > 1 && pnew != NULL)
3439 {
3440 memset(pnew, '\\', i / 2);
3441 pnew += i / 2;
3442 }
3443
3444 /* Even nr of backslashes toggles quoting, uneven copies
3445 * the double quote. */
3446 if ((i & 1) == 0)
3447 inquote = !inquote;
3448 else if (pnew != NULL)
3449 *pnew++ = '"';
3450 p += i + 1;
3451 }
3452 else if (i > 0)
3453 {
3454 /* Copy span of backslashes unmodified. */
3455 if (pnew != NULL)
3456 {
3457 memset(pnew, '\\', i);
3458 pnew += i;
3459 }
3460 p += i;
3461 }
3462 else
3463 {
3464 if (pnew != NULL)
3465 *pnew++ = *p;
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00003466#ifdef FEAT_MBYTE
3467 /* Can't use mb_* functions, because 'encoding' is not
3468 * initialized yet here. */
3469 if (IsDBCSLeadByte(*p))
3470 {
3471 ++p;
3472 if (pnew != NULL)
3473 *pnew++ = *p;
3474 }
3475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476 ++p;
3477 }
3478 }
3479
3480 if (pnew != NUL)
3481 *pnew++ = NUL;
3482 while (*p == ' ' || *p == '\t')
3483 ++p; /* advance until a non-space */
3484 }
3485
3486 if (round == 1)
3487 {
3488 argv = (char **)malloc((argc + 1) * sizeof(char *));
3489 if (argv == NULL )
3490 return 0; /* malloc error */
3491 pnew = newcmdline;
3492 }
3493 }
3494
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003495done:
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00003497 argv[argc] = NULL; /* NULL-terminated list */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003498 *argvp = argv;
3499 return argc;
3500}