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.TextTag; 26 27 private import gdk.Event; 28 private import glib.ConstructionException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.TextIter; 33 public import gtkc.gdktypes; 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 * Tags should be in the #GtkTextTagTable for a given #GtkTextBuffer 46 * before using them with that buffer. 47 * 48 * gtk_text_buffer_create_tag() is the best way to create tags. 49 * See “gtk3-demo” for numerous examples. 50 * 51 * For each property of #GtkTextTag, there is a “set” property, e.g. 52 * “font-set” corresponds to “font”. These “set” properties reflect 53 * whether a property has been set or not. 54 * They are maintained by GTK+ and you should not set them independently. 55 */ 56 public class TextTag : ObjectG 57 { 58 /** the main Gtk struct */ 59 protected GtkTextTag* gtkTextTag; 60 61 /** Get the main Gtk struct */ 62 public GtkTextTag* getTextTagStruct() 63 { 64 return gtkTextTag; 65 } 66 67 /** the main Gtk struct as a void* */ 68 protected override void* getStruct() 69 { 70 return cast(void*)gtkTextTag; 71 } 72 73 protected override void setStruct(GObject* obj) 74 { 75 gtkTextTag = cast(GtkTextTag*)obj; 76 super.setStruct(obj); 77 } 78 79 /** 80 * Sets our main struct and passes it to the parent class. 81 */ 82 public this (GtkTextTag* gtkTextTag, bool ownedRef = false) 83 { 84 this.gtkTextTag = gtkTextTag; 85 super(cast(GObject*)gtkTextTag, ownedRef); 86 } 87 88 89 /** */ 90 public static GType getType() 91 { 92 return gtk_text_tag_get_type(); 93 } 94 95 /** 96 * Creates a #GtkTextTag. Configure the tag using object arguments, 97 * i.e. using g_object_set(). 98 * 99 * Params: 100 * name = tag name, or %NULL 101 * 102 * Return: a new #GtkTextTag 103 * 104 * Throws: ConstructionException GTK+ fails to create the object. 105 */ 106 public this(string name) 107 { 108 auto p = gtk_text_tag_new(Str.toStringz(name)); 109 110 if(p is null) 111 { 112 throw new ConstructionException("null returned by new"); 113 } 114 115 this(cast(GtkTextTag*) p, true); 116 } 117 118 /** 119 * Emits the #GtkTextTagTable::tag-changed signal on the #GtkTextTagTable where 120 * the tag is included. 121 * 122 * The signal is already emitted when setting a #GtkTextTag property. This 123 * function is useful for a #GtkTextTag subclass. 124 * 125 * Params: 126 * sizeChanged = whether the change affects the #GtkTextView layout. 127 * 128 * Since: 3.20 129 */ 130 public void changed(bool sizeChanged) 131 { 132 gtk_text_tag_changed(gtkTextTag, sizeChanged); 133 } 134 135 /** 136 * Emits the “event” signal on the #GtkTextTag. 137 * 138 * Params: 139 * eventObject = object that received the event, such as a widget 140 * event = the event 141 * iter = location where the event was received 142 * 143 * Return: result of signal emission (whether the event was handled) 144 */ 145 public bool event(ObjectG eventObject, Event event, TextIter iter) 146 { 147 return gtk_text_tag_event(gtkTextTag, (eventObject is null) ? null : eventObject.getObjectGStruct(), (event is null) ? null : event.getEventStruct(), (iter is null) ? null : iter.getTextIterStruct()) != 0; 148 } 149 150 /** 151 * Get the tag priority. 152 * 153 * Return: The tag’s priority. 154 */ 155 public int getPriority() 156 { 157 return gtk_text_tag_get_priority(gtkTextTag); 158 } 159 160 /** 161 * Sets the priority of a #GtkTextTag. Valid priorities 162 * start at 0 and go to one less than gtk_text_tag_table_get_size(). 163 * Each tag in a table has a unique priority; setting the priority 164 * of one tag shifts the priorities of all the other tags in the 165 * table to maintain a unique priority for each tag. Higher priority 166 * tags “win” if two tags both set the same text attribute. When adding 167 * a tag to a tag table, it will be assigned the highest priority in 168 * the table by default; so normally the precedence of a set of tags 169 * is the order in which they were added to the table, or created with 170 * gtk_text_buffer_create_tag(), which adds the tag to the buffer’s table 171 * automatically. 172 * 173 * Params: 174 * priority = the new priority 175 */ 176 public void setPriority(int priority) 177 { 178 gtk_text_tag_set_priority(gtkTextTag, priority); 179 } 180 181 protected class OnDelegateWrapper 182 { 183 bool delegate(ObjectG, Event, TextIter, TextTag) dlg; 184 gulong handlerId; 185 ConnectFlags flags; 186 this(bool delegate(ObjectG, Event, TextIter, TextTag) dlg, gulong handlerId, ConnectFlags flags) 187 { 188 this.dlg = dlg; 189 this.handlerId = handlerId; 190 this.flags = flags; 191 } 192 } 193 protected OnDelegateWrapper[] onListeners; 194 195 /** 196 * The ::event signal is emitted when an event occurs on a region of the 197 * buffer marked with this tag. 198 * 199 * Params: 200 * object = the object the event was fired from (typically a #GtkTextView) 201 * event = the event which triggered the signal 202 * iter = a #GtkTextIter pointing at the location the event occurred 203 * 204 * Return: %TRUE to stop other handlers from being invoked for the 205 * event. %FALSE to propagate the event further. 206 */ 207 gulong addOn(bool delegate(ObjectG, Event, TextIter, TextTag) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 208 { 209 onListeners ~= new OnDelegateWrapper(dlg, 0, connectFlags); 210 onListeners[onListeners.length - 1].handlerId = Signals.connectData( 211 this, 212 "event", 213 cast(GCallback)&callBack, 214 cast(void*)onListeners[onListeners.length - 1], 215 cast(GClosureNotify)&callBackDestroy, 216 connectFlags); 217 return onListeners[onListeners.length - 1].handlerId; 218 } 219 220 extern(C) static int callBack(GtkTextTag* texttagStruct, GObject* object, GdkEvent* event, GtkTextIter* iter,OnDelegateWrapper wrapper) 221 { 222 return wrapper.dlg(ObjectG.getDObject!(ObjectG)(object), ObjectG.getDObject!(Event)(event), ObjectG.getDObject!(TextIter)(iter), wrapper.outer); 223 } 224 225 extern(C) static void callBackDestroy(OnDelegateWrapper wrapper, GClosure* closure) 226 { 227 wrapper.outer.internalRemoveOn(wrapper); 228 } 229 230 protected void internalRemoveOn(OnDelegateWrapper source) 231 { 232 foreach(index, wrapper; onListeners) 233 { 234 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 235 { 236 onListeners[index] = null; 237 onListeners = std.algorithm.remove(onListeners, index); 238 break; 239 } 240 } 241 } 242 243 }