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