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