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