sd/UIConfig_simpress.mk                   |    1 
 sd/source/ui/app/tmplctrl.cxx             |   79 +++++++++---------------------
 sd/uiconfig/simpress/ui/masterpagemenu.ui |    9 +++
 3 files changed, 35 insertions(+), 54 deletions(-)

New commits:
commit e0bee1a05bdad73d61fb89e25b1510a12deed1f1
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Feb 22 20:35:35 2021 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue Feb 23 10:18:07 2021 +0100

    replace SdTemplatePopup_Impl
    
    Change-Id: I734124939139e34c776e5e4fe52acde08abf24ac
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111364
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sd/UIConfig_simpress.mk b/sd/UIConfig_simpress.mk
index d6b96e034661..a532a2819e2d 100644
--- a/sd/UIConfig_simpress.mk
+++ b/sd/UIConfig_simpress.mk
@@ -134,6 +134,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/simpress,\
        sd/uiconfig/simpress/ui/layoutwindow \
        sd/uiconfig/simpress/ui/masterlayoutdlg \
        sd/uiconfig/simpress/ui/mastermenu \
+       sd/uiconfig/simpress/ui/masterpagemenu \
        sd/uiconfig/simpress/ui/masterpagepanel \
        sd/uiconfig/simpress/ui/navigatorpanel \
        sd/uiconfig/simpress/ui/notebookbar \
diff --git a/sd/source/ui/app/tmplctrl.cxx b/sd/source/ui/app/tmplctrl.cxx
index 62d3ba6336a1..a6b89fb1dad4 100644
--- a/sd/source/ui/app/tmplctrl.cxx
+++ b/sd/source/ui/app/tmplctrl.cxx
@@ -18,8 +18,8 @@
  */
 
 #include <vcl/commandevent.hxx>
-#include <vcl/menu.hxx>
 #include <vcl/status.hxx>
+#include <vcl/weldutils.hxx>
 #include <svl/stritem.hxx>
 #include <sfx2/dispatch.hxx>
 #include <sfx2/viewfrm.hxx>
@@ -35,38 +35,7 @@
 
 SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem );
 
-// class SdTemplatePopup_Impl 
--------------------------------------------------
-
-namespace {
-
-class SdTemplatePopup_Impl : public PopupMenu
-{
-public:
-    SdTemplatePopup_Impl();
-
-    sal_uInt16          GetCurId() const { return nCurId; }
-
-private:
-    sal_uInt16          nCurId;
-
-    virtual void    Select() override;
-};
-
-}
-
-SdTemplatePopup_Impl::SdTemplatePopup_Impl() :
-    PopupMenu(),
-    nCurId(USHRT_MAX)
-{
-}
-
-void SdTemplatePopup_Impl::Select()
-{
-    nCurId = GetCurItemId();
-}
-
 // class SdTemplateControl ------------------------------------------
-
 SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId,
                                       sal_uInt16 _nId,
                                       StatusBar& rStb ) :
@@ -110,29 +79,31 @@ void SdTemplateControl::Command( const CommandEvent& rCEvt 
)
     if( !pDoc )
         return;
 
-    ScopedVclPtrInstance<SdTemplatePopup_Impl> aPop;
+    std::unique_ptr<weld::Builder> 
xBuilder(Application::CreateBuilder(nullptr, 
"modules/simpress/ui/masterpagemenu.ui"));
+    std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
+
+    const sal_uInt16 nMasterCount = 
pDoc->GetMasterSdPageCount(PageKind::Standard);
+
+    for (sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage)
+    {
+        SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PageKind::Standard);
+        if (!pMaster)
+            continue;
+        xPopup->append(OUString::number(nPage), pMaster->GetName());
+    }
+
+    ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
+    weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect);
+    OString sResult = xPopup->popup_at_rect(pParent, aRect);
+    if (!sResult.isEmpty())
     {
-        const sal_uInt16 nMasterCount = 
pDoc->GetMasterSdPageCount(PageKind::Standard);
-
-        sal_uInt16 nCount = 0;
-        for( sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage )
-        {
-            SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PageKind::Standard);
-            if( pMaster )
-                aPop->InsertItem( ++nCount, pMaster->GetName() );
-        }
-        aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
-
-        sal_uInt16 nCurrId = aPop->GetCurId()-1;
-        if( nCurrId < nMasterCount )
-        {
-            SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, 
PageKind::Standard);
-            SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
-            pViewFrame->GetDispatcher()->ExecuteList(
-                SID_PRESENTATION_LAYOUT, SfxCallMode::SLOT, { &aStyle });
-            pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
-            pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
-        }
+        sal_uInt16 nCurrId = sResult.toUInt32();
+        SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PageKind::Standard);
+        SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
+        pViewFrame->GetDispatcher()->ExecuteList(
+            SID_PRESENTATION_LAYOUT, SfxCallMode::SLOT, { &aStyle });
+        pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
+        pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
     }
 }
 
diff --git a/sd/uiconfig/simpress/ui/masterpagemenu.ui 
b/sd/uiconfig/simpress/ui/masterpagemenu.ui
new file mode 100644
index 000000000000..5bb702561dd2
--- /dev/null
+++ b/sd/uiconfig/simpress/ui/masterpagemenu.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="sd">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="menu">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+  </object>
+</interface>
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to