mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-25 21:21:21 +00:00
GtkFontChooser: Add a property to control whether the preview entry is shown or not
This commit is contained in:
parent
731120e26e
commit
6dec212d1d
@ -88,23 +88,24 @@
|
||||
|
||||
struct _GtkFontSelectionPrivate
|
||||
{
|
||||
GtkWidget *search_entry;
|
||||
GtkWidget *family_face_list;
|
||||
GtkWidget *size_slider;
|
||||
GtkWidget *size_spin;
|
||||
GtkWidget *preview;
|
||||
|
||||
gboolean ignore_slider;
|
||||
|
||||
GtkWidget *search_entry;
|
||||
GtkWidget *family_face_list;
|
||||
GtkListStore *model;
|
||||
GtkTreeModel *filter;
|
||||
|
||||
GtkWidget *preview;
|
||||
GtkWidget *preview_scrolled_window;
|
||||
gchar *preview_text;
|
||||
gboolean show_preview_entry;
|
||||
|
||||
GtkWidget *size_spin;
|
||||
GtkWidget *size_slider;
|
||||
gboolean ignore_slider;
|
||||
|
||||
gint size;
|
||||
PangoFontFace *face;
|
||||
PangoFontFamily *family;
|
||||
|
||||
gchar *preview_text;
|
||||
|
||||
#ifndef GTK_DISABLE_DEPRECATED
|
||||
GtkWidget *size_list;
|
||||
GtkWidget *font_list;
|
||||
@ -162,7 +163,8 @@ static const gint font_sizes[] = {
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_FONT_NAME,
|
||||
PROP_PREVIEW_TEXT
|
||||
PROP_PREVIEW_TEXT,
|
||||
PROP_SHOW_PREVIEW_ENTRY
|
||||
};
|
||||
|
||||
|
||||
@ -235,6 +237,14 @@ gtk_font_selection_class_init (GtkFontSelectionClass *klass)
|
||||
pango_language_get_sample_string (NULL),
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
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));
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GtkFontSelectionPrivate));
|
||||
}
|
||||
|
||||
@ -256,6 +266,8 @@ gtk_font_selection_set_property (GObject *object,
|
||||
case PROP_PREVIEW_TEXT:
|
||||
gtk_font_selection_set_preview_text (fontsel, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_SHOW_PREVIEW_ENTRY:
|
||||
gtk_font_selection_set_show_preview_entry (fontsel, g_value_get_boolean (value));
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -280,6 +292,8 @@ gtk_font_selection_get_property (GObject *object,
|
||||
case PROP_PREVIEW_TEXT:
|
||||
g_value_set_string (value, gtk_font_selection_get_preview_text (fontsel));
|
||||
break;
|
||||
case PROP_SHOW_PREVIEW_ENTRY:
|
||||
g_value_set_boolean (value, gtk_font_selection_get_show_preview_entry (fontsel));
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -605,6 +619,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
|
||||
|
||||
/* Default preview string */
|
||||
priv->preview_text = g_strdup (pango_language_get_sample_string (NULL));
|
||||
priv->show_preview_entry = TRUE;
|
||||
|
||||
/* Getting the default size */
|
||||
font_desc = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)));
|
||||
@ -646,6 +661,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
|
||||
|
||||
/* The preview entry needs a scrolled window to make sure we have a */
|
||||
scrolled_win = gtk_scrolled_window_new (NULL, NULL);
|
||||
priv->preview_scrolled_window = scrolled_win;
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
|
||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
|
||||
@ -1674,6 +1690,45 @@ gtk_font_selection_set_preview_text (GtkFontSelection *fontsel,
|
||||
g_object_notify (G_OBJECT (fontsel), "preview-text");
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_font_selection_get_show_preview_entry:
|
||||
* @fontsel: a #GtkFontSelection
|
||||
*
|
||||
* Return value: %TRUE if the preview entry is shown or %FALSE if
|
||||
* it is hidden.
|
||||
* Since: 3.2
|
||||
*/
|
||||
gboolean
|
||||
gtk_font_selection_get_show_preview_entry (GtkFontSelection *fontsel)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
|
||||
|
||||
return fontsel->priv->show_preview_entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_font_selection_set_show_preview_entry:
|
||||
* @fontsel: a #GtkFontSelection
|
||||
* @show_preview_entry: whether to show the editable preview entry or not
|
||||
*
|
||||
* Shows or hides the editable preview entry.
|
||||
* Since: 3.2
|
||||
*/
|
||||
void
|
||||
gtk_font_selection_set_show_preview_entry (GtkFontSelection *fontsel,
|
||||
gboolean show_preview_entry)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_FONT_SELECTION (fontsel));
|
||||
|
||||
if (show_preview_entry)
|
||||
gtk_widget_show (fontsel->priv->preview_scrolled_window);
|
||||
else
|
||||
gtk_widget_hide (fontsel->priv->preview_scrolled_window);
|
||||
|
||||
fontsel->priv->show_preview_entry = show_preview_entry;
|
||||
g_object_notify (G_OBJECT (fontsel), "show-preview-entry");
|
||||
}
|
||||
|
||||
#ifndef GTK_DISABLE_DEPRECATED
|
||||
|
||||
/**
|
||||
|
@ -112,27 +112,30 @@ struct _GtkFontSelectionDialogClass
|
||||
* see the comments in the GtkFontSelectionDialog functions.
|
||||
*****************************************************************************/
|
||||
|
||||
GType gtk_font_selection_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget * gtk_font_selection_new (void);
|
||||
PangoFontFamily *
|
||||
gtk_font_selection_get_family (GtkFontSelection *fontsel);
|
||||
PangoFontFace *
|
||||
gtk_font_selection_get_face (GtkFontSelection *fontsel);
|
||||
gint gtk_font_selection_get_size (GtkFontSelection *fontsel);
|
||||
gchar* gtk_font_selection_get_font_name (GtkFontSelection *fontsel);
|
||||
GType gtk_font_selection_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget* gtk_font_selection_new (void);
|
||||
PangoFontFamily*
|
||||
gtk_font_selection_get_family (GtkFontSelection *fontsel);
|
||||
PangoFontFace*
|
||||
gtk_font_selection_get_face (GtkFontSelection *fontsel);
|
||||
gint gtk_font_selection_get_size (GtkFontSelection *fontsel);
|
||||
gchar* gtk_font_selection_get_font_name (GtkFontSelection *fontsel);
|
||||
|
||||
gboolean gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
|
||||
const gchar *fontname);
|
||||
const gchar* gtk_font_selection_get_preview_text (GtkFontSelection *fontsel);
|
||||
void gtk_font_selection_set_preview_text (GtkFontSelection *fontsel,
|
||||
const gchar *text);
|
||||
gboolean gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
|
||||
const gchar *fontname);
|
||||
const gchar* gtk_font_selection_get_preview_text (GtkFontSelection *fontsel);
|
||||
void gtk_font_selection_set_preview_text (GtkFontSelection *fontsel,
|
||||
const gchar *text);
|
||||
gboolean gtk_font_selection_get_show_preview_entry (GtkFontSelection *fontsel);
|
||||
void gtk_font_selection_set_show_preview_entry (GtkFontSelection *fontsel,
|
||||
gboolean show_preview_entry);
|
||||
/* Deprecated GtkFontSelection methods */
|
||||
#ifndef GTK_DISABLE_DEPRECATED
|
||||
GtkWidget * gtk_font_selection_get_family_list (GtkFontSelection *fontsel);
|
||||
GtkWidget * gtk_font_selection_get_face_list (GtkFontSelection *fontsel);
|
||||
GtkWidget * gtk_font_selection_get_size_entry (GtkFontSelection *fontsel);
|
||||
GtkWidget * gtk_font_selection_get_size_list (GtkFontSelection *fontsel);
|
||||
GtkWidget * gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel);
|
||||
GtkWidget* gtk_font_selection_get_family_list (GtkFontSelection *fontsel);
|
||||
GtkWidget* gtk_font_selection_get_face_list (GtkFontSelection *fontsel);
|
||||
GtkWidget* gtk_font_selection_get_size_entry (GtkFontSelection *fontsel);
|
||||
GtkWidget* gtk_font_selection_get_size_list (GtkFontSelection *fontsel);
|
||||
GtkWidget* gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel);
|
||||
#endif
|
||||
|
||||
/*****************************************************************************
|
||||
@ -141,12 +144,12 @@ GtkWidget * gtk_font_selection_get_preview_entry (GtkFontSelection *fontsel);
|
||||
* GtkFontSelection.
|
||||
*****************************************************************************/
|
||||
|
||||
GType gtk_font_selection_dialog_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget *gtk_font_selection_dialog_new (const gchar *title);
|
||||
GType gtk_font_selection_dialog_get_typei (void) G_GNUC_CONST;
|
||||
GtkWidget* gtk_font_selection_dialog_new (const gchar *title);
|
||||
|
||||
|
||||
GtkWidget *gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd);
|
||||
GtkWidget *gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd);
|
||||
GtkWidget* gtk_font_selection_dialog_get_cancel_button (GtkFontSelectionDialog *fsd);
|
||||
GtkWidget* gtk_font_selection_dialog_get_font_selection (GtkFontSelectionDialog *fsd);
|
||||
|
||||
/* This returns the X Logical Font Description fontname, or NULL if no font
|
||||
is selected. Note that there is a slight possibility that the font might not
|
||||
|
@ -33,6 +33,13 @@ notify_preview_text_cb (GObject *fontsel, GParamSpec *pspec, gpointer data)
|
||||
g_debug ("Changed preview text %s", gtk_font_selection_get_preview_text (GTK_FONT_SELECTION (fontsel)));
|
||||
}
|
||||
|
||||
static void
|
||||
notify_show_preview_entry_cb (GObject *fontsel, GParamSpec *pspec, gpointer data)
|
||||
{
|
||||
g_debug ("Changed show preview_entry %d",
|
||||
gtk_font_selection_get_show_preview_entry (GTK_FONT_SELECTION (fontsel)));
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@ -66,10 +73,14 @@ main (int argc, char *argv[])
|
||||
g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK(gtk_main_quit), NULL);
|
||||
g_signal_connect (G_OBJECT (fontsel), "notify::font-name", G_CALLBACK(notify_font_name_cb), NULL);
|
||||
g_signal_connect (G_OBJECT (fontsel), "notify::preview-text", G_CALLBACK(notify_preview_text_cb), NULL);
|
||||
g_signal_connect (G_OBJECT (fontsel), "notify::show-preview-entry",
|
||||
G_CALLBACK(notify_show_preview_entry_cb), NULL);
|
||||
|
||||
gtk_font_selection_set_font_name (GTK_FONT_SELECTION (fontsel), "Bitstream Vera Sans 45");
|
||||
gtk_font_selection_set_preview_text (GTK_FONT_SELECTION (fontsel), "[user@host ~]$ ");
|
||||
|
||||
gtk_font_selection_set_show_preview_entry (GTK_FONT_SELECTION (fontsel), FALSE);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
gtk_widget_destroy (window);
|
||||
|
Loading…
Reference in New Issue
Block a user