include/vcl/builder.hxx       |   23 +++++--
 vcl/source/window/builder.cxx |  135 +++++++++++++++++++++---------------------
 2 files changed, 86 insertions(+), 72 deletions(-)

New commits:
commit 4353b73fb343115ab25d242d11896e153a91a9d3
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Tue Jan 30 11:43:29 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Feb 8 22:49:40 2024 +0100

    tdf#130857 VclBuilder: Extract helper method for tweaking new child
    
    Extract the post-processing to apply specific tweaks
    to a newly inserted/created `vcl::Window` child from
    `VclBuilder::handleChild` into a new helper method
    `VclBuilder::tweakInsertedChild`.
    
    Change-Id: I6ef813fe899f3dd6e4357c37b8da990ddf7c5155
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162919
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index e53a89321095..95105f8cc7ec 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -332,6 +332,10 @@ private:
     css::uno::Reference<css::frame::XFrame> m_xFrame;
 
 private:
+    // tweak newly inserted child depending on window type
+    void tweakInsertedChild(vcl::Window *pParent, vcl::Window* pCurrentChild,
+                            std::string_view sType, std::string_view 
sInternalChild);
+
     VclPtr<vcl::Window> insertObject(vcl::Window *pParent,
                     const OUString &rClass, const OUString &rID,
                     stringmap &rProps, stringmap &rPangoAttributes,
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index f3d16da17b8c..82cdf7a1b0eb 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -2733,6 +2733,70 @@ bool 
VclBuilder::sortIntoBestTabTraversalOrder::operator()(const vcl::Window *pA
     return false;
 }
 
+void VclBuilder::tweakInsertedChild(vcl::Window *pParent, vcl::Window* 
pCurrentChild,
+                                    std::string_view sType, std::string_view 
sInternalChild)
+{
+    //Internal-children default in glade to not having their visible bits set
+    //even though they are visible (generally anyway)
+    if (!sInternalChild.empty())
+        pCurrentChild->Show();
+
+    //Select the first page if it's a notebook
+    if (pCurrentChild->GetType() == WindowType::TABCONTROL)
+    {
+        TabControl *pTabControl = static_cast<TabControl*>(pCurrentChild);
+        pTabControl->SetCurPageId(pTabControl->GetPageId(0));
+
+        //To-Do add reorder capability to the TabControl
+    }
+    else
+    {
+        // We want to sort labels before contents of frames
+        // for keyboard traversal, especially if there
+        // are multiple widgets using the same mnemonic
+        if (sType == "label")
+        {
+            if (VclFrame *pFrameParent = dynamic_cast<VclFrame*>(pParent))
+                pFrameParent->designate_label(pCurrentChild);
+        }
+        if (sInternalChild.starts_with("vbox") || 
sInternalChild.starts_with("messagedialog-vbox"))
+        {
+            if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pParent))
+                
pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild)); // 
FIXME-VCLPTR
+        }
+        else if (sInternalChild.starts_with("action_area") || 
sInternalChild.starts_with("messagedialog-action_area"))
+        {
+            vcl::Window *pContentArea = pCurrentChild->GetParent();
+            if (Dialog *pBoxParent = dynamic_cast<Dialog*>(pContentArea ? 
pContentArea->GetParent() : nullptr))
+            {
+                
pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild)); // 
FIXME-VCLPTR
+            }
+        }
+
+        bool bIsButtonBox = dynamic_cast<VclButtonBox*>(pCurrentChild) != 
nullptr;
+
+        //To-Do make reorder a virtual in Window, move this foo
+        //there and see above
+        std::vector<vcl::Window*> aChilds;
+        for (vcl::Window* pChild = 
pCurrentChild->GetWindow(GetWindowType::FirstChild); pChild;
+             pChild = pChild->GetWindow(GetWindowType::Next))
+        {
+            if (bIsButtonBox)
+            {
+                if (PushButton* pPushButton = 
dynamic_cast<PushButton*>(pChild))
+                    pPushButton->setAction(true);
+            }
+
+            aChilds.push_back(pChild);
+        }
+
+        //sort child order within parent so that tabbing
+        //between controls goes in a visually sensible sequence
+        std::stable_sort(aChilds.begin(), aChilds.end(), 
sortIntoBestTabTraversalOrder(this));
+        BuilderUtils::reorderWithinParent(aChilds, bIsButtonBox);
+    }
+}
+
 void VclBuilder::handleChild(vcl::Window *pParent, stringmap* pAtkProps, 
xmlreader::XmlReader &reader)
 {
     vcl::Window *pCurrentChild = nullptr;
@@ -2774,69 +2838,8 @@ void VclBuilder::handleChild(vcl::Window *pParent, 
stringmap* pAtkProps, xmlread
                 pCurrentChild = handleObject(pParent, pAtkProps, reader).get();
 
                 bool bObjectInserted = pCurrentChild && pParent != 
pCurrentChild;
-
                 if (bObjectInserted)
-                {
-                    //Internal-children default in glade to not having their 
visible bits set
-                    //even though they are visible (generally anyway)
-                    if (!sInternalChild.isEmpty())
-                        pCurrentChild->Show();
-
-                    //Select the first page if it's a notebook
-                    if (pCurrentChild->GetType() == WindowType::TABCONTROL)
-                    {
-                        TabControl *pTabControl = 
static_cast<TabControl*>(pCurrentChild);
-                        pTabControl->SetCurPageId(pTabControl->GetPageId(0));
-
-                        //To-Do add reorder capability to the TabControl
-                    }
-                    else
-                    {
-                        // We want to sort labels before contents of frames
-                        // for keyboard traversal, especially if there
-                        // are multiple widgets using the same mnemonic
-                        if (sType == "label")
-                        {
-                            if (VclFrame *pFrameParent = 
dynamic_cast<VclFrame*>(pParent))
-                                pFrameParent->designate_label(pCurrentChild);
-                        }
-                        if (sInternalChild.startsWith("vbox") || 
sInternalChild.startsWith("messagedialog-vbox"))
-                        {
-                            if (Dialog *pBoxParent = 
dynamic_cast<Dialog*>(pParent))
-                                
pBoxParent->set_content_area(static_cast<VclBox*>(pCurrentChild)); // 
FIXME-VCLPTR
-                        }
-                        else if (sInternalChild.startsWith("action_area") || 
sInternalChild.startsWith("messagedialog-action_area"))
-                        {
-                            vcl::Window *pContentArea = 
pCurrentChild->GetParent();
-                            if (Dialog *pBoxParent = 
dynamic_cast<Dialog*>(pContentArea ? pContentArea->GetParent() : nullptr))
-                            {
-                                
pBoxParent->set_action_area(static_cast<VclButtonBox*>(pCurrentChild)); // 
FIXME-VCLPTR
-                            }
-                        }
-
-                        bool bIsButtonBox = 
dynamic_cast<VclButtonBox*>(pCurrentChild) != nullptr;
-
-                        //To-Do make reorder a virtual in Window, move this foo
-                        //there and see above
-                        std::vector<vcl::Window*> aChilds;
-                        for (vcl::Window* pChild = 
pCurrentChild->GetWindow(GetWindowType::FirstChild); pChild;
-                            pChild = pChild->GetWindow(GetWindowType::Next))
-                        {
-                            if (bIsButtonBox)
-                            {
-                                if (PushButton* pPushButton = 
dynamic_cast<PushButton*>(pChild))
-                                    pPushButton->setAction(true);
-                            }
-
-                            aChilds.push_back(pChild);
-                        }
-
-                        //sort child order within parent so that tabbing
-                        //between controls goes in a visually sensible sequence
-                        std::stable_sort(aChilds.begin(), aChilds.end(), 
sortIntoBestTabTraversalOrder(this));
-                        BuilderUtils::reorderWithinParent(aChilds, 
bIsButtonBox);
-                    }
-                }
+                    tweakInsertedChild(pParent, pCurrentChild, sType, 
sInternalChild);
             }
             else if (name == "packing")
             {
commit 9d928231e71806d4cfe76af2159630bff242c5da
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Mon Jan 29 14:42:24 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Feb 8 22:49:30 2024 +0100

    tdf#130857 VclBuilder: Extract static methods to new base class
    
    Extract static methods from VclBuilder to a new base class
    BuilderBase that can be reused by other builder implementations
    (like the upcoming one for the Qt-based VCL plugins) in the future.
    
    Change-Id: I719ab5fe1b8a6b36050815204550aae3e3dd25e0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162917
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 64538f81272e..e53a89321095 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -64,12 +64,23 @@ struct ComboBoxTextItem
     }
 };
 
-/// Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, 
sidebar, etc.
-class VCL_DLLPUBLIC VclBuilder
+class VCL_DLLPUBLIC BuilderBase
 {
 public:
     typedef std::map<OUString, OUString> stringmap;
     typedef std::map<OUString, std::pair<OUString, OUString>> accelmap;
+
+protected:
+    static void collectPangoAttribute(xmlreader::XmlReader& reader, stringmap& 
rMap);
+    static void collectAtkRelationAttribute(xmlreader::XmlReader& reader, 
stringmap& rMap);
+    static void collectAtkRoleAttribute(xmlreader::XmlReader& reader, 
stringmap& rMap);
+    static void collectAccelerator(xmlreader::XmlReader& reader, accelmap& 
rMap);
+};
+
+/// Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, 
sidebar, etc.
+class VCL_DLLPUBLIC VclBuilder : public BuilderBase
+{
+public:
     /// These functions create a new widget with parent pParent and return it 
in rRet
     typedef void (*customMakeWidget)(VclPtr<vcl::Window> &rRet, const 
VclPtr<vcl::Window> &pParent, stringmap &rVec);
 
@@ -351,10 +362,6 @@ private:
     static OUString getStyleClass(xmlreader::XmlReader &reader);
     void        applyPackingProperty(vcl::Window *pCurrent, vcl::Window 
*pParent, xmlreader::XmlReader &reader);
     void        collectProperty(xmlreader::XmlReader &reader, stringmap &rVec) 
const;
-    static void collectPangoAttribute(xmlreader::XmlReader &reader, stringmap 
&rMap);
-    static void collectAtkRelationAttribute(xmlreader::XmlReader &reader, 
stringmap &rMap);
-    static void collectAtkRoleAttribute(xmlreader::XmlReader &reader, 
stringmap &rMap);
-    static void collectAccelerator(xmlreader::XmlReader &reader, accelmap 
&rMap);
 
     void        insertMenuObject(
                    Menu *pParent,
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index b4c96baf6595..f3d16da17b8c 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -2870,7 +2870,7 @@ void VclBuilder::handleChild(vcl::Window *pParent, 
stringmap* pAtkProps, xmlread
     }
 }
 
-void VclBuilder::collectPangoAttribute(xmlreader::XmlReader &reader, stringmap 
&rMap)
+void BuilderBase::collectPangoAttribute(xmlreader::XmlReader& reader, 
stringmap& rMap)
 {
     xmlreader::Span span;
     int nsId;
@@ -2896,7 +2896,7 @@ void 
VclBuilder::collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &
         rMap[sProperty] = sValue;
 }
 
-void VclBuilder::collectAtkRelationAttribute(xmlreader::XmlReader &reader, 
stringmap &rMap)
+void BuilderBase::collectAtkRelationAttribute(xmlreader::XmlReader& reader, 
stringmap& rMap)
 {
     xmlreader::Span span;
     int nsId;
@@ -2925,7 +2925,7 @@ void 
VclBuilder::collectAtkRelationAttribute(xmlreader::XmlReader &reader, strin
         rMap[sProperty] = sValue;
 }
 
-void VclBuilder::collectAtkRoleAttribute(xmlreader::XmlReader &reader, 
stringmap &rMap)
+void BuilderBase::collectAtkRoleAttribute(xmlreader::XmlReader& reader, 
stringmap& rMap)
 {
     xmlreader::Span span;
     int nsId;
@@ -3997,7 +3997,7 @@ void VclBuilder::handleActionWidget(xmlreader::XmlReader 
&reader)
     set_response(sID, sResponse.toInt32());
 }
 
-void VclBuilder::collectAccelerator(xmlreader::XmlReader &reader, accelmap 
&rMap)
+void BuilderBase::collectAccelerator(xmlreader::XmlReader& reader, accelmap& 
rMap)
 {
     xmlreader::Span name;
     int nsId;

Reply via email to