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