[gnumeric] GUI: Eliminate Gnumeric's copy of GOFileSel.



commit bbf435371017acfcbf91eb909bc2e09eaedda9b3
Author: Morten Welinder <terra gnome org>
Date:   Thu Mar 14 15:12:44 2013 -0400

    GUI: Eliminate Gnumeric's copy of GOFileSel.

 NEWS                               |    1 +
 po-functions/POTFILES.in           |    2 -
 po/POTFILES.in                     |    2 -
 src/GNOME_Gnumeric-gtk.xml.in      |    2 -
 src/dialogs/Makefile.am            |    1 -
 src/dialogs/dialog-cell-format.c   |  259 +++++++++++----
 src/dialogs/font-sel.ui            |  185 -----------
 src/wbc-gtk-impl.h                 |    2 +-
 src/wbc-gtk.c                      |  326 ++++++++------------
 src/widgets/Makefile.am            |    2 -
 src/widgets/widget-font-selector.c |  605 ------------------------------------
 src/widgets/widget-font-selector.h |   29 --
 12 files changed, 314 insertions(+), 1102 deletions(-)
---
diff --git a/NEWS b/NEWS
index 346cb39..d12b94b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ Gnumeric 1.12.2
 
 Morten:
        * Improve ssconvert error handling.  [#695529]
+       * New font selector for toolbar.  [#695031]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.1
diff --git a/po-functions/POTFILES.in b/po-functions/POTFILES.in
index 2b3e95f..e3fa1f0 100644
--- a/po-functions/POTFILES.in
+++ b/po-functions/POTFILES.in
@@ -169,7 +169,6 @@ src/dialogs/dialog-zoom.c
 [type: gettext/glade]src/dialogs/doc-meta-data.ui
 [type: gettext/glade]src/dialogs/exp-smoothing.ui
 [type: gettext/glade]src/dialogs/fill-series.ui
-[type: gettext/glade]src/dialogs/font-sel.ui
 [type: gettext/glade]src/dialogs/formula-guru.ui
 [type: gettext/glade]src/dialogs/fourier-analysis.ui
 [type: gettext/glade]src/dialogs/frequency.ui
@@ -325,7 +324,6 @@ src/widgets/gnumeric-cell-renderer-text.c
 src/widgets/gnumeric-cell-renderer-toggle.c
 src/widgets/gnumeric-expr-entry.c
 src/widgets/gnumeric-text-view.c
-src/widgets/widget-font-selector.c
 src/workbook-cmd-format.c
 src/workbook-control.c
 src/workbook-view.c
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1f4c739..68b06f2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -227,7 +227,6 @@ src/dialogs/dialog-zoom.c
 [type: gettext/glade]src/dialogs/doc-meta-data.ui
 [type: gettext/glade]src/dialogs/exp-smoothing.ui
 [type: gettext/glade]src/dialogs/fill-series.ui
-[type: gettext/glade]src/dialogs/font-sel.ui
 [type: gettext/glade]src/dialogs/formula-guru.ui
 [type: gettext/glade]src/dialogs/fourier-analysis.ui
 [type: gettext/glade]src/dialogs/frequency.ui
@@ -383,7 +382,6 @@ src/widgets/gnumeric-cell-renderer-text.c
 src/widgets/gnumeric-cell-renderer-toggle.c
 src/widgets/gnumeric-expr-entry.c
 src/widgets/gnumeric-text-view.c
-src/widgets/widget-font-selector.c
 src/workbook-cmd-format.c
 src/workbook-control.c
 src/workbook-view.c
diff --git a/src/GNOME_Gnumeric-gtk.xml.in b/src/GNOME_Gnumeric-gtk.xml.in
index b694f14..54955e0 100644
--- a/src/GNOME_Gnumeric-gtk.xml.in
+++ b/src/GNOME_Gnumeric-gtk.xml.in
@@ -359,7 +359,6 @@
   </toolbar>
   <toolbar _name="FormatToolbar">
     <toolitem action="FontName"/>
-    <toolitem action="FontSize"/>
     <toolitem action="FontBold"/>
     <toolitem action="FontItalic"/>
     <toolitem action="FontUnderline"/>
@@ -386,7 +385,6 @@
   </toolbar>
   <toolbar _name="LongFormatToolbar">
     <toolitem action="FontName"/>
-    <toolitem action="FontSize"/>
     <toolitem action="FontSuperscript"/>
     <toolitem action="FontSubscript"/>
     <toolitem action="FontBold"/>
diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am
index 15af3a6..817b924 100644
--- a/src/dialogs/Makefile.am
+++ b/src/dialogs/Makefile.am
@@ -125,7 +125,6 @@ embedded_uis =                      \
        doc-meta-data.ui                \
        exp-smoothing.ui                \
        fill-series.ui                  \
-       font-sel.ui                     \
        formula-guru.ui                 \
        fourier-analysis.ui             \
        frequency.ui                    \
diff --git a/src/dialogs/dialog-cell-format.c b/src/dialogs/dialog-cell-format.c
index 79ed211..babd204 100644
--- a/src/dialogs/dialog-cell-format.c
+++ b/src/dialogs/dialog-cell-format.c
@@ -50,7 +50,6 @@
 #include <commands.h>
 #include <mathfunc.h>
 #include <preview-grid.h>
-#include <widgets/widget-font-selector.h>
 #include <widgets/gnumeric-dashed-canvas-line.h>
 #include <widgets/gnm-format-sel.h>
 #include <style-conditions.h>
@@ -150,7 +149,7 @@ typedef struct _FormatState {
                GORotationSel   *rotation;
        } align;
        struct {
-               FontSelector    *selector;
+               GOFontSel       *selector;
                GtkToggleButton *superscript, *subscript;
                ColorPicker      color;
        } font;
@@ -349,21 +348,6 @@ setup_pattern_button (GdkScreen *screen,
 }
 
 static void
-replace_in_grid (GtkWidget *w, GtkWidget *neww)
-{      
-       GtkWidget *parent = gtk_widget_get_parent (w);
-       int col, row, width, height;
-       gtk_container_child_get (GTK_CONTAINER (parent),
-                                w,
-                                "left-attach", &col,
-                                "top-attach", &row,
-                                "width", &width,
-                                "height", &height,
-                                NULL);
-       gtk_grid_attach (GTK_GRID (parent), neww, col, row, width, height);
-}
-
-static void
 setup_color_pickers (FormatState *state,
                     ColorPicker *picker,
                     char const *color_group,
@@ -429,7 +413,7 @@ setup_color_pickers (FormatState *state,
        gtk_widget_show_all (frame);
 
        w = go_gtk_builder_get_widget (state->gui, placeholder);
-       replace_in_grid (w, frame);
+       go_gtk_widget_replace (w, frame);
 
        w = go_gtk_builder_get_widget (state->gui, label);
        gtk_label_set_mnemonic_widget (GTK_LABEL (w), combo);
@@ -493,6 +477,8 @@ static void
 fmt_dialog_init_format_page (FormatState *state)
 {
        GOFormatSel *gfs;
+       GODateConventions const *date_conv =
+               workbook_date_conv (state->sheet->workbook);
 
        state->format_sel = gnm_format_sel_new ();
        gfs = GO_FORMAT_SEL (state->format_sel);
@@ -506,10 +492,7 @@ fmt_dialog_init_format_page (FormatState *state)
                GOFormat const *fmt = gnm_style_get_format (state->style);
                go_format_sel_set_style_format (gfs, fmt);
        }
-       if (state->value)
-               gnm_format_sel_set_value (gfs, state->value);
-       go_format_sel_set_dateconv (gfs,
-                                   workbook_date_conv (state->sheet->workbook));
+       go_format_sel_set_dateconv (gfs, date_conv);
        go_format_sel_editable_enters (gfs, GTK_WINDOW (state->dialog));
 
        g_signal_connect (G_OBJECT (state->format_sel), "format_changed",
@@ -708,7 +691,7 @@ fmt_dialog_init_align_page (FormatState *state)
        go_rotation_sel_set_rotation (state->align.rotation, r);
        g_signal_connect (G_OBJECT (state->align.rotation), "rotation-changed",
                          G_CALLBACK (cb_rotation_changed), state);
-       replace_in_grid (go_gtk_builder_get_widget (state->gui, "rotation_placeholder"),
+       go_gtk_widget_replace (go_gtk_builder_get_widget (state->gui, "rotation_placeholder"),
                         GTK_WIDGET (state->align.rotation));
 }
 
@@ -716,20 +699,13 @@ fmt_dialog_init_align_page (FormatState *state)
 
 static void
 cb_font_changed (G_GNUC_UNUSED GtkWidget *widget,
-                GnmStyle *style, FormatState *state)
-{
-       static GnmStyleElement const font_types[] = {
-               MSTYLE_FONT_NAME,
-               MSTYLE_FONT_SIZE,
-               MSTYLE_FONT_BOLD,
-               MSTYLE_FONT_ITALIC,
-               MSTYLE_FONT_UNDERLINE,
-               MSTYLE_FONT_STRIKETHROUGH,
-               MSTYLE_FONT_SCRIPT,
-               MSTYLE_FONT_COLOR
-       };
-       int i;
-       static int const num_font_types = G_N_ELEMENTS (font_types);
+                PangoAttrList *attrs, FormatState *state)
+{
+       PangoAttrIterator *aiter;
+       const PangoAttribute *attr;
+       GnmStyle *res = state->result;
+       GOFontScript script = GO_FONT_SCRIPT_STANDARD;
+       gboolean has_script_attr = FALSE;
 
        gboolean changed = FALSE;
        g_return_if_fail (state != NULL);
@@ -737,18 +713,141 @@ cb_font_changed (G_GNUC_UNUSED GtkWidget *widget,
        if (!state->enable_edit)
                return;
 
-       for (i = 0 ; i < num_font_types; i++) {
-               GnmStyleElement const t = font_types[i];
-               if (gnm_style_is_element_set (style, t)) {
-                       gnm_style_merge_element (state->result, style, t);
+       aiter = pango_attr_list_get_iterator (attrs);
+
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_FAMILY);
+       if (attr) {
+               const char *s = ((PangoAttrString*)attr)->value;
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_NAME) ||
+                   !g_str_equal (s, gnm_style_get_font_name (res))) {
                        changed = TRUE;
+                       gnm_style_set_font_name (res, s);
                }
        }
 
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_SIZE);
+       if (attr) {
+               int i = ((PangoAttrInt*)attr)->value;
+               double d = i / (double)PANGO_SCALE;
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_SIZE) ||
+                   d != gnm_style_get_font_size (res)) {
+                       changed = TRUE;
+                       gnm_style_set_font_size (res, d);
+               }
+       }
+
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_WEIGHT);
+       if (attr) {
+               int i = ((PangoAttrInt*)attr)->value;
+               gboolean b = (i >= PANGO_WEIGHT_BOLD);
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_BOLD) ||
+                   b != gnm_style_get_font_bold (res)) {
+                       changed = TRUE;
+                       gnm_style_set_font_bold (res, b);
+               }
+       }
+
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_STYLE);
+       if (attr) {
+               int i = ((PangoAttrInt*)attr)->value;
+               gboolean b = (i != PANGO_STYLE_NORMAL);
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_ITALIC) ||
+                   b != gnm_style_get_font_italic (res)) {
+                       changed = TRUE;
+                       gnm_style_set_font_italic (res, b);
+               }
+       }
+
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_UNDERLINE);
+       if (attr) {
+               int i = ((PangoAttrInt*)attr)->value;
+               GnmUnderline u = gnm_translate_underline_from_pango (i);
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_UNDERLINE) ||
+                   u != gnm_style_get_font_uline (res)) {
+                       changed = TRUE;
+                       gnm_style_set_font_uline (res, u);
+               }
+       }
+
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_STRIKETHROUGH);
+       if (attr) {
+               int i = ((PangoAttrInt*)attr)->value;
+               gboolean b = (i != 0);
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_STRIKETHROUGH) ||
+                   b != gnm_style_get_font_strike (res)) {
+                       changed = TRUE;
+                       gnm_style_set_font_strike (res, b);
+               }
+       }
+
+       attr = pango_attr_iterator_get (aiter, go_pango_attr_subscript_get_attr_type ());
+       if (attr) {
+               has_script_attr = TRUE;
+               if (((GOPangoAttrSubscript*)attr)->val)
+                       script = GO_FONT_SCRIPT_SUB;
+       }
+       attr = pango_attr_iterator_get (aiter, go_pango_attr_superscript_get_attr_type ());
+       if (attr) {
+               has_script_attr = TRUE;
+               if (((GOPangoAttrSuperscript*)attr)->val)
+                       script = GO_FONT_SCRIPT_SUPER;
+       }
+       if (has_script_attr &&
+           (!gnm_style_is_element_set (res, MSTYLE_FONT_SCRIPT) ||
+            script != gnm_style_get_font_script (res))) {
+               changed = TRUE;
+               gnm_style_set_font_script (res, script);
+       }
+
+       attr = pango_attr_iterator_get (aiter, PANGO_ATTR_FOREGROUND);
+       if (attr) {
+               const PangoColor *pc = &((PangoAttrColor*)attr)->color;
+               GnmColor *c = gnm_color_new_pango (pc);
+               if (!gnm_style_is_element_set (res, MSTYLE_FONT_COLOR) ||
+                   !style_color_equal (c, gnm_style_get_font_color (res))) {
+                       changed = TRUE;
+                       gnm_style_set_font_color (res, c);
+               } else
+                       style_color_unref (c);
+       }
+
+       pango_attr_iterator_destroy (aiter);
+
        if (changed)
                fmt_dialog_changed (state);
 }
 
+static void
+change_font_attr (FormatState *state, PangoAttribute *attr)
+{
+       GOFontSel *gfs = state->font.selector;
+       PangoAttrList *attrs = pango_attr_list_copy
+               (go_font_sel_get_sample_attributes (gfs));
+       attr->start_index = 0;
+       attr->end_index = -1;
+       pango_attr_list_change (attrs, attr);
+       go_font_sel_set_sample_attributes (gfs, attrs);
+       cb_font_changed (NULL, attrs, state);
+       pango_attr_list_unref (attrs);
+}
+
+static void
+set_font_underline (FormatState *state, GnmUnderline u)
+{
+       PangoUnderline pu = gnm_translate_underline_to_pango (u);
+       change_font_attr (state, pango_attr_underline_new (pu));
+}
+
+static void
+set_font_script (FormatState *state, GOFontScript s)
+{
+       gboolean is_super = (s == GO_FONT_SCRIPT_SUPER);
+       gboolean is_sub = (s == GO_FONT_SCRIPT_SUB);
+
+       change_font_attr (state, go_pango_attr_subscript_new (is_sub));
+       change_font_attr (state, go_pango_attr_superscript_new (is_super));
+}
+
 /*
  * A callback to set the font color.
  * It is called whenever the color combo changes value.
@@ -768,18 +867,20 @@ cb_font_preview_color (G_GNUC_UNUSED GOComboColor *combo,
        col = is_default
                ? style_color_auto_font ()
                : gnm_color_new_go (c);
-       font_selector_set_color (state->font.selector, col);
+
+       change_font_attr (state, go_color_to_pango (col->go_color, TRUE));
+       style_color_unref (col);
 }
 
 static void
 cb_font_strike_toggle (GtkToggleButton *button, FormatState *state)
 {
        if (state->enable_edit) {
-               font_selector_set_strike (
-                       state->font.selector,
-                       gtk_toggle_button_get_active (button));
+               gboolean b = gtk_toggle_button_get_active (button);
+               change_font_attr (state, pango_attr_strikethrough_new (b));
        }
 }
+
 static void
 cb_font_script_toggle (GtkToggleButton *button, FormatState *state)
 {
@@ -796,7 +897,7 @@ cb_font_script_toggle (GtkToggleButton *button, FormatState *state)
                        }
                        state->enable_edit = TRUE;
                }
-               font_selector_set_script (state->font.selector, script);
+               set_font_script (state, script);
        }
 }
 
@@ -819,7 +920,7 @@ cb_font_underline_changed (GtkComboBoxText *combo,
                        break;
                }
 
-       font_selector_set_underline (state->font.selector, res);
+       set_font_underline (state, res);
        g_free (new_text);
        return TRUE;
 }
@@ -828,14 +929,18 @@ cb_font_underline_changed (GtkComboBoxText *combo,
 static void
 fmt_dialog_init_font_page (FormatState *state)
 {
-       GtkWidget *tmp = font_selector_new ();
-       FontSelector *font_widget = FONT_SELECTOR (tmp);
+       GtkWidget *tmp = g_object_new (GO_TYPE_FONT_SEL,
+                                      "show-style", TRUE,
+                                      NULL);
+       GOFontSel *font_widget = GO_FONT_SEL (tmp);
        GtkWidget *uline = gtk_combo_box_text_new_with_entry ();
        GtkEntry *uline_entry = GTK_ENTRY (gtk_bin_get_child (GTK_BIN (uline)));
        char const *uline_str;
        GtkWidget *strike = go_gtk_builder_get_widget (state->gui, "strikethrough_button");
        gboolean   strikethrough = FALSE;
        GOFontScript script = GO_FONT_SCRIPT_STANDARD;
+       GODateConventions const *date_conv =
+               workbook_date_conv (state->sheet->workbook);
        int i;
 
        g_return_if_fail (uline != NULL);
@@ -844,27 +949,40 @@ fmt_dialog_init_font_page (FormatState *state)
        gtk_widget_set_vexpand (tmp, TRUE);
        gtk_widget_set_hexpand (tmp, TRUE);
        gtk_widget_show (tmp);
-       replace_in_grid (go_gtk_builder_get_widget (state->gui, "font_sel_placeholder"),
+       go_gtk_widget_replace (go_gtk_builder_get_widget (state->gui, "font_sel_placeholder"),
                         tmp);
 
-       font_selector_editable_enters (font_widget, GTK_WINDOW (state->dialog));
+       go_font_sel_editable_enters (font_widget, GTK_WINDOW (state->dialog));
 
-       state->font.selector = FONT_SELECTOR (font_widget);
+       state->font.selector = GO_FONT_SEL (font_widget);
 
-       font_selector_set_value (state->font.selector, state->value);
+       if (state->value) {
+               char *s = format_value (NULL, state->value, -1, date_conv);
+               go_font_sel_set_sample_text (state->font.selector, s);
+               g_free (s);
+       }
 
-       if (0 == (state->conflicts & (1 << MSTYLE_FONT_NAME)))
-               font_selector_set_name (state->font.selector,
-                                       gnm_style_get_font_name (state->style));
+       if (0 == (state->conflicts & (1 << MSTYLE_FONT_NAME))) {
+               const char *family = gnm_style_get_font_name (state->style);
+               go_font_sel_set_family (state->font.selector, family);
+       }
 
        if (0 == (state->conflicts & (1 << MSTYLE_FONT_BOLD)) &&
-           0 == (state->conflicts & (1 << MSTYLE_FONT_ITALIC)))
-               font_selector_set_style (state->font.selector,
-                                        gnm_style_get_font_bold (state->style),
-                                        gnm_style_get_font_italic (state->style));
-       if (0 == (state->conflicts & (1 << MSTYLE_FONT_SIZE)))
-               font_selector_set_points (state->font.selector,
-                                         gnm_style_get_font_size (state->style));
+           0 == (state->conflicts & (1 << MSTYLE_FONT_ITALIC))) {
+               gboolean is_bold = gnm_style_get_font_bold (state->style);
+               gboolean is_italic = gnm_style_get_font_italic (state->style);
+
+               go_font_sel_set_style
+                       (state->font.selector,
+                        is_bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
+                        is_italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
+       }
+
+       if (0 == (state->conflicts & (1 << MSTYLE_FONT_SIZE))) {
+               double pts = gnm_style_get_font_size (state->style);
+               go_font_sel_set_size (state->font.selector,
+                                     pts * PANGO_SCALE);
+       }
 
        for (i = 0; i < (int)G_N_ELEMENTS (underline_types); i++)
                gtk_combo_box_text_append_text
@@ -874,7 +992,7 @@ fmt_dialog_init_font_page (FormatState *state)
        if (0 == (state->conflicts & (1 << MSTYLE_FONT_UNDERLINE))) {
                GnmUnderline ut = gnm_style_get_font_uline (state->style);
                uline_str = g_dpgettext2 (NULL, "underline", underline_types[ut].Cname);
-               font_selector_set_underline (state->font.selector, ut);
+               set_font_underline (state, ut);
        } else
                uline_str = "";
        gtk_entry_set_text (uline_entry, uline_str);
@@ -886,7 +1004,7 @@ fmt_dialog_init_font_page (FormatState *state)
                          "changed",
                          G_CALLBACK (cb_font_underline_changed), state);
        gtk_widget_show_all (uline);
-       replace_in_grid (go_gtk_builder_get_widget (state->gui, "underline_placeholder"),
+       go_gtk_widget_replace (go_gtk_builder_get_widget (state->gui, "underline_placeholder"),
                         uline);
 
        tmp = go_gtk_builder_get_widget (state->gui, "underline_label");
@@ -895,14 +1013,14 @@ fmt_dialog_init_font_page (FormatState *state)
        if (0 == (state->conflicts & (1 << MSTYLE_FONT_STRIKETHROUGH)))
                strikethrough = gnm_style_get_font_strike (state->style);
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (strike), strikethrough);
-       font_selector_set_strike (state->font.selector, strikethrough);
+       change_font_attr (state, pango_attr_strikethrough_new (strikethrough));
        g_signal_connect (G_OBJECT (strike),
                          "toggled",
                          G_CALLBACK (cb_font_strike_toggle), state);
 
        if (0 == (state->conflicts & (1 << MSTYLE_FONT_SCRIPT)))
                script = gnm_style_get_font_script (state->style);
-       font_selector_set_script (state->font.selector, script);
+       set_font_script (state, script);
        if (NULL != (tmp = go_gtk_builder_get_widget (state->gui, "superscript_button"))) {
                state->font.superscript = GTK_TOGGLE_BUTTON (tmp);
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tmp),
@@ -919,9 +1037,10 @@ fmt_dialog_init_font_page (FormatState *state)
        }
 
        if (0 == (state->conflicts & (1 << MSTYLE_FONT_COLOR)))
-               font_selector_set_color (
-                       state->font.selector,
-                       style_color_ref (gnm_style_get_font_color (state->style)));
+               change_font_attr
+                       (state,
+                        go_color_to_pango (gnm_style_get_font_color (state->style)->go_color,
+                                           TRUE));
 
        g_signal_connect (G_OBJECT (font_widget),
                          "font_changed",
@@ -1291,7 +1410,7 @@ draw_border_preview (FormatState *state)
                gtk_widget_show (GTK_WIDGET (state->border.canvas));
                gtk_widget_set_size_request (GTK_WIDGET (state->border.canvas),
                                             150, 100);
-               replace_in_grid (go_gtk_builder_get_widget (state->gui, "border_sample_placeholder"),
+               go_gtk_widget_replace (go_gtk_builder_get_widget (state->gui, "border_sample_placeholder"),
                                 GTK_WIDGET (state->border.canvas));
                group = GOC_GROUP (goc_canvas_get_root (state->border.canvas));
 
diff --git a/src/wbc-gtk-impl.h b/src/wbc-gtk-impl.h
index 0404bbb..1eb748d 100644
--- a/src/wbc-gtk-impl.h
+++ b/src/wbc-gtk-impl.h
@@ -114,7 +114,7 @@ struct _WBCGtk {
        GtkAction               *undo_vaction, *redo_vaction;
        GOActionComboColor      *fore_color, *back_color;
        GtkAction               *font_name;
-       GOActionComboText       *font_size, *zoom_haction;
+       GOActionComboText       *zoom_haction;
        GtkAction               *zoom_vaction;
        GOActionComboPixmaps    *borders, *halignment, *valignment;
        struct {
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 61261ce..5c4244c 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -50,6 +50,7 @@
 #include "gnumeric-conf.h"
 #include "dialogs/dialogs.h"
 #include "widgets/widget-editable-label.h"
+#include "widgets/gnm-fontbutton.h"
 #include "pixmaps/gnumeric-stock-pixbufs.h"
 #include "gui-clipboard.h"
 #include "libgnumeric.h"
@@ -3337,134 +3338,99 @@ wbc_gtk_init_color_back (WBCGtk *gtk)
 }
 /****************************************************************************/
 
+typedef struct { GtkAction base; } GnmFontAction;
+typedef struct { GtkActionClass base; } GnmFontActionClass;
+
+static PangoFontDescription *
+gnm_font_action_get_font_desc (GnmFontAction *act)
+{
+       PangoFontDescription *desc =
+               g_object_get_data (G_OBJECT (act), "font-data");
+       return desc;
+}
+
 static void
-set_font_name_feedback (GtkAction *act, const char *name)
+gnm_font_action_set_font_desc (GnmFontAction *act, PangoFontDescription *desc)
 {
-       char *tooltip = g_strdup_printf (_("Use font \"%s\""), name);
+       PangoFontDescription *old_desc;
+       GSList *p;
 
-       g_object_set (act,
-                     "label", name,
-                     "tooltip", tooltip,
-                     NULL);
+       old_desc = g_object_get_data (G_OBJECT (act), "font-data");
+       if (!old_desc) {
+               old_desc = pango_font_description_new ();
+               g_object_set_data_full (G_OBJECT (act),
+                                       "font-data", old_desc,
+                                       (GDestroyNotify)pango_font_description_free);
+       }
+       pango_font_description_merge (old_desc, desc, TRUE);
 
-       g_free (tooltip);
-}
+       for (p = gtk_action_get_proxies (GTK_ACTION (act)); p; p = p->next) {
+               GtkWidget *w = p->data;
+               GtkWidget *child;
+               GtkFontChooser *chooser;
 
-typedef struct { GtkAction base; } GnmFontAction;
-typedef struct { GtkActionClass base; } GnmFontActionClass;
+               if (!GTK_IS_BIN (w))
+                       continue;
 
-static void
-cb_font_name_selected (GtkMenuItem *i, GtkAction *act)
-{
-       const char *font_name = gtk_menu_item_get_label (i);
-       set_font_name_feedback (act, font_name);
-       gtk_action_activate (act);
+               child = gtk_bin_get_child (GTK_BIN (w));
+               if (!GTK_IS_FONT_CHOOSER (child))
+                       continue;
+
+               chooser = GTK_FONT_CHOOSER (child);
+               gtk_font_chooser_set_font_desc (chooser, old_desc);
+       }
 }
 
 static void
-add_font_to_menu (GtkWidget *m, const char *name, GtkAction *act)
+cb_font_set (GtkFontChooser *chooser, GnmFontAction *act)
 {
-       GtkWidget *w = gtk_menu_item_new_with_label (name);
-       gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
-       g_signal_connect (w,
-                         "activate",
-                         G_CALLBACK (cb_font_name_selected),
-                         act);
+       PangoFontDescription *desc = gtk_font_chooser_get_font_desc (chooser);
+       gnm_font_action_set_font_desc (act, desc);
+       pango_font_description_free (desc);
+       gtk_action_activate (GTK_ACTION (act));
 }
 
 static void
-cb_font_name_action_label (GtkAction *act, G_GNUC_UNUSED GParamSpec *pspec,
-                          GtkEntry *e)
+cb_font_button_screen_changed (GtkWidget *widget)
 {
-       gtk_entry_set_text (e, gtk_action_get_label (act));
+/* Doesn't look right */
+#if 0
+       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");
+               gtk_widget_set_size_request (widget, w, -1);
+       }
+#endif
 }
 
 static GtkWidget *
 gnm_font_action_create_tool_item (GtkAction *action)
 {
-       GtkWidget *item = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
-       GtkWidget *m, *e;
-       GSList *fast_choices, *p;
-       WBCGtk *wbcg = g_object_get_data (G_OBJECT (action), "wbcg");
-       PangoContext *context = gtk_widget_get_pango_context
-               (GTK_WIDGET (wbcg_toplevel (wbcg)));
-
-       m = gtk_menu_new ();
-       gtk_menu_set_title (GTK_MENU (m), _("Font"));
-
-       /* FIMXE: Where should these come from and how do we validate them?  */
-       fast_choices = go_slist_create
-               ((char *)"Sans", "Serif", "Monospace", NULL);
-       for (p = fast_choices; p; p = p->next) {
-               const char *name = p->data;
-               add_font_to_menu (m, name, action);
-       }
-       g_slist_free (fast_choices);
-
-       gtk_menu_shell_append (GTK_MENU_SHELL (m),
-                              gtk_separator_menu_item_new ());
-
-       {
-               GtkWidget *sm, *mall, *msingle = NULL, *mother = NULL;
-               GSList *p, *families = go_fonts_list_families (context);
-               gunichar uc = 0;
-               mall = gtk_menu_new ();
-               for (p = families; p != NULL; p = p->next) {
-                       const char *name = p->data;
-                       gunichar fc;
-                       if (!name || !*name)
-                               continue;
-                       fc = g_unichar_toupper (g_utf8_get_char (name));
-
-                       if (!g_unichar_isalpha (fc)) {
-                               if (!mother)
-                                       mother = gtk_menu_new ();
-                               add_font_to_menu (mother, name, action);
-                               continue;
-                       }
-
-                       if (fc != uc || !msingle) {
-                               char txt[10];
-
-                               uc = fc;
-                               txt[g_unichar_to_utf8 (uc, txt)] = 0;
-                               msingle = gtk_menu_new ();
-                               sm = gtk_menu_item_new_with_label (txt);
-                               gtk_menu_item_set_submenu (GTK_MENU_ITEM (sm), msingle);
-                               gtk_menu_shell_append (GTK_MENU_SHELL (mall), sm);
-                       }
-
-                       add_font_to_menu (msingle, name, action);
-               }
-               if (mother) {
-                       sm = gtk_menu_item_new_with_label (_("Other"));
-                       gtk_menu_item_set_submenu (GTK_MENU_ITEM (sm), mother);
-                       gtk_menu_shell_append (GTK_MENU_SHELL (mall), sm);
-               }
-
-               g_slist_free_full (families, (GDestroyNotify)g_free);
-               sm = gtk_menu_item_new_with_label (_("All fonts..."));
-               gtk_menu_item_set_submenu (GTK_MENU_ITEM (sm), mall);
-               gtk_menu_shell_append (GTK_MENU_SHELL (m), sm);
-       }
-
-       gtk_widget_show_all (m);
-       gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (item), m);
-
-       gtk_menu_tool_button_set_arrow_tooltip_text
-               (GTK_MENU_TOOL_BUTTON (item),
-                _("Pick another font"));
-
-       e = g_object_new (GTK_TYPE_ENTRY,
-                         "width-chars", 10,
-                         "editable", FALSE,
-                         NULL);
-       gtk_tool_button_set_label_widget (GTK_TOOL_BUTTON (item), e);
-       g_signal_connect (action,
-                         "notify::label",
-                         G_CALLBACK (cb_font_name_action_label),
-                         e);
-
+       GtkWidget *item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
+       GtkWidget *but = g_object_new
+               (gnm_font_button_get_type(),
+                "dialog-type", GO_TYPE_FONT_SEL_DIALOG,
+//              "dialog-type", GTK_TYPE_FONT_CHOOSER_DIALOG,
+                NULL);
+       gtk_widget_show_all (but);
+       gtk_button_set_relief
+               (GTK_BUTTON (but),
+                gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (item)));
+       gtk_button_set_focus_on_click (GTK_BUTTON (but), FALSE);
+       gtk_container_add (GTK_CONTAINER (item), but);
+       g_signal_connect (but,
+                         "font-set", G_CALLBACK (cb_font_set),
+                         action);
+       g_signal_connect (but,
+                         "screen-changed",
+                         G_CALLBACK (cb_font_button_screen_changed),
+                         action);
        return item;
 }
 
@@ -3480,12 +3446,17 @@ gnm_font_action_class_init (GObjectClass *gobject_class)
 static
 GSF_CLASS (GnmFontAction, gnm_font_action,
           gnm_font_action_class_init, NULL, GTK_TYPE_ACTION)
-
+#if 0
+       ;
+#endif
+#define GNM_FONT_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), gnm_font_action_get_type(), GnmFontAction))
 
 static void
-cb_font_name_changed (GtkAction *a, WBCGtk *gtk)
+cb_font_changed (GnmFontAction *act, WBCGtk *gtk)
 {
-       char const *new_name;
+       PangoFontDescription *desc = gnm_font_action_get_font_desc (act);
+       const char *family = pango_font_description_get_family (desc);
+       int size = pango_font_description_get_size (desc);
 
        /*
         * Ignore events during destruction.  This is an attempt at avoiding
@@ -3495,21 +3466,41 @@ cb_font_name_changed (GtkAction *a, WBCGtk *gtk)
        if (gtk->snotebook == NULL)
                return;
 
-       new_name = gtk_action_get_label (gtk->font_name);
+       if (wbcg_is_editing (WBC_GTK (gtk))) {
+               wbcg_edit_add_markup (WBC_GTK (gtk),
+                                     pango_attr_family_new (family));
+               wbcg_edit_add_markup (WBC_GTK (gtk),
+                                     pango_attr_size_new (size));
+       } else {
+               GnmStyle *style = gnm_style_new ();
+               char *font_name = pango_font_description_to_string (desc);
+               char *title = g_strdup_printf (_("Setting Font %s"), font_name);
+               g_free (font_name);
 
-       if (*new_name) {
-               if (wbcg_is_editing (WBC_GTK (gtk))) {
-                       wbcg_edit_add_markup (WBC_GTK (gtk),
-                               pango_attr_family_new (new_name));
-               } else {
-                       GnmStyle *style = gnm_style_new ();
-                       char *title = g_strdup_printf (_("Font Name %s"), new_name);
-                       gnm_style_set_font_name (style, new_name);
-                       cmd_selection_format (WORKBOOK_CONTROL (gtk), style, NULL, title);
-                       g_free (title);
-               }
-       } else
-               wb_control_style_feedback (WORKBOOK_CONTROL (gtk), NULL);
+               gnm_style_set_font_name (style, family);
+               gnm_style_set_font_size (style, size / (double)PANGO_SCALE);
+
+               cmd_selection_format (WORKBOOK_CONTROL (gtk), style, NULL, title);
+               g_free (title);
+       }
+}
+
+static void
+set_font_name_feedback (GtkAction *act, const char *family)
+{
+       PangoFontDescription *desc = pango_font_description_new ();
+       pango_font_description_set_family (desc, family);
+       gnm_font_action_set_font_desc (GNM_FONT_ACTION (act), desc);
+       pango_font_description_free (desc);
+}
+
+static void
+set_font_size_feedback (GtkAction *act, double size)
+{
+       PangoFontDescription *desc = pango_font_description_new ();
+       pango_font_description_set_size (desc, size * PANGO_SCALE);
+       gnm_font_action_set_font_desc (GNM_FONT_ACTION (act), desc);
+       pango_font_description_free (desc);
 }
 
 static void
@@ -3518,85 +3509,19 @@ wbc_gtk_init_font_name (WBCGtk *gtk)
        gtk->font_name = g_object_new
                (gnm_font_action_get_type (),
                 "name", "FontName",
-                //"stock-id", GTK_STOCK_SELECT_FONT,
+                "tooltip", _("Change font"),
                 NULL);
        g_object_set_data (G_OBJECT (gtk->font_name), "wbcg", gtk);
 
        g_signal_connect (G_OBJECT (gtk->font_name),
                "activate",
-               G_CALLBACK (cb_font_name_changed), gtk);
+               G_CALLBACK (cb_font_changed), gtk);
        gtk_action_group_add_action (gtk->font_actions,
                                     GTK_ACTION (gtk->font_name));
 }
-/****************************************************************************/
-
-static void
-cb_font_size_changed (GOActionComboText *a, WBCGtk *gtk)
-{
-       char const *new_size;
-       char *end;
-       double size;
 
-       /*
-        * Ignore events during destruction.  This is an attempt at avoiding
-        * https://bugzilla.redhat.com/show_bug.cgi?id=803904 for which we
-        * blame gtk.
-        */
-       if (gtk->snotebook == NULL)
-               return;
-
-       new_size = go_action_combo_text_get_entry (gtk->font_size);
-       size = go_strtod (new_size, &end);
-       size = floor ((size * 20.) + .5) / 20.; /* round .05 */
-
-       if (new_size != end && errno != ERANGE && 1. <= size && size <= 400.) {
-               if (wbcg_is_editing (WBC_GTK (gtk))) {
-                       wbcg_edit_add_markup (WBC_GTK (gtk),
-                               pango_attr_size_new (size * PANGO_SCALE));
-               } else {
-                       GnmStyle *style = gnm_style_new ();
-                       char *title = g_strdup_printf (_("Font Size %f"), size);
-                       gnm_style_set_font_size (style, size);
-                       cmd_selection_format (WORKBOOK_CONTROL (gtk), style, NULL, title);
-                       g_free (title);
-               }
-       } else
-               wb_control_style_feedback (WORKBOOK_CONTROL (gtk), NULL);
-}
-
-static void
-wbc_gtk_init_font_size (WBCGtk *gtk)
-{
-       GSList *ptr, *font_sizes;
-
-       gtk->font_size = g_object_new (go_action_combo_text_get_type (),
-                                      "name", "FontSize",
-                                      "stock-id", GTK_STOCK_SELECT_FONT,
-                                      "visible-vertical", FALSE,
-                                      "label", _("Font Size"),
-                                      "tooltip", _("Font Size"),
-                                      NULL);
-
-       /* TODO: Create vertical version of this.  */
+/****************************************************************************/
 
-       font_sizes = go_fonts_list_sizes ();
-       for (ptr = font_sizes; ptr != NULL ; ptr = ptr->next) {
-               int psize = GPOINTER_TO_INT (ptr->data);
-               char *size_text = g_strdup_printf ("%g", psize / (double)PANGO_SCALE);
-               go_action_combo_text_add_item (gtk->font_size, size_text);
-               g_free (size_text);
-       }
-       g_slist_free (font_sizes);
-       go_action_combo_text_set_width (gtk->font_size, "888");
-       g_signal_connect (G_OBJECT (gtk->font_size),
-               "activate",
-               G_CALLBACK (cb_font_size_changed), gtk);
-#if 0
-       gnm_combo_box_set_title (GO_COMBO_BOX (fore_combo), _("Foreground"));
-#endif
-       gtk_action_group_add_action (gtk->font_actions,
-               GTK_ACTION (gtk->font_size));
-}
 static WorkbookControl *
 wbc_gtk_control_new (G_GNUC_UNUSED WorkbookControl *wbc,
                     WorkbookView *wbv,
@@ -3685,12 +3610,9 @@ wbc_gtk_style_feedback_real (WorkbookControl *wbc, GnmStyle const *changes)
                go_action_combo_pixmaps_select_id (wbcg->valignment, align);
        }
 
-       if (gnm_style_is_element_set (changes, MSTYLE_FONT_SIZE)) {
-               char *size_str = g_strdup_printf ("%d", (int)gnm_style_get_font_size (changes));
-               go_action_combo_text_set_entry (wbcg->font_size,
-                       size_str, GO_ACTION_COMBO_SEARCH_FROM_TOP);
-               g_free (size_str);
-       }
+       if (gnm_style_is_element_set (changes, MSTYLE_FONT_SIZE))
+               set_font_size_feedback (wbcg->font_name,
+                                       gnm_style_get_font_size (changes));
 
        if (gnm_style_is_element_set (changes, MSTYLE_FONT_NAME))
                set_font_name_feedback (wbcg->font_name,
@@ -5246,7 +5168,6 @@ wbc_gtk_finalize (GObject *obj)
        UNREF_OBJ (fore_color);
        UNREF_OBJ (back_color);
        UNREF_OBJ (font_name);
-       UNREF_OBJ (font_size);
        UNREF_OBJ (redo_haction);
        UNREF_OBJ (redo_vaction);
        UNREF_OBJ (undo_haction);
@@ -5787,7 +5708,6 @@ wbc_gtk_init (GObject *obj)
        wbc_gtk_init_color_fore (wbcg);
        wbc_gtk_init_color_back (wbcg);
        wbc_gtk_init_font_name (wbcg);
-       wbc_gtk_init_font_size (wbcg);
        wbc_gtk_init_zoom (wbcg);
        wbc_gtk_init_borders (wbcg);
 
diff --git a/src/widgets/Makefile.am b/src/widgets/Makefile.am
index bef5e04..6315b91 100644
--- a/src/widgets/Makefile.am
+++ b/src/widgets/Makefile.am
@@ -20,8 +20,6 @@ libwidgets_la_SOURCES =                               \
        gnm-radiobutton.h                       \
        widget-editable-label.c                 \
        widget-editable-label.h                 \
-       widget-font-selector.c                  \
-       widget-font-selector.h                  \
        gnm-cell-combo-view.c           \
        gnm-cell-combo-view.h           \
        gnm-cell-combo-view-impl.h              \


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