1 /* 2 * This file is part of d-handy. 3 * 4 * d-handy 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-handy 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-handy; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module handy.Leaflet; 20 21 private import glib.ConstructionException; 22 private import glib.Str; 23 private import gobject.ObjectG; 24 private import gtk.BuildableIF; 25 private import gtk.BuildableT; 26 private import gtk.Container; 27 private import gtk.OrientableIF; 28 private import gtk.OrientableT; 29 private import gtk.Widget; 30 private import handy.c.functions; 31 public import handy.c.types; 32 33 34 /** */ 35 public class Leaflet : Container, OrientableIF 36 { 37 /** the main Gtk struct */ 38 protected HdyLeaflet* hdyLeaflet; 39 40 /** Get the main Gtk struct */ 41 public HdyLeaflet* getLeafletStruct(bool transferOwnership = false) 42 { 43 if (transferOwnership) 44 ownedRef = false; 45 return hdyLeaflet; 46 } 47 48 /** the main Gtk struct as a void* */ 49 protected override void* getStruct() 50 { 51 return cast(void*)hdyLeaflet; 52 } 53 54 /** 55 * Sets our main struct and passes it to the parent class. 56 */ 57 public this (HdyLeaflet* hdyLeaflet, bool ownedRef = false) 58 { 59 this.hdyLeaflet = hdyLeaflet; 60 super(cast(GtkContainer*)hdyLeaflet, ownedRef); 61 } 62 63 // add the Orientable capabilities 64 mixin OrientableT!(HdyLeaflet); 65 66 67 /** */ 68 public static GType getType() 69 { 70 return hdy_leaflet_get_type(); 71 } 72 73 /** */ 74 public this() 75 { 76 auto p = hdy_leaflet_new(); 77 78 if(p is null) 79 { 80 throw new ConstructionException("null returned by new"); 81 } 82 83 this(cast(HdyLeaflet*) p); 84 } 85 86 /** 87 * Returns the amount of time (in milliseconds) that 88 * transitions between children in @self will take. 89 * 90 * Returns: the mode transition duration 91 */ 92 public uint getChildTransitionDuration() 93 { 94 return hdy_leaflet_get_child_transition_duration(hdyLeaflet); 95 } 96 97 /** 98 * Returns whether @self is currently in a transition from one page to 99 * another. 100 * 101 * Returns: %TRUE if the transition is currently running, %FALSE otherwise. 102 */ 103 public bool getChildTransitionRunning() 104 { 105 return hdy_leaflet_get_child_transition_running(hdyLeaflet) != 0; 106 } 107 108 /** 109 * Gets the type of animation that will be used 110 * for transitions between modes in @self. 111 * 112 * Returns: the current mode transition type of @self 113 */ 114 public HdyLeafletChildTransitionType getChildTransitionType() 115 { 116 return hdy_leaflet_get_child_transition_type(hdyLeaflet); 117 } 118 119 /** 120 * Gets the fold of @self. 121 * 122 * Returns: the fold of @self. 123 */ 124 public HdyFold getFold() 125 { 126 return hdy_leaflet_get_fold(hdyLeaflet); 127 } 128 129 /** 130 * Gets whether @self is homogeneous for the given fold and orientation. 131 * See hdy_leaflet_set_homogeneous(). 132 * 133 * Params: 134 * fold = the fold 135 * orientation = the orientation 136 * 137 * Returns: whether @self is homogeneous for the given fold and orientation. 138 */ 139 public bool getHomogeneous(HdyFold fold, GtkOrientation orientation) 140 { 141 return hdy_leaflet_get_homogeneous(hdyLeaflet, fold, orientation) != 0; 142 } 143 144 /** 145 * Returns wether the #HdyLeaflet is set up to interpolate between 146 * the sizes of children on page switch. 147 * 148 * Returns: %TRUE if child sizes are interpolated 149 */ 150 public bool getInterpolateSize() 151 { 152 return hdy_leaflet_get_interpolate_size(hdyLeaflet) != 0; 153 } 154 155 /** 156 * Returns the amount of time (in milliseconds) that 157 * transitions between modes in @self will take. 158 * 159 * Returns: the mode transition duration 160 */ 161 public uint getModeTransitionDuration() 162 { 163 return hdy_leaflet_get_mode_transition_duration(hdyLeaflet); 164 } 165 166 /** 167 * Gets the type of animation that will be used 168 * for transitions between modes in @self. 169 * 170 * Returns: the current mode transition type of @self 171 */ 172 public HdyLeafletModeTransitionType getModeTransitionType() 173 { 174 return hdy_leaflet_get_mode_transition_type(hdyLeaflet); 175 } 176 177 /** 178 * Get the visible child widget. 179 * 180 * Returns: the visible child widget 181 */ 182 public Widget getVisibleChild() 183 { 184 auto p = hdy_leaflet_get_visible_child(hdyLeaflet); 185 186 if(p is null) 187 { 188 return null; 189 } 190 191 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 192 } 193 194 /** */ 195 public string getVisibleChildName() 196 { 197 return Str.toString(hdy_leaflet_get_visible_child_name(hdyLeaflet)); 198 } 199 200 /** 201 * Sets the duration that transitions between children in @self 202 * will take. 203 * 204 * Params: 205 * duration = the new duration, in milliseconds 206 */ 207 public void setChildTransitionDuration(uint duration) 208 { 209 hdy_leaflet_set_child_transition_duration(hdyLeaflet, duration); 210 } 211 212 /** 213 * Sets the type of animation that will be used for 214 * transitions between children in @self. 215 * 216 * The transition type can be changed without problems 217 * at runtime, so it is possible to change the animation 218 * based on the mode that is about to become current. 219 * 220 * Params: 221 * transition = the new transition type 222 */ 223 public void setChildTransitionType(HdyLeafletChildTransitionType transition) 224 { 225 hdy_leaflet_set_child_transition_type(hdyLeaflet, transition); 226 } 227 228 /** 229 * Sets the #HdyLeaflet to be homogeneous or not for the given fold and orientation. 230 * If it is homogeneous, the #HdyLeaflet will request the same 231 * width or height for all its children depending on the orientation. 232 * If it isn't and it is folded, the leaflet may change width or height 233 * when a different child becomes visible. 234 * 235 * Params: 236 * fold = the fold 237 * orientation = the orientation 238 * homogeneous = %TRUE to make @self homogeneous 239 */ 240 public void setHomogeneous(HdyFold fold, GtkOrientation orientation, bool homogeneous) 241 { 242 hdy_leaflet_set_homogeneous(hdyLeaflet, fold, orientation, homogeneous); 243 } 244 245 /** 246 * Sets whether or not @self will interpolate its size when 247 * changing the visible child. If the #HdyLeaflet:interpolate-size 248 * property is set to %TRUE, @stack will interpolate its size between 249 * the current one and the one it'll take after changing the 250 * visible child, according to the set transition duration. 251 * 252 * Params: 253 * interpolateSize = the new value 254 */ 255 public void setInterpolateSize(bool interpolateSize) 256 { 257 hdy_leaflet_set_interpolate_size(hdyLeaflet, interpolateSize); 258 } 259 260 /** 261 * Sets the duration that transitions between modes in @self 262 * will take. 263 * 264 * Params: 265 * duration = the new duration, in milliseconds 266 */ 267 public void setModeTransitionDuration(uint duration) 268 { 269 hdy_leaflet_set_mode_transition_duration(hdyLeaflet, duration); 270 } 271 272 /** 273 * Sets the type of animation that will be used for 274 * transitions between modes in @self. 275 * 276 * The transition type can be changed without problems 277 * at runtime, so it is possible to change the animation 278 * based on the mode that is about to become current. 279 * 280 * Params: 281 * transition = the new transition type 282 */ 283 public void setModeTransitionType(HdyLeafletModeTransitionType transition) 284 { 285 hdy_leaflet_set_mode_transition_type(hdyLeaflet, transition); 286 } 287 288 /** */ 289 public void setVisibleChild(Widget visibleChild) 290 { 291 hdy_leaflet_set_visible_child(hdyLeaflet, (visibleChild is null) ? null : visibleChild.getWidgetStruct()); 292 } 293 294 /** */ 295 public void setVisibleChildName(string name) 296 { 297 hdy_leaflet_set_visible_child_name(hdyLeaflet, Str.toStringz(name)); 298 } 299 }