summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2015-02-19 16:39:06 +0100
committerLuboš Luňák <l.lunak@collabora.com>2015-02-26 23:55:23 +0100
commita3dae6b5b63687ed1dfde476dc826f1f3eff23ab (patch)
tree2e401a25f8d5eba1cdad8b61b2ec37fa42b120a6
parent5a6655ef9d02b9cb5d504d2df6337654c278c151 (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. 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/ui/dbui/dbmgr.cxx40
-rw-r--r--sw/source/ui/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 ad4c64cd5272..57d067d92262 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -36,6 +36,7 @@
#include <tools/errcode.hxx>
#include <vcl/jobset.hxx>
#include <vector>
+#include <boost/shared_ptr.hpp>
class SfxBaseController;
class Size;
@@ -59,6 +60,7 @@ class SfxFrameItem;
class Dialog;
class Menu;
class NotifyEvent;
+namespace vcl { class PrinterController; }
#define SFX_PRINTER_PRINTER 1 // without JOB SETUP => Temporary
#define SFX_PRINTER_JOBSETUP 2
@@ -257,6 +259,9 @@ public:
sal_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 >&, sal_Bool, sal_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 );
+ boost::shared_ptr< vcl::PrinterController > GetPrinterController() const;
void AddRemoveClipboardListener( const com::sun::star::uno::Reference < com::sun::star::datatransfer::clipboard::XClipboardListener>&, sal_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 40997dd25336..9ab73447eccc 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -373,9 +373,16 @@ public:
const JobSetup& i_rInitSetup
);
+ // 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( boost::shared_ptr<vcl::PrinterController> i_pController,
+ const JobSetup& i_rInitSetup );
+ static bool ExecutePrintJob( boost::shared_ptr<vcl::PrinterController> i_pController );
+ static void FinishPrintJob( boost::shared_ptr<vcl::PrinterController> i_pController );
+
// implementation detail of PrintJob being asynchronous
// not exported, not usable outside vcl
- static void SAL_DLLPRIVATE ImplPrintJob( const boost::shared_ptr<vcl::PrinterController>& i_pController,
+ static void SAL_DLLPRIVATE ImplPrintJob( boost::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 251dbb054d96..27b720d64a68 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -579,8 +579,10 @@ SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter )
return pDocPrinter;
}
-void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, sal_Bool bIsAPI, sal_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 );
@@ -622,7 +624,11 @@ void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rPro
SfxObjectShell *pObjShell = GetObjectShell();
pController->setValue( OUString( "JobName" ),
makeAny( OUString( pObjShell->GetTitle(0) ) ) );
+}
+void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rProps, sal_Bool bIsAPI, sal_Bool bIsDirect )
+{
+ StartPrint( rProps, bIsAPI, bIsDirect );
// FIXME: job setup
SfxPrinter* pDocPrt = GetPrinter(sal_False);
JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : GetJobSetup();
@@ -630,7 +636,12 @@ void SfxViewShell::ExecPrint( const uno::Sequence < beans::PropertyValue >& rPro
aJobSetup.SetValue( String( "IsQuickJob" ),
String( "true" ) );
- Printer::PrintJob( pController, aJobSetup );
+ Printer::PrintJob( GetPrinterController(), aJobSetup );
+}
+
+boost::shared_ptr< vcl::PrinterController > SfxViewShell::GetPrinterController() const
+{
+ return pImp->m_pPrinterController;
}
Printer* SfxViewShell::GetActivePrinter() const
diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx
index ca697eb3d65e..50cce9236861 100644
--- a/sw/source/ui/dbui/dbmgr.cxx
+++ b/sw/source/ui/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>
@@ -1253,6 +1254,41 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
rMergeDescriptor.pMailMergeConfigItem->AddMergedDocument( aMergeInfo );
}
}
+ 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
{
assert( createTempFile );
@@ -1385,6 +1421,8 @@ sal_Bool SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
if( !rMergeDescriptor.bCreateSingleFile )
{
+ if( rMergeDescriptor.nMergeType == DBMGR_MERGE_PRINTER )
+ Printer::FinishPrintJob( pWorkView->GetPrinterController());
pWorkDoc->SetNewDBMgr( pOldDBManager );
xWorkDocSh->DoClose();
}
@@ -2704,7 +2742,7 @@ void SwNewDBMgr::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/ui/uno/unomailmerge.cxx b/sw/source/ui/uno/unomailmerge.cxx
index c58e1dd7b6f0..bffd112ac9a4 100644
--- a/sw/source/ui/uno/unomailmerge.cxx
+++ b/sw/source/ui/uno/unomailmerge.cxx
@@ -718,7 +718,7 @@ uno::Any SAL_CALL SwXMailMerge::execute(
// when mail merge is called as command line macro
aMergeDesc.bPrintAsync = sal_False;
aMergeDesc.aPrintOptions = aPrintSettings;
- aMergeDesc.bCreateSingleFile = sal_True;
+ aMergeDesc.bCreateSingleFile = sal_False;
}
break;
case MailMergeType::SHELL:
diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx
index cb534c8b73b8..dc94cd4ee991 100644
--- a/vcl/source/gdi/print3.cxx
+++ b/vcl/source/gdi/print3.cxx
@@ -302,12 +302,10 @@ void Printer::PrintJob( const boost::shared_ptr<PrinterController>& i_pControlle
}
}
-void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pController,
+void Printer::PreparePrintJob( boost::shared_ptr<PrinterController> pController,
const JobSetup& i_rInitSetup
)
{
- boost::shared_ptr<PrinterController> pController( i_pController );
-
// check if there is a default printer; if not, show an error box (if appropriate)
if( GetDefaultPrinterName().isEmpty() )
{
@@ -335,7 +333,7 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
}
// reset last page property
- i_pController->setLastPage( sal_False );
+ pController->setLastPage( sal_False );
// update "PageRange" property inferring from other properties:
// case 1: "Pages" set from UNO API ->
@@ -347,12 +345,12 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
// "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
- beans::PropertyValue* pContentVal = i_pController->getValue( OUString( "PrintRange" ) );
+ beans::PropertyValue* pContentVal = pController->getValue( OUString( "PrintRange" ) );
if( ! pContentVal )
- pContentVal = i_pController->getValue( OUString( "PrintContent" ) );
+ pContentVal = pController->getValue( OUString( "PrintContent" ) );
// case 1: UNO API has set "Pages"
- beans::PropertyValue* pPagesVal = i_pController->getValue( OUString( "Pages" ) );
+ beans::PropertyValue* pPagesVal = pController->getValue( OUString( "Pages" ) );
if( pPagesVal )
{
OUString aPagesVal;
@@ -365,7 +363,7 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
if( pContentVal )
{
pContentVal->Value = makeAny( sal_Int32( 1 ) );
- i_pController->setValue( OUString( "PageRange" ), pPagesVal->Value );
+ pController->setValue( OUString( "PageRange" ), pPagesVal->Value );
}
}
}
@@ -378,13 +376,13 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
if( nContent == 0 )
{
// do not overwrite PageRange if it is already set
- beans::PropertyValue* pRangeVal = i_pController->getValue( OUString( "PageRange" ) );
+ beans::PropertyValue* pRangeVal = pController->getValue( OUString( "PageRange" ) );
OUString aRange;
if( pRangeVal )
pRangeVal->Value >>= aRange;
if( aRange.isEmpty() )
{
- sal_Int32 nPages = i_pController->getPageCount();
+ sal_Int32 nPages = pController->getPageCount();
if( nPages > 0 )
{
OUStringBuffer aBuf( 32 );
@@ -394,14 +392,14 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
aBuf.appendAscii( "-" );
aBuf.append( nPages );
}
- i_pController->setValue( OUString( "PageRange" ), makeAny( aBuf.makeStringAndClear() ) );
+ pController->setValue( OUString( "PageRange" ), makeAny( aBuf.makeStringAndClear() ) );
}
}
}
}
}
- beans::PropertyValue* pReverseVal = i_pController->getValue( OUString( "PrintReverse" ) );
+ beans::PropertyValue* pReverseVal = pController->getValue( OUString( "PrintReverse" ) );
if( pReverseVal )
{
sal_Bool bReverse = sal_False;
@@ -409,7 +407,7 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
pController->setReversePrint( bReverse );
}
- beans::PropertyValue* pPapersizeFromSetupVal = i_pController->getValue( OUString( "PapersizeFromSetup" ) );
+ beans::PropertyValue* pPapersizeFromSetupVal = pController->getValue( OUString( "PapersizeFromSetup" ) );
if( pPapersizeFromSetupVal )
{
sal_Bool bPapersizeFromSetup = sal_False;
@@ -418,35 +416,35 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
}
// setup NUp printing from properties
- sal_Int32 nRows = i_pController->getIntProperty( OUString( "NUpRows" ), 1 );
- sal_Int32 nCols = i_pController->getIntProperty( OUString( "NUpColumns" ), 1 );
+ sal_Int32 nRows = pController->getIntProperty( OUString( "NUpRows" ), 1 );
+ sal_Int32 nCols = pController->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_pController->getIntProperty( OUString( "NUpPageMarginLeft" ), aMPS.nLeftMargin );
+ sal_Int32 nValue = pController->getIntProperty( OUString( "NUpPageMarginLeft" ), aMPS.nLeftMargin );
if( nValue >= 0 )
aMPS.nLeftMargin = nValue;
- nValue = i_pController->getIntProperty( OUString( "NUpPageMarginRight" ), aMPS.nRightMargin );
+ nValue = pController->getIntProperty( OUString( "NUpPageMarginRight" ), aMPS.nRightMargin );
if( nValue >= 0 )
aMPS.nRightMargin = nValue;
- nValue = i_pController->getIntProperty( OUString( "NUpPageMarginTop" ), aMPS.nTopMargin );
+ nValue = pController->getIntProperty( OUString( "NUpPageMarginTop" ), aMPS.nTopMargin );
if( nValue >= 0 )
aMPS.nTopMargin = nValue;
- nValue = i_pController->getIntProperty( OUString( "NUpPageMarginBottom" ), aMPS.nBottomMargin );
+ nValue = pController->getIntProperty( OUString( "NUpPageMarginBottom" ), aMPS.nBottomMargin );
if( nValue >= 0 )
aMPS.nBottomMargin = nValue;
- nValue = i_pController->getIntProperty( OUString( "NUpHorizontalSpacing" ), aMPS.nHorizontalSpacing );
+ nValue = pController->getIntProperty( OUString( "NUpHorizontalSpacing" ), aMPS.nHorizontalSpacing );
if( nValue >= 0 )
aMPS.nHorizontalSpacing = nValue;
- nValue = i_pController->getIntProperty( OUString( "NUpVerticalSpacing" ), aMPS.nVerticalSpacing );
+ nValue = pController->getIntProperty( OUString( "NUpVerticalSpacing" ), aMPS.nVerticalSpacing );
if( nValue >= 0 )
aMPS.nVerticalSpacing = nValue;
- aMPS.bDrawBorder = i_pController->getBoolProperty( OUString( "NUpDrawBorder" ), aMPS.bDrawBorder );
- aMPS.nOrder = static_cast<PrinterController::NupOrderType>(i_pController->getIntProperty( OUString( "NUpSubPageOrder" ), aMPS.nOrder ));
- aMPS.aPaperSize = i_pController->getPrinter()->PixelToLogic( i_pController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
- beans::PropertyValue* pPgSizeVal = i_pController->getValue( OUString( "NUpPaperSize" ) );
+ aMPS.bDrawBorder = pController->getBoolProperty( OUString( "NUpDrawBorder" ), aMPS.bDrawBorder );
+ aMPS.nOrder = static_cast<PrinterController::NupOrderType>(pController->getIntProperty( OUString( "NUpSubPageOrder" ), aMPS.nOrder ));
+ aMPS.aPaperSize = pController->getPrinter()->PixelToLogic( pController->getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
+ beans::PropertyValue* pPgSizeVal = pController->getValue( OUString( "NUpPaperSize" ) );
awt::Size aSizeVal;
if( pPgSizeVal && (pPgSizeVal->Value >>= aSizeVal) )
{
@@ -454,7 +452,7 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
aMPS.aPaperSize.Height() = aSizeVal.Height;
}
- i_pController->setMultipage( aMPS );
+ pController->setMultipage( aMPS );
}
// in direct print case check whether there is anything to print.
@@ -478,10 +476,10 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
{
try
{
- PrintDialog aDlg( NULL, i_pController );
+ PrintDialog aDlg( NULL, pController );
if( ! aDlg.Execute() )
{
- i_pController->abortJob();
+ pController->abortJob();
return;
}
if( aDlg.isPrintToFile() )
@@ -489,7 +487,7 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
OUString aFile = queryFile( pController->getPrinter().get() );
if( aFile.isEmpty() )
{
- i_pController->abortJob();
+ pController->abortJob();
return;
}
pController->setValue( OUString( "LocalFileName" ),
@@ -507,19 +505,32 @@ void Printer::ImplPrintJob( const boost::shared_ptr<PrinterController>& i_pContr
}
pController->pushPropertiesToPrinter();
+}
+bool Printer::ExecutePrintJob(boost::shared_ptr<PrinterController> pController)
+{
OUString aJobName;
beans::PropertyValue* pJobNameVal = pController->getValue( OUString( "JobName" ) );
if( pJobNameVal )
pJobNameVal->Value >>= aJobName;
- pController->getPrinter()->StartJob( String( aJobName ), pController );
+ return pController->getPrinter()->StartJob( aJobName, pController );
+}
+void Printer::FinishPrintJob(boost::shared_ptr<PrinterController> pController)
+{
pController->resetPaperToLastConfigured();
-
pController->jobFinished( pController->getJobState() );
}
+void Printer::ImplPrintJob(boost::shared_ptr<PrinterController> xController,
+ const JobSetup& i_rInitSetup)
+{
+ PreparePrintJob( xController, i_rInitSetup );
+ ExecutePrintJob( xController );
+ FinishPrintJob( xController );
+}
+
bool Printer::StartJob( const OUString& i_rJobName, boost::shared_ptr<vcl::PrinterController>& i_pController )
{
mnError = PRINTER_OK;