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.HeaderBar;
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.Widget;
28 private import handy.c.functions;
29 public  import handy.c.types;
30 
31 
32 /** */
33 public class HeaderBar : Container
34 {
35 	/** the main Gtk struct */
36 	protected HdyHeaderBar* hdyHeaderBar;
37 
38 	/** Get the main Gtk struct */
39 	public HdyHeaderBar* getHeaderBarStruct(bool transferOwnership = false)
40 	{
41 		if (transferOwnership)
42 			ownedRef = false;
43 		return hdyHeaderBar;
44 	}
45 
46 	/** the main Gtk struct as a void* */
47 	protected override void* getStruct()
48 	{
49 		return cast(void*)hdyHeaderBar;
50 	}
51 
52 	/**
53 	 * Sets our main struct and passes it to the parent class.
54 	 */
55 	public this (HdyHeaderBar* hdyHeaderBar, bool ownedRef = false)
56 	{
57 		this.hdyHeaderBar = hdyHeaderBar;
58 		super(cast(GtkContainer*)hdyHeaderBar, ownedRef);
59 	}
60 
61 
62 	/** */
63 	public static GType getType()
64 	{
65 		return hdy_header_bar_get_type();
66 	}
67 
68 	/**
69 	 * Creates a new #HdyHeaderBar widget.
70 	 *
71 	 * Returns: a new #HdyHeaderBar
72 	 *
73 	 * Since: 0.0.10
74 	 *
75 	 * Throws: ConstructionException GTK+ fails to create the object.
76 	 */
77 	public this()
78 	{
79 		auto p = hdy_header_bar_new();
80 
81 		if(p is null)
82 		{
83 			throw new ConstructionException("null returned by new");
84 		}
85 
86 		this(cast(HdyHeaderBar*) p);
87 	}
88 
89 	/**
90 	 * Gets the policy @self follows to horizontally align its center widget.
91 	 *
92 	 * Returns: the centering policy
93 	 *
94 	 * Since: 0.0.10
95 	 */
96 	public HdyCenteringPolicy getCenteringPolicy()
97 	{
98 		return hdy_header_bar_get_centering_policy(hdyHeaderBar);
99 	}
100 
101 	/**
102 	 * Retrieves the custom title widget of the header. See
103 	 * hdy_header_bar_set_custom_title().
104 	 *
105 	 * Returns: the custom title widget
106 	 *     of the header, or %NULL if none has been set explicitly.
107 	 *
108 	 * Since: 0.0.10
109 	 */
110 	public Widget getCustomTitle()
111 	{
112 		auto p = hdy_header_bar_get_custom_title(hdyHeaderBar);
113 
114 		if(p is null)
115 		{
116 			return null;
117 		}
118 
119 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
120 	}
121 
122 	/**
123 	 * Gets the decoration layout set with
124 	 * hdy_header_bar_set_decoration_layout().
125 	 *
126 	 * Returns: the decoration layout
127 	 *
128 	 * Since: 0.0.10
129 	 */
130 	public string getDecorationLayout()
131 	{
132 		return Str.toString(hdy_header_bar_get_decoration_layout(hdyHeaderBar));
133 	}
134 
135 	/**
136 	 * Retrieves whether the header bar reserves space for
137 	 * a subtitle, regardless if one is currently set or not.
138 	 *
139 	 * Returns: %TRUE if the header bar reserves space
140 	 *     for a subtitle
141 	 *
142 	 * Since: 0.0.10
143 	 */
144 	public bool getHasSubtitle()
145 	{
146 		return hdy_header_bar_get_has_subtitle(hdyHeaderBar) != 0;
147 	}
148 
149 	/**
150 	 * Gets wether @self should interpolate its size on visible child change.
151 	 *
152 	 * See hdy_header_bar_set_interpolate_size().
153 	 *
154 	 * Returns: %TRUE if @self interpolates its size on visible child change, %FALSE if not
155 	 *
156 	 * Since: 0.0.10
157 	 */
158 	public bool getInterpolateSize()
159 	{
160 		return hdy_header_bar_get_interpolate_size(hdyHeaderBar) != 0;
161 	}
162 
163 	/**
164 	 * Returns whether this header bar shows the standard window
165 	 * decorations.
166 	 *
167 	 * Returns: %TRUE if the decorations are shown
168 	 *
169 	 * Since: 0.0.10
170 	 */
171 	public bool getShowCloseButton()
172 	{
173 		return hdy_header_bar_get_show_close_button(hdyHeaderBar) != 0;
174 	}
175 
176 	/**
177 	 * Retrieves the subtitle of the header. See hdy_header_bar_set_subtitle().
178 	 *
179 	 * Returns: the subtitle of the header, or %NULL if none has
180 	 *     been set explicitly. The returned string is owned by the widget
181 	 *     and must not be modified or freed.
182 	 *
183 	 * Since: 0.0.10
184 	 */
185 	public string getSubtitle()
186 	{
187 		return Str.toString(hdy_header_bar_get_subtitle(hdyHeaderBar));
188 	}
189 
190 	/**
191 	 * Retrieves the title of the header. See hdy_header_bar_set_title().
192 	 *
193 	 * Returns: the title of the header, or %NULL if none has
194 	 *     been set explicitly. The returned string is owned by the widget
195 	 *     and must not be modified or freed.
196 	 *
197 	 * Since: 0.0.10
198 	 */
199 	public string getTitle()
200 	{
201 		return Str.toString(hdy_header_bar_get_title(hdyHeaderBar));
202 	}
203 
204 	/**
205 	 * Returns the amount of time (in milliseconds) that
206 	 * transitions between pages in @self will take.
207 	 *
208 	 * Returns: the transition duration
209 	 *
210 	 * Since: 0.0.10
211 	 */
212 	public uint getTransitionDuration()
213 	{
214 		return hdy_header_bar_get_transition_duration(hdyHeaderBar);
215 	}
216 
217 	/**
218 	 * Returns whether the @self is currently in a transition from one page to
219 	 * another.
220 	 *
221 	 * Returns: %TRUE if the transition is currently running, %FALSE otherwise.
222 	 *
223 	 * Since: 0.0.10
224 	 */
225 	public bool getTransitionRunning()
226 	{
227 		return hdy_header_bar_get_transition_running(hdyHeaderBar) != 0;
228 	}
229 
230 	/**
231 	 * Adds @child to @self:, packed with reference to the
232 	 * end of the @self:.
233 	 *
234 	 * Params:
235 	 *     child = the #GtkWidget to be added to @self:
236 	 *
237 	 * Since: 0.0.10
238 	 */
239 	public void packEnd(Widget child)
240 	{
241 		hdy_header_bar_pack_end(hdyHeaderBar, (child is null) ? null : child.getWidgetStruct());
242 	}
243 
244 	/**
245 	 * Adds @child to @self:, packed with reference to the
246 	 * start of the @self:.
247 	 *
248 	 * Params:
249 	 *     child = the #GtkWidget to be added to @self:
250 	 *
251 	 * Since: 0.0.10
252 	 */
253 	public void packStart(Widget child)
254 	{
255 		hdy_header_bar_pack_start(hdyHeaderBar, (child is null) ? null : child.getWidgetStruct());
256 	}
257 
258 	/**
259 	 * Sets the policy @self must follow to horizontally align its center widget.
260 	 *
261 	 * Params:
262 	 *     centeringPolicy = the centering policy
263 	 *
264 	 * Since: 0.0.10
265 	 */
266 	public void setCenteringPolicy(HdyCenteringPolicy centeringPolicy)
267 	{
268 		hdy_header_bar_set_centering_policy(hdyHeaderBar, centeringPolicy);
269 	}
270 
271 	/**
272 	 * Sets a custom title for the #HdyHeaderBar.
273 	 *
274 	 * The title should help a user identify the current view. This
275 	 * supersedes any title set by hdy_header_bar_set_title() or
276 	 * hdy_header_bar_set_subtitle(). To achieve the same style as
277 	 * the builtin title and subtitle, use the “title” and “subtitle”
278 	 * style classes.
279 	 *
280 	 * You should set the custom title to %NULL, for the header title
281 	 * label to be visible again.
282 	 *
283 	 * Params:
284 	 *     titleWidget = a custom widget to use for a title
285 	 *
286 	 * Since: 0.0.10
287 	 */
288 	public void setCustomTitle(Widget titleWidget)
289 	{
290 		hdy_header_bar_set_custom_title(hdyHeaderBar, (titleWidget is null) ? null : titleWidget.getWidgetStruct());
291 	}
292 
293 	/**
294 	 * Sets the decoration layout for this header bar, overriding
295 	 * the #GtkSettings:gtk-decoration-layout setting.
296 	 *
297 	 * There can be valid reasons for overriding the setting, such
298 	 * as a header bar design that does not allow for buttons to take
299 	 * room on the right, or only offers room for a single close button.
300 	 * Split header bars are another example for overriding the
301 	 * setting.
302 	 *
303 	 * The format of the string is button names, separated by commas.
304 	 * A colon separates the buttons that should appear on the left
305 	 * from those on the right. Recognized button names are minimize,
306 	 * maximize, close, icon (the window icon) and menu (a menu button
307 	 * for the fallback app menu).
308 	 *
309 	 * For example, “menu:minimize,maximize,close” specifies a menu
310 	 * on the left, and minimize, maximize and close buttons on the right.
311 	 *
312 	 * Params:
313 	 *     layout = a decoration layout, or %NULL to
314 	 *         unset the layout
315 	 *
316 	 * Since: 0.0.10
317 	 */
318 	public void setDecorationLayout(string layout)
319 	{
320 		hdy_header_bar_set_decoration_layout(hdyHeaderBar, Str.toStringz(layout));
321 	}
322 
323 	/**
324 	 * Sets whether the header bar should reserve space
325 	 * for a subtitle, even if none is currently set.
326 	 *
327 	 * Params:
328 	 *     setting = %TRUE to reserve space for a subtitle
329 	 *
330 	 * Since: 0.0.10
331 	 */
332 	public void setHasSubtitle(bool setting)
333 	{
334 		hdy_header_bar_set_has_subtitle(hdyHeaderBar, setting);
335 	}
336 
337 	/**
338 	 * Sets whether or not @self will interpolate the size of its opposing
339 	 * orientation when changing the visible child. If %TRUE, @self will interpolate
340 	 * its size between the one of the previous visible child and the one of the new
341 	 * visible child, according to the set transition duration and the orientation,
342 	 * e.g. if @self is horizontal, it will interpolate the its height.
343 	 *
344 	 * Params:
345 	 *     interpolateSize = %TRUE to interpolate the size
346 	 *
347 	 * Since: 0.0.10
348 	 */
349 	public void setInterpolateSize(bool interpolateSize)
350 	{
351 		hdy_header_bar_set_interpolate_size(hdyHeaderBar, interpolateSize);
352 	}
353 
354 	/**
355 	 * Sets whether this header bar shows the standard window decorations,
356 	 * including close, maximize, and minimize.
357 	 *
358 	 * Params:
359 	 *     setting = %TRUE to show standard window decorations
360 	 *
361 	 * Since: 0.0.10
362 	 */
363 	public void setShowCloseButton(bool setting)
364 	{
365 		hdy_header_bar_set_show_close_button(hdyHeaderBar, setting);
366 	}
367 
368 	/**
369 	 * Sets the subtitle of the #HdyHeaderBar. The title should give a user
370 	 * an additional detail to help him identify the current view.
371 	 *
372 	 * Note that HdyHeaderBar by default reserves room for the subtitle,
373 	 * even if none is currently set. If this is not desired, set the
374 	 * #HdyHeaderBar:has-subtitle property to %FALSE.
375 	 *
376 	 * Params:
377 	 *     subtitle = a subtitle, or %NULL
378 	 *
379 	 * Since: 0.0.10
380 	 */
381 	public void setSubtitle(string subtitle)
382 	{
383 		hdy_header_bar_set_subtitle(hdyHeaderBar, Str.toStringz(subtitle));
384 	}
385 
386 	/**
387 	 * Sets the title of the #HdyHeaderBar. The title should help a user
388 	 * identify the current view. A good title should not include the
389 	 * application name.
390 	 *
391 	 * Params:
392 	 *     title = a title, or %NULL
393 	 *
394 	 * Since: 0.0.10
395 	 */
396 	public void setTitle(string title)
397 	{
398 		hdy_header_bar_set_title(hdyHeaderBar, Str.toStringz(title));
399 	}
400 
401 	/**
402 	 * Sets the duration that transitions between pages in @self
403 	 * will take.
404 	 *
405 	 * Params:
406 	 *     duration = the new duration, in milliseconds
407 	 *
408 	 * Since: 0.0.10
409 	 */
410 	public void setTransitionDuration(uint duration)
411 	{
412 		hdy_header_bar_set_transition_duration(hdyHeaderBar, duration);
413 	}
414 }