static void font_changed (GObject *object, GParamSpec *pspec, gpointer data) { GtkFontChooser *fb = GTK_FONT_CHOOSER (data); GValue val = G_VALUE_INIT; const PangoFontDescription *font_desc; PangoFontDescription *fb_font_desc; g_value_init (&val, PANGO_TYPE_FONT_DESCRIPTION); get_property_value (object, pspec, &val); font_desc = g_value_get_boxed (&val); fb_font_desc = gtk_font_chooser_get_font_desc (fb); if (font_desc == NULL || (fb_font_desc != NULL && !pango_font_description_equal (fb_font_desc, font_desc))) { block_controller (G_OBJECT (fb)); gtk_font_chooser_set_font_desc (fb, font_desc); unblock_controller (G_OBJECT (fb)); } g_value_unset (&val); pango_font_description_free (fb_font_desc); }
static void gnm_font_button_take_font_desc (GnmFontButton *font_button, PangoFontDescription *font_desc) { GnmFontButtonPrivate *priv = font_button->priv; GObject *object = G_OBJECT (font_button); if (priv->font_desc && font_desc && pango_font_description_equal (priv->font_desc, font_desc)) { pango_font_description_free (font_desc); return; } g_object_freeze_notify (object); clear_font_data (font_button); if (font_desc) priv->font_desc = font_desc; /* adopted */ else priv->font_desc = pango_font_description_from_string (_("Sans 12")); if (pango_font_description_get_size_is_absolute (priv->font_desc)) priv->font_size = pango_font_description_get_size (priv->font_desc); else priv->font_size = pango_font_description_get_size (priv->font_desc) / PANGO_SCALE; gnm_font_button_update_font_data (font_button); gnm_font_button_update_font_info (font_button); if (priv->font_dialog) gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (priv->font_dialog), priv->font_desc); g_object_notify (G_OBJECT (font_button), "font"); g_object_notify (G_OBJECT (font_button), "font-desc"); g_object_notify (G_OBJECT (font_button), "font-name"); g_object_thaw_notify (object); }
static void termomix_font_dialog (GtkWidget *widget, void *data) { GtkWidget *font_dialog; gint response; font_dialog=gtk_font_chooser_dialog_new(gettext("Select font"), GTK_WINDOW(termomix.main_window)); gtk_font_chooser_set_font_desc(GTK_FONT_CHOOSER(font_dialog), termomix.font); response=gtk_dialog_run(GTK_DIALOG(font_dialog)); if (response==GTK_RESPONSE_OK) { pango_font_description_free(termomix.font); termomix.font=gtk_font_chooser_get_font_desc(GTK_FONT_CHOOSER(font_dialog)); termomix_set_font(); termomix_set_size(termomix.columns, termomix.rows); termomix_set_config_string("font", pango_font_description_to_string(termomix.font)); } gtk_widget_destroy(font_dialog); }
static void gnm_font_button_clicked (GtkButton *button) { GtkFontChooser *font_dialog; GnmFontButton *font_button = GNM_FONT_BUTTON (button); GnmFontButtonPrivate *priv = font_button->priv; if (!font_button->priv->font_dialog) { GtkWidget *parent; parent = gtk_widget_get_toplevel (GTK_WIDGET (font_button)); priv->font_dialog = g_object_new (priv->dialog_type, NULL); font_dialog = GTK_FONT_CHOOSER (font_button->priv->font_dialog); gtk_font_chooser_set_show_preview_entry (font_dialog, priv->show_preview_entry); if (priv->preview_text) { gtk_font_chooser_set_preview_text (font_dialog, priv->preview_text); g_free (priv->preview_text); priv->preview_text = NULL; } if (priv->font_filter) { gtk_font_chooser_set_filter_func (font_dialog, priv->font_filter, priv->font_filter_data, priv->font_filter_data_destroy); priv->font_filter = NULL; priv->font_filter_data = NULL; priv->font_filter_data_destroy = NULL; } if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent)) { if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog))) gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent)); gtk_window_set_modal (GTK_WINDOW (font_dialog), gtk_window_get_modal (GTK_WINDOW (parent))); } g_signal_connect (font_dialog, "notify", G_CALLBACK (gnm_font_button_font_chooser_notify), button); g_signal_connect (font_dialog, "response", G_CALLBACK (response_cb), font_button); g_signal_connect (font_dialog, "destroy", G_CALLBACK (dialog_destroy), font_button); } if (!gtk_widget_get_visible (font_button->priv->font_dialog)) { font_dialog = GTK_FONT_CHOOSER (font_button->priv->font_dialog); gtk_font_chooser_set_font_desc (font_dialog, font_button->priv->font_desc); } gtk_window_present (GTK_WINDOW (font_button->priv->font_dialog)); }