forked from coolwanglu/vim.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_w16.c
1564 lines (1346 loc) · 37.7 KB
/
gui_w16.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* GUI support by Robert Webb
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* gui_w16.c
*
* GUI support for Microsoft Windows 3.1x
*
* George V. Reilly <[email protected]> wrote the original Win32 GUI.
* Robert Webb reworked it to use the existing GUI stuff and added menu,
* scrollbars, etc.
*
* Vince Negri then butchered the code to get it compiling for
* 16-bit windows.
*
*/
/* Win16 doesn't use the "W" methods. */
#define pDispatchMessage DispatchMessage
#define pGetMessage GetMessage
#define pIsDialogMessage IsDialogMessage
#define pPeekMessage PeekMessage
/*
* Include the common stuff for MS-Windows GUI.
*/
#include "gui_w48.c"
#include "guiw16rc.h"
/* Undocumented Windows Message - not even defined in some SDK headers */
#define WM_EXITSIZEMOVE 0x0232
#ifdef FEAT_TOOLBAR
# define CMD_TB_BASE (99)
# include <vimtbar.h>
#endif
#ifdef PROTO
# define WINAPI
#endif
#define HANDLE_WM_DROPFILES(hwnd, wParam, lParam, fn) \
((fn)((hwnd), (HDROP)(wParam)), 0L)
/* Local variables: */
#ifdef FEAT_MENU
static UINT s_menu_id = 100;
#endif
#define VIM_NAME "vim"
#define VIM_CLASS "Vim"
#define DLG_ALLOC_SIZE 16 * 1024
/*
* stuff for dialogs, menus, tearoffs etc.
*/
#if defined(FEAT_GUI_DIALOG) || defined(PROTO)
static BOOL CALLBACK dialog_callback(HWND, UINT, WPARAM, LPARAM);
static LPWORD
add_dialog_element(
LPWORD p,
DWORD lStyle,
WORD x,
WORD y,
WORD w,
WORD h,
WORD Id,
BYTE clss,
const char *caption);
static int dialog_default_button = -1;
#endif
static void get_dialog_font_metrics(void);
#ifdef FEAT_TOOLBAR
static void initialise_toolbar(void);
#endif
#ifdef FEAT_MENU
/*
* Figure out how high the menu bar is at the moment.
*/
static int
gui_mswin_get_menu_height(
int fix_window) /* If TRUE, resize window if menu height changed */
{
static int old_menu_height = -1;
int num;
int menu_height;
if (gui.menu_is_active)
num = GetMenuItemCount(s_menuBar);
else
num = 0;
if (num == 0)
menu_height = 0;
else if (gui.starting)
menu_height = GetSystemMetrics(SM_CYMENU);
else
{
RECT r1, r2;
int frameht = GetSystemMetrics(SM_CYFRAME);
int capht = GetSystemMetrics(SM_CYCAPTION);
/* get window rect of s_hwnd
* get client rect of s_hwnd
* get cap height
* subtract from window rect, the sum of client height,
* (if not maximized)frame thickness, and caption height.
*/
GetWindowRect(s_hwnd, &r1);
GetClientRect(s_hwnd, &r2);
menu_height = r1.bottom - r1.top - (r2.bottom-r2.top +
2 * frameht * (!IsZoomed(s_hwnd)) + capht);
}
if (fix_window && menu_height != old_menu_height)
{
old_menu_height = menu_height;
gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
}
return menu_height;
}
#endif /*FEAT_MENU*/
/*
* Even though we have _DuringSizing() which makes the rubber band a valid
* size, we need this for when the user maximises the window.
* TODO: Doesn't seem to adjust the width though for some reason.
*/
static BOOL
_OnWindowPosChanging(
HWND hwnd,
LPWINDOWPOS lpwpos)
{
if (!IsIconic(hwnd) && !(lpwpos->flags & SWP_NOSIZE))
{
gui_mswin_get_valid_dimensions(lpwpos->cx, lpwpos->cy,
&lpwpos->cx, &lpwpos->cy);
}
return 0;
}
static LRESULT CALLBACK
_WndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
/*
TRACE("WndProc: hwnd = %08x, msg = %x, wParam = %x, lParam = %x\n",
hwnd, uMsg, wParam, lParam);
*/
HandleMouseHide(uMsg, lParam);
s_uMsg = uMsg;
s_wParam = wParam;
s_lParam = lParam;
switch (uMsg)
{
HANDLE_MSG(hwnd, WM_DEADCHAR, _OnDeadChar);
HANDLE_MSG(hwnd, WM_SYSDEADCHAR, _OnDeadChar);
/* HANDLE_MSG(hwnd, WM_ACTIVATE, _OnActivate); */
HANDLE_MSG(hwnd, WM_CHAR, _OnChar);
HANDLE_MSG(hwnd, WM_CLOSE, _OnClose);
/* HANDLE_MSG(hwnd, WM_COMMAND, _OnCommand); */
HANDLE_MSG(hwnd, WM_DESTROY, _OnDestroy);
HANDLE_MSG(hwnd, WM_DROPFILES, _OnDropFiles);
HANDLE_MSG(hwnd, WM_HSCROLL, _OnScroll);
HANDLE_MSG(hwnd, WM_KILLFOCUS, _OnKillFocus);
#ifdef FEAT_MENU
HANDLE_MSG(hwnd, WM_COMMAND, _OnMenu);
#endif
/* HANDLE_MSG(hwnd, WM_MOVE, _OnMove); */
/* HANDLE_MSG(hwnd, WM_NCACTIVATE, _OnNCActivate); */
HANDLE_MSG(hwnd, WM_SETFOCUS, _OnSetFocus);
HANDLE_MSG(hwnd, WM_SIZE, _OnSize);
/* HANDLE_MSG(hwnd, WM_SYSCOMMAND, _OnSysCommand); */
/* HANDLE_MSG(hwnd, WM_SYSKEYDOWN, _OnAltKey); */
HANDLE_MSG(hwnd, WM_VSCROLL, _OnScroll);
HANDLE_MSG(hwnd, WM_WINDOWPOSCHANGING, _OnWindowPosChanging);
HANDLE_MSG(hwnd, WM_ACTIVATEAPP, _OnActivateApp);
case WM_QUERYENDSESSION: /* System wants to go down. */
gui_shell_closed(); /* Will exit when no changed buffers. */
return FALSE; /* Do NOT allow system to go down. */
case WM_ENDSESSION:
if (wParam) /* system only really goes down when wParam is TRUE */
_OnEndSession();
break;
case WM_SYSCHAR:
/*
* if 'winaltkeys' is "no", or it's "menu" and it's not a menu
* shortcut key, handle like a typed ALT key, otherwise call Windows
* ALT key handling.
*/
#ifdef FEAT_MENU
if ( !gui.menu_is_active
|| p_wak[0] == 'n'
|| (p_wak[0] == 'm' && !gui_is_menu_shortcut((int)wParam))
)
#endif
return HANDLE_WM_SYSCHAR((hwnd), (wParam), (lParam), (_OnSysChar));
#ifdef FEAT_MENU
else
return MyWindowProc(hwnd, uMsg, wParam, lParam);
#endif
case WM_SYSKEYUP:
#ifdef FEAT_MENU
/* Only when menu is active, ALT key is used for that. */
if (gui.menu_is_active)
{
return MyWindowProc(hwnd, uMsg, wParam, lParam);
}
else
#endif
return 0;
#if defined(MENUHINTS) && defined(FEAT_MENU)
case WM_MENUSELECT:
if (((UINT) LOWORD(lParam)
& (0xffff ^ (MF_MOUSESELECT + MF_BITMAP + MF_POPUP)))
== MF_HILITE
&& (State & CMDLINE) == 0)
{
UINT idButton;
int idx;
vimmenu_T *pMenu;
idButton = (UINT)LOWORD(wParam);
pMenu = gui_mswin_find_menu(root_menu, idButton);
if (pMenu)
{
idx = MENU_INDEX_TIP;
msg_clr_cmdline();
if (pMenu->strings[idx])
msg(pMenu->strings[idx]);
else
msg("");
setcursor();
out_flush();
}
}
break;
#endif
case WM_NCHITTEST:
{
LRESULT result;
int x, y;
int xPos = GET_X_LPARAM(lParam);
result = MyWindowProc(hwnd, uMsg, wParam, lParam);
if (result == HTCLIENT)
{
gui_mch_get_winpos(&x, &y);
xPos -= x;
if (xPos < 48) /*<VN> TODO should use system metric?*/
return HTBOTTOMLEFT;
else
return HTBOTTOMRIGHT;
}
else
return result;
}
/* break; */
default:
#ifdef MSWIN_FIND_REPLACE
if (uMsg == s_findrep_msg && s_findrep_msg != 0)
{
_OnFindRepl();
}
#endif
return MyWindowProc(hwnd, uMsg, wParam, lParam);
}
return 1;
}
/*
* End of call-back routines
*/
/*
* Parse the GUI related command-line arguments. Any arguments used are
* deleted from argv, and *argc is decremented accordingly. This is called
* when vim is started, whether or not the GUI has been started.
*/
void
gui_mch_prepare(int *argc, char **argv)
{
/* No special args for win16 GUI at the moment. */
}
/*
* Initialise the GUI. Create all the windows, set up all the call-backs
* etc.
*/
int
gui_mch_init(void)
{
const char szVimWndClass[] = VIM_CLASS;
const char szTextAreaClass[] = "VimTextArea";
WNDCLASS wndclass;
#ifdef WIN16_3DLOOK
Ctl3dRegister(s_hinst);
Ctl3dAutoSubclass(s_hinst);
#endif
/* Display any pending error messages */
display_errors();
gui.scrollbar_width = GetSystemMetrics(SM_CXVSCROLL);
gui.scrollbar_height = GetSystemMetrics(SM_CYHSCROLL);
#ifdef FEAT_MENU
gui.menu_height = 0; /* Windows takes care of this */
#endif
gui.border_width = 0;
gui.currBgColor = INVALCOLOR;
s_brush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
if (GetClassInfo(s_hinst, szVimWndClass, &wndclass) == 0) {
wndclass.style = 0;
wndclass.lpfnWndProc = _WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = s_hinst;
wndclass.hIcon = LoadIcon(wndclass.hInstance, MAKEINTRESOURCE(IDR_VIM));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = s_brush;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szVimWndClass;
if ((
#ifdef GLOBAL_IME
atom =
#endif
RegisterClass(&wndclass)) == 0)
return FAIL;
}
s_hwnd = CreateWindow(
szVimWndClass, "Vim MSWindows GUI",
WS_OVERLAPPEDWINDOW,
gui_win_x == -1 ? CW_USEDEFAULT : gui_win_x,
gui_win_y == -1 ? CW_USEDEFAULT : gui_win_y,
100, /* Any value will do */
100, /* Any value will do */
NULL, NULL,
s_hinst, NULL);
if (s_hwnd == NULL)
return FAIL;
#ifdef GLOBAL_IME
global_ime_init(atom, s_hwnd);
#endif
/* Create the text area window */
if (GetClassInfo(s_hinst, szTextAreaClass, &wndclass) == 0) {
wndclass.style = CS_OWNDC;
wndclass.lpfnWndProc = _TextAreaWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = s_hinst;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szTextAreaClass;
if (RegisterClass(&wndclass) == 0)
return FAIL;
}
s_textArea = CreateWindow(
szTextAreaClass, "Vim text area",
WS_CHILD | WS_VISIBLE, 0, 0,
100, /* Any value will do for now */
100, /* Any value will do for now */
s_hwnd, NULL,
s_hinst, NULL);
if (s_textArea == NULL)
return FAIL;
#ifdef FEAT_MENU
s_menuBar = CreateMenu();
#endif
s_hdc = GetDC(s_textArea);
#ifdef MSWIN16_FASTTEXT
SetBkMode(s_hdc, OPAQUE);
#endif
DragAcceptFiles(s_hwnd, TRUE);
/* Do we need to bother with this? */
/* m_fMouseAvail = GetSystemMetrics(SM_MOUSEPRESENT); */
/* Get background/foreground colors from the system */
gui_mch_def_colors();
/* Get the colors from the "Normal" group (set in syntax.c or in a vimrc
* file) */
set_normal_colors();
/*
* Check that none of the colors are the same as the background color.
* Then store the current values as the defaults.
*/
gui_check_colors();
gui.def_norm_pixel = gui.norm_pixel;
gui.def_back_pixel = gui.back_pixel;
/* Get the colors for the highlight groups (gui_check_colors() might have
* changed them) */
highlight_gui_started();
/*
* Start out by adding the configured border width into the border offset
*/
gui.border_offset = gui.border_width;
/*
* compute a couple of metrics used for the dialogs
*/
get_dialog_font_metrics();
#ifdef FEAT_TOOLBAR
/*
* Create the toolbar
*/
initialise_toolbar();
#endif
#ifdef MSWIN_FIND_REPLACE
/*
* Initialise the dialog box stuff
*/
s_findrep_msg = RegisterWindowMessage(FINDMSGSTRING);
/* Initialise the struct */
s_findrep_struct.lStructSize = sizeof(s_findrep_struct);
s_findrep_struct.lpstrFindWhat = alloc(MSWIN_FR_BUFSIZE);
s_findrep_struct.lpstrFindWhat[0] = NUL;
s_findrep_struct.lpstrReplaceWith = alloc(MSWIN_FR_BUFSIZE);
s_findrep_struct.lpstrReplaceWith[0] = NUL;
s_findrep_struct.wFindWhatLen = MSWIN_FR_BUFSIZE;
s_findrep_struct.wReplaceWithLen = MSWIN_FR_BUFSIZE;
#endif
return OK;
}
/*
* Set the size of the window to the given width and height in pixels.
*/
void
gui_mch_set_shellsize(int width, int height,
int min_width, int min_height, int base_width, int base_height,
int direction)
{
RECT workarea_rect;
int win_width, win_height;
int win_xpos, win_ypos;
WINDOWPLACEMENT wndpl;
/* try to keep window completely on screen */
/* get size of the screen work area - use SM_CYFULLSCREEN
* instead of SM_CYSCREEN so that we don't overlap the
* taskbar if someone fires us up on Win95/NT */
workarea_rect.left = 0;
workarea_rect.top = 0;
workarea_rect.right = GetSystemMetrics(SM_CXSCREEN);
workarea_rect.bottom = GetSystemMetrics(SM_CYFULLSCREEN);
/* get current position of our window */
wndpl.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(s_hwnd, &wndpl);
if (wndpl.showCmd == SW_SHOWNORMAL)
{
win_xpos = wndpl.rcNormalPosition.left;
win_ypos = wndpl.rcNormalPosition.top;
}
else
{
win_xpos = workarea_rect.left;
win_ypos = workarea_rect.top;
}
/* compute the size of the outside of the window */
win_width = width + GetSystemMetrics(SM_CXFRAME) * 2;
win_height = height + GetSystemMetrics(SM_CYFRAME) * 2
+ GetSystemMetrics(SM_CYCAPTION)
#ifdef FEAT_MENU
+ gui_mswin_get_menu_height(FALSE)
#endif
;
/* if the window is going off the screen, move it on to the screen */
if ((direction & RESIZE_HOR) && win_xpos + win_width > workarea_rect.right)
win_xpos = workarea_rect.right - win_width;
if ((direction & RESIZE_HOR) && win_xpos < workarea_rect.left)
win_xpos = workarea_rect.left;
if ((direction & RESIZE_VERT)
&& win_ypos + win_height > workarea_rect.bottom)
win_ypos = workarea_rect.bottom - win_height;
if ((direction & RESIZE_VERT) && win_ypos < workarea_rect.top)
win_ypos = workarea_rect.top;
/* set window position */
SetWindowPos(s_hwnd, NULL, win_xpos, win_ypos, win_width, win_height,
SWP_NOZORDER | SWP_NOACTIVATE);
#ifdef FEAT_MENU
/* Menu may wrap differently now */
gui_mswin_get_menu_height(!gui.starting);
#endif
}
void
gui_mch_set_scrollbar_thumb(
scrollbar_T *sb,
long val,
long size,
long max)
{
sb->scroll_shift = 0;
while (max > 32767)
{
max = (max + 1) >> 1;
val >>= 1;
size >>= 1;
++sb->scroll_shift;
}
if (sb->scroll_shift > 0)
++size;
SetScrollRange(sb->id, SB_CTL, 0, (int) max, FALSE);
SetScrollPos(sb->id, SB_CTL, (int) val, TRUE);
}
/*
* Set the current text font.
*/
void
gui_mch_set_font(GuiFont font)
{
gui.currFont = font;
SelectFont(s_hdc, gui.currFont);
}
/*
* Set the current text foreground color.
*/
void
gui_mch_set_fg_color(guicolor_T color)
{
gui.currFgColor = color;
SetTextColor(s_hdc, gui.currFgColor);
}
/*
* Set the current text background color.
*/
void
gui_mch_set_bg_color(guicolor_T color)
{
if (gui.currBgColor == color)
return;
gui.currBgColor = color;
SetBkColor(s_hdc, gui.currBgColor);
}
/*
* Set the current text special color.
*/
void
gui_mch_set_sp_color(guicolor_T color)
{
/* TODO */
}
void
gui_mch_draw_string(
int row,
int col,
char_u *text,
int len,
int flags)
{
#ifndef MSWIN16_FASTTEXT
static int *padding = NULL;
static int pad_size = 0;
int i;
#endif
HPEN hpen, old_pen;
int y;
#ifndef MSWIN16_FASTTEXT
/*
* Italic and bold text seems to have an extra row of pixels at the bottom
* (below where the bottom of the character should be). If we draw the
* characters with a solid background, the top row of pixels in the
* character below will be overwritten. We can fix this by filling in the
* background ourselves, to the correct character proportions, and then
* writing the character in transparent mode. Still have a problem when
* the character is "_", which gets written on to the character below.
* New fix: set gui.char_ascent to -1. This shifts all characters up one
* pixel in their slots, which fixes the problem with the bottom row of
* pixels. We still need this code because otherwise the top row of pixels
* becomes a problem. - webb.
*/
HBRUSH hbr;
RECT rc;
if (!(flags & DRAW_TRANSP))
{
/*
* Clear background first.
* Note: FillRect() excludes right and bottom of rectangle.
*/
rc.left = FILL_X(col);
rc.top = FILL_Y(row);
#ifdef FEAT_MBYTE
if (has_mbyte)
{
/* Compute the length in display cells. */
rc.right = FILL_X(col + mb_string2cells(text, len));
}
else
#endif
rc.right = FILL_X(col + len);
rc.bottom = FILL_Y(row + 1);
hbr = CreateSolidBrush(gui.currBgColor);
FillRect(s_hdc, &rc, hbr);
DeleteBrush(hbr);
SetBkMode(s_hdc, TRANSPARENT);
/*
* When drawing block cursor, prevent inverted character spilling
* over character cell (can happen with bold/italic)
*/
if (flags & DRAW_CURSOR)
{
pcliprect = &rc;
foptions = ETO_CLIPPED;
}
}
#else
/*
* Alternative: write the characters in opaque mode, since we have blocked
* bold or italic fonts.
*/
/* The OPAQUE mode and backcolour have already been set */
#endif
/* The forecolor and font have already been set */
#ifndef MSWIN16_FASTTEXT
if (pad_size != Columns || padding == NULL || padding[0] != gui.char_width)
{
vim_free(padding);
pad_size = Columns;
padding = (int *)alloc(pad_size * sizeof(int));
if (padding != NULL)
for (i = 0; i < pad_size; i++)
padding[i] = gui.char_width;
}
#endif
/*
* We have to provide the padding argument because italic and bold versions
* of fixed-width fonts are often one pixel or so wider than their normal
* versions.
* No check for DRAW_BOLD, Windows will have done it already.
*/
#ifndef MSWIN16_FASTTEXT
ExtTextOut(s_hdc, TEXT_X(col), TEXT_Y(row), 0, NULL,
(char *)text, len, padding);
#else
TextOut(s_hdc, TEXT_X(col), TEXT_Y(row), (char *)text, len);
#endif
if (flags & DRAW_UNDERL)
{
hpen = CreatePen(PS_SOLID, 1, gui.currFgColor);
old_pen = SelectObject(s_hdc, hpen);
/* When p_linespace is 0, overwrite the bottom row of pixels.
* Otherwise put the line just below the character. */
y = FILL_Y(row + 1) - 1;
#ifndef MSWIN16_FASTTEXT
if (p_linespace > 1)
y -= p_linespace - 1;
#endif
MoveToEx(s_hdc, FILL_X(col), y, NULL);
/* Note: LineTo() excludes the last pixel in the line. */
LineTo(s_hdc, FILL_X(col + len), y);
DeleteObject(SelectObject(s_hdc, old_pen));
}
}
/*
* Output routines.
*/
/* Flush any output to the screen */
void
gui_mch_flush(void)
{
/* Is anything needed here? */
}
static void
clear_rect(RECT *rcp)
{
/* Use trick for fast rect clear */
gui_mch_set_bg_color(gui.back_pixel);
ExtTextOut(s_hdc, 0, 0, ETO_CLIPPED | ETO_OPAQUE, rcp, NULL, 0, NULL);
}
void
gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
{
*screen_w = GetSystemMetrics(SM_CXFULLSCREEN)
- GetSystemMetrics(SM_CXFRAME) * 2;
/* FIXME: dirty trick: Because the gui_get_base_height() doesn't include
* the menubar for MSwin, we subtract it from the screen height, so that
* the window size can be made to fit on the screen. */
*screen_h = GetSystemMetrics(SM_CYFULLSCREEN)
- GetSystemMetrics(SM_CYFRAME) * 2
#ifdef FEAT_MENU
- gui_mswin_get_menu_height(FALSE)
#endif
;
}
#if defined(FEAT_MENU) || defined(PROTO)
/*
* Add a sub menu to the menu bar.
*/
void
gui_mch_add_menu(
vimmenu_T *menu,
int pos)
{
vimmenu_T *parent = menu->parent;
menu->submenu_id = CreatePopupMenu();
menu->id = s_menu_id++;
if (menu_is_menubar(menu->name))
{
InsertMenu((parent == NULL) ? s_menuBar : parent->submenu_id,
(UINT)pos, MF_POPUP | MF_STRING | MF_BYPOSITION,
(UINT)menu->submenu_id, menu->name);
}
/* Fix window size if menu may have wrapped */
if (parent == NULL)
gui_mswin_get_menu_height(!gui.starting);
}
void
gui_mch_show_popupmenu(vimmenu_T *menu)
{
POINT mp;
(void)GetCursorPos((LPPOINT)&mp);
gui_mch_show_popupmenu_at(menu, (int)mp.x, (int)mp.y);
}
void
gui_make_popup(char_u *path_name, int mouse_pos)
{
vimmenu_T *menu = gui_find_menu(path_name);
if (menu != NULL)
{
/* Find the position of the current cursor */
DWORD temp_p;
POINT p;
temp_p = GetDCOrg(s_hdc);
p.x = LOWORD(temp_p);
p.y = HIWORD(temp_p);
if (mouse_pos)
{
int mx, my;
gui_mch_getmouse(&mx, &my);
p.x += mx;
p.y += my;
}
else if (curwin != NULL)
{
p.x += TEXT_X(W_WINCOL(curwin) + curwin->w_wcol + 1);
p.y += TEXT_Y(W_WINROW(curwin) + curwin->w_wrow + 1);
}
msg_scroll = FALSE;
gui_mch_show_popupmenu_at(menu, (int)p.x, (int)p.y);
}
}
/*
* Add a menu item to a menu
*/
void
gui_mch_add_menu_item(
vimmenu_T *menu,
int idx)
{
vimmenu_T *parent = menu->parent;
menu->id = s_menu_id++;
menu->submenu_id = NULL;
#ifdef FEAT_TOOLBAR
if (menu_is_toolbar(parent->name))
{
TBBUTTON newtb;
vim_memset(&newtb, 0, sizeof(newtb));
if (menu_is_separator(menu->name))
{
newtb.iBitmap = 0;
newtb.fsStyle = TBSTYLE_SEP;
}
else
{
if (menu->iconidx >= TOOLBAR_BITMAP_COUNT)
newtb.iBitmap = -1;
else
newtb.iBitmap = menu->iconidx;
newtb.fsStyle = TBSTYLE_BUTTON;
}
newtb.idCommand = menu->id;
newtb.fsState = TBSTATE_ENABLED;
SendMessage(s_toolbarhwnd, TB_INSERTBUTTON, (WPARAM)idx,
(LPARAM)&newtb);
menu->submenu_id = (HMENU)-1;
}
else
#endif
{
InsertMenu(parent->submenu_id, (UINT)idx,
(menu_is_separator(menu->name) ? MF_SEPARATOR : MF_STRING)
| MF_BYPOSITION,
(UINT)menu->id, menu->name);
}
}
/*
* Destroy the machine specific menu widget.
*/
void
gui_mch_destroy_menu(vimmenu_T *menu)
{
UINT i, j;
char pants[80]; /*<VN> hack*/
#ifdef FEAT_TOOLBAR
/*
* is this a toolbar button?
*/
if (menu->submenu_id == (HMENU)-1)
{
int iButton;
iButton = SendMessage(s_toolbarhwnd, TB_COMMANDTOINDEX, (WPARAM)menu->id, 0);
SendMessage(s_toolbarhwnd, TB_DELETEBUTTON, (WPARAM)iButton, 0);
}
else
#endif
{
/*
* negri: horrible API bug when running 16-bit programs under Win9x or
* NT means that we can't use MF_BYCOMMAND for menu items which have
* submenus, including the top-level headings. We have to find the menu
* item and use MF_BYPOSITION instead. :-p
*/
if (menu->parent != NULL
&& menu_is_popup(menu->parent->dname)
&& menu->parent->submenu_id != NULL)
RemoveMenu(menu->parent->submenu_id, menu->id, MF_BYCOMMAND);
else if (menu->submenu_id == NULL)
RemoveMenu(s_menuBar, menu->id, MF_BYCOMMAND);
else if (menu->parent != NULL)
{
i = GetMenuItemCount(menu->parent->submenu_id);
for (j = 0; j < i; ++j)
{
GetMenuString(menu->parent->submenu_id, j,
pants, 80, MF_BYPOSITION);
if (strcmp(pants, menu->name) == 0)
{
RemoveMenu(menu->parent->submenu_id, j, MF_BYPOSITION);
break;
}
}
}
else
{
i = GetMenuItemCount(s_menuBar);
for (j = 0; j < i; ++j)
{
GetMenuString(s_menuBar, j, pants, 80, MF_BYPOSITION);
if (strcmp(pants, menu->name) == 0)
{
RemoveMenu(s_menuBar, j, MF_BYPOSITION);
break;
}
}
}
if (menu->submenu_id != NULL)
DestroyMenu(menu->submenu_id);
}
DrawMenuBar(s_hwnd);
}
/*
* Make a menu either grey or not grey.
*/
void
gui_mch_menu_grey(
vimmenu_T *menu,
int grey)
{
#ifdef FEAT_TOOLBAR
/*
* is this a toolbar button?
*/
if (menu->submenu_id == (HMENU)-1)
{
SendMessage(s_toolbarhwnd, TB_ENABLEBUTTON,
(WPARAM)menu->id, (LPARAM) MAKELONG((grey ? FALSE : TRUE), 0) );
}
else
#endif
if (grey)
EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_GRAYED);
else
EnableMenuItem(s_menuBar, menu->id, MF_BYCOMMAND | MF_ENABLED);
}
#endif /*FEAT_MENU*/