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