3
* Copyright (C) 2002 Jasper Huijsmans (huysmans@users.sourceforge.net)
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program 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 General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
* The panel consist of a collection of panel groups. A panel group defines
23
* several containers to pack widgets into and to allow easy rearragement of
26
* Two widgets are packed into a panel group: a panel control and a popup
34
#include <libxfce4util/i18n.h>
35
#include <libxfce4util/debug.h>
41
static GSList *group_list = NULL;
42
static GSList *removed_list = NULL;
43
static GtkArrowType popup_arrow_type = GTK_ARROW_UP;
45
static GtkBox *groupbox;
50
typedef struct _PanelGroup PanelGroup;
56
GtkWidget *base; /* container to pack into panel */
57
GtkWidget *box; /* hbox or vbox */
64
panel_group_arrange (PanelGroup * pg)
66
int position = settings.popup_position;
71
panel_popup_unpack (pg->popup);
73
control_unpack (pg->control);
75
gtk_widget_destroy (pg->box);
78
if (position == TOP || position == BOTTOM)
79
pg->box = gtk_vbox_new (FALSE, 0);
81
pg->box = gtk_hbox_new (FALSE, 0);
83
gtk_widget_show (pg->box);
84
gtk_container_add (GTK_CONTAINER (pg->base), pg->box);
86
if (position == RIGHT || position == BOTTOM)
89
control_pack (pg->control, GTK_BOX (pg->box));
91
panel_popup_pack (pg->popup, GTK_BOX (pg->box));
96
panel_popup_pack (pg->popup, GTK_BOX (pg->box));
98
control_pack (pg->control, GTK_BOX (pg->box));
103
create_panel_group (int index)
105
PanelGroup *pg = g_new (PanelGroup, 1);
109
pg->base = gtk_alignment_new (0, 0, 1, 1);
110
gtk_widget_show (pg->base);
112
/* protect against destruction when unpacking */
113
g_object_ref (pg->base);
114
gtk_object_sink (GTK_OBJECT (pg->base));
124
panel_group_free (PanelGroup * pg)
126
panel_popup_free (pg->popup);
127
control_free (pg->control);
129
g_object_unref (pg->base);
134
panel_group_pack (PanelGroup * pg, GtkBox * hbox)
136
gtk_box_pack_start (hbox, pg->base, TRUE, TRUE, 0);
140
panel_group_unpack (PanelGroup * pg)
142
gtk_container_remove (GTK_CONTAINER (pg->base->parent), pg->base);
147
* Mainly housekeeping for the global list of panel groups
150
groups_init (GtkBox * box)
154
/* we need this later on, so we may just as well initialize it here */
155
control_class_list_init ();
159
groups_cleanup (void)
164
for (li = group_list; li; li = li->next)
168
panel_group_free (group);
171
control_class_list_cleanup ();
173
g_slist_free (group_list);
174
g_slist_free (removed_list);
180
old_groups_set_from_xml (int side, xmlNodePtr node)
182
static int last_group = 0;
191
li = g_slist_nth (group_list, last_group);
193
/* children are "Group" nodes */
195
node = node->children;
197
for (i = last_group; /*i < settings.num_groups ||*/ li || node; i++)
199
gboolean control_created = FALSE;
201
if (side == LEFT && !node)
210
group = create_panel_group (i);
211
panel_group_pack (group, groupbox);
212
group_list = g_slist_append (group_list, group);
214
group->popup = create_panel_popup ();
216
group->control = control_new (i);
218
panel_group_arrange (group);
223
for (child = node->children; child; child = child->next)
225
/* create popup items and panel control */
226
if (xmlStrEqual (child->name, (const xmlChar *) "Popup"))
228
panel_popup_set_from_xml (group->popup, child);
231
(child->name, (const xmlChar *) "Control"))
233
control_set_from_xml (group->control, child);
234
control_created = TRUE;
239
if (!control_created)
240
control_set_from_xml (group->control, NULL);
253
groups_set_from_xml (xmlNodePtr node)
262
/* children are "Group" nodes */
264
node = node->children;
266
DBG("expected number of panel items: %d", settings.num_groups);
268
for (i = 0; /* i < settings.num_groups || */ li || node; i++)
270
gboolean control_created = FALSE;
278
group = create_panel_group (i);
279
panel_group_pack (group, groupbox);
280
group_list = g_slist_append (group_list, group);
282
group->popup = create_panel_popup ();
284
group->control = control_new (i);
286
panel_group_arrange (group);
291
for (child = node->children; child; child = child->next)
293
/* create popup items and panel control */
294
if (xmlStrEqual (child->name, (const xmlChar *) "Popup"))
296
panel_popup_set_from_xml (group->popup, child);
299
(child->name, (const xmlChar *) "Control"))
301
control_set_from_xml (group->control, child);
302
control_created = TRUE;
307
if (!control_created)
308
control_set_from_xml (group->control, NULL);
317
settings.num_groups = g_slist_length (group_list);
319
DBG("actual number of panel items: %d", settings.num_groups);
323
groups_write_xml (xmlNodePtr root)
325
xmlNodePtr node, child;
329
node = xmlNewTextChild (root, NULL, "Groups", NULL);
331
for (li = group_list; li; li = li->next)
335
child = xmlNewTextChild (node, NULL, "Group", NULL);
337
panel_popup_write_xml (group->popup, child);
338
control_write_xml (group->control, child);
343
groups_pack (GtkBox * box)
350
for (li = group_list; li; li = li->next)
354
panel_group_pack (group, box);
355
panel_group_arrange (group);
365
for (li = group_list; li; li = li->next)
369
panel_group_unpack (group);
374
groups_register_control (Control * control)
378
group = g_slist_nth (group_list, control->index)->data;
380
group->control = control;
382
if (!control->with_popup)
383
groups_show_popup (control->index, FALSE);
385
groups_show_popup (control->index, TRUE);
387
panel_group_arrange (group);
391
groups_get_nth (int n)
397
len = g_slist_length (group_list);
406
li = g_slist_nth (group_list, index);
414
groups_get_control (int index)
418
group = groups_get_nth (index);
419
return group->control;
423
groups_get_popup (int index)
427
group = groups_get_nth (index);
432
groups_move (int from, int to)
438
if (from < 0 || from >= g_slist_length (group_list))
441
li = g_slist_nth (group_list, from);
444
gtk_box_reorder_child (groupbox, group->base, to);
446
group_list = g_slist_delete_link (group_list, li);
447
group_list = g_slist_insert (group_list, group, to);
449
for (i = 0, li = group_list; li; i++, li = li->next)
453
group->index = group->control->index = i;
458
groups_remove (int index)
464
li = g_slist_nth (group_list, index);
467
panel_group_unpack (group);
469
group_list = g_slist_delete_link (group_list, li);
471
panel_group_free (group);
473
settings.num_groups--;
475
for (i = 0, li = group_list; li; i++, li = li->next)
479
group->index = group->control->index = i;
484
groups_show_popup (int index, gboolean show)
489
li = g_slist_nth (group_list, index);
493
gtk_widget_show (group->popup->button);
495
gtk_widget_hide (group->popup->button);
500
groups_set_orientation (int orientation)
505
for (li = group_list; li; li = li->next)
509
control_set_orientation (group->control, orientation);
514
groups_set_layer (int layer)
519
for (li = group_list; li; li = li->next)
523
panel_popup_set_layer (group->popup, layer);
528
groups_set_size (int size)
533
for (li = group_list; li; li = li->next)
537
panel_popup_set_size (group->popup, size);
538
control_set_size (group->control, size);
543
groups_set_popup_position (int position)
548
for (li = group_list; li; li = li->next)
552
panel_group_arrange (group);
553
panel_popup_set_popup_position (group->popup, position);
558
groups_set_theme (const char *theme)
563
for (li = group_list; li; li = li->next)
567
panel_popup_set_theme (group->popup, theme);
568
control_set_theme (group->control, theme);
573
groups_add_control (int id, const char *filename, int index)
576
PanelGroup *group = NULL;
578
len = g_slist_length (group_list);
580
if (index < 0 || index > len)
583
group = create_panel_group (index);
584
panel_group_pack (group, groupbox);
585
group_list = g_slist_append (group_list, group);
587
group->popup = create_panel_popup ();
589
group->control = control_new (index);
590
create_control (group->control, id, filename);
592
panel_group_arrange (group);
594
if (index >= 0 && index < len)
595
groups_move (len, index);
597
if (!group->control->with_popup)
598
groups_show_popup (index, FALSE);
600
settings.num_groups++;
604
groups_set_num_groups (int n)
608
PanelGroup *group = NULL;
610
len = g_slist_length (group_list);
619
for (i = len; i < n; i++)
623
group = removed_list->data;
625
g_slist_delete_link (removed_list, removed_list);
627
panel_group_pack (group, groupbox);
628
group_list = g_slist_append (group_list, group);
630
panel_group_arrange (group);
631
settings.num_groups++;
635
groups_add_control (ICON, NULL, i);
638
gtk_widget_show (group->base);
644
/* removing group(s) */
645
li = g_slist_nth (group_list, n);
647
for (i = n; i < len; i++)
652
panel_group_unpack (group);
654
/* this sets the list to the next group */
658
group_list = g_slist_remove_link (group_list, li2);
659
removed_list = g_slist_prepend (removed_list, group);
660
settings.num_groups--;
664
/* arrow direction */
667
groups_set_arrow_direction (GtkArrowType type)
672
popup_arrow_type = type;
674
for (li = group_list; li; li = li->next)
678
panel_popup_set_arrow_type (group->popup, type);
683
groups_get_arrow_direction (void)
685
return popup_arrow_type;