2011-04-15 20:07:32 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2011-05-03 23:14:31 +00:00
|
|
|
* Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
|
2011-04-15 20:07:32 +00:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
2011-05-03 23:14:31 +00:00
|
|
|
* Massively updated to rework the user interface by Alberto Ruiz, 2011
|
2011-04-15 20:07:32 +00:00
|
|
|
* Massively updated for Pango by Owen Taylor, May 2000
|
2011-05-11 13:21:55 +00:00
|
|
|
* GtkFontChooser widget for Gtk+, by Damon Chaplin, May 1998.
|
2011-04-15 20:07:32 +00:00
|
|
|
* 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 <stdlib.h>
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <atk/atk.h>
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
#include "gtkfontchooser.h"
|
2011-04-15 20:07:32 +00:00
|
|
|
#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"
|
2011-04-15 21:32:20 +00:00
|
|
|
#include "gtkalignment.h"
|
|
|
|
#include "gtkscale.h"
|
2011-04-15 22:22:38 +00:00
|
|
|
#include "gtkbox.h"
|
2011-04-16 11:10:29 +00:00
|
|
|
#include "gtkspinbutton.h"
|
2011-04-16 21:36:25 +00:00
|
|
|
#include "gtkwidget.h"
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* SECTION:gtkfontchooser
|
2011-04-15 20:07:32 +00:00
|
|
|
* @Short_description: A widget for selecting fonts
|
2011-05-11 13:21:55 +00:00
|
|
|
* @Title: GtkFontChooser
|
|
|
|
* @See_also: #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* The #GtkFontChooser widget lists the available fonts, styles and sizes,
|
2011-04-15 20:07:32 +00:00
|
|
|
* allowing the user to select a font.
|
2011-05-11 13:21:55 +00:00
|
|
|
* It is used in the #GtkFontChooserDialog widget to provide a dialog box for
|
2011-04-15 20:07:32 +00:00
|
|
|
* selecting fonts.
|
|
|
|
*
|
|
|
|
* To set the font which is initially selected, use
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_set_font_name().
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* To get the selected font use gtk_font_chooser_get_font_name().
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* To change the text which is shown in the preview area, use
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_set_preview_text().
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
struct _GtkFontChooserPrivate
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-04 19:29:26 +00:00
|
|
|
GtkWidget *search_entry;
|
|
|
|
GtkWidget *family_face_list;
|
2011-04-16 13:27:31 +00:00
|
|
|
GtkListStore *model;
|
|
|
|
GtkTreeModel *filter;
|
|
|
|
|
2011-05-04 19:29:26 +00:00
|
|
|
GtkWidget *preview;
|
|
|
|
GtkWidget *preview_scrolled_window;
|
|
|
|
gchar *preview_text;
|
|
|
|
gboolean show_preview_entry;
|
|
|
|
|
|
|
|
GtkWidget *size_spin;
|
|
|
|
GtkWidget *size_slider;
|
|
|
|
gboolean ignore_slider;
|
|
|
|
|
2011-04-15 20:23:37 +00:00
|
|
|
gint size;
|
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontFamily *family;
|
2011-04-15 20:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
struct _GtkFontChooserDialogPrivate
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkWidget *fontchooser;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-03 23:14:31 +00:00
|
|
|
GtkWidget *select_button;
|
2011-04-15 20:07:32 +00:00
|
|
|
GtkWidget *cancel_button;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define DEFAULT_FONT_NAME "Sans 10"
|
2011-04-16 15:40:47 +00:00
|
|
|
#define MAX_FONT_SIZE 999
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-04-15 22:10:25 +00:00
|
|
|
/* This is the initial fixed height and the top padding of the preview entry */
|
2011-04-26 23:15:03 +00:00
|
|
|
#define PREVIEW_HEIGHT 72
|
2011-04-15 22:10:25 +00:00
|
|
|
#define PREVIEW_TOP_PADDING 6
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-04-26 23:15:03 +00:00
|
|
|
/* Widget default geometry */
|
2011-05-11 13:21:55 +00:00
|
|
|
#define FONT_CHOOSER_WIDTH 540
|
|
|
|
#define FONT_CHOOSER_HEIGHT 408
|
2011-04-26 23:15:03 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
/* These are the sizes of the font, style & size lists. */
|
2011-04-27 23:39:15 +00:00
|
|
|
#define FONT_LIST_HEIGHT 136
|
|
|
|
#define FONT_LIST_WIDTH 190
|
|
|
|
#define FONT_STYLE_LIST_WIDTH 170
|
|
|
|
#define FONT_SIZE_LIST_WIDTH 60
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-04-18 21:38:11 +00:00
|
|
|
#define ROW_FORMAT_STRING "<span weight=\"bold\" size=\"small\" foreground=\"%s\">%s</span>\n<span size=\"x-large\" font_desc=\"%s\">%s</span>"
|
2011-04-16 01:31:31 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
/* These are what we use as the standard font sizes, for the size list.
|
|
|
|
*/
|
2011-04-17 01:26:16 +00:00
|
|
|
#define FONT_SIZES_LENGTH 14
|
2011-04-17 01:00:32 +00:00
|
|
|
static const gint font_sizes[] = {
|
2011-04-17 01:26:16 +00:00
|
|
|
6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
|
2011-04-15 20:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_FONT_NAME,
|
2011-05-04 19:29:26 +00:00
|
|
|
PROP_PREVIEW_TEXT,
|
|
|
|
PROP_SHOW_PREVIEW_ENTRY
|
2011-04-15 20:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
FAMILY_COLUMN,
|
|
|
|
FACE_COLUMN,
|
2011-04-18 21:20:15 +00:00
|
|
|
PREVIEW_TEXT_COLUMN,
|
2011-04-28 00:57:02 +00:00
|
|
|
PREVIEW_TITLE_COLUMN
|
2011-04-15 20:07:32 +00:00
|
|
|
};
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
static void gtk_font_chooser_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_font_chooser_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_font_chooser_finalize (GObject *object);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
static void gtk_font_chooser_screen_changed (GtkWidget *widget,
|
|
|
|
GdkScreen *previous_screen);
|
|
|
|
static void gtk_font_chooser_style_updated (GtkWidget *widget);
|
2011-04-17 02:11:11 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
static void gtk_font_chooser_ref_family (GtkFontChooser *fontchooser,
|
|
|
|
PangoFontFamily *family);
|
|
|
|
static void gtk_font_chooser_ref_face (GtkFontChooser *fontchooser,
|
|
|
|
PangoFontFace *face);
|
2011-04-17 02:11:11 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
static void gtk_font_chooser_bootstrap_fontlist (GtkFontChooser *fontchooser);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
G_DEFINE_TYPE (GtkFontChooser, gtk_font_chooser, GTK_TYPE_VBOX)
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_class_init (GtkFontChooserClass *klass)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2011-04-30 09:54:50 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2011-05-04 22:07:16 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
widget_class->screen_changed = gtk_font_chooser_screen_changed;
|
|
|
|
widget_class->style_updated = gtk_font_chooser_style_updated;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gobject_class->finalize = gtk_font_chooser_finalize;
|
|
|
|
gobject_class->set_property = gtk_font_chooser_set_property;
|
|
|
|
gobject_class->get_property = gtk_font_chooser_get_property;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
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"),
|
|
|
|
DEFAULT_FONT_NAME,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_PREVIEW_TEXT,
|
|
|
|
g_param_spec_string ("preview-text",
|
|
|
|
P_("Preview text"),
|
|
|
|
P_("The text to display in order to demonstrate the selected font"),
|
2011-04-18 21:20:15 +00:00
|
|
|
pango_language_get_sample_string (NULL),
|
2011-04-15 20:07:32 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2011-05-04 19:29:26 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_SHOW_PREVIEW_ENTRY,
|
|
|
|
g_param_spec_boolean ("show-preview-entry",
|
|
|
|
P_("Show preview text entry"),
|
|
|
|
P_("Whether the preview text entry is shown or not"),
|
|
|
|
TRUE,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GtkFontChooserPrivate));
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_property (GObject *object,
|
2011-04-27 23:39:15 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser = GTK_FONT_CHOOSER (object);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FONT_NAME:
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_font_name (fontchooser, g_value_get_string (value));
|
2011-04-15 20:07:32 +00:00
|
|
|
break;
|
|
|
|
case PROP_PREVIEW_TEXT:
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_preview_text (fontchooser, g_value_get_string (value));
|
2011-04-15 20:07:32 +00:00
|
|
|
break;
|
2011-05-04 19:29:26 +00:00
|
|
|
case PROP_SHOW_PREVIEW_ENTRY:
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_show_preview_entry (fontchooser, g_value_get_boolean (value));
|
2011-04-15 20:07:32 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_property (GObject *object,
|
2011-04-27 23:39:15 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser = GTK_FONT_CHOOSER (object);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_FONT_NAME:
|
2011-05-11 13:21:55 +00:00
|
|
|
g_value_take_string (value, gtk_font_chooser_get_font_name (fontchooser));
|
2011-04-15 20:07:32 +00:00
|
|
|
break;
|
|
|
|
case PROP_PREVIEW_TEXT:
|
2011-05-11 13:21:55 +00:00
|
|
|
g_value_set_string (value, gtk_font_chooser_get_preview_text (fontchooser));
|
2011-04-15 20:07:32 +00:00
|
|
|
break;
|
2011-05-04 19:29:26 +00:00
|
|
|
case PROP_SHOW_PREVIEW_ENTRY:
|
2011-05-11 13:21:55 +00:00
|
|
|
g_value_set_boolean (value, gtk_font_chooser_get_show_preview_entry (fontchooser));
|
2011-04-15 20:07:32 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
void
|
2011-05-11 13:21:55 +00:00
|
|
|
refilter_and_focus (GtkFontChooserPrivate *priv)
|
2011-04-18 21:20:15 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeView *treeview = GTK_TREE_VIEW (priv->family_face_list);
|
|
|
|
GtkTreePath *path = gtk_tree_path_new ();
|
|
|
|
|
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_view_get_cursor (treeview, &path, NULL);
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->filter), &iter, path))
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-11 14:36:28 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
|
2011-04-18 21:20:15 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2011-04-16 13:59:43 +00:00
|
|
|
void
|
|
|
|
deleted_text_cb (GtkEntryBuffer *buffer,
|
|
|
|
guint position,
|
|
|
|
guint n_chars,
|
|
|
|
gpointer user_data)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*)user_data;
|
|
|
|
GtkWidget *entry = priv->search_entry;
|
2011-04-16 14:17:53 +00:00
|
|
|
|
2011-04-16 15:40:47 +00:00
|
|
|
if (gtk_entry_buffer_get_length (buffer) == 0)
|
|
|
|
{
|
|
|
|
gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
GTK_STOCK_FIND);
|
|
|
|
}
|
|
|
|
|
2011-04-16 14:17:53 +00:00
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
|
2011-04-16 13:59:43 +00:00
|
|
|
}
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-04-16 13:59:43 +00:00
|
|
|
void
|
|
|
|
inserted_text_cb (GtkEntryBuffer *buffer,
|
|
|
|
guint position,
|
|
|
|
gchar *chars,
|
|
|
|
guint n_chars,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*)user_data;
|
|
|
|
GtkWidget *entry = priv->search_entry;
|
2011-04-16 15:40:47 +00:00
|
|
|
|
|
|
|
if (g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY),
|
|
|
|
GTK_STOCK_CLEAR))
|
|
|
|
gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
GTK_STOCK_CLEAR);
|
|
|
|
|
|
|
|
|
2011-04-16 14:17:53 +00:00
|
|
|
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
2011-04-16 16:01:53 +00:00
|
|
|
void
|
|
|
|
icon_press_cb (GtkEntry *entry,
|
|
|
|
GtkEntryIconPosition pos,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gtk_entry_buffer_delete_text (gtk_entry_get_buffer (entry), 0, -1);
|
|
|
|
}
|
|
|
|
|
2011-04-16 14:56:56 +00:00
|
|
|
void
|
|
|
|
slider_change_cb (GtkAdjustment *adjustment, gpointer data)
|
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*)data;
|
2011-04-16 15:40:47 +00:00
|
|
|
|
2011-04-16 16:21:07 +00:00
|
|
|
/* If we set the silder value manually, we ignore this callback */
|
|
|
|
if (priv->ignore_slider)
|
|
|
|
{
|
|
|
|
priv->ignore_slider = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-16 15:40:47 +00:00
|
|
|
gtk_adjustment_set_value (gtk_spin_button_get_adjustment( GTK_SPIN_BUTTON(priv->size_spin)),
|
|
|
|
gtk_adjustment_get_value (adjustment));
|
2011-04-16 14:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spin_change_cb (GtkAdjustment *adjustment, gpointer data)
|
|
|
|
{
|
2011-05-01 02:33:47 +00:00
|
|
|
PangoFontDescription *desc;
|
2011-05-11 13:59:23 +00:00
|
|
|
GtkFontChooser *fontchooser = (GtkFontChooser*)data;
|
|
|
|
GtkFontChooserPrivate *priv = fontchooser->priv;
|
2011-04-16 16:12:18 +00:00
|
|
|
|
|
|
|
gdouble size = gtk_adjustment_get_value (adjustment);
|
2011-04-16 16:01:53 +00:00
|
|
|
|
2011-04-16 16:12:18 +00:00
|
|
|
GtkAdjustment *slider_adj = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
|
|
|
|
|
2011-04-16 16:21:07 +00:00
|
|
|
/* We ignore the slider value change callback for both of this set_value call */
|
2011-04-17 03:10:37 +00:00
|
|
|
priv->ignore_slider = TRUE;
|
2011-04-16 16:21:07 +00:00
|
|
|
if (size < gtk_adjustment_get_lower (slider_adj))
|
2011-04-17 03:10:37 +00:00
|
|
|
gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
|
2011-04-16 16:21:07 +00:00
|
|
|
else if (size > gtk_adjustment_get_upper (slider_adj))
|
2011-04-17 03:10:37 +00:00
|
|
|
gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
|
|
|
|
else
|
|
|
|
gtk_adjustment_set_value (slider_adj, size);
|
2011-04-16 16:12:18 +00:00
|
|
|
|
2011-04-16 16:01:53 +00:00
|
|
|
priv->size = ((gint)gtk_adjustment_get_value (adjustment)) * PANGO_SCALE;
|
2011-04-16 17:02:52 +00:00
|
|
|
|
|
|
|
desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview));
|
|
|
|
pango_font_description_set_size (desc, priv->size);
|
2011-04-16 22:57:04 +00:00
|
|
|
gtk_widget_override_font (priv->preview, desc);
|
2011-05-08 14:45:20 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font-name");
|
2011-05-01 11:12:13 +00:00
|
|
|
|
2011-04-16 17:02:52 +00:00
|
|
|
gtk_widget_queue_draw (priv->preview);
|
2011-04-16 14:56:56 +00:00
|
|
|
}
|
|
|
|
|
2011-04-16 22:57:04 +00:00
|
|
|
void
|
2011-05-11 13:21:55 +00:00
|
|
|
set_range_marks (GtkFontChooserPrivate *priv,
|
2011-04-18 21:20:15 +00:00
|
|
|
GtkWidget* size_slider,
|
|
|
|
gint* sizes,
|
|
|
|
gint length)
|
2011-04-16 22:57:04 +00:00
|
|
|
{
|
2011-04-18 21:20:15 +00:00
|
|
|
GtkAdjustment *adj;
|
2011-04-16 22:57:04 +00:00
|
|
|
gint i;
|
2011-04-18 21:20:15 +00:00
|
|
|
gdouble value;
|
2011-05-11 13:21:55 +00:00
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
if (length<2)
|
|
|
|
{
|
|
|
|
sizes = (gint*)font_sizes;
|
|
|
|
length = FONT_SIZES_LENGTH;
|
|
|
|
}
|
2011-04-16 22:57:04 +00:00
|
|
|
|
|
|
|
gtk_scale_clear_marks (GTK_SCALE (size_slider));
|
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
adj = gtk_range_get_adjustment(GTK_RANGE (size_slider));
|
|
|
|
|
|
|
|
gtk_adjustment_set_lower (adj, (gdouble) sizes[0]);
|
|
|
|
gtk_adjustment_set_upper (adj, (gdouble) sizes[length-1]);
|
|
|
|
|
|
|
|
value = gtk_adjustment_get_value (adj);
|
|
|
|
if (value > (gdouble) sizes[length-1])
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (adj, (gdouble) sizes[length-1]);
|
|
|
|
priv->ignore_slider = TRUE;
|
|
|
|
}
|
|
|
|
else if (value < (gdouble) sizes[0])
|
|
|
|
{
|
|
|
|
gtk_adjustment_set_value (adj, (gdouble) sizes[0]);
|
|
|
|
priv->ignore_slider = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
for (i=0; i<length; i++)
|
|
|
|
gtk_scale_add_mark (GTK_SCALE (size_slider),
|
|
|
|
(gdouble) sizes[i],
|
|
|
|
GTK_POS_BOTTOM, NULL);
|
2011-04-16 22:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cursor_changed_cb (GtkTreeView *treeview, gpointer data)
|
|
|
|
{
|
2011-04-17 01:11:53 +00:00
|
|
|
PangoFontFamily *family;
|
2011-04-16 22:57:04 +00:00
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontDescription *desc;
|
2011-04-17 01:00:32 +00:00
|
|
|
|
|
|
|
gint *sizes;
|
2011-04-18 21:20:15 +00:00
|
|
|
gint i, n_sizes;
|
2011-04-16 22:57:04 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
GtkTreeIter iter;
|
2011-04-16 22:57:04 +00:00
|
|
|
GtkTreePath *path = gtk_tree_path_new ();
|
2011-04-17 01:11:53 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser = (GtkFontChooser*)data;
|
2011-04-16 22:57:04 +00:00
|
|
|
|
|
|
|
gtk_tree_view_get_cursor (treeview, &path, NULL);
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (fontchooser->priv->filter), &iter, path))
|
2011-04-18 21:20:15 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return;
|
|
|
|
}
|
2011-04-16 22:57:04 +00:00
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (fontchooser->priv->filter), &iter,
|
2011-04-16 22:57:04 +00:00
|
|
|
FACE_COLUMN, &face,
|
2011-04-17 01:11:53 +00:00
|
|
|
FAMILY_COLUMN, &family,
|
2011-04-16 22:57:04 +00:00
|
|
|
-1);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-05-11 14:36:28 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-04-17 01:11:53 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
path = NULL;
|
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
if (!face || !family)
|
2011-04-16 22:57:04 +00:00
|
|
|
{
|
2011-04-17 01:11:53 +00:00
|
|
|
g_object_unref (face);
|
|
|
|
g_object_unref (family);
|
2011-04-16 22:57:04 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
desc = pango_font_face_describe (face);
|
2011-05-11 13:21:55 +00:00
|
|
|
pango_font_description_set_size (desc, fontchooser->priv->size);
|
|
|
|
gtk_widget_override_font (fontchooser->priv->preview, desc);
|
2011-04-16 22:57:04 +00:00
|
|
|
|
2011-04-17 01:00:32 +00:00
|
|
|
pango_font_face_list_sizes (face, &sizes, &n_sizes);
|
|
|
|
/* It seems not many fonts actually have a sane set of sizes */
|
2011-04-18 21:20:15 +00:00
|
|
|
for (i=0; i<n_sizes; i++)
|
|
|
|
sizes[i] = sizes[i] / PANGO_SCALE;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
set_range_marks (fontchooser->priv, fontchooser->priv->size_slider, sizes, n_sizes);
|
2011-04-16 22:57:04 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_ref_family (fontchooser, family);
|
|
|
|
gtk_font_chooser_ref_face (fontchooser, face);
|
2011-04-17 01:11:53 +00:00
|
|
|
|
2011-04-16 22:57:04 +00:00
|
|
|
/* Free resources */
|
2011-05-01 00:06:06 +00:00
|
|
|
g_object_unref ((gpointer)family);
|
2011-04-16 22:57:04 +00:00
|
|
|
g_object_unref ((gpointer)face);
|
|
|
|
pango_font_description_free(desc);
|
2011-05-03 00:09:12 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font-name");
|
2011-04-16 22:57:04 +00:00
|
|
|
}
|
|
|
|
|
2011-04-17 03:10:37 +00:00
|
|
|
gboolean
|
|
|
|
zoom_preview_cb (GtkWidget *scrolled_window, GdkEventScroll *event, gpointer data)
|
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*)data;
|
2011-04-17 03:10:37 +00:00
|
|
|
|
|
|
|
GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
|
|
|
|
|
|
|
|
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT)
|
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) +
|
|
|
|
gtk_adjustment_get_step_increment (adj));
|
|
|
|
else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT)
|
|
|
|
gtk_adjustment_set_value (adj,
|
|
|
|
gtk_adjustment_get_value (adj) -
|
|
|
|
gtk_adjustment_get_step_increment (adj));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_init (GtkFontChooser *fontchooser)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:59:23 +00:00
|
|
|
GtkFontChooserPrivate *priv;
|
2011-04-16 12:36:45 +00:00
|
|
|
PangoFontDescription *font_desc;
|
2011-04-15 21:18:14 +00:00
|
|
|
GtkWidget *scrolled_win;
|
2011-04-15 21:26:45 +00:00
|
|
|
GtkWidget *preview_and_size;
|
|
|
|
GtkWidget *size_controls;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooser,
|
|
|
|
GTK_TYPE_FONT_CHOOSER,
|
|
|
|
GtkFontChooserPrivate);
|
2011-04-26 23:37:29 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
priv = fontchooser->priv;
|
2011-04-28 18:17:20 +00:00
|
|
|
|
2011-05-03 18:59:57 +00:00
|
|
|
/* Default preview string */
|
|
|
|
priv->preview_text = g_strdup (pango_language_get_sample_string (NULL));
|
2011-05-04 19:29:26 +00:00
|
|
|
priv->show_preview_entry = TRUE;
|
2011-05-03 18:59:57 +00:00
|
|
|
|
2011-04-30 09:54:50 +00:00
|
|
|
/* Getting the default size */
|
2011-05-11 13:21:55 +00:00
|
|
|
font_desc = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)));
|
2011-04-30 09:54:50 +00:00
|
|
|
priv->size = pango_font_description_get_size (font_desc);
|
|
|
|
priv->face = NULL;
|
|
|
|
priv->family = NULL;
|
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
gtk_widget_push_composite_child ();
|
2011-04-15 20:40:57 +00:00
|
|
|
|
2011-04-15 21:18:14 +00:00
|
|
|
/* Creating fundamental widgets for the private struct */
|
2011-04-15 20:40:57 +00:00
|
|
|
priv->search_entry = gtk_entry_new ();
|
|
|
|
priv->family_face_list = gtk_tree_view_new ();
|
2011-04-15 21:18:14 +00:00
|
|
|
priv->preview = gtk_entry_new ();
|
2011-04-15 20:40:57 +00:00
|
|
|
priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
|
2011-04-15 21:32:20 +00:00
|
|
|
(gdouble) font_sizes[0],
|
|
|
|
(gdouble) font_sizes[FONT_SIZES_LENGTH - 1],
|
|
|
|
1.0);
|
2011-04-15 22:22:38 +00:00
|
|
|
|
2011-04-16 15:40:47 +00:00
|
|
|
priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
|
2011-04-16 12:36:45 +00:00
|
|
|
|
2011-04-17 01:00:32 +00:00
|
|
|
/** Bootstrapping widget layout **/
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_box_set_spacing (GTK_BOX (fontchooser), 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (fontchooser), priv->search_entry, FALSE, TRUE, 0);
|
2011-04-16 21:36:25 +00:00
|
|
|
|
2011-04-15 21:18:14 +00:00
|
|
|
/* Main font family/face view */
|
2011-04-15 21:02:42 +00:00
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
2011-04-16 21:36:25 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
2011-04-18 21:38:11 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_SHADOW_ETCHED_IN);
|
2011-04-15 21:02:42 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_win), priv->family_face_list);
|
|
|
|
|
2011-04-15 21:18:14 +00:00
|
|
|
/* Alignment for the preview and size controls */
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (fontchooser), scrolled_win, TRUE, TRUE, 0);
|
2011-04-15 21:18:14 +00:00
|
|
|
|
2011-04-15 21:26:45 +00:00
|
|
|
preview_and_size = gtk_vbox_new (TRUE, 0);
|
2011-04-15 22:22:38 +00:00
|
|
|
gtk_box_set_homogeneous (GTK_BOX (preview_and_size), FALSE);
|
2011-04-26 23:15:03 +00:00
|
|
|
gtk_box_set_spacing (GTK_BOX (preview_and_size), 6);
|
|
|
|
|
2011-04-16 21:36:25 +00:00
|
|
|
/* The preview entry needs a scrolled window to make sure we have a */
|
|
|
|
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
2011-05-04 19:29:26 +00:00
|
|
|
priv->preview_scrolled_window = scrolled_win;
|
2011-04-16 21:36:25 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
2011-04-18 21:38:11 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
GTK_SHADOW_ETCHED_IN);
|
2011-04-16 21:36:25 +00:00
|
|
|
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_win),
|
|
|
|
priv->preview);
|
|
|
|
gtk_box_pack_start (GTK_BOX (preview_and_size), scrolled_win, FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* Setting the size requests for various widgets */
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (fontchooser), FONT_CHOOSER_WIDTH, FONT_CHOOSER_HEIGHT);
|
2011-04-16 21:52:03 +00:00
|
|
|
gtk_widget_set_size_request (scrolled_win, -1, PREVIEW_HEIGHT);
|
2011-04-18 21:38:11 +00:00
|
|
|
gtk_widget_set_size_request (priv->preview, -1, PREVIEW_HEIGHT - 6);
|
2011-04-16 21:36:25 +00:00
|
|
|
|
2011-04-17 03:10:37 +00:00
|
|
|
/* Unset the frame on the preview entry */
|
2011-04-16 21:36:25 +00:00
|
|
|
gtk_entry_set_has_frame (GTK_ENTRY (priv->preview), FALSE);
|
2011-04-15 21:32:20 +00:00
|
|
|
|
|
|
|
/* Packing the slider and the spin in a hbox */
|
|
|
|
size_controls = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
gtk_scale_set_draw_value (GTK_SCALE (priv->size_slider), FALSE);
|
2011-04-26 23:15:03 +00:00
|
|
|
gtk_box_set_spacing (GTK_BOX (size_controls), 6);
|
|
|
|
gtk_box_pack_start (GTK_BOX (size_controls), priv->size_slider, TRUE, TRUE, 0);
|
|
|
|
gtk_box_pack_start (GTK_BOX (size_controls), priv->size_spin, FALSE, TRUE, 0);
|
2011-04-17 01:00:32 +00:00
|
|
|
|
|
|
|
gtk_widget_set_valign (priv->size_spin, GTK_ALIGN_START);
|
2011-04-15 21:32:20 +00:00
|
|
|
|
2011-04-15 22:22:38 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (preview_and_size), size_controls, FALSE, FALSE, 0);
|
2011-04-15 21:18:14 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (fontchooser), GTK_WIDGET(preview_and_size), FALSE, TRUE, 0);
|
2011-04-16 14:56:56 +00:00
|
|
|
|
|
|
|
gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
|
|
|
|
(gdouble)(priv->size / PANGO_SCALE));
|
|
|
|
gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
|
|
|
|
(gdouble)(priv->size / PANGO_SCALE));
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_widget_show_all (GTK_WIDGET (fontchooser));
|
|
|
|
gtk_widget_hide (GTK_WIDGET (fontchooser));
|
2011-04-15 20:49:46 +00:00
|
|
|
|
2011-04-16 12:36:45 +00:00
|
|
|
/* Treeview column and model bootstrapping */
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_bootstrap_fontlist (fontchooser);
|
2011-04-16 12:36:45 +00:00
|
|
|
|
|
|
|
/* Set default preview text */
|
2011-04-16 13:27:31 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->preview),
|
|
|
|
pango_language_get_sample_string (NULL));
|
2011-04-16 13:59:43 +00:00
|
|
|
|
2011-04-16 14:17:53 +00:00
|
|
|
/* Set search icon and place holder text */
|
|
|
|
gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry),
|
|
|
|
GTK_ENTRY_ICON_SECONDARY,
|
|
|
|
GTK_STOCK_FIND);
|
2011-04-16 15:40:47 +00:00
|
|
|
gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
|
2011-04-16 14:17:53 +00:00
|
|
|
|
2011-04-16 13:59:43 +00:00
|
|
|
/** Callback connections **/
|
|
|
|
/* Connect to callback for the live search text entry */
|
|
|
|
g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
|
2011-04-17 02:11:11 +00:00
|
|
|
"deleted-text", G_CALLBACK (deleted_text_cb), priv);
|
2011-04-16 13:59:43 +00:00
|
|
|
g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
|
2011-04-17 02:11:11 +00:00
|
|
|
"inserted-text", G_CALLBACK (inserted_text_cb), priv);
|
2011-04-16 16:01:53 +00:00
|
|
|
g_signal_connect (G_OBJECT (priv->search_entry),
|
2011-04-17 02:11:11 +00:00
|
|
|
"icon-press", G_CALLBACK (icon_press_cb), priv);
|
2011-04-15 23:28:02 +00:00
|
|
|
|
2011-04-16 14:56:56 +00:00
|
|
|
/* Size controls callbacks */
|
|
|
|
g_signal_connect (G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider))),
|
2011-04-17 02:11:11 +00:00
|
|
|
"value-changed", G_CALLBACK (slider_change_cb), priv);
|
2011-04-16 14:56:56 +00:00
|
|
|
g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))),
|
2011-05-11 13:21:55 +00:00
|
|
|
"value-changed", G_CALLBACK (spin_change_cb), fontchooser);
|
2011-04-16 16:21:07 +00:00
|
|
|
priv->ignore_slider = FALSE;
|
2011-04-16 22:57:04 +00:00
|
|
|
|
2011-04-17 02:11:11 +00:00
|
|
|
/* Font selection callback */
|
2011-04-16 22:57:04 +00:00
|
|
|
g_signal_connect (G_OBJECT (priv->family_face_list), "cursor-changed",
|
2011-05-11 13:21:55 +00:00
|
|
|
G_CALLBACK (cursor_changed_cb), fontchooser);
|
2011-04-17 02:11:11 +00:00
|
|
|
|
|
|
|
/* Zoom on preview scroll*/
|
|
|
|
g_signal_connect (G_OBJECT (scrolled_win), "scroll-event",
|
|
|
|
G_CALLBACK (zoom_preview_cb), priv);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-04-17 03:10:37 +00:00
|
|
|
g_signal_connect (G_OBJECT (priv->size_slider), "scroll-event",
|
|
|
|
G_CALLBACK (zoom_preview_cb), priv);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
|
|
|
set_range_marks (priv, priv->size_slider, (gint*)font_sizes, FONT_SIZES_LENGTH);
|
|
|
|
|
2011-04-17 02:11:11 +00:00
|
|
|
/* Set default focus */
|
2011-04-15 20:07:32 +00:00
|
|
|
gtk_widget_pop_composite_child();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_new:
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Creates a new #GtkFontChooser.
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Return value: a new #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_new (void)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser = g_object_new (GTK_TYPE_FONT_CHOOSER, NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return GTK_WIDGET (fontchooser);
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
2011-04-16 00:47:39 +00:00
|
|
|
static int
|
|
|
|
cmp_families (const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
|
|
|
|
const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
|
|
|
|
|
|
|
|
return g_utf8_collate (a_name, b_name);
|
|
|
|
}
|
|
|
|
|
2011-04-15 23:28:02 +00:00
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
populate_list (GtkFontChooser *fontchooser, GtkTreeView* treeview, GtkListStore* model)
|
2011-04-15 23:28:02 +00:00
|
|
|
{
|
2011-04-29 12:19:57 +00:00
|
|
|
GtkStyleContext *style_context;
|
|
|
|
GdkRGBA g_color;
|
|
|
|
PangoColor p_color;
|
|
|
|
gchar *color_string;
|
|
|
|
PangoFontDescription *default_font;
|
2011-04-16 11:10:29 +00:00
|
|
|
|
2011-04-16 13:27:31 +00:00
|
|
|
GtkTreeIter match_row;
|
2011-04-17 01:00:32 +00:00
|
|
|
GtkTreePath *path;
|
2011-04-16 11:10:29 +00:00
|
|
|
|
|
|
|
gint n_families, i;
|
2011-04-16 00:47:39 +00:00
|
|
|
PangoFontFamily **families;
|
2011-04-16 11:10:29 +00:00
|
|
|
|
|
|
|
GString *tmp = g_string_new (NULL);
|
2011-04-18 21:20:15 +00:00
|
|
|
GString *family_and_face = g_string_new (NULL);
|
2011-04-16 11:10:29 +00:00
|
|
|
|
2011-04-16 00:47:39 +00:00
|
|
|
pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
|
|
|
|
&families,
|
|
|
|
&n_families);
|
|
|
|
|
|
|
|
qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
|
|
|
|
|
|
|
|
gtk_list_store_clear (model);
|
|
|
|
|
2011-04-16 11:10:29 +00:00
|
|
|
/* Get row header font color */
|
|
|
|
style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
|
|
|
|
gtk_style_context_get_color (style_context,
|
2011-04-29 12:19:57 +00:00
|
|
|
GTK_STATE_FLAG_NORMAL | GTK_STATE_FLAG_INSENSITIVE,
|
2011-04-16 11:10:29 +00:00
|
|
|
&g_color);
|
|
|
|
|
|
|
|
p_color.red = (guint16)((gdouble)G_MAXUINT16 * g_color.red);
|
|
|
|
p_color.green = (guint16)((gdouble)G_MAXUINT16 * g_color.green);
|
|
|
|
p_color.blue = (guint16)((gdouble)G_MAXUINT16 * g_color.blue);
|
|
|
|
color_string = pango_color_to_string (&p_color);
|
|
|
|
|
2011-04-29 12:19:57 +00:00
|
|
|
/* Get theme font */
|
2011-05-01 00:06:06 +00:00
|
|
|
default_font = (PangoFontDescription*) gtk_style_context_get_font (style_context,
|
|
|
|
GTK_STATE_NORMAL);
|
2011-04-29 12:19:57 +00:00
|
|
|
|
2011-04-16 11:10:29 +00:00
|
|
|
/* Iterate over families and faces */
|
2011-04-16 00:47:39 +00:00
|
|
|
for (i=0; i<n_families; i++)
|
|
|
|
{
|
2011-04-16 10:28:46 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
PangoFontFace **faces;
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-04-16 10:28:46 +00:00
|
|
|
int j, n_faces;
|
|
|
|
const gchar *fam_name = pango_font_family_get_name (families[i]);
|
|
|
|
|
|
|
|
pango_font_family_list_faces (families[i], &faces, &n_faces);
|
2011-04-16 01:31:31 +00:00
|
|
|
|
2011-04-16 10:28:46 +00:00
|
|
|
for (j=0; j<n_faces; j++)
|
2011-04-16 00:47:39 +00:00
|
|
|
{
|
2011-04-16 10:28:46 +00:00
|
|
|
PangoFontDescription *pango_desc = pango_font_face_describe (faces[j]);
|
|
|
|
const gchar *face_name = pango_font_face_get_face_name (faces[j]);
|
|
|
|
gchar *font_desc = pango_font_description_to_string (pango_desc);
|
|
|
|
|
|
|
|
/* foreground_color, family_name, face_name, desc, sample string */
|
2011-04-18 21:20:15 +00:00
|
|
|
g_string_printf (family_and_face, "%s %s",
|
|
|
|
fam_name,
|
|
|
|
face_name);
|
|
|
|
|
2011-04-16 10:28:46 +00:00
|
|
|
g_string_printf (tmp, ROW_FORMAT_STRING,
|
2011-05-11 13:21:55 +00:00
|
|
|
color_string,
|
|
|
|
family_and_face->str,
|
|
|
|
font_desc,
|
|
|
|
fontchooser->priv->preview_text);
|
2011-04-16 10:28:46 +00:00
|
|
|
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
|
|
gtk_list_store_set (model, &iter,
|
|
|
|
FAMILY_COLUMN, families[i],
|
|
|
|
FACE_COLUMN, faces[j],
|
2011-04-18 21:20:15 +00:00
|
|
|
PREVIEW_TITLE_COLUMN, family_and_face->str,
|
|
|
|
PREVIEW_TEXT_COLUMN, tmp->str,
|
2011-04-16 10:28:46 +00:00
|
|
|
-1);
|
|
|
|
|
2011-05-01 00:06:06 +00:00
|
|
|
/* Select the first font or the default font/face from the style context */
|
2011-04-16 10:28:46 +00:00
|
|
|
if ((i == 0 && j == 0) ||
|
2011-04-29 12:19:57 +00:00
|
|
|
(!strcmp (fam_name, pango_font_description_get_family (default_font)) && j == 0))
|
2011-04-28 00:57:02 +00:00
|
|
|
match_row = iter;
|
2011-04-16 10:28:46 +00:00
|
|
|
|
|
|
|
pango_font_description_free(pango_desc);
|
|
|
|
g_free (font_desc);
|
2011-04-16 00:47:39 +00:00
|
|
|
}
|
2011-04-16 10:28:46 +00:00
|
|
|
|
|
|
|
g_free (faces);
|
2011-04-16 00:47:39 +00:00
|
|
|
}
|
|
|
|
|
2011-04-17 01:00:32 +00:00
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &match_row);
|
2011-05-01 00:06:06 +00:00
|
|
|
|
2011-04-18 21:20:15 +00:00
|
|
|
if (path)
|
2011-05-11 13:21:55 +00:00
|
|
|
{
|
|
|
|
gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
|
2011-05-11 14:36:28 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_tree_path_free(path);
|
|
|
|
}
|
2011-04-18 21:20:15 +00:00
|
|
|
|
|
|
|
g_string_free (family_and_face, TRUE);
|
2011-04-16 01:31:31 +00:00
|
|
|
g_string_free (tmp, TRUE);
|
2011-04-16 11:10:29 +00:00
|
|
|
g_free (color_string);
|
2011-04-16 00:47:39 +00:00
|
|
|
g_free (families);
|
2011-04-15 23:28:02 +00:00
|
|
|
}
|
|
|
|
|
2011-04-16 13:27:31 +00:00
|
|
|
gboolean
|
|
|
|
visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
|
|
|
{
|
2011-05-11 14:47:15 +00:00
|
|
|
gboolean result = TRUE;
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*) data;
|
2011-04-16 13:27:31 +00:00
|
|
|
|
|
|
|
const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
|
|
|
|
gchar *font_name;
|
2011-05-11 14:47:15 +00:00
|
|
|
gchar *term;
|
|
|
|
gchar **split_terms;
|
|
|
|
gint n_terms = 0;
|
|
|
|
|
|
|
|
/* If there's no filter string we show the item */
|
|
|
|
if (strlen (search_text) == 0)
|
|
|
|
return TRUE;
|
2011-04-16 13:27:31 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
2011-04-26 23:20:04 +00:00
|
|
|
PREVIEW_TITLE_COLUMN, &font_name,
|
2011-04-16 13:27:31 +00:00
|
|
|
-1);
|
|
|
|
|
2011-05-11 14:47:15 +00:00
|
|
|
if (font_name == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
split_terms = g_strsplit (search_text, " ", 0);
|
|
|
|
term = split_terms[0];
|
|
|
|
|
|
|
|
while (term && result)
|
|
|
|
{
|
|
|
|
gchar* font_name_casefold = g_utf8_casefold (font_name, -1);
|
|
|
|
gchar* term_casefold = g_utf8_casefold (term, -1);
|
|
|
|
|
|
|
|
if (g_strrstr (font_name_casefold, term_casefold))
|
|
|
|
result = result && TRUE;
|
|
|
|
else
|
|
|
|
result = FALSE;
|
|
|
|
|
|
|
|
n_terms++;
|
|
|
|
term = split_terms[n_terms];
|
|
|
|
|
|
|
|
g_free (term_casefold);
|
|
|
|
g_free (font_name_casefold);
|
|
|
|
}
|
2011-04-16 13:27:31 +00:00
|
|
|
|
|
|
|
g_free (font_name);
|
2011-05-11 14:47:15 +00:00
|
|
|
g_strfreev (split_terms);
|
|
|
|
|
2011-04-16 14:17:53 +00:00
|
|
|
return result;
|
2011-04-16 13:27:31 +00:00
|
|
|
}
|
|
|
|
|
2011-04-15 23:28:02 +00:00
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_bootstrap_fontlist (GtkFontChooser* fontchooser)
|
2011-04-15 23:28:02 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkTreeView *treeview = GTK_TREE_VIEW (fontchooser->priv->family_face_list);
|
2011-04-17 01:26:16 +00:00
|
|
|
GtkCellRenderer *cell;
|
2011-04-16 11:10:29 +00:00
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser->priv->model = gtk_list_store_new (4,
|
2011-05-11 14:47:15 +00:00
|
|
|
PANGO_TYPE_FONT_FAMILY,
|
|
|
|
PANGO_TYPE_FONT_FACE,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_STRING);
|
2011-04-16 14:17:53 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontchooser->priv->model),
|
2011-05-11 14:47:15 +00:00
|
|
|
NULL);
|
2011-05-11 13:21:55 +00:00
|
|
|
g_object_unref (fontchooser->priv->model);
|
2011-04-17 01:00:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontchooser->priv->filter),
|
2011-04-16 14:17:53 +00:00
|
|
|
visible_func,
|
2011-05-11 13:21:55 +00:00
|
|
|
(gpointer)fontchooser->priv,
|
2011-04-16 14:17:53 +00:00
|
|
|
NULL);
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontchooser->priv->filter));
|
|
|
|
g_object_unref (fontchooser->priv->filter);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-04-16 00:54:39 +00:00
|
|
|
gtk_tree_view_set_rules_hint (treeview, TRUE);
|
|
|
|
gtk_tree_view_set_headers_visible (treeview, FALSE);
|
2011-04-16 00:26:26 +00:00
|
|
|
|
2011-04-17 01:26:16 +00:00
|
|
|
cell = gtk_cell_renderer_text_new ();
|
2011-04-16 00:26:26 +00:00
|
|
|
col = gtk_tree_view_column_new_with_attributes ("Family",
|
2011-04-17 01:26:16 +00:00
|
|
|
cell,
|
2011-04-18 21:20:15 +00:00
|
|
|
"markup", PREVIEW_TEXT_COLUMN,
|
2011-04-17 01:26:16 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
2011-04-18 21:20:15 +00:00
|
|
|
|
2011-04-16 00:26:26 +00:00
|
|
|
gtk_tree_view_append_column (treeview, col);
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
populate_list (fontchooser, treeview, fontchooser->priv->model);
|
2011-04-15 23:28:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_finalize (GObject *object)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (object);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_ref_family (fontchooser, NULL);
|
|
|
|
gtk_font_chooser_ref_face (fontchooser, NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
G_OBJECT_CLASS (gtk_font_chooser_parent_class)->finalize (object);
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
2011-05-04 22:07:16 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_screen_changed (GtkWidget *widget,
|
2011-04-18 21:20:15 +00:00
|
|
|
GdkScreen *previous_screen)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
|
2011-05-04 22:07:16 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
populate_list (fontchooser,
|
|
|
|
GTK_TREE_VIEW (fontchooser->priv->family_face_list),
|
|
|
|
fontchooser->priv->model);
|
2011-04-15 20:07:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_style_updated (GtkWidget *widget)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
|
2011-05-04 22:07:16 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_font_chooser_parent_class)->style_updated (widget);
|
2011-05-04 22:07:16 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
populate_list (fontchooser,
|
|
|
|
GTK_TREE_VIEW (fontchooser->priv->family_face_list),
|
|
|
|
fontchooser->priv->model);
|
2011-04-15 20:07:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_ref_family (GtkFontChooser *fontchooser,
|
2011-04-16 00:47:39 +00:00
|
|
|
PangoFontFamily *family)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = fontchooser->priv;
|
2011-04-16 00:47:39 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
if (family)
|
|
|
|
family = g_object_ref (family);
|
|
|
|
if (priv->family)
|
|
|
|
g_object_unref (priv->family);
|
|
|
|
priv->family = family;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_ref_face (GtkFontChooser *fontchooser,
|
2011-04-16 00:47:39 +00:00
|
|
|
PangoFontFace *face)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = fontchooser->priv;
|
2011-04-16 00:47:39 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
if (face)
|
|
|
|
face = g_object_ref (face);
|
|
|
|
if (priv->face)
|
|
|
|
g_object_unref (priv->face);
|
|
|
|
priv->face = face;
|
|
|
|
}
|
|
|
|
|
2011-04-27 00:08:55 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* These functions are the main public interface for getting/setting the font.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_get_family:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Gets the #PangoFontFamily representing the selected font family.
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): A #PangoFontFamily representing the
|
|
|
|
* selected font family. Font families are a collection of font
|
2011-05-11 13:21:55 +00:00
|
|
|
* faces. The returned object is owned by @fontchooser and must not
|
2011-04-15 20:07:32 +00:00
|
|
|
* be modified or freed.
|
|
|
|
*
|
2011-05-11 13:59:23 +00:00
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
PangoFontFamily *
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_family (GtkFontChooser *fontchooser)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return fontchooser->priv->family;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_get_face:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Gets the #PangoFontFace representing the selected font group
|
|
|
|
* details (i.e. family, slant, weight, width, etc).
|
|
|
|
*
|
|
|
|
* Return value: (transfer none): A #PangoFontFace representing the
|
|
|
|
* selected font group details. The returned object is owned by
|
2011-05-11 13:21:55 +00:00
|
|
|
* @fontchooser and must not be modified or freed.
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:59:23 +00:00
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
PangoFontFace *
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_face (GtkFontChooser *fontchooser)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return fontchooser->priv->face;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_get_size:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* The selected font size.
|
|
|
|
*
|
|
|
|
* Return value: A n integer representing the selected font size,
|
|
|
|
* or -1 if no font size is selected.
|
|
|
|
*
|
2011-05-11 13:59:23 +00:00
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
**/
|
|
|
|
gint
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_size (GtkFontChooser *fontchooser)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return fontchooser->priv->size;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_get_font_name:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Gets the currently-selected font name.
|
|
|
|
*
|
|
|
|
* Note that this can be a different string than what you set with
|
2011-05-11 13:59:23 +00:00
|
|
|
* gtk_font_chooser_set_font_name(), as the font chooser widget may
|
2011-04-15 20:07:32 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2011-04-17 02:11:11 +00:00
|
|
|
* Return value: (transfer full) (allow-none): A string with the name of the
|
|
|
|
* current font, or %NULL if no font is selected. You must free this
|
|
|
|
* string with g_free().
|
2011-05-11 13:59:23 +00:00
|
|
|
*
|
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
gchar *
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_font_name (GtkFontChooser *fontchooser)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-03 00:09:12 +00:00
|
|
|
gchar *font_name;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
if (!fontchooser->priv->face)
|
2011-04-17 02:11:11 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
desc = pango_font_face_describe (fontchooser->priv->face);
|
2011-05-03 00:09:12 +00:00
|
|
|
font_name = pango_font_description_to_string (desc);
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
return font_name;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This sets the current font, then selecting the appropriate list rows. */
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_set_font_name:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
* @fontname: a font name like "Helvetica 12" or "Times Bold 18"
|
|
|
|
*
|
|
|
|
* Sets the currently-selected font.
|
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Note that the @fontchooser needs to know the screen in which it will appear
|
2011-04-15 20:07:32 +00:00
|
|
|
* for this to work; this can be guaranteed by simply making sure that the
|
2011-05-11 13:21:55 +00:00
|
|
|
* @fontchooser is inserted in a toplevel window before you call this function.
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the font could be set successfully; %FALSE if no
|
2011-05-11 13:21:55 +00:00
|
|
|
* such font exists or if the @fontchooser doesn't belong to a particular
|
2011-04-15 20:07:32 +00:00
|
|
|
* screen yet.
|
2011-05-11 13:59:23 +00:00
|
|
|
*
|
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_font_name (GtkFontChooser *fontchooser,
|
2011-05-03 00:09:12 +00:00
|
|
|
const gchar *fontname)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserPrivate *priv = fontchooser->priv;
|
2011-05-03 00:09:12 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean valid;
|
|
|
|
gchar *family_name;
|
|
|
|
PangoFontDescription *desc;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
|
2011-05-03 00:37:48 +00:00
|
|
|
g_return_val_if_fail (fontname != NULL, FALSE);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
if (!gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
|
2011-05-03 00:09:12 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
desc = pango_font_description_from_string (fontname);
|
|
|
|
family_name = (gchar*)pango_font_description_get_family (desc);
|
|
|
|
|
|
|
|
if (!family_name)
|
|
|
|
{
|
|
|
|
pango_font_description_free (desc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We make sure the filter is clear */
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
|
|
|
|
|
|
|
|
/* We find the matching family/face */
|
|
|
|
for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), &iter);
|
|
|
|
valid;
|
|
|
|
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter), &iter))
|
|
|
|
{
|
|
|
|
PangoFontFace *face;
|
|
|
|
PangoFontDescription *tmp_desc;
|
|
|
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (priv->filter), &iter,
|
|
|
|
FACE_COLUMN, &face,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
tmp_desc = pango_font_face_describe (face);
|
|
|
|
if (pango_font_description_get_size_is_absolute (desc))
|
|
|
|
pango_font_description_set_absolute_size (tmp_desc,
|
|
|
|
pango_font_description_get_size (desc));
|
|
|
|
else
|
|
|
|
pango_font_description_set_size (tmp_desc,
|
|
|
|
pango_font_description_get_size (desc));
|
|
|
|
|
|
|
|
|
|
|
|
if (pango_font_description_equal (desc, tmp_desc))
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint size = pango_font_description_get_size (desc);
|
|
|
|
|
|
|
|
if (size)
|
|
|
|
{
|
|
|
|
if (pango_font_description_get_size_is_absolute (desc))
|
|
|
|
size = size * PANGO_SCALE;
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin),
|
|
|
|
size / PANGO_SCALE);
|
|
|
|
}
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter),
|
|
|
|
&iter);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list),
|
|
|
|
path,
|
|
|
|
NULL,
|
|
|
|
FALSE);
|
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
|
|
|
|
path,
|
|
|
|
NULL,
|
2011-05-11 14:36:28 +00:00
|
|
|
FALSE,
|
2011-05-03 00:09:12 +00:00
|
|
|
0.5,
|
|
|
|
0.5);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (face);
|
|
|
|
pango_font_description_free (tmp_desc);
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pango_font_description_free (desc);
|
2011-05-11 13:21:55 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "font-name");
|
2011-05-03 00:09:12 +00:00
|
|
|
|
|
|
|
return found;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_get_preview_text:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Gets the text displayed in the preview area.
|
|
|
|
*
|
2011-05-03 18:59:57 +00:00
|
|
|
* Return value: (transfer none): the text displayed in the
|
|
|
|
* preview area. This string is owned by the widget and
|
2011-05-11 13:59:23 +00:00
|
|
|
* should not be modified or freed
|
|
|
|
*
|
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
G_CONST_RETURN gchar*
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
|
|
|
|
return (const gchar*)fontchooser->priv->preview_text;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_set_preview_text:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-05-03 18:59:57 +00:00
|
|
|
* @text: (transfer none): the text to display in the preview area
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Sets the text displayed in the preview area.
|
|
|
|
* The @text is used to show how the selected font looks.
|
2011-05-11 13:59:23 +00:00
|
|
|
*
|
|
|
|
* Since: 3.2
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_preview_text (GtkFontChooser *fontchooser,
|
2011-05-03 18:59:57 +00:00
|
|
|
const gchar *text)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
|
2011-04-15 20:07:32 +00:00
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
g_free (fontchooser->priv->preview_text);
|
|
|
|
fontchooser->priv->preview_text = g_strdup (text);
|
2011-05-03 18:59:57 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
populate_list (fontchooser,
|
|
|
|
GTK_TREE_VIEW (fontchooser->priv->family_face_list),
|
|
|
|
fontchooser->priv->model);
|
2011-05-03 18:59:57 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (fontchooser->priv->preview), text);
|
2011-05-03 18:59:57 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
g_object_notify (G_OBJECT (fontchooser), "preview-text");
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
2011-05-04 19:29:26 +00:00
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_get_show_preview_entry:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-05-04 19:29:26 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the preview entry is shown or %FALSE if
|
|
|
|
* it is hidden.
|
|
|
|
* Since: 3.2
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser)
|
2011-05-04 19:29:26 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
|
2011-05-04 19:29:26 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return fontchooser->priv->show_preview_entry;
|
2011-05-04 19:29:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_set_show_preview_entry:
|
|
|
|
* @fontchooser: a #GtkFontChooser
|
2011-05-04 19:29:26 +00:00
|
|
|
* @show_preview_entry: whether to show the editable preview entry or not
|
|
|
|
*
|
|
|
|
* Shows or hides the editable preview entry.
|
|
|
|
* Since: 3.2
|
|
|
|
*/
|
|
|
|
void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser,
|
2011-05-04 19:29:26 +00:00
|
|
|
gboolean show_preview_entry)
|
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
|
2011-05-04 19:29:26 +00:00
|
|
|
|
|
|
|
if (show_preview_entry)
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_widget_show (fontchooser->priv->preview_scrolled_window);
|
2011-05-04 19:29:26 +00:00
|
|
|
else
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_widget_hide (fontchooser->priv->preview_scrolled_window);
|
2011-05-04 19:29:26 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooser->priv->show_preview_entry = show_preview_entry;
|
|
|
|
g_object_notify (G_OBJECT (fontchooser), "show-preview-entry");
|
2011-05-04 19:29:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-28 18:17:20 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* SECTION:gtkfontchooserdlg
|
2011-04-15 20:07:32 +00:00
|
|
|
* @Short_description: A dialog box for selecting fonts
|
2011-05-11 13:21:55 +00:00
|
|
|
* @Title: GtkFontChooserDialog
|
|
|
|
* @See_also: #GtkFontChooser, #GtkDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* The #GtkFontChooserDialog widget is a dialog box for selecting a font.
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* To set the font which is initially selected, use
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_set_font_name().
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* To get the selected font use gtk_font_chooser_dialog_get_font_name().
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* To change the text which is shown in the preview area, use
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_set_preview_text().
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* <refsect2 id="GtkFontChooserDialog-BUILDER-UI">
|
|
|
|
* <title>GtkFontChooserDialog as GtkBuildable</title>
|
|
|
|
* The GtkFontChooserDialog implementation of the GtkBuildable interface
|
|
|
|
* exposes the embedded #GtkFontChooser as internal child with the
|
2011-05-11 13:59:23 +00:00
|
|
|
* name "font_chooser". It also exposes the buttons with the names
|
2011-05-03 23:14:31 +00:00
|
|
|
* "select_button" and "cancel_button. The buttons with the names
|
|
|
|
* "ok_button" and "apply_button" are exposed but deprecated.
|
2011-04-15 20:07:32 +00:00
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
static void gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface);
|
|
|
|
static GObject * gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
|
2011-04-27 23:39:15 +00:00
|
|
|
GtkBuilder *builder,
|
|
|
|
const gchar *childname);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkFontChooserDialog, gtk_font_chooser_dialog,
|
2011-04-27 23:39:15 +00:00
|
|
|
GTK_TYPE_DIALOG,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_dialog_buildable_interface_init))
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GtkFontChooserDialogPrivate));
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialogPrivate *priv;
|
|
|
|
GtkDialog *dialog = GTK_DIALOG (fontchooserdiag);
|
2011-04-15 20:07:32 +00:00
|
|
|
GtkWidget *action_area, *content_area;
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooserdiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooserdiag,
|
|
|
|
GTK_TYPE_FONT_CHOOSER_DIALOG,
|
|
|
|
GtkFontChooserDialogPrivate);
|
|
|
|
priv = fontchooserdiag->priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
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 ();
|
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (fontchooserdiag), TRUE);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
/* Create the content area */
|
2011-05-11 13:21:55 +00:00
|
|
|
priv->fontchooser = gtk_font_chooser_new ();
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (priv->fontchooser), 5);
|
|
|
|
gtk_widget_show (priv->fontchooser);
|
2011-04-15 20:07:32 +00:00
|
|
|
gtk_box_pack_start (GTK_BOX (content_area),
|
2011-05-11 13:21:55 +00:00
|
|
|
priv->fontchooser, TRUE, TRUE, 0);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
/* Create the action area */
|
|
|
|
priv->cancel_button = gtk_dialog_add_button (dialog,
|
|
|
|
GTK_STOCK_CANCEL,
|
|
|
|
GTK_RESPONSE_CANCEL);
|
2011-05-03 23:14:31 +00:00
|
|
|
priv->select_button = gtk_dialog_add_button (dialog,
|
|
|
|
_("Select"),
|
|
|
|
GTK_RESPONSE_OK);
|
|
|
|
gtk_widget_grab_default (priv->select_button);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontchooserdiag),
|
2011-04-27 23:39:15 +00:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (fontchooserdiag),
|
2011-04-15 20:07:32 +00:00
|
|
|
_("Font Selection"));
|
|
|
|
|
|
|
|
gtk_widget_pop_composite_child ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_new:
|
2011-05-03 23:14:31 +00:00
|
|
|
* @title: (allow-none): the title of the dialog window
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Creates a new #GtkFontChooserDialog.
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Return value: a new #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
*/
|
|
|
|
GtkWidget*
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_dialog_new (const gchar *title)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialog *fontchooserdiag;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
fontchooserdiag = g_object_new (GTK_TYPE_FONT_CHOOSER_DIALOG, NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
|
|
|
if (title)
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (fontchooserdiag), title);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return GTK_WIDGET (fontchooserdiag);
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:59:23 +00:00
|
|
|
* gtk_font_chooser_dialog_get_font_chooser:
|
|
|
|
* @fcd: a #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Retrieves the #GtkFontChooser widget embedded in the dialog.
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
2011-05-11 13:21:55 +00:00
|
|
|
* Returns: (transfer none): the embedded #GtkFontChooser
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Since: 2.22
|
|
|
|
**/
|
|
|
|
GtkWidget*
|
2011-05-11 13:59:23 +00:00
|
|
|
gtk_font_chooser_dialog_get_font_chooser (GtkFontChooserDialog *fcd)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:59:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
return fcd->priv->fontchooser;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_dialog_buildable_interface_init (GtkBuildableIface *iface)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
2011-05-11 13:21:55 +00:00
|
|
|
iface->get_internal_child = gtk_font_chooser_dialog_buildable_get_internal_child;
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GObject *
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
|
2011-04-27 23:39:15 +00:00
|
|
|
GtkBuilder *builder,
|
|
|
|
const gchar *childname)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialogPrivate *priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
priv = GTK_FONT_CHOOSER_DIALOG (buildable)->priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-03 23:14:31 +00:00
|
|
|
if (g_strcmp0 (childname, "select_button") == 0)
|
|
|
|
return G_OBJECT (priv->select_button);
|
2011-04-15 20:07:32 +00:00
|
|
|
else if (g_strcmp0 (childname, "cancel_button") == 0)
|
|
|
|
return G_OBJECT (priv->cancel_button);
|
2011-05-11 13:59:23 +00:00
|
|
|
else if (g_strcmp0 (childname, "font_chooser") == 0)
|
2011-05-11 13:21:55 +00:00
|
|
|
return G_OBJECT (priv->fontchooser);
|
2011-05-08 14:45:20 +00:00
|
|
|
|
2011-04-15 20:07:32 +00:00
|
|
|
return parent_buildable_iface->get_internal_child (buildable, builder, childname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_get_font_name:
|
2011-05-11 13:59:23 +00:00
|
|
|
* @fcd: a #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* Gets the currently-selected font name.
|
|
|
|
*
|
|
|
|
* Note that this can be a different string than what you set with
|
2011-05-11 13:59:23 +00:00
|
|
|
* gtk_font_chooser_dialog_set_font_name(), as the font chooser widget
|
2011-04-15 20:07:32 +00:00
|
|
|
* 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*
|
2011-05-11 13:59:23 +00:00
|
|
|
gtk_font_chooser_dialog_get_font_name (GtkFontChooserDialog *fcd)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialogPrivate *priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
priv = fcd->priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return gtk_font_chooser_get_font_name (GTK_FONT_CHOOSER (priv->fontchooser));
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_set_font_name:
|
2011-05-11 13:59:23 +00:00
|
|
|
* @fcd: a #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
* @fontname: a font name like "Helvetica 12" or "Times Bold 18"
|
|
|
|
*
|
|
|
|
* Sets the currently selected font.
|
|
|
|
*
|
2011-05-11 13:59:23 +00:00
|
|
|
* Return value: %TRUE if the font selected in @fcd is now the
|
2011-04-15 20:07:32 +00:00
|
|
|
* @fontname specified, %FALSE otherwise.
|
|
|
|
*/
|
|
|
|
gboolean
|
2011-05-11 13:59:23 +00:00
|
|
|
gtk_font_chooser_dialog_set_font_name (GtkFontChooserDialog *fcd,
|
2011-04-27 23:39:15 +00:00
|
|
|
const gchar *fontname)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialogPrivate *priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), FALSE);
|
2011-04-15 20:07:32 +00:00
|
|
|
g_return_val_if_fail (fontname, FALSE);
|
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
priv = fcd->priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return gtk_font_chooser_set_font_name (GTK_FONT_CHOOSER (priv->fontchooser), fontname);
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_get_preview_text:
|
2011-05-11 13:59:23 +00:00
|
|
|
* @fcd: a #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
*
|
|
|
|
* 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*
|
2011-05-11 13:59:23 +00:00
|
|
|
gtk_font_chooser_dialog_get_preview_text (GtkFontChooserDialog *fcd)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialogPrivate *priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd), NULL);
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
priv = fcd->priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
return gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (priv->fontchooser));
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-05-11 13:21:55 +00:00
|
|
|
* gtk_font_chooser_dialog_set_preview_text:
|
2011-05-11 13:59:23 +00:00
|
|
|
* @fcd: a #GtkFontChooserDialog
|
2011-04-15 20:07:32 +00:00
|
|
|
* @text: the text to display in the preview area
|
|
|
|
*
|
|
|
|
* Sets the text displayed in the preview area.
|
|
|
|
*/
|
|
|
|
void
|
2011-05-11 13:59:23 +00:00
|
|
|
gtk_font_chooser_dialog_set_preview_text (GtkFontChooserDialog *fcd,
|
2011-04-27 23:39:15 +00:00
|
|
|
const gchar *text)
|
2011-04-15 20:07:32 +00:00
|
|
|
{
|
2011-05-11 13:21:55 +00:00
|
|
|
GtkFontChooserDialogPrivate *priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
g_return_if_fail (GTK_IS_FONT_CHOOSER_DIALOG (fcd));
|
2011-04-15 20:07:32 +00:00
|
|
|
g_return_if_fail (text != NULL);
|
|
|
|
|
2011-05-11 13:59:23 +00:00
|
|
|
priv = fcd->priv;
|
2011-04-15 20:07:32 +00:00
|
|
|
|
2011-05-11 13:21:55 +00:00
|
|
|
gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (priv->fontchooser), text);
|
2011-04-15 20:07:32 +00:00
|
|
|
}
|