[gnumeric] Dead kittens.



commit f1845e4ae9132768a52e9e672e550868b84873fb
Author: Morten Welinder <terra gnome org>
Date:   Sun Dec 22 17:53:49 2013 -0500

    Dead kittens.

 ChangeLog                         |    5 +++++
 src/dialogs/dialog-sheet-resize.c |    7 ++-----
 src/dialogs/dialog-solver.c       |    9 +--------
 src/gui-util.c                    |   20 ++++++++++++++++++++
 src/gui-util.h                    |    2 ++
 src/wbc-gtk.c                     |   37 ++++++++++++++++---------------------
 6 files changed, 46 insertions(+), 34 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 07a9eee..ffac2ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-12-22  Morten Welinder  <terra gnome org>
+
+       * src/gui-util.c (gnm_widget_measure_string): New function
+       allowing the elimination of all gtk_style_context_get_font calls.
+
 2013-12-19  Morten Welinder  <terra gnome org>
 
        * src/sf-gamma.c (qfactf): Squeeze a few extra bits out of this,
diff --git a/src/dialogs/dialog-sheet-resize.c b/src/dialogs/dialog-sheet-resize.c
index 60b5baf..40876e5 100644
--- a/src/dialogs/dialog-sheet-resize.c
+++ b/src/dialogs/dialog-sheet-resize.c
@@ -160,7 +160,6 @@ dialog_sheet_resize (WBCGtk *wbcg)
        GtkBuilder *gui;
        ResizeState *state;
        int slider_width;
-       GtkStyleContext *ctxt;
 
        if (gnumeric_dialog_raise_if_exists (wbcg, RESIZE_DIALOG_KEY))
                return;
@@ -174,12 +173,10 @@ dialog_sheet_resize (WBCGtk *wbcg)
        state->sheet = wbcg_cur_sheet (wbcg);
        g_return_if_fail (state->dialog != NULL);
 
-       ctxt = gtk_widget_get_style_context (GTK_WIDGET (wbcg_toplevel (wbcg)));
        slider_width = mylog2 (MAX (GNM_MAX_ROWS / GNM_MIN_ROWS,
                                    GNM_MAX_COLS / GNM_MIN_COLS)) *
-               go_pango_measure_string
-               (gtk_widget_get_pango_context (GTK_WIDGET (wbcg_toplevel (wbcg))),
-                gtk_style_context_get_font (ctxt, GTK_STATE_FLAG_NORMAL), "00");
+               gnm_widget_measure_string (GTK_WIDGET (wbcg_toplevel (wbcg)),
+                                          "00");
 
        state->columns_scale = go_gtk_builder_get_widget (gui, "columns_scale");
        gtk_widget_set_size_request (state->columns_scale, slider_width, -1);
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 3e378dd..6bc4768 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -654,7 +654,6 @@ run_solver (SolverState *state, GnmSolverParameters *param)
        GtkWindow *top = GTK_WINDOW (gtk_widget_get_toplevel (state->dialog));
        GnmSolverResult *res = NULL;
        int y;
-       GtkStyleContext *ctxt;
 
        sol = gnm_solver_factory_functional (param->options.algorithm,
                                             state->wbcg)
@@ -709,8 +708,6 @@ run_solver (SolverState *state, GnmSolverParameters *param)
                        N_("Elapsed Time:")
                };
                GtkWidget *w;
-               PangoContext *context =
-                       gtk_widget_get_pango_context (state->dialog);
 
                w = gtk_label_new (_(ltxt[y]));
                g_object_set (w,
@@ -719,13 +716,9 @@ run_solver (SolverState *state, GnmSolverParameters *param)
                              NULL);
                gtk_grid_attach (GTK_GRID (grid), w, 0, y, 1, 1);
                w = gtk_label_new ("");
-               ctxt = gtk_widget_get_style_context (w);
                gtk_widget_set_size_request
                        (w,
-                        go_pango_measure_string
-                        (context,
-                         gtk_style_context_get_font (ctxt, GTK_STATE_FLAG_NORMAL),
-                         "0") * (5 + GNM_DIG),
+                        gnm_widget_measure_string (w, "0") * (5 + GNM_DIG),
                         -1);
                gtk_grid_attach (GTK_GRID (grid), w, 1, y, 1, 1);
                switch (y) {
diff --git a/src/gui-util.c b/src/gui-util.c
index 9229d9a..427a627 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -1318,3 +1318,23 @@ gnm_cell_renderer_text_copy_background_to_cairo (GtkCellRendererText *crt,
        gdk_cairo_set_source_rgba (cr, c);
        gdk_rgba_free (c);
 }
+
+int
+gnm_widget_measure_string (GtkWidget *w, const char *s)
+{
+       GtkStyleContext *ctxt;
+       int len;
+       PangoFontDescription *desc;
+       GtkStateFlags state = GTK_STATE_FLAG_NORMAL;
+
+       ctxt = gtk_widget_get_style_context (w);
+
+       gtk_style_context_get (ctxt, state, "font", &desc, NULL);
+
+       len = go_pango_measure_string
+               (gtk_widget_get_pango_context (w), desc, s);
+
+       pango_font_description_free (desc);
+
+       return len;
+}
diff --git a/src/gui-util.h b/src/gui-util.h
index d3f8ecc..23f5e6a 100644
--- a/src/gui-util.h
+++ b/src/gui-util.h
@@ -107,6 +107,8 @@ void gnm_link_button_and_entry (GtkWidget *button, GtkWidget *entry);
 void gnm_widget_set_cursor_type (GtkWidget *w, GdkCursorType ct);
 void gnm_widget_set_cursor (GtkWidget *w, GdkCursor *ct);
 
+int gnm_widget_measure_string (GtkWidget *w, const char *s);
+
 GtkWidget * gnumeric_message_dialog_create (GtkWindow * parent,
                                             GtkDialogFlags flags,
                                             GtkMessageType type,
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 04751ec..b78f20b 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -2746,10 +2746,9 @@ wbc_gtk_create_edit_area (WBCGtk *wbcg)
        entry = wbcg_get_entry (wbcg);
 
        /* Set a reasonable width for the selection box. */
-       len = go_pango_measure_string (
-               gtk_widget_get_pango_context (GTK_WIDGET (wbcg_toplevel (wbcg))),
-               gtk_style_context_get_font (gtk_widget_get_style_context (GTK_WIDGET (entry)), 
GTK_STATE_FLAG_NORMAL),
-               cell_coord_name (GNM_MAX_COLS - 1, GNM_MAX_ROWS - 1));
+       len = gnm_widget_measure_string
+               (GTK_WIDGET (wbcg_toplevel (wbcg)),
+                cell_coord_name (GNM_MAX_COLS - 1, GNM_MAX_ROWS - 1));
        /*
         * Add a little extra since font might be proportional and since
         * we also put user defined names there.
@@ -3473,12 +3472,8 @@ cb_font_button_screen_changed (GtkWidget *widget)
        GdkScreen *screen = gtk_widget_get_screen (widget);
 
        if (screen) {
-               PangoContext *context = gtk_widget_get_pango_context (widget);
-               const PangoFontDescription *desc = gtk_style_context_get_font
-                       (gtk_widget_get_style_context (widget),
-                        GTK_STATE_FLAG_NORMAL);
-               int w = go_pango_measure_string (context, desc,
-                                                "XXMonospace | 99XX");
+               int w = gnm_widget_measure_string (widget,
+                                                  "XXMonospace | 99XX");
                gtk_widget_set_size_request (widget, w, -1);
        }
 #endif
@@ -4774,17 +4769,17 @@ wbc_gtk_create_status_area (WBCGtk *wbcg)
        g_object_ref (wbcg->auto_expr_label);
        gtk_label_set_max_width_chars (GTK_LABEL (wbcg->auto_expr_label),
                                       strlen (AUTO_EXPR_SAMPLE));
-       gtk_widget_set_size_request (wbcg->auto_expr_label,
-               go_pango_measure_string (
-               gtk_widget_get_pango_context (GTK_WIDGET (wbcg->toplevel)),
-               gtk_style_context_get_font (gtk_widget_get_style_context (wbcg->auto_expr_label), 
GTK_STATE_FLAG_NORMAL),
-               AUTO_EXPR_SAMPLE), -1);
-
-       gtk_widget_set_size_request (wbcg->status_text,
-               go_pango_measure_string (
-               gtk_widget_get_pango_context (GTK_WIDGET (wbcg->toplevel)),
-               gtk_style_context_get_font (gtk_widget_get_style_context (wbcg->status_text), 
GTK_STATE_FLAG_NORMAL),
-               "W") * 5, -1);
+       gtk_widget_set_size_request
+               (wbcg->auto_expr_label,
+                gnm_widget_measure_string (GTK_WIDGET (wbcg->toplevel),
+                                           AUTO_EXPR_SAMPLE),
+                -1);
+
+       gtk_widget_set_size_request
+               (wbcg->status_text,
+                gnm_widget_measure_string (GTK_WIDGET (wbcg->toplevel),
+                                           "W") * 5,
+                -1);
        ebox = GET_GUI_ITEM ("auto_expr_event_box");
        gtk_style_context_add_class (gtk_widget_get_style_context (ebox),
                                     "auto-expr");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]