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.TextTagTable; 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.BuildableIF; 32 private import gtk.BuildableT; 33 private import gtk.TextTag; 34 private import gtkc.gtk; 35 public import gtkc.gtktypes; 36 private import std.algorithm; 37 38 39 /** 40 * You may wish to begin by reading the 41 * [text widget conceptual overview][TextWidget] 42 * which gives an overview of all the objects and 43 * data types related to the text widget and how they work together. 44 * 45 * # GtkTextTagTables as GtkBuildable 46 * 47 * The GtkTextTagTable implementation of the GtkBuildable interface 48 * supports adding tags by specifying “tag” as the “type” attribute 49 * of a <child> element. 50 * 51 * An example of a UI definition fragment specifying tags: 52 * |[ 53 * <object class="GtkTextTagTable"> 54 * <child type="tag"> 55 * <object class="GtkTextTag"/> 56 * </child> 57 * </object> 58 * ]| 59 */ 60 public class TextTagTable : ObjectG, BuildableIF 61 { 62 /** the main Gtk struct */ 63 protected GtkTextTagTable* gtkTextTagTable; 64 65 /** Get the main Gtk struct */ 66 public GtkTextTagTable* getTextTagTableStruct() 67 { 68 return gtkTextTagTable; 69 } 70 71 /** the main Gtk struct as a void* */ 72 protected override void* getStruct() 73 { 74 return cast(void*)gtkTextTagTable; 75 } 76 77 protected override void setStruct(GObject* obj) 78 { 79 gtkTextTagTable = cast(GtkTextTagTable*)obj; 80 super.setStruct(obj); 81 } 82 83 /** 84 * Sets our main struct and passes it to the parent class. 85 */ 86 public this (GtkTextTagTable* gtkTextTagTable, bool ownedRef = false) 87 { 88 this.gtkTextTagTable = gtkTextTagTable; 89 super(cast(GObject*)gtkTextTagTable, ownedRef); 90 } 91 92 // add the Buildable capabilities 93 mixin BuildableT!(GtkTextTagTable); 94 95 96 /** */ 97 public static GType getType() 98 { 99 return gtk_text_tag_table_get_type(); 100 } 101 102 /** 103 * Creates a new #GtkTextTagTable. The table contains no tags by 104 * default. 105 * 106 * Returns: a new #GtkTextTagTable 107 * 108 * Throws: ConstructionException GTK+ fails to create the object. 109 */ 110 public this() 111 { 112 auto p = gtk_text_tag_table_new(); 113 114 if(p is null) 115 { 116 throw new ConstructionException("null returned by new"); 117 } 118 119 this(cast(GtkTextTagTable*) p, true); 120 } 121 122 /** 123 * Add a tag to the table. The tag is assigned the highest priority 124 * in the table. 125 * 126 * @tag must not be in a tag table already, and may not have 127 * the same name as an already-added tag. 128 * 129 * Params: 130 * tag = a #GtkTextTag 131 * 132 * Returns: %TRUE on success. 133 */ 134 public bool add(TextTag tag) 135 { 136 return gtk_text_tag_table_add(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct()) != 0; 137 } 138 139 /** 140 * Calls @func on each tag in @table, with user data @data. 141 * Note that the table may not be modified while iterating 142 * over it (you can’t add/remove tags). 143 * 144 * Params: 145 * func = a function to call on each tag 146 * data = user data 147 */ 148 public void foreac(GtkTextTagTableForeach func, void* data) 149 { 150 gtk_text_tag_table_foreach(gtkTextTagTable, func, data); 151 } 152 153 /** 154 * Returns the size of the table (number of tags) 155 * 156 * Returns: number of tags in @table 157 */ 158 public int getSize() 159 { 160 return gtk_text_tag_table_get_size(gtkTextTagTable); 161 } 162 163 /** 164 * Look up a named tag. 165 * 166 * Params: 167 * name = name of a tag 168 * 169 * Returns: The tag, or %NULL if none by that 170 * name is in the table. 171 */ 172 public TextTag lookup(string name) 173 { 174 auto p = gtk_text_tag_table_lookup(gtkTextTagTable, Str.toStringz(name)); 175 176 if(p is null) 177 { 178 return null; 179 } 180 181 return ObjectG.getDObject!(TextTag)(cast(GtkTextTag*) p); 182 } 183 184 /** 185 * Remove a tag from the table. If a #GtkTextBuffer has @table as its tag table, 186 * the tag is removed from the buffer. The table’s reference to the tag is 187 * removed, so the tag will end up destroyed if you don’t have a reference to 188 * it. 189 * 190 * Params: 191 * tag = a #GtkTextTag 192 */ 193 public void remove(TextTag tag) 194 { 195 gtk_text_tag_table_remove(gtkTextTagTable, (tag is null) ? null : tag.getTextTagStruct()); 196 } 197 198 protected class OnTagAddedDelegateWrapper 199 { 200 static OnTagAddedDelegateWrapper[] listeners; 201 void delegate(TextTag, TextTagTable) dlg; 202 gulong handlerId; 203 204 this(void delegate(TextTag, TextTagTable) dlg) 205 { 206 this.dlg = dlg; 207 this.listeners ~= this; 208 } 209 210 void remove(OnTagAddedDelegateWrapper source) 211 { 212 foreach(index, wrapper; listeners) 213 { 214 if (wrapper.handlerId == source.handlerId) 215 { 216 listeners[index] = null; 217 listeners = std.algorithm.remove(listeners, index); 218 break; 219 } 220 } 221 } 222 } 223 224 /** */ 225 gulong addOnTagAdded(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 226 { 227 auto wrapper = new OnTagAddedDelegateWrapper(dlg); 228 wrapper.handlerId = Signals.connectData( 229 this, 230 "tag-added", 231 cast(GCallback)&callBackTagAdded, 232 cast(void*)wrapper, 233 cast(GClosureNotify)&callBackTagAddedDestroy, 234 connectFlags); 235 return wrapper.handlerId; 236 } 237 238 extern(C) static void callBackTagAdded(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, OnTagAddedDelegateWrapper wrapper) 239 { 240 wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), wrapper.outer); 241 } 242 243 extern(C) static void callBackTagAddedDestroy(OnTagAddedDelegateWrapper wrapper, GClosure* closure) 244 { 245 wrapper.remove(wrapper); 246 } 247 248 protected class OnTagChangedDelegateWrapper 249 { 250 static OnTagChangedDelegateWrapper[] listeners; 251 void delegate(TextTag, bool, TextTagTable) dlg; 252 gulong handlerId; 253 254 this(void delegate(TextTag, bool, TextTagTable) dlg) 255 { 256 this.dlg = dlg; 257 this.listeners ~= this; 258 } 259 260 void remove(OnTagChangedDelegateWrapper source) 261 { 262 foreach(index, wrapper; listeners) 263 { 264 if (wrapper.handlerId == source.handlerId) 265 { 266 listeners[index] = null; 267 listeners = std.algorithm.remove(listeners, index); 268 break; 269 } 270 } 271 } 272 } 273 274 /** */ 275 gulong addOnTagChanged(void delegate(TextTag, bool, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 276 { 277 auto wrapper = new OnTagChangedDelegateWrapper(dlg); 278 wrapper.handlerId = Signals.connectData( 279 this, 280 "tag-changed", 281 cast(GCallback)&callBackTagChanged, 282 cast(void*)wrapper, 283 cast(GClosureNotify)&callBackTagChangedDestroy, 284 connectFlags); 285 return wrapper.handlerId; 286 } 287 288 extern(C) static void callBackTagChanged(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, bool sizeChanged, OnTagChangedDelegateWrapper wrapper) 289 { 290 wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), sizeChanged, wrapper.outer); 291 } 292 293 extern(C) static void callBackTagChangedDestroy(OnTagChangedDelegateWrapper wrapper, GClosure* closure) 294 { 295 wrapper.remove(wrapper); 296 } 297 298 protected class OnTagRemovedDelegateWrapper 299 { 300 static OnTagRemovedDelegateWrapper[] listeners; 301 void delegate(TextTag, TextTagTable) dlg; 302 gulong handlerId; 303 304 this(void delegate(TextTag, TextTagTable) dlg) 305 { 306 this.dlg = dlg; 307 this.listeners ~= this; 308 } 309 310 void remove(OnTagRemovedDelegateWrapper source) 311 { 312 foreach(index, wrapper; listeners) 313 { 314 if (wrapper.handlerId == source.handlerId) 315 { 316 listeners[index] = null; 317 listeners = std.algorithm.remove(listeners, index); 318 break; 319 } 320 } 321 } 322 } 323 324 /** */ 325 gulong addOnTagRemoved(void delegate(TextTag, TextTagTable) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 326 { 327 auto wrapper = new OnTagRemovedDelegateWrapper(dlg); 328 wrapper.handlerId = Signals.connectData( 329 this, 330 "tag-removed", 331 cast(GCallback)&callBackTagRemoved, 332 cast(void*)wrapper, 333 cast(GClosureNotify)&callBackTagRemovedDestroy, 334 connectFlags); 335 return wrapper.handlerId; 336 } 337 338 extern(C) static void callBackTagRemoved(GtkTextTagTable* texttagtableStruct, GtkTextTag* tag, OnTagRemovedDelegateWrapper wrapper) 339 { 340 wrapper.dlg(ObjectG.getDObject!(TextTag)(tag), wrapper.outer); 341 } 342 343 extern(C) static void callBackTagRemovedDestroy(OnTagRemovedDelegateWrapper wrapper, GClosure* closure) 344 { 345 wrapper.remove(wrapper); 346 } 347 }