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.ImageMenuItem;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtk.AccelGroup;
31 private import gtk.MenuItem;
32 private import gtk.Widget;
33 private import gtkc.gtk;
34 public  import gtkc.gtktypes;
35 
36 
37 /**
38  * A GtkImageMenuItem is a menu item which has an icon next to the text label.
39  * 
40  * This is functionally equivalent to:
41  * 
42  * |[<!-- language="C" -->
43  * GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
44  * GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
45  * GtkWidget *label = gtk_label_new ("Music");
46  * GtkWidget *menu_item = gtk_menu_item_new ();
47  * 
48  * gtk_container_add (GTK_CONTAINER (box), icon);
49  * gtk_container_add (GTK_CONTAINER (box), label);
50  * 
51  * gtk_container_add (GTK_CONTAINER (menu_item), box);
52  * 
53  * gtk_widget_show_all (menu_item);
54  * ]|
55  * 
56  * Note that the user may disable display of menu icons using
57  * the #GtkSettings:gtk-menu-images setting, so make sure to still
58  * fill in the text label. If you want to ensure that your menu items
59  * show an icon you are strongly encouraged to use a #GtkMenuItem
60  * with a #GtkImage instead.
61  * 
62  * #GtkImageMenuItem has been deprecated since GTK+ 3.10. If you want to
63  * display an icon in a menu item, you should use #GtkMenuItem and pack a
64  * #GtkBox with a #GtkImage and a #GtkLabel instead. You should also consider
65  * using #GtkBuilder and the XML #GMenu description for creating menus, by
66  * following the [GMenu guide][https://developer.gnome.org/GMenu/]. You should
67  * consider using icons in menu items only sparingly, and for "objects" (or
68  * "nouns") elements only, like bookmarks, files, and links; "actions" (or
69  * "verbs") should not have icons.
70  */
71 public class ImageMenuItem : MenuItem
72 {
73 	/** the main Gtk struct */
74 	protected GtkImageMenuItem* gtkImageMenuItem;
75 
76 	/** Get the main Gtk struct */
77 	public GtkImageMenuItem* getImageMenuItemStruct()
78 	{
79 		return gtkImageMenuItem;
80 	}
81 
82 	/** the main Gtk struct as a void* */
83 	protected override void* getStruct()
84 	{
85 		return cast(void*)gtkImageMenuItem;
86 	}
87 
88 	protected override void setStruct(GObject* obj)
89 	{
90 		gtkImageMenuItem = cast(GtkImageMenuItem*)obj;
91 		super.setStruct(obj);
92 	}
93 
94 	/**
95 	 * Sets our main struct and passes it to the parent class.
96 	 */
97 	public this (GtkImageMenuItem* gtkImageMenuItem, bool ownedRef = false)
98 	{
99 		this.gtkImageMenuItem = gtkImageMenuItem;
100 		super(cast(GtkMenuItem*)gtkImageMenuItem, ownedRef);
101 	}
102 
103 	/**
104 	 * Creates a new GtkImageMenuItem containing a label.
105 	 * If mnemonic it true the label will be created using
106 	 * gtk_label_new_with_mnemonic(), so underscores
107 	 * in label indicate the mnemonic for the menu item.
108 	 * Params:
109 	 *  label = the text of the menu item.
110 	 * Throws: ConstructionException GTK+ fails to create the object.
111 	 */
112 	public this (string label, bool mnemonic=true)
113 	{
114 		GtkImageMenuItem* p;
115 		
116 		if ( mnemonic )
117 		{
118 			// GtkWidget* gtk_image_menu_item_new_with_mnemonic  (const gchar *label);
119 			p = cast(GtkImageMenuItem*)gtk_image_menu_item_new_with_mnemonic(Str.toStringz(label));
120 		}
121 		else
122 		{
123 			// GtkWidget* gtk_image_menu_item_new_with_label  (const gchar *label);
124 			p = cast(GtkImageMenuItem*)gtk_image_menu_item_new_with_label(Str.toStringz(label));
125 		}
126 		
127 		if(p is null)
128 		{
129 			throw new ConstructionException("null returned by gtk_image_menu_item_new_with_");
130 		}
131 		
132 		this(p);
133 	}
134 	
135 	/**
136 	 * Creates a new GtkImageMenuItem containing the image and text from a
137 	 * stock item.
138 	 * If you want this menu item to have changeable accelerators, then pass in
139 	 * null for accelGroup. Next call setAccelPath() with an appropriate path
140 	 * for the menu item, use gtk.StockItem.StockItem.lookup() to look up the
141 	 * standard accelerator for the stock item, and if one is found, call
142 	 * gtk.AccelMap.AccelMap.addEntry() to register it.
143 	 * Params:
144 	 *   StockID    = the name of the stock item
145 	 *   accelGroup = the GtkAccelGroup to add the menu items accelerator to,
146 	 *                or NULL.
147 	 * Throws: ConstructionException GTK+ fails to create the object.
148 	 */
149 	public this (StockID stockID, AccelGroup accelGroup)
150 	{
151 		auto p = gtk_image_menu_item_new_from_stock(Str.toStringz(stockID), (accelGroup is null) ? null : accelGroup.getAccelGroupStruct());
152 		if(p is null)
153 		{
154 			throw new ConstructionException("null returned by gtk_image_menu_item_new_from_stock");
155 		}
156 		this(cast(GtkImageMenuItem*) p);
157 	}
158 
159 	/**
160 	 */
161 
162 	public static GType getType()
163 	{
164 		return gtk_image_menu_item_get_type();
165 	}
166 
167 	/**
168 	 * Creates a new #GtkImageMenuItem with an empty label.
169 	 *
170 	 * Deprecated: Use gtk_menu_item_new() instead.
171 	 *
172 	 * Return: a new #GtkImageMenuItem
173 	 *
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this()
177 	{
178 		auto p = gtk_image_menu_item_new();
179 		
180 		if(p is null)
181 		{
182 			throw new ConstructionException("null returned by new");
183 		}
184 		
185 		this(cast(GtkImageMenuItem*) p);
186 	}
187 
188 	/**
189 	 * Returns whether the menu item will ignore the #GtkSettings:gtk-menu-images
190 	 * setting and always show the image, if available.
191 	 *
192 	 * Return: %TRUE if the menu item will always show the image
193 	 *
194 	 * Since: 2.16
195 	 */
196 	public bool getAlwaysShowImage()
197 	{
198 		return gtk_image_menu_item_get_always_show_image(gtkImageMenuItem) != 0;
199 	}
200 
201 	/**
202 	 * Gets the widget that is currently set as the image of @image_menu_item.
203 	 * See gtk_image_menu_item_set_image().
204 	 *
205 	 * Return: the widget set as image of @image_menu_item
206 	 */
207 	public Widget getImage()
208 	{
209 		auto p = gtk_image_menu_item_get_image(gtkImageMenuItem);
210 		
211 		if(p is null)
212 		{
213 			return null;
214 		}
215 		
216 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
217 	}
218 
219 	/**
220 	 * Checks whether the label set in the menuitem is used as a
221 	 * stock id to select the stock item for the item.
222 	 *
223 	 * Return: %TRUE if the label set in the menuitem is used as a
224 	 *     stock id to select the stock item for the item
225 	 *
226 	 * Since: 2.16
227 	 */
228 	public bool getUseStock()
229 	{
230 		return gtk_image_menu_item_get_use_stock(gtkImageMenuItem) != 0;
231 	}
232 
233 	/**
234 	 * Specifies an @accel_group to add the menu items accelerator to
235 	 * (this only applies to stock items so a stock item must already
236 	 * be set, make sure to call gtk_image_menu_item_set_use_stock()
237 	 * and gtk_menu_item_set_label() with a valid stock item first).
238 	 *
239 	 * If you want this menu item to have changeable accelerators then
240 	 * you shouldnt need this (see gtk_image_menu_item_new_from_stock()).
241 	 *
242 	 * Params:
243 	 *     accelGroup = the #GtkAccelGroup
244 	 *
245 	 * Since: 2.16
246 	 */
247 	public void setAccelGroup(AccelGroup accelGroup)
248 	{
249 		gtk_image_menu_item_set_accel_group(gtkImageMenuItem, (accelGroup is null) ? null : accelGroup.getAccelGroupStruct());
250 	}
251 
252 	/**
253 	 * If %TRUE, the menu item will ignore the #GtkSettings:gtk-menu-images
254 	 * setting and always show the image, if available.
255 	 *
256 	 * Use this property if the menuitem would be useless or hard to use
257 	 * without the image.
258 	 *
259 	 * Params:
260 	 *     alwaysShow = %TRUE if the menuitem should always show the image
261 	 *
262 	 * Since: 2.16
263 	 */
264 	public void setAlwaysShowImage(bool alwaysShow)
265 	{
266 		gtk_image_menu_item_set_always_show_image(gtkImageMenuItem, alwaysShow);
267 	}
268 
269 	/**
270 	 * Sets the image of @image_menu_item to the given widget.
271 	 * Note that it depends on the show-menu-images setting whether
272 	 * the image will be displayed or not.
273 	 *
274 	 * Params:
275 	 *     image = a widget to set as the image for the menu item.
276 	 */
277 	public void setImage(Widget image)
278 	{
279 		gtk_image_menu_item_set_image(gtkImageMenuItem, (image is null) ? null : image.getWidgetStruct());
280 	}
281 
282 	/**
283 	 * If %TRUE, the label set in the menuitem is used as a
284 	 * stock id to select the stock item for the item.
285 	 *
286 	 * Params:
287 	 *     useStock = %TRUE if the menuitem should use a stock item
288 	 *
289 	 * Since: 2.16
290 	 */
291 	public void setUseStock(bool useStock)
292 	{
293 		gtk_image_menu_item_set_use_stock(gtkImageMenuItem, useStock);
294 	}
295 }