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