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.ToggleToolButton; 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.ToolButton; 32 private import gtk.ToolItem; 33 public import gtkc.gdktypes; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * A #GtkToggleToolButton is a #GtkToolItem that contains a toggle 41 * button. 42 * 43 * Use gtk_toggle_tool_button_new() to create a new GtkToggleToolButton. 44 * 45 * # CSS nodes 46 * 47 * GtkToggleToolButton has a single CSS node with name togglebutton. 48 */ 49 public class ToggleToolButton : ToolButton 50 { 51 /** the main Gtk struct */ 52 protected GtkToggleToolButton* gtkToggleToolButton; 53 54 /** Get the main Gtk struct */ 55 public GtkToggleToolButton* getToggleToolButtonStruct() 56 { 57 return gtkToggleToolButton; 58 } 59 60 /** the main Gtk struct as a void* */ 61 protected override void* getStruct() 62 { 63 return cast(void*)gtkToggleToolButton; 64 } 65 66 protected override void setStruct(GObject* obj) 67 { 68 gtkToggleToolButton = cast(GtkToggleToolButton*)obj; 69 super.setStruct(obj); 70 } 71 72 /** 73 * Sets our main struct and passes it to the parent class. 74 */ 75 public this (GtkToggleToolButton* gtkToggleToolButton, bool ownedRef = false) 76 { 77 this.gtkToggleToolButton = gtkToggleToolButton; 78 super(cast(GtkToolButton*)gtkToggleToolButton, ownedRef); 79 } 80 81 /** 82 * Creates a new GtkToggleToolButton containing the image and text 83 * from a stock item. 84 */ 85 public this(StockID stockId) 86 { 87 this(cast(string)stockId); 88 } 89 90 /** 91 */ 92 93 /** */ 94 public static GType getType() 95 { 96 return gtk_toggle_tool_button_get_type(); 97 } 98 99 /** 100 * Returns a new #GtkToggleToolButton 101 * 102 * Return: a newly created #GtkToggleToolButton 103 * 104 * Since: 2.4 105 * 106 * Throws: ConstructionException GTK+ fails to create the object. 107 */ 108 public this() 109 { 110 auto p = gtk_toggle_tool_button_new(); 111 112 if(p is null) 113 { 114 throw new ConstructionException("null returned by new"); 115 } 116 117 this(cast(GtkToggleToolButton*) p); 118 } 119 120 /** 121 * Creates a new #GtkToggleToolButton containing the image and text from a 122 * stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK 123 * and #GTK_STOCK_APPLY. 124 * 125 * It is an error if @stock_id is not a name of a stock item. 126 * 127 * Deprecated: Use gtk_toggle_tool_button_new() instead. 128 * 129 * Params: 130 * stockId = the name of the stock item 131 * 132 * Return: A new #GtkToggleToolButton 133 * 134 * Since: 2.4 135 * 136 * Throws: ConstructionException GTK+ fails to create the object. 137 */ 138 public this(string stockId) 139 { 140 auto p = gtk_toggle_tool_button_new_from_stock(Str.toStringz(stockId)); 141 142 if(p is null) 143 { 144 throw new ConstructionException("null returned by new_from_stock"); 145 } 146 147 this(cast(GtkToggleToolButton*) p); 148 } 149 150 /** 151 * Queries a #GtkToggleToolButton and returns its current state. 152 * Returns %TRUE if the toggle button is pressed in and %FALSE if it is raised. 153 * 154 * Return: %TRUE if the toggle tool button is pressed in, %FALSE if not 155 * 156 * Since: 2.4 157 */ 158 public bool getActive() 159 { 160 return gtk_toggle_tool_button_get_active(gtkToggleToolButton) != 0; 161 } 162 163 /** 164 * Sets the status of the toggle tool button. Set to %TRUE if you 165 * want the GtkToggleButton to be “pressed in”, and %FALSE to raise it. 166 * This action causes the toggled signal to be emitted. 167 * 168 * Params: 169 * isActive = whether @button should be active 170 * 171 * Since: 2.4 172 */ 173 public void setActive(bool isActive) 174 { 175 gtk_toggle_tool_button_set_active(gtkToggleToolButton, isActive); 176 } 177 178 protected class OnToggledDelegateWrapper 179 { 180 void delegate(ToggleToolButton) dlg; 181 gulong handlerId; 182 ConnectFlags flags; 183 this(void delegate(ToggleToolButton) dlg, gulong handlerId, ConnectFlags flags) 184 { 185 this.dlg = dlg; 186 this.handlerId = handlerId; 187 this.flags = flags; 188 } 189 } 190 protected OnToggledDelegateWrapper[] onToggledListeners; 191 192 /** 193 * Emitted whenever the toggle tool button changes state. 194 */ 195 gulong addOnToggled(void delegate(ToggleToolButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 196 { 197 onToggledListeners ~= new OnToggledDelegateWrapper(dlg, 0, connectFlags); 198 onToggledListeners[onToggledListeners.length - 1].handlerId = Signals.connectData( 199 this, 200 "toggled", 201 cast(GCallback)&callBackToggled, 202 cast(void*)onToggledListeners[onToggledListeners.length - 1], 203 cast(GClosureNotify)&callBackToggledDestroy, 204 connectFlags); 205 return onToggledListeners[onToggledListeners.length - 1].handlerId; 206 } 207 208 extern(C) static void callBackToggled(GtkToggleToolButton* toggletoolbuttonStruct,OnToggledDelegateWrapper wrapper) 209 { 210 wrapper.dlg(wrapper.outer); 211 } 212 213 extern(C) static void callBackToggledDestroy(OnToggledDelegateWrapper wrapper, GClosure* closure) 214 { 215 wrapper.outer.internalRemoveOnToggled(wrapper); 216 } 217 218 protected void internalRemoveOnToggled(OnToggledDelegateWrapper source) 219 { 220 foreach(index, wrapper; onToggledListeners) 221 { 222 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 223 { 224 onToggledListeners[index] = null; 225 onToggledListeners = std.algorithm.remove(onToggledListeners, index); 226 break; 227 } 228 } 229 } 230 231 }