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 gtkc.gtk; 38 public import gtkc.gtktypes; 39 private import std.algorithm; 40 41 42 /** 43 * A toolbar is created with a call to gtk_toolbar_new(). 44 * 45 * A toolbar can contain instances of a subclass of #GtkToolItem. To add 46 * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove 47 * an item from the toolbar use gtk_container_remove(). To add a button 48 * to the toolbar, add an instance of #GtkToolButton. 49 * 50 * Toolbar items can be visually grouped by adding instances of 51 * #GtkSeparatorToolItem to the toolbar. If the GtkToolbar child property 52 * “expand” is #TRUE and the property #GtkSeparatorToolItem:draw is set to 53 * #FALSE, the effect is to force all following items to the end of the toolbar. 54 * 55 * Creating a context menu for the toolbar can be done by connecting to 56 * the #GtkToolbar::popup-context-menu signal. 57 * 58 * # CSS nodes 59 * 60 * GtkToolbar has a single CSS node with name toolbar. 61 */ 62 public class Toolbar : Container, OrientableIF, ToolShellIF 63 { 64 /** the main Gtk struct */ 65 protected GtkToolbar* gtkToolbar; 66 67 /** Get the main Gtk struct */ 68 public GtkToolbar* getToolbarStruct(bool transferOwnership = false) 69 { 70 if (transferOwnership) 71 ownedRef = false; 72 return gtkToolbar; 73 } 74 75 /** the main Gtk struct as a void* */ 76 protected override void* getStruct() 77 { 78 return cast(void*)gtkToolbar; 79 } 80 81 protected override void setStruct(GObject* obj) 82 { 83 gtkToolbar = cast(GtkToolbar*)obj; 84 super.setStruct(obj); 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 282 * @toolbar doesn’t have room for all items on it. If %TRUE, 283 * items that there are not room are available through an 284 * overflow menu. 285 * 286 * Params: 287 * showArrow = Whether to show an overflow menu 288 * 289 * Since: 2.4 290 */ 291 public void setShowArrow(bool showArrow) 292 { 293 gtk_toolbar_set_show_arrow(gtkToolbar, showArrow); 294 } 295 296 /** 297 * Alters the view of @toolbar to display either icons only, text only, or both. 298 * 299 * Params: 300 * style = the new style for @toolbar. 301 */ 302 public void setStyle(GtkToolbarStyle style) 303 { 304 gtk_toolbar_set_style(gtkToolbar, style); 305 } 306 307 /** 308 * Unsets toolbar icon size set with gtk_toolbar_set_icon_size(), so that 309 * user preferences will be used to determine the icon size. 310 */ 311 public void unsetIconSize() 312 { 313 gtk_toolbar_unset_icon_size(gtkToolbar); 314 } 315 316 /** 317 * Unsets a toolbar style set with gtk_toolbar_set_style(), so that 318 * user preferences will be used to determine the toolbar style. 319 */ 320 public void unsetStyle() 321 { 322 gtk_toolbar_unset_style(gtkToolbar); 323 } 324 325 protected class OnFocusHomeOrEndDelegateWrapper 326 { 327 bool delegate(bool, Toolbar) dlg; 328 gulong handlerId; 329 330 this(bool delegate(bool, Toolbar) dlg) 331 { 332 this.dlg = dlg; 333 onFocusHomeOrEndListeners ~= this; 334 } 335 336 void remove(OnFocusHomeOrEndDelegateWrapper source) 337 { 338 foreach(index, wrapper; onFocusHomeOrEndListeners) 339 { 340 if (wrapper.handlerId == source.handlerId) 341 { 342 onFocusHomeOrEndListeners[index] = null; 343 onFocusHomeOrEndListeners = std.algorithm.remove(onFocusHomeOrEndListeners, index); 344 break; 345 } 346 } 347 } 348 } 349 OnFocusHomeOrEndDelegateWrapper[] onFocusHomeOrEndListeners; 350 351 /** 352 * A keybinding signal used internally by GTK+. This signal can't 353 * be used in application code 354 * 355 * Params: 356 * focusHome = %TRUE if the first item should be focused 357 * 358 * Returns: %TRUE if the signal was handled, %FALSE if not 359 */ 360 gulong addOnFocusHomeOrEnd(bool delegate(bool, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 361 { 362 auto wrapper = new OnFocusHomeOrEndDelegateWrapper(dlg); 363 wrapper.handlerId = Signals.connectData( 364 this, 365 "focus-home-or-end", 366 cast(GCallback)&callBackFocusHomeOrEnd, 367 cast(void*)wrapper, 368 cast(GClosureNotify)&callBackFocusHomeOrEndDestroy, 369 connectFlags); 370 return wrapper.handlerId; 371 } 372 373 extern(C) static int callBackFocusHomeOrEnd(GtkToolbar* toolbarStruct, bool focusHome, OnFocusHomeOrEndDelegateWrapper wrapper) 374 { 375 return wrapper.dlg(focusHome, wrapper.outer); 376 } 377 378 extern(C) static void callBackFocusHomeOrEndDestroy(OnFocusHomeOrEndDelegateWrapper wrapper, GClosure* closure) 379 { 380 wrapper.remove(wrapper); 381 } 382 383 protected class OnOrientationChangedDelegateWrapper 384 { 385 void delegate(GtkOrientation, Toolbar) dlg; 386 gulong handlerId; 387 388 this(void delegate(GtkOrientation, Toolbar) dlg) 389 { 390 this.dlg = dlg; 391 onOrientationChangedListeners ~= this; 392 } 393 394 void remove(OnOrientationChangedDelegateWrapper source) 395 { 396 foreach(index, wrapper; onOrientationChangedListeners) 397 { 398 if (wrapper.handlerId == source.handlerId) 399 { 400 onOrientationChangedListeners[index] = null; 401 onOrientationChangedListeners = std.algorithm.remove(onOrientationChangedListeners, index); 402 break; 403 } 404 } 405 } 406 } 407 OnOrientationChangedDelegateWrapper[] onOrientationChangedListeners; 408 409 /** 410 * Emitted when the orientation of the toolbar changes. 411 * 412 * Params: 413 * orientation = the new #GtkOrientation of the toolbar 414 */ 415 gulong addOnOrientationChanged(void delegate(GtkOrientation, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 416 { 417 auto wrapper = new OnOrientationChangedDelegateWrapper(dlg); 418 wrapper.handlerId = Signals.connectData( 419 this, 420 "orientation-changed", 421 cast(GCallback)&callBackOrientationChanged, 422 cast(void*)wrapper, 423 cast(GClosureNotify)&callBackOrientationChangedDestroy, 424 connectFlags); 425 return wrapper.handlerId; 426 } 427 428 extern(C) static void callBackOrientationChanged(GtkToolbar* toolbarStruct, GtkOrientation orientation, OnOrientationChangedDelegateWrapper wrapper) 429 { 430 wrapper.dlg(orientation, wrapper.outer); 431 } 432 433 extern(C) static void callBackOrientationChangedDestroy(OnOrientationChangedDelegateWrapper wrapper, GClosure* closure) 434 { 435 wrapper.remove(wrapper); 436 } 437 438 protected class OnPopupContextMenuDelegateWrapper 439 { 440 bool delegate(int, int, int, Toolbar) dlg; 441 gulong handlerId; 442 443 this(bool delegate(int, int, int, Toolbar) dlg) 444 { 445 this.dlg = dlg; 446 onPopupContextMenuListeners ~= this; 447 } 448 449 void remove(OnPopupContextMenuDelegateWrapper source) 450 { 451 foreach(index, wrapper; onPopupContextMenuListeners) 452 { 453 if (wrapper.handlerId == source.handlerId) 454 { 455 onPopupContextMenuListeners[index] = null; 456 onPopupContextMenuListeners = std.algorithm.remove(onPopupContextMenuListeners, index); 457 break; 458 } 459 } 460 } 461 } 462 OnPopupContextMenuDelegateWrapper[] onPopupContextMenuListeners; 463 464 /** 465 * Emitted when the user right-clicks the toolbar or uses the 466 * keybinding to display a popup menu. 467 * 468 * Application developers should handle this signal if they want 469 * to display a context menu on the toolbar. The context-menu should 470 * appear at the coordinates given by @x and @y. The mouse button 471 * number is given by the @button parameter. If the menu was popped 472 * up using the keybaord, @button is -1. 473 * 474 * Params: 475 * x = the x coordinate of the point where the menu should appear 476 * y = the y coordinate of the point where the menu should appear 477 * button = the mouse button the user pressed, or -1 478 * 479 * Returns: return %TRUE if the signal was handled, %FALSE if not 480 */ 481 gulong addOnPopupContextMenu(bool delegate(int, int, int, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 482 { 483 auto wrapper = new OnPopupContextMenuDelegateWrapper(dlg); 484 wrapper.handlerId = Signals.connectData( 485 this, 486 "popup-context-menu", 487 cast(GCallback)&callBackPopupContextMenu, 488 cast(void*)wrapper, 489 cast(GClosureNotify)&callBackPopupContextMenuDestroy, 490 connectFlags); 491 return wrapper.handlerId; 492 } 493 494 extern(C) static int callBackPopupContextMenu(GtkToolbar* toolbarStruct, int x, int y, int button, OnPopupContextMenuDelegateWrapper wrapper) 495 { 496 return wrapper.dlg(x, y, button, wrapper.outer); 497 } 498 499 extern(C) static void callBackPopupContextMenuDestroy(OnPopupContextMenuDelegateWrapper wrapper, GClosure* closure) 500 { 501 wrapper.remove(wrapper); 502 } 503 504 protected class OnStyleChangedDelegateWrapper 505 { 506 void delegate(GtkToolbarStyle, Toolbar) dlg; 507 gulong handlerId; 508 509 this(void delegate(GtkToolbarStyle, Toolbar) dlg) 510 { 511 this.dlg = dlg; 512 onStyleChangedListeners ~= this; 513 } 514 515 void remove(OnStyleChangedDelegateWrapper source) 516 { 517 foreach(index, wrapper; onStyleChangedListeners) 518 { 519 if (wrapper.handlerId == source.handlerId) 520 { 521 onStyleChangedListeners[index] = null; 522 onStyleChangedListeners = std.algorithm.remove(onStyleChangedListeners, index); 523 break; 524 } 525 } 526 } 527 } 528 OnStyleChangedDelegateWrapper[] onStyleChangedListeners; 529 530 /** 531 * Emitted when the style of the toolbar changes. 532 * 533 * Params: 534 * style = the new #GtkToolbarStyle of the toolbar 535 */ 536 gulong addOnStyleChanged(void delegate(GtkToolbarStyle, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 537 { 538 auto wrapper = new OnStyleChangedDelegateWrapper(dlg); 539 wrapper.handlerId = Signals.connectData( 540 this, 541 "style-changed", 542 cast(GCallback)&callBackStyleChanged, 543 cast(void*)wrapper, 544 cast(GClosureNotify)&callBackStyleChangedDestroy, 545 connectFlags); 546 return wrapper.handlerId; 547 } 548 549 extern(C) static void callBackStyleChanged(GtkToolbar* toolbarStruct, GtkToolbarStyle style, OnStyleChangedDelegateWrapper wrapper) 550 { 551 wrapper.dlg(style, wrapper.outer); 552 } 553 554 extern(C) static void callBackStyleChangedDestroy(OnStyleChangedDelegateWrapper wrapper, GClosure* closure) 555 { 556 wrapper.remove(wrapper); 557 } 558 }