diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 119ef4f8a3..2ddfab1e38 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -219,6 +219,7 @@ gtk_public_h_sources = \ gtkfontbutton.h \ gtkfontsel.h \ gtkfontchooser.h \ + gtkfontchooserdialog.h \ gtkframe.h \ gtkgradient.h \ gtkgrid.h \ @@ -550,6 +551,7 @@ gtk_base_c_sources = \ gtkfontbutton.c \ gtkfontsel.c \ gtkfontchooser.c \ + gtkfontchooserdialog.c \ gtkframe.c \ gtkgradient.c \ gtkgrid.c \ diff --git a/gtk/gtk.h b/gtk/gtk.h index 97317fdccc..7e2526e5b0 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -102,6 +102,7 @@ #include #include #include +#include #include #include #include diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c index 9fc5aad3eb..f79b314df1 100644 --- a/gtk/gtkfontchooser.c +++ b/gtk/gtkfontchooser.c @@ -33,7 +33,6 @@ #include #include "gtkfontchooser.h" -#include "gtkbutton.h" #include "gtkcellrenderertext.h" #include "gtkentry.h" #include "gtkframe.h" @@ -41,9 +40,7 @@ #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" @@ -100,16 +97,6 @@ struct _GtkFontChooserPrivate PangoFontFamily *family; }; - -struct _GtkFontChooserDialogPrivate -{ - GtkWidget *fontchooser; - - GtkWidget *select_button; - GtkWidget *cancel_button; -}; - - #define DEFAULT_FONT_NAME "Sans 10" #define MAX_FONT_SIZE 999 @@ -645,7 +632,7 @@ gtk_font_chooser_init (GtkFontChooser *fontchooser) g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))), "value-changed", G_CALLBACK (spin_change_cb), fontchooser); priv->ignore_slider = FALSE; - + /* Font selection callback */ g_signal_connect (G_OBJECT (priv->family_face_list), "cursor-changed", G_CALLBACK (cursor_changed_cb), fontchooser); @@ -674,9 +661,9 @@ GtkWidget * gtk_font_chooser_new (void) { GtkFontChooser *fontchooser; - + fontchooser = g_object_new (GTK_TYPE_FONT_CHOOSER, NULL); - + return GTK_WIDGET (fontchooser); } @@ -1250,259 +1237,3 @@ gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, fontchooser->priv->show_preview_entry = show_preview_entry; g_object_notify (G_OBJECT (fontchooser), "show-preview-entry"); } - - -/** - * SECTION:gtkfontchooserdlg - * @Short_description: A dialog box for selecting fonts - * @Title: GtkFontChooserDialog - * @See_also: #GtkFontChooser, #GtkDialog - * - * The #GtkFontChooserDialog widget is a dialog box for selecting a font. - * - * To set the font which is initially selected, use - * gtk_font_chooser_dialog_set_font_name(). - * - * To get the selected font use gtk_font_chooser_dialog_get_font_name(). - * - * To change the text which is shown in the preview area, use - * gtk_font_chooser_dialog_set_preview_text(). - * - * - * GtkFontChooserDialog as GtkBuildable - * The GtkFontChooserDialog implementation of the GtkBuildable interface - * exposes the embedded #GtkFontChooser as internal child with the - * name "font_chooser". 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. - * - */ - -static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface); -static GObject * gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable, - GtkBuilder *builder, - const gchar *childname); - -G_DEFINE_TYPE_WITH_CODE (GtkFontChooserDialog, gtk_font_chooser_dialog, - GTK_TYPE_DIALOG, - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, - gtk_font_chooser_dialog_buildable_interface_init)) - -static GtkBuildableIface *parent_buildable_iface; - -static void -gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass) -{ - g_type_class_add_private (klass, sizeof (GtkFontChooserDialogPrivate)); -} - -static void -gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag) -{ - GtkFontChooserDialogPrivate *priv; - GtkDialog *dialog = GTK_DIALOG (fontchooserdiag); - GtkWidget *action_area, *content_area; - - fontchooserdiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooserdiag, - GTK_TYPE_FONT_CHOOSER_DIALOG, - GtkFontChooserDialogPrivate); - priv = fontchooserdiag->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 (fontchooserdiag), TRUE); - - /* Create the content area */ - priv->fontchooser = gtk_font_chooser_new (); - gtk_container_set_border_width (GTK_CONTAINER (priv->fontchooser), 5); - gtk_widget_show (priv->fontchooser); - gtk_box_pack_start (GTK_BOX (content_area), - priv->fontchooser, TRUE, TRUE, 0); - - /* Create the action area */ - priv->cancel_button = gtk_dialog_add_button (dialog, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL); - 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 (fontchooserdiag), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); - - gtk_window_set_title (GTK_WINDOW (fontchooserdiag), - _("Font Selection")); - - gtk_widget_pop_composite_child (); -} - -/** - * gtk_font_chooser_dialog_new: - * @title: (allow-none): the title of the dialog window - * - * Creates a new #GtkFontChooserDialog. - * - * Return value: a new #GtkFontChooserDialog - */ -GtkWidget* -gtk_font_chooser_dialog_new (const gchar *title) -{ - GtkFontChooserDialog *fontchooserdiag; - - fontchooserdiag = g_object_new (GTK_TYPE_FONT_CHOOSER_DIALOG, NULL); - - if (title) - gtk_window_set_title (GTK_WINDOW (fontchooserdiag), title); - - return GTK_WIDGET (fontchooserdiag); -} - -/** - * gtk_font_chooser_dialog_get_font_chooser: - * @fcd: a #GtkFontChooserDialog - * - * Retrieves the #GtkFontChooser widget embedded in the dialog. - * - * Returns: (transfer none): the embedded #GtkFontChooser - * - * Since: 2.22 - **/ -GtkWidget* -gtk_font_chooser_dialog_get_font_chooser (GtkFontChooserDialog *fcd) -{ - g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL); - - return fcd->priv->fontchooser; -} - -static void -gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface) -{ - parent_buildable_iface = g_type_interface_peek_parent (iface); - iface->get_internal_child = gtk_font_chooser_dialog_buildable_get_internal_child; -} - -static GObject * -gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable, - GtkBuilder *builder, - const gchar *childname) -{ - GtkFontChooserDialogPrivate *priv; - - priv = GTK_FONT_CHOOSER_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_chooser") == 0) - return G_OBJECT (priv->fontchooser); - - return parent_buildable_iface->get_internal_child (buildable, builder, childname); -} - -/** - * gtk_font_chooser_dialog_get_font_name: - * @fcd: a #GtkFontChooserDialog - * - * Gets the currently-selected font name. - * - * Note that this can be a different string than what you set with - * gtk_font_chooser_dialog_set_font_name(), as the font chooser 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_chooser_dialog_get_font_name (GtkFontChooserDialog *fcd) -{ - GtkFontChooserDialogPrivate *priv; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL); - - priv = fcd->priv; - - return gtk_font_chooser_get_font_name (GTK_FONT_CHOOSER (priv->fontchooser)); -} - -/** - * gtk_font_chooser_dialog_set_font_name: - * @fcd: a #GtkFontChooserDialog - * @fontname: a font name like "Helvetica 12" or "Times Bold 18" - * - * Sets the currently selected font. - * - * Return value: %TRUE if the font selected in @fcd is now the - * @fontname specified, %FALSE otherwise. - */ -gboolean -gtk_font_chooser_dialog_set_font_name (GtkFontChooserDialog *fcd, - const gchar *fontname) -{ - GtkFontChooserDialogPrivate *priv; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), FALSE); - g_return_val_if_fail (fontname, FALSE); - - priv = fcd->priv; - - return gtk_font_chooser_set_font_name (GTK_FONT_CHOOSER (priv->fontchooser), fontname); -} - -/** - * gtk_font_chooser_dialog_get_preview_text: - * @fcd: a #GtkFontChooserDialog - * - * 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_chooser_dialog_get_preview_text (GtkFontChooserDialog *fcd) -{ - GtkFontChooserDialogPrivate *priv; - - g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL); - - priv = fcd->priv; - - return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (priv->fontchooser)); -} - -/** - * gtk_font_chooser_dialog_set_preview_text: - * @fcd: a #GtkFontChooserDialog - * @text: the text to display in the preview area - * - * Sets the text displayed in the preview area. - */ -void -gtk_font_chooser_dialog_set_preview_text (GtkFontChooserDialog *fcd, - const gchar *text) -{ - GtkFontChooserDialogPrivate *priv; - - g_return_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd)); - g_return_if_fail (text != NULL); - - priv = fcd->priv; - - gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (priv->fontchooser), text); -} diff --git a/gtk/gtkfontchooser.h b/gtk/gtkfontchooser.h index 718f822b8a..5634afc962 100644 --- a/gtk/gtkfontchooser.h +++ b/gtk/gtkfontchooser.h @@ -29,11 +29,8 @@ #ifndef __GTK_FONT_CHOOSER_H__ #define __GTK_FONT_CHOOSER_H__ - -#include #include - G_BEGIN_DECLS #define GTK_TYPE_FONT_CHOOSER (gtk_font_chooser_get_type ()) @@ -43,23 +40,10 @@ G_BEGIN_DECLS #define GTK_IS_FONT_CHOOSER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_CHOOSER)) #define GTK_FONT_CHOOSER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FONT_CHOOSER, GtkFontChooserClass)) - -#define GTK_TYPE_FONT_CHOOSER_DIALOG (gtk_font_chooser_dialog_get_type ()) -#define GTK_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialog)) -#define GTK_FONT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialogClass)) -#define GTK_IS_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG)) -#define GTK_IS_FONT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_CHOOSER_DIALOG)) -#define GTK_FONT_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialogClass)) - - typedef struct _GtkFontChooser GtkFontChooser; typedef struct _GtkFontChooserPrivate GtkFontChooserPrivate; typedef struct _GtkFontChooserClass GtkFontChooserClass; -typedef struct _GtkFontChooserDialog GtkFontChooserDialog; -typedef struct _GtkFontChooserDialogPrivate GtkFontChooserDialogPrivate; -typedef struct _GtkFontChooserDialogClass GtkFontChooserDialogClass; - struct _GtkFontChooser { GtkVBox parent_instance; @@ -79,28 +63,6 @@ struct _GtkFontChooserClass void (*_gtk_reserved4) (void); }; - -struct _GtkFontChooserDialog -{ - GtkDialog parent_instance; - - /*< private >*/ - GtkFontChooserDialogPrivate *priv; -}; - -struct _GtkFontChooserDialogClass -{ - GtkDialogClass parent_class; - - /* Padding for future expansion */ - void (*_gtk_reserved1) (void); - void (*_gtk_reserved2) (void); - void (*_gtk_reserved3) (void); - void (*_gtk_reserved4) (void); -}; - - - /***************************************************************************** * GtkFontChooser functions. * see the comments in the GtkFontChooserDialog functions. @@ -123,42 +85,5 @@ void gtk_font_chooser_set_preview_text (GtkFontChooser *fontchoo gboolean gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser); void gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser, gboolean show_preview_entry); -/***************************************************************************** - * GtkFontChooserDialog functions. - * most of these functions simply call the corresponding function in the - * GtkFontChooser. - *****************************************************************************/ -GType gtk_font_chooser_dialog_get_type (void) G_GNUC_CONST; -GtkWidget* gtk_font_chooser_dialog_new (const gchar *title); - -GtkWidget* gtk_font_chooser_dialog_get_font_selection (GtkFontChooserDialog *fcd); - -/* 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_chooser_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_chooser_dialog_get_font_name (GtkFontChooserDialog *fcd); - -/* 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_chooser_dialog_set_font_name (GtkFontChooserDialog *fcd, - 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_chooser_dialog_get_preview_text (GtkFontChooserDialog *fcd); - -/* 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_chooser_dialog_set_preview_text (GtkFontChooserDialog *fcd, - const gchar *text); - -G_END_DECLS - - -#endif /* __GTK_FONTSEL_H__ */ +#endif /* __GTK_FONT_CHOOSER_H__ */ diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c new file mode 100644 index 0000000000..1df7fbbd6f --- /dev/null +++ b/gtk/gtkfontchooserdialog.c @@ -0,0 +1,312 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2011 Alberto Ruiz + * 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 + * GtkFontChooser 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. + */ + +#include "config.h" + +#include +#include +#include + +#include + +#include "gtkfontchooserdialog.h" +#include "gtkfontchooser.h" +#include "gtkstock.h" +#include "gtkintl.h" +#include "gtkaccessible.h" +#include "gtkbuildable.h" +#include "gtkprivate.h" +#include "gtkwidget.h" + +struct _GtkFontChooserDialogPrivate +{ + GtkWidget *fontchooser; + + GtkWidget *select_button; + GtkWidget *cancel_button; +}; + +/** + * SECTION:gtkfontchooserdlg + * @Short_description: A dialog box for selecting fonts + * @Title: GtkFontChooserDialog + * @See_also: #GtkFontChooser, #GtkDialog + * + * The #GtkFontChooserDialog widget is a dialog box for selecting a font. + * + * To set the font which is initially selected, use + * gtk_font_chooser_dialog_set_font_name(). + * + * To get the selected font use gtk_font_chooser_dialog_get_font_name(). + * + * To change the text which is shown in the preview area, use + * gtk_font_chooser_dialog_set_preview_text(). + * + * + * GtkFontChooserDialog as GtkBuildable + * The GtkFontChooserDialog implementation of the GtkBuildable interface + * exposes the embedded #GtkFontChooser as internal child with the + * name "font_chooser". It also exposes the buttons with the names + * "select_button" and "cancel_button. + * + */ + +static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface); +static GObject* gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable, + GtkBuilder *builder, + const gchar *childname); + +G_DEFINE_TYPE_WITH_CODE (GtkFontChooserDialog, gtk_font_chooser_dialog, + GTK_TYPE_DIALOG, + G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, + gtk_font_chooser_dialog_buildable_interface_init)) + +static GtkBuildableIface *parent_buildable_iface; + +static void +gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass) +{ + g_type_class_add_private (klass, sizeof (GtkFontChooserDialogPrivate)); +} + +static void +gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag) +{ + GtkFontChooserDialogPrivate *priv; + GtkDialog *dialog = GTK_DIALOG (fontchooserdiag); + GtkWidget *action_area, *content_area; + + fontchooserdiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooserdiag, + GTK_TYPE_FONT_CHOOSER_DIALOG, + GtkFontChooserDialogPrivate); + priv = fontchooserdiag->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 (fontchooserdiag), TRUE); + + /* Create the content area */ + priv->fontchooser = gtk_font_chooser_new (); + gtk_container_set_border_width (GTK_CONTAINER (priv->fontchooser), 5); + gtk_widget_show (priv->fontchooser); + gtk_box_pack_start (GTK_BOX (content_area), + priv->fontchooser, TRUE, TRUE, 0); + + /* Create the action area */ + priv->cancel_button = gtk_dialog_add_button (dialog, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL); + 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 (fontchooserdiag), + GTK_RESPONSE_OK, + GTK_RESPONSE_CANCEL, + -1); + + gtk_window_set_title (GTK_WINDOW (fontchooserdiag), + _("Font Selection")); + + gtk_widget_pop_composite_child (); +} + +/** + * gtk_font_chooser_dialog_new: + * @title: (allow-none): the title of the dialog window + * + * Creates a new #GtkFontChooserDialog. + * + * Return value: a new #GtkFontChooserDialog + */ +GtkWidget* +gtk_font_chooser_dialog_new (const gchar *title) +{ + GtkFontChooserDialog *fontchooserdiag; + + fontchooserdiag = g_object_new (GTK_TYPE_FONT_CHOOSER_DIALOG, NULL); + + if (title) + gtk_window_set_title (GTK_WINDOW (fontchooserdiag), title); + + return GTK_WIDGET (fontchooserdiag); +} + +/** + * gtk_font_chooser_dialog_get_font_chooser: + * @fcd: a #GtkFontChooserDialog + * + * Retrieves the #GtkFontChooser widget embedded in the dialog. + * + * Returns: (transfer none): the embedded #GtkFontChooser + * + * Since: 3.2 + **/ +GtkWidget* +gtk_font_chooser_dialog_get_font_chooser (GtkFontChooserDialog *fcd) +{ + g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL); + + return fcd->priv->fontchooser; +} + +static void +gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface) +{ + parent_buildable_iface = g_type_interface_peek_parent (iface); + iface->get_internal_child = gtk_font_chooser_dialog_buildable_get_internal_child; +} + +static GObject * +gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable, + GtkBuilder *builder, + const gchar *childname) +{ + GtkFontChooserDialogPrivate *priv; + + priv = GTK_FONT_CHOOSER_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_chooser") == 0) + return G_OBJECT (priv->fontchooser); + + return parent_buildable_iface->get_internal_child (buildable, builder, childname); +} + +/** + * gtk_font_chooser_dialog_get_font_name: + * @fcd: a #GtkFontChooserDialog + * + * Gets the currently-selected font name. + * + * Note that this can be a different string than what you set with + * gtk_font_chooser_dialog_set_font_name(), as the font chooser 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(). + * + * Since: 3.2 + */ +gchar* +gtk_font_chooser_dialog_get_font_name (GtkFontChooserDialog *fcd) +{ + GtkFontChooserDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL); + + priv = fcd->priv; + + return gtk_font_chooser_get_font_name (GTK_FONT_CHOOSER (priv->fontchooser)); +} + +/** + * gtk_font_chooser_dialog_set_font_name: + * @fcd: a #GtkFontChooserDialog + * @fontname: a font name like "Helvetica 12" or "Times Bold 18" + * + * Sets the currently selected font. + * + * Return value: %TRUE if the font selected in @fcd is now the + * @fontname specified, %FALSE otherwise. + * + * Since: 3.2 + */ +gboolean +gtk_font_chooser_dialog_set_font_name (GtkFontChooserDialog *fcd, + const gchar *fontname) +{ + GtkFontChooserDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), FALSE); + g_return_val_if_fail (fontname, FALSE); + + priv = fcd->priv; + + return gtk_font_chooser_set_font_name (GTK_FONT_CHOOSER (priv->fontchooser), fontname); +} + +/** + * gtk_font_chooser_dialog_get_preview_text: + * @fcd: a #GtkFontChooserDialog + * + * 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 + * + * Since: 3.2 + */ +G_CONST_RETURN gchar* +gtk_font_chooser_dialog_get_preview_text (GtkFontChooserDialog *fcd) +{ + GtkFontChooserDialogPrivate *priv; + + g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL); + + priv = fcd->priv; + + return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (priv->fontchooser)); +} + +/** + * gtk_font_chooser_dialog_set_preview_text: + * @fcd: a #GtkFontChooserDialog + * @text: the text to display in the preview area + * + * Sets the text displayed in the preview area. + * + * Since: 3.2 + */ +void +gtk_font_chooser_dialog_set_preview_text (GtkFontChooserDialog *fcd, + const gchar *text) +{ + GtkFontChooserDialogPrivate *priv; + + g_return_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd)); + g_return_if_fail (text != NULL); + + priv = fcd->priv; + + gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (priv->fontchooser), text); +} diff --git a/gtk/gtkfontchooserdialog.h b/gtk/gtkfontchooserdialog.h new file mode 100644 index 0000000000..0e5f89c685 --- /dev/null +++ b/gtk/gtkfontchooserdialog.h @@ -0,0 +1,89 @@ +/* GTK - The GIMP Toolkit + * Copyright (C) 2011 Alberto Ruiz + * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald + * + * GtkFontChooser 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. + */ + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GTK_FONT_CHOOSER_DIALOG_H__ +#define __GTK_FONT_CHOOSER_DIALOG_H__ + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_FONT_CHOOSER_DIALOG (gtk_font_chooser_dialog_get_type ()) +#define GTK_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialog)) +#define GTK_FONT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialogClass)) +#define GTK_IS_FONT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG)) +#define GTK_IS_FONT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_FONT_CHOOSER_DIALOG)) +#define GTK_FONT_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_FONT_CHOOSER_DIALOG, GtkFontChooserDialogClass)) + +typedef struct _GtkFontChooserDialog GtkFontChooserDialog; +typedef struct _GtkFontChooserDialogPrivate GtkFontChooserDialogPrivate; +typedef struct _GtkFontChooserDialogClass GtkFontChooserDialogClass; + +struct _GtkFontChooserDialog +{ + GtkDialog parent_instance; + + /*< private >*/ + GtkFontChooserDialogPrivate *priv; +}; + +struct _GtkFontChooserDialogClass +{ + GtkDialogClass parent_class; + + /* Padding for future expansion */ + void (*_gtk_reserved1) (void); + void (*_gtk_reserved2) (void); + void (*_gtk_reserved3) (void); + void (*_gtk_reserved4) (void); +}; + +/***************************************************************************** + * GtkFontChooserDialog functions. + * most of these functions simply call the corresponding function in the + * GtkFontChooser. + *****************************************************************************/ + +GType gtk_font_chooser_dialog_get_type (void) G_GNUC_CONST; +GtkWidget* gtk_font_chooser_dialog_new (const gchar *title); + +GtkWidget* gtk_font_chooser_dialog_get_font_selection (GtkFontChooserDialog *fcd); + +gchar* gtk_font_chooser_dialog_get_font_name (GtkFontChooserDialog *fcd); + +gboolean gtk_font_chooser_dialog_set_font_name (GtkFontChooserDialog *fcd, + const gchar *fontname); +G_CONST_RETURN gchar* + gtk_font_chooser_dialog_get_preview_text (GtkFontChooserDialog *fcd); + +void gtk_font_chooser_dialog_set_preview_text (GtkFontChooserDialog *fcd, + const gchar *text); + +G_END_DECLS + +#endif /* __GTK_FONT_CHOOSER_DIALOG_H__ */