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 gdk.PopupLayout;
26 
27 private import gdk.c.functions;
28 public  import gdk.c.types;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gtkd.Loader;
32 
33 
34 /**
35  * The `GdkPopupLayout` struct contains information that is
36  * necessary position a [interface@Gdk.Popup] relative to its parent.
37  * 
38  * The positioning requires a negotiation with the windowing system,
39  * since it depends on external constraints, such as the position of
40  * the parent surface, and the screen dimensions.
41  * 
42  * The basic ingredients are a rectangle on the parent surface,
43  * and the anchor on both that rectangle and the popup. The anchors
44  * specify a side or corner to place next to each other.
45  * 
46  * ![Popup anchors](popup-anchors.png)
47  * 
48  * For cases where placing the anchors next to each other would make
49  * the popup extend offscreen, the layout includes some hints for how
50  * to resolve this problem. The hints may suggest to flip the anchor
51  * position to the other side, or to 'slide' the popup along a side,
52  * or to resize it.
53  * 
54  * ![Flipping popups](popup-flip.png)
55  * 
56  * ![Sliding popups](popup-slide.png)
57  * 
58  * These hints may be combined.
59  * 
60  * Ultimatively, it is up to the windowing system to determine the position
61  * and size of the popup. You can learn about the result by calling
62  * [method@Gdk.Popup.get_position_x], [method@Gdk.Popup.get_position_y],
63  * [method@Gdk.Popup.get_rect_anchor] and [method@Gdk.Popup.get_surface_anchor]
64  * after the popup has been presented. This can be used to adjust the rendering.
65  * For example, [class@Gtk.Popover] changes its arrow position accordingly.
66  * But you have to be careful avoid changing the size of the popover, or it
67  * has to be presented again.
68  */
69 public class PopupLayout
70 {
71 	/** the main Gtk struct */
72 	protected GdkPopupLayout* gdkPopupLayout;
73 	protected bool ownedRef;
74 
75 	/** Get the main Gtk struct */
76 	public GdkPopupLayout* getPopupLayoutStruct(bool transferOwnership = false)
77 	{
78 		if (transferOwnership)
79 			ownedRef = false;
80 		return gdkPopupLayout;
81 	}
82 
83 	/** the main Gtk struct as a void* */
84 	protected void* getStruct()
85 	{
86 		return cast(void*)gdkPopupLayout;
87 	}
88 
89 	/**
90 	 * Sets our main struct and passes it to the parent class.
91 	 */
92 	public this (GdkPopupLayout* gdkPopupLayout, bool ownedRef = false)
93 	{
94 		this.gdkPopupLayout = gdkPopupLayout;
95 		this.ownedRef = ownedRef;
96 	}
97 
98 	~this ()
99 	{
100 		if ( Linker.isLoaded(LIBRARY_GDK) && ownedRef )
101 			gdk_popup_layout_unref(gdkPopupLayout);
102 	}
103 
104 
105 	/** */
106 	public static GType getType()
107 	{
108 		return gdk_popup_layout_get_type();
109 	}
110 
111 	/**
112 	 * Create a popup layout description.
113 	 *
114 	 * Used together with [method@Gdk.Popup.present] to describe how a popup
115 	 * surface should be placed and behave on-screen.
116 	 *
117 	 * @anchor_rect is relative to the top-left corner of the surface's parent.
118 	 * @rect_anchor and @surface_anchor determine anchor points on @anchor_rect
119 	 * and surface to pin together.
120 	 *
121 	 * The position of @anchor_rect's anchor point can optionally be offset using
122 	 * [method@Gdk.PopupLayout.set_offset], which is equivalent to offsetting the
123 	 * position of surface.
124 	 *
125 	 * Params:
126 	 *     anchorRect = the anchor `GdkRectangle` to align @surface with
127 	 *     rectAnchor = the point on @anchor_rect to align with @surface's anchor point
128 	 *     surfaceAnchor = the point on @surface to align with @rect's anchor point
129 	 *
130 	 * Returns: newly created instance of `GdkPopupLayout`
131 	 *
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this(GdkRectangle* anchorRect, GdkGravity rectAnchor, GdkGravity surfaceAnchor)
135 	{
136 		auto __p = gdk_popup_layout_new(anchorRect, rectAnchor, surfaceAnchor);
137 
138 		if(__p is null)
139 		{
140 			throw new ConstructionException("null returned by new");
141 		}
142 
143 		this(cast(GdkPopupLayout*) __p);
144 	}
145 
146 	/**
147 	 * Makes a copy of @layout.
148 	 *
149 	 * Returns: a copy of @layout.
150 	 */
151 	public PopupLayout copy()
152 	{
153 		auto __p = gdk_popup_layout_copy(gdkPopupLayout);
154 
155 		if(__p is null)
156 		{
157 			return null;
158 		}
159 
160 		return ObjectG.getDObject!(PopupLayout)(cast(GdkPopupLayout*) __p, true);
161 	}
162 
163 	/**
164 	 * Check whether @layout and @other has identical layout properties.
165 	 *
166 	 * Params:
167 	 *     other = another `GdkPopupLayout`
168 	 *
169 	 * Returns: %TRUE if @layout and @other have identical layout properties,
170 	 *     otherwise %FALSE.
171 	 */
172 	public bool equal(PopupLayout other)
173 	{
174 		return gdk_popup_layout_equal(gdkPopupLayout, (other is null) ? null : other.getPopupLayoutStruct()) != 0;
175 	}
176 
177 	/**
178 	 * Get the `GdkAnchorHints`.
179 	 *
180 	 * Returns: the `GdkAnchorHints`
181 	 */
182 	public GdkAnchorHints getAnchorHints()
183 	{
184 		return gdk_popup_layout_get_anchor_hints(gdkPopupLayout);
185 	}
186 
187 	/**
188 	 * Get the anchor rectangle.
189 	 *
190 	 * Returns: The anchor rectangle
191 	 */
192 	public GdkRectangle* getAnchorRect()
193 	{
194 		return gdk_popup_layout_get_anchor_rect(gdkPopupLayout);
195 	}
196 
197 	/**
198 	 * Retrieves the offset for the anchor rectangle.
199 	 *
200 	 * Params:
201 	 *     dx = return location for the delta X coordinate
202 	 *     dy = return location for the delta Y coordinate
203 	 */
204 	public void getOffset(out int dx, out int dy)
205 	{
206 		gdk_popup_layout_get_offset(gdkPopupLayout, &dx, &dy);
207 	}
208 
209 	/**
210 	 * Returns the anchor position on the anchor rectangle.
211 	 *
212 	 * Returns: the anchor on the anchor rectangle.
213 	 */
214 	public GdkGravity getRectAnchor()
215 	{
216 		return gdk_popup_layout_get_rect_anchor(gdkPopupLayout);
217 	}
218 
219 	/**
220 	 * Obtains the shadow widths of this layout.
221 	 *
222 	 * Params:
223 	 *     left = return location for the left shadow width
224 	 *     right = return location for the right shadow width
225 	 *     top = return location for the top shadow width
226 	 *     bottom = return location for the bottom shadow width
227 	 *
228 	 * Since: 4.2
229 	 */
230 	public void getShadowWidth(out int left, out int right, out int top, out int bottom)
231 	{
232 		gdk_popup_layout_get_shadow_width(gdkPopupLayout, &left, &right, &top, &bottom);
233 	}
234 
235 	/**
236 	 * Returns the anchor position on the popup surface.
237 	 *
238 	 * Returns: the anchor on the popup surface.
239 	 */
240 	public GdkGravity getSurfaceAnchor()
241 	{
242 		return gdk_popup_layout_get_surface_anchor(gdkPopupLayout);
243 	}
244 
245 	alias doref = ref_;
246 	/**
247 	 * Increases the reference count of @value.
248 	 *
249 	 * Returns: the same @layout
250 	 */
251 	public PopupLayout ref_()
252 	{
253 		auto __p = gdk_popup_layout_ref(gdkPopupLayout);
254 
255 		if(__p is null)
256 		{
257 			return null;
258 		}
259 
260 		return ObjectG.getDObject!(PopupLayout)(cast(GdkPopupLayout*) __p, true);
261 	}
262 
263 	/**
264 	 * Set new anchor hints.
265 	 *
266 	 * The set @anchor_hints determines how @surface will be moved
267 	 * if the anchor points cause it to move off-screen. For example,
268 	 * %GDK_ANCHOR_FLIP_X will replace %GDK_GRAVITY_NORTH_WEST with
269 	 * %GDK_GRAVITY_NORTH_EAST and vice versa if @surface extends
270 	 * beyond the left or right edges of the monitor.
271 	 *
272 	 * Params:
273 	 *     anchorHints = the new `GdkAnchorHints`
274 	 */
275 	public void setAnchorHints(GdkAnchorHints anchorHints)
276 	{
277 		gdk_popup_layout_set_anchor_hints(gdkPopupLayout, anchorHints);
278 	}
279 
280 	/**
281 	 * Set the anchor rectangle.
282 	 *
283 	 * Params:
284 	 *     anchorRect = the new anchor rectangle
285 	 */
286 	public void setAnchorRect(GdkRectangle* anchorRect)
287 	{
288 		gdk_popup_layout_set_anchor_rect(gdkPopupLayout, anchorRect);
289 	}
290 
291 	/**
292 	 * Offset the position of the anchor rectangle with the given delta.
293 	 *
294 	 * Params:
295 	 *     dx = x delta to offset the anchor rectangle with
296 	 *     dy = y delta to offset the anchor rectangle with
297 	 */
298 	public void setOffset(int dx, int dy)
299 	{
300 		gdk_popup_layout_set_offset(gdkPopupLayout, dx, dy);
301 	}
302 
303 	/**
304 	 * Set the anchor on the anchor rectangle.
305 	 *
306 	 * Params:
307 	 *     anchor = the new rect anchor
308 	 */
309 	public void setRectAnchor(GdkGravity anchor)
310 	{
311 		gdk_popup_layout_set_rect_anchor(gdkPopupLayout, anchor);
312 	}
313 
314 	/**
315 	 * Sets the shadow width of the popup.
316 	 *
317 	 * The shadow width corresponds to the part of the computed
318 	 * surface size that would consist of the shadow margin
319 	 * surrounding the window, would there be any.
320 	 *
321 	 * Params:
322 	 *     left = width of the left part of the shadow
323 	 *     right = width of the right part of the shadow
324 	 *     top = height of the top part of the shadow
325 	 *     bottom = height of the bottom part of the shadow
326 	 *
327 	 * Since: 4.2
328 	 */
329 	public void setShadowWidth(int left, int right, int top, int bottom)
330 	{
331 		gdk_popup_layout_set_shadow_width(gdkPopupLayout, left, right, top, bottom);
332 	}
333 
334 	/**
335 	 * Set the anchor on the popup surface.
336 	 *
337 	 * Params:
338 	 *     anchor = the new popup surface anchor
339 	 */
340 	public void setSurfaceAnchor(GdkGravity anchor)
341 	{
342 		gdk_popup_layout_set_surface_anchor(gdkPopupLayout, anchor);
343 	}
344 
345 	/**
346 	 * Decreases the reference count of @value.
347 	 */
348 	public void unref()
349 	{
350 		gdk_popup_layout_unref(gdkPopupLayout);
351 	}
352 }