--- a/sw/inc/printdata.hxx +++ b/sw/inc/printdata.hxx @@ -32,6 +32,7 @@ #include <sal/types.h> #include <rtl/ustring.hxx> #include <vcl/print.hxx> +#include <sfx2/objsh.hxx> #include <set> #include <map> @@ -246,6 +247,10 @@ rtl::OUString m_aPageRange; + // temp print document -- must live longer than m_pViewOptionAdjust! + // also this is a Lock and not a Ref because Ref does not delete the doc + SfxObjectShellLock m_xTempDocShell; + // the view options to be applied for printing SwViewOptionAdjust_Impl * m_pViewOptionAdjust; @@ -267,9 +272,12 @@ void CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev ); void DeletePostItData(); + SfxObjectShellLock const& GetTempDocShell() const; + void SetTempDocShell(SfxObjectShellLock const&); + bool IsViewOptionAdjust() const { return m_pViewOptionAdjust != 0; } bool NeedNewViewOptionAdjust( const SwWrtShell& ) const; - void ViewOptionAdjustStart( SwWrtShell &rSh, const SwViewOption &rViewOptions, bool bIsTmpSelection ); + void ViewOptionAdjustStart( SwWrtShell &rSh, const SwViewOption &rViewOptions); void ViewOptionAdjust( const SwPrtOptions *pPrtOptions ); void ViewOptionAdjustStop(); --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -600,12 +600,11 @@ { SwWrtShell & m_rShell; SwViewOption m_aOldViewOptions; - bool m_bIsTmpSelection; // SwViewOption m_aRenderViewOptions; // view options to use when rendering for PDF export or printing // bool m_bRestoreViewOptions; public: - SwViewOptionAdjust_Impl( SwWrtShell& rSh, const SwViewOption &rViewOptions, bool bIsTmpSelection ); + SwViewOptionAdjust_Impl( SwWrtShell& rSh, const SwViewOption &rViewOptions ); ~SwViewOptionAdjust_Impl(); void AdjustViewOptions( const SwPrtOptions *pPrtOptions ); --- a/sw/source/core/view/printdata.cxx +++ b/sw/source/core/view/printdata.cxx @@ -112,19 +112,28 @@ } } +SfxObjectShellLock const& SwRenderData::GetTempDocShell() const +{ + return m_xTempDocShell; +} +void SwRenderData::SetTempDocShell(SfxObjectShellLock const& xShell) +{ + m_xTempDocShell = xShell; +} + bool SwRenderData::NeedNewViewOptionAdjust( const SwWrtShell& rCompare ) const { return m_pViewOptionAdjust ? ! m_pViewOptionAdjust->checkShell( rCompare ) : true; } -void SwRenderData::ViewOptionAdjustStart( SwWrtShell &rSh, const SwViewOption &rViewOptions, bool bIsTmpSelection ) +void SwRenderData::ViewOptionAdjustStart( SwWrtShell &rSh, const SwViewOption &rViewOptions ) { if (m_pViewOptionAdjust) { DBG_ASSERT( 0, "error: there should be no ViewOptionAdjust active when calling this function" ); } - m_pViewOptionAdjust = new SwViewOptionAdjust_Impl( rSh, rViewOptions, bIsTmpSelection ); + m_pViewOptionAdjust = new SwViewOptionAdjust_Impl( rSh, rViewOptions ); } --- a/sw/source/ui/inc/view.hxx +++ b/sw/source/ui/inc/view.hxx @@ -643,8 +643,7 @@ void NotifyDBChanged(); - SfxObjectShellRef & GetTmpSelectionDoc(); - SfxObjectShellRef & GetOrCreateTmpSelectionDoc(); + SfxObjectShellLock CreateTmpSelectionDoc(); void AddTransferable(SwTransferable& rTransferable); --- a/sw/source/ui/uiview/view.cxx +++ b/sw/source/ui/uiview/view.cxx @@ -1878,21 +1878,10 @@ /*-------------------------------------------------------------------- Beschreibung: Drucken --------------------------------------------------------------------*/ -SfxObjectShellRef & SwView::GetTmpSelectionDoc() +SfxObjectShellLock SwView::CreateTmpSelectionDoc() { - return GetViewImpl()->GetTmpSelectionDoc(); -} - -SfxObjectShellRef & SwView::GetOrCreateTmpSelectionDoc() -{ - SfxObjectShellRef &rxTmpDoc = GetViewImpl()->GetTmpSelectionDoc(); - if (!rxTmpDoc.Is()) - { - SwXTextView *pImpl = GetViewImpl()->GetUNOObject_Impl(); - rxTmpDoc = pImpl->BuildTmpSelectionDoc( - GetViewImpl()->GetEmbeddedObjRef() ); - } - return rxTmpDoc; + SwXTextView *const pImpl = GetViewImpl()->GetUNOObject_Impl(); + return pImpl->BuildTmpSelectionDoc(); } void SwView::AddTransferable(SwTransferable& rTransferable) --- a/sw/source/ui/uno/unotxdoc.cxx +++ b/sw/source/ui/uno/unotxdoc.cxx @@ -2439,7 +2439,16 @@ const TypeId aSwViewTypeId = TYPE(SwView); if (rpView && rpView->IsA(aSwViewTypeId)) { - SfxObjectShellRef xDocSh(((SwView*)rpView)->GetOrCreateTmpSelectionDoc()); + OSL_ENSURE(m_pRenderData, "GetRenderDoc: no renderdata"); + if (!m_pRenderData) + return 0; + SwView *const pSwView(static_cast<SwView *>(rpView)); + SfxObjectShellLock xDocSh(m_pRenderData->GetTempDocShell()); + if (!xDocSh.Is()) + { + xDocSh = pSwView->CreateTmpSelectionDoc(); + m_pRenderData->SetTempDocShell(xDocSh); + } if (xDocSh.Is()) { pDoc = ((SwDocShell*)&xDocSh)->GetDoc(); @@ -2555,7 +2564,10 @@ if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pWrtShell ) ) m_pRenderData->ViewOptionAdjustStop(); if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust()) - m_pRenderData->ViewOptionAdjustStart( *pWrtShell, *pWrtShell->GetViewOptions(), rSelection.hasValue() ); + { + m_pRenderData->ViewOptionAdjustStart( + *pWrtShell, *pWrtShell->GetViewOptions() ); + } } m_pRenderData->SetSwPrtOptions( new SwPrtOptions( C2U( bIsPDFExport ? "PDF export" : "Printing" ) ) ); @@ -3823,21 +3835,15 @@ m_pDoc->SetModified(); } -SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl( SwWrtShell& rSh, const SwViewOption &rViewOptions, bool bIsTmpSelection ) : +SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl( SwWrtShell& rSh, const SwViewOption &rViewOptions ) : m_rShell( rSh ), - m_aOldViewOptions( rViewOptions ), - m_bIsTmpSelection( bIsTmpSelection ) + m_aOldViewOptions( rViewOptions ) { } SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl() { - //fdo#39159 don't restore original view options on a temporary document - //selection, it triggers throwing away the current view. Presumably we can - //forget about it in the temporary document case as unimportant to restore - //the original view settings - if (!m_bIsTmpSelection) - m_rShell.ApplyViewOptions( m_aOldViewOptions ); + m_rShell.ApplyViewOptions( m_aOldViewOptions ); } void SwViewOptionAdjust_Impl::AdjustViewOptions( --- a/sw/source/ui/uno/unotxvw.cxx +++ b/sw/source/ui/uno/unotxvw.cxx @@ -851,12 +851,12 @@ pDoc->SetRubyList( *rSh.GetCrsr(), aList, 0 ); } -SfxObjectShellRef SwXTextView::BuildTmpSelectionDoc( SfxObjectShellRef& /*rRef*/ ) +SfxObjectShellLock SwXTextView::BuildTmpSelectionDoc() { SwWrtShell& rOldSh = m_pView->GetWrtShell(); SfxPrinter *pPrt = rOldSh.getIDocumentDeviceAccess()->getPrinter( false ); SwDocShell* pDocSh; - SfxObjectShellRef xDocSh( pDocSh = new SwDocShell( /*pPrtDoc, */SFX_CREATE_MODE_STANDARD ) ); + SfxObjectShellLock xDocSh( pDocSh = new SwDocShell( /*pPrtDoc, */SFX_CREATE_MODE_STANDARD ) ); xDocSh->DoInitNew( 0 ); rOldSh.FillPrtDoc(pDocSh->GetDoc(), pPrt); SfxViewFrame* pDocFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 ); @@ -887,14 +887,6 @@ { OSL_ENSURE( m_pView, "view is missing" ); - // destroy temporary document with selected text that is used - // in PDF export of (multi-)selections. - if (m_pView && m_pView->GetTmpSelectionDoc().Is()) - { - m_pView->GetTmpSelectionDoc()->DoClose(); - m_pView->GetTmpSelectionDoc() = 0; - } - uno::Reference< uno::XInterface > xInt = (cppu::OWeakObject*)(SfxBaseController*)this; lang::EventObject aEvent(xInt); --- a/sw/source/ui/inc/unotxvw.hxx 2012-01-13 14:55:40.347525516 +0000 +++ b/sw/source/ui/inc/unotxvw.hxx 2012-01-13 14:56:24.179060267 +0000 @@ -154,7 +154,7 @@ void Invalidate(); // temporary document used for PDF export of selections/multi-selections - SfxObjectShellRef BuildTmpSelectionDoc( SfxObjectShellRef& ); + SfxObjectShellLock BuildTmpSelectionDoc(); }; typedef cppu::WeakImplHelper8<