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