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

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