summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-05-10 10:51:42 +0200
committerBjoern Michaelsen <bjoern.michaelsen@libreoffice.org>2018-05-12 10:20:02 +0200
commit3fe21e2ca91aeb8f257a08c2e2fd086bc0ea1b7b (patch)
tree177330bccc48ca0e530a9cb41dd8051ede160e62
parentcc81012a92dfbca52e9a5f281c23ef33176895d2 (diff)
dont use SwClient/SwModify in unocore: HeadFootText
Change-Id: Icf0fa7ec07c8c52981c50bc03a34ae0fa9683fcf
-rw-r--r--sw/inc/calbck.hxx4
-rw-r--r--sw/inc/frmfmt.hxx4
-rw-r--r--sw/inc/section.hxx1
-rw-r--r--sw/inc/unotextbodyhf.hxx1
-rw-r--r--sw/source/core/layout/atrfrm.cxx2
-rw-r--r--sw/source/core/unocore/unotext.cxx183
6 files changed, 86 insertions, 109 deletions
diff --git a/sw/inc/calbck.hxx b/sw/inc/calbck.hxx
index 595a3deab14d..8a2567f4ce50 100644
--- a/sw/inc/calbck.hxx
+++ b/sw/inc/calbck.hxx
@@ -83,6 +83,10 @@ namespace sw
class SW_DLLPUBLIC BroadcasterMixin {
SvtBroadcaster m_aNotifier;
public:
+ BroadcasterMixin& operator=(const BroadcasterMixin&)
+ {
+ return *this; // Listeners are never copied or moved.
+ }
SvtBroadcaster& GetNotifier() { return m_aNotifier; }
};
/// refactoring out the some of the more sane SwClient functionality
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx
index 787988467407..a8f61f3cf17a 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -53,7 +53,9 @@ namespace sw
class SwFrameFormats;
/// Style of a layout element.
-class SW_DLLPUBLIC SwFrameFormat: public SwFormat
+class SW_DLLPUBLIC SwFrameFormat
+ : public SwFormat
+ , public sw::BroadcasterMixin
{
friend class SwDoc;
friend class SwPageDesc; ///< Is allowed to call protected CTor.
diff --git a/sw/inc/section.hxx b/sw/inc/section.hxx
index eb4cc6913f38..30b582b89a80 100644
--- a/sw/inc/section.hxx
+++ b/sw/inc/section.hxx
@@ -270,7 +270,6 @@ enum class SectionSort { Not, Pos };
class SW_DLLPUBLIC SwSectionFormat
: public SwFrameFormat
, public ::sfx2::Metadatable
- , public sw::BroadcasterMixin
{
friend class SwDoc;
diff --git a/sw/inc/unotextbodyhf.hxx b/sw/inc/unotextbodyhf.hxx
index 11aa3cbf794f..439d434dade0 100644
--- a/sw/inc/unotextbodyhf.hxx
+++ b/sw/inc/unotextbodyhf.hxx
@@ -116,7 +116,6 @@ public:
static css::uno::Reference< css::text::XText >
CreateXHeadFootText(SwFrameFormat & rHeadFootFormat, const bool bIsHeader);
- static bool IsXHeadFootText(SwClient const *const pClient);
// XInterface
virtual css::uno::Any SAL_CALL queryInterface(
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index bcc42a8b06f8..7f4d27ad6e1c 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -121,7 +121,7 @@ static void lcl_DelHFFormat( SwClient *pToRemove, SwFrameFormat *pFormat )
// It's suboptimal if the format is deleted beforehand.
SwIterator<SwClient,SwFrameFormat> aIter(*pFormat);
for(SwClient* pLast = aIter.First(); bDel && pLast; pLast = aIter.Next())
- if (dynamic_cast<const SwFrame*>(pLast) == nullptr && !SwXHeadFootText::IsXHeadFootText(pLast))
+ if (dynamic_cast<const SwFrame*>(pLast) == nullptr)
bDel = false;
}
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 6d01370e5d19..cc238510ab99 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -30,6 +30,7 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
+#include <svl/listener.hxx>
#include <vcl/svapp.hxx>
#include <comphelper/profilezone.hxx>
#include <comphelper/sequence.hxx>
@@ -2453,108 +2454,90 @@ SwXBodyText::hasElements()
}
class SwXHeadFootText::Impl
- : public SwClient
+ : public SvtListener
{
+ public:
+ SwFrameFormat* m_pHeadFootFormat;
+ bool m_bIsHeader;
-public:
-
- bool m_bIsHeader;
-
- Impl( SwFrameFormat & rHeadFootFormat, const bool bIsHeader)
- : SwClient(& rHeadFootFormat)
- , m_bIsHeader(bIsHeader)
- {
- }
-
- SwFrameFormat * GetHeadFootFormat() const {
- return static_cast<SwFrameFormat*>(
- const_cast<SwModify*>(GetRegisteredIn()));
- }
+ Impl(SwFrameFormat& rHeadFootFormat, const bool bIsHeader)
+ : m_pHeadFootFormat(&rHeadFootFormat)
+ , m_bIsHeader(bIsHeader)
+ {
+ if(m_pHeadFootFormat)
+ StartListening(m_pHeadFootFormat->GetNotifier());
+ }
- SwFrameFormat & GetHeadFootFormatOrThrow() {
- SwFrameFormat *const pFormat( GetHeadFootFormat() );
- if (!pFormat) {
- throw uno::RuntimeException("SwXHeadFootText: disposed or invalid", nullptr);
+ SwFrameFormat* GetHeadFootFormat() const {
+ return m_pHeadFootFormat;
}
- return *pFormat;
- }
-protected:
- // SwClient
- virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override;
+ SwFrameFormat& GetHeadFootFormatOrThrow() {
+ if (!m_pHeadFootFormat) {
+ throw uno::RuntimeException("SwXHeadFootText: disposed or invalid", nullptr);
+ }
+ return *m_pHeadFootFormat;
+ }
+ protected:
+ virtual void Notify(const SfxHint& rHint) override
+ {
+ if(rHint.GetId() == SfxHintId::Dying)
+ m_pHeadFootFormat = nullptr;
+ }
};
-void SwXHeadFootText::Impl::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew)
-{
- ClientModify(this, pOld, pNew);
-}
-
-bool SwXHeadFootText::IsXHeadFootText(SwClient const *const pClient)
-{
- return dynamic_cast<SwXHeadFootText::Impl const *>(pClient) != nullptr;
-}
-
-uno::Reference< text::XText >
-SwXHeadFootText::CreateXHeadFootText(
- SwFrameFormat & rHeadFootFormat, const bool bIsHeader)
+uno::Reference<text::XText> SwXHeadFootText::CreateXHeadFootText(
+ SwFrameFormat& rHeadFootFormat,
+ const bool bIsHeader)
{
// re-use existing SwXHeadFootText
// #i105557#: do not iterate over the registered clients: race condition
- uno::Reference< text::XText > xText(rHeadFootFormat.GetXObject(),
- uno::UNO_QUERY);
- if (!xText.is())
+ uno::Reference<text::XText> xText(rHeadFootFormat.GetXObject(), uno::UNO_QUERY);
+ if(!xText.is())
{
- SwXHeadFootText *const pXHFT(
- new SwXHeadFootText(rHeadFootFormat, bIsHeader));
+ const auto pXHFT(new SwXHeadFootText(rHeadFootFormat, bIsHeader));
xText.set(pXHFT);
rHeadFootFormat.SetXObject(xText);
}
return xText;
}
-SwXHeadFootText::SwXHeadFootText(SwFrameFormat & rHeadFootFormat, const bool bIsHeader)
- : SwXText(rHeadFootFormat.GetDoc(),
+SwXHeadFootText::SwXHeadFootText(SwFrameFormat& rHeadFootFormat, const bool bIsHeader)
+ : SwXText(
+ rHeadFootFormat.GetDoc(),
bIsHeader ? CursorType::Header : CursorType::Footer)
- , m_pImpl( new SwXHeadFootText::Impl(rHeadFootFormat, bIsHeader) )
+ , m_pImpl(new SwXHeadFootText::Impl(rHeadFootFormat, bIsHeader))
{
}
SwXHeadFootText::~SwXHeadFootText()
-{
-}
+{ }
OUString SAL_CALL
SwXHeadFootText::getImplementationName()
{
- return OUString("SwXHeadFootText");
+ return "SwXHeadFootText";
}
-static char const*const g_ServicesHeadFootText[] =
-{
- "com.sun.star.text.Text",
-};
-
sal_Bool SAL_CALL SwXHeadFootText::supportsService(const OUString& rServiceName)
{
return cppu::supportsService(this, rServiceName);
}
-uno::Sequence< OUString > SAL_CALL
+uno::Sequence<OUString> SAL_CALL
SwXHeadFootText::getSupportedServiceNames()
{
- return ::sw::GetSupportedServiceNamesImpl(
- SAL_N_ELEMENTS(g_ServicesHeadFootText),
- g_ServicesHeadFootText);
+ return {"com.sun.star.text.Text"};
}
-const SwStartNode *SwXHeadFootText::GetStartNode() const
+const SwStartNode* SwXHeadFootText::GetStartNode() const
{
- const SwStartNode *pSttNd = nullptr;
- SwFrameFormat *const pHeadFootFormat = m_pImpl->GetHeadFootFormat();
+ const SwStartNode* pSttNd = nullptr;
+ SwFrameFormat* const pHeadFootFormat = m_pImpl->GetHeadFootFormat();
if(pHeadFootFormat)
{
const SwFormatContent& rFlyContent = pHeadFootFormat->GetContent();
- if( rFlyContent.GetContentIdx() )
+ if(rFlyContent.GetContentIdx())
{
pSttNd = rFlyContent.GetContentIdx()->GetNode().GetStartNode();
}
@@ -2562,43 +2545,38 @@ const SwStartNode *SwXHeadFootText::GetStartNode() const
return pSttNd;
}
-uno::Reference< text::XTextCursor >
-SwXHeadFootText::CreateCursor()
+uno::Reference<text::XTextCursor> SwXHeadFootText::CreateCursor()
{
return createTextCursor();
}
-uno::Sequence< uno::Type > SAL_CALL
-SwXHeadFootText::getTypes()
+uno::Sequence<uno::Type> SAL_CALL SwXHeadFootText::getTypes()
{
- const uno::Sequence< uno::Type > aTypes = SwXHeadFootText_Base::getTypes();
- const uno::Sequence< uno::Type > aTextTypes = SwXText::getTypes();
- return ::comphelper::concatSequences(aTypes, aTextTypes);
+ return ::comphelper::concatSequences(
+ SwXHeadFootText_Base::getTypes(),
+ SwXText::getTypes());
}
-uno::Sequence< sal_Int8 > SAL_CALL
-SwXHeadFootText::getImplementationId()
+uno::Sequence<sal_Int8> SAL_CALL SwXHeadFootText::getImplementationId()
{
return css::uno::Sequence<sal_Int8>();
}
-uno::Any SAL_CALL
-SwXHeadFootText::queryInterface(const uno::Type& rType)
+uno::Any SAL_CALL SwXHeadFootText::queryInterface(const uno::Type& rType)
{
const uno::Any ret = SwXHeadFootText_Base::queryInterface(rType);
return (ret.getValueType() == cppu::UnoType<void>::get())
- ? SwXText::queryInterface(rType)
- : ret;
+ ? SwXText::queryInterface(rType)
+ : ret;
}
-uno::Reference< text::XTextCursor > SAL_CALL
+uno::Reference<text::XTextCursor> SAL_CALL
SwXHeadFootText::createTextCursor()
{
SolarMutexGuard aGuard;
SwFrameFormat & rHeadFootFormat( m_pImpl->GetHeadFootFormatOrThrow() );
- uno::Reference< text::XTextCursor > xRet;
const SwFormatContent& rFlyContent = rHeadFootFormat.GetContent();
const SwNode& rNode = rFlyContent.GetContentIdx()->GetNode();
SwPosition aPos(rNode);
@@ -2624,8 +2602,7 @@ SwXHeadFootText::createTextCursor()
{
rUnoCursor.GetPoint()->nContent.Assign(pCont, 0);
}
- SwStartNode const*const pNewStartNode =
- rUnoCursor.GetNode().FindSttNodeByType(
+ SwStartNode const*const pNewStartNode = rUnoCursor.GetNode().FindSttNodeByType(
(m_pImpl->m_bIsHeader) ? SwHeaderStartNode : SwFooterStartNode);
if (!pNewStartNode || (pNewStartNode != pOwnStartNode))
{
@@ -2633,69 +2610,65 @@ SwXHeadFootText::createTextCursor()
aExcept.Message = "no text available";
throw aExcept;
}
- xRet = static_cast<text::XWordCursor*>(pXCursor);
- return xRet;
+ return static_cast<text::XWordCursor*>(pXCursor);
}
-uno::Reference< text::XTextCursor > SAL_CALL
-SwXHeadFootText::createTextCursorByRange(
- const uno::Reference< text::XTextRange > & xTextPosition)
+uno::Reference<text::XTextCursor> SAL_CALL SwXHeadFootText::createTextCursorByRange(
+ const uno::Reference<text::XTextRange>& xTextPosition)
{
SolarMutexGuard aGuard;
-
- SwFrameFormat & rHeadFootFormat( m_pImpl->GetHeadFootFormatOrThrow() );
+ SwFrameFormat& rHeadFootFormat( m_pImpl->GetHeadFootFormatOrThrow() );
SwUnoInternalPaM aPam(*GetDoc());
- if (!::sw::XTextRangeToSwPaM(aPam, xTextPosition))
+ if (!sw::XTextRangeToSwPaM(aPam, xTextPosition))
{
uno::RuntimeException aRuntime;
aRuntime.Message = cInvalidObject;
throw aRuntime;
}
- uno::Reference< text::XTextCursor > xRet;
SwNode& rNode = rHeadFootFormat.GetContent().GetContentIdx()->GetNode();
SwPosition aPos(rNode);
SwPaM aHFPam(aPos);
aHFPam.Move(fnMoveForward, GoInNode);
- SwStartNode *const pOwnStartNode = aHFPam.GetNode().FindSttNodeByType(
+ SwStartNode* const pOwnStartNode = aHFPam.GetNode().FindSttNodeByType(
(m_pImpl->m_bIsHeader) ? SwHeaderStartNode : SwFooterStartNode);
- SwStartNode *const p1 = aPam.GetNode().FindSttNodeByType(
+ SwStartNode* const p1 = aPam.GetNode().FindSttNodeByType(
(m_pImpl->m_bIsHeader) ? SwHeaderStartNode : SwFooterStartNode);
if (p1 == pOwnStartNode)
{
- xRet = static_cast<text::XWordCursor*>(
- new SwXTextCursor(*GetDoc(), this,
+ return static_cast<text::XWordCursor*>(
+ new SwXTextCursor(
+ *GetDoc(),
+ this,
(m_pImpl->m_bIsHeader) ? CursorType::Header : CursorType::Footer,
*aPam.GetPoint(), aPam.GetMark()));
}
- return xRet;
+ return nullptr;
}
-uno::Reference< container::XEnumeration > SAL_CALL
-SwXHeadFootText::createEnumeration()
+uno::Reference<container::XEnumeration> SAL_CALL SwXHeadFootText::createEnumeration()
{
SolarMutexGuard aGuard;
-
- SwFrameFormat & rHeadFootFormat( m_pImpl->GetHeadFootFormatOrThrow() );
+ SwFrameFormat& rHeadFootFormat(m_pImpl->GetHeadFootFormatOrThrow());
const SwFormatContent& rFlyContent = rHeadFootFormat.GetContent();
const SwNode& rNode = rFlyContent.GetContentIdx()->GetNode();
SwPosition aPos(rNode);
auto pUnoCursor(GetDoc()->CreateUnoCursor(aPos));
pUnoCursor->Move(fnMoveForward, GoInNode);
- return SwXParagraphEnumeration::Create(this, pUnoCursor, (m_pImpl->m_bIsHeader) ? CursorType::Header : CursorType::Footer);
+ return SwXParagraphEnumeration::Create(
+ this,
+ pUnoCursor,
+ (m_pImpl->m_bIsHeader)
+ ? CursorType::Header
+ : CursorType::Footer);
}
-uno::Type SAL_CALL
-SwXHeadFootText::getElementType()
-{
- return cppu::UnoType<text::XTextRange>::get();
-}
+uno::Type SAL_CALL SwXHeadFootText::getElementType()
+ { return cppu::UnoType<text::XTextRange>::get(); }
sal_Bool SAL_CALL SwXHeadFootText::hasElements()
-{
- return true;
-}
+ { return true; }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */