Fix usage of constrain-width attribute of PanelIconGrid in size_allocate method.
[lxde/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 = 1;
239 requisition->height = 1;
240 gtk_widget_hide(widget); /* Necessary to get the plugin to disappear */
241 }
242 else
243 {
244 int column_spaces = ig->columns - 1;
245 int row_spaces = ig->rows - 1;
246 if (column_spaces < 0) column_spaces = 0;
247 if (row_spaces < 0) row_spaces = 0;
248 requisition->width = ig->child_width * ig->columns + column_spaces * ig->spacing + 2 * border;
249 requisition->height = ig->child_height * ig->rows + row_spaces * ig->spacing + 2 * border;
250 gtk_widget_show(widget);
251 }
252 if (ig->rows != old_rows || ig->columns != old_columns)
253 gtk_widget_queue_resize(widget);
254 }
255
256 /* Handler for "size-request" event on the icon grid element. */
257 static void icon_grid_element_size_request(GtkWidget * widget, GtkRequisition * requisition, PanelIconGrid * ig)
258 {
259 /* This is our opportunity to request space for the element. */
260 // FIXME: if fill_width then calculate width from aspect
261 requisition->width = ig->child_width;
262 if ((ig->constrain_width) && (ig->constrained_child_width > 1))
263 requisition->width = ig->constrained_child_width;
264 requisition->height = ig->child_height;
265 }
266
267 /* Add an icon grid element and establish its initial visibility. */
268 static void panel_icon_grid_add(GtkContainer *container, GtkWidget *widget)
269 {
270 PanelIconGrid *ig = PANEL_ICON_GRID(container);
271
272 /* Insert at the tail of the child list. This keeps the graphics in the order they were added. */
273 ig->children = g_list_append(ig->children, widget);
274
275 /* Add the widget to the layout container. */
276 g_signal_connect(G_OBJECT(widget), "size-request",
277 G_CALLBACK(icon_grid_element_size_request), container);
278 gtk_widget_set_parent(widget, GTK_WIDGET(container));
279 gtk_widget_queue_resize(GTK_WIDGET(container));
280 }
281
282 void panel_icon_grid_set_constrain_width(PanelIconGrid * ig, gboolean constrain_width)
283 {
284 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
285
286 if ((!ig->constrain_width && !constrain_width) ||
287 (ig->constrain_width && constrain_width))
288 return;
289
290 ig->constrain_width = !!constrain_width;
291 gtk_widget_queue_resize(GTK_WIDGET(ig));
292 }
293
294 /* void panel_icon_grid_set_fill_width(PanelIconGrid * ig, gboolean fill_width)
295 {
296 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
297
298 if ((!ig->fill_width && !fill_width) || (ig->fill_width && fill_width))
299 return;
300
301 ig->fill_width = !!fill_width;
302 gtk_widget_queue_resize(GTK_WIDGET(ig));
303 } */
304
305 /* Remove an icon grid element. */
306 static void panel_icon_grid_remove(GtkContainer *container, GtkWidget *widget)
307 {
308 PanelIconGrid *ig = PANEL_ICON_GRID(container);
309 GList *children = ig->children;
310 GtkWidget *child;
311
312 while (children)
313 {
314 child = children->data;
315 if (widget == child)
316 {
317 gboolean was_visible = gtk_widget_get_visible(widget);
318
319 /* The child is found. Remove from child list and layout container. */
320 g_signal_handlers_disconnect_by_func(widget,
321 icon_grid_element_size_request,
322 container);
323 gtk_widget_unparent (widget);
324 ig->children = g_list_remove_link(ig->children, children);
325 g_list_free(children);
326
327 /* Do a relayout if needed. */
328 if (was_visible)
329 gtk_widget_queue_resize(GTK_WIDGET(ig));
330 break;
331 }
332 children = children->next;
333 }
334 }
335
336 /* Get the index of an icon grid element. */
337 gint panel_icon_grid_get_child_position(PanelIconGrid * ig, GtkWidget * child)
338 {
339 g_return_val_if_fail(PANEL_IS_ICON_GRID(ig), -1);
340
341 return g_list_index(ig->children, child);
342 }
343
344 /* Reorder an icon grid element. */
345 void panel_icon_grid_reorder_child(PanelIconGrid * ig, GtkWidget * child, gint position)
346 {
347 GList *old_link;
348 GList *new_link;
349 gint old_position;
350
351 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
352 g_return_if_fail(GTK_IS_WIDGET(child));
353
354 old_link = ig->children;
355 old_position = 0;
356 while (old_link)
357 {
358 if (old_link->data == child)
359 break;
360 old_link = old_link->next;
361 old_position++;
362 }
363
364 g_return_if_fail(old_link != NULL);
365
366 if (position == old_position)
367 return;
368
369 /* Remove the child from its current position. */
370 ig->children = g_list_delete_link(ig->children, old_link);
371 if (position < 0)
372 new_link = NULL;
373 else
374 new_link = g_list_nth(ig->children, position);
375
376 /* If the child was found, insert it at the new position. */
377 ig->children = g_list_insert_before(ig->children, new_link, child);
378
379 /* Do a relayout. */
380 if (gtk_widget_get_visible(child) && gtk_widget_get_visible(GTK_WIDGET(ig)))
381 gtk_widget_queue_resize(child);
382 }
383
384 /* Change the geometry of an icon grid. */
385 void panel_icon_grid_set_geometry(PanelIconGrid * ig,
386 GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
387 {
388 g_return_if_fail(PANEL_IS_ICON_GRID(ig));
389
390 gtk_container_set_border_width(GTK_CONTAINER(ig), border);
391
392 if (ig->orientation == orientation && ig->child_width == child_width &&
393 ig->child_height == child_height && ig->spacing == spacing &&
394 ig->target_dimension == target_dimension)
395 return;
396
397 ig->orientation = orientation;
398 ig->child_width = child_width;
399 ig->constrained_child_width = child_width;
400 ig->child_height = child_height;
401 ig->spacing = spacing;
402 ig->target_dimension = target_dimension;
403 gtk_widget_queue_resize(GTK_WIDGET(ig));
404 }
405
406 G_DEFINE_TYPE_WITH_CODE(PanelIconGrid, panel_icon_grid, GTK_TYPE_CONTAINER,
407 G_IMPLEMENT_INTERFACE(GTK_TYPE_ORIENTABLE, NULL));
408
409 static void panel_icon_grid_set_property(GObject *object, guint prop_id,
410 const GValue *value, GParamSpec *pspec)
411 {
412 PanelIconGrid *ig = PANEL_ICON_GRID(object);
413 gint spacing;
414 GtkOrientation orientation;
415
416 switch (prop_id)
417 {
418 case PROP_ORIENTATION:
419 orientation = g_value_get_enum(value);
420 if (orientation != ig->orientation)
421 {
422 ig->orientation = orientation;
423 gtk_widget_queue_resize(GTK_WIDGET(ig));
424 }
425 break;
426 case PROP_SPACING:
427 spacing = g_value_get_int(value);
428 if (spacing != ig->spacing)
429 {
430 ig->spacing = spacing;
431 g_object_notify(object, "spacing");
432 gtk_widget_queue_resize(GTK_WIDGET(ig));
433 }
434 break;
435 case PROP_CONSTRAIN_WIDTH:
436 panel_icon_grid_set_constrain_width(ig, g_value_get_boolean(value));
437 break;
438 /* case PROP_FILL_WIDTH:
439 panel_icon_grid_set_fill_width(ig, g_value_get_boolean(value));
440 break; */
441 default:
442 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
443 break;
444 }
445 }
446
447 static void panel_icon_grid_get_property(GObject *object, guint prop_id,
448 GValue *value, GParamSpec *pspec)
449 {
450 PanelIconGrid *ig = PANEL_ICON_GRID(object);
451
452 switch (prop_id)
453 {
454 case PROP_ORIENTATION:
455 g_value_set_enum(value, ig->orientation);
456 break;
457 case PROP_SPACING:
458 g_value_set_int(value, ig->spacing);
459 break;
460 case PROP_CONSTRAIN_WIDTH:
461 g_value_set_boolean(value, ig->constrain_width);
462 break;
463 /* case PROP_FILL_WIDTH:
464 g_value_set_boolean(value, ig->fill_width);
465 break; */
466 default:
467 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
468 break;
469 }
470 }
471
472 /* realize()...expose() are taken from GtkEventBox implementation */
473 static void panel_icon_grid_realize(GtkWidget *widget)
474 {
475 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
476 GdkWindow *window;
477 GtkStyle *style;
478 GtkAllocation allocation;
479 GdkWindowAttr attributes;
480 guint border = gtk_container_get_border_width(GTK_CONTAINER(widget));
481 gint attributes_mask;
482 gboolean visible_window;
483
484 gtk_widget_set_realized(widget, TRUE);
485
486 gtk_widget_get_allocation(widget, &allocation);
487 attributes.x = allocation.x + border;
488 attributes.y = allocation.y + border;
489 attributes.width = allocation.width - 2*border;
490 attributes.height = allocation.height - 2*border;
491 attributes.window_type = GDK_WINDOW_CHILD;
492 attributes.event_mask = gtk_widget_get_events(widget)
493 | GDK_BUTTON_MOTION_MASK
494 | GDK_BUTTON_PRESS_MASK
495 | GDK_BUTTON_RELEASE_MASK
496 | GDK_EXPOSURE_MASK
497 | GDK_ENTER_NOTIFY_MASK
498 | GDK_LEAVE_NOTIFY_MASK;
499
500 visible_window = gtk_widget_get_has_window(widget);
501 if (visible_window)
502 {
503 attributes.visual = gtk_widget_get_visual(widget);
504 attributes.colormap = gtk_widget_get_colormap(widget);
505 attributes.wclass = GDK_INPUT_OUTPUT;
506
507 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
508
509 window = gdk_window_new(gtk_widget_get_parent_window(widget),
510 &attributes, attributes_mask);
511 gtk_widget_set_window(widget, window);
512 gdk_window_set_user_data(window, widget);
513 }
514 else
515 {
516 window = gtk_widget_get_parent_window(widget);
517 gtk_widget_set_window(widget, window);
518 g_object_ref(window);
519
520 attributes.wclass = GDK_INPUT_ONLY;
521 attributes_mask = GDK_WA_X | GDK_WA_Y;
522
523 ig->event_window = gdk_window_new(window, &attributes, attributes_mask);
524 gdk_window_set_user_data(ig->event_window, widget);
525 }
526
527 style = gtk_style_attach(gtk_widget_get_style(widget), window);
528 gtk_widget_set_style(widget, style);
529
530 if (visible_window)
531 gtk_style_set_background(style, window, GTK_STATE_NORMAL);
532 }
533
534 static void panel_icon_grid_unrealize(GtkWidget *widget)
535 {
536 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
537
538 if (ig->event_window != NULL)
539 {
540 gdk_window_set_user_data(ig->event_window, NULL);
541 gdk_window_destroy(ig->event_window);
542 ig->event_window = NULL;
543 }
544
545 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->unrealize(widget);
546 }
547
548 static void panel_icon_grid_map(GtkWidget *widget)
549 {
550 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
551
552 if (ig->event_window != NULL)
553 gdk_window_show(ig->event_window);
554 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->map(widget);
555 }
556
557 static void panel_icon_grid_unmap(GtkWidget *widget)
558 {
559 PanelIconGrid *ig = PANEL_ICON_GRID(widget);
560
561 if (ig->event_window != NULL)
562 gdk_window_hide(ig->event_window);
563 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->unmap(widget);
564 }
565
566 static gboolean panel_icon_grid_expose(GtkWidget *widget, GdkEventExpose *event)
567 {
568 if (gtk_widget_is_drawable(widget))
569 {
570 if (gtk_widget_get_has_window(widget) &&
571 !gtk_widget_get_app_paintable(widget))
572 gtk_paint_flat_box(gtk_widget_get_style(widget),
573 gtk_widget_get_window(widget),
574 gtk_widget_get_state(widget), GTK_SHADOW_NONE,
575 &event->area, widget, "panelicongrid",
576 0, 0, -1, -1);
577
578 GTK_WIDGET_CLASS(panel_icon_grid_parent_class)->expose_event(widget, event);
579 }
580 return FALSE;
581 }
582
583 static void panel_icon_grid_forall(GtkContainer *container,
584 gboolean include_internals,
585 GtkCallback callback,
586 gpointer callback_data)
587 {
588 PanelIconGrid *ig = PANEL_ICON_GRID(container);
589 GList *children = ig->children;
590 GtkWidget *child;
591
592 while (children)
593 {
594 child = children->data;
595 children = children->next;
596 (* callback)(child, callback_data);
597 }
598 }
599
600 static GType panel_icon_grid_child_type(GtkContainer *container)
601 {
602 return GTK_TYPE_WIDGET;
603 }
604
605 static void panel_icon_grid_class_init(PanelIconGridClass *class)
606 {
607 GObjectClass *object_class = G_OBJECT_CLASS(class);
608 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(class);
609 GtkContainerClass *container_class = GTK_CONTAINER_CLASS(class);
610
611 object_class->set_property = panel_icon_grid_set_property;
612 object_class->get_property = panel_icon_grid_get_property;
613
614 widget_class->size_request = panel_icon_grid_size_request;
615 widget_class->size_allocate = panel_icon_grid_size_allocate;
616 widget_class->realize = panel_icon_grid_realize;
617 widget_class->unrealize = panel_icon_grid_unrealize;
618 widget_class->map = panel_icon_grid_map;
619 widget_class->unmap = panel_icon_grid_unmap;
620 widget_class->expose_event = panel_icon_grid_expose;
621
622 container_class->add = panel_icon_grid_add;
623 container_class->remove = panel_icon_grid_remove;
624 container_class->forall = panel_icon_grid_forall;
625 container_class->child_type = panel_icon_grid_child_type;
626
627 g_object_class_override_property(object_class,
628 PROP_ORIENTATION,
629 "orientation");
630 g_object_class_install_property(object_class,
631 PROP_SPACING,
632 g_param_spec_int("spacing",
633 "Spacing",
634 "The amount of space between children",
635 0,
636 G_MAXINT,
637 0,
638 G_PARAM_READWRITE));
639 g_object_class_install_property(object_class,
640 PROP_CONSTRAIN_WIDTH,
641 g_param_spec_boolean("constrain-width",
642 "Constrain width",
643 "Whether to constrain width by allocated space",
644 FALSE, G_PARAM_READWRITE));
645 }
646
647 static void panel_icon_grid_init(PanelIconGrid *ig)
648 {
649 gtk_widget_set_has_window(GTK_WIDGET(ig), FALSE);
650 gtk_widget_set_redraw_on_allocate(GTK_WIDGET(ig), FALSE);
651
652 ig->orientation = GTK_ORIENTATION_HORIZONTAL;
653 }
654
655 /* Establish an icon grid in a specified container widget.
656 * The icon grid manages the contents of the container.
657 * The orientation, geometry of the elements, and spacing can be varied. All elements are the same size. */
658 GtkWidget * panel_icon_grid_new(
659 GtkOrientation orientation, gint child_width, gint child_height, gint spacing, gint border, gint target_dimension)
660 {
661 /* Create a structure representing the icon grid and collect the parameters. */
662 PanelIconGrid * ig = g_object_new(PANEL_TYPE_ICON_GRID,
663 "orientation", orientation,
664 "spacing", spacing, NULL);
665
666 ig->child_width = child_width;
667 ig->constrained_child_width = child_width;
668 ig->child_height = child_height;
669 ig->target_dimension = target_dimension;
670 gtk_container_set_border_width(GTK_CONTAINER(ig), border);
671
672 return (GtkWidget *)ig;
673 }