1 module declgtk.components.window; 2 3 import declgtk.components.component; 4 import declgtk.components.menu : GtkMenuBar; 5 import declgtk.util; 6 import declui.components.component; 7 import declui.components.window : IWindow; 8 import gtk.Application : Application; 9 import gtk.Window; 10 import gtk.ApplicationWindow : ApplicationWindow; 11 import gtk.VBox; 12 import gio.Application : GioApplication = Application; 13 14 /** 15 A GTK window. 16 */ 17 class GtkWindow : GtkWidgetComponent!VBox, IWindow, IApplicationProxy 18 { 19 private IApplicationProxy _application; 20 private Window _window; 21 private string _title = "Untitled Window"; 22 23 private Window createWindow() 24 { 25 if (_application is null) 26 return new Window(_title); 27 else 28 return new ApplicationWindow(_application.application()); 29 } 30 31 override VBox createInstance() 32 { 33 _window = createWindow(); 34 auto vbox = new VBox(true, 3); 35 _window.add(vbox); 36 return vbox; 37 } 38 39 void setApplication(IApplicationProxy application) 40 { 41 _application = application; 42 } 43 44 override string title() 45 { 46 return _title; 47 } 48 49 override void title(string title) 50 { 51 _title = title; 52 queue(widget => _window.setTitle(title)); 53 } 54 55 override void add(IComponent child) 56 { 57 auto component = child.getInternal(); 58 if (cast(GtkMenuBar) component !is null) 59 (cast(GtkMenuBar) component).application = this; 60 61 queue((widget) 62 { 63 auto widgetComponent = cast(IGtkWidgetComponent) component; 64 if (widgetComponent !is null) 65 widget.add(widgetComponent.getWidget()); 66 else if (cast(GtkMenuBar) component !is null) 67 { 68 auto menubar = cast(GtkMenuBar) component; 69 _application.application().setMenubar(menubar.getWidget()); 70 } 71 }); 72 } 73 74 override void visible(bool visible) 75 { 76 super.visible = visible; 77 queue((widget) 78 { 79 if (visible) 80 _window.show(); 81 else 82 _window.hide(); 83 }); 84 } 85 86 override Application application() 87 { 88 return _application.application(); 89 } 90 91 override GioApplication gioApplication() 92 { 93 return _application.gioApplication(); 94 } 95 }