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 glib.Str;
30 private import glib.c.functions;
31 private import gobject.ObjectG;
32 private import gtk.Popover;
33 private import gtk.Widget;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 
37 
38 /**
39  * The `GtkMenuButton` widget is used to display a popup when clicked.
40  * 
41  * ![An example GtkMenuButton](menu-button.png)
42  * 
43  * This popup can be provided either as a `GtkPopover` or as an abstract
44  * `GMenuModel`.
45  * 
46  * The `GtkMenuButton` widget can show either an icon (set with the
47  * [property@Gtk.MenuButton:icon-name] property) or a label (set with the
48  * [property@Gtk.MenuButton:label] property). If neither is explicitly set,
49  * a [class@Gtk.Image] is automatically created, using an arrow image oriented
50  * according to [property@Gtk.MenuButton:direction] or the generic
51  * “open-menu-symbolic” icon if the direction is not set.
52  * 
53  * The positioning of the popup is determined by the
54  * [property@Gtk.MenuButton:direction] property of the menu button.
55  * 
56  * For menus, the [property@Gtk.Widget:halign] and [property@Gtk.Widget:valign]
57  * properties of the menu are also taken into account. For example, when the
58  * direction is %GTK_ARROW_DOWN and the horizontal alignment is %GTK_ALIGN_START,
59  * the menu will be positioned below the button, with the starting edge
60  * (depending on the text direction) of the menu aligned with the starting
61  * edge of the button. If there is not enough space below the button, the
62  * menu is popped up above the button instead. If the alignment would move
63  * part of the menu offscreen, it is “pushed in”.
64  * 
65  * |           | start                | center                | end                |
66  * | -         | ---                  | ---                   | ---                |
67  * | **down**  | ![](down-start.png)  | ![](down-center.png)  | ![](down-end.png)  |
68  * | **up**    | ![](up-start.png)    | ![](up-center.png)    | ![](up-end.png)    |
69  * | **left**  | ![](left-start.png)  | ![](left-center.png)  | ![](left-end.png)  |
70  * | **right** | ![](right-start.png) | ![](right-center.png) | ![](right-end.png) |
71  * 
72  * # CSS nodes
73  * 
74  * ```
75  * menubutton
76  * ╰── button.toggle
77  * ╰── <content>
78  * ╰── [arrow]
79  * ```
80  * 
81  * `GtkMenuButton` has a single CSS node with name `menubutton`
82  * which contains a `button` node with a `.toggle` style class.
83  * 
84  * Inside the toggle button content, there is an `arrow` node for
85  * the indicator, which will carry one of the `.none`, `.up`, `.down`,
86  * `.left` or `.right` style classes to indicate the direction that
87  * the menu will appear in. The CSS is expected to provide a suitable
88  * image for each of these cases using the `-gtk-icon-source` property.
89  * 
90  * Optionally, the `menubutton` node can carry the `.circular` style class
91  * to request a round appearance.
92  * 
93  * # Accessibility
94  * 
95  * `GtkMenuButton` uses the #GTK_ACCESSIBLE_ROLE_BUTTON role.
96  */
97 public class MenuButton : Widget
98 {
99 	/** the main Gtk struct */
100 	protected GtkMenuButton* gtkMenuButton;
101 
102 	/** Get the main Gtk struct */
103 	public GtkMenuButton* getMenuButtonStruct(bool transferOwnership = false)
104 	{
105 		if (transferOwnership)
106 			ownedRef = false;
107 		return gtkMenuButton;
108 	}
109 
110 	/** the main Gtk struct as a void* */
111 	protected override void* getStruct()
112 	{
113 		return cast(void*)gtkMenuButton;
114 	}
115 
116 	/**
117 	 * Sets our main struct and passes it to the parent class.
118 	 */
119 	public this (GtkMenuButton* gtkMenuButton, bool ownedRef = false)
120 	{
121 		this.gtkMenuButton = gtkMenuButton;
122 		super(cast(GtkWidget*)gtkMenuButton, ownedRef);
123 	}
124 
125 
126 	/** */
127 	public static GType getType()
128 	{
129 		return gtk_menu_button_get_type();
130 	}
131 
132 	/**
133 	 * Creates a new `GtkMenuButton` widget with downwards-pointing
134 	 * arrow as the only child.
135 	 *
136 	 * You can replace the child widget with another `GtkWidget`
137 	 * should you wish to.
138 	 *
139 	 * Returns: The newly created `GtkMenuButton`
140 	 *
141 	 * Throws: ConstructionException GTK+ fails to create the object.
142 	 */
143 	public this()
144 	{
145 		auto __p = gtk_menu_button_new();
146 
147 		if(__p is null)
148 		{
149 			throw new ConstructionException("null returned by new");
150 		}
151 
152 		this(cast(GtkMenuButton*) __p);
153 	}
154 
155 	/**
156 	 * Returns the direction the popup will be pointing at when popped up.
157 	 *
158 	 * Returns: a `GtkArrowType` value
159 	 */
160 	public GtkArrowType getMenuDirection()
161 	{
162 		return gtk_menu_button_get_direction(gtkMenuButton);
163 	}
164 
165 	/**
166 	 * Returns whether the button has a frame.
167 	 *
168 	 * Returns: %TRUE if the button has a frame
169 	 */
170 	public bool getHasFrame()
171 	{
172 		return gtk_menu_button_get_has_frame(gtkMenuButton) != 0;
173 	}
174 
175 	/**
176 	 * Gets the name of the icon shown in the button.
177 	 *
178 	 * Returns: the name of the icon shown in the button
179 	 */
180 	public string getIconName()
181 	{
182 		return Str.toString(gtk_menu_button_get_icon_name(gtkMenuButton));
183 	}
184 
185 	/**
186 	 * Gets the label shown in the button
187 	 *
188 	 * Returns: the label shown in the button
189 	 */
190 	public string getLabel()
191 	{
192 		return Str.toString(gtk_menu_button_get_label(gtkMenuButton));
193 	}
194 
195 	/**
196 	 * Returns the `GMenuModel` used to generate the popup.
197 	 *
198 	 * Returns: a `GMenuModel` or %NULL
199 	 */
200 	public MenuModel getMenuModel()
201 	{
202 		auto __p = gtk_menu_button_get_menu_model(gtkMenuButton);
203 
204 		if(__p is null)
205 		{
206 			return null;
207 		}
208 
209 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) __p);
210 	}
211 
212 	/**
213 	 * Returns the `GtkPopover` that pops out of the button.
214 	 *
215 	 * If the button is not using a `GtkPopover`, this function
216 	 * returns %NULL.
217 	 *
218 	 * Returns: a `GtkPopover` or %NULL
219 	 */
220 	public Popover getPopover()
221 	{
222 		auto __p = gtk_menu_button_get_popover(gtkMenuButton);
223 
224 		if(__p is null)
225 		{
226 			return null;
227 		}
228 
229 		return ObjectG.getDObject!(Popover)(cast(GtkPopover*) __p);
230 	}
231 
232 	/**
233 	 * Returns whether an embedded underline in the text indicates a
234 	 * mnemonic.
235 	 *
236 	 * Returns: %TRUE whether an embedded underline in the text indicates
237 	 *     the mnemonic accelerator keys.
238 	 */
239 	public bool getUseUnderline()
240 	{
241 		return gtk_menu_button_get_use_underline(gtkMenuButton) != 0;
242 	}
243 
244 	/**
245 	 * Dismiss the menu.
246 	 */
247 	public void popdown()
248 	{
249 		gtk_menu_button_popdown(gtkMenuButton);
250 	}
251 
252 	/**
253 	 * Pop up the menu.
254 	 */
255 	public void popup()
256 	{
257 		gtk_menu_button_popup(gtkMenuButton);
258 	}
259 
260 	/**
261 	 * Sets @func to be called when a popup is about to be shown.
262 	 *
263 	 * @func should use one of
264 	 *
265 	 * - [method@Gtk.MenuButton.set_popover]
266 	 * - [method@Gtk.MenuButton.set_menu_model]
267 	 *
268 	 * to set a popup for @menu_button.
269 	 * If @func is non-%NULL, @menu_button will always be sensitive.
270 	 *
271 	 * Using this function will not reset the menu widget attached to
272 	 * @menu_button. Instead, this can be done manually in @func.
273 	 *
274 	 * Params:
275 	 *     func = function to call when a popup is about to
276 	 *         be shown, but none has been provided via other means, or %NULL
277 	 *         to reset to default behavior.
278 	 *     userData = user data to pass to @func.
279 	 *     destroyNotify = destroy notify for @user_data
280 	 */
281 	public void setCreatePopupFunc(GtkMenuButtonCreatePopupFunc func, void* userData, GDestroyNotify destroyNotify)
282 	{
283 		gtk_menu_button_set_create_popup_func(gtkMenuButton, func, userData, destroyNotify);
284 	}
285 
286 	/**
287 	 * Sets the direction in which the popup will be popped up.
288 	 *
289 	 * If the button is automatically populated with an arrow icon,
290 	 * its direction will be changed to match.
291 	 *
292 	 * If the does not fit in the available space in the given direction,
293 	 * GTK will its best to keep it inside the screen and fully visible.
294 	 *
295 	 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
296 	 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).
297 	 *
298 	 * Params:
299 	 *     direction = a `GtkArrowType`
300 	 */
301 	public void setMenuDirection(GtkArrowType direction)
302 	{
303 		gtk_menu_button_set_direction(gtkMenuButton, direction);
304 	}
305 
306 	/**
307 	 * Sets the style of the button.
308 	 *
309 	 * Params:
310 	 *     hasFrame = whether the button should have a visible frame
311 	 */
312 	public void setHasFrame(bool hasFrame)
313 	{
314 		gtk_menu_button_set_has_frame(gtkMenuButton, hasFrame);
315 	}
316 
317 	/**
318 	 * Sets the name of an icon to show inside the menu button.
319 	 *
320 	 * Params:
321 	 *     iconName = the icon name
322 	 */
323 	public void setIconName(string iconName)
324 	{
325 		gtk_menu_button_set_icon_name(gtkMenuButton, Str.toStringz(iconName));
326 	}
327 
328 	/**
329 	 * Sets the label to show inside the menu button.
330 	 *
331 	 * Params:
332 	 *     label = the label
333 	 */
334 	public void setLabel(string label)
335 	{
336 		gtk_menu_button_set_label(gtkMenuButton, Str.toStringz(label));
337 	}
338 
339 	/**
340 	 * Sets the `GMenuModel` from which the popup will be constructed.
341 	 *
342 	 * If @menu_model is %NULL, the button is disabled.
343 	 *
344 	 * A [class@Gtk.Popover] will be created from the menu model with
345 	 * [ctor@Gtk.PopoverMenu.new_from_model]. Actions will be connected
346 	 * as documented for this function.
347 	 *
348 	 * If [property@Gtk.MenuButton:popover] is already set, it will be
349 	 * dissociated from the @menu_button, and the property is set to %NULL.
350 	 *
351 	 * Params:
352 	 *     menuModel = a `GMenuModel`, or %NULL to unset and disable the
353 	 *         button
354 	 */
355 	public void setMenuModel(MenuModel menuModel)
356 	{
357 		gtk_menu_button_set_menu_model(gtkMenuButton, (menuModel is null) ? null : menuModel.getMenuModelStruct());
358 	}
359 
360 	/**
361 	 * Sets the `GtkPopover` that will be popped up when the @menu_button is clicked.
362 	 *
363 	 * If @popover is %NULL, the button is disabled.
364 	 *
365 	 * If [property@Gtk.MenuButton:menu-model] is set, the menu model is dissociated
366 	 * from the @menu_button, and the property is set to %NULL.
367 	 *
368 	 * Params:
369 	 *     popover = a `GtkPopover`, or %NULL to unset and disable the button
370 	 */
371 	public void setPopover(Widget popover)
372 	{
373 		gtk_menu_button_set_popover(gtkMenuButton, (popover is null) ? null : popover.getWidgetStruct());
374 	}
375 
376 	/**
377 	 * If true, an underline in the text indicates a mnemonic.
378 	 *
379 	 * Params:
380 	 *     useUnderline = %TRUE if underlines in the text indicate mnemonics
381 	 */
382 	public void setUseUnderline(bool useUnderline)
383 	{
384 		gtk_menu_button_set_use_underline(gtkMenuButton, useUnderline);
385 	}
386 }