[gtk+/font-selection-new] GtkFontSelection: GtkFontSelectionDialog: Split gtkfontsel.[ch] into gtkfontselection.[ch] gtkfontse



commit 3f7de1d1ca7c8e46ba52708e6287fe4319948302
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sun May 8 16:07:18 2011 +0100

    GtkFontSelection: GtkFontSelectionDialog: Split gtkfontsel.[ch] into gtkfontselection.[ch] gtkfontselectiondialog.[ch]

 gtk/Makefile.am                          |    6 +-
 gtk/gtk.h                                |    3 +-
 gtk/gtkfontbutton.c                      |    2 +-
 gtk/gtkfontsel.h                         |  186 ---------------
 gtk/{gtkfontsel.c => gtkfontselection.c} |  321 +-------------------------
 gtk/gtkfontselection.h                   |  107 +++++++++
 gtk/gtkfontselectiondialog.c             |  384 ++++++++++++++++++++++++++++++
 gtk/gtkfontselectiondialog.h             |  120 ++++++++++
 8 files changed, 619 insertions(+), 510 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index b558763..6fe4d3c 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -214,7 +214,8 @@ gtk_public_h_sources = 		\
 	gtkfilefilter.h		\
 	gtkfixed.h		\
 	gtkfontbutton.h		\
-	gtkfontsel.h		\
+	gtkfontselection.h	\
+	gtkfontselectiondialog.h \
 	gtkframe.h		\
 	gtkgradient.h		\
 	gtkgrid.h		\
@@ -533,7 +534,8 @@ gtk_base_c_sources = 		\
 	gtkfilesystemmodel.c	\
 	gtkfixed.c		\
 	gtkfontbutton.c		\
-	gtkfontsel.c		\
+	gtkfontselection.c	\
+	gtkfontselectiondialog.c \
 	gtkframe.c		\
 	gtkgradient.c		\
 	gtkgrid.c		\
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 6d6b416..33c4476 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -100,7 +100,8 @@
 #include <gtk/gtkfilechooserwidget.h>
 #include <gtk/gtkfilefilter.h>
 #include <gtk/gtkfontbutton.h>
-#include <gtk/gtkfontsel.h>
+#include <gtk/gtkfontselection.h>
+#include <gtk/gtkfontselectiondialog.h>
 #include <gtk/gtkframe.h>
 #include <gtk/gtkgradient.h>
 #include <gtk/gtkgrid.h>
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 0cd08f4..2e3b431 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -35,7 +35,7 @@
 #include "gtkhbox.h"
 #include "gtklabel.h"
 #include "gtkvseparator.h"
-#include "gtkfontsel.h"
+#include "gtkfontselectiondialog.h"
 #include "gtkimage.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontselection.c
similarity index 85%
rename from gtk/gtkfontsel.c
rename to gtk/gtkfontselection.c
index 9c3b97a..b7056c5 100644
--- a/gtk/gtkfontsel.c
+++ b/gtk/gtkfontselection.c
@@ -39,7 +39,7 @@
 
 #include <atk/atk.h>
 
-#include "gtkfontsel.h"
+#include "gtkfontselection.h"
 #include "gtkbutton.h"
 #include "gtkcellrenderertext.h"
 #include "gtkentry.h"
@@ -120,19 +120,6 @@ struct _GtkFontSelectionPrivate
   gboolean      ignore_font;
 };
 
-
-struct _GtkFontSelectionDialogPrivate
-{
-  GtkWidget *fontsel;
-
-  GtkWidget *select_button;
-  GtkWidget *cancel_button;
-
-  /* Deprecated */
-  GtkWidget *apply_button;
-};
-
-
 #define DEFAULT_FONT_NAME "Sans 10"
 #define MAX_FONT_SIZE 999
 
@@ -1827,309 +1814,3 @@ gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel)
 
   return priv->preview;
 }
-
-/**
- * SECTION:gtkfontseldlg
- * @Short_description: A dialog box for selecting fonts
- * @Title: GtkFontSelectionDialog
- * @See_also: #GtkFontSelection, #GtkDialog
- *
- * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
- *
- * To set the font which is initially selected, use
- * gtk_font_selection_dialog_set_font_name().
- *
- * To get the selected font use gtk_font_selection_dialog_get_font_name().
- *
- * To change the text which is shown in the preview area, use
- * gtk_font_selection_dialog_set_preview_text().
- *
- * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
- * <title>GtkFontSelectionDialog as GtkBuildable</title>
- * The GtkFontSelectionDialog implementation of the GtkBuildable interface
- * exposes the embedded #GtkFontSelection as internal child with the
- * name "font_selection". It also exposes the buttons with the names
- * "select_button" and "cancel_button. The buttons with the names 
- * "ok_button" and "apply_button" are exposed but deprecated.
- * </refsect2>
- */
-
-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)
-{
-  g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
-}
-
-static void
-gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
-{
-  GtkFontSelectionDialogPrivate *priv;
-  GtkDialog *dialog = GTK_DIALOG (fontseldiag);
-  GtkWidget *action_area, *content_area;
-
-  fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
-                                                   GTK_TYPE_FONT_SELECTION_DIALOG,
-                                                   GtkFontSelectionDialogPrivate);
-  priv = fontseldiag->priv;
-
-  content_area = gtk_dialog_get_content_area (dialog);
-  action_area = gtk_dialog_get_action_area (dialog);
-
-  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
-  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
-  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
-  gtk_box_set_spacing (GTK_BOX (action_area), 6);
-
-  gtk_widget_push_composite_child ();
-
-  gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
-
-  /* Create the content area */
-  priv->fontsel = gtk_font_selection_new ();
-  gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
-  gtk_widget_show (priv->fontsel);
-  gtk_box_pack_start (GTK_BOX (content_area),
-                      priv->fontsel, TRUE, TRUE, 0);
-
-  /* Create the action area */
-  priv->cancel_button = gtk_dialog_add_button (dialog,
-                                               GTK_STOCK_CANCEL,
-                                               GTK_RESPONSE_CANCEL);
-  /* Deprecated: Apply button is not used anymore */
-  priv->apply_button = gtk_dialog_add_button (dialog,
-                                              GTK_STOCK_APPLY,
-                                              GTK_RESPONSE_APPLY);
-  gtk_widget_hide (priv->apply_button);
-
-  priv->select_button = gtk_dialog_add_button (dialog,
-                                               _("Select"),
-                                               GTK_RESPONSE_OK);
-  gtk_widget_grab_default (priv->select_button);
-
-  gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
-             GTK_RESPONSE_OK,
-             GTK_RESPONSE_APPLY, /* Deprecated */
-             GTK_RESPONSE_CANCEL,
-             -1);
-
-  gtk_window_set_title (GTK_WINDOW (fontseldiag),
-                        _("Font Selection"));
-
-  gtk_widget_pop_composite_child ();
-}
-
-/**
- * gtk_font_selection_dialog_new:
- * @title: (allow-none): the title of the dialog window 
- *
- * Creates a new #GtkFontSelectionDialog.
- *
- * Return value: a new #GtkFontSelectionDialog
- */
-GtkWidget*
-gtk_font_selection_dialog_new (const gchar *title)
-{
-  GtkFontSelectionDialog *fontseldiag;
-  
-  fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
-
-  if (title)
-    gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
-  
-  return GTK_WIDGET (fontseldiag);
-}
-
-/**
- * gtk_font_selection_dialog_get_font_selection:
- * @fsd: a #GtkFontSelectionDialog
- *
- * Retrieves the #GtkFontSelection widget embedded in the dialog.
- *
- * Returns: (transfer none): the embedded #GtkFontSelection
- *
- * Since: 2.22
- **/
-GtkWidget*
-gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
-{
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
-
-  return fsd->priv->fontsel;
-}
-
-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)
-{
-  GtkFontSelectionDialogPrivate *priv;
-
-  priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
-
-  if (g_strcmp0 (childname, "select_button") == 0)
-    return G_OBJECT (priv->select_button);
-  else if (g_strcmp0 (childname, "cancel_button") == 0)
-    return G_OBJECT (priv->cancel_button);
-  else if (g_strcmp0 (childname, "font_selection") == 0)
-    return G_OBJECT (priv->fontsel);
-
-  /* Deprecated */
-  else if (g_strcmp0 (childname, "ok_button") == 0)
-    return G_OBJECT (priv->select_button);
-  else if (g_strcmp0 (childname, "apply_button") == 0)
-    return G_OBJECT (priv->apply_button);
-
-  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)
-{
-  GtkFontSelectionDialogPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
-
-  priv = fsd->priv;
-
-  return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->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)
-{
-  GtkFontSelectionDialogPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
-  g_return_val_if_fail (fontname, FALSE);
-
-  priv = fsd->priv;
-
-  return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->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)
-{
-  GtkFontSelectionDialogPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
-
-  priv = fsd->priv;
-
-  return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->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)
-{
-  GtkFontSelectionDialogPrivate *priv;
-
-  g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
-  g_return_if_fail (text != NULL);
-
-  priv = fsd->priv;
-
-  gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
-}
-
-/**
- * gtk_font_selection_dialog_get_ok_button:
- * @fsd: a #GtkFontSelectionDialog
- *
- * Gets the 'OK' button.
- *
- * Return value: (transfer none): the #GtkWidget used in the dialog
- *     for the 'OK' button.
- *
- * Deprecated: 3.2
- */
-GtkWidget *
-gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
-{
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
-
-  return fsd->priv->select_button;
-}
-
-/**
- * gtk_font_selection_dialog_get_cancel_button:
- * @fsd: a #GtkFontSelectionDialog
- *
- * Gets the 'Cancel' button.
- *
- * Return value: (transfer none): the #GtkWidget used in the dialog
- *     for the 'Cancel' button.
- *
- * Deprecated: 3.2
- */
-GtkWidget *
-gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
-{
-  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
-
-  return fsd->priv->cancel_button;
-}
diff --git a/gtk/gtkfontselection.h b/gtk/gtkfontselection.h
new file mode 100644
index 0000000..d9c3434
--- /dev/null
+++ b/gtk/gtkfontselection.h
@@ -0,0 +1,107 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011      Alberto Ruiz <aruiz gnome org>
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998.
+ * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes.
+ * The GnomeFontSelector was derived from app/text_tool.c in the GIMP.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_FONTSELECTION_H__
+#define __GTK_FONTSELECTION_H__
+
+
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkvbox.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_FONT_SELECTION              (gtk_font_selection_get_type ())
+#define GTK_FONT_SELECTION(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_SELECTION, GtkFontSelection))
+#define GTK_FONT_SELECTION_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_SELECTION, GtkFontSelectionClass))
+#define GTK_IS_FONT_SELECTION(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_SELECTION))
+#define GTK_IS_FONT_SELECTION_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_SELECTION))
+#define GTK_FONT_SELECTION_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FONT_SELECTION, GtkFontSelectionClass))
+
+typedef struct _GtkFontSelection              GtkFontSelection;
+typedef struct _GtkFontSelectionPrivate       GtkFontSelectionPrivate;
+typedef struct _GtkFontSelectionClass         GtkFontSelectionClass;
+
+struct _GtkFontSelection
+{
+  GtkVBox parent_instance;
+
+  /*< private >*/
+  GtkFontSelectionPrivate *priv;
+};
+
+struct _GtkFontSelectionClass
+{
+  GtkVBoxClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+/*****************************************************************************
+ * GtkFontSelection functions.
+ *   see the comments in the GtkFontSelectionDialog functions.
+ *****************************************************************************/
+
+GType        gtk_font_selection_get_type                 (void) G_GNUC_CONST;
+GtkWidget*   gtk_font_selection_new                      (void);
+PangoFontFamily*
+             gtk_font_selection_get_family               (GtkFontSelection *fontsel);
+PangoFontFace*
+             gtk_font_selection_get_face                 (GtkFontSelection *fontsel);
+gint         gtk_font_selection_get_size                 (GtkFontSelection *fontsel);
+gchar*       gtk_font_selection_get_font_name            (GtkFontSelection *fontsel);
+
+gboolean     gtk_font_selection_set_font_name            (GtkFontSelection *fontsel,
+                                                          const gchar      *fontname);
+const gchar* gtk_font_selection_get_preview_text         (GtkFontSelection *fontsel);
+void         gtk_font_selection_set_preview_text         (GtkFontSelection *fontsel,
+                                                          const gchar      *text);
+gboolean     gtk_font_selection_get_show_preview_entry   (GtkFontSelection *fontsel);
+void         gtk_font_selection_set_show_preview_entry   (GtkFontSelection *fontsel,
+                                                          gboolean          show_preview_entry);
+/* Deprecated GtkFontSelection methods */
+#ifndef GTK_DISABLE_DEPRECATED
+GtkWidget*  gtk_font_selection_get_family_list   (GtkFontSelection *fontsel);
+GtkWidget*  gtk_font_selection_get_face_list     (GtkFontSelection *fontsel);
+GtkWidget*  gtk_font_selection_get_size_entry    (GtkFontSelection *fontsel);
+GtkWidget*  gtk_font_selection_get_size_list     (GtkFontSelection *fontsel);
+GtkWidget*  gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel);
+#endif
+
+#endif /* __GTK_FONTSELECTION_H__ */
diff --git a/gtk/gtkfontselectiondialog.c b/gtk/gtkfontselectiondialog.c
new file mode 100644
index 0000000..70c07fa
--- /dev/null
+++ b/gtk/gtkfontselectiondialog.c
@@ -0,0 +1,384 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011 Alberto Ruiz <aruiz gnome org>
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * Massively updated to rework the user interface by Alberto Ruiz, 2011
+ * Massively updated for Pango by Owen Taylor, May 2000
+ * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998.
+ * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes.
+ * The GnomeFontSelector was derived from app/text_tool.c in the GIMP.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <glib/gprintf.h>
+#include <string.h>
+
+#include <atk/atk.h>
+
+#include "gtkfontselection.h"
+#include "gtkfontselectiondialog.h"
+#include "gtkbutton.h"
+#include "gtkcellrenderertext.h"
+#include "gtkentry.h"
+#include "gtkframe.h"
+#include "gtkhbbox.h"
+#include "gtkhbox.h"
+#include "gtklabel.h"
+#include "gtkliststore.h"
+#include "gtkrc.h"
+#include "gtkstock.h"
+#include "gtktable.h"
+#include "gtktreeselection.h"
+#include "gtktreeview.h"
+#include "gtkvbox.h"
+#include "gtkscrolledwindow.h"
+#include "gtkintl.h"
+#include "gtkaccessible.h"
+#include "gtkbuildable.h"
+#include "gtkprivate.h"
+#include "gtkalignment.h"
+#include "gtkscale.h"
+#include "gtkbox.h"
+#include "gtkspinbutton.h"
+#include "gtkwidget.h"
+
+/**
+ * SECTION:gtkfontseldlg
+ * @Short_description: A dialog box for selecting fonts
+ * @Title: GtkFontSelectionDialog
+ * @See_also: #GtkFontSelection, #GtkDialog
+ *
+ * The #GtkFontSelectionDialog widget is a dialog box for selecting a font.
+ *
+ * To set the font which is initially selected, use
+ * gtk_font_selection_dialog_set_font_name().
+ *
+ * To get the selected font use gtk_font_selection_dialog_get_font_name().
+ *
+ * To change the text which is shown in the preview area, use
+ * gtk_font_selection_dialog_set_preview_text().
+ *
+ * <refsect2 id="GtkFontSelectionDialog-BUILDER-UI">
+ * <title>GtkFontSelectionDialog as GtkBuildable</title>
+ * The GtkFontSelectionDialog implementation of the GtkBuildable interface
+ * exposes the embedded #GtkFontSelection as internal child with the
+ * name "font_selection". It also exposes the buttons with the names
+ * "select_button" and "cancel_button. The buttons with the names 
+ * "ok_button" and "apply_button" are exposed but deprecated.
+ * </refsect2>
+ */
+
+struct _GtkFontSelectionDialogPrivate
+{
+  GtkWidget *fontsel;
+
+  GtkWidget *select_button;
+  GtkWidget *cancel_button;
+
+  /* Deprecated */
+  GtkWidget *apply_button;
+};
+
+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)
+{
+  g_type_class_add_private (klass, sizeof (GtkFontSelectionDialogPrivate));
+}
+
+static void
+gtk_font_selection_dialog_init (GtkFontSelectionDialog *fontseldiag)
+{
+  GtkFontSelectionDialogPrivate *priv;
+  GtkDialog *dialog = GTK_DIALOG (fontseldiag);
+  GtkWidget *action_area, *content_area;
+
+  fontseldiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontseldiag,
+                                                   GTK_TYPE_FONT_SELECTION_DIALOG,
+                                                   GtkFontSelectionDialogPrivate);
+  priv = fontseldiag->priv;
+
+  content_area = gtk_dialog_get_content_area (dialog);
+  action_area = gtk_dialog_get_action_area (dialog);
+
+  gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
+  gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
+  gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
+  gtk_box_set_spacing (GTK_BOX (action_area), 6);
+
+  gtk_widget_push_composite_child ();
+
+  gtk_window_set_resizable (GTK_WINDOW (fontseldiag), TRUE);
+
+  /* Create the content area */
+  priv->fontsel = gtk_font_selection_new ();
+  gtk_container_set_border_width (GTK_CONTAINER (priv->fontsel), 5);
+  gtk_widget_show (priv->fontsel);
+  gtk_box_pack_start (GTK_BOX (content_area),
+                      priv->fontsel, TRUE, TRUE, 0);
+
+  /* Create the action area */
+  priv->cancel_button = gtk_dialog_add_button (dialog,
+                                               GTK_STOCK_CANCEL,
+                                               GTK_RESPONSE_CANCEL);
+  /* Deprecated: Apply button is not used anymore */
+  priv->apply_button = gtk_dialog_add_button (dialog,
+                                              GTK_STOCK_APPLY,
+                                              GTK_RESPONSE_APPLY);
+  gtk_widget_hide (priv->apply_button);
+
+  priv->select_button = gtk_dialog_add_button (dialog,
+                                               _("Select"),
+                                               GTK_RESPONSE_OK);
+  gtk_widget_grab_default (priv->select_button);
+
+  gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontseldiag),
+             GTK_RESPONSE_OK,
+             GTK_RESPONSE_APPLY, /* Deprecated */
+             GTK_RESPONSE_CANCEL,
+             -1);
+
+  gtk_window_set_title (GTK_WINDOW (fontseldiag),
+                        _("Font Selection"));
+
+  gtk_widget_pop_composite_child ();
+}
+
+/**
+ * gtk_font_selection_dialog_new:
+ * @title: (allow-none): the title of the dialog window 
+ *
+ * Creates a new #GtkFontSelectionDialog.
+ *
+ * Return value: a new #GtkFontSelectionDialog
+ */
+GtkWidget*
+gtk_font_selection_dialog_new (const gchar *title)
+{
+  GtkFontSelectionDialog *fontseldiag;
+  
+  fontseldiag = g_object_new (GTK_TYPE_FONT_SELECTION_DIALOG, NULL);
+
+  if (title)
+    gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
+  
+  return GTK_WIDGET (fontseldiag);
+}
+
+/**
+ * gtk_font_selection_dialog_get_font_selection:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Retrieves the #GtkFontSelection widget embedded in the dialog.
+ *
+ * Returns: (transfer none): the embedded #GtkFontSelection
+ *
+ * Since: 2.22
+ **/
+GtkWidget*
+gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return fsd->priv->fontsel;
+}
+
+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)
+{
+  GtkFontSelectionDialogPrivate *priv;
+
+  priv = GTK_FONT_SELECTION_DIALOG (buildable)->priv;
+
+  if (g_strcmp0 (childname, "select_button") == 0)
+    return G_OBJECT (priv->select_button);
+  else if (g_strcmp0 (childname, "cancel_button") == 0)
+    return G_OBJECT (priv->cancel_button);
+  else if (g_strcmp0 (childname, "font_selection") == 0)
+    return G_OBJECT (priv->fontsel);
+
+  /* Deprecated */
+  else if (g_strcmp0 (childname, "ok_button") == 0)
+    return G_OBJECT (priv->select_button);
+  else if (g_strcmp0 (childname, "apply_button") == 0)
+    return G_OBJECT (priv->apply_button);
+
+  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)
+{
+  GtkFontSelectionDialogPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  priv = fsd->priv;
+
+  return gtk_font_selection_get_font_name (GTK_FONT_SELECTION (priv->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)
+{
+  GtkFontSelectionDialogPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
+  g_return_val_if_fail (fontname, FALSE);
+
+  priv = fsd->priv;
+
+  return gtk_font_selection_set_font_name (GTK_FONT_SELECTION (priv->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)
+{
+  GtkFontSelectionDialogPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  priv = fsd->priv;
+
+  return gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (priv->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)
+{
+  GtkFontSelectionDialogPrivate *priv;
+
+  g_return_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd));
+  g_return_if_fail (text != NULL);
+
+  priv = fsd->priv;
+
+  gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (priv->fontsel), text);
+}
+
+/**
+ * gtk_font_selection_dialog_get_ok_button:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Gets the 'OK' button.
+ *
+ * Return value: (transfer none): the #GtkWidget used in the dialog
+ *     for the 'OK' button.
+ *
+ * Deprecated: 3.2
+ */
+GtkWidget *
+gtk_font_selection_dialog_get_ok_button (GtkFontSelectionDialog *fsd)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return fsd->priv->select_button;
+}
+
+/**
+ * gtk_font_selection_dialog_get_cancel_button:
+ * @fsd: a #GtkFontSelectionDialog
+ *
+ * Gets the 'Cancel' button.
+ *
+ * Return value: (transfer none): the #GtkWidget used in the dialog
+ *     for the 'Cancel' button.
+ *
+ * Deprecated: 3.2
+ */
+GtkWidget *
+gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd)
+{
+  g_return_val_if_fail (GTK_IS_FONT_SELECTION_DIALOG (fsd), NULL);
+
+  return fsd->priv->cancel_button;
+}
diff --git a/gtk/gtkfontselectiondialog.h b/gtk/gtkfontselectiondialog.h
new file mode 100644
index 0000000..a1e5178
--- /dev/null
+++ b/gtk/gtkfontselectiondialog.h
@@ -0,0 +1,120 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2011      Alberto Ruiz <aruiz gnome org>
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * GtkFontSelection widget for Gtk+, by Damon Chaplin, May 1998.
+ * Based on the GnomeFontSelector widget, by Elliot Lee, but major changes.
+ * The GnomeFontSelector was derived from app/text_tool.c in the GIMP.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+ */
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#ifndef __GTK_FONTSELECTIONDIALOG_H__
+#define __GTK_FONTSELECTIONDIALOG_H__
+
+
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkvbox.h>
+
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_FONT_SELECTION_DIALOG              (gtk_font_selection_dialog_get_type ())
+#define GTK_FONT_SELECTION_DIALOG(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialog))
+#define GTK_FONT_SELECTION_DIALOG_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialogClass))
+#define GTK_IS_FONT_SELECTION_DIALOG(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_SELECTION_DIALOG))
+#define GTK_IS_FONT_SELECTION_DIALOG_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_SELECTION_DIALOG))
+#define GTK_FONT_SELECTION_DIALOG_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FONT_SELECTION_DIALOG, GtkFontSelectionDialogClass))
+
+
+typedef struct _GtkFontSelectionDialog              GtkFontSelectionDialog;
+typedef struct _GtkFontSelectionDialogPrivate       GtkFontSelectionDialogPrivate;
+typedef struct _GtkFontSelectionDialogClass         GtkFontSelectionDialogClass;
+
+struct _GtkFontSelectionDialog
+{
+  GtkDialog parent_instance;
+
+  /*< private >*/
+  GtkFontSelectionDialogPrivate *priv;
+};
+
+struct _GtkFontSelectionDialogClass
+{
+  GtkDialogClass parent_class;
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+/*****************************************************************************
+ * GtkFontSelectionDialog functions.
+ *   most of these functions simply call the corresponding function in the
+ *   GtkFontSelection.
+ *****************************************************************************/
+
+GType	   gtk_font_selection_dialog_get_type           (void) G_GNUC_CONST;
+GtkWidget* gtk_font_selection_dialog_new	            (const gchar            *title);
+
+GtkWidget* gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd);
+
+/* This returns the X Logical Font Description fontname, or NULL if no font
+   is selected. Note that there is a slight possibility that the font might not
+   have been loaded OK. You should call gtk_font_selection_dialog_get_font()
+   to see if it has been loaded OK.
+   You should g_free() the returned font name after you're done with it. */
+gchar*     gtk_font_selection_dialog_get_font_name     (GtkFontSelectionDialog *fsd);
+
+/* This sets the currently displayed font. It should be a valid X Logical
+   Font Description font name (anything else will be ignored), e.g.
+   "-adobe-courier-bold-o-normal--25-*-*-*-*-*-*-*" 
+   It returns TRUE on success. */
+gboolean   gtk_font_selection_dialog_set_font_name     (GtkFontSelectionDialog *fsd,
+                                                        const gchar	           *fontname);
+
+/* This returns the text in the preview entry. You should copy the returned
+   text if you need it. */
+G_CONST_RETURN gchar* 
+          gtk_font_selection_dialog_get_preview_text   (GtkFontSelectionDialog *fsd);
+
+/* This sets the text in the preview entry. It will be copied by the entry,
+   so there's no need to g_strdup() it first. */
+void	  gtk_font_selection_dialog_set_preview_text   (GtkFontSelectionDialog *fsd,
+                                                        const gchar	           *text);
+
+/* Deprecated GtkFontSelectionDialog methods */
+#ifndef GTK_DISABLE_DEPRECATED
+GtkWidget* gtk_font_selection_dialog_get_cancel_button  (GtkFontSelectionDialog *fsd);
+GtkWidget* gtk_font_selection_dialog_get_ok_button      (GtkFontSelectionDialog *fsd);
+#endif
+
+G_END_DECLS
+
+#endif /* __GTK_FONTSELECTIONDIALOG_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]