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.Overlay;
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 public  import gtkc.gdktypes;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 private import std.algorithm;
36 
37 
38 /**
39  * GtkOverlay is a container which contains a single main child, on top
40  * of which it can place “overlay” widgets. The position of each overlay
41  * widget is determined by its #GtkWidget:halign and #GtkWidget:valign
42  * properties. E.g. a widget with both alignments set to %GTK_ALIGN_START
43  * will be placed at the top left corner of the GtkOverlay container,
44  * whereas an overlay with halign set to %GTK_ALIGN_CENTER and valign set
45  * to %GTK_ALIGN_END will be placed a the bottom edge of the GtkOverlay,
46  * horizontally centered. The position can be adjusted by setting the margin
47  * properties of the child to non-zero values.
48  * 
49  * More complicated placement of overlays is possible by connecting
50  * to the #GtkOverlay::get-child-position signal.
51  * 
52  * # GtkOverlay as GtkBuildable
53  * 
54  * The GtkOverlay implementation of the GtkBuildable interface
55  * supports placing a child as an overlay by specifying “overlay” as
56  * the “type” attribute of a `<child>` element.
57  */
58 public class Overlay : Bin
59 {
60 	/** the main Gtk struct */
61 	protected GtkOverlay* gtkOverlay;
62 
63 	/** Get the main Gtk struct */
64 	public GtkOverlay* getOverlayStruct()
65 	{
66 		return gtkOverlay;
67 	}
68 
69 	/** the main Gtk struct as a void* */
70 	protected override void* getStruct()
71 	{
72 		return cast(void*)gtkOverlay;
73 	}
74 
75 	protected override void setStruct(GObject* obj)
76 	{
77 		gtkOverlay = cast(GtkOverlay*)obj;
78 		super.setStruct(obj);
79 	}
80 
81 	/**
82 	 * Sets our main struct and passes it to the parent class.
83 	 */
84 	public this (GtkOverlay* gtkOverlay, bool ownedRef = false)
85 	{
86 		this.gtkOverlay = gtkOverlay;
87 		super(cast(GtkBin*)gtkOverlay, ownedRef);
88 	}
89 
90 
91 	/** */
92 	public static GType getType()
93 	{
94 		return gtk_overlay_get_type();
95 	}
96 
97 	/**
98 	 * Creates a new #GtkOverlay.
99 	 *
100 	 * Return: a new #GtkOverlay object.
101 	 *
102 	 * Since: 3.2
103 	 *
104 	 * Throws: ConstructionException GTK+ fails to create the object.
105 	 */
106 	public this()
107 	{
108 		auto p = gtk_overlay_new();
109 		
110 		if(p is null)
111 		{
112 			throw new ConstructionException("null returned by new");
113 		}
114 		
115 		this(cast(GtkOverlay*) p);
116 	}
117 
118 	/**
119 	 * Adds @widget to @overlay.
120 	 *
121 	 * The widget will be stacked on top of the main widget
122 	 * added with gtk_container_add().
123 	 *
124 	 * The position at which @widget is placed is determined
125 	 * from its #GtkWidget:halign and #GtkWidget:valign properties.
126 	 *
127 	 * Params:
128 	 *     widget = a #GtkWidget to be added to the container
129 	 *
130 	 * Since: 3.2
131 	 */
132 	public void addOverlay(Widget widget)
133 	{
134 		gtk_overlay_add_overlay(gtkOverlay, (widget is null) ? null : widget.getWidgetStruct());
135 	}
136 
137 	/**
138 	 * Convenience function to get the value of the #GtkOverlay:pass-through
139 	 * child property for @widget.
140 	 *
141 	 * Params:
142 	 *     widget = an overlay child of #GtkOverlay
143 	 *
144 	 * Return: whether the widget is a pass through child.
145 	 *
146 	 * Since: 3.18
147 	 */
148 	public bool getOverlayPassThrough(Widget widget)
149 	{
150 		return gtk_overlay_get_overlay_pass_through(gtkOverlay, (widget is null) ? null : widget.getWidgetStruct()) != 0;
151 	}
152 
153 	/**
154 	 * Moves @child to a new @index in the list of @overlay children.
155 	 * The list contains overlays in the order that these were
156 	 * added to @overlay.
157 	 *
158 	 * A widget’s index in the @overlay children list determines which order
159 	 * the children are drawn if they overlap. The first child is drawn at
160 	 * the bottom. It also affects the default focus chain order.
161 	 *
162 	 * Params:
163 	 *     child = the overlaid #GtkWidget to move
164 	 *     position = the new index for @child in the list of overlay children
165 	 *         of @overlay, starting from 0. If negative, indicates the end of
166 	 *         the list
167 	 *
168 	 * Since: 3.18
169 	 */
170 	public void reorderOverlay(Widget child, int position)
171 	{
172 		gtk_overlay_reorder_overlay(gtkOverlay, (child is null) ? null : child.getWidgetStruct(), position);
173 	}
174 
175 	/**
176 	 * Convenience function to set the value of the #GtkOverlay:pass-through
177 	 * child property for @widget.
178 	 *
179 	 * Params:
180 	 *     widget = an overlay child of #GtkOverlay
181 	 *     passThrough = whether the child should pass the input through
182 	 *
183 	 * Since: 3.18
184 	 */
185 	public void setOverlayPassThrough(Widget widget, bool passThrough)
186 	{
187 		gtk_overlay_set_overlay_pass_through(gtkOverlay, (widget is null) ? null : widget.getWidgetStruct(), passThrough);
188 	}
189 
190 	protected class OnGetChildPositionDelegateWrapper
191 	{
192 		bool delegate(Widget, GdkRectangle*, Overlay) dlg;
193 		gulong handlerId;
194 		ConnectFlags flags;
195 		this(bool delegate(Widget, GdkRectangle*, Overlay) dlg, gulong handlerId, ConnectFlags flags)
196 		{
197 			this.dlg = dlg;
198 			this.handlerId = handlerId;
199 			this.flags = flags;
200 		}
201 	}
202 	protected OnGetChildPositionDelegateWrapper[] onGetChildPositionListeners;
203 
204 	/**
205 	 * The ::get-child-position signal is emitted to determine
206 	 * the position and size of any overlay child widgets. A
207 	 * handler for this signal should fill @allocation with
208 	 * the desired position and size for @widget, relative to
209 	 * the 'main' child of @overlay.
210 	 *
211 	 * The default handler for this signal uses the @widget's
212 	 * halign and valign properties to determine the position
213 	 * and gives the widget its natural size (except that an
214 	 * alignment of %GTK_ALIGN_FILL will cause the overlay to
215 	 * be full-width/height). If the main child is a
216 	 * #GtkScrolledWindow, the overlays are placed relative
217 	 * to its contents.
218 	 *
219 	 * Params:
220 	 *     widget = the child widget to position
221 	 *     allocation = return
222 	 *         location for the allocation
223 	 *
224 	 * Return: %TRUE if the @allocation has been filled
225 	 */
226 	gulong addOnGetChildPosition(bool delegate(Widget, GdkRectangle*, Overlay) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
227 	{
228 		onGetChildPositionListeners ~= new OnGetChildPositionDelegateWrapper(dlg, 0, connectFlags);
229 		onGetChildPositionListeners[onGetChildPositionListeners.length - 1].handlerId = Signals.connectData(
230 			this,
231 			"get-child-position",
232 			cast(GCallback)&callBackGetChildPosition,
233 			cast(void*)onGetChildPositionListeners[onGetChildPositionListeners.length - 1],
234 			cast(GClosureNotify)&callBackGetChildPositionDestroy,
235 			connectFlags);
236 		return onGetChildPositionListeners[onGetChildPositionListeners.length - 1].handlerId;
237 	}
238 	
239 	extern(C) static int callBackGetChildPosition(GtkOverlay* overlayStruct, GtkWidget* widget, GdkRectangle* allocation,OnGetChildPositionDelegateWrapper wrapper)
240 	{
241 		return wrapper.dlg(ObjectG.getDObject!(Widget)(widget), allocation, wrapper.outer);
242 	}
243 	
244 	extern(C) static void callBackGetChildPositionDestroy(OnGetChildPositionDelegateWrapper wrapper, GClosure* closure)
245 	{
246 		wrapper.outer.internalRemoveOnGetChildPosition(wrapper);
247 	}
248 
249 	protected void internalRemoveOnGetChildPosition(OnGetChildPositionDelegateWrapper source)
250 	{
251 		foreach(index, wrapper; onGetChildPositionListeners)
252 		{
253 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
254 			{
255 				onGetChildPositionListeners[index] = null;
256 				onGetChildPositionListeners = std.algorithm.remove(onGetChildPositionListeners, index);
257 				break;
258 			}
259 		}
260 	}
261 	
262 }