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
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.
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.
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.
22 #include "gtkstatusbar.h"
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);
29 static GtkContainerClass *parent_class;
32 gtk_statusbar_get_type ()
34 static guint statusbar_type = 0;
38 GtkTypeInfo statusbar_info =
41 sizeof (GtkStatusbar),
42 sizeof (GtkStatusbarClass),
43 (GtkClassInitFunc) gtk_statusbar_class_init,
44 (GtkObjectInitFunc) gtk_statusbar_init,
49 statusbar_type = gtk_type_unique (gtk_hbox_get_type (), &statusbar_info);
52 return statusbar_type;
56 gtk_statusbar_class_init (GtkStatusbarClass *class)
58 GtkObjectClass *object_class;
59 GtkWidgetClass *widget_class;
60 GtkContainerClass *container_class;
62 object_class = (GtkObjectClass *) class;
63 widget_class = (GtkWidgetClass *) class;
64 container_class = (GtkContainerClass *) class;
66 parent_class = gtk_type_class (gtk_box_get_type ());
68 object_class->destroy = gtk_statusbar_destroy;
73 gtk_statusbar_init (GtkStatusbar *statusbar)
75 GTK_BOX (statusbar)->spacing = 2;
76 GTK_BOX (statusbar)->homogeneous = FALSE;
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);
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);
86 statusbar->next_statusid = 1;
88 statusbar->msgs = g_list_alloc();
94 GtkStatusbar *statusbar;
96 statusbar = gtk_type_new (gtk_statusbar_get_type ());
98 return GTK_WIDGET (statusbar);
102 gtk_statusbar_push (GtkStatusbar *statusbar, gchar *str)
104 GtkStatusbarMsg *msg;
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++;
113 g_list_append(list, msg);
115 gtk_statusbar_show_top_msg(statusbar);
117 return msg->statusid;
121 gtk_statusbar_show_top_msg (GtkStatusbar *statusbar)
124 listitem = g_list_last(statusbar->msgs);
127 if ((listitem != NULL) && (listitem->data != NULL))
128 gtk_label_set(GTK_LABEL(statusbar->label), ((GtkStatusbarMsg*) (listitem->data))->str);
133 gtk_statusbar_pop (GtkStatusbar *statusbar, gint statusid)
137 listitem = g_list_last(statusbar->msgs);
140 while ((listitem != NULL) && (listitem->data != NULL)) {
142 if (((GtkStatusbarMsg*)(listitem->data))->statusid == statusid) {
143 g_list_remove(listitem, listitem->data);
147 listitem = listitem->prev;
150 gtk_statusbar_show_top_msg(statusbar);
154 gtk_statusbar_destroy (GtkObject *object)
156 GtkStatusbar *statusbar;
157 g_return_if_fail (object != NULL);
158 g_return_if_fail (GTK_IS_STATUSBAR (object));
160 statusbar = GTK_STATUSBAR (object);
161 g_list_free(statusbar->msgs);
163 if (GTK_OBJECT_CLASS (parent_class)->destroy)
164 (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);