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.Switch; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.ActionableIF; 31 private import gtk.ActionableT; 32 private import gtk.ActivatableIF; 33 private import gtk.ActivatableT; 34 private import gtk.Widget; 35 public import gtkc.gdktypes; 36 private import gtkc.gtk; 37 public import gtkc.gtktypes; 38 39 40 /** 41 * #GtkSwitch is a widget that has two states: on or off. The user can control 42 * which state should be active by clicking the empty area, or by dragging the 43 * handle. 44 * 45 * GtkSwitch can also handle situations where the underlying state changes with 46 * a delay. See #GtkSwitch::state-set for details. 47 */ 48 public class Switch : Widget, ActionableIF, ActivatableIF 49 { 50 /** the main Gtk struct */ 51 protected GtkSwitch* gtkSwitch; 52 53 /** Get the main Gtk struct */ 54 public GtkSwitch* getSwitchStruct() 55 { 56 return gtkSwitch; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected override void* getStruct() 61 { 62 return cast(void*)gtkSwitch; 63 } 64 65 protected override void setStruct(GObject* obj) 66 { 67 gtkSwitch = cast(GtkSwitch*)obj; 68 super.setStruct(obj); 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GtkSwitch* gtkSwitch, bool ownedRef = false) 75 { 76 this.gtkSwitch = gtkSwitch; 77 super(cast(GtkWidget*)gtkSwitch, ownedRef); 78 } 79 80 // add the Actionable capabilities 81 mixin ActionableT!(GtkSwitch); 82 83 // add the Activatable capabilities 84 mixin ActivatableT!(GtkSwitch); 85 86 /** 87 */ 88 89 public static GType getType() 90 { 91 return gtk_switch_get_type(); 92 } 93 94 /** 95 * Creates a new #GtkSwitch widget. 96 * 97 * Return: the newly created #GtkSwitch instance 98 * 99 * Since: 3.0 100 * 101 * Throws: ConstructionException GTK+ fails to create the object. 102 */ 103 public this() 104 { 105 auto p = gtk_switch_new(); 106 107 if(p is null) 108 { 109 throw new ConstructionException("null returned by new"); 110 } 111 112 this(cast(GtkSwitch*) p); 113 } 114 115 /** 116 * Gets whether the #GtkSwitch is in its “on” or “off” state. 117 * 118 * Return: %TRUE if the #GtkSwitch is active, and %FALSE otherwise 119 * 120 * Since: 3.0 121 */ 122 public bool getActive() 123 { 124 return gtk_switch_get_active(gtkSwitch) != 0; 125 } 126 127 /** 128 * Gets the underlying state of the #GtkSwitch. 129 * 130 * Return: the underlying state 131 * 132 * Since: 3.14 133 */ 134 public bool getState() 135 { 136 return gtk_switch_get_state(gtkSwitch) != 0; 137 } 138 139 /** 140 * Changes the state of @sw to the desired one. 141 * 142 * Params: 143 * isActive = %TRUE if @sw should be active, and %FALSE otherwise 144 * 145 * Since: 3.0 146 */ 147 public void setActive(bool isActive) 148 { 149 gtk_switch_set_active(gtkSwitch, isActive); 150 } 151 152 /** 153 * Sets the underlying state of the #GtkSwitch. 154 * 155 * Normally, this is the same as #GtkSwitch:active, unless the switch 156 * is set up for delayed state changes. This function is typically 157 * called from a #GtkSwitch::state-set signal handler. 158 * 159 * See #GtkSwitch::state-set for details. 160 * 161 * Params: 162 * state = the new state 163 * 164 * Since: 3.14 165 */ 166 public void setState(bool state) 167 { 168 gtk_switch_set_state(gtkSwitch, state); 169 } 170 171 int[string] connectedSignals; 172 173 void delegate(Switch)[] onActivateListeners; 174 /** 175 * The ::activate signal on GtkSwitch is an action signal and 176 * emitting it causes the switch to animate. 177 * Applications should never connect to this signal, but use the 178 * notify::active signal. 179 */ 180 void addOnActivate(void delegate(Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 181 { 182 if ( "activate" !in connectedSignals ) 183 { 184 Signals.connectData( 185 this, 186 "activate", 187 cast(GCallback)&callBackActivate, 188 cast(void*)this, 189 null, 190 connectFlags); 191 connectedSignals["activate"] = 1; 192 } 193 onActivateListeners ~= dlg; 194 } 195 extern(C) static void callBackActivate(GtkSwitch* switchStruct, Switch _switch) 196 { 197 foreach ( void delegate(Switch) dlg; _switch.onActivateListeners ) 198 { 199 dlg(_switch); 200 } 201 } 202 203 bool delegate(bool, Switch)[] onStateSetListeners; 204 /** 205 * The ::state-set signal on GtkSwitch is emitted to change the underlying 206 * state. It is emitted when the user changes the switch position. The 207 * default handler keeps the state in sync with the #GtkState:active 208 * property. 209 * 210 * To implement delayed state change, applications can connect to this signal, 211 * initiate the change of the underlying state, and call gtk_switch_set_state() 212 * when the underlying state change is complete. The signal handler should 213 * return %TRUE to prevent the default handler from running. 214 * 215 * Visually, the underlying state is represented by the trough color of 216 * the switch, while the #GtkSwitch:active property is represented by the 217 * position of the switch. 218 * 219 * Params: 220 * state = the new state of the switch 221 * 222 * Return: %TRUE to stop the signal emission 223 * 224 * Since: 3.14 225 */ 226 void addOnStateSet(bool delegate(bool, Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 227 { 228 if ( "state-set" !in connectedSignals ) 229 { 230 Signals.connectData( 231 this, 232 "state-set", 233 cast(GCallback)&callBackStateSet, 234 cast(void*)this, 235 null, 236 connectFlags); 237 connectedSignals["state-set"] = 1; 238 } 239 onStateSetListeners ~= dlg; 240 } 241 extern(C) static int callBackStateSet(GtkSwitch* switchStruct, bool state, Switch _switch) 242 { 243 foreach ( bool delegate(bool, Switch) dlg; _switch.onStateSetListeners ) 244 { 245 if ( dlg(state, _switch) ) 246 { 247 return 1; 248 } 249 } 250 251 return 0; 252 } 253 }