diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-02-19 15:55:06 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-02-19 20:43:41 +0100 |
commit | d648cf4d1a56ac7d4bb4e0e6c533549a0e4b25f8 (patch) | |
tree | d57da7bfff1c8bfe188e3dcb6557c33d7805e27a /sd/source/ui/sidebar | |
parent | bac75eaed7d09f917497f59b021235b5eeb567ae (diff) |
weld MasterPagesSelector context menus
Change-Id: I0ed933d81ef8f5004c8efa36dd0cdcdca947a0a7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111233
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sd/source/ui/sidebar')
-rw-r--r-- | sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx | 15 | ||||
-rw-r--r-- | sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx | 3 | ||||
-rw-r--r-- | sd/source/ui/sidebar/MasterPagesSelector.cxx | 38 | ||||
-rw-r--r-- | sd/source/ui/sidebar/MasterPagesSelector.hxx | 3 |
4 files changed, 16 insertions, 43 deletions
diff --git a/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx b/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx index 9eba6427953d..93fb071b8080 100644 --- a/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx +++ b/sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx @@ -215,24 +215,17 @@ void CurrentMasterPagesSelector::ExecuteCommand(const OString &rIdent) MasterPagesSelector::ExecuteCommand(rIdent); } -void CurrentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu) +void CurrentMasterPagesSelector::ProcessPopupMenu(weld::Menu& rMenu) { // Disable the delete entry when there is only one master page. if (mrDocument.GetMasterPageUserCount(GetSelectedMasterPage()) > 0) - { - sal_uInt16 nItemid = rMenu.GetItemId("delete"); - if (rMenu.GetItemPos(nItemid) != MENU_ITEM_NOTFOUND) - rMenu.EnableItem(nItemid, false); - } + rMenu.set_sensitive("delete", false); std::shared_ptr<DrawViewShell> pDrawViewShell ( std::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell())); - if (pDrawViewShell - && pDrawViewShell->GetEditMode() == EditMode::MasterPage) + if (pDrawViewShell && pDrawViewShell->GetEditMode() == EditMode::MasterPage) { - sal_uInt16 nItemid = rMenu.GetItemId("edit"); - if (rMenu.GetItemPos(nItemid) != MENU_ITEM_NOTFOUND) - rMenu.EnableItem(nItemid, false); + rMenu.set_sensitive("edit", false); } MasterPagesSelector::ProcessPopupMenu(rMenu); diff --git a/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx b/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx index 87244b530f81..889996f7160a 100644 --- a/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx +++ b/sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx @@ -24,7 +24,6 @@ #include "MasterPagesSelector.hxx" - namespace sd::tools { class EventMultiplexerEvent; } namespace sd::sidebar { @@ -57,7 +56,7 @@ public: protected: virtual OUString GetContextMenuUIFile() const override; - virtual void ProcessPopupMenu (Menu& rMenu) override; + virtual void ProcessPopupMenu(weld::Menu& rMenu) override; virtual void ExecuteCommand(const OString &rIdent) override; private: diff --git a/sd/source/ui/sidebar/MasterPagesSelector.cxx b/sd/source/ui/sidebar/MasterPagesSelector.cxx index 9f8cc860669e..7376d63ec7d3 100644 --- a/sd/source/ui/sidebar/MasterPagesSelector.cxx +++ b/sd/source/ui/sidebar/MasterPagesSelector.cxx @@ -35,10 +35,10 @@ #include "PreviewValueSet.hxx" #include <ViewShellBase.hxx> #include <o3tl/safeint.hxx> -#include <vcl/builder.hxx> #include <vcl/commandevent.hxx> #include <vcl/image.hxx> #include <vcl/floatwin.hxx> +#include <vcl/weldutils.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/sidebar/Theme.hxx> @@ -213,18 +213,13 @@ void MasterPagesSelector::ShowContextMenu(const Point* pPos) aPosition = *pPos; // Setup the menu. - VclBuilder aBuilder(nullptr, AllSettings::GetUIRootDir(), GetContextMenuUIFile(), ""); - VclPtr<PopupMenu> pMenu(aBuilder.get_menu("menu")); - FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); - if (pMenuWindow != nullptr) - pMenuWindow->SetPopupModeFlags( - pMenuWindow->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose); - pMenu->SetSelectHdl(LINK(this, MasterPagesSelector, OnMenuItemSelected)); - - ProcessPopupMenu(*pMenu); - + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, GetContextMenuUIFile())); + std::unique_ptr<weld::Menu> xMenu(xBuilder->weld_menu("menu")); + ProcessPopupMenu(*xMenu); + ::tools::Rectangle aRect(aPosition, Size(1,1)); + weld::Window* pParent = weld::GetPopupParent(*this, aRect); // Show the menu. - pMenu->Execute(this, ::tools::Rectangle(aPosition,Size(1,1)), PopupMenuFlags::ExecuteDown); + ExecuteCommand(xMenu->popup_at_rect(pParent, aRect)); } void MasterPagesSelector::Command (const CommandEvent& rEvent) @@ -233,26 +228,13 @@ void MasterPagesSelector::Command (const CommandEvent& rEvent) ShowContextMenu(rEvent.IsMouseEvent() ? &rEvent.GetMousePosPixel() : nullptr); } -void MasterPagesSelector::ProcessPopupMenu (Menu& rMenu) +void MasterPagesSelector::ProcessPopupMenu(weld::Menu& rMenu) { // Disable some entries. if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL) - rMenu.EnableItem(rMenu.GetItemId("small"), false); + rMenu.set_sensitive("small", false); else - rMenu.EnableItem(rMenu.GetItemId("large"), false); -} - -IMPL_LINK(MasterPagesSelector, OnMenuItemSelected, Menu*, pMenu, bool) -{ - if (pMenu == nullptr) - { - OSL_ENSURE(pMenu!=nullptr, "MasterPagesSelector::OnMenuItemSelected: illegal menu!"); - return false; - } - - pMenu->Deactivate(); - ExecuteCommand(pMenu->GetCurItemIdent()); - return false; + rMenu.set_sensitive("large", false); } void MasterPagesSelector::ExecuteCommand(const OString &rIdent) diff --git a/sd/source/ui/sidebar/MasterPagesSelector.hxx b/sd/source/ui/sidebar/MasterPagesSelector.hxx index a406f3bc9a99..28b7be099c5a 100644 --- a/sd/source/ui/sidebar/MasterPagesSelector.hxx +++ b/sd/source/ui/sidebar/MasterPagesSelector.hxx @@ -153,7 +153,7 @@ protected: virtual void Command (const CommandEvent& rEvent) override; - virtual void ProcessPopupMenu (Menu& rMenu); + virtual void ProcessPopupMenu(weld::Menu& rMenu); virtual void ExecuteCommand(const OString& rIdent); private: @@ -166,7 +166,6 @@ private: DECL_LINK(ClickHandler, ValueSet*, void); DECL_LINK(RightClickHandler, const MouseEvent&, void); DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent&, void); - DECL_LINK(OnMenuItemSelected, Menu*, bool); void SetItem ( sal_uInt16 nIndex, |