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.ToggleAction; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.Action; 32 private import gtkc.gtk; 33 public import gtkc.gtktypes; 34 private import std.algorithm; 35 36 37 /** 38 * A #GtkToggleAction corresponds roughly to a #GtkCheckMenuItem. It has an 39 * “active” state specifying whether the action has been checked or not. 40 */ 41 public class ToggleAction : Action 42 { 43 /** the main Gtk struct */ 44 protected GtkToggleAction* gtkToggleAction; 45 46 /** Get the main Gtk struct */ 47 public GtkToggleAction* getToggleActionStruct(bool transferOwnership = false) 48 { 49 if (transferOwnership) 50 ownedRef = false; 51 return gtkToggleAction; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected override void* getStruct() 56 { 57 return cast(void*)gtkToggleAction; 58 } 59 60 protected override void setStruct(GObject* obj) 61 { 62 gtkToggleAction = cast(GtkToggleAction*)obj; 63 super.setStruct(obj); 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GtkToggleAction* gtkToggleAction, bool ownedRef = false) 70 { 71 this.gtkToggleAction = gtkToggleAction; 72 super(cast(GtkAction*)gtkToggleAction, ownedRef); 73 } 74 75 /** 76 * Creates a new ToggleAction object. To add the action to 77 * a ActionGroup and set the accelerator for the action, 78 * call gtk.ActionGroup.ActionGroup.addActionWithAccel(). 79 * 80 * Since: 2.4 81 * 82 * Params: 83 * name = A unique name for the action 84 * label = The label displayed in menu items and on buttons, or null 85 * tooltip = A tooltip for the action, or null 86 * stockId = The stock icon to display in widgets representing the 87 * action, or null 88 * Throws: ConstructionException GTK+ fails to create the object. 89 */ 90 public this (string name, string label, string tooltip, StockID stockId) 91 { 92 this(name, label, tooltip, cast(string)stockId); 93 } 94 95 /** 96 */ 97 98 /** */ 99 public static GType getType() 100 { 101 return gtk_toggle_action_get_type(); 102 } 103 104 /** 105 * Creates a new #GtkToggleAction object. To add the action to 106 * a #GtkActionGroup and set the accelerator for the action, 107 * call gtk_action_group_add_action_with_accel(). 108 * 109 * Params: 110 * name = A unique name for the action 111 * label = The label displayed in menu items and on buttons, 112 * or %NULL 113 * tooltip = A tooltip for the action, or %NULL 114 * stockId = The stock icon to display in widgets representing 115 * the action, or %NULL 116 * 117 * Returns: a new #GtkToggleAction 118 * 119 * Since: 2.4 120 * 121 * Throws: ConstructionException GTK+ fails to create the object. 122 */ 123 public this(string name, string label, string tooltip, string stockId) 124 { 125 auto p = gtk_toggle_action_new(Str.toStringz(name), Str.toStringz(label), Str.toStringz(tooltip), Str.toStringz(stockId)); 126 127 if(p is null) 128 { 129 throw new ConstructionException("null returned by new"); 130 } 131 132 this(cast(GtkToggleAction*) p, true); 133 } 134 135 /** 136 * Returns the checked state of the toggle action. 137 * 138 * Returns: the checked state of the toggle action 139 * 140 * Since: 2.4 141 */ 142 public bool getActive() 143 { 144 return gtk_toggle_action_get_active(gtkToggleAction) != 0; 145 } 146 147 /** 148 * Returns whether the action should have proxies like a radio action. 149 * 150 * Returns: whether the action should have proxies like a radio action. 151 * 152 * Since: 2.4 153 */ 154 public bool getDrawAsRadio() 155 { 156 return gtk_toggle_action_get_draw_as_radio(gtkToggleAction) != 0; 157 } 158 159 /** 160 * Sets the checked state on the toggle action. 161 * 162 * Params: 163 * isActive = whether the action should be checked or not 164 * 165 * Since: 2.4 166 */ 167 public void setActive(bool isActive) 168 { 169 gtk_toggle_action_set_active(gtkToggleAction, isActive); 170 } 171 172 /** 173 * Sets whether the action should have proxies like a radio action. 174 * 175 * Params: 176 * drawAsRadio = whether the action should have proxies like a radio 177 * action 178 * 179 * Since: 2.4 180 */ 181 public void setDrawAsRadio(bool drawAsRadio) 182 { 183 gtk_toggle_action_set_draw_as_radio(gtkToggleAction, drawAsRadio); 184 } 185 186 /** 187 * Emits the “toggled” signal on the toggle action. 188 * 189 * Since: 2.4 190 */ 191 public void toggled() 192 { 193 gtk_toggle_action_toggled(gtkToggleAction); 194 } 195 196 protected class OnToggledDelegateWrapper 197 { 198 static OnToggledDelegateWrapper[] listeners; 199 void delegate(ToggleAction) dlg; 200 gulong handlerId; 201 202 this(void delegate(ToggleAction) dlg) 203 { 204 this.dlg = dlg; 205 this.listeners ~= this; 206 } 207 208 void remove(OnToggledDelegateWrapper source) 209 { 210 foreach(index, wrapper; listeners) 211 { 212 if (wrapper.handlerId == source.handlerId) 213 { 214 listeners[index] = null; 215 listeners = std.algorithm.remove(listeners, index); 216 break; 217 } 218 } 219 } 220 } 221 222 /** 223 * Should be connected if you wish to perform an action 224 * whenever the #GtkToggleAction state is changed. 225 */ 226 gulong addOnToggled(void delegate(ToggleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 227 { 228 auto wrapper = new OnToggledDelegateWrapper(dlg); 229 wrapper.handlerId = Signals.connectData( 230 this, 231 "toggled", 232 cast(GCallback)&callBackToggled, 233 cast(void*)wrapper, 234 cast(GClosureNotify)&callBackToggledDestroy, 235 connectFlags); 236 return wrapper.handlerId; 237 } 238 239 extern(C) static void callBackToggled(GtkToggleAction* toggleactionStruct, OnToggledDelegateWrapper wrapper) 240 { 241 wrapper.dlg(wrapper.outer); 242 } 243 244 extern(C) static void callBackToggledDestroy(OnToggledDelegateWrapper wrapper, GClosure* closure) 245 { 246 wrapper.remove(wrapper); 247 } 248 }