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