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 	protected override void setStruct(GObject* obj)
88 	{
89 		gtkToolbar = cast(GtkToolbar*)obj;
90 		super.setStruct(obj);
91 	}
92 
93 	/**
94 	 * Sets our main struct and passes it to the parent class.
95 	 */
96 	public this (GtkToolbar* gtkToolbar, bool ownedRef = false)
97 	{
98 		this.gtkToolbar = gtkToolbar;
99 		super(cast(GtkContainer*)gtkToolbar, ownedRef);
100 	}
101 
102 	// add the Orientable capabilities
103 	mixin OrientableT!(GtkToolbar);
104 
105 	// add the ToolShell capabilities
106 	mixin ToolShellT!(GtkToolbar);
107 
108 	/**
109 	 * Insert a GtkToolItem into the toolbar at position pos.
110 	 * 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.
111 	 * Since 2.4
112 	 * Params:
113 	 * toolItem  = a GtkToolItem
114 	 * pos = the position of the new item
115 	 */
116 	public void insert(ToolItem toolItem, int pos=-1)
117 	{
118 		gtk_toolbar_insert(gtkToolbar, toolItem.getToolItemStruct(), pos);
119 	}
120 
121 	/**
122 	 */
123 
124 	/** */
125 	public static GType getType()
126 	{
127 		return gtk_toolbar_get_type();
128 	}
129 
130 	/**
131 	 * Creates a new toolbar.
132 	 *
133 	 * Returns: the newly-created toolbar.
134 	 *
135 	 * Throws: ConstructionException GTK+ fails to create the object.
136 	 */
137 	public this()
138 	{
139 		auto p = gtk_toolbar_new();
140 
141 		if(p is null)
142 		{
143 			throw new ConstructionException("null returned by new");
144 		}
145 
146 		this(cast(GtkToolbar*) p);
147 	}
148 
149 	/**
150 	 * Returns the position corresponding to the indicated point on
151 	 * @toolbar. This is useful when dragging items to the toolbar:
152 	 * this function returns the position a new item should be
153 	 * inserted.
154 	 *
155 	 * @x and @y are in @toolbar coordinates.
156 	 *
157 	 * Params:
158 	 *     x = x coordinate of a point on the toolbar
159 	 *     y = y coordinate of a point on the toolbar
160 	 *
161 	 * Returns: The position corresponding to the point (@x, @y) on the toolbar.
162 	 *
163 	 * Since: 2.4
164 	 */
165 	public int getDropIndex(int x, int y)
166 	{
167 		return gtk_toolbar_get_drop_index(gtkToolbar, x, y);
168 	}
169 
170 	/**
171 	 * Returns the position of @item on the toolbar, starting from 0.
172 	 * It is an error if @item is not a child of the toolbar.
173 	 *
174 	 * Params:
175 	 *     item = a #GtkToolItem that is a child of @toolbar
176 	 *
177 	 * Returns: the position of item on the toolbar.
178 	 *
179 	 * Since: 2.4
180 	 */
181 	public int getItemIndex(ToolItem item)
182 	{
183 		return gtk_toolbar_get_item_index(gtkToolbar, (item is null) ? null : item.getToolItemStruct());
184 	}
185 
186 	/**
187 	 * Returns the number of items on the toolbar.
188 	 *
189 	 * Returns: the number of items on the toolbar
190 	 *
191 	 * Since: 2.4
192 	 */
193 	public int getNItems()
194 	{
195 		return gtk_toolbar_get_n_items(gtkToolbar);
196 	}
197 
198 	/**
199 	 * Returns the @n'th item on @toolbar, or %NULL if the
200 	 * toolbar does not contain an @n'th item.
201 	 *
202 	 * Params:
203 	 *     n = A position on the toolbar
204 	 *
205 	 * Returns: The @n'th #GtkToolItem on @toolbar,
206 	 *     or %NULL if there isn’t an @n'th item.
207 	 *
208 	 * Since: 2.4
209 	 */
210 	public ToolItem getNthItem(int n)
211 	{
212 		auto p = gtk_toolbar_get_nth_item(gtkToolbar, n);
213 
214 		if(p is null)
215 		{
216 			return null;
217 		}
218 
219 		return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p);
220 	}
221 
222 	/**
223 	 * Returns whether the toolbar has an overflow menu.
224 	 * See gtk_toolbar_set_show_arrow().
225 	 *
226 	 * Returns: %TRUE if the toolbar has an overflow menu.
227 	 *
228 	 * Since: 2.4
229 	 */
230 	public bool getShowArrow()
231 	{
232 		return gtk_toolbar_get_show_arrow(gtkToolbar) != 0;
233 	}
234 
235 	/**
236 	 * Retrieves whether the toolbar has text, icons, or both . See
237 	 * gtk_toolbar_set_style().
238 	 *
239 	 * Returns: the current style of @toolbar
240 	 */
241 	public GtkToolbarStyle getToolbarStyle()
242 	{
243 		return gtk_toolbar_get_style(gtkToolbar);
244 	}
245 
246 	/**
247 	 * Highlights @toolbar to give an idea of what it would look like
248 	 * if @item was added to @toolbar at the position indicated by @index_.
249 	 * If @item is %NULL, highlighting is turned off. In that case @index_
250 	 * is ignored.
251 	 *
252 	 * The @tool_item passed to this function must not be part of any widget
253 	 * hierarchy. When an item is set as drop highlight item it can not
254 	 * added to any widget hierarchy or used as highlight item for another
255 	 * toolbar.
256 	 *
257 	 * Params:
258 	 *     toolItem = a #GtkToolItem, or %NULL to turn of highlighting
259 	 *     index = a position on @toolbar
260 	 *
261 	 * Since: 2.4
262 	 */
263 	public void setDropHighlightItem(ToolItem toolItem, int index)
264 	{
265 		gtk_toolbar_set_drop_highlight_item(gtkToolbar, (toolItem is null) ? null : toolItem.getToolItemStruct(), index);
266 	}
267 
268 	/**
269 	 * This function sets the size of stock icons in the toolbar. You
270 	 * can call it both before you add the icons and after they’ve been
271 	 * added. The size you set will override user preferences for the default
272 	 * icon size.
273 	 *
274 	 * This should only be used for special-purpose toolbars, normal
275 	 * application toolbars should respect the user preferences for the
276 	 * size of icons.
277 	 *
278 	 * Params:
279 	 *     iconSize = The #GtkIconSize that stock icons in the toolbar shall have.
280 	 */
281 	public void setIconSize(GtkIconSize iconSize)
282 	{
283 		gtk_toolbar_set_icon_size(gtkToolbar, iconSize);
284 	}
285 
286 	/**
287 	 * Sets whether to show an overflow menu when @toolbar isn’t allocated enough
288 	 * size to show all of its items. If %TRUE, items which can’t fit in @toolbar,
289 	 * and which have a proxy menu item set by gtk_tool_item_set_proxy_menu_item()
290 	 * or #GtkToolItem::create-menu-proxy, will be available in an overflow menu,
291 	 * which can be opened by an added arrow button. If %FALSE, @toolbar will
292 	 * request enough size to fit all of its child items without any overflow.
293 	 *
294 	 * Params:
295 	 *     showArrow = Whether to show an overflow menu
296 	 *
297 	 * Since: 2.4
298 	 */
299 	public void setShowArrow(bool showArrow)
300 	{
301 		gtk_toolbar_set_show_arrow(gtkToolbar, showArrow);
302 	}
303 
304 	/**
305 	 * Alters the view of @toolbar to display either icons only, text only, or both.
306 	 *
307 	 * Params:
308 	 *     style = the new style for @toolbar.
309 	 */
310 	public void setStyle(GtkToolbarStyle style)
311 	{
312 		gtk_toolbar_set_style(gtkToolbar, style);
313 	}
314 
315 	/**
316 	 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that
317 	 * user preferences will be used to determine the icon size.
318 	 */
319 	public void unsetIconSize()
320 	{
321 		gtk_toolbar_unset_icon_size(gtkToolbar);
322 	}
323 
324 	/**
325 	 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
326 	 * user preferences will be used to determine the toolbar style.
327 	 */
328 	public void unsetStyle()
329 	{
330 		gtk_toolbar_unset_style(gtkToolbar);
331 	}
332 
333 	protected class OnFocusHomeOrEndDelegateWrapper
334 	{
335 		bool delegate(bool, Toolbar) dlg;
336 		gulong handlerId;
337 
338 		this(bool delegate(bool, Toolbar) dlg)
339 		{
340 			this.dlg = dlg;
341 			onFocusHomeOrEndListeners ~= this;
342 		}
343 
344 		void remove(OnFocusHomeOrEndDelegateWrapper source)
345 		{
346 			foreach(index, wrapper; onFocusHomeOrEndListeners)
347 			{
348 				if (wrapper.handlerId == source.handlerId)
349 				{
350 					onFocusHomeOrEndListeners[index] = null;
351 					onFocusHomeOrEndListeners = std.algorithm.remove(onFocusHomeOrEndListeners, index);
352 					break;
353 				}
354 			}
355 		}
356 	}
357 	OnFocusHomeOrEndDelegateWrapper[] onFocusHomeOrEndListeners;
358 
359 	/**
360 	 * A keybinding signal used internally by GTK+. This signal can't
361 	 * be used in application code
362 	 *
363 	 * Params:
364 	 *     focusHome = %TRUE if the first item should be focused
365 	 *
366 	 * Returns: %TRUE if the signal was handled, %FALSE if not
367 	 */
368 	gulong addOnFocusHomeOrEnd(bool delegate(bool, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
369 	{
370 		auto wrapper = new OnFocusHomeOrEndDelegateWrapper(dlg);
371 		wrapper.handlerId = Signals.connectData(
372 			this,
373 			"focus-home-or-end",
374 			cast(GCallback)&callBackFocusHomeOrEnd,
375 			cast(void*)wrapper,
376 			cast(GClosureNotify)&callBackFocusHomeOrEndDestroy,
377 			connectFlags);
378 		return wrapper.handlerId;
379 	}
380 
381 	extern(C) static int callBackFocusHomeOrEnd(GtkToolbar* toolbarStruct, bool focusHome, OnFocusHomeOrEndDelegateWrapper wrapper)
382 	{
383 		return wrapper.dlg(focusHome, wrapper.outer);
384 	}
385 
386 	extern(C) static void callBackFocusHomeOrEndDestroy(OnFocusHomeOrEndDelegateWrapper wrapper, GClosure* closure)
387 	{
388 		wrapper.remove(wrapper);
389 	}
390 
391 	protected class OnOrientationChangedDelegateWrapper
392 	{
393 		void delegate(GtkOrientation, Toolbar) dlg;
394 		gulong handlerId;
395 
396 		this(void delegate(GtkOrientation, Toolbar) dlg)
397 		{
398 			this.dlg = dlg;
399 			onOrientationChangedListeners ~= this;
400 		}
401 
402 		void remove(OnOrientationChangedDelegateWrapper source)
403 		{
404 			foreach(index, wrapper; onOrientationChangedListeners)
405 			{
406 				if (wrapper.handlerId == source.handlerId)
407 				{
408 					onOrientationChangedListeners[index] = null;
409 					onOrientationChangedListeners = std.algorithm.remove(onOrientationChangedListeners, index);
410 					break;
411 				}
412 			}
413 		}
414 	}
415 	OnOrientationChangedDelegateWrapper[] onOrientationChangedListeners;
416 
417 	/**
418 	 * Emitted when the orientation of the toolbar changes.
419 	 *
420 	 * Params:
421 	 *     orientation = the new #GtkOrientation of the toolbar
422 	 */
423 	gulong addOnOrientationChanged(void delegate(GtkOrientation, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
424 	{
425 		auto wrapper = new OnOrientationChangedDelegateWrapper(dlg);
426 		wrapper.handlerId = Signals.connectData(
427 			this,
428 			"orientation-changed",
429 			cast(GCallback)&callBackOrientationChanged,
430 			cast(void*)wrapper,
431 			cast(GClosureNotify)&callBackOrientationChangedDestroy,
432 			connectFlags);
433 		return wrapper.handlerId;
434 	}
435 
436 	extern(C) static void callBackOrientationChanged(GtkToolbar* toolbarStruct, GtkOrientation orientation, OnOrientationChangedDelegateWrapper wrapper)
437 	{
438 		wrapper.dlg(orientation, wrapper.outer);
439 	}
440 
441 	extern(C) static void callBackOrientationChangedDestroy(OnOrientationChangedDelegateWrapper wrapper, GClosure* closure)
442 	{
443 		wrapper.remove(wrapper);
444 	}
445 
446 	protected class OnPopupContextMenuDelegateWrapper
447 	{
448 		bool delegate(int, int, int, Toolbar) dlg;
449 		gulong handlerId;
450 
451 		this(bool delegate(int, int, int, Toolbar) dlg)
452 		{
453 			this.dlg = dlg;
454 			onPopupContextMenuListeners ~= this;
455 		}
456 
457 		void remove(OnPopupContextMenuDelegateWrapper source)
458 		{
459 			foreach(index, wrapper; onPopupContextMenuListeners)
460 			{
461 				if (wrapper.handlerId == source.handlerId)
462 				{
463 					onPopupContextMenuListeners[index] = null;
464 					onPopupContextMenuListeners = std.algorithm.remove(onPopupContextMenuListeners, index);
465 					break;
466 				}
467 			}
468 		}
469 	}
470 	OnPopupContextMenuDelegateWrapper[] onPopupContextMenuListeners;
471 
472 	/**
473 	 * Emitted when the user right-clicks the toolbar or uses the
474 	 * keybinding to display a popup menu.
475 	 *
476 	 * Application developers should handle this signal if they want
477 	 * to display a context menu on the toolbar. The context-menu should
478 	 * appear at the coordinates given by @x and @y. The mouse button
479 	 * number is given by the @button parameter. If the menu was popped
480 	 * up using the keybaord, @button is -1.
481 	 *
482 	 * Params:
483 	 *     x = the x coordinate of the point where the menu should appear
484 	 *     y = the y coordinate of the point where the menu should appear
485 	 *     button = the mouse button the user pressed, or -1
486 	 *
487 	 * Returns: return %TRUE if the signal was handled, %FALSE if not
488 	 */
489 	gulong addOnPopupContextMenu(bool delegate(int, int, int, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
490 	{
491 		auto wrapper = new OnPopupContextMenuDelegateWrapper(dlg);
492 		wrapper.handlerId = Signals.connectData(
493 			this,
494 			"popup-context-menu",
495 			cast(GCallback)&callBackPopupContextMenu,
496 			cast(void*)wrapper,
497 			cast(GClosureNotify)&callBackPopupContextMenuDestroy,
498 			connectFlags);
499 		return wrapper.handlerId;
500 	}
501 
502 	extern(C) static int callBackPopupContextMenu(GtkToolbar* toolbarStruct, int x, int y, int button, OnPopupContextMenuDelegateWrapper wrapper)
503 	{
504 		return wrapper.dlg(x, y, button, wrapper.outer);
505 	}
506 
507 	extern(C) static void callBackPopupContextMenuDestroy(OnPopupContextMenuDelegateWrapper wrapper, GClosure* closure)
508 	{
509 		wrapper.remove(wrapper);
510 	}
511 
512 	protected class OnStyleChangedDelegateWrapper
513 	{
514 		void delegate(GtkToolbarStyle, Toolbar) dlg;
515 		gulong handlerId;
516 
517 		this(void delegate(GtkToolbarStyle, Toolbar) dlg)
518 		{
519 			this.dlg = dlg;
520 			onStyleChangedListeners ~= this;
521 		}
522 
523 		void remove(OnStyleChangedDelegateWrapper source)
524 		{
525 			foreach(index, wrapper; onStyleChangedListeners)
526 			{
527 				if (wrapper.handlerId == source.handlerId)
528 				{
529 					onStyleChangedListeners[index] = null;
530 					onStyleChangedListeners = std.algorithm.remove(onStyleChangedListeners, index);
531 					break;
532 				}
533 			}
534 		}
535 	}
536 	OnStyleChangedDelegateWrapper[] onStyleChangedListeners;
537 
538 	/**
539 	 * Emitted when the style of the toolbar changes.
540 	 *
541 	 * Params:
542 	 *     style = the new #GtkToolbarStyle of the toolbar
543 	 */
544 	gulong addOnStyleChanged(void delegate(GtkToolbarStyle, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
545 	{
546 		auto wrapper = new OnStyleChangedDelegateWrapper(dlg);
547 		wrapper.handlerId = Signals.connectData(
548 			this,
549 			"style-changed",
550 			cast(GCallback)&callBackStyleChanged,
551 			cast(void*)wrapper,
552 			cast(GClosureNotify)&callBackStyleChangedDestroy,
553 			connectFlags);
554 		return wrapper.handlerId;
555 	}
556 
557 	extern(C) static void callBackStyleChanged(GtkToolbar* toolbarStruct, GtkToolbarStyle style, OnStyleChangedDelegateWrapper wrapper)
558 	{
559 		wrapper.dlg(style, wrapper.outer);
560 	}
561 
562 	extern(C) static void callBackStyleChangedDestroy(OnStyleChangedDelegateWrapper wrapper, GClosure* closure)
563 	{
564 		wrapper.remove(wrapper);
565 	}
566 }