Permalink
Browse files

Revert "Drop usage of the GtkStatusbar."

This reverts commit 185821a.
  • Loading branch information...
1 parent ff0faf3 commit 6bdfbdf87e4ac5ffd528b6daafd9755acfe04415 @codebrainz committed Oct 3, 2011
Showing with 38 additions and 35 deletions.
  1. +23 −31 mousepad/mousepad-statusbar.c
  2. +0 −2 mousepad/mousepad-statusbar.h
  3. +15 −2 mousepad/mousepad-window.c
@@ -39,20 +39,19 @@ enum
struct _MousepadStatusbarClass
{
- GtkHBoxClass __parent__;
+ GtkStatusbarClass __parent__;
};
struct _MousepadStatusbar
{
- GtkHBox __parent__;
+ GtkStatusbar __parent__;
/* whether overwrite is enabled */
- guint overwrite_enabled : 1;
+ guint overwrite_enabled : 1;
/* extra labels in the statusbar */
- GtkWidget *tooltip;
- GtkWidget *position;
- GtkWidget *overwrite;
+ GtkWidget *position;
+ GtkWidget *overwrite;
};
@@ -61,7 +60,7 @@ static guint statusbar_signals[LAST_SIGNAL];
-G_DEFINE_TYPE (MousepadStatusbar, mousepad_statusbar, GTK_TYPE_HBOX);
+G_DEFINE_TYPE (MousepadStatusbar, mousepad_statusbar, GTK_TYPE_STATUSBAR);
@@ -94,38 +93,41 @@ mousepad_statusbar_class_init (MousepadStatusbarClass *klass)
static void
mousepad_statusbar_init (MousepadStatusbar *statusbar)
{
- GtkWidget *ebox, *separator;
+ GtkWidget *ebox, *box, *separator;
+ GtkStatusbar *bar = GTK_STATUSBAR (statusbar);
/* init statusbar */
- gtk_box_set_spacing (GTK_BOX (statusbar), 6);
- gtk_container_set_border_width (GTK_CONTAINER (statusbar), 2);
+ gtk_statusbar_set_has_resize_grip (bar, TRUE);
- /* tooltip label */
- statusbar->tooltip = gtk_label_new (NULL);
- gtk_misc_set_alignment (GTK_MISC (statusbar->tooltip), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (statusbar), statusbar->tooltip, TRUE, TRUE, 0);
- gtk_label_set_ellipsize (GTK_LABEL (statusbar->tooltip), PANGO_ELLIPSIZE_END);
- gtk_label_set_single_line_mode (GTK_LABEL (statusbar->tooltip), TRUE);
- gtk_widget_show (statusbar->tooltip);
+ /* create a new horizontal box */
+ box = gtk_hbox_new (FALSE, 8);
+ gtk_widget_show (box);
+
+ /* reorder the gtk statusbar */
+ g_object_ref (G_OBJECT (bar->label));
+ gtk_container_remove (GTK_CONTAINER (bar->frame), bar->label);
+ gtk_container_add (GTK_CONTAINER (bar->frame), box);
+ gtk_box_pack_start (GTK_BOX (box), bar->label, TRUE, TRUE, 0);
+ g_object_unref (G_OBJECT (bar->label));
/* separator */
separator = gtk_vseparator_new ();
- gtk_box_pack_start (GTK_BOX (statusbar), separator, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
gtk_widget_show (separator);
/* line and column numbers */
statusbar->position = gtk_label_new (NULL);
- gtk_box_pack_start (GTK_BOX (statusbar), statusbar->position, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), statusbar->position, FALSE, TRUE, 0);
gtk_widget_show (statusbar->position);
/* separator */
separator = gtk_vseparator_new ();
- gtk_box_pack_start (GTK_BOX (statusbar), separator, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
gtk_widget_show (separator);
/* overwrite event box */
ebox = gtk_event_box_new ();
- gtk_box_pack_start (GTK_BOX (statusbar), ebox, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (box), ebox, FALSE, TRUE, 0);
gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE);
mousepad_widget_set_tooltip_text (ebox, _("Toggle the overwrite mode"));
g_signal_connect (G_OBJECT (ebox), "button-press-event", G_CALLBACK (mousepad_statusbar_overwrite_clicked), statusbar);
@@ -193,13 +195,3 @@ mousepad_statusbar_set_overwrite (MousepadStatusbar *statusbar,
statusbar->overwrite_enabled = overwrite;
}
-
-
-
-void
-mousepad_statusbar_set_tooltip (MousepadStatusbar *statusbar,
- const gchar *tooltip)
-{
- mousepad_return_if_fail (MOUSEPAD_IS_STATUSBAR (statusbar));
- gtk_label_set_text (GTK_LABEL (statusbar->tooltip), tooltip);
-}
@@ -41,8 +41,6 @@ void mousepad_statusbar_set_cursor_position (MousepadStatusbar *statusba
void mousepad_statusbar_set_overwrite (MousepadStatusbar *statusbar,
gboolean overwrite);
-void mousepad_statusbar_set_tooltip (MousepadStatusbar *statusbar,
- const gchar *tooltip);
G_END_DECLS
#endif /* !__MOUSEPAD_STATUSBAR_H__ */
View
@@ -820,7 +820,9 @@ mousepad_window_menu_item_selected (GtkWidget *menu_item,
{
GtkAction *action;
gchar *tooltip;
+ gint id;
+ /* we can only display tooltips if we have a statusbar */
if (G_LIKELY (window->statusbar != NULL))
{
/* get the action from the menu item */
@@ -836,7 +838,11 @@ mousepad_window_menu_item_selected (GtkWidget *menu_item,
if (G_LIKELY (tooltip != NULL))
{
- mousepad_statusbar_set_tooltip (MOUSEPAD_STATUSBAR (window->statusbar), tooltip);
+ /* show the tooltip */
+ id = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->statusbar), "tooltip");
+ gtk_statusbar_push (GTK_STATUSBAR (window->statusbar), id, tooltip);
+
+ /* cleanup */
g_free (tooltip);
}
}
@@ -849,8 +855,15 @@ static void
mousepad_window_menu_item_deselected (GtkWidget *menu_item,
MousepadWindow *window)
{
+ gint id;
+
+ /* we can only undisplay tooltips if we have a statusbar */
if (G_LIKELY (window->statusbar != NULL))
- mousepad_statusbar_set_tooltip (MOUSEPAD_STATUSBAR (window->statusbar), NULL);
+ {
+ /* drop the last tooltip from the statusbar */
+ id = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->statusbar), "tooltip");
+ gtk_statusbar_pop (GTK_STATUSBAR (window->statusbar), id);
+ }
}

0 comments on commit 6bdfbdf

Please sign in to comment.