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 private import gtk.c.functions; 36 public import gtk.c.types; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 39 40 41 /** 42 * #GtkSwitch is a widget that has two states: on or off. The user can control 43 * which state should be active by clicking the empty area, or by dragging the 44 * handle. 45 * 46 * GtkSwitch can also handle situations where the underlying state changes with 47 * a delay. See #GtkSwitch::state-set for details. 48 * 49 * # CSS nodes 50 * 51 * |[<!-- language="plain" --> 52 * switch 53 * ╰── slider 54 * ]| 55 * 56 * GtkSwitch has two css nodes, the main node with the name switch and a subnode 57 * named slider. Neither of them is using any style classes. 58 */ 59 public class Switch : Widget, ActionableIF, ActivatableIF 60 { 61 /** the main Gtk struct */ 62 protected GtkSwitch* gtkSwitch; 63 64 /** Get the main Gtk struct */ 65 public GtkSwitch* getSwitchStruct(bool transferOwnership = false) 66 { 67 if (transferOwnership) 68 ownedRef = false; 69 return gtkSwitch; 70 } 71 72 /** the main Gtk struct as a void* */ 73 protected override void* getStruct() 74 { 75 return cast(void*)gtkSwitch; 76 } 77 78 /** 79 * Sets our main struct and passes it to the parent class. 80 */ 81 public this (GtkSwitch* gtkSwitch, bool ownedRef = false) 82 { 83 this.gtkSwitch = gtkSwitch; 84 super(cast(GtkWidget*)gtkSwitch, ownedRef); 85 } 86 87 // add the Actionable capabilities 88 mixin ActionableT!(GtkSwitch); 89 90 // add the Activatable capabilities 91 mixin ActivatableT!(GtkSwitch); 92 93 94 /** */ 95 public static GType getType() 96 { 97 return gtk_switch_get_type(); 98 } 99 100 /** 101 * Creates a new #GtkSwitch widget. 102 * 103 * Returns: the newly created #GtkSwitch instance 104 * 105 * Since: 3.0 106 * 107 * Throws: ConstructionException GTK+ fails to create the object. 108 */ 109 public this() 110 { 111 auto p = gtk_switch_new(); 112 113 if(p is null) 114 { 115 throw new ConstructionException("null returned by new"); 116 } 117 118 this(cast(GtkSwitch*) p); 119 } 120 121 /** 122 * Gets whether the #GtkSwitch is in its “on” or “off” state. 123 * 124 * Returns: %TRUE if the #GtkSwitch is active, and %FALSE otherwise 125 * 126 * Since: 3.0 127 */ 128 public bool getActive() 129 { 130 return gtk_switch_get_active(gtkSwitch) != 0; 131 } 132 133 /** 134 * Gets the underlying state of the #GtkSwitch. 135 * 136 * Returns: the underlying state 137 * 138 * Since: 3.14 139 */ 140 public bool getState() 141 { 142 return gtk_switch_get_state(gtkSwitch) != 0; 143 } 144 145 /** 146 * Changes the state of @sw to the desired one. 147 * 148 * Params: 149 * isActive = %TRUE if @sw should be active, and %FALSE otherwise 150 * 151 * Since: 3.0 152 */ 153 public void setActive(bool isActive) 154 { 155 gtk_switch_set_active(gtkSwitch, isActive); 156 } 157 158 /** 159 * Sets the underlying state of the #GtkSwitch. 160 * 161 * Normally, this is the same as #GtkSwitch:active, unless the switch 162 * is set up for delayed state changes. This function is typically 163 * called from a #GtkSwitch::state-set signal handler. 164 * 165 * See #GtkSwitch::state-set for details. 166 * 167 * Params: 168 * state = the new state 169 * 170 * Since: 3.14 171 */ 172 public void setState(bool state) 173 { 174 gtk_switch_set_state(gtkSwitch, state); 175 } 176 177 /** 178 * The ::activate signal on GtkSwitch is an action signal and 179 * emitting it causes the switch to animate. 180 * Applications should never connect to this signal, but use the 181 * notify::active signal. 182 */ 183 gulong addOnActivate(void delegate(Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 184 { 185 return Signals.connect(this, "activate", dlg, connectFlags ^ ConnectFlags.SWAPPED); 186 } 187 188 /** 189 * The ::state-set signal on GtkSwitch is emitted to change the underlying 190 * state. It is emitted when the user changes the switch position. The 191 * default handler keeps the state in sync with the #GtkSwitch:active 192 * property. 193 * 194 * To implement delayed state change, applications can connect to this signal, 195 * initiate the change of the underlying state, and call gtk_switch_set_state() 196 * when the underlying state change is complete. The signal handler should 197 * return %TRUE to prevent the default handler from running. 198 * 199 * Visually, the underlying state is represented by the trough color of 200 * the switch, while the #GtkSwitch:active property is represented by the 201 * position of the switch. 202 * 203 * Params: 204 * state = the new state of the switch 205 * 206 * Returns: %TRUE to stop the signal emission 207 * 208 * Since: 3.14 209 */ 210 gulong addOnStateSet(bool delegate(bool, Switch) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 211 { 212 return Signals.connect(this, "state-set", dlg, connectFlags ^ ConnectFlags.SWAPPED); 213 } 214 }