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