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.CellRendererAccel; 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 gtk.CellRendererText; 33 public import gtkc.gdktypes; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * #GtkCellRendererAccel displays a keyboard accelerator (i.e. a key 41 * combination like `Control + a`). If the cell renderer is editable, 42 * the accelerator can be changed by simply typing the new combination. 43 * 44 * The #GtkCellRendererAccel cell renderer was added in GTK+ 2.10. 45 */ 46 public class CellRendererAccel : CellRendererText 47 { 48 /** the main Gtk struct */ 49 protected GtkCellRendererAccel* gtkCellRendererAccel; 50 51 /** Get the main Gtk struct */ 52 public GtkCellRendererAccel* getCellRendererAccelStruct() 53 { 54 return gtkCellRendererAccel; 55 } 56 57 /** the main Gtk struct as a void* */ 58 protected override void* getStruct() 59 { 60 return cast(void*)gtkCellRendererAccel; 61 } 62 63 protected override void setStruct(GObject* obj) 64 { 65 gtkCellRendererAccel = cast(GtkCellRendererAccel*)obj; 66 super.setStruct(obj); 67 } 68 69 /** 70 * Sets our main struct and passes it to the parent class. 71 */ 72 public this (GtkCellRendererAccel* gtkCellRendererAccel, bool ownedRef = false) 73 { 74 this.gtkCellRendererAccel = gtkCellRendererAccel; 75 super(cast(GtkCellRendererText*)gtkCellRendererAccel, ownedRef); 76 } 77 78 79 /** */ 80 public static GType getType() 81 { 82 return gtk_cell_renderer_accel_get_type(); 83 } 84 85 /** 86 * Creates a new #GtkCellRendererAccel. 87 * 88 * Return: the new cell renderer 89 * 90 * Since: 2.10 91 * 92 * Throws: ConstructionException GTK+ fails to create the object. 93 */ 94 public this() 95 { 96 auto p = gtk_cell_renderer_accel_new(); 97 98 if(p is null) 99 { 100 throw new ConstructionException("null returned by new"); 101 } 102 103 this(cast(GtkCellRendererAccel*) p); 104 } 105 106 protected class OnAccelClearedDelegateWrapper 107 { 108 void delegate(string, CellRendererAccel) dlg; 109 gulong handlerId; 110 ConnectFlags flags; 111 this(void delegate(string, CellRendererAccel) dlg, gulong handlerId, ConnectFlags flags) 112 { 113 this.dlg = dlg; 114 this.handlerId = handlerId; 115 this.flags = flags; 116 } 117 } 118 protected OnAccelClearedDelegateWrapper[] onAccelClearedListeners; 119 120 /** 121 * Gets emitted when the user has removed the accelerator. 122 * 123 * Params: 124 * pathString = the path identifying the row of the edited cell 125 * 126 * Since: 2.10 127 */ 128 gulong addOnAccelCleared(void delegate(string, CellRendererAccel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 129 { 130 onAccelClearedListeners ~= new OnAccelClearedDelegateWrapper(dlg, 0, connectFlags); 131 onAccelClearedListeners[onAccelClearedListeners.length - 1].handlerId = Signals.connectData( 132 this, 133 "accel-cleared", 134 cast(GCallback)&callBackAccelCleared, 135 cast(void*)onAccelClearedListeners[onAccelClearedListeners.length - 1], 136 cast(GClosureNotify)&callBackAccelClearedDestroy, 137 connectFlags); 138 return onAccelClearedListeners[onAccelClearedListeners.length - 1].handlerId; 139 } 140 141 extern(C) static void callBackAccelCleared(GtkCellRendererAccel* cellrendereraccelStruct, char* pathString,OnAccelClearedDelegateWrapper wrapper) 142 { 143 wrapper.dlg(Str.toString(pathString), wrapper.outer); 144 } 145 146 extern(C) static void callBackAccelClearedDestroy(OnAccelClearedDelegateWrapper wrapper, GClosure* closure) 147 { 148 wrapper.outer.internalRemoveOnAccelCleared(wrapper); 149 } 150 151 protected void internalRemoveOnAccelCleared(OnAccelClearedDelegateWrapper source) 152 { 153 foreach(index, wrapper; onAccelClearedListeners) 154 { 155 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 156 { 157 onAccelClearedListeners[index] = null; 158 onAccelClearedListeners = std.algorithm.remove(onAccelClearedListeners, index); 159 break; 160 } 161 } 162 } 163 164 165 protected class OnAccelEditedDelegateWrapper 166 { 167 void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg; 168 gulong handlerId; 169 ConnectFlags flags; 170 this(void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg, gulong handlerId, ConnectFlags flags) 171 { 172 this.dlg = dlg; 173 this.handlerId = handlerId; 174 this.flags = flags; 175 } 176 } 177 protected OnAccelEditedDelegateWrapper[] onAccelEditedListeners; 178 179 /** 180 * Gets emitted when the user has selected a new accelerator. 181 * 182 * Params: 183 * pathString = the path identifying the row of the edited cell 184 * accelKey = the new accelerator keyval 185 * accelMods = the new acclerator modifier mask 186 * hardwareKeycode = the keycode of the new accelerator 187 * 188 * Since: 2.10 189 */ 190 gulong addOnAccelEdited(void delegate(string, uint, GdkModifierType, uint, CellRendererAccel) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 191 { 192 onAccelEditedListeners ~= new OnAccelEditedDelegateWrapper(dlg, 0, connectFlags); 193 onAccelEditedListeners[onAccelEditedListeners.length - 1].handlerId = Signals.connectData( 194 this, 195 "accel-edited", 196 cast(GCallback)&callBackAccelEdited, 197 cast(void*)onAccelEditedListeners[onAccelEditedListeners.length - 1], 198 cast(GClosureNotify)&callBackAccelEditedDestroy, 199 connectFlags); 200 return onAccelEditedListeners[onAccelEditedListeners.length - 1].handlerId; 201 } 202 203 extern(C) static void callBackAccelEdited(GtkCellRendererAccel* cellrendereraccelStruct, char* pathString, uint accelKey, GdkModifierType accelMods, uint hardwareKeycode,OnAccelEditedDelegateWrapper wrapper) 204 { 205 wrapper.dlg(Str.toString(pathString), accelKey, accelMods, hardwareKeycode, wrapper.outer); 206 } 207 208 extern(C) static void callBackAccelEditedDestroy(OnAccelEditedDelegateWrapper wrapper, GClosure* closure) 209 { 210 wrapper.outer.internalRemoveOnAccelEdited(wrapper); 211 } 212 213 protected void internalRemoveOnAccelEdited(OnAccelEditedDelegateWrapper source) 214 { 215 foreach(index, wrapper; onAccelEditedListeners) 216 { 217 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 218 { 219 onAccelEditedListeners[index] = null; 220 onAccelEditedListeners = std.algorithm.remove(onAccelEditedListeners, index); 221 break; 222 } 223 } 224 } 225 226 }