]> Pileus Git - ~andy/gtk/blob - gtk/gtkstatusbar.c
Statusbar widget. -Shawn
[~andy/gtk] / gtk / gtkstatusbar.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library 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  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free
17  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "gtkframe.h"
21 #include "gtklabel.h"
22 #include "gtkstatusbar.h"
23
24 static void gtk_statusbar_class_init               (GtkStatusbarClass *class);
25 static void gtk_statusbar_init                     (GtkStatusbar      *statusbar);
26 static void gtk_statusbar_destroy                  (GtkObject         *object);
27 static void gtk_statusbar_show_top_msg             (GtkStatusbar *statusbar);
28
29 static GtkContainerClass *parent_class;
30
31 guint      
32 gtk_statusbar_get_type ()
33 {
34   static guint statusbar_type = 0;
35
36   if (!statusbar_type)
37     {
38       GtkTypeInfo statusbar_info =
39       {
40         "GtkStatusbar",
41         sizeof (GtkStatusbar),
42         sizeof (GtkStatusbarClass),
43         (GtkClassInitFunc) gtk_statusbar_class_init,
44         (GtkObjectInitFunc) gtk_statusbar_init,
45         (GtkArgSetFunc) NULL,
46         (GtkArgGetFunc) NULL,
47       };
48
49       statusbar_type = gtk_type_unique (gtk_hbox_get_type (), &statusbar_info);
50     }
51
52   return statusbar_type;
53 };
54
55 static void
56 gtk_statusbar_class_init (GtkStatusbarClass *class)
57 {
58   GtkObjectClass *object_class;
59   GtkWidgetClass *widget_class;
60   GtkContainerClass *container_class;
61
62   object_class = (GtkObjectClass *) class;
63   widget_class = (GtkWidgetClass *) class;
64   container_class = (GtkContainerClass *) class;
65
66   parent_class = gtk_type_class (gtk_box_get_type ());
67
68   object_class->destroy = gtk_statusbar_destroy;
69
70 }
71
72 static void
73 gtk_statusbar_init (GtkStatusbar *statusbar)
74 {
75   GTK_BOX (statusbar)->spacing = 2;
76   GTK_BOX (statusbar)->homogeneous = FALSE;
77
78   statusbar->frame = gtk_frame_new(NULL);
79   gtk_frame_set_shadow_type(GTK_FRAME(statusbar->frame), GTK_SHADOW_IN);
80   gtk_box_pack_start(GTK_BOX(statusbar), statusbar->frame, 1,1,0);
81
82   statusbar->label = gtk_label_new("");
83   gtk_misc_set_alignment(GTK_MISC(statusbar->label), 0.0, 0.0);
84   gtk_container_add(GTK_CONTAINER(statusbar->frame), statusbar->label);
85
86   statusbar->next_statusid = 1;
87
88   statusbar->msgs = g_list_alloc();
89 }
90
91 GtkWidget* 
92 gtk_statusbar_new ()
93 {
94   GtkStatusbar *statusbar;
95
96   statusbar = gtk_type_new (gtk_statusbar_get_type ());
97
98   return GTK_WIDGET (statusbar);
99 }
100
101 gint
102 gtk_statusbar_push (GtkStatusbar *statusbar, gchar *str)
103 {
104   GtkStatusbarMsg *msg;
105   GList *list;
106
107   list = statusbar->msgs;
108   msg = g_new(GtkStatusbarMsg, 1);
109   msg->str = g_strdup(str);
110   msg->statusid = statusbar->next_statusid;
111   statusbar->next_statusid++;
112
113   g_list_append(list, msg);
114
115   gtk_statusbar_show_top_msg(statusbar);
116
117   return msg->statusid;
118 }
119
120 static void
121 gtk_statusbar_show_top_msg (GtkStatusbar *statusbar)
122 {
123   GList *listitem;
124   listitem = g_list_last(statusbar->msgs);
125
126
127   if ((listitem != NULL)  && (listitem->data != NULL)) 
128     gtk_label_set(GTK_LABEL(statusbar->label), ((GtkStatusbarMsg*) (listitem->data))->str);
129
130 }
131
132 void
133 gtk_statusbar_pop (GtkStatusbar *statusbar, gint statusid) 
134 {
135   GList *listitem;
136
137   listitem = g_list_last(statusbar->msgs);
138
139
140   while ((listitem != NULL) && (listitem->data != NULL)) {
141     
142     if (((GtkStatusbarMsg*)(listitem->data))->statusid == statusid) {
143       g_list_remove(listitem, listitem->data);
144       break;
145     }
146
147     listitem = listitem->prev;
148   }
149  
150   gtk_statusbar_show_top_msg(statusbar);
151 }
152
153 static void
154 gtk_statusbar_destroy (GtkObject *object)
155 {
156   GtkStatusbar *statusbar;
157   g_return_if_fail (object != NULL);
158   g_return_if_fail (GTK_IS_STATUSBAR (object));
159
160   statusbar = GTK_STATUSBAR (object);
161   g_list_free(statusbar->msgs);
162
163   if (GTK_OBJECT_CLASS (parent_class)->destroy)
164     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
165 }
166