Blame SOURCES/0003-gnome-documents-rework-SfxPickList-as-pimpl.patch

f325b2
From f0efe28ec775c3205d3591750cd5159119128d20 Mon Sep 17 00:00:00 2001
f325b2
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
f325b2
Date: Mon, 8 May 2017 15:27:49 +0100
f325b2
Subject: [PATCH 3/6] gnome-documents: rework SfxPickList as pimpl
f325b2
MIME-Version: 1.0
f325b2
Content-Type: text/plain; charset=UTF-8
f325b2
Content-Transfer-Encoding: 8bit
f325b2
f325b2
and call impl dtor with SolarMutex held
f325b2
f325b2
Reviewed-on: https://gerrit.libreoffice.org/37395
f325b2
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
f325b2
Tested-by: Caolán McNamara <caolanm@redhat.com>
f325b2
(cherry picked from commit 53082fcd1b1cccf7ef0c3cb1bef8e747c4e88a61)
f325b2
f325b2
Change-Id: I06931ca9ab4384a5e3c255847cf3533ed03b77dc
f325b2
---
f325b2
 sfx2/source/appl/sfxpicklist.cxx | 101 ++++++++++++++++++++++++++++++---------
f325b2
 sfx2/source/inc/sfxpicklist.hxx  |  53 +++++---------------
f325b2
 sfx2/source/menu/virtmenu.cxx    |   2 +-
f325b2
 3 files changed, 92 insertions(+), 64 deletions(-)
f325b2
f325b2
diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx
f325b2
index 24754ca..478c537 100644
f325b2
--- a/sfx2/source/appl/sfxpicklist.cxx
f325b2
+++ b/sfx2/source/appl/sfxpicklist.cxx
f325b2
@@ -78,7 +78,54 @@ class StringLength : public ::cppu::WeakImplHelper1< XStringWidth >
f325b2
         }
f325b2
 };
f325b2
 
f325b2
-void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURLString, sal_uInt32 nNo )
f325b2
+namespace
f325b2
+{
f325b2
+    class thePickListMutex
f325b2
+        : public rtl::Static<osl::Mutex, thePickListMutex> {};
f325b2
+}
f325b2
+
f325b2
+class SfxPickListImpl : public SfxListener
f325b2
+{
f325b2
+    struct PickListEntry
f325b2
+    {
f325b2
+        PickListEntry( const OUString& _aName, const OUString& _aFilter, const OUString& _aTitle ) :
f325b2
+            aName( _aName ), aFilter( _aFilter ), aTitle( _aTitle ) {}
f325b2
+
f325b2
+        OUString aName;
f325b2
+        OUString aFilter;
f325b2
+        OUString aTitle;
f325b2
+        OUString aOptions;
f325b2
+    };
f325b2
+
f325b2
+    std::vector< PickListEntry* >   m_aPicklistVector;
f325b2
+    sal_uInt32                      m_nAllowedMenuSize;
f325b2
+    css::uno::Reference< css::util::XStringWidth > m_xStringLength;
f325b2
+
f325b2
+    void                    CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURL, sal_uInt32 nNo );
f325b2
+    PickListEntry*          GetPickListEntry( sal_uInt32 nIndex );
f325b2
+    void                    CreatePickListEntries();
f325b2
+    void                    RemovePickListEntries();
f325b2
+    /**
f325b2
+     * Adds the given document to the pick list (recent documents) if it satisfies
f325b2
+       certain requirements, e.g. being writable. Check implementation for requirement
f325b2
+       details.
f325b2
+     */
f325b2
+    static void             AddDocumentToPickList( SfxObjectShell* pDocShell );
f325b2
+
f325b2
+public:
f325b2
+    void                CreateMenuEntries( Menu* pMenu );
f325b2
+    void                ExecuteMenuEntry( sal_uInt16 nId );
f325b2
+    void                ExecuteEntry( sal_uInt32 nIndex );
f325b2
+
f325b2
+    SfxPickListImpl(sal_uInt32 nMenuSize);
f325b2
+    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
f325b2
+    ~SfxPickListImpl()
f325b2
+    {
f325b2
+        RemovePickListEntries();
f325b2
+    }
f325b2
+};
f325b2
+
f325b2
+void SfxPickListImpl::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURLString, sal_uInt32 nNo )
f325b2
 {
f325b2
     OUStringBuffer aPickEntry;
f325b2
 
f325b2
@@ -136,13 +183,7 @@ void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, cons
f325b2
     pMenu->SetAccessibleName( nItemId, aAccessibleName );
f325b2
 }
f325b2
 
f325b2
-namespace
f325b2
-{
f325b2
-    class thePickListMutex
f325b2
-        : public rtl::Static<osl::Mutex, thePickListMutex> {};
f325b2
-}
f325b2
-
f325b2
-void SfxPickList::RemovePickListEntries()
f325b2
+void SfxPickListImpl::RemovePickListEntries()
f325b2
 {
f325b2
     ::osl::MutexGuard aGuard( thePickListMutex::get() );
f325b2
     for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ )
f325b2
@@ -150,7 +191,7 @@ void SfxPickList::RemovePickListEntries()
f325b2
     m_aPicklistVector.clear();
f325b2
 }
f325b2
 
f325b2
-SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex )
f325b2
+SfxPickListImpl::PickListEntry* SfxPickListImpl::GetPickListEntry( sal_uInt32 nIndex )
f325b2
 {
f325b2
     OSL_ASSERT( m_aPicklistVector.size() > nIndex );
f325b2
 
f325b2
@@ -160,7 +201,7 @@ SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex )
f325b2
         return 0;
f325b2
 }
f325b2
 
f325b2
-void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh )
f325b2
+void SfxPickListImpl::AddDocumentToPickList( SfxObjectShell* pDocSh )
f325b2
 {
f325b2
     if (comphelper::LibreOfficeKit::isActive())
f325b2
         return;
f325b2
@@ -242,13 +283,34 @@ void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh )
f325b2
                                                                  (pFilter) ? pFilter->GetServiceName() : OUString() );
f325b2
 }
f325b2
 
f325b2
+SfxPickList::SfxPickList(sal_uInt32 nAllowedMenuSize)
f325b2
+    : mxImpl(new SfxPickListImpl(nAllowedMenuSize))
f325b2
+{
f325b2
+}
f325b2
+
f325b2
+SfxPickList::~SfxPickList()
f325b2
+{
f325b2
+    std::unique_ptr<SolarMutexGuard> xGuard(comphelper::SolarMutex::get() ? new SolarMutexGuard : nullptr);
f325b2
+    mxImpl.reset();
f325b2
+}
f325b2
+
f325b2
 SfxPickList& SfxPickList::Get()
f325b2
 {
f325b2
     static SfxPickList aUniqueInstance(SvtHistoryOptions().GetSize(ePICKLIST));
f325b2
     return aUniqueInstance;
f325b2
 }
f325b2
 
f325b2
-SfxPickList::SfxPickList( sal_uInt32 nAllowedMenuSize ) :
f325b2
+void SfxPickList::CreateMenuEntries(Menu* pMenu)
f325b2
+{
f325b2
+    mxImpl->CreateMenuEntries(pMenu);
f325b2
+}
f325b2
+
f325b2
+void SfxPickList::ExecuteMenuEntry(sal_uInt16 nId)
f325b2
+{
f325b2
+    mxImpl->ExecuteMenuEntry(nId);
f325b2
+}
f325b2
+
f325b2
+SfxPickListImpl::SfxPickListImpl( sal_uInt32 nAllowedMenuSize ) :
f325b2
     m_nAllowedMenuSize( nAllowedMenuSize )
f325b2
 {
f325b2
     m_xStringLength = new StringLength;
f325b2
@@ -256,12 +318,7 @@ SfxPickList::SfxPickList( sal_uInt32 nAllowedMenuSize ) :
f325b2
     StartListening( *SfxGetpApp() );
f325b2
 }
f325b2
 
f325b2
-SfxPickList::~SfxPickList()
f325b2
-{
f325b2
-    RemovePickListEntries();
f325b2
-}
f325b2
-
f325b2
-void SfxPickList::CreatePickListEntries()
f325b2
+void SfxPickListImpl::CreatePickListEntries()
f325b2
 {
f325b2
     RemovePickListEntries();
f325b2
 
f325b2
@@ -305,7 +362,7 @@ void SfxPickList::CreatePickListEntries()
f325b2
     }
f325b2
 }
f325b2
 
f325b2
-void SfxPickList::CreateMenuEntries( Menu* pMenu )
f325b2
+void SfxPickListImpl::CreateMenuEntries( Menu* pMenu )
f325b2
 {
f325b2
     ::osl::MutexGuard aGuard( thePickListMutex::get() );
f325b2
 
f325b2
@@ -340,11 +397,11 @@ void SfxPickList::CreateMenuEntries( Menu* pMenu )
f325b2
     bPickListMenuInitializing = false;
f325b2
 }
f325b2
 
f325b2
-void SfxPickList::ExecuteEntry( sal_uInt32 nIndex )
f325b2
+void SfxPickListImpl::ExecuteEntry( sal_uInt32 nIndex )
f325b2
 {
f325b2
     ::osl::ClearableMutexGuard aGuard( thePickListMutex::get() );
f325b2
 
f325b2
-    PickListEntry *pPick = SfxPickList::Get().GetPickListEntry( nIndex );
f325b2
+    PickListEntry *pPick = GetPickListEntry(nIndex);
f325b2
 
f325b2
     if ( pPick )
f325b2
     {
f325b2
@@ -369,12 +426,12 @@ void SfxPickList::ExecuteEntry( sal_uInt32 nIndex )
f325b2
     }
f325b2
 }
f325b2
 
f325b2
-void SfxPickList::ExecuteMenuEntry( sal_uInt16 nId )
f325b2
+void SfxPickListImpl::ExecuteMenuEntry( sal_uInt16 nId )
f325b2
 {
f325b2
     ExecuteEntry( (sal_uInt32)( nId - START_ITEMID_PICKLIST ) );
f325b2
 }
f325b2
 
f325b2
-void SfxPickList::Notify( SfxBroadcaster&, const SfxHint& rHint )
f325b2
+void SfxPickListImpl::Notify( SfxBroadcaster&, const SfxHint& rHint )
f325b2
 {
f325b2
     const SfxStringHint* pStringHint = dynamic_cast<const SfxStringHint*>(&rHint);
f325b2
     if ( pStringHint )
f325b2
diff --git a/sfx2/source/inc/sfxpicklist.hxx b/sfx2/source/inc/sfxpicklist.hxx
f325b2
index 502492c..56da5d4 100644
f325b2
--- a/sfx2/source/inc/sfxpicklist.hxx
f325b2
+++ b/sfx2/source/inc/sfxpicklist.hxx
f325b2
@@ -29,48 +29,19 @@
f325b2
 
f325b2
 #define PICKLIST_MAXSIZE  100
f325b2
 
f325b2
-class SfxPickList : public SfxListener
f325b2
-{
f325b2
-    struct PickListEntry
f325b2
-    {
f325b2
-        PickListEntry( const OUString& _aName, const OUString& _aFilter, const OUString& _aTitle ) :
f325b2
-            aName( _aName ), aFilter( _aFilter ), aTitle( _aTitle ) {}
f325b2
-
f325b2
-        OUString aName;
f325b2
-        OUString aFilter;
f325b2
-        OUString aTitle;
f325b2
-        OUString aOptions;
f325b2
-    };
f325b2
-
f325b2
-    std::vector< PickListEntry* >   m_aPicklistVector;
f325b2
-    sal_uInt32                      m_nAllowedMenuSize;
f325b2
-    ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > m_xStringLength;
f325b2
-
f325b2
-                            SfxPickList( sal_uInt32 nMenuSize );
f325b2
-                            virtual ~SfxPickList();
f325b2
+class SfxPickListImpl;
f325b2
 
f325b2
-    void                    CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURL, sal_uInt32 nNo );
f325b2
-    PickListEntry*          GetPickListEntry( sal_uInt32 nIndex );
f325b2
-    void                    CreatePickListEntries();
f325b2
-    void                    RemovePickListEntries();
f325b2
-    /**
f325b2
-     * Adds the given document to the pick list (recent documents) if it satisfies
f325b2
-       certain requirements, e.g. being writable. Check implementation for requirement
f325b2
-       details.
f325b2
-     */
f325b2
-    static void             AddDocumentToPickList( SfxObjectShell* pDocShell );
f325b2
-
f325b2
-    public:
f325b2
-        static SfxPickList& Get();
f325b2
-        static void ensure() { Get(); }
f325b2
-
f325b2
-        sal_uInt32          GetAllowedMenuSize() { return m_nAllowedMenuSize; }
f325b2
-        sal_uInt32          GetNumOfEntries() const { return m_aPicklistVector.size(); }
f325b2
-        void                CreateMenuEntries( Menu* pMenu );
f325b2
-        static void         ExecuteMenuEntry( sal_uInt16 nId );
f325b2
-        static void         ExecuteEntry( sal_uInt32 nIndex );
f325b2
-
f325b2
-        virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
f325b2
+class SfxPickList
f325b2
+{
f325b2
+private:
f325b2
+    std::unique_ptr<SfxPickListImpl> mxImpl;
f325b2
+public:
f325b2
+    SfxPickList(sal_uInt32 nAllowedMenuSize);
f325b2
+    static SfxPickList& Get();
f325b2
+    void CreateMenuEntries(Menu* pMenu);
f325b2
+    void ExecuteMenuEntry(sal_uInt16 nId);
f325b2
+    static void ensure() { Get(); }
f325b2
+    ~SfxPickList();
f325b2
 };
f325b2
 
f325b2
 #endif // INCLUDED_SFX2_SOURCE_INC_SFXPICKLIST_HXX
f325b2
diff --git a/sfx2/source/menu/virtmenu.cxx b/sfx2/source/menu/virtmenu.cxx
f325b2
index e14bb24..eab7bb7 100644
f325b2
--- a/sfx2/source/menu/virtmenu.cxx
f325b2
+++ b/sfx2/source/menu/virtmenu.cxx
f325b2
@@ -964,7 +964,7 @@ IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu )
f325b2
     }
f325b2
     else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST )
f325b2
     {
f325b2
-        SfxPickList::ExecuteMenuEntry( nSlotId );
f325b2
+        SfxPickList::Get().ExecuteMenuEntry(nSlotId);
f325b2
         return sal_IntPtr(true);
f325b2
     }
f325b2
 
f325b2
-- 
f325b2
2.9.3
f325b2