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.ToggleAction; 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.Action; 32 public import gtkc.gdktypes; 33 private import gtkc.gtk; 34 public import gtkc.gtktypes; 35 36 37 /** 38 * A #GtkToggleAction corresponds roughly to a #GtkCheckMenuItem. It has an 39 * “active” state specifying whether the action has been checked or not. 40 */ 41 public class ToggleAction : Action 42 { 43 /** the main Gtk struct */ 44 protected GtkToggleAction* gtkToggleAction; 45 46 /** Get the main Gtk struct */ 47 public GtkToggleAction* getToggleActionStruct() 48 { 49 return gtkToggleAction; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected override void* getStruct() 54 { 55 return cast(void*)gtkToggleAction; 56 } 57 58 protected override void setStruct(GObject* obj) 59 { 60 gtkToggleAction = cast(GtkToggleAction*)obj; 61 super.setStruct(obj); 62 } 63 64 /** 65 * Sets our main struct and passes it to the parent class. 66 */ 67 public this (GtkToggleAction* gtkToggleAction, bool ownedRef = false) 68 { 69 this.gtkToggleAction = gtkToggleAction; 70 super(cast(GtkAction*)gtkToggleAction, ownedRef); 71 } 72 73 /** 74 * Creates a new ToggleAction object. To add the action to 75 * a ActionGroup and set the accelerator for the action, 76 * call gtk.ActionGroup.ActionGroup.addActionWithAccel(). 77 * 78 * Since: 2.4 79 * 80 * Params: 81 * name = A unique name for the action 82 * label = The label displayed in menu items and on buttons, or null 83 * tooltip = A tooltip for the action, or null 84 * stockId = The stock icon to display in widgets representing the 85 * action, or null 86 * Throws: ConstructionException GTK+ fails to create the object. 87 */ 88 public this (string name, string label, string tooltip, StockID stockId) 89 { 90 this(name, label, tooltip, cast(string)stockId); 91 } 92 93 /** 94 */ 95 96 public static GType getType() 97 { 98 return gtk_toggle_action_get_type(); 99 } 100 101 /** 102 * Creates a new #GtkToggleAction object. To add the action to 103 * a #GtkActionGroup and set the accelerator for the action, 104 * call gtk_action_group_add_action_with_accel(). 105 * 106 * Params: 107 * name = A unique name for the action 108 * label = The label displayed in menu items and on buttons, 109 * or %NULL 110 * tooltip = A tooltip for the action, or %NULL 111 * stockId = The stock icon to display in widgets representing 112 * the action, or %NULL 113 * 114 * Return: a new #GtkToggleAction 115 * 116 * Since: 2.4 117 * 118 * Throws: ConstructionException GTK+ fails to create the object. 119 */ 120 public this(string name, string label, string tooltip, string stockId) 121 { 122 auto p = gtk_toggle_action_new(Str.toStringz(name), Str.toStringz(label), Str.toStringz(tooltip), Str.toStringz(stockId)); 123 124 if(p is null) 125 { 126 throw new ConstructionException("null returned by new"); 127 } 128 129 this(cast(GtkToggleAction*) p, true); 130 } 131 132 /** 133 * Returns the checked state of the toggle action. 134 * 135 * Return: the checked state of the toggle action 136 * 137 * Since: 2.4 138 */ 139 public bool getActive() 140 { 141 return gtk_toggle_action_get_active(gtkToggleAction) != 0; 142 } 143 144 /** 145 * Returns whether the action should have proxies like a radio action. 146 * 147 * Return: whether the action should have proxies like a radio action. 148 * 149 * Since: 2.4 150 */ 151 public bool getDrawAsRadio() 152 { 153 return gtk_toggle_action_get_draw_as_radio(gtkToggleAction) != 0; 154 } 155 156 /** 157 * Sets the checked state on the toggle action. 158 * 159 * Params: 160 * isActive = whether the action should be checked or not 161 * 162 * Since: 2.4 163 */ 164 public void setActive(bool isActive) 165 { 166 gtk_toggle_action_set_active(gtkToggleAction, isActive); 167 } 168 169 /** 170 * Sets whether the action should have proxies like a radio action. 171 * 172 * Params: 173 * drawAsRadio = whether the action should have proxies like a radio 174 * action 175 * 176 * Since: 2.4 177 */ 178 public void setDrawAsRadio(bool drawAsRadio) 179 { 180 gtk_toggle_action_set_draw_as_radio(gtkToggleAction, drawAsRadio); 181 } 182 183 /** 184 * Emits the “toggled” signal on the toggle action. 185 * 186 * Since: 2.4 187 */ 188 public void toggled() 189 { 190 gtk_toggle_action_toggled(gtkToggleAction); 191 } 192 193 int[string] connectedSignals; 194 195 void delegate(ToggleAction)[] onToggledListeners; 196 /** 197 * Should be connected if you wish to perform an action 198 * whenever the #GtkToggleAction state is changed. 199 */ 200 void addOnToggled(void delegate(ToggleAction) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 201 { 202 if ( "toggled" !in connectedSignals ) 203 { 204 Signals.connectData( 205 this, 206 "toggled", 207 cast(GCallback)&callBackToggled, 208 cast(void*)this, 209 null, 210 connectFlags); 211 connectedSignals["toggled"] = 1; 212 } 213 onToggledListeners ~= dlg; 214 } 215 extern(C) static void callBackToggled(GtkToggleAction* toggleactionStruct, ToggleAction _toggleaction) 216 { 217 foreach ( void delegate(ToggleAction) dlg; _toggleaction.onToggledListeners ) 218 { 219 dlg(_toggleaction); 220 } 221 } 222 }