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.RadioAction; 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.ToggleAction; 33 private import gtkc.gtk; 34 public import gtkc.gtktypes; 35 private import std.algorithm; 36 37 38 /** 39 * A #GtkRadioAction is similar to #GtkRadioMenuItem. A number of radio 40 * actions can be linked together so that only one may be active at any 41 * one time. 42 */ 43 public class RadioAction : ToggleAction 44 { 45 /** the main Gtk struct */ 46 protected GtkRadioAction* gtkRadioAction; 47 48 /** Get the main Gtk struct */ 49 public GtkRadioAction* getRadioActionStruct(bool transferOwnership = false) 50 { 51 if (transferOwnership) 52 ownedRef = false; 53 return gtkRadioAction; 54 } 55 56 /** the main Gtk struct as a void* */ 57 protected override void* getStruct() 58 { 59 return cast(void*)gtkRadioAction; 60 } 61 62 protected override void setStruct(GObject* obj) 63 { 64 gtkRadioAction = cast(GtkRadioAction*)obj; 65 super.setStruct(obj); 66 } 67 68 /** 69 * Sets our main struct and passes it to the parent class. 70 */ 71 public this (GtkRadioAction* gtkRadioAction, bool ownedRef = false) 72 { 73 this.gtkRadioAction = gtkRadioAction; 74 super(cast(GtkToggleAction*)gtkRadioAction, ownedRef); 75 } 76 77 /** 78 * Creates a new RadioAction object. To add the action to 79 * a ActionGroup and set the accelerator for the action, 80 * call gtk.ActionGroup.ActionGroup.addActionWithAccel(). 81 * 82 * Since: 2.4 83 * 84 * Params: 85 * name = A unique name for the action 86 * label = The label displayed in menu items and on buttons, or null 87 * tooltip = A tooltip for this action, or null 88 * stockId = The stock icon to display in widgets representing this 89 * action, or null 90 * value = The value which getCurrentValue() should 91 * return if this action is selected. 92 * Throws: ConstructionException GTK+ fails to create the object. 93 */ 94 public this (string name, string label, string tooltip, StockID stockId, int value) 95 { 96 this(name, label, tooltip, cast(string)stockId, value); 97 } 98 99 /** 100 */ 101 102 /** */ 103 public static GType getType() 104 { 105 return gtk_radio_action_get_type(); 106 } 107 108 /** 109 * Creates a new #GtkRadioAction object. To add the action to 110 * a #GtkActionGroup and set the accelerator for the action, 111 * call gtk_action_group_add_action_with_accel(). 112 * 113 * Params: 114 * name = A unique name for the action 115 * label = The label displayed in menu items and on buttons, 116 * or %NULL 117 * tooltip = A tooltip for this action, or %NULL 118 * stockId = The stock icon to display in widgets representing 119 * this action, or %NULL 120 * value = The value which gtk_radio_action_get_current_value() should 121 * return if this action is selected. 122 * 123 * Returns: a new #GtkRadioAction 124 * 125 * Since: 2.4 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this(string name, string label, string tooltip, string stockId, int value) 130 { 131 auto p = gtk_radio_action_new(Str.toStringz(name), Str.toStringz(label), Str.toStringz(tooltip), Str.toStringz(stockId), value); 132 133 if(p is null) 134 { 135 throw new ConstructionException("null returned by new"); 136 } 137 138 this(cast(GtkRadioAction*) p, true); 139 } 140 141 /** 142 * Obtains the value property of the currently active member of 143 * the group to which @action belongs. 144 * 145 * Returns: The value of the currently active group member 146 * 147 * Since: 2.4 148 */ 149 public int getCurrentValue() 150 { 151 return gtk_radio_action_get_current_value(gtkRadioAction); 152 } 153 154 /** 155 * Returns the list representing the radio group for this object. 156 * Note that the returned list is only valid until the next change 157 * to the group. 158 * 159 * A common way to set up a group of radio group is the following: 160 * |[<!-- language="C" --> 161 * GSList *group = NULL; 162 * GtkRadioAction *action; 163 * 164 * while ( ...more actions to add... /) 165 * { 166 * action = gtk_radio_action_new (...); 167 * 168 * gtk_radio_action_set_group (action, group); 169 * group = gtk_radio_action_get_group (action); 170 * } 171 * ]| 172 * 173 * Returns: the list representing the radio group for this object 174 * 175 * Since: 2.4 176 */ 177 public ListSG getGroup() 178 { 179 auto p = gtk_radio_action_get_group(gtkRadioAction); 180 181 if(p is null) 182 { 183 return null; 184 } 185 186 return new ListSG(cast(GSList*) p); 187 } 188 189 /** 190 * Joins a radio action object to the group of another radio action object. 191 * 192 * Use this in language bindings instead of the gtk_radio_action_get_group() 193 * and gtk_radio_action_set_group() methods 194 * 195 * A common way to set up a group of radio actions is the following: 196 * |[<!-- language="C" --> 197 * GtkRadioAction *action; 198 * GtkRadioAction *last_action; 199 * 200 * while ( ...more actions to add... /) 201 * { 202 * action = gtk_radio_action_new (...); 203 * 204 * gtk_radio_action_join_group (action, last_action); 205 * last_action = action; 206 * } 207 * ]| 208 * 209 * Params: 210 * groupSource = a radio action object whos group we are 211 * joining, or %NULL to remove the radio action from its group 212 * 213 * Since: 3.0 214 */ 215 public void joinGroup(RadioAction groupSource) 216 { 217 gtk_radio_action_join_group(gtkRadioAction, (groupSource is null) ? null : groupSource.getRadioActionStruct()); 218 } 219 220 /** 221 * Sets the currently active group member to the member with value 222 * property @current_value. 223 * 224 * Params: 225 * currentValue = the new value 226 * 227 * Since: 2.10 228 */ 229 public void setCurrentValue(int currentValue) 230 { 231 gtk_radio_action_set_current_value(gtkRadioAction, currentValue); 232 } 233 234 /** 235 * Sets the radio group for the radio action object. 236 * 237 * Params: 238 * group = a list representing a radio group, or %NULL 239 * 240 * Since: 2.4 241 */ 242 public void setGroup(ListSG group) 243 { 244 gtk_radio_action_set_group(gtkRadioAction, (group is null) ? null : group.getListSGStruct()); 245 } 246 247 protected class OnChangedDelegateWrapper 248 { 249 void delegate(RadioAction, RadioAction) dlg; 250 gulong handlerId; 251 252 this(void delegate(RadioAction, RadioAction) dlg) 253 { 254 this.dlg = dlg; 255 onChangedListeners ~= this; 256 } 257 258 void remove(OnChangedDelegateWrapper source) 259 { 260 foreach(index, wrapper; onChangedListeners) 261 { 262 if (wrapper.handlerId == source.handlerId) 263 { 264 onChangedListeners[index] = null; 265 onChangedListeners = std.algorithm.remove(onChangedListeners, index); 266 break; 267 } 268 } 269 } 270 } 271 OnChangedDelegateWrapper[] onChangedListeners; 272 273 /** 274 * The ::changed signal is emitted on every member of a radio group when the 275 * active member is changed. The signal gets emitted after the ::activate signals 276 * for the previous and current active members. 277 * 278 * Params: 279 * current = the member of @action's group which has just been activated 280 * 281 * Since: 2.4 282 */ 283 gulong addOnChanged(void delegate(RadioAction, RadioAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 284 { 285 auto wrapper = new OnChangedDelegateWrapper(dlg); 286 wrapper.handlerId = Signals.connectData( 287 this, 288 "changed", 289 cast(GCallback)&callBackChanged, 290 cast(void*)wrapper, 291 cast(GClosureNotify)&callBackChangedDestroy, 292 connectFlags); 293 return wrapper.handlerId; 294 } 295 296 extern(C) static void callBackChanged(GtkRadioAction* radioactionStruct, GtkRadioAction* current, OnChangedDelegateWrapper wrapper) 297 { 298 wrapper.dlg(ObjectG.getDObject!(RadioAction)(current), wrapper.outer); 299 } 300 301 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 302 { 303 wrapper.remove(wrapper); 304 } 305 }