blob: b8e8ca9495b40a6e5d4fd375d0fc6a4372207d75 [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_w16.c
12 *
13 * GUI support for Microsoft Windows 3.1x
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 * Vince Negri then butchered the code to get it compiling for
20 * 16-bit windows.
21 *
22 */
23
24/*
25 * Include the common stuff for MS-Windows GUI.
26 */
27#include "gui_w48.c"
28
29#include "guiw16rc.h"
30
31/* Undocumented Windows Message - not even defined in some SDK headers */
32#define WM_EXITSIZEMOVE 0x0232
33
34
35#ifdef FEAT_TOOLBAR
36# define CMD_TB_BASE (99)
37# include <vimtbar.h>
38#endif
39
40#ifdef PROTO
41# define WINAPI
42#endif
43
44#define HANDLE_WM_DROPFILES(hwnd, wParam, lParam, fn) \
45 ((fn)((hwnd), (HDROP)(wParam)), 0L)
46
47
48/* Local variables: */
49
50#ifdef FEAT_MENU
51static UINT s_menu_id = 100;
52#endif
53
54
55#define VIM_NAME "vim"
56#define VIM_CLASS "Vim"
57
58#define DLG_ALLOC_SIZE 16 * 1024
59
60/*
61 * stuff for dialogs, menus, tearoffs etc.
62 */
63#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
64static BOOL CALLBACK dialog_callback(HWND, UINT, WPARAM, LPARAM);
65
66static LPWORD
67add_dialog_element(
68 LPWORD p,
69 DWORD lStyle,
70 WORD x,
71 WORD y,
72 WORD w,
73 WORD h,
74 WORD Id,
75 BYTE clss,
76 const char *caption);
77
78static int dialog_default_button = -1;
79#endif
80
81static void get_dialog_font_metrics(void);
82
83#ifdef FEAT_TOOLBAR
84static void initialise_toolbar(void);
85#endif
86
87
88#ifdef FEAT_MENU
89/*
90 * Figure out how high the menu bar is at the moment.
91 */
92 static int
93gui_mswin_get_menu_height(
94 int fix_window) /* If TRUE, resize window if menu height changed */
95{
96 static int old_menu_height = -1;
97
98 int num;
99 int menu_height;
100
101 if (gui.menu_is_active)
102 num = GetMenuItemCount(s_menuBar);
103 else
104 num = 0;
105
106 if (num == 0)
107 menu_height = 0;
108 else if (gui.starting)
109 menu_height = GetSystemMetrics(SM_CYMENU);
110 else
111 {
112 RECT r1, r2;
113 int frameht = GetSystemMetrics(SM_CYFRAME);
114 int capht = GetSystemMetrics(SM_CYCAPTION);
115
116 /* get window rect of s_hwnd
117 * get client rect of s_hwnd
118 * get cap height
119 * subtract from window rect, the sum of client height,
120 * (if not maximized)frame thickness, and caption height.
121 */
122 GetWindowRect(s_hwnd, &r1);
123 GetClientRect(s_hwnd, &r2);
124 menu_height = r1.bottom - r1.top - (r2.bottom-r2.top +
125 2 * frameht * (!IsZoomed(s_hwnd)) + capht);
126 }
127
128 if (fix_window && menu_height != old_menu_height)
129 {
130 old_menu_height = menu_height;
131 gui_set_shellsize(FALSE, FALSE);
132 }
133
134 return menu_height;
135}
136#endif /*FEAT_MENU*/
137
138
139/*
140 * Even though we have _DuringSizing() which makes the rubber band a valid
141 * size, we need this for when the user maximises the window.
142 * TODO: Doesn't seem to adjust the width though for some reason.
143 */
144 static BOOL
145_OnWindowPosChanging(
146 HWND hwnd,
147 LPWINDOWPOS lpwpos)
148{
149
150 if (!IsIconic(hwnd) && !(lpwpos->flags & SWP_NOSIZE))
151 {
152 gui_mswin_get_valid_dimensions(lpwpos->cx, lpwpos->cy,
153 &lpwpos->cx, &lpwpos->cy);
154 }
155 return 0;
156}
157
158
159
160
161
162 static LRESULT CALLBACK
163_WndProc(
164 HWND hwnd,
165 UINT uMsg,
166 WPARAM wParam,
167 LPARAM lParam)
168{
169 /*
170 TRACE("WndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n",
171 hwnd, uMsg, wParam, lParam);
172 */
173
174 HandleMouseHide(uMsg, lParam);
175
176 s_uMsg = uMsg;
177 s_wParam = wParam;
178 s_lParam = lParam;
179
180 switch (uMsg)
181 {
182 HANDLE_MSG(hwnd, WM_DEADCHAR, _OnDeadChar);
183 HANDLE_MSG(hwnd, WM_SYSDEADCHAR, _OnDeadChar);
184 /* HANDLE_MSG(hwnd, WM_ACTIVATE, _OnActivate); */
185 HANDLE_MSG(hwnd, WM_CHAR, _OnChar);
186 HANDLE_MSG(hwnd, WM_CLOSE, _OnClose);
187 /* HANDLE_MSG(hwnd, WM_COMMAND, _OnCommand); */
188 HANDLE_MSG(hwnd, WM_DESTROY, _OnDestroy);
189 HANDLE_MSG(hwnd, WM_DROPFILES, _OnDropFiles);
190 HANDLE_MSG(hwnd, WM_HSCROLL, _OnScroll);
191 HANDLE_MSG(hwnd, WM_KILLFOCUS, _OnKillFocus);
192#ifdef FEAT_MENU
193 HANDLE_MSG(hwnd, WM_COMMAND, _OnMenu);
194#endif
195 /* HANDLE_MSG(hwnd, WM_MOVE, _OnMove); */
196 /* HANDLE_MSG(hwnd, WM_NCACTIVATE, _OnNCActivate); */
197 HANDLE_MSG(hwnd, WM_SETFOCUS, _OnSetFocus);
198 HANDLE_MSG(hwnd, WM_SIZE, _OnSize);
199 /* HANDLE_MSG(hwnd, WM_SYSCOMMAND, _OnSysCommand); */
200 /* HANDLE_MSG(hwnd, WM_SYSKEYDOWN, _OnAltKey); */
201 HANDLE_MSG(hwnd, WM_VSCROLL, _OnScroll);
202 HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, _OnWindowPosChanging);
203 HANDLE_MSG(hwnd, WM_ACTIVATEAPP, _OnActivateApp);
204
205 case WM_QUERYENDSESSION: /* System wants to go down. */
206 gui_shell_closed(); /* Will exit when no changed buffers. */
207 return FALSE; /* Do NOT allow system to go down. */
208
209 case WM_ENDSESSION:
210 if (wParam) /* system only really goes down when wParam is TRUE */
211 _OnEndSession();
212 break;
213
214 case WM_SYSCHAR:
215 /*
216 * if 'winaltkeys' is "no", or it's "menu" and it's not a menu
217 * shortcut key, handle like a typed ALT key, otherwise call Windows
218 * ALT key handling.
219 */
220#ifdef FEAT_MENU
221 if ( !gui.menu_is_active
222 || p_wak[0] == 'n'
223 || (p_wak[0] == 'm' && !gui_is_menu_shortcut((int)wParam))
224 )
225#endif
226 return HANDLE_WM_SYSCHAR((hwnd), (wParam), (lParam), (_OnSysChar));
227#ifdef FEAT_MENU
228 else
229 return MyWindowProc(hwnd, uMsg, wParam, lParam);
230#endif
231
232 case WM_SYSKEYUP:
233#ifdef FEAT_MENU
234 /* Only when menu is active, ALT key is used for that. */
235 if (gui.menu_is_active)
236 {
237 return MyWindowProc(hwnd, uMsg, wParam, lParam);
238 }
239 else
240#endif
241 return 0;
242
243#if defined(MENUHINTS) && defined(FEAT_MENU)
244 case WM_MENUSELECT:
245 if (((UINT) LOWORD(lParam)
246 & (0xffff ^ (MF_MOUSESELECT + MF_BITMAP + MF_POPUP)))
247 == MF_HILITE
248 && (State & CMDLINE) == 0)
249 {
250 UINT idButton;
251 int idx;
252 vimmenu_T *pMenu;
253
254 idButton = (UINT)LOWORD(wParam);
255 pMenu = gui_mswin_find_menu(root_menu, idButton);
256 if (pMenu)
257 {
258 idx = MENU_INDEX_TIP;
259 msg_clr_cmdline();
260 if (pMenu->strings[idx])
261 msg(pMenu->strings[idx]);
262 else
263 msg("");
264 setcursor();
265 out_flush();
266 }
267 }
268 break;
269#endif
270 case WM_NCHITTEST:
271 {
272 LRESULT result;
273 int x, y;
274 int xPos = GET_X_LPARAM(lParam);
275
276 result = MyWindowProc(hwnd, uMsg, wParam, lParam);
277 if (result == HTCLIENT)
278 {
279 gui_mch_get_winpos(&x, &y);
280 xPos -= x;
281
282 if (xPos < 48) /*<VN> TODO should use system metric?*/
283 return HTBOTTOMLEFT;
284 else
285 return HTBOTTOMRIGHT;
286 }
287 else
288 return result;
289 }
290 /* break; */
291 default:
292#ifdef MSWIN_FIND_REPLACE
293 if (uMsg == s_findrep_msg && s_findrep_msg != 0)
294 {
295 _OnFindRepl();
296 }
297#endif
298 return MyWindowProc(hwnd, uMsg, wParam, lParam);
299 }
300
301 return 1;
302}
303
304
305
306/*
307 * End of call-back routines
308 */
309
310
311/*
312 * Parse the GUI related command-line arguments. Any arguments used are
313 * deleted from argv, and *argc is decremented accordingly. This is called
314 * when vim is started, whether or not the GUI has been started.
315 */
316 void
317gui_mch_prepare(int *argc, char **argv)
318{
319 /* No special args for win16 GUI at the moment. */
320
321}
322
323/*
324 * Initialise the GUI. Create all the windows, set up all the call-backs
325 * etc.
326 */
327 int
328gui_mch_init(void)
329{
330 const char szVimWndClass[] = VIM_CLASS;
331 const char szTextAreaClass[] = "VimTextArea";
332 WNDCLASS wndclass;
333
334#ifdef WIN16_3DLOOK
335 Ctl3dRegister(s_hinst);
336 Ctl3dAutoSubclass(s_hinst);
337#endif
338
339 /* Display any pending error messages */
340 display_errors();
341
342 gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL);
343 gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL);
344#ifdef FEAT_MENU
345 gui.menu_height = 0; /* Windows takes care of this */
346#endif
347 gui.border_width = 0;
348
349 gui.currBgColor = INVALCOLOR;
350
351 s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
352
353 if (GetClassInfo(s_hinst, szVimWndClass, &wndclass) == 0) {
354 wndclass.style = 0;
355 wndclass.lpfnWndProc = _WndProc;
356 wndclass.cbClsExtra = 0;
357 wndclass.cbWndExtra = 0;
358 wndclass.hInstance = s_hinst;
359 wndclass.hIcon = LoadIcon(wndclass.hInstance, MAKEINTRESOURCE(IDR_VIM));
360 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
361 wndclass.hbrBackground = s_brush;
362 wndclass.lpszMenuName = NULL;
363 wndclass.lpszClassName = szVimWndClass;
364
365 if ((
366#ifdef GLOBAL_IME
367 atom =
368#endif
369 RegisterClass(&wndclass)) == 0)
370 return FAIL;
371 }
372
373 s_hwnd = CreateWindow(
374 szVimWndClass, "Vim MSWindows GUI",
375 WS_OVERLAPPEDWINDOW,
376 gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x,
377 gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y,
378 100, /* Any value will do */
379 100, /* Any value will do */
380 NULL, NULL,
381 s_hinst, NULL);
382
383 if (s_hwnd == NULL)
384 return FAIL;
385
386#ifdef GLOBAL_IME
387 global_ime_init(atom, s_hwnd);
388#endif
389
390 /* Create the text area window */
391 if (GetClassInfo(s_hinst, szTextAreaClass, &wndclass) == 0) {
392 wndclass.style = CS_OWNDC;
393 wndclass.lpfnWndProc = _TextAreaWndProc;
394 wndclass.cbClsExtra = 0;
395 wndclass.cbWndExtra = 0;
396 wndclass.hInstance = s_hinst;
397 wndclass.hIcon = NULL;
398 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
399 wndclass.hbrBackground = NULL;
400 wndclass.lpszMenuName = NULL;
401 wndclass.lpszClassName = szTextAreaClass;
402
403 if (RegisterClass(&wndclass) == 0)
404 return FAIL;
405 }
406 s_textArea = CreateWindow(
407 szTextAreaClass, "Vim text area",
408 WS_CHILD | WS_VISIBLE, 0, 0,
409 100, /* Any value will do for now */
410 100, /* Any value will do for now */
411 s_hwnd, NULL,
412 s_hinst, NULL);
413
414 if (s_textArea == NULL)
415 return FAIL;
416
417#ifdef FEAT_MENU
418 s_menuBar = CreateMenu();
419#endif
420 s_hdc = GetDC(s_textArea);
421
422#ifdef MSWIN16_FASTTEXT
423 SetBkMode(s_hdc, OPAQUE);
424#endif
425
426 DragAcceptFiles(s_hwnd, TRUE);
427
428 /* Do we need to bother with this? */
429 /* m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); */
430
431 /* Get background/foreground colors from the system */
432 gui_mch_def_colors();
433
434 /* Get the colors from the "Normal" group (set in syntax.c or in a vimrc
435 * file) */
436 set_normal_colors();
437
438 /*
439 * Check that none of the colors are the same as the background color.
440 * Then store the current values as the defaults.
441 */
442 gui_check_colors();
443 gui.def_norm_pixel = gui.norm_pixel;
444 gui.def_back_pixel = gui.back_pixel;
445
446 /* Get the colors for the highlight groups (gui_check_colors() might have
447 * changed them) */
448 highlight_gui_started();
449
450 /*
451 * Start out by adding the configured border width into the border offset
452 */
453 gui.border_offset = gui.border_width;
454
455
456 /*
457 * compute a couple of metrics used for the dialogs
458 */
459 get_dialog_font_metrics();
460#ifdef FEAT_TOOLBAR
461 /*
462 * Create the toolbar
463 */
464 initialise_toolbar();
465#endif
466#ifdef MSWIN_FIND_REPLACE
467 /*
468 * Initialise the dialog box stuff
469 */
470 s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING);
471
472 /* Initialise the struct */
473 s_findrep_struct.lStructSize = sizeof(s_findrep_struct);
474 s_findrep_struct.lpstrFindWhat = alloc(MSWIN_FR_BUFSIZE);
475 s_findrep_struct.lpstrFindWhat[0] = NUL;
476 s_findrep_struct.lpstrReplaceWith = alloc(MSWIN_FR_BUFSIZE);
477 s_findrep_struct.lpstrReplaceWith[0] = NUL;
478 s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE;
479 s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE;
480#endif
481
482 return OK;
483}
484
485
486/*
487 * Set the size of the window to the given width and height in pixels.
488 */
489 void
490gui_mch_set_shellsize(int width, int height,
491 int min_width, int min_height, int base_width, int base_height)
492{
493 RECT workarea_rect;
494 int win_width, win_height;
495 int win_xpos, win_ypos;
496 WINDOWPLACEMENT wndpl;
497
498 /* try to keep window completely on screen */
499 /* get size of the screen work area - use SM_CYFULLSCREEN
500 * instead of SM_CYSCREEN so that we don't overlap the
501 * taskbar if someone fires us up on Win95/NT */
502 workarea_rect.left = 0;
503 workarea_rect.top = 0;
504 workarea_rect.right = GetSystemMetrics(SM_CXSCREEN);
505 workarea_rect.bottom = GetSystemMetrics(SM_CYFULLSCREEN);
506
507 /* get current posision of our window */
508 wndpl.length = sizeof(WINDOWPLACEMENT);
509 GetWindowPlacement(s_hwnd, &wndpl);
510 if (wndpl.showCmd == SW_SHOWNORMAL)
511 {
512 win_xpos = wndpl.rcNormalPosition.left;
513 win_ypos = wndpl.rcNormalPosition.top;
514 }
515 else
516 {
517 win_xpos = workarea_rect.left;
518 win_ypos = workarea_rect.top;
519 }
520
521 /* compute the size of the outside of the window */
522 win_width = width + GetSystemMetrics(SM_CXFRAME) * 2;
523 win_height = height + GetSystemMetrics(SM_CYFRAME) * 2
524 + GetSystemMetrics(SM_CYCAPTION)
525#ifdef FEAT_MENU
526 + gui_mswin_get_menu_height(FALSE)
527#endif
528 ;
529
530 /* if the window is going off the screen, move it on to the screen */
531 if (win_xpos + win_width > workarea_rect.right)
532 win_xpos = workarea_rect.right - win_width;
533
534 if (win_xpos < workarea_rect.left)
535 win_xpos = workarea_rect.left;
536
537 if (win_ypos + win_height > workarea_rect.bottom)
538 win_ypos = workarea_rect.bottom - win_height;
539
540 if (win_ypos < workarea_rect.top)
541 win_ypos = workarea_rect.top;
542
543 /* set window position */
544 SetWindowPos(s_hwnd, NULL, win_xpos, win_ypos, win_width, win_height,
545 SWP_NOZORDER | SWP_NOACTIVATE);
546
547#ifdef FEAT_MENU
548 /* Menu may wrap differently now */
549 gui_mswin_get_menu_height(!gui.starting);
550#endif
551}
552
553 void
554gui_mch_set_scrollbar_thumb(
555 scrollbar_T *sb,
556 long val,
557 long size,
558 long max)
559{
560 sb->scroll_shift = 0;
561 while (max > 32767)
562 {
563 max = (max + 1) >> 1;
564 val >>= 1;
565 size >>= 1;
566 ++sb->scroll_shift;
567 }
568
569 if (sb->scroll_shift > 0)
570 ++size;
571
572 SetScrollRange(sb->id, SB_CTL, 0, (int) max, FALSE);
573 SetScrollPos(sb->id, SB_CTL, (int) val, TRUE);
574}
575
576
577/*
578 * Set the current text font.
579 */
580 void
581gui_mch_set_font(GuiFont font)
582{
583 gui.currFont = font;
584 SelectFont(s_hdc, gui.currFont);
585}
586
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587/*
588 * Set the current text foreground color.
589 */
590 void
591gui_mch_set_fg_color(guicolor_T color)
592{
593 gui.currFgColor = color;
594 SetTextColor(s_hdc, gui.currFgColor);
595}
596
597/*
598 * Set the current text background color.
599 */
600 void
601gui_mch_set_bg_color(guicolor_T color)
602{
603 if (gui.currBgColor == color)
604 return;
605
606 gui.currBgColor = color;
607 SetBkColor(s_hdc, gui.currBgColor);
608}
609
Bram Moolenaar3918c952005-03-15 22:34:55 +0000610/*
611 * Set the current text special color.
612 */
613 void
614gui_mch_set_sp_color(guicolor_T color)
615{
616 /* TODO */
617}
618
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619
620
621 void
622gui_mch_draw_string(
623 int row,
624 int col,
625 char_u *text,
626 int len,
627 int flags)
628{
629#ifndef MSWIN16_FASTTEXT
630 static int *padding = NULL;
631 static int pad_size = 0;
632 int i;
633#endif
634 HPEN hpen, old_pen;
635 int y;
636
637#ifndef MSWIN16_FASTTEXT
638 /*
639 * Italic and bold text seems to have an extra row of pixels at the bottom
640 * (below where the bottom of the character should be). If we draw the
641 * characters with a solid background, the top row of pixels in the
642 * character below will be overwritten. We can fix this by filling in the
643 * background ourselves, to the correct character proportions, and then
644 * writing the character in transparent mode. Still have a problem when
645 * the character is "_", which gets written on to the character below.
646 * New fix: set gui.char_ascent to -1. This shifts all characters up one
647 * pixel in their slots, which fixes the problem with the bottom row of
648 * pixels. We still need this code because otherwise the top row of pixels
649 * becomes a problem. - webb.
650 */
651 HBRUSH hbr;
652 RECT rc;
653
654 if (!(flags & DRAW_TRANSP))
655 {
656 /*
657 * Clear background first.
658 * Note: FillRect() excludes right and bottom of rectangle.
659 */
660 rc.left = FILL_X(col);
661 rc.top = FILL_Y(row);
662#ifdef FEAT_MBYTE
663 if (has_mbyte)
664 {
665 int cell_len = 0;
666
667 /* Compute the length in display cells. */
668 for (n = 0; n < len; n += MB_BYTE2LEN(text[n]))
669 cell_len += (*mb_ptr2cells)(text + n);
670 rc.right = FILL_X(col + cell_len);
671 }
672 else
673#endif
674 rc.right = FILL_X(col + len);
675 rc.bottom = FILL_Y(row + 1);
676 hbr = CreateSolidBrush(gui.currBgColor);
677 FillRect(s_hdc, &rc, hbr);
678 DeleteBrush(hbr);
679
680 SetBkMode(s_hdc, TRANSPARENT);
681
682 /*
683 * When drawing block cursor, prevent inverted character spilling
684 * over character cell (can happen with bold/italic)
685 */
686 if (flags & DRAW_CURSOR)
687 {
688 pcliprect = &rc;
689 foptions = ETO_CLIPPED;
690 }
691 }
692#else
693 /*
694 * Alternative: write the characters in opaque mode, since we have blocked
695 * bold or italic fonts.
696 */
697 /* The OPAQUE mode and backcolour have already been set */
698#endif
699 /* The forecolor and font have already been set */
700
701#ifndef MSWIN16_FASTTEXT
702
703 if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width)
704 {
705 vim_free(padding);
706 pad_size = Columns;
707
708 padding = (int *)alloc(pad_size * sizeof(int));
709 if (padding != NULL)
710 for (i = 0; i < pad_size; i++)
711 padding[i] = gui.char_width;
712 }
713#endif
714
715 /*
716 * We have to provide the padding argument because italic and bold versions
717 * of fixed-width fonts are often one pixel or so wider than their normal
718 * versions.
719 * No check for DRAW_BOLD, Windows will have done it already.
720 */
721#ifndef MSWIN16_FASTTEXT
722 ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), 0, NULL,
723 (char *)text, len, padding);
724#else
725 TextOut(s_hdc, TEXT_X(col), TEXT_Y(row), (char *)text, len);
726#endif
727
728 if (flags & DRAW_UNDERL)
729 {
730 hpen = CreatePen(PS_SOLID, 1, gui.currFgColor);
731 old_pen = SelectObject(s_hdc, hpen);
732 /* When p_linespace is 0, overwrite the bottom row of pixels.
733 * Otherwise put the line just below the character. */
734 y = FILL_Y(row + 1) - 1;
735#ifndef MSWIN16_FASTTEXT
736 if (p_linespace > 1)
737 y -= p_linespace - 1;
738#endif
739 MoveToEx(s_hdc, FILL_X(col), y, NULL);
740 /* Note: LineTo() excludes the last pixel in the line. */
741 LineTo(s_hdc, FILL_X(col + len), y);
742 DeleteObject(SelectObject(s_hdc, old_pen));
743 }
744}
745
746
747/*
748 * Output routines.
749 */
750
751/* Flush any output to the screen */
752 void
753gui_mch_flush(void)
754{
755 /* Is anything needed here? */
756}
757
758 static void
759clear_rect(RECT *rcp)
760{
761 /* Use trick for fast rect clear */
762 gui_mch_set_bg_color(gui.back_pixel);
763 ExtTextOut(s_hdc, 0, 0, ETO_CLIPPED | ETO_OPAQUE, rcp, NULL, 0, NULL);
764}
765
766
Bram Moolenaarb1b715d2006-01-21 22:09:43 +0000767 void
768gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
769{
770
771 *screen_w = GetSystemMetrics(SM_CXFULLSCREEN)
772 - GetSystemMetrics(SM_CXFRAME) * 2;
773 /* FIXME: dirty trick: Because the gui_get_base_height() doesn't include
774 * the menubar for MSwin, we subtract it from the screen height, so that
775 * the window size can be made to fit on the screen. */
776 *screen_h = GetSystemMetrics(SM_CYFULLSCREEN)
777 - GetSystemMetrics(SM_CYFRAME) * 2
778#ifdef FEAT_MENU
779 - gui_mswin_get_menu_height(FALSE)
780#endif
781 ;
782}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783
784
785#if defined(FEAT_MENU) || defined(PROTO)
786/*
787 * Add a sub menu to the menu bar.
788 */
789 void
790gui_mch_add_menu(
791 vimmenu_T *menu,
792 int pos)
793{
794 vimmenu_T *parent = menu->parent;
795
796 menu->submenu_id = CreatePopupMenu();
797 menu->id = s_menu_id++;
798
799 if (menu_is_menubar(menu->name))
800 {
801 InsertMenu((parent == NULL) ? s_menuBar : parent->submenu_id,
802 (UINT)pos, MF_POPUP | MF_STRING | MF_BYPOSITION,
803 (UINT)menu->submenu_id, menu->name);
804 }
805
806 /* Fix window size if menu may have wrapped */
807 if (parent == NULL)
808 gui_mswin_get_menu_height(!gui.starting);
809}
810
811 void
812gui_mch_show_popupmenu(vimmenu_T *menu)
813{
814 POINT mp;
815
816 (void)GetCursorPos((LPPOINT)&mp);
817 gui_mch_show_popupmenu_at(menu, (int)mp.x, (int)mp.y);
818}
819
820 void
Bram Moolenaarec8a10a2005-07-08 22:19:11 +0000821gui_make_popup(char_u *path_name, int mouse_pos)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822{
823 vimmenu_T *menu = gui_find_menu(path_name);
824
825 if (menu != NULL)
826 {
827 /* Find the position of the current cursor */
828 DWORD temp_p;
829 POINT p;
830 temp_p = GetDCOrg(s_hdc);
831 p.x = LOWORD(temp_p);
832 p.y = HIWORD(temp_p);
Bram Moolenaarec8a10a2005-07-08 22:19:11 +0000833 if (mouse_pos)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000834 {
Bram Moolenaarec8a10a2005-07-08 22:19:11 +0000835 int mx, my;
836
837 gui_mch_getmouse(&mx, &my);
838 p.x += mx;
839 p.y += my;
840 }
841 else if (curwin != NULL)
842 {
843 p.x += TEXT_X(W_WINCOL(curwin) + curwin->w_wcol + 1);
844 p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845 }
846 msg_scroll = FALSE;
847 gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y);
848 }
849}
850
851/*
852 * Add a menu item to a menu
853 */
854 void
855gui_mch_add_menu_item(
856 vimmenu_T *menu,
857 int idx)
858{
859 vimmenu_T *parent = menu->parent;
860
861 menu->id = s_menu_id++;
862 menu->submenu_id = NULL;
863
864#ifdef FEAT_TOOLBAR
865 if (menu_is_toolbar(parent->name))
866 {
867 TBBUTTON newtb;
868
869 vim_memset(&newtb, 0, sizeof(newtb));
870 if (menu_is_separator(menu->name))
871 {
872 newtb.iBitmap = 0;
873 newtb.fsStyle = TBSTYLE_SEP;
874 }
875 else
876 {
877 if (menu->iconidx >= TOOLBAR_BITMAP_COUNT)
878 newtb.iBitmap = -1;
879 else
880 newtb.iBitmap = menu->iconidx;
881 newtb.fsStyle = TBSTYLE_BUTTON;
882 }
883 newtb.idCommand = menu->id;
884 newtb.fsState = TBSTATE_ENABLED;
885 SendMessage(s_toolbarhwnd, TB_INSERTBUTTON, (WPARAM)idx,
886 (LPARAM)&newtb);
887 menu->submenu_id = (HMENU)-1;
888 }
889 else
890#endif
891 {
892 InsertMenu(parent->submenu_id, (UINT)idx,
893 (menu_is_separator(menu->name) ? MF_SEPARATOR : MF_STRING)
894 | MF_BYPOSITION,
895 (UINT)menu->id, menu->name);
896 }
897}
898
899/*
900 * Destroy the machine specific menu widget.
901 */
902 void
903gui_mch_destroy_menu(vimmenu_T *menu)
904{
905 UINT i, j;
906 char pants[80]; /*<VN> hack*/
907#ifdef FEAT_TOOLBAR
908 /*
909 * is this a toolbar button?
910 */
911 if (menu->submenu_id == (HMENU)-1)
912 {
913 int iButton;
914
915 iButton = SendMessage(s_toolbarhwnd, TB_COMMANDTOINDEX, (WPARAM)menu->id, 0);
916 SendMessage(s_toolbarhwnd, TB_DELETEBUTTON, (WPARAM)iButton, 0);
917 }
918 else
919#endif
920 {
921 /*
922 * negri: horrible API bug when running 16-bit programs under Win9x or
923 * NT means that we can't use MF_BYCOMMAND for menu items which have
924 * submenus, including the top-level headings. We have to find the menu
925 * item and use MF_BYPOSITION instead. :-p
926 */
927 if (menu->parent != NULL
928 && menu_is_popup(menu->parent->dname)
929 && menu->parent->submenu_id != NULL)
930 RemoveMenu(menu->parent->submenu_id, menu->id, MF_BYCOMMAND);
931 else if (menu->submenu_id == NULL)
932 RemoveMenu(s_menuBar, menu->id, MF_BYCOMMAND);
933 else if (menu->parent != NULL)
934 {
935 i = GetMenuItemCount(menu->parent->submenu_id);
936 for (j = 0; j < i; ++j)
937 {
938 GetMenuString(menu->parent->submenu_id, j,
939 pants, 80, MF_BYPOSITION);
940 if (strcmp(pants, menu->name) == 0)
941 {
942 RemoveMenu(menu->parent->submenu_id, j, MF_BYPOSITION);
943 break;
944 }
945 }
946 }
947 else
948 {
949 i = GetMenuItemCount(s_menuBar);
950 for (j = 0; j < i; ++j)
951 {
952 GetMenuString(s_menuBar, j, pants, 80, MF_BYPOSITION);
953 if (strcmp(pants, menu->name) == 0)
954 {
955 RemoveMenu(s_menuBar, j, MF_BYPOSITION);
956 break;
957 }
958 }
959 }
960
961 if (menu->submenu_id != NULL)
962 DestroyMenu(menu->submenu_id);
963 }
964 DrawMenuBar(s_hwnd);
965}
966
967
968/*
969 * Make a menu either grey or not grey.
970 */
971 void
972gui_mch_menu_grey(
973 vimmenu_T *menu,
974 int grey)
975{
976#ifdef FEAT_TOOLBAR
977 /*
978 * is this a toolbar button?
979 */
980 if (menu->submenu_id == (HMENU)-1)
981 {
982 SendMessage(s_toolbarhwnd, TB_ENABLEBUTTON,
983 (WPARAM)menu->id, (LPARAM) MAKELONG((grey ? FALSE : TRUE), 0) );
984 }
985 else
986#endif
987 if (grey)
988 EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_GRAYED);
989 else
990 EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_ENABLED);
991
992}
993
994
995#endif /*FEAT_MENU*/
996
997
998/* define some macros used to make the dialogue creation more readable */
999
1000#define add_string(s) strcpy((LPSTR)p, s); (LPSTR)p += (strlen((LPSTR)p) + 1)
1001#define add_word(x) *p++ = (x)
1002#define add_byte(x) *((LPSTR)p)++ = (x)
1003#define add_long(x) *((LPDWORD)p)++ = (x)
1004
1005#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
1006/*
1007 * stuff for dialogs
1008 */
1009
1010/*
1011 * The callback routine used by all the dialogs. Very simple. First,
1012 * acknowledges the INITDIALOG message so that Windows knows to do standard
1013 * dialog stuff (Return = default, Esc = cancel....) Second, if a button is
1014 * pressed, return that button's ID - IDCANCEL (2), which is the button's
1015 * number.
1016 */
1017 static BOOL CALLBACK
1018dialog_callback(
1019 HWND hwnd,
1020 UINT message,
1021 WPARAM wParam,
1022 LPARAM lParam)
1023{
1024 if (message == WM_INITDIALOG)
1025 {
1026 CenterWindow(hwnd, GetWindow(hwnd, GW_OWNER));
1027 /* Set focus to the dialog. Set the default button, if specified. */
1028 (void)SetFocus(hwnd);
1029 if (dialog_default_button > IDCANCEL)
1030 (void)SetFocus(GetDlgItem(hwnd, dialog_default_button));
1031// if (dialog_default_button > 0)
1032// (void)SetFocus(GetDlgItem(hwnd, dialog_default_button + IDCANCEL));
1033 return FALSE;
1034 }
1035
1036 if (message == WM_COMMAND)
1037 {
1038 int button = LOWORD(wParam);
1039
1040 /* Don't end the dialog if something was selected that was
1041 * not a button.
1042 */
1043 if (button >= DLG_NONBUTTON_CONTROL)
1044 return TRUE;
1045
1046 /* If the edit box exists, copy the string. */
1047 if (s_textfield != NULL)
1048 GetDlgItemText(hwnd, DLG_NONBUTTON_CONTROL + 2,
1049 s_textfield, IOSIZE);
1050
1051 /*
1052 * Need to check for IDOK because if the user just hits Return to
1053 * accept the default value, some reason this is what we get.
1054 */
1055 if (button == IDOK)
1056 EndDialog(hwnd, dialog_default_button);
1057 else
1058 EndDialog(hwnd, button - IDCANCEL);
1059 return TRUE;
1060 }
1061
1062 if ((message == WM_SYSCOMMAND) && (wParam == SC_CLOSE))
1063 {
1064 EndDialog(hwnd, 0);
1065 return TRUE;
1066 }
1067 return FALSE;
1068}
1069
1070/*
1071 * Create a dialog dynamically from the parameter strings.
1072 * type = type of dialog (question, alert, etc.)
1073 * title = dialog title. may be NULL for default title.
1074 * message = text to display. Dialog sizes to accommodate it.
1075 * buttons = '\n' separated list of button captions, default first.
1076 * dfltbutton = number of default button.
1077 *
1078 * This routine returns 1 if the first button is pressed,
1079 * 2 for the second, etc.
1080 *
1081 * 0 indicates Esc was pressed.
1082 * -1 for unexpected error
1083 *
1084 * If stubbing out this fn, return 1.
1085 */
1086
1087static const char_u dlg_icons[] = /* must match names in resource file */
1088{
1089 IDR_VIM,
1090 IDR_VIM_ERROR,
1091 IDR_VIM_ALERT,
1092 IDR_VIM_INFO,
1093 IDR_VIM_QUESTION
1094};
1095
1096 int
1097gui_mch_dialog(
1098 int type,
1099 char_u *title,
1100 char_u *message,
1101 char_u *buttons,
1102 int dfltbutton,
1103 char_u *textfield)
1104{
1105 FARPROC dp;
1106 LPWORD p, pnumitems;
1107 int numButtons;
1108 int *buttonWidths, *buttonPositions;
1109 int buttonYpos;
1110 int nchar, i;
1111 DWORD lStyle;
1112 int dlgwidth = 0;
1113 int dlgheight;
1114 int editboxheight;
1115 int horizWidth;
1116 int msgheight;
1117 char_u *pstart;
1118 char_u *pend;
1119 char_u *tbuffer;
1120 RECT rect;
1121 HWND hwnd;
1122 HDC hdc;
1123 HFONT oldFont;
1124 TEXTMETRIC fontInfo;
1125 int fontHeight;
1126 int textWidth, minButtonWidth, messageWidth;
1127 int maxDialogWidth;
1128 int vertical;
1129 int dlgPaddingX;
1130 int dlgPaddingY;
1131 HGLOBAL hglbDlgTemp;
1132
1133#ifndef NO_CONSOLE
1134 /* Don't output anything in silent mode ("ex -s") */
1135 if (silent_mode)
1136 return dfltbutton; /* return default option */
1137#endif
1138
1139 /* If there is no window yet, open it. */
1140 if (s_hwnd == NULL && gui_mch_init() == FAIL)
1141 return dfltbutton;
1142
1143 if ((type < 0) || (type > VIM_LAST_TYPE))
1144 type = 0;
1145
1146 /* allocate some memory for dialog template */
1147 /* TODO should compute this really*/
1148
1149 hglbDlgTemp = GlobalAlloc(GHND, DLG_ALLOC_SIZE);
1150 if (hglbDlgTemp == NULL)
1151 return -1;
1152
1153 p = (LPWORD) GlobalLock(hglbDlgTemp);
1154
1155 if (p == NULL)
1156 return -1;
1157
1158 /*
1159 * make a copy of 'buttons' to fiddle with it. complier grizzles because
1160 * vim_strsave() doesn't take a const arg (why not?), so cast away the
1161 * const.
1162 */
1163 tbuffer = vim_strsave(buttons);
1164 if (tbuffer == NULL)
1165 return -1;
1166
1167 --dfltbutton; /* Change from one-based to zero-based */
1168
1169 /* Count buttons */
1170 numButtons = 1;
1171 for (i = 0; tbuffer[i] != '\0'; i++)
1172 {
1173 if (tbuffer[i] == DLG_BUTTON_SEP)
1174 numButtons++;
1175 }
1176 if (dfltbutton >= numButtons)
1177 dfltbutton = 0;
1178
1179 /* Allocate array to hold the width of each button */
1180 buttonWidths = (int *) lalloc(numButtons * sizeof(int), TRUE);
1181 if (buttonWidths == NULL)
1182 return -1;
1183
1184 /* Allocate array to hold the X position of each button */
1185 buttonPositions = (int *) lalloc(numButtons * sizeof(int), TRUE);
1186 if (buttonPositions == NULL)
1187 return -1;
1188
1189 /*
1190 * Calculate how big the dialog must be.
1191 */
1192 hwnd = GetDesktopWindow();
1193 hdc = GetWindowDC(hwnd);
1194 oldFont = SelectFont(hdc, GetStockObject(SYSTEM_FONT));
1195 dlgPaddingX = DLG_OLD_STYLE_PADDING_X;
1196 dlgPaddingY = DLG_OLD_STYLE_PADDING_Y;
1197
1198 GetTextMetrics(hdc, &fontInfo);
1199 fontHeight = fontInfo.tmHeight;
1200
1201 /* Minimum width for horizontal button */
1202 minButtonWidth = GetTextWidth(hdc, "Cancel", 6);
1203
1204 /* Maximum width of a dialog, if possible */
1205 GetWindowRect(s_hwnd, &rect);
1206 maxDialogWidth = rect.right - rect.left
1207 - GetSystemMetrics(SM_CXFRAME) * 2;
1208 if (maxDialogWidth < DLG_MIN_MAX_WIDTH)
1209 maxDialogWidth = DLG_MIN_MAX_WIDTH;
1210
1211 /* Set dlgwidth to width of message */
1212 pstart = message;
1213 messageWidth = 0;
1214 msgheight = 0;
1215 do
1216 {
1217 pend = vim_strchr(pstart, DLG_BUTTON_SEP);
1218 if (pend == NULL)
1219 pend = pstart + STRLEN(pstart); /* Last line of message. */
1220 msgheight += fontHeight;
1221 textWidth = GetTextWidth(hdc, pstart, pend - pstart);
1222 if (textWidth > messageWidth)
1223 messageWidth = textWidth;
1224 pstart = pend + 1;
1225 } while (*pend != NUL);
1226 dlgwidth = messageWidth;
1227
1228 /* Add width of icon to dlgwidth, and some space */
1229 dlgwidth += DLG_ICON_WIDTH + 3 * dlgPaddingX;
1230
1231 if (msgheight < DLG_ICON_HEIGHT)
1232 msgheight = DLG_ICON_HEIGHT;
1233
1234 /*
1235 * Check button names. A long one will make the dialog wider.
1236 */
1237 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
1238 if (!vertical)
1239 {
1240 // Place buttons horizontally if they fit.
1241 horizWidth = dlgPaddingX;
1242 pstart = tbuffer;
1243 i = 0;
1244 do
1245 {
1246 pend = vim_strchr(pstart, DLG_BUTTON_SEP);
1247 if (pend == NULL)
1248 pend = pstart + STRLEN(pstart); // Last button name.
1249 textWidth = GetTextWidth(hdc, pstart, pend - pstart);
1250 if (textWidth < minButtonWidth)
1251 textWidth = minButtonWidth;
1252 textWidth += dlgPaddingX; /* Padding within button */
1253 buttonWidths[i] = textWidth;
1254 buttonPositions[i++] = horizWidth;
1255 horizWidth += textWidth + dlgPaddingX; /* Pad between buttons */
1256 pstart = pend + 1;
1257 } while (*pend != NUL);
1258
1259 if (horizWidth > maxDialogWidth)
1260 vertical = TRUE; // Too wide to fit on the screen.
1261 else if (horizWidth > dlgwidth)
1262 dlgwidth = horizWidth;
1263 }
1264
1265 if (vertical)
1266 {
1267 // Stack buttons vertically.
1268 pstart = tbuffer;
1269 do
1270 {
1271 pend = vim_strchr(pstart, DLG_BUTTON_SEP);
1272 if (pend == NULL)
1273 pend = pstart + STRLEN(pstart); // Last button name.
1274 textWidth = GetTextWidth(hdc, pstart, pend - pstart);
1275 textWidth += dlgPaddingX; /* Padding within button */
1276 textWidth += DLG_VERT_PADDING_X * 2; /* Padding around button */
1277 if (textWidth > dlgwidth)
1278 dlgwidth = textWidth;
1279 pstart = pend + 1;
1280 } while (*pend != NUL);
1281 }
1282
1283 if (dlgwidth < DLG_MIN_WIDTH)
1284 dlgwidth = DLG_MIN_WIDTH; /* Don't allow a really thin dialog!*/
1285
1286 /* start to fill in the dlgtemplate information. addressing by WORDs */
1287 lStyle = DS_MODALFRAME | WS_CAPTION | WS_VISIBLE ;
1288
1289 add_long(lStyle);
1290 pnumitems = p; /*save where the number of items must be stored*/
1291 add_byte(0); // NumberOfItems(will change later)
1292 add_word(10); // x
1293 add_word(10); // y
1294 add_word(PixelToDialogX(dlgwidth));
1295
1296 // Dialog height.
1297 if (vertical)
1298 dlgheight = msgheight + 2 * dlgPaddingY +
1299 DLG_VERT_PADDING_Y + 2 * fontHeight * numButtons;
1300 else
1301 dlgheight = msgheight + 3 * dlgPaddingY + 2 * fontHeight;
1302
1303 // Dialog needs to be taller if contains an edit box.
1304 editboxheight = fontHeight + dlgPaddingY + 4 * DLG_VERT_PADDING_Y;
1305 if (textfield != NULL)
1306 dlgheight += editboxheight;
1307
1308 add_word(PixelToDialogY(dlgheight));
1309
1310 add_byte(0); //menu
1311 add_byte(0); //class
1312
1313 /* copy the title of the dialog */
1314 add_string(title ? title : ("Vim"VIM_VERSION_MEDIUM));
1315
1316 buttonYpos = msgheight + 2 * dlgPaddingY;
1317
1318 if (textfield != NULL)
1319 buttonYpos += editboxheight;
1320
1321 pstart = tbuffer; //dflt_text
1322 horizWidth = (dlgwidth - horizWidth) / 2; /* Now it's X offset */
1323 for (i = 0; i < numButtons; i++)
1324 {
1325 /* get end of this button. */
1326 for ( pend = pstart;
1327 *pend && (*pend != DLG_BUTTON_SEP);
1328 pend++)
1329 ;
1330
1331 if (*pend)
1332 *pend = '\0';
1333
1334 /*
1335 * NOTE:
1336 * setting the BS_DEFPUSHBUTTON style doesn't work because Windows sets
1337 * the focus to the first tab-able button and in so doing makes that
1338 * the default!! Grrr. Workaround: Make the default button the only
1339 * one with WS_TABSTOP style. Means user can't tab between buttons, but
1340 * he/she can use arrow keys.
1341 *
1342 * NOTE (Thore): Setting BS_DEFPUSHBUTTON works fine when it's the
1343 * first one, so I changed the correct button to be this style. This
1344 * is necessary because when an edit box is added, we need a button to
1345 * be default. The edit box will be the default control, and when the
1346 * user presses enter from the edit box we want the default button to
1347 * be pressed.
1348 */
1349 if (vertical)
1350 {
1351 p = add_dialog_element(p,
1352 ((i == dfltbutton || dfltbutton < 0) && textfield != NULL
1353 ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP,
1354 PixelToDialogX(DLG_VERT_PADDING_X),
1355 PixelToDialogY(buttonYpos /* TBK */
1356 + 2 * fontHeight * i),
1357 PixelToDialogX(dlgwidth - 2 * DLG_VERT_PADDING_X),
1358 (WORD)(PixelToDialogY(2 * fontHeight) - 1),
1359 (WORD)(IDCANCEL + 1 + i), (BYTE)0x80, pstart);
1360 }
1361 else
1362 {
1363 p = add_dialog_element(p,
1364 ((i == dfltbutton || dfltbutton < 0) && textfield != NULL
1365 ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON) | WS_TABSTOP,
1366 PixelToDialogX(horizWidth + buttonPositions[i]),
1367 PixelToDialogY(buttonYpos), /* TBK */
1368 PixelToDialogX(buttonWidths[i]),
1369 (WORD)(PixelToDialogY(2 * fontHeight) - 1),
1370 (WORD)(IDCANCEL + 1 + i), (BYTE)0x80, pstart);
1371 }
1372
1373 pstart = pend + 1; /*next button*/
1374
1375 }
1376 *pnumitems += numButtons;
1377
1378 /* Vim icon */
1379 p = add_dialog_element(p, SS_ICON,
1380 PixelToDialogX(dlgPaddingX),
1381 PixelToDialogY(dlgPaddingY),
1382 PixelToDialogX(DLG_ICON_WIDTH),
1383 PixelToDialogY(DLG_ICON_HEIGHT),
1384 DLG_NONBUTTON_CONTROL + 0, (BYTE)0x82,
1385 &dlg_icons[type]);
1386
1387
1388 /* Dialog message */
1389 p = add_dialog_element(p, SS_LEFT,
1390 PixelToDialogX(2 * dlgPaddingX + DLG_ICON_WIDTH),
1391 PixelToDialogY(dlgPaddingY),
1392 (WORD)(PixelToDialogX(messageWidth) + 1),
1393 PixelToDialogY(msgheight),
1394 DLG_NONBUTTON_CONTROL + 1, (BYTE)0x82, message);
1395
1396 /* Edit box */
1397 if (textfield != NULL)
1398 {
1399 p = add_dialog_element(p, ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_BORDER,
1400 PixelToDialogX(2 * dlgPaddingX),
1401 PixelToDialogY(2 * dlgPaddingY + msgheight),
1402 PixelToDialogX(dlgwidth - 4 * dlgPaddingX),
1403 PixelToDialogY(fontHeight + dlgPaddingY),
1404 DLG_NONBUTTON_CONTROL + 2, (BYTE)0x81, textfield);
1405 *pnumitems += 1;
1406 }
1407
1408 *pnumitems += 2;
1409
1410 SelectFont(hdc, oldFont);
1411 ReleaseDC(hwnd, hdc);
1412 dp = MakeProcInstance((FARPROC)dialog_callback, s_hinst);
1413
1414
1415 /* Let the dialog_callback() function know which button to make default
1416 * If we have an edit box, make that the default. We also need to tell
1417 * dialog_callback() if this dialog contains an edit box or not. We do
1418 * this by setting s_textfield if it does.
1419 */
1420 if (textfield != NULL)
1421 {
1422 dialog_default_button = DLG_NONBUTTON_CONTROL + 2;
1423 s_textfield = textfield;
1424 }
1425 else
1426 {
1427 dialog_default_button = IDCANCEL + 1 + dfltbutton;
1428 s_textfield = NULL;
1429 }
1430
1431 /*show the dialog box modally and get a return value*/
1432 nchar = DialogBoxIndirect(
1433 s_hinst,
1434 (HGLOBAL) hglbDlgTemp,
1435 s_hwnd,
1436 (DLGPROC)dp);
1437
1438 FreeProcInstance( dp );
1439 GlobalUnlock(hglbDlgTemp);
1440 GlobalFree(hglbDlgTemp);
1441 vim_free(tbuffer);
1442 vim_free(buttonWidths);
1443 vim_free(buttonPositions);
1444
1445
1446 return nchar;
1447}
1448
1449/*
1450 * Put a simple element (basic class) onto a dialog template in memory.
1451 * return a pointer to where the next item should be added.
1452 *
1453 * parameters:
1454 * lStyle = additional style flags
1455 * x,y = x & y positions IN DIALOG UNITS
1456 * w,h = width and height IN DIALOG UNITS
1457 * Id = ID used in messages
1458 * clss = class ID, e.g 0x80 for a button, 0x82 for a static
1459 * caption = usually text or resource name
1460 *
1461 * TODO: use the length information noted here to enable the dialog creation
1462 * routines to work out more exactly how much memory they need to alloc.
1463 */
1464 static LPWORD
1465add_dialog_element(
1466 LPWORD p,
1467 DWORD lStyle,
1468 WORD x,
1469 WORD y,
1470 WORD w,
1471 WORD h,
1472 WORD Id,
1473 BYTE clss,
1474 const char *caption)
1475{
1476
1477 lStyle = lStyle | WS_VISIBLE | WS_CHILD;
1478
1479 add_word(x);
1480 add_word(y);
1481 add_word(w);
1482 add_word(h);
1483 add_word(Id);
1484 add_long(lStyle);
1485 add_byte(clss);
1486 if (((lStyle & SS_ICON) != 0) && (clss == 0x82))
1487 {
1488 /* Use resource ID */
1489 add_byte(0xff);
1490 add_byte(*caption);
1491 }
1492 else
1493 add_string(caption);
1494
1495 add_byte(0); //# of extra bytes following
1496
1497
1498 return p;
1499}
1500
1501#undef add_byte
1502#undef add_string
1503#undef add_long
1504#undef add_word
1505
1506#endif /* FEAT_GUI_DIALOG */
1507
1508 static void
1509get_dialog_font_metrics(void)
1510{
1511 DWORD dlgFontSize;
1512 dlgFontSize = GetDialogBaseUnits(); /* fall back to big old system*/
1513 s_dlgfntwidth = LOWORD(dlgFontSize);
1514 s_dlgfntheight = HIWORD(dlgFontSize);
1515}
1516
1517
1518#if defined(FEAT_TOOLBAR) || defined(PROTO)
1519#include "gui_w3~1.h"
1520/*
1521 * Create the toolbar, initially unpopulated.
1522 * (just like the menu, there are no defaults, it's all
1523 * set up through menu.vim)
1524 */
1525 static void
1526initialise_toolbar(void)
1527{
1528 s_toolbarhwnd = CreateToolbar(
1529 s_hwnd,
1530 WS_CHILD | WS_VISIBLE,
1531 CMD_TB_BASE, /*<vn>*/
1532 31, //number of images in inital bitmap
1533 s_hinst,
1534 IDR_TOOLBAR1, // id of initial bitmap
1535 NULL,
1536 0 // initial number of buttons
1537 );
1538
1539 gui_mch_show_toolbar(vim_strchr(p_go, GO_TOOLBAR) != NULL);
1540}
1541#endif
1542
1543#if defined(FEAT_OLE) || defined(FEAT_EVAL) || defined(PROTO)
1544/*
1545 * Make the GUI window come to the foreground.
1546 */
1547 void
1548gui_mch_set_foreground(void)
1549{
1550 if (IsIconic(s_hwnd))
1551 SendMessage(s_hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
1552 SetActiveWindow(s_hwnd);
1553}
1554#endif