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