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