[gtk+] GtkTextView: Add a monospace property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] GtkTextView: Add a monospace property
- Date: Tue, 7 Oct 2014 04:48:50 +0000 (UTC)
commit 0004e667abdab749b991d320ed4f735778385766
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Oct 7 00:39:42 2014 -0400
GtkTextView: Add a monospace property
This is a convenient shortcut for a common case. It is implemented
by adding a .monospace style class to the text view, and letting
the theme decide about the monospace font to use.
docs/reference/gtk/gtk3-sections.txt | 3 +
gtk/gtkstylecontext.h | 10 ++++
gtk/gtktextview.c | 82 +++++++++++++++++++++++++++++++++-
gtk/gtktextview.h | 5 ++
4 files changed, 99 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 81576ca..6a1dacb 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -3888,6 +3888,8 @@ gtk_text_view_set_input_purpose
gtk_text_view_get_input_purpose
gtk_text_view_set_input_hints
gtk_text_view_get_input_hints
+gtk_text_view_set_monospace
+gtk_text_view_get_monospace
GTK_TEXT_VIEW_PRIORITY_VALIDATE
<SUBSECTION Standard>
GTK_TEXT_VIEW
@@ -6011,6 +6013,7 @@ GTK_STYLE_CLASS_MENU
GTK_STYLE_CLASS_MENUBAR
GTK_STYLE_CLASS_MENUITEM
GTK_STYLE_CLASS_MESSAGE_DIALOG
+GTK_STYLE_CLASS_MONOSPACE
GTK_STYLE_CLASS_NEEDS_ATTENTION
GTK_STYLE_CLASS_NOTEBOOK
GTK_STYLE_CLASS_OSD
diff --git a/gtk/gtkstylecontext.h b/gtk/gtkstylecontext.h
index b1e65dd..6e22a6c 100644
--- a/gtk/gtkstylecontext.h
+++ b/gtk/gtkstylecontext.h
@@ -896,6 +896,16 @@ struct _GtkStyleContextClass
#define GTK_STYLE_CLASS_PAPER "paper"
/**
+ * GTK_STYLE_CLASS_MONOSPACE:
+ *
+ * A CSS class that is added to text view that should use
+ * a monospace font.
+ *
+ * Since: 3.16
+ */
+#define GTK_STYLE_CLASS_MONOSPACE "monospace"
+
+/**
* GTK_STYLE_REGION_ROW:
*
* A widget region name to define a treeview row.
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 1543336..0ba3c5b 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -308,7 +308,8 @@ enum
PROP_VSCROLL_POLICY,
PROP_INPUT_PURPOSE,
PROP_INPUT_HINTS,
- PROP_POPULATE_ALL
+ PROP_POPULATE_ALL,
+ PROP_MONOSPACE
};
static GQuark quark_text_selection_data = 0;
@@ -905,6 +906,23 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+ /**
+ * GtkTextview:monospace:
+ *
+ * If %TRUE, set the %GTK_STYLE_CLASS_MONOSPACE style class on the
+ * text view to indicate that a monospace font is desired.
+ *
+ * Since: 3.16
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_MONOSPACE,
+ g_param_spec_boolean ("monospace",
+ P_("Monospace"),
+ P_("Whether to use a monospace font"),
+ FALSE,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
+
/* GtkScrollable interface */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
@@ -3389,6 +3407,9 @@ gtk_text_view_set_property (GObject *object,
g_object_notify_by_pspec (object, pspec);
}
break;
+ case PROP_MONOSPACE:
+ gtk_text_view_set_monospace (text_view, g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -3498,6 +3519,10 @@ gtk_text_view_get_property (GObject *object,
g_value_set_boolean (value, priv->populate_all);
break;
+ case PROP_MONOSPACE:
+ g_value_set_boolean (value, gtk_text_view_get_monospace (text_view));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -10558,3 +10583,58 @@ gtk_text_view_get_input_hints (GtkTextView *text_view)
return hints;
}
+
+/**
+ * gtk_text_view_set_monospace:
+ * @text_view: a #GtkTextView
+ * @monospace: %TRUE to request monospace styling
+ *
+ * Sets the #GtkTextView:monospace property, which
+ * indicates that the text view should use monospace
+ * fonts.
+ *
+ * Since: 3.16
+ */
+void
+gtk_text_view_set_monospace (GtkTextView *text_view,
+ gboolean monospace)
+{
+ GtkStyleContext *context;
+ gboolean has_monospace;
+
+ g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
+ has_monospace = gtk_style_context_has_class (context, GTK_STYLE_CLASS_MONOSPACE);
+
+ if (has_monospace != monospace)
+ {
+ if (monospace)
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_MONOSPACE);
+ else
+ gtk_style_context_remove_class (context, GTK_STYLE_CLASS_MONOSPACE);
+ g_object_notify (G_OBJECT (text_view), "monospace");
+ }
+}
+
+/**
+ * gtk_text_view_get_monospace:
+ * @text_view: a #GtkTextView
+ *
+ * Gets the value of the #GtkTextView:monospace property.
+ *
+ * Return: %TRUE if monospace fonts are desired
+ *
+ * Since: 3.16
+ */
+gboolean
+gtk_text_view_get_monospace (GtkTextView *text_view)
+{
+ GtkStyleContext *context;
+
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), FALSE);
+
+ context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
+
+ return gtk_style_context_has_class (context, GTK_STYLE_CLASS_MONOSPACE);
+}
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h
index 23ff349..df1f5d9 100644
--- a/gtk/gtktextview.h
+++ b/gtk/gtktextview.h
@@ -408,6 +408,11 @@ void gtk_text_view_set_input_hints (GtkTextView *text_vi
GDK_AVAILABLE_IN_3_6
GtkInputHints gtk_text_view_get_input_hints (GtkTextView *text_view);
+GDK_AVAILABLE_IN_3_16
+void gtk_text_view_set_monospace (GtkTextView *text_view,
+ gboolean monospace);
+GDK_AVAILABLE_IN_3_16
+gboolean gtk_text_view_get_monospace (GtkTextView *text_view);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]