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