[Libreoffice-commits] core.git: include/svx svx/source svx/uiconfig svx/UIConfig_svx.mk

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


 include/svx/clipboardctl.hxx         |    8 +-------
 svx/UIConfig_svx.mk                  |    1 +
 svx/source/mnuctrls/clipboardctl.cxx |   33 +++++++++------------------------
 svx/uiconfig/ui/clipboardmenu.ui     |    9 +++++++++
 4 files changed, 20 insertions(+), 31 deletions(-)

New commits:
commit c25f4b4db367ab66702e83bf27c2561cc7d0e5f9
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Feb 22 19:59:56 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Feb 23 10:14:27 2021 +0100

    weld clipboard menu
    
    Change-Id: Ifbc3154c740e2731f4462324a3413bdcdae068ae
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111358
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/svx/clipboardctl.hxx b/include/svx/clipboardctl.hxx
index ec805c95896f..00a0a301d7f7 100644
--- a/include/svx/clipboardctl.hxx
+++ b/include/svx/clipboardctl.hxx
@@ -24,22 +24,16 @@
 #include <sfx2/tbxctrl.hxx>
 #include <svl/poolitem.hxx>
 #include <svx/svxdllapi.h>
-#include <vcl/vclptr.hxx>
 #include <memory>
 
-class PopupMenu;
 class SfxModule;
 class ToolBox;
 
 class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxClipBoardControl final : public SfxToolBoxControl
 {
-    std::unique_ptr<SfxPoolItem>
-                            pClipboardFmtItem;
-    VclPtr<PopupMenu>       pPopup;
+    std::unique_ptr<SfxPoolItem> pClipboardFmtItem;
     bool                    bDisabled;
 
-    void                    DelPopup();
-
 public:
     SFX_DECL_TOOLBOX_CONTROL();
 
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index 667ef8ad8f33..747777aa95ad 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -28,6 +28,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
 	svx/uiconfig/ui/chineseconversiondialog \
 	svx/uiconfig/ui/chinesedictionary \
 	svx/uiconfig/ui/classificationdialog \
+	svx/uiconfig/ui/clipboardmenu \
 	svx/uiconfig/ui/colorwindow \
 	svx/uiconfig/ui/currencywindow \
 	svx/uiconfig/ui/colsmenu \
diff --git a/svx/source/mnuctrls/clipboardctl.cxx b/svx/source/mnuctrls/clipboardctl.cxx
index bfa024bd93bd..84e686e72f35 100644
--- a/svx/source/mnuctrls/clipboardctl.cxx
+++ b/svx/source/mnuctrls/clipboardctl.cxx
@@ -19,8 +19,9 @@
 
 #include <sfx2/tbxctrl.hxx>
 #include <svl/intitem.hxx>
-#include <vcl/menu.hxx>
+#include <vcl/svapp.hxx>
 #include <vcl/toolbox.hxx>
+#include <vcl/weldutils.hxx>
 #include <svx/clipboardctl.hxx>
 #include <svx/clipfmtitem.hxx>
 
@@ -38,7 +39,6 @@ SvxClipBoardControl::SvxClipBoardControl(
         sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
 
     SfxToolBoxControl( nSlotId, nId, rTbx ),
-    pPopup( nullptr ),
     bDisabled( false )
 {
     addStatusListener( ".uno:ClipboardFormatItems");
@@ -47,10 +47,8 @@ SvxClipBoardControl::SvxClipBoardControl(
     rBox.Invalidate();
 }
 
-
 SvxClipBoardControl::~SvxClipBoardControl()
 {
-    DelPopup();
 }
 
 void SvxClipBoardControl::CreatePopupWindow()
@@ -58,10 +56,8 @@ void SvxClipBoardControl::CreatePopupWindow()
     const SvxClipboardFormatItem* pFmtItem = dynamic_cast<SvxClipboardFormatItem*>( pClipboardFmtItem.get()  );
     if ( pFmtItem )
     {
-        if (pPopup)
-            pPopup->Clear();
-        else
-            pPopup = VclPtr<PopupMenu>::Create();
+        std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "svx/ui/clipboardmenu.ui"));
+        std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
 
         sal_uInt16 nCount = pFmtItem->Count();
         for (sal_uInt16 i = 0;  i < nCount;  ++i)
@@ -70,20 +66,20 @@ void SvxClipBoardControl::CreatePopupWindow()
             OUString aFmtStr( pFmtItem->GetClipbrdFormatName( i ) );
             if (aFmtStr.isEmpty())
               aFmtStr = SvPasteObjectHelper::GetSotFormatUIName( nFmtID );
-            pPopup->InsertItem( static_cast<sal_uInt16>(nFmtID), aFmtStr );
+            xPopup->append(OUString::number(static_cast<sal_uInt32>(nFmtID)), aFmtStr);
         }
 
         ToolBox& rBox = GetToolBox();
         sal_uInt16 nId = GetId();
         rBox.SetItemDown( nId, true );
 
-        pPopup->Execute( &rBox, rBox.GetItemRect( nId ),
-            (rBox.GetAlign() == WindowAlign::Top || rBox.GetAlign() == WindowAlign::Bottom) ?
-                PopupMenuFlags::ExecuteDown : PopupMenuFlags::ExecuteRight );
+        ::tools::Rectangle aRect(rBox.GetItemRect(nId));
+        weld::Window* pParent = weld::GetPopupParent(rBox, aRect);
+        OString sResult = xPopup->popup_at_rect(pParent, aRect);
 
         rBox.SetItemDown( nId, false );
 
-        SfxUInt32Item aItem( SID_CLIPBOARD_FORMAT_ITEMS, pPopup->GetCurItemId() );
+        SfxUInt32Item aItem(SID_CLIPBOARD_FORMAT_ITEMS, sResult.toUInt32());
 
         Any a;
         Sequence< PropertyValue > aArgs( 1 );
@@ -95,7 +91,6 @@ void SvxClipBoardControl::CreatePopupWindow()
     }
 
     GetToolBox().EndSelection();
-    DelPopup();
 }
 
 void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState )
@@ -120,14 +115,4 @@ void SvxClipBoardControl::StateChanged( sal_uInt16 nSID, SfxItemState eState, co
     }
 }
 
-
-void SvxClipBoardControl::DelPopup()
-{
-    if(pPopup)
-    {
-        pPopup.disposeAndClear();
-    }
-}
-
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/uiconfig/ui/clipboardmenu.ui b/svx/uiconfig/ui/clipboardmenu.ui
new file mode 100644
index 000000000000..ae9032b68e07
--- /dev/null
+++ b/svx/uiconfig/ui/clipboardmenu.ui
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface domain="svx">
+  <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