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