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 	public static GType getType()
131 	{
132 		return gtk_menu_tool_button_get_type();
133 	}
134 
135 	/**
136 	 * Creates a new #GtkMenuToolButton using @icon_widget as icon and
137 	 * @label as label.
138 	 *
139 	 * Params:
140 	 *     iconWidget = a widget that will be used as icon widget, or %NULL
141 	 *     label = a string that will be used as label, or %NULL
142 	 *
143 	 * Return: the new #GtkMenuToolButton
144 	 *
145 	 * Since: 2.6
146 	 *
147 	 * Throws: ConstructionException GTK+ fails to create the object.
148 	 */
149 	public this(Widget iconWidget, string label)
150 	{
151 		auto p = gtk_menu_tool_button_new((iconWidget is null) ? null : iconWidget.getWidgetStruct(), Str.toStringz(label));
152 		
153 		if(p is null)
154 		{
155 			throw new ConstructionException("null returned by new");
156 		}
157 		
158 		this(cast(GtkMenuToolButton*) p);
159 	}
160 
161 	/**
162 	 * Creates a new #GtkMenuToolButton.
163 	 * The new #GtkMenuToolButton will contain an icon and label from
164 	 * the stock item indicated by @stock_id.
165 	 *
166 	 * Deprecated: Use gtk_menu_tool_button_new() instead.
167 	 *
168 	 * Params:
169 	 *     stockId = the name of a stock item
170 	 *
171 	 * Return: the new #GtkMenuToolButton
172 	 *
173 	 * Since: 2.6
174 	 *
175 	 * Throws: ConstructionException GTK+ fails to create the object.
176 	 */
177 	public this(string stockId)
178 	{
179 		auto p = gtk_menu_tool_button_new_from_stock(Str.toStringz(stockId));
180 		
181 		if(p is null)
182 		{
183 			throw new ConstructionException("null returned by new_from_stock");
184 		}
185 		
186 		this(cast(GtkMenuToolButton*) p);
187 	}
188 
189 	/**
190 	 * Sets the tooltip markup text to be used as tooltip for the arrow button
191 	 * which pops up the menu.  See gtk_tool_item_set_tooltip_text() for setting
192 	 * a tooltip on the whole #GtkMenuToolButton.
193 	 *
194 	 * Params:
195 	 *     markup = markup text to be used as tooltip text for button’s arrow button
196 	 *
197 	 * Since: 2.12
198 	 */
199 	public void setArrowTooltipMarkup(string markup)
200 	{
201 		gtk_menu_tool_button_set_arrow_tooltip_markup(gtkMenuToolButton, Str.toStringz(markup));
202 	}
203 
204 	/**
205 	 * Sets the tooltip text to be used as tooltip for the arrow button which
206 	 * pops up the menu.  See gtk_tool_item_set_tooltip_text() for setting a tooltip
207 	 * on the whole #GtkMenuToolButton.
208 	 *
209 	 * Params:
210 	 *     text = text to be used as tooltip text for button’s arrow button
211 	 *
212 	 * Since: 2.12
213 	 */
214 	public void setArrowTooltipText(string text)
215 	{
216 		gtk_menu_tool_button_set_arrow_tooltip_text(gtkMenuToolButton, Str.toStringz(text));
217 	}
218 
219 	/**
220 	 * Sets the #GtkMenu that is popped up when the user clicks on the arrow.
221 	 * If @menu is NULL, the arrow button becomes insensitive.
222 	 *
223 	 * Params:
224 	 *     menu = the #GtkMenu associated with #GtkMenuToolButton
225 	 *
226 	 * Since: 2.6
227 	 */
228 	public void setMenu(Widget menu)
229 	{
230 		gtk_menu_tool_button_set_menu(gtkMenuToolButton, (menu is null) ? null : menu.getWidgetStruct());
231 	}
232 
233 	int[string] connectedSignals;
234 
235 	void delegate(MenuToolButton)[] onShowMenuListeners;
236 	/**
237 	 * The ::show-menu signal is emitted before the menu is shown.
238 	 *
239 	 * It can be used to populate the menu on demand, using
240 	 * gtk_menu_tool_button_set_menu().
241 	 *
242 	 * Note that even if you populate the menu dynamically in this way,
243 	 * you must set an empty menu on the #GtkMenuToolButton beforehand,
244 	 * since the arrow is made insensitive if the menu is not set.
245 	 */
246 	void addOnShowMenu(void delegate(MenuToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
247 	{
248 		if ( "show-menu" !in connectedSignals )
249 		{
250 			Signals.connectData(
251 				this,
252 				"show-menu",
253 				cast(GCallback)&callBackShowMenu,
254 				cast(void*)this,
255 				null,
256 				connectFlags);
257 			connectedSignals["show-menu"] = 1;
258 		}
259 		onShowMenuListeners ~= dlg;
260 	}
261 	extern(C) static void callBackShowMenu(GtkMenuToolButton* menutoolbuttonStruct, MenuToolButton _menutoolbutton)
262 	{
263 		foreach ( void delegate(MenuToolButton) dlg; _menutoolbutton.onShowMenuListeners )
264 		{
265 			dlg(_menutoolbutton);
266 		}
267 	}
268 }