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

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