[gnumeric] GUI: Style arguments in function help texts.



commit 9be7b912a2839354cd630bed2b400ef371f47fca
Author: Morten Welinder <terra gnome org>
Date:   Wed Apr 24 19:51:07 2013 -0400

    GUI: Style arguments in function help texts.
    
    Use link-color instead of a hardcoded blue.

 ChangeLog                         |    3 +++
 src/dialogs/dialog-formula-guru.c |   19 ++++++++++---------
 src/func.c                        |   20 ++++++++++++++++----
 src/func.h                        |    3 ++-
 src/gnumeric.css                  |    7 +++++++
 src/widgets/gnumeric-expr-entry.c |    5 ++++-
 6 files changed, 42 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a75b2f8..effce5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2013-04-24  Morten Welinder  <terra gnome org>
 
+       * src/func.c (gnm_func_convert_markup_to_pango): Add a target
+       widget parameter.  All callers changed.
+
        * src/sheet-control-gui.c (scg_init): Ditto comment.timer and
        delayedMovement.timer.
 
diff --git a/src/dialogs/dialog-formula-guru.c b/src/dialogs/dialog-formula-guru.c
index a4b11ed..05586d7 100644
--- a/src/dialogs/dialog-formula-guru.c
+++ b/src/dialogs/dialog-formula-guru.c
@@ -309,8 +309,6 @@ dialog_formula_guru_adjust_children (GtkTreeIter *parent, GnmFunc const *fd,
                                               &iter, parent, args))
                gtk_tree_store_remove (state->model, &iter);
        for (i = 0; i < args; i++) {
-               gchar *desc;
-
                if (!gtk_tree_model_iter_nth_child (GTK_TREE_MODEL(state->model),
                                                    &iter, parent, i)) {
                        gtk_tree_store_append (state->model, &iter, parent);
@@ -328,14 +326,12 @@ dialog_formula_guru_adjust_children (GtkTreeIter *parent, GnmFunc const *fd,
                        g_free (arg_name);
                        arg_name = mod_name;
                }
-               desc = gnm_func_convert_markup_to_pango
-                       (gnm_func_get_arg_description (fd, i));
+
                gtk_tree_store_set (state->model, &iter,
                                    ARG_NAME, arg_name,
-                                   ARG_TOOLTIP, desc,
+                                   ARG_TOOLTIP, gnm_func_get_arg_description (fd, i),
                                    ARG_TYPE, function_def_get_arg_type_string (fd, i),
                                    -1);
-               g_free (desc);
                g_free (arg_name);
        }
 
@@ -821,12 +817,12 @@ cb_dialog_formula_guru_query_tooltip (G_GNUC_UNUSED GtkWidget  *widget,
 
        if (gtk_tree_view_get_tooltip_context
            (state->treeview, &x_, &y_, keyboard_mode, NULL, &path, &iter)) {
-               char *markup;
+               char *markup, *arg_desc;
                GtkWidget *parent, *window;
 
                gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
-                                   ARG_TOOLTIP, &markup, -1);
-               if (markup == NULL || markup[0]=='\0')
+                                   ARG_TOOLTIP, &arg_desc, -1);
+               if (arg_desc == NULL || arg_desc[0]=='\0')
                        return FALSE;
                if (!state->tooltip_widget) {
                        state->tooltip_label = gtk_label_new ("");
@@ -850,8 +846,13 @@ cb_dialog_formula_guru_query_tooltip (G_GNUC_UNUSED GtkWidget  *widget,
                                        (GTK_ALIGNMENT (parent),
                                         0,0,0,0);
                }
+
+               markup = gnm_func_convert_markup_to_pango
+                       (arg_desc,
+                        state->tooltip_label);
                gtk_label_set_markup (GTK_LABEL (state->tooltip_label), markup);
                g_free (markup);
+               g_free (arg_desc);
                gtk_tree_view_set_tooltip_row (state->treeview,
                                               tooltip, path);
                gtk_tree_path_free (path);
diff --git a/src/func.c b/src/func.c
index 61c16eb..2d59ee9 100644
--- a/src/func.c
+++ b/src/func.c
@@ -1671,15 +1671,27 @@ gnm_func_get_arg_description (GnmFunc const *fn_def, guint arg_idx)
 /**
  * gnm_func_convert_markup_to_pango:
  * @desc: the fn or arg description string
+ * @target: target widget for the markup.
  *
  * Return value: the escaped string with @{} markup converted to
  *               pango markup
  **/
 char *
-gnm_func_convert_markup_to_pango (char const *desc)
+gnm_func_convert_markup_to_pango (char const *desc, GtkWidget *target)
 {
        GString *str;
        gchar *markup, *at;
+       GdkColor *link_color = NULL;
+       char *link_color_text, *span_text;
+       size_t span_text_len;
+
+       gtk_widget_style_get (target, "link-color", &link_color, NULL);
+       link_color_text = gdk_color_to_string (link_color);
+       gdk_color_free (link_color);
+       span_text = g_strdup_printf ("<span foreground=\"%s\">",
+                                    link_color_text);
+       span_text_len = strlen (span_text);
+       g_free (link_color_text);
 
        markup = g_markup_escape_text (desc, -1);
        str = g_string_new (markup);
@@ -1687,15 +1699,15 @@ gnm_func_convert_markup_to_pango (char const *desc)
 
        while ((at = strstr (str->str, "@{"))) {
                gint len = at - str->str;
-               go_string_replace (str, len, 2,
-                                  "<span foreground=\"#0000FF\">", -1);
+               go_string_replace (str, len, 2, span_text, -1);
                if ((at = strstr
-                    (str->str + len + 26, "}"))) {
+                    (str->str + len + span_text_len, "}"))) {
                        len = at - str->str;
                        go_string_replace (str, len, 1, "</span>", -1);
                } else
                        g_string_append (str, "</span>");
        }
+       g_free (span_text);
 
        return g_string_free (str, FALSE);
 }
diff --git a/src/func.h b/src/func.h
index 518bb72..eee4eae 100644
--- a/src/func.h
+++ b/src/func.h
@@ -261,7 +261,8 @@ char       *function_def_get_arg_name  (GnmFunc const *fn_def,
                                         guint arg_idx);
 char const *gnm_func_get_arg_description (GnmFunc const *fn_def,
                                         guint arg_idx);
-char       *gnm_func_convert_markup_to_pango (char const *desc);
+char       *gnm_func_convert_markup_to_pango (char const *desc,
+                                             GtkWidget *target);
 
 /*************************************************************************/
 
diff --git a/src/gnumeric.css b/src/gnumeric.css
index 393338f..33cbc66 100644
--- a/src/gnumeric.css
+++ b/src/gnumeric.css
@@ -206,3 +206,10 @@ GnmNotebookButton:active {
 }
 
 /* ------------------------------------------------------------------------- */
+/* Functions' arguments link-like appearance in pseudo-tooltips.  */
+
+GtkTextView.function-help {
+  -GtkWidget-link-color: red;
+}
+
+/* ------------------------------------------------------------------------- */
diff --git a/src/widgets/gnumeric-expr-entry.c b/src/widgets/gnumeric-expr-entry.c
index 1759e19..845f7f4 100644
--- a/src/widgets/gnumeric-expr-entry.c
+++ b/src/widgets/gnumeric-expr-entry.c
@@ -808,6 +808,9 @@ gee_create_tooltip (GnmExprEntry *gee, gchar const *str,
        label = gnumeric_convert_to_tooltip (toplevel, gtk_text_view_new ());
        tip = gtk_widget_get_toplevel (label);
 
+       gtk_style_context_add_class (gtk_widget_get_style_context (label),
+                                    "function-help");
+
 #if !GTK_CHECK_VERSION(3,4,0)
        /* Workaround for theme bugs and missing "inherit" in pre GTK 3.4. */
        {
@@ -820,7 +823,7 @@ gee_create_tooltip (GnmExprEntry *gee, gchar const *str,
 #endif
 
        if (str)
-               markup = gnm_func_convert_markup_to_pango (str);
+               markup = gnm_func_convert_markup_to_pango (str, label);
        string = g_string_new (markup);
        if (marked_str)
                g_string_append (string, marked_str);


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