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.RadioMenuItem;
26 
27 private import glib.ConstructionException;
28 private import glib.ListSG;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.CheckMenuItem;
33 private import gtk.Widget;
34 public  import gtkc.gdktypes;
35 private import gtkc.gtk;
36 public  import gtkc.gtktypes;
37 
38 
39 /**
40  * A radio menu item is a check menu item that belongs to a group. At each
41  * instant exactly one of the radio menu items from a group is selected.
42  * 
43  * The group list does not need to be freed, as each #GtkRadioMenuItem will
44  * remove itself and its list item when it is destroyed.
45  * 
46  * The correct way to create a group of radio menu items is approximatively
47  * this:
48  * 
49  * ## How to create a group of radio menu items.
50  * 
51  * |[<!-- language="C" -->
52  * GSList *group = NULL;
53  * GtkWidget *item;
54  * gint i;
55  * 
56  * for (i = 0; i < 5; i++)
57  * {
58  * item = gtk_radio_menu_item_new_with_label (group, "This is an example");
59  * group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (item));
60  * if (i == 1)
61  * gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
62  * }
63  * ]|
64  * 
65  * # CSS nodes
66  * 
67  * |[<!-- language="plain" -->
68  * menuitem
69  * ├── radio.left
70  * ╰── <child>
71  * ]|
72  * 
73  * GtkRadioMenuItem has a main CSS node with name menuitem, and a subnode
74  * with name radio, which gets the .left or .right style class.
75  */
76 public class RadioMenuItem : CheckMenuItem
77 {
78 	/** the main Gtk struct */
79 	protected GtkRadioMenuItem* gtkRadioMenuItem;
80 
81 	/** Get the main Gtk struct */
82 	public GtkRadioMenuItem* getRadioMenuItemStruct()
83 	{
84 		return gtkRadioMenuItem;
85 	}
86 
87 	/** the main Gtk struct as a void* */
88 	protected override void* getStruct()
89 	{
90 		return cast(void*)gtkRadioMenuItem;
91 	}
92 
93 	protected override void setStruct(GObject* obj)
94 	{
95 		gtkRadioMenuItem = cast(GtkRadioMenuItem*)obj;
96 		super.setStruct(obj);
97 	}
98 
99 	/**
100 	 * Sets our main struct and passes it to the parent class.
101 	 */
102 	public this (GtkRadioMenuItem* gtkRadioMenuItem, bool ownedRef = false)
103 	{
104 		this.gtkRadioMenuItem = gtkRadioMenuItem;
105 		super(cast(GtkCheckMenuItem*)gtkRadioMenuItem, ownedRef);
106 	}
107 
108 	/**
109 	 * Creates a new GtkRadioMenuItem whose child is a simple GtkLabel.
110 	 * The new GtkRadioMenuItem is added to the same group as group.
111 	 * If mnemonic is true the label will be
112 	 * created using gtk_label_new_with_mnemonic(), so underscores in label
113 	 * indicate the mnemonic for the menu item.
114 	 * Since 2.4
115 	 * Params:
116 	 *  group = an existing GtkRadioMenuItem
117 	 *  label = the text for the label
118 	 * Throws: ConstructionException GTK+ fails to create the object.
119 	 */
120 	public this (RadioMenuItem radioMenuItem, string label, bool mnemonic=true)
121 	{
122 		GtkRadioMenuItem* p;
123 		
124 		if ( mnemonic )
125 		{
126 			// GtkWidget* gtk_radio_menu_item_new_with_mnemonic_from_widget  (GtkRadioMenuItem *group,  const gchar *label);
127 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_mnemonic_from_widget(
128 			radioMenuItem.getRadioMenuItemStruct(), Str.toStringz(label));
129 		}
130 		else
131 		{
132 			// GtkWidget* gtk_radio_menu_item_new_with_label_from_widget  (GtkRadioMenuItem *group,  const gchar *label);
133 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_label_from_widget(
134 			radioMenuItem.getRadioMenuItemStruct(), Str.toStringz(label));
135 		}
136 		
137 		if(p is null)
138 		{
139 			throw new ConstructionException("null returned by gtk_radio_menu_item_new_with_");
140 		}
141 		
142 		this(p);
143 	}
144 	
145 	/**
146 	 * Creates a new GtkRadioMenuItem whose child is a simple GtkLabel.
147 	 * Params:
148 	 *  group = the group to which the radio menu item is to be attached
149 	 *  label = the text for the label
150 	 *  mnemonic = if true the label
151 	 *  will be created using gtk_label_new_with_mnemonic(), so underscores
152 	 *  in label indicate the mnemonic for the menu item.
153 	 * Throws: ConstructionException GTK+ fails to create the object.
154 	 */
155 	public this (ListSG group, string label, bool mnemonic=true)
156 	{
157 		GtkRadioMenuItem* p;
158 		
159 		if ( mnemonic )
160 		{
161 			// GtkWidget* gtk_radio_menu_item_new_with_mnemonic  (GSList *group,  const gchar *label);
162 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_mnemonic(
163 			group is null ? null : group.getListSGStruct(), Str.toStringz(label));
164 		}
165 		else
166 		{
167 			// GtkWidget* gtk_radio_menu_item_new_with_label  (GSList *group,  const gchar *label);
168 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_label(
169 			group is null ? null : group.getListSGStruct(), Str.toStringz(label));
170 		}
171 		
172 		if(p is null)
173 		{
174 			throw new ConstructionException("null returned by gtk_radio_menu_item_new_with_");
175 		}
176 		
177 		this(p);
178 	}
179 
180 	/**
181 	 */
182 
183 	/** */
184 	public static GType getType()
185 	{
186 		return gtk_radio_menu_item_get_type();
187 	}
188 
189 	/**
190 	 * Creates a new #GtkRadioMenuItem.
191 	 *
192 	 * Params:
193 	 *     group = the group to which the
194 	 *         radio menu item is to be attached, or %NULL
195 	 *
196 	 * Return: a new #GtkRadioMenuItem
197 	 *
198 	 * Throws: ConstructionException GTK+ fails to create the object.
199 	 */
200 	public this(ListSG group)
201 	{
202 		auto p = gtk_radio_menu_item_new((group is null) ? null : group.getListSGStruct());
203 		
204 		if(p is null)
205 		{
206 			throw new ConstructionException("null returned by new");
207 		}
208 		
209 		this(cast(GtkRadioMenuItem*) p);
210 	}
211 
212 	/**
213 	 * Creates a new #GtkRadioMenuItem adding it to the same group as @group.
214 	 *
215 	 * Params:
216 	 *     group = An existing #GtkRadioMenuItem
217 	 *
218 	 * Return: The new #GtkRadioMenuItem
219 	 *
220 	 * Since: 2.4
221 	 *
222 	 * Throws: ConstructionException GTK+ fails to create the object.
223 	 */
224 	public this(RadioMenuItem group)
225 	{
226 		auto p = gtk_radio_menu_item_new_from_widget((group is null) ? null : group.getRadioMenuItemStruct());
227 		
228 		if(p is null)
229 		{
230 			throw new ConstructionException("null returned by new_from_widget");
231 		}
232 		
233 		this(cast(GtkRadioMenuItem*) p);
234 	}
235 
236 	/**
237 	 * Returns the group to which the radio menu item belongs, as a #GList of
238 	 * #GtkRadioMenuItem. The list belongs to GTK+ and should not be freed.
239 	 *
240 	 * Return: the group
241 	 *     of @radio_menu_item
242 	 */
243 	public ListSG getGroup()
244 	{
245 		auto p = gtk_radio_menu_item_get_group(gtkRadioMenuItem);
246 		
247 		if(p is null)
248 		{
249 			return null;
250 		}
251 		
252 		return new ListSG(cast(GSList*) p);
253 	}
254 
255 	/**
256 	 * Joins a #GtkRadioMenuItem object to the group of another #GtkRadioMenuItem
257 	 * object.
258 	 *
259 	 * This function should be used by language bindings to avoid the memory
260 	 * manangement of the opaque #GSList of gtk_radio_menu_item_get_group()
261 	 * and gtk_radio_menu_item_set_group().
262 	 *
263 	 * A common way to set up a group of #GtkRadioMenuItem instances is:
264 	 *
265 	 * |[
266 	 * GtkRadioMenuItem *last_item = NULL;
267 	 *
268 	 * while ( ...more items to add... )
269 	 * {
270 	 * GtkRadioMenuItem *radio_item;
271 	 *
272 	 * radio_item = gtk_radio_menu_item_new (...);
273 	 *
274 	 * gtk_radio_menu_item_join_group (radio_item, last_item);
275 	 * last_item = radio_item;
276 	 * }
277 	 * ]|
278 	 *
279 	 * Params:
280 	 *     groupSource = a #GtkRadioMenuItem whose group we are
281 	 *         joining, or %NULL to remove the @radio_menu_item from its current
282 	 *         group
283 	 *
284 	 * Since: 3.18
285 	 */
286 	public void joinGroup(RadioMenuItem groupSource)
287 	{
288 		gtk_radio_menu_item_join_group(gtkRadioMenuItem, (groupSource is null) ? null : groupSource.getRadioMenuItemStruct());
289 	}
290 
291 	/**
292 	 * Sets the group of a radio menu item, or changes it.
293 	 *
294 	 * Params:
295 	 *     group = the new group, or %NULL.
296 	 */
297 	public void setGroup(ListSG group)
298 	{
299 		gtk_radio_menu_item_set_group(gtkRadioMenuItem, (group is null) ? null : group.getListSGStruct());
300 	}
301 
302 	int[string] connectedSignals;
303 
304 	void delegate(RadioMenuItem)[] onGroupChangedListeners;
305 	/** */
306 	void addOnGroupChanged(void delegate(RadioMenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
307 	{
308 		if ( "group-changed" !in connectedSignals )
309 		{
310 			Signals.connectData(
311 				this,
312 				"group-changed",
313 				cast(GCallback)&callBackGroupChanged,
314 				cast(void*)this,
315 				null,
316 				connectFlags);
317 			connectedSignals["group-changed"] = 1;
318 		}
319 		onGroupChangedListeners ~= dlg;
320 	}
321 	extern(C) static void callBackGroupChanged(GtkRadioMenuItem* radiomenuitemStruct, RadioMenuItem _radiomenuitem)
322 	{
323 		foreach ( void delegate(RadioMenuItem) dlg; _radiomenuitem.onGroupChangedListeners )
324 		{
325 			dlg(_radiomenuitem);
326 		}
327 	}
328 }