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 	protected override void setStruct(GObject* obj)
144 	{
145 		gtkMenuButton = cast(GtkMenuButton*)obj;
146 		super.setStruct(obj);
147 	}
148 
149 	/**
150 	 * Sets our main struct and passes it to the parent class.
151 	 */
152 	public this (GtkMenuButton* gtkMenuButton, bool ownedRef = false)
153 	{
154 		this.gtkMenuButton = gtkMenuButton;
155 		super(cast(GtkToggleButton*)gtkMenuButton, ownedRef);
156 	}
157 
158 
159 	/** */
160 	public static GType getType()
161 	{
162 		return gtk_menu_button_get_type();
163 	}
164 
165 	/**
166 	 * Creates a new #GtkMenuButton widget with downwards-pointing
167 	 * arrow as the only child. You can replace the child widget
168 	 * with another #GtkWidget should you wish to.
169 	 *
170 	 * Returns: The newly created #GtkMenuButton widget
171 	 *
172 	 * Since: 3.6
173 	 *
174 	 * Throws: ConstructionException GTK+ fails to create the object.
175 	 */
176 	public this()
177 	{
178 		auto p = gtk_menu_button_new();
179 
180 		if(p is null)
181 		{
182 			throw new ConstructionException("null returned by new");
183 		}
184 
185 		this(cast(GtkMenuButton*) p);
186 	}
187 
188 	/**
189 	 * Returns the parent #GtkWidget to use to line up with menu.
190 	 *
191 	 * Returns: a #GtkWidget value or %NULL
192 	 *
193 	 * Since: 3.6
194 	 */
195 	public Widget getAlignWidget()
196 	{
197 		auto p = gtk_menu_button_get_align_widget(gtkMenuButton);
198 
199 		if(p is null)
200 		{
201 			return null;
202 		}
203 
204 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
205 	}
206 
207 	/**
208 	 * Returns the direction the popup will be pointing at when popped up.
209 	 *
210 	 * Returns: a #GtkArrowType value
211 	 *
212 	 * Since: 3.6
213 	 */
214 	public GtkArrowType getMenuDirection()
215 	{
216 		return gtk_menu_button_get_direction(gtkMenuButton);
217 	}
218 
219 	/**
220 	 * Returns the #GMenuModel used to generate the popup.
221 	 *
222 	 * Returns: a #GMenuModel or %NULL
223 	 *
224 	 * Since: 3.6
225 	 */
226 	public MenuModel getMenuModel()
227 	{
228 		auto p = gtk_menu_button_get_menu_model(gtkMenuButton);
229 
230 		if(p is null)
231 		{
232 			return null;
233 		}
234 
235 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) p);
236 	}
237 
238 	/**
239 	 * Returns the #GtkPopover that pops out of the button.
240 	 * If the button is not using a #GtkPopover, this function
241 	 * returns %NULL.
242 	 *
243 	 * Returns: a #GtkPopover or %NULL
244 	 *
245 	 * Since: 3.12
246 	 */
247 	public Popover getPopover()
248 	{
249 		auto p = gtk_menu_button_get_popover(gtkMenuButton);
250 
251 		if(p is null)
252 		{
253 			return null;
254 		}
255 
256 		return ObjectG.getDObject!(Popover)(cast(GtkPopover*) p);
257 	}
258 
259 	/**
260 	 * Returns the #GtkMenu that pops out of the button.
261 	 * If the button does not use a #GtkMenu, this function
262 	 * returns %NULL.
263 	 *
264 	 * Returns: a #GtkMenu or %NULL
265 	 *
266 	 * Since: 3.6
267 	 */
268 	public Menu getPopup()
269 	{
270 		auto p = gtk_menu_button_get_popup(gtkMenuButton);
271 
272 		if(p is null)
273 		{
274 			return null;
275 		}
276 
277 		return ObjectG.getDObject!(Menu)(cast(GtkMenu*) p);
278 	}
279 
280 	/**
281 	 * Returns whether a #GtkPopover or a #GtkMenu will be constructed
282 	 * from the menu model.
283 	 *
284 	 * Returns: %TRUE if using a #GtkPopover
285 	 *
286 	 * Since: 3.12
287 	 */
288 	public bool getUsePopover()
289 	{
290 		return gtk_menu_button_get_use_popover(gtkMenuButton) != 0;
291 	}
292 
293 	/**
294 	 * Sets the #GtkWidget to use to line the menu with when popped up.
295 	 * Note that the @align_widget must contain the #GtkMenuButton itself.
296 	 *
297 	 * Setting it to %NULL means that the menu will be aligned with the
298 	 * button itself.
299 	 *
300 	 * Note that this property is only used with menus currently,
301 	 * and not for popovers.
302 	 *
303 	 * Params:
304 	 *     alignWidget = a #GtkWidget
305 	 *
306 	 * Since: 3.6
307 	 */
308 	public void setAlignWidget(Widget alignWidget)
309 	{
310 		gtk_menu_button_set_align_widget(gtkMenuButton, (alignWidget is null) ? null : alignWidget.getWidgetStruct());
311 	}
312 
313 	/**
314 	 * Sets the direction in which the popup will be popped up, as
315 	 * well as changing the arrow’s direction. The child will not
316 	 * be changed to an arrow if it was customized.
317 	 *
318 	 * If the does not fit in the available space in the given direction,
319 	 * GTK+ will its best to keep it inside the screen and fully visible.
320 	 *
321 	 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
322 	 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).
323 	 *
324 	 * Params:
325 	 *     direction = a #GtkArrowType
326 	 *
327 	 * Since: 3.6
328 	 */
329 	public void setMenuDirection(GtkArrowType direction)
330 	{
331 		gtk_menu_button_set_direction(gtkMenuButton, direction);
332 	}
333 
334 	/**
335 	 * Sets the #GMenuModel from which the popup will be constructed,
336 	 * or %NULL to disable the button.
337 	 *
338 	 * Depending on the value of #GtkMenuButton:use-popover, either a
339 	 * #GtkMenu will be created with gtk_menu_new_from_model(), or a
340 	 * #GtkPopover with gtk_popover_new_from_model(). In either case,
341 	 * actions will be connected as documented for these functions.
342 	 *
343 	 * If #GtkMenuButton:popup or #GtkMenuButton:popover are already set,
344 	 * their content will be lost and replaced by the newly created popup.
345 	 *
346 	 * Params:
347 	 *     menuModel = a #GMenuModel
348 	 *
349 	 * Since: 3.6
350 	 */
351 	public void setMenuModel(MenuModel menuModel)
352 	{
353 		gtk_menu_button_set_menu_model(gtkMenuButton, (menuModel is null) ? null : menuModel.getMenuModelStruct());
354 	}
355 
356 	/**
357 	 * Sets the #GtkPopover that will be popped up when the button is
358 	 * clicked, or %NULL to disable the button. If #GtkMenuButton:menu-model
359 	 * or #GtkMenuButton:popup are set, they will be set to %NULL.
360 	 *
361 	 * Params:
362 	 *     popover = a #GtkPopover
363 	 *
364 	 * Since: 3.12
365 	 */
366 	public void setPopover(Widget popover)
367 	{
368 		gtk_menu_button_set_popover(gtkMenuButton, (popover is null) ? null : popover.getWidgetStruct());
369 	}
370 
371 	/**
372 	 * Sets the #GtkMenu that will be popped up when the button is clicked,
373 	 * or %NULL to disable the button. If #GtkMenuButton:menu-model or
374 	 * #GtkMenuButton:popover are set, they will be set to %NULL.
375 	 *
376 	 * Params:
377 	 *     menu = a #GtkMenu
378 	 *
379 	 * Since: 3.6
380 	 */
381 	public void setPopup(Widget menu)
382 	{
383 		gtk_menu_button_set_popup(gtkMenuButton, (menu is null) ? null : menu.getWidgetStruct());
384 	}
385 
386 	/**
387 	 * Sets whether to construct a #GtkPopover instead of #GtkMenu
388 	 * when gtk_menu_button_set_menu_model() is called. Note that
389 	 * this property is only consulted when a new menu model is set.
390 	 *
391 	 * Params:
392 	 *     usePopover = %TRUE to construct a popover from the menu model
393 	 *
394 	 * Since: 3.12
395 	 */
396 	public void setUsePopover(bool usePopover)
397 	{
398 		gtk_menu_button_set_use_popover(gtkMenuButton, usePopover);
399 	}
400 }