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