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