* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include "gtkframe.h"
#include "gtklabel.h"
#include "gtkmarshalers.h"
#include "gtkstatusbar.h"
#include "gtkwindow.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkalias.h"
SIGNAL_LAST
};
-enum
+enum
{
- PROP_ZERO,
+ PROP_0,
PROP_HAS_RESIZE_GRIP
};
-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_update (GtkStatusbar *statusbar,
guint context_id,
GtkAllocation *allocation);
static void gtk_statusbar_direction_changed (GtkWidget *widget,
GtkTextDirection prev_dir);
+static void gtk_statusbar_state_changed (GtkWidget *widget,
+ GtkStateType previous_state);
static void gtk_statusbar_create_window (GtkStatusbar *statusbar);
static void gtk_statusbar_destroy_window (GtkStatusbar *statusbar);
static void gtk_statusbar_get_property (GObject *object,
gpointer data);
-static GtkContainerClass *parent_class;
static guint statusbar_signals[SIGNAL_LAST] = { 0 };
-GType
-gtk_statusbar_get_type (void)
-{
- static GType statusbar_type = 0;
-
- if (!statusbar_type)
- {
- static const GTypeInfo statusbar_info =
- {
- sizeof (GtkStatusbarClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_statusbar_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkStatusbar),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_statusbar_init,
- };
-
- statusbar_type = g_type_register_static (GTK_TYPE_HBOX, "GtkStatusbar",
- &statusbar_info, 0);
- }
-
- return statusbar_type;
-}
+G_DEFINE_TYPE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX)
static void
gtk_statusbar_class_init (GtkStatusbarClass *class)
GObjectClass *gobject_class;
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
gobject_class = (GObjectClass *) class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
- container_class = (GtkContainerClass *) class;
- parent_class = g_type_class_peek_parent (class);
-
gobject_class->set_property = gtk_statusbar_set_property;
gobject_class->get_property = gtk_statusbar_get_property;
widget_class->unrealize = gtk_statusbar_unrealize;
widget_class->map = gtk_statusbar_map;
widget_class->unmap = gtk_statusbar_unmap;
-
widget_class->button_press_event = gtk_statusbar_button_press;
widget_class->expose_event = gtk_statusbar_expose_event;
-
widget_class->size_request = gtk_statusbar_size_request;
widget_class->size_allocate = gtk_statusbar_size_allocate;
-
widget_class->direction_changed = gtk_statusbar_direction_changed;
+ widget_class->state_changed = gtk_statusbar_state_changed;
- class->messages_mem_chunk = g_mem_chunk_new ("GtkStatusbar messages mem chunk",
- sizeof (GtkStatusbarMsg),
- sizeof (GtkStatusbarMsg) * 64,
- G_ALLOC_AND_FREE);
-
class->text_pushed = gtk_statusbar_update;
class->text_popped = gtk_statusbar_update;
P_("Has Resize Grip"),
P_("Whether the statusbar has a grip for resizing the toplevel"),
TRUE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkStatusbar::text-pushed:
+ * @statusbar: the object which received the signal.
+ * @context_id: the context id of the relevant message/statusbar.
+ * @text: the message that was pushed.
+ *
+ * Is emitted whenever a new message gets pushed onto a statusbar's stack.
+ */
statusbar_signals[SIGNAL_TEXT_PUSHED] =
- g_signal_new ("text_pushed",
+ g_signal_new (I_("text-pushed"),
G_OBJECT_CLASS_TYPE (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
G_TYPE_NONE, 2,
G_TYPE_UINT,
G_TYPE_STRING);
+
+ /**
+ * GtkStatusbar::text-popped:
+ * @statusbar: the object which received the signal.
+ * @context_id: the context id of the relevant message/statusbar.
+ * @text: the message that was just popped.
+ *
+ * Is emitted whenever a new message is popped off a statusbar's stack.
+ */
statusbar_signals[SIGNAL_TEXT_POPPED] =
- g_signal_new ("text_popped",
+ g_signal_new (I_("text-popped"),
G_OBJECT_CLASS_TYPE (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
P_("Style of bevel around the statusbar text"),
GTK_TYPE_SHADOW_TYPE,
GTK_SHADOW_IN,
- G_PARAM_READABLE));
+ GTK_PARAM_READABLE));
}
static void
statusbar->has_resize_grip = TRUE;
- gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow_type", &shadow_type, NULL);
+ gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
statusbar->frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
statusbar->keys = NULL;
}
+/**
+ * gtk_statusbar_new:
+ *
+ * Creates a new #GtkStatusbar ready for messages.
+ *
+ * Returns: the new #GtkStatusbar
+ */
GtkWidget*
gtk_statusbar_new (void)
{
gtk_label_set_text (GTK_LABEL (statusbar->label), text);
}
+/**
+ * gtk_statusbar_get_context_id:
+ * @statusbar: a #GtkStatusbar
+ * @context_description: textual description of what context
+ * the new message is being used in
+ *
+ * Returns a new context identifier, given a description
+ * of the actual context. Note that the description is
+ * <emphasis>not</emphasis> shown in the UI.
+ *
+ * Returns: an integer id
+ */
guint
gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
const gchar *context_description)
{
gchar *string;
- guint *id;
+ guint id;
g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
g_return_val_if_fail (context_description != NULL, 0);
/* we need to preserve namespaces on object datas */
string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
- id = g_object_get_data (G_OBJECT (statusbar), string);
- if (!id)
+ id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string));
+ if (id == 0)
{
- id = g_new (guint, 1);
- *id = statusbar->seq_context_id++;
- g_object_set_data_full (G_OBJECT (statusbar), string, id, g_free);
+ id = statusbar->seq_context_id++;
+ g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL);
statusbar->keys = g_slist_prepend (statusbar->keys, string);
}
else
g_free (string);
- return *id;
+ return id;
}
+/**
+ * gtk_statusbar_push:
+ * @statusbar: a #GtkStatusbar
+ * @context_id: the message's context id, as returned by
+ * gtk_statusbar_get_context_id()
+ * @text: the message to add to the statusbar
+ *
+ * Pushes a new message onto a statusbar's stack.
+ *
+ * Returns: a message id that can be used with
+ * gtk_statusbar_remove().
+ */
guint
gtk_statusbar_push (GtkStatusbar *statusbar,
guint context_id,
const gchar *text)
{
GtkStatusbarMsg *msg;
- GtkStatusbarClass *class;
g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
g_return_val_if_fail (text != NULL, 0);
- class = GTK_STATUSBAR_GET_CLASS (statusbar);
- msg = g_chunk_new (GtkStatusbarMsg, class->messages_mem_chunk);
+ msg = g_slice_new (GtkStatusbarMsg);
msg->text = g_strdup (text);
msg->context_id = context_id;
msg->message_id = statusbar->seq_message_id++;
return msg->message_id;
}
+/**
+ * gtk_statusbar_pop:
+ * @statusbar: a #GtkStatusBar
+ * @context_id: a context identifier
+ *
+ * Removes the first message in the #GtkStatusBar's stack
+ * with the given context id.
+ *
+ * Note that this may not change the displayed message, if
+ * the message at the top of the stack has a different
+ * context id.
+ */
void
gtk_statusbar_pop (GtkStatusbar *statusbar,
guint context_id)
if (msg->context_id == context_id)
{
- GtkStatusbarClass *class;
-
- class = GTK_STATUSBAR_GET_CLASS (statusbar);
-
statusbar->messages = g_slist_remove_link (statusbar->messages,
list);
g_free (msg->text);
- g_mem_chunk_free (class->messages_mem_chunk, msg);
+ g_slice_free (GtkStatusbarMsg, msg);
g_slist_free_1 (list);
break;
}
msg ? msg->text : NULL);
}
+/**
+ * gtk_statusbar_remove:
+ * @statusbar: a #GtkStatusBar
+ * @context_id: a context identifier
+ * @message_id: a message identifier, as returned by gtk_statusbar_push()
+ *
+ * Forces the removal of a message from a statusbar's stack.
+ * The exact @context_id and @message_id must be specified.
+ */
void
gtk_statusbar_remove (GtkStatusbar *statusbar,
guint context_id,
if (msg->context_id == context_id &&
msg->message_id == message_id)
{
- GtkStatusbarClass *class;
-
- class = GTK_STATUSBAR_GET_CLASS (statusbar);
statusbar->messages = g_slist_remove_link (statusbar->messages, list);
g_free (msg->text);
- g_mem_chunk_free (class->messages_mem_chunk, msg);
+ g_slice_free (GtkStatusbarMsg, msg);
g_slist_free_1 (list);
break;
}
}
+/**
+ * gtk_statusbar_set_has_resize_grip:
+ * @statusbar: a #GtkStatusBar
+ * @setting: %TRUE to have a resize grip
+ *
+ * Sets whether the statusbar has a resize grip.
+ * %TRUE by default.
+ */
void
gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
gboolean setting)
gtk_statusbar_destroy_window (statusbar);
}
- g_object_notify (G_OBJECT (statusbar), "has_resize_grip");
+ g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
}
}
+/**
+ * gtk_statusbar_get_has_resize_grip:
+ * @statusbar: a #GtkStatusBar
+ *
+ * Returns whether the statusbar has a resize grip.
+ *
+ * Returns: %TRUE if the statusbar has a resize grip.
+ */
gboolean
gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
{
static void
gtk_statusbar_destroy (GtkObject *object)
{
- GtkStatusbar *statusbar;
- GtkStatusbarClass *class;
+ GtkStatusbar *statusbar = GTK_STATUSBAR (object);
GSList *list;
- g_return_if_fail (GTK_IS_STATUSBAR (object));
-
- statusbar = GTK_STATUSBAR (object);
- class = GTK_STATUSBAR_GET_CLASS (statusbar);
-
for (list = statusbar->messages; list; list = list->next)
{
GtkStatusbarMsg *msg;
msg = list->data;
g_free (msg->text);
- g_mem_chunk_free (class->messages_mem_chunk, msg);
+ g_slice_free (GtkStatusbarMsg, msg);
}
g_slist_free (statusbar->messages);
statusbar->messages = NULL;
g_slist_free (statusbar->keys);
statusbar->keys = NULL;
- GTK_OBJECT_CLASS (parent_class)->destroy (object);
+ GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
}
static void
GdkCursorType cursor_type;
GdkCursor *cursor;
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
- cursor_type = GDK_BOTTOM_RIGHT_CORNER;
+ if (GTK_WIDGET_IS_SENSITIVE (widget))
+ {
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
+ cursor_type = GDK_BOTTOM_RIGHT_CORNER;
+ else
+ cursor_type = GDK_BOTTOM_LEFT_CORNER;
+
+ cursor = gdk_cursor_new_for_display (display, cursor_type);
+ gdk_window_set_cursor (statusbar->grip_window, cursor);
+ gdk_cursor_unref (cursor);
+ }
else
- cursor_type = GDK_BOTTOM_LEFT_CORNER;
-
- cursor = gdk_cursor_new_for_display (display, cursor_type);
- gdk_window_set_cursor (statusbar->grip_window, cursor);
- gdk_cursor_unref (cursor);
+ gdk_window_set_cursor (statusbar->grip_window, NULL);
}
}
set_grip_cursor (statusbar);
}
+static void
+gtk_statusbar_state_changed (GtkWidget *widget,
+ GtkStateType previous_state)
+{
+ GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
+
+ set_grip_cursor (statusbar);
+}
+
static void
gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
{
GtkStatusbar *statusbar;
statusbar = GTK_STATUSBAR (widget);
-
- (* GTK_WIDGET_CLASS (parent_class)->realize) (widget);
+
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
if (statusbar->has_resize_grip)
gtk_statusbar_create_window (statusbar);
if (statusbar->grip_window)
gtk_statusbar_destroy_window (statusbar);
-
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize (widget);
}
static void
GtkStatusbar *statusbar;
statusbar = GTK_STATUSBAR (widget);
-
- (* GTK_WIDGET_CLASS (parent_class)->map) (widget);
-
+
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map (widget);
+
if (statusbar->grip_window)
gdk_window_show (statusbar->grip_window);
}
if (statusbar->grip_window)
gdk_window_hide (statusbar->grip_window);
-
- (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget);
+
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap (widget);
}
static gboolean
statusbar = GTK_STATUSBAR (widget);
- GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
if (statusbar->has_resize_grip)
{
gtk_paint_resize_grip (widget->style,
widget->window,
GTK_WIDGET_STATE (widget),
- NULL,
+ &event->area,
widget,
"statusbar",
edge,
}
static void
-gtk_statusbar_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+gtk_statusbar_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
GtkStatusbar *statusbar;
GtkShadowType shadow_type;
statusbar = GTK_STATUSBAR (widget);
- gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow_type", &shadow_type, NULL);
+ gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
- GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
}
/* look for extra children between the frame containing
GList *l;
GtkBoxChild *child, *frame;
+ /* If the internal frame has been modified assume we have extra children */
+ if (gtk_bin_get_child (GTK_BIN (statusbar->frame)) != statusbar->label)
+ return TRUE;
+
frame = NULL;
for (l = GTK_BOX (statusbar)->children; l; l = l->next)
{
if (statusbar->has_resize_grip)
{
- widget->allocation = *allocation;
get_grip_rect (statusbar, &rect);
extra_children = has_extra_children (statusbar);
allocation->x += rect.width;
}
}
-
+
/* chain up normally */
- GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation);
+ GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
if (statusbar->has_resize_grip)
{
}
else
{
- /* shrink the label to make room for the grip */
- *allocation = statusbar->label->allocation;
- allocation->width -= rect.width;
- if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
- allocation->x += rect.width;
-
- gtk_widget_size_allocate (statusbar->label, allocation);
+ GtkWidget *child;
+
+ /* Use the frame's child instead of statusbar->label directly, in case
+ * the label has been replaced by a container as the frame's child
+ * (and the label reparented into that container).
+ */
+ child = gtk_bin_get_child (GTK_BIN (statusbar->frame));
+
+ if (child->allocation.width + rect.width > statusbar->frame->allocation.width)
+ {
+ /* shrink the label to make room for the grip */
+ *allocation = child->allocation;
+ allocation->width = MAX (1, allocation->width - rect.width);
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ allocation->x += child->allocation.width - allocation->width;
+
+ gtk_widget_size_allocate (child, allocation);
+ }
}
}
}