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