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 	public static GType getType()
192 	{
193 		return gtk_image_menu_item_get_type();
194 	}
195 
196 	/**
197 	 * Creates a new #GtkImageMenuItem with an empty label.
198 	 *
199 	 * Deprecated: Use gtk_menu_item_new() instead.
200 	 *
201 	 * Return: a new #GtkImageMenuItem
202 	 *
203 	 * Throws: ConstructionException GTK+ fails to create the object.
204 	 */
205 	public this()
206 	{
207 		auto p = gtk_image_menu_item_new();
208 		
209 		if(p is null)
210 		{
211 			throw new ConstructionException("null returned by new");
212 		}
213 		
214 		this(cast(GtkImageMenuItem*) p);
215 	}
216 
217 	/**
218 	 * Returns whether the menu item will ignore the #GtkSettings:gtk-menu-images
219 	 * setting and always show the image, if available.
220 	 *
221 	 * Return: %TRUE if the menu item will always show the image
222 	 *
223 	 * Since: 2.16
224 	 */
225 	public bool getAlwaysShowImage()
226 	{
227 		return gtk_image_menu_item_get_always_show_image(gtkImageMenuItem) != 0;
228 	}
229 
230 	/**
231 	 * Gets the widget that is currently set as the image of @image_menu_item.
232 	 * See gtk_image_menu_item_set_image().
233 	 *
234 	 * Return: the widget set as image of @image_menu_item
235 	 */
236 	public Widget getImage()
237 	{
238 		auto p = gtk_image_menu_item_get_image(gtkImageMenuItem);
239 		
240 		if(p is null)
241 		{
242 			return null;
243 		}
244 		
245 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
246 	}
247 
248 	/**
249 	 * Checks whether the label set in the menuitem is used as a
250 	 * stock id to select the stock item for the item.
251 	 *
252 	 * Return: %TRUE if the label set in the menuitem is used as a
253 	 *     stock id to select the stock item for the item
254 	 *
255 	 * Since: 2.16
256 	 */
257 	public bool getUseStock()
258 	{
259 		return gtk_image_menu_item_get_use_stock(gtkImageMenuItem) != 0;
260 	}
261 
262 	/**
263 	 * Specifies an @accel_group to add the menu items accelerator to
264 	 * (this only applies to stock items so a stock item must already
265 	 * be set, make sure to call gtk_image_menu_item_set_use_stock()
266 	 * and gtk_menu_item_set_label() with a valid stock item first).
267 	 *
268 	 * If you want this menu item to have changeable accelerators then
269 	 * you shouldnt need this (see gtk_image_menu_item_new_from_stock()).
270 	 *
271 	 * Params:
272 	 *     accelGroup = the #GtkAccelGroup
273 	 *
274 	 * Since: 2.16
275 	 */
276 	public void setAccelGroup(AccelGroup accelGroup)
277 	{
278 		gtk_image_menu_item_set_accel_group(gtkImageMenuItem, (accelGroup is null) ? null : accelGroup.getAccelGroupStruct());
279 	}
280 
281 	/**
282 	 * If %TRUE, the menu item will ignore the #GtkSettings:gtk-menu-images
283 	 * setting and always show the image, if available.
284 	 *
285 	 * Use this property if the menuitem would be useless or hard to use
286 	 * without the image.
287 	 *
288 	 * Params:
289 	 *     alwaysShow = %TRUE if the menuitem should always show the image
290 	 *
291 	 * Since: 2.16
292 	 */
293 	public void setAlwaysShowImage(bool alwaysShow)
294 	{
295 		gtk_image_menu_item_set_always_show_image(gtkImageMenuItem, alwaysShow);
296 	}
297 
298 	/**
299 	 * Sets the image of @image_menu_item to the given widget.
300 	 * Note that it depends on the show-menu-images setting whether
301 	 * the image will be displayed or not.
302 	 *
303 	 * Params:
304 	 *     image = a widget to set as the image for the menu item.
305 	 */
306 	public void setImage(Widget image)
307 	{
308 		gtk_image_menu_item_set_image(gtkImageMenuItem, (image is null) ? null : image.getWidgetStruct());
309 	}
310 
311 	/**
312 	 * If %TRUE, the label set in the menuitem is used as a
313 	 * stock id to select the stock item for the item.
314 	 *
315 	 * Params:
316 	 *     useStock = %TRUE if the menuitem should use a stock item
317 	 *
318 	 * Since: 2.16
319 	 */
320 	public void setUseStock(bool useStock)
321 	{
322 		gtk_image_menu_item_set_use_stock(gtkImageMenuItem, useStock);
323 	}
324 }