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.Popover;
26 
27 private import gio.MenuModel;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.Bin;
33 private import gtk.Widget;
34 public  import gtkc.gdktypes;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 
38 
39 /**
40  * GtkPopover is a bubble-like context window, primarily meant to
41  * provide context-dependent information or options. Popovers are
42  * attached to a widget, passed at construction time on gtk_popover_new(),
43  * or updated afterwards through gtk_popover_set_relative_to(), by
44  * default they will point to the whole widget area, although this
45  * behavior can be changed through gtk_popover_set_pointing_to().
46  * 
47  * The position of a popover relative to the widget it is attached to
48  * can also be changed through gtk_popover_set_position().
49  * 
50  * By default, #GtkPopover performs a GTK+ grab, in order to ensure
51  * input events get redirected to it while it is shown, and also so
52  * the popover is dismissed in the expected situations (clicks outside
53  * the popover, or the Esc key being pressed). If no such modal behavior
54  * is desired on a popover, gtk_popover_set_modal() may be called on it
55  * to tweak its behavior.
56  * 
57  * ## GtkPopover as menu replacement
58  * 
59  * GtkPopover is often used to replace menus. To facilitate this, it
60  * supports being populated from a #GMenuModel, using
61  * gtk_popover_new_from_model(). In addition to all the regular menu
62  * model features, this function supports rendering sections in the
63  * model in a more compact form, as a row of icon buttons instead of
64  * menu items.
65  * 
66  * To use this rendering, set the ”display-hint” attribute of the
67  * section to ”horizontal-buttons” and set the icons of your items
68  * with the ”verb-icon” attribute.
69  * 
70  * |[
71  * <section>
72  * <attribute name="display-hint">horizontal-buttons</attribute>
73  * <item>
74  * <attribute name="label">Cut</attribute>
75  * <attribute name="action">app.cut</attribute>
76  * <attribute name="verb-icon">edit-cut-symbolic</attribute>
77  * </item>
78  * <item>
79  * <attribute name="label">Copy</attribute>
80  * <attribute name="action">app.copy</attribute>
81  * <attribute name="verb-icon">edit-copy-symbolic</attribute>
82  * </item>
83  * <item>
84  * <attribute name="label">Paste</attribute>
85  * <attribute name="action">app.paste</attribute>
86  * <attribute name="verb-icon">edit-paste-symbolic</attribute>
87  * </item>
88  * </section>
89  * ]|
90  */
91 public class Popover : Bin
92 {
93 	/** the main Gtk struct */
94 	protected GtkPopover* gtkPopover;
95 
96 	/** Get the main Gtk struct */
97 	public GtkPopover* getPopoverStruct()
98 	{
99 		return gtkPopover;
100 	}
101 
102 	/** the main Gtk struct as a void* */
103 	protected override void* getStruct()
104 	{
105 		return cast(void*)gtkPopover;
106 	}
107 
108 	protected override void setStruct(GObject* obj)
109 	{
110 		gtkPopover = cast(GtkPopover*)obj;
111 		super.setStruct(obj);
112 	}
113 
114 	/**
115 	 * Sets our main struct and passes it to the parent class.
116 	 */
117 	public this (GtkPopover* gtkPopover, bool ownedRef = false)
118 	{
119 		this.gtkPopover = gtkPopover;
120 		super(cast(GtkBin*)gtkPopover, ownedRef);
121 	}
122 
123 
124 	/** */
125 	public static GType getType()
126 	{
127 		return gtk_popover_get_type();
128 	}
129 
130 	/**
131 	 * Creates a new popover to point to @relative_to
132 	 *
133 	 * Params:
134 	 *     relativeTo = #GtkWidget the popover is related to
135 	 *
136 	 * Return: a new #GtkPopover
137 	 *
138 	 * Since: 3.12
139 	 *
140 	 * Throws: ConstructionException GTK+ fails to create the object.
141 	 */
142 	public this(Widget relativeTo)
143 	{
144 		auto p = gtk_popover_new((relativeTo is null) ? null : relativeTo.getWidgetStruct());
145 		
146 		if(p is null)
147 		{
148 			throw new ConstructionException("null returned by new");
149 		}
150 		
151 		this(cast(GtkPopover*) p);
152 	}
153 
154 	/**
155 	 * Creates a #GtkPopover and populates it according to
156 	 * @model. The popover is pointed to the @relative_to widget.
157 	 *
158 	 * The created buttons are connected to actions found in the
159 	 * #GtkApplicationWindow to which the popover belongs - typically
160 	 * by means of being attached to a widget that is contained within
161 	 * the #GtkApplicationWindows widget hierarchy.
162 	 *
163 	 * Actions can also be added using gtk_widget_insert_action_group()
164 	 * on the menus attach widget or on any of its parent widgets.
165 	 *
166 	 * Params:
167 	 *     relativeTo = #GtkWidget the popover is related to
168 	 *     model = a #GMenuModel
169 	 *
170 	 * Return: the new #GtkPopover
171 	 *
172 	 * Since: 3.12
173 	 *
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this(Widget relativeTo, MenuModel model)
177 	{
178 		auto p = gtk_popover_new_from_model((relativeTo is null) ? null : relativeTo.getWidgetStruct(), (model is null) ? null : model.getMenuModelStruct());
179 		
180 		if(p is null)
181 		{
182 			throw new ConstructionException("null returned by new_from_model");
183 		}
184 		
185 		this(cast(GtkPopover*) p);
186 	}
187 
188 	/**
189 	 * Establishes a binding between a #GtkPopover and a #GMenuModel.
190 	 *
191 	 * The contents of @popover are removed and then refilled with menu items
192 	 * according to @model.  When @model changes, @popover is updated.
193 	 * Calling this function twice on @popover with different @model will
194 	 * cause the first binding to be replaced with a binding to the new
195 	 * model. If @model is %NULL then any previous binding is undone and
196 	 * all children are removed.
197 	 *
198 	 * If @action_namespace is non-%NULL then the effect is as if all
199 	 * actions mentioned in the @model have their names prefixed with the
200 	 * namespace, plus a dot.  For example, if the action “quit” is
201 	 * mentioned and @action_namespace is “app” then the effective action
202 	 * name is “app.quit”.
203 	 *
204 	 * This function uses #GtkActionable to define the action name and
205 	 * target values on the created menu items.  If you want to use an
206 	 * action group other than “app” and “win”, or if you want to use a
207 	 * #GtkMenuShell outside of a #GtkApplicationWindow, then you will need
208 	 * to attach your own action group to the widget hierarchy using
209 	 * gtk_widget_insert_action_group().  As an example, if you created a
210 	 * group with a “quit” action and inserted it with the name “mygroup”
211 	 * then you would use the action name “mygroup.quit” in your
212 	 * #GMenuModel.
213 	 *
214 	 * Params:
215 	 *     model = the #GMenuModel to bind to or %NULL to remove
216 	 *         binding
217 	 *     actionNamespace = the namespace for actions in @model
218 	 *
219 	 * Since: 3.12
220 	 */
221 	public void bindModel(MenuModel model, string actionNamespace)
222 	{
223 		gtk_popover_bind_model(gtkPopover, (model is null) ? null : model.getMenuModelStruct(), Str.toStringz(actionNamespace));
224 	}
225 
226 	/**
227 	 * Gets the widget that should be set as the default while
228 	 * the popover is shown.
229 	 *
230 	 * Return: the default widget, or %NULL if there is none
231 	 *
232 	 * Since: 3.18
233 	 */
234 	public Widget getDefaultWidget()
235 	{
236 		auto p = gtk_popover_get_default_widget(gtkPopover);
237 		
238 		if(p is null)
239 		{
240 			return null;
241 		}
242 		
243 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
244 	}
245 
246 	/**
247 	 * Returns whether the popover is modal, see gtk_popover_set_modal to
248 	 * see the implications of this.
249 	 *
250 	 * Return: #TRUE if @popover is modal
251 	 *
252 	 * Since: 3.12
253 	 */
254 	public bool getModal()
255 	{
256 		return gtk_popover_get_modal(gtkPopover) != 0;
257 	}
258 
259 	/**
260 	 * If a rectangle to point to has been set, this function will
261 	 * return %TRUE and fill in @rect with such rectangle, otherwise
262 	 * it will return %FALSE and fill in @rect with the attached
263 	 * widget coordinates.
264 	 *
265 	 * Params:
266 	 *     rect = location to store the rectangle
267 	 *
268 	 * Return: %TRUE if a rectangle to point to was set.
269 	 */
270 	public bool getPointingTo(out GdkRectangle rect)
271 	{
272 		return gtk_popover_get_pointing_to(gtkPopover, &rect) != 0;
273 	}
274 
275 	/**
276 	 * Returns the preferred position of @popover.
277 	 *
278 	 * Return: The preferred position.
279 	 */
280 	public GtkPositionType getPosition()
281 	{
282 		return gtk_popover_get_position(gtkPopover);
283 	}
284 
285 	/**
286 	 * Returns the widget @popover is currently attached to
287 	 *
288 	 * Return: a #GtkWidget
289 	 *
290 	 * Since: 3.12
291 	 */
292 	public Widget getRelativeTo()
293 	{
294 		auto p = gtk_popover_get_relative_to(gtkPopover);
295 		
296 		if(p is null)
297 		{
298 			return null;
299 		}
300 		
301 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
302 	}
303 
304 	/**
305 	 * Returns whether show/hide transitions are enabled on this popover.
306 	 *
307 	 * Return: #TRUE if the show and hide transitions of the given
308 	 *     popover are enabled, #FALSE otherwise.
309 	 *
310 	 * Since: 3.16
311 	 */
312 	public bool getTransitionsEnabled()
313 	{
314 		return gtk_popover_get_transitions_enabled(gtkPopover) != 0;
315 	}
316 
317 	/**
318 	 * Sets the widget that should be set as default widget while
319 	 * the popover is shown (see gtk_window_set_default()). #GtkPopover
320 	 * remembers the previous default widget and reestablishes it
321 	 * when the popover is dismissed.
322 	 *
323 	 * Params:
324 	 *     widget = the new default widget, or %NULL
325 	 *
326 	 * Since: 3.18
327 	 */
328 	public void setDefaultWidget(Widget widget)
329 	{
330 		gtk_popover_set_default_widget(gtkPopover, (widget is null) ? null : widget.getWidgetStruct());
331 	}
332 
333 	/**
334 	 * Sets whether @popover is modal, a modal popover will grab all input
335 	 * within the toplevel and grab the keyboard focus on it when being
336 	 * displayed. Clicking outside the popover area or pressing Esc will
337 	 * dismiss the popover and ungrab input.
338 	 *
339 	 * Params:
340 	 *     modal = #TRUE to make popover claim all input within the toplevel
341 	 *
342 	 * Since: 3.12
343 	 */
344 	public void setModal(bool modal)
345 	{
346 		gtk_popover_set_modal(gtkPopover, modal);
347 	}
348 
349 	/**
350 	 * Sets the rectangle that @popover will point to, in the
351 	 * coordinate space of the widget @popover is attached to,
352 	 * see gtk_popover_set_relative_to().
353 	 *
354 	 * Params:
355 	 *     rect = rectangle to point to
356 	 *
357 	 * Since: 3.12
358 	 */
359 	public void setPointingTo(GdkRectangle* rect)
360 	{
361 		gtk_popover_set_pointing_to(gtkPopover, rect);
362 	}
363 
364 	/**
365 	 * Sets the preferred position for @popover to appear. If the @popover
366 	 * is currently visible, it will be immediately updated.
367 	 *
368 	 * This preference will be respected where possible, although
369 	 * on lack of space (eg. if close to the window edges), the
370 	 * #GtkPopover may choose to appear on the opposite side
371 	 *
372 	 * Params:
373 	 *     position = preferred popover position
374 	 *
375 	 * Since: 3.12
376 	 */
377 	public void setPosition(GtkPositionType position)
378 	{
379 		gtk_popover_set_position(gtkPopover, position);
380 	}
381 
382 	/**
383 	 * Sets a new widget to be attached to @popover. If @popover is
384 	 * visible, the position will be updated.
385 	 *
386 	 * Note: the ownership of popovers is always given to their @relative_to
387 	 * widget, so if @relative_to is set to %NULL on an attached @popover, it
388 	 * will be detached from its previous widget, and consequently destroyed
389 	 * unless extra references are kept.
390 	 *
391 	 * Params:
392 	 *     relativeTo = a #GtkWidget
393 	 *
394 	 * Since: 3.12
395 	 */
396 	public void setRelativeTo(Widget relativeTo)
397 	{
398 		gtk_popover_set_relative_to(gtkPopover, (relativeTo is null) ? null : relativeTo.getWidgetStruct());
399 	}
400 
401 	/**
402 	 * Sets whether show/hide transitions are enabled on this popover
403 	 *
404 	 * Params:
405 	 *     transitionsEnabled = Whether transitions are enabled
406 	 *
407 	 * Since: 3.16
408 	 */
409 	public void setTransitionsEnabled(bool transitionsEnabled)
410 	{
411 		gtk_popover_set_transitions_enabled(gtkPopover, transitionsEnabled);
412 	}
413 
414 	int[string] connectedSignals;
415 
416 	void delegate(Popover)[] onClosedListeners;
417 	/** */
418 	void addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
419 	{
420 		if ( "closed" !in connectedSignals )
421 		{
422 			Signals.connectData(
423 				this,
424 				"closed",
425 				cast(GCallback)&callBackClosed,
426 				cast(void*)this,
427 				null,
428 				connectFlags);
429 			connectedSignals["closed"] = 1;
430 		}
431 		onClosedListeners ~= dlg;
432 	}
433 	extern(C) static void callBackClosed(GtkPopover* popoverStruct, Popover _popover)
434 	{
435 		foreach ( void delegate(Popover) dlg; _popover.onClosedListeners )
436 		{
437 			dlg(_popover);
438 		}
439 	}
440 }