[Libreoffice-commits] .: 2 commits - sw/source

Michael Stahl mst at kemper.freedesktop.org
Tue Apr 24 09:59:13 PDT 2012


 sw/source/ui/inc/unotxvw.hxx |   10 ++---
 sw/source/ui/uno/unotxvw.cxx |   72 +++++++++++++++----------------------------
 2 files changed, 30 insertions(+), 52 deletions(-)

New commits:
commit 009920703bfd5426588ee575b94231064c4b45df
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Apr 24 18:56:09 2012 +0200

    SwXTextView: use cppu::OInterfaceContainerHelper

diff --git a/sw/source/ui/inc/unotxvw.hxx b/sw/source/ui/inc/unotxvw.hxx
index 89a98f7..cf851bc 100644
--- a/sw/source/ui/inc/unotxvw.hxx
+++ b/sw/source/ui/inc/unotxvw.hxx
@@ -25,9 +25,10 @@
  * for a copy of the LGPLv3 License.
  *
  ************************************************************************/
-#ifndef _UNOTXVW_HXX
-#define _UNOTXVW_HXX
+#ifndef SW_UNOTXVW_HXX
+#define SW_UNOTXVW_HXX
 #include <sfx2/sfxbasecontroller.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
 #include <com/sun/star/text/XTextViewCursor.hpp>
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
@@ -55,9 +56,6 @@
 class SdrObject;
 class SwView;
 
-typedef ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener > XSelectionChangeListenerRef;
-typedef std::vector<XSelectionChangeListenerRef> SelectionChangeListenerArr;
-
 class SwXTextView :
     public ::com::sun::star::view::XSelectionSupplier,
     public ::com::sun::star::lang::XServiceInfo,
@@ -69,7 +67,7 @@ class SwXTextView :
     public ::com::sun::star::datatransfer::XTransferableSupplier,
     public SfxBaseController
 {
-    SelectionChangeListenerArr aSelChangedListeners;
+    ::cppu::OInterfaceContainerHelper m_SelChangedListeners;
 
     SwView*                     m_pView;
     const SfxItemPropertySet*   m_pPropSet;   // property map for SwXTextView properties
diff --git a/sw/source/ui/uno/unotxvw.cxx b/sw/source/ui/uno/unotxvw.cxx
index ce17dab..fb08029 100644
--- a/sw/source/ui/uno/unotxvw.cxx
+++ b/sw/source/ui/uno/unotxvw.cxx
@@ -109,6 +109,7 @@ SwPaM* lcl_createPamCopy(const SwPaM& rPam)
  ******************************************************************/
 SwXTextView::SwXTextView(SwView* pSwView) :
     SfxBaseController(pSwView),
+    m_SelChangedListeners(m_aMutex),
     m_pView(pSwView),
     m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_TEXT_VIEW ) ),
     pxViewSettings(0),
@@ -139,23 +140,11 @@ void SwXTextView::Invalidate()
 
     m_refCount++; //prevent second d'tor call
 
-    sal_uInt16 nCount = aSelChangedListeners.size();
-    if(nCount)
     {
-        uno::Reference< uno::XInterface >  xInt = (cppu::OWeakObject*)(SfxBaseController*)this;
+        uno::Reference<uno::XInterface> const xInt(static_cast<
+                cppu::OWeakObject*>(static_cast<SfxBaseController*>(this)));
         lang::EventObject aEvent(xInt);
-        for ( sal_uInt16 i = nCount; i--; )
-        {
-            uno::Reference< view::XSelectionChangeListener >  *pObj = &aSelChangedListeners[i];
-            (*pObj)->disposing(aEvent);
-        }
-    }
-
-    // #i85580: now clean up any possibly remaining entries in the array...
-    // (i.e. listeners that did not call removeSelectionChangeListener in their disposing.)
-    while ((nCount = aSelChangedListeners.size()) != 0)
-    {
-        removeSelectionChangeListener( aSelChangedListeners[0] );
+        m_SelChangedListeners.disposeAndClear(aEvent);
     }
 
     m_refCount--;
@@ -606,7 +595,7 @@ void SwXTextView::addSelectionChangeListener(
                                     throw( uno::RuntimeException )
 {
     SolarMutexGuard aGuard;
-    aSelChangedListeners.push_back(rxListener);
+    m_SelChangedListeners.addInterface(rxListener);
 }
 
 void SwXTextView::removeSelectionChangeListener(
@@ -614,18 +603,7 @@ void SwXTextView::removeSelectionChangeListener(
                                         throw( uno::RuntimeException )
 {
     SolarMutexGuard aGuard;
-    view::XSelectionChangeListener* pLeft = rxListener.get();
-    for(SelectionChangeListenerArr::iterator it = aSelChangedListeners.begin();
-        it != aSelChangedListeners.end(); ++it)
-    {
-        uno::Reference< view::XSelectionChangeListener > * pElem = &*it;
-        view::XSelectionChangeListener* pRight = pElem->get();
-        if(pLeft == pRight)
-        {
-            aSelChangedListeners.erase(it);
-            break;
-        }
-    }
+    m_SelChangedListeners.removeInterface(rxListener);
 }
 
 SdrObject* SwXTextView::GetControl(
@@ -877,16 +855,27 @@ void SwXTextView::NotifySelChanged()
 {
     OSL_ENSURE( m_pView, "view is missing" );
 
-    uno::Reference< uno::XInterface >  xInt = (cppu::OWeakObject*)(SfxBaseController*)this;
+    uno::Reference<uno::XInterface> const xInt(
+        static_cast<cppu::OWeakObject*>(static_cast<SfxBaseController*>(this)));
 
-     lang::EventObject aEvent(xInt);
+    lang::EventObject const aEvent(xInt);
+    m_SelChangedListeners.notifyEach(
+            &view::XSelectionChangeListener::selectionChanged, aEvent);
+}
 
-    sal_uInt16 nCount = aSelChangedListeners.size();
-    for ( sal_uInt16 i = nCount; i--; )
+namespace {
+    struct DispatchListener
     {
-        uno::Reference< view::XSelectionChangeListener >  *pObj = &aSelChangedListeners[i];
-        (*pObj)->selectionChanged(aEvent);
-    }
+        URL const & m_rURL;
+        Sequence<PropertyValue> const& m_rSeq;
+        explicit DispatchListener(URL const& rURL,
+                Sequence<PropertyValue> const& rSeq)
+            : m_rURL(rURL), m_rSeq(rSeq) { }
+        void operator()(uno::Reference<XDispatch> const & xListener) const
+        {
+            xListener->dispatch(m_rURL, m_rSeq);
+        }
+    };
 }
 
 void SwXTextView::NotifyDBChanged()
@@ -894,14 +883,8 @@ void SwXTextView::NotifyDBChanged()
     URL aURL;
     aURL.Complete = rtl::OUString::createFromAscii(SwXDispatch::GetDBChangeURL());
 
-    sal_uInt16 nCount = aSelChangedListeners.size();
-    for ( sal_uInt16 i = nCount; i--; )
-    {
-        uno::Reference< view::XSelectionChangeListener >  *pObj = &aSelChangedListeners[i];
-        uno::Reference<XDispatch> xDispatch((*pObj), UNO_QUERY);
-        if(xDispatch.is())
-            xDispatch->dispatch(aURL, Sequence<PropertyValue>(0));
-    }
+    m_SelChangedListeners.forEach<XDispatch>(
+            DispatchListener(aURL, Sequence<PropertyValue>(0)));
 }
 
 uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXTextView::getPropertySetInfo(  )
commit f92b087ffc68c054e7f183ab5c8e3e02fb9e35e2
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Apr 24 18:10:07 2012 +0200

    fix double free in SwXTextView::removeSelectionChangeListener
    
    dbaccess_complex segfaults because ptr_vector::erase actually deletes
    the element; also, a std::vector is more appropriate to store smart ptr.
    (regression from 8533a191f4434490aa44118bce0e5719477d957a)

diff --git a/sw/source/ui/inc/unotxvw.hxx b/sw/source/ui/inc/unotxvw.hxx
index c764c15..89a98f7 100644
--- a/sw/source/ui/inc/unotxvw.hxx
+++ b/sw/source/ui/inc/unotxvw.hxx
@@ -56,7 +56,7 @@ class SdrObject;
 class SwView;
 
 typedef ::com::sun::star::uno::Reference< ::com::sun::star::view::XSelectionChangeListener > XSelectionChangeListenerRef;
-typedef boost::ptr_vector<XSelectionChangeListenerRef> SelectionChangeListenerArr;
+typedef std::vector<XSelectionChangeListenerRef> SelectionChangeListenerArr;
 
 class SwXTextView :
     public ::com::sun::star::view::XSelectionSupplier,
diff --git a/sw/source/ui/uno/unotxvw.cxx b/sw/source/ui/uno/unotxvw.cxx
index 3cd93ac..ce17dab 100644
--- a/sw/source/ui/uno/unotxvw.cxx
+++ b/sw/source/ui/uno/unotxvw.cxx
@@ -606,9 +606,7 @@ void SwXTextView::addSelectionChangeListener(
                                     throw( uno::RuntimeException )
 {
     SolarMutexGuard aGuard;
-    uno::Reference< view::XSelectionChangeListener > * pInsert = new uno::Reference< view::XSelectionChangeListener > ;
-    *pInsert = rxListener;
-    aSelChangedListeners.push_back(pInsert);
+    aSelChangedListeners.push_back(rxListener);
 }
 
 void SwXTextView::removeSelectionChangeListener(
@@ -625,7 +623,6 @@ void SwXTextView::removeSelectionChangeListener(
         if(pLeft == pRight)
         {
             aSelChangedListeners.erase(it);
-            delete pElem;
             break;
         }
     }


More information about the Libreoffice-commits mailing list