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 public class RadioMenuItem : CheckMenuItem
66 {
67 	/** the main Gtk struct */
68 	protected GtkRadioMenuItem* gtkRadioMenuItem;
69 
70 	/** Get the main Gtk struct */
71 	public GtkRadioMenuItem* getRadioMenuItemStruct()
72 	{
73 		return gtkRadioMenuItem;
74 	}
75 
76 	/** the main Gtk struct as a void* */
77 	protected override void* getStruct()
78 	{
79 		return cast(void*)gtkRadioMenuItem;
80 	}
81 
82 	protected override void setStruct(GObject* obj)
83 	{
84 		gtkRadioMenuItem = cast(GtkRadioMenuItem*)obj;
85 		super.setStruct(obj);
86 	}
87 
88 	/**
89 	 * Sets our main struct and passes it to the parent class.
90 	 */
91 	public this (GtkRadioMenuItem* gtkRadioMenuItem, bool ownedRef = false)
92 	{
93 		this.gtkRadioMenuItem = gtkRadioMenuItem;
94 		super(cast(GtkCheckMenuItem*)gtkRadioMenuItem, ownedRef);
95 	}
96 
97 	/**
98 	 * Creates a new GtkRadioMenuItem whose child is a simple GtkLabel.
99 	 * The new GtkRadioMenuItem is added to the same group as group.
100 	 * If mnemonic is true the label will be
101 	 * created using gtk_label_new_with_mnemonic(), so underscores in label
102 	 * indicate the mnemonic for the menu item.
103 	 * Since 2.4
104 	 * Params:
105 	 *  group = an existing GtkRadioMenuItem
106 	 *  label = the text for the label
107 	 * Throws: ConstructionException GTK+ fails to create the object.
108 	 */
109 	public this (RadioMenuItem radioMenuItem, string label, bool mnemonic=true)
110 	{
111 		GtkRadioMenuItem* p;
112 		
113 		if ( mnemonic )
114 		{
115 			// GtkWidget* gtk_radio_menu_item_new_with_mnemonic_from_widget  (GtkRadioMenuItem *group,  const gchar *label);
116 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_mnemonic_from_widget(
117 			radioMenuItem.getRadioMenuItemStruct(), Str.toStringz(label));
118 		}
119 		else
120 		{
121 			// GtkWidget* gtk_radio_menu_item_new_with_label_from_widget  (GtkRadioMenuItem *group,  const gchar *label);
122 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_label_from_widget(
123 			radioMenuItem.getRadioMenuItemStruct(), Str.toStringz(label));
124 		}
125 		
126 		if(p is null)
127 		{
128 			throw new ConstructionException("null returned by gtk_radio_menu_item_new_with_");
129 		}
130 		
131 		this(p);
132 	}
133 	
134 	/**
135 	 * Creates a new GtkRadioMenuItem whose child is a simple GtkLabel.
136 	 * Params:
137 	 *  group = the group to which the radio menu item is to be attached
138 	 *  label = the text for the label
139 	 *  mnemonic = if true the label
140 	 *  will be created using gtk_label_new_with_mnemonic(), so underscores
141 	 *  in label indicate the mnemonic for the menu item.
142 	 * Throws: ConstructionException GTK+ fails to create the object.
143 	 */
144 	public this (ListSG group, string label, bool mnemonic=true)
145 	{
146 		GtkRadioMenuItem* p;
147 		
148 		if ( mnemonic )
149 		{
150 			// GtkWidget* gtk_radio_menu_item_new_with_mnemonic  (GSList *group,  const gchar *label);
151 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_mnemonic(
152 			group is null ? null : group.getListSGStruct(), Str.toStringz(label));
153 		}
154 		else
155 		{
156 			// GtkWidget* gtk_radio_menu_item_new_with_label  (GSList *group,  const gchar *label);
157 			p = cast(GtkRadioMenuItem*)gtk_radio_menu_item_new_with_label(
158 			group is null ? null : group.getListSGStruct(), Str.toStringz(label));
159 		}
160 		
161 		if(p is null)
162 		{
163 			throw new ConstructionException("null returned by gtk_radio_menu_item_new_with_");
164 		}
165 		
166 		this(p);
167 	}
168 
169 	/**
170 	 */
171 
172 	public static GType getType()
173 	{
174 		return gtk_radio_menu_item_get_type();
175 	}
176 
177 	/**
178 	 * Creates a new #GtkRadioMenuItem.
179 	 *
180 	 * Params:
181 	 *     group = the group to which the
182 	 *         radio menu item is to be attached, or %NULL
183 	 *
184 	 * Return: a new #GtkRadioMenuItem
185 	 *
186 	 * Throws: ConstructionException GTK+ fails to create the object.
187 	 */
188 	public this(ListSG group)
189 	{
190 		auto p = gtk_radio_menu_item_new((group is null) ? null : group.getListSGStruct());
191 		
192 		if(p is null)
193 		{
194 			throw new ConstructionException("null returned by new");
195 		}
196 		
197 		this(cast(GtkRadioMenuItem*) p);
198 	}
199 
200 	/**
201 	 * Creates a new #GtkRadioMenuItem adding it to the same group as @group.
202 	 *
203 	 * Params:
204 	 *     group = An existing #GtkRadioMenuItem
205 	 *
206 	 * Return: The new #GtkRadioMenuItem
207 	 *
208 	 * Since: 2.4
209 	 *
210 	 * Throws: ConstructionException GTK+ fails to create the object.
211 	 */
212 	public this(RadioMenuItem group)
213 	{
214 		auto p = gtk_radio_menu_item_new_from_widget((group is null) ? null : group.getRadioMenuItemStruct());
215 		
216 		if(p is null)
217 		{
218 			throw new ConstructionException("null returned by new_from_widget");
219 		}
220 		
221 		this(cast(GtkRadioMenuItem*) p);
222 	}
223 
224 	/**
225 	 * Returns the group to which the radio menu item belongs, as a #GList of
226 	 * #GtkRadioMenuItem. The list belongs to GTK+ and should not be freed.
227 	 *
228 	 * Return: the group
229 	 *     of @radio_menu_item
230 	 */
231 	public ListSG getGroup()
232 	{
233 		auto p = gtk_radio_menu_item_get_group(gtkRadioMenuItem);
234 		
235 		if(p is null)
236 		{
237 			return null;
238 		}
239 		
240 		return new ListSG(cast(GSList*) p);
241 	}
242 
243 	/**
244 	 * Sets the group of a radio menu item, or changes it.
245 	 *
246 	 * Params:
247 	 *     group = the new group, or %NULL.
248 	 */
249 	public void setGroup(ListSG group)
250 	{
251 		gtk_radio_menu_item_set_group(gtkRadioMenuItem, (group is null) ? null : group.getListSGStruct());
252 	}
253 
254 	int[string] connectedSignals;
255 
256 	void delegate(RadioMenuItem)[] onGroupChangedListeners;
257 	void addOnGroupChanged(void delegate(RadioMenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
258 	{
259 		if ( "group-changed" !in connectedSignals )
260 		{
261 			Signals.connectData(
262 				this,
263 				"group-changed",
264 				cast(GCallback)&callBackGroupChanged,
265 				cast(void*)this,
266 				null,
267 				connectFlags);
268 			connectedSignals["group-changed"] = 1;
269 		}
270 		onGroupChangedListeners ~= dlg;
271 	}
272 	extern(C) static void callBackGroupChanged(GtkRadioMenuItem* radiomenuitemStruct, RadioMenuItem _radiomenuitem)
273 	{
274 		foreach ( void delegate(RadioMenuItem) dlg; _radiomenuitem.onGroupChangedListeners )
275 		{
276 			dlg(_radiomenuitem);
277 		}
278 	}
279 }