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