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.Deck;
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.SwipeableIF;
31 private import handy.SwipeableT;
32 private import handy.c.functions;
33 public  import handy.c.types;
34 
35 
36 /** */
37 public class Deck : Container, OrientableIF, SwipeableIF
38 {
39 	/** the main Gtk struct */
40 	protected HdyDeck* hdyDeck;
41 
42 	/** Get the main Gtk struct */
43 	public HdyDeck* getDeckStruct(bool transferOwnership = false)
44 	{
45 		if (transferOwnership)
46 			ownedRef = false;
47 		return hdyDeck;
48 	}
49 
50 	/** the main Gtk struct as a void* */
51 	protected override void* getStruct()
52 	{
53 		return cast(void*)hdyDeck;
54 	}
55 
56 	/**
57 	 * Sets our main struct and passes it to the parent class.
58 	 */
59 	public this (HdyDeck* hdyDeck, bool ownedRef = false)
60 	{
61 		this.hdyDeck = hdyDeck;
62 		super(cast(GtkContainer*)hdyDeck, ownedRef);
63 	}
64 
65 	// add the Orientable capabilities
66 	mixin OrientableT!(HdyDeck);
67 
68 	// add the Swipeable capabilities
69 	mixin SwipeableT!(HdyDeck);
70 
71 
72 	/** */
73 	public static GType getType()
74 	{
75 		return hdy_deck_get_type();
76 	}
77 
78 	/** */
79 	public this()
80 	{
81 		auto __p = hdy_deck_new();
82 
83 		if(__p is null)
84 		{
85 			throw new ConstructionException("null returned by new");
86 		}
87 
88 		this(cast(HdyDeck*) __p);
89 	}
90 
91 	/**
92 	 * Gets the previous or next child, or %NULL if it doesn't exist. This will be
93 	 * the same widget hdy_deck_navigate() will navigate to.
94 	 *
95 	 * Params:
96 	 *     direction = the direction
97 	 *
98 	 * Returns: the previous or next child, or
99 	 *     %NULL if it doesn't exist.
100 	 *
101 	 * Since: 1.0
102 	 */
103 	public Widget getAdjacentChild(HdyNavigationDirection direction)
104 	{
105 		auto __p = hdy_deck_get_adjacent_child(hdyDeck, direction);
106 
107 		if(__p is null)
108 		{
109 			return null;
110 		}
111 
112 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
113 	}
114 
115 	/**
116 	 * Returns whether the #HdyDeck allows swiping to the previous child.
117 	 *
118 	 * Returns: %TRUE if back swipe is enabled.
119 	 *
120 	 * Since: 1.0
121 	 */
122 	public bool getCanSwipeBack()
123 	{
124 		return hdy_deck_get_can_swipe_back(hdyDeck) != 0;
125 	}
126 
127 	/**
128 	 * Returns whether the #HdyDeck allows swiping to the next child.
129 	 *
130 	 * Returns: %TRUE if forward swipe is enabled.
131 	 *
132 	 * Since: 1.0
133 	 */
134 	public bool getCanSwipeForward()
135 	{
136 		return hdy_deck_get_can_swipe_forward(hdyDeck) != 0;
137 	}
138 
139 	/**
140 	 * Finds the child of @self with the name given as the argument. Returns %NULL
141 	 * if there is no child with this name.
142 	 *
143 	 * Params:
144 	 *     name = the name of the child to find
145 	 *
146 	 * Returns: the requested child of @self
147 	 *
148 	 * Since: 1.0
149 	 */
150 	public Widget getChildByName(string name)
151 	{
152 		auto __p = hdy_deck_get_child_by_name(hdyDeck, Str.toStringz(name));
153 
154 		if(__p is null)
155 		{
156 			return null;
157 		}
158 
159 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
160 	}
161 
162 	/**
163 	 * Gets whether @self is homogeneous for the given orientation.
164 	 * See hdy_deck_set_homogeneous().
165 	 *
166 	 * Params:
167 	 *     orientation = the orientation
168 	 *
169 	 * Returns: whether @self is homogeneous for the given orientation.
170 	 *
171 	 * Since: 1.0
172 	 */
173 	public bool getHomogeneous(GtkOrientation orientation)
174 	{
175 		return hdy_deck_get_homogeneous(hdyDeck, orientation) != 0;
176 	}
177 
178 	/**
179 	 * Returns whether the #HdyDeck is set up to interpolate between
180 	 * the sizes of children on page switch.
181 	 *
182 	 * Returns: %TRUE if child sizes are interpolated
183 	 *
184 	 * Since: 1.0
185 	 */
186 	public bool getInterpolateSize()
187 	{
188 		return hdy_deck_get_interpolate_size(hdyDeck) != 0;
189 	}
190 
191 	/**
192 	 * Returns the amount of time (in milliseconds) that
193 	 * transitions between children in @self will take.
194 	 *
195 	 * Returns: the child transition duration
196 	 *
197 	 * Since: 1.0
198 	 */
199 	public uint getTransitionDuration()
200 	{
201 		return hdy_deck_get_transition_duration(hdyDeck);
202 	}
203 
204 	/**
205 	 * Returns whether @self is currently in a transition from one page to
206 	 * another.
207 	 *
208 	 * Returns: %TRUE if the transition is currently running, %FALSE otherwise.
209 	 *
210 	 * Since: 1.0
211 	 */
212 	public bool getTransitionRunning()
213 	{
214 		return hdy_deck_get_transition_running(hdyDeck) != 0;
215 	}
216 
217 	/**
218 	 * Gets the type of animation that will be used
219 	 * for transitions between children in @self.
220 	 *
221 	 * Returns: the current transition type of @self
222 	 *
223 	 * Since: 1.0
224 	 */
225 	public HdyDeckTransitionType getTransitionType()
226 	{
227 		return hdy_deck_get_transition_type(hdyDeck);
228 	}
229 
230 	/**
231 	 * Gets the visible child widget.
232 	 *
233 	 * Returns: the visible child widget
234 	 *
235 	 * Since: 1.0
236 	 */
237 	public Widget getVisibleChild()
238 	{
239 		auto __p = hdy_deck_get_visible_child(hdyDeck);
240 
241 		if(__p is null)
242 		{
243 			return null;
244 		}
245 
246 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
247 	}
248 
249 	/**
250 	 * Gets the name of the currently visible child widget.
251 	 *
252 	 * Returns: the name of the visible child
253 	 *
254 	 * Since: 1.0
255 	 */
256 	public string getVisibleChildName()
257 	{
258 		return Str.toString(hdy_deck_get_visible_child_name(hdyDeck));
259 	}
260 
261 	/**
262 	 * Switches to the previous or next child, similar to performing a swipe
263 	 * gesture to go in @direction.
264 	 *
265 	 * Params:
266 	 *     direction = the direction
267 	 *
268 	 * Returns: %TRUE if visible child was changed, %FALSE otherwise.
269 	 *
270 	 * Since: 1.0
271 	 */
272 	public bool navigate(HdyNavigationDirection direction)
273 	{
274 		return hdy_deck_navigate(hdyDeck, direction) != 0;
275 	}
276 
277 	/**
278 	 * Sets whether or not @self allows switching to the previous child via a swipe
279 	 * gesture.
280 	 *
281 	 * Params:
282 	 *     canSwipeBack = the new value
283 	 *
284 	 * Since: 1.0
285 	 */
286 	public void setCanSwipeBack(bool canSwipeBack)
287 	{
288 		hdy_deck_set_can_swipe_back(hdyDeck, canSwipeBack);
289 	}
290 
291 	/**
292 	 * Sets whether or not @self allows switching to the next child via a swipe
293 	 * gesture.
294 	 *
295 	 * Params:
296 	 *     canSwipeForward = the new value
297 	 *
298 	 * Since: 1.0
299 	 */
300 	public void setCanSwipeForward(bool canSwipeForward)
301 	{
302 		hdy_deck_set_can_swipe_forward(hdyDeck, canSwipeForward);
303 	}
304 
305 	/**
306 	 * Sets the #HdyDeck to be homogeneous or not for the given orientation.
307 	 * If it is homogeneous, the #HdyDeck will request the same
308 	 * width or height for all its children depending on the orientation.
309 	 * If it isn't, the deck may change width or height when a different child
310 	 * becomes visible.
311 	 *
312 	 * Params:
313 	 *     orientation = the orientation
314 	 *     homogeneous = %TRUE to make @self homogeneous
315 	 *
316 	 * Since: 1.0
317 	 */
318 	public void setHomogeneous(GtkOrientation orientation, bool homogeneous)
319 	{
320 		hdy_deck_set_homogeneous(hdyDeck, orientation, homogeneous);
321 	}
322 
323 	/**
324 	 * Sets whether or not @self will interpolate its size when
325 	 * changing the visible child. If the #HdyDeck:interpolate-size
326 	 * property is set to %TRUE, @self will interpolate its size between
327 	 * the current one and the one it'll take after changing the
328 	 * visible child, according to the set transition duration.
329 	 *
330 	 * Params:
331 	 *     interpolateSize = the new value
332 	 *
333 	 * Since: 1.0
334 	 */
335 	public void setInterpolateSize(bool interpolateSize)
336 	{
337 		hdy_deck_set_interpolate_size(hdyDeck, interpolateSize);
338 	}
339 
340 	/**
341 	 * Sets the duration that transitions between children in @self
342 	 * will take.
343 	 *
344 	 * Params:
345 	 *     duration = the new duration, in milliseconds
346 	 *
347 	 * Since: 1.0
348 	 */
349 	public void setTransitionDuration(uint duration)
350 	{
351 		hdy_deck_set_transition_duration(hdyDeck, duration);
352 	}
353 
354 	/**
355 	 * Sets the type of animation that will be used for transitions between children
356 	 * in @self.
357 	 *
358 	 * The transition type can be changed without problems at runtime, so it is
359 	 * possible to change the animation based on the child that is about to become
360 	 * current.
361 	 *
362 	 * Params:
363 	 *     transition = the new transition type
364 	 *
365 	 * Since: 1.0
366 	 */
367 	public void setTransitionType(HdyDeckTransitionType transition)
368 	{
369 		hdy_deck_set_transition_type(hdyDeck, transition);
370 	}
371 
372 	/**
373 	 * Makes @visible_child visible using a transition determined by
374 	 * HdyDeck:transition-type and HdyDeck:transition-duration. The transition can
375 	 * be cancelled by the user, in which case visible child will change back to
376 	 * the previously visible child.
377 	 *
378 	 * Params:
379 	 *     visibleChild = the new child
380 	 *
381 	 * Since: 1.0
382 	 */
383 	public void setVisibleChild(Widget visibleChild)
384 	{
385 		hdy_deck_set_visible_child(hdyDeck, (visibleChild is null) ? null : visibleChild.getWidgetStruct());
386 	}
387 
388 	/**
389 	 * Makes the child with the name @name visible.
390 	 *
391 	 * See hdy_deck_set_visible_child() for more details.
392 	 *
393 	 * Params:
394 	 *     name = the name of a child
395 	 *
396 	 * Since: 1.0
397 	 */
398 	public void setVisibleChildName(string name)
399 	{
400 		hdy_deck_set_visible_child_name(hdyDeck, Str.toStringz(name));
401 	}
402 }