]> www.fi.muni.cz Git - evince.git/blob - shell/ev-statusbar.c
Fix tooltip border and size handling
[evince.git] / shell / ev-statusbar.c
1 /* this file is part of evince, a gnome document viewer
2  *
3  *  Copyright (C) 2004 Red Hat, Inc.
4  *
5  *  Author:
6  *    Jonathan Blandford <jrb@alum.mit.edu>
7  *
8  * Evince is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Evince is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <string.h>
28 #include <gtk/gtk.h>
29
30 #include "ev-statusbar.h"
31
32 struct _EvStatusbarPrivate {
33         GtkWidget *bar;
34         GtkWidget *progress;
35
36         guint help_message_cid;
37         guint view_message_cid;
38         guint progress_message_cid;
39         
40         guint pulse_timeout_id;
41         guint progress_timeout_id;
42 };
43
44 G_DEFINE_TYPE (EvStatusbar, ev_statusbar, GTK_TYPE_HBOX)
45
46 #define EV_STATUSBAR_GET_PRIVATE(object) \
47                 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_STATUSBAR, EvStatusbarPrivate))
48
49 static void
50 ev_statusbar_destroy (GtkObject *object)
51 {
52         EvStatusbar *ev_statusbar = EV_STATUSBAR (object);
53         
54         ev_statusbar_set_progress (ev_statusbar, FALSE);
55         
56         (* GTK_OBJECT_CLASS (ev_statusbar_parent_class)->destroy) (object);
57 }
58
59 static void
60 ev_statusbar_class_init (EvStatusbarClass *ev_statusbar_class)
61 {
62         GObjectClass *g_object_class;
63         GtkWidgetClass *widget_class;
64         GtkObjectClass *gtk_object_klass;
65  
66         g_object_class = G_OBJECT_CLASS (ev_statusbar_class);
67         widget_class = GTK_WIDGET_CLASS (ev_statusbar_class);
68         gtk_object_klass = GTK_OBJECT_CLASS (ev_statusbar_class);
69            
70         g_type_class_add_private (g_object_class, sizeof (EvStatusbarPrivate));
71            
72         gtk_object_klass->destroy = ev_statusbar_destroy;
73 }
74
75 static void
76 ev_statusbar_init (EvStatusbar *ev_statusbar)
77 {
78         ev_statusbar->priv = EV_STATUSBAR_GET_PRIVATE (ev_statusbar);
79
80         ev_statusbar->priv->progress = gtk_progress_bar_new ();
81         gtk_box_pack_start (GTK_BOX (ev_statusbar), ev_statusbar->priv->progress, FALSE, FALSE, 3);
82         ev_statusbar->priv->bar = gtk_statusbar_new ();
83         gtk_box_pack_start (GTK_BOX (ev_statusbar), ev_statusbar->priv->bar, TRUE, TRUE, 0);
84             
85         ev_statusbar->priv->help_message_cid = gtk_statusbar_get_context_id
86                 (GTK_STATUSBAR (ev_statusbar->priv->bar), "help_message");
87         ev_statusbar->priv->view_message_cid = gtk_statusbar_get_context_id
88                 (GTK_STATUSBAR (ev_statusbar->priv->bar), "view_message");
89         ev_statusbar->priv->progress_message_cid = gtk_statusbar_get_context_id
90                 (GTK_STATUSBAR (ev_statusbar->priv->bar), "progress_message");
91     
92         gtk_widget_show (GTK_WIDGET (ev_statusbar->priv->bar));
93         gtk_widget_show (GTK_WIDGET (ev_statusbar));
94         
95         ev_statusbar->priv->progress_timeout_id = 0;
96         ev_statusbar->priv->pulse_timeout_id = 0;
97 }
98
99 /* Public functions */
100
101 GtkWidget *
102 ev_statusbar_new (void)
103 {
104         GtkWidget *ev_statusbar;
105
106         ev_statusbar = g_object_new (EV_TYPE_STATUSBAR, NULL);
107
108         return ev_statusbar;
109 }
110
111 static guint 
112 ev_statusbar_get_context_id (EvStatusbar *statusbar, EvStatusbarContext context)
113 {
114     switch (context) {
115         case EV_CONTEXT_HELP:
116                 return statusbar->priv->help_message_cid;
117         case EV_CONTEXT_VIEW:
118                 return statusbar->priv->view_message_cid;
119         case EV_CONTEXT_PROGRESS:
120                 return statusbar->priv->progress_message_cid;
121     }
122     return -1;
123 }
124
125 void
126 ev_statusbar_push    (EvStatusbar *ev_statusbar, 
127                       EvStatusbarContext context, 
128                       const gchar *message)
129 {
130         gtk_statusbar_push (GTK_STATUSBAR (ev_statusbar->priv->bar),
131                             ev_statusbar_get_context_id (ev_statusbar, context), 
132                             message);
133         return;
134 }
135
136 void
137 ev_statusbar_pop     (EvStatusbar *ev_statusbar, 
138                       EvStatusbarContext context)
139 {
140         gtk_statusbar_pop (GTK_STATUSBAR (ev_statusbar->priv->bar),
141                            ev_statusbar_get_context_id (ev_statusbar, context));
142         return;
143 }
144
145 void 
146 ev_statusbar_set_maximized (EvStatusbar *ev_statusbar, 
147                             gboolean maximized)
148 {
149        gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (ev_statusbar->priv->bar),
150                                           maximized);
151        return;
152 }
153
154 static gboolean
155 ev_statusbar_pulse (gpointer data) 
156 {
157     EvStatusbar *ev_statusbar = EV_STATUSBAR (data);
158     
159     gtk_progress_bar_pulse (GTK_PROGRESS_BAR (ev_statusbar->priv->progress));
160     
161     return TRUE;
162 }
163
164 static gboolean
165 ev_statusbar_show_progress (gpointer data)
166 {
167     EvStatusbar *ev_statusbar = EV_STATUSBAR (data);
168
169     gtk_widget_show (ev_statusbar->priv->progress);
170     ev_statusbar->priv->pulse_timeout_id = g_timeout_add (300, ev_statusbar_pulse, ev_statusbar);
171     ev_statusbar->priv->progress_timeout_id = 0;
172
173     return FALSE;
174 }
175
176 void
177 ev_statusbar_set_progress  (EvStatusbar *ev_statusbar, 
178                             gboolean active)
179 {
180     if (active){
181             if (ev_statusbar->priv->progress_timeout_id == 0 
182                         && ev_statusbar->priv->pulse_timeout_id == 0)
183                     ev_statusbar->priv->progress_timeout_id = 
184                             g_timeout_add (500, ev_statusbar_show_progress, ev_statusbar);
185     } else {
186             if (ev_statusbar->priv->pulse_timeout_id) {
187                     g_source_remove (ev_statusbar->priv->pulse_timeout_id);
188                     gtk_widget_hide (ev_statusbar->priv->progress);
189             }
190
191             if (ev_statusbar->priv->progress_timeout_id)
192                     g_source_remove (ev_statusbar->priv->progress_timeout_id);
193
194             ev_statusbar->priv->progress_timeout_id = 0;
195             ev_statusbar->priv->pulse_timeout_id = 0;
196             
197     }
198 }
199
200
201