1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle 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 * d-dazzle 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 d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.MenuButton; 20 21 private import dazzle.c.functions; 22 public import dazzle.c.types; 23 private import gio.MenuModel; 24 private import glib.ConstructionException; 25 private import glib.Str; 26 private import gobject.ObjectG; 27 private import gtk.ActionableIF; 28 private import gtk.ActionableT; 29 private import gtk.ActivatableIF; 30 private import gtk.ActivatableT; 31 private import gtk.BuildableIF; 32 private import gtk.BuildableT; 33 private import gtk.MenuButton : GtkMenuButtonEx = MenuButton; 34 private import gtk.Widget; 35 36 37 /** */ 38 public class MenuButton : GtkMenuButtonEx 39 { 40 /** the main Gtk struct */ 41 protected DzlMenuButton* dzlMenuButton; 42 43 /** Get the main Gtk struct */ 44 public DzlMenuButton* getDazzleMenuButtonStruct(bool transferOwnership = false) 45 { 46 if (transferOwnership) 47 ownedRef = false; 48 return dzlMenuButton; 49 } 50 51 /** the main Gtk struct as a void* */ 52 protected override void* getStruct() 53 { 54 return cast(void*)dzlMenuButton; 55 } 56 57 /** 58 * Sets our main struct and passes it to the parent class. 59 */ 60 public this (DzlMenuButton* dzlMenuButton, bool ownedRef = false) 61 { 62 this.dzlMenuButton = dzlMenuButton; 63 super(cast(GtkMenuButton*)dzlMenuButton, ownedRef); 64 } 65 66 67 /** */ 68 public static GType getType() 69 { 70 return dzl_menu_button_get_type(); 71 } 72 73 /** 74 * Creates a new #DzlMenuButton with the icon @icon_name and 75 * the menu contents of @model. 76 * 77 * Params: 78 * iconName = An icon-name for the button 79 * model = A #GMenuModel or %NULL 80 * 81 * Returns: A #DzlMenuButton 82 * 83 * Throws: ConstructionException GTK+ fails to create the object. 84 */ 85 public this(string iconName, MenuModel model) 86 { 87 auto p = dzl_menu_button_new_with_model(Str.toStringz(iconName), (model is null) ? null : model.getMenuModelStruct()); 88 89 if(p is null) 90 { 91 throw new ConstructionException("null returned by new_with_model"); 92 } 93 94 this(cast(DzlMenuButton*) p, true); 95 } 96 97 /** 98 * Returns: A #DzlMenuButton or %NULL. 99 * 100 * Since: 3.26 101 */ 102 public MenuModel getModel() 103 { 104 auto p = dzl_menu_button_get_model(dzlMenuButton); 105 106 if(p is null) 107 { 108 return null; 109 } 110 111 return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p); 112 } 113 114 /** */ 115 public bool getShowAccels() 116 { 117 return dzl_menu_button_get_show_accels(dzlMenuButton) != 0; 118 } 119 120 /** */ 121 public bool getShowArrow() 122 { 123 return dzl_menu_button_get_show_arrow(dzlMenuButton) != 0; 124 } 125 126 /** */ 127 public bool getShowIcons() 128 { 129 return dzl_menu_button_get_show_icons(dzlMenuButton) != 0; 130 } 131 132 /** */ 133 public void setModel(MenuModel model) 134 { 135 dzl_menu_button_set_model(dzlMenuButton, (model is null) ? null : model.getMenuModelStruct()); 136 } 137 138 /** 139 * Sets the #DzlMenuButton:show-accels property. 140 * 141 * If %TRUE, accelerators will be displayed next to menu items that 142 * contain a shortcut. 143 * 144 * Params: 145 * showAccels = if accelerators should be visible 146 * 147 * Since: 3.26 148 */ 149 public void setShowAccels(bool showAccels) 150 { 151 dzl_menu_button_set_show_accels(dzlMenuButton, showAccels); 152 } 153 154 /** 155 * Sets the #DzlMenuButton:show-arrow property. 156 * 157 * If %TRUE, an pan-down-symbolic image will be displayed next to the 158 * image in the button. 159 * 160 * Since: 3.26 161 */ 162 public void setShowArrow(bool showArrow) 163 { 164 dzl_menu_button_set_show_arrow(dzlMenuButton, showArrow); 165 } 166 167 /** 168 * Sets the #DzlMenuButton:show-icons property. 169 * 170 * If %TRUE, icons will be displayed next to menu items that 171 * contain a shortcut. 172 * 173 * Params: 174 * showIcons = if icons should be visible 175 * 176 * Since: 3.26 177 */ 178 public void setShowIcons(bool showIcons) 179 { 180 dzl_menu_button_set_show_icons(dzlMenuButton, showIcons); 181 } 182 }