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 public import gtkc.gdktypes; 38 private import gtkc.gtk; 39 public import gtkc.gtktypes; 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 * Return: 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 * Return: 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 * Return: 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 * Return: 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 * Return: 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 * Return: %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 * Return: 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 int[string] connectedSignals; 324 325 bool delegate(bool, Toolbar)[] onFocusHomeOrEndListeners; 326 /** 327 * A keybinding signal used internally by GTK+. This signal can't 328 * be used in application code 329 * 330 * Params: 331 * focusHome = %TRUE if the first item should be focused 332 * 333 * Return: %TRUE if the signal was handled, %FALSE if not 334 */ 335 void addOnFocusHomeOrEnd(bool delegate(bool, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 336 { 337 if ( "focus-home-or-end" !in connectedSignals ) 338 { 339 Signals.connectData( 340 this, 341 "focus-home-or-end", 342 cast(GCallback)&callBackFocusHomeOrEnd, 343 cast(void*)this, 344 null, 345 connectFlags); 346 connectedSignals["focus-home-or-end"] = 1; 347 } 348 onFocusHomeOrEndListeners ~= dlg; 349 } 350 extern(C) static int callBackFocusHomeOrEnd(GtkToolbar* toolbarStruct, bool focusHome, Toolbar _toolbar) 351 { 352 foreach ( bool delegate(bool, Toolbar) dlg; _toolbar.onFocusHomeOrEndListeners ) 353 { 354 if ( dlg(focusHome, _toolbar) ) 355 { 356 return 1; 357 } 358 } 359 360 return 0; 361 } 362 363 void delegate(GtkOrientation, Toolbar)[] onOrientationChangedListeners; 364 /** 365 * Emitted when the orientation of the toolbar changes. 366 * 367 * Params: 368 * orientation = the new #GtkOrientation of the toolbar 369 */ 370 void addOnOrientationChanged(void delegate(GtkOrientation, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 371 { 372 if ( "orientation-changed" !in connectedSignals ) 373 { 374 Signals.connectData( 375 this, 376 "orientation-changed", 377 cast(GCallback)&callBackOrientationChanged, 378 cast(void*)this, 379 null, 380 connectFlags); 381 connectedSignals["orientation-changed"] = 1; 382 } 383 onOrientationChangedListeners ~= dlg; 384 } 385 extern(C) static void callBackOrientationChanged(GtkToolbar* toolbarStruct, GtkOrientation orientation, Toolbar _toolbar) 386 { 387 foreach ( void delegate(GtkOrientation, Toolbar) dlg; _toolbar.onOrientationChangedListeners ) 388 { 389 dlg(orientation, _toolbar); 390 } 391 } 392 393 bool delegate(int, int, int, Toolbar)[] onPopupContextMenuListeners; 394 /** 395 * Emitted when the user right-clicks the toolbar or uses the 396 * keybinding to display a popup menu. 397 * 398 * Application developers should handle this signal if they want 399 * to display a context menu on the toolbar. The context-menu should 400 * appear at the coordinates given by @x and @y. The mouse button 401 * number is given by the @button parameter. If the menu was popped 402 * up using the keybaord, @button is -1. 403 * 404 * Params: 405 * x = the x coordinate of the point where the menu should appear 406 * y = the y coordinate of the point where the menu should appear 407 * button = the mouse button the user pressed, or -1 408 * 409 * Return: return %TRUE if the signal was handled, %FALSE if not 410 */ 411 void addOnPopupContextMenu(bool delegate(int, int, int, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 412 { 413 if ( "popup-context-menu" !in connectedSignals ) 414 { 415 Signals.connectData( 416 this, 417 "popup-context-menu", 418 cast(GCallback)&callBackPopupContextMenu, 419 cast(void*)this, 420 null, 421 connectFlags); 422 connectedSignals["popup-context-menu"] = 1; 423 } 424 onPopupContextMenuListeners ~= dlg; 425 } 426 extern(C) static int callBackPopupContextMenu(GtkToolbar* toolbarStruct, int x, int y, int button, Toolbar _toolbar) 427 { 428 foreach ( bool delegate(int, int, int, Toolbar) dlg; _toolbar.onPopupContextMenuListeners ) 429 { 430 if ( dlg(x, y, button, _toolbar) ) 431 { 432 return 1; 433 } 434 } 435 436 return 0; 437 } 438 439 void delegate(GtkToolbarStyle, Toolbar)[] onStyleChangedListeners; 440 /** 441 * Emitted when the style of the toolbar changes. 442 * 443 * Params: 444 * style = the new #GtkToolbarStyle of the toolbar 445 */ 446 void addOnStyleChanged(void delegate(GtkToolbarStyle, Toolbar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 447 { 448 if ( "style-changed" !in connectedSignals ) 449 { 450 Signals.connectData( 451 this, 452 "style-changed", 453 cast(GCallback)&callBackStyleChanged, 454 cast(void*)this, 455 null, 456 connectFlags); 457 connectedSignals["style-changed"] = 1; 458 } 459 onStyleChangedListeners ~= dlg; 460 } 461 extern(C) static void callBackStyleChanged(GtkToolbar* toolbarStruct, GtkToolbarStyle style, Toolbar _toolbar) 462 { 463 foreach ( void delegate(GtkToolbarStyle, Toolbar) dlg; _toolbar.onStyleChangedListeners ) 464 { 465 dlg(style, _toolbar); 466 } 467 } 468 }