1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD 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  * gtkD 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 gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.HandleBox;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Bin;
31 private import gtk.Widget;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * The #GtkHandleBox widget allows a portion of a window to be "torn
40  * off". It is a bin widget which displays its child and a handle that
41  * the user can drag to tear off a separate window (the “float
42  * window”) containing the child widget. A thin
43  * “ghost” is drawn in the original location of the
44  * handlebox. By dragging the separate window back to its original
45  * location, it can be reattached.
46  * 
47  * When reattaching, the ghost and float window, must be aligned
48  * along one of the edges, the “snap edge”.
49  * This either can be specified by the application programmer
50  * explicitly, or GTK+ will pick a reasonable default based
51  * on the handle position.
52  * 
53  * To make detaching and reattaching the handlebox as minimally confusing
54  * as possible to the user, it is important to set the snap edge so that
55  * the snap edge does not move when the handlebox is deattached. For
56  * instance, if the handlebox is packed at the bottom of a VBox, then
57  * when the handlebox is detached, the bottom edge of the handlebox's
58  * allocation will remain fixed as the height of the handlebox shrinks,
59  * so the snap edge should be set to %GTK_POS_BOTTOM.
60  * 
61  * > #GtkHandleBox has been deprecated. It is very specialized, lacks features
62  * > to make it useful and most importantly does not fit well into modern
63  * > application design. Do not use it. There is no replacement.
64  */
65 public class HandleBox : Bin
66 {
67 	/** the main Gtk struct */
68 	protected GtkHandleBox* gtkHandleBox;
69 
70 	/** Get the main Gtk struct */
71 	public GtkHandleBox* getHandleBoxStruct(bool transferOwnership = false)
72 	{
73 		if (transferOwnership)
74 			ownedRef = false;
75 		return gtkHandleBox;
76 	}
77 
78 	/** the main Gtk struct as a void* */
79 	protected override void* getStruct()
80 	{
81 		return cast(void*)gtkHandleBox;
82 	}
83 
84 	protected override void setStruct(GObject* obj)
85 	{
86 		gtkHandleBox = cast(GtkHandleBox*)obj;
87 		super.setStruct(obj);
88 	}
89 
90 	/**
91 	 * Sets our main struct and passes it to the parent class.
92 	 */
93 	public this (GtkHandleBox* gtkHandleBox, bool ownedRef = false)
94 	{
95 		this.gtkHandleBox = gtkHandleBox;
96 		super(cast(GtkBin*)gtkHandleBox, ownedRef);
97 	}
98 
99 
100 	/** */
101 	public static GType getType()
102 	{
103 		return gtk_handle_box_get_type();
104 	}
105 
106 	/**
107 	 * Create a new handle box.
108 	 *
109 	 * Deprecated: #GtkHandleBox has been deprecated.
110 	 *
111 	 * Returns: a new #GtkHandleBox.
112 	 *
113 	 * Throws: ConstructionException GTK+ fails to create the object.
114 	 */
115 	public this()
116 	{
117 		auto p = gtk_handle_box_new();
118 
119 		if(p is null)
120 		{
121 			throw new ConstructionException("null returned by new");
122 		}
123 
124 		this(cast(GtkHandleBox*) p);
125 	}
126 
127 	/**
128 	 * Whether the handlebox’s child is currently detached.
129 	 *
130 	 * Deprecated: #GtkHandleBox has been deprecated.
131 	 *
132 	 * Returns: %TRUE if the child is currently detached, otherwise %FALSE
133 	 *
134 	 * Since: 2.14
135 	 */
136 	public bool getChildDetached()
137 	{
138 		return gtk_handle_box_get_child_detached(gtkHandleBox) != 0;
139 	}
140 
141 	/**
142 	 * Gets the handle position of the handle box. See
143 	 * gtk_handle_box_set_handle_position().
144 	 *
145 	 * Deprecated: #GtkHandleBox has been deprecated.
146 	 *
147 	 * Returns: the current handle position.
148 	 */
149 	public GtkPositionType getHandlePosition()
150 	{
151 		return gtk_handle_box_get_handle_position(gtkHandleBox);
152 	}
153 
154 	/**
155 	 * Gets the type of shadow drawn around the handle box. See
156 	 * gtk_handle_box_set_shadow_type().
157 	 *
158 	 * Deprecated: #GtkHandleBox has been deprecated.
159 	 *
160 	 * Returns: the type of shadow currently drawn around the handle box.
161 	 */
162 	public GtkShadowType getShadowType()
163 	{
164 		return gtk_handle_box_get_shadow_type(gtkHandleBox);
165 	}
166 
167 	/**
168 	 * Gets the edge used for determining reattachment of the handle box.
169 	 * See gtk_handle_box_set_snap_edge().
170 	 *
171 	 * Deprecated: #GtkHandleBox has been deprecated.
172 	 *
173 	 * Returns: the edge used for determining reattachment, or
174 	 *     (GtkPositionType)-1 if this is determined (as per default)
175 	 *     from the handle position.
176 	 */
177 	public GtkPositionType getSnapEdge()
178 	{
179 		return gtk_handle_box_get_snap_edge(gtkHandleBox);
180 	}
181 
182 	/**
183 	 * Sets the side of the handlebox where the handle is drawn.
184 	 *
185 	 * Deprecated: #GtkHandleBox has been deprecated.
186 	 *
187 	 * Params:
188 	 *     position = the side of the handlebox where the handle should be drawn.
189 	 */
190 	public void setHandlePosition(GtkPositionType position)
191 	{
192 		gtk_handle_box_set_handle_position(gtkHandleBox, position);
193 	}
194 
195 	/**
196 	 * Sets the type of shadow to be drawn around the border
197 	 * of the handle box.
198 	 *
199 	 * Deprecated: #GtkHandleBox has been deprecated.
200 	 *
201 	 * Params:
202 	 *     type = the shadow type.
203 	 */
204 	public void setShadowType(GtkShadowType type)
205 	{
206 		gtk_handle_box_set_shadow_type(gtkHandleBox, type);
207 	}
208 
209 	/**
210 	 * Sets the snap edge of a handlebox. The snap edge is
211 	 * the edge of the detached child that must be aligned
212 	 * with the corresponding edge of the “ghost” left
213 	 * behind when the child was detached to reattach
214 	 * the torn-off window. Usually, the snap edge should
215 	 * be chosen so that it stays in the same place on
216 	 * the screen when the handlebox is torn off.
217 	 *
218 	 * If the snap edge is not set, then an appropriate value
219 	 * will be guessed from the handle position. If the
220 	 * handle position is %GTK_POS_RIGHT or %GTK_POS_LEFT,
221 	 * then the snap edge will be %GTK_POS_TOP, otherwise
222 	 * it will be %GTK_POS_LEFT.
223 	 *
224 	 * Deprecated: #GtkHandleBox has been deprecated.
225 	 *
226 	 * Params:
227 	 *     edge = the snap edge, or -1 to unset the value; in which
228 	 *         case GTK+ will try to guess an appropriate value
229 	 *         in the future.
230 	 */
231 	public void setSnapEdge(GtkPositionType edge)
232 	{
233 		gtk_handle_box_set_snap_edge(gtkHandleBox, edge);
234 	}
235 
236 	protected class OnChildAttachedDelegateWrapper
237 	{
238 		void delegate(Widget, HandleBox) dlg;
239 		gulong handlerId;
240 
241 		this(void delegate(Widget, HandleBox) dlg)
242 		{
243 			this.dlg = dlg;
244 			onChildAttachedListeners ~= this;
245 		}
246 
247 		void remove(OnChildAttachedDelegateWrapper source)
248 		{
249 			foreach(index, wrapper; onChildAttachedListeners)
250 			{
251 				if (wrapper.handlerId == source.handlerId)
252 				{
253 					onChildAttachedListeners[index] = null;
254 					onChildAttachedListeners = std.algorithm.remove(onChildAttachedListeners, index);
255 					break;
256 				}
257 			}
258 		}
259 	}
260 	OnChildAttachedDelegateWrapper[] onChildAttachedListeners;
261 
262 	/**
263 	 * This signal is emitted when the contents of the
264 	 * handlebox are reattached to the main window.
265 	 *
266 	 * Deprecated: #GtkHandleBox has been deprecated.
267 	 *
268 	 * Params:
269 	 *     widget = the child widget of the handlebox.
270 	 *         (this argument provides no extra information
271 	 *         and is here only for backwards-compatibility)
272 	 */
273 	gulong addOnChildAttached(void delegate(Widget, HandleBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
274 	{
275 		auto wrapper = new OnChildAttachedDelegateWrapper(dlg);
276 		wrapper.handlerId = Signals.connectData(
277 			this,
278 			"child-attached",
279 			cast(GCallback)&callBackChildAttached,
280 			cast(void*)wrapper,
281 			cast(GClosureNotify)&callBackChildAttachedDestroy,
282 			connectFlags);
283 		return wrapper.handlerId;
284 	}
285 
286 	extern(C) static void callBackChildAttached(GtkHandleBox* handleboxStruct, GtkWidget* widget, OnChildAttachedDelegateWrapper wrapper)
287 	{
288 		wrapper.dlg(ObjectG.getDObject!(Widget)(widget), wrapper.outer);
289 	}
290 
291 	extern(C) static void callBackChildAttachedDestroy(OnChildAttachedDelegateWrapper wrapper, GClosure* closure)
292 	{
293 		wrapper.remove(wrapper);
294 	}
295 
296 	protected class OnChildDetachedDelegateWrapper
297 	{
298 		void delegate(Widget, HandleBox) dlg;
299 		gulong handlerId;
300 
301 		this(void delegate(Widget, HandleBox) dlg)
302 		{
303 			this.dlg = dlg;
304 			onChildDetachedListeners ~= this;
305 		}
306 
307 		void remove(OnChildDetachedDelegateWrapper source)
308 		{
309 			foreach(index, wrapper; onChildDetachedListeners)
310 			{
311 				if (wrapper.handlerId == source.handlerId)
312 				{
313 					onChildDetachedListeners[index] = null;
314 					onChildDetachedListeners = std.algorithm.remove(onChildDetachedListeners, index);
315 					break;
316 				}
317 			}
318 		}
319 	}
320 	OnChildDetachedDelegateWrapper[] onChildDetachedListeners;
321 
322 	/**
323 	 * This signal is emitted when the contents of the
324 	 * handlebox are detached from the main window.
325 	 *
326 	 * Deprecated: #GtkHandleBox has been deprecated.
327 	 *
328 	 * Params:
329 	 *     widget = the child widget of the handlebox.
330 	 *         (this argument provides no extra information
331 	 *         and is here only for backwards-compatibility)
332 	 */
333 	gulong addOnChildDetached(void delegate(Widget, HandleBox) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
334 	{
335 		auto wrapper = new OnChildDetachedDelegateWrapper(dlg);
336 		wrapper.handlerId = Signals.connectData(
337 			this,
338 			"child-detached",
339 			cast(GCallback)&callBackChildDetached,
340 			cast(void*)wrapper,
341 			cast(GClosureNotify)&callBackChildDetachedDestroy,
342 			connectFlags);
343 		return wrapper.handlerId;
344 	}
345 
346 	extern(C) static void callBackChildDetached(GtkHandleBox* handleboxStruct, GtkWidget* widget, OnChildDetachedDelegateWrapper wrapper)
347 	{
348 		wrapper.dlg(ObjectG.getDObject!(Widget)(widget), wrapper.outer);
349 	}
350 
351 	extern(C) static void callBackChildDetachedDestroy(OnChildDetachedDelegateWrapper wrapper, GClosure* closure)
352 	{
353 		wrapper.remove(wrapper);
354 	}
355 }