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  * # CSS nodes
92  * 
93  * GtkPopover has a single css node called popover. It always gets the
94  * .background style class and it gets the .menu style class if it is
95  * menu-like (e.g. #GtkPopoverMenu or created using gtk_popover_new_from_model().
96  * 
97  * Particular uses of GtkPopover, such as touch selection popups
98  * or magnifiers in #GtkEntry or #GtkTextView get style classes
99  * like .touch-selection or .magnifier to differentiate from
100  * plain popovers.
101  */
102 public class Popover : Bin
103 {
104 	/** the main Gtk struct */
105 	protected GtkPopover* gtkPopover;
106 
107 	/** Get the main Gtk struct */
108 	public GtkPopover* getPopoverStruct()
109 	{
110 		return gtkPopover;
111 	}
112 
113 	/** the main Gtk struct as a void* */
114 	protected override void* getStruct()
115 	{
116 		return cast(void*)gtkPopover;
117 	}
118 
119 	protected override void setStruct(GObject* obj)
120 	{
121 		gtkPopover = cast(GtkPopover*)obj;
122 		super.setStruct(obj);
123 	}
124 
125 	/**
126 	 * Sets our main struct and passes it to the parent class.
127 	 */
128 	public this (GtkPopover* gtkPopover, bool ownedRef = false)
129 	{
130 		this.gtkPopover = gtkPopover;
131 		super(cast(GtkBin*)gtkPopover, ownedRef);
132 	}
133 
134 
135 	/** */
136 	public static GType getType()
137 	{
138 		return gtk_popover_get_type();
139 	}
140 
141 	/**
142 	 * Creates a new popover to point to @relative_to
143 	 *
144 	 * Params:
145 	 *     relativeTo = #GtkWidget the popover is related to
146 	 *
147 	 * Return: a new #GtkPopover
148 	 *
149 	 * Since: 3.12
150 	 *
151 	 * Throws: ConstructionException GTK+ fails to create the object.
152 	 */
153 	public this(Widget relativeTo)
154 	{
155 		auto p = gtk_popover_new((relativeTo is null) ? null : relativeTo.getWidgetStruct());
156 		
157 		if(p is null)
158 		{
159 			throw new ConstructionException("null returned by new");
160 		}
161 		
162 		this(cast(GtkPopover*) p);
163 	}
164 
165 	/**
166 	 * Creates a #GtkPopover and populates it according to
167 	 * @model. The popover is pointed to the @relative_to widget.
168 	 *
169 	 * The created buttons are connected to actions found in the
170 	 * #GtkApplicationWindow to which the popover belongs - typically
171 	 * by means of being attached to a widget that is contained within
172 	 * the #GtkApplicationWindows widget hierarchy.
173 	 *
174 	 * Actions can also be added using gtk_widget_insert_action_group()
175 	 * on the menus attach widget or on any of its parent widgets.
176 	 *
177 	 * Params:
178 	 *     relativeTo = #GtkWidget the popover is related to
179 	 *     model = a #GMenuModel
180 	 *
181 	 * Return: the new #GtkPopover
182 	 *
183 	 * Since: 3.12
184 	 *
185 	 * Throws: ConstructionException GTK+ fails to create the object.
186 	 */
187 	public this(Widget relativeTo, MenuModel model)
188 	{
189 		auto p = gtk_popover_new_from_model((relativeTo is null) ? null : relativeTo.getWidgetStruct(), (model is null) ? null : model.getMenuModelStruct());
190 		
191 		if(p is null)
192 		{
193 			throw new ConstructionException("null returned by new_from_model");
194 		}
195 		
196 		this(cast(GtkPopover*) p);
197 	}
198 
199 	/**
200 	 * Establishes a binding between a #GtkPopover and a #GMenuModel.
201 	 *
202 	 * The contents of @popover are removed and then refilled with menu items
203 	 * according to @model.  When @model changes, @popover is updated.
204 	 * Calling this function twice on @popover with different @model will
205 	 * cause the first binding to be replaced with a binding to the new
206 	 * model. If @model is %NULL then any previous binding is undone and
207 	 * all children are removed.
208 	 *
209 	 * If @action_namespace is non-%NULL then the effect is as if all
210 	 * actions mentioned in the @model have their names prefixed with the
211 	 * namespace, plus a dot.  For example, if the action “quit” is
212 	 * mentioned and @action_namespace is “app” then the effective action
213 	 * name is “app.quit”.
214 	 *
215 	 * This function uses #GtkActionable to define the action name and
216 	 * target values on the created menu items.  If you want to use an
217 	 * action group other than “app” and “win”, or if you want to use a
218 	 * #GtkMenuShell outside of a #GtkApplicationWindow, then you will need
219 	 * to attach your own action group to the widget hierarchy using
220 	 * gtk_widget_insert_action_group().  As an example, if you created a
221 	 * group with a “quit” action and inserted it with the name “mygroup”
222 	 * then you would use the action name “mygroup.quit” in your
223 	 * #GMenuModel.
224 	 *
225 	 * Params:
226 	 *     model = the #GMenuModel to bind to or %NULL to remove
227 	 *         binding
228 	 *     actionNamespace = the namespace for actions in @model
229 	 *
230 	 * Since: 3.12
231 	 */
232 	public void bindModel(MenuModel model, string actionNamespace)
233 	{
234 		gtk_popover_bind_model(gtkPopover, (model is null) ? null : model.getMenuModelStruct(), Str.toStringz(actionNamespace));
235 	}
236 
237 	/**
238 	 * Returns the constraint for placing this popover.
239 	 * See gtk_popover_set_constrain_to().
240 	 *
241 	 * Return: the constraint for placing this popover.
242 	 *
243 	 * Since: 3.20
244 	 */
245 	public GtkPopoverConstraint getConstrainTo()
246 	{
247 		return gtk_popover_get_constrain_to(gtkPopover);
248 	}
249 
250 	/**
251 	 * Gets the widget that should be set as the default while
252 	 * the popover is shown.
253 	 *
254 	 * Return: the default widget,
255 	 *     or %NULL if there is none
256 	 *
257 	 * Since: 3.18
258 	 */
259 	public Widget getDefaultWidget()
260 	{
261 		auto p = gtk_popover_get_default_widget(gtkPopover);
262 		
263 		if(p is null)
264 		{
265 			return null;
266 		}
267 		
268 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
269 	}
270 
271 	/**
272 	 * Returns whether the popover is modal, see gtk_popover_set_modal to
273 	 * see the implications of this.
274 	 *
275 	 * Return: #TRUE if @popover is modal
276 	 *
277 	 * Since: 3.12
278 	 */
279 	public bool getModal()
280 	{
281 		return gtk_popover_get_modal(gtkPopover) != 0;
282 	}
283 
284 	/**
285 	 * If a rectangle to point to has been set, this function will
286 	 * return %TRUE and fill in @rect with such rectangle, otherwise
287 	 * it will return %FALSE and fill in @rect with the attached
288 	 * widget coordinates.
289 	 *
290 	 * Params:
291 	 *     rect = location to store the rectangle
292 	 *
293 	 * Return: %TRUE if a rectangle to point to was set.
294 	 */
295 	public bool getPointingTo(out GdkRectangle rect)
296 	{
297 		return gtk_popover_get_pointing_to(gtkPopover, &rect) != 0;
298 	}
299 
300 	/**
301 	 * Returns the preferred position of @popover.
302 	 *
303 	 * Return: The preferred position.
304 	 */
305 	public GtkPositionType getPosition()
306 	{
307 		return gtk_popover_get_position(gtkPopover);
308 	}
309 
310 	/**
311 	 * Returns the widget @popover is currently attached to
312 	 *
313 	 * Return: a #GtkWidget
314 	 *
315 	 * Since: 3.12
316 	 */
317 	public Widget getRelativeTo()
318 	{
319 		auto p = gtk_popover_get_relative_to(gtkPopover);
320 		
321 		if(p is null)
322 		{
323 			return null;
324 		}
325 		
326 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
327 	}
328 
329 	/**
330 	 * Returns whether show/hide transitions are enabled on this popover.
331 	 *
332 	 * Return: #TRUE if the show and hide transitions of the given
333 	 *     popover are enabled, #FALSE otherwise.
334 	 *
335 	 * Since: 3.16
336 	 */
337 	public bool getTransitionsEnabled()
338 	{
339 		return gtk_popover_get_transitions_enabled(gtkPopover) != 0;
340 	}
341 
342 	/**
343 	 * Sets a constraint for positioning this popover.
344 	 *
345 	 * Note that not all platforms support placing popovers freely,
346 	 * and may already impose constraints.
347 	 *
348 	 * Params:
349 	 *     constraint = the new constraint
350 	 *
351 	 * Since: 3.20
352 	 */
353 	public void setConstrainTo(GtkPopoverConstraint constraint)
354 	{
355 		gtk_popover_set_constrain_to(gtkPopover, constraint);
356 	}
357 
358 	/**
359 	 * Sets the widget that should be set as default widget while
360 	 * the popover is shown (see gtk_window_set_default()). #GtkPopover
361 	 * remembers the previous default widget and reestablishes it
362 	 * when the popover is dismissed.
363 	 *
364 	 * Params:
365 	 *     widget = the new default widget, or %NULL
366 	 *
367 	 * Since: 3.18
368 	 */
369 	public void setDefaultWidget(Widget widget)
370 	{
371 		gtk_popover_set_default_widget(gtkPopover, (widget is null) ? null : widget.getWidgetStruct());
372 	}
373 
374 	/**
375 	 * Sets whether @popover is modal, a modal popover will grab all input
376 	 * within the toplevel and grab the keyboard focus on it when being
377 	 * displayed. Clicking outside the popover area or pressing Esc will
378 	 * dismiss the popover and ungrab input.
379 	 *
380 	 * Params:
381 	 *     modal = #TRUE to make popover claim all input within the toplevel
382 	 *
383 	 * Since: 3.12
384 	 */
385 	public void setModal(bool modal)
386 	{
387 		gtk_popover_set_modal(gtkPopover, modal);
388 	}
389 
390 	/**
391 	 * Sets the rectangle that @popover will point to, in the
392 	 * coordinate space of the widget @popover is attached to,
393 	 * see gtk_popover_set_relative_to().
394 	 *
395 	 * Params:
396 	 *     rect = rectangle to point to
397 	 *
398 	 * Since: 3.12
399 	 */
400 	public void setPointingTo(GdkRectangle* rect)
401 	{
402 		gtk_popover_set_pointing_to(gtkPopover, rect);
403 	}
404 
405 	/**
406 	 * Sets the preferred position for @popover to appear. If the @popover
407 	 * is currently visible, it will be immediately updated.
408 	 *
409 	 * This preference will be respected where possible, although
410 	 * on lack of space (eg. if close to the window edges), the
411 	 * #GtkPopover may choose to appear on the opposite side
412 	 *
413 	 * Params:
414 	 *     position = preferred popover position
415 	 *
416 	 * Since: 3.12
417 	 */
418 	public void setPosition(GtkPositionType position)
419 	{
420 		gtk_popover_set_position(gtkPopover, position);
421 	}
422 
423 	/**
424 	 * Sets a new widget to be attached to @popover. If @popover is
425 	 * visible, the position will be updated.
426 	 *
427 	 * Note: the ownership of popovers is always given to their @relative_to
428 	 * widget, so if @relative_to is set to %NULL on an attached @popover, it
429 	 * will be detached from its previous widget, and consequently destroyed
430 	 * unless extra references are kept.
431 	 *
432 	 * Params:
433 	 *     relativeTo = a #GtkWidget
434 	 *
435 	 * Since: 3.12
436 	 */
437 	public void setRelativeTo(Widget relativeTo)
438 	{
439 		gtk_popover_set_relative_to(gtkPopover, (relativeTo is null) ? null : relativeTo.getWidgetStruct());
440 	}
441 
442 	/**
443 	 * Sets whether show/hide transitions are enabled on this popover
444 	 *
445 	 * Params:
446 	 *     transitionsEnabled = Whether transitions are enabled
447 	 *
448 	 * Since: 3.16
449 	 */
450 	public void setTransitionsEnabled(bool transitionsEnabled)
451 	{
452 		gtk_popover_set_transitions_enabled(gtkPopover, transitionsEnabled);
453 	}
454 
455 	int[string] connectedSignals;
456 
457 	void delegate(Popover)[] onClosedListeners;
458 	/** */
459 	void addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
460 	{
461 		if ( "closed" !in connectedSignals )
462 		{
463 			Signals.connectData(
464 				this,
465 				"closed",
466 				cast(GCallback)&callBackClosed,
467 				cast(void*)this,
468 				null,
469 				connectFlags);
470 			connectedSignals["closed"] = 1;
471 		}
472 		onClosedListeners ~= dlg;
473 	}
474 	extern(C) static void callBackClosed(GtkPopover* popoverStruct, Popover _popover)
475 	{
476 		foreach ( void delegate(Popover) dlg; _popover.onClosedListeners )
477 		{
478 			dlg(_popover);
479 		}
480 	}
481 }