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.ToggleToolButton;
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.ToolButton;
32 private import gtk.ToolItem;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * A #GtkToggleToolButton is a #GtkToolItem that contains a toggle
40  * button.
41  * 
42  * Use gtk_toggle_tool_button_new() to create a new GtkToggleToolButton.
43  * 
44  * # CSS nodes
45  * 
46  * GtkToggleToolButton has a single CSS node with name togglebutton.
47  */
48 public class ToggleToolButton : ToolButton
49 {
50 	/** the main Gtk struct */
51 	protected GtkToggleToolButton* gtkToggleToolButton;
52 
53 	/** Get the main Gtk struct */
54 	public GtkToggleToolButton* getToggleToolButtonStruct()
55 	{
56 		return gtkToggleToolButton;
57 	}
58 
59 	/** the main Gtk struct as a void* */
60 	protected override void* getStruct()
61 	{
62 		return cast(void*)gtkToggleToolButton;
63 	}
64 
65 	protected override void setStruct(GObject* obj)
66 	{
67 		gtkToggleToolButton = cast(GtkToggleToolButton*)obj;
68 		super.setStruct(obj);
69 	}
70 
71 	/**
72 	 * Sets our main struct and passes it to the parent class.
73 	 */
74 	public this (GtkToggleToolButton* gtkToggleToolButton, bool ownedRef = false)
75 	{
76 		this.gtkToggleToolButton = gtkToggleToolButton;
77 		super(cast(GtkToolButton*)gtkToggleToolButton, ownedRef);
78 	}
79 
80 	/**
81 	 * Creates a new GtkToggleToolButton containing the image and text
82 	 * from a stock item.
83 	 */
84 	public this(StockID stockId)
85 	{
86 		this(cast(string)stockId);
87 	}
88 
89 	/**
90 	 */
91 
92 	/** */
93 	public static GType getType()
94 	{
95 		return gtk_toggle_tool_button_get_type();
96 	}
97 
98 	/**
99 	 * Returns a new #GtkToggleToolButton
100 	 *
101 	 * Return: a newly created #GtkToggleToolButton
102 	 *
103 	 * Since: 2.4
104 	 *
105 	 * Throws: ConstructionException GTK+ fails to create the object.
106 	 */
107 	public this()
108 	{
109 		auto p = gtk_toggle_tool_button_new();
110 		
111 		if(p is null)
112 		{
113 			throw new ConstructionException("null returned by new");
114 		}
115 		
116 		this(cast(GtkToggleToolButton*) p);
117 	}
118 
119 	/**
120 	 * Creates a new #GtkToggleToolButton containing the image and text from a
121 	 * stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK
122 	 * and #GTK_STOCK_APPLY.
123 	 *
124 	 * It is an error if @stock_id is not a name of a stock item.
125 	 *
126 	 * Deprecated: Use gtk_toggle_tool_button_new() instead.
127 	 *
128 	 * Params:
129 	 *     stockId = the name of the stock item
130 	 *
131 	 * Return: A new #GtkToggleToolButton
132 	 *
133 	 * Since: 2.4
134 	 *
135 	 * Throws: ConstructionException GTK+ fails to create the object.
136 	 */
137 	public this(string stockId)
138 	{
139 		auto p = gtk_toggle_tool_button_new_from_stock(Str.toStringz(stockId));
140 		
141 		if(p is null)
142 		{
143 			throw new ConstructionException("null returned by new_from_stock");
144 		}
145 		
146 		this(cast(GtkToggleToolButton*) p);
147 	}
148 
149 	/**
150 	 * Queries a #GtkToggleToolButton and returns its current state.
151 	 * Returns %TRUE if the toggle button is pressed in and %FALSE if it is raised.
152 	 *
153 	 * Return: %TRUE if the toggle tool button is pressed in, %FALSE if not
154 	 *
155 	 * Since: 2.4
156 	 */
157 	public bool getActive()
158 	{
159 		return gtk_toggle_tool_button_get_active(gtkToggleToolButton) != 0;
160 	}
161 
162 	/**
163 	 * Sets the status of the toggle tool button. Set to %TRUE if you
164 	 * want the GtkToggleButton to be “pressed in”, and %FALSE to raise it.
165 	 * This action causes the toggled signal to be emitted.
166 	 *
167 	 * Params:
168 	 *     isActive = whether @button should be active
169 	 *
170 	 * Since: 2.4
171 	 */
172 	public void setActive(bool isActive)
173 	{
174 		gtk_toggle_tool_button_set_active(gtkToggleToolButton, isActive);
175 	}
176 
177 	int[string] connectedSignals;
178 
179 	void delegate(ToggleToolButton)[] onToggledListeners;
180 	/**
181 	 * Emitted whenever the toggle tool button changes state.
182 	 */
183 	void addOnToggled(void delegate(ToggleToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
184 	{
185 		if ( "toggled" !in connectedSignals )
186 		{
187 			Signals.connectData(
188 				this,
189 				"toggled",
190 				cast(GCallback)&callBackToggled,
191 				cast(void*)this,
192 				null,
193 				connectFlags);
194 			connectedSignals["toggled"] = 1;
195 		}
196 		onToggledListeners ~= dlg;
197 	}
198 	extern(C) static void callBackToggled(GtkToggleToolButton* toggletoolbuttonStruct, ToggleToolButton _toggletoolbutton)
199 	{
200 		foreach ( void delegate(ToggleToolButton) dlg; _toggletoolbutton.onToggledListeners )
201 		{
202 			dlg(_toggletoolbutton);
203 		}
204 	}
205 }