use rtl::Reference in SwXAutoTextEntry

instead of storing both a raw pointer and an uno::Reference

Change-Id: I52c8827446d999d0a34b91ab17c056d4237d71a7
This commit is contained in:
Noel Grandin
2017-01-25 15:54:42 +02:00
parent 12ff6d6c35
commit f025255bf6
2 changed files with 18 additions and 18 deletions

View File

@@ -34,7 +34,9 @@
#include <cppuhelper/basemutex.hxx> #include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx> #include <cppuhelper/compbase.hxx>
#include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase.hxx>
#include <rtl/ref.hxx>
#include <svtools/unoevent.hxx> #include <svtools/unoevent.hxx>
class SwTextBlocks; class SwTextBlocks;
class SwGlossaries; class SwGlossaries;
class SwDoc; class SwDoc;
@@ -172,12 +174,12 @@ class SwXAutoTextEntry
OUString sGroupName; OUString sGroupName;
OUString sEntryName; OUString sEntryName;
SwDocShellRef xDocSh; SwDocShellRef xDocSh;
SwXBodyText* pBodyText; rtl::Reference<SwXBodyText>
css::uno::Reference < css::lang::XServiceInfo> xBodyText; mxBodyText;
void EnsureBodyText () void EnsureBodyText ()
{ {
if ( !pBodyText ) if ( !mxBodyText.is() )
GetBodyText(); GetBodyText();
} }
void GetBodyText (); void GetBodyText ();

View File

@@ -721,8 +721,7 @@ SwXAutoTextEntry::SwXAutoTextEntry(SwGlossaries* pGlss, const OUString& rGroupNa
WeakComponentImplHelper(m_aMutex), WeakComponentImplHelper(m_aMutex),
pGlossaries(pGlss), pGlossaries(pGlss),
sGroupName(rGroupName), sGroupName(rGroupName),
sEntryName(rEntryName), sEntryName(rEntryName)
pBodyText ( nullptr )
{ {
} }
@@ -761,7 +760,7 @@ void SwXAutoTextEntry::Notify( SfxBroadcaster& _rBC, const SfxHint& _rHint )
if (SfxEventHintId::PrepareCloseDoc == pEventHint->GetEventId()) if (SfxEventHintId::PrepareCloseDoc == pEventHint->GetEventId())
{ {
implFlushDocument(); implFlushDocument();
xBodyText = nullptr; mxBodyText.clear();
EndListening( *xDocSh ); EndListening( *xDocSh );
xDocSh.Clear(); xDocSh.Clear();
} }
@@ -791,8 +790,7 @@ void SwXAutoTextEntry::GetBodyText ()
// start listening at the document // start listening at the document
StartListening( *xDocSh ); StartListening( *xDocSh );
pBodyText = new SwXBodyText ( xDocSh->GetDoc() ); mxBodyText = new SwXBodyText ( xDocSh->GetDoc() );
xBodyText.set( *pBodyText, uno::UNO_QUERY);
} }
void SwXAutoTextEntry::disposing() void SwXAutoTextEntry::disposing()
@@ -805,7 +803,7 @@ uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursor() throw(
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
return pBodyText->createTextCursor(); return mxBodyText->createTextCursor();
} }
uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursorByRange( uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursorByRange(
@@ -813,14 +811,14 @@ uno::Reference< text::XTextCursor > SwXAutoTextEntry::createTextCursorByRange(
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
return pBodyText->createTextCursorByRange ( aTextPosition ); return mxBodyText->createTextCursorByRange ( aTextPosition );
} }
void SwXAutoTextEntry::insertString(const uno::Reference< text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) throw( uno::RuntimeException, std::exception ) void SwXAutoTextEntry::insertString(const uno::Reference< text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) throw( uno::RuntimeException, std::exception )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
pBodyText->insertString ( xRange, aString, bAbsorb ); mxBodyText->insertString ( xRange, aString, bAbsorb );
} }
void SwXAutoTextEntry::insertControlCharacter(const uno::Reference< text::XTextRange > & xRange, void SwXAutoTextEntry::insertControlCharacter(const uno::Reference< text::XTextRange > & xRange,
@@ -829,7 +827,7 @@ void SwXAutoTextEntry::insertControlCharacter(const uno::Reference< text::XTextR
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
pBodyText->insertControlCharacter ( xRange, nControlCharacter, bAbsorb ); mxBodyText->insertControlCharacter ( xRange, nControlCharacter, bAbsorb );
} }
void SwXAutoTextEntry::insertTextContent( void SwXAutoTextEntry::insertTextContent(
@@ -839,7 +837,7 @@ void SwXAutoTextEntry::insertTextContent(
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
pBodyText->insertTextContent ( xRange, xContent, bAbsorb ); mxBodyText->insertTextContent ( xRange, xContent, bAbsorb );
} }
void SwXAutoTextEntry::removeTextContent( void SwXAutoTextEntry::removeTextContent(
@@ -848,7 +846,7 @@ void SwXAutoTextEntry::removeTextContent(
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
pBodyText->removeTextContent ( xContent ); mxBodyText->removeTextContent ( xContent );
} }
uno::Reference< text::XText > SwXAutoTextEntry::getText() throw( uno::RuntimeException, std::exception ) uno::Reference< text::XText > SwXAutoTextEntry::getText() throw( uno::RuntimeException, std::exception )
@@ -862,28 +860,28 @@ uno::Reference< text::XTextRange > SwXAutoTextEntry::getStart() throw( uno::Run
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
return pBodyText->getStart(); return mxBodyText->getStart();
} }
uno::Reference< text::XTextRange > SwXAutoTextEntry::getEnd() throw( uno::RuntimeException, std::exception ) uno::Reference< text::XTextRange > SwXAutoTextEntry::getEnd() throw( uno::RuntimeException, std::exception )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
return pBodyText->getEnd(); return mxBodyText->getEnd();
} }
OUString SwXAutoTextEntry::getString() throw( uno::RuntimeException, std::exception ) OUString SwXAutoTextEntry::getString() throw( uno::RuntimeException, std::exception )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
return pBodyText->getString(); return mxBodyText->getString();
} }
void SwXAutoTextEntry::setString(const OUString& aString) throw( uno::RuntimeException, std::exception ) void SwXAutoTextEntry::setString(const OUString& aString) throw( uno::RuntimeException, std::exception )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
EnsureBodyText(); EnsureBodyText();
pBodyText->setString( aString ); mxBodyText->setString( aString );
} }
void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextRange)throw( uno::RuntimeException, std::exception ) void SwXAutoTextEntry::applyTo(const uno::Reference< text::XTextRange > & xTextRange)throw( uno::RuntimeException, std::exception )