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 gobject.Signals;
25 private import gtk.BuildableIF;
26 private import gtk.BuildableT;
27 private import gtk.HeaderBar : GtkdHeaderBar = HeaderBar;
28 private import handy.HeaderBar : HdydHeaderBar = HeaderBar;
29 private import handy.HeaderGroupChild;
30 private import handy.c.functions;
31 public  import handy.c.types;
32 private import std.algorithm;
33 
34 
35 /** */
36 public class HeaderGroup : ObjectG, BuildableIF
37 {
38 	/** the main Gtk struct */
39 	protected HdyHeaderGroup* hdyHeaderGroup;
40 
41 	/** Get the main Gtk struct */
42 	public HdyHeaderGroup* getHeaderGroupStruct(bool transferOwnership = false)
43 	{
44 		if (transferOwnership)
45 			ownedRef = false;
46 		return hdyHeaderGroup;
47 	}
48 
49 	/** the main Gtk struct as a void* */
50 	protected override void* getStruct()
51 	{
52 		return cast(void*)hdyHeaderGroup;
53 	}
54 
55 	/**
56 	 * Sets our main struct and passes it to the parent class.
57 	 */
58 	public this (HdyHeaderGroup* hdyHeaderGroup, bool ownedRef = false)
59 	{
60 		this.hdyHeaderGroup = hdyHeaderGroup;
61 		super(cast(GObject*)hdyHeaderGroup, ownedRef);
62 	}
63 
64 	// add the Buildable capabilities
65 	mixin BuildableT!(HdyHeaderGroup);
66 
67 	/**
68 	 * Adds @header_bar to @self.
69 	 * When the widget is destroyed or no longer referenced elsewhere, it will
70 	 * be removed from the header group.
71 	 *
72 	 * Params:
73 	 *     headerBar = the #GtkHeaderBar to add
74 	 *
75 	 * Since: 1.0
76 	 */
77 	public void addGtkHeaderBar(GtkdHeaderBar headerBar)
78 	{
79 		hdy_header_group_add_gtk_header_bar(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
80 	}
81 
82 	/**
83 	 * Adds @header_bar to @self.
84 	 * When the widget is destroyed or no longer referenced elsewhere, it will
85 	 * be removed from the header group.
86 	 *
87 	 * Params:
88 	 *     headerBar = the #HdyHeaderBar to add
89 	 *
90 	 * Since: 1.0
91 	 */
92 	public void addHeaderBar(HdydHeaderBar headerBar)
93 	{
94 		hdy_header_group_add_header_bar(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
95 	}
96 
97 	/**
98 	 * Removes @header_bar from @self.
99 	 *
100 	 * Params:
101 	 *     headerBar = the #GtkHeaderBar to remove
102 	 *
103 	 * Since: 1.0
104 	 */
105 	public void removeGtkHeaderBar(GtkdHeaderBar headerBar)
106 	{
107 		hdy_header_group_remove_gtk_header_bar(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
108 	}
109 
110 	/**
111 	 * Removes @header_bar from @self.
112 	 *
113 	 * Params:
114 	 *     headerBar = the #HdyHeaderBar to remove
115 	 *
116 	 * Since: 1.0
117 	 */
118 	public void removeHeaderBar(HdydHeaderBar headerBar)
119 	{
120 		hdy_header_group_remove_header_bar(hdyHeaderGroup, (headerBar is null) ? null : headerBar.getHeaderBarStruct());
121 	}
122 
123 	/**
124 	 */
125 
126 	/** */
127 	public static GType getType()
128 	{
129 		return hdy_header_group_get_type();
130 	}
131 
132 	/** */
133 	public this()
134 	{
135 		auto __p = hdy_header_group_new();
136 
137 		if(__p is null)
138 		{
139 			throw new ConstructionException("null returned by new");
140 		}
141 
142 		this(cast(HdyHeaderGroup*) __p, true);
143 	}
144 
145 	/**
146 	 * Adds @header_group to @self.
147 	 * When the nested group is no longer referenced elsewhere, it will be removed
148 	 * from the header group.
149 	 *
150 	 * Params:
151 	 *     headerGroup = the #HdyHeaderGroup to add
152 	 *
153 	 * Since: 1.0
154 	 */
155 	public void addHeaderGroup(HeaderGroup headerGroup)
156 	{
157 		hdy_header_group_add_header_group(hdyHeaderGroup, (headerGroup is null) ? null : headerGroup.getHeaderGroupStruct());
158 	}
159 
160 	/**
161 	 * Returns the list of children associated with @self.
162 	 *
163 	 * Returns: the #GSList of
164 	 *     children. The list is owned by libhandy and should not be modified.
165 	 *
166 	 * Since: 1.0
167 	 */
168 	public ListSG getChildren()
169 	{
170 		auto __p = hdy_header_group_get_children(hdyHeaderGroup);
171 
172 		if(__p is null)
173 		{
174 			return null;
175 		}
176 
177 		return new ListSG(cast(GSList*) __p);
178 	}
179 
180 	/**
181 	 * Gets whether the elements of the group should all receive the full decoration.
182 	 *
183 	 * Returns: %TRUE if the elements of the group should all receive the full
184 	 *     decoration, %FALSE otherwise.
185 	 *
186 	 * Since: 1.0
187 	 */
188 	public bool getDecorateAll()
189 	{
190 		return hdy_header_group_get_decorate_all(hdyHeaderGroup) != 0;
191 	}
192 
193 	/**
194 	 * Removes @child from @self.
195 	 *
196 	 * Params:
197 	 *     child = the #HdyHeaderGroupChild to remove
198 	 *
199 	 * Since: 1.0
200 	 */
201 	public void removeChild(HeaderGroupChild child)
202 	{
203 		hdy_header_group_remove_child(hdyHeaderGroup, (child is null) ? null : child.getHeaderGroupChildStruct());
204 	}
205 
206 	/**
207 	 * Removes a nested #HdyHeaderGroup from a #HdyHeaderGroup
208 	 *
209 	 * Params:
210 	 *     headerGroup = the #HdyHeaderGroup to remove
211 	 *
212 	 * Since: 1.0
213 	 */
214 	public void removeHeaderGroup(HeaderGroup headerGroup)
215 	{
216 		hdy_header_group_remove_header_group(hdyHeaderGroup, (headerGroup is null) ? null : headerGroup.getHeaderGroupStruct());
217 	}
218 
219 	/**
220 	 * Sets whether the elements of the group should all receive the full decoration.
221 	 *
222 	 * Params:
223 	 *     decorateAll = whether the elements of the group should all receive the full decoration
224 	 *
225 	 * Since: 1.0
226 	 */
227 	public void setDecorateAll(bool decorateAll)
228 	{
229 		hdy_header_group_set_decorate_all(hdyHeaderGroup, decorateAll);
230 	}
231 
232 	/**
233 	 * This signal is emitted before updating the decoration layouts.
234 	 *
235 	 * Since: 1.0
236 	 */
237 	gulong addOnUpdateDecorationLayouts(void delegate(HeaderGroup) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
238 	{
239 		return Signals.connect(this, "update-decoration-layouts", dlg, connectFlags ^ ConnectFlags.SWAPPED);
240 	}
241 }