aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2000-05-16 11:39:44 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2000-05-16 11:39:44 +0800
commit062b4e53c4d29699c7a2f040efeace29e74e5427 (patch)
tree29729730411b51f805f9036190c03e9b139e7b60 /widgets/misc
parente4720a7e38d3073570df95fbd98481109d53b3a8 (diff)
downloadgsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.tar
gsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.tar.gz
gsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.tar.bz2
gsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.tar.lz
gsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.tar.xz
gsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.tar.zst
gsoc2013-evolution-062b4e53c4d29699c7a2f040efeace29e74e5427.zip
New `ETitleBar' widget. Also, moved the `EClippedLabel' widget out of
the `EShortcutBar' directory. svn path=/trunk/; revision=3053
Diffstat (limited to 'widgets/misc')
-rw-r--r--widgets/misc/.cvsignore8
-rw-r--r--widgets/misc/Makefile.am27
-rw-r--r--widgets/misc/e-clipped-label.c361
-rw-r--r--widgets/misc/e-clipped-label.h90
-rw-r--r--widgets/misc/e-title-bar.c268
-rw-r--r--widgets/misc/e-title-bar.h79
-rw-r--r--widgets/misc/test-title-bar.c73
7 files changed, 906 insertions, 0 deletions
diff --git a/widgets/misc/.cvsignore b/widgets/misc/.cvsignore
new file mode 100644
index 0000000000..47f6730268
--- /dev/null
+++ b/widgets/misc/.cvsignore
@@ -0,0 +1,8 @@
+.deps
+.libs
+.pure
+Makefile
+Makefile.in
+*.lo
+*.la
+test-title-bar
diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am
new file mode 100644
index 0000000000..c3599c98a6
--- /dev/null
+++ b/widgets/misc/Makefile.am
@@ -0,0 +1,27 @@
+# FIXME we use the EClippedLabel widget from EShortcutBar. Probably
+# it should be moved somewhere else.
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/widgets/shortcut-bar \
+ $(EXTRA_GNOME_CFLAGS) \
+ -DG_LOG_DOMAIN=\"e-title-bar\"
+
+noinst_LIBRARIES = \
+ libemiscwidgets.a
+
+libemiscwidgets_a_SOURCES = \
+ e-clipped-label.c \
+ e-clipped-label.h \
+ e-title-bar.c \
+ e-title-bar.h
+
+noinst_PROGRAMS = \
+ test-title-bar
+
+test_title_bar_SOURCES = \
+ test-title-bar.c
+
+test_title_bar_LDADD = \
+ ./libemiscwidgets.a \
+ $(EXTRA_GNOME_LIBS)
diff --git a/widgets/misc/e-clipped-label.c b/widgets/misc/e-clipped-label.c
new file mode 100644
index 0000000000..e6666ae451
--- /dev/null
+++ b/widgets/misc/e-clipped-label.c
@@ -0,0 +1,361 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * Author :
+ * Damon Chaplin <damon@helixcode.com>
+ *
+ * Copyright 1999, Helix Code, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+/*
+ * This is similar to GtkLabel but clips itself and displays '...' if it
+ * can't fit inside its allocated area. The intended use is for inside buttons
+ * that are a fixed size. The GtkLabel would normally display only the middle
+ * part of the text, which doesn't look very good. This only supports one line
+ * of text (so no wrapping/justification), without underlined characters.
+ */
+
+#include <math.h>
+
+#include <gdk/gdki18n.h>
+#include <libgnome/gnome-defs.h>
+#include <libgnome/gnome-i18n.h>
+
+#include "e-clipped-label.h"
+
+
+static void e_clipped_label_class_init (EClippedLabelClass *class);
+static void e_clipped_label_init (EClippedLabel *label);
+static void e_clipped_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition);
+static void e_clipped_label_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static gint e_clipped_label_expose (GtkWidget *widget,
+ GdkEventExpose *event);
+static void e_clipped_label_recalc_chars_displayed (EClippedLabel *label);
+
+
+static GtkMiscClass *parent_class;
+
+/* This is the string to draw when the label is clipped, e.g. '...'. */
+static gchar *e_clipped_label_ellipsis;
+
+/* Flags used in chars_displayed field. Must be negative. */
+#define E_CLIPPED_LABEL_NEED_RECALC -1
+#define E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL -2
+
+
+GtkType
+e_clipped_label_get_type (void)
+{
+ static GtkType e_clipped_label_type = 0;
+
+ if (!e_clipped_label_type){
+ GtkTypeInfo e_clipped_label_info = {
+ "EClippedLabel",
+ sizeof (EClippedLabel),
+ sizeof (EClippedLabelClass),
+ (GtkClassInitFunc) e_clipped_label_class_init,
+ (GtkObjectInitFunc) e_clipped_label_init,
+ NULL, /* reserved 1 */
+ NULL, /* reserved 2 */
+ (GtkClassInitFunc) NULL
+ };
+
+ parent_class = gtk_type_class (GTK_TYPE_MISC);
+ e_clipped_label_type = gtk_type_unique (GTK_TYPE_MISC,
+ &e_clipped_label_info);
+ }
+
+ return e_clipped_label_type;
+}
+
+
+static void
+e_clipped_label_class_init (EClippedLabelClass *class)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = (GtkObjectClass *) class;
+ widget_class = (GtkWidgetClass *) class;
+
+ /* Method override */
+ widget_class->size_request = e_clipped_label_size_request;
+ widget_class->size_allocate = e_clipped_label_size_allocate;
+ widget_class->expose_event = e_clipped_label_expose;
+
+ e_clipped_label_ellipsis = _("...");
+}
+
+
+static void
+e_clipped_label_init (EClippedLabel *label)
+{
+ GTK_WIDGET_SET_FLAGS (label, GTK_NO_WINDOW);
+
+ label->label = NULL;
+ label->label_wc = NULL;
+ label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC;
+}
+
+
+/**
+ * e_clipped_label_new:
+ *
+ * @text: The label text.
+ * @Returns: A new #EClippedLabel.
+ *
+ * Creates a new #EClippedLabel with the given text.
+ **/
+GtkWidget *
+e_clipped_label_new (const gchar *text)
+{
+ GtkWidget *label;
+
+ label = GTK_WIDGET (gtk_type_new (e_clipped_label_get_type ()));
+
+ if (text && *text)
+ e_clipped_label_set_text (E_CLIPPED_LABEL (label), text);
+
+ return label;
+}
+
+
+static void
+e_clipped_label_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EClippedLabel *label;
+ GdkFont *font;
+
+ g_return_if_fail (E_IS_CLIPPED_LABEL (widget));
+ g_return_if_fail (requisition != NULL);
+
+ label = E_CLIPPED_LABEL (widget);
+ font = widget->style->font;
+
+ requisition->width = 0;
+ requisition->height = font->ascent + font->descent
+ + 2 * GTK_MISC (widget)->ypad;
+}
+
+
+static void
+e_clipped_label_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ EClippedLabel *label;
+
+ label = E_CLIPPED_LABEL (widget);
+
+ widget->allocation = *allocation;
+
+ /* Flag that we need to recalculate how many characters to display. */
+ label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC;
+}
+
+
+static gint
+e_clipped_label_expose (GtkWidget *widget,
+ GdkEventExpose *event)
+{
+ EClippedLabel *label;
+ GtkMisc *misc;
+ gint x, y;
+ GdkFont *font;
+ gchar *tmp_str, tmp_ch;
+
+ g_return_val_if_fail (E_IS_CLIPPED_LABEL (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ label = E_CLIPPED_LABEL (widget);
+ misc = GTK_MISC (widget);
+ font = widget->style->font;
+
+ /* If the label isn't visible or has no text, just return. */
+ if (!GTK_WIDGET_VISIBLE (widget) || !GTK_WIDGET_MAPPED (widget)
+ || !label->label || (*label->label == '\0'))
+ return TRUE;
+
+ /* Recalculate the number of characters displayed, if necessary. */
+ if (label->chars_displayed == E_CLIPPED_LABEL_NEED_RECALC)
+ e_clipped_label_recalc_chars_displayed (label);
+
+ /*
+ * GC Clipping
+ */
+ gdk_gc_set_clip_rectangle (widget->style->white_gc,
+ &event->area);
+ gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state],
+ &event->area);
+
+ y = floor (widget->allocation.y + (gint)misc->ypad
+ + (((gint)widget->allocation.height - 2 * (gint)misc->ypad
+ - (gint)font->ascent - font->descent)
+ * misc->yalign) + 0.5) + font->ascent;
+
+ if (label->chars_displayed == E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL) {
+ x = floor (widget->allocation.x + (gint)misc->xpad
+ + (((gint)widget->allocation.width -
+ (gint)label->label_width - 2 * (gint)misc->xpad)
+ * misc->xalign) + 0.5);
+
+ gtk_paint_string (widget->style, widget->window, widget->state,
+ &event->area, widget, "label",
+ x, y, label->label);
+ } else {
+ x = widget->allocation.x + (gint)misc->xpad;
+
+ tmp_ch = label->label_wc[label->chars_displayed];
+ label->label_wc[label->chars_displayed] = '\0';
+ tmp_str = gdk_wcstombs (label->label_wc);
+ if (tmp_str) {
+ gtk_paint_string (widget->style, widget->window,
+ widget->state, &event->area,
+ widget, "label",
+ x, y, tmp_str);
+ g_free (tmp_str);
+ }
+ label->label_wc[label->chars_displayed] = tmp_ch;
+
+ x = widget->allocation.x + (gint)misc->xpad
+ + label->ellipsis_x;
+ gtk_paint_string (widget->style, widget->window, widget->state,
+ &event->area, widget, "label",
+ x, y, e_clipped_label_ellipsis);
+ }
+
+ gdk_gc_set_clip_mask (widget->style->white_gc, NULL);
+ gdk_gc_set_clip_mask (widget->style->fg_gc[widget->state], NULL);
+
+ return TRUE;
+}
+
+
+/**
+ * e_clipped_label_get_text:
+ *
+ * @label: An #EClippedLabel.
+ * @Return: The label text.
+ *
+ * Returns the label text, or NULL.
+ **/
+gchar*
+e_clipped_label_get_text (EClippedLabel *label)
+{
+ g_return_val_if_fail (E_IS_CLIPPED_LABEL (label), NULL);
+
+ return label->label;
+}
+
+
+/**
+ * e_clipped_label_set_text:
+ *
+ * @label: An #EClippedLabel.
+ * @text: The new label text.
+ *
+ * Sets the label text.
+ **/
+void
+e_clipped_label_set_text (EClippedLabel *label,
+ const gchar *text)
+{
+ gint len;
+
+ g_return_if_fail (E_IS_CLIPPED_LABEL (label));
+
+ if (label->label != text || !label->label || !text
+ || strcmp (label->label, text)) {
+ g_free (label->label);
+ g_free (label->label_wc);
+ label->label = NULL;
+ label->label_wc = NULL;
+
+ if (text) {
+ label->label = g_strdup (text);
+ len = strlen (text);
+ label->label_wc = g_new (GdkWChar, len + 1);
+ label->wc_len = gdk_mbstowcs (label->label_wc,
+ label->label, len + 1);
+ label->label_wc[label->wc_len] = '\0';
+ }
+
+ /* Reset the number of characters displayed, so it is
+ recalculated when needed. */
+ label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC;
+
+ /* We don't queue a resize, since the label should not affect
+ the widget size, but we queue a draw. */
+ gtk_widget_queue_draw (GTK_WIDGET (label));
+ }
+}
+
+
+static void
+e_clipped_label_recalc_chars_displayed (EClippedLabel *label)
+{
+ GdkFont *font;
+ gint max_width, width, ch, last_width;
+
+ font = GTK_WIDGET (label)->style->font;
+
+ max_width = GTK_WIDGET (label)->allocation.width
+ - 2 * GTK_MISC (label)->xpad;
+
+ if (!label->label) {
+ label->chars_displayed = 0;
+ return;
+ }
+
+ /* See if the entire label fits in the allocated width. */
+ label->label_width = gdk_string_width (font, label->label);
+ if (label->label_width <= max_width) {
+ label->chars_displayed = E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL;
+ return;
+ }
+
+ /* Calculate the width of the ellipsis string. */
+ max_width -= gdk_string_measure (font, e_clipped_label_ellipsis);
+
+ if (max_width <= 0) {
+ label->chars_displayed = 0;
+ label->ellipsis_x = 0;
+ return;
+ }
+
+ /* Step through the wide-char label, adding on the widths of the
+ characters, until we can't fit any more in. */
+ width = last_width = 0;
+ for (ch = 0; ch < label->wc_len; ch++) {
+ width += gdk_char_width_wc (font, label->label_wc[ch]);
+
+ if (width > max_width) {
+ label->chars_displayed = ch;
+ label->ellipsis_x = last_width;
+ return;
+ }
+
+ last_width = width;
+ }
+
+ g_warning ("Clipped label width not exceeded as expected");
+ label->chars_displayed = E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL;
+}
+
diff --git a/widgets/misc/e-clipped-label.h b/widgets/misc/e-clipped-label.h
new file mode 100644
index 0000000000..a21ceadeca
--- /dev/null
+++ b/widgets/misc/e-clipped-label.h
@@ -0,0 +1,90 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * Author :
+ * Damon Chaplin <damon@helixcode.com>
+ *
+ * Copyright 1999, Helix Code, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+/*
+ * This is similar to GtkLabel but clips itself and displays '...' if it
+ * can't fit inside its allocated area. The intended use is for inside buttons
+ * that are a fixed size. The GtkLabel would normally display only the middle
+ * part of the text, which doesn't look very good. This only supports one line
+ * of text (so no wrapping/justification), without underlined characters.
+ */
+#ifndef _E_CLIPPED_LABEL_H_
+#define _E_CLIPPED_LABEL_H_
+
+#include <gtk/gtkmisc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define E_CLIPPED_LABEL(obj) GTK_CHECK_CAST (obj, e_clipped_label_get_type (), EClippedLabel)
+#define E_CLIPPED_LABEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_clipped_label_get_type (), EClippedLabelClass)
+#define E_IS_CLIPPED_LABEL(obj) GTK_CHECK_TYPE (obj, e_clipped_label_get_type ())
+
+
+typedef struct _EClippedLabel EClippedLabel;
+typedef struct _EClippedLabelClass EClippedLabelClass;
+
+struct _EClippedLabel
+{
+ GtkMisc misc;
+
+ gchar *label;
+ GdkWChar *label_wc;
+
+ /* This is the number of wide characters in the label. */
+ gint wc_len;
+
+ /* This is the width of the entire label string, in pixels. */
+ gint label_width;
+
+ /* This is the number of characters we can fit in, or
+ E_CLIPPED_LABEL_NEED_RECALC if it needs to be recalculated, or
+ E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL to show the entire label. */
+ gint chars_displayed;
+
+ /* This is the x position to display the ellipsis string, e.g. '...',
+ relative to the start of the label. */
+ gint ellipsis_x;
+};
+
+struct _EClippedLabelClass
+{
+ GtkMiscClass parent_class;
+};
+
+
+GtkType e_clipped_label_get_type (void);
+GtkWidget* e_clipped_label_new (const gchar *text);
+
+gchar* e_clipped_label_get_text (EClippedLabel *label);
+void e_clipped_label_set_text (EClippedLabel *label,
+ const gchar *text);
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _E_CLIPPED_LABEL_H_ */
diff --git a/widgets/misc/e-title-bar.c b/widgets/misc/e-title-bar.c
new file mode 100644
index 0000000000..a161e8145a
--- /dev/null
+++ b/widgets/misc/e-title-bar.c
@@ -0,0 +1,268 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-title-bar.c
+ *
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ettore Perazzoli
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtkbox.h>
+#include <gtk/gtkbutton.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkpixmap.h>
+#include <gtk/gtksignal.h>
+#include <gtk/gtktypeutils.h>
+
+#include "e-util/e-util.h"
+#include "e-clipped-label.h"
+
+#include "e-title-bar.h"
+
+
+enum {
+ TITLE_BUTTON_PRESS_EVENT,
+ CLOSE_BUTTON_CLICKED,
+ LAST_SIGNAL
+};
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+static char *close_button_xpm[] = {
+ "12 12 2 1",
+ " c none",
+ ". c #000000000000",
+ " ",
+ " .. .. ",
+ " ... ... ",
+ " ... ... ",
+ " ...... ",
+ " .... ",
+ " .... ",
+ " ...... ",
+ " ... ... ",
+ " ... ... ",
+ " .. .. ",
+ " "
+};
+
+#define PARENT_TYPE GTK_TYPE_FRAME
+static GtkFrameClass *parent_class = NULL;
+
+struct _ETitleBarPrivate {
+ GtkWidget *label;
+ GtkWidget *close_button;
+ GtkWidget *close_button_gtk_pixmap;
+};
+
+
+/* Child signal callbacks. */
+
+static void
+close_button_realize_cb (GtkWidget *widget,
+ gpointer data)
+{
+ GdkPixmap *close_button_pixmap;
+ GdkBitmap *close_button_mask;
+ ETitleBar *title_bar;
+ ETitleBarPrivate *priv;
+
+ title_bar = E_TITLE_BAR (data);
+ priv = title_bar->priv;
+
+ if (priv->close_button_gtk_pixmap != NULL)
+ return;
+
+ close_button_pixmap = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (priv->close_button)->window,
+ &close_button_mask,
+ NULL, close_button_xpm);
+ priv->close_button_gtk_pixmap = gtk_pixmap_new (close_button_pixmap, close_button_mask);
+
+ gtk_container_add (GTK_CONTAINER (priv->close_button), priv->close_button_gtk_pixmap);
+ gtk_widget_show (priv->close_button_gtk_pixmap);
+}
+
+static void
+close_button_clicked_cb (GtkButton *button,
+ gpointer data)
+{
+ ETitleBar *title_bar;
+
+ title_bar = E_TITLE_BAR (data);
+
+ gtk_signal_emit (GTK_OBJECT (title_bar), signals[CLOSE_BUTTON_CLICKED]);
+}
+
+static void
+label_button_press_event_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer data)
+{
+ ETitleBar *title_bar;
+
+ title_bar = E_TITLE_BAR (data);
+
+ gtk_signal_emit (GTK_OBJECT (title_bar), signals[TITLE_BUTTON_PRESS_EVENT], event);
+}
+
+
+/* GtkObject methods. */
+
+static void
+destroy (GtkObject *object)
+{
+ ETitleBar *title_bar;
+ ETitleBarPrivate *priv;
+
+ title_bar = E_TITLE_BAR (object);
+ priv = title_bar->priv;
+
+ g_free (priv);
+
+ (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+}
+
+
+static void
+class_init (ETitleBarClass *klass)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass*) klass;
+ object_class->destroy = destroy;
+
+ parent_class = gtk_type_class (gtk_frame_get_type ());
+
+ signals[TITLE_BUTTON_PRESS_EVENT] =
+ gtk_signal_new ("title_button_press_event",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETitleBarClass, title_button_press_event),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_GDK_EVENT);
+
+ signals[CLOSE_BUTTON_CLICKED] =
+ gtk_signal_new ("close_button_clicked",
+ GTK_RUN_FIRST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (ETitleBarClass, close_button_clicked),
+ gtk_marshal_NONE__NONE,
+ GTK_TYPE_NONE, 0);
+
+ gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
+}
+
+static void
+init (ETitleBar *title_bar)
+{
+ ETitleBarPrivate *priv;
+
+ priv = g_new (ETitleBarPrivate, 1);
+
+ priv->label = NULL;
+ priv->close_button = NULL;
+ priv->close_button_gtk_pixmap = NULL;
+
+ title_bar->priv = priv;
+}
+
+
+void
+e_title_bar_construct (ETitleBar *title_bar,
+ const char *title)
+{
+ ETitleBarPrivate *priv;
+ GtkWidget *hbox;
+
+ g_return_if_fail (title_bar != NULL);
+ g_return_if_fail (E_IS_TITLE_BAR (title_bar));
+
+ priv = title_bar->priv;
+
+ priv->label = e_clipped_label_new (title);
+ gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
+ gtk_widget_show (priv->label);
+
+ priv->close_button = gtk_button_new ();
+ GTK_WIDGET_UNSET_FLAGS (priv->close_button, GTK_CAN_FOCUS);
+ gtk_container_set_border_width (GTK_CONTAINER (priv->close_button), 1);
+ gtk_button_set_relief (GTK_BUTTON (priv->close_button), GTK_RELIEF_NONE);
+ gtk_widget_show (priv->close_button);
+
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 2);
+ gtk_box_pack_start (GTK_BOX (hbox), priv->close_button, FALSE, TRUE, 1);
+ gtk_widget_show (hbox);
+
+ gtk_container_add (GTK_CONTAINER (title_bar), hbox);
+
+ gtk_signal_connect (GTK_OBJECT (priv->close_button), "realize",
+ GTK_SIGNAL_FUNC (close_button_realize_cb), title_bar);
+ gtk_signal_connect (GTK_OBJECT (priv->close_button), "clicked",
+ GTK_SIGNAL_FUNC (close_button_clicked_cb), title_bar);
+ gtk_signal_connect (GTK_OBJECT (priv->label), "button_press_event",
+ GTK_SIGNAL_FUNC (label_button_press_event_cb), title_bar);
+}
+
+GtkWidget *
+e_title_bar_new (const char *title)
+{
+ ETitleBar *title_bar;
+
+ title_bar = gtk_type_new (e_title_bar_get_type ());
+
+ e_title_bar_construct (title_bar, title);
+
+ return GTK_WIDGET (title_bar);
+}
+
+
+void
+e_title_bar_set_title (ETitleBar *title_bar,
+ const char *title)
+{
+ g_return_if_fail (title_bar != NULL);
+ g_return_if_fail (E_IS_TITLE_BAR (title_bar));
+
+ gtk_label_set_text (GTK_LABEL (title_bar->priv->label), title);
+}
+
+void
+e_title_bar_show_close_button (ETitleBar *title_bar,
+ gboolean show)
+{
+ ETitleBarPrivate *priv;
+
+ g_return_if_fail (title_bar != NULL);
+ g_return_if_fail (E_IS_TITLE_BAR (title_bar));
+
+ priv = title_bar->priv;
+
+ if (show)
+ gtk_widget_show (priv->close_button);
+ else
+ gtk_widget_hide (priv->close_button);
+}
+
+
+E_MAKE_TYPE (e_title_bar, "ETitleBar", ETitleBar, class_init, init, PARENT_TYPE)
diff --git a/widgets/misc/e-title-bar.h b/widgets/misc/e-title-bar.h
new file mode 100644
index 0000000000..ce7d23b07b
--- /dev/null
+++ b/widgets/misc/e-title-bar.h
@@ -0,0 +1,79 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-title-bar.h
+ *
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ettore Perazzoli
+ */
+
+#ifndef __E_TITLE_BAR_H__
+#define __E_TITLE_BAR_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtkframe.h>
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+#define E_TYPE_TITLE_BAR (e_title_bar_get_type ())
+#define E_TITLE_BAR(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TITLE_BAR, ETitleBar))
+#define E_TITLE_BAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TITLE_BAR, ETitleBarClass))
+#define E_IS_TITLE_BAR(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TITLE_BAR))
+#define E_IS_TITLE_BAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_TITLE_BAR))
+
+
+typedef struct _ETitleBar ETitleBar;
+typedef struct _ETitleBarPrivate ETitleBarPrivate;
+typedef struct _ETitleBarClass ETitleBarClass;
+
+struct _ETitleBar {
+ GtkFrame parent;
+
+ ETitleBarPrivate *priv;
+};
+
+struct _ETitleBarClass {
+ GtkFrameClass parent_class;
+
+ /* Signals. */
+
+ void (* title_button_press_event) (ETitleBar *title_bar, GdkEventButton *event);
+ void (* close_button_clicked) (ETitleBar *title_bar);
+};
+
+
+GtkType e_title_bar_get_type (void);
+void e_title_bar_construct (ETitleBar *title_bar,
+ const char *title);
+GtkWidget *e_title_bar_new (const char *title);
+
+void e_title_bar_set_title (ETitleBar *title_bar,
+ const char *title);
+void e_title_bar_show_close_button (ETitleBar *title_bar,
+ gboolean show);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __E_TITLE_BAR_H__ */
diff --git a/widgets/misc/test-title-bar.c b/widgets/misc/test-title-bar.c
new file mode 100644
index 0000000000..fdca1ae0db
--- /dev/null
+++ b/widgets/misc/test-title-bar.c
@@ -0,0 +1,73 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* e-title-bar.c
+ *
+ * Copyright (C) 2000 Helix Code, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ettore Perazzoli
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gnome.h>
+
+#include "e-title-bar.h"
+
+static void
+delete_event_cb (GtkWidget *widget,
+ GdkEventAny *event,
+ gpointer data)
+{
+ gtk_main_quit ();
+}
+
+int
+main (int argc, char **argv)
+{
+ GtkWidget *app;
+ GtkWidget *title_bar;
+ GtkWidget *text;
+ GtkWidget *vbox;
+
+ gnome_init ("test-title-bar", "0.0", argc, argv);
+
+ app = gnome_app_new ("Test", "Test");
+ gtk_window_set_default_size (GTK_WINDOW (app), 400, 400);
+ gtk_window_set_policy (GTK_WINDOW (app), FALSE, TRUE, FALSE);
+
+ gtk_signal_connect (GTK_OBJECT (app), "delete_event", GTK_SIGNAL_FUNC (delete_event_cb), NULL);
+
+ title_bar = e_title_bar_new ("This is a very annoyingly long title bar");
+ gtk_widget_show (title_bar);
+
+ text = gtk_text_new (NULL, NULL);
+ gtk_widget_show (text);
+
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), title_bar, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), text, TRUE, TRUE, 0);
+ gtk_widget_show (vbox);
+
+ gnome_app_set_contents (GNOME_APP (app), vbox);
+ gtk_widget_show (app);
+
+ gtk_main ();
+
+ return 0;
+}