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