Implement a font combobox and use it for Default Font Family.

This commit is contained in:
Christian Dywan 2008-04-20 18:12:39 +02:00
parent 4d11cf3555
commit 1264eb0667
3 changed files with 36 additions and 4 deletions

View File

@ -48,6 +48,15 @@ proxy_uri_file_set_cb (GtkFileChooser* button,
g_object_set (object, property, file, NULL);
}
static gchar*
proxy_combo_box_text_changed_cb (GtkComboBox* button, GObject* object)
{
gchar* text = gtk_combo_box_get_active_text (button);
const gchar* property = g_object_get_data (G_OBJECT (button), "property");
g_object_set (object, property, text, NULL);
return FALSE;
}
static gboolean
proxy_entry_focus_out_event_cb (GtkEntry* entry,
GdkEventFocus* event,
@ -62,7 +71,7 @@ proxy_entry_focus_out_event_cb (GtkEntry* entry,
static gboolean
proxy_spin_button_changed_cb (GtkSpinButton* button, GObject* object)
{
gdouble value = gtk_spin_button_get_value (button);
gint value = gtk_spin_button_get_value_as_int (button);
const gchar* property = g_object_get_data (G_OBJECT (button), "property");
g_object_set (object, property, value, NULL);
return FALSE;
@ -96,6 +105,8 @@ proxy_combo_box_changed_cb (GtkComboBox* button, GObject* object)
* choosing an existing folder.
* "uri": the widget created will be particularly suitable for
* choosing an existing filename, encoded as an URI.
* "font": the widget created will be particularly suitable for
* choosing a font from installed fonts.
*
* Any other values for @hint are silently ignored.
*
@ -167,6 +178,27 @@ katze_property_proxy (gpointer object,
g_signal_connect (widget, "file-set",
G_CALLBACK (proxy_uri_file_set_cb), object);
}
else if (type == G_TYPE_PARAM_STRING && _hint == g_intern_string ("font"))
{
widget = gtk_combo_box_new_text ();
PangoContext* context = gtk_widget_get_pango_context (widget);
PangoFontFamily** families;
int n_families;
pango_context_list_families (context, &families, &n_families);
g_object_get (object, property, &string, NULL);
gint i = 0;
while (i < n_families)
{
const gchar* font = pango_font_family_get_name (families[i]);
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), font);
if (string && !strcmp (font, string))
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), i);
i++;
}
g_signal_connect (widget, "changed",
G_CALLBACK (proxy_combo_box_text_changed_cb), object);
g_free (families);
}
else if (type == G_TYPE_PARAM_STRING)
{
widget = gtk_entry_new ();
@ -182,7 +214,7 @@ katze_property_proxy (gpointer object,
widget = gtk_spin_button_new_with_range (
G_PARAM_SPEC_INT (pspec)->minimum,
G_PARAM_SPEC_INT (pspec)->maximum, 1);
gdouble value;
gint value;
g_object_get (object, property, &value, NULL);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), value);
g_signal_connect (widget, "changed",

View File

@ -53,7 +53,7 @@ static void stock_items_init(void)
{ STOCK_TAB_NEW, N_("New _Tab"), 0, 0, NULL },
{ STOCK_WINDOW_NEW, N_("New _Window"), 0, 0, NULL },
#if !GTK_CHECK_VERSION(2, 10, 0)
{ GTK_STOCK_SELECT_ALL, N_("Select _All", 0, 0, NULL },
{ GTK_STOCK_SELECT_ALL, N_("Select _All"), 0, 0, NULL },
#endif
#if !GTK_CHECK_VERSION(2, 8, 0)
{ GTK_STOCK_FULLSCREEN, N_("_Fullscreen"), 0, 0, NULL },

View File

@ -264,7 +264,7 @@ midori_preferences_set_settings (MidoriPreferences* preferences,
label = katze_property_label (settings, "default-font-family");
INDENTED_ADD (label, 0, 1, 0, 1);
hbox = gtk_hbox_new (FALSE, 4);
button = katze_property_proxy (settings, "default-font-family", NULL);
button = katze_property_proxy (settings, "default-font-family", "font");
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
entry = katze_property_proxy (settings, "default-font-size", NULL);
gtk_box_pack_end (GTK_BOX (hbox), entry, FALSE, FALSE, 4);