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.Squeezer;
20 
21 private import glib.ConstructionException;
22 private import gobject.ObjectG;
23 private import gtk.BuildableIF;
24 private import gtk.BuildableT;
25 private import gtk.Container;
26 private import gtk.OrientableIF;
27 private import gtk.OrientableT;
28 private import gtk.Widget;
29 private import handy.c.functions;
30 public  import handy.c.types;
31 
32 
33 /** */
34 public class Squeezer : Container, OrientableIF
35 {
36 	/** the main Gtk struct */
37 	protected HdySqueezer* hdySqueezer;
38 
39 	/** Get the main Gtk struct */
40 	public HdySqueezer* getSqueezerStruct(bool transferOwnership = false)
41 	{
42 		if (transferOwnership)
43 			ownedRef = false;
44 		return hdySqueezer;
45 	}
46 
47 	/** the main Gtk struct as a void* */
48 	protected override void* getStruct()
49 	{
50 		return cast(void*)hdySqueezer;
51 	}
52 
53 	/**
54 	 * Sets our main struct and passes it to the parent class.
55 	 */
56 	public this (HdySqueezer* hdySqueezer, bool ownedRef = false)
57 	{
58 		this.hdySqueezer = hdySqueezer;
59 		super(cast(GtkContainer*)hdySqueezer, ownedRef);
60 	}
61 
62 	// add the Orientable capabilities
63 	mixin OrientableT!(HdySqueezer);
64 
65 
66 	/** */
67 	public static GType getType()
68 	{
69 		return hdy_squeezer_get_type();
70 	}
71 
72 	/**
73 	 * Creates a new #HdySqueezer container.
74 	 *
75 	 * Returns: a new #HdySqueezer
76 	 *
77 	 * Throws: ConstructionException GTK+ fails to create the object.
78 	 */
79 	public this()
80 	{
81 		auto p = hdy_squeezer_new();
82 
83 		if(p is null)
84 		{
85 			throw new ConstructionException("null returned by new");
86 		}
87 
88 		this(cast(HdySqueezer*) p);
89 	}
90 
91 	/**
92 	 * Gets whether @child is enabled.
93 	 *
94 	 * See hdy_squeezer_set_child_enabled().
95 	 *
96 	 * Params:
97 	 *     child = a child of @self
98 	 *
99 	 * Returns: %TRUE if @child is enabled, %FALSE otherwise.
100 	 */
101 	public bool getChildEnabled(Widget child)
102 	{
103 		return hdy_squeezer_get_child_enabled(hdySqueezer, (child is null) ? null : child.getWidgetStruct()) != 0;
104 	}
105 
106 	/**
107 	 * Gets whether @self is homogeneous.
108 	 *
109 	 * See hdy_squeezer_set_homogeneous().
110 	 *
111 	 * Returns: %TRUE if @self is homogeneous, %FALSE is not
112 	 *
113 	 * Since: 0.0.10
114 	 */
115 	public bool getHomogeneous()
116 	{
117 		return hdy_squeezer_get_homogeneous(hdySqueezer) != 0;
118 	}
119 
120 	/**
121 	 * Gets wether @self should interpolate its size on visible child change.
122 	 *
123 	 * See hdy_squeezer_set_interpolate_size().
124 	 *
125 	 * Returns: %TRUE if @self interpolates its size on visible child change, %FALSE if not
126 	 *
127 	 * Since: 0.0.10
128 	 */
129 	public bool getInterpolateSize()
130 	{
131 		return hdy_squeezer_get_interpolate_size(hdySqueezer) != 0;
132 	}
133 
134 	/**
135 	 * Gets the amount of time (in milliseconds) that transitions between children
136 	 * in @self will take.
137 	 *
138 	 * Returns: the transition duration
139 	 */
140 	public uint getTransitionDuration()
141 	{
142 		return hdy_squeezer_get_transition_duration(hdySqueezer);
143 	}
144 
145 	/**
146 	 * Gets whether @self is currently in a transition from one child to another.
147 	 *
148 	 * Returns: %TRUE if the transition is currently running, %FALSE otherwise.
149 	 */
150 	public bool getTransitionRunning()
151 	{
152 		return hdy_squeezer_get_transition_running(hdySqueezer) != 0;
153 	}
154 
155 	/**
156 	 * Gets the type of animation that will be used for transitions between children
157 	 * in @self.
158 	 *
159 	 * Returns: the current transition type of @self
160 	 */
161 	public HdySqueezerTransitionType getTransitionType()
162 	{
163 		return hdy_squeezer_get_transition_type(hdySqueezer);
164 	}
165 
166 	/**
167 	 * Gets the currently visible child of @self, or %NULL if there are no visible
168 	 * children.
169 	 *
170 	 * Returns: the visible child of the #HdySqueezer
171 	 */
172 	public Widget getVisibleChild()
173 	{
174 		auto p = hdy_squeezer_get_visible_child(hdySqueezer);
175 
176 		if(p is null)
177 		{
178 			return null;
179 		}
180 
181 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
182 	}
183 
184 	/**
185 	 * Make @self enable or disable @child. If a child is disabled, it will be
186 	 * ignored when looking for the child fitting the available size best. This
187 	 * allows to programmatically and prematurely hide a child of @self even if it
188 	 * fits in the available space.
189 	 *
190 	 * This can be used e.g. to ensure a certain child is hidden below a certain
191 	 * window width, or any other constraint you find suitable.
192 	 *
193 	 * Params:
194 	 *     child = a child of @self
195 	 *     enabled = %TRUE to enable the child, %FALSE to disable it
196 	 */
197 	public void setChildEnabled(Widget child, bool enabled)
198 	{
199 		hdy_squeezer_set_child_enabled(hdySqueezer, (child is null) ? null : child.getWidgetStruct(), enabled);
200 	}
201 
202 	/**
203 	 * Sets @self to be homogeneous or not. If it is homogeneous, @self will request
204 	 * the same size for all its children for its opposite orientation, e.g. if
205 	 * @self is oriented horizontally and is homogeneous, it will request the same
206 	 * height for all its children. If it isn't, @self may change size when a
207 	 * different child becomes visible.
208 	 *
209 	 * Params:
210 	 *     homogeneous = %TRUE to make @self homogeneous
211 	 *
212 	 * Since: 0.0.10
213 	 */
214 	public void setHomogeneous(bool homogeneous)
215 	{
216 		hdy_squeezer_set_homogeneous(hdySqueezer, homogeneous);
217 	}
218 
219 	/**
220 	 * Sets whether or not @self will interpolate the size of its opposing
221 	 * orientation when changing the visible child. If %TRUE, @self will interpolate
222 	 * its size between the one of the previous visible child and the one of the new
223 	 * visible child, according to the set transition duration and the orientation,
224 	 * e.g. if @self is horizontal, it will interpolate the its height.
225 	 *
226 	 * Params:
227 	 *     interpolateSize = %TRUE to interpolate the size
228 	 *
229 	 * Since: 0.0.10
230 	 */
231 	public void setInterpolateSize(bool interpolateSize)
232 	{
233 		hdy_squeezer_set_interpolate_size(hdySqueezer, interpolateSize);
234 	}
235 
236 	/**
237 	 * Sets the duration that transitions between children in @self will take.
238 	 *
239 	 * Params:
240 	 *     duration = the new duration, in milliseconds
241 	 */
242 	public void setTransitionDuration(uint duration)
243 	{
244 		hdy_squeezer_set_transition_duration(hdySqueezer, duration);
245 	}
246 
247 	/**
248 	 * Sets the type of animation that will be used for transitions between children
249 	 * in @self. Available types include various kinds of fades and slides.
250 	 *
251 	 * The transition type can be changed without problems at runtime, so it is
252 	 * possible to change the animation based on the child that is about to become
253 	 * current.
254 	 *
255 	 * Params:
256 	 *     transition = the new transition type
257 	 */
258 	public void setTransitionType(HdySqueezerTransitionType transition)
259 	{
260 		hdy_squeezer_set_transition_type(hdySqueezer, transition);
261 	}
262 }