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.ToggleButton; 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.Button; 32 private import gtk.Widget; 33 public import gtkc.gdktypes; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 37 38 /** 39 * A #GtkToggleButton is a #GtkButton which will remain “pressed-in” when 40 * clicked. Clicking again will cause the toggle button to return to its 41 * normal state. 42 * 43 * A toggle button is created by calling either gtk_toggle_button_new() or 44 * gtk_toggle_button_new_with_label(). If using the former, it is advisable to 45 * pack a widget, (such as a #GtkLabel and/or a #GtkImage), into the toggle 46 * button’s container. (See #GtkButton for more information). 47 * 48 * The state of a #GtkToggleButton can be set specifically using 49 * gtk_toggle_button_set_active(), and retrieved using 50 * gtk_toggle_button_get_active(). 51 * 52 * To simply switch the state of a toggle button, use gtk_toggle_button_toggled(). 53 * 54 * ## Creating two #GtkToggleButton widgets. 55 * 56 * |[<!-- language="C" --> 57 * void make_toggles (void) { 58 * GtkWidget *dialog, *toggle1, *toggle2; 59 * GtkWidget *content_area; 60 * const char *text; 61 * 62 * dialog = gtk_dialog_new (text); 63 * content_area = gtk_dialog_get_content_area (); 64 * 65 * text = "Hi, i’m a toggle button."; 66 * toggle1 = gtk_toggle_button_new_with_label (text); 67 * 68 * // Makes this toggle button invisible 69 * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle1), 70 * TRUE); 71 * 72 * g_signal_connect (toggle1, "toggled", 73 * G_CALLBACK (output_state), 74 * NULL); 75 * gtk_box_pack_start (GTK_BOX (content_area), 76 * toggle1, FALSE, FALSE, 2); 77 * 78 * text = "Hi, i’m a toggle button."; 79 * toggle2 = gtk_toggle_button_new_with_label (text); 80 * gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (toggle2), 81 * FALSE); 82 * g_signal_connect (toggle2, "toggled", 83 * G_CALLBACK (output_state), 84 * NULL); 85 * gtk_box_pack_start (GTK_BOX (content_area), 86 * toggle2, FALSE, FALSE, 2); 87 * 88 * gtk_widget_show_all (dialog); 89 * } 90 * ]| 91 */ 92 public class ToggleButton : Button 93 { 94 /** the main Gtk struct */ 95 protected GtkToggleButton* gtkToggleButton; 96 97 /** Get the main Gtk struct */ 98 public GtkToggleButton* getToggleButtonStruct() 99 { 100 return gtkToggleButton; 101 } 102 103 /** the main Gtk struct as a void* */ 104 protected override void* getStruct() 105 { 106 return cast(void*)gtkToggleButton; 107 } 108 109 protected override void setStruct(GObject* obj) 110 { 111 gtkToggleButton = cast(GtkToggleButton*)obj; 112 super.setStruct(obj); 113 } 114 115 /** 116 * Sets our main struct and passes it to the parent class. 117 */ 118 public this (GtkToggleButton* gtkToggleButton, bool ownedRef = false) 119 { 120 this.gtkToggleButton = gtkToggleButton; 121 super(cast(GtkButton*)gtkToggleButton, ownedRef); 122 } 123 124 /** 125 * Creates a new toggle button with a text label. 126 * Params: 127 * label = a string containing the message to be placed in the toggle button. 128 * mnemonic = if true the label 129 * will be created using gtk_label_new_with_mnemonic(), so underscores 130 * in label indicate the mnemonic for the button. 131 * Throws: ConstructionException GTK+ fails to create the object. 132 */ 133 public this (string label, bool mnemonic=true) 134 { 135 GtkToggleButton* p; 136 137 if ( mnemonic ) 138 { 139 // GtkWidget* gtk_toggle_button_new_with_mnemonic (const gchar *label); 140 p = cast(GtkToggleButton*)gtk_toggle_button_new_with_mnemonic(Str.toStringz(label)); 141 } 142 else 143 { 144 // GtkWidget* gtk_toggle_button_new_with_label (const gchar *label); 145 p = cast(GtkToggleButton*)gtk_toggle_button_new_with_label(Str.toStringz(label)); 146 } 147 148 if(p is null) 149 { 150 throw new ConstructionException("null returned by gtk_toggle_button_new_"); 151 } 152 153 this(p); 154 } 155 156 /** 157 */ 158 159 public static GType getType() 160 { 161 return gtk_toggle_button_get_type(); 162 } 163 164 /** 165 * Creates a new toggle button. A widget should be packed into the button, as in gtk_button_new(). 166 * 167 * Return: a new toggle button. 168 * 169 * Throws: ConstructionException GTK+ fails to create the object. 170 */ 171 public this() 172 { 173 auto p = gtk_toggle_button_new(); 174 175 if(p is null) 176 { 177 throw new ConstructionException("null returned by new"); 178 } 179 180 this(cast(GtkToggleButton*) p); 181 } 182 183 /** 184 * Queries a #GtkToggleButton and returns its current state. Returns %TRUE if 185 * the toggle button is pressed in and %FALSE if it is raised. 186 * 187 * Return: a #gboolean value. 188 */ 189 public bool getActive() 190 { 191 return gtk_toggle_button_get_active(gtkToggleButton) != 0; 192 } 193 194 /** 195 * Gets the value set by gtk_toggle_button_set_inconsistent(). 196 * 197 * Return: %TRUE if the button is displayed as inconsistent, %FALSE otherwise 198 */ 199 public bool getInconsistent() 200 { 201 return gtk_toggle_button_get_inconsistent(gtkToggleButton) != 0; 202 } 203 204 /** 205 * Retrieves whether the button is displayed as a separate indicator 206 * and label. See gtk_toggle_button_set_mode(). 207 * 208 * Return: %TRUE if the togglebutton is drawn as a separate indicator 209 * and label. 210 */ 211 public bool getMode() 212 { 213 return gtk_toggle_button_get_mode(gtkToggleButton) != 0; 214 } 215 216 /** 217 * Sets the status of the toggle button. Set to %TRUE if you want the 218 * GtkToggleButton to be “pressed in”, and %FALSE to raise it. 219 * This action causes the #GtkToggleButton::toggled signal and the 220 * #GtkButton::clicked signal to be emitted. 221 * 222 * Params: 223 * isActive = %TRUE or %FALSE. 224 */ 225 public void setActive(bool isActive) 226 { 227 gtk_toggle_button_set_active(gtkToggleButton, isActive); 228 } 229 230 /** 231 * If the user has selected a range of elements (such as some text or 232 * spreadsheet cells) that are affected by a toggle button, and the 233 * current values in that range are inconsistent, you may want to 234 * display the toggle in an “in between” state. This function turns on 235 * “in between” display. Normally you would turn off the inconsistent 236 * state again if the user toggles the toggle button. This has to be 237 * done manually, gtk_toggle_button_set_inconsistent() only affects 238 * visual appearance, it doesn’t affect the semantics of the button. 239 * 240 * Params: 241 * setting = %TRUE if state is inconsistent 242 */ 243 public void setInconsistent(bool setting) 244 { 245 gtk_toggle_button_set_inconsistent(gtkToggleButton, setting); 246 } 247 248 /** 249 * Sets whether the button is displayed as a separate indicator and label. 250 * You can call this function on a checkbutton or a radiobutton with 251 * @draw_indicator = %FALSE to make the button look like a normal button 252 * 253 * This function only affects instances of classes like #GtkCheckButton 254 * and #GtkRadioButton that derive from #GtkToggleButton, 255 * not instances of #GtkToggleButton itself. 256 * 257 * Params: 258 * drawIndicator = if %TRUE, draw the button as a separate indicator 259 * and label; if %FALSE, draw the button like a normal button 260 */ 261 public void setMode(bool drawIndicator) 262 { 263 gtk_toggle_button_set_mode(gtkToggleButton, drawIndicator); 264 } 265 266 /** 267 * Emits the #GtkToggleButton::toggled signal on the 268 * #GtkToggleButton. There is no good reason for an 269 * application ever to call this function. 270 */ 271 public void toggled() 272 { 273 gtk_toggle_button_toggled(gtkToggleButton); 274 } 275 276 int[string] connectedSignals; 277 278 void delegate(ToggleButton)[] onToggledListeners; 279 /** 280 * Should be connected if you wish to perform an action whenever the 281 * #GtkToggleButton's state is changed. 282 */ 283 void addOnToggled(void delegate(ToggleButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 284 { 285 if ( "toggled" !in connectedSignals ) 286 { 287 Signals.connectData( 288 this, 289 "toggled", 290 cast(GCallback)&callBackToggled, 291 cast(void*)this, 292 null, 293 connectFlags); 294 connectedSignals["toggled"] = 1; 295 } 296 onToggledListeners ~= dlg; 297 } 298 extern(C) static void callBackToggled(GtkToggleButton* togglebuttonStruct, ToggleButton _togglebutton) 299 { 300 foreach ( void delegate(ToggleButton) dlg; _togglebutton.onToggledListeners ) 301 { 302 dlg(_togglebutton); 303 } 304 } 305 }