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.MenuButton; 26 27 private import gio.MenuModel; 28 private import glib.ConstructionException; 29 private import gobject.ObjectG; 30 private import gtk.Menu; 31 private import gtk.Popover; 32 private import gtk.ToggleButton; 33 private import gtk.Widget; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 37 38 /** 39 * The #GtkMenuButton widget is used to display a popup when clicked on. 40 * This popup can be provided either as a #GtkMenu, a #GtkPopover or an 41 * abstract #GMenuModel. 42 * 43 * The #GtkMenuButton widget can hold any valid child widget. That is, it 44 * can hold almost any other standard #GtkWidget. The most commonly used 45 * child is #GtkImage. If no widget is explicitely added to the #GtkMenuButton, 46 * a #GtkImage is automatically created, using an arrow image oriented 47 * according to #GtkMenuButton:direction or the generic "view-context-menu" 48 * icon if the direction is not set. 49 * 50 * The positioning of the popup is determined by the #GtkMenuButton:direction 51 * property of the menu button. 52 * 53 * For menus, the #GtkWidget:halign and #GtkWidget:valign properties of the 54 * menu are also taken into account. For example, when the direction is 55 * %GTK_ARROW_DOWN and the horizontal alignment is %GTK_ALIGN_START, the 56 * menu will be positioned below the button, with the starting edge 57 * (depending on the text direction) of the menu aligned with the starting 58 * edge of the button. If there is not enough space below the button, the 59 * menu is popped up above the button instead. If the alignment would move 60 * part of the menu offscreen, it is “pushed in”. 61 * 62 * ## Direction = Down 63 * 64 * - halign = start 65 * 66 * ![](down-start.png) 67 * 68 * - halign = center 69 * 70 * ![](down-center.png) 71 * 72 * - halign = end 73 * 74 * ![](down-end.png) 75 * 76 * ## Direction = Up 77 * 78 * - halign = start 79 * 80 * ![](up-start.png) 81 * 82 * - halign = center 83 * 84 * ![](up-center.png) 85 * 86 * - halign = end 87 * 88 * ![](up-end.png) 89 * 90 * ## Direction = Left 91 * 92 * - valign = start 93 * 94 * ![](left-start.png) 95 * 96 * - valign = center 97 * 98 * ![](left-center.png) 99 * 100 * - valign = end 101 * 102 * ![](left-end.png) 103 * 104 * ## Direction = Right 105 * 106 * - valign = start 107 * 108 * ![](right-start.png) 109 * 110 * - valign = center 111 * 112 * ![](right-center.png) 113 * 114 * - valign = end 115 * 116 * ![](right-end.png) 117 * 118 * # CSS nodes 119 * 120 * GtkMenuButton has a single CSS node with name button. To differentiate 121 * it from a plain #GtkButton, it gets the .popup style class. 122 */ 123 public class MenuButton : ToggleButton 124 { 125 /** the main Gtk struct */ 126 protected GtkMenuButton* gtkMenuButton; 127 128 /** Get the main Gtk struct */ 129 public GtkMenuButton* getMenuButtonStruct(bool transferOwnership = false) 130 { 131 if (transferOwnership) 132 ownedRef = false; 133 return gtkMenuButton; 134 } 135 136 /** the main Gtk struct as a void* */ 137 protected override void* getStruct() 138 { 139 return cast(void*)gtkMenuButton; 140 } 141 142 protected override void setStruct(GObject* obj) 143 { 144 gtkMenuButton = cast(GtkMenuButton*)obj; 145 super.setStruct(obj); 146 } 147 148 /** 149 * Sets our main struct and passes it to the parent class. 150 */ 151 public this (GtkMenuButton* gtkMenuButton, bool ownedRef = false) 152 { 153 this.gtkMenuButton = gtkMenuButton; 154 super(cast(GtkToggleButton*)gtkMenuButton, ownedRef); 155 } 156 157 158 /** */ 159 public static GType getType() 160 { 161 return gtk_menu_button_get_type(); 162 } 163 164 /** 165 * Creates a new #GtkMenuButton widget with downwards-pointing 166 * arrow as the only child. You can replace the child widget 167 * with another #GtkWidget should you wish to. 168 * 169 * Returns: The newly created #GtkMenuButton widget 170 * 171 * Since: 3.6 172 * 173 * Throws: ConstructionException GTK+ fails to create the object. 174 */ 175 public this() 176 { 177 auto p = gtk_menu_button_new(); 178 179 if(p is null) 180 { 181 throw new ConstructionException("null returned by new"); 182 } 183 184 this(cast(GtkMenuButton*) p); 185 } 186 187 /** 188 * Returns the parent #GtkWidget to use to line up with menu. 189 * 190 * Returns: a #GtkWidget value or %NULL 191 * 192 * Since: 3.6 193 */ 194 public Widget getAlignWidget() 195 { 196 auto p = gtk_menu_button_get_align_widget(gtkMenuButton); 197 198 if(p is null) 199 { 200 return null; 201 } 202 203 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 204 } 205 206 /** 207 * Returns the direction the popup will be pointing at when popped up. 208 * 209 * Returns: a #GtkArrowType value 210 * 211 * Since: 3.6 212 */ 213 public GtkArrowType getMenuDirection() 214 { 215 return gtk_menu_button_get_direction(gtkMenuButton); 216 } 217 218 /** 219 * Returns the #GMenuModel used to generate the popup. 220 * 221 * Returns: a #GMenuModel or %NULL 222 * 223 * Since: 3.6 224 */ 225 public MenuModel getMenuModel() 226 { 227 auto p = gtk_menu_button_get_menu_model(gtkMenuButton); 228 229 if(p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p); 235 } 236 237 /** 238 * Returns the #GtkPopover that pops out of the button. 239 * If the button is not using a #GtkPopover, this function 240 * returns %NULL. 241 * 242 * Returns: a #GtkPopover or %NULL 243 * 244 * Since: 3.12 245 */ 246 public Popover getPopover() 247 { 248 auto p = gtk_menu_button_get_popover(gtkMenuButton); 249 250 if(p is null) 251 { 252 return null; 253 } 254 255 return ObjectG.getDObject!(Popover)(cast(GtkPopover*) p); 256 } 257 258 /** 259 * Returns the #GtkMenu that pops out of the button. 260 * If the button does not use a #GtkMenu, this function 261 * returns %NULL. 262 * 263 * Returns: a #GtkMenu or %NULL 264 * 265 * Since: 3.6 266 */ 267 public Menu getPopup() 268 { 269 auto p = gtk_menu_button_get_popup(gtkMenuButton); 270 271 if(p is null) 272 { 273 return null; 274 } 275 276 return ObjectG.getDObject!(Menu)(cast(GtkMenu*) p); 277 } 278 279 /** 280 * Returns whether a #GtkPopover or a #GtkMenu will be constructed 281 * from the menu model. 282 * 283 * Returns: %TRUE if using a #GtkPopover 284 * 285 * Since: 3.12 286 */ 287 public bool getUsePopover() 288 { 289 return gtk_menu_button_get_use_popover(gtkMenuButton) != 0; 290 } 291 292 /** 293 * Sets the #GtkWidget to use to line the menu with when popped up. 294 * Note that the @align_widget must contain the #GtkMenuButton itself. 295 * 296 * Setting it to %NULL means that the menu will be aligned with the 297 * button itself. 298 * 299 * Note that this property is only used with menus currently, 300 * and not for popovers. 301 * 302 * Params: 303 * alignWidget = a #GtkWidget 304 * 305 * Since: 3.6 306 */ 307 public void setAlignWidget(Widget alignWidget) 308 { 309 gtk_menu_button_set_align_widget(gtkMenuButton, (alignWidget is null) ? null : alignWidget.getWidgetStruct()); 310 } 311 312 /** 313 * Sets the direction in which the popup will be popped up, as 314 * well as changing the arrow’s direction. The child will not 315 * be changed to an arrow if it was customized. 316 * 317 * If the does not fit in the available space in the given direction, 318 * GTK+ will its best to keep it inside the screen and fully visible. 319 * 320 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave 321 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows). 322 * 323 * Params: 324 * direction = a #GtkArrowType 325 * 326 * Since: 3.6 327 */ 328 public void setMenuDirection(GtkArrowType direction) 329 { 330 gtk_menu_button_set_direction(gtkMenuButton, direction); 331 } 332 333 /** 334 * Sets the #GMenuModel from which the popup will be constructed, 335 * or %NULL to disable the button. 336 * 337 * Depending on the value of #GtkMenuButton:use-popover, either a 338 * #GtkMenu will be created with gtk_menu_new_from_model(), or a 339 * #GtkPopover with gtk_popover_new_from_model(). In either case, 340 * actions will be connected as documented for these functions. 341 * 342 * If #GtkMenuButton:popup or #GtkMenuButton:popover are already set, 343 * their content will be lost and replaced by the newly created popup. 344 * 345 * Params: 346 * menuModel = a #GMenuModel 347 * 348 * Since: 3.6 349 */ 350 public void setMenuModel(MenuModel menuModel) 351 { 352 gtk_menu_button_set_menu_model(gtkMenuButton, (menuModel is null) ? null : menuModel.getMenuModelStruct()); 353 } 354 355 /** 356 * Sets the #GtkPopover that will be popped up when the button is 357 * clicked, or %NULL to disable the button. If #GtkMenuButton:menu-model 358 * or #GtkMenuButton:popup are set, they will be set to %NULL. 359 * 360 * Params: 361 * popover = a #GtkPopover 362 * 363 * Since: 3.12 364 */ 365 public void setPopover(Widget popover) 366 { 367 gtk_menu_button_set_popover(gtkMenuButton, (popover is null) ? null : popover.getWidgetStruct()); 368 } 369 370 /** 371 * Sets the #GtkMenu that will be popped up when the button is clicked, 372 * or %NULL to disable the button. If #GtkMenuButton:menu-model or 373 * #GtkMenuButton:popover are set, they will be set to %NULL. 374 * 375 * Params: 376 * menu = a #GtkMenu 377 * 378 * Since: 3.6 379 */ 380 public void setPopup(Widget menu) 381 { 382 gtk_menu_button_set_popup(gtkMenuButton, (menu is null) ? null : menu.getWidgetStruct()); 383 } 384 385 /** 386 * Sets whether to construct a #GtkPopover instead of #GtkMenu 387 * when gtk_menu_button_set_menu_model() is called. Note that 388 * this property is only consulted when a new menu model is set. 389 * 390 * Params: 391 * usePopover = %TRUE to construct a popover from the menu model 392 * 393 * Since: 3.12 394 */ 395 public void setUsePopover(bool usePopover) 396 { 397 gtk_menu_button_set_use_popover(gtkMenuButton, usePopover); 398 } 399 }