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