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 glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.NativeIF; 31 private import gtk.NativeT; 32 private import gtk.ShortcutManagerIF; 33 private import gtk.ShortcutManagerT; 34 private import gtk.Widget; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 private import std.algorithm; 38 39 40 /** 41 * `GtkPopover` is a bubble-like context popup. 42 * 43 * ![An example GtkPopover](popover.png) 44 * 45 * It is primarily meant to provide context-dependent information 46 * or options. Popovers are attached to a parent widget. By default, 47 * they point to the whole widget area, although this behavior can be 48 * changed with [method@Gtk.Popover.set_pointing_to]. 49 * 50 * The position of a popover relative to the widget it is attached to 51 * can also be changed with [method@Gtk.Popover.set_position] 52 * 53 * By default, `GtkPopover` performs a grab, in order to ensure input 54 * events get redirected to it while it is shown, and also so the popover 55 * is dismissed in the expected situations (clicks outside the popover, 56 * or the Escape key being pressed). If no such modal behavior is desired 57 * on a popover, [method@Gtk.Popover.set_autohide] may be called on it to 58 * tweak its behavior. 59 * 60 * ## GtkPopover as menu replacement 61 * 62 * `GtkPopover` is often used to replace menus. The best was to do this 63 * is to use the [class@Gtk.PopoverMenu] subclass which supports being 64 * populated from a `GMenuModel` with [ctor@Gtk.PopoverMenu.new_from_model]. 65 * 66 * ```xml 67 * <section> 68 * <attribute name="display-hint">horizontal-buttons</attribute> 69 * <item> 70 * <attribute name="label">Cut</attribute> 71 * <attribute name="action">app.cut</attribute> 72 * <attribute name="verb-icon">edit-cut-symbolic</attribute> 73 * </item> 74 * <item> 75 * <attribute name="label">Copy</attribute> 76 * <attribute name="action">app.copy</attribute> 77 * <attribute name="verb-icon">edit-copy-symbolic</attribute> 78 * </item> 79 * <item> 80 * <attribute name="label">Paste</attribute> 81 * <attribute name="action">app.paste</attribute> 82 * <attribute name="verb-icon">edit-paste-symbolic</attribute> 83 * </item> 84 * </section> 85 * ``` 86 * 87 * # CSS nodes 88 * 89 * ``` 90 * popover[.menu] 91 * ├── arrow 92 * ╰── contents.background 93 * ╰── <child> 94 * ``` 95 * 96 * The contents child node always gets the .background style class 97 * and the popover itself gets the .menu style class if the popover 98 * is menu-like (i.e. `GtkPopoverMenu`). 99 * 100 * Particular uses of `GtkPopover`, such as touch selection popups or 101 * magnifiers in `GtkEntry` or `GtkTextView` get style classes like 102 * .touch-selection or .magnifier to differentiate from plain popovers. 103 * 104 * When styling a popover directly, the popover node should usually 105 * not have any background. The visible part of the popover can have 106 * a shadow. To specify it in CSS, set the box-shadow of the contents node. 107 * 108 * Note that, in order to accomplish appropriate arrow visuals, `GtkPopover` 109 * uses custom drawing for the arrow node. This makes it possible for the 110 * arrow to change its shape dynamically, but it also limits the possibilities 111 * of styling it using CSS. In particular, the arrow gets drawn over the 112 * content node's border and shadow, so they look like one shape, which 113 * means that the border width of the content node and the arrow node should 114 * be the same. The arrow also does not support any border shape other than 115 * solid, no border-radius, only one border width (border-bottom-width is 116 * used) and no box-shadow. 117 */ 118 public class Popover : Widget, NativeIF, ShortcutManagerIF 119 { 120 /** the main Gtk struct */ 121 protected GtkPopover* gtkPopover; 122 123 /** Get the main Gtk struct */ 124 public GtkPopover* getPopoverStruct(bool transferOwnership = false) 125 { 126 if (transferOwnership) 127 ownedRef = false; 128 return gtkPopover; 129 } 130 131 /** the main Gtk struct as a void* */ 132 protected override void* getStruct() 133 { 134 return cast(void*)gtkPopover; 135 } 136 137 /** 138 * Sets our main struct and passes it to the parent class. 139 */ 140 public this (GtkPopover* gtkPopover, bool ownedRef = false) 141 { 142 this.gtkPopover = gtkPopover; 143 super(cast(GtkWidget*)gtkPopover, ownedRef); 144 } 145 146 // add the Native capabilities 147 mixin NativeT!(GtkPopover); 148 149 // add the ShortcutManager capabilities 150 mixin ShortcutManagerT!(GtkPopover); 151 152 153 /** */ 154 public static GType getType() 155 { 156 return gtk_popover_get_type(); 157 } 158 159 /** 160 * Creates a new `GtkPopover`. 161 * 162 * Returns: the new `GtkPopover` 163 * 164 * Throws: ConstructionException GTK+ fails to create the object. 165 */ 166 public this() 167 { 168 auto __p = gtk_popover_new(); 169 170 if(__p is null) 171 { 172 throw new ConstructionException("null returned by new"); 173 } 174 175 this(cast(GtkPopover*) __p); 176 } 177 178 /** 179 * Returns whether the popover is modal. 180 * 181 * See [method@Gtk.Popover.set_autohide] for the 182 * implications of this. 183 * 184 * Returns: %TRUE if @popover is modal 185 */ 186 public bool getAutohide() 187 { 188 return gtk_popover_get_autohide(gtkPopover) != 0; 189 } 190 191 /** 192 * Returns whether the popover will close after a modal child is closed. 193 * 194 * Returns: %TRUE if @popover will close after a modal child. 195 */ 196 public bool getCascadePopdown() 197 { 198 return gtk_popover_get_cascade_popdown(gtkPopover) != 0; 199 } 200 201 /** 202 * Gets the child widget of @popover. 203 * 204 * Returns: the child widget of @popover 205 */ 206 public Widget getChild() 207 { 208 auto __p = gtk_popover_get_child(gtkPopover); 209 210 if(__p is null) 211 { 212 return null; 213 } 214 215 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 216 } 217 218 /** 219 * Gets whether this popover is showing an arrow 220 * pointing at the widget that it is relative to. 221 * 222 * Returns: whether the popover has an arrow 223 */ 224 public bool getHasArrow() 225 { 226 return gtk_popover_get_has_arrow(gtkPopover) != 0; 227 } 228 229 /** 230 * Gets whether mnemonics are visible. 231 * 232 * Returns: %TRUE if mnemonics are supposed to be visible 233 * in this popover 234 */ 235 public bool getMnemonicsVisible() 236 { 237 return gtk_popover_get_mnemonics_visible(gtkPopover) != 0; 238 } 239 240 /** 241 * Gets the offset previous set with gtk_popover_set_offset(). 242 * 243 * Params: 244 * xOffset = a location for the x_offset 245 * yOffset = a location for the y_offset 246 */ 247 public void getOffset(out int xOffset, out int yOffset) 248 { 249 gtk_popover_get_offset(gtkPopover, &xOffset, &yOffset); 250 } 251 252 /** 253 * Gets the rectangle that the popover points to. 254 * 255 * If a rectangle to point to has been set, this function will 256 * return %TRUE and fill in @rect with such rectangle, otherwise 257 * it will return %FALSE and fill in @rect with the parent 258 * widget coordinates. 259 * 260 * Params: 261 * rect = location to store the rectangle 262 * 263 * Returns: %TRUE if a rectangle to point to was set. 264 */ 265 public bool getPointingTo(out GdkRectangle rect) 266 { 267 return gtk_popover_get_pointing_to(gtkPopover, &rect) != 0; 268 } 269 270 /** 271 * Returns the preferred position of @popover. 272 * 273 * Returns: The preferred position. 274 */ 275 public GtkPositionType getPosition() 276 { 277 return gtk_popover_get_position(gtkPopover); 278 } 279 280 /** 281 * Pops @popover down. 282 * 283 * This is different from a [method@Gtk.Widget.hide] call 284 * in that it may show the popover with a transition. If 285 * you want to hide the popover without a transition, just 286 * use [method@Gtk.Widget.hide]. 287 */ 288 public void popdown() 289 { 290 gtk_popover_popdown(gtkPopover); 291 } 292 293 /** 294 * Pops @popover up. 295 * 296 * This is different from a [method@Gtk.Widget.show() call 297 * in that it may show the popover with a transition. If 298 * you want to show the popover without a transition, just 299 * use [method@Gtk.Widget.show]. 300 */ 301 public void popup() 302 { 303 gtk_popover_popup(gtkPopover); 304 } 305 306 /** 307 * Presents the popover to the user. 308 */ 309 public void present() 310 { 311 gtk_popover_present(gtkPopover); 312 } 313 314 /** 315 * Sets whether @popover is modal. 316 * 317 * A modal popover will grab the keyboard focus on it when being 318 * displayed. Clicking outside the popover area or pressing Esc 319 * will dismiss the popover. 320 * 321 * Called this function on an already showing popup with a new 322 * autohide value different from the current one, will cause the 323 * popup to be hidden. 324 * 325 * Params: 326 * autohide = %TRUE to dismiss the popover on outside clicks 327 */ 328 public void setAutohide(bool autohide) 329 { 330 gtk_popover_set_autohide(gtkPopover, autohide); 331 } 332 333 /** 334 * If @cascade_popdown is %TRUE, the popover will be 335 * closed when a child modal popover is closed. 336 * 337 * If %FALSE, @popover will stay visible. 338 * 339 * Params: 340 * cascadePopdown = %TRUE if the popover should follow a child closing 341 */ 342 public void setCascadePopdown(bool cascadePopdown) 343 { 344 gtk_popover_set_cascade_popdown(gtkPopover, cascadePopdown); 345 } 346 347 /** 348 * Sets the child widget of @popover. 349 * 350 * Params: 351 * child = the child widget 352 */ 353 public void setChild(Widget child) 354 { 355 gtk_popover_set_child(gtkPopover, (child is null) ? null : child.getWidgetStruct()); 356 } 357 358 /** 359 * Sets the default widget of a `GtkPopover`. 360 * 361 * The default widget is the widget that’s activated when the user 362 * presses Enter in a dialog (for example). This function sets or 363 * unsets the default widget for a `GtkPopover`. 364 * 365 * Params: 366 * widget = a child widget of @popover to set as 367 * the default, or %NULL to unset the default widget for the popover 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 this popover should draw an arrow 376 * pointing at the widget it is relative to. 377 * 378 * Params: 379 * hasArrow = %TRUE to draw an arrow 380 */ 381 public void setHasArrow(bool hasArrow) 382 { 383 gtk_popover_set_has_arrow(gtkPopover, hasArrow); 384 } 385 386 /** 387 * Sets whether mnemonics should be visible. 388 * 389 * Params: 390 * mnemonicsVisible = the new value 391 */ 392 public void setMnemonicsVisible(bool mnemonicsVisible) 393 { 394 gtk_popover_set_mnemonics_visible(gtkPopover, mnemonicsVisible); 395 } 396 397 /** 398 * Sets the offset to use when calculating the position 399 * of the popover. 400 * 401 * These values are used when preparing the [struct@Gdk.PopupLayout] 402 * for positioning the popover. 403 * 404 * Params: 405 * xOffset = the x offset to adjust the position by 406 * yOffset = the y offset to adjust the position by 407 */ 408 public void setOffset(int xOffset, int yOffset) 409 { 410 gtk_popover_set_offset(gtkPopover, xOffset, yOffset); 411 } 412 413 /** 414 * Sets the rectangle that @popover points to. 415 * 416 * This is in the coordinate space of the @popover parent. 417 * 418 * Params: 419 * rect = rectangle to point to 420 */ 421 public void setPointingTo(GdkRectangle* rect) 422 { 423 gtk_popover_set_pointing_to(gtkPopover, rect); 424 } 425 426 /** 427 * Sets the preferred position for @popover to appear. 428 * 429 * If the @popover is currently visible, it will be immediately 430 * updated. 431 * 432 * This preference will be respected where possible, although 433 * on lack of space (eg. if close to the window edges), the 434 * `GtkPopover` may choose to appear on the opposite side. 435 * 436 * Params: 437 * position = preferred popover position 438 */ 439 public void setPosition(GtkPositionType position) 440 { 441 gtk_popover_set_position(gtkPopover, position); 442 } 443 444 /** 445 * Emitted whend the user activates the default widget. 446 * 447 * This is a [keybinding signal](class.SignalAction.html). 448 */ 449 gulong addOnActivateDefault(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 450 { 451 return Signals.connect(this, "activate-default", dlg, connectFlags ^ ConnectFlags.SWAPPED); 452 } 453 454 /** 455 * Emitted when the popover is closed. 456 */ 457 gulong addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 458 { 459 return Signals.connect(this, "closed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 460 } 461 }