summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mst@openoffice.org>2010-01-08 17:13:50 +0100
committerMichael Stahl <mst@openoffice.org>2010-01-08 17:13:50 +0100
commit440e521dad8c97e939460af857c6a851b220c52e (patch)
tree84a4f19d97704b2efc0c1cd98ce42ecfbbd74a2e /sw
parentfaf50e31a983c1be11d74c1b574cd6c5f63d3a4e (diff)
swunolocking1: #i105557#: fix locking for SwXBookmark:
add Impl struct, and use UnoImplPtr to lock destructor. move all implementation details out of header, into Impl struct. replace broken SwClient iteration with a WeakReference in sw::mark::MarkBase. make constructor protected, and add factory function CreateXBookmark. use new XUnoTunnel and XServiceInfo helpers. clean up the implementation a little. remove SwXBookmarks::GetObject().
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/unobookmark.hxx48
-rw-r--r--sw/inc/unocoll.hxx1
-rw-r--r--sw/source/core/crsr/bookmrk.cxx30
-rw-r--r--sw/source/core/inc/bookmrk.hxx24
-rw-r--r--sw/source/core/unocore/unobkm.cxx480
-rw-r--r--sw/source/core/unocore/unocoll.cxx31
-rw-r--r--sw/source/core/unocore/unoportenum.cxx15
-rw-r--r--sw/source/ui/uno/unotxvw.cxx17
8 files changed, 399 insertions, 247 deletions
diff --git a/sw/inc/unobookmark.hxx b/sw/inc/unobookmark.hxx
index 2b16d7828001..46d0054551b7 100644
--- a/sw/inc/unobookmark.hxx
+++ b/sw/inc/unobookmark.hxx
@@ -41,12 +41,10 @@
#include <cppuhelper/implbase5.hxx>
-#include <tools/string.hxx>
#include <sfx2/Metadatable.hxx>
+#include <unobaseclass.hxx>
#include <IDocumentMarkAccess.hxx>
-#include <calbck.hxx>
-#include <unoevtlstnr.hxx>
class SwDoc;
@@ -63,33 +61,15 @@ typedef ::cppu::ImplInheritanceHelper5
class SwXBookmark
: public SwXBookmark_Base
- , private SwClient
{
private:
- SwEventListenerContainer m_aLstnrCntnr;
- SwDoc* m_pDoc;
- String m_aName;
- ::sw::mark::IMark* m_pRegisteredBookmark;
-
- void registerInMark(::sw::mark::IMark* const pBkmk);
+ class Impl;
+ ::sw::UnoImplPtr<Impl> m_pImpl;
protected:
- virtual ~SwXBookmark();
-
-public:
-
- SwXBookmark(::sw::mark::IMark* pMark = 0, SwDoc* pDoc = 0);
-
- const ::sw::mark::IMark* GetBookmark() const
- { return m_pRegisteredBookmark; }
- ::sw::mark::IMark* GetBookmark()
- { return m_pRegisteredBookmark; }
- SwDoc* GetDoc()
- { return m_pDoc; }
-
void attachToRangeEx(
const ::com::sun::star::uno::Reference<
::com::sun::star::text::XTextRange > & xTextRange,
@@ -102,10 +82,26 @@ public:
throw (::com::sun::star::lang::IllegalArgumentException,
::com::sun::star::uno::RuntimeException);
- TYPEINFO();
+ const ::sw::mark::IMark* GetBookmark() const;
- // SwClient
- virtual void Modify( SfxPoolItem *pOld, SfxPoolItem *pNew );
+ virtual ~SwXBookmark();
+
+ /// @param pDoc and pMark != 0, but not & because of ImplInheritanceHelper
+ SwXBookmark(::sw::mark::IMark *const pMark, SwDoc *const pDoc);
+
+public:
+
+ /// descriptor
+ SwXBookmark();
+
+ static ::com::sun::star::uno::Reference<
+ ::com::sun::star::text::XTextContent>
+ CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark);
+
+ /// @return IMark for this, but only if it lives in pDoc
+ static ::sw::mark::IMark const* GetBookmarkInDoc(SwDoc const*const pDoc,
+ const ::com::sun::star::uno::Reference<
+ ::com::sun::star::lang::XUnoTunnel> & xUT);
// MetadatableMixin
virtual ::sfx2::Metadatable* GetCoreObject();
diff --git a/sw/inc/unocoll.hxx b/sw/inc/unocoll.hxx
index b630668f8965..f4d54a55adca 100644
--- a/sw/inc/unocoll.hxx
+++ b/sw/inc/unocoll.hxx
@@ -481,7 +481,6 @@ class SwXBookmarks : public SwCollectionBaseClass,
virtual BOOL SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( ::com::sun::star::uno::RuntimeException );
virtual ::com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( ::com::sun::star::uno::RuntimeException );
- static SwXBookmark* GetObject( ::sw::mark::IMark& rBkm, SwDoc* pDoc);
};
class SwXNumberingRulesCollection : public cppu::WeakImplHelper1
diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index 1028c7b2b432..a9321324be3a 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -49,6 +49,7 @@
SV_IMPL_REF( SwServerObject )
using namespace ::sw::mark;
+using namespace ::com::sun::star;
namespace
{
@@ -147,6 +148,16 @@ namespace sw { namespace mark
return aResult.append(nCount++).append(sUniquePostfix).makeStringAndClear();
}
+ // SwClient
+ void MarkBase::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew)
+ {
+ SwModify::Modify(pOld, pNew);
+ if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
+ { // invalidate cached uno object
+ SetXBookmark(uno::Reference<text::XTextContent>(0));
+ }
+ }
+
NavigatorReminder::NavigatorReminder(const SwPaM& rPaM)
: MarkBase(rPaM, our_sNamePrefix)
@@ -240,24 +251,13 @@ namespace sw { namespace mark
return !pDoc->IsInHeaderFooter( SwNodeIndex(GetMarkPos().nNode) );
}
- ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XMetadatable >
- Bookmark::MakeUnoObject()
+ uno::Reference< rdf::XMetadatable > Bookmark::MakeUnoObject()
{
- // re-use existing SwXBookmark
- SwClientIter iter( *this );
- SwClient * pClient( iter.First( TYPE( SwXBookmark ) ) );
- while (pClient) {
- SwXBookmark *const pBookmark( dynamic_cast<SwXBookmark*>(pClient) );
- if (pBookmark && pBookmark->GetCoreObject() == this) {
- return pBookmark;
- }
- pClient = iter.Next();
- }
-
- // create new SwXBookmark
SwDoc *const pDoc( GetMarkPos().GetDoc() );
OSL_ENSURE(pDoc, "Bookmark::MakeUnoObject: no doc?");
- return new SwXBookmark(this, pDoc);
+ const uno::Reference< rdf::XMetadatable> xMeta(
+ SwXBookmark::CreateXBookmark(*pDoc, *this), uno::UNO_QUERY);
+ return xMeta;
}
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 18f8860ecab9..313df12fddb7 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -31,12 +31,20 @@
#ifndef _BOOKMRK_HXX
#define _BOOKMRK_HXX
-#include <IMark.hxx>
+#include <cppuhelper/weakref.hxx>
+
#include <sfx2/Metadatable.hxx>
#include <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>
+#include <IMark.hxx>
+
+
+namespace com { namespace sun { namespace star {
+ namespace text { class XTextContent; }
+} } }
+
struct SwPosition; // fwd Decl. wg. UI
class SwDoc;
@@ -90,6 +98,17 @@ namespace sw { namespace mark
{}
virtual ~MarkBase();
+
+ // SwClient
+ virtual void Modify( SfxPoolItem *pOld, SfxPoolItem *pNew );
+
+ const ::com::sun::star::uno::WeakReference<
+ ::com::sun::star::text::XTextContent> & GetXBookmark() const
+ { return m_wXBookmark; }
+ void SetXBookmark(::com::sun::star::uno::Reference<
+ ::com::sun::star::text::XTextContent> const& xBkmk)
+ { m_wXBookmark = xBkmk; }
+
protected:
MarkBase(const SwPaM& rPaM,
const ::rtl::OUString& rName);
@@ -97,6 +116,9 @@ namespace sw { namespace mark
::boost::scoped_ptr<SwPosition> m_pPos2;
::rtl::OUString m_aName;
static ::rtl::OUString GenerateNewName(const ::rtl::OUString& rPrefix);
+
+ ::com::sun::star::uno::WeakReference<
+ ::com::sun::star::text::XTextContent> m_wXBookmark;
};
class NavigatorReminder
diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx
index 282ae6b389a8..86b8b3ee8403 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -34,11 +34,13 @@
#include <unobookmark.hxx>
#include <vos/mutex.hxx>
#include <vcl/svapp.hxx>
+
#include <TextCursorHelper.hxx>
#include <unotextrange.hxx>
#include <unoparagraph.hxx>
#include <unomap.hxx>
#include <unoprnms.hxx>
+#include <unoevtlstnr.hxx>
#include <IMark.hxx>
#include <crossrefbookmark.hxx>
#include <doc.hxx>
@@ -52,13 +54,8 @@
using namespace ::com::sun::star;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::text;
-using namespace ::com::sun::star::container;
-using namespace ::com::sun::star::beans;
using ::rtl::OUString;
-using ::rtl::OUStringBuffer;
+
namespace
{
@@ -66,7 +63,7 @@ namespace
{
static const OUString sStart = OUString(String(SW_RES(STR_START_QUOTE)));
static const OUString sEnd = OUString(String(SW_RES(STR_END_QUOTE)));
- OUStringBuffer sBuf(64);
+ ::rtl::OUStringBuffer sBuf(64);
return sBuf.append(sStart).append(rName).append(sEnd).makeStringAndClear();
}
}
@@ -74,184 +71,307 @@ namespace
/******************************************************************
* SwXBookmark
******************************************************************/
-TYPEINIT1(SwXBookmark, SwClient)
-void SwXBookmark::registerInMark(::sw::mark::IMark* const pBkmk)
+class SwXBookmark::Impl
+ : public SwClient
+{
+
+public:
+ SwEventListenerContainer m_ListenerContainer;
+ SwDoc * m_pDoc;
+ ::sw::mark::IMark * m_pRegisteredBookmark;
+ ::rtl::OUString m_sMarkName;
+
+
+ Impl( SwXBookmark & rThis,
+ SwDoc *const pDoc, ::sw::mark::IMark *const /*pBookmark*/)
+ : SwClient()
+ , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
+ , m_pDoc(pDoc)
+ , m_pRegisteredBookmark(0)
+ {
+ // DO NOT regiserInMark here! (because SetXBookmark would delete rThis)
+ }
+
+ void registerInMark(SwXBookmark & rThis, ::sw::mark::IMark *const pBkmk);
+
+ // SwClient
+ virtual void Modify(SfxPoolItem *pOld, SfxPoolItem *pNew);
+
+};
+
+void SwXBookmark::Impl::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew)
+{
+ ClientModify(this, pOld, pNew);
+ if (!GetRegisteredIn())
+ {
+ m_pRegisteredBookmark = NULL;
+ m_pDoc = NULL;
+ m_ListenerContainer.Disposing();
+ }
+}
+
+void SwXBookmark::Impl::registerInMark(SwXBookmark & rThis,
+ ::sw::mark::IMark *const pBkmk)
{
if (pBkmk)
{
pBkmk->Add(this);
+ ::sw::mark::MarkBase *const pMarkBase(
+ dynamic_cast< ::sw::mark::MarkBase * >(pBkmk));
+ OSL_ENSURE(pMarkBase, "registerInMark: no MarkBase?");
+ if (pMarkBase)
+ {
+ const uno::Reference<text::XTextContent> xBookmark(& rThis);
+ pMarkBase->SetXBookmark(xBookmark);
+ }
}
else if (m_pRegisteredBookmark)
{
- m_aName = m_pRegisteredBookmark->GetName();
+ m_sMarkName = m_pRegisteredBookmark->GetName();
m_pRegisteredBookmark->Remove(this);
}
m_pRegisteredBookmark = pBkmk;
}
-const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId()
+
+const ::sw::mark::IMark* SwXBookmark::GetBookmark() const
{
- static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
- return aSeq;
+ return m_pImpl->m_pRegisteredBookmark;
}
-sal_Int64 SAL_CALL SwXBookmark::getSomething( const uno::Sequence< sal_Int8 >& rId )
- throw(uno::RuntimeException)
+SwXBookmark::SwXBookmark(::sw::mark::IMark *const pBkmk, SwDoc *const pDoc)
+ : m_pImpl( new SwXBookmark::Impl(*this, pDoc, pBkmk) )
{
- if( rId.getLength() == 16
- && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), rId.getConstArray(), 16 ) )
+}
+
+SwXBookmark::SwXBookmark()
+ : m_pImpl( new SwXBookmark::Impl(*this, 0, 0) )
+{
+}
+
+SwXBookmark::~SwXBookmark()
+{
+}
+
+uno::Reference<text::XTextContent>
+SwXBookmark::CreateXBookmark(SwDoc & rDoc, ::sw::mark::IMark & rBookmark)
+{
+ // #i105557#: do not iterate over the registered clients: race condition
+ ::sw::mark::MarkBase *const pMarkBase(
+ dynamic_cast< ::sw::mark::MarkBase * >(&rBookmark));
+ OSL_ENSURE(pMarkBase, "CreateXBookmark: no MarkBase?");
+ if (!pMarkBase) { return 0; }
+ uno::Reference<text::XTextContent> xBookmark(pMarkBase->GetXBookmark());
+ if (!xBookmark.is())
{
- return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >(this) );
+ // FIXME: These belong in XTextFieldsSupplier
+ //if (dynamic_cast< ::sw::mark::TextFieldmark* >(&rBkmk))
+ // pXBkmk = new SwXFieldmark(false, &rBkmk, pDoc);
+ //else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rBkmk))
+ // pXBkmk = new SwXFieldmark(true, &rBkmk, pDoc);
+ //else
+ OSL_ENSURE(
+ dynamic_cast< ::sw::mark::IBookmark* >(&rBookmark),
+ "<SwXBookmark::GetObject(..)>"
+ "SwXBookmark requested for non-bookmark mark.");
+ SwXBookmark *const pXBookmark = new SwXBookmark(&rBookmark, &rDoc);
+ xBookmark.set(pXBookmark);
+ pXBookmark->m_pImpl->registerInMark(*pXBookmark, pMarkBase);
+ }
+ return xBookmark;
+}
+
+::sw::mark::IMark const* SwXBookmark::GetBookmarkInDoc(SwDoc const*const pDoc,
+ const uno::Reference< lang::XUnoTunnel> & xUT)
+{
+ SwXBookmark *const pXBkm(
+ ::sw::UnoTunnelGetImplementation<SwXBookmark>(xUT));
+ if (pXBkm && (pDoc == pXBkm->m_pImpl->m_pDoc))
+ {
+ return pXBkm->m_pImpl->m_pRegisteredBookmark;
}
return 0;
}
-SwXBookmark::SwXBookmark(::sw::mark::IMark* pBkmk, SwDoc* pDoc)
- : m_aLstnrCntnr((text::XTextContent*)this)
- , m_pDoc(pDoc)
- , m_pRegisteredBookmark(NULL)
+const uno::Sequence< sal_Int8 > & SwXBookmark::getUnoTunnelId()
{
- registerInMark(pBkmk);
+ static uno::Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
+ return aSeq;
}
-SwXBookmark::~SwXBookmark()
-{ }
+sal_Int64 SAL_CALL
+SwXBookmark::getSomething(const uno::Sequence< sal_Int8 >& rId)
+throw (uno::RuntimeException)
+{
+ return ::sw::UnoTunnelImpl<SwXBookmark>(rId, this);
+}
void SwXBookmark::attachToRangeEx(
const uno::Reference< text::XTextRange > & xTextRange,
IDocumentMarkAccess::MarkType eType)
- throw(lang::IllegalArgumentException, uno::RuntimeException)
+throw (lang::IllegalArgumentException, uno::RuntimeException)
{
- if(m_pRegisteredBookmark)
+ if (m_pImpl->m_pRegisteredBookmark)
+ {
throw uno::RuntimeException();
+ }
- uno::Reference<lang::XUnoTunnel> xRangeTunnel( xTextRange, uno::UNO_QUERY);
+ const uno::Reference<lang::XUnoTunnel> xRangeTunnel(
+ xTextRange, uno::UNO_QUERY);
SwXTextRange* pRange = 0;
OTextCursorHelper* pCursor = 0;
if(xRangeTunnel.is())
{
+ pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
+ pCursor =
+ ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
+ }
- pRange = reinterpret_cast< SwXTextRange * >(
- sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( SwXTextRange::getUnoTunnelId() )));
- pCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xRangeTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ SwDoc *const pDoc =
+ (pRange) ? pRange->GetDoc() : ((pCursor) ? pCursor->GetDoc() : 0);
+ if (!pDoc)
+ {
+ throw lang::IllegalArgumentException();
}
- SwDoc* pDc = pRange ? (SwDoc*)pRange->GetDoc() : pCursor ?
- (SwDoc*)pCursor->GetDoc() : 0;
- if(pDc)
+ m_pImpl->m_pDoc = pDoc;
+ SwUnoInternalPaM aPam(*m_pImpl->m_pDoc);
+ SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange);
+ UnoActionContext aCont(m_pImpl->m_pDoc);
+ if (!m_pImpl->m_sMarkName.getLength())
{
- m_pDoc = pDc;
- SwUnoInternalPaM aPam(*m_pDoc);
- SwXTextRange::XTextRangeToSwPaM(aPam, xTextRange);
- UnoActionContext aCont(m_pDoc);
- if(!m_aName.Len())
- m_aName = OUString::createFromAscii("Bookmark");
- if(eType == IDocumentMarkAccess::BOOKMARK && ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_aName))
- eType = IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK;
- else if(eType == IDocumentMarkAccess::BOOKMARK && ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_aName))
- eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK;
- registerInMark(m_pDoc->getIDocumentMarkAccess()->makeMark(aPam, m_aName, eType));
- // --> OD 2007-10-23 #i81002#
- // Check, if bookmark has been created.
- // E.g., the creation of a cross-reference bookmark is suppress,
- // if the PaM isn't a valid one for cross-reference bookmarks.
- if(!m_pRegisteredBookmark)
- {
- OSL_ENSURE(false,
- "<SwXBookmark::attachToRange(..)>"
- " - could not create Mark.");
- throw lang::IllegalArgumentException();
- }
- // <--
+ m_pImpl->m_sMarkName = OUString::createFromAscii("Bookmark");
}
- else
+ if ((eType == IDocumentMarkAccess::BOOKMARK) &&
+ ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_pImpl->m_sMarkName))
+ {
+ eType = IDocumentMarkAccess::CROSSREF_NUMITEM_BOOKMARK;
+ }
+ else if ((eType == IDocumentMarkAccess::BOOKMARK) &&
+ ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_pImpl->m_sMarkName))
+ {
+ eType = IDocumentMarkAccess::CROSSREF_HEADING_BOOKMARK;
+ }
+ m_pImpl->registerInMark(*this,
+ m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark(
+ aPam, m_pImpl->m_sMarkName, eType));
+ // --> OD 2007-10-23 #i81002#
+ // Check, if bookmark has been created.
+ // E.g., the creation of a cross-reference bookmark is suppress,
+ // if the PaM isn't a valid one for cross-reference bookmarks.
+ if (!m_pImpl->m_pRegisteredBookmark)
+ {
+ OSL_ENSURE(false,
+ "<SwXBookmark::attachToRange(..)>"
+ " - could not create Mark.");
throw lang::IllegalArgumentException();
+ }
+ // <--
}
-void SwXBookmark::attachToRange(const uno::Reference< text::XTextRange > & xTextRange)
- throw( lang::IllegalArgumentException, uno::RuntimeException )
+void SwXBookmark::attachToRange(
+ const uno::Reference< text::XTextRange > & xTextRange)
+throw (lang::IllegalArgumentException, uno::RuntimeException)
{
attachToRangeEx(xTextRange, IDocumentMarkAccess::BOOKMARK);
}
-void SwXBookmark::attach(const uno::Reference< text::XTextRange > & xTextRange)
- throw( lang::IllegalArgumentException, uno::RuntimeException )
+void SAL_CALL
+SwXBookmark::attach(const uno::Reference< text::XTextRange > & xTextRange)
+throw (lang::IllegalArgumentException, uno::RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
attachToRange( xTextRange );
}
-uno::Reference< text::XTextRange > SwXBookmark::getAnchor(void)
- throw( uno::RuntimeException )
+uno::Reference< text::XTextRange > SAL_CALL
+SwXBookmark::getAnchor() throw (uno::RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
- uno::Reference< text::XTextRange > aRet;
- if(m_pRegisteredBookmark)
- aRet = SwXTextRange::CreateTextRangeFromPosition(
- m_pDoc,
- m_pRegisteredBookmark->GetMarkPos(),
- m_pRegisteredBookmark->IsExpanded() ? &m_pRegisteredBookmark->GetOtherMarkPos() : NULL);
- else
+
+ if (!m_pImpl->m_pRegisteredBookmark)
+ {
throw uno::RuntimeException();
- return aRet;
+ }
+ return SwXTextRange::CreateTextRangeFromPosition(
+ m_pImpl->m_pDoc,
+ m_pImpl->m_pRegisteredBookmark->GetMarkPos(),
+ (m_pImpl->m_pRegisteredBookmark->IsExpanded())
+ ? &m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos() : NULL);
}
-void SwXBookmark::dispose(void)
- throw( uno::RuntimeException )
+void SAL_CALL SwXBookmark::dispose() throw (uno::RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
- if(m_pRegisteredBookmark)
- GetDoc()->getIDocumentMarkAccess()->deleteMark(m_pRegisteredBookmark);
- else
- throw uno::RuntimeException();
+ if (m_pImpl->m_pRegisteredBookmark)
+ {
+ m_pImpl->m_pDoc->getIDocumentMarkAccess()->deleteMark(
+ m_pImpl->m_pRegisteredBookmark);
+ }
}
-void SwXBookmark::addEventListener(const uno::Reference< lang::XEventListener > & aListener)
- throw( uno::RuntimeException )
+void SAL_CALL SwXBookmark::addEventListener(
+ const uno::Reference< lang::XEventListener > & xListener)
+throw (uno::RuntimeException)
{
- if(!m_pRegisteredBookmark)
+ vos::OGuard g(Application::GetSolarMutex());
+
+ if (!m_pImpl->m_pRegisteredBookmark)
+ {
throw uno::RuntimeException();
- m_aLstnrCntnr.AddListener(aListener);
+ }
+ m_pImpl->m_ListenerContainer.AddListener(xListener);
}
-void SwXBookmark::removeEventListener(const uno::Reference< lang::XEventListener > & aListener)
- throw( uno::RuntimeException )
+void SAL_CALL SwXBookmark::removeEventListener(
+ const uno::Reference< lang::XEventListener > & xListener)
+throw (uno::RuntimeException)
{
- if(!m_pRegisteredBookmark || !m_aLstnrCntnr.RemoveListener(aListener))
+ vos::OGuard g(Application::GetSolarMutex());
+
+ if (!m_pImpl->m_pRegisteredBookmark ||
+ !m_pImpl->m_ListenerContainer.RemoveListener(xListener))
+ {
throw uno::RuntimeException();
+ }
}
-OUString SwXBookmark::getName(void)
- throw(uno::RuntimeException)
+OUString SAL_CALL SwXBookmark::getName()
+throw (uno::RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
- OUString sRet;
- if(m_pRegisteredBookmark)
- sRet = m_pRegisteredBookmark->GetName();
- else
- sRet = m_aName;
- return sRet;
+
+ return (m_pImpl->m_pRegisteredBookmark)
+ ? m_pImpl->m_pRegisteredBookmark->GetName()
+ : m_pImpl->m_sMarkName;
}
-void SwXBookmark::setName(const OUString& rName)
- throw(uno::RuntimeException)
+void SAL_CALL SwXBookmark::setName(const OUString& rName)
+throw (uno::RuntimeException)
{
vos::OGuard aGuard(Application::GetSolarMutex());
- if(!m_pRegisteredBookmark)
- m_aName = rName;
- if(!m_pRegisteredBookmark || getName() == rName)
+
+ if (!m_pImpl->m_pRegisteredBookmark)
+ {
+ m_pImpl->m_sMarkName = rName;
+ }
+ if (!m_pImpl->m_pRegisteredBookmark || (getName() == rName))
+ {
return;
- IDocumentMarkAccess* const pMarkAccess = m_pDoc->getIDocumentMarkAccess();
+ }
+ IDocumentMarkAccess *const pMarkAccess =
+ m_pImpl->m_pDoc->getIDocumentMarkAccess();
if(pMarkAccess->findMark(rName) != pMarkAccess->getMarksEnd())
+ {
throw uno::RuntimeException();
+ }
- SwPaM aPam(m_pRegisteredBookmark->GetMarkPos());
- if(m_pRegisteredBookmark->IsExpanded())
+ SwPaM aPam(m_pImpl->m_pRegisteredBookmark->GetMarkPos());
+ if (m_pImpl->m_pRegisteredBookmark->IsExpanded())
{
aPam.SetMark();
- *aPam.GetMark() = m_pRegisteredBookmark->GetOtherMarkPos();
+ *aPam.GetMark() = m_pImpl->m_pRegisteredBookmark->GetOtherMarkPos();
}
SwRewriter aRewriter;
@@ -259,114 +379,145 @@ void SwXBookmark::setName(const OUString& rName)
aRewriter.AddRule(UNDO_ARG2, SW_RES(STR_YIELDS));
aRewriter.AddRule(UNDO_ARG3, lcl_QuoteName(rName));
- m_pDoc->StartUndo(UNDO_BOOKMARK_RENAME, &aRewriter);
- pMarkAccess->renameMark(m_pRegisteredBookmark, rName);
- m_pDoc->EndUndo(UNDO_BOOKMARK_RENAME, NULL);
+ m_pImpl->m_pDoc->StartUndo(UNDO_BOOKMARK_RENAME, &aRewriter);
+ pMarkAccess->renameMark(m_pImpl->m_pRegisteredBookmark, rName);
+ m_pImpl->m_pDoc->EndUndo(UNDO_BOOKMARK_RENAME, NULL);
}
-OUString SwXBookmark::getImplementationName(void) throw( uno::RuntimeException )
+OUString SAL_CALL
+SwXBookmark::getImplementationName() throw (uno::RuntimeException)
{
return OUString::createFromAscii("SwXBookmark");
}
-sal_Bool SwXBookmark::supportsService(const OUString& rServiceName)
- throw( uno::RuntimeException )
+static char const*const g_ServicesBookmark[] =
{
- return !rServiceName.compareToAscii("com.sun.star.text.Bookmark") ||
- !rServiceName.compareToAscii("com.sun.star.document.LinkTarget") ||
- !rServiceName.compareToAscii("com.sun.star.text.TextContent");
-}
-
-uno::Sequence< OUString > SwXBookmark::getSupportedServiceNames(void)
- throw( uno::RuntimeException )
+ "com.sun.star.text.TextContent",
+ "com.sun.star.text.Bookmark",
+ "com.sun.star.document.LinkTarget",
+};
+static const size_t g_nServicesBookmark(
+ sizeof(g_ServicesBookmark)/sizeof(g_ServicesBookmark[0]));
+
+sal_Bool SAL_CALL SwXBookmark::supportsService(const OUString& rServiceName)
+throw (uno::RuntimeException)
{
- uno::Sequence< OUString > aRet(3);
- aRet[0] = OUString::createFromAscii("com.sun.star.text.Bookmark");
- aRet[1] = OUString::createFromAscii("com.sun.star.document.LinkTarget");
- aRet[2] = OUString::createFromAscii("com.sun.star.text.TextContent");
- return aRet;
+ return ::sw::SupportsServiceImpl(
+ g_nServicesBookmark, g_ServicesBookmark, rServiceName);
}
-void SwXBookmark::Modify(SfxPoolItem *pOld, SfxPoolItem *pNew)
+uno::Sequence< OUString > SAL_CALL
+SwXBookmark::getSupportedServiceNames() throw (uno::RuntimeException)
{
- ClientModify(this, pOld, pNew);
- if(!GetRegisteredIn())
- {
- m_pRegisteredBookmark = NULL;
- m_pDoc = NULL;
- m_aLstnrCntnr.Disposing();
- }
+ return ::sw::GetSupportedServiceNamesImpl(
+ g_nServicesBookmark, g_ServicesBookmark);
}
// MetadatableMixin
::sfx2::Metadatable* SwXBookmark::GetCoreObject()
{
- return dynamic_cast< ::sfx2::Metadatable* >( GetBookmark() );
+ return dynamic_cast< ::sfx2::Metadatable* >(m_pImpl->m_pRegisteredBookmark);
}
uno::Reference<frame::XModel> SwXBookmark::GetModel()
{
- if (GetDoc())
+ if (m_pImpl->m_pDoc)
{
- SwDocShell const * const pShell( GetDoc()->GetDocShell() );
+ SwDocShell const * const pShell( m_pImpl->m_pDoc->GetDocShell() );
return (pShell) ? pShell->GetModel() : 0;
}
return 0;
}
-uno::Reference< beans::XPropertySetInfo > SwXBookmark::getPropertySetInfo(void)
- throw( uno::RuntimeException )
+uno::Reference< beans::XPropertySetInfo > SAL_CALL
+SwXBookmark::getPropertySetInfo() throw (uno::RuntimeException)
{
- static uno::Reference< beans::XPropertySetInfo > aRef;
- if(!aRef.is())
- {
- aRef = aSwMapProvider.GetPropertySet(PROPERTY_MAP_BOOKMARK)->getPropertySetInfo();
- }
- return aRef;
+ vos::OGuard g(Application::GetSolarMutex());
+
+ static uno::Reference< beans::XPropertySetInfo > xRef(
+ aSwMapProvider.GetPropertySet(PROPERTY_MAP_BOOKMARK)
+ ->getPropertySetInfo() );
+ return xRef;
}
-void SwXBookmark::setPropertyValue(const OUString& PropertyName, const uno::Any& /*aValue*/)
- throw( beans::UnknownPropertyException,
- beans::PropertyVetoException,
- lang::IllegalArgumentException,
- lang::WrappedTargetException,
- uno::RuntimeException )
+void SAL_CALL
+SwXBookmark::setPropertyValue(const OUString& PropertyName,
+ const uno::Any& /*rValue*/)
+throw (beans::UnknownPropertyException, beans::PropertyVetoException,
+ lang::IllegalArgumentException, lang::WrappedTargetException,
+ uno::RuntimeException)
{
// nothing to set here
- throw IllegalArgumentException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + PropertyName, static_cast < cppu::OWeakObject * > ( this ), 0 );
+ throw lang::IllegalArgumentException( ::rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("Property is read-only: "))
+ + PropertyName, static_cast< cppu::OWeakObject * >(this), 0 );
}
-uno::Any SwXBookmark::getPropertyValue(const OUString& rPropertyName)
- throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
+uno::Any SAL_CALL SwXBookmark::getPropertyValue(const OUString& rPropertyName)
+throw (beans::UnknownPropertyException, lang::WrappedTargetException,
+ uno::RuntimeException)
{
+ vos::OGuard g(Application::GetSolarMutex());
+
uno::Any aRet;
if(!SwXParagraph::getDefaultTextContentValue(aRet, rPropertyName))
{
if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
+ {
aRet <<= getName();
+ }
}
return aRet;
}
-void SwXBookmark::addPropertyChangeListener(const OUString& /*PropertyName*/,
- const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
- throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
-{ }
+void SAL_CALL
+SwXBookmark::addPropertyChangeListener(
+ const ::rtl::OUString& /*rPropertyName*/,
+ const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
+throw (beans::UnknownPropertyException, lang::WrappedTargetException,
+ uno::RuntimeException)
+{
+ OSL_ENSURE(false,
+ "SwXBookmark::addPropertyChangeListener(): not implemented");
+}
-void SwXBookmark::removePropertyChangeListener(const OUString& /*PropertyName*/,
- const uno::Reference< beans::XPropertyChangeListener > & /*aListener*/)
- throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
-{ }
+void SAL_CALL
+SwXBookmark::removePropertyChangeListener(
+ const ::rtl::OUString& /*rPropertyName*/,
+ const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
+throw (beans::UnknownPropertyException, lang::WrappedTargetException,
+ uno::RuntimeException)
+{
+ OSL_ENSURE(false,
+ "SwXBookmark::removePropertyChangeListener(): not implemented");
+}
-void SwXBookmark::addVetoableChangeListener(const OUString& /*PropertyName*/,
- const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
- throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
-{ }
+void SAL_CALL
+SwXBookmark::addVetoableChangeListener(
+ const ::rtl::OUString& /*rPropertyName*/,
+ const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
+throw (beans::UnknownPropertyException, lang::WrappedTargetException,
+ uno::RuntimeException)
+{
+ OSL_ENSURE(false,
+ "SwXBookmark::addVetoableChangeListener(): not implemented");
+}
-void SwXBookmark::removeVetoableChangeListener(const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener > & /*aListener*/)
- throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
-{ }
+void SAL_CALL
+SwXBookmark::removeVetoableChangeListener(
+ const ::rtl::OUString& /*rPropertyName*/,
+ const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
+throw (beans::UnknownPropertyException, lang::WrappedTargetException,
+ uno::RuntimeException)
+{
+ OSL_ENSURE(false,
+ "SwXBookmark::removeVetoableChangeListener(): not implemented");
+}
+
+/******************************************************************
+ * SwXFieldmark
+ ******************************************************************/
SwXFieldmark::SwXFieldmark(bool _isReplacementObject, ::sw::mark::IMark* pBkm, SwDoc* pDc)
: SwXFieldmark_Base(pBkm, pDc)
@@ -436,3 +587,4 @@ void SAL_CALL SwXFieldmark::setDescription( const ::rtl::OUString& description )
else
throw uno::RuntimeException();
}
+
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index 72606237ec70..87f96ba72346 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -1529,8 +1529,9 @@ uno::Any SwXBookmarks::getByIndex(sal_Int32 nIndex)
uno::Any aRet;
::sw::mark::IMark* pBkmk = pMarkAccess->getBookmarksBegin()[nIndex].get();
- uno::Reference< XTextContent > xRef = GetObject(*pBkmk, GetDoc());
- aRet.setValue(&xRef, ::getCppuType((uno::Reference<XTextContent>*)0));
+ const uno::Reference< text::XTextContent > xRef =
+ SwXBookmark::CreateXBookmark(*GetDoc(), *pBkmk);
+ aRet <<= xRef;
return aRet;
}
@@ -1547,8 +1548,9 @@ uno::Any SwXBookmarks::getByName(const rtl::OUString& rName)
throw NoSuchElementException();
uno::Any aRet;
- uno::Reference< XTextContent > xRef = SwXBookmarks::GetObject(*(ppBkmk->get()), GetDoc());
- aRet.setValue(&xRef, ::getCppuType((uno::Reference<XTextContent>*)0));
+ const uno::Reference< text::XTextContent > xRef =
+ SwXBookmark::CreateXBookmark(*GetDoc(), *(ppBkmk->get()));
+ aRet <<= xRef;
return aRet;
}
@@ -1594,27 +1596,6 @@ sal_Bool SwXBookmarks::hasElements(void)
return GetDoc()->getIDocumentMarkAccess()->getBookmarksCount() != 0;
}
-SwXBookmark* SwXBookmarks::GetObject( ::sw::mark::IMark& rBkmk, SwDoc* pDoc)
-{
- SwModify* const pModify = static_cast<SwModify*>(&rBkmk);
- SwXBookmark* pXBkmk = (SwXBookmark*)SwClientIter(*pModify).First(TYPE(SwXBookmark));
- if(!pXBkmk)
- {
- // FIXME: These belong in XTextFieldsSupplier
- //if (dynamic_cast< ::sw::mark::TextFieldmark* >(&rBkmk))
- // pXBkmk = new SwXFieldmark(false, &rBkmk, pDoc);
- //else if (dynamic_cast< ::sw::mark::CheckboxFieldmark* >(&rBkmk))
- // pXBkmk = new SwXFieldmark(true, &rBkmk, pDoc);
- //else
- OSL_ENSURE(
- dynamic_cast< ::sw::mark::IBookmark* >(&rBkmk),
- "<SwXBookmark::GetObject(..)>"
- "SwXBookmark requested for non-bookmark mark.");
- pXBkmk = new SwXBookmark(&rBkmk, pDoc);
- }
- return pXBkmk;
-}
-
/******************************************************************
*
******************************************************************/
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index e7426091f745..605554253bf8 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -100,8 +100,9 @@ namespace
BYTE nBkmType;
const SwPosition aPosition;
- SwXBookmarkPortion_Impl( SwXBookmark* pXMark, BYTE nType, const SwPosition &rPosition )
- : xBookmark ( pXMark )
+ SwXBookmarkPortion_Impl(uno::Reference<text::XTextContent> const& xMark,
+ const BYTE nType, SwPosition const& rPosition)
+ : xBookmark ( xMark )
, nBkmType ( nType )
, aPosition ( rPosition )
{
@@ -165,7 +166,9 @@ namespace
{
const BYTE nType = hasOther ? BKM_TYPE_START : BKM_TYPE_START_END;
rBkmArr.insert(SwXBookmarkPortion_ImplSharedPtr(
- new SwXBookmarkPortion_Impl ( SwXBookmarks::GetObject(*pBkmk, &rDoc ), nType, rStartPos)));
+ new SwXBookmarkPortion_Impl(
+ SwXBookmark::CreateXBookmark(rDoc, *pBkmk),
+ nType, rStartPos)));
}
const SwPosition& rEndPos = pBkmk->GetMarkEnd();
@@ -183,8 +186,12 @@ namespace
pEndPos = pCrossRefEndPos.get();
}
if(pEndPos)
+ {
rBkmArr.insert(SwXBookmarkPortion_ImplSharedPtr(
- new SwXBookmarkPortion_Impl ( SwXBookmarks::GetObject(*pBkmk, &rDoc ), BKM_TYPE_END, *pEndPos)));
+ new SwXBookmarkPortion_Impl(
+ SwXBookmark::CreateXBookmark(rDoc, *pBkmk),
+ BKM_TYPE_END, *pEndPos)));
+ }
}
}
}
diff --git a/sw/source/ui/uno/unotxvw.cxx b/sw/source/ui/uno/unotxvw.cxx
index 9da88953d481..35a4c5a2f92c 100644
--- a/sw/source/ui/uno/unotxvw.cxx
+++ b/sw/source/ui/uno/unotxvw.cxx
@@ -433,19 +433,14 @@ sal_Bool SwXTextView::select(const uno::Any& aInterface) throw( lang::IllegalArg
if(xBkm.is() && xIfcTunnel.is())
{
- SwXBookmark* pBkm = reinterpret_cast<SwXBookmark*>(
- xIfcTunnel->getSomething(SwXBookmark::getUnoTunnelId()));
- if(pBkm && pBkm->GetDoc() == pDoc)
+ ::sw::mark::IMark const*const pMark(
+ SwXBookmark::GetBookmarkInDoc(pDoc, xIfcTunnel) );
+ if (pMark)
{
- IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
- IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(pBkm->getName());
- if( ppMark != pMarkAccess->getMarksEnd() )
- {
- rSh.EnterStdMode();
- rSh.GotoMark( ppMark->get() );
- }
- return sal_True;
+ rSh.EnterStdMode();
+ rSh.GotoMark(pMark);
}
+ return sal_True;
}
// IndexMark, Index, TextField, Draw, Section, Footnote, Paragraph
//