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 public static GType getType() 89 { 90 return gtk_switch_get_type(); 91 } 92 93 /** 94 * Creates a new #GtkSwitch widget. 95 * 96 * Return: the newly created #GtkSwitch instance 97 * 98 * Since: 3.0 99 * 100 * Throws: ConstructionException GTK+ fails to create the object. 101 */ 102 public this() 103 { 104 auto p = gtk_switch_new(); 105 106 if(p is null) 107 { 108 throw new ConstructionException("null returned by new"); 109 } 110 111 this(cast(GtkSwitch*) p); 112 } 113 114 /** 115 * Gets whether the #GtkSwitch is in its “on” or “off” state. 116 * 117 * Return: %TRUE if the #GtkSwitch is active, and %FALSE otherwise 118 * 119 * Since: 3.0 120 */ 121 public bool getActive() 122 { 123 return gtk_switch_get_active(gtkSwitch) != 0; 124 } 125 126 /** 127 * Gets the underlying state of the #GtkSwitch. 128 * 129 * Return: the underlying state 130 * 131 * Since: 3.14 132 */ 133 public bool getState() 134 { 135 return gtk_switch_get_state(gtkSwitch) != 0; 136 } 137 138 /** 139 * Changes the state of @sw to the desired one. 140 * 141 * Params: 142 * isActive = %TRUE if @sw should be active, and %FALSE otherwise 143 * 144 * Since: 3.0 145 */ 146 public void setActive(bool isActive) 147 { 148 gtk_switch_set_active(gtkSwitch, isActive); 149 } 150 151 /** 152 * Sets the underlying state of the #GtkSwitch. 153 * 154 * Normally, this is the same as #GtkSwitch:active, unless the switch 155 * is set up for delayed state changes. This function is typically 156 * called from a #GtkSwitch::state-set signal handler. 157 * 158 * See #GtkSwitch::state-set for details. 159 * 160 * Params: 161 * state = the new state 162 * 163 * Since: 3.14 164 */ 165 public void setState(bool state) 166 { 167 gtk_switch_set_state(gtkSwitch, state); 168 } 169 170 int[string] connectedSignals; 171 172 void delegate(Switch)[] onActivateListeners; 173 /** 174 * The ::activate signal on GtkSwitch is an action signal and 175 * emitting it causes the switch to animate. 176 * Applications should never connect to this signal, but use the 177 * notify::active signal. 178 */ 179 void addOnActivate(void delegate(Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 180 { 181 if ( "activate" !in connectedSignals ) 182 { 183 Signals.connectData( 184 this, 185 "activate", 186 cast(GCallback)&callBackActivate, 187 cast(void*)this, 188 null, 189 connectFlags); 190 connectedSignals["activate"] = 1; 191 } 192 onActivateListeners ~= dlg; 193 } 194 extern(C) static void callBackActivate(GtkSwitch* switchStruct, Switch _switch) 195 { 196 foreach ( void delegate(Switch) dlg; _switch.onActivateListeners ) 197 { 198 dlg(_switch); 199 } 200 } 201 202 bool delegate(bool, Switch)[] onStateSetListeners; 203 /** 204 * The ::state-set signal on GtkSwitch is emitted to change the underlying 205 * state. It is emitted when the user changes the switch position. The 206 * default handler keeps the state in sync with the #GtkState:active 207 * property. 208 * 209 * To implement delayed state change, applications can connect to this signal, 210 * initiate the change of the underlying state, and call gtk_switch_set_state() 211 * when the underlying state change is complete. The signal handler should 212 * return %TRUE to prevent the default handler from running. 213 * 214 * Visually, the underlying state is represented by the trough color of 215 * the switch, while the #GtkSwitch:active property is represented by the 216 * position of the switch. 217 * 218 * Params: 219 * state = the new state of the switch 220 * 221 * Return: %TRUE to stop the signal emission 222 * 223 * Since: 3.14 224 */ 225 void addOnStateSet(bool delegate(bool, Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 226 { 227 if ( "state-set" !in connectedSignals ) 228 { 229 Signals.connectData( 230 this, 231 "state-set", 232 cast(GCallback)&callBackStateSet, 233 cast(void*)this, 234 null, 235 connectFlags); 236 connectedSignals["state-set"] = 1; 237 } 238 onStateSetListeners ~= dlg; 239 } 240 extern(C) static int callBackStateSet(GtkSwitch* switchStruct, bool state, Switch _switch) 241 { 242 foreach ( bool delegate(bool, Switch) dlg; _switch.onStateSetListeners ) 243 { 244 if ( dlg(state, _switch) ) 245 { 246 return 1; 247 } 248 } 249 250 return 0; 251 } 252 }