[Xfce4-commits] <mousepad:nick_0_3> Drop usage of the GtkStatusbar.
Nick Schermer
noreply at xfce.org
Sat Oct 16 17:58:01 CEST 2010
Updating branch refs/heads/nick_0_3
to 185821ae262235222f7ef1d3a86dc0ea2b19bbd9 (commit)
from 385535209b957746bec3d29818bc1d4490df35e3 (commit)
commit 185821ae262235222f7ef1d3a86dc0ea2b19bbd9
Author: Nick Schermer <nick at xfce.org>
Date: Fri Oct 15 16:19:40 2010 +0200
Drop usage of the GtkStatusbar.
Only shows a lot of errors. Because of this we loose the
resize grip for now, but in gtk3 this will be possible again.
mousepad/mousepad-statusbar.c | 54 +++++++++++++++++++++++-----------------
mousepad/mousepad-statusbar.h | 2 +
mousepad/mousepad-window.c | 17 +-----------
3 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/mousepad/mousepad-statusbar.c b/mousepad/mousepad-statusbar.c
index 0321c3e..dc4503f 100644
--- a/mousepad/mousepad-statusbar.c
+++ b/mousepad/mousepad-statusbar.c
@@ -39,19 +39,20 @@ enum
struct _MousepadStatusbarClass
{
- GtkStatusbarClass __parent__;
+ GtkHBoxClass __parent__;
};
struct _MousepadStatusbar
{
- GtkStatusbar __parent__;
+ GtkHBox __parent__;
/* whether overwrite is enabled */
- guint overwrite_enabled : 1;
+ guint overwrite_enabled : 1;
/* extra labels in the statusbar */
- GtkWidget *position;
- GtkWidget *overwrite;
+ GtkWidget *tooltip;
+ GtkWidget *position;
+ GtkWidget *overwrite;
};
@@ -60,7 +61,7 @@ static guint statusbar_signals[LAST_SIGNAL];
-G_DEFINE_TYPE (MousepadStatusbar, mousepad_statusbar, GTK_TYPE_STATUSBAR);
+G_DEFINE_TYPE (MousepadStatusbar, mousepad_statusbar, GTK_TYPE_HBOX);
@@ -93,41 +94,38 @@ mousepad_statusbar_class_init (MousepadStatusbarClass *klass)
static void
mousepad_statusbar_init (MousepadStatusbar *statusbar)
{
- GtkWidget *ebox, *box, *separator;
- GtkStatusbar *bar = GTK_STATUSBAR (statusbar);
+ GtkWidget *ebox, *separator;
/* init statusbar */
- gtk_statusbar_set_has_resize_grip (bar, TRUE);
+ gtk_box_set_spacing (GTK_BOX (statusbar), 6);
+ gtk_container_set_border_width (GTK_CONTAINER (statusbar), 2);
- /* 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));
+ /* 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);
/* separator */
separator = gtk_vseparator_new ();
- gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (statusbar), separator, FALSE, FALSE, 0);
gtk_widget_show (separator);
/* line and column numbers */
statusbar->position = gtk_label_new (NULL);
- gtk_box_pack_start (GTK_BOX (box), statusbar->position, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (statusbar), statusbar->position, FALSE, TRUE, 0);
gtk_widget_show (statusbar->position);
/* separator */
separator = gtk_vseparator_new ();
- gtk_box_pack_start (GTK_BOX (box), separator, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (statusbar), separator, FALSE, FALSE, 0);
gtk_widget_show (separator);
/* overwrite event box */
ebox = gtk_event_box_new ();
- gtk_box_pack_start (GTK_BOX (box), ebox, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (statusbar), 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);
@@ -195,3 +193,13 @@ 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);
+}
diff --git a/mousepad/mousepad-statusbar.h b/mousepad/mousepad-statusbar.h
index c44b54e..0a4fcf1 100644
--- a/mousepad/mousepad-statusbar.h
+++ b/mousepad/mousepad-statusbar.h
@@ -41,6 +41,8 @@ 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__ */
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 1c284a1..deb9696 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -820,9 +820,7 @@ 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 */
@@ -838,11 +836,7 @@ mousepad_window_menu_item_selected (GtkWidget *menu_item,
if (G_LIKELY (tooltip != NULL))
{
- /* show the tooltip */
- id = gtk_statusbar_get_context_id (GTK_STATUSBAR (window->statusbar), "tooltip");
- gtk_statusbar_push (GTK_STATUSBAR (window->statusbar), id, tooltip);
-
- /* cleanup */
+ mousepad_statusbar_set_tooltip (MOUSEPAD_STATUSBAR (window->statusbar), tooltip);
g_free (tooltip);
}
}
@@ -855,15 +849,8 @@ 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))
- {
- /* 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);
- }
+ mousepad_statusbar_set_tooltip (MOUSEPAD_STATUSBAR (window->statusbar), NULL);
}
More information about the Xfce4-commits
mailing list