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() 130 { 131 return gtkMenuButton; 132 } 133 134 /** the main Gtk struct as a void* */ 135 protected override void* getStruct() 136 { 137 return cast(void*)gtkMenuButton; 138 } 139 140 protected override void setStruct(GObject* obj) 141 { 142 gtkMenuButton = cast(GtkMenuButton*)obj; 143 super.setStruct(obj); 144 } 145 146 /** 147 * Sets our main struct and passes it to the parent class. 148 */ 149 public this (GtkMenuButton* gtkMenuButton, bool ownedRef = false) 150 { 151 this.gtkMenuButton = gtkMenuButton; 152 super(cast(GtkToggleButton*)gtkMenuButton, ownedRef); 153 } 154 155 156 /** */ 157 public static GType getType() 158 { 159 return gtk_menu_button_get_type(); 160 } 161 162 /** 163 * Creates a new #GtkMenuButton widget with downwards-pointing 164 * arrow as the only child. You can replace the child widget 165 * with another #GtkWidget should you wish to. 166 * 167 * Return: The newly created #GtkMenuButton widget 168 * 169 * Since: 3.6 170 * 171 * Throws: ConstructionException GTK+ fails to create the object. 172 */ 173 public this() 174 { 175 auto p = gtk_menu_button_new(); 176 177 if(p is null) 178 { 179 throw new ConstructionException("null returned by new"); 180 } 181 182 this(cast(GtkMenuButton*) p); 183 } 184 185 /** 186 * Returns the parent #GtkWidget to use to line up with menu. 187 * 188 * Return: a #GtkWidget value or %NULL 189 * 190 * Since: 3.6 191 */ 192 public Widget getAlignWidget() 193 { 194 auto p = gtk_menu_button_get_align_widget(gtkMenuButton); 195 196 if(p is null) 197 { 198 return null; 199 } 200 201 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 202 } 203 204 /** 205 * Returns the direction the popup will be pointing at when popped up. 206 * 207 * Return: a #GtkArrowType value 208 * 209 * Since: 3.6 210 */ 211 public GtkArrowType getMenuDirection() 212 { 213 return gtk_menu_button_get_direction(gtkMenuButton); 214 } 215 216 /** 217 * Returns the #GMenuModel used to generate the popup. 218 * 219 * Return: a #GMenuModel or %NULL 220 * 221 * Since: 3.6 222 */ 223 public MenuModel getMenuModel() 224 { 225 auto p = gtk_menu_button_get_menu_model(gtkMenuButton); 226 227 if(p is null) 228 { 229 return null; 230 } 231 232 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p); 233 } 234 235 /** 236 * Returns the #GtkPopover that pops out of the button. 237 * If the button is not using a #GtkPopover, this function 238 * returns %NULL. 239 * 240 * Return: a #GtkPopover or %NULL 241 * 242 * Since: 3.12 243 */ 244 public Popover getPopover() 245 { 246 auto p = gtk_menu_button_get_popover(gtkMenuButton); 247 248 if(p is null) 249 { 250 return null; 251 } 252 253 return ObjectG.getDObject!(Popover)(cast(GtkPopover*) p); 254 } 255 256 /** 257 * Returns the #GtkMenu that pops out of the button. 258 * If the button does not use a #GtkMenu, this function 259 * returns %NULL. 260 * 261 * Return: a #GtkMenu or %NULL 262 * 263 * Since: 3.6 264 */ 265 public Menu getPopup() 266 { 267 auto p = gtk_menu_button_get_popup(gtkMenuButton); 268 269 if(p is null) 270 { 271 return null; 272 } 273 274 return ObjectG.getDObject!(Menu)(cast(GtkMenu*) p); 275 } 276 277 /** 278 * Returns whether a #GtkPopover or a #GtkMenu will be constructed 279 * from the menu model. 280 * 281 * Return: %TRUE if using a #GtkPopover 282 * 283 * Since: 3.12 284 */ 285 public bool getUsePopover() 286 { 287 return gtk_menu_button_get_use_popover(gtkMenuButton) != 0; 288 } 289 290 /** 291 * Sets the #GtkWidget to use to line the menu with when popped up. 292 * Note that the @align_widget must contain the #GtkMenuButton itself. 293 * 294 * Setting it to %NULL means that the menu will be aligned with the 295 * button itself. 296 * 297 * Note that this property is only used with menus currently, 298 * and not for popovers. 299 * 300 * Params: 301 * alignWidget = a #GtkWidget 302 * 303 * Since: 3.6 304 */ 305 public void setAlignWidget(Widget alignWidget) 306 { 307 gtk_menu_button_set_align_widget(gtkMenuButton, (alignWidget is null) ? null : alignWidget.getWidgetStruct()); 308 } 309 310 /** 311 * Sets the direction in which the popup will be popped up, as 312 * well as changing the arrow’s direction. The child will not 313 * be changed to an arrow if it was customized. 314 * 315 * If the does not fit in the available space in the given direction, 316 * GTK+ will its best to keep it inside the screen and fully visible. 317 * 318 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave 319 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows). 320 * 321 * Params: 322 * direction = a #GtkArrowType 323 * 324 * Since: 3.6 325 */ 326 public void setMenuDirection(GtkArrowType direction) 327 { 328 gtk_menu_button_set_direction(gtkMenuButton, direction); 329 } 330 331 /** 332 * Sets the #GMenuModel from which the popup will be constructed, 333 * or %NULL to disable the button. 334 * 335 * Depending on the value of #GtkMenuButton:use-popover, either a 336 * #GtkMenu will be created with gtk_menu_new_from_model(), or a 337 * #GtkPopover with gtk_popover_new_from_model(). In either case, 338 * actions will be connected as documented for these functions. 339 * 340 * If #GtkMenuButton:popup or #GtkMenuButton:popover are already set, 341 * their content will be lost and replaced by the newly created popup. 342 * 343 * Params: 344 * menuModel = a #GMenuModel 345 * 346 * Since: 3.6 347 */ 348 public void setMenuModel(MenuModel menuModel) 349 { 350 gtk_menu_button_set_menu_model(gtkMenuButton, (menuModel is null) ? null : menuModel.getMenuModelStruct()); 351 } 352 353 /** 354 * Sets the #GtkPopover that will be popped up when the button is 355 * clicked, or %NULL to disable the button. If #GtkMenuButton:menu-model 356 * or #GtkMenuButton:popup are set, they will be set to %NULL. 357 * 358 * Params: 359 * popover = a #GtkPopover 360 * 361 * Since: 3.12 362 */ 363 public void setPopover(Widget popover) 364 { 365 gtk_menu_button_set_popover(gtkMenuButton, (popover is null) ? null : popover.getWidgetStruct()); 366 } 367 368 /** 369 * Sets the #GtkMenu that will be popped up when the button is clicked, 370 * or %NULL to disable the button. If #GtkMenuButton:menu-model or 371 * #GtkMenuButton:popover are set, they will be set to %NULL. 372 * 373 * Params: 374 * menu = a #GtkMenu 375 * 376 * Since: 3.6 377 */ 378 public void setPopup(Widget menu) 379 { 380 gtk_menu_button_set_popup(gtkMenuButton, (menu is null) ? null : menu.getWidgetStruct()); 381 } 382 383 /** 384 * Sets whether to construct a #GtkPopover instead of #GtkMenu 385 * when gtk_menu_button_set_menu_model() is called. Note that 386 * this property is only consulted when a new menu model is set. 387 * 388 * Params: 389 * usePopover = %TRUE to construct a popover from the menu model 390 * 391 * Since: 3.12 392 */ 393 public void setUsePopover(bool usePopover) 394 { 395 gtk_menu_button_set_use_popover(gtkMenuButton, usePopover); 396 } 397 }