diff --git a/gtk/gtk.h b/gtk/gtk.h index c076ab8c39..eca7326dad 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include diff --git a/gtk/gtkaccessibletext-private.h b/gtk/gtkaccessibletext-private.h new file mode 100644 index 0000000000..4650ab068c --- /dev/null +++ b/gtk/gtkaccessibletext-private.h @@ -0,0 +1,40 @@ +/* gtkaccessibletext-private.h: Private definitions for GtkAccessibleText + * + * SPDX-FileCopyrightText: 2023 Emmanuele Bassi + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#include "gtkaccessibletext.h" + +G_BEGIN_DECLS + +GBytes * +gtk_accessible_text_get_contents (GtkAccessibleText *self, + unsigned int start, + unsigned int end); + +GBytes * +gtk_accessible_text_get_contents_at (GtkAccessibleText *self, + unsigned int offset, + GtkAccessibleTextGranularity granularity, + unsigned int *start, + unsigned int *end); + +unsigned int +gtk_accessible_text_get_caret_position (GtkAccessibleText *self); + +gboolean +gtk_accessible_text_get_selection (GtkAccessibleText *self, + gsize *n_ranges, + GtkAccessibleTextRange **ranges); + +gboolean +gtk_accessible_text_get_attributes (GtkAccessibleText *self, + unsigned int offset, + gsize *n_ranges, + GtkAccessibleTextRange **ranges, + char ***attribute_names, + char ***attribute_values); +G_END_DECLS diff --git a/gtk/gtkaccessibletext.c b/gtk/gtkaccessibletext.c new file mode 100644 index 0000000000..6a74529069 --- /dev/null +++ b/gtk/gtkaccessibletext.c @@ -0,0 +1,354 @@ +/* gtkaccessibletext.c: Interface for accessible text objects + * + * SPDX-FileCopyrightText: 2023 Emmanuele Bassi + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#include "config.h" + +#include "gtkaccessibletext-private.h" + +#include "gtkatcontextprivate.h" + +G_DEFINE_INTERFACE (GtkAccessibleText, gtk_accessible_text, GTK_TYPE_ACCESSIBLE) + +static GBytes * +gtk_accessible_text_default_get_contents (GtkAccessibleText *self, + unsigned int start, + unsigned int end) +{ + return NULL; +} + +static GBytes * +gtk_accessible_text_default_get_contents_at (GtkAccessibleText *self, + unsigned int offset, + GtkAccessibleTextGranularity granularity, + unsigned int *start, + unsigned int *end) +{ + if (start != NULL) + *start = 0; + if (end != NULL) + *end = 0; + + return NULL; +} + +static unsigned int +gtk_accessible_text_default_get_caret_position (GtkAccessibleText *self) +{ + return 0; +} + +static gboolean +gtk_accessible_text_default_get_selection (GtkAccessibleText *self, + gsize *n_ranges, + GtkAccessibleTextRange **ranges) +{ + return FALSE; +} + +static gboolean +gtk_accessible_text_default_get_attributes (GtkAccessibleText *self, + unsigned int offset, + gsize *n_ranges, + GtkAccessibleTextRange **ranges, + char ***attribute_names, + char ***attribute_values) +{ + *attribute_names = NULL; + *attribute_values = NULL; + *n_ranges = 0; + return FALSE; +} + +static void +gtk_accessible_text_default_init (GtkAccessibleTextInterface *iface) +{ + iface->get_contents = gtk_accessible_text_default_get_contents; + iface->get_contents_at = gtk_accessible_text_default_get_contents_at; + iface->get_caret_position = gtk_accessible_text_default_get_caret_position; + iface->get_selection = gtk_accessible_text_default_get_selection; + iface->get_attributes = gtk_accessible_text_default_get_attributes; +} + +static GBytes * +nul_terminate_contents (GBytes *bytes) +{ + const char *data; + gsize size; + + data = g_bytes_get_data (bytes, &size); + if (size > 0 && data[size - 1] != '\0') + { + guchar *copy; + + copy = g_new (guchar, size + 1); + memcpy (copy, data, size); + copy[size] = '\0'; + + g_bytes_unref (bytes); + bytes = g_bytes_new_take (copy, size + 1); + } + + return bytes; +} + +/*< private > + * gtk_accessible_text_get_contents: + * @self: the accessible object + * @start: the beginning of the range, in characters + * @end: the end of the range, in characters + * + * Retrieve the current contents of the accessible object within + * the given range. + * + * If @end is `G_MAXUINT`, the end of the range is the full content of the + * accessible object. + * + * Returns: (transfer full): the requested slice of the contents of the + * accessible object, as NUL-terminated UTF-8 + * + * Since: 4.14 + */ +GBytes * +gtk_accessible_text_get_contents (GtkAccessibleText *self, + unsigned int start, + unsigned int end) +{ + GBytes *bytes; + + g_return_val_if_fail (GTK_IS_ACCESSIBLE_TEXT (self), NULL); + g_return_val_if_fail (end >= start, NULL); + + bytes = GTK_ACCESSIBLE_TEXT_GET_IFACE (self)->get_contents (self, start, end); + + return nul_terminate_contents (bytes); +} + +/*< private > + * gtk_accessible_text_get_contents_at: + * @self: the accessible object + * @offset: the offset of the text to retrieve + * @granularity: specify the boundaries of the text + * @start: (out): the starting offset of the contents, in characters + * @end: (out): the ending offset of the contents, in characters + * + * Retrieve the current contents of the accessible object at the given + * offset. + * + * Using the @granularity enumeration allows to adjust the offset so that + * this function can return the beginning of the word, line, or sentence; + * the initial and final boundaries are stored in @start and @end. + * + * Returns: (transfer full): the requested slice of the contents of the + * accessible object, as NUL-terminated UTF-8 buffer + * + * Since: 4.14 + */ +GBytes * +gtk_accessible_text_get_contents_at (GtkAccessibleText *self, + unsigned int offset, + GtkAccessibleTextGranularity granularity, + unsigned int *start, + unsigned int *end) +{ + GBytes *bytes; + + g_return_val_if_fail (GTK_IS_ACCESSIBLE_TEXT (self), NULL); + + bytes = GTK_ACCESSIBLE_TEXT_GET_IFACE (self)->get_contents_at (self, offset, granularity, start, end); + + return nul_terminate_contents (bytes); +} + +/*< private > + * gtk_accessible_text_get_caret_position: + * @self: the accessible object + * + * Retrieves the position of the caret inside the accessible object. + * + * If the accessible has no caret, 0 is returned. + * + * Returns: the position of the caret, in characters + * + * Since: 4.14 + */ +unsigned int +gtk_accessible_text_get_caret_position (GtkAccessibleText *self) +{ + g_return_val_if_fail (GTK_IS_ACCESSIBLE_TEXT (self), 0); + + return GTK_ACCESSIBLE_TEXT_GET_IFACE (self)->get_caret_position (self); +} + +/*< private > + * gtk_accessible_text_get_selection: + * @self: the accessible object + * @n_ranges: (out): the number of selection ranges + * @ranges: (optional) (out) (array length=n_ranges): the selection ranges + * + * Retrieves the selection ranges in the accessible object. + * + * If this function returns true, `n_ranges` will be set to a value + * greater than or equal to one, and @ranges will be set to a newly + * allocated array of [struct#Gtk.AccessibleTextRange]. + * + * Returns: true if there's at least one selected range inside the + * accessible object, and false otherwise + * + * Since: 4.14 + */ +gboolean +gtk_accessible_text_get_selection (GtkAccessibleText *self, + gsize *n_ranges, + GtkAccessibleTextRange **ranges) +{ + g_return_val_if_fail (GTK_IS_ACCESSIBLE_TEXT (self), FALSE); + + return GTK_ACCESSIBLE_TEXT_GET_IFACE (self)->get_selection (self, n_ranges, ranges); +} + +/*< private > + * gtk_accessible_text_get_attributes: + * @self: the accessible object + * @offset: the offset, in characters + * @n_ranges: (out): the number of attributes + * @ranges: (out) (array length=n_attributes) (optional): the ranges of the attributes + * inside the accessible object + * @attribute_names: (out) (array zero-terminated=1) (element-type utf8) (optional) (transfer full): + * the names of the attributes inside the accessible object + * @attribute_values: (out) (array zero-terminated=1) (element-type utf8) (optional) (transfer full): + * the values of the attributes inside the accessible object + * + * Retrieves the text attributes inside the accessible object. + * + * Each attribute is composed by: + * + * - a range + * - a name, typically in the form of a reverse DNS identifier + * - a value + * + * If this function returns true, `n_attributes` will be set to a value + * greater than or equal to one, @ranges will be set to a newly + * allocated array of [struct#Gtk.AccessibleTextRange] which should + * be freed with g_free(), @attribute_names and @attribute_values + * will be set to string arrays that should be freed with g_strfreev(). + * + * Returns: true if the accessible object has at least an attribute, + * and false otherwise + * + * Since: 4.14 + */ +gboolean +gtk_accessible_text_get_attributes (GtkAccessibleText *self, + unsigned int offset, + gsize *n_ranges, + GtkAccessibleTextRange **ranges, + char ***attribute_names, + char ***attribute_values) +{ + g_return_val_if_fail (GTK_IS_ACCESSIBLE_TEXT (self), FALSE); + + return GTK_ACCESSIBLE_TEXT_GET_IFACE (self)->get_attributes (self, + offset, + n_ranges, + ranges, + attribute_names, + attribute_values); +} + +/** + * gtk_accessible_text_update_caret_position: + * @self: the accessible object + * + * Updates the position of the caret. + * + * Implementations of the `GtkAccessibleText` interface should call this + * function every time the caret has moved, in order to notify assistive + * technologies. + * + * Since: 4.14 + */ +void +gtk_accessible_text_update_caret_position (GtkAccessibleText *self) +{ + GtkATContext *context; + + g_return_if_fail (GTK_IS_ACCESSIBLE_TEXT (self)); + + context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (self)); + if (context == NULL) + return; + + gtk_at_context_update_caret_position (context); + + g_object_unref (context); +} + +/** + * gtk_accessible_text_update_selection_bound: + * @self: the accessible object + * + * Updates the boundary of the selection. + * + * Implementations of the `GtkAccessibleText` interface should call this + * function every time the selection has moved, in order to notify assistive + * technologies. + * + * Since: 4.14 + */ +void +gtk_accessible_text_update_selection_bound (GtkAccessibleText *self) +{ + GtkATContext *context; + + g_return_if_fail (GTK_IS_ACCESSIBLE_TEXT (self)); + + context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (self)); + if (context == NULL) + return; + + gtk_at_context_update_selection_bound (context); + + g_object_unref (context); +} + +/** + * gtk_accessible_text_update_contents: + * @self: the accessible object + * @change: the type of change in the contents + * @start: the starting offset of the change, in characters + * @end: the end offset of the change, in characters + * + * Notifies assistive technologies of a change in contents. + * + * Implementations of the `GtkAccessibleText` interface should call this + * function every time their contents change as the result of an operation, + * like an insertion or a removal. + * + * Note: If the change is a deletion, this function must be called *before* + * removing the contents, if it is an insertion, it must be called *after* + * inserting the new contents. + * + * Since: 4.14 + */ +void +gtk_accessible_text_update_contents (GtkAccessibleText *self, + GtkAccessibleTextContentChange change, + unsigned int start, + unsigned int end) +{ + GtkATContext *context; + + g_return_if_fail (GTK_IS_ACCESSIBLE_TEXT (self)); + + context = gtk_accessible_get_at_context (GTK_ACCESSIBLE (self)); + if (context == NULL) + return; + + gtk_at_context_update_text_contents (context, change, start, end); + + g_object_unref (context); +} diff --git a/gtk/gtkaccessibletext.h b/gtk/gtkaccessibletext.h new file mode 100644 index 0000000000..5915f86c48 --- /dev/null +++ b/gtk/gtkaccessibletext.h @@ -0,0 +1,570 @@ +/* gtkaccessibletext.h: Interface for accessible objects containing text + * + * SPDX-FileCopyrightText: 2023 Emmanuele Bassi + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#pragma once + +#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_ACCESSIBLE_TEXT (gtk_accessible_text_get_type ()) + +/** + * GtkAccessibleText: + * + * An interface for accessible objects containing formatted text. + * + * The `GtkAccessibleText` interfaces is meant to be implemented by accessible + * objects that have text formatted with attributes, or non-trivial text contents. + * + * You should use the [enum@Gtk.AccessibleProperty.LABEL] or the + * [enum@Gtk.AccessibleProperty.DESCRIPTION] properties for accessible + * objects containing simple, unformatted text. + * + * Since: 4.14 + */ +GDK_AVAILABLE_IN_4_14 +G_DECLARE_INTERFACE (GtkAccessibleText, gtk_accessible_text, GTK, ACCESSIBLE_TEXT, GtkAccessible) + +/** + * GtkAccessibleTextRange: + * @start: the start of the range, in characters + * @length: the length of the range, in characters + * + * A range inside the text of an accessible object. + * + * Since: 4.14 + */ +typedef struct { + gsize start; + gsize length; +} GtkAccessibleTextRange; + +/** + * GtkAccessibleTextGranularity: + * @GTK_ACCESSIBLE_TEXT_GRANULARITY_CHARACTER: Use the boundary between + * characters (including non-printing characters) + * @GTK_ACCESSIBLE_TEXT_GRANULARITY_WORD: Use the boundary between words, + * starting from the beginning of the current word and ending at the + * beginning of the next word + * @GTK_ACCESSIBLE_TEXT_GRANULARITY_SENTENCE: Use the boundary between + * sentences, starting from the beginning of the current sentence and + * ending at the beginning of the next sentence + * @GTK_ACCESSIBLE_TEXT_GRANULARITY_LINE: Use the boundary between lines, + * starting from the beginning of the current line and ending at the + * beginning of the next line + * @GTK_ACCESSIBLE_TEXT_GRANULARITY_PARAGRAPH: Use the boundary between + * paragraphs, starting from the beginning of the current paragraph and + * ending at the beginning of the next paragraph + * + * The granularity for queries about the text contents of a [iface@Gtk.AccessibleText] + * implementation. + * + * Since: 4.14 + */ +typedef enum { + GTK_ACCESSIBLE_TEXT_GRANULARITY_CHARACTER, + GTK_ACCESSIBLE_TEXT_GRANULARITY_WORD, + GTK_ACCESSIBLE_TEXT_GRANULARITY_SENTENCE, + GTK_ACCESSIBLE_TEXT_GRANULARITY_LINE, + GTK_ACCESSIBLE_TEXT_GRANULARITY_PARAGRAPH +} GtkAccessibleTextGranularity; + +/** + * GtkAccessibleTextContentChange: + * @GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_INSERT: contents change as the result of + * an insert operation + * @GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_REMOVE: contents change as the result of + * a remove operation + * + * The type of contents change operation. + * + * Since: 4.14 + */ +typedef enum { + GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_INSERT, + GTK_ACCESSIBLE_TEXT_CONTENT_CHANGE_REMOVE +} GtkAccessibleTextContentChange; + +/** + * GtkAccessibleTextInterface: + * + * The interface vtable for accessible objects containing text. + * + * Since: 4.14 + */ +struct _GtkAccessibleTextInterface +{ + /*< private >*/ + GTypeInterface g_iface; + + /*< public >*/ + + /** + * GtkAccessibleTextInterface::get_contents: + * @self: the accessible object + * @start: the beginning of the range, in characters + * @end: the end of the range, in characters + * + * Retrieve the current contents of the accessible object within + * the given range. + * + * If @end is `G_MAXUINT`, the end of the range is the full content + * of the accessible object. + * + * Returns: (transfer full): the requested slice of the contents of the + * accessible object, as UTF-8. Note that the slice does not have to + * be NUL-terminated + * + * Since: 4.14 + */ + GBytes * (* get_contents) (GtkAccessibleText *self, + unsigned int start, + unsigned int end); + + /** + * GtkAccessibleTextInterface::get_contents_at: + * @self: the accessible object + * @offset: the offset, in characters + * @granularity: the granularity of the query + * @start: (out): the start of the range, in characters + * @end: (out): the end of the range, in characters + * + * Retrieve the current contents of the accessible object starting + * from the given offset, and using the given granularity. + * + * The @start and @end values contain the boundaries of the text. + * + * Returns: (transfer full): the requested slice of the contents of the + * accessible object, as UTF-8. Note that the slice does not have to + * be NUL-terminated + * + * Since: 4.14 + */ + GBytes * (* get_contents_at) (GtkAccessibleText *self, + unsigned int offset, + GtkAccessibleTextGranularity granularity, + unsigned int *start, + unsigned int *end); + + /** + * GtkAccessibleTextInterface::get_caret_position: + * @self: the accessible object + * + * Retrieves the position of the caret inside the accessible object. + * + * Returns: the position of the caret, in characters + * + * Since: 4.14 + */ + unsigned int (* get_caret_position) (GtkAccessibleText *self); + + /** + * GtkAccessibleTextInterface::get_selection: + * @self: the accessible object + * @n_ranges: (out): the number of selection ranges + * @ranges: (optional) (out) (array length=n_ranges) (transfer container): the selection ranges + * + * Retrieves the selection ranges in the accessible object. + * + * If this function returns true, `n_ranges` will be set to a value + * greater than or equal to one, and @ranges will be set to a newly + * allocated array of [struct#Gtk.AccessibleTextRange]. + * + * Returns: true if there is at least a selection inside the + * accessible object, and false otherwise + * + * Since: 4.14 + */ + gboolean (* get_selection) (GtkAccessibleText *self, + gsize *n_ranges, + GtkAccessibleTextRange **ranges); + + /** + * GtkAccessibleTextInterface::get_attributes: + * @self: the accessible object + * @offset: the offset, in characters + * @n_ranges: (out): the number of attributes + * @ranges: (out) (array length=n_ranges) (optional) (transfer container): the ranges of the attributes + * inside the accessible object + * @attribute_names: (out) (array zero-terminated=1) (optional) (transfer full): the + * names of the attributes inside the accessible object + * @attribute_values: (out) (array zero-terminated=1) (optional) (transfer full): the + * values of the attributes inside the accessible object + * + * Retrieves the text attributes inside the accessible object. + * + * Each attribute is composed by: + * + * - a range + * - a name + * - a value + * + * It is left to the implementation to determine the serialization format + * of the value to a string. + * + * GTK provides support for various text attribute names and values, but + * implementations of this interface are free to add their own attributes. + * + * If this function returns true, `n_ranges` will be set to a value + * greater than or equal to one, @ranges will be set to a newly + * allocated array of [struct#Gtk.AccessibleTextRange]. + * + * Returns: true if the accessible object has at least an attribute, + * and false otherwise + * + * Since: 4.14 + */ + gboolean (* get_attributes) (GtkAccessibleText *self, + unsigned int offset, + gsize *n_ranges, + GtkAccessibleTextRange **ranges, + char ***attribute_names, + char ***attribute_values); +}; + +GDK_AVAILABLE_IN_4_14 +void gtk_accessible_text_update_caret_position (GtkAccessibleText *self); + +GDK_AVAILABLE_IN_4_14 +void gtk_accessible_text_update_selection_bound (GtkAccessibleText *self); + +GDK_AVAILABLE_IN_4_14 +void gtk_accessible_text_update_contents (GtkAccessibleText *self, + GtkAccessibleTextContentChange change, + unsigned int start, + unsigned int end); + +/** + * GTK_ACCESSIBLE_ATTRIBUTE_FAMILY: + * + * An attribute for the font family name. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_FAMILY "family-name" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STYLE: + * + * An attribute for the font style. + * + * Possible values are: + * + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STYLE_NORMAL] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STYLE_OBLIQUE] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STYLE_ITALIC] + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STYLE "style" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_WEIGHT: + * + * An attribute for the font weight. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_WEIGHT "weight" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT: + * + * An attribute for the font variant. + * + * Possible values are: + * + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT_SMALL_CAPS] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT_ALL_SMALL_CAPS] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT_PETITE_CAPS] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT_ALL_PETITE_CAPS] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT_UNICASE] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT_TITLE_CAPS] + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT "variant" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH: + * + * An attribute for the font stretch type. + * + * Possible values are: + * + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH_ULTRA_CONDENSED] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH_EXTRA_CONDENSED] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH_CONDENSED] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH_SEMI_CONDENSED] + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH "stretch" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_SIZE: + * + * An attribute for the font size, expressed in points. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_SIZE "size" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_FOREGROUND: + * + * An attribute for the foreground color, expressed as an RGB value + * encoded in a string using the format: `{r8},{g8},{b8}`. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_FOREGROUND "fg-color" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_BACKGROUND: + * + * An attribute for the background color, expressed as an RGB value + * encoded in a string using the format: `{r8},{g8},{b8}`. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_BACKGROUND "bg-color" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE: + * + * An attribute for the underline style. + * + * Possible values are: + * + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE_NONE] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE_SINGLE] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE_DOUBLE] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE_ERROR] + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE "underline" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_OVERLINE: + * + * An attribute for the overline style. + * + * Possible values are: + * + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_OVERLINE_NONE] + * - [const@Gtk.ACCESSIBLE_ATTRIBUTE_OVERLINE_SINGLE] + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_OVERLINE "overline" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRIKETHROUGH: + * + * An attribute for strikethrough text. + * + * Possible values are `true` or `false`. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRIKETHROUGH "strikethrough" + +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STYLE_NORMAL: + * + * The "normal" style value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STYLE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STYLE_NORMAL "normal" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STYLE_OBLIQUE: + * + * The "oblique" style value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STYLE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STYLE_OBLIQUE "oblique" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STYLE_ITALIC: + * + * The "italic" style value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STYLE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STYLE_ITALIC "italic" + +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_SMALL_CAPS: + * + * The "small caps" variant value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_SMALL_CAPS "small-caps" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_ALL_SMALL_CAPS: + * + * The "all small caps" variant value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_ALL_SMALL_CAPS "all-small-caps" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_PETITE_CAPS: + * + * The "petite caps" variant value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_PETITE_CAPS "petite-caps" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_ALL_PETITE_CAPS: + * + * The "all petite caps" variant value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_ALL_PETITE_CAPS "all-petite-caps" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_UNICASE: + * + * The "unicase" variant value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_UNICASE "unicase" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_TITLE_CAPS: + * + * The "title caps" variant value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_VARIANT]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_VARIANT_TITLE_CAPS "title-caps" + +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_ULTRA_CONDENSED: + * + * The "ultra condensed" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_ULTRA_CONDENSED "ultra_condensed" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_EXTRA_CONDENSED: + * + * The "extra condensed" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_EXTRA_CONDENSED "extra_condensed" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_CONDENSED: + * + * The "condensed" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_CONDENSED "condensed" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_SEMI_CONDENSED: + * + * The "semi condensed" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_SEMI_CONDENSED "semi_condensed" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_NORMAL: + * + * The "normal" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_NORMAL "normal" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_SEMI_EXPANDED: + * + * The "semi expanded" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_SEMI_EXPANDED "semi_expanded" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_EXPANDED: + * + * The "expanded" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_EXPANDED "expanded" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_EXTRA_EXPANDED: + * + * The "extra expanded" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_EXTRA_EXPANDED "extra_expanded" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_ULTRA_EXPANDED: + * + * The "ultra expanded" stretch value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_STRETCH]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_STRETCH_ULTRA_EXPANDED "ultra_expanded" + +/** + * GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_NONE: + * + * The "none" underline value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_NONE "none" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_SINGLE: + * + * The "single" underline value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_SINGLE "single" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_DOUBLE: + * + * The "double" underline value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_DOUBLE "double" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_ERROR: + * + * The "error" underline value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_UNDERLINE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_UNDERLINE_ERROR "error" + +/** + * GTK_ACCESSIBLE_ATTRIBUTE_OVERLINE_NONE: + * + * The "none" overline value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_OVERLINE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_OVERLINE_NONE "none" +/** + * GTK_ACCESSIBLE_ATTRIBUTE_OVERLINE_SINGLE: + * + * The "single" overline value for [const@Gtk.ACCESSIBLE_ATTRIBUTE_OVERLINE]. + * + * Since: 4.14 + */ +#define GTK_ACCESSIBLE_ATTRIBUTE_OVERLINE_SINGLE "single" + + +G_END_DECLS diff --git a/gtk/gtkatcontext.c b/gtk/gtkatcontext.c index 7f5120e604..77cdba7c90 100644 --- a/gtk/gtkatcontext.c +++ b/gtk/gtkatcontext.c @@ -207,6 +207,24 @@ gtk_at_context_real_unrealize (GtkATContext *self) { } +static void +gtk_at_context_real_update_caret_position (GtkATContext *self) +{ +} + +static void +gtk_at_context_real_update_selection_bound (GtkATContext *self) +{ +} + +static void +gtk_at_context_real_update_text_contents (GtkATContext *self, + GtkAccessibleTextContentChange change, + unsigned int start, + unsigned int end) +{ +} + static void gtk_at_context_class_init (GtkATContextClass *klass) { @@ -223,6 +241,9 @@ gtk_at_context_class_init (GtkATContextClass *klass) klass->platform_change = gtk_at_context_real_platform_change; klass->bounds_change = gtk_at_context_real_bounds_change; klass->child_change = gtk_at_context_real_child_change; + klass->update_caret_position = gtk_at_context_real_update_caret_position; + klass->update_selection_bound = gtk_at_context_real_update_selection_bound; + klass->update_text_contents = gtk_at_context_real_update_text_contents; /** * GtkATContext:accessible-role: (attributes org.gtk.Property.get=gtk_at_context_get_accessible_role) @@ -1508,3 +1529,33 @@ gtk_at_context_announce (GtkATContext *self, GTK_AT_CONTEXT_GET_CLASS (self)->announce (self, message, priority); } + +void +gtk_at_context_update_caret_position (GtkATContext *self) +{ + if (!self->realized) + return; + + GTK_AT_CONTEXT_GET_CLASS (self)->update_caret_position (self); +} + +void +gtk_at_context_update_selection_bound (GtkATContext *self) +{ + if (!self->realized) + return; + + GTK_AT_CONTEXT_GET_CLASS (self)->update_selection_bound (self); +} + +void +gtk_at_context_update_text_contents (GtkATContext *self, + GtkAccessibleTextContentChange change, + unsigned int start, + unsigned int end) +{ + if (!self->realized) + return; + + GTK_AT_CONTEXT_GET_CLASS (self)->update_text_contents (self, change, start, end); +} diff --git a/gtk/gtkatcontextprivate.h b/gtk/gtkatcontextprivate.h index e65b5f8279..189ce02335 100644 --- a/gtk/gtkatcontextprivate.h +++ b/gtk/gtkatcontextprivate.h @@ -24,6 +24,7 @@ #include "gtkaccessibleprivate.h" #include "gtkaccessibleattributesetprivate.h" +#include "gtkaccessibletext.h" G_BEGIN_DECLS @@ -131,6 +132,14 @@ struct _GtkATContextClass void (* announce) (GtkATContext *self, const char *message, GtkAccessibleAnnouncementPriority priority); + + /* Text interface */ + void (* update_caret_position) (GtkATContext *self); + void (* update_selection_bound) (GtkATContext *self); + void (* update_text_contents) (GtkATContext *self, + GtkAccessibleTextContentChange change, + unsigned int start, + unsigned int end); }; GtkATContext * gtk_at_context_clone (GtkATContext *self, @@ -200,5 +209,14 @@ gtk_at_context_set_next_accessible_sibling (GtkATContext *self, void gtk_at_context_announce (GtkATContext *self, const char *message, GtkAccessibleAnnouncementPriority priority); +void +gtk_at_context_update_caret_position (GtkATContext *self); +void +gtk_at_context_update_selection_bound (GtkATContext *self); +void +gtk_at_context_update_text_contents (GtkATContext *self, + GtkAccessibleTextContentChange change, + unsigned int start, + unsigned int end); G_END_DECLS diff --git a/gtk/meson.build b/gtk/meson.build index 8a126be24f..436a167ff0 100644 --- a/gtk/meson.build +++ b/gtk/meson.build @@ -155,6 +155,7 @@ gtk_public_sources = files([ 'gtkaccelgroup.c', 'gtkaccessible.c', 'gtkaccessiblerange.c', + 'gtkaccessibletext.c', 'gtkactionable.c', 'gtkactionbar.c', 'gtkadjustment.c', @@ -417,6 +418,7 @@ gtk_public_headers = files([ 'gtkaccelgroup.h', 'gtkaccessible.h', 'gtkaccessiblerange.h', + 'gtkaccessibletext.h', 'gtkactionable.h', 'gtkactionbar.h', 'gtkadjustment.h',