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