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