2 * gnm-format-sel.c: Gnumeric extensions to the format selector widget
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <https://www.gnu.org/licenses/>.
18 #include <gnumeric-config.h>
19 #include <widgets/gnm-format-sel.h>
20 #include <src/value.h>
21 #include <src/gnm-format.h>
22 #include <src/style-font.h>
25 cb_generate_preview (GOFormatSel
*gfs
, PangoAttrList
**attrs
)
27 GnmValue
const *v
= g_object_get_data (G_OBJECT (gfs
), "value");
32 GOFormat
const *fmt
= go_format_sel_get_fmt (gfs
);
33 GtkWidget
*w
= GTK_WIDGET (gfs
);
34 PangoContext
*context
= gtk_widget_get_pango_context (w
);
35 PangoLayout
*layout
= pango_layout_new (context
);
37 GOFormatNumberError err
;
39 if (go_format_is_general (fmt
) && VALUE_FMT (v
) != NULL
)
41 err
= format_value_layout (layout
, fmt
, v
, -1,
42 go_format_sel_get_dateconv (gfs
));
47 str
= g_strdup (pango_layout_get_text (layout
));
48 go_pango_translate_layout (layout
);
49 *attrs
= pango_attr_list_ref (pango_layout_get_attributes (layout
));
51 g_object_unref (layout
);
59 * Returns: (transfer full): a new format selector
62 gnm_format_sel_new (void)
64 GObject
*w
= G_OBJECT (go_format_sel_new_full (TRUE
));
65 g_signal_connect (w
, "generate-preview",
66 G_CALLBACK (cb_generate_preview
), NULL
);
67 return GTK_WIDGET (w
);
71 gnm_format_sel_set_value (GOFormatSel
*gfs
, GnmValue
const *value
)
73 g_return_if_fail (GO_IS_FORMAT_SEL (gfs
));
74 g_return_if_fail (value
!= NULL
);
76 g_object_set_data_full (G_OBJECT (gfs
),
77 "value", value_dup (value
), (GDestroyNotify
) value_release
);
78 go_format_sel_show_preview (gfs
);