From e09d2a676cf77fadc41709fcc22c5471f4c52a9d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 13 Jul 2022 17:00:59 -0400 Subject: [PATCH] imcontext: Define a pango attribute for highlight Define our own PangoAttribute type for IM Context properties. Currently, the only defined property is for marking the highlighted region. --- gtk/gtkimcontext.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ gtk/gtkimcontext.h | 10 ++++++++++ 2 files changed, 57 insertions(+) diff --git a/gtk/gtkimcontext.c b/gtk/gtkimcontext.c index a46f5d7571..2577d27718 100644 --- a/gtk/gtkimcontext.c +++ b/gtk/gtkimcontext.c @@ -1005,3 +1005,50 @@ gtk_im_context_set_property (GObject *obj, break; } } + + +static PangoAttribute * +attr_preedit_properties_copy (const PangoAttribute *attr) +{ + const PangoAttrInt *int_attr = (PangoAttrInt *)attr; + + return gtk_im_context_preedit_attr_new (int_attr->value); +} + +static void +attr_preedit_properties_destroy (PangoAttribute *attr) +{ + PangoAttrInt *iattr = (PangoAttrInt *)attr; + + g_slice_free (PangoAttrInt, iattr); +} + +static gboolean +attr_preedit_properties_equal (const PangoAttribute *attr1, + const PangoAttribute *attr2) +{ + const PangoAttrInt *int_attr1 = (const PangoAttrInt *)attr1; + const PangoAttrInt *int_attr2 = (const PangoAttrInt *)attr2; + + return (int_attr1->value == int_attr2->value); +} + +PangoAttribute * +gtk_im_context_preedit_attr_new (GtkIMContextPreeditProperties value) +{ + PangoAttrInt *result = g_slice_new (PangoAttrInt); + static PangoAttrClass klass = { + 0, + attr_preedit_properties_copy, + attr_preedit_properties_destroy, + attr_preedit_properties_equal + }; + + if (!klass.type) + klass.type = pango_attr_type_register ("GtkIMContextPreeditProperties"); + + pango_attribute_init (&result->attr, &klass); + result->value = value; + + return (PangoAttribute *)result; +} diff --git a/gtk/gtkimcontext.h b/gtk/gtkimcontext.h index d4268d7e12..6c3bfd66ee 100644 --- a/gtk/gtkimcontext.h +++ b/gtk/gtkimcontext.h @@ -168,6 +168,16 @@ gboolean gtk_im_context_delete_surrounding (GtkIMContext *context, int offset, int n_chars); + +typedef enum +{ + GTK_IM_CONTEXT_PREEDIT_CURSOR, +} GtkIMContextPreeditProperties; + +GDK_AVAILABLE_IN_4_8 +PangoAttribute * gtk_im_context_preedit_attr_new (GtkIMContextPreeditProperties value); + + G_END_DECLS #endif /* __GTK_IM_CONTEXT_H__ */