Mercurial > vim
comparison src/gui_gtk_x11.c @ 18781:79e10adc821d v8.1.2380
patch 8.1.2380: using old C style comments
Commit: https://github.com/vim/vim/commit/306139005c31ea7e6f892dd119beba3c94dcb982
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 1 22:11:18 2019 +0100
patch 8.1.2380: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Dec 2019 22:15:03 +0100 |
parents | df141c730008 |
children | f37028184d6a |
comparison
equal
deleted
inserted
replaced
18780:04ce3b8a50ed | 18781:79e10adc821d |
---|---|
29 #ifdef USE_GRESOURCE | 29 #ifdef USE_GRESOURCE |
30 #include "auto/gui_gtk_gresources.h" | 30 #include "auto/gui_gtk_gresources.h" |
31 #endif | 31 #endif |
32 | 32 |
33 #ifdef FEAT_GUI_GNOME | 33 #ifdef FEAT_GUI_GNOME |
34 /* Gnome redefines _() and N_(). Grrr... */ | 34 // Gnome redefines _() and N_(). Grrr... |
35 # ifdef _ | 35 # ifdef _ |
36 # undef _ | 36 # undef _ |
37 # endif | 37 # endif |
38 # ifdef N_ | 38 # ifdef N_ |
39 # undef N_ | 39 # undef N_ |
46 # endif | 46 # endif |
47 # ifdef bind_textdomain_codeset | 47 # ifdef bind_textdomain_codeset |
48 # undef bind_textdomain_codeset | 48 # undef bind_textdomain_codeset |
49 # endif | 49 # endif |
50 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) | 50 # if defined(FEAT_GETTEXT) && !defined(ENABLE_NLS) |
51 # define ENABLE_NLS /* so the texts in the dialog boxes are translated */ | 51 # define ENABLE_NLS // so the texts in the dialog boxes are translated |
52 # endif | 52 # endif |
53 # include <gnome.h> | 53 # include <gnome.h> |
54 # include "version.h" | 54 # include "version.h" |
55 /* missing prototype in bonobo-dock-item.h */ | 55 // missing prototype in bonobo-dock-item.h |
56 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); | 56 extern void bonobo_dock_item_set_behavior(BonoboDockItem *dock_item, BonoboDockItemBehavior beh); |
57 #endif | 57 #endif |
58 | 58 |
59 #if !defined(FEAT_GUI_GTK) && defined(PROTO) | 59 #if !defined(FEAT_GUI_GTK) && defined(PROTO) |
60 /* When generating prototypes we don't want syntax errors. */ | 60 // When generating prototypes we don't want syntax errors. |
61 # define GdkAtom int | 61 # define GdkAtom int |
62 # define GdkEventExpose int | 62 # define GdkEventExpose int |
63 # define GdkEventFocus int | 63 # define GdkEventFocus int |
64 # define GdkEventVisibility int | 64 # define GdkEventVisibility int |
65 # define GdkEventProperty int | 65 # define GdkEventProperty int |
103 * Easy-to-use macro for multihead support. | 103 * Easy-to-use macro for multihead support. |
104 */ | 104 */ |
105 #define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ | 105 #define GET_X_ATOM(atom) gdk_x11_atom_to_xatom_for_display( \ |
106 gtk_widget_get_display(gui.mainwin), atom) | 106 gtk_widget_get_display(gui.mainwin), atom) |
107 | 107 |
108 /* Selection type distinguishers */ | 108 // Selection type distinguishers |
109 enum | 109 enum |
110 { | 110 { |
111 TARGET_TYPE_NONE, | 111 TARGET_TYPE_NONE, |
112 TARGET_UTF8_STRING, | 112 TARGET_UTF8_STRING, |
113 TARGET_STRING, | 113 TARGET_STRING, |
175 /* | 175 /* |
176 * Atoms used to control/reference X11 selections. | 176 * Atoms used to control/reference X11 selections. |
177 */ | 177 */ |
178 static GdkAtom html_atom = GDK_NONE; | 178 static GdkAtom html_atom = GDK_NONE; |
179 static GdkAtom utf8_string_atom = GDK_NONE; | 179 static GdkAtom utf8_string_atom = GDK_NONE; |
180 static GdkAtom vim_atom = GDK_NONE; /* Vim's own special selection format */ | 180 static GdkAtom vim_atom = GDK_NONE; // Vim's own special selection format |
181 static GdkAtom vimenc_atom = GDK_NONE; /* Vim's extended selection format */ | 181 static GdkAtom vimenc_atom = GDK_NONE; // Vim's extended selection format |
182 | 182 |
183 /* | 183 /* |
184 * Keycodes recognized by vim. | 184 * Keycodes recognized by vim. |
185 * NOTE: when changing this, the table in gui_x11.c probably needs the same | 185 * NOTE: when changing this, the table in gui_x11.c probably needs the same |
186 * change! | 186 * change! |
216 {GDK_F17, 'F', '7'}, | 216 {GDK_F17, 'F', '7'}, |
217 {GDK_F18, 'F', '8'}, | 217 {GDK_F18, 'F', '8'}, |
218 {GDK_F19, 'F', '9'}, | 218 {GDK_F19, 'F', '9'}, |
219 {GDK_F20, 'F', 'A'}, | 219 {GDK_F20, 'F', 'A'}, |
220 {GDK_F21, 'F', 'B'}, | 220 {GDK_F21, 'F', 'B'}, |
221 {GDK_Pause, 'F', 'B'}, /* Pause == F21 according to netbeans.txt */ | 221 {GDK_Pause, 'F', 'B'}, // Pause == F21 according to netbeans.txt |
222 {GDK_F22, 'F', 'C'}, | 222 {GDK_F22, 'F', 'C'}, |
223 {GDK_F23, 'F', 'D'}, | 223 {GDK_F23, 'F', 'D'}, |
224 {GDK_F24, 'F', 'E'}, | 224 {GDK_F24, 'F', 'E'}, |
225 {GDK_F25, 'F', 'F'}, | 225 {GDK_F25, 'F', 'F'}, |
226 {GDK_F26, 'F', 'G'}, | 226 {GDK_F26, 'F', 'G'}, |
247 {GDK_Home, 'k', 'h'}, | 247 {GDK_Home, 'k', 'h'}, |
248 {GDK_End, '@', '7'}, | 248 {GDK_End, '@', '7'}, |
249 {GDK_Prior, 'k', 'P'}, | 249 {GDK_Prior, 'k', 'P'}, |
250 {GDK_Next, 'k', 'N'}, | 250 {GDK_Next, 'k', 'N'}, |
251 {GDK_Print, '%', '9'}, | 251 {GDK_Print, '%', '9'}, |
252 /* Keypad keys: */ | 252 // Keypad keys: |
253 {GDK_KP_Left, 'k', 'l'}, | 253 {GDK_KP_Left, 'k', 'l'}, |
254 {GDK_KP_Right, 'k', 'r'}, | 254 {GDK_KP_Right, 'k', 'r'}, |
255 {GDK_KP_Up, 'k', 'u'}, | 255 {GDK_KP_Up, 'k', 'u'}, |
256 {GDK_KP_Down, 'k', 'd'}, | 256 {GDK_KP_Down, 'k', 'd'}, |
257 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, | 257 {GDK_KP_Insert, KS_EXTRA, (char_u)KE_KINS}, |
258 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, | 258 {GDK_KP_Delete, KS_EXTRA, (char_u)KE_KDEL}, |
259 {GDK_KP_Home, 'K', '1'}, | 259 {GDK_KP_Home, 'K', '1'}, |
260 {GDK_KP_End, 'K', '4'}, | 260 {GDK_KP_End, 'K', '4'}, |
261 {GDK_KP_Prior, 'K', '3'}, /* page up */ | 261 {GDK_KP_Prior, 'K', '3'}, // page up |
262 {GDK_KP_Next, 'K', '5'}, /* page down */ | 262 {GDK_KP_Next, 'K', '5'}, // page down |
263 | 263 |
264 {GDK_KP_Add, 'K', '6'}, | 264 {GDK_KP_Add, 'K', '6'}, |
265 {GDK_KP_Subtract, 'K', '7'}, | 265 {GDK_KP_Subtract, 'K', '7'}, |
266 {GDK_KP_Divide, 'K', '8'}, | 266 {GDK_KP_Divide, 'K', '8'}, |
267 {GDK_KP_Multiply, 'K', '9'}, | 267 {GDK_KP_Multiply, 'K', '9'}, |
277 {GDK_KP_6, 'K', 'I'}, | 277 {GDK_KP_6, 'K', 'I'}, |
278 {GDK_KP_7, 'K', 'J'}, | 278 {GDK_KP_7, 'K', 'J'}, |
279 {GDK_KP_8, 'K', 'K'}, | 279 {GDK_KP_8, 'K', 'K'}, |
280 {GDK_KP_9, 'K', 'L'}, | 280 {GDK_KP_9, 'K', 'L'}, |
281 | 281 |
282 /* End of list marker: */ | 282 // End of list marker: |
283 {0, 0, 0} | 283 {0, 0, 0} |
284 }; | 284 }; |
285 | 285 |
286 /* | 286 /* |
287 * Flags for command line options table below. | 287 * Flags for command line options table below. |
293 #define ARG_BACKGROUND 5 | 293 #define ARG_BACKGROUND 5 |
294 #define ARG_FOREGROUND 6 | 294 #define ARG_FOREGROUND 6 |
295 #define ARG_ICONIC 7 | 295 #define ARG_ICONIC 7 |
296 #define ARG_ROLE 8 | 296 #define ARG_ROLE 8 |
297 #define ARG_NETBEANS 9 | 297 #define ARG_NETBEANS 9 |
298 #define ARG_XRM 10 /* ignored */ | 298 #define ARG_XRM 10 // ignored |
299 #define ARG_MENUFONT 11 /* ignored */ | 299 #define ARG_MENUFONT 11 // ignored |
300 #define ARG_INDEX_MASK 0x00ff | 300 #define ARG_INDEX_MASK 0x00ff |
301 #define ARG_HAS_VALUE 0x0100 /* a value is expected after the argument */ | 301 #define ARG_HAS_VALUE 0x0100 // a value is expected after the argument |
302 #define ARG_NEEDS_GUI 0x0200 /* need to initialize the GUI for this */ | 302 #define ARG_NEEDS_GUI 0x0200 // need to initialize the GUI for this |
303 #define ARG_FOR_GTK 0x0400 /* argument is handled by GTK+ or GNOME */ | 303 #define ARG_FOR_GTK 0x0400 // argument is handled by GTK+ or GNOME |
304 #define ARG_COMPAT_LONG 0x0800 /* accept -foo but substitute with --foo */ | 304 #define ARG_COMPAT_LONG 0x0800 // accept -foo but substitute with --foo |
305 #define ARG_KEEP 0x1000 /* don't remove argument from argv[] */ | 305 #define ARG_KEEP 0x1000 // don't remove argument from argv[] |
306 | 306 |
307 /* | 307 /* |
308 * This table holds all the X GUI command line options allowed. This includes | 308 * This table holds all the X GUI command line options allowed. This includes |
309 * the standard ones so that we can skip them when Vim is started without the | 309 * the standard ones so that we can skip them when Vim is started without the |
310 * GUI (but the GUI might start up later). | 310 * GUI (but the GUI might start up later). |
318 } | 318 } |
319 cmdline_option_T; | 319 cmdline_option_T; |
320 | 320 |
321 static const cmdline_option_T cmdline_options[] = | 321 static const cmdline_option_T cmdline_options[] = |
322 { | 322 { |
323 /* We handle these options ourselves */ | 323 // We handle these options ourselves |
324 {"-fn", ARG_FONT|ARG_HAS_VALUE}, | 324 {"-fn", ARG_FONT|ARG_HAS_VALUE}, |
325 {"-font", ARG_FONT|ARG_HAS_VALUE}, | 325 {"-font", ARG_FONT|ARG_HAS_VALUE}, |
326 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, | 326 {"-geom", ARG_GEOMETRY|ARG_HAS_VALUE}, |
327 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, | 327 {"-geometry", ARG_GEOMETRY|ARG_HAS_VALUE}, |
328 {"-rv", ARG_REVERSE}, | 328 {"-rv", ARG_REVERSE}, |
334 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, | 334 {"-fg", ARG_FOREGROUND|ARG_HAS_VALUE}, |
335 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, | 335 {"-foreground", ARG_FOREGROUND|ARG_HAS_VALUE}, |
336 {"-iconic", ARG_ICONIC}, | 336 {"-iconic", ARG_ICONIC}, |
337 {"--role", ARG_ROLE|ARG_HAS_VALUE}, | 337 {"--role", ARG_ROLE|ARG_HAS_VALUE}, |
338 #ifdef FEAT_NETBEANS_INTG | 338 #ifdef FEAT_NETBEANS_INTG |
339 {"-nb", ARG_NETBEANS}, /* non-standard value format */ | 339 {"-nb", ARG_NETBEANS}, // non-standard value format |
340 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, /* not implemented */ | 340 {"-xrm", ARG_XRM|ARG_HAS_VALUE}, // not implemented |
341 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | 341 {"-mf", ARG_MENUFONT|ARG_HAS_VALUE}, // not implemented |
342 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, /* not implemented */ | 342 {"-menufont", ARG_MENUFONT|ARG_HAS_VALUE}, // not implemented |
343 #endif | 343 #endif |
344 /* Arguments handled by GTK (and GNOME) internally. */ | 344 // Arguments handled by GTK (and GNOME) internally. |
345 {"--g-fatal-warnings", ARG_FOR_GTK}, | 345 {"--g-fatal-warnings", ARG_FOR_GTK}, |
346 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | 346 {"--gdk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, |
347 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | 347 {"--gdk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, |
348 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | 348 {"--gtk-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, |
349 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, | 349 {"--gtk-no-debug", ARG_FOR_GTK|ARG_HAS_VALUE}, |
367 {"--disable-sound", ARG_FOR_GTK}, | 367 {"--disable-sound", ARG_FOR_GTK}, |
368 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, | 368 {"--espeaker", ARG_FOR_GTK|ARG_HAS_VALUE}, |
369 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, | 369 {"-?", ARG_FOR_GTK|ARG_NEEDS_GUI}, |
370 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, | 370 {"--help", ARG_FOR_GTK|ARG_NEEDS_GUI|ARG_KEEP}, |
371 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, | 371 {"--usage", ARG_FOR_GTK|ARG_NEEDS_GUI}, |
372 # if 0 /* conflicts with Vim's own --version argument */ | 372 # if 0 // conflicts with Vim's own --version argument |
373 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, | 373 {"--version", ARG_FOR_GTK|ARG_NEEDS_GUI}, |
374 # endif | 374 # endif |
375 {"--disable-crash-dialog", ARG_FOR_GTK}, | 375 {"--disable-crash-dialog", ARG_FOR_GTK}, |
376 #endif | 376 #endif |
377 {NULL, 0} | 377 {NULL, 0} |
439 | 439 |
440 gui_argv[gui_argc++] = argv[i++]; | 440 gui_argv[gui_argc++] = argv[i++]; |
441 | 441 |
442 while (i < *argc) | 442 while (i < *argc) |
443 { | 443 { |
444 /* Don't waste CPU cycles on non-option arguments. */ | 444 // Don't waste CPU cycles on non-option arguments. |
445 if (argv[i][0] != '-' && argv[i][0] != '+') | 445 if (argv[i][0] != '-' && argv[i][0] != '+') |
446 { | 446 { |
447 ++i; | 447 ++i; |
448 continue; | 448 continue; |
449 } | 449 } |
450 | 450 |
451 /* Look for argv[i] in cmdline_options[] table. */ | 451 // Look for argv[i] in cmdline_options[] table. |
452 for (option = &cmdline_options[0]; option->name != NULL; ++option) | 452 for (option = &cmdline_options[0]; option->name != NULL; ++option) |
453 { | 453 { |
454 len = strlen(option->name); | 454 len = strlen(option->name); |
455 | 455 |
456 if (strncmp(argv[i], option->name, len) == 0) | 456 if (strncmp(argv[i], option->name, len) == 0) |
457 { | 457 { |
458 if (argv[i][len] == '\0') | 458 if (argv[i][len] == '\0') |
459 break; | 459 break; |
460 /* allow --foo=bar style */ | 460 // allow --foo=bar style |
461 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) | 461 if (argv[i][len] == '=' && (option->flags & ARG_HAS_VALUE)) |
462 break; | 462 break; |
463 #ifdef FEAT_NETBEANS_INTG | 463 #ifdef FEAT_NETBEANS_INTG |
464 /* darn, -nb has non-standard syntax */ | 464 // darn, -nb has non-standard syntax |
465 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL | 465 if (vim_strchr((char_u *)":=", argv[i][len]) != NULL |
466 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) | 466 && (option->flags & ARG_INDEX_MASK) == ARG_NETBEANS) |
467 break; | 467 break; |
468 #endif | 468 #endif |
469 } | 469 } |
470 else if ((option->flags & ARG_COMPAT_LONG) | 470 else if ((option->flags & ARG_COMPAT_LONG) |
471 && strcmp(argv[i], option->name + 1) == 0) | 471 && strcmp(argv[i], option->name + 1) == 0) |
472 { | 472 { |
473 /* Replace the standard X arguments "-name" and "-display" | 473 // Replace the standard X arguments "-name" and "-display" |
474 * with their GNU-style long option counterparts. */ | 474 // with their GNU-style long option counterparts. |
475 argv[i] = (char *)option->name; | 475 argv[i] = (char *)option->name; |
476 break; | 476 break; |
477 } | 477 } |
478 } | 478 } |
479 if (option->name == NULL) /* no match */ | 479 if (option->name == NULL) // no match |
480 { | 480 { |
481 ++i; | 481 ++i; |
482 continue; | 482 continue; |
483 } | 483 } |
484 | 484 |
485 if (option->flags & ARG_FOR_GTK) | 485 if (option->flags & ARG_FOR_GTK) |
486 { | 486 { |
487 /* Move the argument into gui_argv, which | 487 // Move the argument into gui_argv, which |
488 * will later be passed to gtk_init_check() */ | 488 // will later be passed to gtk_init_check() |
489 gui_argv[gui_argc++] = argv[i]; | 489 gui_argv[gui_argc++] = argv[i]; |
490 } | 490 } |
491 else | 491 else |
492 { | 492 { |
493 char *value = NULL; | 493 char *value = NULL; |
494 | 494 |
495 /* Extract the option's value if there is one. | 495 // Extract the option's value if there is one. |
496 * Accept both "--foo bar" and "--foo=bar" style. */ | 496 // Accept both "--foo bar" and "--foo=bar" style. |
497 if (option->flags & ARG_HAS_VALUE) | 497 if (option->flags & ARG_HAS_VALUE) |
498 { | 498 { |
499 if (argv[i][len] == '=') | 499 if (argv[i][len] == '=') |
500 value = &argv[i][len + 1]; | 500 value = &argv[i][len + 1]; |
501 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) | 501 else if (i + 1 < *argc && strcmp(argv[i + 1], "--") != 0) |
502 value = argv[i + 1]; | 502 value = argv[i + 1]; |
503 } | 503 } |
504 | 504 |
505 /* Check for options handled by Vim itself */ | 505 // Check for options handled by Vim itself |
506 switch (option->flags & ARG_INDEX_MASK) | 506 switch (option->flags & ARG_INDEX_MASK) |
507 { | 507 { |
508 case ARG_REVERSE: | 508 case ARG_REVERSE: |
509 found_reverse_arg = TRUE; | 509 found_reverse_arg = TRUE; |
510 break; | 510 break; |
526 break; | 526 break; |
527 case ARG_ICONIC: | 527 case ARG_ICONIC: |
528 found_iconic_arg = TRUE; | 528 found_iconic_arg = TRUE; |
529 break; | 529 break; |
530 case ARG_ROLE: | 530 case ARG_ROLE: |
531 role_argument = value; /* used later in gui_mch_open() */ | 531 role_argument = value; // used later in gui_mch_open() |
532 break; | 532 break; |
533 #ifdef FEAT_NETBEANS_INTG | 533 #ifdef FEAT_NETBEANS_INTG |
534 case ARG_NETBEANS: | 534 case ARG_NETBEANS: |
535 gui.dofork = FALSE; /* don't fork() when starting GUI */ | 535 gui.dofork = FALSE; // don't fork() when starting GUI |
536 netbeansArg = argv[i]; | 536 netbeansArg = argv[i]; |
537 break; | 537 break; |
538 #endif | 538 #endif |
539 default: | 539 default: |
540 break; | 540 break; |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 /* These arguments make gnome_program_init() print a message and exit. | 544 // These arguments make gnome_program_init() print a message and exit. |
545 * Must start the GUI for this, otherwise ":gui" will exit later! | 545 // Must start the GUI for this, otherwise ":gui" will exit later! |
546 * Only when the GUI can start. */ | 546 // Only when the GUI can start. |
547 if ((option->flags & ARG_NEEDS_GUI) | 547 if ((option->flags & ARG_NEEDS_GUI) |
548 && gui_mch_early_init_check(FALSE) == OK) | 548 && gui_mch_early_init_check(FALSE) == OK) |
549 gui.starting = TRUE; | 549 gui.starting = TRUE; |
550 | 550 |
551 if (option->flags & ARG_KEEP) | 551 if (option->flags & ARG_KEEP) |
552 ++i; | 552 ++i; |
553 else | 553 else |
554 { | 554 { |
555 /* Remove the flag from the argument vector. */ | 555 // Remove the flag from the argument vector. |
556 if (--*argc > i) | 556 if (--*argc > i) |
557 { | 557 { |
558 int n_strip = 1; | 558 int n_strip = 1; |
559 | 559 |
560 /* Move the argument's value as well, if there is one. */ | 560 // Move the argument's value as well, if there is one. |
561 if ((option->flags & ARG_HAS_VALUE) | 561 if ((option->flags & ARG_HAS_VALUE) |
562 && argv[i][len] != '=' | 562 && argv[i][len] != '=' |
563 && strcmp(argv[i + 1], "--") != 0) | 563 && strcmp(argv[i + 1], "--") != 0) |
564 { | 564 { |
565 ++n_strip; | 565 ++n_strip; |
610 if (gui.text_gc != NULL) | 610 if (gui.text_gc != NULL) |
611 gdk_gc_set_exposures(gui.text_gc, | 611 gdk_gc_set_exposures(gui.text_gc, |
612 gui.visibility != GDK_VISIBILITY_UNOBSCURED); | 612 gui.visibility != GDK_VISIBILITY_UNOBSCURED); |
613 return FALSE; | 613 return FALSE; |
614 } | 614 } |
615 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 615 #endif // !GTK_CHECK_VERSION(3,0,0) |
616 | 616 |
617 /* | 617 /* |
618 * Redraw the corresponding portions of the screen. | 618 * Redraw the corresponding portions of the screen. |
619 */ | 619 */ |
620 #if GTK_CHECK_VERSION(3,0,0) | 620 #if GTK_CHECK_VERSION(3,0,0) |
624 static gboolean gui_gtk_is_blink_on(void); | 624 static gboolean gui_gtk_is_blink_on(void); |
625 | 625 |
626 static void | 626 static void |
627 gui_gtk3_redraw(int x, int y, int width, int height) | 627 gui_gtk3_redraw(int x, int y, int width, int height) |
628 { | 628 { |
629 /* Range checks are left to gui_redraw_block() */ | 629 // Range checks are left to gui_redraw_block() |
630 gui_redraw_block(Y_2_ROW(y), X_2_COL(x), | 630 gui_redraw_block(Y_2_ROW(y), X_2_COL(x), |
631 Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), | 631 Y_2_ROW(y + height - 1), X_2_COL(x + width - 1), |
632 GUI_MON_NOCLEAR); | 632 GUI_MON_NOCLEAR); |
633 } | 633 } |
634 | 634 |
661 static gboolean | 661 static gboolean |
662 draw_event(GtkWidget *widget UNUSED, | 662 draw_event(GtkWidget *widget UNUSED, |
663 cairo_t *cr, | 663 cairo_t *cr, |
664 gpointer user_data UNUSED) | 664 gpointer user_data UNUSED) |
665 { | 665 { |
666 /* Skip this when the GUI isn't set up yet, will redraw later. */ | 666 // Skip this when the GUI isn't set up yet, will redraw later. |
667 if (gui.starting) | 667 if (gui.starting) |
668 return FALSE; | 668 return FALSE; |
669 | 669 |
670 out_flush(); /* make sure all output has been processed */ | 670 out_flush(); // make sure all output has been processed |
671 /* for GTK+ 3, may induce other draw events. */ | 671 // for GTK+ 3, may induce other draw events. |
672 | 672 |
673 cairo_set_source_surface(cr, gui.surface, 0, 0); | 673 cairo_set_source_surface(cr, gui.surface, 0, 0); |
674 | 674 |
675 /* Draw the window without the cursor. */ | 675 // Draw the window without the cursor. |
676 gui.by_signal = TRUE; | 676 gui.by_signal = TRUE; |
677 { | 677 { |
678 cairo_rectangle_list_t *list = NULL; | 678 cairo_rectangle_list_t *list = NULL; |
679 | 679 |
680 list = cairo_copy_clip_rectangle_list(cr); | 680 list = cairo_copy_clip_rectangle_list(cr); |
681 if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) | 681 if (list->status != CAIRO_STATUS_CLIP_NOT_REPRESENTABLE) |
682 { | 682 { |
683 int i; | 683 int i; |
684 | 684 |
685 /* First clear all the blocks and then redraw them. Just in case | 685 // First clear all the blocks and then redraw them. Just in case |
686 * some blocks overlap. */ | 686 // some blocks overlap. |
687 for (i = 0; i < list->num_rectangles; i++) | 687 for (i = 0; i < list->num_rectangles; i++) |
688 { | 688 { |
689 const cairo_rectangle_t rect = list->rectangles[i]; | 689 const cairo_rectangle_t rect = list->rectangles[i]; |
690 | 690 |
691 gui_mch_clear_block(Y_2_ROW((int)rect.y), 0, | 691 gui_mch_clear_block(Y_2_ROW((int)rect.y), 0, |
718 | 718 |
719 cairo_paint(cr); | 719 cairo_paint(cr); |
720 } | 720 } |
721 gui.by_signal = FALSE; | 721 gui.by_signal = FALSE; |
722 | 722 |
723 /* Add the cursor to the window if necessary.*/ | 723 // Add the cursor to the window if necessary. |
724 if (gui_gtk3_should_draw_cursor() && blink_mode) | 724 if (gui_gtk3_should_draw_cursor() && blink_mode) |
725 gui_gtk3_update_cursor(cr); | 725 gui_gtk3_update_cursor(cr); |
726 | 726 |
727 return FALSE; | 727 return FALSE; |
728 } | 728 } |
729 #else /* !GTK_CHECK_VERSION(3,0,0) */ | 729 #else // !GTK_CHECK_VERSION(3,0,0) |
730 static gint | 730 static gint |
731 expose_event(GtkWidget *widget UNUSED, | 731 expose_event(GtkWidget *widget UNUSED, |
732 GdkEventExpose *event, | 732 GdkEventExpose *event, |
733 gpointer data UNUSED) | 733 gpointer data UNUSED) |
734 { | 734 { |
735 /* Skip this when the GUI isn't set up yet, will redraw later. */ | 735 // Skip this when the GUI isn't set up yet, will redraw later. |
736 if (gui.starting) | 736 if (gui.starting) |
737 return FALSE; | 737 return FALSE; |
738 | 738 |
739 out_flush(); /* make sure all output has been processed */ | 739 out_flush(); // make sure all output has been processed |
740 gui_redraw(event->area.x, event->area.y, | 740 gui_redraw(event->area.x, event->area.y, |
741 event->area.width, event->area.height); | 741 event->area.width, event->area.height); |
742 | 742 |
743 /* Clear the border areas if needed */ | 743 // Clear the border areas if needed |
744 if (event->area.x < FILL_X(0)) | 744 if (event->area.x < FILL_X(0)) |
745 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); | 745 gdk_window_clear_area(gui.drawarea->window, 0, 0, FILL_X(0), 0); |
746 if (event->area.y < FILL_Y(0)) | 746 if (event->area.y < FILL_Y(0)) |
747 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); | 747 gdk_window_clear_area(gui.drawarea->window, 0, 0, 0, FILL_Y(0)); |
748 if (event->area.x > FILL_X(Columns)) | 748 if (event->area.x > FILL_X(Columns)) |
751 if (event->area.y > FILL_Y(Rows)) | 751 if (event->area.y > FILL_Y(Rows)) |
752 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); | 752 gdk_window_clear_area(gui.drawarea->window, 0, FILL_Y((int)Rows), 0, 0); |
753 | 753 |
754 return FALSE; | 754 return FALSE; |
755 } | 755 } |
756 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 756 #endif // !GTK_CHECK_VERSION(3,0,0) |
757 | 757 |
758 #ifdef FEAT_CLIENTSERVER | 758 #ifdef FEAT_CLIENTSERVER |
759 /* | 759 /* |
760 * Handle changes to the "Comm" property | 760 * Handle changes to the "Comm" property |
761 */ | 761 */ |
769 && GDK_WINDOW_XID(event->window) == commWindow | 769 && GDK_WINDOW_XID(event->window) == commWindow |
770 && GET_X_ATOM(event->atom) == commProperty) | 770 && GET_X_ATOM(event->atom) == commProperty) |
771 { | 771 { |
772 XEvent xev; | 772 XEvent xev; |
773 | 773 |
774 /* Translate to XLib */ | 774 // Translate to XLib |
775 xev.xproperty.type = PropertyNotify; | 775 xev.xproperty.type = PropertyNotify; |
776 xev.xproperty.atom = commProperty; | 776 xev.xproperty.atom = commProperty; |
777 xev.xproperty.window = commWindow; | 777 xev.xproperty.window = commWindow; |
778 xev.xproperty.state = PropertyNewValue; | 778 xev.xproperty.state = PropertyNewValue; |
779 serverEventProc(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(widget)), | 779 serverEventProc(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(widget)), |
780 &xev, 0); | 780 &xev, 0); |
781 } | 781 } |
782 return FALSE; | 782 return FALSE; |
783 } | 783 } |
784 #endif /* defined(FEAT_CLIENTSERVER) */ | 784 #endif // defined(FEAT_CLIENTSERVER) |
785 | 785 |
786 /* | 786 /* |
787 * Handle changes to the "Xft/DPI" setting | 787 * Handle changes to the "Xft/DPI" setting |
788 */ | 788 */ |
789 static void | 789 static void |
824 { | 824 { |
825 g_source_remove(timer); | 825 g_source_remove(timer); |
826 } | 826 } |
827 | 827 |
828 | 828 |
829 /**************************************************************************** | 829 ///////////////////////////////////////////////////////////////////////////// |
830 * Focus handlers: | 830 // Focus handlers: |
831 */ | |
832 | 831 |
833 | 832 |
834 /* | 833 /* |
835 * This is a simple state machine: | 834 * This is a simple state machine: |
836 * BLINK_NONE not blinking at all | 835 * BLINK_NONE not blinking at all |
929 blink_state = BLINK_ON; | 928 blink_state = BLINK_ON; |
930 blink_timer = timeout_add(blink_ontime, blink_cb, NULL); | 929 blink_timer = timeout_add(blink_ontime, blink_cb, NULL); |
931 } | 930 } |
932 gui_mch_flush(); | 931 gui_mch_flush(); |
933 | 932 |
934 return FALSE; /* don't happen again */ | 933 return FALSE; // don't happen again |
935 } | 934 } |
936 | 935 |
937 /* | 936 /* |
938 * Start the cursor blinking. If it was already blinking, this restarts the | 937 * Start the cursor blinking. If it was already blinking, this restarts the |
939 * waiting time and shows the cursor. | 938 * waiting time and shows the cursor. |
944 if (blink_timer) | 943 if (blink_timer) |
945 { | 944 { |
946 timeout_remove(blink_timer); | 945 timeout_remove(blink_timer); |
947 blink_timer = 0; | 946 blink_timer = 0; |
948 } | 947 } |
949 /* Only switch blinking on if none of the times is zero */ | 948 // Only switch blinking on if none of the times is zero |
950 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) | 949 if (blink_waittime && blink_ontime && blink_offtime && gui.in_focus) |
951 { | 950 { |
952 blink_timer = timeout_add(blink_waittime, blink_cb, NULL); | 951 blink_timer = timeout_add(blink_waittime, blink_cb, NULL); |
953 blink_state = BLINK_ON; | 952 blink_state = BLINK_ON; |
954 gui_update_cursor(TRUE, FALSE); | 953 gui_update_cursor(TRUE, FALSE); |
962 gpointer data UNUSED) | 961 gpointer data UNUSED) |
963 { | 962 { |
964 if (blink_state == BLINK_NONE) | 963 if (blink_state == BLINK_NONE) |
965 gui_mch_start_blink(); | 964 gui_mch_start_blink(); |
966 | 965 |
967 /* make sure keyboard input goes there */ | 966 // make sure keyboard input goes there |
968 if (gtk_socket_id == 0 || !gtk_widget_has_focus(gui.drawarea)) | 967 if (gtk_socket_id == 0 || !gtk_widget_has_focus(gui.drawarea)) |
969 gtk_widget_grab_focus(gui.drawarea); | 968 gtk_widget_grab_focus(gui.drawarea); |
970 | 969 |
971 return FALSE; | 970 return FALSE; |
972 } | 971 } |
990 gui_focus_change(TRUE); | 989 gui_focus_change(TRUE); |
991 | 990 |
992 if (blink_state == BLINK_NONE) | 991 if (blink_state == BLINK_NONE) |
993 gui_mch_start_blink(); | 992 gui_mch_start_blink(); |
994 | 993 |
995 /* make sure keyboard input goes to the draw area (if this is focus for a | 994 // make sure keyboard input goes to the draw area (if this is focus for a |
996 * window) */ | 995 // window) |
997 if (widget != gui.drawarea) | 996 if (widget != gui.drawarea) |
998 gtk_widget_grab_focus(gui.drawarea); | 997 gtk_widget_grab_focus(gui.drawarea); |
999 | 998 |
1000 return TRUE; | 999 return TRUE; |
1001 } | 1000 } |
1030 guint32 uc; | 1029 guint32 uc; |
1031 | 1030 |
1032 uc = gdk_keyval_to_unicode(keyval); | 1031 uc = gdk_keyval_to_unicode(keyval); |
1033 if (uc != 0) | 1032 if (uc != 0) |
1034 { | 1033 { |
1035 /* Check for CTRL-foo */ | 1034 // Check for CTRL-foo |
1036 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | 1035 if ((state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) |
1037 { | 1036 { |
1038 /* These mappings look arbitrary at the first glance, but in fact | 1037 // These mappings look arbitrary at the first glance, but in fact |
1039 * resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | 1038 // resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my |
1040 * machine. The only difference is BS vs. DEL for CTRL-8 (makes | 1039 // machine. The only difference is BS vs. DEL for CTRL-8 (makes |
1041 * more sense and is consistent with usual terminal behaviour). */ | 1040 // more sense and is consistent with usual terminal behaviour). |
1042 if (uc >= '@') | 1041 if (uc >= '@') |
1043 string[0] = uc & 0x1F; | 1042 string[0] = uc & 0x1F; |
1044 else if (uc == '2') | 1043 else if (uc == '2') |
1045 string[0] = NUL; | 1044 string[0] = NUL; |
1046 else if (uc >= '3' && uc <= '7') | 1045 else if (uc >= '3' && uc <= '7') |
1053 string[0] = uc; | 1052 string[0] = uc; |
1054 len = 1; | 1053 len = 1; |
1055 } | 1054 } |
1056 else | 1055 else |
1057 { | 1056 { |
1058 /* Translate a normal key to UTF-8. This doesn't work for dead | 1057 // Translate a normal key to UTF-8. This doesn't work for dead |
1059 * keys of course, you _have_ to use an input method for that. */ | 1058 // keys of course, you _have_ to use an input method for that. |
1060 len = utf_char2bytes((int)uc, string); | 1059 len = utf_char2bytes((int)uc, string); |
1061 } | 1060 } |
1062 } | 1061 } |
1063 else | 1062 else |
1064 { | 1063 { |
1065 /* Translate keys which are represented by ASCII control codes in Vim. | 1064 // Translate keys which are represented by ASCII control codes in Vim. |
1066 * There are only a few of those; most control keys are translated to | 1065 // There are only a few of those; most control keys are translated to |
1067 * special terminal-like control sequences. */ | 1066 // special terminal-like control sequences. |
1068 len = 1; | 1067 len = 1; |
1069 switch (keyval) | 1068 switch (keyval) |
1070 { | 1069 { |
1071 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: | 1070 case GDK_Tab: case GDK_KP_Tab: case GDK_ISO_Left_Tab: |
1072 string[0] = TAB; | 1071 string[0] = TAB; |
1132 static gint | 1131 static gint |
1133 key_press_event(GtkWidget *widget UNUSED, | 1132 key_press_event(GtkWidget *widget UNUSED, |
1134 GdkEventKey *event, | 1133 GdkEventKey *event, |
1135 gpointer data UNUSED) | 1134 gpointer data UNUSED) |
1136 { | 1135 { |
1137 /* For GTK+ 2 we know for sure how large the string might get. | 1136 // For GTK+ 2 we know for sure how large the string might get. |
1138 * (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) */ | 1137 // (That is, up to 6 bytes + NUL + CSI escapes + safety measure.) |
1139 char_u string[32], string2[32]; | 1138 char_u string[32], string2[32]; |
1140 guint key_sym; | 1139 guint key_sym; |
1141 int len; | 1140 int len; |
1142 int i; | 1141 int i; |
1143 int modifiers; | 1142 int modifiers; |
1170 else | 1169 else |
1171 #endif | 1170 #endif |
1172 { | 1171 { |
1173 len = keyval_to_string(key_sym, state, string2); | 1172 len = keyval_to_string(key_sym, state, string2); |
1174 | 1173 |
1175 /* Careful: convert_input() doesn't handle the NUL character. | 1174 // Careful: convert_input() doesn't handle the NUL character. |
1176 * No need to convert pure ASCII anyway, thus the len > 1 check. */ | 1175 // No need to convert pure ASCII anyway, thus the len > 1 check. |
1177 if (len > 1 && input_conv.vc_type != CONV_NONE) | 1176 if (len > 1 && input_conv.vc_type != CONV_NONE) |
1178 len = convert_input(string2, len, sizeof(string2)); | 1177 len = convert_input(string2, len, sizeof(string2)); |
1179 | 1178 |
1180 s = string2; | 1179 s = string2; |
1181 d = string; | 1180 d = string; |
1182 for (i = 0; i < len; ++i) | 1181 for (i = 0; i < len; ++i) |
1183 { | 1182 { |
1184 *d++ = s[i]; | 1183 *d++ = s[i]; |
1185 if (d[-1] == CSI && d + 2 < string + sizeof(string)) | 1184 if (d[-1] == CSI && d + 2 < string + sizeof(string)) |
1186 { | 1185 { |
1187 /* Turn CSI into K_CSI. */ | 1186 // Turn CSI into K_CSI. |
1188 *d++ = KS_EXTRA; | 1187 *d++ = KS_EXTRA; |
1189 *d++ = (int)KE_CSI; | 1188 *d++ = (int)KE_CSI; |
1190 } | 1189 } |
1191 } | 1190 } |
1192 len = d - string; | 1191 len = d - string; |
1193 } | 1192 } |
1194 | 1193 |
1195 /* Shift-Tab results in Left_Tab, but we want <S-Tab> */ | 1194 // Shift-Tab results in Left_Tab, but we want <S-Tab> |
1196 if (key_sym == GDK_ISO_Left_Tab) | 1195 if (key_sym == GDK_ISO_Left_Tab) |
1197 { | 1196 { |
1198 key_sym = GDK_Tab; | 1197 key_sym = GDK_Tab; |
1199 state |= GDK_SHIFT_MASK; | 1198 state |= GDK_SHIFT_MASK; |
1200 } | 1199 } |
1201 | 1200 |
1202 #ifdef FEAT_MENU | 1201 #ifdef FEAT_MENU |
1203 /* If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key | 1202 // If there is a menu and 'wak' is "yes", or 'wak' is "menu" and the key |
1204 * is a menu shortcut, we ignore everything with the ALT modifier. */ | 1203 // is a menu shortcut, we ignore everything with the ALT modifier. |
1205 if ((state & GDK_MOD1_MASK) | 1204 if ((state & GDK_MOD1_MASK) |
1206 && gui.menu_is_active | 1205 && gui.menu_is_active |
1207 && (*p_wak == 'y' | 1206 && (*p_wak == 'y' |
1208 || (*p_wak == 'm' | 1207 || (*p_wak == 'm' |
1209 && len == 1 | 1208 && len == 1 |
1210 && gui_is_menu_shortcut(string[0])))) | 1209 && gui_is_menu_shortcut(string[0])))) |
1211 /* For GTK2 we return false to signify that we haven't handled the | 1210 // For GTK2 we return false to signify that we haven't handled the |
1212 * keypress, so that gtk will handle the mnemonic or accelerator. */ | 1211 // keypress, so that gtk will handle the mnemonic or accelerator. |
1213 return FALSE; | 1212 return FALSE; |
1214 #endif | 1213 #endif |
1215 | 1214 |
1216 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character | 1215 // Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character |
1217 * that already has the 8th bit set. | 1216 // that already has the 8th bit set. |
1218 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. | 1217 // Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. |
1219 * Don't do this for double-byte encodings, it turns the char into a lead | 1218 // Don't do this for double-byte encodings, it turns the char into a lead |
1220 * byte. */ | 1219 // byte. |
1221 if (len == 1 | 1220 if (len == 1 |
1222 && ((state & GDK_MOD1_MASK) | 1221 && ((state & GDK_MOD1_MASK) |
1223 #if GTK_CHECK_VERSION(2,10,0) | 1222 #if GTK_CHECK_VERSION(2,10,0) |
1224 || (state & GDK_SUPER_MASK) | 1223 || (state & GDK_SUPER_MASK) |
1225 #endif | 1224 #endif |
1229 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) | 1228 && !(key_sym == GDK_Tab && (state & GDK_SHIFT_MASK)) |
1230 && !enc_dbcs | 1229 && !enc_dbcs |
1231 ) | 1230 ) |
1232 { | 1231 { |
1233 string[0] |= 0x80; | 1232 string[0] |= 0x80; |
1234 state &= ~GDK_MOD1_MASK; /* don't use it again */ | 1233 state &= ~GDK_MOD1_MASK; // don't use it again |
1235 if (enc_utf8) /* convert to utf-8 */ | 1234 if (enc_utf8) // convert to utf-8 |
1236 { | 1235 { |
1237 string[1] = string[0] & 0xbf; | 1236 string[1] = string[0] & 0xbf; |
1238 string[0] = ((unsigned)string[0] >> 6) + 0xc0; | 1237 string[0] = ((unsigned)string[0] >> 6) + 0xc0; |
1239 if (string[1] == CSI) | 1238 if (string[1] == CSI) |
1240 { | 1239 { |
1245 else | 1244 else |
1246 len = 2; | 1245 len = 2; |
1247 } | 1246 } |
1248 } | 1247 } |
1249 | 1248 |
1250 /* Check for special keys. Also do this when len == 1 (key has an ASCII | 1249 // Check for special keys. Also do this when len == 1 (key has an ASCII |
1251 * value) to detect backspace, delete and keypad keys. */ | 1250 // value) to detect backspace, delete and keypad keys. |
1252 if (len == 0 || len == 1) | 1251 if (len == 0 || len == 1) |
1253 { | 1252 { |
1254 for (i = 0; special_keys[i].key_sym != 0; i++) | 1253 for (i = 0; special_keys[i].key_sym != 0; i++) |
1255 { | 1254 { |
1256 if (special_keys[i].key_sym == key_sym) | 1255 if (special_keys[i].key_sym == key_sym) |
1262 break; | 1261 break; |
1263 } | 1262 } |
1264 } | 1263 } |
1265 } | 1264 } |
1266 | 1265 |
1267 if (len == 0) /* Unrecognized key */ | 1266 if (len == 0) // Unrecognized key |
1268 return TRUE; | 1267 return TRUE; |
1269 | 1268 |
1270 /* Special keys (and a few others) may have modifiers. Also when using a | 1269 // Special keys (and a few others) may have modifiers. Also when using a |
1271 * double-byte encoding (can't set the 8th bit). */ | 1270 // double-byte encoding (can't set the 8th bit). |
1272 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab | 1271 if (len == -3 || key_sym == GDK_space || key_sym == GDK_Tab |
1273 || key_sym == GDK_Return || key_sym == GDK_Linefeed | 1272 || key_sym == GDK_Return || key_sym == GDK_Linefeed |
1274 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab | 1273 || key_sym == GDK_Escape || key_sym == GDK_KP_Tab |
1275 || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter | 1274 || key_sym == GDK_ISO_Enter || key_sym == GDK_3270_Enter |
1276 || (enc_dbcs && len == 1 && ((state & GDK_MOD1_MASK) | 1275 || (enc_dbcs && len == 1 && ((state & GDK_MOD1_MASK) |
1322 got_int = TRUE; | 1321 got_int = TRUE; |
1323 } | 1322 } |
1324 | 1323 |
1325 add_to_input_buf(string, len); | 1324 add_to_input_buf(string, len); |
1326 | 1325 |
1327 /* blank out the pointer if necessary */ | 1326 // blank out the pointer if necessary |
1328 if (p_mh) | 1327 if (p_mh) |
1329 gui_mch_mousehide(TRUE); | 1328 gui_mch_mousehide(TRUE); |
1330 | 1329 |
1331 return TRUE; | 1330 return TRUE; |
1332 } | 1331 } |
1354 # endif | 1353 # endif |
1355 } | 1354 } |
1356 #endif | 1355 #endif |
1357 | 1356 |
1358 | 1357 |
1359 /**************************************************************************** | 1358 ///////////////////////////////////////////////////////////////////////////// |
1360 * Selection handlers: | 1359 // Selection handlers: |
1361 */ | 1360 |
1362 | 1361 // Remember when clip_lose_selection was called from here, we must not call |
1363 /* Remember when clip_lose_selection was called from here, we must not call | 1362 // gtk_selection_owner_set() then. |
1364 * gtk_selection_owner_set() then. */ | |
1365 static int in_selection_clear_event = FALSE; | 1363 static int in_selection_clear_event = FALSE; |
1366 | 1364 |
1367 static gint | 1365 static gint |
1368 selection_clear_event(GtkWidget *widget UNUSED, | 1366 selection_clear_event(GtkWidget *widget UNUSED, |
1369 GdkEventSelection *event, | 1367 GdkEventSelection *event, |
1377 in_selection_clear_event = FALSE; | 1375 in_selection_clear_event = FALSE; |
1378 | 1376 |
1379 return TRUE; | 1377 return TRUE; |
1380 } | 1378 } |
1381 | 1379 |
1382 #define RS_NONE 0 /* selection_received_cb() not called yet */ | 1380 #define RS_NONE 0 // selection_received_cb() not called yet |
1383 #define RS_OK 1 /* selection_received_cb() called and OK */ | 1381 #define RS_OK 1 // selection_received_cb() called and OK |
1384 #define RS_FAIL 2 /* selection_received_cb() called and failed */ | 1382 #define RS_FAIL 2 // selection_received_cb() called and failed |
1385 static int received_selection = RS_NONE; | 1383 static int received_selection = RS_NONE; |
1386 | 1384 |
1387 static void | 1385 static void |
1388 selection_received_cb(GtkWidget *widget UNUSED, | 1386 selection_received_cb(GtkWidget *widget UNUSED, |
1389 GtkSelectionData *data, | 1387 GtkSelectionData *data, |
1406 len = gtk_selection_data_get_length(data); | 1404 len = gtk_selection_data_get_length(data); |
1407 | 1405 |
1408 if (text == NULL || len <= 0) | 1406 if (text == NULL || len <= 0) |
1409 { | 1407 { |
1410 received_selection = RS_FAIL; | 1408 received_selection = RS_FAIL; |
1411 /* clip_free_selection(cbd); ??? */ | 1409 // clip_free_selection(cbd); ??? |
1412 | 1410 |
1413 return; | 1411 return; |
1414 } | 1412 } |
1415 | 1413 |
1416 if (gtk_selection_data_get_data_type(data) == vim_atom) | 1414 if (gtk_selection_data_get_data_type(data) == vim_atom) |
1428 | 1426 |
1429 enc = text; | 1427 enc = text; |
1430 text += STRLEN(text) + 1; | 1428 text += STRLEN(text) + 1; |
1431 len -= text - enc; | 1429 len -= text - enc; |
1432 | 1430 |
1433 /* If the encoding of the text is different from 'encoding', attempt | 1431 // If the encoding of the text is different from 'encoding', attempt |
1434 * converting it. */ | 1432 // converting it. |
1435 conv.vc_type = CONV_NONE; | 1433 conv.vc_type = CONV_NONE; |
1436 convert_setup(&conv, enc, p_enc); | 1434 convert_setup(&conv, enc, p_enc); |
1437 if (conv.vc_type != CONV_NONE) | 1435 if (conv.vc_type != CONV_NONE) |
1438 { | 1436 { |
1439 tmpbuf = string_convert(&conv, text, &len); | 1437 tmpbuf = string_convert(&conv, text, &len); |
1441 text = tmpbuf; | 1439 text = tmpbuf; |
1442 convert_setup(&conv, NULL, NULL); | 1440 convert_setup(&conv, NULL, NULL); |
1443 } | 1441 } |
1444 } | 1442 } |
1445 | 1443 |
1446 /* gtk_selection_data_get_text() handles all the nasty details | 1444 // gtk_selection_data_get_text() handles all the nasty details |
1447 * and targets and encodings etc. This rocks so hard. */ | 1445 // and targets and encodings etc. This rocks so hard. |
1448 else | 1446 else |
1449 { | 1447 { |
1450 tmpbuf_utf8 = gtk_selection_data_get_text(data); | 1448 tmpbuf_utf8 = gtk_selection_data_get_text(data); |
1451 if (tmpbuf_utf8 != NULL) | 1449 if (tmpbuf_utf8 != NULL) |
1452 { | 1450 { |
1462 } | 1460 } |
1463 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) | 1461 else if (len >= 2 && text[0] == 0xff && text[1] == 0xfe) |
1464 { | 1462 { |
1465 vimconv_T conv; | 1463 vimconv_T conv; |
1466 | 1464 |
1467 /* UTF-16, we get this for HTML */ | 1465 // UTF-16, we get this for HTML |
1468 conv.vc_type = CONV_NONE; | 1466 conv.vc_type = CONV_NONE; |
1469 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); | 1467 convert_setup_ext(&conv, (char_u *)"utf-16le", FALSE, p_enc, TRUE); |
1470 | 1468 |
1471 if (conv.vc_type != CONV_NONE) | 1469 if (conv.vc_type != CONV_NONE) |
1472 { | 1470 { |
1478 if (tmpbuf != NULL) | 1476 if (tmpbuf != NULL) |
1479 text = tmpbuf; | 1477 text = tmpbuf; |
1480 } | 1478 } |
1481 } | 1479 } |
1482 | 1480 |
1483 /* Chop off any trailing NUL bytes. OpenOffice sends these. */ | 1481 // Chop off any trailing NUL bytes. OpenOffice sends these. |
1484 while (len > 0 && text[len - 1] == NUL) | 1482 while (len > 0 && text[len - 1] == NUL) |
1485 --len; | 1483 --len; |
1486 | 1484 |
1487 clip_yank_selection(motion_type, text, (long)len, cbd); | 1485 clip_yank_selection(motion_type, text, (long)len, cbd); |
1488 received_selection = RS_OK; | 1486 received_selection = RS_OK; |
1514 cbd = &clip_plus; | 1512 cbd = &clip_plus; |
1515 else | 1513 else |
1516 cbd = &clip_star; | 1514 cbd = &clip_star; |
1517 | 1515 |
1518 if (!cbd->owned) | 1516 if (!cbd->owned) |
1519 return; /* Shouldn't ever happen */ | 1517 return; // Shouldn't ever happen |
1520 | 1518 |
1521 if (info != (guint)TARGET_STRING | 1519 if (info != (guint)TARGET_STRING |
1522 && (!clip_html || info != (guint)TARGET_HTML) | 1520 && (!clip_html || info != (guint)TARGET_HTML) |
1523 && info != (guint)TARGET_UTF8_STRING | 1521 && info != (guint)TARGET_UTF8_STRING |
1524 && info != (guint)TARGET_VIMENC | 1522 && info != (guint)TARGET_VIMENC |
1525 && info != (guint)TARGET_VIM | 1523 && info != (guint)TARGET_VIM |
1526 && info != (guint)TARGET_COMPOUND_TEXT | 1524 && info != (guint)TARGET_COMPOUND_TEXT |
1527 && info != (guint)TARGET_TEXT) | 1525 && info != (guint)TARGET_TEXT) |
1528 return; | 1526 return; |
1529 | 1527 |
1530 /* get the selection from the '*'/'+' register */ | 1528 // get the selection from the '*'/'+' register |
1531 clip_get_selection(cbd); | 1529 clip_get_selection(cbd); |
1532 | 1530 |
1533 motion_type = clip_convert_selection(&string, &tmplen, cbd); | 1531 motion_type = clip_convert_selection(&string, &tmplen, cbd); |
1534 if (motion_type < 0 || string == NULL) | 1532 if (motion_type < 0 || string == NULL) |
1535 return; | 1533 return; |
1536 /* Due to int arguments we can't handle more than G_MAXINT. Also | 1534 // Due to int arguments we can't handle more than G_MAXINT. Also |
1537 * reserve one extra byte for NUL or the motion type; just in case. | 1535 // reserve one extra byte for NUL or the motion type; just in case. |
1538 * (Not that pasting 2G of text is ever going to work, but... ;-) */ | 1536 // (Not that pasting 2G of text is ever going to work, but... ;-) |
1539 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); | 1537 length = MIN(tmplen, (long_u)(G_MAXINT - 1)); |
1540 | 1538 |
1541 if (info == (guint)TARGET_VIM) | 1539 if (info == (guint)TARGET_VIM) |
1542 { | 1540 { |
1543 tmpbuf = alloc(length + 1); | 1541 tmpbuf = alloc(length + 1); |
1544 if (tmpbuf != NULL) | 1542 if (tmpbuf != NULL) |
1545 { | 1543 { |
1546 tmpbuf[0] = motion_type; | 1544 tmpbuf[0] = motion_type; |
1547 mch_memmove(tmpbuf + 1, string, (size_t)length); | 1545 mch_memmove(tmpbuf + 1, string, (size_t)length); |
1548 } | 1546 } |
1549 /* For our own format, the first byte contains the motion type */ | 1547 // For our own format, the first byte contains the motion type |
1550 ++length; | 1548 ++length; |
1551 vim_free(string); | 1549 vim_free(string); |
1552 string = tmpbuf; | 1550 string = tmpbuf; |
1553 type = vim_atom; | 1551 type = vim_atom; |
1554 } | 1552 } |
1555 | 1553 |
1556 else if (info == (guint)TARGET_HTML) | 1554 else if (info == (guint)TARGET_HTML) |
1557 { | 1555 { |
1558 vimconv_T conv; | 1556 vimconv_T conv; |
1559 | 1557 |
1560 /* Since we get utf-16, we probably should set it as well. */ | 1558 // Since we get utf-16, we probably should set it as well. |
1561 conv.vc_type = CONV_NONE; | 1559 conv.vc_type = CONV_NONE; |
1562 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); | 1560 convert_setup_ext(&conv, p_enc, TRUE, (char_u *)"utf-16le", FALSE); |
1563 if (conv.vc_type != CONV_NONE) | 1561 if (conv.vc_type != CONV_NONE) |
1564 { | 1562 { |
1565 tmpbuf = string_convert(&conv, string, &length); | 1563 tmpbuf = string_convert(&conv, string, &length); |
1566 convert_setup(&conv, NULL, NULL); | 1564 convert_setup(&conv, NULL, NULL); |
1567 vim_free(string); | 1565 vim_free(string); |
1568 string = tmpbuf; | 1566 string = tmpbuf; |
1569 } | 1567 } |
1570 | 1568 |
1571 /* Prepend the BOM: "fffe" */ | 1569 // Prepend the BOM: "fffe" |
1572 if (string != NULL) | 1570 if (string != NULL) |
1573 { | 1571 { |
1574 tmpbuf = alloc(length + 2); | 1572 tmpbuf = alloc(length + 2); |
1575 if (tmpbuf != NULL) | 1573 if (tmpbuf != NULL) |
1576 { | 1574 { |
1581 string = tmpbuf; | 1579 string = tmpbuf; |
1582 length += 2; | 1580 length += 2; |
1583 } | 1581 } |
1584 | 1582 |
1585 #if !GTK_CHECK_VERSION(3,0,0) | 1583 #if !GTK_CHECK_VERSION(3,0,0) |
1586 /* Looks redundant even for GTK2 because these values are | 1584 // Looks redundant even for GTK2 because these values are |
1587 * overwritten by gtk_selection_data_set() that follows. */ | 1585 // overwritten by gtk_selection_data_set() that follows. |
1588 selection_data->type = selection_data->target; | 1586 selection_data->type = selection_data->target; |
1589 selection_data->format = 16; /* 16 bits per char */ | 1587 selection_data->format = 16; // 16 bits per char |
1590 #endif | 1588 #endif |
1591 gtk_selection_data_set(selection_data, html_atom, 16, | 1589 gtk_selection_data_set(selection_data, html_atom, 16, |
1592 string, length); | 1590 string, length); |
1593 vim_free(string); | 1591 vim_free(string); |
1594 } | 1592 } |
1596 } | 1594 } |
1597 else if (info == (guint)TARGET_VIMENC) | 1595 else if (info == (guint)TARGET_VIMENC) |
1598 { | 1596 { |
1599 int l = STRLEN(p_enc); | 1597 int l = STRLEN(p_enc); |
1600 | 1598 |
1601 /* contents: motion_type 'encoding' NUL text */ | 1599 // contents: motion_type 'encoding' NUL text |
1602 tmpbuf = alloc(length + l + 2); | 1600 tmpbuf = alloc(length + l + 2); |
1603 if (tmpbuf != NULL) | 1601 if (tmpbuf != NULL) |
1604 { | 1602 { |
1605 tmpbuf[0] = motion_type; | 1603 tmpbuf[0] = motion_type; |
1606 STRCPY(tmpbuf + 1, p_enc); | 1604 STRCPY(tmpbuf + 1, p_enc); |
1610 string = tmpbuf; | 1608 string = tmpbuf; |
1611 } | 1609 } |
1612 type = vimenc_atom; | 1610 type = vimenc_atom; |
1613 } | 1611 } |
1614 | 1612 |
1615 /* gtk_selection_data_set_text() handles everything for us. This is | 1613 // gtk_selection_data_set_text() handles everything for us. This is |
1616 * so easy and simple and cool, it'd be insane not to use it. */ | 1614 // so easy and simple and cool, it'd be insane not to use it. |
1617 else | 1615 else |
1618 { | 1616 { |
1619 if (output_conv.vc_type != CONV_NONE) | 1617 if (output_conv.vc_type != CONV_NONE) |
1620 { | 1618 { |
1621 tmpbuf = string_convert(&output_conv, string, &length); | 1619 tmpbuf = string_convert(&output_conv, string, &length); |
1622 vim_free(string); | 1620 vim_free(string); |
1623 if (tmpbuf == NULL) | 1621 if (tmpbuf == NULL) |
1624 return; | 1622 return; |
1625 string = tmpbuf; | 1623 string = tmpbuf; |
1626 } | 1624 } |
1627 /* Validate the string to avoid runtime warnings */ | 1625 // Validate the string to avoid runtime warnings |
1628 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) | 1626 if (g_utf8_validate((const char *)string, (gssize)length, NULL)) |
1629 { | 1627 { |
1630 gtk_selection_data_set_text(selection_data, | 1628 gtk_selection_data_set_text(selection_data, |
1631 (const char *)string, length); | 1629 (const char *)string, length); |
1632 } | 1630 } |
1635 } | 1633 } |
1636 | 1634 |
1637 if (string != NULL) | 1635 if (string != NULL) |
1638 { | 1636 { |
1639 #if !GTK_CHECK_VERSION(3,0,0) | 1637 #if !GTK_CHECK_VERSION(3,0,0) |
1640 /* Looks redundant even for GTK2 because these values are | 1638 // Looks redundant even for GTK2 because these values are |
1641 * overwritten by gtk_selection_data_set() that follows. */ | 1639 // overwritten by gtk_selection_data_set() that follows. |
1642 selection_data->type = selection_data->target; | 1640 selection_data->type = selection_data->target; |
1643 selection_data->format = 8; /* 8 bits per char */ | 1641 selection_data->format = 8; // 8 bits per char |
1644 #endif | 1642 #endif |
1645 gtk_selection_data_set(selection_data, type, 8, string, length); | 1643 gtk_selection_data_set(selection_data, type, 8, string, length); |
1646 vim_free(string); | 1644 vim_free(string); |
1647 } | 1645 } |
1648 } | 1646 } |
1655 int | 1653 int |
1656 gui_mch_early_init_check(int give_message) | 1654 gui_mch_early_init_check(int give_message) |
1657 { | 1655 { |
1658 char_u *p; | 1656 char_u *p; |
1659 | 1657 |
1660 /* Guess that when $DISPLAY isn't set the GUI can't start. */ | 1658 // Guess that when $DISPLAY isn't set the GUI can't start. |
1661 p = mch_getenv((char_u *)"DISPLAY"); | 1659 p = mch_getenv((char_u *)"DISPLAY"); |
1662 if (p == NULL || *p == NUL) | 1660 if (p == NULL || *p == NUL) |
1663 { | 1661 { |
1664 gui.dying = TRUE; | 1662 gui.dying = TRUE; |
1665 if (give_message) | 1663 if (give_message) |
1680 #ifdef USE_GRESOURCE | 1678 #ifdef USE_GRESOURCE |
1681 static int res_registered = FALSE; | 1679 static int res_registered = FALSE; |
1682 | 1680 |
1683 if (!res_registered) | 1681 if (!res_registered) |
1684 { | 1682 { |
1685 /* Call this function in the GUI process; otherwise, the resources | 1683 // Call this function in the GUI process; otherwise, the resources |
1686 * won't be available. Don't call it twice. */ | 1684 // won't be available. Don't call it twice. |
1687 res_registered = TRUE; | 1685 res_registered = TRUE; |
1688 gui_gtk_register_resource(); | 1686 gui_gtk_register_resource(); |
1689 } | 1687 } |
1690 #endif | 1688 #endif |
1691 | 1689 |
1692 #if GTK_CHECK_VERSION(3,10,0) | 1690 #if GTK_CHECK_VERSION(3,10,0) |
1693 /* Vim currently assumes that Gtk means X11, so it cannot use native Gtk | 1691 // Vim currently assumes that Gtk means X11, so it cannot use native Gtk |
1694 * support for other backends such as Wayland. */ | 1692 // support for other backends such as Wayland. |
1695 gdk_set_allowed_backends ("x11"); | 1693 gdk_set_allowed_backends ("x11"); |
1696 #endif | 1694 #endif |
1697 | 1695 |
1698 #ifdef FEAT_GUI_GNOME | 1696 #ifdef FEAT_GUI_GNOME |
1699 if (gtk_socket_id == 0) | 1697 if (gtk_socket_id == 0) |
1700 using_gnome = 1; | 1698 using_gnome = 1; |
1701 #endif | 1699 #endif |
1702 | 1700 |
1703 /* This defaults to argv[0], but we want it to match the name of the | 1701 // This defaults to argv[0], but we want it to match the name of the |
1704 * shipped gvim.desktop so that Vim's windows can be associated with this | 1702 // shipped gvim.desktop so that Vim's windows can be associated with this |
1705 * file. */ | 1703 // file. |
1706 g_set_prgname("gvim"); | 1704 g_set_prgname("gvim"); |
1707 | 1705 |
1708 /* Don't use gtk_init() or gnome_init(), it exits on failure. */ | 1706 // Don't use gtk_init() or gnome_init(), it exits on failure. |
1709 if (!gtk_init_check(&gui_argc, &gui_argv)) | 1707 if (!gtk_init_check(&gui_argc, &gui_argv)) |
1710 { | 1708 { |
1711 gui.dying = TRUE; | 1709 gui.dying = TRUE; |
1712 emsg(_((char *)e_opendisp)); | 1710 emsg(_((char *)e_opendisp)); |
1713 return FAIL; | 1711 return FAIL; |
1714 } | 1712 } |
1715 | 1713 |
1716 return OK; | 1714 return OK; |
1717 } | 1715 } |
1718 | 1716 |
1719 /**************************************************************************** | 1717 ///////////////////////////////////////////////////////////////////////////// |
1720 * Mouse handling callbacks | 1718 // Mouse handling callbacks |
1721 */ | |
1722 | 1719 |
1723 | 1720 |
1724 static guint mouse_click_timer = 0; | 1721 static guint mouse_click_timer = 0; |
1725 static int mouse_timed_out = TRUE; | 1722 static int mouse_timed_out = TRUE; |
1726 | 1723 |
1728 * Timer used to recognize multiple clicks of the mouse button | 1725 * Timer used to recognize multiple clicks of the mouse button |
1729 */ | 1726 */ |
1730 static timeout_cb_type | 1727 static timeout_cb_type |
1731 mouse_click_timer_cb(gpointer data) | 1728 mouse_click_timer_cb(gpointer data) |
1732 { | 1729 { |
1733 /* we don't use this information currently */ | 1730 // we don't use this information currently |
1734 int *timed_out = (int *) data; | 1731 int *timed_out = (int *) data; |
1735 | 1732 |
1736 *timed_out = TRUE; | 1733 *timed_out = TRUE; |
1737 return FALSE; /* don't happen again */ | 1734 return FALSE; // don't happen again |
1738 } | 1735 } |
1739 | 1736 |
1740 static guint motion_repeat_timer = 0; | 1737 static guint motion_repeat_timer = 0; |
1741 static int motion_repeat_offset = FALSE; | 1738 static int motion_repeat_offset = FALSE; |
1742 static timeout_cb_type motion_repeat_timer_cb(gpointer); | 1739 static timeout_cb_type motion_repeat_timer_cb(gpointer); |
1751 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | | 1748 button = (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | |
1752 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | | 1749 GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | |
1753 GDK_BUTTON5_MASK)) | 1750 GDK_BUTTON5_MASK)) |
1754 ? MOUSE_DRAG : ' '; | 1751 ? MOUSE_DRAG : ' '; |
1755 | 1752 |
1756 /* If our pointer is currently hidden, then we should show it. */ | 1753 // If our pointer is currently hidden, then we should show it. |
1757 gui_mch_mousehide(FALSE); | 1754 gui_mch_mousehide(FALSE); |
1758 | 1755 |
1759 /* Just moving the rodent above the drawing area without any button | 1756 // Just moving the rodent above the drawing area without any button |
1760 * being pressed. */ | 1757 // being pressed. |
1761 if (button != MOUSE_DRAG) | 1758 if (button != MOUSE_DRAG) |
1762 { | 1759 { |
1763 gui_mouse_moved(x, y); | 1760 gui_mouse_moved(x, y); |
1764 return; | 1761 return; |
1765 } | 1762 } |
1766 | 1763 |
1767 /* translate modifier coding between the main engine and GTK */ | 1764 // translate modifier coding between the main engine and GTK |
1768 vim_modifiers = modifiers_gdk2mouse(state); | 1765 vim_modifiers = modifiers_gdk2mouse(state); |
1769 | 1766 |
1770 /* inform the editor engine about the occurrence of this event */ | 1767 // inform the editor engine about the occurrence of this event |
1771 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); | 1768 gui_send_mouse_event(button, x, y, FALSE, vim_modifiers); |
1772 | 1769 |
1773 /* | 1770 /* |
1774 * Auto repeat timer handling. | 1771 * Auto repeat timer handling. |
1775 */ | 1772 */ |
1783 int dx; | 1780 int dx; |
1784 int dy; | 1781 int dy; |
1785 int offshoot; | 1782 int offshoot; |
1786 int delay = 10; | 1783 int delay = 10; |
1787 | 1784 |
1788 /* Calculate the maximal distance of the cursor from the drawing area. | 1785 // Calculate the maximal distance of the cursor from the drawing area. |
1789 * (offshoot can't become negative here!). | 1786 // (offshoot can't become negative here!). |
1790 */ | |
1791 dx = x < 0 ? -x : x - allocation.width; | 1787 dx = x < 0 ? -x : x - allocation.width; |
1792 dy = y < 0 ? -y : y - allocation.height; | 1788 dy = y < 0 ? -y : y - allocation.height; |
1793 | 1789 |
1794 offshoot = dx > dy ? dx : dy; | 1790 offshoot = dx > dy ? dx : dy; |
1795 | 1791 |
1796 /* Make a linearly decaying timer delay with a threshold of 5 at a | 1792 // Make a linearly decaying timer delay with a threshold of 5 at a |
1797 * distance of 127 pixels from the main window. | 1793 // distance of 127 pixels from the main window. |
1798 * | 1794 // |
1799 * One could think endlessly about the most ergonomic variant here. | 1795 // One could think endlessly about the most ergonomic variant here. |
1800 * For example it could make sense to calculate the distance from the | 1796 // For example it could make sense to calculate the distance from the |
1801 * drags start instead... | 1797 // drags start instead... |
1802 * | 1798 // |
1803 * Maybe a parabolic interpolation would suite us better here too... | 1799 // Maybe a parabolic interpolation would suite us better here too... |
1804 */ | |
1805 if (offshoot > 127) | 1800 if (offshoot > 127) |
1806 { | 1801 { |
1807 /* 5 appears to be somehow near to my perceptual limits :-). */ | 1802 // 5 appears to be somehow near to my perceptual limits :-). |
1808 delay = 5; | 1803 delay = 5; |
1809 } | 1804 } |
1810 else | 1805 else |
1811 { | 1806 { |
1812 delay = (130 * (127 - offshoot)) / 127 + 5; | 1807 delay = (130 * (127 - offshoot)) / 127 + 5; |
1813 } | 1808 } |
1814 | 1809 |
1815 /* shoot again */ | 1810 // shoot again |
1816 if (!motion_repeat_timer) | 1811 if (!motion_repeat_timer) |
1817 motion_repeat_timer = timeout_add(delay, motion_repeat_timer_cb, | 1812 motion_repeat_timer = timeout_add(delay, motion_repeat_timer_cb, |
1818 NULL); | 1813 NULL); |
1819 } | 1814 } |
1820 } | 1815 } |
1853 { | 1848 { |
1854 GdkDevice * const dev = gui_gtk_get_pointer_device(widget); | 1849 GdkDevice * const dev = gui_gtk_get_pointer_device(widget); |
1855 return gdk_device_get_window_at_position(dev, x, y); | 1850 return gdk_device_get_window_at_position(dev, x, y); |
1856 } | 1851 } |
1857 # endif | 1852 # endif |
1858 #else /* !GTK_CHECK_VERSION(3,0,0) */ | 1853 #else // !GTK_CHECK_VERSION(3,0,0) |
1859 # define gui_gtk_get_pointer(wid, x, y, s) \ | 1854 # define gui_gtk_get_pointer(wid, x, y, s) \ |
1860 gdk_window_get_pointer((wid)->window, x, y, s) | 1855 gdk_window_get_pointer((wid)->window, x, y, s) |
1861 # define gui_gtk_window_at_position(wid, x, y) gdk_window_at_pointer(x, y) | 1856 # define gui_gtk_window_at_position(wid, x, y) gdk_window_at_pointer(x, y) |
1862 #endif | 1857 #endif |
1863 | 1858 |
1879 { | 1874 { |
1880 motion_repeat_timer = 0; | 1875 motion_repeat_timer = 0; |
1881 return FALSE; | 1876 return FALSE; |
1882 } | 1877 } |
1883 | 1878 |
1884 /* If there already is a mouse click in the input buffer, wait another | 1879 // If there already is a mouse click in the input buffer, wait another |
1885 * time (otherwise we would create a backlog of clicks) */ | 1880 // time (otherwise we would create a backlog of clicks) |
1886 if (vim_used_in_input_buf() > 10) | 1881 if (vim_used_in_input_buf() > 10) |
1887 return TRUE; | 1882 return TRUE; |
1888 | 1883 |
1889 motion_repeat_timer = 0; | 1884 motion_repeat_timer = 0; |
1890 | 1885 |
1898 x += gui.char_width; | 1893 x += gui.char_width; |
1899 | 1894 |
1900 motion_repeat_offset = !motion_repeat_offset; | 1895 motion_repeat_offset = !motion_repeat_offset; |
1901 process_motion_notify(x, y, state); | 1896 process_motion_notify(x, y, state); |
1902 | 1897 |
1903 /* Don't happen again. We will get reinstalled in the synthetic event | 1898 // Don't happen again. We will get reinstalled in the synthetic event |
1904 * if needed -- thus repeating should still work. */ | 1899 // if needed -- thus repeating should still work. |
1905 return FALSE; | 1900 return FALSE; |
1906 } | 1901 } |
1907 | 1902 |
1908 static gint | 1903 static gint |
1909 motion_notify_event(GtkWidget *widget, | 1904 motion_notify_event(GtkWidget *widget, |
1923 { | 1918 { |
1924 process_motion_notify((int)event->x, (int)event->y, | 1919 process_motion_notify((int)event->x, (int)event->y, |
1925 (GdkModifierType)event->state); | 1920 (GdkModifierType)event->state); |
1926 } | 1921 } |
1927 | 1922 |
1928 return TRUE; /* handled */ | 1923 return TRUE; // handled |
1929 } | 1924 } |
1930 | 1925 |
1931 | 1926 |
1932 /* | 1927 /* |
1933 * Mouse button handling. Note please that we are capturing multiple click's | 1928 * Mouse button handling. Note please that we are capturing multiple click's |
1944 int x, y; | 1939 int x, y; |
1945 int_u vim_modifiers; | 1940 int_u vim_modifiers; |
1946 | 1941 |
1947 gui.event_time = event->time; | 1942 gui.event_time = event->time; |
1948 | 1943 |
1949 /* Make sure we have focus now we've been selected */ | 1944 // Make sure we have focus now we've been selected |
1950 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) | 1945 if (gtk_socket_id != 0 && !gtk_widget_has_focus(widget)) |
1951 gtk_widget_grab_focus(widget); | 1946 gtk_widget_grab_focus(widget); |
1952 | 1947 |
1953 /* | 1948 /* |
1954 * Don't let additional events about multiple clicks send by GTK to us | 1949 * Don't let additional events about multiple clicks send by GTK to us |
1958 return FALSE; | 1953 return FALSE; |
1959 | 1954 |
1960 x = event->x; | 1955 x = event->x; |
1961 y = event->y; | 1956 y = event->y; |
1962 | 1957 |
1963 /* Handle multiple clicks */ | 1958 // Handle multiple clicks |
1964 if (!mouse_timed_out && mouse_click_timer) | 1959 if (!mouse_timed_out && mouse_click_timer) |
1965 { | 1960 { |
1966 timeout_remove(mouse_click_timer); | 1961 timeout_remove(mouse_click_timer); |
1967 mouse_click_timer = 0; | 1962 mouse_click_timer = 0; |
1968 repeated_click = TRUE; | 1963 repeated_click = TRUE; |
1972 mouse_click_timer = timeout_add(p_mouset, mouse_click_timer_cb, | 1967 mouse_click_timer = timeout_add(p_mouset, mouse_click_timer_cb, |
1973 &mouse_timed_out); | 1968 &mouse_timed_out); |
1974 | 1969 |
1975 switch (event->button) | 1970 switch (event->button) |
1976 { | 1971 { |
1977 /* Keep in sync with gui_x11.c. | 1972 // Keep in sync with gui_x11.c. |
1978 * Buttons 4-7 are handled in scroll_event() */ | 1973 // Buttons 4-7 are handled in scroll_event() |
1979 case 1: button = MOUSE_LEFT; break; | 1974 case 1: button = MOUSE_LEFT; break; |
1980 case 2: button = MOUSE_MIDDLE; break; | 1975 case 2: button = MOUSE_MIDDLE; break; |
1981 case 3: button = MOUSE_RIGHT; break; | 1976 case 3: button = MOUSE_RIGHT; break; |
1982 case 8: button = MOUSE_X1; break; | 1977 case 8: button = MOUSE_X1; break; |
1983 case 9: button = MOUSE_X2; break; | 1978 case 9: button = MOUSE_X2; break; |
1984 default: | 1979 default: |
1985 return FALSE; /* Unknown button */ | 1980 return FALSE; // Unknown button |
1986 } | 1981 } |
1987 | 1982 |
1988 #ifdef FEAT_XIM | 1983 #ifdef FEAT_XIM |
1989 /* cancel any preediting */ | 1984 // cancel any preediting |
1990 if (im_is_preediting()) | 1985 if (im_is_preediting()) |
1991 xim_reset(); | 1986 xim_reset(); |
1992 #endif | 1987 #endif |
1993 | 1988 |
1994 vim_modifiers = modifiers_gdk2mouse(event->state); | 1989 vim_modifiers = modifiers_gdk2mouse(event->state); |
2024 button = MOUSE_7; | 2019 button = MOUSE_7; |
2025 break; | 2020 break; |
2026 case GDK_SCROLL_RIGHT: | 2021 case GDK_SCROLL_RIGHT: |
2027 button = MOUSE_6; | 2022 button = MOUSE_6; |
2028 break; | 2023 break; |
2029 default: /* This shouldn't happen */ | 2024 default: // This shouldn't happen |
2030 return FALSE; | 2025 return FALSE; |
2031 } | 2026 } |
2032 | 2027 |
2033 # ifdef FEAT_XIM | 2028 # ifdef FEAT_XIM |
2034 /* cancel any preediting */ | 2029 // cancel any preediting |
2035 if (im_is_preediting()) | 2030 if (im_is_preediting()) |
2036 xim_reset(); | 2031 xim_reset(); |
2037 # endif | 2032 # endif |
2038 | 2033 |
2039 vim_modifiers = modifiers_gdk2mouse(event->state); | 2034 vim_modifiers = modifiers_gdk2mouse(event->state); |
2053 int x, y; | 2048 int x, y; |
2054 int_u vim_modifiers; | 2049 int_u vim_modifiers; |
2055 | 2050 |
2056 gui.event_time = event->time; | 2051 gui.event_time = event->time; |
2057 | 2052 |
2058 /* Remove any motion "machine gun" timers used for automatic further | 2053 // Remove any motion "machine gun" timers used for automatic further |
2059 extension of allocation areas if outside of the applications window | 2054 // extension of allocation areas if outside of the applications window |
2060 area .*/ | 2055 // area . |
2061 if (motion_repeat_timer) | 2056 if (motion_repeat_timer) |
2062 { | 2057 { |
2063 timeout_remove(motion_repeat_timer); | 2058 timeout_remove(motion_repeat_timer); |
2064 motion_repeat_timer = 0; | 2059 motion_repeat_timer = 0; |
2065 } | 2060 } |
2074 return TRUE; | 2069 return TRUE; |
2075 } | 2070 } |
2076 | 2071 |
2077 | 2072 |
2078 #ifdef FEAT_DND | 2073 #ifdef FEAT_DND |
2079 /**************************************************************************** | 2074 ///////////////////////////////////////////////////////////////////////////// |
2080 * Drag aNd Drop support handlers. | 2075 // Drag aNd Drop support handlers. |
2081 */ | |
2082 | 2076 |
2083 /* | 2077 /* |
2084 * Count how many items there may be and separate them with a NUL. | 2078 * Count how many items there may be and separate them with a NUL. |
2085 * Apparently the items are separated with \r\n. This is not documented, | 2079 * Apparently the items are separated with \r\n. This is not documented, |
2086 * thus be careful not to go past the end. Also allow separation with | 2080 * thus be careful not to go past the end. Also allow separation with |
2111 else | 2105 else |
2112 *p++ = raw[i]; | 2106 *p++ = raw[i]; |
2113 } | 2107 } |
2114 if (p > out && p[-1] != NUL) | 2108 if (p > out && p[-1] != NUL) |
2115 { | 2109 { |
2116 *p = NUL; /* last item didn't have \r or \n */ | 2110 *p = NUL; // last item didn't have \r or \n |
2117 ++count; | 2111 ++count; |
2118 } | 2112 } |
2119 return count; | 2113 return count; |
2120 } | 2114 } |
2121 | 2115 |
2181 | 2175 |
2182 if (fnames != NULL && nfiles > 0) | 2176 if (fnames != NULL && nfiles > 0) |
2183 { | 2177 { |
2184 int_u modifiers; | 2178 int_u modifiers; |
2185 | 2179 |
2186 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | 2180 gtk_drag_finish(context, TRUE, FALSE, time_); // accept |
2187 | 2181 |
2188 modifiers = modifiers_gdk2mouse(state); | 2182 modifiers = modifiers_gdk2mouse(state); |
2189 | 2183 |
2190 gui_handle_drop(x, y, modifiers, fnames, nfiles); | 2184 gui_handle_drop(x, y, modifiers, fnames, nfiles); |
2191 } | 2185 } |
2214 if (tmpbuf != NULL) | 2208 if (tmpbuf != NULL) |
2215 text = tmpbuf; | 2209 text = tmpbuf; |
2216 } | 2210 } |
2217 | 2211 |
2218 dnd_yank_drag_data(text, (long)len); | 2212 dnd_yank_drag_data(text, (long)len); |
2219 gtk_drag_finish(context, TRUE, FALSE, time_); /* accept */ | 2213 gtk_drag_finish(context, TRUE, FALSE, time_); // accept |
2220 vim_free(tmpbuf); | 2214 vim_free(tmpbuf); |
2221 | 2215 |
2222 dropkey[2] = modifiers_gdk2vim(state); | 2216 dropkey[2] = modifiers_gdk2vim(state); |
2223 | 2217 |
2224 if (dropkey[2] != 0) | 2218 if (dropkey[2] != 0) |
2240 guint time_, | 2234 guint time_, |
2241 gpointer user_data UNUSED) | 2235 gpointer user_data UNUSED) |
2242 { | 2236 { |
2243 GdkModifierType state; | 2237 GdkModifierType state; |
2244 | 2238 |
2245 /* Guard against trash */ | 2239 // Guard against trash |
2246 const guchar * const data_data = gtk_selection_data_get_data(data); | 2240 const guchar * const data_data = gtk_selection_data_get_data(data); |
2247 const gint data_length = gtk_selection_data_get_length(data); | 2241 const gint data_length = gtk_selection_data_get_length(data); |
2248 const gint data_format = gtk_selection_data_get_format(data); | 2242 const gint data_format = gtk_selection_data_get_format(data); |
2249 | 2243 |
2250 if (data_data == NULL | 2244 if (data_data == NULL |
2254 { | 2248 { |
2255 gtk_drag_finish(context, FALSE, FALSE, time_); | 2249 gtk_drag_finish(context, FALSE, FALSE, time_); |
2256 return; | 2250 return; |
2257 } | 2251 } |
2258 | 2252 |
2259 /* Get the current modifier state for proper distinguishment between | 2253 // Get the current modifier state for proper distinguishment between |
2260 * different operations later. */ | 2254 // different operations later. |
2261 gui_gtk_get_pointer(widget, NULL, NULL, &state); | 2255 gui_gtk_get_pointer(widget, NULL, NULL, &state); |
2262 | 2256 |
2263 /* Not sure about the role of "text/plain" here... */ | 2257 // Not sure about the role of "text/plain" here... |
2264 if (info == (guint)TARGET_TEXT_URI_LIST) | 2258 if (info == (guint)TARGET_TEXT_URI_LIST) |
2265 drag_handle_uri_list(context, data, time_, state, x, y); | 2259 drag_handle_uri_list(context, data, time_, state, x, y); |
2266 else | 2260 else |
2267 drag_handle_text(context, data, time_, state); | 2261 drag_handle_text(context, data, time_, state); |
2268 | 2262 |
2269 } | 2263 } |
2270 #endif /* FEAT_DND */ | 2264 #endif // FEAT_DND |
2271 | 2265 |
2272 | 2266 |
2273 #if defined(USE_GNOME_SESSION) | 2267 #if defined(USE_GNOME_SESSION) |
2274 /* | 2268 /* |
2275 * GnomeClient interact callback. Check for unsaved buffers that cannot | 2269 * GnomeClient interact callback. Check for unsaved buffers that cannot |
2299 */ | 2293 */ |
2300 shutdown_cancelled = check_changed_any(FALSE, FALSE); | 2294 shutdown_cancelled = check_changed_any(FALSE, FALSE); |
2301 | 2295 |
2302 exiting = FALSE; | 2296 exiting = FALSE; |
2303 cmdmod = save_cmdmod; | 2297 cmdmod = save_cmdmod; |
2304 setcursor(); /* position the cursor */ | 2298 setcursor(); // position the cursor |
2305 out_flush(); | 2299 out_flush(); |
2306 /* | 2300 /* |
2307 * If the user hit the [Cancel] button the whole shutdown | 2301 * If the user hit the [Cancel] button the whole shutdown |
2308 * will be cancelled. Wow, quite powerful feature (: | 2302 * will be cancelled. Wow, quite powerful feature (: |
2309 */ | 2303 */ |
2327 static const char suffix[] = "-session.vim"; | 2321 static const char suffix[] = "-session.vim"; |
2328 char *session_file; | 2322 char *session_file; |
2329 unsigned int len; | 2323 unsigned int len; |
2330 gboolean success; | 2324 gboolean success; |
2331 | 2325 |
2332 /* Always request an interaction if possible. check_changed_any() | 2326 // Always request an interaction if possible. check_changed_any() |
2333 * won't actually show a dialog unless any buffers have been modified. | 2327 // won't actually show a dialog unless any buffers have been modified. |
2334 * There doesn't seem to be an obvious way to check that without | 2328 // There doesn't seem to be an obvious way to check that without |
2335 * automatically firing the dialog. Anyway, it works just fine. */ | 2329 // automatically firing the dialog. Anyway, it works just fine. |
2336 if (interact_style == GNOME_INTERACT_ANY) | 2330 if (interact_style == GNOME_INTERACT_ANY) |
2337 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, | 2331 gnome_client_request_interaction(client, GNOME_DIALOG_NORMAL, |
2338 &sm_client_check_changed_any, | 2332 &sm_client_check_changed_any, |
2339 NULL); | 2333 NULL); |
2340 out_flush(); | 2334 out_flush(); |
2341 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | 2335 ml_sync_all(FALSE, FALSE); // preserve all swap files |
2342 | 2336 |
2343 /* The path is unique for each session save. We do neither know nor care | 2337 // The path is unique for each session save. We do neither know nor care |
2344 * which session script will actually be used later. This decision is in | 2338 // which session script will actually be used later. This decision is in |
2345 * the domain of the session manager. */ | 2339 // the domain of the session manager. |
2346 session_file = gnome_config_get_real_path( | 2340 session_file = gnome_config_get_real_path( |
2347 gnome_client_get_config_prefix(client)); | 2341 gnome_client_get_config_prefix(client)); |
2348 len = strlen(session_file); | 2342 len = strlen(session_file); |
2349 | 2343 |
2350 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) | 2344 if (len > 0 && session_file[len-1] == G_DIR_SEPARATOR) |
2351 --len; /* get rid of the superfluous trailing '/' */ | 2345 --len; // get rid of the superfluous trailing '/' |
2352 | 2346 |
2353 session_file = g_renew(char, session_file, len + sizeof(suffix)); | 2347 session_file = g_renew(char, session_file, len + sizeof(suffix)); |
2354 memcpy(session_file + len, suffix, sizeof(suffix)); | 2348 memcpy(session_file + len, suffix, sizeof(suffix)); |
2355 | 2349 |
2356 success = write_session_file((char_u *)session_file); | 2350 success = write_session_file((char_u *)session_file); |
2358 if (success) | 2352 if (success) |
2359 { | 2353 { |
2360 const char *argv[8]; | 2354 const char *argv[8]; |
2361 int i; | 2355 int i; |
2362 | 2356 |
2363 /* Tell the session manager how to wipe out the stored session data. | 2357 // Tell the session manager how to wipe out the stored session data. |
2364 * This isn't as dangerous as it looks, don't worry :) session_file | 2358 // This isn't as dangerous as it looks, don't worry :) session_file |
2365 * is a unique absolute filename. Usually it'll be something like | 2359 // is a unique absolute filename. Usually it'll be something like |
2366 * `/home/user/.gnome2/vim-XXXXXX-session.vim'. */ | 2360 // `/home/user/.gnome2/vim-XXXXXX-session.vim'. |
2367 i = 0; | 2361 i = 0; |
2368 argv[i++] = "rm"; | 2362 argv[i++] = "rm"; |
2369 argv[i++] = session_file; | 2363 argv[i++] = session_file; |
2370 argv[i] = NULL; | 2364 argv[i] = NULL; |
2371 | 2365 |
2372 gnome_client_set_discard_command(client, i, (char **)argv); | 2366 gnome_client_set_discard_command(client, i, (char **)argv); |
2373 | 2367 |
2374 /* Tell the session manager how to restore the just saved session. | 2368 // Tell the session manager how to restore the just saved session. |
2375 * This is easily done thanks to Vim's -S option. Pass the -f flag | 2369 // This is easily done thanks to Vim's -S option. Pass the -f flag |
2376 * since there's no need to fork -- it might even cause confusion. | 2370 // since there's no need to fork -- it might even cause confusion. |
2377 * Also pass the window role to give the WM something to match on. | 2371 // Also pass the window role to give the WM something to match on. |
2378 * The role is set in gui_mch_open(), thus should _never_ be NULL. */ | 2372 // The role is set in gui_mch_open(), thus should _never_ be NULL. |
2379 i = 0; | 2373 i = 0; |
2380 argv[i++] = restart_command; | 2374 argv[i++] = restart_command; |
2381 argv[i++] = "-f"; | 2375 argv[i++] = "-f"; |
2382 argv[i++] = "-g"; | 2376 argv[i++] = "-g"; |
2383 argv[i++] = "--role"; | 2377 argv[i++] = "--role"; |
2401 * is happening). | 2395 * is happening). |
2402 */ | 2396 */ |
2403 static void | 2397 static void |
2404 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) | 2398 sm_client_die(GnomeClient *client UNUSED, gpointer data UNUSED) |
2405 { | 2399 { |
2406 /* Don't write messages to the GUI anymore */ | 2400 // Don't write messages to the GUI anymore |
2407 full_screen = FALSE; | 2401 full_screen = FALSE; |
2408 | 2402 |
2409 vim_strncpy(IObuff, (char_u *) | 2403 vim_strncpy(IObuff, (char_u *) |
2410 _("Vim: Received \"die\" request from session manager\n"), | 2404 _("Vim: Received \"die\" request from session manager\n"), |
2411 IOSIZE - 1); | 2405 IOSIZE - 1); |
2422 | 2416 |
2423 client = gnome_master_client(); | 2417 client = gnome_master_client(); |
2424 | 2418 |
2425 if (client != NULL) | 2419 if (client != NULL) |
2426 { | 2420 { |
2427 /* Must use the deprecated gtk_signal_connect() for compatibility | 2421 // Must use the deprecated gtk_signal_connect() for compatibility |
2428 * with GNOME 1. Arrgh, zombies! */ | 2422 // with GNOME 1. Arrgh, zombies! |
2429 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", | 2423 gtk_signal_connect(GTK_OBJECT(client), "save_yourself", |
2430 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); | 2424 GTK_SIGNAL_FUNC(&sm_client_save_yourself), NULL); |
2431 gtk_signal_connect(GTK_OBJECT(client), "die", | 2425 gtk_signal_connect(GTK_OBJECT(client), "die", |
2432 GTK_SIGNAL_FUNC(&sm_client_die), NULL); | 2426 GTK_SIGNAL_FUNC(&sm_client_die), NULL); |
2433 } | 2427 } |
2445 GIOCondition condition, | 2439 GIOCondition condition, |
2446 gpointer data) | 2440 gpointer data) |
2447 { | 2441 { |
2448 if (condition == G_IO_IN) | 2442 if (condition == G_IO_IN) |
2449 { | 2443 { |
2450 /* Do stuff; maybe close connection */ | 2444 // Do stuff; maybe close connection |
2451 if (xsmp_handle_requests() == FAIL) | 2445 if (xsmp_handle_requests() == FAIL) |
2452 g_io_channel_unref((GIOChannel *)data); | 2446 g_io_channel_unref((GIOChannel *)data); |
2453 return TRUE; | 2447 return TRUE; |
2454 } | 2448 } |
2455 /* Error */ | 2449 // Error |
2456 g_io_channel_unref((GIOChannel *)data); | 2450 g_io_channel_unref((GIOChannel *)data); |
2457 xsmp_close(); | 2451 xsmp_close(); |
2458 return TRUE; | 2452 return TRUE; |
2459 } | 2453 } |
2460 # endif /* USE_XSMP */ | 2454 # endif // USE_XSMP |
2461 | 2455 |
2462 /* | 2456 /* |
2463 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. | 2457 * Setup the WM_PROTOCOLS to indicate we want the WM_SAVE_YOURSELF event. |
2464 * This is an ugly use of X functions. GTK doesn't offer an alternative. | 2458 * This is an ugly use of X functions. GTK doesn't offer an alternative. |
2465 */ | 2459 */ |
2483 g_io_channel_unref(g_io); | 2477 g_io_channel_unref(g_io); |
2484 } | 2478 } |
2485 else | 2479 else |
2486 # endif | 2480 # endif |
2487 { | 2481 { |
2488 /* Fall back to old method */ | 2482 // Fall back to old method |
2489 | 2483 |
2490 /* first get the existing value */ | 2484 // first get the existing value |
2491 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); | 2485 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
2492 | 2486 |
2493 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), | 2487 if (XGetWMProtocols(GDK_WINDOW_XDISPLAY(mainwin_win), |
2494 GDK_WINDOW_XID(mainwin_win), | 2488 GDK_WINDOW_XID(mainwin_win), |
2495 &existing_atoms, &count)) | 2489 &existing_atoms, &count)) |
2498 Atom save_yourself_xatom; | 2492 Atom save_yourself_xatom; |
2499 int i; | 2493 int i; |
2500 | 2494 |
2501 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); | 2495 save_yourself_xatom = GET_X_ATOM(save_yourself_atom); |
2502 | 2496 |
2503 /* check if WM_SAVE_YOURSELF isn't there yet */ | 2497 // check if WM_SAVE_YOURSELF isn't there yet |
2504 for (i = 0; i < count; ++i) | 2498 for (i = 0; i < count; ++i) |
2505 if (existing_atoms[i] == save_yourself_xatom) | 2499 if (existing_atoms[i] == save_yourself_xatom) |
2506 break; | 2500 break; |
2507 | 2501 |
2508 if (i == count) | 2502 if (i == count) |
2509 { | 2503 { |
2510 /* allocate an Atoms array which is one item longer */ | 2504 // allocate an Atoms array which is one item longer |
2511 new_atoms = ALLOC_MULT(Atom, count + 1); | 2505 new_atoms = ALLOC_MULT(Atom, count + 1); |
2512 if (new_atoms != NULL) | 2506 if (new_atoms != NULL) |
2513 { | 2507 { |
2514 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); | 2508 memcpy(new_atoms, existing_atoms, count * sizeof(Atom)); |
2515 new_atoms[count] = save_yourself_xatom; | 2509 new_atoms[count] = save_yourself_xatom; |
2551 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) | 2545 && xevent->xclient.message_type == GET_X_ATOM(wm_protocols_atom) |
2552 && (long_u)xevent->xclient.data.l[0] | 2546 && (long_u)xevent->xclient.data.l[0] |
2553 == GET_X_ATOM(save_yourself_atom)) | 2547 == GET_X_ATOM(save_yourself_atom)) |
2554 { | 2548 { |
2555 out_flush(); | 2549 out_flush(); |
2556 ml_sync_all(FALSE, FALSE); /* preserve all swap files */ | 2550 ml_sync_all(FALSE, FALSE); // preserve all swap files |
2557 /* | 2551 /* |
2558 * Set the window's WM_COMMAND property, to let the window manager | 2552 * Set the window's WM_COMMAND property, to let the window manager |
2559 * know we are done saving ourselves. We don't want to be | 2553 * know we are done saving ourselves. We don't want to be |
2560 * restarted, thus set argv to NULL. | 2554 * restarted, thus set argv to NULL. |
2561 */ | 2555 */ |
2574 * Setup the window icon & xcmdsrv comm after the main window has been realized. | 2568 * Setup the window icon & xcmdsrv comm after the main window has been realized. |
2575 */ | 2569 */ |
2576 static void | 2570 static void |
2577 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) | 2571 mainwin_realize(GtkWidget *widget UNUSED, gpointer data UNUSED) |
2578 { | 2572 { |
2579 /* If you get an error message here, you still need to unpack the runtime | 2573 // If you get an error message here, you still need to unpack the runtime |
2580 * archive! */ | 2574 // archive! |
2581 #ifdef magick | 2575 #ifdef magick |
2582 # undef magick | 2576 # undef magick |
2583 #endif | 2577 #endif |
2584 /* A bit hackish, but avoids casting later and allows optimization */ | 2578 // A bit hackish, but avoids casting later and allows optimization |
2585 # define static static const | 2579 # define static static const |
2586 #define magick vim32x32 | 2580 #define magick vim32x32 |
2587 #include "../runtime/vim32x32.xpm" | 2581 #include "../runtime/vim32x32.xpm" |
2588 #undef magick | 2582 #undef magick |
2589 #define magick vim16x16 | 2583 #define magick vim16x16 |
2594 #undef magick | 2588 #undef magick |
2595 # undef static | 2589 # undef static |
2596 | 2590 |
2597 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); | 2591 GdkWindow * const mainwin_win = gtk_widget_get_window(gui.mainwin); |
2598 | 2592 |
2599 /* When started with "--echo-wid" argument, write window ID on stdout. */ | 2593 // When started with "--echo-wid" argument, write window ID on stdout. |
2600 if (echo_wid_arg) | 2594 if (echo_wid_arg) |
2601 { | 2595 { |
2602 printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); | 2596 printf("WID: %ld\n", (long)GDK_WINDOW_XID(mainwin_win)); |
2603 fflush(stdout); | 2597 fflush(stdout); |
2604 } | 2598 } |
2619 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); | 2613 g_list_foreach(icons, (GFunc)&g_object_unref, NULL); |
2620 g_list_free(icons); | 2614 g_list_free(icons); |
2621 } | 2615 } |
2622 | 2616 |
2623 #if !defined(USE_GNOME_SESSION) | 2617 #if !defined(USE_GNOME_SESSION) |
2624 /* Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F */ | 2618 // Register a handler for WM_SAVE_YOURSELF with GDK's low-level X I/F |
2625 gdk_window_add_filter(NULL, &global_event_filter, NULL); | 2619 gdk_window_add_filter(NULL, &global_event_filter, NULL); |
2626 #endif | 2620 #endif |
2627 /* Setup to indicate to the window manager that we want to catch the | 2621 // Setup to indicate to the window manager that we want to catch the |
2628 * WM_SAVE_YOURSELF event. For GNOME, this connects to the session | 2622 // WM_SAVE_YOURSELF event. For GNOME, this connects to the session |
2629 * manager instead. */ | 2623 // manager instead. |
2630 #if defined(USE_GNOME_SESSION) | 2624 #if defined(USE_GNOME_SESSION) |
2631 if (using_gnome) | 2625 if (using_gnome) |
2632 #endif | 2626 #endif |
2633 setup_save_yourself(); | 2627 setup_save_yourself(); |
2634 | 2628 |
2635 #ifdef FEAT_CLIENTSERVER | 2629 #ifdef FEAT_CLIENTSERVER |
2636 if (serverName == NULL && serverDelayedStartName != NULL) | 2630 if (serverName == NULL && serverDelayedStartName != NULL) |
2637 { | 2631 { |
2638 /* This is a :gui command in a plain vim with no previous server */ | 2632 // This is a :gui command in a plain vim with no previous server |
2639 commWindow = GDK_WINDOW_XID(mainwin_win); | 2633 commWindow = GDK_WINDOW_XID(mainwin_win); |
2640 | 2634 |
2641 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(mainwin_win), | 2635 (void)serverRegisterName(GDK_WINDOW_XDISPLAY(mainwin_win), |
2642 serverDelayedStartName); | 2636 serverDelayedStartName); |
2643 } | 2637 } |
2682 } | 2676 } |
2683 #else | 2677 #else |
2684 root_window = gtk_widget_get_root_window(gui.mainwin); | 2678 root_window = gtk_widget_get_root_window(gui.mainwin); |
2685 #endif | 2679 #endif |
2686 | 2680 |
2687 /* Create a pseudo blank pointer, which is in fact one pixel by one pixel | 2681 // Create a pseudo blank pointer, which is in fact one pixel by one pixel |
2688 * in size. */ | 2682 // in size. |
2689 #if GTK_CHECK_VERSION(3,0,0) | 2683 #if GTK_CHECK_VERSION(3,0,0) |
2690 { | 2684 { |
2691 cairo_surface_t *surf; | 2685 cairo_surface_t *surf; |
2692 cairo_t *cr; | 2686 cairo_t *cr; |
2693 | 2687 |
2790 | 2784 |
2791 gui.blank_pointer = create_blank_pointer(); | 2785 gui.blank_pointer = create_blank_pointer(); |
2792 if (gui.pointer_hidden) | 2786 if (gui.pointer_hidden) |
2793 gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); | 2787 gdk_window_set_cursor(gtk_widget_get_window(widget), gui.blank_pointer); |
2794 | 2788 |
2795 /* get the actual size of the scrollbars, if they are realized */ | 2789 // get the actual size of the scrollbars, if they are realized |
2796 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; | 2790 sbar = firstwin->w_scrollbars[SBAR_LEFT].id; |
2797 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] | 2791 if (!sbar || (!gui.which_scrollbars[SBAR_LEFT] |
2798 && firstwin->w_scrollbars[SBAR_RIGHT].id)) | 2792 && firstwin->w_scrollbars[SBAR_RIGHT].id)) |
2799 sbar = firstwin->w_scrollbars[SBAR_RIGHT].id; | 2793 sbar = firstwin->w_scrollbars[SBAR_RIGHT].id; |
2800 gtk_widget_get_allocation(sbar, &allocation); | 2794 gtk_widget_get_allocation(sbar, &allocation); |
2810 * Properly clean up on shutdown. | 2804 * Properly clean up on shutdown. |
2811 */ | 2805 */ |
2812 static void | 2806 static void |
2813 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) | 2807 drawarea_unrealize_cb(GtkWidget *widget UNUSED, gpointer data UNUSED) |
2814 { | 2808 { |
2815 /* Don't write messages to the GUI anymore */ | 2809 // Don't write messages to the GUI anymore |
2816 full_screen = FALSE; | 2810 full_screen = FALSE; |
2817 | 2811 |
2818 #ifdef FEAT_XIM | 2812 #ifdef FEAT_XIM |
2819 im_shutdown(); | 2813 im_shutdown(); |
2820 #endif | 2814 #endif |
2875 | 2869 |
2876 g_return_val_if_fail(event | 2870 g_return_val_if_fail(event |
2877 && event->width >= 1 && event->height >= 1, TRUE); | 2871 && event->width >= 1 && event->height >= 1, TRUE); |
2878 | 2872 |
2879 # if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) | 2873 # if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
2880 /* As of 3.22.2, GdkWindows have started distributing configure events to | 2874 // As of 3.22.2, GdkWindows have started distributing configure events to |
2881 * their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). | 2875 // their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
2882 * | 2876 // |
2883 * As can be seen from the implementation of move_native_children() and | 2877 // As can be seen from the implementation of move_native_children() and |
2884 * configure_native_child() in gdkwindow.c, those functions actually | 2878 // configure_native_child() in gdkwindow.c, those functions actually |
2885 * propagate configure events to every child, failing to distinguish | 2879 // propagate configure events to every child, failing to distinguish |
2886 * "native" one from non-native one. | 2880 // "native" one from non-native one. |
2887 * | 2881 // |
2888 * Naturally, configure events propagated to here like that are fallacious | 2882 // Naturally, configure events propagated to here like that are fallacious |
2889 * and, as a matter of fact, they trigger a geometric collapse of | 2883 // and, as a matter of fact, they trigger a geometric collapse of |
2890 * gui.drawarea in fullscreen and maximized modes. | 2884 // gui.drawarea in fullscreen and maximized modes. |
2891 * | 2885 // |
2892 * To filter out such nuisance events, we are making use of the fact that | 2886 // To filter out such nuisance events, we are making use of the fact that |
2893 * the field send_event of such GdkEventConfigures is set to FALSE in | 2887 // the field send_event of such GdkEventConfigures is set to FALSE in |
2894 * configure_native_child(). | 2888 // configure_native_child(). |
2895 * | 2889 // |
2896 * Obviously, this is a terrible hack making GVim depend on GTK's | 2890 // Obviously, this is a terrible hack making GVim depend on GTK's |
2897 * implementation details. Therefore, watch out any relevant internal | 2891 // implementation details. Therefore, watch out any relevant internal |
2898 * changes happening in GTK in the feature (sigh). | 2892 // changes happening in GTK in the feature (sigh). |
2899 */ | 2893 // |
2900 /* Follow-up | 2894 // Follow-up |
2901 * After a few weeks later, the GdkWindow change mentioned above was | 2895 // After a few weeks later, the GdkWindow change mentioned above was |
2902 * reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). | 2896 // reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). |
2903 * The corresponding official release is 3.22.4. */ | 2897 // The corresponding official release is 3.22.4. |
2904 if (event->send_event == FALSE) | 2898 if (event->send_event == FALSE) |
2905 return TRUE; | 2899 return TRUE; |
2906 # endif | 2900 # endif |
2907 | 2901 |
2908 if (event->width == cur_width && event->height == cur_height) | 2902 if (event->width == cur_width && event->height == cur_height) |
2951 BonoboDockItem *dockitem; | 2945 BonoboDockItem *dockitem; |
2952 | 2946 |
2953 parent = gtk_widget_get_parent(widget); | 2947 parent = gtk_widget_get_parent(widget); |
2954 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) | 2948 if (G_TYPE_FROM_INSTANCE(parent) == BONOBO_TYPE_DOCK_ITEM) |
2955 { | 2949 { |
2956 /* Only menu & toolbar are dock items. Could tabline be? | 2950 // Only menu & toolbar are dock items. Could tabline be? |
2957 * Seem to be only the 2 defined in GNOME */ | 2951 // Seem to be only the 2 defined in GNOME |
2958 widget = parent; | 2952 widget = parent; |
2959 dockitem = BONOBO_DOCK_ITEM(widget); | 2953 dockitem = BONOBO_DOCK_ITEM(widget); |
2960 | 2954 |
2961 if (dockitem == NULL || dockitem->is_floating) | 2955 if (dockitem == NULL || dockitem->is_floating) |
2962 return 0; | 2956 return 0; |
2991 static int | 2985 static int |
2992 get_menu_tool_width(void) | 2986 get_menu_tool_width(void) |
2993 { | 2987 { |
2994 int width = 0; | 2988 int width = 0; |
2995 | 2989 |
2996 #ifdef FEAT_GUI_GNOME /* these are never vertical without GNOME */ | 2990 #ifdef FEAT_GUI_GNOME // these are never vertical without GNOME |
2997 # ifdef FEAT_MENU | 2991 # ifdef FEAT_MENU |
2998 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); | 2992 width += get_item_dimensions(gui.menubar, GTK_ORIENTATION_VERTICAL); |
2999 # endif | 2993 # endif |
3000 # ifdef FEAT_TOOLBAR | 2994 # ifdef FEAT_TOOLBAR |
3001 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); | 2995 width += get_item_dimensions(gui.toolbar, GTK_ORIENTATION_VERTICAL); |
3026 #endif | 3020 #endif |
3027 | 3021 |
3028 return height; | 3022 return height; |
3029 } | 3023 } |
3030 | 3024 |
3031 /* This controls whether we can set the real window hints at | 3025 // This controls whether we can set the real window hints at |
3032 * start-up when in a GtkPlug. | 3026 // start-up when in a GtkPlug. |
3033 * 0 = normal processing (default) | 3027 // 0 = normal processing (default) |
3034 * 1 = init. hints set, no-one's tried to reset since last check | 3028 // 1 = init. hints set, no-one's tried to reset since last check |
3035 * 2 = init. hints set, attempt made to change hints | 3029 // 2 = init. hints set, attempt made to change hints |
3036 */ | |
3037 static int init_window_hints_state = 0; | 3030 static int init_window_hints_state = 0; |
3038 | 3031 |
3039 static void | 3032 static void |
3040 update_window_manager_hints(int force_width, int force_height) | 3033 update_window_manager_hints(int force_width, int force_height) |
3041 { | 3034 { |
3049 int width; | 3042 int width; |
3050 int height; | 3043 int height; |
3051 int min_width; | 3044 int min_width; |
3052 int min_height; | 3045 int min_height; |
3053 | 3046 |
3054 /* At start-up, don't try to set the hints until the initial | 3047 // At start-up, don't try to set the hints until the initial |
3055 * values have been used (those that dictate our initial size) | 3048 // values have been used (those that dictate our initial size) |
3056 * Let forced (i.e., correct) values through always. | 3049 // Let forced (i.e., correct) values through always. |
3057 */ | |
3058 if (!(force_width && force_height) && init_window_hints_state > 0) | 3050 if (!(force_width && force_height) && init_window_hints_state > 0) |
3059 { | 3051 { |
3060 /* Don't do it! */ | 3052 // Don't do it! |
3061 init_window_hints_state = 2; | 3053 init_window_hints_state = 2; |
3062 return; | 3054 return; |
3063 } | 3055 } |
3064 | 3056 |
3065 /* This also needs to be done when the main window isn't there yet, | 3057 // This also needs to be done when the main window isn't there yet, |
3066 * otherwise the hints don't work. */ | 3058 // otherwise the hints don't work. |
3067 width = gui_get_base_width(); | 3059 width = gui_get_base_width(); |
3068 height = gui_get_base_height(); | 3060 height = gui_get_base_height(); |
3069 # ifdef FEAT_MENU | 3061 # ifdef FEAT_MENU |
3070 height += tabline_height() * gui.char_height; | 3062 height += tabline_height() * gui.char_height; |
3071 # endif | 3063 # endif |
3072 width += get_menu_tool_width(); | 3064 width += get_menu_tool_width(); |
3073 height += get_menu_tool_height(); | 3065 height += get_menu_tool_height(); |
3074 | 3066 |
3075 /* GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine | 3067 // GtkSockets use GtkPlug's [gui,mainwin] min-size hints to determine |
3076 * their actual widget size. When we set our size ourselves (e.g., | 3068 // their actual widget size. When we set our size ourselves (e.g., |
3077 * 'set columns=' or init. -geom) we briefly set the min. to the size | 3069 // 'set columns=' or init. -geom) we briefly set the min. to the size |
3078 * we wish to be instead of the legitimate minimum so that we actually | 3070 // we wish to be instead of the legitimate minimum so that we actually |
3079 * resize correctly. | 3071 // resize correctly. |
3080 */ | |
3081 if (force_width && force_height) | 3072 if (force_width && force_height) |
3082 { | 3073 { |
3083 min_width = force_width; | 3074 min_width = force_width; |
3084 min_height = force_height; | 3075 min_height = force_height; |
3085 } | 3076 } |
3087 { | 3078 { |
3088 min_width = width + MIN_COLUMNS * gui.char_width; | 3079 min_width = width + MIN_COLUMNS * gui.char_width; |
3089 min_height = height + MIN_LINES * gui.char_height; | 3080 min_height = height + MIN_LINES * gui.char_height; |
3090 } | 3081 } |
3091 | 3082 |
3092 /* Avoid an expose event when the size didn't change. */ | 3083 // Avoid an expose event when the size didn't change. |
3093 if (width != old_width | 3084 if (width != old_width |
3094 || height != old_height | 3085 || height != old_height |
3095 || min_width != old_min_width | 3086 || min_width != old_min_width |
3096 || min_height != old_min_height | 3087 || min_height != old_min_height |
3097 || gui.char_width != old_char_width | 3088 || gui.char_width != old_char_width |
3106 geometry.base_height = height; | 3097 geometry.base_height = height; |
3107 geometry.min_width = min_width; | 3098 geometry.min_width = min_width; |
3108 geometry.min_height = min_height; | 3099 geometry.min_height = min_height; |
3109 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC | 3100 geometry_mask = GDK_HINT_BASE_SIZE|GDK_HINT_RESIZE_INC |
3110 |GDK_HINT_MIN_SIZE; | 3101 |GDK_HINT_MIN_SIZE; |
3111 /* Using gui.formwin as geometry widget doesn't work as expected | 3102 // Using gui.formwin as geometry widget doesn't work as expected |
3112 * with GTK+ 2 -- dunno why. Presumably all the resizing hacks | 3103 // with GTK+ 2 -- dunno why. Presumably all the resizing hacks |
3113 * in Vim confuse GTK+. */ | 3104 // in Vim confuse GTK+. |
3114 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, | 3105 gtk_window_set_geometry_hints(GTK_WINDOW(gui.mainwin), gui.mainwin, |
3115 &geometry, geometry_mask); | 3106 &geometry, geometry_mask); |
3116 old_width = width; | 3107 old_width = width; |
3117 old_height = height; | 3108 old_height = height; |
3118 old_min_width = min_width; | 3109 old_min_width = min_width; |
3131 | 3122 |
3132 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | 3123 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); |
3133 g_object_set(gtk_settings, "gtk-application-prefer-dark-theme", (gboolean)dark, NULL); | 3124 g_object_set(gtk_settings, "gtk-application-prefer-dark-theme", (gboolean)dark, NULL); |
3134 # endif | 3125 # endif |
3135 } | 3126 } |
3136 #endif /* FEAT_GUI_DARKTHEME */ | 3127 #endif // FEAT_GUI_DARKTHEME |
3137 | 3128 |
3138 #ifdef FEAT_TOOLBAR | 3129 #ifdef FEAT_TOOLBAR |
3139 | 3130 |
3140 /* | 3131 /* |
3141 * This extra effort wouldn't be necessary if we only used stock icons in the | 3132 * This extra effort wouldn't be necessary if we only used stock icons in the |
3158 gtk_image_get_icon_name(image, &icon_name, NULL); | 3149 gtk_image_get_icon_name(image, &icon_name, NULL); |
3159 | 3150 |
3160 gtk_image_set_from_icon_name(image, icon_name, icon_size); | 3151 gtk_image_set_from_icon_name(image, icon_name, icon_size); |
3161 } | 3152 } |
3162 # else | 3153 # else |
3163 /* User-defined icons are stored in a GtkIconSet */ | 3154 // User-defined icons are stored in a GtkIconSet |
3164 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) | 3155 if (gtk_image_get_storage_type(image) == GTK_IMAGE_ICON_SET) |
3165 { | 3156 { |
3166 GtkIconSet *icon_set; | 3157 GtkIconSet *icon_set; |
3167 GtkIconSize icon_size; | 3158 GtkIconSize icon_size; |
3168 | 3159 |
3218 } | 3209 } |
3219 oldsize = gtk_toolbar_get_icon_size(toolbar); | 3210 oldsize = gtk_toolbar_get_icon_size(toolbar); |
3220 | 3211 |
3221 if (size == GTK_ICON_SIZE_INVALID) | 3212 if (size == GTK_ICON_SIZE_INVALID) |
3222 { | 3213 { |
3223 /* Let global user preferences decide the icon size. */ | 3214 // Let global user preferences decide the icon size. |
3224 gtk_toolbar_unset_icon_size(toolbar); | 3215 gtk_toolbar_unset_icon_size(toolbar); |
3225 size = gtk_toolbar_get_icon_size(toolbar); | 3216 size = gtk_toolbar_get_icon_size(toolbar); |
3226 } | 3217 } |
3227 if (size != oldsize) | 3218 if (size != oldsize) |
3228 { | 3219 { |
3231 GINT_TO_POINTER((int)size)); | 3222 GINT_TO_POINTER((int)size)); |
3232 } | 3223 } |
3233 gtk_toolbar_set_icon_size(toolbar, size); | 3224 gtk_toolbar_set_icon_size(toolbar, size); |
3234 } | 3225 } |
3235 | 3226 |
3236 #endif /* FEAT_TOOLBAR */ | 3227 #endif // FEAT_TOOLBAR |
3237 | 3228 |
3238 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) | 3229 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
3239 static int ignore_tabline_evt = FALSE; | 3230 static int ignore_tabline_evt = FALSE; |
3240 static GtkWidget *tabline_menu; | 3231 static GtkWidget *tabline_menu; |
3241 # if !GTK_CHECK_VERSION(3,0,0) | 3232 # if !GTK_CHECK_VERSION(3,0,0) |
3242 static GtkTooltips *tabline_tooltip; | 3233 static GtkTooltips *tabline_tooltip; |
3243 # endif | 3234 # endif |
3244 static int clicked_page; /* page clicked in tab line */ | 3235 static int clicked_page; // page clicked in tab line |
3245 | 3236 |
3246 /* | 3237 /* |
3247 * Handle selecting an item in the tab line popup menu. | 3238 * Handle selecting an item in the tab line popup menu. |
3248 */ | 3239 */ |
3249 static void | 3240 static void |
3250 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) | 3241 tabline_menu_handler(GtkMenuItem *item UNUSED, gpointer user_data) |
3251 { | 3242 { |
3252 /* Add the string cmd into input buffer */ | 3243 // Add the string cmd into input buffer |
3253 send_tabline_menu_event(clicked_page, (int)(long)user_data); | 3244 send_tabline_menu_event(clicked_page, (int)(long)user_data); |
3254 } | 3245 } |
3255 | 3246 |
3256 static void | 3247 static void |
3257 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) | 3248 add_tabline_menu_item(GtkWidget *menu, char_u *text, int resp) |
3287 } | 3278 } |
3288 | 3279 |
3289 static gboolean | 3280 static gboolean |
3290 on_tabline_menu(GtkWidget *widget, GdkEvent *event) | 3281 on_tabline_menu(GtkWidget *widget, GdkEvent *event) |
3291 { | 3282 { |
3292 /* Was this button press event ? */ | 3283 // Was this button press event ? |
3293 if (event->type == GDK_BUTTON_PRESS) | 3284 if (event->type == GDK_BUTTON_PRESS) |
3294 { | 3285 { |
3295 GdkEventButton *bevent = (GdkEventButton *)event; | 3286 GdkEventButton *bevent = (GdkEventButton *)event; |
3296 int x = bevent->x; | 3287 int x = bevent->x; |
3297 int y = bevent->y; | 3288 int y = bevent->y; |
3298 GtkWidget *tabwidget; | 3289 GtkWidget *tabwidget; |
3299 GdkWindow *tabwin; | 3290 GdkWindow *tabwin; |
3300 | 3291 |
3301 /* When ignoring events return TRUE so that the selected page doesn't | 3292 // When ignoring events return TRUE so that the selected page doesn't |
3302 * change. */ | 3293 // change. |
3303 if (hold_gui_events | 3294 if (hold_gui_events |
3304 # ifdef FEAT_CMDWIN | 3295 # ifdef FEAT_CMDWIN |
3305 || cmdwin_type != 0 | 3296 || cmdwin_type != 0 |
3306 # endif | 3297 # endif |
3307 ) | 3298 ) |
3311 | 3302 |
3312 gdk_window_get_user_data(tabwin, (gpointer)&tabwidget); | 3303 gdk_window_get_user_data(tabwin, (gpointer)&tabwidget); |
3313 clicked_page = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tabwidget), | 3304 clicked_page = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tabwidget), |
3314 "tab_num")); | 3305 "tab_num")); |
3315 | 3306 |
3316 /* If the event was generated for 3rd button popup the menu. */ | 3307 // If the event was generated for 3rd button popup the menu. |
3317 if (bevent->button == 3) | 3308 if (bevent->button == 3) |
3318 { | 3309 { |
3319 # if GTK_CHECK_VERSION(3,22,2) | 3310 # if GTK_CHECK_VERSION(3,22,2) |
3320 gtk_menu_popup_at_pointer(GTK_MENU(widget), event); | 3311 gtk_menu_popup_at_pointer(GTK_MENU(widget), event); |
3321 # else | 3312 # else |
3322 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, | 3313 gtk_menu_popup(GTK_MENU(widget), NULL, NULL, NULL, NULL, |
3323 bevent->button, bevent->time); | 3314 bevent->button, bevent->time); |
3324 # endif | 3315 # endif |
3325 /* We handled the event. */ | 3316 // We handled the event. |
3326 return TRUE; | 3317 return TRUE; |
3327 } | 3318 } |
3328 else if (bevent->button == 1) | 3319 else if (bevent->button == 1) |
3329 { | 3320 { |
3330 if (clicked_page == 0) | 3321 if (clicked_page == 0) |
3331 { | 3322 { |
3332 /* Click after all tabs moves to next tab page. When "x" is | 3323 // Click after all tabs moves to next tab page. When "x" is |
3333 * small guess it's the left button. */ | 3324 // small guess it's the left button. |
3334 send_tabline_event(x < 50 ? -1 : 0); | 3325 send_tabline_event(x < 50 ? -1 : 0); |
3335 } | 3326 } |
3336 } | 3327 } |
3337 } | 3328 } |
3338 | 3329 |
3339 /* We didn't handle the event. */ | 3330 // We didn't handle the event. |
3340 return FALSE; | 3331 return FALSE; |
3341 } | 3332 } |
3342 | 3333 |
3343 /* | 3334 /* |
3344 * Handle selecting one of the tabs. | 3335 * Handle selecting one of the tabs. |
3384 if (gui.tabline == NULL) | 3375 if (gui.tabline == NULL) |
3385 return; | 3376 return; |
3386 | 3377 |
3387 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) | 3378 if (!showit != !gtk_notebook_get_show_tabs(GTK_NOTEBOOK(gui.tabline))) |
3388 { | 3379 { |
3389 /* Note: this may cause a resize event */ | 3380 // Note: this may cause a resize event |
3390 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); | 3381 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(gui.tabline), showit); |
3391 update_window_manager_hints(0, 0); | 3382 update_window_manager_hints(0, 0); |
3392 if (showit) | 3383 if (showit) |
3393 gtk_widget_set_can_focus(GTK_WIDGET(gui.tabline), FALSE); | 3384 gtk_widget_set_can_focus(GTK_WIDGET(gui.tabline), FALSE); |
3394 } | 3385 } |
3424 if (gui.tabline == NULL) | 3415 if (gui.tabline == NULL) |
3425 return; | 3416 return; |
3426 | 3417 |
3427 ignore_tabline_evt = TRUE; | 3418 ignore_tabline_evt = TRUE; |
3428 | 3419 |
3429 /* Add a label for each tab page. They all contain the same text area. */ | 3420 // Add a label for each tab page. They all contain the same text area. |
3430 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) | 3421 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr) |
3431 { | 3422 { |
3432 if (tp == curtab) | 3423 if (tp == curtab) |
3433 curtabidx = nr; | 3424 curtabidx = nr; |
3434 | 3425 |
3435 tab_num = nr + 1; | 3426 tab_num = nr + 1; |
3436 | 3427 |
3437 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); | 3428 page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr); |
3438 if (page == NULL) | 3429 if (page == NULL) |
3439 { | 3430 { |
3440 /* Add notebook page */ | 3431 // Add notebook page |
3441 # if GTK_CHECK_VERSION(3,2,0) | 3432 # if GTK_CHECK_VERSION(3,2,0) |
3442 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); | 3433 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3443 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); | 3434 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
3444 # else | 3435 # else |
3445 page = gtk_vbox_new(FALSE, 0); | 3436 page = gtk_vbox_new(FALSE, 0); |
3482 (const char *)labeltext, NULL); | 3473 (const char *)labeltext, NULL); |
3483 # endif | 3474 # endif |
3484 CONVERT_TO_UTF8_FREE(labeltext); | 3475 CONVERT_TO_UTF8_FREE(labeltext); |
3485 } | 3476 } |
3486 | 3477 |
3487 /* Remove any old labels. */ | 3478 // Remove any old labels. |
3488 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) | 3479 while (gtk_notebook_get_nth_page(GTK_NOTEBOOK(gui.tabline), nr) != NULL) |
3489 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); | 3480 gtk_notebook_remove_page(GTK_NOTEBOOK(gui.tabline), nr); |
3490 | 3481 |
3491 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) | 3482 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != curtabidx) |
3492 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), curtabidx); | 3483 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), curtabidx); |
3493 | 3484 |
3494 /* Make sure everything is in place before drawing text. */ | 3485 // Make sure everything is in place before drawing text. |
3495 gui_mch_update(); | 3486 gui_mch_update(); |
3496 | 3487 |
3497 ignore_tabline_evt = FALSE; | 3488 ignore_tabline_evt = FALSE; |
3498 } | 3489 } |
3499 | 3490 |
3510 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) | 3501 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(gui.tabline)) != nr - 1) |
3511 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), nr - 1); | 3502 gtk_notebook_set_current_page(GTK_NOTEBOOK(gui.tabline), nr - 1); |
3512 ignore_tabline_evt = FALSE; | 3503 ignore_tabline_evt = FALSE; |
3513 } | 3504 } |
3514 | 3505 |
3515 #endif /* FEAT_GUI_TABLINE */ | 3506 #endif // FEAT_GUI_TABLINE |
3516 | 3507 |
3517 /* | 3508 /* |
3518 * Add selection targets for PRIMARY and CLIPBOARD selections. | 3509 * Add selection targets for PRIMARY and CLIPBOARD selections. |
3519 */ | 3510 */ |
3520 void | 3511 void |
3524 int n_targets = N_SELECTION_TARGETS; | 3515 int n_targets = N_SELECTION_TARGETS; |
3525 GtkTargetEntry targets[N_SELECTION_TARGETS]; | 3516 GtkTargetEntry targets[N_SELECTION_TARGETS]; |
3526 | 3517 |
3527 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) | 3518 for (i = 0; i < (int)N_SELECTION_TARGETS; ++i) |
3528 { | 3519 { |
3529 /* OpenOffice tries to use TARGET_HTML and fails when we don't | 3520 // OpenOffice tries to use TARGET_HTML and fails when we don't |
3530 * return something, instead of trying another target. Therefore only | 3521 // return something, instead of trying another target. Therefore only |
3531 * offer TARGET_HTML when it works. */ | 3522 // offer TARGET_HTML when it works. |
3532 if (!clip_html && selection_targets[i].info == TARGET_HTML) | 3523 if (!clip_html && selection_targets[i].info == TARGET_HTML) |
3533 n_targets--; | 3524 n_targets--; |
3534 else | 3525 else |
3535 targets[j++] = selection_targets[i]; | 3526 targets[j++] = selection_targets[i]; |
3536 } | 3527 } |
3578 gui_mch_init(void) | 3569 gui_mch_init(void) |
3579 { | 3570 { |
3580 GtkWidget *vbox; | 3571 GtkWidget *vbox; |
3581 | 3572 |
3582 #ifdef FEAT_GUI_GNOME | 3573 #ifdef FEAT_GUI_GNOME |
3583 /* Initialize the GNOME libraries. gnome_program_init()/gnome_init() | 3574 // Initialize the GNOME libraries. gnome_program_init()/gnome_init() |
3584 * exits on failure, but that's a non-issue because we already called | 3575 // exits on failure, but that's a non-issue because we already called |
3585 * gtk_init_check() in gui_mch_init_check(). */ | 3576 // gtk_init_check() in gui_mch_init_check(). |
3586 if (using_gnome) | 3577 if (using_gnome) |
3587 { | 3578 { |
3588 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, | 3579 gnome_program_init(VIMPACKAGE, VIM_VERSION_SHORT, |
3589 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); | 3580 LIBGNOMEUI_MODULE, gui_argc, gui_argv, NULL); |
3590 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) | 3581 # if defined(FEAT_FLOAT) && defined(LC_NUMERIC) |
3591 { | 3582 { |
3592 char *p = setlocale(LC_NUMERIC, NULL); | 3583 char *p = setlocale(LC_NUMERIC, NULL); |
3593 | 3584 |
3594 /* Make sure strtod() uses a decimal point, not a comma. Gnome | 3585 // Make sure strtod() uses a decimal point, not a comma. Gnome |
3595 * init may change it. */ | 3586 // init may change it. |
3596 if (p == NULL || strcmp(p, "C") != 0) | 3587 if (p == NULL || strcmp(p, "C") != 0) |
3597 setlocale(LC_NUMERIC, "C"); | 3588 setlocale(LC_NUMERIC, "C"); |
3598 } | 3589 } |
3599 # endif | 3590 # endif |
3600 } | 3591 } |
3601 #endif | 3592 #endif |
3602 VIM_CLEAR(gui_argv); | 3593 VIM_CLEAR(gui_argv); |
3603 | 3594 |
3604 #if GLIB_CHECK_VERSION(2,1,3) | 3595 #if GLIB_CHECK_VERSION(2,1,3) |
3605 /* Set the human-readable application name */ | 3596 // Set the human-readable application name |
3606 g_set_application_name("Vim"); | 3597 g_set_application_name("Vim"); |
3607 #endif | 3598 #endif |
3608 /* | 3599 /* |
3609 * Force UTF-8 output no matter what the value of 'encoding' is. | 3600 * Force UTF-8 output no matter what the value of 'encoding' is. |
3610 * did_set_string_option() in option.c prohibits changing 'termencoding' | 3601 * did_set_string_option() in option.c prohibits changing 'termencoding' |
3613 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); | 3604 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0); |
3614 | 3605 |
3615 #ifdef FEAT_TOOLBAR | 3606 #ifdef FEAT_TOOLBAR |
3616 gui_gtk_register_stock_icons(); | 3607 gui_gtk_register_stock_icons(); |
3617 #endif | 3608 #endif |
3618 /* FIXME: Need to install the classic icons and a gtkrc.classic file. | 3609 // FIXME: Need to install the classic icons and a gtkrc.classic file. |
3619 * The hard part is deciding install locations and the Makefile magic. */ | 3610 // The hard part is deciding install locations and the Makefile magic. |
3620 #if !GTK_CHECK_VERSION(3,0,0) | 3611 #if !GTK_CHECK_VERSION(3,0,0) |
3621 # if 0 | 3612 # if 0 |
3622 gtk_rc_parse("gtkrc"); | 3613 gtk_rc_parse("gtkrc"); |
3623 # endif | 3614 # endif |
3624 #endif | 3615 #endif |
3625 | 3616 |
3626 /* Initialize values */ | 3617 // Initialize values |
3627 gui.border_width = 2; | 3618 gui.border_width = 2; |
3628 gui.scrollbar_width = SB_DEFAULT_WIDTH; | 3619 gui.scrollbar_width = SB_DEFAULT_WIDTH; |
3629 gui.scrollbar_height = SB_DEFAULT_WIDTH; | 3620 gui.scrollbar_height = SB_DEFAULT_WIDTH; |
3630 #if GTK_CHECK_VERSION(3,0,0) | 3621 #if GTK_CHECK_VERSION(3,0,0) |
3631 gui.fgcolor = g_new(GdkRGBA, 1); | 3622 gui.fgcolor = g_new(GdkRGBA, 1); |
3632 gui.bgcolor = g_new(GdkRGBA, 1); | 3623 gui.bgcolor = g_new(GdkRGBA, 1); |
3633 gui.spcolor = g_new(GdkRGBA, 1); | 3624 gui.spcolor = g_new(GdkRGBA, 1); |
3634 #else | 3625 #else |
3635 /* LINTED: avoid warning: conversion to 'unsigned long' */ | 3626 // LINTED: avoid warning: conversion to 'unsigned long' |
3636 gui.fgcolor = g_new0(GdkColor, 1); | 3627 gui.fgcolor = g_new0(GdkColor, 1); |
3637 /* LINTED: avoid warning: conversion to 'unsigned long' */ | 3628 // LINTED: avoid warning: conversion to 'unsigned long' |
3638 gui.bgcolor = g_new0(GdkColor, 1); | 3629 gui.bgcolor = g_new0(GdkColor, 1); |
3639 /* LINTED: avoid warning: conversion to 'unsigned long' */ | 3630 // LINTED: avoid warning: conversion to 'unsigned long' |
3640 gui.spcolor = g_new0(GdkColor, 1); | 3631 gui.spcolor = g_new0(GdkColor, 1); |
3641 #endif | 3632 #endif |
3642 | 3633 |
3643 /* Initialise atoms */ | 3634 // Initialise atoms |
3644 html_atom = gdk_atom_intern("text/html", FALSE); | 3635 html_atom = gdk_atom_intern("text/html", FALSE); |
3645 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); | 3636 utf8_string_atom = gdk_atom_intern("UTF8_STRING", FALSE); |
3646 | 3637 |
3647 /* Set default foreground and background colors. */ | 3638 // Set default foreground and background colors. |
3648 gui.norm_pixel = gui.def_norm_pixel; | 3639 gui.norm_pixel = gui.def_norm_pixel; |
3649 gui.back_pixel = gui.def_back_pixel; | 3640 gui.back_pixel = gui.def_back_pixel; |
3650 | 3641 |
3651 if (gtk_socket_id != 0) | 3642 if (gtk_socket_id != 0) |
3652 { | 3643 { |
3653 GtkWidget *plug; | 3644 GtkWidget *plug; |
3654 | 3645 |
3655 /* Use GtkSocket from another app. */ | 3646 // Use GtkSocket from another app. |
3656 plug = gtk_plug_new_for_display(gdk_display_get_default(), | 3647 plug = gtk_plug_new_for_display(gdk_display_get_default(), |
3657 gtk_socket_id); | 3648 gtk_socket_id); |
3658 if (plug != NULL && gtk_plug_get_socket_window(GTK_PLUG(plug)) != NULL) | 3649 if (plug != NULL && gtk_plug_get_socket_window(GTK_PLUG(plug)) != NULL) |
3659 { | 3650 { |
3660 gui.mainwin = plug; | 3651 gui.mainwin = plug; |
3661 } | 3652 } |
3662 else | 3653 else |
3663 { | 3654 { |
3664 g_warning("Connection to GTK+ socket (ID %u) failed", | 3655 g_warning("Connection to GTK+ socket (ID %u) failed", |
3665 (unsigned int)gtk_socket_id); | 3656 (unsigned int)gtk_socket_id); |
3666 /* Pretend we never wanted it if it failed (get own window) */ | 3657 // Pretend we never wanted it if it failed (get own window) |
3667 gtk_socket_id = 0; | 3658 gtk_socket_id = 0; |
3668 } | 3659 } |
3669 } | 3660 } |
3670 | 3661 |
3671 if (gtk_socket_id == 0) | 3662 if (gtk_socket_id == 0) |
3673 #ifdef FEAT_GUI_GNOME | 3664 #ifdef FEAT_GUI_GNOME |
3674 if (using_gnome) | 3665 if (using_gnome) |
3675 { | 3666 { |
3676 gui.mainwin = gnome_app_new("Vim", NULL); | 3667 gui.mainwin = gnome_app_new("Vim", NULL); |
3677 # ifdef USE_XSMP | 3668 # ifdef USE_XSMP |
3678 /* Use the GNOME save-yourself functionality now. */ | 3669 // Use the GNOME save-yourself functionality now. |
3679 xsmp_close(); | 3670 xsmp_close(); |
3680 # endif | 3671 # endif |
3681 } | 3672 } |
3682 else | 3673 else |
3683 #endif | 3674 #endif |
3684 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 3675 gui.mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
3685 } | 3676 } |
3686 | 3677 |
3687 gtk_widget_set_name(gui.mainwin, "vim-main-window"); | 3678 gtk_widget_set_name(gui.mainwin, "vim-main-window"); |
3688 | 3679 |
3689 /* Create the PangoContext used for drawing all text. */ | 3680 // Create the PangoContext used for drawing all text. |
3690 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); | 3681 gui.text_context = gtk_widget_create_pango_context(gui.mainwin); |
3691 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); | 3682 pango_context_set_base_dir(gui.text_context, PANGO_DIRECTION_LTR); |
3692 | 3683 |
3693 gtk_container_set_border_width(GTK_CONTAINER(gui.mainwin), 0); | 3684 gtk_container_set_border_width(GTK_CONTAINER(gui.mainwin), 0); |
3694 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); | 3685 gtk_widget_add_events(gui.mainwin, GDK_VISIBILITY_NOTIFY_MASK); |
3703 G_CALLBACK(&mainwin_screen_changed_cb), NULL); | 3694 G_CALLBACK(&mainwin_screen_changed_cb), NULL); |
3704 | 3695 |
3705 gui.accel_group = gtk_accel_group_new(); | 3696 gui.accel_group = gtk_accel_group_new(); |
3706 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); | 3697 gtk_window_add_accel_group(GTK_WINDOW(gui.mainwin), gui.accel_group); |
3707 | 3698 |
3708 /* A vertical box holds the menubar, toolbar and main text window. */ | 3699 // A vertical box holds the menubar, toolbar and main text window. |
3709 #if GTK_CHECK_VERSION(3,2,0) | 3700 #if GTK_CHECK_VERSION(3,2,0) |
3710 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); | 3701 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3711 gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); | 3702 gtk_box_set_homogeneous(GTK_BOX(vbox), FALSE); |
3712 #else | 3703 #else |
3713 vbox = gtk_vbox_new(FALSE, 0); | 3704 vbox = gtk_vbox_new(FALSE, 0); |
3715 | 3706 |
3716 #ifdef FEAT_GUI_GNOME | 3707 #ifdef FEAT_GUI_GNOME |
3717 if (using_gnome) | 3708 if (using_gnome) |
3718 { | 3709 { |
3719 # if defined(FEAT_MENU) | 3710 # if defined(FEAT_MENU) |
3720 /* automagically restore menubar/toolbar placement */ | 3711 // automagically restore menubar/toolbar placement |
3721 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); | 3712 gnome_app_enable_layout_config(GNOME_APP(gui.mainwin), TRUE); |
3722 # endif | 3713 # endif |
3723 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); | 3714 gnome_app_set_contents(GNOME_APP(gui.mainwin), vbox); |
3724 } | 3715 } |
3725 else | 3716 else |
3734 * Create the menubar and handle | 3725 * Create the menubar and handle |
3735 */ | 3726 */ |
3736 gui.menubar = gtk_menu_bar_new(); | 3727 gui.menubar = gtk_menu_bar_new(); |
3737 gtk_widget_set_name(gui.menubar, "vim-menubar"); | 3728 gtk_widget_set_name(gui.menubar, "vim-menubar"); |
3738 | 3729 |
3739 /* Avoid that GTK takes <F10> away from us. */ | 3730 // Avoid that GTK takes <F10> away from us. |
3740 { | 3731 { |
3741 GtkSettings *gtk_settings; | 3732 GtkSettings *gtk_settings; |
3742 | 3733 |
3743 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); | 3734 gtk_settings = gtk_settings_get_for_screen(gdk_screen_get_default()); |
3744 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); | 3735 g_object_set(gtk_settings, "gtk-menu-bar-accel", NULL, NULL); |
3751 BonoboDockItem *dockitem; | 3742 BonoboDockItem *dockitem; |
3752 | 3743 |
3753 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); | 3744 gnome_app_set_menus(GNOME_APP(gui.mainwin), GTK_MENU_BAR(gui.menubar)); |
3754 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | 3745 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), |
3755 GNOME_APP_MENUBAR_NAME); | 3746 GNOME_APP_MENUBAR_NAME); |
3756 /* We don't want the menu to float. */ | 3747 // We don't want the menu to float. |
3757 bonobo_dock_item_set_behavior(dockitem, | 3748 bonobo_dock_item_set_behavior(dockitem, |
3758 bonobo_dock_item_get_behavior(dockitem) | 3749 bonobo_dock_item_get_behavior(dockitem) |
3759 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | 3750 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); |
3760 gui.menubar_h = GTK_WIDGET(dockitem); | 3751 gui.menubar_h = GTK_WIDGET(dockitem); |
3761 } | 3752 } |
3762 else | 3753 else |
3763 # endif /* FEAT_GUI_GNOME */ | 3754 # endif // FEAT_GUI_GNOME |
3764 { | 3755 { |
3765 /* Always show the menubar, otherwise <F10> doesn't work. It may be | 3756 // Always show the menubar, otherwise <F10> doesn't work. It may be |
3766 * disabled in gui_init() later. */ | 3757 // disabled in gui_init() later. |
3767 gtk_widget_show(gui.menubar); | 3758 gtk_widget_show(gui.menubar); |
3768 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); | 3759 gtk_box_pack_start(GTK_BOX(vbox), gui.menubar, FALSE, FALSE, 0); |
3769 } | 3760 } |
3770 #endif /* FEAT_MENU */ | 3761 #endif // FEAT_MENU |
3771 | 3762 |
3772 #ifdef FEAT_TOOLBAR | 3763 #ifdef FEAT_TOOLBAR |
3773 /* | 3764 /* |
3774 * Create the toolbar and handle | 3765 * Create the toolbar and handle |
3775 */ | 3766 */ |
3776 /* some aesthetics on the toolbar */ | 3767 // some aesthetics on the toolbar |
3777 # ifdef USE_GTK3 | 3768 # ifdef USE_GTK3 |
3778 /* TODO: Add GTK+ 3 code here using GtkCssProvider if necessary. */ | 3769 // TODO: Add GTK+ 3 code here using GtkCssProvider if necessary. |
3779 /* N.B. Since the default value of GtkToolbar::button-relief is | 3770 // N.B. Since the default value of GtkToolbar::button-relief is |
3780 * GTK_RELIEF_NONE, there's no need to specify that, probably. */ | 3771 // GTK_RELIEF_NONE, there's no need to specify that, probably. |
3781 # else | 3772 # else |
3782 gtk_rc_parse_string( | 3773 gtk_rc_parse_string( |
3783 "style \"vim-toolbar-style\" {\n" | 3774 "style \"vim-toolbar-style\" {\n" |
3784 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" | 3775 " GtkToolbar::button_relief = GTK_RELIEF_NONE\n" |
3785 "}\n" | 3776 "}\n" |
3796 | 3787 |
3797 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); | 3788 gnome_app_set_toolbar(GNOME_APP(gui.mainwin), GTK_TOOLBAR(gui.toolbar)); |
3798 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), | 3789 dockitem = gnome_app_get_dock_item_by_name(GNOME_APP(gui.mainwin), |
3799 GNOME_APP_TOOLBAR_NAME); | 3790 GNOME_APP_TOOLBAR_NAME); |
3800 gui.toolbar_h = GTK_WIDGET(dockitem); | 3791 gui.toolbar_h = GTK_WIDGET(dockitem); |
3801 /* When the toolbar is floating it gets stuck. So long as that isn't | 3792 // When the toolbar is floating it gets stuck. So long as that isn't |
3802 * fixed let's disallow floating. */ | 3793 // fixed let's disallow floating. |
3803 bonobo_dock_item_set_behavior(dockitem, | 3794 bonobo_dock_item_set_behavior(dockitem, |
3804 bonobo_dock_item_get_behavior(dockitem) | 3795 bonobo_dock_item_get_behavior(dockitem) |
3805 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); | 3796 | BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); |
3806 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); | 3797 gtk_container_set_border_width(GTK_CONTAINER(gui.toolbar), 0); |
3807 } | 3798 } |
3808 else | 3799 else |
3809 # endif /* FEAT_GUI_GNOME */ | 3800 # endif // FEAT_GUI_GNOME |
3810 { | 3801 { |
3811 if (vim_strchr(p_go, GO_TOOLBAR) != NULL | 3802 if (vim_strchr(p_go, GO_TOOLBAR) != NULL |
3812 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) | 3803 && (toolbar_flags & (TOOLBAR_TEXT | TOOLBAR_ICONS))) |
3813 gtk_widget_show(gui.toolbar); | 3804 gtk_widget_show(gui.toolbar); |
3814 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); | 3805 gtk_box_pack_start(GTK_BOX(vbox), gui.toolbar, FALSE, FALSE, 0); |
3815 } | 3806 } |
3816 #endif /* FEAT_TOOLBAR */ | 3807 #endif // FEAT_TOOLBAR |
3817 | 3808 |
3818 #ifdef FEAT_GUI_TABLINE | 3809 #ifdef FEAT_GUI_TABLINE |
3819 /* | 3810 /* |
3820 * Use a Notebook for the tab pages labels. The labels are hidden by | 3811 * Use a Notebook for the tab pages labels. The labels are hidden by |
3821 * default. | 3812 * default. |
3836 # endif | 3827 # endif |
3837 | 3828 |
3838 { | 3829 { |
3839 GtkWidget *page, *label, *event_box; | 3830 GtkWidget *page, *label, *event_box; |
3840 | 3831 |
3841 /* Add the first tab. */ | 3832 // Add the first tab. |
3842 # if GTK_CHECK_VERSION(3,2,0) | 3833 # if GTK_CHECK_VERSION(3,2,0) |
3843 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); | 3834 page = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); |
3844 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); | 3835 gtk_box_set_homogeneous(GTK_BOX(page), FALSE); |
3845 # else | 3836 # else |
3846 page = gtk_vbox_new(FALSE, 0); | 3837 page = gtk_vbox_new(FALSE, 0); |
3867 # if GTK_CHECK_VERSION(2,10,0) | 3858 # if GTK_CHECK_VERSION(2,10,0) |
3868 g_signal_connect(G_OBJECT(gui.tabline), "page-reordered", | 3859 g_signal_connect(G_OBJECT(gui.tabline), "page-reordered", |
3869 G_CALLBACK(on_tab_reordered), NULL); | 3860 G_CALLBACK(on_tab_reordered), NULL); |
3870 # endif | 3861 # endif |
3871 | 3862 |
3872 /* Create a popup menu for the tab line and connect it. */ | 3863 // Create a popup menu for the tab line and connect it. |
3873 tabline_menu = create_tabline_menu(); | 3864 tabline_menu = create_tabline_menu(); |
3874 g_signal_connect_swapped(G_OBJECT(gui.tabline), "button-press-event", | 3865 g_signal_connect_swapped(G_OBJECT(gui.tabline), "button-press-event", |
3875 G_CALLBACK(on_tabline_menu), G_OBJECT(tabline_menu)); | 3866 G_CALLBACK(on_tabline_menu), G_OBJECT(tabline_menu)); |
3876 #endif /* FEAT_GUI_TABLINE */ | 3867 #endif // FEAT_GUI_TABLINE |
3877 | 3868 |
3878 gui.formwin = gtk_form_new(); | 3869 gui.formwin = gtk_form_new(); |
3879 gtk_container_set_border_width(GTK_CONTAINER(gui.formwin), 0); | 3870 gtk_container_set_border_width(GTK_CONTAINER(gui.formwin), 0); |
3880 #if !GTK_CHECK_VERSION(3,0,0) | 3871 #if !GTK_CHECK_VERSION(3,0,0) |
3881 gtk_widget_set_events(gui.formwin, GDK_EXPOSURE_MASK); | 3872 gtk_widget_set_events(gui.formwin, GDK_EXPOSURE_MASK); |
3888 #if GTK_CHECK_VERSION(3,0,0) | 3879 #if GTK_CHECK_VERSION(3,0,0) |
3889 gui.surface = NULL; | 3880 gui.surface = NULL; |
3890 gui.by_signal = FALSE; | 3881 gui.by_signal = FALSE; |
3891 #endif | 3882 #endif |
3892 | 3883 |
3893 /* Determine which events we will filter. */ | 3884 // Determine which events we will filter. |
3894 gtk_widget_set_events(gui.drawarea, | 3885 gtk_widget_set_events(gui.drawarea, |
3895 GDK_EXPOSURE_MASK | | 3886 GDK_EXPOSURE_MASK | |
3896 GDK_ENTER_NOTIFY_MASK | | 3887 GDK_ENTER_NOTIFY_MASK | |
3897 GDK_LEAVE_NOTIFY_MASK | | 3888 GDK_LEAVE_NOTIFY_MASK | |
3898 GDK_BUTTON_PRESS_MASK | | 3889 GDK_BUTTON_PRESS_MASK | |
3906 gtk_widget_show(gui.drawarea); | 3897 gtk_widget_show(gui.drawarea); |
3907 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); | 3898 gtk_form_put(GTK_FORM(gui.formwin), gui.drawarea, 0, 0); |
3908 gtk_widget_show(gui.formwin); | 3899 gtk_widget_show(gui.formwin); |
3909 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); | 3900 gtk_box_pack_start(GTK_BOX(vbox), gui.formwin, TRUE, TRUE, 0); |
3910 | 3901 |
3911 /* For GtkSockets, key-presses must go to the focus widget (drawarea) | 3902 // For GtkSockets, key-presses must go to the focus widget (drawarea) |
3912 * and not the window. */ | 3903 // and not the window. |
3913 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | 3904 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) |
3914 : G_OBJECT(gui.drawarea), | 3905 : G_OBJECT(gui.drawarea), |
3915 "key-press-event", | 3906 "key-press-event", |
3916 G_CALLBACK(key_press_event), NULL); | 3907 G_CALLBACK(key_press_event), NULL); |
3917 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) | 3908 #if defined(FEAT_XIM) || GTK_CHECK_VERSION(3,0,0) |
3918 /* Also forward key release events for the benefit of GTK+ 2 input | 3909 // Also forward key release events for the benefit of GTK+ 2 input |
3919 * modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. */ | 3910 // modules. Try CTRL-SHIFT-xdigits to enter a Unicode code point. |
3920 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) | 3911 g_signal_connect((gtk_socket_id == 0) ? G_OBJECT(gui.mainwin) |
3921 : G_OBJECT(gui.drawarea), | 3912 : G_OBJECT(gui.drawarea), |
3922 "key-release-event", | 3913 "key-release-event", |
3923 G_CALLBACK(&key_release_event), NULL); | 3914 G_CALLBACK(&key_release_event), NULL); |
3924 #endif | 3915 #endif |
3946 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); | 3937 wm_protocols_atom = gdk_atom_intern("WM_PROTOCOLS", FALSE); |
3947 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); | 3938 save_yourself_atom = gdk_atom_intern("WM_SAVE_YOURSELF", FALSE); |
3948 #endif | 3939 #endif |
3949 | 3940 |
3950 if (gtk_socket_id != 0) | 3941 if (gtk_socket_id != 0) |
3951 /* make sure keyboard input can go to the drawarea */ | 3942 // make sure keyboard input can go to the drawarea |
3952 gtk_widget_set_can_focus(gui.drawarea, TRUE); | 3943 gtk_widget_set_can_focus(gui.drawarea, TRUE); |
3953 | 3944 |
3954 /* | 3945 /* |
3955 * Set clipboard specific atoms | 3946 * Set clipboard specific atoms |
3956 */ | 3947 */ |
3984 G_CALLBACK(leave_notify_event), NULL); | 3975 G_CALLBACK(leave_notify_event), NULL); |
3985 g_signal_connect(G_OBJECT(gui.drawarea), "enter-notify-event", | 3976 g_signal_connect(G_OBJECT(gui.drawarea), "enter-notify-event", |
3986 G_CALLBACK(enter_notify_event), NULL); | 3977 G_CALLBACK(enter_notify_event), NULL); |
3987 } | 3978 } |
3988 | 3979 |
3989 /* Real windows can get focus ... GtkPlug, being a mere container can't, | 3980 // Real windows can get focus ... GtkPlug, being a mere container can't, |
3990 * only its widgets. Arguably, this could be common code and we not use | 3981 // only its widgets. Arguably, this could be common code and we not use |
3991 * the window focus at all, but let's be safe. | 3982 // the window focus at all, but let's be safe. |
3992 */ | |
3993 if (gtk_socket_id == 0) | 3983 if (gtk_socket_id == 0) |
3994 { | 3984 { |
3995 g_signal_connect(G_OBJECT(gui.mainwin), "focus-out-event", | 3985 g_signal_connect(G_OBJECT(gui.mainwin), "focus-out-event", |
3996 G_CALLBACK(focus_out_event), NULL); | 3986 G_CALLBACK(focus_out_event), NULL); |
3997 g_signal_connect(G_OBJECT(gui.mainwin), "focus-in-event", | 3987 g_signal_connect(G_OBJECT(gui.mainwin), "focus-in-event", |
4006 #ifdef FEAT_GUI_TABLINE | 3996 #ifdef FEAT_GUI_TABLINE |
4007 g_signal_connect(G_OBJECT(gui.tabline), "focus-out-event", | 3997 g_signal_connect(G_OBJECT(gui.tabline), "focus-out-event", |
4008 G_CALLBACK(focus_out_event), NULL); | 3998 G_CALLBACK(focus_out_event), NULL); |
4009 g_signal_connect(G_OBJECT(gui.tabline), "focus-in-event", | 3999 g_signal_connect(G_OBJECT(gui.tabline), "focus-in-event", |
4010 G_CALLBACK(focus_in_event), NULL); | 4000 G_CALLBACK(focus_in_event), NULL); |
4011 #endif /* FEAT_GUI_TABLINE */ | 4001 #endif // FEAT_GUI_TABLINE |
4012 } | 4002 } |
4013 | 4003 |
4014 g_signal_connect(G_OBJECT(gui.drawarea), "motion-notify-event", | 4004 g_signal_connect(G_OBJECT(gui.drawarea), "motion-notify-event", |
4015 G_CALLBACK(motion_notify_event), NULL); | 4005 G_CALLBACK(motion_notify_event), NULL); |
4016 g_signal_connect(G_OBJECT(gui.drawarea), "button-press-event", | 4006 g_signal_connect(G_OBJECT(gui.drawarea), "button-press-event", |
4031 gui_gtk_set_selection_targets(); | 4021 gui_gtk_set_selection_targets(); |
4032 | 4022 |
4033 g_signal_connect(G_OBJECT(gui.drawarea), "selection-get", | 4023 g_signal_connect(G_OBJECT(gui.drawarea), "selection-get", |
4034 G_CALLBACK(selection_get_cb), NULL); | 4024 G_CALLBACK(selection_get_cb), NULL); |
4035 | 4025 |
4036 /* Pretend we don't have input focus, we will get an event if we do. */ | 4026 // Pretend we don't have input focus, we will get an event if we do. |
4037 gui.in_focus = FALSE; | 4027 gui.in_focus = FALSE; |
4038 | 4028 |
4039 // Handle changes to the "Xft/DPI" setting. | 4029 // Handle changes to the "Xft/DPI" setting. |
4040 { | 4030 { |
4041 GtkSettings *gtk_settings = | 4031 GtkSettings *gtk_settings = |
4084 set_cairo_source_rgba_from_color(cairo_t *cr, guicolor_T color) | 4074 set_cairo_source_rgba_from_color(cairo_t *cr, guicolor_T color) |
4085 { | 4075 { |
4086 const GdkRGBA rgba = color_to_rgba(color); | 4076 const GdkRGBA rgba = color_to_rgba(color); |
4087 cairo_set_source_rgba(cr, rgba.red, rgba.green, rgba.blue, rgba.alpha); | 4077 cairo_set_source_rgba(cr, rgba.red, rgba.green, rgba.blue, rgba.alpha); |
4088 } | 4078 } |
4089 #endif /* GTK_CHECK_VERSION(3,0,0) */ | 4079 #endif // GTK_CHECK_VERSION(3,0,0) |
4090 | 4080 |
4091 /* | 4081 /* |
4092 * Called when the foreground or background color has been changed. | 4082 * Called when the foreground or background color has been changed. |
4093 * This used to change the graphics contexts directly but we are | 4083 * This used to change the graphics contexts directly but we are |
4094 * currently manipulating them where desired. | 4084 * currently manipulating them where desired. |
4118 gtk_style_context_add_provider(context, | 4108 gtk_style_context_add_provider(context, |
4119 GTK_STYLE_PROVIDER(provider), G_MAXUINT); | 4109 GTK_STYLE_PROVIDER(provider), G_MAXUINT); |
4120 | 4110 |
4121 g_free(css); | 4111 g_free(css); |
4122 g_object_unref(provider); | 4112 g_object_unref(provider); |
4123 #elif GTK_CHECK_VERSION(3,4,0) /* !GTK_CHECK_VERSION(3,22,2) */ | 4113 #elif GTK_CHECK_VERSION(3,4,0) // !GTK_CHECK_VERSION(3,22,2) |
4124 GdkRGBA rgba; | 4114 GdkRGBA rgba; |
4125 | 4115 |
4126 rgba = color_to_rgba(gui.back_pixel); | 4116 rgba = color_to_rgba(gui.back_pixel); |
4127 { | 4117 { |
4128 cairo_pattern_t * const pat = cairo_pattern_create_rgba( | 4118 cairo_pattern_t * const pat = cairo_pattern_create_rgba( |
4133 cairo_pattern_destroy(pat); | 4123 cairo_pattern_destroy(pat); |
4134 } | 4124 } |
4135 else | 4125 else |
4136 gdk_window_set_background_rgba(da_win, &rgba); | 4126 gdk_window_set_background_rgba(da_win, &rgba); |
4137 } | 4127 } |
4138 #else /* !GTK_CHECK_VERSION(3,4,0) */ | 4128 #else // !GTK_CHECK_VERSION(3,4,0) |
4139 GdkColor color = { 0, 0, 0, 0 }; | 4129 GdkColor color = { 0, 0, 0, 0 }; |
4140 | 4130 |
4141 color.pixel = gui.back_pixel; | 4131 color.pixel = gui.back_pixel; |
4142 gdk_window_set_background(da_win, &color); | 4132 gdk_window_set_background(da_win, &color); |
4143 #endif /* !GTK_CHECK_VERSION(3,22,2) */ | 4133 #endif // !GTK_CHECK_VERSION(3,22,2) |
4144 } | 4134 } |
4145 } | 4135 } |
4146 | 4136 |
4147 /* | 4137 /* |
4148 * This signal informs us about the need to rearrange our sub-widgets. | 4138 * This signal informs us about the need to rearrange our sub-widgets. |
4153 gpointer data UNUSED) | 4143 gpointer data UNUSED) |
4154 { | 4144 { |
4155 int usable_height = event->height; | 4145 int usable_height = event->height; |
4156 | 4146 |
4157 #if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) | 4147 #if GTK_CHECK_VERSION(3,22,2) && !GTK_CHECK_VERSION(3,22,4) |
4158 /* As of 3.22.2, GdkWindows have started distributing configure events to | 4148 // As of 3.22.2, GdkWindows have started distributing configure events to |
4159 * their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). | 4149 // their "native" children (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=12579fe71b3b8f79eb9c1b80e429443bcc437dd0). |
4160 * | 4150 // |
4161 * As can be seen from the implementation of move_native_children() and | 4151 // As can be seen from the implementation of move_native_children() and |
4162 * configure_native_child() in gdkwindow.c, those functions actually | 4152 // configure_native_child() in gdkwindow.c, those functions actually |
4163 * propagate configure events to every child, failing to distinguish | 4153 // propagate configure events to every child, failing to distinguish |
4164 * "native" one from non-native one. | 4154 // "native" one from non-native one. |
4165 * | 4155 // |
4166 * Naturally, configure events propagated to here like that are fallacious | 4156 // Naturally, configure events propagated to here like that are fallacious |
4167 * and, as a matter of fact, they trigger a geometric collapse of | 4157 // and, as a matter of fact, they trigger a geometric collapse of |
4168 * gui.formwin. | 4158 // gui.formwin. |
4169 * | 4159 // |
4170 * To filter out such fallacious events, check if the given event is the | 4160 // To filter out such fallacious events, check if the given event is the |
4171 * one that was sent out to the right place. Ignore it if not. | 4161 // one that was sent out to the right place. Ignore it if not. |
4172 */ | 4162 // |
4173 /* Follow-up | 4163 // Follow-up |
4174 * After a few weeks later, the GdkWindow change mentioned above was | 4164 // After a few weeks later, the GdkWindow change mentioned above was |
4175 * reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). | 4165 // reverted (https://git.gnome.org/browse/gtk+/commit/?h=gtk-3-22&id=f70039cb9603a02d2369fec4038abf40a1711155). |
4176 * The corresponding official release is 3.22.4. */ | 4166 // The corresponding official release is 3.22.4. |
4177 if (event->window != gtk_widget_get_window(gui.formwin)) | 4167 if (event->window != gtk_widget_get_window(gui.formwin)) |
4178 return TRUE; | 4168 return TRUE; |
4179 #endif | 4169 #endif |
4180 | 4170 |
4181 /* When in a GtkPlug, we can't guarantee valid heights (as a round | 4171 // When in a GtkPlug, we can't guarantee valid heights (as a round |
4182 * no. of char-heights), so we have to manually sanitise them. | 4172 // no. of char-heights), so we have to manually sanitise them. |
4183 * Widths seem to sort themselves out, don't ask me why. | 4173 // Widths seem to sort themselves out, don't ask me why. |
4184 */ | |
4185 if (gtk_socket_id != 0) | 4174 if (gtk_socket_id != 0) |
4186 usable_height -= (gui.char_height - (gui.char_height/2)); /* sic. */ | 4175 usable_height -= (gui.char_height - (gui.char_height/2)); // sic. |
4187 | 4176 |
4188 gtk_form_freeze(GTK_FORM(gui.formwin)); | 4177 gtk_form_freeze(GTK_FORM(gui.formwin)); |
4189 gui_resize_shell(event->width, usable_height); | 4178 gui_resize_shell(event->width, usable_height); |
4190 gtk_form_thaw(GTK_FORM(gui.formwin)); | 4179 gtk_form_thaw(GTK_FORM(gui.formwin)); |
4191 | 4180 |
4198 * since the window is already inevitably going away. | 4187 * since the window is already inevitably going away. |
4199 */ | 4188 */ |
4200 static void | 4189 static void |
4201 mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED) | 4190 mainwin_destroy_cb(GObject *object UNUSED, gpointer data UNUSED) |
4202 { | 4191 { |
4203 /* Don't write messages to the GUI anymore */ | 4192 // Don't write messages to the GUI anymore |
4204 full_screen = FALSE; | 4193 full_screen = FALSE; |
4205 | 4194 |
4206 gui.mainwin = NULL; | 4195 gui.mainwin = NULL; |
4207 gui.drawarea = NULL; | 4196 gui.drawarea = NULL; |
4208 | 4197 |
4209 if (!exiting) /* only do anything if the destroy was unexpected */ | 4198 if (!exiting) // only do anything if the destroy was unexpected |
4210 { | 4199 { |
4211 vim_strncpy(IObuff, | 4200 vim_strncpy(IObuff, |
4212 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), | 4201 (char_u *)_("Vim: Main window unexpectedly destroyed\n"), |
4213 IOSIZE - 1); | 4202 IOSIZE - 1); |
4214 preserve_exit(); | 4203 preserve_exit(); |
4234 static timeout_cb_type | 4223 static timeout_cb_type |
4235 check_startup_plug_hints(gpointer data UNUSED) | 4224 check_startup_plug_hints(gpointer data UNUSED) |
4236 { | 4225 { |
4237 if (init_window_hints_state == 1) | 4226 if (init_window_hints_state == 1) |
4238 { | 4227 { |
4239 /* Safe to use normal hints now */ | 4228 // Safe to use normal hints now |
4240 init_window_hints_state = 0; | 4229 init_window_hints_state = 0; |
4241 update_window_manager_hints(0, 0); | 4230 update_window_manager_hints(0, 0); |
4242 return FALSE; /* stop timer */ | 4231 return FALSE; // stop timer |
4243 } | 4232 } |
4244 | 4233 |
4245 /* Keep on trying */ | 4234 // Keep on trying |
4246 init_window_hints_state = 1; | 4235 init_window_hints_state = 1; |
4247 return TRUE; | 4236 return TRUE; |
4248 } | 4237 } |
4249 | 4238 |
4250 /* | 4239 /* |
4269 } | 4258 } |
4270 else | 4259 else |
4271 { | 4260 { |
4272 char *role; | 4261 char *role; |
4273 | 4262 |
4274 /* Invent a unique-enough ID string for the role */ | 4263 // Invent a unique-enough ID string for the role |
4275 role = g_strdup_printf("vim-%u-%u-%u", | 4264 role = g_strdup_printf("vim-%u-%u-%u", |
4276 (unsigned)mch_get_pid(), | 4265 (unsigned)mch_get_pid(), |
4277 (unsigned)g_random_int(), | 4266 (unsigned)g_random_int(), |
4278 (unsigned)time(NULL)); | 4267 (unsigned)time(NULL)); |
4279 | 4268 |
4282 } | 4271 } |
4283 | 4272 |
4284 if (gui_win_x != -1 && gui_win_y != -1) | 4273 if (gui_win_x != -1 && gui_win_y != -1) |
4285 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); | 4274 gtk_window_move(GTK_WINDOW(gui.mainwin), gui_win_x, gui_win_y); |
4286 | 4275 |
4287 /* Determine user specified geometry, if present. */ | 4276 // Determine user specified geometry, if present. |
4288 if (gui.geom != NULL) | 4277 if (gui.geom != NULL) |
4289 { | 4278 { |
4290 int mask; | 4279 int mask; |
4291 unsigned int w, h; | 4280 unsigned int w, h; |
4292 int x = 0; | 4281 int x = 0; |
4322 y += hh - pixel_height; | 4311 y += hh - pixel_height; |
4323 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); | 4312 gtk_window_move(GTK_WINDOW(gui.mainwin), x, y); |
4324 } | 4313 } |
4325 VIM_CLEAR(gui.geom); | 4314 VIM_CLEAR(gui.geom); |
4326 | 4315 |
4327 /* From now until everyone's stopped trying to set the window hints | 4316 // From now until everyone's stopped trying to set the window hints |
4328 * to their correct minimum values, stop them being set as we need | 4317 // to their correct minimum values, stop them being set as we need |
4329 * them to remain at our required size for the parent GtkSocket to | 4318 // them to remain at our required size for the parent GtkSocket to |
4330 * give us the right initial size. | 4319 // give us the right initial size. |
4331 */ | |
4332 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) | 4320 if (gtk_socket_id != 0 && (mask & WidthValue || mask & HeightValue)) |
4333 { | 4321 { |
4334 update_window_manager_hints(pixel_width, pixel_height); | 4322 update_window_manager_hints(pixel_width, pixel_height); |
4335 init_window_hints_state = 1; | 4323 init_window_hints_state = 1; |
4336 timeout_add(1000, check_startup_plug_hints, NULL); | 4324 timeout_add(1000, check_startup_plug_hints, NULL); |
4337 } | 4325 } |
4338 } | 4326 } |
4339 | 4327 |
4340 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); | 4328 pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width); |
4341 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); | 4329 pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height); |
4342 /* For GTK2 changing the size of the form widget doesn't cause window | 4330 // For GTK2 changing the size of the form widget doesn't cause window |
4343 * resizing. */ | 4331 // resizing. |
4344 if (gtk_socket_id == 0) | 4332 if (gtk_socket_id == 0) |
4345 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); | 4333 gtk_window_resize(GTK_WINDOW(gui.mainwin), pixel_width, pixel_height); |
4346 update_window_manager_hints(0, 0); | 4334 update_window_manager_hints(0, 0); |
4347 | 4335 |
4348 if (foreground_argument != NULL) | 4336 if (foreground_argument != NULL) |
4364 { | 4352 { |
4365 gui.def_norm_pixel = fg_pixel; | 4353 gui.def_norm_pixel = fg_pixel; |
4366 gui.def_back_pixel = bg_pixel; | 4354 gui.def_back_pixel = bg_pixel; |
4367 } | 4355 } |
4368 | 4356 |
4369 /* Get the colors from the "Normal" and "Menu" group (set in syntax.c or | 4357 // Get the colors from the "Normal" and "Menu" group (set in syntax.c or |
4370 * in a vimrc file) */ | 4358 // in a vimrc file) |
4371 set_normal_colors(); | 4359 set_normal_colors(); |
4372 | 4360 |
4373 /* Check that none of the colors are the same as the background color */ | 4361 // Check that none of the colors are the same as the background color |
4374 gui_check_colors(); | 4362 gui_check_colors(); |
4375 | 4363 |
4376 /* Get the colors for the highlight groups (gui_check_colors() might have | 4364 // Get the colors for the highlight groups (gui_check_colors() might have |
4377 * changed them). */ | 4365 // changed them). |
4378 highlight_gui_started(); /* re-init colors and fonts */ | 4366 highlight_gui_started(); // re-init colors and fonts |
4379 | 4367 |
4380 g_signal_connect(G_OBJECT(gui.mainwin), "destroy", | 4368 g_signal_connect(G_OBJECT(gui.mainwin), "destroy", |
4381 G_CALLBACK(mainwin_destroy_cb), NULL); | 4369 G_CALLBACK(mainwin_destroy_cb), NULL); |
4382 | 4370 |
4383 /* | 4371 /* |
4392 */ | 4380 */ |
4393 g_signal_connect(G_OBJECT(gui.formwin), "configure-event", | 4381 g_signal_connect(G_OBJECT(gui.formwin), "configure-event", |
4394 G_CALLBACK(form_configure_event), NULL); | 4382 G_CALLBACK(form_configure_event), NULL); |
4395 | 4383 |
4396 #ifdef FEAT_DND | 4384 #ifdef FEAT_DND |
4397 /* Set up for receiving DND items. */ | 4385 // Set up for receiving DND items. |
4398 gui_gtk_set_dnd_targets(); | 4386 gui_gtk_set_dnd_targets(); |
4399 | 4387 |
4400 g_signal_connect(G_OBJECT(gui.drawarea), "drag-data-received", | 4388 g_signal_connect(G_OBJECT(gui.drawarea), "drag-data-received", |
4401 G_CALLBACK(drag_data_received_cb), NULL); | 4389 G_CALLBACK(drag_data_received_cb), NULL); |
4402 #endif | 4390 #endif |
4403 | 4391 |
4404 /* With GTK+ 2, we need to iconify the window before calling show() | 4392 // With GTK+ 2, we need to iconify the window before calling show() |
4405 * to avoid mapping the window for a short time. */ | 4393 // to avoid mapping the window for a short time. |
4406 if (found_iconic_arg && gtk_socket_id == 0) | 4394 if (found_iconic_arg && gtk_socket_id == 0) |
4407 gui_mch_iconify(); | 4395 gui_mch_iconify(); |
4408 | 4396 |
4409 { | 4397 { |
4410 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) | 4398 #if defined(FEAT_GUI_GNOME) && defined(FEAT_MENU) |
4508 | 4496 |
4509 gui_resize_shell(width, height); | 4497 gui_resize_shell(width, height); |
4510 } | 4498 } |
4511 | 4499 |
4512 resize_idle_installed = FALSE; | 4500 resize_idle_installed = FALSE; |
4513 return FALSE; /* don't call me again */ | 4501 return FALSE; // don't call me again |
4514 } | 4502 } |
4515 # endif | 4503 # endif |
4516 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 4504 #endif // !GTK_CHECK_VERSION(3,0,0) |
4517 | 4505 |
4518 /* | 4506 /* |
4519 * Return TRUE if the main window is maximized. | 4507 * Return TRUE if the main window is maximized. |
4520 */ | 4508 */ |
4521 int | 4509 int |
4559 gui_mch_set_shellsize(int width, int height, | 4547 gui_mch_set_shellsize(int width, int height, |
4560 int min_width UNUSED, int min_height UNUSED, | 4548 int min_width UNUSED, int min_height UNUSED, |
4561 int base_width UNUSED, int base_height UNUSED, | 4549 int base_width UNUSED, int base_height UNUSED, |
4562 int direction UNUSED) | 4550 int direction UNUSED) |
4563 { | 4551 { |
4564 /* give GTK+ a chance to put all widget's into place */ | 4552 // give GTK+ a chance to put all widget's into place |
4565 gui_mch_update(); | 4553 gui_mch_update(); |
4566 | 4554 |
4567 /* this will cause the proper resizement to happen too */ | 4555 // this will cause the proper resizement to happen too |
4568 if (gtk_socket_id == 0) | 4556 if (gtk_socket_id == 0) |
4569 update_window_manager_hints(0, 0); | 4557 update_window_manager_hints(0, 0); |
4570 | 4558 |
4571 /* With GTK+ 2, changing the size of the form widget doesn't resize | 4559 // With GTK+ 2, changing the size of the form widget doesn't resize |
4572 * the window. So let's do it the other way around and resize the | 4560 // the window. So let's do it the other way around and resize the |
4573 * main window instead. */ | 4561 // main window instead. |
4574 width += get_menu_tool_width(); | 4562 width += get_menu_tool_width(); |
4575 height += get_menu_tool_height(); | 4563 height += get_menu_tool_height(); |
4576 | 4564 |
4577 if (gtk_socket_id == 0) | 4565 if (gtk_socket_id == 0) |
4578 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); | 4566 gtk_window_resize(GTK_WINDOW(gui.mainwin), width, height); |
4586 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, | 4574 g_idle_add_full(GDK_PRIORITY_EVENTS + 10, |
4587 &force_shell_resize_idle, NULL, NULL); | 4575 &force_shell_resize_idle, NULL, NULL); |
4588 resize_idle_installed = TRUE; | 4576 resize_idle_installed = TRUE; |
4589 } | 4577 } |
4590 # endif | 4578 # endif |
4591 # endif /* !GTK_CHECK_VERSION(3,0,0) */ | 4579 # endif // !GTK_CHECK_VERSION(3,0,0) |
4592 /* | 4580 /* |
4593 * Wait until all events are processed to prevent a crash because the | 4581 * Wait until all events are processed to prevent a crash because the |
4594 * real size of the drawing area doesn't reflect Vim's internal ideas. | 4582 * real size of the drawing area doesn't reflect Vim's internal ideas. |
4595 * | 4583 * |
4596 * This is a bit of a hack, since Vim is a terminal application with a GUI | 4584 * This is a bit of a hack, since Vim is a terminal application with a GUI |
4641 { | 4629 { |
4642 int x, y; | 4630 int x, y; |
4643 | 4631 |
4644 gui_gtk_get_screen_geom_of_win(gui.mainwin, &x, &y, screen_w, screen_h); | 4632 gui_gtk_get_screen_geom_of_win(gui.mainwin, &x, &y, screen_w, screen_h); |
4645 | 4633 |
4646 /* Subtract 'guiheadroom' from the height to allow some room for the | 4634 // Subtract 'guiheadroom' from the height to allow some room for the |
4647 * window manager (task list and window title bar). */ | 4635 // window manager (task list and window title bar). |
4648 *screen_h -= p_ghr; | 4636 *screen_h -= p_ghr; |
4649 | 4637 |
4650 /* | 4638 /* |
4651 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include | 4639 * FIXME: dirty trick: Because the gui_get_base_height() doesn't include |
4652 * the toolbar and menubar for GTK, we subtract them from the screen | 4640 * the toolbar and menubar for GTK, we subtract them from the screen |
4667 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); | 4655 gtk_window_set_title(GTK_WINDOW(gui.mainwin), (const char *)title); |
4668 | 4656 |
4669 if (output_conv.vc_type != CONV_NONE) | 4657 if (output_conv.vc_type != CONV_NONE) |
4670 vim_free(title); | 4658 vim_free(title); |
4671 } | 4659 } |
4672 #endif /* FEAT_TITLE */ | 4660 #endif // FEAT_TITLE |
4673 | 4661 |
4674 #if defined(FEAT_MENU) || defined(PROTO) | 4662 #if defined(FEAT_MENU) || defined(PROTO) |
4675 void | 4663 void |
4676 gui_mch_enable_menu(int showit) | 4664 gui_mch_enable_menu(int showit) |
4677 { | 4665 { |
4682 widget = gui.menubar_h; | 4670 widget = gui.menubar_h; |
4683 else | 4671 else |
4684 # endif | 4672 # endif |
4685 widget = gui.menubar; | 4673 widget = gui.menubar; |
4686 | 4674 |
4687 /* Do not disable the menu while starting up, otherwise F10 doesn't work. */ | 4675 // Do not disable the menu while starting up, otherwise F10 doesn't work. |
4688 if (!showit != !gtk_widget_get_visible(widget) && !gui.starting) | 4676 if (!showit != !gtk_widget_get_visible(widget) && !gui.starting) |
4689 { | 4677 { |
4690 if (showit) | 4678 if (showit) |
4691 gtk_widget_show(widget); | 4679 gtk_widget_show(widget); |
4692 else | 4680 else |
4693 gtk_widget_hide(widget); | 4681 gtk_widget_hide(widget); |
4694 | 4682 |
4695 update_window_manager_hints(0, 0); | 4683 update_window_manager_hints(0, 0); |
4696 } | 4684 } |
4697 } | 4685 } |
4698 #endif /* FEAT_MENU */ | 4686 #endif // FEAT_MENU |
4699 | 4687 |
4700 #if defined(FEAT_TOOLBAR) || defined(PROTO) | 4688 #if defined(FEAT_TOOLBAR) || defined(PROTO) |
4701 void | 4689 void |
4702 gui_mch_show_toolbar(int showit) | 4690 gui_mch_show_toolbar(int showit) |
4703 { | 4691 { |
4724 gtk_widget_hide(widget); | 4712 gtk_widget_hide(widget); |
4725 | 4713 |
4726 update_window_manager_hints(0, 0); | 4714 update_window_manager_hints(0, 0); |
4727 } | 4715 } |
4728 } | 4716 } |
4729 #endif /* FEAT_TOOLBAR */ | 4717 #endif // FEAT_TOOLBAR |
4730 | 4718 |
4731 /* | 4719 /* |
4732 * Check if a given font is a CJK font. This is done in a very crude manner. It | 4720 * Check if a given font is a CJK font. This is done in a very crude manner. It |
4733 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given | 4721 * just see if U+04E00 for zh and ja and U+AC00 for ko are covered in a given |
4734 * font. Consequently, this function cannot be used as a general purpose check | 4722 * font. Consequently, this function cannot be used as a general purpose check |
4788 | 4776 |
4789 pango_font_metrics_unref(metrics); | 4777 pango_font_metrics_unref(metrics); |
4790 | 4778 |
4791 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE | 4779 gui.char_height = (ascent + descent + PANGO_SCALE - 1) / PANGO_SCALE |
4792 + p_linespace; | 4780 + p_linespace; |
4793 /* LINTED: avoid warning: bitwise operation on signed value */ | 4781 // LINTED: avoid warning: bitwise operation on signed value |
4794 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); | 4782 gui.char_ascent = PANGO_PIXELS(ascent + p_linespace * PANGO_SCALE / 2); |
4795 | 4783 |
4796 /* A not-positive value of char_height may crash Vim. Only happens | 4784 // A not-positive value of char_height may crash Vim. Only happens |
4797 * if 'linespace' is negative (which does make sense sometimes). */ | 4785 // if 'linespace' is negative (which does make sense sometimes). |
4798 gui.char_ascent = MAX(gui.char_ascent, 0); | 4786 gui.char_ascent = MAX(gui.char_ascent, 0); |
4799 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); | 4787 gui.char_height = MAX(gui.char_height, gui.char_ascent + 1); |
4800 | 4788 |
4801 return OK; | 4789 return OK; |
4802 } | 4790 } |
4803 | 4791 |
4804 #if GTK_CHECK_VERSION(3,0,0) | 4792 #if GTK_CHECK_VERSION(3,0,0) |
4805 /* Callback function used in gui_mch_font_dialog() */ | 4793 // Callback function used in gui_mch_font_dialog() |
4806 static gboolean | 4794 static gboolean |
4807 font_filter(const PangoFontFamily *family, | 4795 font_filter(const PangoFontFamily *family, |
4808 const PangoFontFace *face UNUSED, | 4796 const PangoFontFace *face UNUSED, |
4809 gpointer data UNUSED) | 4797 gpointer data UNUSED) |
4810 { | 4798 { |
4845 if (output_conv.vc_type != CONV_NONE) | 4833 if (output_conv.vc_type != CONV_NONE) |
4846 oldname = string_convert(&output_conv, oldval, NULL); | 4834 oldname = string_convert(&output_conv, oldval, NULL); |
4847 else | 4835 else |
4848 oldname = oldval; | 4836 oldname = oldval; |
4849 | 4837 |
4850 /* Annoying bug in GTK (or Pango): if the font name does not include a | 4838 // Annoying bug in GTK (or Pango): if the font name does not include a |
4851 * size, zero is used. Use default point size ten. */ | 4839 // size, zero is used. Use default point size ten. |
4852 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) | 4840 if (!vim_isdigit(oldname[STRLEN(oldname) - 1])) |
4853 { | 4841 { |
4854 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); | 4842 char_u *p = vim_strnsave(oldname, STRLEN(oldname) + 3); |
4855 | 4843 |
4856 if (p != NULL) | 4844 if (p != NULL) |
4896 #endif | 4884 #endif |
4897 if (name != NULL) | 4885 if (name != NULL) |
4898 { | 4886 { |
4899 char_u *p; | 4887 char_u *p; |
4900 | 4888 |
4901 /* Apparently some font names include a comma, need to escape | 4889 // Apparently some font names include a comma, need to escape |
4902 * that, because in 'guifont' it separates names. */ | 4890 // that, because in 'guifont' it separates names. |
4903 p = vim_strsave_escaped((char_u *)name, (char_u *)","); | 4891 p = vim_strsave_escaped((char_u *)name, (char_u *)","); |
4904 g_free(name); | 4892 g_free(name); |
4905 if (p != NULL && input_conv.vc_type != CONV_NONE) | 4893 if (p != NULL && input_conv.vc_type != CONV_NONE) |
4906 { | 4894 { |
4907 fontname = string_convert(&input_conv, p, NULL); | 4895 fontname = string_convert(&input_conv, p, NULL); |
4983 g_object_unref(gui.ascii_font); | 4971 g_object_unref(gui.ascii_font); |
4984 | 4972 |
4985 gui.ascii_glyphs = NULL; | 4973 gui.ascii_glyphs = NULL; |
4986 gui.ascii_font = NULL; | 4974 gui.ascii_font = NULL; |
4987 | 4975 |
4988 /* For safety, fill in question marks for the control characters. | 4976 // For safety, fill in question marks for the control characters. |
4989 * Put a space between characters to avoid shaping. */ | 4977 // Put a space between characters to avoid shaping. |
4990 for (i = 0; i < 128; ++i) | 4978 for (i = 0; i < 128; ++i) |
4991 { | 4979 { |
4992 if (i >= 32 && i < 127) | 4980 if (i >= 32 && i < 127) |
4993 ascii_chars[2 * i] = i; | 4981 ascii_chars[2 * i] = i; |
4994 else | 4982 else |
4998 | 4986 |
4999 attr_list = pango_attr_list_new(); | 4987 attr_list = pango_attr_list_new(); |
5000 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, | 4988 item_list = pango_itemize(gui.text_context, (const char *)ascii_chars, |
5001 0, sizeof(ascii_chars), attr_list, NULL); | 4989 0, sizeof(ascii_chars), attr_list, NULL); |
5002 | 4990 |
5003 if (item_list != NULL && item_list->next == NULL) /* play safe */ | 4991 if (item_list != NULL && item_list->next == NULL) // play safe |
5004 { | 4992 { |
5005 PangoItem *item; | 4993 PangoItem *item; |
5006 int width; | 4994 int width; |
5007 | 4995 |
5008 item = (PangoItem *)item_list->data; | 4996 item = (PangoItem *)item_list->data; |
5009 width = gui.char_width * PANGO_SCALE; | 4997 width = gui.char_width * PANGO_SCALE; |
5010 | 4998 |
5011 /* Remember the shape engine used for ASCII. */ | 4999 // Remember the shape engine used for ASCII. |
5012 default_shape_engine = item->analysis.shape_engine; | 5000 default_shape_engine = item->analysis.shape_engine; |
5013 | 5001 |
5014 gui.ascii_font = item->analysis.font; | 5002 gui.ascii_font = item->analysis.font; |
5015 g_object_ref(gui.ascii_font); | 5003 g_object_ref(gui.ascii_font); |
5016 | 5004 |
5045 { | 5033 { |
5046 PangoFontDescription *font_desc; | 5034 PangoFontDescription *font_desc; |
5047 PangoLayout *layout; | 5035 PangoLayout *layout; |
5048 int width; | 5036 int width; |
5049 | 5037 |
5050 /* If font_name is NULL, this means to use the default, which should | 5038 // If font_name is NULL, this means to use the default, which should |
5051 * be present on all proper Pango/fontconfig installations. */ | 5039 // be present on all proper Pango/fontconfig installations. |
5052 if (font_name == NULL) | 5040 if (font_name == NULL) |
5053 font_name = (char_u *)DEFAULT_FONT; | 5041 font_name = (char_u *)DEFAULT_FONT; |
5054 | 5042 |
5055 font_desc = gui_mch_get_font(font_name, FALSE); | 5043 font_desc = gui_mch_get_font(font_name, FALSE); |
5056 | 5044 |
5086 */ | 5074 */ |
5087 if (is_cjk_font(gui.norm_font)) | 5075 if (is_cjk_font(gui.norm_font)) |
5088 { | 5076 { |
5089 int cjk_width; | 5077 int cjk_width; |
5090 | 5078 |
5091 /* Measure the text extent of U+4E00 and U+4E8C */ | 5079 // Measure the text extent of U+4E00 and U+4E8C |
5092 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); | 5080 pango_layout_set_text(layout, "\344\270\200\344\272\214", -1); |
5093 pango_layout_get_size(layout, &cjk_width, NULL); | 5081 pango_layout_get_size(layout, &cjk_width, NULL); |
5094 | 5082 |
5095 if (width == cjk_width) /* Xft not patched */ | 5083 if (width == cjk_width) // Xft not patched |
5096 width /= 2; | 5084 width /= 2; |
5097 } | 5085 } |
5098 g_object_unref(layout); | 5086 g_object_unref(layout); |
5099 | 5087 |
5100 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; | 5088 gui.char_width = (width / 2 + PANGO_SCALE - 1) / PANGO_SCALE; |
5101 | 5089 |
5102 /* A zero width may cause a crash. Happens for semi-invalid fontsets. */ | 5090 // A zero width may cause a crash. Happens for semi-invalid fontsets. |
5103 if (gui.char_width <= 0) | 5091 if (gui.char_width <= 0) |
5104 gui.char_width = 8; | 5092 gui.char_width = 8; |
5105 | 5093 |
5106 gui_mch_adjust_charheight(); | 5094 gui_mch_adjust_charheight(); |
5107 | 5095 |
5108 /* Set the fontname, which will be used for information purposes */ | 5096 // Set the fontname, which will be used for information purposes |
5109 hl_set_font_name(font_name); | 5097 hl_set_font_name(font_name); |
5110 | 5098 |
5111 get_styled_font_variants(); | 5099 get_styled_font_variants(); |
5112 ascii_glyph_table_init(); | 5100 ascii_glyph_table_init(); |
5113 | 5101 |
5114 /* Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. */ | 5102 // Avoid unnecessary overhead if 'guifontwide' is equal to 'guifont'. |
5115 if (gui.wide_font != NULL | 5103 if (gui.wide_font != NULL |
5116 && pango_font_description_equal(gui.norm_font, gui.wide_font)) | 5104 && pango_font_description_equal(gui.norm_font, gui.wide_font)) |
5117 { | 5105 { |
5118 pango_font_description_free(gui.wide_font); | 5106 pango_font_description_free(gui.wide_font); |
5119 gui.wide_font = NULL; | 5107 gui.wide_font = NULL; |
5120 } | 5108 } |
5121 | 5109 |
5122 if (gui_mch_maximized()) | 5110 if (gui_mch_maximized()) |
5123 { | 5111 { |
5124 /* Update lines and columns in accordance with the new font, keep the | 5112 // Update lines and columns in accordance with the new font, keep the |
5125 * window maximized. */ | 5113 // window maximized. |
5126 gui_mch_newfont(); | 5114 gui_mch_newfont(); |
5127 } | 5115 } |
5128 else | 5116 else |
5129 { | 5117 { |
5130 /* Preserve the logical dimensions of the screen. */ | 5118 // Preserve the logical dimensions of the screen. |
5131 update_window_manager_hints(0, 0); | 5119 update_window_manager_hints(0, 0); |
5132 } | 5120 } |
5133 | 5121 |
5134 return OK; | 5122 return OK; |
5135 } | 5123 } |
5141 GuiFont | 5129 GuiFont |
5142 gui_mch_get_font(char_u *name, int report_error) | 5130 gui_mch_get_font(char_u *name, int report_error) |
5143 { | 5131 { |
5144 PangoFontDescription *font; | 5132 PangoFontDescription *font; |
5145 | 5133 |
5146 /* can't do this when GUI is not running */ | 5134 // can't do this when GUI is not running |
5147 if (!gui.in_use || name == NULL) | 5135 if (!gui.in_use || name == NULL) |
5148 return NULL; | 5136 return NULL; |
5149 | 5137 |
5150 if (output_conv.vc_type != CONV_NONE) | 5138 if (output_conv.vc_type != CONV_NONE) |
5151 { | 5139 { |
5165 | 5153 |
5166 if (font != NULL) | 5154 if (font != NULL) |
5167 { | 5155 { |
5168 PangoFont *real_font; | 5156 PangoFont *real_font; |
5169 | 5157 |
5170 /* pango_context_load_font() bails out if no font size is set */ | 5158 // pango_context_load_font() bails out if no font size is set |
5171 if (pango_font_description_get_size(font) <= 0) | 5159 if (pango_font_description_get_size(font) <= 0) |
5172 pango_font_description_set_size(font, 10 * PANGO_SCALE); | 5160 pango_font_description_set_size(font, 10 * PANGO_SCALE); |
5173 | 5161 |
5174 real_font = pango_context_load_font(gui.text_context, font); | 5162 real_font = pango_context_load_font(gui.text_context, font); |
5175 | 5163 |
5233 guicolor_T | 5221 guicolor_T |
5234 gui_mch_get_color(char_u *name) | 5222 gui_mch_get_color(char_u *name) |
5235 { | 5223 { |
5236 guicolor_T color = INVALCOLOR; | 5224 guicolor_T color = INVALCOLOR; |
5237 | 5225 |
5238 if (!gui.in_use) /* can't do this when GUI not running */ | 5226 if (!gui.in_use) // can't do this when GUI not running |
5239 return color; | 5227 return color; |
5240 | 5228 |
5241 if (name != NULL) | 5229 if (name != NULL) |
5242 color = gui_get_color_cmn(name); | 5230 color = gui_get_color_cmn(name); |
5243 | 5231 |
5343 if (start == NULL) | 5331 if (start == NULL) |
5344 { | 5332 { |
5345 if (uc >= 0x80 && utf_char2cells(uc) == 2) | 5333 if (uc >= 0x80 && utf_char2cells(uc) == 2) |
5346 start = p; | 5334 start = p; |
5347 } | 5335 } |
5348 else if (uc < 0x80 /* optimization shortcut */ | 5336 else if (uc < 0x80 // optimization shortcut |
5349 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) | 5337 || (utf_char2cells(uc) != 2 && !utf_iscomposing(uc))) |
5350 { | 5338 { |
5351 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), | 5339 INSERT_PANGO_ATTR(pango_attr_font_desc_new(gui.wide_font), |
5352 attr_list, start - s, p - s); | 5340 attr_list, start - s, p - s); |
5353 start = NULL; | 5341 start = NULL; |
5364 PangoGlyphString* glyphs, int i, | 5352 PangoGlyphString* glyphs, int i, |
5365 int *cluster_width, | 5353 int *cluster_width, |
5366 int *last_glyph_rbearing) | 5354 int *last_glyph_rbearing) |
5367 { | 5355 { |
5368 char_u *p; | 5356 char_u *p; |
5369 int next; /* glyph start index of next cluster */ | 5357 int next; // glyph start index of next cluster |
5370 int start, end; /* string segment of current cluster */ | 5358 int start, end; // string segment of current cluster |
5371 int width; /* real cluster width in Pango units */ | 5359 int width; // real cluster width in Pango units |
5372 int uc; | 5360 int uc; |
5373 int cellcount = 0; | 5361 int cellcount = 0; |
5374 | 5362 |
5375 width = glyphs->glyphs[i].geometry.width; | 5363 width = glyphs->glyphs[i].geometry.width; |
5376 | 5364 |
5454 glyph->geometry.x_offset += last_glyph_rbearing; | 5442 glyph->geometry.x_offset += last_glyph_rbearing; |
5455 glyph->geometry.y_offset = logical_rect.height | 5443 glyph->geometry.y_offset = logical_rect.height |
5456 - (gui.char_height - p_linespace) * PANGO_SCALE; | 5444 - (gui.char_height - p_linespace) * PANGO_SCALE; |
5457 } | 5445 } |
5458 else | 5446 else |
5459 /* If the accent width is smaller than the cluster width, position it | 5447 // If the accent width is smaller than the cluster width, position it |
5460 * in the middle. */ | 5448 // in the middle. |
5461 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; | 5449 glyph->geometry.x_offset = -width + MAX(0, width - ink_rect.width) / 2; |
5462 } | 5450 } |
5463 | 5451 |
5464 #if GTK_CHECK_VERSION(3,0,0) | 5452 #if GTK_CHECK_VERSION(3,0,0) |
5465 static void | 5453 static void |
5510 TEXT_X(col), | 5498 TEXT_X(col), |
5511 TEXT_Y(row), | 5499 TEXT_Y(row), |
5512 glyphs); | 5500 glyphs); |
5513 #endif | 5501 #endif |
5514 | 5502 |
5515 /* redraw the contents with an offset of 1 to emulate bold */ | 5503 // redraw the contents with an offset of 1 to emulate bold |
5516 if ((flags & DRAW_BOLD) && !gui.font_can_bold) | 5504 if ((flags & DRAW_BOLD) && !gui.font_can_bold) |
5517 #if GTK_CHECK_VERSION(3,0,0) | 5505 #if GTK_CHECK_VERSION(3,0,0) |
5518 { | 5506 { |
5519 cairo_set_source_rgba(cr, | 5507 cairo_set_source_rgba(cr, |
5520 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, | 5508 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
5546 int i; | 5534 int i; |
5547 int offset; | 5535 int offset; |
5548 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; | 5536 static const int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 }; |
5549 int y = FILL_Y(row + 1) - 1; | 5537 int y = FILL_Y(row + 1) - 1; |
5550 | 5538 |
5551 /* Undercurl: draw curl at the bottom of the character cell. */ | 5539 // Undercurl: draw curl at the bottom of the character cell. |
5552 if (flags & DRAW_UNDERC) | 5540 if (flags & DRAW_UNDERC) |
5553 { | 5541 { |
5554 #if GTK_CHECK_VERSION(3,0,0) | 5542 #if GTK_CHECK_VERSION(3,0,0) |
5555 cairo_set_line_width(cr, 1.0); | 5543 cairo_set_line_width(cr, 1.0); |
5556 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); | 5544 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
5572 } | 5560 } |
5573 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | 5561 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5574 #endif | 5562 #endif |
5575 } | 5563 } |
5576 | 5564 |
5577 /* Draw a strikethrough line */ | 5565 // Draw a strikethrough line |
5578 if (flags & DRAW_STRIKE) | 5566 if (flags & DRAW_STRIKE) |
5579 { | 5567 { |
5580 #if GTK_CHECK_VERSION(3,0,0) | 5568 #if GTK_CHECK_VERSION(3,0,0) |
5581 cairo_set_line_width(cr, 1.0); | 5569 cairo_set_line_width(cr, 1.0); |
5582 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); | 5570 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
5593 FILL_X(col + cells), y + 1 - gui.char_height/2); | 5581 FILL_X(col + cells), y + 1 - gui.char_height/2); |
5594 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | 5582 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
5595 #endif | 5583 #endif |
5596 } | 5584 } |
5597 | 5585 |
5598 /* Underline: draw a line at the bottom of the character cell. */ | 5586 // Underline: draw a line at the bottom of the character cell. |
5599 if (flags & DRAW_UNDERL) | 5587 if (flags & DRAW_UNDERL) |
5600 { | 5588 { |
5601 /* When p_linespace is 0, overwrite the bottom row of pixels. | 5589 // When p_linespace is 0, overwrite the bottom row of pixels. |
5602 * Otherwise put the line just below the character. */ | 5590 // Otherwise put the line just below the character. |
5603 if (p_linespace > 1) | 5591 if (p_linespace > 1) |
5604 y -= p_linespace - 1; | 5592 y -= p_linespace - 1; |
5605 #if GTK_CHECK_VERSION(3,0,0) | 5593 #if GTK_CHECK_VERSION(3,0,0) |
5606 cairo_set_line_width(cr, 1.0); | 5594 cairo_set_line_width(cr, 1.0); |
5607 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); | 5595 cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT); |
5620 } | 5608 } |
5621 | 5609 |
5622 int | 5610 int |
5623 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) | 5611 gui_gtk2_draw_string(int row, int col, char_u *s, int len, int flags) |
5624 { | 5612 { |
5625 GdkRectangle area; /* area for clip mask */ | 5613 GdkRectangle area; // area for clip mask |
5626 PangoGlyphString *glyphs; /* glyphs of current item */ | 5614 PangoGlyphString *glyphs; // glyphs of current item |
5627 int column_offset = 0; /* column offset in cells */ | 5615 int column_offset = 0; // column offset in cells |
5628 int i; | 5616 int i; |
5629 char_u *conv_buf = NULL; /* result of UTF-8 conversion */ | 5617 char_u *conv_buf = NULL; // result of UTF-8 conversion |
5630 char_u *new_conv_buf; | 5618 char_u *new_conv_buf; |
5631 int convlen; | 5619 int convlen; |
5632 char_u *sp, *bp; | 5620 char_u *sp, *bp; |
5633 int plen; | 5621 int plen; |
5634 #if GTK_CHECK_VERSION(3,0,0) | 5622 #if GTK_CHECK_VERSION(3,0,0) |
5648 */ | 5636 */ |
5649 convlen = len; | 5637 convlen = len; |
5650 conv_buf = string_convert(&output_conv, s, &convlen); | 5638 conv_buf = string_convert(&output_conv, s, &convlen); |
5651 g_return_val_if_fail(conv_buf != NULL, len); | 5639 g_return_val_if_fail(conv_buf != NULL, len); |
5652 | 5640 |
5653 /* Correct for differences in char width: some chars are | 5641 // Correct for differences in char width: some chars are |
5654 * double-wide in 'encoding' but single-wide in utf-8. Add a space to | 5642 // double-wide in 'encoding' but single-wide in utf-8. Add a space to |
5655 * compensate for that. */ | 5643 // compensate for that. |
5656 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) | 5644 for (sp = s, bp = conv_buf; sp < s + len && bp < conv_buf + convlen; ) |
5657 { | 5645 { |
5658 plen = utf_ptr2len(bp); | 5646 plen = utf_ptr2len(bp); |
5659 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) | 5647 if ((*mb_ptr2cells)(sp) == 2 && utf_ptr2cells(bp) == 1) |
5660 { | 5648 { |
5735 { | 5723 { |
5736 PangoAttrList *attr_list; | 5724 PangoAttrList *attr_list; |
5737 GList *item_list; | 5725 GList *item_list; |
5738 int cluster_width; | 5726 int cluster_width; |
5739 int last_glyph_rbearing; | 5727 int last_glyph_rbearing; |
5740 int cells = 0; /* cells occupied by current cluster */ | 5728 int cells = 0; // cells occupied by current cluster |
5741 | 5729 |
5742 /* Safety check: pango crashes when invoked with invalid utf-8 | 5730 // Safety check: pango crashes when invoked with invalid utf-8 |
5743 * characters. */ | 5731 // characters. |
5744 if (!utf_valid_string(s, s + len)) | 5732 if (!utf_valid_string(s, s + len)) |
5745 { | 5733 { |
5746 column_offset = len; | 5734 column_offset = len; |
5747 goto skipitall; | 5735 goto skipitall; |
5748 } | 5736 } |
5749 | 5737 |
5750 /* original width of the current cluster */ | 5738 // original width of the current cluster |
5751 cluster_width = PANGO_SCALE * gui.char_width; | 5739 cluster_width = PANGO_SCALE * gui.char_width; |
5752 | 5740 |
5753 /* right bearing of the last non-composing glyph */ | 5741 // right bearing of the last non-composing glyph |
5754 last_glyph_rbearing = PANGO_SCALE * gui.char_width; | 5742 last_glyph_rbearing = PANGO_SCALE * gui.char_width; |
5755 | 5743 |
5756 attr_list = pango_attr_list_new(); | 5744 attr_list = pango_attr_list_new(); |
5757 | 5745 |
5758 /* If 'guifontwide' is set then use that for double-width characters. | 5746 // If 'guifontwide' is set then use that for double-width characters. |
5759 * Otherwise just go with 'guifont' and let Pango do its thing. */ | 5747 // Otherwise just go with 'guifont' and let Pango do its thing. |
5760 if (gui.wide_font != NULL) | 5748 if (gui.wide_font != NULL) |
5761 apply_wide_font_attr(s, len, attr_list); | 5749 apply_wide_font_attr(s, len, attr_list); |
5762 | 5750 |
5763 if ((flags & DRAW_BOLD) && gui.font_can_bold) | 5751 if ((flags & DRAW_BOLD) && gui.font_can_bold) |
5764 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), | 5752 INSERT_PANGO_ATTR(pango_attr_weight_new(PANGO_WEIGHT_BOLD), |
5776 (const char *)s, 0, len, attr_list, NULL); | 5764 (const char *)s, 0, len, attr_list, NULL); |
5777 | 5765 |
5778 while (item_list != NULL) | 5766 while (item_list != NULL) |
5779 { | 5767 { |
5780 PangoItem *item; | 5768 PangoItem *item; |
5781 int item_cells = 0; /* item length in cells */ | 5769 int item_cells = 0; // item length in cells |
5782 | 5770 |
5783 item = (PangoItem *)item_list->data; | 5771 item = (PangoItem *)item_list->data; |
5784 item_list = g_list_delete_link(item_list, item_list); | 5772 item_list = g_list_delete_link(item_list, item_list); |
5785 /* | 5773 /* |
5786 * Increment the bidirectional embedding level by 1 if it is not | 5774 * Increment the bidirectional embedding level by 1 if it is not |
5794 * that, Vim's main screen engine would have to make use of Pango | 5782 * that, Vim's main screen engine would have to make use of Pango |
5795 * functionality. | 5783 * functionality. |
5796 */ | 5784 */ |
5797 item->analysis.level = (item->analysis.level + 1) & (~1U); | 5785 item->analysis.level = (item->analysis.level + 1) & (~1U); |
5798 | 5786 |
5799 /* HACK: Overrule the shape engine, we don't want shaping to be | 5787 // HACK: Overrule the shape engine, we don't want shaping to be |
5800 * done, because drawing the cursor would change the display. */ | 5788 // done, because drawing the cursor would change the display. |
5801 item->analysis.shape_engine = default_shape_engine; | 5789 item->analysis.shape_engine = default_shape_engine; |
5802 | 5790 |
5803 #ifdef HAVE_PANGO_SHAPE_FULL | 5791 #ifdef HAVE_PANGO_SHAPE_FULL |
5804 pango_shape_full((const char *)s + item->offset, item->length, | 5792 pango_shape_full((const char *)s + item->offset, item->length, |
5805 (const char *)s, len, &item->analysis, glyphs); | 5793 (const char *)s, len, &item->analysis, glyphs); |
5839 MAX(0, width - cluster_width) / 2; | 5827 MAX(0, width - cluster_width) / 2; |
5840 glyph->geometry.width = width; | 5828 glyph->geometry.width = width; |
5841 } | 5829 } |
5842 else | 5830 else |
5843 { | 5831 { |
5844 /* If there are only combining characters in the | 5832 // If there are only combining characters in the |
5845 * cluster, we cannot just change the width of the | 5833 // cluster, we cannot just change the width of the |
5846 * previous glyph since there is none. Therefore | 5834 // previous glyph since there is none. Therefore |
5847 * some guesswork is needed. */ | 5835 // some guesswork is needed. |
5848 setup_zero_width_cluster(item, glyph, cells, | 5836 setup_zero_width_cluster(item, glyph, cells, |
5849 cluster_width, | 5837 cluster_width, |
5850 last_glyph_rbearing); | 5838 last_glyph_rbearing); |
5851 } | 5839 } |
5852 | 5840 |
5855 } | 5843 } |
5856 else if (i > 0) | 5844 else if (i > 0) |
5857 { | 5845 { |
5858 int width; | 5846 int width; |
5859 | 5847 |
5860 /* There is a previous glyph, so we deal with combining | 5848 // There is a previous glyph, so we deal with combining |
5861 * characters the canonical way. | 5849 // characters the canonical way. |
5862 * In some circumstances Pango uses a positive x_offset, | 5850 // In some circumstances Pango uses a positive x_offset, |
5863 * then use the width of the previous glyph for this one | 5851 // then use the width of the previous glyph for this one |
5864 * and set the previous width to zero. | 5852 // and set the previous width to zero. |
5865 * Otherwise we get a negative x_offset, Pango has already | 5853 // Otherwise we get a negative x_offset, Pango has already |
5866 * positioned the combining char, keep the widths as they | 5854 // positioned the combining char, keep the widths as they |
5867 * are. | 5855 // are. |
5868 * For both adjust the x_offset to position the glyph in | 5856 // For both adjust the x_offset to position the glyph in |
5869 * the middle. */ | 5857 // the middle. |
5870 if (glyph->geometry.x_offset >= 0) | 5858 if (glyph->geometry.x_offset >= 0) |
5871 { | 5859 { |
5872 glyphs->glyphs[i].geometry.width = | 5860 glyphs->glyphs[i].geometry.width = |
5873 glyphs->glyphs[i - 1].geometry.width; | 5861 glyphs->glyphs[i - 1].geometry.width; |
5874 glyphs->glyphs[i - 1].geometry.width = 0; | 5862 glyphs->glyphs[i - 1].geometry.width = 0; |
5875 } | 5863 } |
5876 width = cells * gui.char_width * PANGO_SCALE; | 5864 width = cells * gui.char_width * PANGO_SCALE; |
5877 glyph->geometry.x_offset += | 5865 glyph->geometry.x_offset += |
5878 MAX(0, width - cluster_width) / 2; | 5866 MAX(0, width - cluster_width) / 2; |
5879 } | 5867 } |
5880 else /* i == 0 "cannot happen" */ | 5868 else // i == 0 "cannot happen" |
5881 { | 5869 { |
5882 glyph->geometry.width = 0; | 5870 glyph->geometry.width = 0; |
5883 } | 5871 } |
5884 } | 5872 } |
5885 | 5873 |
5886 /*** Aaaaand action! ***/ | 5874 //// Aaaaand action! ** |
5887 #if GTK_CHECK_VERSION(3,0,0) | 5875 #if GTK_CHECK_VERSION(3,0,0) |
5888 draw_glyph_string(row, col + column_offset, item_cells, | 5876 draw_glyph_string(row, col + column_offset, item_cells, |
5889 flags, item->analysis.font, glyphs, | 5877 flags, item->analysis.font, glyphs, |
5890 cr); | 5878 cr); |
5891 #else | 5879 #else |
5900 | 5888 |
5901 pango_attr_list_unref(attr_list); | 5889 pango_attr_list_unref(attr_list); |
5902 } | 5890 } |
5903 | 5891 |
5904 skipitall: | 5892 skipitall: |
5905 /* Draw underline and undercurl. */ | 5893 // Draw underline and undercurl. |
5906 #if GTK_CHECK_VERSION(3,0,0) | 5894 #if GTK_CHECK_VERSION(3,0,0) |
5907 draw_under(flags, row, col, column_offset, cr); | 5895 draw_under(flags, row, col, column_offset, cr); |
5908 #else | 5896 #else |
5909 draw_under(flags, row, col, column_offset); | 5897 draw_under(flags, row, col, column_offset); |
5910 #endif | 5898 #endif |
5988 | 5976 |
5989 void | 5977 void |
5990 gui_mch_flash(int msec) | 5978 gui_mch_flash(int msec) |
5991 { | 5979 { |
5992 #if GTK_CHECK_VERSION(3,0,0) | 5980 #if GTK_CHECK_VERSION(3,0,0) |
5993 /* TODO Replace GdkGC with Cairo */ | 5981 // TODO Replace GdkGC with Cairo |
5994 (void)msec; | 5982 (void)msec; |
5995 #else | 5983 #else |
5996 GdkGCValues values; | 5984 GdkGCValues values; |
5997 GdkGC *invert_gc; | 5985 GdkGC *invert_gc; |
5998 | 5986 |
6021 0, 0, | 6009 0, 0, |
6022 FILL_X((int)Columns) + gui.border_offset, | 6010 FILL_X((int)Columns) + gui.border_offset, |
6023 FILL_Y((int)Rows) + gui.border_offset); | 6011 FILL_Y((int)Rows) + gui.border_offset); |
6024 | 6012 |
6025 gui_mch_flush(); | 6013 gui_mch_flush(); |
6026 ui_delay((long)msec, TRUE); /* wait so many msec */ | 6014 ui_delay((long)msec, TRUE); // wait so many msec |
6027 | 6015 |
6028 gdk_draw_rectangle(gui.drawarea->window, invert_gc, | 6016 gdk_draw_rectangle(gui.drawarea->window, invert_gc, |
6029 TRUE, | 6017 TRUE, |
6030 0, 0, | 6018 0, 0, |
6031 FILL_X((int)Columns) + gui.border_offset, | 6019 FILL_X((int)Columns) + gui.border_offset, |
6049 | 6037 |
6050 set_cairo_source_rgba_from_color(cr, gui.norm_pixel ^ gui.back_pixel); | 6038 set_cairo_source_rgba_from_color(cr, gui.norm_pixel ^ gui.back_pixel); |
6051 # if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,2) | 6039 # if CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1,9,2) |
6052 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); | 6040 cairo_set_operator(cr, CAIRO_OPERATOR_DIFFERENCE); |
6053 # else | 6041 # else |
6054 /* Give an implementation for older cairo versions if necessary. */ | 6042 // Give an implementation for older cairo versions if necessary. |
6055 # endif | 6043 # endif |
6056 gdk_cairo_rectangle(cr, &rect); | 6044 gdk_cairo_rectangle(cr, &rect); |
6057 cairo_fill(cr); | 6045 cairo_fill(cr); |
6058 | 6046 |
6059 cairo_destroy(cr); | 6047 cairo_destroy(cr); |
6171 cairo_set_source_rgba(cr, | 6159 cairo_set_source_rgba(cr, |
6172 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, | 6160 gui.fgcolor->red, gui.fgcolor->green, gui.fgcolor->blue, |
6173 gui.fgcolor->alpha); | 6161 gui.fgcolor->alpha); |
6174 cairo_rectangle(cr, | 6162 cairo_rectangle(cr, |
6175 # ifdef FEAT_RIGHTLEFT | 6163 # ifdef FEAT_RIGHTLEFT |
6176 /* vertical line should be on the right of current point */ | 6164 // vertical line should be on the right of current point |
6177 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : | 6165 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
6178 # endif | 6166 # endif |
6179 FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h, | 6167 FILL_X(gui.col), FILL_Y(gui.row) + gui.char_height - h, |
6180 w, h); | 6168 w, h); |
6181 cairo_fill(cr); | 6169 cairo_fill(cr); |
6182 cairo_destroy(cr); | 6170 cairo_destroy(cr); |
6183 } | 6171 } |
6184 #else /* !GTK_CHECK_VERSION(3,0,0) */ | 6172 #else // !GTK_CHECK_VERSION(3,0,0) |
6185 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | 6173 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6186 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, | 6174 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, |
6187 TRUE, | 6175 TRUE, |
6188 # ifdef FEAT_RIGHTLEFT | 6176 # ifdef FEAT_RIGHTLEFT |
6189 /* vertical line should be on the right of current point */ | 6177 // vertical line should be on the right of current point |
6190 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : | 6178 CURSOR_BAR_RIGHT ? FILL_X(gui.col + 1) - w : |
6191 # endif | 6179 # endif |
6192 FILL_X(gui.col), | 6180 FILL_X(gui.col), |
6193 FILL_Y(gui.row) + gui.char_height - h, | 6181 FILL_Y(gui.row) + gui.char_height - h, |
6194 w, h); | 6182 w, h); |
6195 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 6183 #endif // !GTK_CHECK_VERSION(3,0,0) |
6196 } | 6184 } |
6197 | 6185 |
6198 | 6186 |
6199 /* | 6187 /* |
6200 * Catch up with any queued X11 events. This may put keyboard input into the | 6188 * Catch up with any queued X11 events. This may put keyboard input into the |
6212 static timeout_cb_type | 6200 static timeout_cb_type |
6213 input_timer_cb(gpointer data) | 6201 input_timer_cb(gpointer data) |
6214 { | 6202 { |
6215 int *timed_out = (int *) data; | 6203 int *timed_out = (int *) data; |
6216 | 6204 |
6217 /* Just inform the caller about the occurrence of it */ | 6205 // Just inform the caller about the occurrence of it |
6218 *timed_out = TRUE; | 6206 *timed_out = TRUE; |
6219 | 6207 |
6220 return FALSE; /* don't happen again */ | 6208 return FALSE; // don't happen again |
6221 } | 6209 } |
6222 | 6210 |
6223 #ifdef FEAT_JOB_CHANNEL | 6211 #ifdef FEAT_JOB_CHANNEL |
6224 static timeout_cb_type | 6212 static timeout_cb_type |
6225 channel_poll_cb(gpointer data UNUSED) | 6213 channel_poll_cb(gpointer data UNUSED) |
6226 { | 6214 { |
6227 /* Using an event handler for a channel that may be disconnected does | 6215 // Using an event handler for a channel that may be disconnected does |
6228 * not work, it hangs. Instead poll for messages. */ | 6216 // not work, it hangs. Instead poll for messages. |
6229 channel_handle_events(TRUE); | 6217 channel_handle_events(TRUE); |
6230 parse_queued_messages(); | 6218 parse_queued_messages(); |
6231 | 6219 |
6232 return TRUE; /* repeat */ | 6220 return TRUE; // repeat |
6233 } | 6221 } |
6234 #endif | 6222 #endif |
6235 | 6223 |
6236 /* | 6224 /* |
6237 * GUI input routine called by gui_wait_for_chars(). Waits for a character | 6225 * GUI input routine called by gui_wait_for_chars(). Waits for a character |
6262 input_timer_cb, &timed_out); | 6250 input_timer_cb, &timed_out); |
6263 else | 6251 else |
6264 timer = 0; | 6252 timer = 0; |
6265 | 6253 |
6266 #ifdef FEAT_JOB_CHANNEL | 6254 #ifdef FEAT_JOB_CHANNEL |
6267 /* If there is a channel with the keep_open flag we need to poll for input | 6255 // If there is a channel with the keep_open flag we need to poll for input |
6268 * on them. */ | 6256 // on them. |
6269 if (channel_any_keep_open()) | 6257 if (channel_any_keep_open()) |
6270 channel_timer = timeout_add(20, channel_poll_cb, NULL); | 6258 channel_timer = timeout_add(20, channel_poll_cb, NULL); |
6271 #endif | 6259 #endif |
6272 | 6260 |
6273 focus = gui.in_focus; | 6261 focus = gui.in_focus; |
6274 | 6262 |
6275 do | 6263 do |
6276 { | 6264 { |
6277 /* Stop or start blinking when focus changes */ | 6265 // Stop or start blinking when focus changes |
6278 if (gui.in_focus != focus) | 6266 if (gui.in_focus != focus) |
6279 { | 6267 { |
6280 if (gui.in_focus) | 6268 if (gui.in_focus) |
6281 gui_mch_start_blink(); | 6269 gui_mch_start_blink(); |
6282 else | 6270 else |
6289 did_add_timer = FALSE; | 6277 did_add_timer = FALSE; |
6290 # endif | 6278 # endif |
6291 parse_queued_messages(); | 6279 parse_queued_messages(); |
6292 # ifdef FEAT_TIMERS | 6280 # ifdef FEAT_TIMERS |
6293 if (did_add_timer) | 6281 if (did_add_timer) |
6294 /* Need to recompute the waiting time. */ | 6282 // Need to recompute the waiting time. |
6295 goto theend; | 6283 goto theend; |
6296 # endif | 6284 # endif |
6297 #endif | 6285 #endif |
6298 | 6286 |
6299 /* | 6287 /* |
6302 * situations, sort of race condition). | 6290 * situations, sort of race condition). |
6303 */ | 6291 */ |
6304 if (!input_available()) | 6292 if (!input_available()) |
6305 g_main_context_iteration(NULL, TRUE); | 6293 g_main_context_iteration(NULL, TRUE); |
6306 | 6294 |
6307 /* Got char, return immediately */ | 6295 // Got char, return immediately |
6308 if (input_available()) | 6296 if (input_available()) |
6309 { | 6297 { |
6310 retval = OK; | 6298 retval = OK; |
6311 goto theend; | 6299 goto theend; |
6312 } | 6300 } |
6327 | 6315 |
6328 return retval; | 6316 return retval; |
6329 } | 6317 } |
6330 | 6318 |
6331 | 6319 |
6332 /**************************************************************************** | 6320 ///////////////////////////////////////////////////////////////////////////// |
6333 * Output drawing routines. | 6321 // Output drawing routines. |
6334 ****************************************************************************/ | 6322 // |
6335 | 6323 |
6336 | 6324 |
6337 /* Flush any output to the screen */ | 6325 // Flush any output to the screen |
6338 void | 6326 void |
6339 gui_mch_flush(void) | 6327 gui_mch_flush(void) |
6340 { | 6328 { |
6341 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) | 6329 if (gui.mainwin != NULL && gtk_widget_get_realized(gui.mainwin)) |
6342 #if GTK_CHECK_VERSION(2,4,0) | 6330 #if GTK_CHECK_VERSION(2,4,0) |
6371 color.pixel = gui.back_pixel; | 6359 color.pixel = gui.back_pixel; |
6372 #endif | 6360 #endif |
6373 | 6361 |
6374 #if GTK_CHECK_VERSION(3,0,0) | 6362 #if GTK_CHECK_VERSION(3,0,0) |
6375 { | 6363 { |
6376 /* Add one pixel to the far right column in case a double-stroked | 6364 // Add one pixel to the far right column in case a double-stroked |
6377 * bold glyph may sit there. */ | 6365 // bold glyph may sit there. |
6378 const GdkRectangle rect = { | 6366 const GdkRectangle rect = { |
6379 FILL_X(col1), FILL_Y(row1), | 6367 FILL_X(col1), FILL_Y(row1), |
6380 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), | 6368 (col2 - col1 + 1) * gui.char_width + (col2 == Columns - 1), |
6381 (row2 - row1 + 1) * gui.char_height | 6369 (row2 - row1 + 1) * gui.char_height |
6382 }; | 6370 }; |
6396 cairo_destroy(cr); | 6384 cairo_destroy(cr); |
6397 | 6385 |
6398 if (!gui.by_signal) | 6386 if (!gui.by_signal) |
6399 gdk_window_invalidate_rect(win, &rect, FALSE); | 6387 gdk_window_invalidate_rect(win, &rect, FALSE); |
6400 } | 6388 } |
6401 #else /* !GTK_CHECK_VERSION(3,0,0) */ | 6389 #else // !GTK_CHECK_VERSION(3,0,0) |
6402 gdk_gc_set_foreground(gui.text_gc, &color); | 6390 gdk_gc_set_foreground(gui.text_gc, &color); |
6403 | 6391 |
6404 /* Clear one extra pixel at the far right, for when bold characters have | 6392 // Clear one extra pixel at the far right, for when bold characters have |
6405 * spilled over to the window border. */ | 6393 // spilled over to the window border. |
6406 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, | 6394 gdk_draw_rectangle(gui.drawarea->window, gui.text_gc, TRUE, |
6407 FILL_X(col1), FILL_Y(row1), | 6395 FILL_X(col1), FILL_Y(row1), |
6408 (col2 - col1 + 1) * gui.char_width | 6396 (col2 - col1 + 1) * gui.char_width |
6409 + (col2 == Columns - 1), | 6397 + (col2 == Columns - 1), |
6410 (row2 - row1 + 1) * gui.char_height); | 6398 (row2 - row1 + 1) * gui.char_height); |
6411 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 6399 #endif // !GTK_CHECK_VERSION(3,0,0) |
6412 } | 6400 } |
6413 | 6401 |
6414 #if GTK_CHECK_VERSION(3,0,0) | 6402 #if GTK_CHECK_VERSION(3,0,0) |
6415 static void | 6403 static void |
6416 gui_gtk_window_clear(GdkWindow *win) | 6404 gui_gtk_window_clear(GdkWindow *win) |
6457 int expose_count; | 6445 int expose_count; |
6458 | 6446 |
6459 if (gui.visibility != GDK_VISIBILITY_PARTIAL) | 6447 if (gui.visibility != GDK_VISIBILITY_PARTIAL) |
6460 return; | 6448 return; |
6461 | 6449 |
6462 /* Avoid redrawing the cursor while scrolling or it'll end up where | 6450 // Avoid redrawing the cursor while scrolling or it'll end up where |
6463 * we don't want it to be. I'm not sure if it's correct to call | 6451 // we don't want it to be. I'm not sure if it's correct to call |
6464 * gui_dont_update_cursor() at this point but it works as a quick | 6452 // gui_dont_update_cursor() at this point but it works as a quick |
6465 * fix for now. */ | 6453 // fix for now. |
6466 gui_dont_update_cursor(TRUE); | 6454 gui_dont_update_cursor(TRUE); |
6467 | 6455 |
6468 do | 6456 do |
6469 { | 6457 { |
6470 /* Wait to check whether the scroll worked or not. */ | 6458 // Wait to check whether the scroll worked or not. |
6471 event = gdk_event_get_graphics_expose(gui.drawarea->window); | 6459 event = gdk_event_get_graphics_expose(gui.drawarea->window); |
6472 | 6460 |
6473 if (event == NULL) | 6461 if (event == NULL) |
6474 break; /* received NoExpose event */ | 6462 break; // received NoExpose event |
6475 | 6463 |
6476 gui_redraw(event->expose.area.x, event->expose.area.y, | 6464 gui_redraw(event->expose.area.x, event->expose.area.y, |
6477 event->expose.area.width, event->expose.area.height); | 6465 event->expose.area.width, event->expose.area.height); |
6478 | 6466 |
6479 expose_count = event->expose.count; | 6467 expose_count = event->expose.count; |
6480 gdk_event_free(event); | 6468 gdk_event_free(event); |
6481 } | 6469 } |
6482 while (expose_count > 0); /* more events follow */ | 6470 while (expose_count > 0); // more events follow |
6483 | 6471 |
6484 gui_can_update_cursor(); | 6472 gui_can_update_cursor(); |
6485 } | 6473 } |
6486 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 6474 #endif // !GTK_CHECK_VERSION(3,0,0) |
6487 | 6475 |
6488 #if GTK_CHECK_VERSION(3,0,0) | 6476 #if GTK_CHECK_VERSION(3,0,0) |
6489 static void | 6477 static void |
6490 gui_gtk_surface_copy_rect(int dest_x, int dest_y, | 6478 gui_gtk_surface_copy_rect(int dest_x, int dest_y, |
6491 int src_x, int src_y, | 6479 int src_x, int src_y, |
6531 gtk_widget_queue_draw_area(gui.drawarea, | 6519 gtk_widget_queue_draw_area(gui.drawarea, |
6532 FILL_X(gui.scroll_region_left), FILL_Y(row), | 6520 FILL_X(gui.scroll_region_left), FILL_Y(row), |
6533 gui.char_width * ncols + 1, gui.char_height * nrows); | 6521 gui.char_width * ncols + 1, gui.char_height * nrows); |
6534 #else | 6522 #else |
6535 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) | 6523 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6536 return; /* Can't see the window */ | 6524 return; // Can't see the window |
6537 | 6525 |
6538 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | 6526 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6539 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | 6527 gdk_gc_set_background(gui.text_gc, gui.bgcolor); |
6540 | 6528 |
6541 /* copy one extra pixel, for when bold has spilled over */ | 6529 // copy one extra pixel, for when bold has spilled over |
6542 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | 6530 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, |
6543 FILL_X(gui.scroll_region_left), FILL_Y(row), | 6531 FILL_X(gui.scroll_region_left), FILL_Y(row), |
6544 gui.drawarea->window, | 6532 gui.drawarea->window, |
6545 FILL_X(gui.scroll_region_left), | 6533 FILL_X(gui.scroll_region_left), |
6546 FILL_Y(row + num_lines), | 6534 FILL_Y(row + num_lines), |
6550 | 6538 |
6551 gui_clear_block(gui.scroll_region_bot - num_lines + 1, | 6539 gui_clear_block(gui.scroll_region_bot - num_lines + 1, |
6552 gui.scroll_region_left, | 6540 gui.scroll_region_left, |
6553 gui.scroll_region_bot, gui.scroll_region_right); | 6541 gui.scroll_region_bot, gui.scroll_region_right); |
6554 check_copy_area(); | 6542 check_copy_area(); |
6555 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 6543 #endif // !GTK_CHECK_VERSION(3,0,0) |
6556 } | 6544 } |
6557 | 6545 |
6558 /* | 6546 /* |
6559 * Insert the given number of lines before the given row, scrolling down any | 6547 * Insert the given number of lines before the given row, scrolling down any |
6560 * following text within the scroll region. | 6548 * following text within the scroll region. |
6581 gtk_widget_queue_draw_area(gui.drawarea, | 6569 gtk_widget_queue_draw_area(gui.drawarea, |
6582 FILL_X(gui.scroll_region_left), FILL_Y(row), | 6570 FILL_X(gui.scroll_region_left), FILL_Y(row), |
6583 gui.char_width * ncols + 1, gui.char_height * nrows); | 6571 gui.char_width * ncols + 1, gui.char_height * nrows); |
6584 #else | 6572 #else |
6585 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) | 6573 if (gui.visibility == GDK_VISIBILITY_FULLY_OBSCURED) |
6586 return; /* Can't see the window */ | 6574 return; // Can't see the window |
6587 | 6575 |
6588 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); | 6576 gdk_gc_set_foreground(gui.text_gc, gui.fgcolor); |
6589 gdk_gc_set_background(gui.text_gc, gui.bgcolor); | 6577 gdk_gc_set_background(gui.text_gc, gui.bgcolor); |
6590 | 6578 |
6591 /* copy one extra pixel, for when bold has spilled over */ | 6579 // copy one extra pixel, for when bold has spilled over |
6592 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, | 6580 gdk_window_copy_area(gui.drawarea->window, gui.text_gc, |
6593 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), | 6581 FILL_X(gui.scroll_region_left), FILL_Y(row + num_lines), |
6594 gui.drawarea->window, | 6582 gui.drawarea->window, |
6595 FILL_X(gui.scroll_region_left), FILL_Y(row), | 6583 FILL_X(gui.scroll_region_left), FILL_Y(row), |
6596 gui.char_width * (gui.scroll_region_right | 6584 gui.char_width * (gui.scroll_region_right |
6598 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); | 6586 gui.char_height * (gui.scroll_region_bot - row - num_lines + 1)); |
6599 | 6587 |
6600 gui_clear_block(row, gui.scroll_region_left, | 6588 gui_clear_block(row, gui.scroll_region_left, |
6601 row + num_lines - 1, gui.scroll_region_right); | 6589 row + num_lines - 1, gui.scroll_region_right); |
6602 check_copy_area(); | 6590 check_copy_area(); |
6603 #endif /* !GTK_CHECK_VERSION(3,0,0) */ | 6591 #endif // !GTK_CHECK_VERSION(3,0,0) |
6604 } | 6592 } |
6605 | 6593 |
6606 /* | 6594 /* |
6607 * X Selection stuff, for cutting and pasting text to other windows. | 6595 * X Selection stuff, for cutting and pasting text to other windows. |
6608 */ | 6596 */ |
6622 | 6610 |
6623 gtk_selection_convert(gui.drawarea, | 6611 gtk_selection_convert(gui.drawarea, |
6624 cbd->gtk_sel_atom, target, | 6612 cbd->gtk_sel_atom, target, |
6625 (guint32)GDK_CURRENT_TIME); | 6613 (guint32)GDK_CURRENT_TIME); |
6626 | 6614 |
6627 /* Hack: Wait up to three seconds for the selection. A hang was | 6615 // Hack: Wait up to three seconds for the selection. A hang was |
6628 * noticed here when using the netrw plugin combined with ":gui" | 6616 // noticed here when using the netrw plugin combined with ":gui" |
6629 * during the FocusGained event. */ | 6617 // during the FocusGained event. |
6630 start = time(NULL); | 6618 start = time(NULL); |
6631 while (received_selection == RS_NONE && time(NULL) < start + 3) | 6619 while (received_selection == RS_NONE && time(NULL) < start + 3) |
6632 g_main_context_iteration(NULL, TRUE); /* wait for selection_received_cb */ | 6620 g_main_context_iteration(NULL, TRUE); // wait for selection_received_cb |
6633 | 6621 |
6634 if (received_selection != RS_FAIL) | 6622 if (received_selection != RS_FAIL) |
6635 return; | 6623 return; |
6636 } | 6624 } |
6637 | 6625 |
6638 /* Final fallback position - use the X CUT_BUFFER0 store */ | 6626 // Final fallback position - use the X CUT_BUFFER0 store |
6639 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), | 6627 yank_cut_buffer0(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.mainwin)), |
6640 cbd); | 6628 cbd); |
6641 } | 6629 } |
6642 | 6630 |
6643 /* | 6631 /* |
6697 | 6685 |
6698 if (menu_is_separator(menu->name)) | 6686 if (menu_is_separator(menu->name)) |
6699 grey = TRUE; | 6687 grey = TRUE; |
6700 | 6688 |
6701 gui_mch_menu_hidden(menu, FALSE); | 6689 gui_mch_menu_hidden(menu, FALSE); |
6702 /* Be clever about bitfields versus true booleans here! */ | 6690 // Be clever about bitfields versus true booleans here! |
6703 if (!gtk_widget_get_sensitive(menu->id) == !grey) | 6691 if (!gtk_widget_get_sensitive(menu->id) == !grey) |
6704 { | 6692 { |
6705 gtk_widget_set_sensitive(menu->id, !grey); | 6693 gtk_widget_set_sensitive(menu->id, !grey); |
6706 gui_mch_update(); | 6694 gui_mch_update(); |
6707 } | 6695 } |
6738 * This is called after setting all the menus to grey/hidden or not. | 6726 * This is called after setting all the menus to grey/hidden or not. |
6739 */ | 6727 */ |
6740 void | 6728 void |
6741 gui_mch_draw_menubar(void) | 6729 gui_mch_draw_menubar(void) |
6742 { | 6730 { |
6743 /* just make sure that the visual changes get effect immediately */ | 6731 // just make sure that the visual changes get effect immediately |
6744 gui_mch_update(); | 6732 gui_mch_update(); |
6745 } | 6733 } |
6746 #endif /* FEAT_MENU */ | 6734 #endif // FEAT_MENU |
6747 | 6735 |
6748 /* | 6736 /* |
6749 * Scrollbar stuff. | 6737 * Scrollbar stuff. |
6750 */ | 6738 */ |
6751 void | 6739 void |
6790 } | 6778 } |
6791 | 6779 |
6792 void | 6780 void |
6793 gui_mch_setmouse(int x, int y) | 6781 gui_mch_setmouse(int x, int y) |
6794 { | 6782 { |
6795 /* Sorry for the Xlib call, but we can't avoid it, since there is no | 6783 // Sorry for the Xlib call, but we can't avoid it, since there is no |
6796 * internal GDK mechanism present to accomplish this. (and for good | 6784 // internal GDK mechanism present to accomplish this. (and for good |
6797 * reason...) */ | 6785 // reason...) |
6798 XWarpPointer(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.drawarea)), | 6786 XWarpPointer(GDK_WINDOW_XDISPLAY(gtk_widget_get_window(gui.drawarea)), |
6799 (Window)0, GDK_WINDOW_XID(gtk_widget_get_window(gui.drawarea)), | 6787 (Window)0, GDK_WINDOW_XID(gtk_widget_get_window(gui.drawarea)), |
6800 0, 0, 0U, 0U, x, y); | 6788 0, 0, 0U, 0U, x, y); |
6801 } | 6789 } |
6802 | 6790 |
6803 | 6791 |
6804 #ifdef FEAT_MOUSESHAPE | 6792 #ifdef FEAT_MOUSESHAPE |
6805 /* The last set mouse pointer shape is remembered, to be used when it goes | 6793 // The last set mouse pointer shape is remembered, to be used when it goes |
6806 * from hidden to not hidden. */ | 6794 // from hidden to not hidden. |
6807 static int last_shape = 0; | 6795 static int last_shape = 0; |
6808 #endif | 6796 #endif |
6809 | 6797 |
6810 /* | 6798 /* |
6811 * Use the blank mouse pointer or not. | 6799 * Use the blank mouse pointer or not. |
6833 } | 6821 } |
6834 } | 6822 } |
6835 | 6823 |
6836 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) | 6824 #if defined(FEAT_MOUSESHAPE) || defined(PROTO) |
6837 | 6825 |
6838 /* Table for shape IDs. Keep in sync with the mshape_names[] table in | 6826 // Table for shape IDs. Keep in sync with the mshape_names[] table in |
6839 * misc2.c! */ | 6827 // misc2.c! |
6840 static const int mshape_ids[] = | 6828 static const int mshape_ids[] = |
6841 { | 6829 { |
6842 GDK_LEFT_PTR, /* arrow */ | 6830 GDK_LEFT_PTR, // arrow |
6843 GDK_CURSOR_IS_PIXMAP, /* blank */ | 6831 GDK_CURSOR_IS_PIXMAP, // blank |
6844 GDK_XTERM, /* beam */ | 6832 GDK_XTERM, // beam |
6845 GDK_SB_V_DOUBLE_ARROW, /* updown */ | 6833 GDK_SB_V_DOUBLE_ARROW, // updown |
6846 GDK_SIZING, /* udsizing */ | 6834 GDK_SIZING, // udsizing |
6847 GDK_SB_H_DOUBLE_ARROW, /* leftright */ | 6835 GDK_SB_H_DOUBLE_ARROW, // leftright |
6848 GDK_SIZING, /* lrsizing */ | 6836 GDK_SIZING, // lrsizing |
6849 GDK_WATCH, /* busy */ | 6837 GDK_WATCH, // busy |
6850 GDK_X_CURSOR, /* no */ | 6838 GDK_X_CURSOR, // no |
6851 GDK_CROSSHAIR, /* crosshair */ | 6839 GDK_CROSSHAIR, // crosshair |
6852 GDK_HAND1, /* hand1 */ | 6840 GDK_HAND1, // hand1 |
6853 GDK_HAND2, /* hand2 */ | 6841 GDK_HAND2, // hand2 |
6854 GDK_PENCIL, /* pencil */ | 6842 GDK_PENCIL, // pencil |
6855 GDK_QUESTION_ARROW, /* question */ | 6843 GDK_QUESTION_ARROW, // question |
6856 GDK_RIGHT_PTR, /* right-arrow */ | 6844 GDK_RIGHT_PTR, // right-arrow |
6857 GDK_CENTER_PTR, /* up-arrow */ | 6845 GDK_CENTER_PTR, // up-arrow |
6858 GDK_LEFT_PTR /* last one */ | 6846 GDK_LEFT_PTR // last one |
6859 }; | 6847 }; |
6860 | 6848 |
6861 void | 6849 void |
6862 mch_set_mouse_shape(int shape) | 6850 mch_set_mouse_shape(int shape) |
6863 { | 6851 { |
6876 { | 6864 { |
6877 id = shape - MSHAPE_NUMBERED; | 6865 id = shape - MSHAPE_NUMBERED; |
6878 if (id >= GDK_LAST_CURSOR) | 6866 if (id >= GDK_LAST_CURSOR) |
6879 id = GDK_LEFT_PTR; | 6867 id = GDK_LEFT_PTR; |
6880 else | 6868 else |
6881 id &= ~1; /* they are always even (why?) */ | 6869 id &= ~1; // they are always even (why?) |
6882 } | 6870 } |
6883 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) | 6871 else if (shape < (int)(sizeof(mshape_ids) / sizeof(int))) |
6884 id = mshape_ids[shape]; | 6872 id = mshape_ids[shape]; |
6885 else | 6873 else |
6886 return; | 6874 return; |
6888 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); | 6876 gtk_widget_get_display(gui.drawarea), (GdkCursorType)id); |
6889 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), c); | 6877 gdk_window_set_cursor(gtk_widget_get_window(gui.drawarea), c); |
6890 # if GTK_CHECK_VERSION(3,0,0) | 6878 # if GTK_CHECK_VERSION(3,0,0) |
6891 g_object_unref(G_OBJECT(c)); | 6879 g_object_unref(G_OBJECT(c)); |
6892 # else | 6880 # else |
6893 gdk_cursor_destroy(c); /* Unref, actually. Bloody GTK+ 1. */ | 6881 gdk_cursor_destroy(c); // Unref, actually. Bloody GTK+ 1. |
6894 # endif | 6882 # endif |
6895 } | 6883 } |
6896 if (shape != MSHAPE_HIDE) | 6884 if (shape != MSHAPE_HIDE) |
6897 last_shape = shape; | 6885 last_shape = shape; |
6898 } | 6886 } |
6899 #endif /* FEAT_MOUSESHAPE */ | 6887 #endif // FEAT_MOUSESHAPE |
6900 | 6888 |
6901 | 6889 |
6902 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) | 6890 #if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
6903 /* | 6891 /* |
6904 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be | 6892 * Signs are currently always 2 chars wide. With GTK+ 2, the image will be |
6943 { | 6931 { |
6944 double aspect; | 6932 double aspect; |
6945 int w = width; | 6933 int w = width; |
6946 int h = height; | 6934 int h = height; |
6947 | 6935 |
6948 /* Keep the original aspect ratio */ | 6936 // Keep the original aspect ratio |
6949 aspect = (double)height / (double)width; | 6937 aspect = (double)height / (double)width; |
6950 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; | 6938 width = (double)SIGN_WIDTH * SIGN_ASPECT / aspect; |
6951 width = MIN(width, SIGN_WIDTH); | 6939 width = MIN(width, SIGN_WIDTH); |
6952 if (((double)(MAX(height, SIGN_HEIGHT)) / | 6940 if (((double)(MAX(height, SIGN_HEIGHT)) / |
6953 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) | 6941 (double)(MIN(height, SIGN_HEIGHT))) < 1.15) |
6954 { | 6942 { |
6955 /* Change the aspect ratio by at most 15% to fill the | 6943 // Change the aspect ratio by at most 15% to fill the |
6956 * available space completely. */ | 6944 // available space completely. |
6957 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; | 6945 height = (double)SIGN_HEIGHT * SIGN_ASPECT / aspect; |
6958 height = MIN(height, SIGN_HEIGHT); | 6946 height = MIN(height, SIGN_HEIGHT); |
6959 } | 6947 } |
6960 else | 6948 else |
6961 height = (double)width * aspect; | 6949 height = (double)width * aspect; |
6962 | 6950 |
6963 if (w == width && h == height) | 6951 if (w == width && h == height) |
6964 { | 6952 { |
6965 /* no change in dimensions; don't decrease reference counter | 6953 // no change in dimensions; don't decrease reference counter |
6966 * (below) */ | 6954 // (below) |
6967 need_scale = FALSE; | 6955 need_scale = FALSE; |
6968 } | 6956 } |
6969 else | 6957 else |
6970 { | 6958 { |
6971 /* This doesn't seem to be worth caching, and doing so would | 6959 // This doesn't seem to be worth caching, and doing so would |
6972 * complicate the code quite a bit. */ | 6960 // complicate the code quite a bit. |
6973 sign = gdk_pixbuf_scale_simple(sign, width, height, | 6961 sign = gdk_pixbuf_scale_simple(sign, width, height, |
6974 GDK_INTERP_BILINEAR); | 6962 GDK_INTERP_BILINEAR); |
6975 if (sign == NULL) | 6963 if (sign == NULL) |
6976 return; /* out of memory */ | 6964 return; // out of memory |
6977 } | 6965 } |
6978 } | 6966 } |
6979 | 6967 |
6980 /* The origin is the upper-left corner of the pixmap. Therefore | 6968 // The origin is the upper-left corner of the pixmap. Therefore |
6981 * these offset may become negative if the pixmap is smaller than | 6969 // these offset may become negative if the pixmap is smaller than |
6982 * the 2x1 cells reserved for the sign icon. */ | 6970 // the 2x1 cells reserved for the sign icon. |
6983 xoffset = (width - SIGN_WIDTH) / 2; | 6971 xoffset = (width - SIGN_WIDTH) / 2; |
6984 yoffset = (height - SIGN_HEIGHT) / 2; | 6972 yoffset = (height - SIGN_HEIGHT) / 2; |
6985 | 6973 |
6986 # if GTK_CHECK_VERSION(3,0,0) | 6974 # if GTK_CHECK_VERSION(3,0,0) |
6987 { | 6975 { |
7025 if (!gui.by_signal) | 7013 if (!gui.by_signal) |
7026 gtk_widget_queue_draw_area(gui.drawarea, | 7014 gtk_widget_queue_draw_area(gui.drawarea, |
7027 FILL_X(col), FILL_Y(col), width, height); | 7015 FILL_X(col), FILL_Y(col), width, height); |
7028 | 7016 |
7029 } | 7017 } |
7030 # else /* !GTK_CHECK_VERSION(3,0,0) */ | 7018 # else // !GTK_CHECK_VERSION(3,0,0) |
7031 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); | 7019 gdk_gc_set_foreground(gui.text_gc, gui.bgcolor); |
7032 | 7020 |
7033 gdk_draw_rectangle(gui.drawarea->window, | 7021 gdk_draw_rectangle(gui.drawarea->window, |
7034 gui.text_gc, | 7022 gui.text_gc, |
7035 TRUE, | 7023 TRUE, |
7048 MIN(height, SIGN_HEIGHT), | 7036 MIN(height, SIGN_HEIGHT), |
7049 GDK_PIXBUF_ALPHA_BILEVEL, | 7037 GDK_PIXBUF_ALPHA_BILEVEL, |
7050 127, | 7038 127, |
7051 GDK_RGB_DITHER_NORMAL, | 7039 GDK_RGB_DITHER_NORMAL, |
7052 0, 0); | 7040 0, 0); |
7053 # endif /* !GTK_CHECK_VERSION(3,0,0) */ | 7041 # endif // !GTK_CHECK_VERSION(3,0,0) |
7054 if (need_scale) | 7042 if (need_scale) |
7055 g_object_unref(sign); | 7043 g_object_unref(sign); |
7056 } | 7044 } |
7057 } | 7045 } |
7058 | 7046 |
7075 if (message != NULL && input_conv.vc_type != CONV_NONE) | 7063 if (message != NULL && input_conv.vc_type != CONV_NONE) |
7076 message = string_convert(&input_conv, message, NULL); | 7064 message = string_convert(&input_conv, message, NULL); |
7077 | 7065 |
7078 if (message != NULL) | 7066 if (message != NULL) |
7079 { | 7067 { |
7080 /* The error message is already translated and will be more | 7068 // The error message is already translated and will be more |
7081 * descriptive than anything we could possibly do ourselves. */ | 7069 // descriptive than anything we could possibly do ourselves. |
7082 semsg("E255: %s", message); | 7070 semsg("E255: %s", message); |
7083 | 7071 |
7084 if (input_conv.vc_type != CONV_NONE) | 7072 if (input_conv.vc_type != CONV_NONE) |
7085 vim_free(message); | 7073 vim_free(message); |
7086 } | 7074 } |
7095 { | 7083 { |
7096 if (sign != NULL) | 7084 if (sign != NULL) |
7097 g_object_unref(sign); | 7085 g_object_unref(sign); |
7098 } | 7086 } |
7099 | 7087 |
7100 #endif /* FEAT_SIGN_ICONS */ | 7088 #endif // FEAT_SIGN_ICONS |