[gtk+/font-chooser-api: 9/15] Setters should not return a boolean
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/font-chooser-api: 9/15] Setters should not return a boolean
- Date: Sun, 11 Sep 2011 23:53:39 +0000 (UTC)
commit c39129efb4ba481076a6d8c4e404f89dd96703e7
Author: Christian Persch <chpe gnome org>
Date: Mon Sep 5 22:45:44 2011 +0200
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.
gtk/gtkfontbutton.c | 13 +++++--------
gtk/gtkfontchooser.c | 19 ++++++-------------
gtk/gtkfontchooser.h | 4 ++--
gtk/gtkfontchooserprivate.h | 2 ++
gtk/gtkfontchooserutils.c | 4 ++--
gtk/gtkfontchooserwidget.c | 28 +++++++++++++---------------
6 files changed, 30 insertions(+), 40 deletions(-)
---
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 7492a9a..dc0fde6 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -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
diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c
index cdc8d5a..c83174f 100644
--- a/gtk/gtkfontchooser.c
+++ b/gtk/gtkfontchooser.c
@@ -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);
}
/**
diff --git a/gtk/gtkfontchooser.h b/gtk/gtkfontchooser.h
index 39c503c..8573f8c 100644
--- a/gtk/gtkfontchooser.h
+++ b/gtk/gtkfontchooser.h
@@ -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,
diff --git a/gtk/gtkfontchooserprivate.h b/gtk/gtkfontchooserprivate.h
index 8a8ac35..ef62553 100644
--- a/gtk/gtkfontchooserprivate.h
+++ b/gtk/gtkfontchooserprivate.h
@@ -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,
diff --git a/gtk/gtkfontchooserutils.c b/gtk/gtkfontchooserutils.c
index 5cef3a0..418442f 100644
--- a/gtk/gtkfontchooserutils.c
+++ b/gtk/gtkfontchooserutils.c
@@ -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 *
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index cc6306e..568df2f 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -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*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]