summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2015-02-19 16:39:06 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-03-11 16:21:43 +0100
commite0ad036eed6b151ea81311fcf9ba46f1726b103c (patch)
tree9508f293ab9e4af6f6132dd5ac6827a35b00530f
parent1ef9952e804da953706cc514564db92a4a4a07b5 (diff)
mailmerge doesn't need to use the singlefile technique for printing
It should be sufficient for every record to just update the fields and print the document. The printing code apparently rather expects to do the printing in one go, so split the functions up there. Conflicts: include/sfx2/viewsh.hxx include/vcl/print.hxx sfx2/source/view/viewprn.cxx sw/source/uibase/dbui/dbmgr.cxx sw/source/uibase/uno/unomailmerge.cxx vcl/source/gdi/print3.cxx Change-Id: I4d17c703b3220f47609fc4b054ce048b299a0c92
-rw-r--r--include/sfx2/viewsh.hxx5
-rw-r--r--include/vcl/print.hxx9
-rw-r--r--sfx2/source/view/viewprn.cxx15
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx40
-rw-r--r--sw/source/uibase/uno/unomailmerge.cxx2
-rw-r--r--vcl/source/gdi/print3.cxx73
6 files changed, 108 insertions, 36 deletions
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 31e2d6884a13..42cea7201da8 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -35,6 +35,7 @@
#include <tools/gen.hxx>
#include <tools/errcode.hxx>
#include <vcl/jobset.hxx>
+#include <boost/shared_ptr.hpp>
class SfxBaseController;
class Size;
@@ -59,6 +60,7 @@ class Dialog;
class Menu;
class NotifyEvent;
class SfxInPlaceClient;
+namespace vcl { class PrinterController; }
#define SFX_PRINTER_PRINTER 1 // without JOB SETUP => Temporary
#define SFX_PRINTER_JOBSETUP 2
@@ -266,6 +268,9 @@ public:
bool TryContextMenuInterception( Menu& rIn, const OUString& rMenuIdentifier, Menu*& rpOut, ::com::sun::star::ui::ContextMenuExecuteEvent aEvent );
void ExecPrint( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >&, bool, bool );
+ // Like ExecPrint(), but only sets up for printing. Use Printer::ExecutePrintJob() and Printer::FinishPrintJob() afterwards.
+ void StartPrint( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >&, bool, bool );
+ std::shared_ptr< vcl::PrinterController > GetPrinterController() const;
void AddRemoveClipboardListener( const com::sun::star::uno::Reference < com::sun::star::datatransfer::clipboard::XClipboardListener>&, bool );
::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::clipboard::XClipboardNotifier > GetClipboardNotifier();
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index b0dd3f07afd3..d74976981bd8 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -405,9 +405,16 @@ public:
const Image&, sal_uInt16 ) SAL_OVERRIDE;
+ // These 3 together are more modular PrintJob(), allowing printing more documents as one print job
+ // by repeated calls to ExecutePrintJob(). Used by mailmerge.
+ static void PreparePrintJob( std::shared_ptr<vcl::PrinterController> i_pController,
+ const JobSetup& i_rInitSetup );
+ static bool ExecutePrintJob( std::shared_ptr<vcl::PrinterController> i_pController );
+ static void FinishPrintJob( std::shared_ptr<vcl::PrinterController> i_pController );
+
// implementation detail of PrintJob being asynchronous
// not exported, not usable outside vcl
- static void SAL_DLLPRIVATE ImplPrintJob( const std::shared_ptr<vcl::PrinterController>& i_pController,
+ static void SAL_DLLPRIVATE ImplPrintJob( std::shared_ptr<vcl::PrinterController> i_pController,
const JobSetup& i_rInitSetup );
};
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 0ed526d48670..21045325bc5f 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -567,8 +567,10 @@ SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter )
return pDocPrinter;
}
-void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, bool bIsAPI, bool bIsDirect )
+void SfxViewShell::StartPrint( const uno::Sequence < beans::PropertyValue >& rProps, bool bIsAPI, bool bIsDirect )
{
+ assert( pImp->m_xPrinterController.get() == NULL );
+
// get the current selection; our controller should know it
Reference< frame::XController > xController( GetController() );
Reference< view::XSelectionSupplier > xSupplier( xController, UNO_QUERY );
@@ -610,11 +612,20 @@ void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rPro
SfxObjectShell *pObjShell = GetObjectShell();
xNewController->setValue( OUString( "JobName" ),
makeAny( OUString( pObjShell->GetTitle(0) ) ) );
+}
+void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, bool bIsAPI, bool bIsDirect )
+{
+ StartPrint( rProps, bIsAPI, bIsDirect );
// FIXME: job setup
SfxPrinter* pDocPrt = GetPrinter(false);
JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : GetJobSetup();
- Printer::PrintJob( xNewController, aJobSetup );
+ Printer::PrintJob( GetPrinterController(), aJobSetup );
+}
+
+std::shared_ptr< vcl::PrinterController > SfxViewShell::GetPrinterController() const
+{
+ return pImp->m_xPrinterController;
}
Printer* SfxViewShell::GetActivePrinter() const
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index d93e85cdde2e..af65b335fa8e 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -23,6 +23,7 @@
#include <unotxdoc.hxx>
#include <com/sun/star/text/NotePrintMode.hpp>
#include <sfx2/app.hxx>
+#include <sfx2/printer.hxx>
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/sdb/XDocumentDataSource.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -1159,6 +1160,41 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
lcl_CopyFollowPageDesc( *pTargetShell, *pWorkPageDesc, *pTargetPageDesc, nDocNo );
}
}
+ else if( rMergeDescriptor.nMergeType == DBMGR_MERGE_PRINTER )
+ {
+ if( 1 == nDocNo ) // set up printing only once at the beginning
+ {
+ // printing should be done synchronously otherwise the document
+ // might already become invalid during the process
+ uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.aPrintOptions );
+
+ aOptions.realloc( 2 );
+ aOptions[ 0 ].Name = "Wait";
+ aOptions[ 0 ].Value <<= sal_True;
+ aOptions[ 1 ].Name = "MonitorVisible";
+ aOptions[ 1 ].Value <<= sal_False;
+ // move print options
+ const beans::PropertyValue* pPrintOptions = rMergeDescriptor.aPrintOptions.getConstArray();
+ for( sal_Int32 nOption = 0, nIndex = 1 ; nOption < rMergeDescriptor.aPrintOptions.getLength(); ++nOption)
+ {
+ if( pPrintOptions[nOption].Name == "CopyCount" || pPrintOptions[nOption].Name == "FileName"
+ || pPrintOptions[nOption].Name == "Collate" || pPrintOptions[nOption].Name == "Pages"
+ || pPrintOptions[nOption].Name == "Wait" || pPrintOptions[nOption].Name == "PrinterName" )
+ {
+ // add an option
+ aOptions.realloc( nIndex + 1 );
+ aOptions[ nIndex ].Name = pPrintOptions[nOption].Name;
+ aOptions[ nIndex++ ].Value = pPrintOptions[nOption].Value ;
+ }
+ }
+ pWorkView->StartPrint( aOptions, IsMergeSilent(), rMergeDescriptor.bPrintAsync );
+ SfxPrinter* pDocPrt = pWorkView->GetPrinter(false);
+ JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : pWorkView->GetJobSetup();
+ Printer::PreparePrintJob( pWorkView->GetPrinterController(), aJobSetup );
+ }
+ if( !Printer::ExecutePrintJob( pWorkView->GetPrinterController()))
+ bCancel = true;
+ }
else
pTargetPageDesc = pTargetShell->FindPageDescByName( sModifiedStartingPageDesc );
@@ -1313,6 +1349,8 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
if( !rMergeDescriptor.bCreateSingleFile )
{
+ if( rMergeDescriptor.nMergeType == DBMGR_MERGE_PRINTER )
+ Printer::FinishPrintJob( pWorkView->GetPrinterController());
pWorkDoc->SetDBManager( pOldDBManager );
xWorkDocSh->DoClose();
}
@@ -2665,7 +2703,7 @@ void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh,
SwMergeDescriptor aMergeDesc( pImpl->pMergeDialog->GetMergeType(), pView->GetWrtShell(), aDescriptor );
aMergeDesc.sSaveToFilter = pImpl->pMergeDialog->GetSaveFilter();
- aMergeDesc.bCreateSingleFile = pImpl->pMergeDialog->IsSaveSingleDoc();
+ aMergeDesc.bCreateSingleFile = pImpl->pMergeDialog->IsSaveSingleDoc() && pImpl->pMergeDialog->GetMergeType() != DBMGR_MERGE_PRINTER;
aMergeDesc.bSubjectIsFilename = aMergeDesc.bCreateSingleFile;
if( !aMergeDesc.bCreateSingleFile && pImpl->pMergeDialog->IsGenerateFromDataBase() )
{
diff --git a/sw/source/uibase/uno/unomailmerge.cxx b/sw/source/uibase/uno/unomailmerge.cxx
index 30adba6fc0f5..216a6c6f7c12 100644
--- a/sw/source/uibase/uno/unomailmerge.cxx
+++ b/sw/source/uibase/uno/unomailmerge.cxx
@@ -691,7 +691,7 @@ uno::Any SAL_CALL SwXMailMerge::execute(
// when mail merge is called as command line macro
aMergeDesc.bPrintAsync = false;
aMergeDesc.aPrintOptions = aPrintSettings;
- aMergeDesc.bCreateSingleFile = true;
+ aMergeDesc.bCreateSingleFile = false;
}
break;
case MailMergeType::SHELL:
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index bfabad1374d5..3bd9f05a359b 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -297,11 +297,9 @@ void Printer::PrintJob(const std::shared_ptr<PrinterController>& i_xController,
}
}
-void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xController,
+void Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController,
const JobSetup& i_rInitSetup)
{
- std::shared_ptr<PrinterController> xController(i_xController);
-
// check if there is a default printer; if not, show an error box (if appropriate)
if( GetDefaultPrinterName().isEmpty() )
{
@@ -328,7 +326,7 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
}
// reset last page property
- i_xController->setLastPage(false);
+ xController->setLastPage(false);
// update "PageRange" property inferring from other properties:
// case 1: "Pages" set from UNO API ->
@@ -340,12 +338,12 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
// "Pages" attribute from API is now equivalent to "PageRange"
// AND "PrintContent" = 1 except calc where it is "PrintRange" = 1
// Argh ! That sure needs cleaning up
- PropertyValue* pContentVal = i_xController->getValue(OUString("PrintRange"));
+ PropertyValue* pContentVal = xController->getValue(OUString("PrintRange"));
if( ! pContentVal )
- pContentVal = i_xController->getValue(OUString("PrintContent"));
+ pContentVal = xController->getValue(OUString("PrintContent"));
// case 1: UNO API has set "Pages"
- PropertyValue* pPagesVal = i_xController->getValue(OUString("Pages"));
+ PropertyValue* pPagesVal = xController->getValue(OUString("Pages"));
if( pPagesVal )
{
OUString aPagesVal;
@@ -358,7 +356,7 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
if( pContentVal )
{
pContentVal->Value = makeAny( sal_Int32( 1 ) );
- i_xController->setValue(OUString("PageRange"), pPagesVal->Value);
+ xController->setValue(OUString("PageRange"), pPagesVal->Value);
}
}
}
@@ -371,13 +369,13 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
if( nContent == 0 )
{
// do not overwrite PageRange if it is already set
- PropertyValue* pRangeVal = i_xController->getValue(OUString("PageRange"));
+ PropertyValue* pRangeVal = xController->getValue(OUString("PageRange"));
OUString aRange;
if( pRangeVal )
pRangeVal->Value >>= aRange;
if( aRange.isEmpty() )
{
- sal_Int32 nPages = i_xController->getPageCount();
+ sal_Int32 nPages = xController->getPageCount();
if( nPages > 0 )
{
OUStringBuffer aBuf( 32 );
@@ -387,14 +385,14 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
aBuf.appendAscii( "-" );
aBuf.append( nPages );
}
- i_xController->setValue(OUString("PageRange"), makeAny(aBuf.makeStringAndClear()));
+ xController->setValue(OUString("PageRange"), makeAny(aBuf.makeStringAndClear()));
}
}
}
}
}
- PropertyValue* pReverseVal = i_xController->getValue(OUString("PrintReverse"));
+ PropertyValue* pReverseVal = xController->getValue(OUString("PrintReverse"));
if( pReverseVal )
{
bool bReverse = false;
@@ -402,7 +400,7 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
xController->setReversePrint( bReverse );
}
- PropertyValue* pPapersizeFromSetupVal = i_xController->getValue(OUString("PapersizeFromSetup"));
+ PropertyValue* pPapersizeFromSetupVal = xController->getValue(OUString("PapersizeFromSetup"));
if( pPapersizeFromSetupVal )
{
bool bPapersizeFromSetup = false;
@@ -411,35 +409,35 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
}
// setup NUp printing from properties
- sal_Int32 nRows = i_xController->getIntProperty(OUString("NUpRows"), 1);
- sal_Int32 nCols = i_xController->getIntProperty(OUString("NUpColumns"), 1);
+ sal_Int32 nRows = xController->getIntProperty(OUString("NUpRows"), 1);
+ sal_Int32 nCols = xController->getIntProperty(OUString("NUpColumns"), 1);
if( nRows > 1 || nCols > 1 )
{
PrinterController::MultiPageSetup aMPS;
aMPS.nRows = nRows > 1 ? nRows : 1;
aMPS.nColumns = nCols > 1 ? nCols : 1;
- sal_Int32 nValue = i_xController->getIntProperty(OUString("NUpPageMarginLeft"), aMPS.nLeftMargin);
+ sal_Int32 nValue = xController->getIntProperty(OUString("NUpPageMarginLeft"), aMPS.nLeftMargin);
if( nValue >= 0 )
aMPS.nLeftMargin = nValue;
- nValue = i_xController->getIntProperty(OUString("NUpPageMarginRight"), aMPS.nRightMargin);
+ nValue = xController->getIntProperty(OUString("NUpPageMarginRight"), aMPS.nRightMargin);
if( nValue >= 0 )
aMPS.nRightMargin = nValue;
- nValue = i_xController->getIntProperty( OUString( "NUpPageMarginTop" ), aMPS.nTopMargin );
+ nValue = xController->getIntProperty( OUString( "NUpPageMarginTop" ), aMPS.nTopMargin );
if( nValue >= 0 )
aMPS.nTopMargin = nValue;
- nValue = i_xController->getIntProperty( OUString( "NUpPageMarginBottom" ), aMPS.nBottomMargin );
+ nValue = xController->getIntProperty( OUString( "NUpPageMarginBottom" ), aMPS.nBottomMargin );
if( nValue >= 0 )
aMPS.nBottomMargin = nValue;
- nValue = i_xController->getIntProperty( OUString( "NUpHorizontalSpacing" ), aMPS.nHorizontalSpacing );
+ nValue = xController->getIntProperty( OUString( "NUpHorizontalSpacing" ), aMPS.nHorizontalSpacing );
if( nValue >= 0 )
aMPS.nHorizontalSpacing = nValue;
- nValue = i_xController->getIntProperty( OUString( "NUpVerticalSpacing" ), aMPS.nVerticalSpacing );
+ nValue = xController->getIntProperty( OUString( "NUpVerticalSpacing" ), aMPS.nVerticalSpacing );
if( nValue >= 0 )
aMPS.nVerticalSpacing = nValue;
- aMPS.bDrawBorder = i_xController->getBoolProperty( OUString( "NUpDrawBorder" ), aMPS.bDrawBorder );
- aMPS.nOrder = static_cast<PrinterController::NupOrderType>(i_xController->getIntProperty( OUString( "NUpSubPageOrder" ), aMPS.nOrder ));
- aMPS.aPaperSize = i_xController->getPrinter()->PixelToLogic( i_xController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
- PropertyValue* pPgSizeVal = i_xController->getValue( OUString( "NUpPaperSize" ) );
+ aMPS.bDrawBorder = xController->getBoolProperty( OUString( "NUpDrawBorder" ), aMPS.bDrawBorder );
+ aMPS.nOrder = static_cast<PrinterController::NupOrderType>(xController->getIntProperty( OUString( "NUpSubPageOrder" ), aMPS.nOrder ));
+ aMPS.aPaperSize = xController->getPrinter()->PixelToLogic( xController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
+ PropertyValue* pPgSizeVal = xController->getValue( OUString( "NUpPaperSize" ) );
awt::Size aSizeVal;
if( pPgSizeVal && (pPgSizeVal->Value >>= aSizeVal) )
{
@@ -447,7 +445,7 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
aMPS.aPaperSize.Height() = aSizeVal.Height;
}
- i_xController->setMultipage( aMPS );
+ xController->setMultipage( aMPS );
}
// in direct print case check whether there is anything to print.
@@ -472,10 +470,10 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
{
try
{
- PrintDialog aDlg( NULL, i_xController );
+ PrintDialog aDlg( NULL, xController );
if( ! aDlg.Execute() )
{
- i_xController->abortJob();
+ xController->abortJob();
return;
}
if( aDlg.isPrintToFile() )
@@ -483,7 +481,7 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
OUString aFile = queryFile( xController->getPrinter().get() );
if( aFile.isEmpty() )
{
- i_xController->abortJob();
+ xController->abortJob();
return;
}
xController->setValue( OUString( "LocalFileName" ),
@@ -501,19 +499,32 @@ void Printer::ImplPrintJob(const std::shared_ptr<PrinterController>& i_xControll
}
xController->pushPropertiesToPrinter();
+}
+bool Printer::ExecutePrintJob(std::shared_ptr<PrinterController> xController)
+{
OUString aJobName;
PropertyValue* pJobNameVal = xController->getValue( OUString( "JobName" ) );
if( pJobNameVal )
pJobNameVal->Value >>= aJobName;
- xController->getPrinter()->StartJob( aJobName, xController );
+ return xController->getPrinter()->StartJob( aJobName, xController );
+}
+void Printer::FinishPrintJob(std::shared_ptr<PrinterController> xController)
+{
xController->resetPaperToLastConfigured();
-
xController->jobFinished( xController->getJobState() );
}
+void Printer::ImplPrintJob(std::shared_ptr<PrinterController> xController,
+ const JobSetup& i_rInitSetup)
+{
+ PreparePrintJob( xController, i_rInitSetup );
+ ExecutePrintJob( xController );
+ FinishPrintJob( xController );
+}
+
bool Printer::StartJob( const OUString& i_rJobName, std::shared_ptr<vcl::PrinterController>& i_xController)
{
mnError = PRINTER_OK;