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.PopoverMenu;
26 
27 private import gio.MenuModel;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gtk.Popover;
32 private import gtk.Widget;
33 private import gtk.c.functions;
34 public  import gtk.c.types;
35 
36 
37 /**
38  * `GtkPopoverMenu` is a subclass of `GtkPopover` that implements menu
39  * behavior.
40  * 
41  * ![An example GtkPopoverMenu](menu.png)
42  * 
43  * `GtkPopoverMenu` treats its children like menus and allows switching
44  * between them. It can open submenus as traditional, nested submenus,
45  * or in a more touch-friendly sliding fashion.
46  * 
47  * `GtkPopoverMenu` is meant to be used primarily with menu models,
48  * using [ctor@Gtk.PopoverMenu.new_from_model]. If you need to put
49  * other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover,
50  * you can use [method@Gtk.PopoverMenu.add_child].
51  * 
52  * For more dialog-like behavior, use a plain `GtkPopover`.
53  * 
54  * ## Menu models
55  * 
56  * The XML format understood by `GtkBuilder` for `GMenuModel` consists
57  * of a toplevel `<menu>` element, which contains one or more `<item>`
58  * elements. Each `<item>` element contains `<attribute>` and `<link>`
59  * elements with a mandatory name attribute. `<link>` elements have the
60  * same content model as `<menu>`. Instead of `<link name="submenu>` or
61  * `<link name="section">`, you can use `<submenu>` or `<section>`
62  * elements.
63  * 
64  * ```xml
65  * <menu id='app-menu'>
66  * <section>
67  * <item>
68  * <attribute name='label' translatable='yes'>_New Window</attribute>
69  * <attribute name='action'>app.new</attribute>
70  * </item>
71  * <item>
72  * <attribute name='label' translatable='yes'>_About Sunny</attribute>
73  * <attribute name='action'>app.about</attribute>
74  * </item>
75  * <item>
76  * <attribute name='label' translatable='yes'>_Quit</attribute>
77  * <attribute name='action'>app.quit</attribute>
78  * </item>
79  * </section>
80  * </menu>
81  * ```
82  * 
83  * Attribute values can be translated using gettext, like other `GtkBuilder`
84  * content. `<attribute>` elements can be marked for translation with a
85  * `translatable="yes"` attribute. It is also possible to specify message
86  * context and translator comments, using the context and comments attributes.
87  * To make use of this, the #GtkBuilder must have been given the gettext
88  * domain to use.
89  * 
90  * The following attributes are used when constructing menu items:
91  * 
92  * - "label": a user-visible string to display
93  * - "action": the prefixed name of the action to trigger
94  * - "target": the parameter to use when activating the action
95  * - "icon" and "verb-icon": names of icons that may be displayed
96  * - "submenu-action": name of an action that may be used to determine
97  * if a submenu can be opened
98  * - "hidden-when": a string used to determine when the item will be hidden.
99  * Possible values include "action-disabled", "action-missing", "macos-menubar".
100  * This is mainly useful for exported menus, see [method@Gtk.Application.set_menubar].
101  * - "custom": a string used to match against the ID of a custom child added with
102  * [method@Gtk.PopoverMenu.add_child], [method@Gtk.PopoverMenuBar.add_child],
103  * or in the ui file with `<child type="ID">`.
104  * 
105  * The following attributes are used when constructing sections:
106  * 
107  * - "label": a user-visible string to use as section heading
108  * - "display-hint": a string used to determine special formatting for the section.
109  * Possible values include "horizontal-buttons", "circular-buttons" and
110  * "inline-buttons". They all indicate that section should be
111  * displayed as a horizontal row of buttons.
112  * - "text-direction": a string used to determine the `GtkTextDirection` to use
113  * when "display-hint" is set to "horizontal-buttons". Possible values
114  * include "rtl", "ltr", and "none".
115  * 
116  * The following attributes are used when constructing submenus:
117  * 
118  * - "label": a user-visible string to display
119  * - "icon": icon name to display
120  * 
121  * Menu items will also show accelerators, which are usually associated
122  * with actions via [method@Gtk.Application.set_accels_for_action],
123  * [id@gtk_widget_class_add_binding_action] or
124  * [method@Gtk.ShortcutController.add_shortcut].
125  * 
126  * # CSS Nodes
127  * 
128  * `GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content
129  * to it, therefore it has the same CSS nodes. It is one of the cases that add
130  * a .menu style class to the popover's main node.
131  * 
132  * # Accessibility
133  * 
134  * `GtkPopoverMenu` uses the %GTK_ACCESSIBLE_ROLE_MENU role, and its
135  * items use the %GTK_ACCESSIBLE_ROLE_MENU_ITEM,
136  * %GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX or
137  * %GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO roles, depending on the
138  * action they are connected to.
139  */
140 public class PopoverMenu : Popover
141 {
142 	/** the main Gtk struct */
143 	protected GtkPopoverMenu* gtkPopoverMenu;
144 
145 	/** Get the main Gtk struct */
146 	public GtkPopoverMenu* getPopoverMenuStruct(bool transferOwnership = false)
147 	{
148 		if (transferOwnership)
149 			ownedRef = false;
150 		return gtkPopoverMenu;
151 	}
152 
153 	/** the main Gtk struct as a void* */
154 	protected override void* getStruct()
155 	{
156 		return cast(void*)gtkPopoverMenu;
157 	}
158 
159 	/**
160 	 * Sets our main struct and passes it to the parent class.
161 	 */
162 	public this (GtkPopoverMenu* gtkPopoverMenu, bool ownedRef = false)
163 	{
164 		this.gtkPopoverMenu = gtkPopoverMenu;
165 		super(cast(GtkPopover*)gtkPopoverMenu, ownedRef);
166 	}
167 
168 
169 	/** */
170 	public static GType getType()
171 	{
172 		return gtk_popover_menu_get_type();
173 	}
174 
175 	/**
176 	 * Creates a `GtkPopoverMenu` and populates it according to @model.
177 	 *
178 	 * The created buttons are connected to actions found in the
179 	 * `GtkApplicationWindow` to which the popover belongs - typically
180 	 * by means of being attached to a widget that is contained within
181 	 * the `GtkApplicationWindow`s widget hierarchy.
182 	 *
183 	 * Actions can also be added using [method@Gtk.Widget.insert_action_group]
184 	 * on the menus attach widget or on any of its parent widgets.
185 	 *
186 	 * This function creates menus with sliding submenus.
187 	 * See [ctor@Gtk.PopoverMenu.new_from_model_full] for a way
188 	 * to control this.
189 	 *
190 	 * Params:
191 	 *     model = a `GMenuModel`, or %NULL
192 	 *
193 	 * Returns: the new `GtkPopoverMenu`
194 	 *
195 	 * Throws: ConstructionException GTK+ fails to create the object.
196 	 */
197 	public this(MenuModel model)
198 	{
199 		auto __p = gtk_popover_menu_new_from_model((model is null) ? null : model.getMenuModelStruct());
200 
201 		if(__p is null)
202 		{
203 			throw new ConstructionException("null returned by new_from_model");
204 		}
205 
206 		this(cast(GtkPopoverMenu*) __p);
207 	}
208 
209 	/**
210 	 * Creates a `GtkPopoverMenu` and populates it according to @model.
211 	 *
212 	 * The created buttons are connected to actions found in the
213 	 * action groups that are accessible from the parent widget.
214 	 * This includes the `GtkApplicationWindow` to which the popover
215 	 * belongs. Actions can also be added using [method@Gtk.Widget.insert_action_group]
216 	 * on the parent widget or on any of its parent widgets.
217 	 *
218 	 * The only flag that is supported currently is
219 	 * %GTK_POPOVER_MENU_NESTED, which makes GTK create traditional,
220 	 * nested submenus instead of the default sliding submenus.
221 	 *
222 	 * Params:
223 	 *     model = a `GMenuModel`
224 	 *     flags = flags that affect how the menu is created
225 	 *
226 	 * Returns: the new `GtkPopoverMenu`
227 	 *
228 	 * Throws: ConstructionException GTK+ fails to create the object.
229 	 */
230 	public this(MenuModel model, GtkPopoverMenuFlags flags)
231 	{
232 		auto __p = gtk_popover_menu_new_from_model_full((model is null) ? null : model.getMenuModelStruct(), flags);
233 
234 		if(__p is null)
235 		{
236 			throw new ConstructionException("null returned by new_from_model_full");
237 		}
238 
239 		this(cast(GtkPopoverMenu*) __p, true);
240 	}
241 
242 	/**
243 	 * Adds a custom widget to a generated menu.
244 	 *
245 	 * For this to work, the menu model of @popover must have
246 	 * an item with a `custom` attribute that matches @id.
247 	 *
248 	 * Params:
249 	 *     child = the `GtkWidget` to add
250 	 *     id = the ID to insert @child at
251 	 *
252 	 * Returns: %TRUE if @id was found and the widget added
253 	 */
254 	public bool addChild(Widget child, string id)
255 	{
256 		return gtk_popover_menu_add_child(gtkPopoverMenu, (child is null) ? null : child.getWidgetStruct(), Str.toStringz(id)) != 0;
257 	}
258 
259 	/**
260 	 * Returns the menu model used to populate the popover.
261 	 *
262 	 * Returns: the menu model of @popover
263 	 */
264 	public MenuModel getMenuModel()
265 	{
266 		auto __p = gtk_popover_menu_get_menu_model(gtkPopoverMenu);
267 
268 		if(__p is null)
269 		{
270 			return null;
271 		}
272 
273 		return ObjectG.getDObject!(MenuModel)(cast(GMenuModel*) __p);
274 	}
275 
276 	/**
277 	 * Removes a widget that has previously been added with
278 	 * gtk_popover_menu_add_child().
279 	 *
280 	 * Params:
281 	 *     child = the `GtkWidget` to remove
282 	 *
283 	 * Returns: %TRUE if the widget was removed
284 	 */
285 	public bool removeChild(Widget child)
286 	{
287 		return gtk_popover_menu_remove_child(gtkPopoverMenu, (child is null) ? null : child.getWidgetStruct()) != 0;
288 	}
289 
290 	/**
291 	 * Sets a new menu model on @popover.
292 	 *
293 	 * The existing contents of @popover are removed, and
294 	 * the @popover is populated with new contents according
295 	 * to @model.
296 	 *
297 	 * Params:
298 	 *     model = a `GMenuModel`, or %NULL
299 	 */
300 	public void setMenuModel(MenuModel model)
301 	{
302 		gtk_popover_menu_set_menu_model(gtkPopoverMenu, (model is null) ? null : model.getMenuModelStruct());
303 	}
304 }