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