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 126 public static GType getType() 127 { 128 return gtk_popover_get_type(); 129 } 130 131 /** 132 * Creates a new popover to point to @relative_to 133 * 134 * Params: 135 * relativeTo = #GtkWidget the popover is related to 136 * 137 * Return: a new #GtkPopover 138 * 139 * Since: 3.12 140 * 141 * Throws: ConstructionException GTK+ fails to create the object. 142 */ 143 public this(Widget relativeTo) 144 { 145 auto p = gtk_popover_new((relativeTo is null) ? null : relativeTo.getWidgetStruct()); 146 147 if(p is null) 148 { 149 throw new ConstructionException("null returned by new"); 150 } 151 152 this(cast(GtkPopover*) p); 153 } 154 155 /** 156 * Creates a #GtkPopover and populates it according to 157 * @model. The popover is pointed to the @relative_to widget. 158 * 159 * The created buttons are connected to actions found in the 160 * #GtkApplicationWindow to which the popover belongs - typically 161 * by means of being attached to a widget that is contained within 162 * the #GtkApplicationWindows widget hierarchy. 163 * 164 * Actions can also be added using gtk_widget_insert_action_group() 165 * on the menus attach widget or on any of its parent widgets. 166 * 167 * Params: 168 * relativeTo = #GtkWidget the popover is related to 169 * model = a #GMenuModel 170 * 171 * Return: the new #GtkPopover 172 * 173 * Since: 3.12 174 * 175 * Throws: ConstructionException GTK+ fails to create the object. 176 */ 177 public this(Widget relativeTo, MenuModel model) 178 { 179 auto p = gtk_popover_new_from_model((relativeTo is null) ? null : relativeTo.getWidgetStruct(), (model is null) ? null : model.getMenuModelStruct()); 180 181 if(p is null) 182 { 183 throw new ConstructionException("null returned by new_from_model"); 184 } 185 186 this(cast(GtkPopover*) p); 187 } 188 189 /** 190 * Establishes a binding between a #GtkPopover and a #GMenuModel. 191 * 192 * The contents of @popover are removed and then refilled with menu items 193 * according to @model. When @model changes, @popover is updated. 194 * Calling this function twice on @popover with different @model will 195 * cause the first binding to be replaced with a binding to the new 196 * model. If @model is %NULL then any previous binding is undone and 197 * all children are removed. 198 * 199 * If @action_namespace is non-%NULL then the effect is as if all 200 * actions mentioned in the @model have their names prefixed with the 201 * namespace, plus a dot. For example, if the action “quit” is 202 * mentioned and @action_namespace is “app” then the effective action 203 * name is “app.quit”. 204 * 205 * This function uses #GtkActionable to define the action name and 206 * target values on the created menu items. If you want to use an 207 * action group other than “app” and “win”, or if you want to use a 208 * #GtkMenuShell outside of a #GtkApplicationWindow, then you will need 209 * to attach your own action group to the widget hierarchy using 210 * gtk_widget_insert_action_group(). As an example, if you created a 211 * group with a “quit” action and inserted it with the name “mygroup” 212 * then you would use the action name “mygroup.quit” in your 213 * #GMenuModel. 214 * 215 * Params: 216 * model = the #GMenuModel to bind to or %NULL to remove 217 * binding 218 * actionNamespace = the namespace for actions in @model 219 * 220 * Since: 3.12 221 */ 222 public void bindModel(MenuModel model, string actionNamespace) 223 { 224 gtk_popover_bind_model(gtkPopover, (model is null) ? null : model.getMenuModelStruct(), Str.toStringz(actionNamespace)); 225 } 226 227 /** 228 * Returns whether the popover is modal, see gtk_popover_set_modal to 229 * see the implications of this. 230 * 231 * Return: #TRUE if @popover is modal 232 * 233 * Since: 3.12 234 */ 235 public bool getModal() 236 { 237 return gtk_popover_get_modal(gtkPopover) != 0; 238 } 239 240 /** 241 * If a rectangle to point to has been set, this function will 242 * return %TRUE and fill in @rect with such rectangle, otherwise 243 * it will return %FALSE and fill in @rect with the attached 244 * widget coordinates. 245 * 246 * Params: 247 * rect = location to store the rectangle 248 * 249 * Return: %TRUE if a rectangle to point to was set. 250 */ 251 public bool getPointingTo(out GdkRectangle rect) 252 { 253 return gtk_popover_get_pointing_to(gtkPopover, &rect) != 0; 254 } 255 256 /** 257 * Returns the preferred position of @popover. 258 * 259 * Return: The preferred position. 260 */ 261 public GtkPositionType getPosition() 262 { 263 return gtk_popover_get_position(gtkPopover); 264 } 265 266 /** 267 * Returns the widget @popover is currently attached to 268 * 269 * Return: a #GtkWidget 270 * 271 * Since: 3.12 272 */ 273 public Widget getRelativeTo() 274 { 275 auto p = gtk_popover_get_relative_to(gtkPopover); 276 277 if(p is null) 278 { 279 return null; 280 } 281 282 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 283 } 284 285 /** 286 * Returns whether show/hide transitions are enabled on this popover. 287 * 288 * Return: #TRUE if the show and hide transitions of the given 289 * popover are enabled, #FALSE otherwise. 290 * 291 * Since: 3.16 292 */ 293 public bool getTransitionsEnabled() 294 { 295 return gtk_popover_get_transitions_enabled(gtkPopover) != 0; 296 } 297 298 /** 299 * Sets whether @popover is modal, a modal popover will grab all input 300 * within the toplevel and grab the keyboard focus on it when being 301 * displayed. Clicking outside the popover area or pressing Esc will 302 * dismiss the popover and ungrab input. 303 * 304 * Params: 305 * modal = #TRUE to make popover claim all input within the toplevel 306 * 307 * Since: 3.12 308 */ 309 public void setModal(bool modal) 310 { 311 gtk_popover_set_modal(gtkPopover, modal); 312 } 313 314 /** 315 * Sets the rectangle that @popover will point to, in the 316 * coordinate space of the widget @popover is attached to, 317 * see gtk_popover_set_relative_to(). 318 * 319 * Params: 320 * rect = rectangle to point to 321 * 322 * Since: 3.12 323 */ 324 public void setPointingTo(GdkRectangle* rect) 325 { 326 gtk_popover_set_pointing_to(gtkPopover, rect); 327 } 328 329 /** 330 * Sets the preferred position for @popover to appear. If the @popover 331 * is currently visible, it will be immediately updated. 332 * 333 * This preference will be respected where possible, although 334 * on lack of space (eg. if close to the window edges), the 335 * #GtkPopover may choose to appear on the opposite side 336 * 337 * Params: 338 * position = preferred popover position 339 * 340 * Since: 3.12 341 */ 342 public void setPosition(GtkPositionType position) 343 { 344 gtk_popover_set_position(gtkPopover, position); 345 } 346 347 /** 348 * Sets a new widget to be attached to @popover. If @popover is 349 * visible, the position will be updated. 350 * 351 * Note: the ownership of popovers is always given to their @relative_to 352 * widget, so if @relative_to is set to %NULL on an attached @popover, it 353 * will be detached from its previous widget, and consequently destroyed 354 * unless extra references are kept. 355 * 356 * Params: 357 * relativeTo = a #GtkWidget 358 * 359 * Since: 3.12 360 */ 361 public void setRelativeTo(Widget relativeTo) 362 { 363 gtk_popover_set_relative_to(gtkPopover, (relativeTo is null) ? null : relativeTo.getWidgetStruct()); 364 } 365 366 /** 367 * Sets whether show/hide transitions are enabled on this popover 368 * 369 * Params: 370 * transitionsEnabled = Whether transitions are enabled 371 * 372 * Since: 3.16 373 */ 374 public void setTransitionsEnabled(bool transitionsEnabled) 375 { 376 gtk_popover_set_transitions_enabled(gtkPopover, transitionsEnabled); 377 } 378 379 int[string] connectedSignals; 380 381 void delegate(Popover)[] onClosedListeners; 382 void addOnClosed(void delegate(Popover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 383 { 384 if ( "closed" !in connectedSignals ) 385 { 386 Signals.connectData( 387 this, 388 "closed", 389 cast(GCallback)&callBackClosed, 390 cast(void*)this, 391 null, 392 connectFlags); 393 connectedSignals["closed"] = 1; 394 } 395 onClosedListeners ~= dlg; 396 } 397 extern(C) static void callBackClosed(GtkPopover* popoverStruct, Popover _popover) 398 { 399 foreach ( void delegate(Popover) dlg; _popover.onClosedListeners ) 400 { 401 dlg(_popover); 402 } 403 } 404 }