include/vcl/builder.hxx | 16 +--------------- include/vcl/builderbase.hxx | 18 ++++++++++++++++++ include/vcl/widgetbuilder.hxx | 7 +++++++ vcl/inc/qt5/QtBuilder.hxx | 2 ++ vcl/qt5/QtBuilder.cxx | 5 +++++ vcl/source/window/builder.cxx | 31 ++++++++++++++++++------------- 6 files changed, 51 insertions(+), 28 deletions(-)
New commits: commit b54ffcb1337fb76c8c29ce6145c914f80c7f95b5 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Oct 4 22:18:17 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Oct 5 09:39:56 2024 +0200 tdf#130857 VclBuilder: Extract setMnemonicWidget helper + call from base Instead of iterating over the map of mnemonic widgets in the VclBuilder ctor, split the logic: Add a new purely virtual WidgetBuilder::setMnemonicWidget method to the base class that passes the IDs of a single pair of label + the corresponding mnemonic widget as params, and let WidgetBuilder::processUIFile call the method once for every pair in the map. Implement that for VclBuilder (by moving the remaining logic for that previously in the ctor) to the new override VclBuilder::setMnemonicWidget and add a dummy implementation for QtBuilder that only triggers a warning for now. Change-Id: I32c922f91e5e1d06c003e6d26a4342cbb98942e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174509 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 5c4fd558b5d2..1ea9410fd6b6 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -295,6 +295,7 @@ private: void applyAtkProperties(vcl::Window* pWindow, const stringmap& rProperties, bool bToolbarItem) override; + void setMnemonicWidget(const OUString& rLabelId, const OUString& rMnemonicWidgetId) override; void setPriority(vcl::Window* pWindow, int nPriority) override; void setContext(vcl::Window* pWindow, std::vector<vcl::EnumContext::Context>&& aContext) override; diff --git a/include/vcl/widgetbuilder.hxx b/include/vcl/widgetbuilder.hxx index 54d3d89c4d4f..b111b2d2041f 100644 --- a/include/vcl/widgetbuilder.hxx +++ b/include/vcl/widgetbuilder.hxx @@ -55,6 +55,12 @@ protected: assert(false && "missing ui file or missing gb_CppunitTest_use_uiconfigs dependency"); throw; } + + // Set Mnemonic widgets when everything has been imported + for (const MnemonicWidgetMap& rMnemonic : getMnemonicWidgetMaps()) + { + setMnemonicWidget(rMnemonic.m_sID, rMnemonic.m_sValue); + } } // either pParent or pAtkProps must be set, pParent for a child of a widget, pAtkProps for @@ -282,6 +288,7 @@ protected: std::string_view sInternalChild) = 0; + virtual void setMnemonicWidget(const OUString& rLabelId, const OUString& rMnemonicWidgetId) = 0; virtual void setPriority(Widget* pWidget, int nPriority) = 0; virtual void setContext(Widget* pWidget, std::vector<vcl::EnumContext::Context>&& aContext) = 0; diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx index 6ae06e3536b8..7e74f96bdfef 100644 --- a/vcl/inc/qt5/QtBuilder.hxx +++ b/vcl/inc/qt5/QtBuilder.hxx @@ -61,6 +61,8 @@ public: void tweakInsertedChild(QObject* pParent, QObject* pCurrentChild, std::string_view sType, std::string_view sInternalChild) override; + virtual void setMnemonicWidget(const OUString& rLabelId, + const OUString& rMnemonicWidgetId) override; virtual void setPriority(QObject* pObject, int nPriority) override; virtual void setContext(QObject* pObject, std::vector<vcl::EnumContext::Context>&& aContext) override; diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx index 36affcc04718..293399affc08 100644 --- a/vcl/qt5/QtBuilder.cxx +++ b/vcl/qt5/QtBuilder.cxx @@ -249,6 +249,11 @@ void QtBuilder::tweakInsertedChild(QObject* pParent, QObject* pCurrentChild, std } } +void QtBuilder::setMnemonicWidget(const OUString&, const OUString&) +{ + SAL_WARN("vcl.qt", "QtBuilder::setMnemonicWidget not implemented yet"); +} + void QtBuilder::setPriority(QObject*, int) { SAL_WARN("vcl.qt", "Ignoring priority"); } void QtBuilder::setContext(QObject*, std::vector<vcl::EnumContext::Context>&&) diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 3ac7e9db7abd..ddfa66e0ac3b 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -519,17 +519,6 @@ VclBuilder::VclBuilder(vcl::Window* pParent, std::u16string_view sUIDir, const O processUIFile(pParent); - //Set Mnemonic widgets when everything has been imported - for (auto const& mnemonicWidget : getMnemonicWidgetMaps()) - { - FixedText *pOne = get<FixedText>(mnemonicWidget.m_sID); - vcl::Window *pOther = get(mnemonicWidget.m_sValue); - SAL_WARN_IF(!pOne || !pOther, "vcl", "missing either source " << mnemonicWidget.m_sID - << " or target " << mnemonicWidget.m_sValue << " member of Mnemonic Widget Mapping"); - if (pOne && pOther) - pOne->set_mnemonic_widget(pOther); - } - //Set a11y relations and role when everything has been imported for (auto const& elemAtk : m_pVclParserState->m_aAtkInfo) { @@ -3084,6 +3073,17 @@ void VclBuilder::applyAtkProperties(vcl::Window *pWindow, const stringmap& rProp } } +void VclBuilder::setMnemonicWidget(const OUString& rLabelId, const OUString& rMnemonicWidgetId) +{ + FixedText* pOne = get<FixedText>(rLabelId); + vcl::Window* pOther = get(rMnemonicWidgetId); + SAL_WARN_IF(!pOne || !pOther, "vcl", + "missing either source " << rLabelId << " or target " << rMnemonicWidgetId + << " member of Mnemonic Widget Mapping"); + if (pOne && pOther) + pOne->set_mnemonic_widget(pOther); +} + void VclBuilder::setPriority(vcl::Window* pWindow, int nPriority) { vcl::IPrioritable* pPrioritable = dynamic_cast<vcl::IPrioritable*>(pWindow); commit 9bf932c00ba1ee8a2554f1c3c4bbc7ebff8b1995 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Oct 4 22:04:08 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Oct 5 09:39:48 2024 +0200 tdf#130857 VclBuilder: Move mnemonic-widget bookkeeping to base class Move the `m_aMnemonicWidgetMaps` member and related struct and typedef from VclBuilder's `m_pVclParserState` to the base class BuilderBase's `m_pParserState` and also move the VclBuilder::extractMnemonicWidget method to the base class, so the logic can later be reused by QtBuilder. Add a new getter BuilderBase::getMnemonicWidgetMaps to get access and use that in VclBuilder instead. At least for now, VclBuilder::extractMnemonicWidget still explicitly needs to be called by VclBuilder (and other subclasses) when encountering a "GtkLabel" object for the mnemonic widget relationship to be added to the map in the base class. Change-Id: I878eec7be5e82fac3e1b944d7fed7bf6711744ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174508 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index e378601656cb..5c4fd558b5d2 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -139,17 +139,6 @@ private: }; std::vector<MenuAndId> m_aMenus; - struct StringPair - { - OUString m_sID; - OUString m_sValue; - StringPair(OUString sId, OUString sValue) - : m_sID(std::move(sId)) - , m_sValue(std::move(sValue)) - { - } - }; - typedef StringPair RadioButtonGroupMap; struct ButtonImageWidgetMap @@ -168,7 +157,6 @@ private: typedef StringPair TextBufferMap; typedef StringPair WidgetAdjustmentMap; typedef StringPair ButtonMenuMap; - typedef StringPair MnemonicWidgetMap; struct ComboBoxModelMap { @@ -223,8 +211,6 @@ private: std::map<VclPtr<vcl::Window>, stringmap> m_aAtkInfo; - std::vector<MnemonicWidgetMap> m_aMnemonicWidgetMaps; - std::vector< VclPtr<VclExpander> > m_aExpanderWidgets; std::vector< VclPtr<MessageDialog> > m_aMessageDialogs; @@ -285,7 +271,6 @@ private: void extractBuffer(const OUString &id, stringmap &rVec); static bool extractAdjustmentToMap(const OUString &id, stringmap &rVec, std::vector<WidgetAdjustmentMap>& rAdjustmentMap); void extractButtonImage(const OUString &id, stringmap &rMap, bool bRadio); - void extractMnemonicWidget(const OUString &id, stringmap &rMap); void applyPackingProperties(vcl::Window* pCurrent, vcl::Window* pParent, const stringmap& rPackingProperties) override; diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx index 3c9ab89b9110..55f46c67a6e2 100644 --- a/include/vcl/builderbase.hxx +++ b/include/vcl/builderbase.hxx @@ -61,6 +61,19 @@ protected: SizeGroup() {} }; + struct StringPair + { + OUString m_sID; + OUString m_sValue; + StringPair(OUString sId, OUString sValue) + : m_sID(std::move(sId)) + , m_sValue(std::move(sValue)) + { + } + }; + + typedef StringPair MnemonicWidgetMap; + static void collectPangoAttribute(xmlreader::XmlReader& reader, stringmap& rMap); static void collectAtkRelationAttribute(xmlreader::XmlReader& reader, stringmap& rMap); static void collectAtkRoleAttribute(xmlreader::XmlReader& reader, stringmap& rMap); @@ -84,6 +97,9 @@ protected: const std::locale& getResLocale() const; const std::vector<SizeGroup>& getSizeGroups() const; + void extractMnemonicWidget(const OUString& id, stringmap& rMap); + const std::vector<MnemonicWidgetMap>& getMnemonicWidgetMaps() const; + OUString finalizeValue(const OString& rContext, const OString& rValue, const bool bTranslate) const; @@ -119,6 +135,8 @@ private: std::map<OUString, Adjustment> m_aAdjustments; std::map<OUString, TextBuffer> m_aTextBuffers; + + std::vector<MnemonicWidgetMap> m_aMnemonicWidgetMaps; }; std::unique_ptr<ParserState> m_pParserState; diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 2b8381f89b65..3ac7e9db7abd 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -474,6 +474,11 @@ const std::vector<BuilderBase::SizeGroup>& BuilderBase::getSizeGroups() const return m_pParserState->m_aSizeGroups; } +const std::vector<BuilderBase::MnemonicWidgetMap>& BuilderBase::getMnemonicWidgetMaps() const { + assert(m_pParserState && "parser state no more valid"); + return m_pParserState->m_aMnemonicWidgetMaps; +} + OUString BuilderBase::finalizeValue(const OString& rContext, const OString& rValue, const bool bTranslate) const { @@ -515,7 +520,7 @@ VclBuilder::VclBuilder(vcl::Window* pParent, std::u16string_view sUIDir, const O processUIFile(pParent); //Set Mnemonic widgets when everything has been imported - for (auto const& mnemonicWidget : m_pVclParserState->m_aMnemonicWidgetMaps) + for (auto const& mnemonicWidget : getMnemonicWidgetMaps()) { FixedText *pOne = get<FixedText>(mnemonicWidget.m_sID); vcl::Window *pOther = get(mnemonicWidget.m_sValue); @@ -1405,7 +1410,7 @@ void VclBuilder::extractButtonImage(const OUString &id, stringmap &rMap, bool bR } } -void VclBuilder::extractMnemonicWidget(const OUString &rLabelID, stringmap &rMap) +void BuilderBase::extractMnemonicWidget(const OUString &rLabelID, stringmap &rMap) { VclBuilder::stringmap::iterator aFind = rMap.find(u"mnemonic-widget"_ustr); if (aFind != rMap.end()) @@ -1414,7 +1419,7 @@ void VclBuilder::extractMnemonicWidget(const OUString &rLabelID, stringmap &rMap sal_Int32 nDelim = sID.indexOf(':'); if (nDelim != -1) sID = sID.copy(0, nDelim); - m_pVclParserState->m_aMnemonicWidgetMaps.emplace_back(rLabelID, sID); + m_pParserState->m_aMnemonicWidgetMaps.emplace_back(rLabelID, sID); rMap.erase(aFind); } }