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.ToolItem;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 private import gtk.ActivatableIF;
32 private import gtk.ActivatableT;
33 private import gtk.Bin;
34 private import gtk.SizeGroup;
35 private import gtk.Widget;
36 public  import gtkc.gdktypes;
37 private import gtkc.gtk;
38 public  import gtkc.gtktypes;
39 
40 
41 /**
42  * #GtkToolItems are widgets that can appear on a toolbar. To
43  * create a toolbar item that contain something else than a button, use
44  * gtk_tool_item_new(). Use gtk_container_add() to add a child
45  * widget to the tool item.
46  * 
47  * For toolbar items that contain buttons, see the #GtkToolButton,
48  * #GtkToggleToolButton and #GtkRadioToolButton classes.
49  * 
50  * See the #GtkToolbar class for a description of the toolbar widget, and
51  * #GtkToolShell for a description of the tool shell interface.
52  */
53 public class ToolItem : Bin, ActivatableIF
54 {
55 	/** the main Gtk struct */
56 	protected GtkToolItem* gtkToolItem;
57 
58 	/** Get the main Gtk struct */
59 	public GtkToolItem* getToolItemStruct()
60 	{
61 		return gtkToolItem;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkToolItem;
68 	}
69 
70 	protected override void setStruct(GObject* obj)
71 	{
72 		gtkToolItem = cast(GtkToolItem*)obj;
73 		super.setStruct(obj);
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GtkToolItem* gtkToolItem, bool ownedRef = false)
80 	{
81 		this.gtkToolItem = gtkToolItem;
82 		super(cast(GtkBin*)gtkToolItem, ownedRef);
83 	}
84 
85 	// add the Activatable capabilities
86 	mixin ActivatableT!(GtkToolItem);
87 
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return gtk_tool_item_get_type();
93 	}
94 
95 	/**
96 	 * Creates a new #GtkToolItem
97 	 *
98 	 * Return: the new #GtkToolItem
99 	 *
100 	 * Since: 2.4
101 	 *
102 	 * Throws: ConstructionException GTK+ fails to create the object.
103 	 */
104 	public this()
105 	{
106 		auto p = gtk_tool_item_new();
107 		
108 		if(p is null)
109 		{
110 			throw new ConstructionException("null returned by new");
111 		}
112 		
113 		this(cast(GtkToolItem*) p);
114 	}
115 
116 	/**
117 	 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
118 	 * #GtkToolItem should call this function to find out how text should
119 	 * be ellipsized.
120 	 *
121 	 * Return: a #PangoEllipsizeMode indicating how text in @tool_item
122 	 *     should be ellipsized.
123 	 *
124 	 * Since: 2.20
125 	 */
126 	public PangoEllipsizeMode getEllipsizeMode()
127 	{
128 		return gtk_tool_item_get_ellipsize_mode(gtkToolItem);
129 	}
130 
131 	/**
132 	 * Returns whether @tool_item is allocated extra space.
133 	 * See gtk_tool_item_set_expand().
134 	 *
135 	 * Return: %TRUE if @tool_item is allocated extra space.
136 	 *
137 	 * Since: 2.4
138 	 */
139 	public bool getExpand()
140 	{
141 		return gtk_tool_item_get_expand(gtkToolItem) != 0;
142 	}
143 
144 	/**
145 	 * Returns whether @tool_item is the same size as other homogeneous
146 	 * items. See gtk_tool_item_set_homogeneous().
147 	 *
148 	 * Return: %TRUE if the item is the same size as other homogeneous
149 	 *     items.
150 	 *
151 	 * Since: 2.4
152 	 */
153 	public bool getHomogeneous()
154 	{
155 		return gtk_tool_item_get_homogeneous(gtkToolItem) != 0;
156 	}
157 
158 	/**
159 	 * Returns the icon size used for @tool_item. Custom subclasses of
160 	 * #GtkToolItem should call this function to find out what size icons
161 	 * they should use.
162 	 *
163 	 * Return: a #GtkIconSize indicating the icon size
164 	 *     used for @tool_item
165 	 *
166 	 * Since: 2.4
167 	 */
168 	public GtkIconSize getIconSize()
169 	{
170 		return gtk_tool_item_get_icon_size(gtkToolItem);
171 	}
172 
173 	/**
174 	 * Returns whether @tool_item is considered important. See
175 	 * gtk_tool_item_set_is_important()
176 	 *
177 	 * Return: %TRUE if @tool_item is considered important.
178 	 *
179 	 * Since: 2.4
180 	 */
181 	public bool getIsImportant()
182 	{
183 		return gtk_tool_item_get_is_important(gtkToolItem) != 0;
184 	}
185 
186 	/**
187 	 * Returns the orientation used for @tool_item. Custom subclasses of
188 	 * #GtkToolItem should call this function to find out what size icons
189 	 * they should use.
190 	 *
191 	 * Return: a #GtkOrientation indicating the orientation
192 	 *     used for @tool_item
193 	 *
194 	 * Since: 2.4
195 	 */
196 	public GtkOrientation getOrientation()
197 	{
198 		return gtk_tool_item_get_orientation(gtkToolItem);
199 	}
200 
201 	/**
202 	 * If @menu_item_id matches the string passed to
203 	 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
204 	 *
205 	 * Custom subclasses of #GtkToolItem should use this function to
206 	 * update their menu item when the #GtkToolItem changes. That the
207 	 * @menu_item_ids must match ensures that a #GtkToolItem
208 	 * will not inadvertently change a menu item that they did not create.
209 	 *
210 	 * Params:
211 	 *     menuItemId = a string used to identify the menu item
212 	 *
213 	 * Return: The #GtkMenuItem passed to
214 	 *     gtk_tool_item_set_proxy_menu_item(), if the @menu_item_ids
215 	 *     match.
216 	 *
217 	 * Since: 2.4
218 	 */
219 	public Widget getProxyMenuItem(string menuItemId)
220 	{
221 		auto p = gtk_tool_item_get_proxy_menu_item(gtkToolItem, Str.toStringz(menuItemId));
222 		
223 		if(p is null)
224 		{
225 			return null;
226 		}
227 		
228 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
229 	}
230 
231 	/**
232 	 * Returns the relief style of @tool_item. See gtk_button_set_relief().
233 	 * Custom subclasses of #GtkToolItem should call this function in the handler
234 	 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
235 	 * relief style of buttons.
236 	 *
237 	 * Return: a #GtkReliefStyle indicating the relief style used
238 	 *     for @tool_item.
239 	 *
240 	 * Since: 2.4
241 	 */
242 	public GtkReliefStyle getReliefStyle()
243 	{
244 		return gtk_tool_item_get_relief_style(gtkToolItem);
245 	}
246 
247 	/**
248 	 * Returns the text alignment used for @tool_item. Custom subclasses of
249 	 * #GtkToolItem should call this function to find out how text should
250 	 * be aligned.
251 	 *
252 	 * Return: a #gfloat indicating the horizontal text alignment
253 	 *     used for @tool_item
254 	 *
255 	 * Since: 2.20
256 	 */
257 	public float getTextAlignment()
258 	{
259 		return gtk_tool_item_get_text_alignment(gtkToolItem);
260 	}
261 
262 	/**
263 	 * Returns the text orientation used for @tool_item. Custom subclasses of
264 	 * #GtkToolItem should call this function to find out how text should
265 	 * be orientated.
266 	 *
267 	 * Return: a #GtkOrientation indicating the text orientation
268 	 *     used for @tool_item
269 	 *
270 	 * Since: 2.20
271 	 */
272 	public GtkOrientation getTextOrientation()
273 	{
274 		return gtk_tool_item_get_text_orientation(gtkToolItem);
275 	}
276 
277 	/**
278 	 * Returns the size group used for labels in @tool_item.
279 	 * Custom subclasses of #GtkToolItem should call this function
280 	 * and use the size group for labels.
281 	 *
282 	 * Return: a #GtkSizeGroup
283 	 *
284 	 * Since: 2.20
285 	 */
286 	public SizeGroup getTextSizeGroup()
287 	{
288 		auto p = gtk_tool_item_get_text_size_group(gtkToolItem);
289 		
290 		if(p is null)
291 		{
292 			return null;
293 		}
294 		
295 		return ObjectG.getDObject!(SizeGroup)(cast(GtkSizeGroup*) p);
296 	}
297 
298 	/**
299 	 * Returns the toolbar style used for @tool_item. Custom subclasses of
300 	 * #GtkToolItem should call this function in the handler of the
301 	 * GtkToolItem::toolbar_reconfigured signal to find out in what style
302 	 * the toolbar is displayed and change themselves accordingly
303 	 *
304 	 * Possibilities are:
305 	 * - %GTK_TOOLBAR_BOTH, meaning the tool item should show
306 	 * both an icon and a label, stacked vertically
307 	 * - %GTK_TOOLBAR_ICONS, meaning the toolbar shows only icons
308 	 * - %GTK_TOOLBAR_TEXT, meaning the tool item should only show text
309 	 * - %GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
310 	 * both an icon and a label, arranged horizontally
311 	 *
312 	 * Return: A #GtkToolbarStyle indicating the toolbar style used
313 	 *     for @tool_item.
314 	 *
315 	 * Since: 2.4
316 	 */
317 	public GtkToolbarStyle getToolbarStyle()
318 	{
319 		return gtk_tool_item_get_toolbar_style(gtkToolItem);
320 	}
321 
322 	/**
323 	 * Returns whether @tool_item has a drag window. See
324 	 * gtk_tool_item_set_use_drag_window().
325 	 *
326 	 * Return: %TRUE if @tool_item uses a drag window.
327 	 *
328 	 * Since: 2.4
329 	 */
330 	public bool getUseDragWindow()
331 	{
332 		return gtk_tool_item_get_use_drag_window(gtkToolItem) != 0;
333 	}
334 
335 	/**
336 	 * Returns whether the @tool_item is visible on toolbars that are
337 	 * docked horizontally.
338 	 *
339 	 * Return: %TRUE if @tool_item is visible on toolbars that are
340 	 *     docked horizontally.
341 	 *
342 	 * Since: 2.4
343 	 */
344 	public bool getVisibleHorizontal()
345 	{
346 		return gtk_tool_item_get_visible_horizontal(gtkToolItem) != 0;
347 	}
348 
349 	/**
350 	 * Returns whether @tool_item is visible when the toolbar is docked vertically.
351 	 * See gtk_tool_item_set_visible_vertical().
352 	 *
353 	 * Return: Whether @tool_item is visible when the toolbar is docked vertically
354 	 *
355 	 * Since: 2.4
356 	 */
357 	public bool getVisibleVertical()
358 	{
359 		return gtk_tool_item_get_visible_vertical(gtkToolItem) != 0;
360 	}
361 
362 	/**
363 	 * Calling this function signals to the toolbar that the
364 	 * overflow menu item for @tool_item has changed. If the
365 	 * overflow menu is visible when this function it called,
366 	 * the menu will be rebuilt.
367 	 *
368 	 * The function must be called when the tool item changes what it
369 	 * will do in response to the #GtkToolItem::create-menu-proxy signal.
370 	 *
371 	 * Since: 2.6
372 	 */
373 	public void rebuildMenu()
374 	{
375 		gtk_tool_item_rebuild_menu(gtkToolItem);
376 	}
377 
378 	/**
379 	 * Returns the #GtkMenuItem that was last set by
380 	 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
381 	 * that is going to appear in the overflow menu.
382 	 *
383 	 * Return: The #GtkMenuItem that is going to appear in the
384 	 *     overflow menu for @tool_item.
385 	 *
386 	 * Since: 2.4
387 	 */
388 	public Widget retrieveProxyMenuItem()
389 	{
390 		auto p = gtk_tool_item_retrieve_proxy_menu_item(gtkToolItem);
391 		
392 		if(p is null)
393 		{
394 			return null;
395 		}
396 		
397 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
398 	}
399 
400 	/**
401 	 * Sets whether @tool_item is allocated extra space when there
402 	 * is more room on the toolbar then needed for the items. The
403 	 * effect is that the item gets bigger when the toolbar gets bigger
404 	 * and smaller when the toolbar gets smaller.
405 	 *
406 	 * Params:
407 	 *     expand = Whether @tool_item is allocated extra space
408 	 *
409 	 * Since: 2.4
410 	 */
411 	public void setExpand(bool expand)
412 	{
413 		gtk_tool_item_set_expand(gtkToolItem, expand);
414 	}
415 
416 	/**
417 	 * Sets whether @tool_item is to be allocated the same size as other
418 	 * homogeneous items. The effect is that all homogeneous items will have
419 	 * the same width as the widest of the items.
420 	 *
421 	 * Params:
422 	 *     homogeneous = whether @tool_item is the same size as other homogeneous items
423 	 *
424 	 * Since: 2.4
425 	 */
426 	public void setHomogeneous(bool homogeneous)
427 	{
428 		gtk_tool_item_set_homogeneous(gtkToolItem, homogeneous);
429 	}
430 
431 	/**
432 	 * Sets whether @tool_item should be considered important. The #GtkToolButton
433 	 * class uses this property to determine whether to show or hide its label
434 	 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
435 	 * only tool buttons with the “is_important” property set have labels, an
436 	 * effect known as “priority text”
437 	 *
438 	 * Params:
439 	 *     isImportant = whether the tool item should be considered important
440 	 *
441 	 * Since: 2.4
442 	 */
443 	public void setIsImportant(bool isImportant)
444 	{
445 		gtk_tool_item_set_is_important(gtkToolItem, isImportant);
446 	}
447 
448 	/**
449 	 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
450 	 * @menu_item_id is used to identify the caller of this function and
451 	 * should also be used with gtk_tool_item_get_proxy_menu_item().
452 	 *
453 	 * Params:
454 	 *     menuItemId = a string used to identify @menu_item
455 	 *     menuItem = a #GtkMenuItem to be used in the overflow menu
456 	 *
457 	 * Since: 2.4
458 	 */
459 	public void setProxyMenuItem(string menuItemId, Widget menuItem)
460 	{
461 		gtk_tool_item_set_proxy_menu_item(gtkToolItem, Str.toStringz(menuItemId), (menuItem is null) ? null : menuItem.getWidgetStruct());
462 	}
463 
464 	/**
465 	 * Sets the markup text to be displayed as tooltip on the item.
466 	 * See gtk_widget_set_tooltip_markup().
467 	 *
468 	 * Params:
469 	 *     markup = markup text to be used as tooltip for @tool_item
470 	 *
471 	 * Since: 2.12
472 	 */
473 	public override void setTooltipMarkup(string markup)
474 	{
475 		gtk_tool_item_set_tooltip_markup(gtkToolItem, Str.toStringz(markup));
476 	}
477 
478 	/**
479 	 * Sets the text to be displayed as tooltip on the item.
480 	 * See gtk_widget_set_tooltip_text().
481 	 *
482 	 * Params:
483 	 *     text = text to be used as tooltip for @tool_item
484 	 *
485 	 * Since: 2.12
486 	 */
487 	public override void setTooltipText(string text)
488 	{
489 		gtk_tool_item_set_tooltip_text(gtkToolItem, Str.toStringz(text));
490 	}
491 
492 	/**
493 	 * Sets whether @tool_item has a drag window. When %TRUE the
494 	 * toolitem can be used as a drag source through gtk_drag_source_set().
495 	 * When @tool_item has a drag window it will intercept all events,
496 	 * even those that would otherwise be sent to a child of @tool_item.
497 	 *
498 	 * Params:
499 	 *     useDragWindow = Whether @tool_item has a drag window.
500 	 *
501 	 * Since: 2.4
502 	 */
503 	public void setUseDragWindow(bool useDragWindow)
504 	{
505 		gtk_tool_item_set_use_drag_window(gtkToolItem, useDragWindow);
506 	}
507 
508 	/**
509 	 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
510 	 *
511 	 * Params:
512 	 *     visibleHorizontal = Whether @tool_item is visible when in horizontal mode
513 	 *
514 	 * Since: 2.4
515 	 */
516 	public void setVisibleHorizontal(bool visibleHorizontal)
517 	{
518 		gtk_tool_item_set_visible_horizontal(gtkToolItem, visibleHorizontal);
519 	}
520 
521 	/**
522 	 * Sets whether @tool_item is visible when the toolbar is docked
523 	 * vertically. Some tool items, such as text entries, are too wide to be
524 	 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
525 	 * @tool_item will not appear on toolbars that are docked vertically.
526 	 *
527 	 * Params:
528 	 *     visibleVertical = whether @tool_item is visible when the toolbar
529 	 *         is in vertical mode
530 	 *
531 	 * Since: 2.4
532 	 */
533 	public void setVisibleVertical(bool visibleVertical)
534 	{
535 		gtk_tool_item_set_visible_vertical(gtkToolItem, visibleVertical);
536 	}
537 
538 	/**
539 	 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
540 	 * #GtkToolbar and other #GtkToolShell implementations use this function
541 	 * to notify children, when some aspect of their configuration changes.
542 	 *
543 	 * Since: 2.14
544 	 */
545 	public void toolbarReconfigured()
546 	{
547 		gtk_tool_item_toolbar_reconfigured(gtkToolItem);
548 	}
549 
550 	int[string] connectedSignals;
551 
552 	bool delegate(ToolItem)[] onCreateMenuProxyListeners;
553 	/**
554 	 * This signal is emitted when the toolbar needs information from @tool_item
555 	 * about whether the item should appear in the toolbar overflow menu. In
556 	 * response the tool item should either
557 	 *
558 	 * - call gtk_tool_item_set_proxy_menu_item() with a %NULL
559 	 * pointer and return %TRUE to indicate that the item should not appear
560 	 * in the overflow menu
561 	 *
562 	 * - call gtk_tool_item_set_proxy_menu_item() with a new menu
563 	 * item and return %TRUE, or
564 	 *
565 	 * - return %FALSE to indicate that the signal was not handled by the item.
566 	 * This means that the item will not appear in the overflow menu unless
567 	 * a later handler installs a menu item.
568 	 *
569 	 * The toolbar may cache the result of this signal. When the tool item changes
570 	 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
571 	 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
572 	 * menu.
573 	 *
574 	 * Return: %TRUE if the signal was handled, %FALSE if not
575 	 */
576 	void addOnCreateMenuProxy(bool delegate(ToolItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
577 	{
578 		if ( "create-menu-proxy" !in connectedSignals )
579 		{
580 			Signals.connectData(
581 				this,
582 				"create-menu-proxy",
583 				cast(GCallback)&callBackCreateMenuProxy,
584 				cast(void*)this,
585 				null,
586 				connectFlags);
587 			connectedSignals["create-menu-proxy"] = 1;
588 		}
589 		onCreateMenuProxyListeners ~= dlg;
590 	}
591 	extern(C) static int callBackCreateMenuProxy(GtkToolItem* toolitemStruct, ToolItem _toolitem)
592 	{
593 		foreach ( bool delegate(ToolItem) dlg; _toolitem.onCreateMenuProxyListeners )
594 		{
595 			if ( dlg(_toolitem) )
596 			{
597 				return 1;
598 			}
599 		}
600 		
601 		return 0;
602 	}
603 
604 	void delegate(ToolItem)[] onToolbarReconfiguredListeners;
605 	/**
606 	 * This signal is emitted when some property of the toolbar that the
607 	 * item is a child of changes. For custom subclasses of #GtkToolItem,
608 	 * the default handler of this signal use the functions
609 	 * - gtk_tool_shell_get_orientation()
610 	 * - gtk_tool_shell_get_style()
611 	 * - gtk_tool_shell_get_icon_size()
612 	 * - gtk_tool_shell_get_relief_style()
613 	 * to find out what the toolbar should look like and change
614 	 * themselves accordingly.
615 	 */
616 	void addOnToolbarReconfigured(void delegate(ToolItem) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
617 	{
618 		if ( "toolbar-reconfigured" !in connectedSignals )
619 		{
620 			Signals.connectData(
621 				this,
622 				"toolbar-reconfigured",
623 				cast(GCallback)&callBackToolbarReconfigured,
624 				cast(void*)this,
625 				null,
626 				connectFlags);
627 			connectedSignals["toolbar-reconfigured"] = 1;
628 		}
629 		onToolbarReconfiguredListeners ~= dlg;
630 	}
631 	extern(C) static void callBackToolbarReconfigured(GtkToolItem* toolitemStruct, ToolItem _toolitem)
632 	{
633 		foreach ( void delegate(ToolItem) dlg; _toolitem.onToolbarReconfiguredListeners )
634 		{
635 			dlg(_toolitem);
636 		}
637 	}
638 }