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