[goffice] Font Selector: add underline support.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Font Selector: add underline support.
- Date: Thu, 21 Mar 2013 14:58:06 +0000 (UTC)
commit 5fedaecf35bd99d21d895a16449beda4bc6d2da1
Author: Morten Welinder <terra gnome org>
Date: Thu Mar 21 10:57:45 2013 -0400
Font Selector: add underline support.
ChangeLog | 7 +++
goffice/gtk/go-font-sel.c | 106 ++++++++++++++++++++++++++++++++++++-------
goffice/gtk/go-font-sel.ui | 43 ++++++++++++++++--
goffice/gtk/go-optionmenu.c | 25 ++++++++++
goffice/gtk/go-optionmenu.h | 5 ++-
goffice/gtk/goffice-gtk.c | 3 +-
6 files changed, 167 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f032fc5..e8d8338 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-03-21 Morten Welinder <terra gnome org>
+
+ * goffice/gtk/go-optionmenu.c (go_option_menu_build): New
+ function.
+
+ * goffice/gtk/go-font-sel.c: Add underline support.
+
2013-03-20 Morten Welinder <terra gnome org>
* goffice/gtk/go-optionmenu.c (go_option_menu_set_history): Plug
diff --git a/goffice/gtk/go-font-sel.c b/goffice/gtk/go-font-sel.c
index 2aa7216..6556a9b 100644
--- a/goffice/gtk/go-font-sel.c
+++ b/goffice/gtk/go-font-sel.c
@@ -56,6 +56,9 @@ struct _GOFontSel {
char *color_unset_text;
GOColor color_default;
+ gboolean show_underline;
+ GtkWidget *underline_picker;
+
gboolean show_strikethrough;
GtkWidget *strikethrough_button;
@@ -83,11 +86,13 @@ enum {
PROP_0,
PROP_SHOW_STYLE,
PROP_SHOW_COLOR,
+ PROP_SHOW_UNDERLINE,
PROP_SHOW_SCRIPT,
PROP_SHOW_STRIKETHROUGH,
PROP_COLOR_UNSET_TEXT,
PROP_COLOR_GROUP,
PROP_COLOR_DEFAULT,
+ PROP_UNDERLINE_PICKER,
GFS_GTK_FONT_CHOOSER_PROP_FIRST = 0x4000,
GFS_GTK_FONT_CHOOSER_PROP_FONT,
@@ -740,6 +745,20 @@ cb_color_changed (GOComboColor *color_picker, GOColor color,
static void
+cb_underline_changed (GOOptionMenu *om, GOFontSel *gfs)
+{
+ GtkWidget *selected = go_option_menu_get_history (om);
+ PangoUnderline u;
+
+ if (!selected)
+ return;
+
+ u = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (selected), "value"));
+ go_font_sel_add_attr (gfs, pango_attr_underline_new (u));
+ go_font_sel_emit_changed (gfs);
+}
+
+static void
cb_script_changed (GOOptionMenu *om, GOFontSel *gfs)
{
GtkWidget *selected = go_option_menu_get_history (om);
@@ -750,7 +769,7 @@ cb_script_changed (GOOptionMenu *om, GOFontSel *gfs)
return;
script = GPOINTER_TO_INT
- (g_object_get_data (G_OBJECT (selected), "script"));
+ (g_object_get_data (G_OBJECT (selected), "value"));
is_super = (script == GO_FONT_SCRIPT_SUPER);
is_sub = (script == GO_FONT_SCRIPT_SUB);
@@ -866,6 +885,7 @@ gfs_constructor (GType type,
go_combo_color_new (NULL, gfs->color_unset_text,
gfs->color_default,
gfs->color_group);
+ gtk_widget_set_halign (gfs->color_picker, GTK_ALIGN_START);
g_object_ref_sink (gfs->color_picker);
gtk_widget_show_all (gfs->color_picker);
go_gtk_widget_replace (placeholder, gfs->color_picker);
@@ -879,25 +899,43 @@ gfs_constructor (GType type,
/* ---------------------------------------- */
placeholder = go_gtk_builder_get_widget
+ (gfs->gui, "underline-picker-placeholder");
+ if (!gfs->underline_picker) {
+ gfs->underline_picker = go_option_menu_build
+ (C_("underline", "None"), PANGO_UNDERLINE_NONE,
+ C_("underline", "Single"), PANGO_UNDERLINE_SINGLE,
+ C_("underline", "Double"), PANGO_UNDERLINE_DOUBLE,
+ C_("underline", "Low"), PANGO_UNDERLINE_LOW,
+ C_("underline", "Error"), PANGO_UNDERLINE_ERROR,
+ NULL);
+ if (gfs->show_underline)
+ g_signal_connect (gfs->underline_picker,
+ "changed",
+ G_CALLBACK (cb_underline_changed),
+ gfs);
+ }
+ g_object_ref_sink (gfs->underline_picker);
+ gtk_widget_show_all (gfs->underline_picker);
+ go_gtk_widget_replace (placeholder, gfs->underline_picker);
+ if (gfs->show_underline) {
+ /* Nothing here */
+ } else
+ remove_row_containing (gfs->underline_picker);
+
+ /* ---------------------------------------- */
+
+ placeholder = go_gtk_builder_get_widget
(gfs->gui, "script-picker-placeholder");
- gfs->script_picker = go_option_menu_new ();
+ gfs->script_picker =
+ go_option_menu_build (_("Normal"), GO_FONT_SCRIPT_STANDARD,
+ _("Subscript"), GO_FONT_SCRIPT_SUB,
+ _("Superscript"), GO_FONT_SCRIPT_SUPER,
+ NULL);
+
g_object_ref_sink (gfs->script_picker);
gtk_widget_show_all (gfs->script_picker);
go_gtk_widget_replace (placeholder, gfs->script_picker);
if (gfs->show_script) {
- GtkWidget *m = gtk_menu_new ();
- add_item_to_menu (m, _("Normal"),
- "script", GINT_TO_POINTER (GO_FONT_SCRIPT_STANDARD),
- NULL);
- add_item_to_menu (m, _("Subscript"),
- "script", GINT_TO_POINTER (GO_FONT_SCRIPT_SUB),
- NULL);
- add_item_to_menu (m, _("Superscript"),
- "script", GINT_TO_POINTER (GO_FONT_SCRIPT_SUPER),
- NULL);
- gtk_widget_show_all (m);
- go_option_menu_set_menu (GO_OPTION_MENU (gfs->script_picker),
- m);
g_signal_connect (gfs->script_picker,
"changed",
G_CALLBACK (cb_script_changed),
@@ -936,6 +974,7 @@ gfs_finalize (GObject *obj)
g_clear_object (&gfs->face_picker);
g_clear_object (&gfs->color_picker);
g_clear_object (&gfs->color_group);
+ g_clear_object (&gfs->underline_picker);
g_clear_object (&gfs->script_picker);
g_clear_object (&gfs->strikethrough_button);
@@ -997,6 +1036,10 @@ gfs_get_property (GObject *object,
g_value_set_boolean (value, gfs->show_color);
break;
+ case PROP_SHOW_UNDERLINE:
+ g_value_set_boolean (value, gfs->show_underline);
+ break;
+
case PROP_SHOW_SCRIPT:
g_value_set_boolean (value, gfs->show_script);
break;
@@ -1017,6 +1060,10 @@ gfs_get_property (GObject *object,
g_value_set_uint (value, gfs->color_default);
break;
+ case PROP_UNDERLINE_PICKER:
+ g_value_set_object (value, gfs->underline_picker);
+ break;
+
case GFS_GTK_FONT_CHOOSER_PROP_FONT: {
PangoFontDescription *desc = go_font_sel_get_font_desc (gfs);
g_value_take_string (value, pango_font_description_to_string (desc));
@@ -1059,6 +1106,10 @@ gfs_set_property (GObject *object,
gfs->show_color = g_value_get_boolean (value);
break;
+ case PROP_SHOW_UNDERLINE:
+ gfs->show_underline = g_value_get_boolean (value);
+ break;
+
case PROP_SHOW_SCRIPT:
gfs->show_script = g_value_get_boolean (value);
break;
@@ -1081,6 +1132,11 @@ gfs_set_property (GObject *object,
gfs->color_default = g_value_get_uint (value);
break;
+ case PROP_UNDERLINE_PICKER:
+ g_clear_object (&gfs->underline_picker);
+ gfs->underline_picker = g_value_dup_object (value);
+ break;
+
case GFS_GTK_FONT_CHOOSER_PROP_FONT: {
PangoFontDescription *desc = pango_font_description_from_string
(g_value_get_string (value));
@@ -1142,6 +1198,15 @@ gfs_class_init (GObjectClass *klass)
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
+ (klass, PROP_SHOW_UNDERLINE,
+ g_param_spec_boolean ("show-underline",
+ _("Show Underline"),
+ _("Whether underlining is part of the font being selected"),
+ FALSE,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property
(klass, PROP_SHOW_SCRIPT,
g_param_spec_boolean ("show-script",
_("Show Script"),
@@ -1188,6 +1253,15 @@ gfs_class_init (GObjectClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property
+ (klass, PROP_UNDERLINE_PICKER,
+ g_param_spec_object ("underline-picker",
+ _("Underline Picker"),
+ _("The widget to use for picking underline type"),
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
+
g_object_class_override_property (klass,
GFS_GTK_FONT_CHOOSER_PROP_FONT,
"font");
@@ -1450,7 +1524,7 @@ go_font_sel_set_script (GOFontSel *fs, GOFontScript script)
for (l = children; l; l = l->next) {
GtkMenuItem *item = GTK_MENU_ITEM (l->data);
GOFontScript s = GPOINTER_TO_INT
- (g_object_get_data (G_OBJECT (item), "script"));
+ (g_object_get_data (G_OBJECT (item), "value"));
if (s == script)
go_option_menu_select_item (om, item);
}
diff --git a/goffice/gtk/go-font-sel.ui b/goffice/gtk/go-font-sel.ui
index 691d632..9be85c4 100644
--- a/goffice/gtk/go-font-sel.ui
+++ b/goffice/gtk/go-font-sel.ui
@@ -124,24 +124,26 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="strikethrough-button">
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
+ <property name="use_action_appearance">False</property>
<property name="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">4</property>
+ <property name="top_attach">5</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@@ -192,7 +194,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">5</property>
+ <property name="top_attach">6</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@@ -207,7 +209,40 @@
</object>
<packing>
<property name="left_attach">1</property>
- <property name="top_attach">5</property>
+ <property name="top_attach">6</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label6">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip_markup" translatable="yes">Select the type of underlining</property>
+ <property name="tooltip_text" translatable="yes">Select the type of underlining</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Underline:</property>
+ <property name="justify">center</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">4</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="underline-picker-placeholder">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
diff --git a/goffice/gtk/go-optionmenu.c b/goffice/gtk/go-optionmenu.c
index 7e33545..f7b05cd 100644
--- a/goffice/gtk/go-optionmenu.c
+++ b/goffice/gtk/go-optionmenu.c
@@ -37,6 +37,7 @@
#include <gdk/gdkkeysyms.h>
#include <glib/gi18n-lib.h>
#include <gsf/gsf-impl-utils.h>
+#include <stdarg.h>
enum {
@@ -59,6 +60,30 @@ go_option_menu_new (void)
return g_object_new (GO_TYPE_OPTION_MENU, NULL);
}
+
+GtkWidget *
+go_option_menu_build (const char *first_entry, ...)
+{
+ GtkMenu *m = gtk_menu_new ();
+ GtkWidget *om;
+ va_list var_args;
+
+ va_start (var_args, first_entry);
+ while (first_entry) {
+ int v = va_arg (var_args, int);
+ GtkWidget *w = gtk_menu_item_new_with_label (first_entry);
+ gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
+ g_object_set_data (G_OBJECT (w), "value", GINT_TO_POINTER (v));
+ first_entry = va_arg (var_args, char *);
+ }
+ va_end (var_args);
+ gtk_widget_show_all (GTK_WIDGET (m));
+
+ om = go_option_menu_new ();
+ go_option_menu_set_menu (GO_OPTION_MENU (om), m);
+ return om;
+}
+
static void
go_option_menu_detacher (GtkWidget *widget, GtkMenu *menu)
{
diff --git a/goffice/gtk/go-optionmenu.h b/goffice/gtk/go-optionmenu.h
index 83357e4..e068e1f 100644
--- a/goffice/gtk/go-optionmenu.h
+++ b/goffice/gtk/go-optionmenu.h
@@ -74,7 +74,10 @@ struct _GOOptionMenuClass
GType go_option_menu_get_type (void) G_GNUC_CONST;
-GtkWidget* go_option_menu_new (void);
+
+GtkWidget *go_option_menu_new (void);
+GtkWidget *go_option_menu_build (const char *first_entry, ...);
+
GtkWidget *go_option_menu_get_menu (GOOptionMenu *option_menu);
void go_option_menu_set_menu (GOOptionMenu *option_menu,
GtkWidget *menu);
diff --git a/goffice/gtk/goffice-gtk.c b/goffice/gtk/goffice-gtk.c
index 397af54..355c3af 100644
--- a/goffice/gtk/goffice-gtk.c
+++ b/goffice/gtk/goffice-gtk.c
@@ -535,7 +535,8 @@ go_gtk_widget_replace (GtkWidget *victim, GtkWidget *replacement)
padding, pack_type);
gtk_box_reorder_child (box, replacement, pos);
} else {
- g_error ("Unsupported container");
+ g_error ("Unsupported container: %s",
+ g_type_name_from_instance ((gpointer)parent));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]