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