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.ToolPalette; 26 27 private import glib.ConstructionException; 28 private import gobject.ObjectG; 29 private import gtk.Container; 30 private import gtk.OrientableIF; 31 private import gtk.OrientableT; 32 private import gtk.ScrollableIF; 33 private import gtk.ScrollableT; 34 private import gtk.SelectionData; 35 private import gtk.TargetEntry; 36 private import gtk.ToolItem; 37 private import gtk.ToolItemGroup; 38 private import gtk.Widget; 39 private import gtk.c.functions; 40 public import gtk.c.types; 41 public import gtkc.gtktypes; 42 43 44 /** 45 * A #GtkToolPalette allows you to add #GtkToolItems to a palette-like 46 * container with different categories and drag and drop support. 47 * 48 * A #GtkToolPalette is created with a call to gtk_tool_palette_new(). 49 * 50 * #GtkToolItems cannot be added directly to a #GtkToolPalette - 51 * instead they are added to a #GtkToolItemGroup which can than be added 52 * to a #GtkToolPalette. To add a #GtkToolItemGroup to a #GtkToolPalette, 53 * use gtk_container_add(). 54 * 55 * |[<!-- language="C" --> 56 * GtkWidget *palette, *group; 57 * GtkToolItem *item; 58 * 59 * palette = gtk_tool_palette_new (); 60 * group = gtk_tool_item_group_new (_("Test Category")); 61 * gtk_container_add (GTK_CONTAINER (palette), group); 62 * 63 * item = gtk_tool_button_new_new (NULL, _("_Open")); 64 * gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open"); 65 * gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1); 66 * ]| 67 * 68 * The easiest way to use drag and drop with #GtkToolPalette is to call 69 * gtk_tool_palette_add_drag_dest() with the desired drag source @palette 70 * and the desired drag target @widget. Then gtk_tool_palette_get_drag_item() 71 * can be used to get the dragged item in the #GtkWidget::drag-data-received 72 * signal handler of the drag target. 73 * 74 * |[<!-- language="C" --> 75 * static void 76 * passive_canvas_drag_data_received (GtkWidget *widget, 77 * GdkDragContext *context, 78 * gint x, 79 * gint y, 80 * GtkSelectionData *selection, 81 * guint info, 82 * guint time, 83 * gpointer data) 84 * { 85 * GtkWidget *palette; 86 * GtkWidget *item; 87 * 88 * // Get the dragged item 89 * palette = gtk_widget_get_ancestor (gtk_drag_get_source_widget (context), 90 * GTK_TYPE_TOOL_PALETTE); 91 * if (palette != NULL) 92 * item = gtk_tool_palette_get_drag_item (GTK_TOOL_PALETTE (palette), 93 * selection); 94 * 95 * // Do something with item 96 * } 97 * 98 * GtkWidget *target, palette; 99 * 100 * palette = gtk_tool_palette_new (); 101 * target = gtk_drawing_area_new (); 102 * 103 * g_signal_connect (G_OBJECT (target), "drag-data-received", 104 * G_CALLBACK (passive_canvas_drag_data_received), NULL); 105 * gtk_tool_palette_add_drag_dest (GTK_TOOL_PALETTE (palette), target, 106 * GTK_DEST_DEFAULT_ALL, 107 * GTK_TOOL_PALETTE_DRAG_ITEMS, 108 * GDK_ACTION_COPY); 109 * ]| 110 * 111 * # CSS nodes 112 * 113 * GtkToolPalette has a single CSS node named toolpalette. 114 */ 115 public class ToolPalette : Container, OrientableIF, ScrollableIF 116 { 117 /** the main Gtk struct */ 118 protected GtkToolPalette* gtkToolPalette; 119 120 /** Get the main Gtk struct */ 121 public GtkToolPalette* getToolPaletteStruct(bool transferOwnership = false) 122 { 123 if (transferOwnership) 124 ownedRef = false; 125 return gtkToolPalette; 126 } 127 128 /** the main Gtk struct as a void* */ 129 protected override void* getStruct() 130 { 131 return cast(void*)gtkToolPalette; 132 } 133 134 protected override void setStruct(GObject* obj) 135 { 136 gtkToolPalette = cast(GtkToolPalette*)obj; 137 super.setStruct(obj); 138 } 139 140 /** 141 * Sets our main struct and passes it to the parent class. 142 */ 143 public this (GtkToolPalette* gtkToolPalette, bool ownedRef = false) 144 { 145 this.gtkToolPalette = gtkToolPalette; 146 super(cast(GtkContainer*)gtkToolPalette, ownedRef); 147 } 148 149 // add the Orientable capabilities 150 mixin OrientableT!(GtkToolPalette); 151 152 // add the Scrollable capabilities 153 mixin ScrollableT!(GtkToolPalette); 154 155 156 /** */ 157 public static GType getType() 158 { 159 return gtk_tool_palette_get_type(); 160 } 161 162 /** 163 * Creates a new tool palette. 164 * 165 * Returns: a new #GtkToolPalette 166 * 167 * Since: 2.20 168 * 169 * Throws: ConstructionException GTK+ fails to create the object. 170 */ 171 public this() 172 { 173 auto p = gtk_tool_palette_new(); 174 175 if(p is null) 176 { 177 throw new ConstructionException("null returned by new"); 178 } 179 180 this(cast(GtkToolPalette*) p); 181 } 182 183 /** 184 * Get the target entry for a dragged #GtkToolItemGroup. 185 * 186 * Returns: the #GtkTargetEntry for a dragged group 187 * 188 * Since: 2.20 189 */ 190 public static TargetEntry getDragTargetGroup() 191 { 192 auto p = gtk_tool_palette_get_drag_target_group(); 193 194 if(p is null) 195 { 196 return null; 197 } 198 199 return ObjectG.getDObject!(TargetEntry)(cast(GtkTargetEntry*) p); 200 } 201 202 /** 203 * Gets the target entry for a dragged #GtkToolItem. 204 * 205 * Returns: the #GtkTargetEntry for a dragged item. 206 * 207 * Since: 2.20 208 */ 209 public static TargetEntry getDragTargetItem() 210 { 211 auto p = gtk_tool_palette_get_drag_target_item(); 212 213 if(p is null) 214 { 215 return null; 216 } 217 218 return ObjectG.getDObject!(TargetEntry)(cast(GtkTargetEntry*) p); 219 } 220 221 /** 222 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source()) 223 * and sets @widget as a drag destination for drags from @palette. 224 * See gtk_drag_dest_set(). 225 * 226 * Params: 227 * widget = a #GtkWidget which should be a drag destination for @palette 228 * flags = the flags that specify what actions GTK+ should take for drops 229 * on that widget 230 * targets = the #GtkToolPaletteDragTargets which the widget 231 * should support 232 * actions = the #GdkDragActions which the widget should suppport 233 * 234 * Since: 2.20 235 */ 236 public void addDragDest(Widget widget, GtkDestDefaults flags, GtkToolPaletteDragTargets targets, GdkDragAction actions) 237 { 238 gtk_tool_palette_add_drag_dest(gtkToolPalette, (widget is null) ? null : widget.getWidgetStruct(), flags, targets, actions); 239 } 240 241 /** 242 * Get the dragged item from the selection. 243 * This could be a #GtkToolItem or a #GtkToolItemGroup. 244 * 245 * Params: 246 * selection = a #GtkSelectionData 247 * 248 * Returns: the dragged item in selection 249 * 250 * Since: 2.20 251 */ 252 public Widget getDragItem(SelectionData selection) 253 { 254 auto p = gtk_tool_palette_get_drag_item(gtkToolPalette, (selection is null) ? null : selection.getSelectionDataStruct()); 255 256 if(p is null) 257 { 258 return null; 259 } 260 261 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 262 } 263 264 /** 265 * Gets the group at position (x, y). 266 * 267 * Params: 268 * x = the x position 269 * y = the y position 270 * 271 * Returns: the #GtkToolItemGroup at position 272 * or %NULL if there is no such group 273 * 274 * Since: 2.20 275 */ 276 public ToolItemGroup getDropGroup(int x, int y) 277 { 278 auto p = gtk_tool_palette_get_drop_group(gtkToolPalette, x, y); 279 280 if(p is null) 281 { 282 return null; 283 } 284 285 return ObjectG.getDObject!(ToolItemGroup)(cast(GtkToolItemGroup*) p); 286 } 287 288 /** 289 * Gets the item at position (x, y). 290 * See gtk_tool_palette_get_drop_group(). 291 * 292 * Params: 293 * x = the x position 294 * y = the y position 295 * 296 * Returns: the #GtkToolItem at position or %NULL if there is no such item 297 * 298 * Since: 2.20 299 */ 300 public ToolItem getDropItem(int x, int y) 301 { 302 auto p = gtk_tool_palette_get_drop_item(gtkToolPalette, x, y); 303 304 if(p is null) 305 { 306 return null; 307 } 308 309 return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p); 310 } 311 312 /** 313 * Gets whether @group is exclusive or not. 314 * See gtk_tool_palette_set_exclusive(). 315 * 316 * Params: 317 * group = a #GtkToolItemGroup which is a child of palette 318 * 319 * Returns: %TRUE if @group is exclusive 320 * 321 * Since: 2.20 322 */ 323 public bool getExclusive(ToolItemGroup group) 324 { 325 return gtk_tool_palette_get_exclusive(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct()) != 0; 326 } 327 328 /** 329 * Gets whether group should be given extra space. 330 * See gtk_tool_palette_set_expand(). 331 * 332 * Params: 333 * group = a #GtkToolItemGroup which is a child of palette 334 * 335 * Returns: %TRUE if group should be given extra space, %FALSE otherwise 336 * 337 * Since: 2.20 338 */ 339 public bool getExpand(ToolItemGroup group) 340 { 341 return gtk_tool_palette_get_expand(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct()) != 0; 342 } 343 344 /** 345 * Gets the position of @group in @palette as index. 346 * See gtk_tool_palette_set_group_position(). 347 * 348 * Params: 349 * group = a #GtkToolItemGroup 350 * 351 * Returns: the index of group or -1 if @group is not a child of @palette 352 * 353 * Since: 2.20 354 */ 355 public int getGroupPosition(ToolItemGroup group) 356 { 357 return gtk_tool_palette_get_group_position(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct()); 358 } 359 360 /** 361 * Gets the size of icons in the tool palette. 362 * See gtk_tool_palette_set_icon_size(). 363 * 364 * Returns: the #GtkIconSize of icons in the tool palette 365 * 366 * Since: 2.20 367 */ 368 public GtkIconSize getIconSize() 369 { 370 return gtk_tool_palette_get_icon_size(gtkToolPalette); 371 } 372 373 /** 374 * Gets the style (icons, text or both) of items in the tool palette. 375 * 376 * Returns: the #GtkToolbarStyle of items in the tool palette. 377 * 378 * Since: 2.20 379 */ 380 public GtkToolbarStyle getToolbarStyle() 381 { 382 return gtk_tool_palette_get_style(gtkToolPalette); 383 } 384 385 /** 386 * Sets the tool palette as a drag source. 387 * Enables all groups and items in the tool palette as drag sources 388 * on button 1 and button 3 press with copy and move actions. 389 * See gtk_drag_source_set(). 390 * 391 * Params: 392 * targets = the #GtkToolPaletteDragTargets 393 * which the widget should support 394 * 395 * Since: 2.20 396 */ 397 public void setDragSource(GtkToolPaletteDragTargets targets) 398 { 399 gtk_tool_palette_set_drag_source(gtkToolPalette, targets); 400 } 401 402 /** 403 * Sets whether the group should be exclusive or not. 404 * If an exclusive group is expanded all other groups are collapsed. 405 * 406 * Params: 407 * group = a #GtkToolItemGroup which is a child of palette 408 * exclusive = whether the group should be exclusive or not 409 * 410 * Since: 2.20 411 */ 412 public void setExclusive(ToolItemGroup group, bool exclusive) 413 { 414 gtk_tool_palette_set_exclusive(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct(), exclusive); 415 } 416 417 /** 418 * Sets whether the group should be given extra space. 419 * 420 * Params: 421 * group = a #GtkToolItemGroup which is a child of palette 422 * expand = whether the group should be given extra space 423 * 424 * Since: 2.20 425 */ 426 public void setExpand(ToolItemGroup group, bool expand) 427 { 428 gtk_tool_palette_set_expand(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct(), expand); 429 } 430 431 /** 432 * Sets the position of the group as an index of the tool palette. 433 * If position is 0 the group will become the first child, if position is 434 * -1 it will become the last child. 435 * 436 * Params: 437 * group = a #GtkToolItemGroup which is a child of palette 438 * position = a new index for group 439 * 440 * Since: 2.20 441 */ 442 public void setGroupPosition(ToolItemGroup group, int position) 443 { 444 gtk_tool_palette_set_group_position(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct(), position); 445 } 446 447 /** 448 * Sets the size of icons in the tool palette. 449 * 450 * Params: 451 * iconSize = the #GtkIconSize that icons in the tool 452 * palette shall have 453 * 454 * Since: 2.20 455 */ 456 public void setIconSize(GtkIconSize iconSize) 457 { 458 gtk_tool_palette_set_icon_size(gtkToolPalette, iconSize); 459 } 460 461 /** 462 * Sets the style (text, icons or both) of items in the tool palette. 463 * 464 * Params: 465 * style = the #GtkToolbarStyle that items in the tool palette shall have 466 * 467 * Since: 2.20 468 */ 469 public void setStyle(GtkToolbarStyle style) 470 { 471 gtk_tool_palette_set_style(gtkToolPalette, style); 472 } 473 474 /** 475 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(), 476 * so that user preferences will be used to determine the icon size. 477 * 478 * Since: 2.20 479 */ 480 public void unsetIconSize() 481 { 482 gtk_tool_palette_unset_icon_size(gtkToolPalette); 483 } 484 485 /** 486 * Unsets a toolbar style set with gtk_tool_palette_set_style(), 487 * so that user preferences will be used to determine the toolbar style. 488 * 489 * Since: 2.20 490 */ 491 public void unsetStyle() 492 { 493 gtk_tool_palette_unset_style(gtkToolPalette); 494 } 495 }