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  * Conversion parameters:
26  * inFile  = GtkSourceMarkAttributes.html
27  * outPack = gsv
28  * outFile = SourceMarkAttributes
29  * strct   = GtkSourceMarkAttributes
30  * realStrct=
31  * ctorStrct=
32  * clss    = SourceMarkAttributes
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_source_mark_attributes_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- gio.Icon
48  * 	- gio.IconIF
49  * 	- gdk.Pixbuf
50  * 	- gdk.RGBA
51  * 	- gsv.SourceMark
52  * 	- gtk.Widget
53  * structWrap:
54  * 	- GIcon* -> IconIF
55  * 	- GdkPixbuf* -> Pixbuf
56  * 	- GdkRGBA* -> RGBA
57  * 	- GtkSourceMark* -> SourceMark
58  * 	- GtkWidget* -> Widget
59  * module aliases:
60  * local aliases:
61  * overrides:
62  */
63 
64 module gsv.SourceMarkAttributes;
65 
66 public  import gsvc.gsvtypes;
67 
68 private import gsvc.gsv;
69 private import glib.ConstructionException;
70 private import gobject.ObjectG;
71 
72 private import gobject.Signals;
73 public  import gtkc.gdktypes;
74 private import glib.Str;
75 private import gio.Icon;
76 private import gio.IconIF;
77 private import gdk.Pixbuf;
78 private import gdk.RGBA;
79 private import gsv.SourceMark;
80 private import gtk.Widget;
81 
82 
83 private import gobject.ObjectG;
84 
85 /**
86  * GtkSourceMarkAttributes is an object specifying attributes used by
87  * a GtkSourceView to visually show lines marked with GtkSourceMarks
88  * of a specific category. It allows you to define a background color of a line,
89  * an icon shown in gutter and tooltips.
90  *
91  * The background color is used as a background of a line where a mark is placed
92  * and it can be set with gtk_source_mark_attributes_set_background(). To check
93  * if any custom background color was defined and what color it is, use
94  * gtk_source_mark_attributes_get_background().
95  *
96  * An icon is a graphic element which is shown in the gutter of a view. An
97  * example use is showing a red filled circle in a debugger to show that a
98  * breakpoint was set in certain line. To get an icon that will be placed in
99  * a gutter, first a base for it must be specified and then
100  * gtk_source_mark_attributes_render_icon() must be called.
101  * There are several ways to specify a base for an icon:
102  *
103  *  gtk_source_mark_attributes_set_icon_name()
104  *
105  *  gtk_source_mark_attributes_set_stock_id()
106  *
107  *  gtk_source_mark_attributes_set_gicon()
108  *
109  *  gtk_source_mark_attributes_set_pixbuf()
110  *
111  * Using any of the above functions overrides the one used earlier. But note
112  * that a getter counterpart of earlier used function can still return some
113  * value, but it is just not used when rendering the proper icon.
114  *
115  * To provide meaningful tooltips for a given mark of a category, you should
116  * connect to "query-tooltip-text" or
117  * "query-tooltip-markup" where the latter
118  * takes precedence.
119  */
120 public class SourceMarkAttributes : ObjectG
121 {
122 	
123 	/** the main Gtk struct */
124 	protected GtkSourceMarkAttributes* gtkSourceMarkAttributes;
125 	
126 	
127 	/** Get the main Gtk struct */
128 	public GtkSourceMarkAttributes* getSourceMarkAttributesStruct()
129 	{
130 		return gtkSourceMarkAttributes;
131 	}
132 	
133 	
134 	/** the main Gtk struct as a void* */
135 	protected override void* getStruct()
136 	{
137 		return cast(void*)gtkSourceMarkAttributes;
138 	}
139 	
140 	/**
141 	 * Sets our main struct and passes it to the parent class
142 	 */
143 	public this (GtkSourceMarkAttributes* gtkSourceMarkAttributes)
144 	{
145 		super(cast(GObject*)gtkSourceMarkAttributes);
146 		this.gtkSourceMarkAttributes = gtkSourceMarkAttributes;
147 	}
148 	
149 	protected override void setStruct(GObject* obj)
150 	{
151 		super.setStruct(obj);
152 		gtkSourceMarkAttributes = cast(GtkSourceMarkAttributes*)obj;
153 	}
154 	
155 	/** */
156 	public void setStockId(StockID stockId)
157 	{
158 		setStockId(StockDesc[stockId]);
159 	}
160 	
161 	/**
162 	 */
163 	int[string] connectedSignals;
164 	
165 	string delegate(SourceMark, SourceMarkAttributes)[] onQueryTooltipMarkupListeners;
166 	/**
167 	 * The code should connect to this signal to provide a tooltip for given
168 	 * mark. The tooltip can contain a markup.
169 	 */
170 	void addOnQueryTooltipMarkup(string delegate(SourceMark, SourceMarkAttributes) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
171 	{
172 		if ( !("query-tooltip-markup" in connectedSignals) )
173 		{
174 			Signals.connectData(
175 			getStruct(),
176 			"query-tooltip-markup",
177 			cast(GCallback)&callBackQueryTooltipMarkup,
178 			cast(void*)this,
179 			null,
180 			connectFlags);
181 			connectedSignals["query-tooltip-markup"] = 1;
182 		}
183 		onQueryTooltipMarkupListeners ~= dlg;
184 	}
185 	extern(C) static void callBackQueryTooltipMarkup(GtkSourceMarkAttributes* attributesStruct, GtkSourceMark* mark, SourceMarkAttributes _sourceMarkAttributes)
186 	{
187 		foreach ( string delegate(SourceMark, SourceMarkAttributes) dlg ; _sourceMarkAttributes.onQueryTooltipMarkupListeners )
188 		{
189 			dlg(ObjectG.getDObject!(SourceMark)(mark), _sourceMarkAttributes);
190 		}
191 	}
192 	
193 	string delegate(SourceMark, SourceMarkAttributes)[] onQueryTooltipTextListeners;
194 	/**
195 	 * The code should connect to this signal to provide a tooltip for given
196 	 * mark. The tooltip should be just a plain text.
197 	 * See Also
198 	 * GtkSourceMark
199 	 */
200 	void addOnQueryTooltipText(string delegate(SourceMark, SourceMarkAttributes) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
201 	{
202 		if ( !("query-tooltip-text" in connectedSignals) )
203 		{
204 			Signals.connectData(
205 			getStruct(),
206 			"query-tooltip-text",
207 			cast(GCallback)&callBackQueryTooltipText,
208 			cast(void*)this,
209 			null,
210 			connectFlags);
211 			connectedSignals["query-tooltip-text"] = 1;
212 		}
213 		onQueryTooltipTextListeners ~= dlg;
214 	}
215 	extern(C) static void callBackQueryTooltipText(GtkSourceMarkAttributes* attributesStruct, GtkSourceMark* mark, SourceMarkAttributes _sourceMarkAttributes)
216 	{
217 		foreach ( string delegate(SourceMark, SourceMarkAttributes) dlg ; _sourceMarkAttributes.onQueryTooltipTextListeners )
218 		{
219 			dlg(ObjectG.getDObject!(SourceMark)(mark), _sourceMarkAttributes);
220 		}
221 	}
222 	
223 	
224 	/**
225 	 * Creates a new source mark attributes.
226 	 * Throws: ConstructionException GTK+ fails to create the object.
227 	 */
228 	public this ()
229 	{
230 		// GtkSourceMarkAttributes * gtk_source_mark_attributes_new  (void);
231 		auto p = gtk_source_mark_attributes_new();
232 		if(p is null)
233 		{
234 			throw new ConstructionException("null returned by gtk_source_mark_attributes_new()");
235 		}
236 		this(cast(GtkSourceMarkAttributes*) p);
237 	}
238 	
239 	/**
240 	 * Sets background color to the one given in background.
241 	 * Params:
242 	 * background = a GdkRGBA.
243 	 */
244 	public void setBackground(RGBA background)
245 	{
246 		// void gtk_source_mark_attributes_set_background  (GtkSourceMarkAttributes *attributes,  const GdkRGBA *background);
247 		gtk_source_mark_attributes_set_background(gtkSourceMarkAttributes, (background is null) ? null : background.getRGBAStruct());
248 	}
249 	
250 	/**
251 	 * Stores background color in background.
252 	 * Params:
253 	 * background = a GdkRGBA. [out caller-allocates]
254 	 * Returns: whether background color for attributes was set.
255 	 */
256 	public int getBackground(RGBA background)
257 	{
258 		// gboolean gtk_source_mark_attributes_get_background  (GtkSourceMarkAttributes *attributes,  GdkRGBA *background);
259 		return gtk_source_mark_attributes_get_background(gtkSourceMarkAttributes, (background is null) ? null : background.getRGBAStruct());
260 	}
261 	
262 	/**
263 	 * Warning
264 	 * gtk_source_mark_attributes_set_stock_id has been deprecated since version 3.10 and should not be used in newly-written code. Don't use this function.
265 	 * Sets stock id to be used as a base for rendered icon.
266 	 * Params:
267 	 * stockId = a stock id.
268 	 */
269 	public void setStockId(string stockId)
270 	{
271 		// void gtk_source_mark_attributes_set_stock_id  (GtkSourceMarkAttributes *attributes,  const gchar *stock_id);
272 		gtk_source_mark_attributes_set_stock_id(gtkSourceMarkAttributes, Str.toStringz(stockId));
273 	}
274 	
275 	/**
276 	 * Warning
277 	 * gtk_source_mark_attributes_get_stock_id has been deprecated since version 3.10 and should not be used in newly-written code. Don't use this function.
278 	 * Gets a stock id of an icon used by this attributes. Note that the stock id can
279 	 * be NULL if it wasn't set earlier.
280 	 * Returns: Stock id. Returned string is owned by attributes and shouldn't be freed. [transfer none]
281 	 */
282 	public string getStockId()
283 	{
284 		// const gchar * gtk_source_mark_attributes_get_stock_id  (GtkSourceMarkAttributes *attributes);
285 		return Str.toString(gtk_source_mark_attributes_get_stock_id(gtkSourceMarkAttributes));
286 	}
287 	
288 	/**
289 	 * Sets a name of an icon to be used as a base for rendered icon.
290 	 * Params:
291 	 * iconName = name of an icon to be used.
292 	 */
293 	public void setIconName(string iconName)
294 	{
295 		// void gtk_source_mark_attributes_set_icon_name  (GtkSourceMarkAttributes *attributes,  const gchar *icon_name);
296 		gtk_source_mark_attributes_set_icon_name(gtkSourceMarkAttributes, Str.toStringz(iconName));
297 	}
298 	
299 	/**
300 	 * Gets a name of an icon to be used as a base for rendered icon. Note that the
301 	 * icon name can be NULL if it wasn't set earlier.
302 	 * Returns: An icon name. The string belongs to attributes and should not be freed. [transfer none]
303 	 */
304 	public string getIconName()
305 	{
306 		// const gchar * gtk_source_mark_attributes_get_icon_name  (GtkSourceMarkAttributes *attributes);
307 		return Str.toString(gtk_source_mark_attributes_get_icon_name(gtkSourceMarkAttributes));
308 	}
309 	
310 	/**
311 	 * Sets an icon to be used as a base for rendered icon.
312 	 * Params:
313 	 * gicon = a GIcon to be used.
314 	 */
315 	public void setGicon(IconIF gicon)
316 	{
317 		// void gtk_source_mark_attributes_set_gicon  (GtkSourceMarkAttributes *attributes,  GIcon *gicon);
318 		gtk_source_mark_attributes_set_gicon(gtkSourceMarkAttributes, (gicon is null) ? null : gicon.getIconTStruct());
319 	}
320 	
321 	/**
322 	 * Gets a GIcon to be used as a base for rendered icon. Note that the icon can
323 	 * be NULL if it wasn't set earlier.
324 	 * Returns: An icon. The icon belongs to attributes and should not be unreffed. [transfer none]
325 	 */
326 	public IconIF getGicon()
327 	{
328 		// GIcon * gtk_source_mark_attributes_get_gicon  (GtkSourceMarkAttributes *attributes);
329 		auto p = gtk_source_mark_attributes_get_gicon(gtkSourceMarkAttributes);
330 		
331 		if(p is null)
332 		{
333 			return null;
334 		}
335 		
336 		return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p);
337 	}
338 	
339 	/**
340 	 * Sets a pixbuf to be used as a base for rendered icon.
341 	 * Params:
342 	 * pixbuf = a GdkPixbuf to be used.
343 	 */
344 	public void setPixbuf(Pixbuf pixbuf)
345 	{
346 		// void gtk_source_mark_attributes_set_pixbuf  (GtkSourceMarkAttributes *attributes,  const GdkPixbuf *pixbuf);
347 		gtk_source_mark_attributes_set_pixbuf(gtkSourceMarkAttributes, (pixbuf is null) ? null : pixbuf.getPixbufStruct());
348 	}
349 	
350 	/**
351 	 * Gets a GdkPixbuf to be used as a base for rendered icon. Note that the
352 	 * pixbuf can be NULL if it wasn't set earlier.
353 	 * Returns: A pixbuf. The pixbuf belongs to attributes and should not be unreffed. [transfer none]
354 	 */
355 	public Pixbuf getPixbuf()
356 	{
357 		// const GdkPixbuf * gtk_source_mark_attributes_get_pixbuf  (GtkSourceMarkAttributes *attributes);
358 		auto p = gtk_source_mark_attributes_get_pixbuf(gtkSourceMarkAttributes);
359 		
360 		if(p is null)
361 		{
362 			return null;
363 		}
364 		
365 		import gtkc.gobject : g_object_ref;
366 		g_object_ref(cast(GObject*)p);
367 		
368 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
369 	}
370 	
371 	/**
372 	 * Renders an icon of given size. The base of the icon is set by the last call
373 	 * to one of: gtk_source_mark_attributes_set_pixbuf(),
374 	 * gtk_source_mark_attributes_set_gicon(),
375 	 * gtk_source_mark_attributes_set_icon_name() or
376 	 * gtk_source_mark_attributes_set_stock_id(). size cannot be lower than 1.
377 	 * Params:
378 	 * widget = widget of which style settings may be used.
379 	 * size = size of the rendered icon.
380 	 * Returns: A rendered pixbuf. The pixbuf belongs to attributes and should not be unreffed. [transfer none]
381 	 */
382 	public Pixbuf renderIcon(Widget widget, int size)
383 	{
384 		// const GdkPixbuf * gtk_source_mark_attributes_render_icon  (GtkSourceMarkAttributes *attributes,  GtkWidget *widget,  gint size);
385 		auto p = gtk_source_mark_attributes_render_icon(gtkSourceMarkAttributes, (widget is null) ? null : widget.getWidgetStruct(), size);
386 		
387 		if(p is null)
388 		{
389 			return null;
390 		}
391 		
392 		import gtkc.gobject : g_object_ref;
393 		g_object_ref(cast(GObject*)p);
394 		
395 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
396 	}
397 	
398 	/**
399 	 * Queries for a tooltip by emitting
400 	 * a "query-tooltip-text" signal. The tooltip is a plain
401 	 * text.
402 	 * Params:
403 	 * mark = a GtkSourceMark.
404 	 * Returns: A tooltip. The returned string should be freed by using g_free() when done with it. [transfer full]
405 	 */
406 	public string getTooltipText(SourceMark mark)
407 	{
408 		// gchar * gtk_source_mark_attributes_get_tooltip_text  (GtkSourceMarkAttributes *attributes,  GtkSourceMark *mark);
409 		return Str.toString(gtk_source_mark_attributes_get_tooltip_text(gtkSourceMarkAttributes, (mark is null) ? null : mark.getSourceMarkStruct()));
410 	}
411 	
412 	/**
413 	 * Queries for a tooltip by emitting
414 	 * a "query-tooltip-markup" signal. The tooltip may contain
415 	 * a markup.
416 	 * Params:
417 	 * mark = a GtkSourceMark.
418 	 * Returns: A tooltip. The returned string should be freed by using g_free() when done with it. [transfer full]
419 	 */
420 	public string getTooltipMarkup(SourceMark mark)
421 	{
422 		// gchar * gtk_source_mark_attributes_get_tooltip_markup  (GtkSourceMarkAttributes *attributes,  GtkSourceMark *mark);
423 		return Str.toString(gtk_source_mark_attributes_get_tooltip_markup(gtkSourceMarkAttributes, (mark is null) ? null : mark.getSourceMarkStruct()));
424 	}
425 }