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 gtk.StockItem;
26 
27 private import glib.ListSG;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtkc.Loader;
31 private import gtkc.gtk;
32 public  import gtkc.gtktypes;
33 private import gtkc.paths;
34 
35 
36 public class StockItem
37 {
38 	/** the main Gtk struct */
39 	protected GtkStockItem* gtkStockItem;
40 
41 	/** Get the main Gtk struct */
42 	public GtkStockItem* getStockItemStruct()
43 	{
44 		return gtkStockItem;
45 	}
46 
47 	/** the main Gtk struct as a void* */
48 	protected void* getStruct()
49 	{
50 		return cast(void*)gtkStockItem;
51 	}
52 
53 	/**
54 	 * Sets our main struct and passes it to the parent class.
55 	 */
56 	public this (GtkStockItem* gtkStockItem)
57 	{
58 		this.gtkStockItem = gtkStockItem;
59 	}
60 
61 	~this ()
62 	{
63 		if (  Linker.isLoaded(LIBRARY.GTK) && gtkStockItem !is null )
64 		{
65 			gtk_stock_item_free(gtkStockItem);
66 		}
67 	}
68 
69 	/**
70 	 */
71 
72 	/**
73 	 * Copies a stock item, mostly useful for language bindings and not in applications.
74 	 *
75 	 * Return: a new #GtkStockItem
76 	 */
77 	public StockItem copy()
78 	{
79 		auto p = gtk_stock_item_copy(gtkStockItem);
80 		
81 		if(p is null)
82 		{
83 			return null;
84 		}
85 		
86 		return ObjectG.getDObject!(StockItem)(cast(GtkStockItem*) p);
87 	}
88 
89 	/**
90 	 * Frees a stock item allocated on the heap, such as one returned by
91 	 * gtk_stock_item_copy(). Also frees the fields inside the stock item,
92 	 * if they are not %NULL.
93 	 */
94 	public void free()
95 	{
96 		gtk_stock_item_free(gtkStockItem);
97 	}
98 
99 	/**
100 	 * Registers each of the stock items in @items. If an item already
101 	 * exists with the same stock ID as one of the @items, the old item
102 	 * gets replaced. The stock items are copied, so GTK+ does not hold
103 	 * any pointer into @items and @items can be freed. Use
104 	 * gtk_stock_add_static() if @items is persistent and GTK+ need not
105 	 * copy the array.
106 	 *
107 	 * Params:
108 	 *     items = a #GtkStockItem or array of items
109 	 *     nItems = number of #GtkStockItem in @items
110 	 */
111 	public static void stockAdd(StockItem[] items)
112 	{
113 		GtkStockItem[] itemsArray = new GtkStockItem[items.length];
114 		for ( int i = 0; i < items.length; i++ )
115 		{
116 			itemsArray[i] = *(items[i].getStockItemStruct());
117 		}
118 		
119 		gtk_stock_add(itemsArray.ptr, cast(uint)items.length);
120 	}
121 
122 	/**
123 	 * Same as gtk_stock_add(), but doesn’t copy @items, so
124 	 * @items must persist until application exit.
125 	 *
126 	 * Params:
127 	 *     items = a #GtkStockItem or array of #GtkStockItem
128 	 *     nItems = number of items
129 	 */
130 	public static void stockAddStatic(StockItem[] items)
131 	{
132 		GtkStockItem[] itemsArray = new GtkStockItem[items.length];
133 		for ( int i = 0; i < items.length; i++ )
134 		{
135 			itemsArray[i] = *(items[i].getStockItemStruct());
136 		}
137 		
138 		gtk_stock_add_static(itemsArray.ptr, cast(uint)items.length);
139 	}
140 
141 	/**
142 	 * Retrieves a list of all known stock IDs added to a #GtkIconFactory
143 	 * or registered with gtk_stock_add(). The list must be freed with g_slist_free(),
144 	 * and each string in the list must be freed with g_free().
145 	 *
146 	 * Return: a list of known stock IDs
147 	 */
148 	public static ListSG stockListIds()
149 	{
150 		auto p = gtk_stock_list_ids();
151 		
152 		if(p is null)
153 		{
154 			return null;
155 		}
156 		
157 		return new ListSG(cast(GSList*) p);
158 	}
159 
160 	/**
161 	 * Fills @item with the registered values for @stock_id, returning %TRUE
162 	 * if @stock_id was known.
163 	 *
164 	 * Params:
165 	 *     stockId = a stock item name
166 	 *     item = stock item to initialize with values
167 	 *
168 	 * Return: %TRUE if @item was initialized
169 	 */
170 	public static bool stockLookup(string stockId, out StockItem item)
171 	{
172 		GtkStockItem* outitem = new GtkStockItem;
173 		
174 		auto p = gtk_stock_lookup(Str.toStringz(stockId), outitem) != 0;
175 		
176 		item = ObjectG.getDObject!(StockItem)(outitem);
177 		
178 		return p;
179 	}
180 
181 	/**
182 	 * Sets a function to be used for translating the @label of
183 	 * a stock item.
184 	 *
185 	 * If no function is registered for a translation domain,
186 	 * g_dgettext() is used.
187 	 *
188 	 * The function is used for all stock items whose
189 	 * @translation_domain matches @domain. Note that it is possible
190 	 * to use strings different from the actual gettext translation domain
191 	 * of your application for this, as long as your #GtkTranslateFunc uses
192 	 * the correct domain when calling dgettext(). This can be useful, e.g.
193 	 * when dealing with message contexts:
194 	 *
195 	 * |[<!-- language="C" -->
196 	 * GtkStockItem items[] = {
197 	 * { MY_ITEM1, NC_("odd items", "Item 1"), 0, 0, "odd-item-domain" },
198 	 * { MY_ITEM2, NC_("even items", "Item 2"), 0, 0, "even-item-domain" },
199 	 * };
200 	 *
201 	 * gchar *
202 	 * my_translate_func (const gchar *msgid,
203 	 * gpointer     data)
204 	 * {
205 	 * gchar *msgctxt = data;
206 	 *
207 	 * return (gchar*)g_dpgettext2 (GETTEXT_PACKAGE, msgctxt, msgid);
208 	 * }
209 	 *
210 	 * ...
211 	 *
212 	 * gtk_stock_add (items, G_N_ELEMENTS (items));
213 	 * gtk_stock_set_translate_func ("odd-item-domain", my_translate_func, "odd items");
214 	 * gtk_stock_set_translate_func ("even-item-domain", my_translate_func, "even items");
215 	 * ]|
216 	 *
217 	 * Params:
218 	 *     domain = the translation domain for which @func shall be used
219 	 *     func = a #GtkTranslateFunc
220 	 *     data = data to pass to @func
221 	 *     notify = a #GDestroyNotify that is called when @data is
222 	 *         no longer needed
223 	 *
224 	 * Since: 2.8
225 	 */
226 	public static void stockSetTranslateFunc(string domain, GtkTranslateFunc func, void* data, GDestroyNotify notify)
227 	{
228 		gtk_stock_set_translate_func(Str.toStringz(domain), func, data, notify);
229 	}
230 }