switch to GtklLabel for statusbar buttons + remove non nedded resize-grip code
- fixes the large statusbar with GTK3 - remove extra resize-grip code, which is handle by gtk+ itself GTK2 builds displays the resize-grip without the extra code. Since GTK+-3.14 the rezise-grip widget is removed. - the size of the statusbar is now themable
This commit is contained in:
parent
42f9f19d30
commit
e1b2a4e298
|
@ -44,8 +44,8 @@
|
||||||
|
|
||||||
struct _PlumaStatusbarPrivate
|
struct _PlumaStatusbarPrivate
|
||||||
{
|
{
|
||||||
GtkWidget *overwrite_mode_statusbar;
|
GtkWidget *overwrite_mode_label;
|
||||||
GtkWidget *cursor_position_statusbar;
|
GtkWidget *cursor_position_label;
|
||||||
|
|
||||||
GtkWidget *state_frame;
|
GtkWidget *state_frame;
|
||||||
GtkWidget *load_image;
|
GtkWidget *load_image;
|
||||||
|
@ -76,41 +76,18 @@ get_overwrite_mode_length (void)
|
||||||
return 2 + MAX (g_utf8_strlen (_("OVR"), -1), g_utf8_strlen (_("INS"), -1));
|
return 2 + MAX (g_utf8_strlen (_("OVR"), -1), g_utf8_strlen (_("INS"), -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTK_CHECK_VERSION (3, 0, 0)
|
|
||||||
static void
|
static void
|
||||||
gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar, gboolean state)
|
pluma_statusbar_dispose (GObject *object)
|
||||||
{
|
|
||||||
/* nothing */
|
|
||||||
/* https://developer.gnome.org/gtk3/stable/ch24s02.html#id-1.6.3.4.17 */
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
|
||||||
pluma_statusbar_notify (GObject *object,
|
|
||||||
GParamSpec *pspec)
|
|
||||||
{
|
|
||||||
/* don't allow gtk_statusbar_set_has_resize_grip to mess with us.
|
|
||||||
* See _pluma_statusbar_set_has_resize_grip for an explanation.
|
|
||||||
*/
|
|
||||||
if (strcmp (g_param_spec_get_name (pspec), "has-resize-grip") == 0)
|
|
||||||
{
|
|
||||||
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (object), FALSE);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (G_OBJECT_CLASS (pluma_statusbar_parent_class)->notify)
|
|
||||||
G_OBJECT_CLASS (pluma_statusbar_parent_class)->notify (object, pspec);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
pluma_statusbar_finalize (GObject *object)
|
|
||||||
{
|
{
|
||||||
PlumaStatusbar *statusbar = PLUMA_STATUSBAR (object);
|
PlumaStatusbar *statusbar = PLUMA_STATUSBAR (object);
|
||||||
|
|
||||||
if (statusbar->priv->flash_timeout > 0)
|
if (statusbar->priv->flash_timeout > 0)
|
||||||
|
{
|
||||||
g_source_remove (statusbar->priv->flash_timeout);
|
g_source_remove (statusbar->priv->flash_timeout);
|
||||||
|
statusbar->priv->flash_timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (pluma_statusbar_parent_class)->finalize (object);
|
G_OBJECT_CLASS (pluma_statusbar_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -118,45 +95,12 @@ pluma_statusbar_class_init (PlumaStatusbarClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
object_class->notify = pluma_statusbar_notify;
|
object_class->dispose = pluma_statusbar_dispose;
|
||||||
object_class->finalize = pluma_statusbar_finalize;
|
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (PlumaStatusbarPrivate));
|
g_type_class_add_private (object_class, sizeof (PlumaStatusbarPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define RESIZE_GRIP_EXTRA_WIDTH 30
|
#define CURSOR_POSITION_LABEL_WIDTH_CHARS 18
|
||||||
|
|
||||||
static void
|
|
||||||
set_statusbar_width_chars (GtkWidget *statusbar,
|
|
||||||
gint n_chars,
|
|
||||||
gboolean has_resize_grip)
|
|
||||||
{
|
|
||||||
PangoContext *context;
|
|
||||||
PangoFontMetrics *metrics;
|
|
||||||
gint char_width, digit_width, width;
|
|
||||||
GtkStyle *style;
|
|
||||||
|
|
||||||
context = gtk_widget_get_pango_context (statusbar);
|
|
||||||
style = gtk_widget_get_style (GTK_WIDGET (statusbar));
|
|
||||||
metrics = pango_context_get_metrics (context,
|
|
||||||
style->font_desc,
|
|
||||||
pango_context_get_language (context));
|
|
||||||
|
|
||||||
char_width = pango_font_metrics_get_approximate_digit_width (metrics);
|
|
||||||
digit_width = pango_font_metrics_get_approximate_char_width (metrics);
|
|
||||||
|
|
||||||
width = PANGO_PIXELS (MAX (char_width, digit_width) * n_chars);
|
|
||||||
|
|
||||||
pango_font_metrics_unref (metrics);
|
|
||||||
|
|
||||||
/* If there is a resize grip, allocate some extra width.
|
|
||||||
* It would be nice to calculate the exact size programmatically
|
|
||||||
* but I could not find out how to do it */
|
|
||||||
if (has_resize_grip)
|
|
||||||
width += RESIZE_GRIP_EXTRA_WIDTH;
|
|
||||||
|
|
||||||
gtk_widget_set_size_request (statusbar, width, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pluma_statusbar_init (PlumaStatusbar *statusbar)
|
pluma_statusbar_init (PlumaStatusbar *statusbar)
|
||||||
|
@ -166,30 +110,25 @@ pluma_statusbar_init (PlumaStatusbar *statusbar)
|
||||||
|
|
||||||
statusbar->priv = PLUMA_STATUSBAR_GET_PRIVATE (statusbar);
|
statusbar->priv = PLUMA_STATUSBAR_GET_PRIVATE (statusbar);
|
||||||
|
|
||||||
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar), FALSE);
|
statusbar->priv->overwrite_mode_label = gtk_label_new (NULL);
|
||||||
|
gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->overwrite_mode_label),
|
||||||
statusbar->priv->overwrite_mode_statusbar = gtk_statusbar_new ();
|
get_overwrite_mode_length ());
|
||||||
gtk_widget_show (statusbar->priv->overwrite_mode_statusbar);
|
gtk_widget_show (statusbar->priv->overwrite_mode_label);
|
||||||
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar->priv->overwrite_mode_statusbar),
|
|
||||||
TRUE);
|
|
||||||
set_statusbar_width_chars (statusbar->priv->overwrite_mode_statusbar,
|
|
||||||
get_overwrite_mode_length (),
|
|
||||||
TRUE);
|
|
||||||
gtk_box_pack_end (GTK_BOX (statusbar),
|
gtk_box_pack_end (GTK_BOX (statusbar),
|
||||||
statusbar->priv->overwrite_mode_statusbar,
|
statusbar->priv->overwrite_mode_label,
|
||||||
FALSE, TRUE, 0);
|
FALSE, TRUE, 0);
|
||||||
|
|
||||||
statusbar->priv->cursor_position_statusbar = gtk_statusbar_new ();
|
statusbar->priv->cursor_position_label = gtk_label_new (NULL);
|
||||||
gtk_widget_show (statusbar->priv->cursor_position_statusbar);
|
gtk_label_set_width_chars (GTK_LABEL (statusbar->priv->cursor_position_label),
|
||||||
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (statusbar->priv->cursor_position_statusbar),
|
CURSOR_POSITION_LABEL_WIDTH_CHARS);
|
||||||
FALSE);
|
gtk_widget_show (statusbar->priv->cursor_position_label);
|
||||||
set_statusbar_width_chars (statusbar->priv->cursor_position_statusbar, 18, FALSE);
|
|
||||||
gtk_box_pack_end (GTK_BOX (statusbar),
|
gtk_box_pack_end (GTK_BOX (statusbar),
|
||||||
statusbar->priv->cursor_position_statusbar,
|
statusbar->priv->cursor_position_label,
|
||||||
FALSE, TRUE, 0);
|
FALSE, TRUE, 0);
|
||||||
|
|
||||||
statusbar->priv->state_frame = gtk_frame_new (NULL);
|
statusbar->priv->state_frame = gtk_frame_new (NULL);
|
||||||
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame), GTK_SHADOW_IN);
|
gtk_frame_set_shadow_type (GTK_FRAME (statusbar->priv->state_frame),
|
||||||
|
GTK_SHADOW_IN);
|
||||||
|
|
||||||
hbox = gtk_hbox_new (FALSE, 0);
|
hbox = gtk_hbox_new (FALSE, 0);
|
||||||
gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox);
|
gtk_container_add (GTK_CONTAINER (statusbar->priv->state_frame), hbox);
|
||||||
|
@ -253,35 +192,6 @@ pluma_statusbar_new (void)
|
||||||
return GTK_WIDGET (g_object_new (PLUMA_TYPE_STATUSBAR, NULL));
|
return GTK_WIDGET (g_object_new (PLUMA_TYPE_STATUSBAR, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* pluma_set_has_resize_grip:
|
|
||||||
* @statusbar: a #PlumaStatusbar
|
|
||||||
* @show: if the resize grip is shown
|
|
||||||
*
|
|
||||||
* Sets if a resize grip showld be shown.
|
|
||||||
*
|
|
||||||
**/
|
|
||||||
/*
|
|
||||||
* I don't like this much, in a perfect world it would have been
|
|
||||||
* possible to override the parent property and use
|
|
||||||
* gtk_statusbar_set_has_resize_grip. Unfortunately this is not
|
|
||||||
* possible and it's not even possible to intercept the notify signal
|
|
||||||
* since the parent property should always be set to false thus when
|
|
||||||
* using set_resize_grip (FALSE) the property doesn't change and the
|
|
||||||
* notification is not emitted.
|
|
||||||
* For now just add this private method; if needed we can turn it into
|
|
||||||
* a property.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
_pluma_statusbar_set_has_resize_grip (PlumaStatusbar *bar,
|
|
||||||
gboolean show)
|
|
||||||
{
|
|
||||||
g_return_if_fail (PLUMA_IS_STATUSBAR (bar));
|
|
||||||
|
|
||||||
gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (bar->priv->overwrite_mode_statusbar),
|
|
||||||
show);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pluma_statusbar_set_overwrite:
|
* pluma_statusbar_set_overwrite:
|
||||||
* @statusbar: a #PlumaStatusbar
|
* @statusbar: a #PlumaStatusbar
|
||||||
|
@ -297,11 +207,9 @@ pluma_statusbar_set_overwrite (PlumaStatusbar *statusbar,
|
||||||
|
|
||||||
g_return_if_fail (PLUMA_IS_STATUSBAR (statusbar));
|
g_return_if_fail (PLUMA_IS_STATUSBAR (statusbar));
|
||||||
|
|
||||||
gtk_statusbar_pop (GTK_STATUSBAR (statusbar->priv->overwrite_mode_statusbar), 0);
|
|
||||||
|
|
||||||
msg = get_overwrite_mode_string (overwrite);
|
msg = get_overwrite_mode_string (overwrite);
|
||||||
|
|
||||||
gtk_statusbar_push (GTK_STATUSBAR (statusbar->priv->overwrite_mode_statusbar), 0, msg);
|
gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), msg);
|
||||||
|
|
||||||
g_free (msg);
|
g_free (msg);
|
||||||
}
|
}
|
||||||
|
@ -311,7 +219,7 @@ pluma_statusbar_clear_overwrite (PlumaStatusbar *statusbar)
|
||||||
{
|
{
|
||||||
g_return_if_fail (PLUMA_IS_STATUSBAR (statusbar));
|
g_return_if_fail (PLUMA_IS_STATUSBAR (statusbar));
|
||||||
|
|
||||||
gtk_statusbar_pop (GTK_STATUSBAR (statusbar->priv->overwrite_mode_statusbar), 0);
|
gtk_label_set_text (GTK_LABEL (statusbar->priv->overwrite_mode_label), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -327,20 +235,18 @@ pluma_statusbar_set_cursor_position (PlumaStatusbar *statusbar,
|
||||||
gint line,
|
gint line,
|
||||||
gint col)
|
gint col)
|
||||||
{
|
{
|
||||||
gchar *msg;
|
gchar *msg = NULL;
|
||||||
|
|
||||||
g_return_if_fail (PLUMA_IS_STATUSBAR (statusbar));
|
g_return_if_fail (PLUMA_IS_STATUSBAR (statusbar));
|
||||||
|
|
||||||
gtk_statusbar_pop (GTK_STATUSBAR (statusbar->priv->cursor_position_statusbar), 0);
|
if ((line >= 0) || (col >= 0))
|
||||||
|
{
|
||||||
if ((line == -1) && (col == -1))
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* Translators: "Ln" is an abbreviation for "Line", Col is an abbreviation for "Column". Please,
|
/* Translators: "Ln" is an abbreviation for "Line", Col is an abbreviation for "Column". Please,
|
||||||
use abbreviations if possible to avoid space problems. */
|
use abbreviations if possible to avoid space problems. */
|
||||||
msg = g_strdup_printf (_(" Ln %d, Col %d"), line, col);
|
msg = g_strdup_printf (_(" Ln %d, Col %d"), line, col);
|
||||||
|
}
|
||||||
|
|
||||||
gtk_statusbar_push (GTK_STATUSBAR (statusbar->priv->cursor_position_statusbar), 0, msg);
|
gtk_label_set_text (GTK_LABEL (statusbar->priv->cursor_position_label), msg);
|
||||||
|
|
||||||
g_free (msg);
|
g_free (msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,18 +81,6 @@ void pluma_statusbar_flash_message (PlumaStatusbar *statusbar,
|
||||||
guint context_id,
|
guint context_id,
|
||||||
const gchar *format,
|
const gchar *format,
|
||||||
...) G_GNUC_PRINTF(3, 4);
|
...) G_GNUC_PRINTF(3, 4);
|
||||||
/* FIXME: these would be nice for plugins...
|
|
||||||
void pluma_statusbar_add_widget (PlumaStatusbar *statusbar,
|
|
||||||
GtkWidget *widget);
|
|
||||||
void pluma_statusbar_remove_widget (PlumaStatusbar *statusbar,
|
|
||||||
GtkWidget *widget);
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Non exported functions
|
|
||||||
*/
|
|
||||||
void _pluma_statusbar_set_has_resize_grip (PlumaStatusbar *statusbar,
|
|
||||||
gboolean show);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -329,9 +329,6 @@ pluma_window_window_state_event (GtkWidget *widget,
|
||||||
|
|
||||||
show = !(event->new_window_state &
|
show = !(event->new_window_state &
|
||||||
(GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN));
|
(GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN));
|
||||||
|
|
||||||
_pluma_statusbar_set_has_resize_grip (PLUMA_STATUSBAR (window->priv->statusbar),
|
|
||||||
show);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Reference in New Issue