fontbutton: Drop the Private struct

This commit is contained in:
Matthias Clasen 2020-04-13 00:32:50 -04:00
parent 800f1c03d5
commit 6831d3e28e

View File

@ -67,19 +67,8 @@ typedef struct _GtkFontButtonClass GtkFontButtonClass;
struct _GtkFontButton
{
GtkWidget parent_instance;
};
struct _GtkFontButtonClass
{
GtkWidgetClass parent_class;
void (* font_set) (GtkFontButton *gfp);
};
typedef struct
{
gchar *title;
gchar *fontname;
guint use_font : 1;
@ -107,7 +96,14 @@ typedef struct
GtkCssProvider *provider;
GtkFontChooserLevel level;
} GtkFontButtonPrivate;
};
struct _GtkFontButtonClass
{
GtkWidgetClass parent_class;
void (* font_set) (GtkFontButton *gfp);
};
/* Signals */
enum
@ -184,32 +180,27 @@ gtk_font_button_font_chooser_iface_init (GtkFontChooserIface *iface)
}
G_DEFINE_TYPE_WITH_CODE (GtkFontButton, gtk_font_button, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkFontButton)
G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
gtk_font_button_font_chooser_iface_init))
static void
clear_font_data (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_clear_object (&priv->font_family);
g_clear_object (&priv->font_face);
g_clear_pointer (&priv->font_desc, pango_font_description_free);
g_clear_pointer (&priv->fontname, g_free);
g_clear_pointer (&priv->font_features, g_free);
g_clear_object (&font_button->font_family);
g_clear_object (&font_button->font_face);
g_clear_pointer (&font_button->font_desc, pango_font_description_free);
g_clear_pointer (&font_button->fontname, g_free);
g_clear_pointer (&font_button->font_features, g_free);
}
static void
clear_font_filter_data (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_filter_data_destroy)
priv->font_filter_data_destroy (priv->font_filter_data);
priv->font_filter = NULL;
priv->font_filter_data = NULL;
priv->font_filter_data_destroy = NULL;
if (font_button->font_filter_data_destroy)
font_button->font_filter_data_destroy (font_button->font_filter_data);
font_button->font_filter = NULL;
font_button->font_filter_data = NULL;
font_button->font_filter_data_destroy = NULL;
}
static gboolean
@ -225,17 +216,16 @@ font_description_style_equal (const PangoFontDescription *a,
static void
gtk_font_button_update_font_data (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
PangoFontFamily **families;
PangoFontFace **faces;
gint n_families, n_faces, i;
const gchar *family;
g_assert (priv->font_desc != NULL);
g_assert (font_button->font_desc != NULL);
priv->fontname = pango_font_description_to_string (priv->font_desc);
font_button->fontname = pango_font_description_to_string (font_button->font_desc);
family = pango_font_description_get_family (priv->font_desc);
family = pango_font_description_get_family (font_button->font_desc);
if (family == NULL)
return;
@ -251,7 +241,7 @@ gtk_font_button_update_font_data (GtkFontButton *font_button)
if (!g_ascii_strcasecmp (name, family))
{
priv->font_family = g_object_ref (families[i]);
font_button->font_family = g_object_ref (families[i]);
pango_font_family_list_faces (families[i], &faces, &n_faces);
break;
@ -263,9 +253,9 @@ gtk_font_button_update_font_data (GtkFontButton *font_button)
{
PangoFontDescription *tmp_desc = pango_font_face_describe (faces[i]);
if (font_description_style_equal (tmp_desc, priv->font_desc))
if (font_description_style_equal (tmp_desc, font_button->font_desc))
{
priv->font_face = g_object_ref (faces[i]);
font_button->font_face = g_object_ref (faces[i]);
pango_font_description_free (tmp_desc);
break;
@ -280,56 +270,48 @@ gtk_font_button_update_font_data (GtkFontButton *font_button)
static gchar *
gtk_font_button_get_preview_text (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (font_button->font_dialog)
return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog));
if (priv->font_dialog)
return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (priv->font_dialog));
return g_strdup (priv->preview_text);
return g_strdup (font_button->preview_text);
}
static void
gtk_font_button_set_preview_text (GtkFontButton *font_button,
const gchar *preview_text)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_dialog)
if (font_button->font_dialog)
{
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (priv->font_dialog),
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (font_button->font_dialog),
preview_text);
return;
}
g_free (priv->preview_text);
priv->preview_text = g_strdup (preview_text);
g_free (font_button->preview_text);
font_button->preview_text = g_strdup (preview_text);
}
static gboolean
gtk_font_button_get_show_preview_entry (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (font_button->font_dialog)
return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog));
if (priv->font_dialog)
return gtk_font_chooser_get_show_preview_entry (GTK_FONT_CHOOSER (priv->font_dialog));
return priv->show_preview_entry;
return font_button->show_preview_entry;
}
static void
gtk_font_button_set_show_preview_entry (GtkFontButton *font_button,
gboolean show)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
show = show != FALSE;
if (priv->show_preview_entry != show)
if (font_button->show_preview_entry != show)
{
priv->show_preview_entry = show;
if (priv->font_dialog)
gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (priv->font_dialog), show);
font_button->show_preview_entry = show;
if (font_button->font_dialog)
gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (font_button->font_dialog), show);
g_object_notify (G_OBJECT (font_button), "show-preview-entry");
}
}
@ -338,27 +320,24 @@ static PangoFontFamily *
gtk_font_button_font_chooser_get_font_family (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_family;
return font_button->font_family;
}
static PangoFontFace *
gtk_font_button_font_chooser_get_font_face (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_face;
return font_button->font_face;
}
static int
gtk_font_button_font_chooser_get_font_size (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_size;
return font_button->font_size;
}
static void
@ -368,11 +347,10 @@ gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser,
GDestroyNotify data_destroy)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_dialog)
if (font_button->font_dialog)
{
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (priv->font_dialog),
gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (font_button->font_dialog),
filter_func,
filter_data,
data_destroy);
@ -380,20 +358,19 @@ gtk_font_button_font_chooser_set_filter_func (GtkFontChooser *chooser,
}
clear_font_filter_data (font_button);
priv->font_filter = filter_func;
priv->font_filter_data = filter_data;
priv->font_filter_data_destroy = data_destroy;
font_button->font_filter = filter_func;
font_button->font_filter_data = filter_data;
font_button->font_filter_data_destroy = data_destroy;
}
static void
gtk_font_button_take_font_desc (GtkFontButton *font_button,
PangoFontDescription *font_desc)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GObject *object = G_OBJECT (font_button);
if (priv->font_desc && font_desc &&
pango_font_description_equal (priv->font_desc, font_desc))
if (font_button->font_desc && font_desc &&
pango_font_description_equal (font_button->font_desc, font_desc))
{
pango_font_description_free (font_desc);
return;
@ -404,21 +381,21 @@ gtk_font_button_take_font_desc (GtkFontButton *font_button,
clear_font_data (font_button);
if (font_desc)
priv->font_desc = font_desc; /* adopted */
font_button->font_desc = font_desc; /* adopted */
else
priv->font_desc = pango_font_description_from_string (_("Sans 12"));
font_button->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);
if (pango_font_description_get_size_is_absolute (font_button->font_desc))
font_button->font_size = pango_font_description_get_size (font_button->font_desc);
else
priv->font_size = pango_font_description_get_size (priv->font_desc) / PANGO_SCALE;
font_button->font_size = pango_font_description_get_size (font_button->font_desc) / PANGO_SCALE;
gtk_font_button_update_font_data (font_button);
gtk_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);
if (font_button->font_dialog)
gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (font_button->font_dialog),
font_button->font_desc);
g_object_notify (G_OBJECT (font_button), "font");
g_object_notify (G_OBJECT (font_button), "font-desc");
@ -429,9 +406,7 @@ gtk_font_button_take_font_desc (GtkFontButton *font_button,
static const PangoFontDescription *
gtk_font_button_get_font_desc (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_desc;
return font_button->font_desc;
}
static void
@ -439,16 +414,15 @@ gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser,
PangoFontMap *font_map)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (g_set_object (&priv->font_map, font_map))
if (g_set_object (&font_button->font_map, font_map))
{
PangoContext *context;
if (!font_map)
font_map = pango_cairo_font_map_get_default ();
context = gtk_widget_get_pango_context (priv->font_label);
context = gtk_widget_get_pango_context (font_button->font_label);
pango_context_set_font_map (context, font_map);
}
}
@ -457,9 +431,8 @@ static PangoFontMap *
gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
return priv->font_map;
return font_button->font_map;
}
static void
@ -569,65 +542,63 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
static void
gtk_font_button_init (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GtkWidget *box;
priv->button = gtk_button_new ();
g_signal_connect (priv->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button);
priv->font_label = gtk_label_new (_("Font"));
gtk_widget_set_hexpand (priv->font_label, TRUE);
priv->size_label = gtk_label_new ("14");
priv->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
font_button->button = gtk_button_new ();
g_signal_connect (font_button->button, "clicked", G_CALLBACK (gtk_font_button_clicked), font_button);
font_button->font_label = gtk_label_new (_("Font"));
gtk_widget_set_hexpand (font_button->font_label, TRUE);
font_button->size_label = gtk_label_new ("14");
font_button->font_size_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (box), priv->font_label);
gtk_container_add (GTK_CONTAINER (box), font_button->font_label);
gtk_container_add (GTK_CONTAINER (priv->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL));
gtk_container_add (GTK_CONTAINER (priv->font_size_box), priv->size_label);
gtk_container_add (GTK_CONTAINER (box), priv->font_size_box);
gtk_container_add (GTK_CONTAINER (font_button->font_size_box), gtk_separator_new (GTK_ORIENTATION_VERTICAL));
gtk_container_add (GTK_CONTAINER (font_button->font_size_box), font_button->size_label);
gtk_container_add (GTK_CONTAINER (box), font_button->font_size_box);
gtk_container_add (GTK_CONTAINER (priv->button), box);
gtk_widget_set_parent (priv->button, GTK_WIDGET (font_button));
gtk_container_add (GTK_CONTAINER (font_button->button), box);
gtk_widget_set_parent (font_button->button, GTK_WIDGET (font_button));
/* Initialize fields */
priv->modal = TRUE;
priv->use_font = FALSE;
priv->use_size = FALSE;
priv->show_preview_entry = TRUE;
priv->font_dialog = NULL;
priv->font_family = NULL;
priv->font_face = NULL;
priv->font_size = -1;
priv->title = g_strdup (_("Pick a Font"));
priv->level = GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE |
GTK_FONT_CHOOSER_LEVEL_SIZE;
priv->language = pango_language_get_default ();
font_button->modal = TRUE;
font_button->use_font = FALSE;
font_button->use_size = FALSE;
font_button->show_preview_entry = TRUE;
font_button->font_dialog = NULL;
font_button->font_family = NULL;
font_button->font_face = NULL;
font_button->font_size = -1;
font_button->title = g_strdup (_("Pick a Font"));
font_button->level = GTK_FONT_CHOOSER_LEVEL_FAMILY |
GTK_FONT_CHOOSER_LEVEL_STYLE |
GTK_FONT_CHOOSER_LEVEL_SIZE;
font_button->language = pango_language_get_default ();
gtk_font_button_take_font_desc (font_button, NULL);
gtk_widget_add_css_class (priv->button, "font");
gtk_widget_add_css_class (font_button->button, "font");
}
static void
gtk_font_button_finalize (GObject *object)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->font_dialog != NULL)
gtk_widget_destroy (priv->font_dialog);
if (font_button->font_dialog != NULL)
gtk_widget_destroy (font_button->font_dialog);
g_free (priv->title);
g_free (font_button->title);
clear_font_data (font_button);
clear_font_filter_data (font_button);
g_free (priv->preview_text);
g_free (font_button->preview_text);
g_clear_object (&priv->provider);
g_clear_object (&font_button->provider);
gtk_widget_unparent (priv->button);
gtk_widget_unparent (font_button->button);
G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object);
}
@ -685,7 +656,6 @@ gtk_font_button_get_property (GObject *object,
GParamSpec *pspec)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (object);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
switch (param_id)
{
@ -705,13 +675,13 @@ gtk_font_button_get_property (GObject *object,
g_value_set_boxed (value, gtk_font_button_get_font_desc (font_button));
break;
case GTK_FONT_CHOOSER_PROP_FONT_FEATURES:
g_value_set_string (value, priv->font_features);
g_value_set_string (value, font_button->font_features);
break;
case GTK_FONT_CHOOSER_PROP_LANGUAGE:
g_value_set_string (value, pango_language_to_string (priv->language));
g_value_set_string (value, pango_language_to_string (font_button->language));
break;
case GTK_FONT_CHOOSER_PROP_LEVEL:
g_value_set_flags (value, priv->level);
g_value_set_flags (value, font_button->level);
break;
case GTK_FONT_CHOOSER_PROP_FONT:
g_value_set_string (value, gtk_font_button_get_font_name (font_button));
@ -767,16 +737,15 @@ void
gtk_font_button_set_title (GtkFontButton *font_button,
const gchar *title)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
gchar *old_title;
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
old_title = priv->title;
priv->title = g_strdup (title);
old_title = font_button->title;
font_button->title = g_strdup (title);
g_free (old_title);
if (priv->font_dialog)
gtk_window_set_title (GTK_WINDOW (priv->font_dialog), priv->title);
if (font_button->font_dialog)
gtk_window_set_title (GTK_WINDOW (font_button->font_dialog), font_button->title);
g_object_notify (G_OBJECT (font_button), "title");
}
@ -792,11 +761,9 @@ gtk_font_button_set_title (GtkFontButton *font_button,
const gchar*
gtk_font_button_get_title (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL);
return priv->title;
return font_button->title;
}
/**
@ -810,17 +777,15 @@ void
gtk_font_button_set_modal (GtkFontButton *font_button,
gboolean modal)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
if (priv->modal == modal)
if (font_button->modal == modal)
return;
priv->modal = modal;
font_button->modal = modal;
if (priv->font_dialog)
gtk_window_set_modal (GTK_WINDOW (priv->font_dialog), priv->modal);
if (font_button->font_dialog)
gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal);
g_object_notify (G_OBJECT (font_button), "modal");
}
@ -836,11 +801,9 @@ gtk_font_button_set_modal (GtkFontButton *font_button,
gboolean
gtk_font_button_get_modal (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
return priv->modal;
return font_button->modal;
}
/**
@ -854,11 +817,9 @@ gtk_font_button_get_modal (GtkFontButton *font_button)
gboolean
gtk_font_button_get_use_font (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
return priv->use_font;
return font_button->use_font;
}
/**
@ -872,14 +833,13 @@ void
gtk_font_button_set_use_font (GtkFontButton *font_button,
gboolean use_font)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
use_font = (use_font != FALSE);
if (priv->use_font != use_font)
if (font_button->use_font != use_font)
{
priv->use_font = use_font;
font_button->use_font = use_font;
gtk_font_button_label_use_font (font_button);
@ -899,11 +859,9 @@ gtk_font_button_set_use_font (GtkFontButton *font_button,
gboolean
gtk_font_button_get_use_size (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
return priv->use_size;
return font_button->use_size;
}
/**
@ -917,14 +875,12 @@ void
gtk_font_button_set_use_size (GtkFontButton *font_button,
gboolean use_size)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_if_fail (GTK_IS_FONT_BUTTON (font_button));
use_size = (use_size != FALSE);
if (priv->use_size != use_size)
if (font_button->use_size != use_size)
{
priv->use_size = use_size;
font_button->use_size = use_size;
gtk_font_button_label_use_font (font_button);
@ -935,11 +891,9 @@ gtk_font_button_set_use_size (GtkFontButton *font_button,
static const gchar *
gtk_font_button_get_font_name (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), NULL);
return priv->fontname;
return font_button->fontname;
}
static void
@ -958,43 +912,42 @@ gtk_font_button_clicked (GtkButton *button,
{
GtkFontChooser *font_dialog;
GtkFontButton *font_button = user_data;
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (!priv->font_dialog)
if (!font_button->font_dialog)
{
GtkWidget *parent;
parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (font_button)));
priv->font_dialog = gtk_font_chooser_dialog_new (priv->title, NULL);
gtk_window_set_hide_on_close (GTK_WINDOW (priv->font_dialog), TRUE);
gtk_window_set_modal (GTK_WINDOW (priv->font_dialog), priv->modal);
font_button->font_dialog = gtk_font_chooser_dialog_new (font_button->title, NULL);
gtk_window_set_hide_on_close (GTK_WINDOW (font_button->font_dialog), TRUE);
gtk_window_set_modal (GTK_WINDOW (font_button->font_dialog), font_button->modal);
font_dialog = GTK_FONT_CHOOSER (priv->font_dialog);
font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog);
if (priv->font_map)
gtk_font_chooser_set_font_map (font_dialog, priv->font_map);
if (font_button->font_map)
gtk_font_chooser_set_font_map (font_dialog, font_button->font_map);
gtk_font_chooser_set_show_preview_entry (font_dialog, priv->show_preview_entry);
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), priv->level);
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (priv->language));
gtk_font_chooser_set_show_preview_entry (font_dialog, font_button->show_preview_entry);
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_dialog), font_button->level);
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_dialog), pango_language_to_string (font_button->language));
if (priv->preview_text)
if (font_button->preview_text)
{
gtk_font_chooser_set_preview_text (font_dialog, priv->preview_text);
g_free (priv->preview_text);
priv->preview_text = NULL;
gtk_font_chooser_set_preview_text (font_dialog, font_button->preview_text);
g_free (font_button->preview_text);
font_button->preview_text = NULL;
}
if (priv->font_filter)
if (font_button->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;
font_button->font_filter,
font_button->font_filter_data,
font_button->font_filter_data_destroy);
font_button->font_filter = NULL;
font_button->font_filter_data = NULL;
font_button->font_filter_data_destroy = NULL;
}
if (GTK_IS_WINDOW (parent))
@ -1016,14 +969,14 @@ gtk_font_button_clicked (GtkButton *button,
G_CALLBACK (dialog_destroy), font_button);
}
if (!gtk_widget_get_visible (priv->font_dialog))
if (!gtk_widget_get_visible (font_button->font_dialog))
{
font_dialog = GTK_FONT_CHOOSER (priv->font_dialog);
gtk_font_chooser_set_font_desc (font_dialog, priv->font_desc);
font_dialog = GTK_FONT_CHOOSER (font_button->font_dialog);
gtk_font_chooser_set_font_desc (font_dialog, font_button->font_desc);
}
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
gtk_window_present (GTK_WINDOW (priv->font_dialog));
gtk_window_present (GTK_WINDOW (font_button->font_dialog));
G_GNUC_END_IGNORE_DEPRECATIONS
}
@ -1034,35 +987,34 @@ response_cb (GtkDialog *dialog,
gpointer data)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (data);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GtkFontChooser *font_chooser;
GObject *object;
gtk_widget_hide (priv->font_dialog);
gtk_widget_hide (font_button->font_dialog);
if (response_id != GTK_RESPONSE_OK)
return;
font_chooser = GTK_FONT_CHOOSER (priv->font_dialog);
font_chooser = GTK_FONT_CHOOSER (font_button->font_dialog);
object = G_OBJECT (font_chooser);
g_object_freeze_notify (object);
clear_font_data (font_button);
priv->font_desc = gtk_font_chooser_get_font_desc (font_chooser);
if (priv->font_desc)
priv->fontname = pango_font_description_to_string (priv->font_desc);
priv->font_family = gtk_font_chooser_get_font_family (font_chooser);
if (priv->font_family)
g_object_ref (priv->font_family);
priv->font_face = gtk_font_chooser_get_font_face (font_chooser);
if (priv->font_face)
g_object_ref (priv->font_face);
priv->font_size = gtk_font_chooser_get_font_size (font_chooser);
g_free (priv->font_features);
priv->font_features = gtk_font_chooser_get_font_features (font_chooser);
priv->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser));
font_button->font_desc = gtk_font_chooser_get_font_desc (font_chooser);
if (font_button->font_desc)
font_button->fontname = pango_font_description_to_string (font_button->font_desc);
font_button->font_family = gtk_font_chooser_get_font_family (font_chooser);
if (font_button->font_family)
g_object_ref (font_button->font_family);
font_button->font_face = gtk_font_chooser_get_font_face (font_chooser);
if (font_button->font_face)
g_object_ref (font_button->font_face);
font_button->font_size = gtk_font_chooser_get_font_size (font_chooser);
g_free (font_button->font_features);
font_button->font_features = gtk_font_chooser_get_font_features (font_chooser);
font_button->language = pango_language_from_string (gtk_font_chooser_get_language (font_chooser));
/* Set label font */
gtk_font_button_update_font_info (font_button);
@ -1082,10 +1034,9 @@ dialog_destroy (GtkWidget *widget,
gpointer data)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (data);
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
/* Dialog will get destroyed so reference is not valid now */
priv->font_dialog = NULL;
font_button->font_dialog = NULL;
}
static void
@ -1291,17 +1242,16 @@ pango_font_description_to_css (PangoFontDescription *desc,
static void
gtk_font_button_label_use_font (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
GtkStyleContext *context;
context = gtk_widget_get_style_context (priv->font_label);
context = gtk_widget_get_style_context (font_button->font_label);
if (!priv->use_font)
if (!font_button->use_font)
{
if (priv->provider)
if (font_button->provider)
{
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (priv->provider));
g_clear_object (&priv->provider);
gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (font_button->provider));
g_clear_object (&font_button->provider);
}
}
else
@ -1309,23 +1259,23 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
PangoFontDescription *desc;
gchar *data;
if (!priv->provider)
if (!font_button->provider)
{
priv->provider = gtk_css_provider_new ();
font_button->provider = gtk_css_provider_new ();
gtk_style_context_add_provider (context,
GTK_STYLE_PROVIDER (priv->provider),
GTK_STYLE_PROVIDER (font_button->provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
desc = pango_font_description_copy (priv->font_desc);
desc = pango_font_description_copy (font_button->font_desc);
if (!priv->use_size)
if (!font_button->use_size)
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
data = pango_font_description_to_css (desc,
priv->font_features,
pango_language_to_string (priv->language));
gtk_css_provider_load_from_data (priv->provider, data, -1);
font_button->font_features,
pango_language_to_string (font_button->language));
gtk_css_provider_load_from_data (font_button->provider, data, -1);
g_free (data);
pango_font_description_free (desc);
@ -1335,43 +1285,42 @@ gtk_font_button_label_use_font (GtkFontButton *font_button)
static void
gtk_font_button_update_font_info (GtkFontButton *font_button)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
const gchar *fam_name;
const gchar *face_name;
gchar *family_style;
if (priv->font_family)
fam_name = pango_font_family_get_name (priv->font_family);
if (font_button->font_family)
fam_name = pango_font_family_get_name (font_button->font_family);
else
fam_name = C_("font", "None");
if (priv->font_face)
face_name = pango_font_face_get_face_name (priv->font_face);
if (font_button->font_face)
face_name = pango_font_face_get_face_name (font_button->font_face);
else
face_name = "";
if ((priv->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0)
if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_STYLE) != 0)
family_style = g_strconcat (fam_name, " ", face_name, NULL);
else
family_style = g_strdup (fam_name);
gtk_label_set_text (GTK_LABEL (priv->font_label), family_style);
gtk_label_set_text (GTK_LABEL (font_button->font_label), family_style);
g_free (family_style);
if ((priv->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0)
if ((font_button->level & GTK_FONT_CHOOSER_LEVEL_SIZE) != 0)
{
/* mirror Pango, which doesn't translate this either */
gchar *size = g_strdup_printf ("%2.4g%s",
pango_font_description_get_size (priv->font_desc) / (double)PANGO_SCALE,
pango_font_description_get_size_is_absolute (priv->font_desc) ? "px" : "");
pango_font_description_get_size (font_button->font_desc) / (double)PANGO_SCALE,
pango_font_description_get_size_is_absolute (font_button->font_desc) ? "px" : "");
gtk_label_set_text (GTK_LABEL (priv->size_label), size);
gtk_label_set_text (GTK_LABEL (font_button->size_label), size);
g_free (size);
gtk_widget_show (priv->font_size_box);
gtk_widget_show (font_button->font_size_box);
}
else
gtk_widget_hide (priv->font_size_box);
gtk_widget_hide (font_button->font_size_box);
gtk_font_button_label_use_font (font_button);
@ -1381,15 +1330,13 @@ static void
gtk_font_button_set_level (GtkFontButton *font_button,
GtkFontChooserLevel level)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
if (priv->level == level)
if (font_button->level == level)
return;
priv->level = level;
font_button->level = level;
if (priv->font_dialog)
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (priv->font_dialog), level);
if (font_button->font_dialog)
gtk_font_chooser_set_level (GTK_FONT_CHOOSER (font_button->font_dialog), level);
gtk_font_button_update_font_info (font_button);
@ -1400,12 +1347,10 @@ static void
gtk_font_button_set_language (GtkFontButton *font_button,
const char *language)
{
GtkFontButtonPrivate *priv = gtk_font_button_get_instance_private (font_button);
font_button->language = pango_language_from_string (language);
priv->language = pango_language_from_string (language);
if (priv->font_dialog)
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (priv->font_dialog), language);
if (font_button->font_dialog)
gtk_font_chooser_set_language (GTK_FONT_CHOOSER (font_button->font_dialog), language);
g_object_notify (G_OBJECT (font_button), "language");
}