[Libreoffice-commits] core.git: sw/source sw/uiconfig sw/UIConfig_swriter.mk

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Feb 23 09:17:20 UTC 2021


 sw/UIConfig_swriter.mk                  |    1 
 sw/source/uibase/utlui/tmplctrl.cxx     |   46 +++++++-------------------------
 sw/uiconfig/swriter/ui/pagestylemenu.ui |    9 ++++++
 3 files changed, 21 insertions(+), 35 deletions(-)

New commits:
commit fbac6127c7d2200afa0c476aa36785cb407fb6bd
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Feb 22 20:20:10 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Feb 23 10:16:42 2021 +0100

    replace SwTemplatePopup_Impl
    
    Change-Id: I82afec995488d388cb39c324f8f9a6684441fbe9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111361
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/UIConfig_swriter.mk b/sw/UIConfig_swriter.mk
index 16aaf178b3e3..167fa92548e8 100644
--- a/sw/UIConfig_swriter.mk
+++ b/sw/UIConfig_swriter.mk
@@ -239,6 +239,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/swriter,\
 	sw/uiconfig/swriter/ui/pagemargincontrol \
 	sw/uiconfig/swriter/ui/pageorientationcontrol \
 	sw/uiconfig/swriter/ui/pagesizecontrol \
+	sw/uiconfig/swriter/ui/pagestylemenu \
 	sw/uiconfig/swriter/ui/paradialog \
 	sw/uiconfig/swriter/ui/picturedialog \
 	sw/uiconfig/swriter/ui/picturepage \
diff --git a/sw/source/uibase/utlui/tmplctrl.cxx b/sw/source/uibase/utlui/tmplctrl.cxx
index d398dadee0b8..88a750be4d88 100644
--- a/sw/source/uibase/utlui/tmplctrl.cxx
+++ b/sw/source/uibase/utlui/tmplctrl.cxx
@@ -18,12 +18,12 @@
  */
 
 #include <svl/style.hxx>
-#include <vcl/menu.hxx>
 #include <svl/stritem.hxx>
 #include <sfx2/dispatch.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/status.hxx>
+#include <vcl/weldutils.hxx>
 
 #include <swtypes.hxx>
 #include <strings.hrc>
@@ -37,34 +37,6 @@
 
 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
 
-namespace {
-
-class SwTemplatePopup_Impl : public PopupMenu
-{
-public:
-    SwTemplatePopup_Impl();
-
-    sal_uInt16          GetCurId() const { return nCurId; }
-
-private:
-    sal_uInt16          nCurId;
-
-    virtual void    Select() override;
-};
-
-}
-
-SwTemplatePopup_Impl::SwTemplatePopup_Impl() :
-    PopupMenu(),
-    nCurId(USHRT_MAX)
-{
-}
-
-void SwTemplatePopup_Impl::Select()
-{
-    nCurId = GetCurItemId();
-}
-
 SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
                                       sal_uInt16 _nId,
                                       StatusBar& rStb ) :
@@ -100,7 +72,6 @@ void SwTemplateControl::Command( const CommandEvent& rCEvt )
             GetStatusBar().GetItemText( GetId() ).isEmpty())
         return;
 
-    ScopedVclPtrInstance<SwTemplatePopup_Impl> aPop;
     {
         SwView* pView = ::GetActiveView();
         SwWrtShell *const pWrtShell(pView ? pView->GetWrtShellPtr() : nullptr);
@@ -114,18 +85,23 @@ void SwTemplateControl::Command( const CommandEvent& rCEvt )
             auto xIter = pPool->CreateIterator(SfxStyleFamily::Page);
             if (xIter->Count() > 1)
             {
-                sal_uInt16 nCount = 0;
+                std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/pagestylemenu.ui"));
+                std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
+
+                sal_uInt32 nCount = 0;
                 SfxStyleSheetBase* pStyle = xIter->First();
                 while( pStyle )
                 {
-                    aPop->InsertItem( ++nCount, pStyle->GetName() );
+                    xPopup->append(OUString::number(++nCount), pStyle->GetName());
                     pStyle = xIter->Next();
                 }
 
-                aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
-                const sal_uInt16 nCurrId = aPop->GetCurId();
-                if( nCurrId != USHRT_MAX)
+                ::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())
                 {
+                    sal_uInt32 nCurrId = sResult.toUInt32();
                     // looks a bit awkward, but another way is not possible
                     pStyle = xIter->operator[]( nCurrId - 1 );
                     SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
diff --git a/sw/uiconfig/swriter/ui/pagestylemenu.ui b/sw/uiconfig/swriter/ui/pagestylemenu.ui
new file mode 100644
index 000000000000..53f81216379e
--- /dev/null
+++ b/sw/uiconfig/swriter/ui/pagestylemenu.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="sw">
+  <requires lib="gtk+" version="3.20"/>
+  <object class="GtkMenu" id="menu">
+    <property name="visible">True</property>
+    <property name="can-focus">False</property>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list