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.HeaderGroup;
20 
21 private import glib.ConstructionException;
22 private import glib.ListSG;
23 private import gobject.ObjectG;
24 private import gtk.BuildableIF;
25 private import gtk.BuildableT;
26 private import gtk.HeaderBar;
27 private import handy.c.functions;
28 public  import handy.c.types;
29 
30 
31 /** */
32 public class HeaderGroup : ObjectG, BuildableIF
33 {
34 	/** the main Gtk struct */
35 	protected HdyHeaderGroup* hdyHeaderGroup;
36 
37 	/** Get the main Gtk struct */
38 	public HdyHeaderGroup* getHeaderGroupStruct(bool transferOwnership = false)
39 	{
40 		if (transferOwnership)
41 			ownedRef = false;
42 		return hdyHeaderGroup;
43 	}
44 
45 	/** the main Gtk struct as a void* */
46 	protected override void* getStruct()
47 	{
48 		return cast(void*)hdyHeaderGroup;
49 	}
50 
51 	/**
52 	 * Sets our main struct and passes it to the parent class.
53 	 */
54 	public this (HdyHeaderGroup* hdyHeaderGroup, bool ownedRef = false)
55 	{
56 		this.hdyHeaderGroup = hdyHeaderGroup;
57 		super(cast(GObject*)hdyHeaderGroup, ownedRef);
58 	}
59 
60 	// add the Buildable capabilities
61 	mixin BuildableT!(HdyHeaderGroup);
62 
63 
64 	/** */
65 	public static GType getType()
66 	{
67 		return hdy_header_group_get_type();
68 	}
69 
70 	/** */
71 	public this()
72 	{
73 		auto p = hdy_header_group_new();
74 
75 		if(p is null)
76 		{
77 			throw new ConstructionException("null returned by new");
78 		}
79 
80 		this(cast(HdyHeaderGroup*) p, true);
81 	}
82 
83 	/**
84 	 * Adds a header bar to a #HdyHeaderGroup. The decoration layout of the
85 	 * widgets will be edited depending on their position in the composite header
86 	 * bar, the start widget displaying only the start of the user's decoration
87 	 * layout and the end widget displaying only its end while widgets in the middle
88 	 * won't display anything. A header bar can be set as having the focus to
89 	 * display all the decorations. See gtk_header_bar_set_decoration_layout().
90 	 *
91 	 * When the widget is destroyed or no longer referenced elsewhere, it will
92 	 * be removed from the header group.
93 	 *
94 	 * Params:
95 	 *     headerBar = the #GtkHeaderBar to add
96 	 */
97 	public void addHeaderBar(HeaderBar headerBar)
98 	{
99 		hdy_header_group_add_header_bar(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
100 	}
101 
102 	/**
103 	 * Returns: The currently focused header bar
104 	 */
105 	public HeaderBar getFocus()
106 	{
107 		auto p = hdy_header_group_get_focus(hdyHeaderGroup);
108 
109 		if(p is null)
110 		{
111 			return null;
112 		}
113 
114 		return ObjectG.getDObject!(HeaderBar)(cast(GtkHeaderBar*) p);
115 	}
116 
117 	/**
118 	 * Returns the list of headerbars associated with @self.
119 	 *
120 	 * Returns: a #GSList of
121 	 *     headerbars. The list is owned by libhandy and should not be modified.
122 	 */
123 	public ListSG getHeaderBars()
124 	{
125 		auto p = hdy_header_group_get_header_bars(hdyHeaderGroup);
126 
127 		if(p is null)
128 		{
129 			return null;
130 		}
131 
132 		return new ListSG(cast(GSList*) p);
133 	}
134 
135 	/**
136 	 * Removes a widget from a #HdyHeaderGroup
137 	 *
138 	 * Params:
139 	 *     headerBar = the #GtkHeaderBar to remove
140 	 */
141 	public void removeHeaderBar(HeaderBar headerBar)
142 	{
143 		hdy_header_group_remove_header_bar(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
144 	}
145 
146 	/**
147 	 * Sets the the currently focused header bar. If @header_bar is %NULL, the
148 	 * decoration will be spread as if the header bars of the group were only one,
149 	 * otherwise @header_bar will be the only one to receive the decoration.
150 	 *
151 	 * Params:
152 	 *     headerBar = a #GtkHeaderBar of @self, or %NULL
153 	 */
154 	public void setFocus(HeaderBar headerBar)
155 	{
156 		hdy_header_group_set_focus(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
157 	}
158 }