source: trunk/third/evolution/shell/e-task-bar.c @ 16787

Revision 16787, 4.8 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r16786, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* e-task-bar.c
3 *
4 * Copyright (C) 2001  Ximian, Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
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 GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * Author: Ettore Perazzoli <ettore@ximian.com>
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include "e-task-bar.h"
28
29#include <gal/util/e-util.h>
30
31
32#define PARENT_TYPE gtk_hbox_get_type ()
33static GtkHBoxClass *parent_class = NULL;
34
35
36/* WARNING: Ugly hack starts here.  */
37
38#define MAX_ACTIVITIES_PER_COMPONENT 2
39
40static void
41reduce_displayed_activities_per_component (ETaskBar *task_bar)
42{
43        GHashTable *component_ids_hash;
44        GtkBox *box;
45        GList *p;
46
47        component_ids_hash = g_hash_table_new (g_str_hash, g_str_equal);
48
49        box = GTK_BOX (task_bar);
50
51        for (p = box->children; p != NULL; p = p->next) {
52                GtkBoxChild *child;
53                const char *component_id;
54                void *hash_item;
55
56                child = (GtkBoxChild *) p->data;
57                component_id = e_task_widget_get_component_id (E_TASK_WIDGET (child->widget));
58
59                hash_item = g_hash_table_lookup (component_ids_hash, component_id);
60
61                if (hash_item == NULL) {
62                        gtk_widget_show (child->widget);
63                        g_hash_table_insert (component_ids_hash, (void *) component_id, GINT_TO_POINTER (1));
64                } else {
65                        int num_items;
66
67                        num_items = GPOINTER_TO_INT (hash_item);
68                        g_assert (num_items <= MAX_ACTIVITIES_PER_COMPONENT);
69
70                        if (num_items == MAX_ACTIVITIES_PER_COMPONENT) {
71                                gtk_widget_hide (child->widget);
72                        } else {
73                                num_items ++;
74                                gtk_widget_show (child->widget);
75                                g_hash_table_insert (component_ids_hash, (void *) component_id, GINT_TO_POINTER (num_items));
76                        }
77                }
78        }
79
80        g_hash_table_destroy (component_ids_hash);
81}
82
83
84/* GtkObject methods.  */
85
86static void
87impl_destroy (GtkObject *object)
88{
89        ETaskBar *task_bar;
90
91        task_bar = E_TASK_BAR (object);
92
93        /* Nothing to do here.  */
94
95        (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
96}
97
98
99static void
100class_init (GtkObjectClass *object_class)
101{
102        parent_class = gtk_type_class (PARENT_TYPE);
103
104        object_class->destroy = impl_destroy;
105}
106
107static void
108init (ETaskBar *task_bar)
109{
110        /* Nothing to do here.  */
111}
112
113
114void
115e_task_bar_construct (ETaskBar *task_bar)
116{
117        g_return_if_fail (task_bar != NULL);
118        g_return_if_fail (E_IS_TASK_BAR (task_bar));
119
120        /* Nothing to do here.  */
121}
122
123GtkWidget *
124e_task_bar_new (void)
125{
126        ETaskBar *task_bar;
127
128        task_bar = gtk_type_new (e_task_bar_get_type ());
129        e_task_bar_construct (task_bar);
130
131        return GTK_WIDGET (task_bar);
132}
133
134void
135e_task_bar_prepend_task (ETaskBar *task_bar,
136                         ETaskWidget *task_widget)
137{
138        GtkBoxChild *child_info;
139        GtkBox *box;
140
141        g_return_if_fail (task_bar != NULL);
142        g_return_if_fail (E_IS_TASK_BAR (task_bar));
143        g_return_if_fail (task_widget != NULL);
144        g_return_if_fail (E_IS_TASK_WIDGET (task_widget));
145
146        /* Hah hah.  GTK+ sucks.  This is adapted from `gtkhbox.c'.  */
147
148        child_info = g_new (GtkBoxChild, 1);
149        child_info->widget = GTK_WIDGET (task_widget);
150        child_info->padding = 0;
151        child_info->expand = TRUE;
152        child_info->fill = TRUE;
153        child_info->pack = GTK_PACK_START;
154
155        box = GTK_BOX (task_bar);
156
157        box->children = g_list_prepend (box->children, child_info);
158
159        gtk_widget_set_parent (GTK_WIDGET (task_widget), GTK_WIDGET (task_bar));
160
161        if (GTK_WIDGET_REALIZED (task_bar))
162                gtk_widget_realize (GTK_WIDGET (task_widget));
163
164        if (GTK_WIDGET_VISIBLE (task_bar) && GTK_WIDGET_VISIBLE (task_widget)) {
165                if (GTK_WIDGET_MAPPED (task_bar))
166                        gtk_widget_map (GTK_WIDGET (task_widget));
167                gtk_widget_queue_resize (GTK_WIDGET (task_widget));
168        }
169
170        reduce_displayed_activities_per_component (task_bar);
171}
172
173void
174e_task_bar_remove_task (ETaskBar *task_bar,
175                        int n)
176{
177        ETaskWidget *task_widget;
178
179        g_return_if_fail (task_bar != NULL);
180        g_return_if_fail (E_IS_TASK_BAR (task_bar));
181        g_return_if_fail (n >= 0);
182
183        task_widget = e_task_bar_get_task_widget (task_bar, n);
184        gtk_widget_destroy (GTK_WIDGET (task_widget));
185
186        reduce_displayed_activities_per_component (task_bar);
187}
188       
189ETaskWidget *
190e_task_bar_get_task_widget (ETaskBar *task_bar,
191                            int n)
192{
193        GtkBoxChild *child_info;
194
195        g_return_val_if_fail (task_bar != NULL, NULL);
196        g_return_val_if_fail (E_IS_TASK_BAR (task_bar), NULL);
197
198        child_info = (GtkBoxChild *) g_list_nth (GTK_BOX (task_bar)->children, n)->data;
199
200        return E_TASK_WIDGET (child_info->widget);
201}
202
203
204E_MAKE_TYPE (e_task_bar, "ETaskBar", ETaskBar, class_init, init, PARENT_TYPE)
Note: See TracBrowser for help on using the repository browser.