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 (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 * Since: 2.20 116 */ 117 public class ToolPalette : Container, OrientableIF, ScrollableIF 118 { 119 /** the main Gtk struct */ 120 protected GtkToolPalette* gtkToolPalette; 121 122 /** Get the main Gtk struct */ 123 public GtkToolPalette* getToolPaletteStruct(bool transferOwnership = false) 124 { 125 if (transferOwnership) 126 ownedRef = false; 127 return gtkToolPalette; 128 } 129 130 /** the main Gtk struct as a void* */ 131 protected override void* getStruct() 132 { 133 return cast(void*)gtkToolPalette; 134 } 135 136 /** 137 * Sets our main struct and passes it to the parent class. 138 */ 139 public this (GtkToolPalette* gtkToolPalette, bool ownedRef = false) 140 { 141 this.gtkToolPalette = gtkToolPalette; 142 super(cast(GtkContainer*)gtkToolPalette, ownedRef); 143 } 144 145 // add the Orientable capabilities 146 mixin OrientableT!(GtkToolPalette); 147 148 // add the Scrollable capabilities 149 mixin ScrollableT!(GtkToolPalette); 150 151 152 /** */ 153 public static GType getType() 154 { 155 return gtk_tool_palette_get_type(); 156 } 157 158 /** 159 * Creates a new tool palette. 160 * 161 * Returns: a new #GtkToolPalette 162 * 163 * Since: 2.20 164 * 165 * Throws: ConstructionException GTK+ fails to create the object. 166 */ 167 public this() 168 { 169 auto p = gtk_tool_palette_new(); 170 171 if(p is null) 172 { 173 throw new ConstructionException("null returned by new"); 174 } 175 176 this(cast(GtkToolPalette*) p); 177 } 178 179 /** 180 * Get the target entry for a dragged #GtkToolItemGroup. 181 * 182 * Returns: the #GtkTargetEntry for a dragged group 183 * 184 * Since: 2.20 185 */ 186 public static TargetEntry getDragTargetGroup() 187 { 188 auto p = gtk_tool_palette_get_drag_target_group(); 189 190 if(p is null) 191 { 192 return null; 193 } 194 195 return ObjectG.getDObject!(TargetEntry)(cast(GtkTargetEntry*) p); 196 } 197 198 /** 199 * Gets the target entry for a dragged #GtkToolItem. 200 * 201 * Returns: the #GtkTargetEntry for a dragged item. 202 * 203 * Since: 2.20 204 */ 205 public static TargetEntry getDragTargetItem() 206 { 207 auto p = gtk_tool_palette_get_drag_target_item(); 208 209 if(p is null) 210 { 211 return null; 212 } 213 214 return ObjectG.getDObject!(TargetEntry)(cast(GtkTargetEntry*) p); 215 } 216 217 /** 218 * Sets @palette as drag source (see gtk_tool_palette_set_drag_source()) 219 * and sets @widget as a drag destination for drags from @palette. 220 * See gtk_drag_dest_set(). 221 * 222 * Params: 223 * widget = a #GtkWidget which should be a drag destination for @palette 224 * flags = the flags that specify what actions GTK+ should take for drops 225 * on that widget 226 * targets = the #GtkToolPaletteDragTargets which the widget 227 * should support 228 * actions = the #GdkDragActions which the widget should suppport 229 * 230 * Since: 2.20 231 */ 232 public void addDragDest(Widget widget, GtkDestDefaults flags, GtkToolPaletteDragTargets targets, GdkDragAction actions) 233 { 234 gtk_tool_palette_add_drag_dest(gtkToolPalette, (widget is null) ? null : widget.getWidgetStruct(), flags, targets, actions); 235 } 236 237 /** 238 * Get the dragged item from the selection. 239 * This could be a #GtkToolItem or a #GtkToolItemGroup. 240 * 241 * Params: 242 * selection = a #GtkSelectionData 243 * 244 * Returns: the dragged item in selection 245 * 246 * Since: 2.20 247 */ 248 public Widget getDragItem(SelectionData selection) 249 { 250 auto p = gtk_tool_palette_get_drag_item(gtkToolPalette, (selection is null) ? null : selection.getSelectionDataStruct()); 251 252 if(p is null) 253 { 254 return null; 255 } 256 257 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p); 258 } 259 260 /** 261 * Gets the group at position (x, y). 262 * 263 * Params: 264 * x = the x position 265 * y = the y position 266 * 267 * Returns: the #GtkToolItemGroup at position 268 * or %NULL if there is no such group 269 * 270 * Since: 2.20 271 */ 272 public ToolItemGroup getDropGroup(int x, int y) 273 { 274 auto p = gtk_tool_palette_get_drop_group(gtkToolPalette, x, y); 275 276 if(p is null) 277 { 278 return null; 279 } 280 281 return ObjectG.getDObject!(ToolItemGroup)(cast(GtkToolItemGroup*) p); 282 } 283 284 /** 285 * Gets the item at position (x, y). 286 * See gtk_tool_palette_get_drop_group(). 287 * 288 * Params: 289 * x = the x position 290 * y = the y position 291 * 292 * Returns: the #GtkToolItem at position or %NULL if there is no such item 293 * 294 * Since: 2.20 295 */ 296 public ToolItem getDropItem(int x, int y) 297 { 298 auto p = gtk_tool_palette_get_drop_item(gtkToolPalette, x, y); 299 300 if(p is null) 301 { 302 return null; 303 } 304 305 return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p); 306 } 307 308 /** 309 * Gets whether @group is exclusive or not. 310 * See gtk_tool_palette_set_exclusive(). 311 * 312 * Params: 313 * group = a #GtkToolItemGroup which is a child of palette 314 * 315 * Returns: %TRUE if @group is exclusive 316 * 317 * Since: 2.20 318 */ 319 public bool getExclusive(ToolItemGroup group) 320 { 321 return gtk_tool_palette_get_exclusive(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct()) != 0; 322 } 323 324 /** 325 * Gets whether group should be given extra space. 326 * See gtk_tool_palette_set_expand(). 327 * 328 * Params: 329 * group = a #GtkToolItemGroup which is a child of palette 330 * 331 * Returns: %TRUE if group should be given extra space, %FALSE otherwise 332 * 333 * Since: 2.20 334 */ 335 public bool getExpand(ToolItemGroup group) 336 { 337 return gtk_tool_palette_get_expand(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct()) != 0; 338 } 339 340 /** 341 * Gets the position of @group in @palette as index. 342 * See gtk_tool_palette_set_group_position(). 343 * 344 * Params: 345 * group = a #GtkToolItemGroup 346 * 347 * Returns: the index of group or -1 if @group is not a child of @palette 348 * 349 * Since: 2.20 350 */ 351 public int getGroupPosition(ToolItemGroup group) 352 { 353 return gtk_tool_palette_get_group_position(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct()); 354 } 355 356 /** 357 * Gets the size of icons in the tool palette. 358 * See gtk_tool_palette_set_icon_size(). 359 * 360 * Returns: the #GtkIconSize of icons in the tool palette 361 * 362 * Since: 2.20 363 */ 364 public GtkIconSize getIconSize() 365 { 366 return gtk_tool_palette_get_icon_size(gtkToolPalette); 367 } 368 369 /** 370 * Gets the style (icons, text or both) of items in the tool palette. 371 * 372 * Returns: the #GtkToolbarStyle of items in the tool palette. 373 * 374 * Since: 2.20 375 */ 376 public GtkToolbarStyle getToolbarStyle() 377 { 378 return gtk_tool_palette_get_style(gtkToolPalette); 379 } 380 381 /** 382 * Sets the tool palette as a drag source. 383 * Enables all groups and items in the tool palette as drag sources 384 * on button 1 and button 3 press with copy and move actions. 385 * See gtk_drag_source_set(). 386 * 387 * Params: 388 * targets = the #GtkToolPaletteDragTargets 389 * which the widget should support 390 * 391 * Since: 2.20 392 */ 393 public void setDragSource(GtkToolPaletteDragTargets targets) 394 { 395 gtk_tool_palette_set_drag_source(gtkToolPalette, targets); 396 } 397 398 /** 399 * Sets whether the group should be exclusive or not. 400 * If an exclusive group is expanded all other groups are collapsed. 401 * 402 * Params: 403 * group = a #GtkToolItemGroup which is a child of palette 404 * exclusive = whether the group should be exclusive or not 405 * 406 * Since: 2.20 407 */ 408 public void setExclusive(ToolItemGroup group, bool exclusive) 409 { 410 gtk_tool_palette_set_exclusive(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct(), exclusive); 411 } 412 413 /** 414 * Sets whether the group should be given extra space. 415 * 416 * Params: 417 * group = a #GtkToolItemGroup which is a child of palette 418 * expand = whether the group should be given extra space 419 * 420 * Since: 2.20 421 */ 422 public void setExpand(ToolItemGroup group, bool expand) 423 { 424 gtk_tool_palette_set_expand(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct(), expand); 425 } 426 427 /** 428 * Sets the position of the group as an index of the tool palette. 429 * If position is 0 the group will become the first child, if position is 430 * -1 it will become the last child. 431 * 432 * Params: 433 * group = a #GtkToolItemGroup which is a child of palette 434 * position = a new index for group 435 * 436 * Since: 2.20 437 */ 438 public void setGroupPosition(ToolItemGroup group, int position) 439 { 440 gtk_tool_palette_set_group_position(gtkToolPalette, (group is null) ? null : group.getToolItemGroupStruct(), position); 441 } 442 443 /** 444 * Sets the size of icons in the tool palette. 445 * 446 * Params: 447 * iconSize = the #GtkIconSize that icons in the tool 448 * palette shall have 449 * 450 * Since: 2.20 451 */ 452 public void setIconSize(GtkIconSize iconSize) 453 { 454 gtk_tool_palette_set_icon_size(gtkToolPalette, iconSize); 455 } 456 457 /** 458 * Sets the style (text, icons or both) of items in the tool palette. 459 * 460 * Params: 461 * style = the #GtkToolbarStyle that items in the tool palette shall have 462 * 463 * Since: 2.20 464 */ 465 public void setStyle(GtkToolbarStyle style) 466 { 467 gtk_tool_palette_set_style(gtkToolPalette, style); 468 } 469 470 /** 471 * Unsets the tool palette icon size set with gtk_tool_palette_set_icon_size(), 472 * so that user preferences will be used to determine the icon size. 473 * 474 * Since: 2.20 475 */ 476 public void unsetIconSize() 477 { 478 gtk_tool_palette_unset_icon_size(gtkToolPalette); 479 } 480 481 /** 482 * Unsets a toolbar style set with gtk_tool_palette_set_style(), 483 * so that user preferences will be used to determine the toolbar style. 484 * 485 * Since: 2.20 486 */ 487 public void unsetStyle() 488 { 489 gtk_tool_palette_unset_style(gtkToolPalette); 490 } 491 }