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 gsv.SourceMarkAttributes; 26 27 private import gdk.RGBA; 28 private import gdkpixbuf.Pixbuf; 29 private import gio.Icon; 30 private import gio.IconIF; 31 private import glib.ConstructionException; 32 private import glib.Str; 33 private import gobject.ObjectG; 34 private import gobject.Signals; 35 private import gsv.SourceMark; 36 private import gsvc.gsv; 37 public import gsvc.gsvtypes; 38 private import gtk.Widget; 39 public import gtkc.gdktypes; 40 private import std.algorithm; 41 42 43 /** */ 44 public class SourceMarkAttributes : ObjectG 45 { 46 /** the main Gtk struct */ 47 protected GtkSourceMarkAttributes* gtkSourceMarkAttributes; 48 49 /** Get the main Gtk struct */ 50 public GtkSourceMarkAttributes* getSourceMarkAttributesStruct() 51 { 52 return gtkSourceMarkAttributes; 53 } 54 55 /** the main Gtk struct as a void* */ 56 protected override void* getStruct() 57 { 58 return cast(void*)gtkSourceMarkAttributes; 59 } 60 61 protected override void setStruct(GObject* obj) 62 { 63 gtkSourceMarkAttributes = cast(GtkSourceMarkAttributes*)obj; 64 super.setStruct(obj); 65 } 66 67 /** 68 * Sets our main struct and passes it to the parent class. 69 */ 70 public this (GtkSourceMarkAttributes* gtkSourceMarkAttributes, bool ownedRef = false) 71 { 72 this.gtkSourceMarkAttributes = gtkSourceMarkAttributes; 73 super(cast(GObject*)gtkSourceMarkAttributes, ownedRef); 74 } 75 76 /** */ 77 public void setStockId(StockID stockId) 78 { 79 setStockId(cast(string)stockId); 80 } 81 82 /** 83 */ 84 85 /** */ 86 public static GType getType() 87 { 88 return gtk_source_mark_attributes_get_type(); 89 } 90 91 /** 92 * Creates a new source mark attributes. 93 * 94 * Return: a new source mark attributes. 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this() 99 { 100 auto p = gtk_source_mark_attributes_new(); 101 102 if(p is null) 103 { 104 throw new ConstructionException("null returned by new"); 105 } 106 107 this(cast(GtkSourceMarkAttributes*) p, true); 108 } 109 110 /** 111 * Stores background color in @background. 112 * 113 * Params: 114 * background = a #GdkRGBA. 115 * 116 * Return: whether background color for @attributes was set. 117 */ 118 public bool getBackground(out RGBA background) 119 { 120 GdkRGBA* outbackground = gMalloc!GdkRGBA(); 121 122 auto p = gtk_source_mark_attributes_get_background(gtkSourceMarkAttributes, outbackground) != 0; 123 124 background = ObjectG.getDObject!(RGBA)(outbackground, true); 125 126 return p; 127 } 128 129 /** 130 * Gets a #GIcon to be used as a base for rendered icon. Note that the icon can 131 * be %NULL if it wasn't set earlier. 132 * 133 * Return: An icon. The icon belongs to @attributes and should 134 * not be unreffed. 135 */ 136 public IconIF getGicon() 137 { 138 auto p = gtk_source_mark_attributes_get_gicon(gtkSourceMarkAttributes); 139 140 if(p is null) 141 { 142 return null; 143 } 144 145 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p); 146 } 147 148 /** 149 * Gets a name of an icon to be used as a base for rendered icon. Note that the 150 * icon name can be %NULL if it wasn't set earlier. 151 * 152 * Return: An icon name. The string belongs to @attributes and 153 * should not be freed. 154 */ 155 public string getIconName() 156 { 157 return Str.toString(gtk_source_mark_attributes_get_icon_name(gtkSourceMarkAttributes)); 158 } 159 160 /** 161 * Gets a #GdkPixbuf to be used as a base for rendered icon. Note that the 162 * pixbuf can be %NULL if it wasn't set earlier. 163 * 164 * Return: A pixbuf. The pixbuf belongs to @attributes and 165 * should not be unreffed. 166 */ 167 public Pixbuf getPixbuf() 168 { 169 auto p = gtk_source_mark_attributes_get_pixbuf(gtkSourceMarkAttributes); 170 171 if(p is null) 172 { 173 return null; 174 } 175 176 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 177 } 178 179 /** 180 * Gets a stock id of an icon used by this attributes. Note that the stock id can 181 * be %NULL if it wasn't set earlier. 182 * 183 * Deprecated: Don't use this function. 184 * 185 * Return: Stock id. Returned string is owned by @attributes and 186 * shouldn't be freed. 187 */ 188 public string getStockId() 189 { 190 return Str.toString(gtk_source_mark_attributes_get_stock_id(gtkSourceMarkAttributes)); 191 } 192 193 /** 194 * Queries for a tooltip by emitting 195 * a #GtkSourceMarkAttributes::query-tooltip-markup signal. The tooltip may contain 196 * a markup. 197 * 198 * Params: 199 * mark = a #GtkSourceMark. 200 * 201 * Return: A tooltip. The returned string should be freed by 202 * using g_free() when done with it. 203 */ 204 public string getTooltipMarkup(SourceMark mark) 205 { 206 auto retStr = gtk_source_mark_attributes_get_tooltip_markup(gtkSourceMarkAttributes, (mark is null) ? null : mark.getSourceMarkStruct()); 207 208 scope(exit) Str.freeString(retStr); 209 return Str.toString(retStr); 210 } 211 212 /** 213 * Queries for a tooltip by emitting 214 * a #GtkSourceMarkAttributes::query-tooltip-text signal. The tooltip is a plain 215 * text. 216 * 217 * Params: 218 * mark = a #GtkSourceMark. 219 * 220 * Return: A tooltip. The returned string should be freed by 221 * using g_free() when done with it. 222 */ 223 public string getTooltipText(SourceMark mark) 224 { 225 auto retStr = gtk_source_mark_attributes_get_tooltip_text(gtkSourceMarkAttributes, (mark is null) ? null : mark.getSourceMarkStruct()); 226 227 scope(exit) Str.freeString(retStr); 228 return Str.toString(retStr); 229 } 230 231 /** 232 * Renders an icon of given size. The base of the icon is set by the last call 233 * to one of: gtk_source_mark_attributes_set_pixbuf(), 234 * gtk_source_mark_attributes_set_gicon(), 235 * gtk_source_mark_attributes_set_icon_name() or 236 * gtk_source_mark_attributes_set_stock_id(). @size cannot be lower than 1. 237 * 238 * Params: 239 * widget = widget of which style settings may be used. 240 * size = size of the rendered icon. 241 * 242 * Return: A rendered pixbuf. The pixbuf belongs to @attributes 243 * and should not be unreffed. 244 */ 245 public Pixbuf renderIcon(Widget widget, int size) 246 { 247 auto p = gtk_source_mark_attributes_render_icon(gtkSourceMarkAttributes, (widget is null) ? null : widget.getWidgetStruct(), size); 248 249 if(p is null) 250 { 251 return null; 252 } 253 254 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 255 } 256 257 /** 258 * Sets background color to the one given in @background. 259 * 260 * Params: 261 * background = a #GdkRGBA. 262 */ 263 public void setBackground(RGBA background) 264 { 265 gtk_source_mark_attributes_set_background(gtkSourceMarkAttributes, (background is null) ? null : background.getRGBAStruct()); 266 } 267 268 /** 269 * Sets an icon to be used as a base for rendered icon. 270 * 271 * Params: 272 * gicon = a #GIcon to be used. 273 */ 274 public void setGicon(IconIF gicon) 275 { 276 gtk_source_mark_attributes_set_gicon(gtkSourceMarkAttributes, (gicon is null) ? null : gicon.getIconStruct()); 277 } 278 279 /** 280 * Sets a name of an icon to be used as a base for rendered icon. 281 * 282 * Params: 283 * iconName = name of an icon to be used. 284 */ 285 public void setIconName(string iconName) 286 { 287 gtk_source_mark_attributes_set_icon_name(gtkSourceMarkAttributes, Str.toStringz(iconName)); 288 } 289 290 /** 291 * Sets a pixbuf to be used as a base for rendered icon. 292 * 293 * Params: 294 * pixbuf = a #GdkPixbuf to be used. 295 */ 296 public void setPixbuf(Pixbuf pixbuf) 297 { 298 gtk_source_mark_attributes_set_pixbuf(gtkSourceMarkAttributes, (pixbuf is null) ? null : pixbuf.getPixbufStruct()); 299 } 300 301 /** 302 * Sets stock id to be used as a base for rendered icon. 303 * 304 * Deprecated: Don't use this function. 305 * 306 * Params: 307 * stockId = a stock id. 308 */ 309 public void setStockId(string stockId) 310 { 311 gtk_source_mark_attributes_set_stock_id(gtkSourceMarkAttributes, Str.toStringz(stockId)); 312 } 313 314 protected class OnQueryTooltipMarkupDelegateWrapper 315 { 316 string delegate(SourceMark, SourceMarkAttributes) dlg; 317 gulong handlerId; 318 ConnectFlags flags; 319 this(string delegate(SourceMark, SourceMarkAttributes) dlg, gulong handlerId, ConnectFlags flags) 320 { 321 this.dlg = dlg; 322 this.handlerId = handlerId; 323 this.flags = flags; 324 } 325 } 326 protected OnQueryTooltipMarkupDelegateWrapper[] onQueryTooltipMarkupListeners; 327 328 /** 329 * The code should connect to this signal to provide a tooltip for given 330 * @mark. The tooltip can contain a markup. 331 * 332 * Params: 333 * mark = The #GtkSourceMark. 334 * 335 * Return: A tooltip. The string should be freed with 336 * g_free() when done with it. 337 */ 338 gulong addOnQueryTooltipMarkup(string delegate(SourceMark, SourceMarkAttributes) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 339 { 340 onQueryTooltipMarkupListeners ~= new OnQueryTooltipMarkupDelegateWrapper(dlg, 0, connectFlags); 341 onQueryTooltipMarkupListeners[onQueryTooltipMarkupListeners.length - 1].handlerId = Signals.connectData( 342 this, 343 "query-tooltip-markup", 344 cast(GCallback)&callBackQueryTooltipMarkup, 345 cast(void*)onQueryTooltipMarkupListeners[onQueryTooltipMarkupListeners.length - 1], 346 cast(GClosureNotify)&callBackQueryTooltipMarkupDestroy, 347 connectFlags); 348 return onQueryTooltipMarkupListeners[onQueryTooltipMarkupListeners.length - 1].handlerId; 349 } 350 351 extern(C) static string callBackQueryTooltipMarkup(GtkSourceMarkAttributes* sourcemarkattributesStruct, GtkSourceMark* mark,OnQueryTooltipMarkupDelegateWrapper wrapper) 352 { 353 return wrapper.dlg(ObjectG.getDObject!(SourceMark)(mark), wrapper.outer); 354 } 355 356 extern(C) static void callBackQueryTooltipMarkupDestroy(OnQueryTooltipMarkupDelegateWrapper wrapper, GClosure* closure) 357 { 358 wrapper.outer.internalRemoveOnQueryTooltipMarkup(wrapper); 359 } 360 361 protected void internalRemoveOnQueryTooltipMarkup(OnQueryTooltipMarkupDelegateWrapper source) 362 { 363 foreach(index, wrapper; onQueryTooltipMarkupListeners) 364 { 365 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 366 { 367 onQueryTooltipMarkupListeners[index] = null; 368 onQueryTooltipMarkupListeners = std.algorithm.remove(onQueryTooltipMarkupListeners, index); 369 break; 370 } 371 } 372 } 373 374 375 protected class OnQueryTooltipTextDelegateWrapper 376 { 377 string delegate(SourceMark, SourceMarkAttributes) dlg; 378 gulong handlerId; 379 ConnectFlags flags; 380 this(string delegate(SourceMark, SourceMarkAttributes) dlg, gulong handlerId, ConnectFlags flags) 381 { 382 this.dlg = dlg; 383 this.handlerId = handlerId; 384 this.flags = flags; 385 } 386 } 387 protected OnQueryTooltipTextDelegateWrapper[] onQueryTooltipTextListeners; 388 389 /** 390 * The code should connect to this signal to provide a tooltip for given 391 * @mark. The tooltip should be just a plain text. 392 * 393 * Params: 394 * mark = The #GtkSourceMark. 395 * 396 * Return: A tooltip. The string should be freed with 397 * g_free() when done with it. 398 */ 399 gulong addOnQueryTooltipText(string delegate(SourceMark, SourceMarkAttributes) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 400 { 401 onQueryTooltipTextListeners ~= new OnQueryTooltipTextDelegateWrapper(dlg, 0, connectFlags); 402 onQueryTooltipTextListeners[onQueryTooltipTextListeners.length - 1].handlerId = Signals.connectData( 403 this, 404 "query-tooltip-text", 405 cast(GCallback)&callBackQueryTooltipText, 406 cast(void*)onQueryTooltipTextListeners[onQueryTooltipTextListeners.length - 1], 407 cast(GClosureNotify)&callBackQueryTooltipTextDestroy, 408 connectFlags); 409 return onQueryTooltipTextListeners[onQueryTooltipTextListeners.length - 1].handlerId; 410 } 411 412 extern(C) static string callBackQueryTooltipText(GtkSourceMarkAttributes* sourcemarkattributesStruct, GtkSourceMark* mark,OnQueryTooltipTextDelegateWrapper wrapper) 413 { 414 return wrapper.dlg(ObjectG.getDObject!(SourceMark)(mark), wrapper.outer); 415 } 416 417 extern(C) static void callBackQueryTooltipTextDestroy(OnQueryTooltipTextDelegateWrapper wrapper, GClosure* closure) 418 { 419 wrapper.outer.internalRemoveOnQueryTooltipText(wrapper); 420 } 421 422 protected void internalRemoveOnQueryTooltipText(OnQueryTooltipTextDelegateWrapper source) 423 { 424 foreach(index, wrapper; onQueryTooltipTextListeners) 425 { 426 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 427 { 428 onQueryTooltipTextListeners[index] = null; 429 onQueryTooltipTextListeners = std.algorithm.remove(onQueryTooltipTextListeners, index); 430 break; 431 } 432 } 433 } 434 435 }