The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

GtkWindow.vala in birdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of birdfont/GtkWindow.vala.
Merge branch 'master' of github.com:johanmattssonm/birdfont
1 /* 2 Copyright (C) 2012, 2013, 2014 Johan Mattsson 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 using Cairo; 19 using Gtk; 20 using Gdk; 21 using BirdFont; 22 using WebKit; 23 using Gdk; 24 using Notify; 25 26 namespace BirdFont { 27 28 public class GtkWindow : Gtk.Window, NativeWindow { 29 30 Box list_box; 31 Box canvas_box; 32 33 WebView html_canvas; 34 ScrolledWindow html_box; 35 36 Box tab_box; 37 38 GlyphCanvasArea glyph_canvas_area; 39 40 Clipboard clipboard; 41 string clipboard_svg = ""; 42 string inkscape_clipboard = ""; 43 44 Scrollbar scrollbar; 45 bool scrollbar_supress_signal = false; 46 47 /** Text input and callbacks. */ 48 public static bool text_input_is_active = false; 49 TextListener text_listener = new TextListener ("", "", ""); 50 Label text_input_label; 51 Entry text_entry; 52 Box text_box; 53 Gtk.Button submit_text_button; 54 55 Gtk.Window tooltip_window = new Gtk.Window (); 56 57 ToolboxCanvas toolbox; 58 59 Task background_task = new Task (); 60 61 public GtkWindow (string title) { 62 scrollbar = new Scrollbar (Orientation.VERTICAL, new Adjustment (0, 0, 1, 1, 0.01, 0.1)); 63 ((Gtk.Window)this).set_title ("BirdFont"); 64 } 65 66 public void init () { 67 Notify.init ("Fonts have been exported."); 68 69 clipboard = Clipboard.get_for_display (get_display (), Gdk.SELECTION_CLIPBOARD); 70 71 Signal.connect(this, "notify::is-active", (GLib.Callback) window_focus, null); 72 73 scrollbar.value_changed.connect (() => { 74 double p; 75 76 if (!scrollbar_supress_signal) { 77 p = scrollbar.get_value () / (1 - scrollbar.adjustment.page_size); 78 FontDisplay display = MainWindow.get_current_display (); 79 display.scroll_to (p); 80 } 81 }); 82 83 delete_event.connect (() => { 84 MenuTab.quit (); 85 return true; 86 }); 87 88 set_size_and_position (); 89 90 glyph_canvas_area = new GlyphCanvasArea (MainWindow.glyph_canvas); 91 92 html_canvas = new WebView (); 93 WebKit.set_cache_model (CacheModel.DOCUMENT_VIEWER); 94 html_canvas.get_settings ().enable_default_context_menu = false; 95 96 html_box = new ScrolledWindow (null, null); 97 html_box.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC); 98 html_box.add (html_canvas); 99 html_canvas.set_editable (true); 100 101 MainWindow.get_tab_bar ().signal_tab_selected.connect ((f, tab) => { 102 string uri = ""; 103 string html = ""; 104 FontDisplay fd = tab.get_display (); 105 106 scrollbar.set_visible (fd.has_scrollbar ()); 107 108 if (fd.get_name () == "Preview") { 109 uri = Preview.get_uri (); 110 html = Preview.get_html_with_absolute_paths (); 111 112 try { 113 html_canvas.load_html_string (html, uri); 114 } catch (Error e) { 115 warning (e.message); 116 warning ("Failed to load html into canvas."); 117 } 118 119 // show the webview when loading has finished 120 html_box.set_visible (true); 121 glyph_canvas_area.set_visible (false); 122 } else { 123 html_box.set_visible (false); 124 glyph_canvas_area.set_visible (true); 125 } 126 }); 127 128 // Hide this canvas when window is realized and flip canvas 129 // visibility in tab selection signal. 130 html_canvas.draw.connect ((t, e) => { 131 glyph_canvas_area.set_visible (false); 132 return false; 133 }); 134 135 canvas_box = new Box (Orientation.HORIZONTAL, 0); 136 canvas_box.pack_start (glyph_canvas_area, true, true, 0); 137 canvas_box.pack_start (html_box, true, true, 0); 138 canvas_box.pack_start (scrollbar, false, true, 0); 139 140 submit_text_button = new Gtk.Button (); 141 submit_text_button.set_label ("Submit"); 142 text_input_label = new Label (" " + "Text"); 143 text_entry = new Entry (); 144 text_box = new Box (Orientation.HORIZONTAL, 6); 145 text_box.pack_start (text_input_label, false, false, 0); 146 text_box.pack_start (text_entry, true, true, 0); 147 text_box.pack_start (submit_text_button, false, false, 0); 148 149 text_entry.changed.connect (() => { 150 text_listener.signal_text_input (text_entry.text); 151 }); 152 153 submit_text_button.clicked.connect (() => { 154 text_listener.signal_submit (text_entry.text); 155 text_input_is_active = false; 156 }); 157 158 tab_box = new Box (Orientation.VERTICAL, 0); 159 160 tab_box.pack_start (new TabbarCanvas (MainWindow.get_tab_bar ()), false, false, 0); 161 tab_box.pack_start (text_box, false, false, 5); 162 tab_box.pack_start (canvas_box, true, true, 0); 163 164 toolbox = new ToolboxCanvas (MainWindow.get_toolbox ()); 165 list_box = new Box (Orientation.HORIZONTAL, 0); 166 list_box.pack_start (toolbox, false, false, 0); 167 list_box.pack_start (tab_box, true, true, 0); 168 169 Box vbox = new Box (Orientation.VERTICAL, 0); 170 vbox.pack_start(list_box, true, true, 0); 171 add (vbox); 172 173 try { 174 set_icon_from_file ((!) SearchPaths.find_file (null, "birdfont_window_icon.png").get_path ()); 175 } catch (GLib.Error e) { 176 warning (e.message); 177 } 178 179 key_press_event.connect ((t, event) => { 180 if (!GtkWindow.text_input_is_active) { 181 GtkWindow.reset_modifier (event.state); 182 TabContent.key_press (event.keyval); 183 } 184 185 return false; 186 }); 187 188 key_release_event.connect ((t, event) => { 189 if (!GtkWindow.text_input_is_active) { 190 TabContent.key_release (event.keyval); 191 } 192 193 return false; 194 }); 195 196 show_all (); 197 198 scrollbar.set_visible (false); 199 200 hide_text_input (); 201 202 MainWindow.open_recent_files_tab (); 203 } 204 205 public void window_focus (void* data) { 206 TabContent.reset_modifier (); 207 } 208 209 public static void reset_modifier (ModifierType flags) { 210 if ((flags & ModifierType.CONTROL_MASK) == 0) { 211 TabContent.key_release (Key.CTRL_RIGHT); 212 TabContent.key_release (Key.CTRL_LEFT); 213 } 214 215 if ((flags & ModifierType.SHIFT_MASK) == 0) { 216 TabContent.key_release (Key.SHIFT_LEFT); 217 TabContent.key_release (Key.SHIFT_RIGHT); 218 } 219 220 if ((flags & ModifierType.MOD1_MASK) == 0) { 221 TabContent.key_release (Key.ALT_LEFT); 222 TabContent.key_release (Key.ALT_RIGHT); 223 } 224 225 if ((flags & ModifierType.MOD5_MASK) == 0) { 226 TabContent.key_release (Key.LOGO_LEFT); 227 TabContent.key_release (Key.LOGO_RIGHT); 228 } 229 } 230 231 public void font_loaded () { 232 Font f = BirdFont.get_current_font (); 233 set_title (@"$(f.full_name)"); 234 } 235 236 public void set_scrollbar_size (double size) { 237 scrollbar.adjustment.page_size = size; 238 scrollbar.set_visible (size != 0); 239 } 240 241 public void set_scrollbar_position (double position) { 242 scrollbar_supress_signal = true; 243 scrollbar.adjustment.value = position * (1 - scrollbar.adjustment.page_size); 244 scrollbar_supress_signal = false; 245 } 246 247 public void dump_clipboard_content (Clipboard clipboard, SelectionData selection_data) { 248 string d; 249 return_if_fail (!is_null (selection_data)); 250 d = (string) ((!) selection_data); 251 stdout.printf (d); 252 } 253 254 public void dump_clipboard_target (Clipboard clipboard, Atom[] atoms) { 255 foreach (Atom target in atoms) { 256 print ("Target: " + target.name () + "\n"); 257 clipboard.request_contents (target, dump_clipboard_content); 258 } 259 } 260 261 public void dump_clipboard () { 262 clipboard.request_targets (dump_clipboard_target); 263 } 264 265 public string get_clipboard_data () { 266 SelectionData? selection_data; 267 Atom target; 268 string? t; 269 270 target = Atom.intern_static_string ("image/x-inkscape-svg"); 271 selection_data = clipboard.wait_for_contents (target); 272 273 if (!is_null (selection_data)) { 274 return (string) (((!) selection_data).get_data ()); 275 } 276 277 t = clipboard.wait_for_text (); 278 if (t != null) { 279 return (!) t; 280 } 281 282 return ""; 283 } 284 285 public void set_inkscape_clipboard (string inkscape_clipboard_data) { 286 if (BirdFont.mac) { 287 clipboard.set_text (inkscape_clipboard_data, -1); 288 } else { 289 TargetEntry t = { "image/x-inkscape-svg", 0, 0 }; 290 TargetEntry[] targets = { t }; 291 inkscape_clipboard = inkscape_clipboard_data; 292 293 // we can not add data to this closure because the third argument 294 // is owner and not private data. 295 clipboard.set_with_owner (targets, 296 297 // obtain clipboard data 298 (clipboard, selection_data, info, owner) => { 299 Atom type; 300 uchar[] data = (uchar[])(!)((GtkWindow*)owner)->inkscape_clipboard.to_utf8 (); 301 type = Atom.intern_static_string ("image/x-inkscape-svg"); 302 selection_data.set (type, 8, data); 303 }, 304 305 // clear clipboard data 306 (clipboard, user_data) => { 307 }, 308 309 this); 310 } 311 } 312 313 public void set_clipboard_text (string text) { 314 clipboard.set_text (text, -1); 315 } 316 317 public string get_clipboard_text () { 318 string? t; 319 320 t = clipboard.wait_for_text (); 321 if (t != null) { 322 return ((!) t).dup (); 323 } 324 325 return "".dup (); 326 } 327 328 public void set_clipboard (string svg) { 329 TargetEntry t = { "image/svg+xml", 0, 0 }; 330 TargetEntry[] targets = { t }; 331 clipboard_svg = svg; 332 clipboard.set_with_owner (targets, 333 334 // obtain clipboard data 335 (clipboard, selection_data, info, owner) => { 336 Atom type; 337 uchar[] data = (uchar[])(!)((GtkWindow*)owner)->clipboard_svg.to_utf8 (); 338 type = Atom.intern_static_string ("image/svg+xml"); 339 selection_data.set (type, 0, data); 340 }, 341 342 // clear clipboard data 343 (clipboard, user_data) => { 344 }, 345 346 this); 347 } 348 349 public void update_window_size () { 350 int w, h; 351 get_size (out w, out h); 352 353 Preferences.set ("window_width", @"$w"); 354 Preferences.set ("window_height", @"$h"); 355 } 356 357 private void set_size_and_position () { 358 int w = Preferences.get_window_width (); 359 int h = Preferences.get_window_height (); 360 set_default_size (w, h); 361 } 362 363 public void quit () { 364 Gtk.main_quit (); 365 } 366 367 public void file_chooser (string title, FileChooser fc, uint flags) { 368 string? fn = null; 369 bool folder; 370 if (BirdFont.get_arguments () .has_argument ("--windows")) { 371 folder = (flags & FileChooser.DIRECTORY) > 0; 372 MenuTab.show_file_dialog_tab (title, fc, folder); 373 } else { 374 if ((flags & FileChooser.DIRECTORY) > 0) { 375 if ((flags & FileChooser.LOAD) > 0) { 376 fn = show_file_chooser (title, FileChooserAction.SELECT_FOLDER, Stock.OPEN); 377 } else if ((flags & FileChooser.SAVE) > 0) { 378 fn = show_file_chooser (title, FileChooserAction.SELECT_FOLDER, Stock.SAVE); 379 } else { 380 warning ("Open or save is not set."); 381 } 382 } else if ((flags & FileChooser.LOAD) > 0) { 383 fn = show_file_chooser (title, FileChooserAction.OPEN, Stock.OPEN); 384 } else if ((flags & FileChooser.SAVE) > 0) { 385 fn = show_file_chooser (title, FileChooserAction.SAVE, Stock.SAVE); 386 } else { 387 warning ("Unknown type"); 388 } 389 } 390 391 fc.selected (fn); 392 } 393 394 public string? show_file_chooser (string title, FileChooserAction action, string label) { 395 string? fn = null; 396 FileChooserDialog file_chooser = new FileChooserDialog (title, this, action, Stock.CANCEL, ResponseType.CANCEL, label, ResponseType.ACCEPT); 397 Font font = BirdFont.get_current_font (); 398 int i; 399 string last_folder; 400 401 last_folder = Preferences.get ("last_folder"); 402 403 try { 404 if (last_folder == "") { 405 file_chooser.set_current_folder_file (font.get_folder ()); 406 } else { 407 file_chooser.set_current_folder_file (File.new_for_path (last_folder)); 408 } 409 } catch (GLib.Error e) { 410 stderr.printf (e.message); 411 } 412 413 if (file_chooser.run () == ResponseType.ACCEPT) { 414 GlyphCanvas.redraw (); 415 fn = file_chooser.get_filename (); 416 } 417 418 file_chooser.destroy (); 419 420 if (fn != null) { 421 i = ((!) fn).last_index_of ("/"); 422 if (i > -1) { 423 last_folder = ((!) fn).substring (0, i); 424 Preferences.set ("last_folder", @"$last_folder"); 425 } 426 } 427 428 return fn; 429 } 430 431 public void hide_text_input () { 432 text_listener = new TextListener ("", "", ""); 433 text_box.hide (); 434 text_input_is_active = false; 435 } 436 437 public void set_text_listener (TextListener listener) { 438 text_listener = listener; 439 text_input_label.set_text (" " + listener.label); 440 submit_text_button.set_label (listener.button_label); 441 text_box.show (); 442 text_entry.set_text (listener.default_text); 443 text_entry.activate.connect (() => { 444 text_listener.signal_submit (text_entry.text); 445 text_input_is_active = false; 446 }); 447 text_entry.grab_focus (); 448 text_input_is_active = true; 449 } 450 451 public bool convert_to_png (string from, string to) { 452 Pixbuf pixbuf; 453 string folder; 454 int i; 455 456 try { 457 i = to.last_index_of ("/"); 458 if (i != -1) { 459 folder = to.substring (0, i); 460 DirUtils.create (folder, 0xFFFFFF); 461 } 462 463 pixbuf = new Pixbuf.from_file (from); 464 pixbuf.save (to, "png"); 465 } catch (GLib.Error e) { 466 warning (e.message); 467 return false; 468 } 469 470 return true; 471 } 472 473 public void run_background_thread (Task t) { 474 unowned Thread<void*> bg; 475 476 MenuTab.start_background_thread (); 477 background_task = t; 478 479 try { 480 bg = Thread.create<void*> (this.background_thread, true); 481 } catch (GLib.Error e) { 482 warning (e.message); 483 } 484 } 485 486 public void run_non_blocking_background_thread (Task t) { 487 unowned Thread<void*> bg; 488 489 try { 490 bg = Thread.create<void*> (t.perform_task, true); 491 } catch (GLib.Error e) { 492 warning (e.message); 493 } 494 } 495 496 public void* background_thread () { 497 background_task.run (); 498 MenuTab.stop_background_thread (); 499 return null; 500 } 501 502 /** Run export in a background thread. */ 503 public void export_font () { 504 unowned Thread<void*> export_thread; 505 506 MenuTab.start_background_thread (); 507 508 try { 509 export_thread = Thread.create<void*> (this.export_thread, true); 510 } catch (GLib.Error e) { 511 warning (e.message); 512 } 513 } 514 515 public void* export_thread () { 516 IdleSource idle = new IdleSource (); 517 518 ExportCallback.export_fonts (); 519 MenuTab.stop_background_thread (); 520 MenuTab.signal_file_exported (); 521 522 idle.set_callback (() => { 523 Notify.Notification export_notification; 524 export_notification = new Notify.Notification ("BirdFont", t_("Your fonts have been exported."), null); 525 export_notification.show (); 526 return false; 527 }); 528 idle.attach (null); 529 530 return null; 531 } 532 533 /** Load font in a background thread. */ 534 public void load () { 535 unowned Thread<void*> thread; 536 537 MenuTab.start_background_thread (); 538 539 try { 540 thread = Thread.create<void*> (this.loading_thread, true); 541 } catch (GLib.Error e) { 542 warning (e.message); 543 } 544 } 545 546 public void* loading_thread () { 547 BirdFont.get_current_font ().load (); 548 MenuTab.stop_background_thread (); 549 MenuTab.signal_file_loaded (); 550 return null; 551 } 552 553 /** Save font in a background thread. */ 554 public void save () { 555 unowned Thread<void*> thread; 556 557 MenuTab.start_background_thread (); 558 559 try { 560 thread = Thread.create<void*> (this.saving_thread, true); 561 } catch (GLib.Error e) { 562 warning (e.message); 563 } 564 } 565 566 public void* saving_thread () { 567 BirdFont.get_current_font ().save (); 568 MenuTab.stop_background_thread (); 569 MenuTab.signal_file_saved (); 570 return null; 571 } 572 573 public void load_background_image () { 574 unowned Thread<void*> thread; 575 576 MenuTab.start_background_thread (); 577 578 try { 579 thread = Thread.create<void*> (this.background_image_thread, true); 580 } catch (GLib.Error e) { 581 warning (e.message); 582 } 583 } 584 585 public void* background_image_thread () { 586 BackgroundTool.load_background_image (); 587 MenuTab.stop_background_thread (); 588 return null; 589 } 590 591 public bool can_export () { 592 return true; 593 } 594 595 public void set_cursor (int visible) { 596 if (visible != NativeWindow.VISIBLE) { 597 get_window ().set_cursor (new Cursor (CursorType.BLANK_CURSOR)); 598 } else { 599 get_window ().set_cursor (new Cursor (CursorType.ARROW)); 600 } 601 } 602 603 public double get_screen_scale () { 604 return 1; 605 } 606 } 607 608 class TabbarCanvas : DrawingArea { 609 TabBar tabbar; 610 611 public TabbarCanvas (TabBar tb) { 612 tabbar = tb; 613 614 // FIXME: DELETE set_extension_events (ExtensionMode.CURSOR | EventMask.POINTER_MOTION_MASK); 615 add_events (EventMask.BUTTON_PRESS_MASK | EventMask.POINTER_MOTION_MASK | EventMask.LEAVE_NOTIFY_MASK); 616 617 motion_notify_event.connect ((t, e)=> { 618 Gtk.Allocation alloc; 619 tabbar.motion (e.x, e.y); 620 get_allocation (out alloc); 621 queue_draw_area (0, 0, alloc.width, alloc.height); 622 return true; 623 }); 624 625 button_press_event.connect ((t, e)=> { 626 Gtk.Allocation alloc; 627 get_allocation (out alloc); 628 GtkWindow.reset_modifier (e.state); 629 tabbar.select_tab_click (e.x, e.y, alloc.width, alloc.height); 630 queue_draw_area (0, 0, alloc.width, alloc.height); 631 return true; 632 }); 633 634 draw.connect ((t, e)=> { 635 Gtk.Allocation alloc; 636 Context cr; 637 StyleContext context; 638 Gdk.RGBA color; 639 640 cr = cairo_create (get_window ()); 641 get_allocation (out alloc); 642 643 context = get_style_context (); 644 context.add_class (STYLE_CLASS_BUTTON); 645 color = context.get_background_color (Gtk.StateFlags.NORMAL); 646 647 if (color.alpha > 0) { 648 tabbar.set_background_color (color.red, color.green, color.blue); 649 } 650 651 tabbar.draw (cr, alloc.width, alloc.height); 652 return true; 653 }); 654 655 tabbar.signal_tab_selected.connect ((t) => { 656 Gtk.Allocation alloc; 657 get_allocation (out alloc); 658 queue_draw_area (0, 0, alloc.width, alloc.height); 659 }); 660 661 tabbar.redraw_tab_bar.connect ((x, y, w, h) => { 662 queue_draw_area (x, y, w, h); 663 }); 664 665 set_size_request (20, 38); 666 } 667 668 } 669 670 class ToolboxCanvas : DrawingArea { 671 Toolbox tb; 672 673 public ToolboxCanvas (Toolbox toolbox) { 674 tb = toolbox; 675 676 realize.connect (() => { 677 Gtk.Allocation allocation; 678 get_allocation (out allocation); 679 Toolbox.allocation_width = allocation.width; 680 Toolbox.allocation_height = allocation.height; 681 Toolbox.redraw_tool_box (); 682 }); 683 684 tb.redraw.connect ((x, y, w, h) => { 685 queue_draw_area (x, y, w, h); 686 }); 687 688 button_press_event.connect ((se, e)=> { 689 if (e.type == EventType.2BUTTON_PRESS) { 690 tb.double_click (e.button, e.x, e.y); 691 } else { 692 tb.press (e.button, e.x, e.y); 693 } 694 return true; 695 }); 696 697 button_release_event.connect ((se, e)=> { 698 tb.release (e.button, e.x, e.y); 699 return true; 700 }); 701 702 motion_notify_event.connect ((sen, e)=> { 703 // FIXME: e.y is two pixels off in GTK under Gnome 704 tb.move (e.x, e.y); 705 return true; 706 }); 707 708 draw.connect ((t, e)=> { 709 Gtk.Allocation allocation; 710 get_allocation (out allocation); 711 712 Context cw = cairo_create(get_window()); 713 Toolbox.allocation_width = allocation.width; 714 Toolbox.allocation_height = allocation.height; 715 tb.draw (allocation.width, allocation.height, cw); 716 717 return true; 718 }); 719 720 scroll_event.connect ((t, e)=> { 721 if (e.direction == Gdk.ScrollDirection.UP) { 722 tb.scroll_up (e.x, e.y); 723 } else if (e.direction == Gdk.ScrollDirection.DOWN) { 724 tb.scroll_down (e.x, e.y); 725 } 726 return true; 727 }); 728 729 add_events (EventMask.BUTTON_PRESS_MASK | EventMask.BUTTON_RELEASE_MASK | EventMask.POINTER_MOTION_MASK | EventMask.LEAVE_NOTIFY_MASK | EventMask.SCROLL_MASK); 730 731 set_size_request (212, 100); 732 733 leave_notify_event.connect ((t, e)=> { 734 tb.reset_active_tool (); 735 return true; 736 }); 737 738 } 739 } 740 741 public class GlyphCanvasArea : DrawingArea { 742 GlyphCanvas glyph_canvas; 743 WidgetAllocation alloc = new WidgetAllocation (); 744 uint32 last_release = 0; 745 uint32 last_press = 0; 746 747 public GlyphCanvasArea (GlyphCanvas gc) { 748 int event_flags; 749 750 glyph_canvas = gc; 751 752 event_flags = EventMask.BUTTON_PRESS_MASK; 753 event_flags |= EventMask.BUTTON_RELEASE_MASK; 754 event_flags |= EventMask.POINTER_MOTION_MASK; 755 event_flags |= EventMask.LEAVE_NOTIFY_MASK; 756 event_flags |= EventMask.SCROLL_MASK; 757 758 add_events (event_flags); 759 760 bool button_down = false; 761 762 glyph_canvas.signal_redraw_area.connect ((x, y, w, h) => { 763 queue_draw_area ((int)x, (int)y, (int)w, (int)h); 764 }); 765 766 draw.connect ((t, e)=> { 767 Gtk.Allocation allocation; 768 get_allocation (out allocation); 769 770 alloc = new WidgetAllocation (); 771 772 alloc.width = allocation.width; 773 alloc.height = allocation.height; 774 alloc.x = allocation.x; 775 alloc.y = allocation.y; 776 777 Context cw = cairo_create (get_window()); 778 779 Surface s = new Surface.similar (cw.get_target (), Cairo.Content.COLOR_ALPHA, alloc.width, alloc.height); 780 Context c = new Context (s); 781 782 TabContent.draw (alloc, c); 783 784 cw.save (); 785 cw.set_source_surface (c.get_target (), 0, 0); 786 cw.paint (); 787 cw.restore (); 788 789 return true; 790 }); 791 792 button_press_event.connect ((t, e)=> { 793 GtkWindow.reset_modifier (e.state); 794 795 if (button_down) { 796 warning (@"Button already is down. $(e.button)"); 797 } 798 799 if (e.time < last_press) { 800 warning ("Discarding event."); 801 return true; 802 } 803 804 last_press = e.time; 805 806 if (e.type == EventType.BUTTON_PRESS) { 807 TabContent.button_press (e.button, e.x, e.y); 808 button_down = true; 809 } else if (e.type == EventType.2BUTTON_PRESS) { 810 TabContent.double_click (e.button, e.x, e.y); 811 } 812 813 return true; 814 }); 815 816 button_release_event.connect ((t, e)=> { 817 if (!button_down) { 818 warning (@"Button is not down $(e.button)"); 819 } 820 821 if (e.time < last_release) { 822 warning ("Discarding event."); 823 return true; 824 } 825 826 if (e.type == EventType.BUTTON_RELEASE) { 827 TabContent.button_release ((int) e.button, e.x, e.y); 828 last_release = e.time; 829 button_down = false; 830 } 831 832 return true; 833 }); 834 835 motion_notify_event.connect ((t, e)=> { 836 TabContent.motion_notify (e.x, e.y); 837 return true; 838 }); 839 840 scroll_event.connect ((t, e)=> { 841 if (e.direction == Gdk.ScrollDirection.UP) { 842 TabContent.scroll_wheel_up (e.x, e.y); 843 } else if (e.direction == Gdk.ScrollDirection.DOWN) { 844 TabContent.scroll_wheel_down (e.x, e.y) ; 845 } 846 847 TabContent.button_release (2, e.x, e.y); 848 return true; 849 }); 850 851 can_focus = true; 852 } 853 } 854 855 } 856