Blob Blame History Raw
From f0efe28ec775c3205d3591750cd5159119128d20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
Date: Mon, 8 May 2017 15:27:49 +0100
Subject: [PATCH 3/6] gnome-documents: rework SfxPickList as pimpl
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

and call impl dtor with SolarMutex held

Reviewed-on: https://gerrit.libreoffice.org/37395
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 53082fcd1b1cccf7ef0c3cb1bef8e747c4e88a61)

Change-Id: I06931ca9ab4384a5e3c255847cf3533ed03b77dc
---
 sfx2/source/appl/sfxpicklist.cxx | 101 ++++++++++++++++++++++++++++++---------
 sfx2/source/inc/sfxpicklist.hxx  |  53 +++++---------------
 sfx2/source/menu/virtmenu.cxx    |   2 +-
 3 files changed, 92 insertions(+), 64 deletions(-)

diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx
index 24754ca..478c537 100644
--- a/sfx2/source/appl/sfxpicklist.cxx
+++ b/sfx2/source/appl/sfxpicklist.cxx
@@ -78,7 +78,54 @@ class StringLength : public ::cppu::WeakImplHelper1< XStringWidth >
         }
 };
 
-void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURLString, sal_uInt32 nNo )
+namespace
+{
+    class thePickListMutex
+        : public rtl::Static<osl::Mutex, thePickListMutex> {};
+}
+
+class SfxPickListImpl : public SfxListener
+{
+    struct PickListEntry
+    {
+        PickListEntry( const OUString& _aName, const OUString& _aFilter, const OUString& _aTitle ) :
+            aName( _aName ), aFilter( _aFilter ), aTitle( _aTitle ) {}
+
+        OUString aName;
+        OUString aFilter;
+        OUString aTitle;
+        OUString aOptions;
+    };
+
+    std::vector< PickListEntry* >   m_aPicklistVector;
+    sal_uInt32                      m_nAllowedMenuSize;
+    css::uno::Reference< css::util::XStringWidth > m_xStringLength;
+
+    void                    CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURL, sal_uInt32 nNo );
+    PickListEntry*          GetPickListEntry( sal_uInt32 nIndex );
+    void                    CreatePickListEntries();
+    void                    RemovePickListEntries();
+    /**
+     * Adds the given document to the pick list (recent documents) if it satisfies
+       certain requirements, e.g. being writable. Check implementation for requirement
+       details.
+     */
+    static void             AddDocumentToPickList( SfxObjectShell* pDocShell );
+
+public:
+    void                CreateMenuEntries( Menu* pMenu );
+    void                ExecuteMenuEntry( sal_uInt16 nId );
+    void                ExecuteEntry( sal_uInt32 nIndex );
+
+    SfxPickListImpl(sal_uInt32 nMenuSize);
+    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
+    ~SfxPickListImpl()
+    {
+        RemovePickListEntries();
+    }
+};
+
+void SfxPickListImpl::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURLString, sal_uInt32 nNo )
 {
     OUStringBuffer aPickEntry;
 
@@ -136,13 +183,7 @@ void SfxPickList::CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, cons
     pMenu->SetAccessibleName( nItemId, aAccessibleName );
 }
 
-namespace
-{
-    class thePickListMutex
-        : public rtl::Static<osl::Mutex, thePickListMutex> {};
-}
-
-void SfxPickList::RemovePickListEntries()
+void SfxPickListImpl::RemovePickListEntries()
 {
     ::osl::MutexGuard aGuard( thePickListMutex::get() );
     for ( sal_uInt32 i = 0; i < m_aPicklistVector.size(); i++ )
@@ -150,7 +191,7 @@ void SfxPickList::RemovePickListEntries()
     m_aPicklistVector.clear();
 }
 
-SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex )
+SfxPickListImpl::PickListEntry* SfxPickListImpl::GetPickListEntry( sal_uInt32 nIndex )
 {
     OSL_ASSERT( m_aPicklistVector.size() > nIndex );
 
@@ -160,7 +201,7 @@ SfxPickList::PickListEntry* SfxPickList::GetPickListEntry( sal_uInt32 nIndex )
         return 0;
 }
 
-void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh )
+void SfxPickListImpl::AddDocumentToPickList( SfxObjectShell* pDocSh )
 {
     if (comphelper::LibreOfficeKit::isActive())
         return;
@@ -242,13 +283,34 @@ void SfxPickList::AddDocumentToPickList( SfxObjectShell* pDocSh )
                                                                  (pFilter) ? pFilter->GetServiceName() : OUString() );
 }
 
+SfxPickList::SfxPickList(sal_uInt32 nAllowedMenuSize)
+    : mxImpl(new SfxPickListImpl(nAllowedMenuSize))
+{
+}
+
+SfxPickList::~SfxPickList()
+{
+    std::unique_ptr<SolarMutexGuard> xGuard(comphelper::SolarMutex::get() ? new SolarMutexGuard : nullptr);
+    mxImpl.reset();
+}
+
 SfxPickList& SfxPickList::Get()
 {
     static SfxPickList aUniqueInstance(SvtHistoryOptions().GetSize(ePICKLIST));
     return aUniqueInstance;
 }
 
-SfxPickList::SfxPickList( sal_uInt32 nAllowedMenuSize ) :
+void SfxPickList::CreateMenuEntries(Menu* pMenu)
+{
+    mxImpl->CreateMenuEntries(pMenu);
+}
+
+void SfxPickList::ExecuteMenuEntry(sal_uInt16 nId)
+{
+    mxImpl->ExecuteMenuEntry(nId);
+}
+
+SfxPickListImpl::SfxPickListImpl( sal_uInt32 nAllowedMenuSize ) :
     m_nAllowedMenuSize( nAllowedMenuSize )
 {
     m_xStringLength = new StringLength;
@@ -256,12 +318,7 @@ SfxPickList::SfxPickList( sal_uInt32 nAllowedMenuSize ) :
     StartListening( *SfxGetpApp() );
 }
 
-SfxPickList::~SfxPickList()
-{
-    RemovePickListEntries();
-}
-
-void SfxPickList::CreatePickListEntries()
+void SfxPickListImpl::CreatePickListEntries()
 {
     RemovePickListEntries();
 
@@ -305,7 +362,7 @@ void SfxPickList::CreatePickListEntries()
     }
 }
 
-void SfxPickList::CreateMenuEntries( Menu* pMenu )
+void SfxPickListImpl::CreateMenuEntries( Menu* pMenu )
 {
     ::osl::MutexGuard aGuard( thePickListMutex::get() );
 
@@ -340,11 +397,11 @@ void SfxPickList::CreateMenuEntries( Menu* pMenu )
     bPickListMenuInitializing = false;
 }
 
-void SfxPickList::ExecuteEntry( sal_uInt32 nIndex )
+void SfxPickListImpl::ExecuteEntry( sal_uInt32 nIndex )
 {
     ::osl::ClearableMutexGuard aGuard( thePickListMutex::get() );
 
-    PickListEntry *pPick = SfxPickList::Get().GetPickListEntry( nIndex );
+    PickListEntry *pPick = GetPickListEntry(nIndex);
 
     if ( pPick )
     {
@@ -369,12 +426,12 @@ void SfxPickList::ExecuteEntry( sal_uInt32 nIndex )
     }
 }
 
-void SfxPickList::ExecuteMenuEntry( sal_uInt16 nId )
+void SfxPickListImpl::ExecuteMenuEntry( sal_uInt16 nId )
 {
     ExecuteEntry( (sal_uInt32)( nId - START_ITEMID_PICKLIST ) );
 }
 
-void SfxPickList::Notify( SfxBroadcaster&, const SfxHint& rHint )
+void SfxPickListImpl::Notify( SfxBroadcaster&, const SfxHint& rHint )
 {
     const SfxStringHint* pStringHint = dynamic_cast<const SfxStringHint*>(&rHint);
     if ( pStringHint )
diff --git a/sfx2/source/inc/sfxpicklist.hxx b/sfx2/source/inc/sfxpicklist.hxx
index 502492c..56da5d4 100644
--- a/sfx2/source/inc/sfxpicklist.hxx
+++ b/sfx2/source/inc/sfxpicklist.hxx
@@ -29,48 +29,19 @@
 
 #define PICKLIST_MAXSIZE  100
 
-class SfxPickList : public SfxListener
-{
-    struct PickListEntry
-    {
-        PickListEntry( const OUString& _aName, const OUString& _aFilter, const OUString& _aTitle ) :
-            aName( _aName ), aFilter( _aFilter ), aTitle( _aTitle ) {}
-
-        OUString aName;
-        OUString aFilter;
-        OUString aTitle;
-        OUString aOptions;
-    };
-
-    std::vector< PickListEntry* >   m_aPicklistVector;
-    sal_uInt32                      m_nAllowedMenuSize;
-    ::com::sun::star::uno::Reference< ::com::sun::star::util::XStringWidth > m_xStringLength;
-
-                            SfxPickList( sal_uInt32 nMenuSize );
-                            virtual ~SfxPickList();
+class SfxPickListImpl;
 
-    void                    CreatePicklistMenuTitle( Menu* pMenu, sal_uInt16 nItemId, const OUString& aURL, sal_uInt32 nNo );
-    PickListEntry*          GetPickListEntry( sal_uInt32 nIndex );
-    void                    CreatePickListEntries();
-    void                    RemovePickListEntries();
-    /**
-     * Adds the given document to the pick list (recent documents) if it satisfies
-       certain requirements, e.g. being writable. Check implementation for requirement
-       details.
-     */
-    static void             AddDocumentToPickList( SfxObjectShell* pDocShell );
-
-    public:
-        static SfxPickList& Get();
-        static void ensure() { Get(); }
-
-        sal_uInt32          GetAllowedMenuSize() { return m_nAllowedMenuSize; }
-        sal_uInt32          GetNumOfEntries() const { return m_aPicklistVector.size(); }
-        void                CreateMenuEntries( Menu* pMenu );
-        static void         ExecuteMenuEntry( sal_uInt16 nId );
-        static void         ExecuteEntry( sal_uInt32 nIndex );
-
-        virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
+class SfxPickList
+{
+private:
+    std::unique_ptr<SfxPickListImpl> mxImpl;
+public:
+    SfxPickList(sal_uInt32 nAllowedMenuSize);
+    static SfxPickList& Get();
+    void CreateMenuEntries(Menu* pMenu);
+    void ExecuteMenuEntry(sal_uInt16 nId);
+    static void ensure() { Get(); }
+    ~SfxPickList();
 };
 
 #endif // INCLUDED_SFX2_SOURCE_INC_SFXPICKLIST_HXX
diff --git a/sfx2/source/menu/virtmenu.cxx b/sfx2/source/menu/virtmenu.cxx
index e14bb24..eab7bb7 100644
--- a/sfx2/source/menu/virtmenu.cxx
+++ b/sfx2/source/menu/virtmenu.cxx
@@ -964,7 +964,7 @@ IMPL_LINK( SfxVirtualMenu, Select, Menu *, pMenu )
     }
     else if ( nSlotId >= START_ITEMID_PICKLIST && nSlotId <= END_ITEMID_PICKLIST )
     {
-        SfxPickList::ExecuteMenuEntry( nSlotId );
+        SfxPickList::Get().ExecuteMenuEntry(nSlotId);
         return sal_IntPtr(true);
     }
 
-- 
2.9.3