]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfontsel.c
Remove GtkItemFactory completely
[~andy/gtk] / gtk / gtkfontsel.c
index 1a752e72daf7e3f5f4e8a8efc2ec589b0ba05eb1..3eb3d45c33eb8862341306f068478de89703c51d 100644 (file)
@@ -29,7 +29,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 #include <stdlib.h>
 #include <glib/gprintf.h>
 #include <string.h>
@@ -59,6 +59,7 @@
 #include "gtkintl.h"
 #include "gtkaccessible.h"
 #include "gtkprivate.h"
+#include "gtkbuildable.h"
 #include "gtkalias.h"
 
 /* We don't enable the font and style entries because they don't add
@@ -73,6 +74,8 @@
    can set it. Remember that some fonts only have capital letters. */
 #define PREVIEW_TEXT N_("abcdefghijk ABCDEFGHIJK")
 
+#define DEFAULT_FONT_NAME "Sans 10"
+
 /* This is the initial and maximum height of the preview entry (it expands
    when large font sizes are selected). Initial height is also the minimum. */
 #define INITIAL_PREVIEW_HEIGHT 44
@@ -87,7 +90,7 @@
 /* These are what we use as the standard font sizes, for the size list.
  */
 static const guint16 font_sizes[] = {
-  8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, 24, 26, 28,
+  6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 24, 26, 28,
   32, 36, 40, 48, 56, 64, 72
 };
 
@@ -113,7 +116,6 @@ enum {
   SIZE_COLUMN
 };
 
-static void    gtk_font_selection_class_init        (GtkFontSelectionClass *klass);
 static void    gtk_font_selection_set_property       (GObject         *object,
                                                      guint            prop_id,
                                                      const GValue    *value,
@@ -122,10 +124,11 @@ static void    gtk_font_selection_get_property       (GObject         *object,
                                                      guint            prop_id,
                                                      GValue          *value,
                                                      GParamSpec      *pspec);
-static void    gtk_font_selection_init              (GtkFontSelection      *fontsel);
-static void    gtk_font_selection_finalize          (GObject               *object);
-static void    gtk_font_selection_screen_changed     (GtkWidget                    *widget,
-                                                     GdkScreen             *previous_screen);
+static void    gtk_font_selection_finalize          (GObject         *object);
+static void    gtk_font_selection_screen_changed     (GtkWidget              *widget,
+                                                     GdkScreen       *previous_screen);
+static void    gtk_font_selection_style_set          (GtkWidget      *widget,
+                                                     GtkStyle       *prev_style);
 
 /* These are the callbacks & related functions. */
 static void     gtk_font_selection_select_font           (GtkTreeSelection *selection,
@@ -154,48 +157,26 @@ static void     gtk_font_selection_scroll_on_map         (GtkWidget        *w,
 
 static void     gtk_font_selection_preview_changed       (GtkWidget        *entry,
                                                          GtkFontSelection *fontsel);
+static void     gtk_font_selection_scroll_to_selection   (GtkFontSelection *fontsel);
+
 
 /* Misc. utility functions. */
 static void    gtk_font_selection_load_font          (GtkFontSelection *fs);
 static void    gtk_font_selection_update_preview     (GtkFontSelection *fs);
 
 static GdkFont* gtk_font_selection_get_font_internal (GtkFontSelection *fontsel);
-
-/* FontSelectionDialog */
-static void    gtk_font_selection_dialog_class_init  (GtkFontSelectionDialogClass *klass);
-static void    gtk_font_selection_dialog_init       (GtkFontSelectionDialog *fontseldiag);
-
-static GtkVBoxClass *font_selection_parent_class = NULL;
-static GtkWindowClass *font_selection_dialog_parent_class = NULL;
-
-
-GType
-gtk_font_selection_get_type (void)
-{
-  static GType font_selection_type = 0;
-  
-  if (!font_selection_type)
-    {
-      static const GTypeInfo fontsel_type_info =
-      {
-       sizeof (GtkFontSelectionClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_font_selection_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkFontSelection),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_font_selection_init,
-      };
-      
-      font_selection_type =
-       g_type_register_static (GTK_TYPE_VBOX, g_intern_static_string ("GtkFontSelection"),
-                               &fontsel_type_info, 0);
-    }
-  
-  return font_selection_type;
-}
+static PangoFontDescription *gtk_font_selection_get_font_description (GtkFontSelection *fontsel);
+static gboolean gtk_font_selection_select_font_desc  (GtkFontSelection      *fontsel,
+                                                     PangoFontDescription  *new_desc,
+                                                     PangoFontFamily      **pfamily,
+                                                     PangoFontFace        **pface);
+static void     gtk_font_selection_reload_fonts          (GtkFontSelection *fontsel);
+static void     gtk_font_selection_ref_family            (GtkFontSelection *fontsel,
+                                                         PangoFontFamily  *family);
+static void     gtk_font_selection_ref_face              (GtkFontSelection *fontsel,
+                                                         PangoFontFace    *face);
+
+G_DEFINE_TYPE (GtkFontSelection, gtk_font_selection, GTK_TYPE_VBOX)
 
 static void
 gtk_font_selection_class_init (GtkFontSelectionClass *klass)
@@ -203,19 +184,18 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   
-  font_selection_parent_class = g_type_class_peek_parent (klass);
-  
   gobject_class->set_property = gtk_font_selection_set_property;
   gobject_class->get_property = gtk_font_selection_get_property;
 
   widget_class->screen_changed = gtk_font_selection_screen_changed;
+  widget_class->style_set = gtk_font_selection_style_set;
    
   g_object_class_install_property (gobject_class,
                                    PROP_FONT_NAME,
                                    g_param_spec_string ("font-name",
                                                         P_("Font name"),
-                                                        P_("The string that represents this font"),
-                                                        NULL,
+                                                        P_("The string that represents this font"),
+                                                        DEFAULT_FONT_NAME,
                                                         GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
                                   PROP_FONT,
@@ -229,7 +209,7 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass)
                                    g_param_spec_string ("preview-text",
                                                         P_("Preview text"),
                                                         P_("The text to display in order to demonstrate the selected font"),
-                                                        PREVIEW_TEXT,
+                                                        _(PREVIEW_TEXT),
                                                         GTK_PARAM_READWRITE));
   gobject_class->finalize = gtk_font_selection_finalize;
 }
@@ -270,10 +250,10 @@ static void gtk_font_selection_get_property (GObject         *object,
   switch (prop_id)
     {
     case PROP_FONT_NAME:
-      g_value_set_string (value, gtk_font_selection_get_font_name (fontsel));
+      g_value_take_string (value, gtk_font_selection_get_font_name (fontsel));
       break;
     case PROP_FONT:
-      g_value_set_object (value, gtk_font_selection_get_font_internal (fontsel));
+      g_value_set_boxed (value, gtk_font_selection_get_font_internal (fontsel));
       break;
     case PROP_PREVIEW_TEXT:
       g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
@@ -293,13 +273,13 @@ list_row_activated (GtkWidget *widget)
   GtkWindow *window;
   
   window = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
-  if (!GTK_WIDGET_TOPLEVEL (window))
+  if (!gtk_widget_is_toplevel (GTK_WIDGET (window)))
     window = NULL;
   
   if (window
       && widget != window->default_widget
       && !(widget == window->focus_widget &&
-          (!window->default_widget || !GTK_WIDGET_SENSITIVE (window->default_widget))))
+          (!window->default_widget || !gtk_widget_get_sensitive (window->default_widget))))
     {
       gtk_window_activate_default (window);
     }
@@ -311,10 +291,10 @@ static void
 gtk_font_selection_init (GtkFontSelection *fontsel)
 {
   GtkWidget *scrolled_win;
-  GtkWidget *text_frame;
   GtkWidget *text_box;
   GtkWidget *table, *label;
   GtkWidget *font_label, *style_label;
+  GtkWidget *vbox;
   GtkListStore *model;
   GtkTreeViewColumn *column;
   GList *focus_chain = NULL;
@@ -322,12 +302,14 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
 
   gtk_widget_push_composite_child ();
 
+  gtk_box_set_spacing (GTK_BOX (fontsel), 12);
   fontsel->size = 12 * PANGO_SCALE;
   
   /* Create the table of font, style & size. */
   table = gtk_table_new (3, 3, FALSE);
   gtk_widget_show (table);
-  gtk_table_set_col_spacings (GTK_TABLE (table), 8);
+  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
   gtk_box_pack_start (GTK_BOX (fontsel), table, TRUE, TRUE, 0);
 
 #ifdef INCLUDE_FONT_ENTRIES
@@ -354,7 +336,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
   g_signal_connect (fontsel->size_entry, "activate",
                    G_CALLBACK (gtk_font_selection_size_activate),
                    fontsel);
-  g_signal_connect_after (fontsel->size_entry, "focus_out_event",
+  g_signal_connect_after (fontsel->size_entry, "focus-out-event",
                          G_CALLBACK (gtk_font_selection_size_focus_out),
                          fontsel);
   
@@ -510,15 +492,13 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
       AtkRelationSet *relation_set;
       AtkRelation *relation;
       AtkObject *obj_array[1];
-      GPtrArray *array;
 
       atk_label = gtk_widget_get_accessible (label);
       relation_set = atk_object_ref_relation_set (atk_obj);
       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_LABELLED_BY);
       if (relation)
         {
-          array = atk_relation_get_target (relation);
-          g_ptr_array_add (array, atk_label);
+          atk_relation_add_target (relation, atk_label);
         }
       else 
         {
@@ -532,8 +512,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
       relation = atk_relation_set_get_relation_by_type (relation_set, ATK_RELATION_LABEL_FOR);
       if (relation)
         {
-          array = atk_relation_get_target (relation);
-          g_ptr_array_add (array, atk_obj);
+          atk_relation_add_target (relation, atk_obj);
         }
       else 
         {
@@ -545,26 +524,23 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
     }    
       
 
+  vbox = gtk_vbox_new (FALSE, 6);
+  gtk_widget_show (vbox);
+  gtk_box_pack_start (GTK_BOX (fontsel), vbox, FALSE, TRUE, 0);
+  
   /* create the text entry widget */
   label = gtk_label_new_with_mnemonic (_("_Preview:"));
+  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
   gtk_widget_show (label);
+  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0);
   
-  text_frame = gtk_frame_new (NULL);
-  gtk_frame_set_label_widget (GTK_FRAME (text_frame), label);
-  
-  gtk_widget_show (text_frame);
-  gtk_frame_set_shadow_type (GTK_FRAME (text_frame), GTK_SHADOW_ETCHED_IN);
-  gtk_box_pack_start (GTK_BOX (fontsel), text_frame,
-                     FALSE, TRUE, 0);
-  
-  /* This is just used to get a 4-pixel space around the preview entry. */
   text_box = gtk_hbox_new (FALSE, 0);
   gtk_widget_show (text_box);
-  gtk_container_add (GTK_CONTAINER (text_frame), text_box);
-  gtk_container_set_border_width (GTK_CONTAINER (text_box), 4);
+  gtk_box_pack_start (GTK_BOX (vbox), text_box, FALSE, TRUE, 0);
   
   fontsel->preview_entry = gtk_entry_new ();
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), fontsel->preview_entry);
+  gtk_entry_set_text (GTK_ENTRY (fontsel->preview_entry), _(PREVIEW_TEXT));
   
   gtk_widget_show (fontsel->preview_entry);
   g_signal_connect (fontsel->preview_entry, "changed",
@@ -573,10 +549,16 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
                               -1, INITIAL_PREVIEW_HEIGHT);
   gtk_box_pack_start (GTK_BOX (text_box), fontsel->preview_entry,
                      TRUE, TRUE, 0);
-
   gtk_widget_pop_composite_child();
 }
 
+/**
+ * gtk_font_selection_new:
+ *
+ * Creates a new #GtkFontSelection.
+ *
+ * Return value: a n ew #GtkFontSelection
+ */
 GtkWidget *
 gtk_font_selection_new (void)
 {
@@ -598,29 +580,73 @@ gtk_font_selection_finalize (GObject *object)
 
   if (fontsel->font)
     gdk_font_unref (fontsel->font);
-  
-  (* G_OBJECT_CLASS (font_selection_parent_class)->finalize) (object);
+
+  gtk_font_selection_ref_family (fontsel, NULL);
+  gtk_font_selection_ref_face (fontsel, NULL);
+
+  G_OBJECT_CLASS (gtk_font_selection_parent_class)->finalize (object);
 }
 
 static void
-gtk_font_selection_screen_changed (GtkWidget *widget,
-                                  GdkScreen *previous_screen)
+gtk_font_selection_ref_family (GtkFontSelection *fontsel,
+                              PangoFontFamily  *family)
+{
+  if (family)
+    family = g_object_ref (family);
+  if (fontsel->family)
+    g_object_unref (fontsel->family);
+  fontsel->family = family;
+}
+
+static void gtk_font_selection_ref_face (GtkFontSelection *fontsel,
+                                        PangoFontFace    *face)
 {
-  GtkFontSelection *fontsel = GTK_FONT_SELECTION (widget);
+  if (face)
+    face = g_object_ref (face);
+  if (fontsel->face)
+    g_object_unref (fontsel->face);
+  fontsel->face = face;
+}
 
+static void
+gtk_font_selection_reload_fonts (GtkFontSelection *fontsel)
+{
   if (gtk_widget_has_screen (GTK_WIDGET (fontsel)))
     {
+      PangoFontDescription *desc;
+      desc = gtk_font_selection_get_font_description (fontsel);
+
       gtk_font_selection_show_available_fonts (fontsel);
       gtk_font_selection_show_available_sizes (fontsel, TRUE);
       gtk_font_selection_show_available_styles (fontsel);
+
+      gtk_font_selection_select_font_desc (fontsel, desc, NULL, NULL);
+      gtk_font_selection_scroll_to_selection (fontsel);
+
+      pango_font_description_free (desc);
     }
 }
 
+static void
+gtk_font_selection_screen_changed (GtkWidget *widget,
+                                  GdkScreen *previous_screen)
+{
+  gtk_font_selection_reload_fonts (GTK_FONT_SELECTION (widget));
+}
+
+static void
+gtk_font_selection_style_set (GtkWidget *widget,
+                             GtkStyle  *prev_style)
+{
+  /* Maybe fonts where installed or removed... */
+  gtk_font_selection_reload_fonts (GTK_FONT_SELECTION (widget));
+}
+
 static void
 gtk_font_selection_preview_changed (GtkWidget        *entry,
                                    GtkFontSelection *fontsel)
 {
-  g_object_notify (G_OBJECT (fontsel), "preview_text");
+  g_object_notify (G_OBJECT (fontsel), "preview-text");
 }
 
 static void
@@ -650,19 +676,9 @@ set_cursor_to_iter (GtkTreeView *view,
   gtk_tree_path_free (path);
 }
 
-/* This is called when the list is mapped. Here we scroll to the current
-   font if necessary. */
 static void
-gtk_font_selection_scroll_on_map (GtkWidget            *widget,
-                                  gpointer              data)
+gtk_font_selection_scroll_to_selection (GtkFontSelection *fontsel)
 {
-  GtkFontSelection *fontsel;
-  
-#ifdef FONTSEL_DEBUG
-  g_message ("In expose_list\n");
-#endif
-  fontsel = GTK_FONT_SELECTION (data);
-  
   /* Try to scroll the font family list to the selected item */
   scroll_to_selection (GTK_TREE_VIEW (fontsel->family_list));
       
@@ -671,6 +687,15 @@ gtk_font_selection_scroll_on_map (GtkWidget                *widget,
       
   /* Try to scroll the font family list to the selected item */
   scroll_to_selection (GTK_TREE_VIEW (fontsel->size_list));
+/* This is called when the list is mapped. Here we scroll to the current
+   font if necessary. */
+}
+
+static void
+gtk_font_selection_scroll_on_map (GtkWidget            *widget,
+                                  gpointer              data)
+{
+  gtk_font_selection_scroll_to_selection (GTK_FONT_SELECTION (data));
 }
 
 /* This is called when a family is selected in the list. */
@@ -681,8 +706,10 @@ gtk_font_selection_select_font (GtkTreeSelection *selection,
   GtkFontSelection *fontsel;
   GtkTreeModel *model;
   GtkTreeIter iter;
+#ifdef INCLUDE_FONT_ENTRIES
   const gchar *family_name;
-  
+#endif
+
   fontsel = GTK_FONT_SELECTION (data);
 
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
@@ -692,11 +719,10 @@ gtk_font_selection_select_font (GtkTreeSelection *selection,
       gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1);
       if (fontsel->family != family)
        {
-         fontsel->family = family;
-         
-         family_name = pango_font_family_get_name (fontsel->family);
+         gtk_font_selection_ref_family (fontsel, family);
          
 #ifdef INCLUDE_FONT_ENTRIES
+         family_name = pango_font_family_get_name (fontsel->family);
          gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name);
 #endif
          
@@ -752,7 +778,7 @@ gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel)
        }
     }
 
-  fontsel->family = match_family;
+  gtk_font_selection_ref_family (fontsel, match_family);
   if (match_family)
     {
       set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &match_row);
@@ -868,7 +894,7 @@ gtk_font_selection_show_available_styles (GtkFontSelection *fontsel)
   if (old_desc)
     pango_font_description_free (old_desc);
 
-  fontsel->face = match_face;
+  gtk_font_selection_ref_face (fontsel, match_face);
   if (match_face)
     {
 #ifdef INCLUDE_FONT_ENTRIES
@@ -921,8 +947,7 @@ gtk_font_selection_select_style (GtkTreeSelection *selection,
       PangoFontFace *face;
       
       gtk_tree_model_get (model, &iter, FACE_COLUMN, &face, -1);
-      fontsel->face = face;
-
+      gtk_font_selection_ref_face (fontsel, face);
       g_object_unref (face);
     }
 
@@ -936,12 +961,10 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel,
 {
   gint i;
   GtkListStore *model;
-  GtkTreeSelection *selection;
   gchar buffer[128];
   gchar *p;
       
   model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->size_list)));
-  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (fontsel->size_list));
 
   /* Insert the standard font sizes */
   if (first_time)
@@ -1101,7 +1124,7 @@ gtk_font_selection_get_font_description (GtkFontSelection *fontsel)
       pango_font_description_set_size (font_desc, fontsel->size);
     }
   else
-    font_desc = pango_font_description_from_string ("Sans 10");
+    font_desc = pango_font_description_from_string (DEFAULT_FONT_NAME);
 
   return font_desc;
 }
@@ -1127,7 +1150,7 @@ gtk_font_selection_update_preview (GtkFontSelection *fontsel)
   rc_style->font_desc = gtk_font_selection_get_font_description (fontsel);
   
   gtk_widget_modify_style (preview_entry, rc_style);
-  gtk_rc_style_unref (rc_style);
+  g_object_unref (rc_style);
 
   gtk_widget_size_request (preview_entry, NULL);
   
@@ -1162,12 +1185,194 @@ gtk_font_selection_get_font_internal (GtkFontSelection *fontsel)
  * These functions are the main public interface for getting/setting the font.
  *****************************************************************************/
 
-GdkFont*
+/**
+ * gtk_font_selection_get_family_list:
+ * @fontsel: a #GtkFontSelection
+ *
+ * This returns the #GtkTreeView that lists font families, for
+ * example, 'Sans', 'Serif', etc.
+ * 
+ * Return value: A #GtkWidget that is part of @fontsel
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_get_family_list (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->family_list;
+}
+
+/**
+ * gtk_font_selection_get_face_list:
+ * @fontsel: a #GtkFontSelection
+ *
+ * This returns the #GtkTreeView which lists all styles available for
+ * the selected font. For example, 'Regular', 'Bold', etc.
+ * 
+ * Return value: A #GtkWidget that is part of @fontsel
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_get_face_list (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->face_list;
+}
+
+/**
+ * gtk_font_selection_get_size_entry:
+ * @fontsel: a #GtkFontSelection
+ *
+ * This returns the #GtkEntry used to allow the user to edit the font
+ * number manually instead of selecting it from the list of font sizes. 
+ * 
+ * Return value: A #GtkWidget that is part of @fontsel
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_get_size_entry (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->size_entry;
+}
+
+/**
+ * gtk_font_selection_get_size_list:
+ * @fontsel: a #GtkFontSelection
+ *
+ * This returns the #GtkTreeeView used to list font sizes. 
+ * 
+ * Return value: A #GtkWidget that is part of @fontsel
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_get_size_list (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->size_list;
+}
+
+/**
+ * gtk_font_selection_get_preview_entry:
+ * @fontsel: a #GtkFontSelection
+ * 
+ * This returns the #GtkEntry used to display the font as a preview.
+ *
+ * Return value: A #GtkWidget that is part of @fontsel
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->preview_entry;
+}
+
+/**
+ * gtk_font_selection_get_family:
+ * @fontsel: a #GtkFontSelection
+ * 
+ * Gets the #PangoFontFamily representing the selected font family.
+ *
+ * Return value: A #PangoFontFamily representing the selected font
+ *     family. Font families are a collection of font faces. The 
+ *     returned object is owned by @fontsel and must not be modified 
+ *     or freed.
+ *
+ * Since: 2.14
+ */
+PangoFontFamily *
+gtk_font_selection_get_family (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->family;
+}
+
+/**
+ * gtk_font_selection_get_face:
+ * @fontsel: a #GtkFontSelection
+ * 
+ * Gets the #PangoFontFace representing the selected font group
+ * details (i.e. family, slant, weight, width, etc).   
+ *
+ * Return value: A #PangoFontFace representing the selected font 
+ *     group details. The returned object is owned by @fontsel and
+ *     must not be modified or freed. 
+ *
+ * Since: 2.14
+ */
+PangoFontFace *
+gtk_font_selection_get_face (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+  
+  return fontsel->face;
+}
+
+/**
+ * gtk_font_selection_get_size:
+ * @fontsel: a #GtkFontSelection
+ * 
+ * The selected font size.
+ *
+ * Return value: A n integer representing the selected font size, 
+ *     or -1 if no font size is selected.
+ *
+ * Since: 2.14
+ **/
+gint
+gtk_font_selection_get_size (GtkFontSelection *fontsel)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), -1);
+  
+  return fontsel->size;
+}
+
+/**
+ * gtk_font_selection_get_font:
+ * @fontsel: a #GtkFontSelection
+ *
+ * Gets the currently-selected font.
+ * 
+ * Return value: A #GdkFont.
+ *
+ * Deprecated: 2.0: Use gtk_font_selection_get_font_name() instead.
+ */
+GdkFont *
 gtk_font_selection_get_font (GtkFontSelection *fontsel)
 {
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+
   return gtk_font_selection_get_font_internal (fontsel);
 }
 
+/**
+ * gtk_font_selection_get_font_name:
+ * @fontsel: a #GtkFontSelection
+ * 
+ * Gets the currently-selected font name. 
+ *
+ * Note that this can be a different string than what you set with 
+ * gtk_font_selection_set_font_name(), as the font selection widget may 
+ * normalize font names and thus return a string with a different structure. 
+ * For example, "Helvetica Italic Bold 12" could be normalized to 
+ * "Helvetica Bold Italic 12". Use pango_font_description_equal()
+ * if you want to compare two font descriptions.
+ * 
+ * Return value: A string with the name of the current font, or %NULL if 
+ *     no font is selected. You must free this string with g_free().
+ */
 gchar *
 gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
 {
@@ -1180,31 +1385,33 @@ gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
   return result;
 }
 
-
-/* This sets the current font, selecting the appropriate list rows.
+/* This selects the appropriate list rows.
    First we check the fontname is valid and try to find the font family
    - i.e. the name in the main list. If we can't find that, then just return.
    Next we try to set each of the properties according to the fontname.
    Finally we select the font family & style in the lists. */
-gboolean
-gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
-                                 const gchar      *fontname)
+static gboolean
+gtk_font_selection_select_font_desc (GtkFontSelection      *fontsel,
+                                    PangoFontDescription  *new_desc,
+                                    PangoFontFamily      **pfamily,
+                                    PangoFontFace        **pface)
 {
   PangoFontFamily *new_family = NULL;
   PangoFontFace *new_face = NULL;
   PangoFontFace *fallback_face = NULL;
-  PangoFontDescription *new_desc;
   GtkTreeModel *model;
   GtkTreeIter iter;
   GtkTreeIter match_iter;
   gboolean valid;
-  
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
-  
-  new_desc = pango_font_description_from_string (fontname);
+  const gchar *new_family_name;
+
+  new_family_name = pango_font_description_get_family (new_desc);
 
-  /* Check to make sure that this is in the list of allowed fonts */
+  if (!new_family_name)
+    return FALSE;
 
+  /* Check to make sure that this is in the list of allowed fonts 
+   */
   model = gtk_tree_view_get_model (GTK_TREE_VIEW (fontsel->family_list));
   for (valid = gtk_tree_model_get_iter_first (model, &iter);
        valid;
@@ -1215,9 +1422,9 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
       gtk_tree_model_get (model, &iter, FAMILY_COLUMN, &family, -1);
       
       if (g_ascii_strcasecmp (pango_font_family_get_name (family),
-                             pango_font_description_get_family (new_desc)) == 0)
-       new_family = family;
-      
+                             new_family_name) == 0)
+       new_family = g_object_ref (family);
+
       g_object_unref (family);
       
       if (new_family)
@@ -1227,7 +1434,10 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
   if (!new_family)
     return FALSE;
 
-  fontsel->family = new_family;
+  if (pfamily)
+    *pfamily = new_family;
+  else
+    g_object_unref (new_family);
   set_cursor_to_iter (GTK_TREE_VIEW (fontsel->family_list), &iter);
   gtk_font_selection_show_available_styles (fontsel);
 
@@ -1243,11 +1453,11 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
       tmp_desc = pango_font_face_describe (face);
       
       if (font_description_style_equal (tmp_desc, new_desc))
-       new_face = face;
+       new_face = g_object_ref (face);
       
       if (!fallback_face)
        {
-         fallback_face = face;
+         fallback_face = g_object_ref (face);
          match_iter = iter;
        }
       
@@ -1263,37 +1473,108 @@ gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
 
   if (!new_face)
     new_face = fallback_face;
+  else if (fallback_face)
+    g_object_unref (fallback_face);
 
-  fontsel->face = new_face;
+  if (pface)
+    *pface = new_face;
+  else if (new_face)
+    g_object_unref (new_face);
   set_cursor_to_iter (GTK_TREE_VIEW (fontsel->face_list), &match_iter);  
 
   gtk_font_selection_set_size (fontsel, pango_font_description_get_size (new_desc));
+
+  return TRUE;
+}
+
+
+/* This sets the current font, then selecting the appropriate list rows. */
+
+/**
+ * gtk_font_selection_set_font_name:
+ * @fontsel: a #GtkFontSelection
+ * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
+ * 
+ * Sets the currently-selected font. 
+ *
+ * Note that the @fontsel needs to know the screen in which it will appear 
+ * for this to work; this can be guaranteed by simply making sure that the 
+ * @fontsel is inserted in a toplevel window before you call this function.
+ * 
+ * Return value: %TRUE if the font could be set successfully; %FALSE if no 
+ *     such font exists or if the @fontsel doesn't belong to a particular 
+ *     screen yet.
+ */
+gboolean
+gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
+                                 const gchar      *fontname)
+{
+  PangoFontFamily *family = NULL;
+  PangoFontFace *face = NULL;
+  PangoFontDescription *new_desc;
+  
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
+
+  if (!gtk_widget_has_screen (GTK_WIDGET (fontsel)))
+    return FALSE;
+
+  new_desc = pango_font_description_from_string (fontname);
+
+  if (gtk_font_selection_select_font_desc (fontsel, new_desc, &family, &face))
+    {
+      gtk_font_selection_ref_family (fontsel, family);
+      if (family)
+        g_object_unref (family);
+
+      gtk_font_selection_ref_face (fontsel, face);
+      if (face)
+        g_object_unref (face);
+    }
+
+  pango_font_description_free (new_desc);
   
   g_object_freeze_notify (G_OBJECT (fontsel));
-  g_object_notify (G_OBJECT (fontsel), "font_name");
+  g_object_notify (G_OBJECT (fontsel), "font-name");
   g_object_notify (G_OBJECT (fontsel), "font");
   g_object_thaw_notify (G_OBJECT (fontsel));
 
-  pango_font_description_free (new_desc);
-
   return TRUE;
 }
 
-
-/* This returns the text in the preview entry. You should copy the returned
-   text if you need it. */
+/**
+ * gtk_font_selection_get_preview_text:
+ * @fontsel: a #GtkFontSelection
+ *
+ * Gets the text displayed in the preview area.
+ * 
+ * Return value: the text displayed in the preview area. 
+ *     This string is owned by the widget and should not be 
+ *     modified or freed 
+ */
 G_CONST_RETURN gchar*
-gtk_font_selection_get_preview_text  (GtkFontSelection *fontsel)
+gtk_font_selection_get_preview_text (GtkFontSelection *fontsel)
 {
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), NULL);
+
   return gtk_entry_get_text (GTK_ENTRY (fontsel->preview_entry));
 }
 
 
-/* This sets the text in the preview entry. */
+/**
+ * gtk_font_selection_set_preview_text:
+ * @fontsel: a #GtkFontSelection
+ * @text: the text to display in the preview area 
+ *
+ * Sets the text displayed in the preview area.
+ * The @text is used to show how the selected font looks.
+ */
 void
 gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
-                                     const gchar         *text)
+                                     const gchar      *text)
 {
+  g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
+  g_return_if_fail (text != NULL);
+
   gtk_entry_set_text (GTK_ENTRY (fontsel->preview_entry), text);
 }
 
@@ -1301,56 +1582,42 @@ gtk_font_selection_set_preview_text  (GtkFontSelection *fontsel,
  * GtkFontSelectionDialog
  *****************************************************************************/
 
-GType
-gtk_font_selection_dialog_get_type (void)
-{
-  static GType font_selection_dialog_type = 0;
-  
-  if (!font_selection_dialog_type)
-    {
-      static const GTypeInfo fontsel_diag_info =
-      {
-       sizeof (GtkFontSelectionDialogClass),
-       NULL,           /* base_init */
-       NULL,           /* base_finalize */
-       (GClassInitFunc) gtk_font_selection_dialog_class_init,
-       NULL,           /* class_finalize */
-       NULL,           /* class_data */
-       sizeof (GtkFontSelectionDialog),
-       0,              /* n_preallocs */
-       (GInstanceInitFunc) gtk_font_selection_dialog_init,
-      };
-      
-      font_selection_dialog_type =
-       g_type_register_static (GTK_TYPE_DIALOG, g_intern_static_string ("GtkFontSelectionDialog"),
-                               &fontsel_diag_info, 0);
-    }
-  
-  return font_selection_dialog_type;
-}
+static void gtk_font_selection_dialog_buildable_interface_init     (GtkBuildableIface *iface);
+static GObject * gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
+                                                                         GtkBuilder   *builder,
+                                                                         const gchar  *childname);
+
+G_DEFINE_TYPE_WITH_CODE (GtkFontSelectionDialog, gtk_font_selection_dialog,
+                        GTK_TYPE_DIALOG,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                               gtk_font_selection_dialog_buildable_interface_init))
+
+static GtkBuildableIface *parent_buildable_iface;
 
 static void
 gtk_font_selection_dialog_class_init (GtkFontSelectionDialogClass *klass)
 {
-  font_selection_dialog_parent_class = g_type_class_peek_parent (klass);
 }
 
 static void
 gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
 {
-  GtkDialog *dialog;
+  GtkDialog *dialog = GTK_DIALOG (fontseldiag);
+  
+  gtk_dialog_set_has_separator (dialog, FALSE);
+  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+  gtk_box_set_spacing (GTK_BOX (dialog->vbox), 2); /* 2 * 5 + 2 = 12 */
+  gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 5);
+  gtk_box_set_spacing (GTK_BOX (dialog->action_area), 6);
 
   gtk_widget_push_composite_child ();
 
-  dialog = GTK_DIALOG (fontseldiag);
-  
-  gtk_container_set_border_width (GTK_CONTAINER (fontseldiag), 4);
   gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
   
   fontseldiag->main_vbox = dialog->vbox;
   
   fontseldiag->fontsel = gtk_font_selection_new ();
-  gtk_container_set_border_width (GTK_CONTAINER (fontseldiag->fontsel), 4);
+  gtk_container_set_border_width (GTK_CONTAINER (fontseldiag->fontsel), 5);
   gtk_widget_show (fontseldiag->fontsel);
   gtk_box_pack_start (GTK_BOX (fontseldiag->main_vbox),
                      fontseldiag->fontsel, TRUE, TRUE, 0);
@@ -1378,15 +1645,22 @@ gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
                                           GTK_RESPONSE_CANCEL,
                                           -1);
 
-
   gtk_window_set_title (GTK_WINDOW (fontseldiag),
                         _("Font Selection"));
 
-  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-  
   gtk_widget_pop_composite_child ();
+
+  _gtk_dialog_set_ignore_separator (dialog, TRUE);
 }
 
+/**
+ * gtk_font_selection_dialog_new:
+ * @title: the title of the dialog window 
+ *
+ * Creates a new #GtkFontSelectionDialog.
+ *
+ * Return value: a new #GtkFontSelectionDialog
+ */
 GtkWidget*
 gtk_font_selection_dialog_new (const gchar *title)
 {
@@ -1400,35 +1674,181 @@ gtk_font_selection_dialog_new (const gchar *title)
   return GTK_WIDGET (fontseldiag);
 }
 
+/**
+ * gtk_font_selection_dialog_get_ok_button:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Gets the 'OK' button.
+ *
+ * Return value: the #GtkWidget used in the dialog for the 'OK' button.
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return fsd->ok_button;
+}
+
+/**
+ * gtk_font_selection_dialog_get_apply_button:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Obtains a button. The button doesn't have any function.
+ *
+ * Return value: a #GtkWidget
+ *
+ * Since: 2.14
+ *
+ * Deprecated: 2.16: Don't use this function.
+ */
+GtkWidget *
+gtk_font_selection_dialog_get_apply_button (GtkFontSelectionDialog *fsd)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return fsd->apply_button;
+}
+
+/**
+ * gtk_font_selection_dialog_get_cancel_button:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Gets the 'Cancel' button.
+ *
+ * Return value: the #GtkWidget used in the dialog for the 'Cancel' button.
+ *
+ * Since: 2.14
+ */
+GtkWidget *
+gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return fsd->cancel_button;
+}
+
+static void
+gtk_font_selection_dialog_buildable_interface_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+  iface->get_internal_child = gtk_font_selection_dialog_buildable_get_internal_child;
+}
+
+static GObject *
+gtk_font_selection_dialog_buildable_get_internal_child (GtkBuildable *buildable,
+                                                       GtkBuilder   *builder,
+                                                       const gchar  *childname)
+{
+    if (strcmp(childname, "ok_button") == 0)
+       return G_OBJECT (GTK_FONT_SELECTION_DIALOG(buildable)->ok_button);
+    else if (strcmp(childname, "cancel_button") == 0)
+       return G_OBJECT (GTK_FONT_SELECTION_DIALOG (buildable)->cancel_button);
+    else if (strcmp(childname, "apply_button") == 0)
+       return G_OBJECT (GTK_FONT_SELECTION_DIALOG(buildable)->apply_button);
+    else if (strcmp(childname, "font_selection") == 0)
+       return G_OBJECT (GTK_FONT_SELECTION_DIALOG(buildable)->fontsel);
+
+    return parent_buildable_iface->get_internal_child (buildable, builder, childname);
+}
+
+/**
+ * gtk_font_selection_dialog_get_font_name:
+ * @fsd: a #GtkFontSelectionDialog
+ * 
+ * Gets the currently-selected font name.
+ *
+ * Note that this can be a different string than what you set with 
+ * gtk_font_selection_dialog_set_font_name(), as the font selection widget
+ * may normalize font names and thus return a string with a different 
+ * structure. For example, "Helvetica Italic Bold 12" could be normalized 
+ * to "Helvetica Bold Italic 12".  Use pango_font_description_equal()
+ * if you want to compare two font descriptions.
+ * 
+ * Return value: A string with the name of the current font, or %NULL if no 
+ *     font is selected. You must free this string with g_free().
+ */
 gchar*
 gtk_font_selection_dialog_get_font_name (GtkFontSelectionDialog *fsd)
 {
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
   return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (fsd->fontsel));
 }
 
+/**
+ * gtk_font_selection_dialog_get_font:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Gets the currently-selected font.
+ *
+ * Return value: the #GdkFont from the #GtkFontSelection for the
+ *     currently selected font in the dialog, or %NULL if no font is selected
+ *
+ * Deprecated: 2.0: Use gtk_font_selection_dialog_get_font_name() instead.
+ */
 GdkFont*
 gtk_font_selection_dialog_get_font (GtkFontSelectionDialog *fsd)
 {
-  return gtk_font_selection_get_font (GTK_FONT_SELECTION (fsd->fontsel));
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return gtk_font_selection_get_font_internal (GTK_FONT_SELECTION (fsd->fontsel));
 }
 
+/**
+ * gtk_font_selection_dialog_set_font_name:
+ * @fsd: a #GtkFontSelectionDialog
+ * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
+ *
+ * Sets the currently selected font. 
+ * 
+ * Return value: %TRUE if the font selected in @fsd is now the
+ *     @fontname specified, %FALSE otherwise. 
+ */
 gboolean
 gtk_font_selection_dialog_set_font_name (GtkFontSelectionDialog *fsd,
-                                        const gchar      *fontname)
+                                        const gchar            *fontname)
 {
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
+  g_return_val_if_fail (fontname, FALSE);
+
   return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (fsd->fontsel), fontname);
 }
 
+/**
+ * gtk_font_selection_dialog_get_preview_text:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Gets the text displayed in the preview area.
+ * 
+ * Return value: the text displayed in the preview area. 
+ *     This string is owned by the widget and should not be 
+ *     modified or freed 
+ */
 G_CONST_RETURN gchar*
 gtk_font_selection_dialog_get_preview_text (GtkFontSelectionDialog *fsd)
 {
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
   return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (fsd->fontsel));
 }
 
+/**
+ * gtk_font_selection_dialog_set_preview_text:
+ * @fsd: a #GtkFontSelectionDialog
+ * @text: the text to display in the preview area
+ *
+ * Sets the text displayed in the preview area. 
+ */
 void
 gtk_font_selection_dialog_set_preview_text (GtkFontSelectionDialog *fsd,
                                            const gchar            *text)
 {
+  g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
+  g_return_if_fail (text != NULL);
+
   gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (fsd->fontsel), text);
 }