1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * d-dazzle is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.ApplicationWindow; 20 21 private import dazzle.c.functions; 22 public import dazzle.c.types; 23 private import gobject.ObjectG; 24 private import gtk.ApplicationWindow : GtkAppWindow = ApplicationWindow; 25 private import gtk.BuildableIF; 26 private import gtk.BuildableT; 27 private import gtk.Widget; 28 private import dazzle.Application; 29 private import glib.ConstructionException; 30 31 32 /** */ 33 public class ApplicationWindow : GtkAppWindow 34 { 35 /** the main Gtk struct */ 36 protected DzlApplicationWindow* dzlApplicationWindow; 37 38 /** Get the main Gtk struct */ 39 public DzlApplicationWindow* getDazzleApplicationWindowStruct(bool transferOwnership = false) 40 { 41 if (transferOwnership) 42 ownedRef = false; 43 return dzlApplicationWindow; 44 } 45 46 /** the main Gtk struct as a void* */ 47 protected override void* getStruct() 48 { 49 return cast(void*)dzlApplicationWindow; 50 } 51 52 /** 53 * Sets our main struct and passes it to the parent class. 54 */ 55 public this (DzlApplicationWindow* dzlApplicationWindow, bool ownedRef = false) 56 { 57 this.dzlApplicationWindow = dzlApplicationWindow; 58 super(cast(GtkApplicationWindow*)dzlApplicationWindow, ownedRef); 59 } 60 61 /** 62 * Allows subclasses to create new instances of Dazzle applications 63 * This is a frontend to g_object_new 64 */ 65 protected this (Application app) 66 { 67 import gobject.c.functions : g_object_new; 68 auto p = g_object_new(getType(), 69 Str.toStringz("application"), app.getDazzleApplicationStruct(), null); 70 71 if(p is null) 72 { 73 throw new ConstructionException("null returned by new"); 74 } 75 76 this(cast(DzlApplicationWindow*) p); 77 } 78 79 /** */ 80 public static GType getType() 81 { 82 return dzl_application_window_get_type(); 83 } 84 85 /** 86 * Gets if the window is in the fullscreen state. 87 * 88 * Returns: %TRUE if @self is fullscreen, otherwise %FALSE. 89 * 90 * Since: 3.26 91 */ 92 public bool getFullscreen() 93 { 94 return dzl_application_window_get_fullscreen(dzlApplicationWindow) != 0; 95 } 96 97 /** 98 * Gets the titlebar for the window, if there is one. 99 * 100 * Returns: A #GtkWidget or %NULL 101 * 102 * Since: 3.26 103 */ 104 public override Widget getTitlebar() 105 { 106 auto p = dzl_application_window_get_titlebar(dzlApplicationWindow); 107 108 if(p is null) 109 { 110 return null; 111 } 112 113 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 114 } 115 116 /** 117 * Sets the #DzlApplicationWindow into either the fullscreen or unfullscreen 118 * state based on @fullscreen. 119 * 120 * The titlebar for the window is contained within a #GtkRevealer which is 121 * repurposed as a floating bar when the application is in fullscreen mode. 122 * 123 * See dzl_application_window_get_fullscreen() to get the current fullscreen 124 * state. 125 * 126 * Params: 127 * fullscreen = if the window should be in the fullscreen state 128 * 129 * Since: 3.26 130 */ 131 public void setFullscreen(bool fullscreen) 132 { 133 dzl_application_window_set_fullscreen(dzlApplicationWindow, fullscreen); 134 } 135 136 /** 137 * Sets the titlebar for the window. 138 * 139 * Generally, you want to do this from your GTK ui template by setting 140 * the <child type="titlebar"> 141 * 142 * Since: 3.26 143 */ 144 public override void setTitlebar(Widget titlebar) 145 { 146 dzl_application_window_set_titlebar(dzlApplicationWindow, (titlebar is null) ? null : titlebar.getWidgetStruct()); 147 } 148 }