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