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