include/sfx2/charmapcontainer.hxx        |    5 +++
 include/sfx2/charwin.hxx                 |    5 +--
 sfx2/source/control/charmapcontainer.cxx |   50 +++++++++++++++++++++++++++++++
 sfx2/source/control/charmapcontrol.cxx   |    2 -
 sfx2/source/control/charwin.cxx          |   47 -----------------------------
 5 files changed, 60 insertions(+), 49 deletions(-)

New commits:
commit c542af53305fe877c71e84bf9604e1789dcb2460
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Dec 16 16:41:40 2025 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Tue Dec 16 23:18:05 2025 +0100

    tdf#168594 Move tooltip text and a11y name logic out of SvxCharView
    
    Move the logic to generate the tooltip text and
    the accessible name from the SvxCharView class to
    the SfxCharmapContainer that manages all of the recent
    and favorite characters, i.e. which owns the SvxCharView
    instances.
    (Make the relevant SvxCharView methods static methods
    in SfxCharmapContainer instead.)
    
    No change in behavior intended or seen in a
    quick test.
    
    This is in preparation of switching away from
    SvxCharView and using a weld::IconView for
    the recent and favorite characters instead in an
    upcoming commit.
    
    With previous commit
    
        Change-Id: I56e8dde0b591073dea7f58190746ca0ba1fd8a4f
        Author: Michael Weghorn <[email protected]>
        Date:   Tue Dec 16 12:10:48 2025 +0100
    
            tdf#130857 tdf#168594 weld: Introduce 
weld::IconView::set_item_tooltip_text
    
    in place, weld::IconView now has API to set both, the
    accessible name and the tooltip for an item directly which
    should make porting the logic newly added to
    SfxCharmapContainer::updateCharControl in this commit
    straight-forward when switching to weld::IconView in
    the future.
    
    Change-Id: Ica33d45f7b9dbb6840ad67b725c7ed98ff505312
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195736
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/include/sfx2/charmapcontainer.hxx 
b/include/sfx2/charmapcontainer.hxx
index 29a139184272..7007cfeb53fe 100644
--- a/include/sfx2/charmapcontainer.hxx
+++ b/include/sfx2/charmapcontainer.hxx
@@ -72,6 +72,9 @@ class SFX2_DLLPUBLIC SfxCharmapContainer
     static void updateCharControl(std::span<SvxCharView> aCharViews,
                                   const std::deque<CharAndFont>& rChars);
 
+    static bool GetDecimalValueAndCharName(std::u16string_view sCharText, 
sal_UCS4& rDecimalValue,
+                                           OUString& rCharName);
+
 public:
     SfxCharmapContainer(weld::Builder& rBuilder, const VclPtr<VirtualDevice>& 
rVirDev,
                         bool bLockGridSizes);
@@ -96,6 +99,8 @@ public:
     bool FavCharListIsFull() const;
 
     void GrabFocusToFirstFavorite();
+
+    static OUString GetCharInfoText(std::u16string_view sCharText);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/include/sfx2/charwin.hxx b/include/sfx2/charwin.hxx
index dc16b672d774..672a3cc5d402 100644
--- a/include/sfx2/charwin.hxx
+++ b/include/sfx2/charwin.hxx
@@ -31,6 +31,7 @@ private:
     vcl::Font       maFont;
     bool            maHasInsert;
     OUString        m_sText;
+    OUString        m_sToolTip;
 
     Link<SvxCharView&, void> maFocusInHdl;
     Link<SvxCharView&, void> maMouseClickHdl;
@@ -45,7 +46,7 @@ private:
     virtual bool KeyInput(const KeyEvent&) override;
     virtual bool Command(const CommandEvent&) override;
     virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
-    bool GetDecimalValueAndCharName(sal_UCS4& rDecimalValue, OUString& 
rCharName);
+
 public:
     SvxCharView(const VclPtr<VirtualDevice>& rVirDev);
     SFX2_DLLPUBLIC virtual ~SvxCharView() override;
@@ -54,7 +55,7 @@ public:
     vcl::Font const & GetFont() const { return maFont; }
     void            SetText( const OUString& rText );
     OUString const & GetText() const { return m_sText; }
-    OUString GetCharInfoText();
+    void SetToolTip(const OUString& rToolTip) { m_sToolTip = rToolTip; };
     void            SetHasInsert( bool bInsert );
     void            InsertCharToDoc();
 
diff --git a/sfx2/source/control/charmapcontainer.cxx 
b/sfx2/source/control/charmapcontainer.cxx
index 4374e9e625d4..2ebe854c3541 100644
--- a/sfx2/source/control/charmapcontainer.cxx
+++ b/sfx2/source/control/charmapcontainer.cxx
@@ -21,11 +21,16 @@
 #include <officecfg/Office/Common.hxx>
 #include <charmapcontrol.hxx>
 #include <charmappopup.hxx>
+#include <o3tl/string_view.hxx>
+#include <o3tl/temporary.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <sfx2/strings.hrc>
 #include <sfx2/sfxresid.hxx>
 #include <vcl/commandevent.hxx>
 
+#include <unicode/uchar.h>
+#include <unicode/utypes.h>
+
 using namespace css;
 
 SfxCharmapContainer::SfxCharmapContainer(weld::Builder& rBuilder, const 
VclPtr<VirtualDevice>& rVirDev, bool bLockGridSizes)
@@ -307,6 +312,14 @@ void 
SfxCharmapContainer::updateCharControl(std::span<SvxCharView> aCharViews,
     for (auto it = rChars.begin(); it != rChars.end(); ++it, i++)
     {
         aCharViews[i].SetText(it->sChar);
+
+        OUString sAccName;
+        if (GetDecimalValueAndCharName(it->sChar, o3tl::temporary(sal_UCS4()), 
sAccName))
+            aCharViews[i].SetAccessibleName(sAccName);
+        else
+            aCharViews[i].SetAccessibleName(OUString());
+        aCharViews[i].SetToolTip(GetCharInfoText(it->sChar));
+
         aCharViews[i].UpdateFont(it->sFont);
         aCharViews[i].Show();
     }
@@ -314,6 +327,8 @@ void 
SfxCharmapContainer::updateCharControl(std::span<SvxCharView> aCharViews,
     for (; i < 16; i++)
     {
         aCharViews[i].SetText(OUString());
+        aCharViews[i].SetAccessibleName(OUString());
+        aCharViews[i].SetToolTip(OUString());
         aCharViews[i].Hide();
     }
 }
@@ -399,4 +414,39 @@ bool SfxCharmapContainer::hasRecentChars() const
     return !m_aRecentChars.empty();
 }
 
+bool SfxCharmapContainer::GetDecimalValueAndCharName(std::u16string_view 
sCharText,
+                                                     sal_UCS4& rDecimalValue, 
OUString& rCharName)
+{
+    if (sCharText.empty())
+        return false;
+
+    sal_UCS4 nDecimalValue = o3tl::iterateCodePoints(sCharText, 
&o3tl::temporary(sal_Int32(1)), -1);
+    /* get the character name */
+    UErrorCode errorCode = U_ZERO_ERROR;
+    // icu has a private uprv_getMaxCharNameLength function which returns the 
max possible
+    // length of this property. Unicode 3.2 max char name length was 83
+    char buffer[100];
+    u_charName(nDecimalValue, U_UNICODE_CHAR_NAME, buffer, sizeof(buffer), 
&errorCode);
+    if (U_SUCCESS(errorCode))
+    {
+        rDecimalValue = nDecimalValue;
+        rCharName = OUString::createFromAscii(buffer);
+        return true;
+    }
+    return false;
+}
+
+OUString SfxCharmapContainer::GetCharInfoText(std::u16string_view sCharText)
+{
+    sal_UCS4 nDecimalValue = 0;
+    OUString sCharName;
+    const bool bSuccess = GetDecimalValueAndCharName(sCharText, nDecimalValue, 
sCharName);
+    if (bSuccess)
+    {
+        auto aHexText = OUString::number(nDecimalValue, 16).toAsciiUpperCase();
+        return sCharText + u" "_ustr + sCharName + u" U+" + aHexText;
+    }
+    return OUString();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/sfx2/source/control/charmapcontrol.cxx 
b/sfx2/source/control/charmapcontrol.cxx
index b6d29b5eedf2..ae34823a7821 100644
--- a/sfx2/source/control/charmapcontrol.cxx
+++ b/sfx2/source/control/charmapcontrol.cxx
@@ -52,7 +52,7 @@ SfxCharmapCtrl::~SfxCharmapCtrl()
 
 IMPL_LINK(SfxCharmapCtrl, CharFocusInHdl, SvxCharView&, rView, void)
 {
-    m_xCharInfoLabel->set_label(rView.GetCharInfoText());
+    
m_xCharInfoLabel->set_label(SfxCharmapContainer::GetCharInfoText(rView.GetText()));
 }
 
 IMPL_LINK(SfxCharmapCtrl, CharClickHdl, SvxCharView&, rView, void)
diff --git a/sfx2/source/control/charwin.cxx b/sfx2/source/control/charwin.cxx
index 10f5d08dcace..4365b2f74ec9 100644
--- a/sfx2/source/control/charwin.cxx
+++ b/sfx2/source/control/charwin.cxx
@@ -29,10 +29,6 @@
 
 #include <com/sun/star/beans/PropertyValue.hpp>
 
-#include <o3tl/temporary.hxx>
-#include <unicode/uchar.h>
-#include <unicode/utypes.h>
-
 using namespace com::sun::star;
 
 SvxCharView::SvxCharView(const VclPtr<VirtualDevice>& rVirDev)
@@ -65,46 +61,11 @@ void SvxCharView::GetFocus()
 
 void SvxCharView::LoseFocus() { Invalidate(); }
 
-bool SvxCharView::GetDecimalValueAndCharName(sal_UCS4& rDecimalValue, 
OUString& rCharName)
-{
-    OUString charValue = GetText();
-    if (charValue.isEmpty())
-        return false;
-
-    sal_UCS4 nDecimalValue = 
charValue.iterateCodePoints(&o3tl::temporary(sal_Int32(1)), -1);
-    /* get the character name */
-    UErrorCode errorCode = U_ZERO_ERROR;
-    // icu has a private uprv_getMaxCharNameLength function which returns the 
max possible
-    // length of this property. Unicode 3.2 max char name length was 83
-    char buffer[100];
-    u_charName(nDecimalValue, U_UNICODE_CHAR_NAME, buffer, sizeof(buffer), 
&errorCode);
-    if (U_SUCCESS(errorCode))
-    {
-        rDecimalValue = nDecimalValue;
-        rCharName = OUString::createFromAscii(buffer);
-        return true;
-    }
-    return false;
-}
-
-OUString SvxCharView::GetCharInfoText()
-{
-    sal_UCS4 nDecimalValue = 0;
-    OUString sCharName;
-    const bool bSuccess = GetDecimalValueAndCharName(nDecimalValue, sCharName);
-    if (bSuccess)
-    {
-        auto aHexText = OUString::number(nDecimalValue, 16).toAsciiUpperCase();
-        return GetText() + u" " + sCharName + u" U+" + aHexText;
-    }
-    return OUString();
-}
-
 OUString SvxCharView::RequestHelp(tools::Rectangle& rHelpRect)
 {
     // Gtk3 requires a rectangle be specified for the tooltip to display, X11 
does not.
     rHelpRect = tools::Rectangle(Point(), GetOutputSizePixel());
-    return GetCharInfoText();
+    return m_sToolTip;
 }
 
 bool SvxCharView::MouseButtonDown(const MouseEvent& rMEvt)
@@ -293,12 +254,6 @@ void SvxCharView::SetText(const OUString& rText)
 {
     m_sText = rText;
     Invalidate();
-
-    OUString sName;
-    if (GetDecimalValueAndCharName(o3tl::temporary(sal_UCS4()), sName))
-        SetAccessibleName(sName);
-    else
-        SetAccessibleName(OUString());
 }
 
 void SvxCharView::SetHasInsert(bool bInsert) { maHasInsert = bInsert; }

Reply via email to