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