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