diff options
author | Michael Stahl <mstahl@redhat.com> | 2012-09-26 12:43:29 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-09-26 12:57:27 +0200 |
commit | d53e12c7a9c2d0a3b487303673c1fafd09f6593c (patch) | |
tree | 2ad08e0b624d0252f562cd1a22cfb28a2e2fac80 | |
parent | 0843533459302d9d9fe962f79dc5b040c3907ebc (diff) |
rhbz#827695: sw: prevent crashes after incomplete print:
If the last page is not printed for whatever reason, then
SwXTextDocument's destructor will delete a SwViewOptionAdjust_Impl,
which accesses the document's ViewShell, which has already been
deleted at that point. Add a horrible kludge to not crash for now.
Change-Id: I67fe37970d60782030b84f2badddd1e66ef3f9c6
-rw-r--r-- | sw/inc/printdata.hxx | 2 | ||||
-rw-r--r-- | sw/inc/unotxdoc.hxx | 5 | ||||
-rw-r--r-- | sw/source/core/view/printdata.cxx | 5 | ||||
-rw-r--r-- | sw/source/ui/uno/unotxdoc.cxx | 26 |
4 files changed, 27 insertions, 11 deletions
diff --git a/sw/inc/printdata.hxx b/sw/inc/printdata.hxx index 00e7fe544245..0f58d30d761f 100644 --- a/sw/inc/printdata.hxx +++ b/sw/inc/printdata.hxx @@ -39,13 +39,12 @@ #include <map> #include <vector> #include <utility> class SwDoc; class SwDocShell; -class ViewShell; class _SetGetExpFlds; class SwViewOption; class OutputDevice; class SwViewOptionAdjust_Impl; class ViewShell; class SfxViewShell; @@ -274,12 +273,13 @@ public: bool IsViewOptionAdjust() const { return m_pViewOptionAdjust != 0; } bool NeedNewViewOptionAdjust( const ViewShell& ) const; void ViewOptionAdjustStart( ViewShell &rSh, const SwViewOption &rViewOptions); void ViewOptionAdjust( SwPrintData const* const pPrtOptions ); void ViewOptionAdjustStop(); + void ViewOptionAdjustCrashPreventionKludge(); bool HasSwPrtOptions() const { return m_pPrtOptions != 0; } SwPrintData const* GetSwPrtOptions() const { return m_pPrtOptions.get(); } void MakeSwPrtOptions( SwDocShell const*const pDocShell, SwPrintUIOptions const*const pOpt, bool const bIsPDFExport ); diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 443aa763a6eb..3182bd268156 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -576,19 +576,20 @@ public: hidden characters are always invisible. Hidden text and place holders should be printed according to the current print options. After printing the view options are restored -----------------------------------------------------------------------*/ class SwViewOptionAdjust_Impl { - ViewShell & m_rShell; + ViewShell * m_pShell; SwViewOption m_aOldViewOptions; public: SwViewOptionAdjust_Impl( ViewShell& rSh, const SwViewOption &rViewOptions ); ~SwViewOptionAdjust_Impl(); void AdjustViewOptions( SwPrintData const* const pPrtOptions ); bool checkShell( const ViewShell& rCompare ) const - { return &rCompare == &m_rShell; } + { return &rCompare == m_pShell; } + void DontTouchThatViewShellItSmellsFunny() { m_pShell = 0; } }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/view/printdata.cxx b/sw/source/core/view/printdata.cxx index 4e6d37f1cab1..99888555d2dd 100644 --- a/sw/source/core/view/printdata.cxx +++ b/sw/source/core/view/printdata.cxx @@ -128,12 +128,17 @@ void SwRenderData::ViewOptionAdjust(SwPrintData const*const pPrtOptions) void SwRenderData::ViewOptionAdjustStop() { m_pViewOptionAdjust.reset(); } +void SwRenderData::ViewOptionAdjustCrashPreventionKludge() +{ + m_pViewOptionAdjust->DontTouchThatViewShellItSmellsFunny(); +} + void SwRenderData::MakeSwPrtOptions( SwDocShell const*const pDocShell, SwPrintUIOptions const*const pOpt, bool const bIsPDFExport) { diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx index 8bee384245dc..ef09ecf5a026 100644 --- a/sw/source/ui/uno/unotxdoc.cxx +++ b/sw/source/ui/uno/unotxdoc.cxx @@ -397,12 +397,19 @@ SwXTextDocument::~SwXTextDocument() { Reference< XInterface > x0; xNumFmtAgg->setDelegator(x0); xNumFmtAgg = 0; } delete m_pPrintUIOptions; + if (m_pRenderData && m_pRenderData->IsViewOptionAdjust()) + { // rhbz#827695: this can happen if the last page is not printed + // the ViewShell has been deleted already by SwView::~SwView + // FIXME: replace this awful implementation of XRenderable with + // something less insane that has its own view + m_pRenderData->ViewOptionAdjustCrashPreventionKludge(); + } delete m_pRenderData; } SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper () { if(!xPropertyHelper.is()) @@ -3849,35 +3856,38 @@ void SwXDocumentPropertyHelper::onChange() if(m_pDoc) m_pDoc->SetModified(); } SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl( ViewShell& rSh, const SwViewOption &rViewOptions) - : m_rShell( rSh ) + : m_pShell(&rSh) , m_aOldViewOptions( rViewOptions ) { } SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl() { - m_rShell.ApplyViewOptions( m_aOldViewOptions ); + if (m_pShell) + { + m_pShell->ApplyViewOptions( m_aOldViewOptions ); + } } void SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions) { // to avoid unnecessary reformatting the view options related to the content // below should only change if necessary, that is if respective content is present - const bool bContainsHiddenChars = m_rShell.GetDoc()->ContainsHiddenChars(); - const SwFieldType* pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENTXTFLD ); + const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars(); + const SwFieldType* pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENTXTFLD ); const bool bContainsHiddenFields = pFldType && pFldType->GetDepends(); - pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENPARAFLD ); + pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENPARAFLD ); const bool bContainsHiddenParagraphs = pFldType && pFldType->GetDepends(); - pFldType = m_rShell.GetDoc()->GetSysFldType( RES_JUMPEDITFLD ); + pFldType = m_pShell->GetDoc()->GetSysFldType( RES_JUMPEDITFLD ); const bool bContainsPlaceHolders = pFldType && pFldType->GetDepends(); - const bool bContainsFields = m_rShell.IsAnyFieldInDoc(); + const bool bContainsFields = m_pShell->IsAnyFieldInDoc(); SwViewOption aRenderViewOptions( m_aOldViewOptions ); // disable anything in the view that should not be printed (or exported to PDF) by default // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids" // in section "Display of ...") @@ -3911,11 +3921,11 @@ SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions) // some of the above settings (needed for correct rendering) aRenderViewOptions.SetViewMetaChars( sal_True ); if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary { aRenderViewOptions.SetPrinting( pPrtOptions != NULL ); - m_rShell.ApplyViewOptions( aRenderViewOptions ); + m_pShell->ApplyViewOptions( aRenderViewOptions ); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |