[goffice] Font Selector: add some meat to strikethrough, color, script pickers.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Font Selector: add some meat to strikethrough, color, script pickers.
- Date: Mon, 18 Mar 2013 01:50:24 +0000 (UTC)
commit 81bc83375cc8c32a763a3ed00462ecf9cdc8bc35
Author: Morten Welinder <terra gnome org>
Date: Sun Mar 17 21:49:49 2013 -0400
Font Selector: add some meat to strikethrough, color, script pickers.
ChangeLog | 5 ++
goffice/gtk/go-font-sel.c | 126 +++++++++++++++++++++++++++++++-----------
goffice/gtk/go-font-sel.h | 1 +
goffice/gtk/go-font-sel.ui | 2 +
goffice/gtk/go-optionmenu.c | 4 ++
5 files changed, 105 insertions(+), 33 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 43295ad..2de00c2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-03-17 Morten Welinder <terra gnome org>
+
+ * goffice/gtk/go-optionmenu.c (go_option_menu_button_press): Focus
+ on click if button is set to do that.
+
2013-03-16 Morten Welinder <terra gnome org>
* goffice/gtk/goffice-gtk.c (go_gtk_grid_remove_row): New
diff --git a/goffice/gtk/go-font-sel.c b/goffice/gtk/go-font-sel.c
index be8320b..d1910ec 100644
--- a/goffice/gtk/go-font-sel.c
+++ b/goffice/gtk/go-font-sel.c
@@ -50,6 +50,7 @@ struct _GOFontSel {
gboolean show_color;
GtkWidget *color_picker;
+ GOColorGroup *color_group;
gboolean show_strikethrough;
GtkWidget *strikethrough_button;
@@ -219,15 +220,15 @@ my_get_face_name (PangoFontFace *face)
}
static GtkMenuItem *
-add_font_to_menu (GtkWidget *m, const char *name,
- const char *what, gpointer obj,
+add_item_to_menu (GtkWidget *m, const char *name,
+ const char *what, gpointer data,
GHashTable *itemhash)
{
GtkWidget *w = gtk_menu_item_new_with_label (name);
gtk_menu_shell_append (GTK_MENU_SHELL (m), w);
- g_object_set_data (G_OBJECT (w), what, obj);
- if (!g_hash_table_lookup (itemhash, obj))
- g_hash_table_insert (itemhash, obj, w);
+ g_object_set_data (G_OBJECT (w), what, data);
+ if (itemhash && !g_hash_table_lookup (itemhash, data))
+ g_hash_table_insert (itemhash, data, w);
return GTK_MENU_ITEM (w);
}
@@ -259,7 +260,7 @@ reload_faces (GOFontSel *gfs)
faces = faces->next) {
PangoFontFace *face = faces->data;
const char *name = my_get_face_name (face);
- GtkMenuItem *w = add_font_to_menu
+ GtkMenuItem *w = add_item_to_menu
(m, g_dpgettext2 (NULL, "FontFace", name),
"face", face, gfs->item_by_face);
@@ -405,7 +406,7 @@ reload_families (GOFontSel *gfs)
g_hash_table_lookup (gfs->family_by_name, name);
if (family) {
has_priority = TRUE;
- add_font_to_menu (m, name,
+ add_item_to_menu (m, name,
"family", family,
gfs->item_by_family);
}
@@ -451,7 +452,7 @@ reload_families (GOFontSel *gfs)
if (!g_unichar_isalpha (fc)) {
if (!mother)
mother = gtk_menu_new ();
- add_font_to_menu (mother, name,
+ add_item_to_menu (mother, name,
"family", family,
gfs->item_by_family);
continue;
@@ -466,7 +467,7 @@ reload_families (GOFontSel *gfs)
add_submenu_to_menu (mall, txt, msingle);
}
- add_font_to_menu (msingle, name,
+ add_item_to_menu (msingle, name,
"family", family,
gfs->item_by_family);
}
@@ -537,19 +538,6 @@ update_sizes (GOFontSel *gfs)
static void
-cb_face_changed (GOOptionMenu *om, GOFontSel *gfs)
-{
- GtkWidget *selected = go_option_menu_get_history (om);
- PangoFontFace *face = selected
- ? g_object_get_data (G_OBJECT (selected), "face")
- : NULL;
- if (face && face != gfs->current_face) {
- gfs->current_face = face;
- update_preview_after_face_change (gfs, TRUE);
- }
-}
-
-static void
cb_font_changed (GOOptionMenu *om, GOFontSel *gfs)
{
GtkWidget *selected = go_option_menu_get_history (om);
@@ -565,6 +553,19 @@ cb_font_changed (GOOptionMenu *om, GOFontSel *gfs)
}
}
+static void
+cb_face_changed (GOOptionMenu *om, GOFontSel *gfs)
+{
+ GtkWidget *selected = go_option_menu_get_history (om);
+ PangoFontFace *face = selected
+ ? g_object_get_data (G_OBJECT (selected), "face")
+ : NULL;
+ if (face && face != gfs->current_face) {
+ gfs->current_face = face;
+ update_preview_after_face_change (gfs, TRUE);
+ }
+}
+
static gboolean
cb_size_picker_acticated (GtkEntry *entry, GOFontSel *gfs)
{
@@ -608,6 +609,34 @@ cb_size_picker_changed (GtkButton *button, GOFontSel *gfs)
}
static void
+cb_strikethrough_changed (GtkToggleButton *but, GOFontSel *gfs)
+{
+ gboolean b = gtk_toggle_button_get_active (but);
+ go_font_sel_add_attr (gfs, pango_attr_strikethrough_new (b));
+ go_font_sel_emit_changed (gfs);
+}
+
+static void
+cb_script_changed (GOOptionMenu *om, GOFontSel *gfs)
+{
+ GtkWidget *selected = go_option_menu_get_history (om);
+ GOFontScript script;
+ gboolean is_sub, is_super;
+
+ if (!selected)
+ return;
+
+ script = GPOINTER_TO_INT
+ (g_object_get_data (G_OBJECT (selected), "script"));
+ is_super = (script == GO_FONT_SCRIPT_SUPER);
+ is_sub = (script == GO_FONT_SCRIPT_SUB);
+
+ go_font_sel_add_attr (gfs, go_pango_attr_subscript_new (is_sub));
+ go_font_sel_add_attr (gfs, go_pango_attr_superscript_new (is_super));
+ go_font_sel_emit_changed (gfs);
+}
+
+static void
gfs_init (GOFontSel *gfs)
{
gfs->family_by_name = g_hash_table_new_full
@@ -707,7 +736,11 @@ gfs_constructor (GType type,
placeholder = go_gtk_builder_get_widget
(gfs->gui, "color-picker-placeholder");
- gfs->color_picker = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ if (!gfs->color_group)
+ gfs->color_group = go_color_group_fetch (NULL, gfs);
+ gfs->color_picker =
+ go_combo_color_new (NULL, "?", GO_COLOR_BLACK,
+ gfs->color_group);
g_object_ref_sink (gfs->color_picker);
gtk_widget_show_all (gfs->color_picker);
go_gtk_widget_replace (placeholder, gfs->color_picker);
@@ -719,11 +752,28 @@ gfs_constructor (GType type,
placeholder = go_gtk_builder_get_widget
(gfs->gui, "script-picker-placeholder");
- gfs->script_picker = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gfs->script_picker = go_option_menu_new ();
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),
+ gfs);
} else
remove_row_containing (gfs->script_picker);
@@ -734,6 +784,9 @@ gfs_constructor (GType type,
g_object_ref_sink (gfs->strikethrough_button);
gtk_widget_show_all (gfs->strikethrough_button);
if (gfs->show_strikethrough) {
+ g_signal_connect (gfs->strikethrough_button,
+ "toggled",
+ G_CALLBACK (cb_strikethrough_changed), gfs);
} else
remove_row_containing (gfs->strikethrough_button);
@@ -750,10 +803,19 @@ static void
gfs_finalize (GObject *obj)
{
GOFontSel *gfs = GO_FONT_SEL (obj);
+
+ /* We actually own a ref to these. */
+ g_clear_object (&gfs->face_picker);
+ g_clear_object (&gfs->color_picker);
+ g_clear_object (&gfs->color_group);
+ g_clear_object (&gfs->script_picker);
+ g_clear_object (&gfs->strikethrough_button);
+
g_hash_table_destroy (gfs->family_by_name);
g_hash_table_destroy (gfs->item_by_family);
g_hash_table_destroy (gfs->item_by_face);
g_hash_table_destroy (gfs->faces_by_family);
+
gfs_parent_class->finalize (obj);
}
@@ -762,12 +824,6 @@ gfs_dispose (GObject *obj)
{
GOFontSel *gfs = GO_FONT_SEL (obj);
- /* We actually own a ref to these. */
- g_clear_object (&gfs->face_picker);
- g_clear_object (&gfs->color_picker);
- g_clear_object (&gfs->script_picker);
- g_clear_object (&gfs->strikethrough_button);
-
if (gfs->gui) {
g_object_unref (gfs->gui);
gfs->gui = NULL;
@@ -1159,9 +1215,13 @@ go_font_sel_set_size (GOFontSel *fs, int size)
}
-static void
-go_font_sel_set_strike (GOFontSel *gfs, gboolean strike)
+void
+go_font_sel_set_strikethrough (GOFontSel *fs, gboolean strikethrough)
{
+ gtk_toggle_button_set_active
+ (GTK_TOGGLE_BUTTON (fs->strikethrough_button), strikethrough);
+ go_font_sel_add_attr (fs, pango_attr_strikethrough_new (strikethrough));
+ update_preview (fs);
}
static void
@@ -1202,7 +1262,7 @@ go_font_sel_set_font (GOFontSel *fs, GOFont const *font)
g_return_if_fail (GO_IS_FONT_SEL (fs));
go_font_sel_set_font_desc (fs, font->desc);
- go_font_sel_set_strike (fs, font->strikethrough);
+ go_font_sel_set_strikethrough (fs, font->strikethrough);
go_font_sel_set_uline (fs, font->underline);
go_font_sel_set_color (fs, font->color);
}
diff --git a/goffice/gtk/go-font-sel.h b/goffice/gtk/go-font-sel.h
index d53446f..61c7f91 100644
--- a/goffice/gtk/go-font-sel.h
+++ b/goffice/gtk/go-font-sel.h
@@ -44,6 +44,7 @@ void go_font_sel_set_family (GOFontSel *fs, char const *family);
void go_font_sel_set_size (GOFontSel *fs, int size);
void go_font_sel_set_style (GOFontSel *fs,
PangoWeight weight, PangoStyle style);
+void go_font_sel_set_strikethrough (GOFontSel *fs, gboolean strikethrough);
void go_font_sel_set_font_desc (GOFontSel *fs, PangoFontDescription *desc);
PangoFontDescription *go_font_sel_get_font_desc (GOFontSel *fs);
diff --git a/goffice/gtk/go-font-sel.ui b/goffice/gtk/go-font-sel.ui
index aeec894..691d632 100644
--- a/goffice/gtk/go-font-sel.ui
+++ b/goffice/gtk/go-font-sel.ui
@@ -134,6 +134,8 @@
<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="xalign">0</property>
<property name="draw_indicator">True</property>
</object>
diff --git a/goffice/gtk/go-optionmenu.c b/goffice/gtk/go-optionmenu.c
index 44f8555..eff224b 100644
--- a/goffice/gtk/go-optionmenu.c
+++ b/goffice/gtk/go-optionmenu.c
@@ -178,6 +178,9 @@ go_option_menu_button_press (GtkWidget *widget,
option_menu = GO_OPTION_MENU (widget);
if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
+ if (!gtk_widget_has_focus (widget) &&
+ gtk_button_get_focus_on_click (GTK_BUTTON (widget)))
+ gtk_widget_grab_focus (widget);
gtk_menu_popup (GTK_MENU (option_menu->menu), NULL, NULL,
go_option_menu_position, option_menu,
event->button, event->time);
@@ -433,6 +436,7 @@ go_option_menu_init (GOOptionMenu *option_menu)
gtk_widget_push_composite_child ();
gtk_widget_set_can_focus (GTK_WIDGET (option_menu), TRUE);
+ gtk_button_set_focus_on_click (GTK_BUTTON (option_menu), TRUE);
gtk_widget_set_can_default (GTK_WIDGET (option_menu), FALSE);
gtk_widget_set_receives_default (GTK_WIDGET (option_menu), FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]