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