1 module webkit2.OptionMenu;
2 
3 private import gobject.ObjectG;
4 private import gobject.Signals;
5 private import std.algorithm;
6 private import webkit2.OptionMenuItem;
7 private import webkit2.c.functions;
8 public  import webkit2.c.types;
9 
10 
11 /**
12  * WebKitOptionMenu represents the dropdown menu of a select element in a #WebKitWebView.
13  * 
14  * When a select element in a #WebKitWebView needs to display a dropdown menu, the signal
15  * #WebKitWebView::show-option-menu is emitted, providing a WebKitOptionMenu with the
16  * #WebKitOptionMenuItem<!-- -->s that should be displayed.
17  *
18  * Since: 2.18
19  */
20 public class OptionMenu : ObjectG
21 {
22 	/** the main Gtk struct */
23 	protected WebKitOptionMenu* webKitOptionMenu;
24 
25 	/** Get the main Gtk struct */
26 	public WebKitOptionMenu* getOptionMenuStruct(bool transferOwnership = false)
27 	{
28 		if (transferOwnership)
29 			ownedRef = false;
30 		return webKitOptionMenu;
31 	}
32 
33 	/** the main Gtk struct as a void* */
34 	protected override void* getStruct()
35 	{
36 		return cast(void*)webKitOptionMenu;
37 	}
38 
39 	/**
40 	 * Sets our main struct and passes it to the parent class.
41 	 */
42 	public this (WebKitOptionMenu* webKitOptionMenu, bool ownedRef = false)
43 	{
44 		this.webKitOptionMenu = webKitOptionMenu;
45 		super(cast(GObject*)webKitOptionMenu, ownedRef);
46 	}
47 
48 
49 	/** */
50 	public static GType getType()
51 	{
52 		return webkit_option_menu_get_type();
53 	}
54 
55 	/**
56 	 * Activates the #WebKitOptionMenuItem at @index in @menu. Activating an item changes the value
57 	 * of the element making the item the active one. You are expected to close the menu with
58 	 * webkit_option_menu_close() after activating an item, calling this function again will have no
59 	 * effect.
60 	 *
61 	 * Params:
62 	 *     index = the index of the item
63 	 *
64 	 * Since: 2.18
65 	 */
66 	public void activateItem(uint index)
67 	{
68 		webkit_option_menu_activate_item(webKitOptionMenu, index);
69 	}
70 
71 	/**
72 	 * Request to close a #WebKitOptionMenu. This emits WebKitOptionMenu::close signal.
73 	 * This function should always be called to notify WebKit that the associated
74 	 * menu has been closed. If the menu is closed and neither webkit_option_menu_select_item()
75 	 * nor webkit_option_menu_activate_item() have been called, the element value remains
76 	 * unchanged.
77 	 *
78 	 * Since: 2.18
79 	 */
80 	public void close()
81 	{
82 		webkit_option_menu_close(webKitOptionMenu);
83 	}
84 
85 	/**
86 	 * Returns the #WebKitOptionMenuItem at @index in @menu.
87 	 *
88 	 * Params:
89 	 *     index = the index of the item
90 	 *
91 	 * Returns: a #WebKitOptionMenuItem of @menu.
92 	 *
93 	 * Since: 2.18
94 	 */
95 	public OptionMenuItem getItem(uint index)
96 	{
97 		auto __p = webkit_option_menu_get_item(webKitOptionMenu, index);
98 
99 		if(__p is null)
100 		{
101 			return null;
102 		}
103 
104 		return ObjectG.getDObject!(OptionMenuItem)(cast(WebKitOptionMenuItem*) __p);
105 	}
106 
107 	/**
108 	 * Gets the length of the @menu.
109 	 *
110 	 * Returns: the number of #WebKitOptionMenuItem<!-- -->s in @menu
111 	 *
112 	 * Since: 2.18
113 	 */
114 	public uint getNItems()
115 	{
116 		return webkit_option_menu_get_n_items(webKitOptionMenu);
117 	}
118 
119 	/**
120 	 * Selects the #WebKitOptionMenuItem at @index in @menu. Selecting an item changes the
121 	 * text shown by the combo button, but it doesn't change the value of the element. You need to
122 	 * explicitly activate the item with webkit_option_menu_select_item() or close the menu with
123 	 * webkit_option_menu_close() in which case the currently selected item will be activated.
124 	 *
125 	 * Params:
126 	 *     index = the index of the item
127 	 *
128 	 * Since: 2.18
129 	 */
130 	public void selectItem(uint index)
131 	{
132 		webkit_option_menu_select_item(webKitOptionMenu, index);
133 	}
134 
135 	/**
136 	 * Emitted when closing a #WebKitOptionMenu is requested. This can happen
137 	 * when the user explicitly calls webkit_option_menu_close() or when the
138 	 * element is detached from the current page.
139 	 *
140 	 * Since: 2.18
141 	 */
142 	gulong addOnClose(void delegate(OptionMenu) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
143 	{
144 		return Signals.connect(this, "close", dlg, connectFlags ^ ConnectFlags.SWAPPED);
145 	}
146 }