vcl/unx/gtk3/a11y/atkwrapper.cxx |   27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

New commits:
commit 29b0be697d568944b47d3f8cbffa72384d50b076
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Wed May 28 23:40:10 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu May 29 08:10:50 2025 +0200

    gtk3 a11y: Report object's locale
    
    This is basically the gtk3 version of
    
        Change-Id: I33b3bb406da5d84c2353bbeb5bedc7ac0297f31f
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Wed May 28 22:54:57 2025 +0200
    
            qt a11y: Report locale for Qt >= 6.10
    
    and causes the paragraph locales to be reported for the
    use case described in the above-mentioned commit also
    when using the gtk3 VCL plugin:
    
        In [14]: acc.get_object_locale()
        Out[14]: 'en_GB.UTF-8'
        In [15]: acc.get_object_locale()
        Out[15]: 'zh_CN.UTF-8'
    
    Add the character encoding at the end of the locale string,
    as this is consistent with what is reported by default for
    the object locale (was "en_GB.UTF-8" for any object prior
    to this change) for the gtk3/ATK case.
    
    The atk_object_get_object_locale doc [1] says that the
    returned string is owned by the instance, so make sure to
    free the string again by setting it as data for the
    AtkObjectWrapper object and free it in
    atk_object_wrapper_finalize.
    
    [1] https://docs.gtk.org/atk/method.Object.get_object_locale.html
    
    Change-Id: Icaadc5228f2cc5526b427cc3aef127a8eadd94ff
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185982
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/unx/gtk3/a11y/atkwrapper.cxx b/vcl/unx/gtk3/a11y/atkwrapper.cxx
index 6bf67a1e3479..17eefbf637e9 100644
--- a/vcl/unx/gtk3/a11y/atkwrapper.cxx
+++ b/vcl/unx/gtk3/a11y/atkwrapper.cxx
@@ -59,6 +59,8 @@
 
 using namespace ::com::sun::star;
 
+constexpr const char* PROPERTY_LOCALE = "locale";
+
 static GObjectClass *parent_class = nullptr;
 
 static AtkRelationType mapRelationType(accessibility::AccessibleRelationType 
eRelation)
@@ -429,7 +431,26 @@ wrapper_get_description( AtkObject *atk_obj )
 
 }
 
-/*****************************************************************************/
+static const char* wrapper_get_object_locale(AtkObject* pAtkObject)
+{
+    AtkObjectWrapper* pWrapper = ATK_OBJECT_WRAPPER(pAtkObject);
+
+    if (!pWrapper->mpContext.is())
+        return ATK_OBJECT_CLASS(parent_class)->get_object_locale(pAtkObject);
+
+    const css::lang::Locale aLocale = pWrapper->mpContext->getLocale();
+
+    const char* pCharset;
+    g_get_charset(&pCharset);
+
+    const OUString sLocale
+        = aLocale.Language + u"_" + aLocale.Country + u"." + 
OUString::fromUtf8(pCharset);
+    char* pLocale = g_strdup(sLocale.toUtf8().getStr());
+    // set pLocale as object data so it can be freed in 
atk_object_wrapper_finalize
+    g_free(g_object_get_data(G_OBJECT(pWrapper), PROPERTY_LOCALE));
+    g_object_set_data(G_OBJECT(pWrapper), PROPERTY_LOCALE, pLocale);
+    return pLocale;
+}
 
 static AtkAttributeSet *
 wrapper_get_attributes( AtkObject *atk_obj )
@@ -665,6 +686,9 @@ atk_object_wrapper_finalize (GObject *obj)
         pWrap->mpAccessible.clear();
     }
 
+    // free string if allocated in atk_wrapper_get_object_locale
+    g_free(g_object_get_data(obj, PROPERTY_LOCALE));
+
     atk_object_wrapper_dispose( pWrap );
 
     if (pWrap->mpOrig)
@@ -688,6 +712,7 @@ atk_object_wrapper_class_init (gpointer klass_, gpointer)
   // AtkObject methods
   atk_class->get_name = wrapper_get_name;
   atk_class->get_description = wrapper_get_description;
+  atk_class->get_object_locale = wrapper_get_object_locale;
   atk_class->get_attributes = wrapper_get_attributes;
   atk_class->get_n_children = wrapper_get_n_children;
   atk_class->ref_child = wrapper_ref_child;

Reply via email to