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