summaryrefslogtreecommitdiff
path: root/gtk/gtktextview.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2014-10-07 00:39:42 -0400
committerMatthias Clasen <mclasen@redhat.com>2014-10-07 00:39:42 -0400
commit0004e667abdab749b991d320ed4f735778385766 (patch)
tree71030a2d3fc89f33a51245c8df301af0beba149a /gtk/gtktextview.c
parent2dfc03bdb532c14187aa14bf51adc1aec3b71b62 (diff)
downloadgtk+-0004e667abdab749b991d320ed4f735778385766.tar.gz
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.
Diffstat (limited to 'gtk/gtktextview.c')
-rw-r--r--gtk/gtktextview.c82
1 files changed, 81 insertions, 1 deletions
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 15433366fa..0ba3c5b2fc 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);
+}