include/vcl/builder.hxx       |    3 ++
 vcl/source/window/builder.cxx |   43 +++++++++++++++++++++++-------------------
 2 files changed, 27 insertions(+), 19 deletions(-)

New commits:
commit fd67141bbfd7a9167f5a7f49441adb41d117e8b3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Sep 20 15:14:20 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Sep 21 09:08:23 2024 +0200

    tdf#130857 VclBuilder: Extract helpers to set prio/EnumContext
    
    Move setting these in a vcl::Window specific way
    from `BuilderBase::handleObject` to separate helper
    methods.
    
    Change-Id: I2df05e298dc9d2ef5af7b67104ce0b904cce4d1d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173735
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index d3f06fc4935b..3690fdefe82d 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -316,6 +316,9 @@ private:
     // if bToolbarItem=true, pParent is the ToolBox that the item belongs to, 
since there's no widget for the item itself
     void applyAtkProperties(vcl::Window *pWindow, const stringmap& 
rProperties, bool bToolbarItem);
 
+    static void setPriority(vcl::Window* pWindow, int nPriority);
+    static void setContext(vcl::Window* pWindow, 
std::vector<vcl::EnumContext::Context>&& aContext);
+
     PackingData get_window_packing_data(const vcl::Window *pWindow) const;
     void        set_window_packing_position(const vcl::Window *pWindow, 
sal_Int32 nPosition);
 
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 260b05dc9be0..541471a2b5bd 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -3157,6 +3157,21 @@ void VclBuilder::applyAtkProperties(vcl::Window 
*pWindow, const stringmap& rProp
     }
 }
 
+void VclBuilder::setPriority(vcl::Window* pWindow, int nPriority)
+{
+    vcl::IPrioritable* pPrioritable = 
dynamic_cast<vcl::IPrioritable*>(pWindow);
+    SAL_WARN_IF(!pPrioritable, "vcl", "priority set for not supported item");
+    if (pPrioritable)
+        pPrioritable->SetPriority(nPriority);
+}
+void VclBuilder::setContext(vcl::Window* pWindow, 
std::vector<vcl::EnumContext::Context>&& aContext)
+{
+    vcl::IContext* pContextControl = dynamic_cast<vcl::IContext*>(pWindow);
+    SAL_WARN_IF(!pContextControl, "vcl", "context set for not supported item");
+    if (pContextControl)
+        pContextControl->SetContext(std::move(aContext));
+}
+
 std::vector<ComboBoxTextItem> BuilderBase::handleItems(xmlreader::XmlReader& 
reader) const
 {
     int nLevel = 1;
@@ -3705,19 +3720,9 @@ VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window 
*pParent, stringmap *pA
                 int nPriority = 0;
                 std::vector<vcl::EnumContext::Context> aContext = 
handleStyle(reader, nPriority);
                 if (nPriority != 0)
-                {
-                    vcl::IPrioritable* pPrioritable = 
dynamic_cast<vcl::IPrioritable*>(pCurrentChild.get());
-                    SAL_WARN_IF(!pPrioritable, "vcl", "priority set for not 
supported item");
-                    if (pPrioritable)
-                        pPrioritable->SetPriority(nPriority);
-                }
+                    setPriority(pCurrentChild, nPriority);
                 if (!aContext.empty())
-                {
-                    vcl::IContext* pContextControl = 
dynamic_cast<vcl::IContext*>(pCurrentChild.get());
-                    SAL_WARN_IF(!pContextControl, "vcl", "context set for not 
supported item");
-                    if (pContextControl)
-                        pContextControl->SetContext(std::move(aContext));
-                }
+                    setContext(pCurrentChild, std::move(aContext));
             }
             else
             {
commit 46467794b73050fe4f87ac715c993b9dc2ad6269
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Sep 20 14:36:44 2024 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Sep 21 09:08:15 2024 +0200

    tdf#130857 VclBuilder: Avoid using vcl WindowType to detect toolbar
    
    Instead of checking that the type of the vcl::Window
    is WindowType::TOOLBOX, rely on the class name of the
    current item to be one of the toolbar item classes
    in `VclBuilder::handleObject` and instead double-check
    and make the code in `VclBuilder::applyAtkProperties`
    conditional on this actually being a `ToolBox` instead
    of asserting.
    
    (Not sure whether there's a valid case for using toolbar
    items outside of toolbars, but avoid potential regressions
    here if that's used anywhere.)
    
    This gets rid of one vcl::Window specific way of handling
    things in `VclBuilder::handleObject`, which is one step
    for preparing it for reuse by other builders in the future
    in particular QtBuilder from pending WIP Gerrit change [1].
    
    In a quick test, the accessible name of
    "Show Up to Outline Level" is still properly set
    for the corresponding toolbar item in the navigator only
    and not for the toolbar, see
    
        commit ad1167b92b8b8fdabf6b21e945682c0bafc80946
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Tue Feb 27 13:12:43 2024 +0100
    
            tdf#159910 a11y VclBuilder: Apply tool item's a11y name to itself
    
    for background.
    
    [1] https://gerrit.libreoffice.org/c/core/+/161831
    
    Change-Id: I8a7dbbee9b88bcb7c0cd6bc862d2c5cc4a290af4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173734
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index f7f5d836f88d..260b05dc9be0 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -3141,12 +3141,13 @@ void VclBuilder::applyAtkProperties(vcl::Window 
*pWindow, const stringmap& rProp
     {
         if (bToolbarItem)
         {
-            // apply accessible name to the toolbar item
-            if (rKey == u"AtkObject::accessible-name")
+            // apply property to the corresponding toolbar item (which is not 
a vcl::Window itself)
+            // rather than the toolbar itself
+            ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
+            if (pToolBox)
             {
-                ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
-                assert(pToolBox);
-                
pToolBox->SetAccessibleName(m_pVclParserState->m_nLastToolbarId, rValue);
+                if (rKey == u"AtkObject::accessible-name")
+                    
pToolBox->SetAccessibleName(m_pVclParserState->m_nLastToolbarId, rValue);
             }
         }
         else if (pWindow && rKey.match("AtkObject::"))
@@ -3695,8 +3696,7 @@ VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window 
*pParent, stringmap *pA
                     pCurrentChild = insertObject(pParent, sClass, sID,
                         aProperties, aPangoAttributes, aAtkAttributes);
                 }
-                const bool bToolItem = pCurrentChild == pParent && 
pCurrentChild->GetType() == WindowType::TOOLBOX && isToolbarItemClass(sClass);
-                handleChild(pCurrentChild, nullptr, reader, bToolItem);
+                handleChild(pCurrentChild, nullptr, reader, 
isToolbarItemClass(sClass));
             }
             else if (name == "items")
                 aItems = handleItems(reader);

Reply via email to