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