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.ToolButton;
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.ActionableIF;
32 private import gtk.ActionableT;
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  * #GtkToolButtons are #GtkToolItems containing buttons.
43  * 
44  * Use gtk_tool_button_new() to create a new #GtkToolButton.
45  * 
46  * The label of a #GtkToolButton is determined by the properties
47  * #GtkToolButton:label-widget, #GtkToolButton:label, and
48  * #GtkToolButton:stock-id. If #GtkToolButton:label-widget is
49  * non-%NULL, then that widget is used as the label. Otherwise, if
50  * #GtkToolButton:label is non-%NULL, that string is used as the label.
51  * Otherwise, if #GtkToolButton:stock-id is non-%NULL, the label is
52  * determined by the stock item. Otherwise, the button does not have a label.
53  * 
54  * The icon of a #GtkToolButton is determined by the properties
55  * #GtkToolButton:icon-widget and #GtkToolButton:stock-id. If
56  * #GtkToolButton:icon-widget is non-%NULL, then
57  * that widget is used as the icon. Otherwise, if #GtkToolButton:stock-id is
58  * non-%NULL, the icon is determined by the stock item. Otherwise,
59  * the button does not have a icon.
60  * 
61  * # CSS nodes
62  * 
63  * GtkToolButton has a single CSS node with name toolbutton.
64  */
65 public class ToolButton : ToolItem, ActionableIF
66 {
67 	/** the main Gtk struct */
68 	protected GtkToolButton* gtkToolButton;
69 
70 	/** Get the main Gtk struct */
71 	public GtkToolButton* getToolButtonStruct(bool transferOwnership = false)
72 	{
73 		if (transferOwnership)
74 			ownedRef = false;
75 		return gtkToolButton;
76 	}
77 
78 	/** the main Gtk struct as a void* */
79 	protected override void* getStruct()
80 	{
81 		return cast(void*)gtkToolButton;
82 	}
83 
84 	protected override void setStruct(GObject* obj)
85 	{
86 		gtkToolButton = cast(GtkToolButton*)obj;
87 		super.setStruct(obj);
88 	}
89 
90 	/**
91 	 * Sets our main struct and passes it to the parent class.
92 	 */
93 	public this (GtkToolButton* gtkToolButton, bool ownedRef = false)
94 	{
95 		this.gtkToolButton = gtkToolButton;
96 		super(cast(GtkToolItem*)gtkToolButton, ownedRef);
97 	}
98 
99 	// add the Actionable capabilities
100 	mixin ActionableT!(GtkToolButton);
101 
102 	/** */
103 	public this (StockID stockID)
104 	{
105 		this(cast(string)stockID);
106 	}
107 
108 	/**
109 	 */
110 
111 	/** */
112 	public static GType getType()
113 	{
114 		return gtk_tool_button_get_type();
115 	}
116 
117 	/**
118 	 * Creates a new #GtkToolButton using @icon_widget as contents and @label as
119 	 * label.
120 	 *
121 	 * Params:
122 	 *     iconWidget = a widget that will be used as the button contents, or %NULL
123 	 *     label = a string that will be used as label, or %NULL
124 	 *
125 	 * Returns: A new #GtkToolButton
126 	 *
127 	 * Since: 2.4
128 	 *
129 	 * Throws: ConstructionException GTK+ fails to create the object.
130 	 */
131 	public this(Widget iconWidget, string label)
132 	{
133 		auto p = gtk_tool_button_new((iconWidget is null) ? null : iconWidget.getWidgetStruct(), Str.toStringz(label));
134 
135 		if(p is null)
136 		{
137 			throw new ConstructionException("null returned by new");
138 		}
139 
140 		this(cast(GtkToolButton*) p);
141 	}
142 
143 	/**
144 	 * Creates a new #GtkToolButton containing the image and text from a
145 	 * stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK
146 	 * and #GTK_STOCK_APPLY.
147 	 *
148 	 * It is an error if @stock_id is not a name of a stock item.
149 	 *
150 	 * Deprecated: Use gtk_tool_button_new() together with
151 	 * gtk_image_new_from_icon_name() instead.
152 	 *
153 	 * Params:
154 	 *     stockId = the name of the stock item
155 	 *
156 	 * Returns: A new #GtkToolButton
157 	 *
158 	 * Since: 2.4
159 	 *
160 	 * Throws: ConstructionException GTK+ fails to create the object.
161 	 */
162 	public this(string stockId)
163 	{
164 		auto p = gtk_tool_button_new_from_stock(Str.toStringz(stockId));
165 
166 		if(p is null)
167 		{
168 			throw new ConstructionException("null returned by new_from_stock");
169 		}
170 
171 		this(cast(GtkToolButton*) p);
172 	}
173 
174 	/**
175 	 * Returns the name of the themed icon for the tool button,
176 	 * see gtk_tool_button_set_icon_name().
177 	 *
178 	 * Returns: the icon name or %NULL if the tool button has
179 	 *     no themed icon
180 	 *
181 	 * Since: 2.8
182 	 */
183 	public string getIconName()
184 	{
185 		return Str.toString(gtk_tool_button_get_icon_name(gtkToolButton));
186 	}
187 
188 	/**
189 	 * Return the widget used as icon widget on @button.
190 	 * See gtk_tool_button_set_icon_widget().
191 	 *
192 	 * Returns: The widget used as icon
193 	 *     on @button, or %NULL.
194 	 *
195 	 * Since: 2.4
196 	 */
197 	public Widget getIconWidget()
198 	{
199 		auto p = gtk_tool_button_get_icon_widget(gtkToolButton);
200 
201 		if(p is null)
202 		{
203 			return null;
204 		}
205 
206 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
207 	}
208 
209 	/**
210 	 * Returns the label used by the tool button, or %NULL if the tool button
211 	 * doesn’t have a label. or uses a the label from a stock item. The returned
212 	 * string is owned by GTK+, and must not be modified or freed.
213 	 *
214 	 * Returns: The label, or %NULL
215 	 *
216 	 * Since: 2.4
217 	 */
218 	public string getLabel()
219 	{
220 		return Str.toString(gtk_tool_button_get_label(gtkToolButton));
221 	}
222 
223 	/**
224 	 * Returns the widget used as label on @button.
225 	 * See gtk_tool_button_set_label_widget().
226 	 *
227 	 * Returns: The widget used as label
228 	 *     on @button, or %NULL.
229 	 *
230 	 * Since: 2.4
231 	 */
232 	public Widget getLabelWidget()
233 	{
234 		auto p = gtk_tool_button_get_label_widget(gtkToolButton);
235 
236 		if(p is null)
237 		{
238 			return null;
239 		}
240 
241 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
242 	}
243 
244 	/**
245 	 * Returns the name of the stock item. See gtk_tool_button_set_stock_id().
246 	 * The returned string is owned by GTK+ and must not be freed or modifed.
247 	 *
248 	 * Deprecated: Use gtk_tool_button_get_icon_name() instead.
249 	 *
250 	 * Returns: the name of the stock item for @button.
251 	 *
252 	 * Since: 2.4
253 	 */
254 	public string getStockId()
255 	{
256 		return Str.toString(gtk_tool_button_get_stock_id(gtkToolButton));
257 	}
258 
259 	/**
260 	 * Returns whether underscores in the label property are used as mnemonics
261 	 * on menu items on the overflow menu. See gtk_tool_button_set_use_underline().
262 	 *
263 	 * Returns: %TRUE if underscores in the label property are used as
264 	 *     mnemonics on menu items on the overflow menu.
265 	 *
266 	 * Since: 2.4
267 	 */
268 	public bool getUseUnderline()
269 	{
270 		return gtk_tool_button_get_use_underline(gtkToolButton) != 0;
271 	}
272 
273 	/**
274 	 * Sets the icon for the tool button from a named themed icon.
275 	 * See the docs for #GtkIconTheme for more details.
276 	 * The #GtkToolButton:icon-name property only has an effect if not
277 	 * overridden by non-%NULL #GtkToolButton:label-widget,
278 	 * #GtkToolButton:icon-widget and #GtkToolButton:stock-id properties.
279 	 *
280 	 * Params:
281 	 *     iconName = the name of the themed icon
282 	 *
283 	 * Since: 2.8
284 	 */
285 	public void setIconName(string iconName)
286 	{
287 		gtk_tool_button_set_icon_name(gtkToolButton, Str.toStringz(iconName));
288 	}
289 
290 	/**
291 	 * Sets @icon as the widget used as icon on @button. If @icon_widget is
292 	 * %NULL the icon is determined by the #GtkToolButton:stock-id property. If the
293 	 * #GtkToolButton:stock-id property is also %NULL, @button will not have an icon.
294 	 *
295 	 * Params:
296 	 *     iconWidget = the widget used as icon, or %NULL
297 	 *
298 	 * Since: 2.4
299 	 */
300 	public void setIconWidget(Widget iconWidget)
301 	{
302 		gtk_tool_button_set_icon_widget(gtkToolButton, (iconWidget is null) ? null : iconWidget.getWidgetStruct());
303 	}
304 
305 	/**
306 	 * Sets @label as the label used for the tool button. The #GtkToolButton:label
307 	 * property only has an effect if not overridden by a non-%NULL
308 	 * #GtkToolButton:label-widget property. If both the #GtkToolButton:label-widget
309 	 * and #GtkToolButton:label properties are %NULL, the label is determined by the
310 	 * #GtkToolButton:stock-id property. If the #GtkToolButton:stock-id property is
311 	 * also %NULL, @button will not have a label.
312 	 *
313 	 * Params:
314 	 *     label = a string that will be used as label, or %NULL.
315 	 *
316 	 * Since: 2.4
317 	 */
318 	public void setLabel(string label)
319 	{
320 		gtk_tool_button_set_label(gtkToolButton, Str.toStringz(label));
321 	}
322 
323 	/**
324 	 * Sets @label_widget as the widget that will be used as the label
325 	 * for @button. If @label_widget is %NULL the #GtkToolButton:label property is used
326 	 * as label. If #GtkToolButton:label is also %NULL, the label in the stock item
327 	 * determined by the #GtkToolButton:stock-id property is used as label. If
328 	 * #GtkToolButton:stock-id is also %NULL, @button does not have a label.
329 	 *
330 	 * Params:
331 	 *     labelWidget = the widget used as label, or %NULL
332 	 *
333 	 * Since: 2.4
334 	 */
335 	public void setLabelWidget(Widget labelWidget)
336 	{
337 		gtk_tool_button_set_label_widget(gtkToolButton, (labelWidget is null) ? null : labelWidget.getWidgetStruct());
338 	}
339 
340 	/**
341 	 * Sets the name of the stock item. See gtk_tool_button_new_from_stock().
342 	 * The stock_id property only has an effect if not overridden by non-%NULL
343 	 * #GtkToolButton:label-widget and #GtkToolButton:icon-widget properties.
344 	 *
345 	 * Deprecated: Use gtk_tool_button_set_icon_name() instead.
346 	 *
347 	 * Params:
348 	 *     stockId = a name of a stock item, or %NULL
349 	 *
350 	 * Since: 2.4
351 	 */
352 	public void setStockId(string stockId)
353 	{
354 		gtk_tool_button_set_stock_id(gtkToolButton, Str.toStringz(stockId));
355 	}
356 
357 	/**
358 	 * If set, an underline in the label property indicates that the next character
359 	 * should be used for the mnemonic accelerator key in the overflow menu. For
360 	 * example, if the label property is “_Open” and @use_underline is %TRUE,
361 	 * the label on the tool button will be “Open” and the item on the overflow
362 	 * menu will have an underlined “O”.
363 	 *
364 	 * Labels shown on tool buttons never have mnemonics on them; this property
365 	 * only affects the menu item on the overflow menu.
366 	 *
367 	 * Params:
368 	 *     useUnderline = whether the button label has the form “_Open”
369 	 *
370 	 * Since: 2.4
371 	 */
372 	public void setUseUnderline(bool useUnderline)
373 	{
374 		gtk_tool_button_set_use_underline(gtkToolButton, useUnderline);
375 	}
376 
377 	protected class OnClickedDelegateWrapper
378 	{
379 		void delegate(ToolButton) dlg;
380 		gulong handlerId;
381 
382 		this(void delegate(ToolButton) dlg)
383 		{
384 			this.dlg = dlg;
385 			onClickedListeners ~= this;
386 		}
387 
388 		void remove(OnClickedDelegateWrapper source)
389 		{
390 			foreach(index, wrapper; onClickedListeners)
391 			{
392 				if (wrapper.handlerId == source.handlerId)
393 				{
394 					onClickedListeners[index] = null;
395 					onClickedListeners = std.algorithm.remove(onClickedListeners, index);
396 					break;
397 				}
398 			}
399 		}
400 	}
401 	OnClickedDelegateWrapper[] onClickedListeners;
402 
403 	/**
404 	 * This signal is emitted when the tool button is clicked with the mouse
405 	 * or activated with the keyboard.
406 	 */
407 	gulong addOnClicked(void delegate(ToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
408 	{
409 		auto wrapper = new OnClickedDelegateWrapper(dlg);
410 		wrapper.handlerId = Signals.connectData(
411 			this,
412 			"clicked",
413 			cast(GCallback)&callBackClicked,
414 			cast(void*)wrapper,
415 			cast(GClosureNotify)&callBackClickedDestroy,
416 			connectFlags);
417 		return wrapper.handlerId;
418 	}
419 
420 	extern(C) static void callBackClicked(GtkToolButton* toolbuttonStruct, OnClickedDelegateWrapper wrapper)
421 	{
422 		wrapper.dlg(wrapper.outer);
423 	}
424 
425 	extern(C) static void callBackClickedDestroy(OnClickedDelegateWrapper wrapper, GClosure* closure)
426 	{
427 		wrapper.remove(wrapper);
428 	}
429 }