[Libreoffice-commits] core.git: sd/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Feb 19 19:44:25 UTC 2021


 sd/source/ui/sidebar/CurrentMasterPagesSelector.cxx |   15 ++-----
 sd/source/ui/sidebar/CurrentMasterPagesSelector.hxx |    3 -
 sd/source/ui/sidebar/MasterPagesSelector.cxx        |   38 +++++---------------
 sd/source/ui/sidebar/MasterPagesSelector.hxx        |    3 -
 4 files changed, 16 insertions(+), 43 deletions(-)

New commits:
commit d648cf4d1a56ac7d4bb4e0e6c533549a0e4b25f8
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Fri Feb 19 15:55:06 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Feb 19 20:43:41 2021 +0100

    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 at redhat.com>

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,


More information about the Libreoffice-commits mailing list