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