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