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.CellRendererToggle; 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.CellRenderer; 32 private import gtkc.gtk; 33 public import gtkc.gtktypes; 34 private import std.algorithm; 35 36 37 /** 38 * #GtkCellRendererToggle renders a toggle button in a cell. The 39 * button is drawn as a radio or a checkbutton, depending on the 40 * #GtkCellRendererToggle:radio property. 41 * When activated, it emits the #GtkCellRendererToggle::toggled signal. 42 */ 43 public class CellRendererToggle : CellRenderer 44 { 45 /** the main Gtk struct */ 46 protected GtkCellRendererToggle* gtkCellRendererToggle; 47 48 /** Get the main Gtk struct */ 49 public GtkCellRendererToggle* getCellRendererToggleStruct() 50 { 51 return gtkCellRendererToggle; 52 } 53 54 /** the main Gtk struct as a void* */ 55 protected override void* getStruct() 56 { 57 return cast(void*)gtkCellRendererToggle; 58 } 59 60 protected override void setStruct(GObject* obj) 61 { 62 gtkCellRendererToggle = cast(GtkCellRendererToggle*)obj; 63 super.setStruct(obj); 64 } 65 66 /** 67 * Sets our main struct and passes it to the parent class. 68 */ 69 public this (GtkCellRendererToggle* gtkCellRendererToggle, bool ownedRef = false) 70 { 71 this.gtkCellRendererToggle = gtkCellRendererToggle; 72 super(cast(GtkCellRenderer*)gtkCellRendererToggle, ownedRef); 73 } 74 75 76 /** */ 77 public static GType getType() 78 { 79 return gtk_cell_renderer_toggle_get_type(); 80 } 81 82 /** 83 * Creates a new #GtkCellRendererToggle. Adjust rendering 84 * parameters using object properties. Object properties can be set 85 * globally (with g_object_set()). Also, with #GtkTreeViewColumn, you 86 * can bind a property to a value in a #GtkTreeModel. For example, you 87 * can bind the “active” property on the cell renderer to a boolean value 88 * in the model, thus causing the check button to reflect the state of 89 * the model. 90 * 91 * Returns: the new cell renderer 92 * 93 * Throws: ConstructionException GTK+ fails to create the object. 94 */ 95 public this() 96 { 97 auto p = gtk_cell_renderer_toggle_new(); 98 99 if(p is null) 100 { 101 throw new ConstructionException("null returned by new"); 102 } 103 104 this(cast(GtkCellRendererToggle*) p); 105 } 106 107 /** 108 * Returns whether the cell renderer is activatable. See 109 * gtk_cell_renderer_toggle_set_activatable(). 110 * 111 * Returns: %TRUE if the cell renderer is activatable. 112 * 113 * Since: 2.18 114 */ 115 public bool getActivatable() 116 { 117 return gtk_cell_renderer_toggle_get_activatable(gtkCellRendererToggle) != 0; 118 } 119 120 /** 121 * Returns whether the cell renderer is active. See 122 * gtk_cell_renderer_toggle_set_active(). 123 * 124 * Returns: %TRUE if the cell renderer is active. 125 */ 126 public bool getActive() 127 { 128 return gtk_cell_renderer_toggle_get_active(gtkCellRendererToggle) != 0; 129 } 130 131 /** 132 * Returns whether we’re rendering radio toggles rather than checkboxes. 133 * 134 * Returns: %TRUE if we’re rendering radio toggles rather than checkboxes 135 */ 136 public bool getRadio() 137 { 138 return gtk_cell_renderer_toggle_get_radio(gtkCellRendererToggle) != 0; 139 } 140 141 /** 142 * Makes the cell renderer activatable. 143 * 144 * Params: 145 * setting = the value to set. 146 * 147 * Since: 2.18 148 */ 149 public void setActivatable(bool setting) 150 { 151 gtk_cell_renderer_toggle_set_activatable(gtkCellRendererToggle, setting); 152 } 153 154 /** 155 * Activates or deactivates a cell renderer. 156 * 157 * Params: 158 * setting = the value to set. 159 */ 160 public void setActive(bool setting) 161 { 162 gtk_cell_renderer_toggle_set_active(gtkCellRendererToggle, setting); 163 } 164 165 /** 166 * If @radio is %TRUE, the cell renderer renders a radio toggle 167 * (i.e. a toggle in a group of mutually-exclusive toggles). 168 * If %FALSE, it renders a check toggle (a standalone boolean option). 169 * This can be set globally for the cell renderer, or changed just 170 * before rendering each cell in the model (for #GtkTreeView, you set 171 * up a per-row setting using #GtkTreeViewColumn to associate model 172 * columns with cell renderer properties). 173 * 174 * Params: 175 * radio = %TRUE to make the toggle look like a radio button 176 */ 177 public void setRadio(bool radio) 178 { 179 gtk_cell_renderer_toggle_set_radio(gtkCellRendererToggle, radio); 180 } 181 182 protected class OnToggledDelegateWrapper 183 { 184 static OnToggledDelegateWrapper[] listeners; 185 void delegate(string, CellRendererToggle) dlg; 186 gulong handlerId; 187 188 this(void delegate(string, CellRendererToggle) dlg) 189 { 190 this.dlg = dlg; 191 this.listeners ~= this; 192 } 193 194 void remove(OnToggledDelegateWrapper source) 195 { 196 foreach(index, wrapper; listeners) 197 { 198 if (wrapper.handlerId == source.handlerId) 199 { 200 listeners[index] = null; 201 listeners = std.algorithm.remove(listeners, index); 202 break; 203 } 204 } 205 } 206 } 207 208 /** 209 * The ::toggled signal is emitted when the cell is toggled. 210 * 211 * It is the responsibility of the application to update the model 212 * with the correct value to store at @path. Often this is simply the 213 * opposite of the value currently stored at @path. 214 * 215 * Params: 216 * path = string representation of #GtkTreePath describing the 217 * event location 218 */ 219 gulong addOnToggled(void delegate(string, CellRendererToggle) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 220 { 221 auto wrapper = new OnToggledDelegateWrapper(dlg); 222 wrapper.handlerId = Signals.connectData( 223 this, 224 "toggled", 225 cast(GCallback)&callBackToggled, 226 cast(void*)wrapper, 227 cast(GClosureNotify)&callBackToggledDestroy, 228 connectFlags); 229 return wrapper.handlerId; 230 } 231 232 extern(C) static void callBackToggled(GtkCellRendererToggle* cellrenderertoggleStruct, char* path, OnToggledDelegateWrapper wrapper) 233 { 234 wrapper.dlg(Str.toString(path), wrapper.outer); 235 } 236 237 extern(C) static void callBackToggledDestroy(OnToggledDelegateWrapper wrapper, GClosure* closure) 238 { 239 wrapper.remove(wrapper); 240 } 241 }