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 	public static GType getType()
115 	{
116 		return gtk_check_menu_item_get_type();
117 	}
118 
119 	/**
120 	 * Creates a new #GtkCheckMenuItem.
121 	 *
122 	 * Return: a new #GtkCheckMenuItem.
123 	 *
124 	 * Throws: ConstructionException GTK+ fails to create the object.
125 	 */
126 	public this()
127 	{
128 		auto p = gtk_check_menu_item_new();
129 		
130 		if(p is null)
131 		{
132 			throw new ConstructionException("null returned by new");
133 		}
134 		
135 		this(cast(GtkCheckMenuItem*) p);
136 	}
137 
138 	/**
139 	 * Returns whether the check menu item is active. See
140 	 * gtk_check_menu_item_set_active ().
141 	 *
142 	 * Return: %TRUE if the menu item is checked.
143 	 */
144 	public bool getActive()
145 	{
146 		return gtk_check_menu_item_get_active(gtkCheckMenuItem) != 0;
147 	}
148 
149 	/**
150 	 * Returns whether @check_menu_item looks like a #GtkRadioMenuItem
151 	 *
152 	 * Return: Whether @check_menu_item looks like a #GtkRadioMenuItem
153 	 *
154 	 * Since: 2.4
155 	 */
156 	public bool getDrawAsRadio()
157 	{
158 		return gtk_check_menu_item_get_draw_as_radio(gtkCheckMenuItem) != 0;
159 	}
160 
161 	/**
162 	 * Retrieves the value set by gtk_check_menu_item_set_inconsistent().
163 	 *
164 	 * Return: %TRUE if inconsistent
165 	 */
166 	public bool getInconsistent()
167 	{
168 		return gtk_check_menu_item_get_inconsistent(gtkCheckMenuItem) != 0;
169 	}
170 
171 	/**
172 	 * Sets the active state of the menu item’s check box.
173 	 *
174 	 * Params:
175 	 *     isActive = boolean value indicating whether the check box is active.
176 	 */
177 	public void setActive(bool isActive)
178 	{
179 		gtk_check_menu_item_set_active(gtkCheckMenuItem, isActive);
180 	}
181 
182 	/**
183 	 * Sets whether @check_menu_item is drawn like a #GtkRadioMenuItem
184 	 *
185 	 * Params:
186 	 *     drawAsRadio = whether @check_menu_item is drawn like a #GtkRadioMenuItem
187 	 *
188 	 * Since: 2.4
189 	 */
190 	public void setDrawAsRadio(bool drawAsRadio)
191 	{
192 		gtk_check_menu_item_set_draw_as_radio(gtkCheckMenuItem, drawAsRadio);
193 	}
194 
195 	/**
196 	 * If the user has selected a range of elements (such as some text or
197 	 * spreadsheet cells) that are affected by a boolean setting, and the
198 	 * current values in that range are inconsistent, you may want to
199 	 * display the check in an “in between” state. This function turns on
200 	 * “in between” display.  Normally you would turn off the inconsistent
201 	 * state again if the user explicitly selects a setting. This has to be
202 	 * done manually, gtk_check_menu_item_set_inconsistent() only affects
203 	 * visual appearance, it doesn’t affect the semantics of the widget.
204 	 *
205 	 * Params:
206 	 *     setting = %TRUE to display an “inconsistent” third state check
207 	 */
208 	public void setInconsistent(bool setting)
209 	{
210 		gtk_check_menu_item_set_inconsistent(gtkCheckMenuItem, setting);
211 	}
212 
213 	/**
214 	 * Emits the #GtkCheckMenuItem::toggled signal.
215 	 */
216 	public void toggled()
217 	{
218 		gtk_check_menu_item_toggled(gtkCheckMenuItem);
219 	}
220 
221 	int[string] connectedSignals;
222 
223 	void delegate(CheckMenuItem)[] onToggledListeners;
224 	/**
225 	 * This signal is emitted when the state of the check box is changed.
226 	 *
227 	 * A signal handler can use gtk_check_menu_item_get_active()
228 	 * to discover the new state.
229 	 */
230 	void addOnToggled(void delegate(CheckMenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
231 	{
232 		if ( "toggled" !in connectedSignals )
233 		{
234 			Signals.connectData(
235 				this,
236 				"toggled",
237 				cast(GCallback)&callBackToggled,
238 				cast(void*)this,
239 				null,
240 				connectFlags);
241 			connectedSignals["toggled"] = 1;
242 		}
243 		onToggledListeners ~= dlg;
244 	}
245 	extern(C) static void callBackToggled(GtkCheckMenuItem* checkmenuitemStruct, CheckMenuItem _checkmenuitem)
246 	{
247 		foreach ( void delegate(CheckMenuItem) dlg; _checkmenuitem.onToggledListeners )
248 		{
249 			dlg(_checkmenuitem);
250 		}
251 	}
252 }