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