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.CheckMenuItem;
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.MenuItem;
32 private import gtk.Widget;
33 public  import gtkc.gdktypes;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * A #GtkCheckMenuItem is a menu item that maintains the state of a boolean
40  * value in addition to a #GtkMenuItem usual role in activating application
41  * code.
42  * 
43  * A check box indicating the state of the boolean value is displayed
44  * at the left side of the #GtkMenuItem.  Activating the #GtkMenuItem
45  * toggles the value.
46  */
47 public class CheckMenuItem : MenuItem
48 {
49 	/** the main Gtk struct */
50 	protected GtkCheckMenuItem* gtkCheckMenuItem;
51 
52 	/** Get the main Gtk struct */
53 	public GtkCheckMenuItem* getCheckMenuItemStruct()
54 	{
55 		return gtkCheckMenuItem;
56 	}
57 
58 	/** the main Gtk struct as a void* */
59 	protected override void* getStruct()
60 	{
61 		return cast(void*)gtkCheckMenuItem;
62 	}
63 
64 	protected override void setStruct(GObject* obj)
65 	{
66 		gtkCheckMenuItem = cast(GtkCheckMenuItem*)obj;
67 		super.setStruct(obj);
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkCheckMenuItem* gtkCheckMenuItem, bool ownedRef = false)
74 	{
75 		this.gtkCheckMenuItem = gtkCheckMenuItem;
76 		super(cast(GtkMenuItem*)gtkCheckMenuItem, ownedRef);
77 	}
78 
79 	/**
80 	 * Creates a new GtkCheckMenuItem with a label.
81 	 * Params:
82 	 *  label = the string to use for the label.
83 	 *  mnemonic = if true the label
84 	 *  will be created using gtk_label_new_with_mnemonic(), so underscores
85 	 *  in label indicate the mnemonic for the menu item.
86 	 * Throws: ConstructionException GTK+ fails to create the object.
87 	 */
88 	public this (string label, bool mnemonic=true)
89 	{
90 		GtkCheckMenuItem* p;
91 		
92 		if ( mnemonic )
93 		{
94 			// GtkWidget* gtk_check_menu_item_new_with_mnemonic  (const gchar *label);
95 			p = cast(GtkCheckMenuItem*)gtk_check_menu_item_new_with_mnemonic(Str.toStringz(label));
96 		}
97 		else
98 		{
99 			// GtkWidget* gtk_check_menu_item_new_with_label  (const gchar *label);
100 			p = cast(GtkCheckMenuItem*)gtk_check_menu_item_new_with_label(Str.toStringz(label));
101 		}
102 		
103 		if(p is null)
104 		{
105 			throw new ConstructionException("null returned by gtk_check_menu_item_new_with_");
106 		}
107 		
108 		this(p);
109 	}
110 
111 	/**
112 	 */
113 
114 	/** */
115 	public static GType getType()
116 	{
117 		return gtk_check_menu_item_get_type();
118 	}
119 
120 	/**
121 	 * Creates a new #GtkCheckMenuItem.
122 	 *
123 	 * Return: a new #GtkCheckMenuItem.
124 	 *
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this()
128 	{
129 		auto p = gtk_check_menu_item_new();
130 		
131 		if(p is null)
132 		{
133 			throw new ConstructionException("null returned by new");
134 		}
135 		
136 		this(cast(GtkCheckMenuItem*) p);
137 	}
138 
139 	/**
140 	 * Returns whether the check menu item is active. See
141 	 * gtk_check_menu_item_set_active ().
142 	 *
143 	 * Return: %TRUE if the menu item is checked.
144 	 */
145 	public bool getActive()
146 	{
147 		return gtk_check_menu_item_get_active(gtkCheckMenuItem) != 0;
148 	}
149 
150 	/**
151 	 * Returns whether @check_menu_item looks like a #GtkRadioMenuItem
152 	 *
153 	 * Return: Whether @check_menu_item looks like a #GtkRadioMenuItem
154 	 *
155 	 * Since: 2.4
156 	 */
157 	public bool getDrawAsRadio()
158 	{
159 		return gtk_check_menu_item_get_draw_as_radio(gtkCheckMenuItem) != 0;
160 	}
161 
162 	/**
163 	 * Retrieves the value set by gtk_check_menu_item_set_inconsistent().
164 	 *
165 	 * Return: %TRUE if inconsistent
166 	 */
167 	public bool getInconsistent()
168 	{
169 		return gtk_check_menu_item_get_inconsistent(gtkCheckMenuItem) != 0;
170 	}
171 
172 	/**
173 	 * Sets the active state of the menu item’s check box.
174 	 *
175 	 * Params:
176 	 *     isActive = boolean value indicating whether the check box is active.
177 	 */
178 	public void setActive(bool isActive)
179 	{
180 		gtk_check_menu_item_set_active(gtkCheckMenuItem, isActive);
181 	}
182 
183 	/**
184 	 * Sets whether @check_menu_item is drawn like a #GtkRadioMenuItem
185 	 *
186 	 * Params:
187 	 *     drawAsRadio = whether @check_menu_item is drawn like a #GtkRadioMenuItem
188 	 *
189 	 * Since: 2.4
190 	 */
191 	public void setDrawAsRadio(bool drawAsRadio)
192 	{
193 		gtk_check_menu_item_set_draw_as_radio(gtkCheckMenuItem, drawAsRadio);
194 	}
195 
196 	/**
197 	 * If the user has selected a range of elements (such as some text or
198 	 * spreadsheet cells) that are affected by a boolean setting, and the
199 	 * current values in that range are inconsistent, you may want to
200 	 * display the check in an “in between” state. This function turns on
201 	 * “in between” display.  Normally you would turn off the inconsistent
202 	 * state again if the user explicitly selects a setting. This has to be
203 	 * done manually, gtk_check_menu_item_set_inconsistent() only affects
204 	 * visual appearance, it doesn’t affect the semantics of the widget.
205 	 *
206 	 * Params:
207 	 *     setting = %TRUE to display an “inconsistent” third state check
208 	 */
209 	public void setInconsistent(bool setting)
210 	{
211 		gtk_check_menu_item_set_inconsistent(gtkCheckMenuItem, setting);
212 	}
213 
214 	/**
215 	 * Emits the #GtkCheckMenuItem::toggled signal.
216 	 */
217 	public void toggled()
218 	{
219 		gtk_check_menu_item_toggled(gtkCheckMenuItem);
220 	}
221 
222 	int[string] connectedSignals;
223 
224 	void delegate(CheckMenuItem)[] onToggledListeners;
225 	/**
226 	 * This signal is emitted when the state of the check box is changed.
227 	 *
228 	 * A signal handler can use gtk_check_menu_item_get_active()
229 	 * to discover the new state.
230 	 */
231 	void addOnToggled(void delegate(CheckMenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
232 	{
233 		if ( "toggled" !in connectedSignals )
234 		{
235 			Signals.connectData(
236 				this,
237 				"toggled",
238 				cast(GCallback)&callBackToggled,
239 				cast(void*)this,
240 				null,
241 				connectFlags);
242 			connectedSignals["toggled"] = 1;
243 		}
244 		onToggledListeners ~= dlg;
245 	}
246 	extern(C) static void callBackToggled(GtkCheckMenuItem* checkmenuitemStruct, CheckMenuItem _checkmenuitem)
247 	{
248 		foreach ( void delegate(CheckMenuItem) dlg; _checkmenuitem.onToggledListeners )
249 		{
250 			dlg(_checkmenuitem);
251 		}
252 	}
253 }