vcl/inc/jsdialog/jsdialogbuilder.hxx | 42 +++++--- vcl/jsdialog/jsdialogbuilder.cxx | 177 ++++++++++++++++++++--------------- 2 files changed, 133 insertions(+), 86 deletions(-)
New commits: commit 03866e6fab87cf623ac121be0c76b0c61eb094ed Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Wed Dec 4 11:20:09 2024 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Dec 9 08:43:50 2024 +0100 jsdialog: use single constructor for builder - we mostly do the same thing for initial values - enum already have "subtypes" - let's do it in one switch Signed-off-by: Szymon Kłos <szymon.k...@collabora.com> Change-Id: I0f9280168569067fde1758e3577d564f5e63172c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177783 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx index 36a4c6f975bd..9e3a6b0e350d 100644 --- a/vcl/inc/jsdialog/jsdialogbuilder.hxx +++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx @@ -120,6 +120,24 @@ public: class JSInstanceBuilder final : public SalInstanceBuilder, public JSDialogSender { + enum Type + { + Dialog, + Popup, + Sidebar, + Notebookbar, + Formulabar, + Menu, + }; + + void initializeDialogSender(); + void initializePopupSender(); + void initializeSidebarSender(sal_uInt64 nLOKWindowId, const std::u16string_view& rUIFile); + void initializeNotebookbarSender(sal_uInt64 nLOKWindowId); + void initializeFormulabarSender(sal_uInt64 nLOKWindowId, const std::u16string_view& sTypeOfJSON, + vcl::Window* pVclParent); + void initializeMenuSender(weld::Widget* pParent); + static jsdialog::WidgetRegister<std::shared_ptr<WidgetMap>> m_aWidgets; static jsdialog::WidgetRegister<VclPtr<vcl::Window>> m_aPopups; static jsdialog::WidgetRegister<weld::Menu*> m_aMenus; @@ -159,22 +177,15 @@ class JSInstanceBuilder final : public SalInstanceBuilder, public JSDialogSender OUString getMapIdFromWindowId() const; public: - /// used for dialogs or popups - JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile, - bool bPopup = false); - /// used for sidebar panels - JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, 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, - 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, - sal_uInt64 nLOKWindowId, const OUString& sTypeOfJSON); + JSInstanceBuilder(weld::Widget* pParent, vcl::Window* pVclParent, const OUString& rUIRoot, + const OUString& rUIFile, Type eBuilderType, sal_uInt64 nLOKWindowId = 0, + const std::u16string_view& sTypeOfJSON = u"", + const css::uno::Reference<css::frame::XFrame>& rFrame + = css::uno::Reference<css::frame::XFrame>()); static std::unique_ptr<JSInstanceBuilder> CreateDialogBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); + static std::unique_ptr<JSInstanceBuilder> CreateNotebookbarBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, const css::uno::Reference<css::frame::XFrame>& rFrame, @@ -183,8 +194,13 @@ public: const OUString& rUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId = 0); + static std::unique_ptr<JSInstanceBuilder> CreatePopupBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); + + static std::unique_ptr<JSInstanceBuilder> + CreateMenuBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile); + static std::unique_ptr<JSInstanceBuilder> CreateFormulabarBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx index cb4daf66ee2a..8a7b88160993 100644 --- a/vcl/jsdialog/jsdialogbuilder.cxx +++ b/vcl/jsdialog/jsdialogbuilder.cxx @@ -482,26 +482,9 @@ void JSDropTarget::fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEn } } -// used for dialogs -JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, - const OUString& rUIFile, bool bPopup) - : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile) - , m_nWindowId(0) - , m_aParentDialog(nullptr) - , m_aContentWindow(nullptr) - , m_sTypeOfJSON("dialog") - , m_bHasTopLevelDialog(false) - , m_bIsNotebookbar(false) - , m_bSentInitialUpdate(false) - , m_bIsNestedBuilder(false) - , m_aWindowToRelease(nullptr) +void JSInstanceBuilder::initializeDialogSender() { - // when it is a popup we initialize sender in weld_popover - if (bPopup) - { - m_sTypeOfJSON = "popup"; - return; - } + m_sTypeOfJSON = "dialog"; vcl::Window* pRoot = m_xBuilder->get_widget_root(); @@ -516,25 +499,23 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); } -// used for sidebar panels -JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, - const OUString& rUIFile, sal_uInt64 nLOKWindowId) - : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile) - , m_nWindowId(nLOKWindowId) - , m_aParentDialog(nullptr) - , m_aContentWindow(nullptr) - , m_sTypeOfJSON("sidebar") - , m_bHasTopLevelDialog(false) - , m_bIsNotebookbar(false) - , m_bSentInitialUpdate(false) - , m_bIsNestedBuilder(false) - , m_aWindowToRelease(nullptr) +void JSInstanceBuilder::initializePopupSender() +{ + // when it is a popup we initialize sender in weld_popover + m_sTypeOfJSON = "popup"; +} + +void JSInstanceBuilder::initializeSidebarSender(sal_uInt64 nLOKWindowId, + const std::u16string_view& rUIFile) { + m_sTypeOfJSON = "sidebar"; + m_nWindowId = nLOKWindowId; + vcl::Window* pRoot = m_xBuilder->get_widget_root(); m_aParentDialog = pRoot->GetParentWithLOKNotifier(); - if (rUIFile == "sfx/ui/panel.ui") + if (rUIFile == u"sfx/ui/panel.ui") { // builder for Panel, get SidebarDockingWindow as m_aContentWindow m_aContentWindow = pRoot; @@ -544,7 +525,7 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR else { // embedded fragments cannot send close message for whole sidebar - if (rUIFile == "modules/simpress/ui/customanimationfragment.ui") + if (rUIFile == u"modules/simpress/ui/customanimationfragment.ui") m_bCanClose = false; // builder for PanelLayout, get SidebarDockingWindow as m_aContentWindow @@ -558,31 +539,19 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); } -// used for notebookbar -JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, - const OUString& rUIFile, - const css::uno::Reference<css::frame::XFrame>& rFrame, - sal_uInt64 nWindowId) - : SalInstanceBuilder(pParent, rUIRoot, rUIFile, rFrame) - , m_nWindowId(0) - , m_aParentDialog(nullptr) - , m_aContentWindow(nullptr) - , m_sTypeOfJSON("notebookbar") - , m_bHasTopLevelDialog(false) - , m_bIsNotebookbar(false) - , m_bSentInitialUpdate(false) - , m_bIsNestedBuilder(false) - , m_aWindowToRelease(nullptr) +void JSInstanceBuilder::initializeNotebookbarSender(sal_uInt64 nLOKWindowId) { + m_sTypeOfJSON = "notebookbar"; + vcl::Window* pRoot = m_xBuilder->get_widget_root(); if (pRoot && pRoot->GetParent()) { m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); if (m_aParentDialog) m_nWindowId = m_aParentDialog->GetLOKWindowId(); - if (!m_nWindowId && nWindowId) + if (!m_nWindowId && nLOKWindowId) { - m_nWindowId = nWindowId; + m_nWindowId = nLOKWindowId; m_bIsNotebookbar = true; } InsertWindowToMap(getMapIdFromWindowId()); @@ -591,44 +560,94 @@ JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRo initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); } -// used for formulabar and addressinputfield -JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRoot, - const OUString& rUIFile, sal_uInt64 nLOKWindowId, - const OUString& sTypeOfJSON) - : SalInstanceBuilder(pParent, rUIRoot, rUIFile) - , m_nWindowId(nLOKWindowId) +void JSInstanceBuilder::initializeFormulabarSender(sal_uInt64 nLOKWindowId, + const std::u16string_view& sTypeOfJSON, + vcl::Window* pVclParent) +{ + m_sTypeOfJSON = sTypeOfJSON; + m_nWindowId = nLOKWindowId; + + vcl::Window* pRoot = m_xBuilder->get_widget_root(); + m_aContentWindow = pVclParent; + if (pRoot && pRoot->GetParent()) + { + m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); + InsertWindowToMap(getMapIdFromWindowId()); + } + + initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); +} + +void JSInstanceBuilder::initializeMenuSender(weld::Widget* pParent) +{ + m_sTypeOfJSON = "menu"; + m_aParentDialog = extract_sal_widget(pParent)->GetParentWithLOKNotifier(); + initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); +} + +JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, vcl::Window* pVclParent, + const OUString& rUIRoot, const OUString& rUIFile, + JSInstanceBuilder::Type eBuilderType, sal_uInt64 nLOKWindowId, + const std::u16string_view& sTypeOfJSON, + const css::uno::Reference<css::frame::XFrame>& rFrame) + : SalInstanceBuilder(pVclParent ? pVclParent : extract_sal_widget(pParent), rUIRoot, rUIFile, + rFrame) + , m_nWindowId(0) , m_aParentDialog(nullptr) , m_aContentWindow(nullptr) - , m_sTypeOfJSON(sTypeOfJSON) + , m_sTypeOfJSON("unknown") , m_bHasTopLevelDialog(false) , m_bIsNotebookbar(false) , m_bSentInitialUpdate(false) , m_bIsNestedBuilder(false) , m_aWindowToRelease(nullptr) { - vcl::Window* pRoot = m_xBuilder->get_widget_root(); - m_aContentWindow = pParent; - if (pRoot && pRoot->GetParent()) + switch (eBuilderType) { - m_aParentDialog = pRoot->GetParent()->GetParentWithLOKNotifier(); - InsertWindowToMap(getMapIdFromWindowId()); - } + case JSInstanceBuilder::Type::Dialog: + initializeDialogSender(); + break; - initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON()); + case JSInstanceBuilder::Type::Popup: + initializePopupSender(); + break; + + case JSInstanceBuilder::Type::Sidebar: + initializeSidebarSender(nLOKWindowId, rUIFile); + break; + + case JSInstanceBuilder::Type::Notebookbar: + initializeNotebookbarSender(nLOKWindowId); + break; + + case JSInstanceBuilder::Type::Formulabar: + initializeFormulabarSender(nLOKWindowId, sTypeOfJSON, pVclParent); + break; + + case JSInstanceBuilder::Type::Menu: + initializeMenuSender(pParent); + break; + + default: + assert(false); + }; } std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateDialogBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile) { - return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile); + return std::make_unique<JSInstanceBuilder>(pParent, nullptr, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Dialog); } std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateNotebookbarBuilder( vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, const css::uno::Reference<css::frame::XFrame>& rFrame, sal_uInt64 nWindowId) { - return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, rFrame, nWindowId); + return std::make_unique<JSInstanceBuilder>(nullptr, pParent, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Notebookbar, nWindowId, u"", + rFrame); } std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateSidebarBuilder(weld::Widget* pParent, @@ -636,30 +655,42 @@ std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateSidebarBuilder(weld: const OUString& rUIFile, sal_uInt64 nLOKWindowId) { - return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, nLOKWindowId); + return std::make_unique<JSInstanceBuilder>(pParent, nullptr, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Sidebar, nLOKWindowId); } std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreatePopupBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile) { - return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, true); + return std::make_unique<JSInstanceBuilder>(pParent, nullptr, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Popup); +} + +std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateMenuBuilder(weld::Widget* pParent, + const OUString& rUIRoot, + const OUString& rUIFile) +{ + return std::make_unique<JSInstanceBuilder>(pParent, nullptr, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Menu); } std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateFormulabarBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId) { - return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, nLOKWindowId, - "formulabar"); + return std::make_unique<JSInstanceBuilder>(nullptr, pParent, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Formulabar, nLOKWindowId, + u"formulabar"); } std::unique_ptr<JSInstanceBuilder> JSInstanceBuilder::CreateAddressInputBuilder(vcl::Window* pParent, const OUString& rUIRoot, const OUString& rUIFile, sal_uInt64 nLOKWindowId) { - return std::make_unique<JSInstanceBuilder>(pParent, rUIRoot, rUIFile, nLOKWindowId, - "addressinputfield"); + return std::make_unique<JSInstanceBuilder>(nullptr, pParent, rUIRoot, rUIFile, + JSInstanceBuilder::Type::Formulabar, nLOKWindowId, + u"addressinputfield"); } JSInstanceBuilder::~JSInstanceBuilder()