-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui_w48.c
4073 lines (3626 loc) · 92.2 KB
/
gui_w48.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_w48.c: This file is included in gui_w16.c and gui_w32.c.
*
* GUI support for Microsoft Windows (Win16 + Win32 = Win48 :-)
*
* The combined efforts of:
* George V. Reilly <george@reilly.org>
* Robert Webb
* Vince Negri
* ...and contributions from many others
*
*/
#include "vim.h"
#include "version.h" /* used by dialog box routine for default title */
#ifdef DEBUG
# include <tchar.h>
#endif
/* cproto fails on missing include files */
#ifndef PROTO
#ifndef __MINGW32__
# include <shellapi.h>
#endif
#if defined(FEAT_TOOLBAR) || defined(FEAT_BEVAL) || defined(FEAT_GUI_TABLINE)
# include <commctrl.h>
#endif
#ifdef WIN16
# include <commdlg.h>
# include <shellapi.h>
# ifdef WIN16_3DLOOK
# include <ctl3d.h>
# endif
#endif
#include <windowsx.h>
#ifdef GLOBAL_IME
# include "glbl_ime.h"
#endif
#endif /* PROTO */
#ifdef FEAT_MENU
# define MENUHINTS /* show menu hints in command line */
#endif
/* Some parameters for dialog boxes. All in pixels. */
#define DLG_PADDING_X 10
#define DLG_PADDING_Y 10
#define DLG_OLD_STYLE_PADDING_X 5
#define DLG_OLD_STYLE_PADDING_Y 5
#define DLG_VERT_PADDING_X 4 /* For vertical buttons */
#define DLG_VERT_PADDING_Y 4
#define DLG_ICON_WIDTH 34
#define DLG_ICON_HEIGHT 34
#define DLG_MIN_WIDTH 150
#define DLG_FONT_NAME "MS Sans Serif"
#define DLG_FONT_POINT_SIZE 8
#define DLG_MIN_MAX_WIDTH 400
#define DLG_MIN_MAX_HEIGHT 400
#define DLG_NONBUTTON_CONTROL 5000 /* First ID of non-button controls */
#ifndef WM_XBUTTONDOWN /* For Win2K / winME ONLY */
# define WM_XBUTTONDOWN 0x020B
# define WM_XBUTTONUP 0x020C
# define WM_XBUTTONDBLCLK 0x020D
# define MK_XBUTTON1 0x0020
# define MK_XBUTTON2 0x0040
#endif
#ifdef PROTO
/*
* Define a few things for generating prototypes. This is just to avoid
* syntax errors, the defines do not need to be correct.
*/
# define APIENTRY
# define CALLBACK
# define CONST
# define FAR
# define NEAR
# define _cdecl
typedef int BOOL;
typedef int BYTE;
typedef int DWORD;
typedef int WCHAR;
typedef int ENUMLOGFONT;
typedef int FINDREPLACE;
typedef int HANDLE;
typedef int HBITMAP;
typedef int HBRUSH;
typedef int HDROP;
typedef int INT;
typedef int LOGFONT[];
typedef int LPARAM;
typedef int LPCREATESTRUCT;
typedef int LPCSTR;
typedef int LPCTSTR;
typedef int LPRECT;
typedef int LPSTR;
typedef int LPWINDOWPOS;
typedef int LPWORD;
typedef int LRESULT;
typedef int HRESULT;
# undef MSG
typedef int MSG;
typedef int NEWTEXTMETRIC;
typedef int OSVERSIONINFO;
typedef int PWORD;
typedef int RECT;
typedef int UINT;
typedef int WORD;
typedef int WPARAM;
typedef int POINT;
typedef void *HINSTANCE;
typedef void *HMENU;
typedef void *HWND;
typedef void *HDC;
typedef void VOID;
typedef int LPNMHDR;
typedef int LONG;
typedef int WNDPROC;
#endif
#ifndef GET_X_LPARAM
# define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp))
#endif
static void _OnPaint( HWND hwnd);
static void clear_rect(RECT *rcp);
static int gui_mswin_get_menu_height(int fix_window);
static WORD s_dlgfntheight; /* height of the dialog font */
static WORD s_dlgfntwidth; /* width of the dialog font */
#ifdef FEAT_MENU
static HMENU s_menuBar = NULL;
#endif
#ifdef FEAT_TEAROFF
static void rebuild_tearoff(vimmenu_T *menu);
static HBITMAP s_htearbitmap; /* bitmap used to indicate tearoff */
#endif
/* Flag that is set while processing a message that must not be interrupted by
* processing another message. */
static int s_busy_processing = FALSE;
static int destroying = FALSE; /* call DestroyWindow() ourselves */
#ifdef MSWIN_FIND_REPLACE
static UINT s_findrep_msg = 0; /* set in gui_w[16/32].c */
static FINDREPLACE s_findrep_struct;
# if defined(FEAT_MBYTE) && defined(WIN3264)
static FINDREPLACEW s_findrep_struct_w;
# endif
static HWND s_findrep_hwnd = NULL;
static int s_findrep_is_find; /* TRUE for find dialog, FALSE
for find/replace dialog */
#endif
static HINSTANCE s_hinst = NULL;
#if !defined(FEAT_SNIFF) && !defined(FEAT_GUI)
static
#endif
HWND s_hwnd = NULL;
static HDC s_hdc = NULL;
static HBRUSH s_brush = NULL;
#ifdef FEAT_TOOLBAR
static HWND s_toolbarhwnd = NULL;
static WNDPROC s_toolbar_wndproc = NULL;
#endif
#ifdef FEAT_GUI_TABLINE
static HWND s_tabhwnd = NULL;
static WNDPROC s_tabline_wndproc = NULL;
static int showing_tabline = 0;
#endif
static WPARAM s_wParam = 0;
static LPARAM s_lParam = 0;
static HWND s_textArea = NULL;
static UINT s_uMsg = 0;
static char_u *s_textfield; /* Used by dialogs to pass back strings */
static int s_need_activate = FALSE;
/* This variable is set when waiting for an event, which is the only moment
* scrollbar dragging can be done directly. It's not allowed while commands
* are executed, because it may move the cursor and that may cause unexpected
* problems (e.g., while ":s" is working).
*/
static int allow_scrollbar = FALSE;
#ifdef GLOBAL_IME
# define MyTranslateMessage(x) global_ime_TranslateMessage(x)
#else
# define MyTranslateMessage(x) TranslateMessage(x)
#endif
#if (defined(WIN3264) && defined(FEAT_MBYTE)) || defined(GLOBAL_IME)
/* use of WindowProc depends on wide_WindowProc */
# define MyWindowProc vim_WindowProc
#else
/* use ordinary WindowProc */
# define MyWindowProc DefWindowProc
#endif
extern int current_font_height; /* this is in os_mswin.c */
static struct
{
UINT key_sym;
char_u vim_code0;
char_u vim_code1;
} special_keys[] =
{
{VK_UP, 'k', 'u'},
{VK_DOWN, 'k', 'd'},
{VK_LEFT, 'k', 'l'},
{VK_RIGHT, 'k', 'r'},
{VK_F1, 'k', '1'},
{VK_F2, 'k', '2'},
{VK_F3, 'k', '3'},
{VK_F4, 'k', '4'},
{VK_F5, 'k', '5'},
{VK_F6, 'k', '6'},
{VK_F7, 'k', '7'},
{VK_F8, 'k', '8'},
{VK_F9, 'k', '9'},
{VK_F10, 'k', ';'},
{VK_F11, 'F', '1'},
{VK_F12, 'F', '2'},
{VK_F13, 'F', '3'},
{VK_F14, 'F', '4'},
{VK_F15, 'F', '5'},
{VK_F16, 'F', '6'},
{VK_F17, 'F', '7'},
{VK_F18, 'F', '8'},
{VK_F19, 'F', '9'},
{VK_F20, 'F', 'A'},
{VK_F21, 'F', 'B'},
#ifdef FEAT_NETBEANS_INTG
{VK_PAUSE, 'F', 'B'}, /* Pause == F21 (see gui_gtk_x11.c) */
#endif
{VK_F22, 'F', 'C'},
{VK_F23, 'F', 'D'},
{VK_F24, 'F', 'E'}, /* winuser.h defines up to F24 */
{VK_HELP, '%', '1'},
{VK_BACK, 'k', 'b'},
{VK_INSERT, 'k', 'I'},
{VK_DELETE, 'k', 'D'},
{VK_HOME, 'k', 'h'},
{VK_END, '@', '7'},
{VK_PRIOR, 'k', 'P'},
{VK_NEXT, 'k', 'N'},
{VK_PRINT, '%', '9'},
{VK_ADD, 'K', '6'},
{VK_SUBTRACT, 'K', '7'},
{VK_DIVIDE, 'K', '8'},
{VK_MULTIPLY, 'K', '9'},
{VK_SEPARATOR, 'K', 'A'}, /* Keypad Enter */
{VK_DECIMAL, 'K', 'B'},
{VK_NUMPAD0, 'K', 'C'},
{VK_NUMPAD1, 'K', 'D'},
{VK_NUMPAD2, 'K', 'E'},
{VK_NUMPAD3, 'K', 'F'},
{VK_NUMPAD4, 'K', 'G'},
{VK_NUMPAD5, 'K', 'H'},
{VK_NUMPAD6, 'K', 'I'},
{VK_NUMPAD7, 'K', 'J'},
{VK_NUMPAD8, 'K', 'K'},
{VK_NUMPAD9, 'K', 'L'},
/* Keys that we want to be able to use any modifier with: */
{VK_SPACE, ' ', NUL},
{VK_TAB, TAB, NUL},
{VK_ESCAPE, ESC, NUL},
{NL, NL, NUL},
{CAR, CAR, NUL},
/* End of list marker: */
{0, 0, 0}
};
/* Local variables */
static int s_button_pending = -1;
/* s_getting_focus is set when we got focus but didn't see mouse-up event yet,
* so don't reset s_button_pending. */
static int s_getting_focus = FALSE;
static int s_x_pending;
static int s_y_pending;
static UINT s_kFlags_pending;
static UINT s_wait_timer = 0; /* Timer for get char from user */
static int s_timed_out = FALSE;
static int dead_key = 0; /* 0 - no dead key, 1 - dead key pressed */
#ifdef WIN3264
static OSVERSIONINFO os_version; /* like it says. Init in gui_mch_init() */
#endif
#ifdef FEAT_BEVAL
/* balloon-eval WM_NOTIFY_HANDLER */
static void Handle_WM_Notify __ARGS((HWND hwnd, LPNMHDR pnmh));
static void TrackUserActivity __ARGS((UINT uMsg));
#endif
/*
* For control IME.
*
* These LOGFONT used for IME.
*/
#ifdef FEAT_MBYTE
# ifdef USE_IM_CONTROL
/* holds LOGFONT for 'guifontwide' if available, otherwise 'guifont' */
static LOGFONT norm_logfont;
/* holds LOGFONT for 'guifont' always. */
static LOGFONT sub_logfont;
# endif
#endif
#ifdef FEAT_MBYTE_IME
static LRESULT _OnImeNotify(HWND hWnd, DWORD dwCommand, DWORD dwData);
#endif
#if defined(FEAT_MBYTE) && defined(WIN3264)
static char_u *convert_filter(char_u *s);
#endif
#ifdef DEBUG_PRINT_ERROR
/*
* Print out the last Windows error message
*/
static void
print_windows_error(void)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL);
TRACE1("Error: %s\n", lpMsgBuf);
LocalFree(lpMsgBuf);
}
#endif
/*
* Cursor blink functions.
*
* This is a simple state machine:
* BLINK_NONE not blinking at all
* BLINK_OFF blinking, cursor is not shown
* BLINK_ON blinking, cursor is shown
*/
#define BLINK_NONE 0
#define BLINK_OFF 1
#define BLINK_ON 2
static int blink_state = BLINK_NONE;
static long_u blink_waittime = 700;
static long_u blink_ontime = 400;
static long_u blink_offtime = 250;
static UINT blink_timer = 0;
void
gui_mch_set_blinking(long wait, long on, long off)
{
blink_waittime = wait;
blink_ontime = on;
blink_offtime = off;
}
/* ARGSUSED */
static VOID CALLBACK
_OnBlinkTimer(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime)
{
MSG msg;
/*
TRACE2("Got timer event, id %d, blink_timer %d\n", idEvent, blink_timer);
*/
KillTimer(NULL, idEvent);
/* Eat spurious WM_TIMER messages */
while (pPeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
;
if (blink_state == BLINK_ON)
{
gui_undraw_cursor();
blink_state = BLINK_OFF;
blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_offtime,
(TIMERPROC)_OnBlinkTimer);
}
else
{
gui_update_cursor(TRUE, FALSE);
blink_state = BLINK_ON;
blink_timer = (UINT) SetTimer(NULL, 0, (UINT)blink_ontime,
(TIMERPROC)_OnBlinkTimer);
}
}
static void
gui_mswin_rm_blink_timer(void)
{
MSG msg;
if (blink_timer != 0)
{
KillTimer(NULL, blink_timer);
/* Eat spurious WM_TIMER messages */
while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
;
blink_timer = 0;
}
}
/*
* Stop the cursor blinking. Show the cursor if it wasn't shown.
*/
void
gui_mch_stop_blink(void)
{
gui_mswin_rm_blink_timer();
if (blink_state == BLINK_OFF)
gui_update_cursor(TRUE, FALSE);
blink_state = BLINK_NONE;
}
/*
* Start the cursor blinking. If it was already blinking, this restarts the
* waiting time and shows the cursor.
*/
void
gui_mch_start_blink(void)
{
gui_mswin_rm_blink_timer();
/* Only switch blinking on if none of the times is zero */
if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus)
{
blink_timer = (UINT)SetTimer(NULL, 0, (UINT)blink_waittime,
(TIMERPROC)_OnBlinkTimer);
blink_state = BLINK_ON;
gui_update_cursor(TRUE, FALSE);
}
}
/*
* Call-back routines.
*/
/*ARGSUSED*/
static VOID CALLBACK
_OnTimer(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime)
{
MSG msg;
/*
TRACE2("Got timer event, id %d, s_wait_timer %d\n", idEvent, s_wait_timer);
*/
KillTimer(NULL, idEvent);
s_timed_out = TRUE;
/* Eat spurious WM_TIMER messages */
while (pPeekMessage(&msg, hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
;
if (idEvent == s_wait_timer)
s_wait_timer = 0;
}
/*ARGSUSED*/
static void
_OnDeadChar(
HWND hwnd,
UINT ch,
int cRepeat)
{
dead_key = 1;
}
/*
* Convert Unicode character "ch" to bytes in "string[slen]".
* When "had_alt" is TRUE the ALT key was included in "ch".
* Return the length.
*/
static int
char_to_string(int ch, char_u *string, int slen, int had_alt)
{
int len;
int i;
#ifdef FEAT_MBYTE
WCHAR wstring[2];
char_u *ws = NULL;;
if (os_version.dwPlatformId != VER_PLATFORM_WIN32_NT)
{
/* On Windows 95/98 we apparently get the character in the active
* codepage, not in UCS-2. If conversion is needed convert it to
* UCS-2 first. */
if ((int)GetACP() == enc_codepage)
len = 0; /* no conversion required */
else
{
string[0] = ch;
len = MultiByteToWideChar(GetACP(), 0, string, 1, wstring, 2);
}
}
else
{
wstring[0] = ch;
len = 1;
}
if (len > 0)
{
/* "ch" is a UTF-16 character. Convert it to a string of bytes. When
* "enc_codepage" is non-zero use the standard Win32 function,
* otherwise use our own conversion function (e.g., for UTF-8). */
if (enc_codepage > 0)
{
len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
string, slen, 0, NULL);
/* If we had included the ALT key into the character but now the
* upper bit is no longer set, that probably means the conversion
* failed. Convert the original character and set the upper bit
* afterwards. */
if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80)
{
wstring[0] = ch & 0x7f;
len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
string, slen, 0, NULL);
if (len == 1) /* safety check */
string[0] |= 0x80;
}
}
else
{
len = 1;
ws = utf16_to_enc(wstring, &len);
if (ws == NULL)
len = 0;
else
{
if (len > slen) /* just in case */
len = slen;
mch_memmove(string, ws, len);
vim_free(ws);
}
}
}
if (len == 0)
#endif
{
string[0] = ch;
len = 1;
}
for (i = 0; i < len; ++i)
if (string[i] == CSI && len <= slen - 2)
{
/* Insert CSI as K_CSI. */
mch_memmove(string + i + 3, string + i + 1, len - i - 1);
string[++i] = KS_EXTRA;
string[++i] = (int)KE_CSI;
len += 2;
}
return len;
}
/*
* Key hit, add it to the input buffer.
*/
/*ARGSUSED*/
static void
_OnChar(
HWND hwnd,
UINT ch,
int cRepeat)
{
char_u string[40];
int len = 0;
dead_key = 0;
len = char_to_string(ch, string, 40, FALSE);
if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
{
trash_input_buf();
got_int = TRUE;
}
add_to_input_buf(string, len);
}
/*
* Alt-Key hit, add it to the input buffer.
*/
/*ARGSUSED*/
static void
_OnSysChar(
HWND hwnd,
UINT cch,
int cRepeat)
{
char_u string[40]; /* Enough for multibyte character */
int len;
int modifiers;
int ch = cch; /* special keys are negative */
/* TRACE("OnSysChar(%d, %c)\n", ch, ch); */
/* OK, we have a character key (given by ch) which was entered with the
* ALT key pressed. Eg, if the user presses Alt-A, then ch == 'A'. Note
* that the system distinguishes Alt-a and Alt-A (Alt-Shift-a unless
* CAPSLOCK is pressed) at this point.
*/
modifiers = MOD_MASK_ALT;
if (GetKeyState(VK_SHIFT) & 0x8000)
modifiers |= MOD_MASK_SHIFT;
if (GetKeyState(VK_CONTROL) & 0x8000)
modifiers |= MOD_MASK_CTRL;
ch = simplify_key(ch, &modifiers);
/* remove the SHIFT modifier for keys where it's already included, e.g.,
* '(' and '*' */
if (ch < 0x100 && !isalpha(ch) && isprint(ch))
modifiers &= ~MOD_MASK_SHIFT;
/* Interpret the ALT key as making the key META, include SHIFT, etc. */
ch = extract_modifiers(ch, &modifiers);
if (ch == CSI)
ch = K_CSI;
len = 0;
if (modifiers)
{
string[len++] = CSI;
string[len++] = KS_MODIFIER;
string[len++] = modifiers;
}
if (IS_SPECIAL((int)ch))
{
string[len++] = CSI;
string[len++] = K_SECOND((int)ch);
string[len++] = K_THIRD((int)ch);
}
else
{
/* Although the documentation isn't clear about it, we assume "ch" is
* a Unicode character. */
len += char_to_string(ch, string + len, 40 - len, TRUE);
}
add_to_input_buf(string, len);
}
static void
_OnMouseEvent(
int button,
int x,
int y,
int repeated_click,
UINT keyFlags)
{
int vim_modifiers = 0x0;
s_getting_focus = FALSE;
if (keyFlags & MK_SHIFT)
vim_modifiers |= MOUSE_SHIFT;
if (keyFlags & MK_CONTROL)
vim_modifiers |= MOUSE_CTRL;
if (GetKeyState(VK_MENU) & 0x8000)
vim_modifiers |= MOUSE_ALT;
gui_send_mouse_event(button, x, y, repeated_click, vim_modifiers);
}
/*ARGSUSED*/
static void
_OnMouseButtonDown(
HWND hwnd,
BOOL fDoubleClick,
int x,
int y,
UINT keyFlags)
{
static LONG s_prevTime = 0;
LONG currentTime = GetMessageTime();
int button = -1;
int repeated_click;
/* Give main window the focus: this is so the cursor isn't hollow. */
(void)SetFocus(s_hwnd);
if (s_uMsg == WM_LBUTTONDOWN || s_uMsg == WM_LBUTTONDBLCLK)
button = MOUSE_LEFT;
else if (s_uMsg == WM_MBUTTONDOWN || s_uMsg == WM_MBUTTONDBLCLK)
button = MOUSE_MIDDLE;
else if (s_uMsg == WM_RBUTTONDOWN || s_uMsg == WM_RBUTTONDBLCLK)
button = MOUSE_RIGHT;
#ifndef WIN16 /*<VN>*/
else if (s_uMsg == WM_XBUTTONDOWN || s_uMsg == WM_XBUTTONDBLCLK)
{
#ifndef GET_XBUTTON_WPARAM
# define GET_XBUTTON_WPARAM(wParam) (HIWORD(wParam))
#endif
button = ((GET_XBUTTON_WPARAM(s_wParam) == 1) ? MOUSE_X1 : MOUSE_X2);
}
else if (s_uMsg == WM_CAPTURECHANGED)
{
/* on W95/NT4, somehow you get in here with an odd Msg
* if you press one button while holding down the other..*/
if (s_button_pending == MOUSE_LEFT)
button = MOUSE_RIGHT;
else
button = MOUSE_LEFT;
}
#endif
if (button >= 0)
{
repeated_click = ((int)(currentTime - s_prevTime) < p_mouset);
/*
* Holding down the left and right buttons simulates pushing the middle
* button.
*/
if (repeated_click
&& ((button == MOUSE_LEFT && s_button_pending == MOUSE_RIGHT)
|| (button == MOUSE_RIGHT
&& s_button_pending == MOUSE_LEFT)))
{
/*
* Hmm, gui.c will ignore more than one button down at a time, so
* pretend we let go of it first.
*/
gui_send_mouse_event(MOUSE_RELEASE, x, y, FALSE, 0x0);
button = MOUSE_MIDDLE;
repeated_click = FALSE;
s_button_pending = -1;
_OnMouseEvent(button, x, y, repeated_click, keyFlags);
}
else if ((repeated_click)
|| (mouse_model_popup() && (button == MOUSE_RIGHT)))
{
if (s_button_pending > -1)
{
_OnMouseEvent(s_button_pending, x, y, FALSE, keyFlags);
s_button_pending = -1;
}
/* TRACE("Button down at x %d, y %d\n", x, y); */
_OnMouseEvent(button, x, y, repeated_click, keyFlags);
}
else
{
/*
* If this is the first press (i.e. not a multiple click) don't
* action immediately, but store and wait for:
* i) button-up
* ii) mouse move
* iii) another button press
* before using it.
* This enables us to make left+right simulate middle button,
* without left or right being actioned first. The side-effect is
* that if you click and hold the mouse without dragging, the
* cursor doesn't move until you release the button. In practice
* this is hardly a problem.
*/
s_button_pending = button;
s_x_pending = x;
s_y_pending = y;
s_kFlags_pending = keyFlags;
}
s_prevTime = currentTime;
}
}
/*ARGSUSED*/
static void
_OnMouseMoveOrRelease(
HWND hwnd,
int x,
int y,
UINT keyFlags)
{
int button;
s_getting_focus = FALSE;
if (s_button_pending > -1)
{
/* Delayed action for mouse down event */
_OnMouseEvent(s_button_pending, s_x_pending,
s_y_pending, FALSE, s_kFlags_pending);
s_button_pending = -1;
}
if (s_uMsg == WM_MOUSEMOVE)
{
/*
* It's only a MOUSE_DRAG if one or more mouse buttons are being held
* down.
*/
if (!(keyFlags & (MK_LBUTTON | MK_MBUTTON | MK_RBUTTON
| MK_XBUTTON1 | MK_XBUTTON2)))
{
gui_mouse_moved(x, y);
return;
}
/*
* While button is down, keep grabbing mouse move events when
* the mouse goes outside the window
*/
SetCapture(s_textArea);
button = MOUSE_DRAG;
/* TRACE(" move at x %d, y %d\n", x, y); */
}
else
{
ReleaseCapture();
button = MOUSE_RELEASE;
/* TRACE(" up at x %d, y %d\n", x, y); */
}
_OnMouseEvent(button, x, y, FALSE, keyFlags);
}
#ifdef FEAT_MENU
/*
* Find the vimmenu_T with the given id
*/
static vimmenu_T *
gui_mswin_find_menu(
vimmenu_T *pMenu,
int id)
{
vimmenu_T *pChildMenu;
while (pMenu)
{
if (pMenu->id == (UINT)id)
break;
if (pMenu->children != NULL)
{
pChildMenu = gui_mswin_find_menu(pMenu->children, id);
if (pChildMenu)
{
pMenu = pChildMenu;
break;
}
}
pMenu = pMenu->next;
}
return pMenu;
}
/*ARGSUSED*/
static void
_OnMenu(
HWND hwnd,
int id,
HWND hwndCtl,
UINT codeNotify)
{
vimmenu_T *pMenu;
pMenu = gui_mswin_find_menu(root_menu, id);
if (pMenu)
gui_menu_cb(pMenu);
}
#endif
#ifdef MSWIN_FIND_REPLACE
# if defined(FEAT_MBYTE) && defined(WIN3264)
/*
* copy useful data from structure LPFINDREPLACE to structure LPFINDREPLACEW
*/
static void
findrep_atow(LPFINDREPLACEW lpfrw, LPFINDREPLACE lpfr)
{
WCHAR *wp;
lpfrw->hwndOwner = lpfr->hwndOwner;
lpfrw->Flags = lpfr->Flags;
wp = enc_to_utf16(lpfr->lpstrFindWhat, NULL);
wcsncpy(lpfrw->lpstrFindWhat, wp, lpfrw->wFindWhatLen - 1);
vim_free(wp);
/* the field "lpstrReplaceWith" doesn't need to be copied */
}
/*
* copy useful data from structure LPFINDREPLACEW to structure LPFINDREPLACE
*/
static void
findrep_wtoa(LPFINDREPLACE lpfr, LPFINDREPLACEW lpfrw)
{
char_u *p;
lpfr->Flags = lpfrw->Flags;
p = utf16_to_enc(lpfrw->lpstrFindWhat, NULL);
vim_strncpy(lpfr->lpstrFindWhat, p, lpfr->wFindWhatLen - 1);
vim_free(p);
p = utf16_to_enc(lpfrw->lpstrReplaceWith, NULL);
vim_strncpy(lpfr->lpstrReplaceWith, p, lpfr->wReplaceWithLen - 1);
vim_free(p);
}
# endif
/*
* Handle a Find/Replace window message.
*/
static void
_OnFindRepl(void)
{
int flags = 0;
int down;
# if defined(FEAT_MBYTE) && defined(WIN3264)
/* If the OS is Windows NT, and 'encoding' differs from active codepage:
* convert text from wide string. */
if (os_version.dwPlatformId == VER_PLATFORM_WIN32_NT
&& enc_codepage >= 0 && (int)GetACP() != enc_codepage)
{
findrep_wtoa(&s_findrep_struct, &s_findrep_struct_w);
}
# endif
if (s_findrep_struct.Flags & FR_DIALOGTERM)
/* Give main window the focus back. */
(void)SetFocus(s_hwnd);
if (s_findrep_struct.Flags & FR_FINDNEXT)
{
flags = FRD_FINDNEXT;
/* Give main window the focus back: this is so the cursor isn't
* hollow. */
(void)SetFocus(s_hwnd);
}
else if (s_findrep_struct.Flags & FR_REPLACE)
{
flags = FRD_REPLACE;
/* Give main window the focus back: this is so the cursor isn't
* hollow. */
(void)SetFocus(s_hwnd);
}
else if (s_findrep_struct.Flags & FR_REPLACEALL)
{
flags = FRD_REPLACEALL;
}
if (flags != 0)
{
/* Call the generic GUI function to do the actual work. */
if (s_findrep_struct.Flags & FR_WHOLEWORD)
flags |= FRD_WHOLE_WORD;
if (s_findrep_struct.Flags & FR_MATCHCASE)
flags |= FRD_MATCH_CASE;
down = (s_findrep_struct.Flags & FR_DOWN) != 0;