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 /** */ 173 public static GType getType() 174 { 175 return gtk_radio_menu_item_get_type(); 176 } 177 178 /** 179 * Creates a new #GtkRadioMenuItem. 180 * 181 * Params: 182 * group = the group to which the 183 * radio menu item is to be attached, or %NULL 184 * 185 * Return: a new #GtkRadioMenuItem 186 * 187 * Throws: ConstructionException GTK+ fails to create the object. 188 */ 189 public this(ListSG group) 190 { 191 auto p = gtk_radio_menu_item_new((group is null) ? null : group.getListSGStruct()); 192 193 if(p is null) 194 { 195 throw new ConstructionException("null returned by new"); 196 } 197 198 this(cast(GtkRadioMenuItem*) p); 199 } 200 201 /** 202 * Creates a new #GtkRadioMenuItem adding it to the same group as @group. 203 * 204 * Params: 205 * group = An existing #GtkRadioMenuItem 206 * 207 * Return: The new #GtkRadioMenuItem 208 * 209 * Since: 2.4 210 * 211 * Throws: ConstructionException GTK+ fails to create the object. 212 */ 213 public this(RadioMenuItem group) 214 { 215 auto p = gtk_radio_menu_item_new_from_widget((group is null) ? null : group.getRadioMenuItemStruct()); 216 217 if(p is null) 218 { 219 throw new ConstructionException("null returned by new_from_widget"); 220 } 221 222 this(cast(GtkRadioMenuItem*) p); 223 } 224 225 /** 226 * Returns the group to which the radio menu item belongs, as a #GList of 227 * #GtkRadioMenuItem. The list belongs to GTK+ and should not be freed. 228 * 229 * Return: the group 230 * of @radio_menu_item 231 */ 232 public ListSG getGroup() 233 { 234 auto p = gtk_radio_menu_item_get_group(gtkRadioMenuItem); 235 236 if(p is null) 237 { 238 return null; 239 } 240 241 return new ListSG(cast(GSList*) p); 242 } 243 244 /** 245 * Joins a #GtkRadioMenuItem object to the group of another #GtkRadioMenuItem 246 * object. 247 * 248 * This function should be used by language bindings to avoid the memory 249 * manangement of the opaque #GSList of gtk_radio_menu_item_get_group() 250 * and gtk_radio_menu_item_set_group(). 251 * 252 * A common way to set up a group of #GtkRadioMenuItem instances is: 253 * 254 * |[ 255 * GtkRadioMenuItem *last_item = NULL; 256 * 257 * while ( ...more items to add... ) 258 * { 259 * GtkRadioMenuItem *radio_item; 260 * 261 * radio_item = gtk_radio_menu_item_new (...); 262 * 263 * gtk_radio_menu_item_join_group (radio_item, last_item); 264 * last_item = radio_item; 265 * } 266 * ]| 267 * 268 * Params: 269 * groupSource = a #GtkRadioMenuItem whose group we are 270 * joining, or %NULL to remove the @radio_menu_item from its current 271 * group 272 * 273 * Since: 3.18 274 */ 275 public void joinGroup(RadioMenuItem groupSource) 276 { 277 gtk_radio_menu_item_join_group(gtkRadioMenuItem, (groupSource is null) ? null : groupSource.getRadioMenuItemStruct()); 278 } 279 280 /** 281 * Sets the group of a radio menu item, or changes it. 282 * 283 * Params: 284 * group = the new group, or %NULL. 285 */ 286 public void setGroup(ListSG group) 287 { 288 gtk_radio_menu_item_set_group(gtkRadioMenuItem, (group is null) ? null : group.getListSGStruct()); 289 } 290 291 int[string] connectedSignals; 292 293 void delegate(RadioMenuItem)[] onGroupChangedListeners; 294 /** */ 295 void addOnGroupChanged(void delegate(RadioMenuItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 296 { 297 if ( "group-changed" !in connectedSignals ) 298 { 299 Signals.connectData( 300 this, 301 "group-changed", 302 cast(GCallback)&callBackGroupChanged, 303 cast(void*)this, 304 null, 305 connectFlags); 306 connectedSignals["group-changed"] = 1; 307 } 308 onGroupChangedListeners ~= dlg; 309 } 310 extern(C) static void callBackGroupChanged(GtkRadioMenuItem* radiomenuitemStruct, RadioMenuItem _radiomenuitem) 311 { 312 foreach ( void delegate(RadioMenuItem) dlg; _radiomenuitem.onGroupChangedListeners ) 313 { 314 dlg(_radiomenuitem); 315 } 316 } 317 }