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.Toolbar;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.Container;
31 private import gtk.OrientableIF;
32 private import gtk.OrientableT;
33 private import gtk.ToolItem;
34 private import gtk.ToolShellIF;
35 private import gtk.ToolShellT;
36 private import gtk.Widget;
37 private import gtk.c.functions;
38 public  import gtk.c.types;
39 public  import gtkc.gtktypes;
40 private import std.algorithm;
41 
42 
43 /**
44  * A toolbar is created with a call to gtk_toolbar_new().
45  * 
46  * A toolbar can contain instances of a subclass of #GtkToolItem. To add
47  * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove
48  * an item from the toolbar use gtk_container_remove(). To add a button
49  * to the toolbar, add an instance of #GtkToolButton.
50  * 
51  * Toolbar items can be visually grouped by adding instances of
52  * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property
53  * “expand” is #TRUE and the property #GtkSeparatorToolItem:draw is set to
54  * #FALSE, the effect is to force all following items to the end of the toolbar.
55  * 
56  * By default, a toolbar can be shrunk, upon which it will add an arrow button
57  * to show an overflow menu offering access to any #GtkToolItem child that has
58  * a proxy menu item. To disable this and request enough size for all children,
59  * call gtk_toolbar_set_show_arrow() to set #GtkToolbar:show-arrow to %FALSE.
60  * 
61  * Creating a context menu for the toolbar can be done by connecting to
62  * the #GtkToolbar::popup-context-menu signal.
63  * 
64  * # CSS nodes
65  * 
66  * GtkToolbar has a single CSS node with name toolbar.
67  */
68 public class Toolbar : Container, OrientableIF, ToolShellIF
69 {
70 	/** the main Gtk struct */
71 	protected GtkToolbar* gtkToolbar;
72 
73 	/** Get the main Gtk struct */
74 	public GtkToolbar* getToolbarStruct(bool transferOwnership = false)
75 	{
76 		if (transferOwnership)
77 			ownedRef = false;
78 		return gtkToolbar;
79 	}
80 
81 	/** the main Gtk struct as a void* */
82 	protected override void* getStruct()
83 	{
84 		return cast(void*)gtkToolbar;
85 	}
86 
87 	/**
88 	 * Sets our main struct and passes it to the parent class.
89 	 */
90 	public this (GtkToolbar* gtkToolbar, bool ownedRef = false)
91 	{
92 		this.gtkToolbar = gtkToolbar;
93 		super(cast(GtkContainer*)gtkToolbar, ownedRef);
94 	}
95 
96 	// add the Orientable capabilities
97 	mixin OrientableT!(GtkToolbar);
98 
99 	// add the ToolShell capabilities
100 	mixin ToolShellT!(GtkToolbar);
101 
102 	/**
103 	 * Insert a GtkToolItem into the toolbar at position pos.
104 	 * If pos is 0 the item is prepended to the start of the toolbar. If pos is negative, the item is appended to the end of the toolbar.
105 	 * Since 2.4
106 	 * Params:
107 	 * toolItem  = a GtkToolItem
108 	 * pos = the position of the new item
109 	 */
110 	public void insert(ToolItem toolItem, int pos=-1)
111 	{
112 		gtk_toolbar_insert(gtkToolbar, toolItem.getToolItemStruct(), pos);
113 	}
114 
115 	/**
116 	 */
117 
118 	/** */
119 	public static GType getType()
120 	{
121 		return gtk_toolbar_get_type();
122 	}
123 
124 	/**
125 	 * Creates a new toolbar.
126 	 *
127 	 * Returns: the newly-created toolbar.
128 	 *
129 	 * Throws: ConstructionException GTK+ fails to create the object.
130 	 */
131 	public this()
132 	{
133 		auto p = gtk_toolbar_new();
134 
135 		if(p is null)
136 		{
137 			throw new ConstructionException("null returned by new");
138 		}
139 
140 		this(cast(GtkToolbar*) p);
141 	}
142 
143 	/**
144 	 * Returns the position corresponding to the indicated point on
145 	 * @toolbar. This is useful when dragging items to the toolbar:
146 	 * this function returns the position a new item should be
147 	 * inserted.
148 	 *
149 	 * @x and @y are in @toolbar coordinates.
150 	 *
151 	 * Params:
152 	 *     x = x coordinate of a point on the toolbar
153 	 *     y = y coordinate of a point on the toolbar
154 	 *
155 	 * Returns: The position corresponding to the point (@x, @y) on the toolbar.
156 	 *
157 	 * Since: 2.4
158 	 */
159 	public int getDropIndex(int x, int y)
160 	{
161 		return gtk_toolbar_get_drop_index(gtkToolbar, x, y);
162 	}
163 
164 	/**
165 	 * Returns the position of @item on the toolbar, starting from 0.
166 	 * It is an error if @item is not a child of the toolbar.
167 	 *
168 	 * Params:
169 	 *     item = a #GtkToolItem that is a child of @toolbar
170 	 *
171 	 * Returns: the position of item on the toolbar.
172 	 *
173 	 * Since: 2.4
174 	 */
175 	public int getItemIndex(ToolItem item)
176 	{
177 		return gtk_toolbar_get_item_index(gtkToolbar, (item is null) ? null : item.getToolItemStruct());
178 	}
179 
180 	/**
181 	 * Returns the number of items on the toolbar.
182 	 *
183 	 * Returns: the number of items on the toolbar
184 	 *
185 	 * Since: 2.4
186 	 */
187 	public int getNItems()
188 	{
189 		return gtk_toolbar_get_n_items(gtkToolbar);
190 	}
191 
192 	/**
193 	 * Returns the @n'th item on @toolbar, or %NULL if the
194 	 * toolbar does not contain an @n'th item.
195 	 *
196 	 * Params:
197 	 *     n = A position on the toolbar
198 	 *
199 	 * Returns: The @n'th #GtkToolItem on @toolbar,
200 	 *     or %NULL if there isn’t an @n'th item.
201 	 *
202 	 * Since: 2.4
203 	 */
204 	public ToolItem getNthItem(int n)
205 	{
206 		auto p = gtk_toolbar_get_nth_item(gtkToolbar, n);
207 
208 		if(p is null)
209 		{
210 			return null;
211 		}
212 
213 		return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p);
214 	}
215 
216 	/**
217 	 * Returns whether the toolbar has an overflow menu.
218 	 * See gtk_toolbar_set_show_arrow().
219 	 *
220 	 * Returns: %TRUE if the toolbar has an overflow menu.
221 	 *
222 	 * Since: 2.4
223 	 */
224 	public bool getShowArrow()
225 	{
226 		return gtk_toolbar_get_show_arrow(gtkToolbar) != 0;
227 	}
228 
229 	/**
230 	 * Retrieves whether the toolbar has text, icons, or both . See
231 	 * gtk_toolbar_set_style().
232 	 *
233 	 * Returns: the current style of @toolbar
234 	 */
235 	public GtkToolbarStyle getToolbarStyle()
236 	{
237 		return gtk_toolbar_get_style(gtkToolbar);
238 	}
239 
240 	/**
241 	 * Highlights @toolbar to give an idea of what it would look like
242 	 * if @item was added to @toolbar at the position indicated by @index_.
243 	 * If @item is %NULL, highlighting is turned off. In that case @index_
244 	 * is ignored.
245 	 *
246 	 * The @tool_item passed to this function must not be part of any widget
247 	 * hierarchy. When an item is set as drop highlight item it can not
248 	 * added to any widget hierarchy or used as highlight item for another
249 	 * toolbar.
250 	 *
251 	 * Params:
252 	 *     toolItem = a #GtkToolItem, or %NULL to turn of highlighting
253 	 *     index = a position on @toolbar
254 	 *
255 	 * Since: 2.4
256 	 */
257 	public void setDropHighlightItem(ToolItem toolItem, int index)
258 	{
259 		gtk_toolbar_set_drop_highlight_item(gtkToolbar, (toolItem is null) ? null : toolItem.getToolItemStruct(), index);
260 	}
261 
262 	/**
263 	 * This function sets the size of stock icons in the toolbar. You
264 	 * can call it both before you add the icons and after they’ve been
265 	 * added. The size you set will override user preferences for the default
266 	 * icon size.
267 	 *
268 	 * This should only be used for special-purpose toolbars, normal
269 	 * application toolbars should respect the user preferences for the
270 	 * size of icons.
271 	 *
272 	 * Params:
273 	 *     iconSize = The #GtkIconSize that stock icons in the toolbar shall have.
274 	 */
275 	public void setIconSize(GtkIconSize iconSize)
276 	{
277 		gtk_toolbar_set_icon_size(gtkToolbar, iconSize);
278 	}
279 
280 	/**
281 	 * Sets whether to show an overflow menu when @toolbar isn’t allocated enough
282 	 * size to show all of its items. If %TRUE, items which can’t fit in @toolbar,
283 	 * and which have a proxy menu item set by gtk_tool_item_set_proxy_menu_item()
284 	 * or #GtkToolItem::create-menu-proxy, will be available in an overflow menu,
285 	 * which can be opened by an added arrow button. If %FALSE, @toolbar will
286 	 * request enough size to fit all of its child items without any overflow.
287 	 *
288 	 * Params:
289 	 *     showArrow = Whether to show an overflow menu
290 	 *
291 	 * Since: 2.4
292 	 */
293 	public void setShowArrow(bool showArrow)
294 	{
295 		gtk_toolbar_set_show_arrow(gtkToolbar, showArrow);
296 	}
297 
298 	/**
299 	 * Alters the view of @toolbar to display either icons only, text only, or both.
300 	 *
301 	 * Params:
302 	 *     style = the new style for @toolbar.
303 	 */
304 	public void setStyle(GtkToolbarStyle style)
305 	{
306 		gtk_toolbar_set_style(gtkToolbar, style);
307 	}
308 
309 	/**
310 	 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
311 	 * user preferences will be used to determine the icon size.
312 	 */
313 	public void unsetIconSize()
314 	{
315 		gtk_toolbar_unset_icon_size(gtkToolbar);
316 	}
317 
318 	/**
319 	 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
320 	 * user preferences will be used to determine the toolbar style.
321 	 */
322 	public void unsetStyle()
323 	{
324 		gtk_toolbar_unset_style(gtkToolbar);
325 	}
326 
327 	/**
328 	 * A keybinding signal used internally by GTK+. This signal can't
329 	 * be used in application code
330 	 *
331 	 * Params:
332 	 *     focusHome = %TRUE if the first item should be focused
333 	 *
334 	 * Returns: %TRUE if the signal was handled, %FALSE if not
335 	 */
336 	gulong addOnFocusHomeOrEnd(bool delegate(bool, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
337 	{
338 		return Signals.connect(this, "focus-home-or-end", dlg, connectFlags ^ ConnectFlags.SWAPPED);
339 	}
340 
341 	/**
342 	 * Emitted when the orientation of the toolbar changes.
343 	 *
344 	 * Params:
345 	 *     orientation = the new #GtkOrientation of the toolbar
346 	 */
347 	gulong addOnOrientationChanged(void delegate(GtkOrientation, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
348 	{
349 		return Signals.connect(this, "orientation-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
350 	}
351 
352 	/**
353 	 * Emitted when the user right-clicks the toolbar or uses the
354 	 * keybinding to display a popup menu.
355 	 *
356 	 * Application developers should handle this signal if they want
357 	 * to display a context menu on the toolbar. The context-menu should
358 	 * appear at the coordinates given by @x and @y. The mouse button
359 	 * number is given by the @button parameter. If the menu was popped
360 	 * up using the keybaord, @button is -1.
361 	 *
362 	 * Params:
363 	 *     x = the x coordinate of the point where the menu should appear
364 	 *     y = the y coordinate of the point where the menu should appear
365 	 *     button = the mouse button the user pressed, or -1
366 	 *
367 	 * Returns: return %TRUE if the signal was handled, %FALSE if not
368 	 */
369 	gulong addOnPopupContextMenu(bool delegate(int, int, int, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
370 	{
371 		return Signals.connect(this, "popup-context-menu", dlg, connectFlags ^ ConnectFlags.SWAPPED);
372 	}
373 
374 	/**
375 	 * Emitted when the style of the toolbar changes.
376 	 *
377 	 * Params:
378 	 *     style = the new #GtkToolbarStyle of the toolbar
379 	 */
380 	gulong addOnStyleChanged(void delegate(GtkToolbarStyle, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
381 	{
382 		return Signals.connect(this, "style-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
383 	}
384 }