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