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