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