[Libreoffice-commits] .: 6 commits - sfx2/inc sfx2/source sw/inc sw/source
Michael Stahl
mst at kemper.freedesktop.org
Fri Oct 28 08:48:31 PDT 2011
sfx2/inc/sfx2/sfxbasemodel.hxx | 3 -
sfx2/source/doc/sfxbasemodel.cxx | 25 +++-----
sw/inc/printdata.hxx | 42 ++++-----------
sw/source/core/doc/doc.cxx | 106 +++++++++-----------------------------
sw/source/core/view/printdata.cxx | 52 ++++++------------
sw/source/core/view/viewpg.cxx | 12 +---
sw/source/core/view/vprint.cxx | 51 ++++++++++--------
sw/source/ui/uno/unotxdoc.cxx | 8 --
8 files changed, 105 insertions(+), 194 deletions(-)
New commits:
commit d87d2aa40853d6119322698b26d701a4936b52a5
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Oct 28 15:30:12 2011 +0200
SwRenderData: fix regression:
It turns out that the SwDoc member of SwRenderData was not actually
leaked, but was deleted via the ViewShell member.
diff --git a/sw/inc/printdata.hxx b/sw/inc/printdata.hxx
index 5a3d83b..8d29336 100644
--- a/sw/inc/printdata.hxx
+++ b/sw/inc/printdata.hxx
@@ -254,7 +254,7 @@ public:
// PostIt relevant data
/// an array of "_SetGetExpFld *" sorted by page and line numbers
::boost::scoped_ptr<_SetGetExpFlds> m_pPostItFields;
- ::boost::scoped_ptr<SwDoc> m_pPostItDoc;
+ /// this contains a SwDoc with the post-it content
::boost::scoped_ptr<ViewShell> m_pPostItShell;
public:
@@ -262,7 +262,7 @@ public:
~SwRenderData();
- bool HasPostItData() const { return m_pPostItShell != 0 && m_pPostItDoc != 0; }
+ bool HasPostItData() const { return m_pPostItShell != 0; }
void CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev );
void DeletePostItData();
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 5975108..aef0e49 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1398,11 +1398,12 @@ void SwDoc::UpdatePagesForPrintingWithPostItData(
SET_CURR_SHELL( rData.m_pPostItShell.get() );
// clear document and move to end of it
- SwPaM aPam( rData.m_pPostItDoc->GetNodes().GetEndOfContent() );
+ SwDoc & rPostItDoc(*rData.m_pPostItShell->GetDoc());
+ SwPaM aPam(rPostItDoc.GetNodes().GetEndOfContent());
aPam.Move( fnMoveBackward, fnGoDoc );
aPam.SetMark();
aPam.Move( fnMoveForward, fnGoDoc );
- rData.m_pPostItDoc->DeleteRange( aPam );
+ rPostItDoc.DeleteRange( aPam );
const StringRangeEnumerator aRangeEnum( rData.GetPageRange(), 1, nDocPageCount, 0 );
diff --git a/sw/source/core/view/printdata.cxx b/sw/source/core/view/printdata.cxx
index 5b64ed4..3e9bd46 100644
--- a/sw/source/core/view/printdata.cxx
+++ b/sw/source/core/view/printdata.cxx
@@ -64,7 +64,6 @@ SwRenderData::SwRenderData()
SwRenderData::~SwRenderData()
{
OSL_ENSURE( !m_pPostItShell, "m_pPostItShell should already have been deleted" );
- OSL_ENSURE( !m_pPostItDoc, "m_pPostItDoc should already have been deleted" );
OSL_ENSURE( !m_pPostItFields, " should already have been deleted" );
}
@@ -74,7 +73,6 @@ void SwRenderData::CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt,
DeletePostItData();
m_pPostItFields.reset(new _SetGetExpFlds);
lcl_GetPostIts( pDoc, m_pPostItFields.get() );
- m_pPostItDoc.reset(new SwDoc);
//!! Disable spell and grammar checking in the temporary document.
//!! Otherwise the grammar checker might process it and crash if we later on
@@ -82,7 +80,7 @@ void SwRenderData::CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt,
SwViewOption aViewOpt( *pViewOpt );
aViewOpt.SetOnlineSpell( sal_False );
- m_pPostItShell.reset(new ViewShell(*m_pPostItDoc, 0, &aViewOpt, pOutDev));
+ m_pPostItShell.reset(new ViewShell(*new SwDoc, 0, &aViewOpt, pOutDev));
}
@@ -90,10 +88,10 @@ void SwRenderData::DeletePostItData()
{
if (HasPostItData())
{
- m_pPostItDoc->setPrinter( 0, false, false ); // So that the printer remains at the real DOC
+ // So that the printer remains at the real DOC
+ m_pPostItShell->GetDoc()->setPrinter( 0, false, false );
m_pPostItShell.reset();
m_pPostItFields.reset();
- m_pPostItDoc.reset();
}
}
commit 436a1a1a9a79113825b1946f9aa83303a475b00e
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Oct 28 15:01:58 2011 +0200
SwRenderData: more cleanup
diff --git a/sw/inc/printdata.hxx b/sw/inc/printdata.hxx
index dc292a4..5a3d83b 100644
--- a/sw/inc/printdata.hxx
+++ b/sw/inc/printdata.hxx
@@ -245,9 +245,9 @@ class SwRenderData
rtl::OUString m_aPageRange;
// the view options to be applied for printing
- SwViewOptionAdjust_Impl * m_pViewOptionAdjust;
+ ::boost::scoped_ptr<SwViewOptionAdjust_Impl> m_pViewOptionAdjust;
- SwPrintData * m_pPrtOptions;
+ ::boost::scoped_ptr<SwPrintData> m_pPrtOptions;
public:
@@ -273,11 +273,9 @@ public:
void ViewOptionAdjustStop();
bool HasSwPrtOptions() const { return m_pPrtOptions != 0; }
- void SetSwPrtOptions(SwPrintData *const pOpt) { m_pPrtOptions = pOpt; }
- SwPrintData const* GetSwPrtOptions() const { return m_pPrtOptions; }
- SwPrintData & GetSwPrtOptionsRef() { return *m_pPrtOptions; }
- void MakeSwPrtOptions( SwPrintData & rOptions, const SwDocShell *pDocShell,
- const SwPrintUIOptions *pOpt, const SwRenderData *pData, bool bIsPDFExport );
+ SwPrintData const* GetSwPrtOptions() const { return m_pPrtOptions.get(); }
+ void MakeSwPrtOptions( SwDocShell const*const pDocShell,
+ SwPrintUIOptions const*const pOpt, bool const bIsPDFExport );
typedef std::vector< std::pair< sal_Int32, sal_Int32 > > PagePairsVec_t;
diff --git a/sw/source/core/view/printdata.cxx b/sw/source/core/view/printdata.cxx
index 01f68cb..5b64ed4 100644
--- a/sw/source/core/view/printdata.cxx
+++ b/sw/source/core/view/printdata.cxx
@@ -58,15 +58,11 @@ using ::rtl::OUString;
SwRenderData::SwRenderData()
{
- m_pViewOptionAdjust = 0;
- m_pPrtOptions = 0;
}
SwRenderData::~SwRenderData()
{
- delete m_pViewOptionAdjust; m_pViewOptionAdjust = 0;
- delete m_pPrtOptions; m_pPrtOptions = 0;
OSL_ENSURE( !m_pPostItShell, "m_pPostItShell should already have been deleted" );
OSL_ENSURE( !m_pPostItDoc, "m_pPostItDoc should already have been deleted" );
OSL_ENSURE( !m_pPostItFields, " should already have been deleted" );
@@ -113,7 +109,8 @@ void SwRenderData::ViewOptionAdjustStart( ViewShell &rSh, const SwViewOption &rV
{
OSL_FAIL("error: there should be no ViewOptionAdjust active when calling this function" );
}
- m_pViewOptionAdjust = new SwViewOptionAdjust_Impl( rSh, rViewOptions, bIsTmpSelection );
+ m_pViewOptionAdjust.reset(
+ new SwViewOptionAdjust_Impl( rSh, rViewOptions, bIsTmpSelection ));
}
@@ -125,24 +122,21 @@ void SwRenderData::ViewOptionAdjust(SwPrintData const*const pPrtOptions)
void SwRenderData::ViewOptionAdjustStop()
{
- if (m_pViewOptionAdjust)
- {
- delete m_pViewOptionAdjust;
- m_pViewOptionAdjust = 0;
- }
+ m_pViewOptionAdjust.reset();
}
void SwRenderData::MakeSwPrtOptions(
- SwPrintData & rOptions,
- const SwDocShell *pDocShell,
- const SwPrintUIOptions *pOpt,
- const SwRenderData *pData,
- bool bIsPDFExport )
+ SwDocShell const*const pDocShell,
+ SwPrintUIOptions const*const pOpt,
+ bool const bIsPDFExport)
{
- if (!pDocShell || !pOpt || !pData)
+ if (!pDocShell || !pOpt)
return;
+ m_pPrtOptions.reset(new SwPrintData);
+ SwPrintData & rOptions(*m_pPrtOptions);
+
// get default print options
const TypeId aSwWebDocShellTypeId = TYPE(SwWebDocShell);
sal_Bool bWeb = pDocShell->IsA( aSwWebDocShellTypeId );
@@ -172,7 +166,7 @@ void SwRenderData::MakeSwPrtOptions(
//! needs to be set after MakeOptions since the assignment operation in that
//! function will destroy the pointers
rOptions.SetPrintUIOptions( pOpt );
- rOptions.SetRenderData( pData );
+ rOptions.SetRenderData( this );
}
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx
index 8948e2f..43f2400 100644
--- a/sw/source/ui/uno/unotxdoc.cxx
+++ b/sw/source/ui/uno/unotxdoc.cxx
@@ -2547,9 +2547,8 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
m_pRenderData->ViewOptionAdjustStart( *pViewShell, *pViewShell->GetViewOptions(), rSelection.hasValue() );
}
- m_pRenderData->SetSwPrtOptions( new SwPrintData );
- m_pRenderData->MakeSwPrtOptions( m_pRenderData->GetSwPrtOptionsRef(), pRenderDocShell,
- m_pPrintUIOptions, m_pRenderData, bIsPDFExport );
+ m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
+ m_pPrintUIOptions, bIsPDFExport );
if (pSwView)
{
commit 43b116147f66c9abceaae6177a2930b6266e6cad
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Oct 28 14:22:39 2011 +0200
SwRenderData: fix assertion:
apparently SwXTextDocument::getRenderCount() may be called more than once,
so make SwRenderData::CreatePostItData() stop complanining and leaking
memory.
diff --git a/sw/inc/printdata.hxx b/sw/inc/printdata.hxx
index 475cdda..dc292a4 100644
--- a/sw/inc/printdata.hxx
+++ b/sw/inc/printdata.hxx
@@ -33,6 +33,8 @@
#include <rtl/ustring.hxx>
#include <vcl/print.hxx>
+#include <boost/scoped_ptr.hpp>
+
#include <set>
#include <map>
#include <vector>
@@ -250,9 +252,10 @@ class SwRenderData
public:
// PostIt relevant data
- _SetGetExpFlds * m_pPostItFields; // an array of "_SetGetExpFld *" sorted by page and line numbers
- SwDoc * m_pPostItDoc;
- ViewShell * m_pPostItShell;
+ /// an array of "_SetGetExpFld *" sorted by page and line numbers
+ ::boost::scoped_ptr<_SetGetExpFlds> m_pPostItFields;
+ ::boost::scoped_ptr<SwDoc> m_pPostItDoc;
+ ::boost::scoped_ptr<ViewShell> m_pPostItShell;
public:
SwRenderData();
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 9b167e2..5975108 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1395,7 +1395,7 @@ void SwDoc::UpdatePagesForPrintingWithPostItData(
const sal_uInt16 nPostItCount = rData.HasPostItData() ? rData.m_pPostItFields->Count() : 0;
if (nPostItMode != POSTITS_NONE && nPostItCount > 0)
{
- SET_CURR_SHELL( rData.m_pPostItShell );
+ SET_CURR_SHELL( rData.m_pPostItShell.get() );
// clear document and move to end of it
SwPaM aPam( rData.m_pPostItDoc->GetNodes().GetEndOfContent() );
diff --git a/sw/source/core/view/printdata.cxx b/sw/source/core/view/printdata.cxx
index 497a5cb..01f68cb 100644
--- a/sw/source/core/view/printdata.cxx
+++ b/sw/source/core/view/printdata.cxx
@@ -58,10 +58,6 @@ using ::rtl::OUString;
SwRenderData::SwRenderData()
{
- m_pPostItFields = 0;
- m_pPostItDoc = 0;
- m_pPostItShell = 0;
-
m_pViewOptionAdjust = 0;
m_pPrtOptions = 0;
}
@@ -79,10 +75,10 @@ SwRenderData::~SwRenderData()
void SwRenderData::CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt, OutputDevice *pOutDev )
{
- OSL_ENSURE( !m_pPostItFields && !m_pPostItDoc && !m_pPostItShell, "some post-it data already exists" );
- m_pPostItFields = new _SetGetExpFlds;
- lcl_GetPostIts( pDoc, m_pPostItFields );
- m_pPostItDoc = new SwDoc;
+ DeletePostItData();
+ m_pPostItFields.reset(new _SetGetExpFlds);
+ lcl_GetPostIts( pDoc, m_pPostItFields.get() );
+ m_pPostItDoc.reset(new SwDoc);
//!! Disable spell and grammar checking in the temporary document.
//!! Otherwise the grammar checker might process it and crash if we later on
@@ -90,7 +86,7 @@ void SwRenderData::CreatePostItData( SwDoc *pDoc, const SwViewOption *pViewOpt,
SwViewOption aViewOpt( *pViewOpt );
aViewOpt.SetOnlineSpell( sal_False );
- m_pPostItShell = new ViewShell( *m_pPostItDoc, 0, &aViewOpt, pOutDev );
+ m_pPostItShell.reset(new ViewShell(*m_pPostItDoc, 0, &aViewOpt, pOutDev));
}
@@ -99,11 +95,9 @@ void SwRenderData::DeletePostItData()
if (HasPostItData())
{
m_pPostItDoc->setPrinter( 0, false, false ); // So that the printer remains at the real DOC
- delete m_pPostItShell;
- delete m_pPostItFields;
- m_pPostItDoc = 0;
- m_pPostItShell = 0;
- m_pPostItFields = 0;
+ m_pPostItShell.reset();
+ m_pPostItFields.reset();
+ m_pPostItDoc.reset();
}
}
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
index 4d51047..f920ac2 100644
--- a/sw/source/core/view/vprint.cxx
+++ b/sw/source/core/view/vprint.cxx
@@ -505,7 +505,7 @@ sal_Bool ViewShell::PrintOrPDFExport(
rPrintData.GetRenderData().GetValidPagesSet().count( nPage ) == 1,
"ViewShell::PrintOrPDFExport: nPage not valid" );
ViewShell *const pViewSh2 = (nPage < 0)
- ? rPrintData.GetRenderData().m_pPostItShell // post-it page
+ ? rPrintData.GetRenderData().m_pPostItShell.get()// post-it page
: pShell; // a 'regular' page, not one from the post-it doc
SwPageFrm const*const pStPage =
commit b6828ca1624d289dc8d2cb15605ade5da1a2382a
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Oct 28 13:33:42 2011 +0200
rhbz#680365: SwRenderData: do not store SwPageFrm*
Currently when printing via SwXTextDocument::getRendererCount()
two STL containers in class SwRenderData are filled with bare pointers
to page frames from the layout.
These pointers are then used by SwXTextDocument::render(), which takes
one page out of the map and prints it via this non-ref-counted pointer.
This bizarre design will not be tolerated; instead, when printing a page,
iterate over SwRootFrm::GetLower() until the requested page is found.
This is slower, i.e. O(n^2), but at least it does not crash.
diff --git a/sw/inc/printdata.hxx b/sw/inc/printdata.hxx
index 02ff7a3..475cdda 100644
--- a/sw/inc/printdata.hxx
+++ b/sw/inc/printdata.hxx
@@ -38,7 +38,6 @@
#include <vector>
#include <utility>
-class SwPageFrm;
class SwDoc;
class SwDocShell;
class ViewShell;
@@ -226,20 +225,17 @@ public:
class SwRenderData
{
// pages valid for printing (according to the current settings)
- // and their respective start frames (see getRendererCount in unotxdoc.cxx)
// This set of pages does NOT depend on the 'PageRange' that is used as a printing option!
std::set< sal_Int32 > m_aValidPages; // the set of possible pages (see StringRangeEnumerator::getRangesFromString )
- std::map< sal_Int32, const SwPageFrm * > m_aValidStartFrames; // the map of start frames for those pages
// printer paper tray to use for each of the m_aValidPages above
std::map< sal_Int32, sal_Int32 > m_aPrinterPaperTrays;
// vector of pages and their order to be printed (duplicates and any order allowed!)
// (see 'render' in unotxdoc.cxx)
+ // negative entry indicates the page to be printed is from the post-it doc
std::vector< sal_Int32 > m_aPagesToPrint;
- std::vector< const SwPageFrm * > m_aPostItStartFrames;
-
// for prospect printing: the pairs of pages to be printed together on a single prospect page.
// -1 indicates a half page to be left empty.
std::vector< std::pair< sal_Int32, sal_Int32 > > m_aPagePairs;
@@ -281,13 +277,10 @@ public:
const SwPrintUIOptions *pOpt, const SwRenderData *pData, bool bIsPDFExport );
- typedef std::map< sal_Int32, const SwPageFrm * > ValidStartFramesMap_t;
typedef std::vector< std::pair< sal_Int32, sal_Int32 > > PagePairsVec_t;
std::set< sal_Int32 > & GetValidPagesSet() { return m_aValidPages; }
const std::set< sal_Int32 > & GetValidPagesSet() const { return m_aValidPages; }
- ValidStartFramesMap_t & GetValidStartFrames() { return m_aValidStartFrames; }
- const ValidStartFramesMap_t & GetValidStartFrames() const { return m_aValidStartFrames; }
// a map for printer paper tray numbers to use for each document page
// a value of -1 for the tray means that there is no specific tray defined
@@ -300,16 +293,6 @@ public:
std::vector< sal_Int32 > & GetPagesToPrint() { return m_aPagesToPrint; }
const std::vector< sal_Int32 > & GetPagesToPrint() const { return m_aPagesToPrint; }
- // used for 'normal' printing with post-its
- // - if the map entry will be NULL then the respective page to be printed is from
- // the document. In that case use the value from GetPagesToPrint at the same index to
- // get the phys. page number to be printed, and then retrieve the start frame to use
- // from GetValidStartFrms.
- // - If the entry is not NULL it is the start frame of the page from the post-it document
- // that is to be printed
- std::vector< const SwPageFrm * > & GetPostItStartFrames() { return m_aPostItStartFrames; }
- const std::vector< const SwPageFrm * > & GetPostItStartFrames() const { return m_aPostItStartFrames; }
-
// used for prospect printing only
PagePairsVec_t & GetPagePairsForProspectPrinting() { return m_aPagePairs; }
const PagePairsVec_t & GetPagePairsForProspectPrinting() const { return m_aPagePairs; }
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 4580328..9b167e2 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1309,9 +1309,7 @@ void SwDoc::CalculatePagesForPrinting(
std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
std::set< sal_Int32 > &rValidPages = rData.GetValidPagesSet();
- std::map< sal_Int32, const SwPageFrm * > &rValidStartFrms = rData.GetValidStartFrames();
rValidPages.clear();
- rValidStartFrms.clear();
while ( pStPage )
{
const sal_Bool bRightPg = pStPage->OnRightPage();
@@ -1323,8 +1321,6 @@ void SwDoc::CalculatePagesForPrinting(
if ( bPrintEmptyPages || pStPage->Frm().Height() )
{
rValidPages.insert( nPageNo );
- rValidStartFrms[ nPageNo ] = pStPage;
-
rPrinterPaperTrays[ nPageNo ] = lcl_GetPaperBin( pStPage );
}
}
@@ -1459,104 +1455,55 @@ void SwDoc::UpdatePagesForPrintingWithPostItData(
// now add those post-it pages to the vector of pages to print
// or replace them if only post-its should be printed
- rData.GetPostItStartFrames().clear();
- if (nPostItMode == POSTITS_ENDDOC)
- {
- // set all values up to number of pages to print currently known to NULL,
- // meaning none of the pages currently in the vector is from the
- // post-it document, they are the documents pages.
- rData.GetPostItStartFrames().resize( rData.GetPagesToPrint().size() );
- }
- else if (nPostItMode == POSTITS_ONLY)
+ if (nPostItMode == POSTITS_ONLY)
{
// no document page to be printed
rData.GetPagesToPrint().clear();
}
- // now we just need to add the post-it pages to be printed to the end
- // of the vector of pages to print and keep the GetValidStartFrames
- // data conform with it
+ // now we just need to add the post-it pages to be printed to the
+ // end of the vector of pages to print
sal_Int32 nPageNum = 0;
const SwPageFrm * pPageFrm = (SwPageFrm*)rData.m_pPostItShell->GetLayout()->Lower();
while( pPageFrm && nPageNum < nPostItDocPageCount )
{
OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
++nPageNum;
- rData.GetPagesToPrint().push_back( 0 ); // a page number of 0 indicates this page is from the post-it doc
+ // negative page number indicates page is from the post-it doc
+ rData.GetPagesToPrint().push_back( -nPageNum );
OSL_ENSURE( pPageFrm, "pPageFrm is NULL!" );
- rData.GetPostItStartFrames().push_back( pPageFrm );
pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
}
OSL_ENSURE( nPageNum == nPostItDocPageCount, "unexpected number of pages" );
}
else if (nPostItMode == POSTITS_ENDPAGE)
{
- // the next step is to find all the start frames from the post-it
- // document that should be printed for a given physical page of the document
- std::map< sal_Int32, std::vector< const SwPageFrm * > > aPhysPageToPostItFrames;
-
- // ... thus, first collect all post-it doc start frames in a vector
- sal_Int32 nPostItPageNum = 0;
- std::vector< const SwPageFrm * > aAllPostItStartFrames;
- const SwPageFrm * pPageFrm = (SwPageFrm*)rData.m_pPostItShell->GetLayout()->Lower();
- while( pPageFrm && sal_Int32(aAllPostItStartFrames.size()) < nPostItDocPageCount )
- {
- OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
- ++nPostItPageNum;
- aAllPostItStartFrames.push_back( pPageFrm );
- pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
- }
- OSL_ENSURE( sal_Int32(aAllPostItStartFrames.size()) == nPostItDocPageCount,
- "unexpected number of frames; does not match number of pages" );
-
- // get a map that holds all post-it frames to be printed for a
- // given physical page from the document
- sal_Int32 nLastStartPageNum = 0;
- std::map< sal_Int32, sal_Int32 >::const_iterator aIt;
- for (aIt = aPostItLastStartPageNum.begin(); aIt != aPostItLastStartPageNum.end(); ++aIt)
- {
- const sal_Int32 nFrames = aIt->second - nLastStartPageNum;
- const sal_Int32 nFirstStartPageNum = aIt == aPostItLastStartPageNum.begin() ?
- 1 : aIt->second - nFrames + 1;
- OSL_ENSURE( 1 <= nFirstStartPageNum && nFirstStartPageNum <= nPostItDocPageCount,
- "page number for first frame out of range" );
- std::vector< const SwPageFrm * > aStartFrames;
- for (sal_Int32 i = 0; i < nFrames; ++i)
- {
- const sal_Int32 nIdx = nFirstStartPageNum - 1 + i; // -1 because lowest page num is 1
- OSL_ENSURE( 0 <= nIdx && nIdx < sal_Int32(aAllPostItStartFrames.size()),
- "index out of range" );
- aStartFrames.push_back( aAllPostItStartFrames[ nIdx ] );
- }
- aPhysPageToPostItFrames[ aIt->first /* phys page num */ ] = aStartFrames;
- nLastStartPageNum = aIt->second;
- }
-
+ // the next step is to find all the pages from the post-it
+ // document that should be printed for a given physical page
+ // of the document
- // ok, now that aPhysPageToPostItFrames can give the start frames for all
- // post-it pages to be printed we need to merge those at the correct
- // position into the GetPagesToPrint vector and build and maintain the
- // GetValidStartFrames vector as well.
- // Since inserting a larger number of entries in the middle of a vector
- // isn't that efficient we will create new vectors by copying the required data
std::vector< sal_Int32 > aTmpPagesToPrint;
- std::vector< const SwPageFrm * > aTmpPostItStartFrames;
+ sal_Int32 nLastPostItPage(0);
const size_t nNum = rData.GetPagesToPrint().size();
for (size_t i = 0 ; i < nNum; ++i)
{
// add the physical page to print from the document
const sal_Int32 nPhysPage = rData.GetPagesToPrint()[i];
aTmpPagesToPrint.push_back( nPhysPage );
- aTmpPostItStartFrames.push_back( NULL );
// add the post-it document pages to print, i.e those
// post-it pages that have the data for the above physical page
- const std::vector< const SwPageFrm * > &rPostItFrames = aPhysPageToPostItFrames[ nPhysPage ];
- const size_t nPostItFrames = rPostItFrames.size();
- for (size_t k = 0; k < nPostItFrames; ++k)
+ ::std::map<sal_Int32, sal_Int32>::const_iterator const iter(
+ aPostItLastStartPageNum.find(nPhysPage));
+ if (iter != aPostItLastStartPageNum.end())
{
- aTmpPagesToPrint.push_back( 0 );
- aTmpPostItStartFrames.push_back( rPostItFrames[k] );
+ for (sal_Int32 j = nLastPostItPage + 1;
+ j <= iter->second; ++j)
+ {
+ // negative page number indicates page is from the
+ aTmpPagesToPrint.push_back(-j); // post-it document
+ }
+ nLastPostItPage = iter->second;
}
}
@@ -1564,7 +1511,6 @@ void SwDoc::UpdatePagesForPrintingWithPostItData(
// swapping the data should be more efficient than assigning since
// we won't need the temporary vectors anymore
rData.GetPagesToPrint().swap( aTmpPagesToPrint );
- rData.GetPostItStartFrames().swap( aTmpPostItStartFrames );
}
}
}
@@ -1577,12 +1523,11 @@ void SwDoc::CalculatePagePairsForProspectPrinting(
{
std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
std::set< sal_Int32 > &rValidPagesSet = rData.GetValidPagesSet();
- std::map< sal_Int32, const SwPageFrm * > &rValidStartFrms = rData.GetValidStartFrames();
std::vector< std::pair< sal_Int32, sal_Int32 > > &rPagePairs = rData.GetPagePairsForProspectPrinting();
+ std::map< sal_Int32, const SwPageFrm * > validStartFrms;
rPagePairs.clear();
rValidPagesSet.clear();
- rValidStartFrms.clear();
rtl::OUString aPageRange;
// PageContent :
@@ -1620,7 +1565,7 @@ void SwDoc::CalculatePagePairsForProspectPrinting(
OSL_ENSURE( pPageFrm, "Empty page frame. How are we going to print this?" );
++nPageNum;
rValidPagesSet.insert( nPageNum );
- rValidStartFrms[ nPageNum ] = pPageFrm;
+ validStartFrms[ nPageNum ] = pPageFrm;
pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
rPrinterPaperTrays[ nPageNum ] = lcl_GetPaperBin( pStPage );
@@ -1649,7 +1594,7 @@ void SwDoc::CalculatePagePairsForProspectPrinting(
for ( i = 0; i < sal_Int32(aPagesToPrint.size()); ++i)
{
const sal_Int32 nPage = aPagesToPrint[i];
- const SwPageFrm *pFrm = rValidStartFrms[ nPage ];
+ const SwPageFrm *pFrm = validStartFrms[ nPage ];
aVec.push_back( pFrm );
}
diff --git a/sw/source/core/view/viewpg.cxx b/sw/source/core/view/viewpg.cxx
index 3047a18..d3f4105 100644
--- a/sw/source/core/view/viewpg.cxx
+++ b/sw/source/core/view/viewpg.cxx
@@ -59,6 +59,9 @@
using namespace ::com::sun::star;
+SwPageFrm const*
+lcl_getPage(SwRootFrm const& rLayout, sal_Int32 const nPage); // vprint.cxx
+
SwPagePreviewLayout* ViewShell::PagePreviewLayout()
{
return Imp()->PagePreviewLayout();
@@ -125,18 +128,13 @@ void ViewShell::PrintProspect(
const SwPageFrm *pStPage = 0;
const SwPageFrm *pNxtPage = 0;
- const SwRenderData::ValidStartFramesMap_t &rFrms = rPrintData.GetRenderData().GetValidStartFrames();
if (rPagesToPrint.first > 0)
{
- SwRenderData::ValidStartFramesMap_t::const_iterator aIt( rFrms.find( rPagesToPrint.first ) );
- OSL_ENSURE( aIt != rFrms.end(), "failed to find start frame" );
- pStPage = aIt->second;
+ pStPage = lcl_getPage(*aShell.GetLayout(), rPagesToPrint.first);
}
if (rPagesToPrint.second > 0)
{
- SwRenderData::ValidStartFramesMap_t::const_iterator aIt( rFrms.find( rPagesToPrint.second ) );
- OSL_ENSURE( aIt != rFrms.end(), "failed to find start frame" );
- pNxtPage = aIt->second;
+ pNxtPage = lcl_getPage(*aShell.GetLayout(), rPagesToPrint.second);
}
//#i14016# - consider empty pages on calculation of page size, used for calculation of scaling.
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
index 465e6b5..4d51047 100644
--- a/sw/source/core/view/vprint.cxx
+++ b/sw/source/core/view/vprint.cxx
@@ -437,6 +437,24 @@ SwDoc * ViewShell::FillPrtDoc( SwDoc *pPrtDoc, const SfxPrinter* pPrt)
return pPrtDoc;
}
+// TODO: there is already a GetPageByPageNum, but it checks some physical page
+// number; unsure if we want that here, should find out what that is...
+SwPageFrm const*
+lcl_getPage(SwRootFrm const& rLayout, sal_Int32 const nPage)
+{
+ // yes this is O(n^2) but at least it does not crash...
+ SwPageFrm const* pPage = dynamic_cast<const SwPageFrm*>(rLayout.Lower());
+ for (sal_Int32 i = nPage; pPage && (i > 0); --i)
+ {
+ if (1 == i) { // note: nPage is 1-based, i.e. 0 is invalid!
+ return pPage;
+ }
+ pPage = dynamic_cast<SwPageFrm const*>(pPage->GetNext());
+ }
+ OSL_ENSURE(pPage, "ERROR: SwPageFrm expected");
+ OSL_FAIL("non-existent page requested");
+ return 0;
+}
sal_Bool ViewShell::PrintOrPDFExport(
OutputDevice *pOutDev,
@@ -483,30 +501,23 @@ sal_Bool ViewShell::PrintOrPDFExport(
pShell->PrepareForPrint( rPrintData );
const sal_Int32 nPage = rPrintData.GetRenderData().GetPagesToPrint()[ nRenderer ];
-#if OSL_DEBUG_LEVEL > 1
- OSL_ENSURE( nPage == 0 || rPrintData.GetRenderData().GetValidPagesSet().count( nPage ) == 1, "nPage not valid" );
-#endif
- const SwPageFrm *pStPage = 0;
- if (nPage > 0) // a 'regular' page, not one from the post-it document
- {
- const SwRenderData::ValidStartFramesMap_t &rFrms = rPrintData.GetRenderData().GetValidStartFrames();
- SwRenderData::ValidStartFramesMap_t::const_iterator aIt( rFrms.find( nPage ) );
- OSL_ENSURE( aIt != rFrms.end(), "failed to find start frame" );
- if (aIt == rFrms.end())
- return sal_False;
- pStPage = aIt->second;
- }
- else // a page from the post-its document ...
+ OSL_ENSURE( nPage < 0 ||
+ rPrintData.GetRenderData().GetValidPagesSet().count( nPage ) == 1,
+ "ViewShell::PrintOrPDFExport: nPage not valid" );
+ ViewShell *const pViewSh2 = (nPage < 0)
+ ? rPrintData.GetRenderData().m_pPostItShell // post-it page
+ : pShell; // a 'regular' page, not one from the post-it doc
+
+ SwPageFrm const*const pStPage =
+ lcl_getPage(*pViewSh2->GetLayout(), abs(nPage));
+ OSL_ENSURE( pStPage, "failed to get start page" );
+ if (!pStPage)
{
- OSL_ENSURE( nPage == 0, "unexpected page number. 0 for post-it pages expected" );
- pStPage = rPrintData.GetRenderData().GetPostItStartFrames()[ nRenderer ];
+ return sal_False;
}
- OSL_ENSURE( pStPage, "failed to get start page" );
//!! applying view options and formatting the dcoument should now only be done in getRendererCount!
- ViewShell *pViewSh2 = nPage == 0 ? /* post-it page? */
- rPrintData.GetRenderData().m_pPostItShell : pShell;
::SetSwVisArea( pViewSh2, pStPage->Frm() );
// FIXME disabled because rPrintData.aOffset is always (0,0)
@@ -523,8 +534,6 @@ sal_Bool ViewShell::PrintOrPDFExport(
pShell->InitPrt( pOutDev );
- pViewSh2 = nPage == 0 ? /* post-it page? */
- rPrintData.GetRenderData().m_pPostItShell : pShell;
::SetSwVisArea( pViewSh2, pStPage->Frm() );
pStPage->GetUpper()->Paint( pStPage->Frm(), &rPrintData );
commit 96be522e795d88134e010035bc63d625564ddbea
Author: Michael Stahl <mstahl at redhat.com>
Date: Wed Oct 26 17:33:05 2011 +0200
remove pointless SfxBaseModel::setDocumentProperties()
diff --git a/sfx2/inc/sfx2/sfxbasemodel.hxx b/sfx2/inc/sfx2/sfxbasemodel.hxx
index e3c773a..0a15156 100644
--- a/sfx2/inc/sfx2/sfxbasemodel.hxx
+++ b/sfx2/inc/sfx2/sfxbasemodel.hxx
@@ -1512,7 +1512,6 @@ protected:
/* returns true if the document signatures are valid, otherwise false */
sal_Bool hasValidSignatures() const;
- void setDocumentProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties >& );
//________________________________________________________________________________________________________
// private methods
//________________________________________________________________________________________________________
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 36f6184..f44d4ba 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -910,16 +910,6 @@ IMPL_SfxBaseModel_DataContainer::impl_setDocumentProperties(
xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pObjectShell));
}
-void
-SfxBaseModel::setDocumentProperties( const uno::Reference< document::XDocumentProperties >& rxNewDocProps )
-{
- // object already disposed?
- ::SolarMutexGuard aGuard;
- if ( impl_isDisposed() )
- throw lang::DisposedException();
- m_pData->impl_setDocumentProperties(rxNewDocProps);
-}
-
// document::XDocumentPropertiesSupplier:
uno::Reference< document::XDocumentProperties > SAL_CALL
SfxBaseModel::getDocumentProperties()
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx
index 045965d..8948e2f 100644
--- a/sw/source/ui/uno/unotxdoc.cxx
+++ b/sw/source/ui/uno/unotxdoc.cxx
@@ -384,9 +384,6 @@ SwXTextDocument::SwXTextDocument(SwDocShell* pShell) :
m_pPrintUIOptions( NULL ),
m_pRenderData( NULL )
{
- uno::Reference< document::XDocumentProperties > xWriterProps( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.writer.DocumentProperties") ), uno::UNO_QUERY_THROW);
-
- SfxBaseModel::setDocumentProperties( xWriterProps );
}
SwXTextDocument::~SwXTextDocument()
commit c9e2f8ff5d19d746a2f2403465c7f9d7e480e166
Author: Michael Stahl <mstahl at redhat.com>
Date: Tue Oct 25 13:52:04 2011 +0200
SfxBaseModel impl_setDocumentProperties to impl class
diff --git a/sfx2/inc/sfx2/sfxbasemodel.hxx b/sfx2/inc/sfx2/sfxbasemodel.hxx
index 7855708..e3c773a 100644
--- a/sfx2/inc/sfx2/sfxbasemodel.hxx
+++ b/sfx2/inc/sfx2/sfxbasemodel.hxx
@@ -1503,8 +1503,6 @@ public:
/** returns true if someone added a XEventListener to this XEventBroadcaster */
sal_Bool hasEventListeners() const;
- void impl_setDocumentProperties( const ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties >& );
-
protected:
/* returns a unique id for the model that is valid as long as the document
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index cbd04f2..36f6184 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -273,6 +273,9 @@ struct IMPL_SfxBaseModel_DataContainer : public ::sfx2::IModifiableDocument
m_pObjectShell->SetModified( sal_True );
}
+ void impl_setDocumentProperties(
+ const uno::Reference< document::XDocumentProperties >& );
+
uno::Reference<rdf::XDocumentMetadataAccess> GetDMA()
{
if (!m_xDocumentMetadata.is())
@@ -898,11 +901,13 @@ uno::Reference< document::XDocumentInfo > SAL_CALL SfxBaseModel::getDocumentInfo
}
void
-SfxBaseModel::impl_setDocumentProperties( const uno::Reference< document::XDocumentProperties >& rxNewDocProps )
+IMPL_SfxBaseModel_DataContainer::impl_setDocumentProperties(
+ const uno::Reference< document::XDocumentProperties >& rxNewDocProps)
{
- m_pData->m_xDocumentProperties.set(rxNewDocProps, uno::UNO_QUERY_THROW);
- uno::Reference<util::XModifyBroadcaster> xMB(m_pData->m_xDocumentProperties, uno::UNO_QUERY_THROW);
- xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pData->m_pObjectShell));
+ m_xDocumentProperties.set(rxNewDocProps, uno::UNO_QUERY_THROW);
+ uno::Reference<util::XModifyBroadcaster> const xMB(m_xDocumentProperties,
+ uno::UNO_QUERY_THROW);
+ xMB->addModifyListener(new SfxDocInfoListener_Impl(*m_pObjectShell));
}
void
@@ -912,7 +917,7 @@ SfxBaseModel::setDocumentProperties( const uno::Reference< document::XDocumentPr
::SolarMutexGuard aGuard;
if ( impl_isDisposed() )
throw lang::DisposedException();
- impl_setDocumentProperties(rxNewDocProps);
+ m_pData->impl_setDocumentProperties(rxNewDocProps);
}
// document::XDocumentPropertiesSupplier:
@@ -927,7 +932,7 @@ SfxBaseModel::getDocumentProperties()
::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.document.DocumentProperties") ),
uno::UNO_QUERY_THROW);
- impl_setDocumentProperties(xDocProps);
+ m_pData->impl_setDocumentProperties(xDocProps);
}
return m_pData->m_xDocumentProperties;
More information about the Libreoffice-commits
mailing list