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.Toolbar; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gtk.Container; 31 private import gtk.OrientableIF; 32 private import gtk.OrientableT; 33 private import gtk.ToolItem; 34 private import gtk.ToolShellIF; 35 private import gtk.ToolShellT; 36 private import gtk.Widget; 37 private import gtk.c.functions; 38 public import gtk.c.types; 39 public import gtkc.gtktypes; 40 private import std.algorithm; 41 42 43 /** 44 * A toolbar is created with a call to gtk_toolbar_new(). 45 * 46 * A toolbar can contain instances of a subclass of #GtkToolItem. To add 47 * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove 48 * an item from the toolbar use gtk_container_remove(). To add a button 49 * to the toolbar, add an instance of #GtkToolButton. 50 * 51 * Toolbar items can be visually grouped by adding instances of 52 * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property 53 * “expand” is #TRUE and the property #GtkSeparatorToolItem:draw is set to 54 * #FALSE, the effect is to force all following items to the end of the toolbar. 55 * 56 * By default, a toolbar can be shrunk, upon which it will add an arrow button 57 * to show an overflow menu offering access to any #GtkToolItem child that has 58 * a proxy menu item. To disable this and request enough size for all children, 59 * call gtk_toolbar_set_show_arrow() to set #GtkToolbar:show-arrow to %FALSE. 60 * 61 * Creating a context menu for the toolbar can be done by connecting to 62 * the #GtkToolbar::popup-context-menu signal. 63 * 64 * # CSS nodes 65 * 66 * GtkToolbar has a single CSS node with name toolbar. 67 */ 68 public class Toolbar : Container, OrientableIF, ToolShellIF 69 { 70 /** the main Gtk struct */ 71 protected GtkToolbar* gtkToolbar; 72 73 /** Get the main Gtk struct */ 74 public GtkToolbar* getToolbarStruct(bool transferOwnership = false) 75 { 76 if (transferOwnership) 77 ownedRef = false; 78 return gtkToolbar; 79 } 80 81 /** the main Gtk struct as a void* */ 82 protected override void* getStruct() 83 { 84 return cast(void*)gtkToolbar; 85 } 86 87 /** 88 * Sets our main struct and passes it to the parent class. 89 */ 90 public this (GtkToolbar* gtkToolbar, bool ownedRef = false) 91 { 92 this.gtkToolbar = gtkToolbar; 93 super(cast(GtkContainer*)gtkToolbar, ownedRef); 94 } 95 96 // add the Orientable capabilities 97 mixin OrientableT!(GtkToolbar); 98 99 // add the ToolShell capabilities 100 mixin ToolShellT!(GtkToolbar); 101 102 /** 103 * Insert a GtkToolItem into the toolbar at position pos. 104 * If pos is 0 the item is prepended to the start of the toolbar. If pos is negative, the item is appended to the end of the toolbar. 105 * Since 2.4 106 * Params: 107 * toolItem = a GtkToolItem 108 * pos = the position of the new item 109 */ 110 public void insert(ToolItem toolItem, int pos=-1) 111 { 112 gtk_toolbar_insert(gtkToolbar, toolItem.getToolItemStruct(), pos); 113 } 114 115 /** 116 */ 117 118 /** */ 119 public static GType getType() 120 { 121 return gtk_toolbar_get_type(); 122 } 123 124 /** 125 * Creates a new toolbar. 126 * 127 * Returns: the newly-created toolbar. 128 * 129 * Throws: ConstructionException GTK+ fails to create the object. 130 */ 131 public this() 132 { 133 auto p = gtk_toolbar_new(); 134 135 if(p is null) 136 { 137 throw new ConstructionException("null returned by new"); 138 } 139 140 this(cast(GtkToolbar*) p); 141 } 142 143 /** 144 * Returns the position corresponding to the indicated point on 145 * @toolbar. This is useful when dragging items to the toolbar: 146 * this function returns the position a new item should be 147 * inserted. 148 * 149 * @x and @y are in @toolbar coordinates. 150 * 151 * Params: 152 * x = x coordinate of a point on the toolbar 153 * y = y coordinate of a point on the toolbar 154 * 155 * Returns: The position corresponding to the point (@x, @y) on the toolbar. 156 * 157 * Since: 2.4 158 */ 159 public int getDropIndex(int x, int y) 160 { 161 return gtk_toolbar_get_drop_index(gtkToolbar, x, y); 162 } 163 164 /** 165 * Returns the position of @item on the toolbar, starting from 0. 166 * It is an error if @item is not a child of the toolbar. 167 * 168 * Params: 169 * item = a #GtkToolItem that is a child of @toolbar 170 * 171 * Returns: the position of item on the toolbar. 172 * 173 * Since: 2.4 174 */ 175 public int getItemIndex(ToolItem item) 176 { 177 return gtk_toolbar_get_item_index(gtkToolbar, (item is null) ? null : item.getToolItemStruct()); 178 } 179 180 /** 181 * Returns the number of items on the toolbar. 182 * 183 * Returns: the number of items on the toolbar 184 * 185 * Since: 2.4 186 */ 187 public int getNItems() 188 { 189 return gtk_toolbar_get_n_items(gtkToolbar); 190 } 191 192 /** 193 * Returns the @n'th item on @toolbar, or %NULL if the 194 * toolbar does not contain an @n'th item. 195 * 196 * Params: 197 * n = A position on the toolbar 198 * 199 * Returns: The @n'th #GtkToolItem on @toolbar, 200 * or %NULL if there isn’t an @n'th item. 201 * 202 * Since: 2.4 203 */ 204 public ToolItem getNthItem(int n) 205 { 206 auto p = gtk_toolbar_get_nth_item(gtkToolbar, n); 207 208 if(p is null) 209 { 210 return null; 211 } 212 213 return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p); 214 } 215 216 /** 217 * Returns whether the toolbar has an overflow menu. 218 * See gtk_toolbar_set_show_arrow(). 219 * 220 * Returns: %TRUE if the toolbar has an overflow menu. 221 * 222 * Since: 2.4 223 */ 224 public bool getShowArrow() 225 { 226 return gtk_toolbar_get_show_arrow(gtkToolbar) != 0; 227 } 228 229 /** 230 * Retrieves whether the toolbar has text, icons, or both . See 231 * gtk_toolbar_set_style(). 232 * 233 * Returns: the current style of @toolbar 234 */ 235 public GtkToolbarStyle getToolbarStyle() 236 { 237 return gtk_toolbar_get_style(gtkToolbar); 238 } 239 240 /** 241 * Highlights @toolbar to give an idea of what it would look like 242 * if @item was added to @toolbar at the position indicated by @index_. 243 * If @item is %NULL, highlighting is turned off. In that case @index_ 244 * is ignored. 245 * 246 * The @tool_item passed to this function must not be part of any widget 247 * hierarchy. When an item is set as drop highlight item it can not 248 * added to any widget hierarchy or used as highlight item for another 249 * toolbar. 250 * 251 * Params: 252 * toolItem = a #GtkToolItem, or %NULL to turn of highlighting 253 * index = a position on @toolbar 254 * 255 * Since: 2.4 256 */ 257 public void setDropHighlightItem(ToolItem toolItem, int index) 258 { 259 gtk_toolbar_set_drop_highlight_item(gtkToolbar, (toolItem is null) ? null : toolItem.getToolItemStruct(), index); 260 } 261 262 /** 263 * This function sets the size of stock icons in the toolbar. You 264 * can call it both before you add the icons and after they’ve been 265 * added. The size you set will override user preferences for the default 266 * icon size. 267 * 268 * This should only be used for special-purpose toolbars, normal 269 * application toolbars should respect the user preferences for the 270 * size of icons. 271 * 272 * Params: 273 * iconSize = The #GtkIconSize that stock icons in the toolbar shall have. 274 */ 275 public void setIconSize(GtkIconSize iconSize) 276 { 277 gtk_toolbar_set_icon_size(gtkToolbar, iconSize); 278 } 279 280 /** 281 * Sets whether to show an overflow menu when @toolbar isn’t allocated enough 282 * size to show all of its items. If %TRUE, items which can’t fit in @toolbar, 283 * and which have a proxy menu item set by gtk_tool_item_set_proxy_menu_item() 284 * or #GtkToolItem::create-menu-proxy, will be available in an overflow menu, 285 * which can be opened by an added arrow button. If %FALSE, @toolbar will 286 * request enough size to fit all of its child items without any overflow. 287 * 288 * Params: 289 * showArrow = Whether to show an overflow menu 290 * 291 * Since: 2.4 292 */ 293 public void setShowArrow(bool showArrow) 294 { 295 gtk_toolbar_set_show_arrow(gtkToolbar, showArrow); 296 } 297 298 /** 299 * Alters the view of @toolbar to display either icons only, text only, or both. 300 * 301 * Params: 302 * style = the new style for @toolbar. 303 */ 304 public void setStyle(GtkToolbarStyle style) 305 { 306 gtk_toolbar_set_style(gtkToolbar, style); 307 } 308 309 /** 310 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that 311 * user preferences will be used to determine the icon size. 312 */ 313 public void unsetIconSize() 314 { 315 gtk_toolbar_unset_icon_size(gtkToolbar); 316 } 317 318 /** 319 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that 320 * user preferences will be used to determine the toolbar style. 321 */ 322 public void unsetStyle() 323 { 324 gtk_toolbar_unset_style(gtkToolbar); 325 } 326 327 protected class OnFocusHomeOrEndDelegateWrapper 328 { 329 bool delegate(bool, Toolbar) dlg; 330 gulong handlerId; 331 332 this(bool delegate(bool, Toolbar) dlg) 333 { 334 this.dlg = dlg; 335 onFocusHomeOrEndListeners ~= this; 336 } 337 338 void remove(OnFocusHomeOrEndDelegateWrapper source) 339 { 340 foreach(index, wrapper; onFocusHomeOrEndListeners) 341 { 342 if (wrapper.handlerId == source.handlerId) 343 { 344 onFocusHomeOrEndListeners[index] = null; 345 onFocusHomeOrEndListeners = std.algorithm.remove(onFocusHomeOrEndListeners, index); 346 break; 347 } 348 } 349 } 350 } 351 OnFocusHomeOrEndDelegateWrapper[] onFocusHomeOrEndListeners; 352 353 /** 354 * A keybinding signal used internally by GTK+. This signal can't 355 * be used in application code 356 * 357 * Params: 358 * focusHome = %TRUE if the first item should be focused 359 * 360 * Returns: %TRUE if the signal was handled, %FALSE if not 361 */ 362 gulong addOnFocusHomeOrEnd(bool delegate(bool, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 363 { 364 auto wrapper = new OnFocusHomeOrEndDelegateWrapper(dlg); 365 wrapper.handlerId = Signals.connectData( 366 this, 367 "focus-home-or-end", 368 cast(GCallback)&callBackFocusHomeOrEnd, 369 cast(void*)wrapper, 370 cast(GClosureNotify)&callBackFocusHomeOrEndDestroy, 371 connectFlags); 372 return wrapper.handlerId; 373 } 374 375 extern(C) static int callBackFocusHomeOrEnd(GtkToolbar* toolbarStruct, bool focusHome, OnFocusHomeOrEndDelegateWrapper wrapper) 376 { 377 return wrapper.dlg(focusHome, wrapper.outer); 378 } 379 380 extern(C) static void callBackFocusHomeOrEndDestroy(OnFocusHomeOrEndDelegateWrapper wrapper, GClosure* closure) 381 { 382 wrapper.remove(wrapper); 383 } 384 385 protected class OnOrientationChangedDelegateWrapper 386 { 387 void delegate(GtkOrientation, Toolbar) dlg; 388 gulong handlerId; 389 390 this(void delegate(GtkOrientation, Toolbar) dlg) 391 { 392 this.dlg = dlg; 393 onOrientationChangedListeners ~= this; 394 } 395 396 void remove(OnOrientationChangedDelegateWrapper source) 397 { 398 foreach(index, wrapper; onOrientationChangedListeners) 399 { 400 if (wrapper.handlerId == source.handlerId) 401 { 402 onOrientationChangedListeners[index] = null; 403 onOrientationChangedListeners = std.algorithm.remove(onOrientationChangedListeners, index); 404 break; 405 } 406 } 407 } 408 } 409 OnOrientationChangedDelegateWrapper[] onOrientationChangedListeners; 410 411 /** 412 * Emitted when the orientation of the toolbar changes. 413 * 414 * Params: 415 * orientation = the new #GtkOrientation of the toolbar 416 */ 417 gulong addOnOrientationChanged(void delegate(GtkOrientation, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 418 { 419 auto wrapper = new OnOrientationChangedDelegateWrapper(dlg); 420 wrapper.handlerId = Signals.connectData( 421 this, 422 "orientation-changed", 423 cast(GCallback)&callBackOrientationChanged, 424 cast(void*)wrapper, 425 cast(GClosureNotify)&callBackOrientationChangedDestroy, 426 connectFlags); 427 return wrapper.handlerId; 428 } 429 430 extern(C) static void callBackOrientationChanged(GtkToolbar* toolbarStruct, GtkOrientation orientation, OnOrientationChangedDelegateWrapper wrapper) 431 { 432 wrapper.dlg(orientation, wrapper.outer); 433 } 434 435 extern(C) static void callBackOrientationChangedDestroy(OnOrientationChangedDelegateWrapper wrapper, GClosure* closure) 436 { 437 wrapper.remove(wrapper); 438 } 439 440 protected class OnPopupContextMenuDelegateWrapper 441 { 442 bool delegate(int, int, int, Toolbar) dlg; 443 gulong handlerId; 444 445 this(bool delegate(int, int, int, Toolbar) dlg) 446 { 447 this.dlg = dlg; 448 onPopupContextMenuListeners ~= this; 449 } 450 451 void remove(OnPopupContextMenuDelegateWrapper source) 452 { 453 foreach(index, wrapper; onPopupContextMenuListeners) 454 { 455 if (wrapper.handlerId == source.handlerId) 456 { 457 onPopupContextMenuListeners[index] = null; 458 onPopupContextMenuListeners = std.algorithm.remove(onPopupContextMenuListeners, index); 459 break; 460 } 461 } 462 } 463 } 464 OnPopupContextMenuDelegateWrapper[] onPopupContextMenuListeners; 465 466 /** 467 * Emitted when the user right-clicks the toolbar or uses the 468 * keybinding to display a popup menu. 469 * 470 * Application developers should handle this signal if they want 471 * to display a context menu on the toolbar. The context-menu should 472 * appear at the coordinates given by @x and @y. The mouse button 473 * number is given by the @button parameter. If the menu was popped 474 * up using the keybaord, @button is -1. 475 * 476 * Params: 477 * x = the x coordinate of the point where the menu should appear 478 * y = the y coordinate of the point where the menu should appear 479 * button = the mouse button the user pressed, or -1 480 * 481 * Returns: return %TRUE if the signal was handled, %FALSE if not 482 */ 483 gulong addOnPopupContextMenu(bool delegate(int, int, int, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 484 { 485 auto wrapper = new OnPopupContextMenuDelegateWrapper(dlg); 486 wrapper.handlerId = Signals.connectData( 487 this, 488 "popup-context-menu", 489 cast(GCallback)&callBackPopupContextMenu, 490 cast(void*)wrapper, 491 cast(GClosureNotify)&callBackPopupContextMenuDestroy, 492 connectFlags); 493 return wrapper.handlerId; 494 } 495 496 extern(C) static int callBackPopupContextMenu(GtkToolbar* toolbarStruct, int x, int y, int button, OnPopupContextMenuDelegateWrapper wrapper) 497 { 498 return wrapper.dlg(x, y, button, wrapper.outer); 499 } 500 501 extern(C) static void callBackPopupContextMenuDestroy(OnPopupContextMenuDelegateWrapper wrapper, GClosure* closure) 502 { 503 wrapper.remove(wrapper); 504 } 505 506 protected class OnStyleChangedDelegateWrapper 507 { 508 void delegate(GtkToolbarStyle, Toolbar) dlg; 509 gulong handlerId; 510 511 this(void delegate(GtkToolbarStyle, Toolbar) dlg) 512 { 513 this.dlg = dlg; 514 onStyleChangedListeners ~= this; 515 } 516 517 void remove(OnStyleChangedDelegateWrapper source) 518 { 519 foreach(index, wrapper; onStyleChangedListeners) 520 { 521 if (wrapper.handlerId == source.handlerId) 522 { 523 onStyleChangedListeners[index] = null; 524 onStyleChangedListeners = std.algorithm.remove(onStyleChangedListeners, index); 525 break; 526 } 527 } 528 } 529 } 530 OnStyleChangedDelegateWrapper[] onStyleChangedListeners; 531 532 /** 533 * Emitted when the style of the toolbar changes. 534 * 535 * Params: 536 * style = the new #GtkToolbarStyle of the toolbar 537 */ 538 gulong addOnStyleChanged(void delegate(GtkToolbarStyle, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 539 { 540 auto wrapper = new OnStyleChangedDelegateWrapper(dlg); 541 wrapper.handlerId = Signals.connectData( 542 this, 543 "style-changed", 544 cast(GCallback)&callBackStyleChanged, 545 cast(void*)wrapper, 546 cast(GClosureNotify)&callBackStyleChangedDestroy, 547 connectFlags); 548 return wrapper.handlerId; 549 } 550 551 extern(C) static void callBackStyleChanged(GtkToolbar* toolbarStruct, GtkToolbarStyle style, OnStyleChangedDelegateWrapper wrapper) 552 { 553 wrapper.dlg(style, wrapper.outer); 554 } 555 556 extern(C) static void callBackStyleChangedDestroy(OnStyleChangedDelegateWrapper wrapper, GClosure* closure) 557 { 558 wrapper.remove(wrapper); 559 } 560 }