diff options
author | Shawn Amundson <amundson@src.gnome.org> | 1998-01-18 23:01:09 +0000 |
---|---|---|
committer | Shawn Amundson <amundson@src.gnome.org> | 1998-01-18 23:01:09 +0000 |
commit | 67e67570691a9e11a9511ccd233c3243c7418da4 (patch) | |
tree | 4586090f7b9f83bb7f3e885d643ecfef9e70b731 /gtk | |
parent | 2dd1106130a2c3832b05e9d8aacbcff5abe98cd7 (diff) | |
download | gtk+-67e67570691a9e11a9511ccd233c3243c7418da4.tar.gz |
Statusbar widget. -Shawn
Statusbar widget.
-Shawn
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtkstatusbar.c | 166 | ||||
-rw-r--r-- | gtk/gtkstatusbar.h | 69 |
3 files changed, 237 insertions, 0 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index a6ace7c357..98ca2adaf1 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -71,6 +71,7 @@ libgtk_la_SOURCES = \ gtkseparator.c \ gtksignal.c \ gtkstyle.c \ + gtkstatusbar.c \ gtktable.c \ gtktext.c \ gtktogglebutton.c \ @@ -161,6 +162,7 @@ gtkinclude_HEADERS = \ gtkseparator.h \ gtksignal.h \ gtkstyle.h \ + gtkstatusbar.h \ gtktable.h \ gtktext.h \ gtktogglebutton.h \ diff --git a/gtk/gtkstatusbar.c b/gtk/gtkstatusbar.c new file mode 100644 index 0000000000..94f123bbfc --- /dev/null +++ b/gtk/gtkstatusbar.c @@ -0,0 +1,166 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "gtkframe.h" +#include "gtklabel.h" +#include "gtkstatusbar.h" + +static void gtk_statusbar_class_init (GtkStatusbarClass *class); +static void gtk_statusbar_init (GtkStatusbar *statusbar); +static void gtk_statusbar_destroy (GtkObject *object); +static void gtk_statusbar_show_top_msg (GtkStatusbar *statusbar); + +static GtkContainerClass *parent_class; + +guint +gtk_statusbar_get_type () +{ + static guint statusbar_type = 0; + + if (!statusbar_type) + { + GtkTypeInfo statusbar_info = + { + "GtkStatusbar", + sizeof (GtkStatusbar), + sizeof (GtkStatusbarClass), + (GtkClassInitFunc) gtk_statusbar_class_init, + (GtkObjectInitFunc) gtk_statusbar_init, + (GtkArgSetFunc) NULL, + (GtkArgGetFunc) NULL, + }; + + statusbar_type = gtk_type_unique (gtk_hbox_get_type (), &statusbar_info); + } + + return statusbar_type; +}; + +static void +gtk_statusbar_class_init (GtkStatusbarClass *class) +{ + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + GtkContainerClass *container_class; + + object_class = (GtkObjectClass *) class; + widget_class = (GtkWidgetClass *) class; + container_class = (GtkContainerClass *) class; + + parent_class = gtk_type_class (gtk_box_get_type ()); + + object_class->destroy = gtk_statusbar_destroy; + +} + +static void +gtk_statusbar_init (GtkStatusbar *statusbar) +{ + GTK_BOX (statusbar)->spacing = 2; + GTK_BOX (statusbar)->homogeneous = FALSE; + + statusbar->frame = gtk_frame_new(NULL); + gtk_frame_set_shadow_type(GTK_FRAME(statusbar->frame), GTK_SHADOW_IN); + gtk_box_pack_start(GTK_BOX(statusbar), statusbar->frame, 1,1,0); + + statusbar->label = gtk_label_new(""); + gtk_misc_set_alignment(GTK_MISC(statusbar->label), 0.0, 0.0); + gtk_container_add(GTK_CONTAINER(statusbar->frame), statusbar->label); + + statusbar->next_statusid = 1; + + statusbar->msgs = g_list_alloc(); +} + +GtkWidget* +gtk_statusbar_new () +{ + GtkStatusbar *statusbar; + + statusbar = gtk_type_new (gtk_statusbar_get_type ()); + + return GTK_WIDGET (statusbar); +} + +gint +gtk_statusbar_push (GtkStatusbar *statusbar, gchar *str) +{ + GtkStatusbarMsg *msg; + GList *list; + + list = statusbar->msgs; + msg = g_new(GtkStatusbarMsg, 1); + msg->str = g_strdup(str); + msg->statusid = statusbar->next_statusid; + statusbar->next_statusid++; + + g_list_append(list, msg); + + gtk_statusbar_show_top_msg(statusbar); + + return msg->statusid; +} + +static void +gtk_statusbar_show_top_msg (GtkStatusbar *statusbar) +{ + GList *listitem; + listitem = g_list_last(statusbar->msgs); + + + if ((listitem != NULL) && (listitem->data != NULL)) + gtk_label_set(GTK_LABEL(statusbar->label), ((GtkStatusbarMsg*) (listitem->data))->str); + +} + +void +gtk_statusbar_pop (GtkStatusbar *statusbar, gint statusid) +{ + GList *listitem; + + listitem = g_list_last(statusbar->msgs); + + + while ((listitem != NULL) && (listitem->data != NULL)) { + + if (((GtkStatusbarMsg*)(listitem->data))->statusid == statusid) { + g_list_remove(listitem, listitem->data); + break; + } + + listitem = listitem->prev; + } + + gtk_statusbar_show_top_msg(statusbar); +} + +static void +gtk_statusbar_destroy (GtkObject *object) +{ + GtkStatusbar *statusbar; + g_return_if_fail (object != NULL); + g_return_if_fail (GTK_IS_STATUSBAR (object)); + + statusbar = GTK_STATUSBAR (object); + g_list_free(statusbar->msgs); + + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + diff --git a/gtk/gtkstatusbar.h b/gtk/gtkstatusbar.h new file mode 100644 index 0000000000..08f7f96ecf --- /dev/null +++ b/gtk/gtkstatusbar.h @@ -0,0 +1,69 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef __GTK_STATUSBAR_H__ +#define __GTK_STATUSBAR_H_ + +#include <gtk/gtkhbox.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define GTK_STATUSBAR(obj) GTK_CHECK_CAST (obj, gtk_statusbar_get_type (), GtkStatusbar) +#define GTK_STATUSBAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_statusbar_get_type (), GtkStatusbarClass) +#define GTK_IS_STATUSBAR(obj) GTK_CHECK_TYPE (obj, gtk_statusbar_get_type ()) + +typedef struct _GtkStatusbar GtkStatusbar; +typedef struct _GtkStatusbarClass GtkStatusbarClass; +typedef struct _GtkStatusbarMsg GtkStatusbarMsg; + +struct _GtkStatusbar +{ + GtkHBox parent_widget; + + GtkWidget *frame; + GtkWidget *label; + GList *msgs; + + gint next_statusid; +}; + +struct _GtkStatusbarClass +{ + GtkHBoxClass parent_class; +}; + +struct _GtkStatusbarMsg +{ + gchar *str; + gint statusid; +}; + +guint gtk_statusbar_get_type (void); +GtkWidget* gtk_statusbar_new (void); + +/* Returns StatusID used for gtk_statusbar_push */ +gint gtk_statusbar_push (GtkStatusbar *statusbar, + gchar *text); + +void gtk_statusbar_pop (GtkStatusbar *statusbar, + gint statusid); + +#endif /* __GTK_STATUSBAR_H_ */ |