summaryrefslogtreecommitdiff
path: root/gtk/gtktextattributesprivate.h
diff options
context:
space:
mode:
authorChristian Hergert <christian@hergert.me>2015-02-09 16:41:48 -0800
committerMatthias Clasen <mclasen@redhat.com>2015-03-17 23:24:13 -0400
commit28063ee2e42e7ce47b7bd5326f2d53875a377d57 (patch)
treece7c2ca0667be5fee723de429ff60d1195cbe822 /gtk/gtktextattributesprivate.h
parent416c370da1d2eff2458e4a0c5b8e504cd8061559 (diff)
downloadgtk+-28063ee2e42e7ce47b7bd5326f2d53875a377d57.tar.gz
textview: add support for underline and strikethrough colors
This commit adds the GtkTextTag:underline-rgba and :strikethrough-rgba properties and the necessary plumbing to apply these colors in GtkTextLayout. With this change, you can alter the color of underlines including those of type PANGO_UNDERLINE_ERROR. You might want to alter the underline color to differentiate between spelling and grammer mistakes. In code editors, it is convenient to differentiate between errors and warnings. Note that the GtkTextAppearance struct is public ABI and has no spare room for new fields, so we are resorting to some tricky packing to store the colors in the unused pixel field of the fg_color and bg_color structs. This packing is accomplished by the macros in gtktextattributesprivate.h. Signed-off-by: Christian Hergert <christian@hergert.me> https://bugzilla.gnome.org/show_bug.cgi?id=402168
Diffstat (limited to 'gtk/gtktextattributesprivate.h')
-rw-r--r--gtk/gtktextattributesprivate.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/gtk/gtktextattributesprivate.h b/gtk/gtktextattributesprivate.h
new file mode 100644
index 0000000000..45bc07b801
--- /dev/null
+++ b/gtk/gtktextattributesprivate.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2015 Christian Hergert <chergert@gnome.org>
+ *
+ * This program 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 program 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Christian Hergert <chergert@gnome.org>
+ *
+ */
+
+#ifndef __GTK_TEXT_ATTRIBUTE_PRIVATE_H__
+#define __GTK_TEXT_ATTRIBUTE_PRIVATE_H__
+
+/*
+ * The following macros are used to store and extract information about the
+ * Pango underline and strikethrough colors in the unused pixel member of
+ * the GdkColor members of GtkTextAppearance.
+ *
+ * In 4.0, we should revisit this.
+ */
+
+#define GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA_SET(appr) \
+ (((guint8*)&(appr)->bg_color)[3] != 0)
+#define GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA_SET(appr,val) \
+ G_STMT_START { \
+ ((guint8*)&(appr)->bg_color)[3] = !!val; \
+ } G_STMT_END
+#define GTK_TEXT_APPEARANCE_GET_UNDERLINE_RGBA(appr,rgba) \
+ G_STMT_START { \
+ (rgba)->red = ((guint8*)&(appr)->bg_color)[0] / 255.; \
+ (rgba)->green = ((guint8*)&(appr)->bg_color)[1] / 255.; \
+ (rgba)->blue = ((guint8*)&(appr)->bg_color)[2] / 255.; \
+ (rgba)->alpha = 1.0; \
+ } G_STMT_END
+#define GTK_TEXT_APPEARANCE_SET_UNDERLINE_RGBA(appr,rgba) \
+ G_STMT_START { \
+ ((guint8*)&(appr)->bg_color)[0] = (rgba)->red * 255; \
+ ((guint8*)&(appr)->bg_color)[1] = (rgba)->green * 255; \
+ ((guint8*)&(appr)->bg_color)[2] = (rgba)->blue * 255; \
+ } G_STMT_END
+
+
+#define GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA_SET(appr) \
+ (((guint8*)&(appr)->fg_color)[3] != 0)
+#define GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA_SET(appr,val) \
+ G_STMT_START { \
+ ((guint8*)&(appr)->fg_color)[3] = !!val; \
+ } G_STMT_END
+#define GTK_TEXT_APPEARANCE_GET_STRIKETHROUGH_RGBA(appr,rgba) \
+ G_STMT_START { \
+ (rgba)->red = ((guint8*)&(appr)->fg_color)[0] / 255.; \
+ (rgba)->green = ((guint8*)&(appr)->fg_color)[1] / 255.; \
+ (rgba)->blue = ((guint8*)&(appr)->fg_color)[2] / 255.; \
+ (rgba)->alpha = 1.0; \
+ } G_STMT_END
+#define GTK_TEXT_APPEARANCE_SET_STRIKETHROUGH_RGBA(appr,rgba) \
+ G_STMT_START { \
+ ((guint8*)&(appr)->fg_color)[0] = (rgba)->red * 255; \
+ ((guint8*)&(appr)->fg_color)[1] = (rgba)->green * 255; \
+ ((guint8*)&(appr)->fg_color)[2] = (rgba)->blue * 255; \
+ } G_STMT_END
+
+
+#endif /* __GTK_TEXT_ATTRIBUTE_PRIVATE_H__ */