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