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  * Furthermore, if you would like to display keyboard accelerator, you must
72  * pack the accel label into the box using gtk_box_pack_end() and align the
73  * label, otherwise the accelerator will not display correctly. The following
74  * code snippet adds a keyboard accelerator to the menu item, with a key
75  * binding of Ctrl+M:
76  * 
77  * |[<!-- language="C" -->
78  * GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
79  * GtkWidget *icon = gtk_image_new_from_icon_name ("folder-music-symbolic", GTK_ICON_SIZE_MENU);
80  * GtkWidget *label = gtk_accel_label_new ("Music");
81  * GtkWidget *menu_item = gtk_menu_item_new ();
82  * GtkAccelGroup *accel_group = gtk_accel_group_new ();
83  * 
84  * gtk_container_add (GTK_CONTAINER (box), icon);
85  * 
86  * gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
87  * gtk_label_set_xalign (GTK_LABEL (label), 0.0);
88  * 
89  * gtk_widget_add_accelerator (menu_item, "activate", accel_group,
90  * GDK_KEY_m, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
91  * gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label), menu_item);
92  * 
93  * gtk_box_pack_end (GTK_BOX (box), label, TRUE, TRUE, 0);
94  * 
95  * gtk_container_add (GTK_CONTAINER (menu_item), box);
96  * 
97  * gtk_widget_show_all (menu_item);
98  * ]|
99  */
100 public class ImageMenuItem : MenuItem
101 {
102 	/** the main Gtk struct */
103 	protected GtkImageMenuItem* gtkImageMenuItem;
104 
105 	/** Get the main Gtk struct */
106 	public GtkImageMenuItem* getImageMenuItemStruct()
107 	{
108 		return gtkImageMenuItem;
109 	}
110 
111 	/** the main Gtk struct as a void* */
112 	protected override void* getStruct()
113 	{
114 		return cast(void*)gtkImageMenuItem;
115 	}
116 
117 	protected override void setStruct(GObject* obj)
118 	{
119 		gtkImageMenuItem = cast(GtkImageMenuItem*)obj;
120 		super.setStruct(obj);
121 	}
122 
123 	/**
124 	 * Sets our main struct and passes it to the parent class.
125 	 */
126 	public this (GtkImageMenuItem* gtkImageMenuItem, bool ownedRef = false)
127 	{
128 		this.gtkImageMenuItem = gtkImageMenuItem;
129 		super(cast(GtkMenuItem*)gtkImageMenuItem, ownedRef);
130 	}
131 
132 	/**
133 	 * Creates a new GtkImageMenuItem containing a label.
134 	 * If mnemonic it true the label will be created using
135 	 * gtk_label_new_with_mnemonic(), so underscores
136 	 * in label indicate the mnemonic for the menu item.
137 	 * Params:
138 	 *  label = the text of the menu item.
139 	 * Throws: ConstructionException GTK+ fails to create the object.
140 	 */
141 	public this (string label, bool mnemonic=true)
142 	{
143 		GtkImageMenuItem* p;
144 		
145 		if ( mnemonic )
146 		{
147 			// GtkWidget* gtk_image_menu_item_new_with_mnemonic  (const gchar *label);
148 			p = cast(GtkImageMenuItem*)gtk_image_menu_item_new_with_mnemonic(Str.toStringz(label));
149 		}
150 		else
151 		{
152 			// GtkWidget* gtk_image_menu_item_new_with_label  (const gchar *label);
153 			p = cast(GtkImageMenuItem*)gtk_image_menu_item_new_with_label(Str.toStringz(label));
154 		}
155 		
156 		if(p is null)
157 		{
158 			throw new ConstructionException("null returned by gtk_image_menu_item_new_with_");
159 		}
160 		
161 		this(p);
162 	}
163 	
164 	/**
165 	 * Creates a new GtkImageMenuItem containing the image and text from a
166 	 * stock item.
167 	 * If you want this menu item to have changeable accelerators, then pass in
168 	 * null for accelGroup. Next call setAccelPath() with an appropriate path
169 	 * for the menu item, use gtk.StockItem.StockItem.lookup() to look up the
170 	 * standard accelerator for the stock item, and if one is found, call
171 	 * gtk.AccelMap.AccelMap.addEntry() to register it.
172 	 * Params:
173 	 *   StockID    = the name of the stock item
174 	 *   accelGroup = the GtkAccelGroup to add the menu items accelerator to,
175 	 *                or NULL.
176 	 * Throws: ConstructionException GTK+ fails to create the object.
177 	 */
178 	public this (StockID stockID, AccelGroup accelGroup)
179 	{
180 		auto p = gtk_image_menu_item_new_from_stock(Str.toStringz(stockID), (accelGroup is null) ? null : accelGroup.getAccelGroupStruct());
181 		if(p is null)
182 		{
183 			throw new ConstructionException("null returned by gtk_image_menu_item_new_from_stock");
184 		}
185 		this(cast(GtkImageMenuItem*) p);
186 	}
187 
188 	/**
189 	 */
190 
191 	/** */
192 	public static GType getType()
193 	{
194 		return gtk_image_menu_item_get_type();
195 	}
196 
197 	/**
198 	 * Creates a new #GtkImageMenuItem with an empty label.
199 	 *
200 	 * Deprecated: Use gtk_menu_item_new() instead.
201 	 *
202 	 * Return: a new #GtkImageMenuItem
203 	 *
204 	 * Throws: ConstructionException GTK+ fails to create the object.
205 	 */
206 	public this()
207 	{
208 		auto p = gtk_image_menu_item_new();
209 		
210 		if(p is null)
211 		{
212 			throw new ConstructionException("null returned by new");
213 		}
214 		
215 		this(cast(GtkImageMenuItem*) p);
216 	}
217 
218 	/**
219 	 * Returns whether the menu item will ignore the #GtkSettings:gtk-menu-images
220 	 * setting and always show the image, if available.
221 	 *
222 	 * Return: %TRUE if the menu item will always show the image
223 	 *
224 	 * Since: 2.16
225 	 */
226 	public bool getAlwaysShowImage()
227 	{
228 		return gtk_image_menu_item_get_always_show_image(gtkImageMenuItem) != 0;
229 	}
230 
231 	/**
232 	 * Gets the widget that is currently set as the image of @image_menu_item.
233 	 * See gtk_image_menu_item_set_image().
234 	 *
235 	 * Return: the widget set as image of @image_menu_item
236 	 */
237 	public Widget getImage()
238 	{
239 		auto p = gtk_image_menu_item_get_image(gtkImageMenuItem);
240 		
241 		if(p is null)
242 		{
243 			return null;
244 		}
245 		
246 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
247 	}
248 
249 	/**
250 	 * Checks whether the label set in the menuitem is used as a
251 	 * stock id to select the stock item for the item.
252 	 *
253 	 * Return: %TRUE if the label set in the menuitem is used as a
254 	 *     stock id to select the stock item for the item
255 	 *
256 	 * Since: 2.16
257 	 */
258 	public bool getUseStock()
259 	{
260 		return gtk_image_menu_item_get_use_stock(gtkImageMenuItem) != 0;
261 	}
262 
263 	/**
264 	 * Specifies an @accel_group to add the menu items accelerator to
265 	 * (this only applies to stock items so a stock item must already
266 	 * be set, make sure to call gtk_image_menu_item_set_use_stock()
267 	 * and gtk_menu_item_set_label() with a valid stock item first).
268 	 *
269 	 * If you want this menu item to have changeable accelerators then
270 	 * you shouldnt need this (see gtk_image_menu_item_new_from_stock()).
271 	 *
272 	 * Params:
273 	 *     accelGroup = the #GtkAccelGroup
274 	 *
275 	 * Since: 2.16
276 	 */
277 	public void setAccelGroup(AccelGroup accelGroup)
278 	{
279 		gtk_image_menu_item_set_accel_group(gtkImageMenuItem, (accelGroup is null) ? null : accelGroup.getAccelGroupStruct());
280 	}
281 
282 	/**
283 	 * If %TRUE, the menu item will ignore the #GtkSettings:gtk-menu-images
284 	 * setting and always show the image, if available.
285 	 *
286 	 * Use this property if the menuitem would be useless or hard to use
287 	 * without the image.
288 	 *
289 	 * Params:
290 	 *     alwaysShow = %TRUE if the menuitem should always show the image
291 	 *
292 	 * Since: 2.16
293 	 */
294 	public void setAlwaysShowImage(bool alwaysShow)
295 	{
296 		gtk_image_menu_item_set_always_show_image(gtkImageMenuItem, alwaysShow);
297 	}
298 
299 	/**
300 	 * Sets the image of @image_menu_item to the given widget.
301 	 * Note that it depends on the show-menu-images setting whether
302 	 * the image will be displayed or not.
303 	 *
304 	 * Params:
305 	 *     image = a widget to set as the image for the menu item.
306 	 */
307 	public void setImage(Widget image)
308 	{
309 		gtk_image_menu_item_set_image(gtkImageMenuItem, (image is null) ? null : image.getWidgetStruct());
310 	}
311 
312 	/**
313 	 * If %TRUE, the label set in the menuitem is used as a
314 	 * stock id to select the stock item for the item.
315 	 *
316 	 * Params:
317 	 *     useStock = %TRUE if the menuitem should use a stock item
318 	 *
319 	 * Since: 2.16
320 	 */
321 	public void setUseStock(bool useStock)
322 	{
323 		gtk_image_menu_item_set_use_stock(gtkImageMenuItem, useStock);
324 	}
325 }