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.
Fix thread function return type for tasks
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 604 class TabbarCanvas : DrawingArea { 605 TabBar tabbar; 606 607 public TabbarCanvas (TabBar tb) { 608 tabbar = tb; 609 610 // FIXME: DELETE set_extension_events (ExtensionMode.CURSOR | EventMask.POINTER_MOTION_MASK); 611 add_events (EventMask.BUTTON_PRESS_MASK | EventMask.POINTER_MOTION_MASK | EventMask.LEAVE_NOTIFY_MASK); 612 613 motion_notify_event.connect ((t, e)=> { 614 Gtk.Allocation alloc; 615 tabbar.motion (e.x, e.y); 616 get_allocation (out alloc); 617 queue_draw_area (0, 0, alloc.width, alloc.height); 618 return true; 619 }); 620 621 button_press_event.connect ((t, e)=> { 622 Gtk.Allocation alloc; 623 get_allocation (out alloc); 624 GtkWindow.reset_modifier (e.state); 625 tabbar.select_tab_click (e.x, e.y, alloc.width, alloc.height); 626 queue_draw_area (0, 0, alloc.width, alloc.height); 627 return true; 628 }); 629 630 draw.connect ((t, e)=> { 631 Gtk.Allocation alloc; 632 Context cr; 633 StyleContext context; 634 Gdk.RGBA color; 635 636 cr = cairo_create (get_window ()); 637 get_allocation (out alloc); 638 639 context = get_style_context (); 640 context.add_class (STYLE_CLASS_BUTTON); 641 color = context.get_background_color (Gtk.StateFlags.NORMAL); 642 643 if (color.alpha > 0) { 644 tabbar.set_background_color (color.red, color.green, color.blue); 645 } 646 647 tabbar.draw (cr, alloc.width, alloc.height); 648 return true; 649 }); 650 651 tabbar.signal_tab_selected.connect ((t) => { 652 Gtk.Allocation alloc; 653 get_allocation (out alloc); 654 queue_draw_area (0, 0, alloc.width, alloc.height); 655 }); 656 657 tabbar.redraw_tab_bar.connect ((x, y, w, h) => { 658 queue_draw_area (x, y, w, h); 659 }); 660 661 set_size_request (20, 38); 662 } 663 664 } 665 666 class ToolboxCanvas : DrawingArea { 667 Toolbox tb; 668 669 public ToolboxCanvas (Toolbox toolbox) { 670 tb = toolbox; 671 672 realize.connect (() => { 673 Gtk.Allocation allocation; 674 get_allocation (out allocation); 675 Toolbox.allocation_width = allocation.width; 676 Toolbox.allocation_height = allocation.height; 677 Toolbox.redraw_tool_box (); 678 }); 679 680 tb.redraw.connect ((x, y, w, h) => { 681 queue_draw_area (x, y, w, h); 682 }); 683 684 button_press_event.connect ((se, e)=> { 685 if (e.type == EventType.2BUTTON_PRESS) { 686 tb.double_click (e.button, e.x, e.y); 687 } else { 688 tb.press (e.button, e.x, e.y); 689 } 690 return true; 691 }); 692 693 button_release_event.connect ((se, e)=> { 694 tb.release (e.button, e.x, e.y); 695 return true; 696 }); 697 698 motion_notify_event.connect ((sen, e)=> { 699 // FIXME: e.y is two pixels off in GTK under Gnome 700 tb.move (e.x, e.y); 701 return true; 702 }); 703 704 draw.connect ((t, e)=> { 705 Gtk.Allocation allocation; 706 get_allocation (out allocation); 707 708 Context cw = cairo_create(get_window()); 709 Toolbox.allocation_width = allocation.width; 710 Toolbox.allocation_height = allocation.height; 711 tb.draw (allocation.width, allocation.height, cw); 712 713 return true; 714 }); 715 716 scroll_event.connect ((t, e)=> { 717 if (e.direction == Gdk.ScrollDirection.UP) { 718 tb.scroll_up (e.x, e.y); 719 } else if (e.direction == Gdk.ScrollDirection.DOWN) { 720 tb.scroll_down (e.x, e.y); 721 } 722 return true; 723 }); 724 725 add_events (EventMask.BUTTON_PRESS_MASK | EventMask.BUTTON_RELEASE_MASK | EventMask.POINTER_MOTION_MASK | EventMask.LEAVE_NOTIFY_MASK | EventMask.SCROLL_MASK); 726 727 set_size_request (212, 100); 728 729 leave_notify_event.connect ((t, e)=> { 730 tb.reset_active_tool (); 731 return true; 732 }); 733 734 } 735 } 736 737 public class GlyphCanvasArea : DrawingArea { 738 GlyphCanvas glyph_canvas; 739 WidgetAllocation alloc = new WidgetAllocation (); 740 uint32 last_release = 0; 741 uint32 last_press = 0; 742 743 public GlyphCanvasArea (GlyphCanvas gc) { 744 int event_flags; 745 746 glyph_canvas = gc; 747 748 event_flags = EventMask.BUTTON_PRESS_MASK; 749 event_flags |= EventMask.BUTTON_RELEASE_MASK; 750 event_flags |= EventMask.POINTER_MOTION_MASK; 751 event_flags |= EventMask.LEAVE_NOTIFY_MASK; 752 event_flags |= EventMask.SCROLL_MASK; 753 754 add_events (event_flags); 755 756 bool button_down = false; 757 758 glyph_canvas.signal_redraw_area.connect ((x, y, w, h) => { 759 queue_draw_area ((int)x, (int)y, (int)w, (int)h); 760 }); 761 762 draw.connect ((t, e)=> { 763 Gtk.Allocation allocation; 764 get_allocation (out allocation); 765 766 alloc = new WidgetAllocation (); 767 768 alloc.width = allocation.width; 769 alloc.height = allocation.height; 770 alloc.x = allocation.x; 771 alloc.y = allocation.y; 772 773 Context cw = cairo_create (get_window()); 774 775 Surface s = new Surface.similar (cw.get_target (), Cairo.Content.COLOR_ALPHA, alloc.width, alloc.height); 776 Context c = new Context (s); 777 778 TabContent.draw (alloc, c); 779 780 cw.save (); 781 cw.set_source_surface (c.get_target (), 0, 0); 782 cw.paint (); 783 cw.restore (); 784 785 return true; 786 }); 787 788 button_press_event.connect ((t, e)=> { 789 GtkWindow.reset_modifier (e.state); 790 791 if (button_down) { 792 warning (@"Button already is down. $(e.button)"); 793 } 794 795 if (e.time < last_press) { 796 warning ("Discarding event."); 797 return true; 798 } 799 800 last_press = e.time; 801 802 if (e.type == EventType.BUTTON_PRESS) { 803 TabContent.button_press (e.button, e.x, e.y); 804 button_down = true; 805 } else if (e.type == EventType.2BUTTON_PRESS) { 806 TabContent.double_click (e.button, e.x, e.y); 807 } 808 809 return true; 810 }); 811 812 button_release_event.connect ((t, e)=> { 813 if (!button_down) { 814 warning (@"Button is not down $(e.button)"); 815 } 816 817 if (e.time < last_release) { 818 warning ("Discarding event."); 819 return true; 820 } 821 822 if (e.type == EventType.BUTTON_RELEASE) { 823 TabContent.button_release ((int) e.button, e.x, e.y); 824 last_release = e.time; 825 button_down = false; 826 } 827 828 return true; 829 }); 830 831 motion_notify_event.connect ((t, e)=> { 832 TabContent.motion_notify (e.x, e.y); 833 return true; 834 }); 835 836 scroll_event.connect ((t, e)=> { 837 if (e.direction == Gdk.ScrollDirection.UP) { 838 TabContent.scroll_wheel_up (e.x, e.y); 839 } else if (e.direction == Gdk.ScrollDirection.DOWN) { 840 TabContent.scroll_wheel_down (e.x, e.y) ; 841 } 842 843 TabContent.button_release (2, e.x, e.y); 844 return true; 845 }); 846 847 can_focus = true; 848 } 849 } 850 851 } 852