| 1 | /* gtkaccessibleattributeset.c: Accessible attribute content |
| 2 | * |
| 3 | * Copyright 2020 GNOME Foundation |
| 4 | * |
| 5 | * SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "config.h"cxx . . $ `<file>/build/config.h`/ |
| 22 | |
| 23 | #include "gtkaccessibleattributesetprivate.h"cxx . . $ `<file>/gtk/gtkaccessibleattributesetprivate.h`/ |
| 24 | |
| 25 | #include "gtkbitmaskprivate.h"cxx . . $ `<file>/gtk/gtkbitmaskprivate.h`/ |
| 26 | #include "gtkenums.h"cxx . . $ `<file>/gtk/gtkenums.h`/ |
| 27 | |
| 28 | struct _GtkAccessibleAttributeSetcxx . . $ _GtkAccessibleAttributeSet# |
| 29 | { |
| 30 | gsizecxx . . $ gsize# n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes.; |
| 31 | |
| 32 | GtkAccessibleAttributeNameFunccxx . . $ GtkAccessibleAttributeNameFunc# name_funccxx . . $ _GtkAccessibleAttributeSet#name_func.; |
| 33 | GtkAccessibleAttributeDefaultFunccxx . . $ GtkAccessibleAttributeDefaultFunc# default_funccxx . . $ _GtkAccessibleAttributeSet#default_func.; |
| 34 | |
| 35 | GtkBitmaskcxx . . $ GtkBitmask# *attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set.; |
| 36 | |
| 37 | GtkAccessibleValuecxx . . $ GtkAccessibleValue# **attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.; |
| 38 | }; |
| 39 | |
| 40 | static GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# * |
| 41 | gtk_accessible_attribute_set_initcxx . . $ gtk_accessible_attribute_set_init(85a03811a74f1a16). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self, |
| 42 | gsizecxx . . $ gsize# n_attributes, |
| 43 | GtkAccessibleAttributeNameFunccxx . . $ GtkAccessibleAttributeNameFunc# name_func, |
| 44 | GtkAccessibleAttributeDefaultFunccxx . . $ GtkAccessibleAttributeDefaultFunc# default_func) |
| 45 | { |
| 46 | self->n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes. = n_attributes; |
| 47 | self->name_funccxx . . $ _GtkAccessibleAttributeSet#name_func. = name_func; |
| 48 | self->default_funccxx . . $ _GtkAccessibleAttributeSet#default_func. = default_func; |
| 49 | self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values. = g_newcxx . . $ `<external>/1123956534522462559/gmem.h:318:9`! (GtkAccessibleValue *, n_attributes); |
| 50 | self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set. = _gtk_bitmask_newcxx . . $ _gtk_bitmask_new(362ac8b55a0f6712). (); |
| 51 | |
| 52 | /* Initialize all attribute values, so we can always get the full attribute */ |
| 53 | for (int i = 0; i < self->n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes.; i++) |
| 54 | self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[i] = (* self->default_funccxx . . $ _GtkAccessibleAttributeSet#default_func.) (i); |
| 55 | |
| 56 | return self; |
| 57 | } |
| 58 | |
| 59 | GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# * |
| 60 | gtk_accessible_attribute_set_newcxx . . $ gtk_accessible_attribute_set_new(b75a289cabe10d0). (gsizecxx . . $ gsize# n_attributes, |
| 61 | GtkAccessibleAttributeNameFunccxx . . $ GtkAccessibleAttributeNameFunc# name_func, |
| 62 | GtkAccessibleAttributeDefaultFunccxx . . $ GtkAccessibleAttributeDefaultFunc# default_func) |
| 63 | { |
| 64 | GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *set = g_rc_box_new0cxx . . $ `<external>/5328180481899758773/grcbox.h:70:9`! (GtkAccessibleAttributeSet); |
| 65 | |
| 66 | return gtk_accessible_attribute_set_initcxx . . $ gtk_accessible_attribute_set_init(85a03811a74f1a16). (set, n_attributes, name_func, default_func); |
| 67 | } |
| 68 | |
| 69 | GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# * |
| 70 | gtk_accessible_attribute_set_refcxx . . $ gtk_accessible_attribute_set_ref(9cc1e19785bc15a7). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self) |
| 71 | { |
| 72 | g_return_val_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:665:9`! (self != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 73 | |
| 74 | return g_rc_box_acquirecxx . . $ `<external>/5328180481899758773/grcbox.h:79:9`! (self); |
| 75 | } |
| 76 | |
| 77 | static void |
| 78 | gtk_accessible_attribute_set_freecxx . . $ gtk_accessible_attribute_set_free(5d22bdacc48458e8). (gpointercxx . . $ gpointer# data) |
| 79 | { |
| 80 | GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self = data; |
| 81 | |
| 82 | for (int i = 0; i < self->n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes.; i++) |
| 83 | { |
| 84 | if (self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 85 | gtk_accessible_value_unrefcxx . . $ gtk_accessible_value_unref(be6d3a8c1739e9e2). (self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[i]); |
| 86 | } |
| 87 | |
| 88 | g_freecxx . . $ g_free(5d22bdacc48458e8). (self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.); |
| 89 | |
| 90 | _gtk_bitmask_freecxx . . $ _gtk_bitmask_free(44a0a5f2c5822bdd). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set.); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | gtk_accessible_attribute_set_unrefcxx . . $ gtk_accessible_attribute_set_unref(c21fc9a285bb0d07). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self) |
| 95 | { |
| 96 | g_rc_box_release_fullcxx . . $ g_rc_box_release_full(17a496daa110fa54). (self, gtk_accessible_attribute_set_freecxx . . $ gtk_accessible_attribute_set_free(5d22bdacc48458e8).); |
| 97 | } |
| 98 | |
| 99 | /*< private > |
| 100 | * gtk_accessible_attribute_set_add: |
| 101 | * @self: a `GtkAccessibleAttributeSet` |
| 102 | * @attribute: the attribute to set |
| 103 | * @value: (nullable): a `GtkAccessibleValue` |
| 104 | * |
| 105 | * Adds @attribute to the attributes set, and sets its value. |
| 106 | * |
| 107 | * If @value is %NULL, the @attribute is reset to its default value. |
| 108 | * |
| 109 | * If you want to remove @attribute from the set, use gtk_accessible_attribute_set_remove() |
| 110 | * instead. |
| 111 | * |
| 112 | * Returns: %TRUE if the set was modified, and %FALSE otherwise |
| 113 | */ |
| 114 | gbooleancxx . . $ gboolean# |
| 115 | gtk_accessible_attribute_set_addcxx . . $ gtk_accessible_attribute_set_add(e85350845ca98f08). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self, |
| 116 | int attribute, |
| 117 | GtkAccessibleValuecxx . . $ GtkAccessibleValue# *value) |
| 118 | { |
| 119 | g_return_val_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:665:9`! (attribute >= 0 && attribute < self->n_attributes, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!); |
| 120 | |
| 121 | if (value != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 122 | { |
| 123 | if (gtk_accessible_value_equalcxx . . $ gtk_accessible_value_equal(8353f3deb8379b4b). (value, self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[attribute])) |
| 124 | { |
| 125 | if (!_gtk_bitmask_getcxx . . $ _gtk_bitmask_get(ec1f9572e2cb12df). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute)) |
| 126 | { |
| 127 | self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set. = _gtk_bitmask_setcxx . . $ _gtk_bitmask_set(d4be56091f3b3606). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!); |
| 128 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 129 | } |
| 130 | else |
| 131 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 132 | } |
| 133 | } |
| 134 | else |
| 135 | { |
| 136 | if (!_gtk_bitmask_getcxx . . $ _gtk_bitmask_get(ec1f9572e2cb12df). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute)) |
| 137 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 138 | } |
| 139 | |
| 140 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&(self->attribute_values[attribute]), gtk_accessible_value_unref); |
| 141 | |
| 142 | if (value != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 143 | self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[attribute] = gtk_accessible_value_refcxx . . $ gtk_accessible_value_ref(bacafa359650c308). (value); |
| 144 | else |
| 145 | self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[attribute] = (* self->default_funccxx . . $ _GtkAccessibleAttributeSet#default_func.) (attribute); |
| 146 | |
| 147 | self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set. = _gtk_bitmask_setcxx . . $ _gtk_bitmask_set(d4be56091f3b3606). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!); |
| 148 | |
| 149 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 150 | } |
| 151 | |
| 152 | /*< private > |
| 153 | * gtk_accessible_attribute_set_remove: |
| 154 | * @self: a `GtkAccessibleAttributeSet` |
| 155 | * @attribute: the attribute to be removed |
| 156 | * |
| 157 | * Resets the @attribute in the given `GtkAccessibleAttributeSet` |
| 158 | * to its default value. |
| 159 | * |
| 160 | * Returns: %TRUE if the set was modified, and %FALSE otherwise |
| 161 | */ |
| 162 | gbooleancxx . . $ gboolean# |
| 163 | gtk_accessible_attribute_set_removecxx . . $ gtk_accessible_attribute_set_remove(f8a8d1b486d36d7c). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self, |
| 164 | int attribute) |
| 165 | { |
| 166 | g_return_val_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:665:9`! (attribute >= 0 && attribute < self->n_attributes, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!); |
| 167 | |
| 168 | if (!_gtk_bitmask_getcxx . . $ _gtk_bitmask_get(ec1f9572e2cb12df). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute)) |
| 169 | return FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!; |
| 170 | |
| 171 | g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&(self->attribute_values[attribute]), gtk_accessible_value_unref); |
| 172 | |
| 173 | self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[attribute] = (* self->default_funccxx . . $ _GtkAccessibleAttributeSet#default_func.) (attribute); |
| 174 | self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set. = _gtk_bitmask_setcxx . . $ _gtk_bitmask_set(d4be56091f3b3606). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!); |
| 175 | |
| 176 | return TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!; |
| 177 | } |
| 178 | |
| 179 | gbooleancxx . . $ gboolean# |
| 180 | gtk_accessible_attribute_set_containscxx . . $ gtk_accessible_attribute_set_contains(f8a8d1b486d36d7c). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self, |
| 181 | int attribute) |
| 182 | { |
| 183 | g_return_val_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:665:9`! (attribute >= 0 && attribute < self->n_attributes, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!); |
| 184 | |
| 185 | return _gtk_bitmask_getcxx . . $ _gtk_bitmask_get(ec1f9572e2cb12df). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., attribute); |
| 186 | } |
| 187 | |
| 188 | /*< private > |
| 189 | * gtk_accessible_attribute_set_get_value: |
| 190 | * @self: a `GtkAccessibleAttributeSet` |
| 191 | * @attribute: the attribute to retrieve |
| 192 | * |
| 193 | * Retrieves the value of the given @attribute in the set. |
| 194 | * |
| 195 | * Returns: (transfer none): the value for the attribute |
| 196 | */ |
| 197 | GtkAccessibleValuecxx . . $ GtkAccessibleValue# * |
| 198 | gtk_accessible_attribute_set_get_valuecxx . . $ gtk_accessible_attribute_set_get_value(89619d44f46a003). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self, |
| 199 | int attribute) |
| 200 | { |
| 201 | g_return_val_if_failcxx . . $ `<external>/5169755362661750954/gmessages.h:665:9`! (attribute >= 0 && attribute < self->n_attributes, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 202 | |
| 203 | return self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[attribute]; |
| 204 | } |
| 205 | |
| 206 | gsizecxx . . $ gsize# |
| 207 | gtk_accessible_attribute_set_get_lengthcxx . . $ gtk_accessible_attribute_set_get_length(8b0a30135cd135ad). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self) |
| 208 | { |
| 209 | return self->n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes.; |
| 210 | } |
| 211 | |
| 212 | guintcxx . . $ guint# |
| 213 | gtk_accessible_attribute_set_get_changedcxx . . $ gtk_accessible_attribute_set_get_changed(862b52f5deeec684). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self) |
| 214 | { |
| 215 | guintcxx . . $ guint# changed = 0; |
| 216 | |
| 217 | for (gsizecxx . . $ gsize# i = 0; i < self->n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes.; i++) |
| 218 | { |
| 219 | if (gtk_accessible_attribute_set_containscxx . . $ gtk_accessible_attribute_set_contains(f8a8d1b486d36d7c). (self, i)) |
| 220 | changed |= (1 << i); |
| 221 | } |
| 222 | |
| 223 | return changed; |
| 224 | } |
| 225 | |
| 226 | /*< private > |
| 227 | * gtk_accessible_attribute_set_print: |
| 228 | * @self: a `GtkAccessibleAttributeSet` |
| 229 | * @only_set: %TRUE if only the set attributes should be printed |
| 230 | * @buffer: a `GString` |
| 231 | * |
| 232 | * Prints the contents of the `GtkAccessibleAttributeSet` into @buffer. |
| 233 | */ |
| 234 | void |
| 235 | gtk_accessible_attribute_set_printcxx . . $ gtk_accessible_attribute_set_print(39223b785fc6f257). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self, |
| 236 | gbooleancxx . . $ gboolean# only_set, |
| 237 | GStringcxx . . $ GString# *buffer) |
| 238 | { |
| 239 | if (only_set && _gtk_bitmask_is_emptycxx . . $ _gtk_bitmask_is_empty(2272a2a7969c90ab). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set.)) |
| 240 | { |
| 241 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, "{}"); |
| 242 | return; |
| 243 | } |
| 244 | |
| 245 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, "{\n"); |
| 246 | |
| 247 | for (gsizecxx . . $ gsize# i = 0; i < self->n_attributescxx . . $ _GtkAccessibleAttributeSet#n_attributes.; i++) |
| 248 | { |
| 249 | if (only_set && !_gtk_bitmask_getcxx . . $ _gtk_bitmask_get(ec1f9572e2cb12df). (self->attributes_setcxx . . $ _GtkAccessibleAttributeSet#attributes_set., i)) |
| 250 | continue; |
| 251 | |
| 252 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, " "); |
| 253 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, self->name_func (i)); |
| 254 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, ": "); |
| 255 | |
| 256 | gtk_accessible_value_printcxx . . $ gtk_accessible_value_print(d7a76c85628d271c). (self->attribute_valuescxx . . $ _GtkAccessibleAttributeSet#attribute_values.[i], buffer); |
| 257 | |
| 258 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, ",\n"); |
| 259 | } |
| 260 | |
| 261 | g_string_appendcxx . . $ `<external>/2906017559248664336/gstring.h:270:9`! (buffer, "}"); |
| 262 | } |
| 263 | |
| 264 | /*< private > |
| 265 | * gtk_accessible_attribute_set_to_string: |
| 266 | * @self: a `GtkAccessibleAttributeSet` |
| 267 | * |
| 268 | * Prints the contents of a `GtkAccessibleAttributeSet` into a string. |
| 269 | * |
| 270 | * Returns: (transfer full): a newly allocated string with the contents |
| 271 | * of the `GtkAccessibleAttributeSet` |
| 272 | */ |
| 273 | char * |
| 274 | gtk_accessible_attribute_set_to_stringcxx . . $ gtk_accessible_attribute_set_to_string(62624357dd3a44da). (GtkAccessibleAttributeSetcxx . . $ GtkAccessibleAttributeSet# *self) |
| 275 | { |
| 276 | GStringcxx . . $ GString# *buf = g_string_newcxx . . $ g_string_new(e8737c02110bb79b). (NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 277 | |
| 278 | gtk_accessible_attribute_set_printcxx . . $ gtk_accessible_attribute_set_print(39223b785fc6f257). (self, TRUEcxx . . $ `<external>/12741050725406041920/gmacros.h:971:9`!, buf); |
| 279 | |
| 280 | return g_string_freecxx . . $ `<external>/2906017559248664336/gstring.h:73:9`! (buf, FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!); |
| 281 | } |