include/vcl/builder.hxx | 2 +- include/vcl/builderbase.hxx | 4 +++- include/vcl/widgetbuilder.hxx | 25 +++++++++++++++++++++++-- vcl/inc/jsdialog/jsdialogbuilder.hxx | 8 ++++---- vcl/inc/salvtables.hxx | 2 +- vcl/jsdialog/jsdialogbuilder.cxx | 16 ++++++++-------- vcl/source/app/salvtables.cxx | 4 ++-- vcl/source/window/builder.cxx | 23 +++++------------------ 8 files changed, 47 insertions(+), 37 deletions(-)
New commits: commit 1a1bf2b78d689a570cc71b7bcb3e0100947a2fb1 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Wed Sep 25 09:08:06 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Sep 25 21:09:14 2024 +0200 tdf#130857 VclBuilder: Extract helper to start parsing UI file Extract logic to start parsing/processing the VclBuilder's .ui file from the VclBuilder ctor to a new helper method in the base class, WidgetBuilder::processUIFile. This will allow to reuse it in the upcoming QtBuilder. Change-Id: Ia7d31563e5aeef0786b0db34abb1a32a3a479947 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173902 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/widgetbuilder.hxx b/include/vcl/widgetbuilder.hxx index ccd418e2c0d2..d5934dcaf4f3 100644 --- a/include/vcl/widgetbuilder.hxx +++ b/include/vcl/widgetbuilder.hxx @@ -9,6 +9,9 @@ #pragma once +#include <com/sun/star/uno/Exception.hpp> +#include <comphelper/diagnose_ex.hxx> +#include <desktop/crashreport.hxx> #include <sal/log.hxx> #include <vcl/builderbase.hxx> #include <xmlreader/span.hxx> @@ -39,6 +42,24 @@ protected: } virtual ~WidgetBuilder() = default; + void processUIFile(Widget* pParent) + { + try + { + xmlreader::XmlReader reader(getUIFileUrl()); + handleChild(pParent, nullptr, reader); + } + catch (const css::uno::Exception& rExcept) + { + TOOLS_WARN_EXCEPTION("vcl.builder", "Unable to read .ui file " << getUIFileUrl()); + CrashReporter::addKeyValue(u"VclBuilderException"_ustr, + "Unable to read .ui file: " + rExcept.Message, + CrashReporter::Write); + assert(false && "missing ui file or missing gb_CppunitTest_use_uiconfigs dependency"); + throw; + } + } + // either pParent or pAtkProps must be set, pParent for a child of a widget, pAtkProps for // collecting the atk info for a GtkMenuItem or tab child void handleChild(Widget* pParent, stringmap* pAtkProps, xmlreader::XmlReader& reader, diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index bfbab0d89a00..54a1fed494d9 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -72,13 +72,11 @@ #include <PriorityHBox.hxx> #include <window.h> #include <xmlreader/xmlreader.hxx> -#include <desktop/crashreport.hxx> #include <calendar.hxx> #include <menutogglebutton.hxx> #include <salinst.hxx> #include <strings.hrc> #include <treeglue.hxx> -#include <comphelper/diagnose_ex.hxx> #include <verticaltabctrl.hxx> #include <wizdlg.hxx> #include <tools/svlibrary.h> @@ -506,19 +504,7 @@ VclBuilder::VclBuilder(vcl::Window* pParent, std::u16string_view sUIDir, const O (pParent->IsDockingWindow() && static_cast<DockingWindow*>(pParent)->isDeferredInit())); m_bToplevelHasDeferredProperties = m_bToplevelHasDeferredInit; - try - { - xmlreader::XmlReader reader(getUIFileUrl()); - - handleChild(pParent, nullptr, reader); - } - catch (const css::uno::Exception &rExcept) - { - TOOLS_WARN_EXCEPTION("vcl.builder", "Unable to read .ui file " << getUIFileUrl()); - CrashReporter::addKeyValue(u"VclBuilderException"_ustr, "Unable to read .ui file: " + rExcept.Message, CrashReporter::Write); - assert(false && "missing ui file or missing gb_CppunitTest_use_uiconfigs dependency"); - throw; - } + processUIFile(pParent); //Set Mnemonic widgets when everything has been imported for (auto const& mnemonicWidget : m_pVclParserState->m_aMnemonicWidgetMaps) commit ad19f3b9f23ddd4179589e9a641094f3e7642e72 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Sep 23 18:13:05 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Wed Sep 25 21:09:07 2024 +0200 tdf#130857 VclBuilder: Pass UI dir/root to BuilderBase Pass the UI file root down to `BuilderBase`, and add a new getter `BuilderBase::getUIFileUrl` to get the URL composed of the UI dir and the UI file passed to the ctor. This is in preparation of moving the `XmlReader` creation out of the `VclBuilder` ctor, so the code can be reused by the upcoming `QtBuilder`. Change the UI directory param from `const OUString&` to `std::u16_string_view` as suggested by the clang plugin. Change-Id: I3f7719e30e55bae3c774da704e642e4227165a76 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173827 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 3ad480eece64..61f7172d0395 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -61,7 +61,7 @@ public: typedef void (*customMakeWidget)(VclPtr<vcl::Window> &rRet, const VclPtr<vcl::Window> &pParent, stringmap &rVec); public: - VclBuilder(vcl::Window* pParent, const OUString& sUIRootDir, const OUString& sUIFile, + VclBuilder(vcl::Window* pParent, std::u16string_view sUIRootDir, const OUString& sUIFile, OUString sID = {}, css::uno::Reference<css::frame::XFrame> xFrame = css::uno::Reference<css::frame::XFrame>(), diff --git a/include/vcl/builderbase.hxx b/include/vcl/builderbase.hxx index 3c833c054434..cee443c26310 100644 --- a/include/vcl/builderbase.hxx +++ b/include/vcl/builderbase.hxx @@ -43,7 +43,7 @@ public: typedef stringmap TextBuffer; protected: - BuilderBase(const OUString& rUIFile, bool bLegacy); + BuilderBase(std::u16string_view sUIDir, const OUString& rUIFile, bool bLegacy); virtual ~BuilderBase() = default; struct ListStore @@ -76,6 +76,7 @@ protected: static OUString getStyleClass(xmlreader::XmlReader& reader); static bool hasOrientationVertical(stringmap& rMap); + OUString getUIFileUrl() { return m_sUIFileUrl; } OUString getHelpRoot() { return m_sHelpRoot; } bool isLegacy() { return m_bLegacy; } const std::locale& getResLocale() const; @@ -118,6 +119,7 @@ private: std::unique_ptr<ParserState> m_pParserState; + OUString m_sUIFileUrl; OUString m_sHelpRoot; bool m_bLegacy; }; diff --git a/include/vcl/widgetbuilder.hxx b/include/vcl/widgetbuilder.hxx index da2370ad5845..ccd418e2c0d2 100644 --- a/include/vcl/widgetbuilder.hxx +++ b/include/vcl/widgetbuilder.hxx @@ -33,8 +33,8 @@ template <typename Widget, typename WidgetPtr> class WidgetBuilder : public BuilderBase { protected: - WidgetBuilder(const OUString& rUIFile, bool bLegacy) - : BuilderBase(rUIFile, bLegacy) + WidgetBuilder(std::u16string_view sUIDir, const OUString& rUIFile, bool bLegacy) + : BuilderBase(sUIDir, rUIFile, bLegacy) { } virtual ~WidgetBuilder() = default; diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index ac529cef12b0..33bf2ccb6bd3 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -249,17 +249,17 @@ class JSInstanceBuilder final : public SalInstanceBuilder, public JSDialogSender public: /// used for dialogs or popups - JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile, + JSInstanceBuilder(weld::Widget* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, bool bPopup = false); /// used for sidebar panels - JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile, + JSInstanceBuilder(weld::Widget* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId); /// used for notebookbar, optional nWindowId is used if getting parent id failed - JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, + JSInstanceBuilder(vcl::Window* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, const css::uno::Reference<css::frame::XFrame>& rFrame, sal_uInt64 nWindowId = 0); /// used for formulabar - JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, + JSInstanceBuilder(vcl::Window* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId); static std::unique_ptr<JSInstanceBuilder> diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index ba7653a0fc40..f57ecc9395e3 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -46,7 +46,7 @@ protected: VclPtr<vcl::Window> m_aOwnedToplevel; public: - SalInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, + SalInstanceBuilder(vcl::Window* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, const css::uno::Reference<css::frame::XFrame>& rFrame = css::uno::Reference<css::frame::XFrame>()); diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index 7c90d59e8c48..797247fef13e 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -492,9 +492,9 @@ OUString JSInstanceBuilder::getMapIdFromWindowId() const } // used for dialogs -JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, +JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const std::u16string_view sUIRoot, const OUString& rUIFile, bool bPopup) - : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile) + : SalInstanceBuilder(extract_sal_widget(pParent), sUIRoot, rUIFile) , m_nWindowId(0) , m_aParentDialog(nullptr) , m_aContentWindow(nullptr) @@ -526,9 +526,9 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR } // used for sidebar panels -JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, +JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId) - : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile) + : SalInstanceBuilder(extract_sal_widget(pParent), sUIRoot, rUIFile) , m_nWindowId(nLOKWindowId) , m_aParentDialog(nullptr) , m_aContentWindow(nullptr) @@ -568,11 +568,11 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR } // used for notebookbar -JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, +JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, const css::uno::Reference<css::frame::XFrame>& rFrame, sal_uInt64 nWindowId) - : SalInstanceBuilder(pParent, rUIRoot, rUIFile, rFrame) + : SalInstanceBuilder(pParent, sUIRoot, rUIFile, rFrame) , m_nWindowId(0) , m_aParentDialog(nullptr) , m_aContentWindow(nullptr) @@ -601,9 +601,9 @@ JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRo } // used for formulabar -JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, +JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId) - : SalInstanceBuilder(pParent, rUIRoot, rUIFile) + : SalInstanceBuilder(pParent, sUIRoot, rUIFile) , m_nWindowId(nLOKWindowId) , m_aParentDialog(nullptr) , m_aContentWindow(nullptr) diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 728f2ec8428d..c875b3847ea1 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -7078,11 +7078,11 @@ void SalInstancePopover::resize_to_request() IMPL_LINK_NOARG(SalInstancePopover, PopupModeEndHdl, FloatingWindow*, void) { signal_closed(); } -SalInstanceBuilder::SalInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, +SalInstanceBuilder::SalInstanceBuilder(vcl::Window* pParent, std::u16string_view sUIRoot, const OUString& rUIFile, const css::uno::Reference<css::frame::XFrame>& rFrame) : weld::Builder() - , m_xBuilder(new VclBuilder(pParent, rUIRoot, rUIFile, {}, rFrame, false)) + , m_xBuilder(new VclBuilder(pParent, sUIRoot, rUIFile, {}, rFrame, false)) { } diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 25bab94a1265..bfbab0d89a00 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -444,8 +444,9 @@ namespace weld } } -BuilderBase::BuilderBase(const OUString& rUIFile, bool bLegacy) +BuilderBase::BuilderBase(std::u16string_view sUIDir, const OUString& rUIFile, bool bLegacy) : m_pParserState(new ParserState) + , m_sUIFileUrl(sUIDir + rUIFile) , m_sHelpRoot(rUIFile) , m_bLegacy(bLegacy) { @@ -487,10 +488,10 @@ OUString BuilderBase::finalizeValue(const OString& rContext, const OString& rVal void BuilderBase::resetParserState() { m_pParserState.reset(); } -VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUString& sUIFile, +VclBuilder::VclBuilder(vcl::Window* pParent, std::u16string_view sUIDir, const OUString& sUIFile, OUString sID, css::uno::Reference<css::frame::XFrame> xFrame, bool bLegacy, const NotebookBarAddonsItem* pNotebookBarAddonsItem) - : WidgetBuilder(sUIFile, bLegacy) + : WidgetBuilder(sUIDir, sUIFile, bLegacy) , m_pNotebookBarAddonsItem(pNotebookBarAddonsItem ? new NotebookBarAddonsItem(*pNotebookBarAddonsItem) : new NotebookBarAddonsItem{}) @@ -507,13 +508,13 @@ VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUStr try { - xmlreader::XmlReader reader(sUIDir + sUIFile); + xmlreader::XmlReader reader(getUIFileUrl()); handleChild(pParent, nullptr, reader); } catch (const css::uno::Exception &rExcept) { - TOOLS_WARN_EXCEPTION("vcl.builder", "Unable to read .ui file " << sUIDir << sUIFile); + TOOLS_WARN_EXCEPTION("vcl.builder", "Unable to read .ui file " << getUIFileUrl()); CrashReporter::addKeyValue(u"VclBuilderException"_ustr, "Unable to read .ui file: " + rExcept.Message, CrashReporter::Write); assert(false && "missing ui file or missing gb_CppunitTest_use_uiconfigs dependency"); throw;