Merging upstream version 0.7.0 (Closes: #493243, #510888, #567617, #699414, #709777...
[debian/lxpanel.git] / src / icon-grid.c
1 /**
2 * Copyright (c) 2009-2014 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <gtk/gtk.h>
20 #include <string.h>
21
22 #include "icon-grid.h"
23
24 /* Properties */
25 enum {
26 PROP_0,
27 PROP_ORIENTATION,
28 PROP_SPACING,
29 PROP_CONSTRAIN_WIDTH
30 //PROP_FILL_WIDTH
31 };
32
33 /* Representative of an icon grid. This is a manager that packs widgets into a rectangular grid whose size adapts to conditions. */
34 struct _PanelIconGrid
35 {
36 GtkContainer container; /* Parent widget */
37 GList * children; /* List of icon grid elements */
38 GtkOrientation orientation; /* Desired orientation */
39 gint child_width; /* Desired child width */
40 gint child_height; /* Desired child height */
41 gint spacing; /* Desired spacing between grid elements */
42 gint target_dimension; /* Desired dimension perpendicular to orientation */
43 gboolean constrain_width : 1; /* True if width should be constrained by allocated space */
44 gboolean fill_width : 1; /* True if children should fill unused width */
45 int rows; /* Computed layout rows */
46 int columns; /* Computed layout columns */
47 int constrained_child_width; /* Child width constrained by allocation */
48 GdkWindow *event_window; /* Event window if NO_WINDOW is set */
49 };
50
51 struct _PanelIconGridClass
52 {
53 GtkContainerClass parent_class;
54 };
55
56 static void panel_icon_grid_size_request(GtkWidget *widget, GtkRequisition *requisition);
57
58 /* Establish the widget placement of an icon grid. */
59 static void panel_icon_grid_size_allocate(GtkWidget *widget,
60 GtkAllocation *allocation)
61 {
62 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
63 GtkRequisition req;
64 GtkAllocation child_allocation;
65 int child_width;
66 int child_height;
67 GtkTextDirection direction;
68 guint border;
69 int limit;
70 int x_initial;
71 int x_delta;
72 int x, y;
73 GList *ige;
74 GtkWidget *child;
75
76 /* Apply given allocation */
77 gtk_widget_set_allocation(widget, allocation);
78 border = gtk_container_get_border_width(GTK_CONTAINER(widget));
79 if (gtk_widget_get_realized(widget))
80 {
81 if (!gtk_widget_get_has_window(widget))
82 {
83 child_allocation.x = allocation->x + border;
84 child_allocation.y = allocation->y + border;
85 }
86 else
87 {
88 child_allocation.x = 0;
89 child_allocation.y = 0;
90 }
91 child_allocation.width = MAX(allocation->width - border * 2, 0);
92 child_allocation.height = MAX(allocation->height - border * 2, 0);
93 if (ig->event_window != NULL)
94 gdk_window_move_resize(ig->event_window,
95 child_allocation.x,
96 child_allocation.y,
97 child_allocation.width,
98 child_allocation.height);
99 if (gtk_widget_get_has_window(widget))
100 gdk_window_move_resize(gtk_widget_get_window(widget),
101 allocation->x + border,
102 allocation->y + border,
103 child_allocation.width,
104 child_allocation.height);
105 }
106
107 /* Get and save the desired container geometry. */
108 if (ig->orientation == GTK_ORIENTATION_HORIZONTAL && allocation->height > 1)
109 ig->target_dimension = allocation->height;
110 else if (ig->orientation == GTK_ORIENTATION_VERTICAL && allocation->width > 1)
111 ig->target_dimension = allocation->width;
112 child_width = ig->child_width;
113 child_height = ig->child_height;
114
115 /* Calculate required size without borders */
116 panel_icon_grid_size_request(widget, &req);
117 req.width -= 2 * border;
118 req.height -= 2 * border;
119
120 /* Get the constrained child geometry if the allocated geometry is insufficient.
121 * All children are still the same size and share equally in the deficit. */
122 ig->constrained_child_width = ig->child_width;
123 if ((ig->columns != 0) && (ig->rows != 0) && (allocation->width > 1))
124 {
125 if (req.width > allocation->width && ig->constrain_width)
126 ig->constrained_child_width = child_width = (allocation->width + ig->spacing - 2 * border) / ig->columns - ig->spacing;
127 if (ig->orientation == GTK_ORIENTATION_HORIZONTAL && req.height < allocation->height)
128 child_height = (allocation->height + ig->spacing - 2 * border) / ig->rows - ig->spacing;
129 }
130
131 /* Initialize parameters to control repositioning each visible child. */
132 direction = gtk_widget_get_direction(widget);
133 limit = border + ((ig->orientation == GTK_ORIENTATION_HORIZONTAL)
134 ? (ig->rows * (child_height + ig->spacing))
135 : (ig->columns * (child_width + ig->spacing)));
136 x_initial = ((direction == GTK_TEXT_DIR_RTL)
137 ? allocation->width - child_width - border
138 : border);
139 x_delta = child_width + ig->spacing;
140 if (direction == GTK_TEXT_DIR_RTL) x_delta = - x_delta;
141
142 /* Reposition each visible child. */
143 x = x_initial;
144 y = border;
145 for (ige = ig->children; ige != NULL; ige = ige->next)
146 {
147 child = ige->data;
148 if (gtk_widget_get_visible(child))
149 {
150 /* Do necessary operations on the child. */
151 gtk_widget_size_request(child, &req);
152 child_allocation.x = x;
153 child_allocation.y = y;
154 child_allocation.width = child_width;
155 child_allocation.height = MIN(req.height, child_height);
156 if (req.height < child_height - 1)
157 child_allocation.y += (child_height - req.height) / 2;
158 if (!gtk_widget_get_has_window (widget))
159 {
160 child_allocation.x += allocation->x;
161 child_allocation.y += allocation->y;
162 }
163 // FIXME: if fill_width and rows > 1 then delay allocation
164 gtk_widget_size_allocate(child, &child_allocation);
165
166 /* Advance to the next grid position. */
167 if (ig->orientation == GTK_ORIENTATION_HORIZONTAL)
168 {
169 y += child_height + ig->spacing;
170 if (y >= limit)
171 {
172 y = border;
173 x += x_delta;
174 // FIXME: if fill_width and rows = 1 then allocate whole column
175 }
176 }
177 else
178 {
179 // FIXME: if fill_width then use aspect to check delta
180 x += x_delta;
181 if ((direction == GTK_TEXT_DIR_RTL) ? (x <= 0) : (x >= limit))
182 {
183 x = x_initial;
184 y += child_height + ig->spacing;
185 }
186 }
187 }
188 }
189 }
190
191 /* Establish the geometry of an icon grid. */
192 static void panel_icon_grid_size_request(GtkWidget *widget,
193 GtkRequisition *requisition)
194 {
195 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
196 int visible_children = 0;
197 GList *ige;
198 int target_dimension = ig->target_dimension;
199 guint border = gtk_container_get_border_width(GTK_CONTAINER(widget));
200 gint old_rows = ig->rows;
201 gint old_columns = ig->columns;
202
203 /* Count visible children. */
204 for (ige = ig->children; ige != NULL; ige = ige->next)
205 if (gtk_widget_get_visible(ige->data))
206 visible_children += 1;
207
208 if (ig->orientation == GTK_ORIENTATION_HORIZONTAL)
209 {
210 /* In horizontal orientation, fit as many rows into the available height as possible.
211 * Then allocate as many columns as necessary. Guard against zerodivides. */
212 ig->rows = 0;
213 if ((ig->child_height + ig->spacing) != 0)
214 ig->rows = (target_dimension + ig->spacing - border * 2) / (ig->child_height + ig->spacing);
215 if (ig->rows == 0)
216 ig->rows = 1;
217 ig->columns = (visible_children + (ig->rows - 1)) / ig->rows;
218 /* if ((ig->columns == 1) && (ig->rows > visible_children))
219 ig->rows = visible_children; */
220 }
221 else
222 {
223 /* In vertical orientation, fit as many columns into the available width as possible.
224 * Then allocate as many rows as necessary. Guard against zerodivides. */
225 ig->columns = 0;
226 if ((ig->child_width + ig->spacing) != 0)
227 ig->columns = (target_dimension + ig->spacing - border * 2) / (ig->child_width + ig->spacing);
228 if (ig->columns == 0)
229 ig->columns = 1;
230 ig->rows = (visible_children + (ig->columns - 1)) / ig->columns;
231 if ((ig->rows == 1) && (ig->columns > visible_children))
232 ig->columns = visible_children;
233 }
234
235 /* Compute the requisition. */
236 if ((ig->columns == 0) || (ig->rows == 0))
237 {
238 requisition->width = 0;
239 requisition->height = 0;
240 }
241 else
242 {
243 int column_spaces = ig->columns - 1;
244 int row_spaces = ig->rows - 1;
245 if (column_spaces < 0) column_spaces = 0;
246 if (row_spaces < 0) row_spaces = 0;
247 requisition->width = ig->child_width * ig->columns + column_spaces * ig->spacing + 2 * border;
248 requisition->height = ig->child_height * ig->rows + row_spaces * ig->spacing + 2 * border;
249 }
250 if (ig->rows != old_rows || ig->columns != old_columns)
251 gtk_widget_queue_resize(widget);
252 }
253
254 /* Handler for "size-request" event on the icon grid element. */
255 static void icon_grid_element_size_request(GtkWidget * widget, GtkRequisition * requisition, PanelIconGrid * ig)
256 {
257 /* This is our opportunity to request space for the element. */
258 // FIXME: if fill_width then calculate width from aspect
259 requisition->width = ig->child_width;
260 if ((ig->constrain_width) && (ig->constrained_child_width > 1))
261 requisition->width = ig->constrained_child_width;
262 requisition->height = ig->child_height;
263 }
264
265 /* Add an icon grid element and establish its initial visibility. */
266 static void panel_icon_grid_add(GtkContainer *container, GtkWidget *widget)
267 {
268 PanelIconGrid *ig = PANEL_ICON_GRID(container);
269
270 /* Insert at the tail of the child list. This keeps the graphics in the order they were added. */
271 ig->children = g_list_append(ig->children, widget);
272
273 /* Add the widget to the layout container. */
274 g_signal_connect(G_OBJECT(widget), "size-request",
275 G_CALLBACK(icon_grid_element_size_request), container);
276 gtk_widget_set_parent(widget, GTK_WIDGET(container));
277 // gtk_widget_queue_resize(GTK_WIDGET(container));
278 }
279
280 void panel_icon_grid_set_constrain_width(PanelIconGrid * ig, gboolean constrain_width)
281 {
282 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
283
284 if ((!ig->constrain_width && !constrain_width) ||
285 (ig->constrain_width && constrain_width))
286 return;
287
288 ig->constrain_width = !!constrain_width;
289 gtk_widget_queue_resize(GTK_WIDGET(ig));
290 }
291
292 /* void panel_icon_grid_set_fill_width(PanelIconGrid * ig, gboolean fill_width)
293 {
294 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
295
296 if ((!ig->fill_width && !fill_width) || (ig->fill_width && fill_width))
297 return;
298
299 ig->fill_width = !!fill_width;
300 gtk_widget_queue_resize(GTK_WIDGET(ig));
301 } */
302
303 /* Remove an icon grid element. */
304 static void panel_icon_grid_remove(GtkContainer *container, GtkWidget *widget)
305 {
306 PanelIconGrid *ig = PANEL_ICON_GRID(container);
307 GList *children = ig->children;
308 GtkWidget *child;
309
310 while (children)
311 {
312 child = children->data;
313 if (widget == child)
314 {
315 gboolean was_visible = gtk_widget_get_visible(widget);
316
317 /* The child is found. Remove from child list and layout container. */
318 g_signal_handlers_disconnect_by_func(widget,
319 icon_grid_element_size_request,
320 container);
321 gtk_widget_unparent (widget);
322 ig->children = g_list_remove_link(ig->children, children);
323 g_list_free(children);
324
325 /* Do a relayout if needed. */
326 if (was_visible)
327 gtk_widget_queue_resize(GTK_WIDGET(ig));
328 break;
329 }
330 children = children->next;
331 }
332 }
333
334 /* Get the index of an icon grid element. */
335 gint panel_icon_grid_get_child_position(PanelIconGrid * ig, GtkWidget * child)
336 {
337 g_return_val_if_fail(PANEL_IS_ICON_GRID(ig), -1);
338
339 return g_list_index(ig->children, child);
340 }
341
342 /* Reorder an icon grid element. */
343 void panel_icon_grid_reorder_child(PanelIconGrid * ig, GtkWidget * child, gint position)
344 {
345 GList *old_link;
346 GList *new_link;
347 gint old_position;
348
349 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
350 g_return_if_fail(GTK_IS_WIDGET(child));
351
352 old_link = ig->children;
353 old_position = 0;
354 while (old_link)
355 {
356 if (old_link->data == child)
357 break;
358 old_link = old_link->next;
359 old_position++;
360 }
361
362 g_return_if_fail(old_link != NULL);
363
364 if (position == old_position)
365 return;
366
367 /* Remove the child from its current position. */
368 ig->children = g_list_delete_link(ig->children, old_link);
369 if (position < 0)
370 new_link = NULL;
371 else
372 new_link = g_list_nth(ig->children, position);
373
374 /* If the child was found, insert it at the new position. */
375 ig->children = g_list_insert_before(ig->children, new_link, child);
376
377 /* Do a relayout. */
378 if (gtk_widget_get_visible(child) && gtk_widget_get_visible(GTK_WIDGET(ig)))
379 gtk_widget_queue_resize(child);
380 }
381
382 /* Change the geometry of an icon grid. */
383 void panel_icon_grid_set_geometry(PanelIconGrid * ig,
384 GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
385 {
386 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
387
388 gtk_container_set_border_width(GTK_CONTAINER(ig), border);
389
390 if (ig->orientation == orientation && ig->child_width == child_width &&
391 ig->child_height == child_height && ig->spacing == spacing &&
392 ig->target_dimension == target_dimension)
393 return;
394
395 ig->orientation = orientation;
396 ig->child_width = child_width;
397 ig->constrained_child_width = child_width;
398 ig->child_height = child_height;
399 ig->spacing = spacing;
400 ig->target_dimension = target_dimension;
401 gtk_widget_queue_resize(GTK_WIDGET(ig));
402 }
403
404 G_DEFINE_TYPE_WITH_CODE(PanelIconGrid, panel_icon_grid, GTK_TYPE_CONTAINER,
405 G_IMPLEMENT_INTERFACE(GTK_TYPE_ORIENTABLE, NULL));
406
407 static void panel_icon_grid_set_property(GObject *object, guint prop_id,
408 const GValue *value, GParamSpec *pspec)
409 {
410 PanelIconGrid *ig = PANEL_ICON_GRID(object);
411 gint spacing;
412 GtkOrientation orientation;
413
414 switch (prop_id)
415 {
416 case PROP_ORIENTATION:
417 orientation = g_value_get_enum(value);
418 if (orientation != ig->orientation)
419 {
420 ig->orientation = orientation;
421 gtk_widget_queue_resize(GTK_WIDGET(ig));
422 }
423 break;
424 case PROP_SPACING:
425 spacing = g_value_get_int(value);
426 if (spacing != ig->spacing)
427 {
428 ig->spacing = spacing;
429 g_object_notify(object, "spacing");
430 gtk_widget_queue_resize(GTK_WIDGET(ig));
431 }
432 break;
433 case PROP_CONSTRAIN_WIDTH:
434 panel_icon_grid_set_constrain_width(ig, g_value_get_boolean(value));
435 break;
436 /* case PROP_FILL_WIDTH:
437 panel_icon_grid_set_fill_width(ig, g_value_get_boolean(value));
438 break; */
439 default:
440 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
441 break;
442 }
443 }
444
445 static void panel_icon_grid_get_property(GObject *object, guint prop_id,
446 GValue *value, GParamSpec *pspec)
447 {
448 PanelIconGrid *ig = PANEL_ICON_GRID(object);
449
450 switch (prop_id)
451 {
452 case PROP_ORIENTATION:
453 g_value_set_enum(value, ig->orientation);
454 break;
455 case PROP_SPACING:
456 g_value_set_int(value, ig->spacing);
457 break;
458 case PROP_CONSTRAIN_WIDTH:
459 g_value_set_boolean(value, ig->constrain_width);
460 break;
461 /* case PROP_FILL_WIDTH:
462 g_value_set_boolean(value, ig->fill_width);
463 break; */
464 default:
465 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
466 break;
467 }
468 }
469
470 /* realize()...expose() are taken from GtkEventBox implementation */
471 static void panel_icon_grid_realize(GtkWidget *widget)
472 {
473 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
474 GdkWindow *window;
475 GtkStyle *style;
476 GtkAllocation allocation;
477 GdkWindowAttr attributes;
478 guint border = gtk_container_get_border_width(GTK_CONTAINER(widget));
479 gint attributes_mask;
480 gboolean visible_window;
481
482 gtk_widget_set_realized(widget, TRUE);
483
484 gtk_widget_get_allocation(widget, &allocation);
485 attributes.x = allocation.x + border;
486 attributes.y = allocation.y + border;
487 attributes.width = allocation.width - 2*border;
488 attributes.height = allocation.height - 2*border;
489 attributes.window_type = GDK_WINDOW_CHILD;
490 attributes.event_mask = gtk_widget_get_events(widget)
491 | GDK_BUTTON_MOTION_MASK
492 | GDK_BUTTON_PRESS_MASK
493 | GDK_BUTTON_RELEASE_MASK
494 | GDK_EXPOSURE_MASK
495 | GDK_ENTER_NOTIFY_MASK
496 | GDK_LEAVE_NOTIFY_MASK;
497
498 visible_window = gtk_widget_get_has_window(widget);
499 if (visible_window)
500 {
501 attributes.visual = gtk_widget_get_visual(widget);
502 attributes.colormap = gtk_widget_get_colormap(widget);
503 attributes.wclass = GDK_INPUT_OUTPUT;
504
505 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
506
507 window = gdk_window_new(gtk_widget_get_parent_window(widget),
508 &attributes, attributes_mask);
509 gtk_widget_set_window(widget, window);
510 gdk_window_set_user_data(window, widget);
511 }
512 else
513 {
514 window = gtk_widget_get_parent_window(widget);
515 gtk_widget_set_window(widget, window);
516 g_object_ref(window);
517
518 attributes.wclass = GDK_INPUT_ONLY;
519 attributes_mask = GDK_WA_X | GDK_WA_Y;
520
521 ig->event_window = gdk_window_new(window, &attributes, attributes_mask);
522 gdk_window_set_user_data(ig->event_window, widget);
523 }
524
525 style = gtk_style_attach(gtk_widget_get_style(widget), window);
526 gtk_widget_set_style(widget, style);
527
528 if (visible_window)
529 gtk_style_set_background(style, window, GTK_STATE_NORMAL);
530 }
531
532 static void panel_icon_grid_unrealize(GtkWidget *widget)
533 {
534 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
535
536 if (ig->event_window != NULL)
537 {
538 gdk_window_set_user_data(ig->event_window, NULL);
539 gdk_window_destroy(ig->event_window);
540 ig->event_window = NULL;
541 }
542
543 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->unrealize(widget);
544 }
545
546 static void panel_icon_grid_map(GtkWidget *widget)
547 {
548 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
549
550 if (ig->event_window != NULL)
551 gdk_window_show(ig->event_window);
552 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->map(widget);
553 }
554
555 static void panel_icon_grid_unmap(GtkWidget *widget)
556 {
557 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
558
559 if (ig->event_window != NULL)
560 gdk_window_hide(ig->event_window);
561 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->unmap(widget);
562 }
563
564 static gboolean panel_icon_grid_expose(GtkWidget *widget, GdkEventExpose *event)
565 {
566 if (gtk_widget_is_drawable(widget))
567 {
568 if (gtk_widget_get_has_window(widget) &&
569 !gtk_widget_get_app_paintable(widget))
570 gtk_paint_flat_box(gtk_widget_get_style(widget),
571 gtk_widget_get_window(widget),
572 gtk_widget_get_state(widget), GTK_SHADOW_NONE,
573 &event->area, widget, "panelicongrid",
574 0, 0, -1, -1);
575
576 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->expose_event(widget, event);
577 }
578 return FALSE;
579 }
580
581 static void panel_icon_grid_forall(GtkContainer *container,
582 gboolean include_internals,
583 GtkCallback callback,
584 gpointer callback_data)
585 {
586 PanelIconGrid *ig = PANEL_ICON_GRID(container);
587 GList *children = ig->children;
588 GtkWidget *child;
589
590 while (children)
591 {
592 child = children->data;
593 children = children->next;
594 (* callback)(child, callback_data);
595 }
596 }
597
598 static GType panel_icon_grid_child_type(GtkContainer *container)
599 {
600 return GTK_TYPE_WIDGET;
601 }
602
603 static void panel_icon_grid_class_init(PanelIconGridClass *class)
604 {
605 GObjectClass *object_class = G_OBJECT_CLASS(class);
606 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class);
607 GtkContainerClass *container_class = GTK_CONTAINER_CLASS(class);
608
609 object_class->set_property = panel_icon_grid_set_property;
610 object_class->get_property = panel_icon_grid_get_property;
611
612 widget_class->size_request = panel_icon_grid_size_request;
613 widget_class->size_allocate = panel_icon_grid_size_allocate;
614 widget_class->realize = panel_icon_grid_realize;
615 widget_class->unrealize = panel_icon_grid_unrealize;
616 widget_class->map = panel_icon_grid_map;
617 widget_class->unmap = panel_icon_grid_unmap;
618 widget_class->expose_event = panel_icon_grid_expose;
619
620 container_class->add = panel_icon_grid_add;
621 container_class->remove = panel_icon_grid_remove;
622 container_class->forall = panel_icon_grid_forall;
623 container_class->child_type = panel_icon_grid_child_type;
624
625 g_object_class_override_property(object_class,
626 PROP_ORIENTATION,
627 "orientation");
628 g_object_class_install_property(object_class,
629 PROP_SPACING,
630 g_param_spec_int("spacing",
631 "Spacing",
632 "The amount of space between children",
633 0,
634 G_MAXINT,
635 0,
636 G_PARAM_READWRITE));
637 g_object_class_install_property(object_class,
638 PROP_CONSTRAIN_WIDTH,
639 g_param_spec_boolean("constrain-width",
640 "Constrain width",
641 "Whether to constrain width by allocated space",
642 FALSE, G_PARAM_READWRITE));
643 }
644
645 static void panel_icon_grid_init(PanelIconGrid *ig)
646 {
647 gtk_widget_set_has_window(GTK_WIDGET(ig), FALSE);
648 gtk_widget_set_redraw_on_allocate(GTK_WIDGET(ig), FALSE);
649
650 ig->orientation = GTK_ORIENTATION_HORIZONTAL;
651 }
652
653 /* Establish an icon grid in a specified container widget.
654 * The icon grid manages the contents of the container.
655 * The orientation, geometry of the elements, and spacing can be varied. All elements are the same size. */
656 GtkWidget * panel_icon_grid_new(
657 GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
658 {
659 /* Create a structure representing the icon grid and collect the parameters. */
660 PanelIconGrid * ig = g_object_new(PANEL_TYPE_ICON_GRID,
661 "orientation", orientation,
662 "spacing", spacing, NULL);
663
664 ig->child_width = child_width;
665 ig->constrained_child_width = child_width;
666 ig->child_height = child_height;
667 ig->target_dimension = target_dimension;
668 gtk_container_set_border_width(GTK_CONTAINER(ig), border);
669
670 return (GtkWidget *)ig;
671 }