Commit 0b7db688 authored by Christian Persch's avatar Christian Persch

Setters should not return a boolean

The setter for the "font" property returned a boolean that indicated
whether the given font has been found. Instead, fall back to the default
font name when the given font doesn't exist.
parent cf148686
......@@ -201,13 +201,13 @@ gtk_font_button_font_chooser_get_font (GtkFontChooser *chooser)
return g_strdup (gtk_font_button_get_font_name (font_button));
}
static gboolean
static void
gtk_font_button_font_chooser_set_font (GtkFontChooser *chooser,
const gchar *fontname)
{
GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
return gtk_font_button_set_font_name (font_button, fontname);
gtk_font_button_set_font_name (font_button, fontname);
}
static PangoFontFamily *
......@@ -873,7 +873,6 @@ gboolean
gtk_font_button_set_font_name (GtkFontButton *font_button,
const gchar *fontname)
{
gboolean result;
gchar *old_fontname;
g_return_val_if_fail (GTK_IS_FONT_BUTTON (font_button), FALSE);
......@@ -889,15 +888,13 @@ gtk_font_button_set_font_name (GtkFontButton *font_button,
gtk_font_button_update_font_info (font_button);
if (font_button->priv->font_dialog)
result = gtk_font_chooser_set_font (GTK_FONT_CHOOSER (font_button->priv->font_dialog),
font_button->priv->fontname);
else
result = FALSE;
gtk_font_chooser_set_font (GTK_FONT_CHOOSER (font_button->priv->font_dialog),
font_button->priv->fontname);
g_object_notify (G_OBJECT (font_button), "font");
g_object_notify (G_OBJECT (font_button), "font-name");
return result;
return TRUE;
}
static void
......
......@@ -50,9 +50,6 @@ enum
static guint chooser_signals[LAST_SIGNAL];
#define DEFAULT_FONT_NAME "Sans 10"
#define MAX_FONT_SIZE 999
typedef GtkFontChooserIface GtkFontChooserInterface;
G_DEFINE_INTERFACE (GtkFontChooser, gtk_font_chooser, G_TYPE_OBJECT);
......@@ -64,7 +61,7 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
g_param_spec_string ("font",
P_("Font"),
P_("The string that represents this font"),
DEFAULT_FONT_NAME,
GTK_FONT_CHOOSER_DEFAULT_FONT_NAME,
GTK_PARAM_READWRITE));
g_object_interface_install_property
......@@ -201,21 +198,17 @@ gtk_font_chooser_get_font (GtkFontChooser *fontchooser)
*
* Sets the currently-selected font.
*
* Return value: %TRUE if the font could be set successfully; %FALSE
* if no such font exists or if the @fontchooser doesn't belong
* to a particular screen yet.
*
* Since: 3.2
*/
gboolean
void
gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
const gchar *fontname)
{
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
g_return_val_if_fail (fontname != NULL, FALSE);
g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
g_return_if_fail (fontname != NULL);
return GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font (fontchooser,
fontname);
GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font (fontchooser,
fontname);
}
/**
......
......@@ -60,7 +60,7 @@ struct _GtkFontChooserIface
/* Methods */
gchar * (* get_font) (GtkFontChooser *chooser);
gboolean (* set_font) (GtkFontChooser *chooser,
void (* set_font) (GtkFontChooser *chooser,
const gchar *fontname);
PangoFontFamily * (* get_font_family) (GtkFontChooser *chooser);
PangoFontFace * (* get_font_face) (GtkFontChooser *chooser);
......@@ -85,7 +85,7 @@ PangoFontFace *gtk_font_chooser_get_face (GtkFontChooser *fo
gint gtk_font_chooser_get_size (GtkFontChooser *fontchooser);
gchar* gtk_font_chooser_get_font (GtkFontChooser *fontchooser);
gboolean gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
void gtk_font_chooser_set_font (GtkFontChooser *fontchooser,
const gchar *font_name);
gchar* gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser);
void gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser,
......
......@@ -25,6 +25,8 @@
#include "gtkfontchooser.h"
#define GTK_FONT_CHOOSER_DEFAULT_FONT_NAME "Sans 10"
G_BEGIN_DECLS
void _gtk_font_chooser_font_activated (GtkFontChooser *chooser,
......
......@@ -41,11 +41,11 @@ delegate_get_font (GtkFontChooser *chooser)
return gtk_font_chooser_get_font (get_delegate (chooser));
}
static gboolean
static void
delegate_set_font (GtkFontChooser *chooser,
const gchar *fontname)
{
return gtk_font_chooser_set_font (get_delegate (chooser), fontname);
gtk_font_chooser_set_font (get_delegate (chooser), fontname);
}
static PangoFontFamily *
......
......@@ -146,10 +146,10 @@ static void gtk_font_chooser_widget_style_updated (GtkWidget *widge
static void gtk_font_chooser_widget_bootstrap_fontlist (GtkFontChooserWidget *fontchooser);
static gboolean gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser);
static void gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser);
static gchar *gtk_font_chooser_widget_get_font (GtkFontChooser *chooser);
static gboolean gtk_font_chooser_widget_set_font (GtkFontChooser *chooser,
static void gtk_font_chooser_widget_set_font (GtkFontChooser *chooser,
const gchar *fontname);
static const gchar *gtk_font_chooser_widget_get_preview_text (GtkFontChooserWidget *fontchooser);
......@@ -945,8 +945,7 @@ gtk_font_chooser_widget_screen_changed (GtkWidget *widget,
GTK_TREE_VIEW (priv->family_face_list),
priv->model);
if (priv->fontname)
gtk_font_chooser_widget_select_font_name (fontchooser);
gtk_font_chooser_widget_select_font_name (fontchooser);
}
static void
......@@ -994,7 +993,7 @@ gtk_font_chooser_widget_get_font (GtkFontChooser *chooser)
PangoFontDescription *desc;
if (!fontchooser->priv->face)
return NULL;
return g_strdup (GTK_FONT_CHOOSER_DEFAULT_FONT_NAME);
desc = pango_font_face_describe (fontchooser->priv->face);
font_desc_name = pango_font_description_to_string (desc);
......@@ -1006,27 +1005,24 @@ gtk_font_chooser_widget_get_font (GtkFontChooser *chooser)
return font_name;
}
static gboolean
static void
gtk_font_chooser_widget_set_font (GtkFontChooser *chooser,
const gchar *fontname)
{
GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
gboolean found = FALSE;
if (priv->fontname)
g_free (priv->fontname);
priv->fontname = g_strdup (fontname);
if (gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
found = gtk_font_chooser_widget_select_font_name (fontchooser);
gtk_font_chooser_widget_select_font_name (fontchooser);
g_object_notify (G_OBJECT (fontchooser), "font");
return found;
}
static gboolean
static void
gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
{
GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
......@@ -1036,7 +1032,11 @@ gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
PangoFontDescription *desc;
gboolean found = FALSE;
desc = pango_font_description_from_string (priv->fontname);
if (priv->fontname)
desc = pango_font_description_from_string (priv->fontname);
else
desc = pango_font_description_from_string (GTK_FONT_CHOOSER_DEFAULT_FONT_NAME);
family_name = (gchar*)pango_font_description_get_family (desc);
g_free (priv->fontname);
......@@ -1045,7 +1045,7 @@ gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
if (!family_name)
{
pango_font_description_free (desc);
return FALSE;
return;
}
/* We make sure the filter is clear */
......@@ -1112,8 +1112,6 @@ gtk_font_chooser_widget_select_font_name (GtkFontChooserWidget *fontchooser)
}
pango_font_description_free (desc);
return found;
}
static const gchar*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment