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 public  import gtkc.gdktypes;
36 private import gtkc.gtk;
37 public  import gtkc.gtktypes;
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()
70 	{
71 		return gtkMenuToolButton;
72 	}
73 
74 	/** the main Gtk struct as a void* */
75 	protected override void* getStruct()
76 	{
77 		return cast(void*)gtkMenuToolButton;
78 	}
79 
80 	protected override void setStruct(GObject* obj)
81 	{
82 		gtkMenuToolButton = cast(GtkMenuToolButton*)obj;
83 		super.setStruct(obj);
84 	}
85 
86 	/**
87 	 * Sets our main struct and passes it to the parent class.
88 	 */
89 	public this (GtkMenuToolButton* gtkMenuToolButton, bool ownedRef = false)
90 	{
91 		this.gtkMenuToolButton = gtkMenuToolButton;
92 		super(cast(GtkToolButton*)gtkMenuToolButton, ownedRef);
93 	}
94 
95 	/**
96 	 * Creates a new GtkMenuToolButton.
97 	 * The new GtkMenuToolButton will contain an icon and label from
98 	 * the stock item indicated by stockID.
99 	 * Since: 2.6
100 	 * Params:
101 	 *     stockID = the name of a stock item
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this(StockID stockId)
105 	{
106 		this(cast(string)stockId);
107 	}
108 	
109 	/**
110 	 * Gets the GtkMenu associated with GtkMenuToolButton.
111 	 * Since: 2.6
112 	 * Params:
113 	 *  button = a GtkMenuToolButton
114 	 * Returns:
115 	 *  the GtkMenu associated with GtkMenuToolButton
116 	 */
117 	public Menu getMenu()
118 	{
119 		auto p =  gtk_menu_tool_button_get_menu(gtkMenuToolButton);
120 		if(p is null)
121 		{
122 			return null;
123 		}
124 		return new Menu(cast(GtkMenu*)p);
125 	}
126 
127 	/**
128 	 */
129 
130 	/** */
131 	public static GType getType()
132 	{
133 		return gtk_menu_tool_button_get_type();
134 	}
135 
136 	/**
137 	 * Creates a new #GtkMenuToolButton using @icon_widget as icon and
138 	 * @label as label.
139 	 *
140 	 * Params:
141 	 *     iconWidget = a widget that will be used as icon widget, or %NULL
142 	 *     label = a string that will be used as label, or %NULL
143 	 *
144 	 * Return: the new #GtkMenuToolButton
145 	 *
146 	 * Since: 2.6
147 	 *
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this(Widget iconWidget, string label)
151 	{
152 		auto p = gtk_menu_tool_button_new((iconWidget is null) ? null : iconWidget.getWidgetStruct(), Str.toStringz(label));
153 		
154 		if(p is null)
155 		{
156 			throw new ConstructionException("null returned by new");
157 		}
158 		
159 		this(cast(GtkMenuToolButton*) p);
160 	}
161 
162 	/**
163 	 * Creates a new #GtkMenuToolButton.
164 	 * The new #GtkMenuToolButton will contain an icon and label from
165 	 * the stock item indicated by @stock_id.
166 	 *
167 	 * Deprecated: Use gtk_menu_tool_button_new() instead.
168 	 *
169 	 * Params:
170 	 *     stockId = the name of a stock item
171 	 *
172 	 * Return: the new #GtkMenuToolButton
173 	 *
174 	 * Since: 2.6
175 	 *
176 	 * Throws: ConstructionException GTK+ fails to create the object.
177 	 */
178 	public this(string stockId)
179 	{
180 		auto p = gtk_menu_tool_button_new_from_stock(Str.toStringz(stockId));
181 		
182 		if(p is null)
183 		{
184 			throw new ConstructionException("null returned by new_from_stock");
185 		}
186 		
187 		this(cast(GtkMenuToolButton*) p);
188 	}
189 
190 	/**
191 	 * Sets the tooltip markup text to be used as tooltip for the arrow button
192 	 * which pops up the menu.  See gtk_tool_item_set_tooltip_text() for setting
193 	 * a tooltip on the whole #GtkMenuToolButton.
194 	 *
195 	 * Params:
196 	 *     markup = markup text to be used as tooltip text for button’s arrow button
197 	 *
198 	 * Since: 2.12
199 	 */
200 	public void setArrowTooltipMarkup(string markup)
201 	{
202 		gtk_menu_tool_button_set_arrow_tooltip_markup(gtkMenuToolButton, Str.toStringz(markup));
203 	}
204 
205 	/**
206 	 * Sets the tooltip text to be used as tooltip for the arrow button which
207 	 * pops up the menu.  See gtk_tool_item_set_tooltip_text() for setting a tooltip
208 	 * on the whole #GtkMenuToolButton.
209 	 *
210 	 * Params:
211 	 *     text = text to be used as tooltip text for button’s arrow button
212 	 *
213 	 * Since: 2.12
214 	 */
215 	public void setArrowTooltipText(string text)
216 	{
217 		gtk_menu_tool_button_set_arrow_tooltip_text(gtkMenuToolButton, Str.toStringz(text));
218 	}
219 
220 	/**
221 	 * Sets the #GtkMenu that is popped up when the user clicks on the arrow.
222 	 * If @menu is NULL, the arrow button becomes insensitive.
223 	 *
224 	 * Params:
225 	 *     menu = the #GtkMenu associated with #GtkMenuToolButton
226 	 *
227 	 * Since: 2.6
228 	 */
229 	public void setMenu(Widget menu)
230 	{
231 		gtk_menu_tool_button_set_menu(gtkMenuToolButton, (menu is null) ? null : menu.getWidgetStruct());
232 	}
233 
234 	int[string] connectedSignals;
235 
236 	void delegate(MenuToolButton)[] onShowMenuListeners;
237 	/**
238 	 * The ::show-menu signal is emitted before the menu is shown.
239 	 *
240 	 * It can be used to populate the menu on demand, using
241 	 * gtk_menu_tool_button_set_menu().
242 	 *
243 	 * Note that even if you populate the menu dynamically in this way,
244 	 * you must set an empty menu on the #GtkMenuToolButton beforehand,
245 	 * since the arrow is made insensitive if the menu is not set.
246 	 */
247 	void addOnShowMenu(void delegate(MenuToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
248 	{
249 		if ( "show-menu" !in connectedSignals )
250 		{
251 			Signals.connectData(
252 				this,
253 				"show-menu",
254 				cast(GCallback)&callBackShowMenu,
255 				cast(void*)this,
256 				null,
257 				connectFlags);
258 			connectedSignals["show-menu"] = 1;
259 		}
260 		onShowMenuListeners ~= dlg;
261 	}
262 	extern(C) static void callBackShowMenu(GtkMenuToolButton* menutoolbuttonStruct, MenuToolButton _menutoolbutton)
263 	{
264 		foreach ( void delegate(MenuToolButton) dlg; _menutoolbutton.onShowMenuListeners )
265 		{
266 			dlg(_menutoolbutton);
267 		}
268 	}
269 }