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