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.MenuToolButton; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Menu; 32 private import gtk.ToolButton; 33 private import gtk.ToolItem; 34 private import gtk.Widget; 35 private import gtkc.gtk; 36 public import gtkc.gtktypes; 37 private import std.algorithm; 38 39 40 /** 41 * A #GtkMenuToolButton is a #GtkToolItem that contains a button and 42 * a small additional button with an arrow. When clicked, the arrow 43 * button pops up a dropdown menu. 44 * 45 * Use gtk_menu_tool_button_new() to create a new 46 * #GtkMenuToolButton. 47 * 48 * # GtkMenuToolButton as GtkBuildable 49 * 50 * The GtkMenuToolButton implementation of the GtkBuildable interface 51 * supports adding a menu by specifying “menu” as the “type” attribute 52 * of a <child> element. 53 * 54 * An example for a UI definition fragment with menus: 55 * |[ 56 * <object class="GtkMenuToolButton"> 57 * <child type="menu"> 58 * <object class="GtkMenu"/> 59 * </child> 60 * </object> 61 * ]| 62 */ 63 public class MenuToolButton : ToolButton 64 { 65 /** the main Gtk struct */ 66 protected GtkMenuToolButton* gtkMenuToolButton; 67 68 /** Get the main Gtk struct */ 69 public GtkMenuToolButton* getMenuToolButtonStruct(bool transferOwnership = false) 70 { 71 if (transferOwnership) 72 ownedRef = false; 73 return gtkMenuToolButton; 74 } 75 76 /** the main Gtk struct as a void* */ 77 protected override void* getStruct() 78 { 79 return cast(void*)gtkMenuToolButton; 80 } 81 82 protected override void setStruct(GObject* obj) 83 { 84 gtkMenuToolButton = cast(GtkMenuToolButton*)obj; 85 super.setStruct(obj); 86 } 87 88 /** 89 * Sets our main struct and passes it to the parent class. 90 */ 91 public this (GtkMenuToolButton* gtkMenuToolButton, bool ownedRef = false) 92 { 93 this.gtkMenuToolButton = gtkMenuToolButton; 94 super(cast(GtkToolButton*)gtkMenuToolButton, ownedRef); 95 } 96 97 /** 98 * Creates a new GtkMenuToolButton. 99 * The new GtkMenuToolButton will contain an icon and label from 100 * the stock item indicated by stockID. 101 * Since: 2.6 102 * Params: 103 * stockID = the name of a stock item 104 * Throws: ConstructionException GTK+ fails to create the object. 105 */ 106 public this(StockID stockId) 107 { 108 this(cast(string)stockId); 109 } 110 111 /** 112 * Gets the GtkMenu associated with GtkMenuToolButton. 113 * Since: 2.6 114 * Params: 115 * button = a GtkMenuToolButton 116 * Returns: 117 * the GtkMenu associated with GtkMenuToolButton 118 */ 119 public Menu getMenu() 120 { 121 auto p = gtk_menu_tool_button_get_menu(gtkMenuToolButton); 122 if(p is null) 123 { 124 return null; 125 } 126 return new Menu(cast(GtkMenu*)p); 127 } 128 129 /** 130 */ 131 132 /** */ 133 public static GType getType() 134 { 135 return gtk_menu_tool_button_get_type(); 136 } 137 138 /** 139 * Creates a new #GtkMenuToolButton using @icon_widget as icon and 140 * @label as label. 141 * 142 * Params: 143 * iconWidget = a widget that will be used as icon widget, or %NULL 144 * label = a string that will be used as label, or %NULL 145 * 146 * Returns: the new #GtkMenuToolButton 147 * 148 * Since: 2.6 149 * 150 * Throws: ConstructionException GTK+ fails to create the object. 151 */ 152 public this(Widget iconWidget, string label) 153 { 154 auto p = gtk_menu_tool_button_new((iconWidget is null) ? null : iconWidget.getWidgetStruct(), Str.toStringz(label)); 155 156 if(p is null) 157 { 158 throw new ConstructionException("null returned by new"); 159 } 160 161 this(cast(GtkMenuToolButton*) p); 162 } 163 164 /** 165 * Creates a new #GtkMenuToolButton. 166 * The new #GtkMenuToolButton will contain an icon and label from 167 * the stock item indicated by @stock_id. 168 * 169 * Deprecated: Use gtk_menu_tool_button_new() instead. 170 * 171 * Params: 172 * stockId = the name of a stock item 173 * 174 * Returns: the new #GtkMenuToolButton 175 * 176 * Since: 2.6 177 * 178 * Throws: ConstructionException GTK+ fails to create the object. 179 */ 180 public this(string stockId) 181 { 182 auto p = gtk_menu_tool_button_new_from_stock(Str.toStringz(stockId)); 183 184 if(p is null) 185 { 186 throw new ConstructionException("null returned by new_from_stock"); 187 } 188 189 this(cast(GtkMenuToolButton*) p); 190 } 191 192 /** 193 * Sets the tooltip markup text to be used as tooltip for the arrow button 194 * which pops up the menu. See gtk_tool_item_set_tooltip_text() for setting 195 * a tooltip on the whole #GtkMenuToolButton. 196 * 197 * Params: 198 * markup = markup text to be used as tooltip text for button’s arrow button 199 * 200 * Since: 2.12 201 */ 202 public void setArrowTooltipMarkup(string markup) 203 { 204 gtk_menu_tool_button_set_arrow_tooltip_markup(gtkMenuToolButton, Str.toStringz(markup)); 205 } 206 207 /** 208 * Sets the tooltip text to be used as tooltip for the arrow button which 209 * pops up the menu. See gtk_tool_item_set_tooltip_text() for setting a tooltip 210 * on the whole #GtkMenuToolButton. 211 * 212 * Params: 213 * text = text to be used as tooltip text for button’s arrow button 214 * 215 * Since: 2.12 216 */ 217 public void setArrowTooltipText(string text) 218 { 219 gtk_menu_tool_button_set_arrow_tooltip_text(gtkMenuToolButton, Str.toStringz(text)); 220 } 221 222 /** 223 * Sets the #GtkMenu that is popped up when the user clicks on the arrow. 224 * If @menu is NULL, the arrow button becomes insensitive. 225 * 226 * Params: 227 * menu = the #GtkMenu associated with #GtkMenuToolButton 228 * 229 * Since: 2.6 230 */ 231 public void setMenu(Widget menu) 232 { 233 gtk_menu_tool_button_set_menu(gtkMenuToolButton, (menu is null) ? null : menu.getWidgetStruct()); 234 } 235 236 protected class OnShowMenuDelegateWrapper 237 { 238 void delegate(MenuToolButton) dlg; 239 gulong handlerId; 240 241 this(void delegate(MenuToolButton) dlg) 242 { 243 this.dlg = dlg; 244 onShowMenuListeners ~= this; 245 } 246 247 void remove(OnShowMenuDelegateWrapper source) 248 { 249 foreach(index, wrapper; onShowMenuListeners) 250 { 251 if (wrapper.handlerId == source.handlerId) 252 { 253 onShowMenuListeners[index] = null; 254 onShowMenuListeners = std.algorithm.remove(onShowMenuListeners, index); 255 break; 256 } 257 } 258 } 259 } 260 OnShowMenuDelegateWrapper[] onShowMenuListeners; 261 262 /** 263 * The ::show-menu signal is emitted before the menu is shown. 264 * 265 * It can be used to populate the menu on demand, using 266 * gtk_menu_tool_button_set_menu(). 267 * 268 * Note that even if you populate the menu dynamically in this way, 269 * you must set an empty menu on the #GtkMenuToolButton beforehand, 270 * since the arrow is made insensitive if the menu is not set. 271 */ 272 gulong addOnShowMenu(void delegate(MenuToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 273 { 274 auto wrapper = new OnShowMenuDelegateWrapper(dlg); 275 wrapper.handlerId = Signals.connectData( 276 this, 277 "show-menu", 278 cast(GCallback)&callBackShowMenu, 279 cast(void*)wrapper, 280 cast(GClosureNotify)&callBackShowMenuDestroy, 281 connectFlags); 282 return wrapper.handlerId; 283 } 284 285 extern(C) static void callBackShowMenu(GtkMenuToolButton* menutoolbuttonStruct, OnShowMenuDelegateWrapper wrapper) 286 { 287 wrapper.dlg(wrapper.outer); 288 } 289 290 extern(C) static void callBackShowMenuDestroy(OnShowMenuDelegateWrapper wrapper, GClosure* closure) 291 { 292 wrapper.remove(wrapper); 293 } 294 }