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