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