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.MenuButton;
26 
27 private import gio.MenuModel;
28 private import glib.ConstructionException;
29 private import gobject.ObjectG;
30 private import gtk.Menu;
31 private import gtk.Popover;
32 private import gtk.ToggleButton;
33 private import gtk.Widget;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * The #GtkMenuButton widget is used to display a popup when clicked on.
40  * This popup can be provided either as a #GtkMenu, a #GtkPopover or an
41  * abstract #GMenuModel.
42  * 
43  * The #GtkMenuButton widget can hold any valid child widget. That is, it
44  * can hold almost any other standard #GtkWidget. The most commonly used
45  * child is #GtkImage. If no widget is explicitely added to the #GtkMenuButton,
46  * a #GtkImage is automatically created, using an arrow image oriented
47  * according to #GtkMenuButton:direction or the generic "view-context-menu"
48  * icon if the direction is not set.
49  * 
50  * The positioning of the popup is determined by the #GtkMenuButton:direction
51  * property of the menu button.
52  * 
53  * For menus, the #GtkWidget:halign and #GtkWidget:valign properties of the
54  * menu are also taken into account. For example, when the direction is
55  * %GTK_ARROW_DOWN and the horizontal alignment is %GTK_ALIGN_START, the
56  * menu will be positioned below the button, with the starting edge
57  * (depending on the text direction) of the menu aligned with the starting
58  * edge of the button. If there is not enough space below the button, the
59  * menu is popped up above the button instead. If the alignment would move
60  * part of the menu offscreen, it is “pushed in”.
61  * 
62  * ## Direction = Down
63  * 
64  * - halign = start
65  * 
66  * ![](down-start.png)
67  * 
68  * - halign = center
69  * 
70  * ![](down-center.png)
71  * 
72  * - halign = end
73  * 
74  * ![](down-end.png)
75  * 
76  * ## Direction = Up
77  * 
78  * - halign = start
79  * 
80  * ![](up-start.png)
81  * 
82  * - halign = center
83  * 
84  * ![](up-center.png)
85  * 
86  * - halign = end
87  * 
88  * ![](up-end.png)
89  * 
90  * ## Direction = Left
91  * 
92  * - valign = start
93  * 
94  * ![](left-start.png)
95  * 
96  * - valign = center
97  * 
98  * ![](left-center.png)
99  * 
100  * - valign = end
101  * 
102  * ![](left-end.png)
103  * 
104  * ## Direction = Right
105  * 
106  * - valign = start
107  * 
108  * ![](right-start.png)
109  * 
110  * - valign = center
111  * 
112  * ![](right-center.png)
113  * 
114  * - valign = end
115  * 
116  * ![](right-end.png)
117  */
118 public class MenuButton : ToggleButton
119 {
120 	/** the main Gtk struct */
121 	protected GtkMenuButton* gtkMenuButton;
122 
123 	/** Get the main Gtk struct */
124 	public GtkMenuButton* getMenuButtonStruct()
125 	{
126 		return gtkMenuButton;
127 	}
128 
129 	/** the main Gtk struct as a void* */
130 	protected override void* getStruct()
131 	{
132 		return cast(void*)gtkMenuButton;
133 	}
134 
135 	protected override void setStruct(GObject* obj)
136 	{
137 		gtkMenuButton = cast(GtkMenuButton*)obj;
138 		super.setStruct(obj);
139 	}
140 
141 	/**
142 	 * Sets our main struct and passes it to the parent class.
143 	 */
144 	public this (GtkMenuButton* gtkMenuButton, bool ownedRef = false)
145 	{
146 		this.gtkMenuButton = gtkMenuButton;
147 		super(cast(GtkToggleButton*)gtkMenuButton, ownedRef);
148 	}
149 
150 	/**
151 	 */
152 
153 	public static GType getType()
154 	{
155 		return gtk_menu_button_get_type();
156 	}
157 
158 	/**
159 	 * Creates a new #GtkMenuButton widget with downwards-pointing
160 	 * arrow as the only child. You can replace the child widget
161 	 * with another #GtkWidget should you wish to.
162 	 *
163 	 * Return: The newly created #GtkMenuButton widget
164 	 *
165 	 * Since: 3.6
166 	 *
167 	 * Throws: ConstructionException GTK+ fails to create the object.
168 	 */
169 	public this()
170 	{
171 		auto p = gtk_menu_button_new();
172 		
173 		if(p is null)
174 		{
175 			throw new ConstructionException("null returned by new");
176 		}
177 		
178 		this(cast(GtkMenuButton*) p);
179 	}
180 
181 	/**
182 	 * Returns the parent #GtkWidget to use to line up with menu.
183 	 *
184 	 * Return: a #GtkWidget value or %NULL
185 	 *
186 	 * Since: 3.6
187 	 */
188 	public Widget getAlignWidget()
189 	{
190 		auto p = gtk_menu_button_get_align_widget(gtkMenuButton);
191 		
192 		if(p is null)
193 		{
194 			return null;
195 		}
196 		
197 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
198 	}
199 
200 	/**
201 	 * Returns the direction the popup will be pointing at when popped up.
202 	 *
203 	 * Return: a #GtkArrowType value
204 	 *
205 	 * Since: 3.6
206 	 */
207 	public GtkArrowType getMenuDirection()
208 	{
209 		return gtk_menu_button_get_direction(gtkMenuButton);
210 	}
211 
212 	/**
213 	 * Returns the #GMenuModel used to generate the popup.
214 	 *
215 	 * Return: a #GMenuModel or %NULL
216 	 *
217 	 * Since: 3.6
218 	 */
219 	public MenuModel getMenuModel()
220 	{
221 		auto p = gtk_menu_button_get_menu_model(gtkMenuButton);
222 		
223 		if(p is null)
224 		{
225 			return null;
226 		}
227 		
228 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
229 	}
230 
231 	/**
232 	 * Returns the #GtkPopover that pops out of the button.
233 	 * If the button is not using a #GtkPopover, this function
234 	 * returns %NULL.
235 	 *
236 	 * Return: a #GtkPopover or %NULL
237 	 *
238 	 * Since: 3.12
239 	 */
240 	public Popover getPopover()
241 	{
242 		auto p = gtk_menu_button_get_popover(gtkMenuButton);
243 		
244 		if(p is null)
245 		{
246 			return null;
247 		}
248 		
249 		return ObjectG.getDObject!(Popover)(cast(GtkPopover*) p);
250 	}
251 
252 	/**
253 	 * Returns the #GtkMenu that pops out of the button.
254 	 * If the button does not use a #GtkMenu, this function
255 	 * returns %NULL.
256 	 *
257 	 * Return: a #GtkMenu or %NULL
258 	 *
259 	 * Since: 3.6
260 	 */
261 	public Menu getPopup()
262 	{
263 		auto p = gtk_menu_button_get_popup(gtkMenuButton);
264 		
265 		if(p is null)
266 		{
267 			return null;
268 		}
269 		
270 		return ObjectG.getDObject!(Menu)(cast(GtkMenu*) p);
271 	}
272 
273 	/**
274 	 * Returns whether a #GtkPopover or a #GtkMenu will be constructed
275 	 * from the menu model.
276 	 *
277 	 * Return: %TRUE if using a #GtkPopover
278 	 *
279 	 * Since: 3.12
280 	 */
281 	public bool getUsePopover()
282 	{
283 		return gtk_menu_button_get_use_popover(gtkMenuButton) != 0;
284 	}
285 
286 	/**
287 	 * Sets the #GtkWidget to use to line the menu with when popped up.
288 	 * Note that the @align_widget must contain the #GtkMenuButton itself.
289 	 *
290 	 * Setting it to %NULL means that the menu will be aligned with the
291 	 * button itself.
292 	 *
293 	 * Note that this property is only used with menus currently,
294 	 * and not for popovers.
295 	 *
296 	 * Params:
297 	 *     alignWidget = a #GtkWidget
298 	 *
299 	 * Since: 3.6
300 	 */
301 	public void setAlignWidget(Widget alignWidget)
302 	{
303 		gtk_menu_button_set_align_widget(gtkMenuButton, (alignWidget is null) ? null : alignWidget.getWidgetStruct());
304 	}
305 
306 	/**
307 	 * Sets the direction in which the popup will be popped up, as
308 	 * well as changing the arrow’s direction. The child will not
309 	 * be changed to an arrow if it was customized.
310 	 *
311 	 * If the does not fit in the available space in the given direction,
312 	 * GTK+ will its best to keep it inside the screen and fully visible.
313 	 *
314 	 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
315 	 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).
316 	 *
317 	 * Params:
318 	 *     direction = a #GtkArrowType
319 	 *
320 	 * Since: 3.6
321 	 */
322 	public void setMenuDirection(GtkArrowType direction)
323 	{
324 		gtk_menu_button_set_direction(gtkMenuButton, direction);
325 	}
326 
327 	/**
328 	 * Sets the #GMenuModel from which the popup will be constructed,
329 	 * or %NULL to disable the button.
330 	 *
331 	 * Depending on the value of #GtkMenuButton:use-popover, either a
332 	 * #GtkMenu will be created with gtk_menu_new_from_model(), or a
333 	 * #GtkPopover with gtk_popover_new_from_model(). In either case,
334 	 * actions will be connected as documented for these functions.
335 	 *
336 	 * If #GtkMenuButton:popup or #GtkMenuButton:popover are already set,
337 	 * their content will be lost and replaced by the newly created popup.
338 	 *
339 	 * Params:
340 	 *     menuModel = a #GMenuModel
341 	 *
342 	 * Since: 3.6
343 	 */
344 	public void setMenuModel(MenuModel menuModel)
345 	{
346 		gtk_menu_button_set_menu_model(gtkMenuButton, (menuModel is null) ? null : menuModel.getMenuModelStruct());
347 	}
348 
349 	/**
350 	 * Sets the #GtkPopover that will be popped up when the button is
351 	 * clicked, or %NULL to disable the button. If #GtkMenuButton:menu-model
352 	 * or #GtkMenuButton:popup are set, they will be set to %NULL.
353 	 *
354 	 * Params:
355 	 *     popover = a #GtkPopover
356 	 *
357 	 * Since: 3.12
358 	 */
359 	public void setPopover(Widget popover)
360 	{
361 		gtk_menu_button_set_popover(gtkMenuButton, (popover is null) ? null : popover.getWidgetStruct());
362 	}
363 
364 	/**
365 	 * Sets the #GtkMenu that will be popped up when the button is clicked,
366 	 * or %NULL to disable the button. If #GtkMenuButton:menu-model or
367 	 * #GtkMenuButton:popover are set, they will be set to %NULL.
368 	 *
369 	 * Params:
370 	 *     menu = a #GtkMenu
371 	 *
372 	 * Since: 3.6
373 	 */
374 	public void setPopup(Widget menu)
375 	{
376 		gtk_menu_button_set_popup(gtkMenuButton, (menu is null) ? null : menu.getWidgetStruct());
377 	}
378 
379 	/**
380 	 * Sets whether to construct a #GtkPopover instead of #GtkMenu
381 	 * when gtk_menu_button_set_menu_model() is called. Note that
382 	 * this property is only consulted when a new menu model is set.
383 	 *
384 	 * Params:
385 	 *     usePopover = %TRUE to construct a popover from the menu model
386 	 *
387 	 * Since: 3.12
388 	 */
389 	public void setUsePopover(bool usePopover)
390 	{
391 		gtk_menu_button_set_use_popover(gtkMenuButton, usePopover);
392 	}
393 }