diff options
author | Philipp Lohmann [pl] <Philipp.Lohmann@Oracle.COM> | 2010-11-03 17:10:14 +0100 |
---|---|---|
committer | Philipp Lohmann [pl] <Philipp.Lohmann@Oracle.COM> | 2010-11-03 17:10:14 +0100 |
commit | e8ffa7cfebb3dd1ad41f333901286a13eb450232 (patch) | |
tree | 8d2fe535503b977f750b8b62bfcdd130a44a60d7 /vcl/source | |
parent | d8138bfc18fcc2732d3ea7304b24b319268995af (diff) |
vcl117: #i115304# read printer options from configuration
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/print.cxx | 100 | ||||
-rwxr-xr-x | vcl/source/gdi/print3.cxx | 8 | ||||
-rw-r--r-- | vcl/source/window/printdlg.cxx | 31 |
3 files changed, 134 insertions, 5 deletions
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx index 2ea9bfcc4c11..cafaf5cad6eb 100644 --- a/vcl/source/gdi/print.cxx +++ b/vcl/source/gdi/print.cxx @@ -57,8 +57,14 @@ #include <comphelper/processfactory.hxx> +#include "com/sun/star/beans/XPropertySet.hpp" +#include "com/sun/star/container/XNameAccess.hpp" +#include "com/sun/star/lang/XMultiServiceFactory.hpp" + using namespace com::sun::star::uno; using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; int nImplSysDialog = 0; @@ -130,6 +136,100 @@ PrinterOptions::~PrinterOptions() { } +#define PROPERTYNAME_REDUCETRANSPARENCY rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReduceTransparency")) +#define PROPERTYNAME_REDUCEDTRANSPARENCYMODE rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedTransparencyMode")) +#define PROPERTYNAME_REDUCEGRADIENTS rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReduceGradients")) +#define PROPERTYNAME_REDUCEDGRADIENTMODE rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedGradientMode")) +#define PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedGradientStepCount")) +#define PROPERTYNAME_REDUCEBITMAPS rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReduceBitmaps")) +#define PROPERTYNAME_REDUCEDBITMAPMODE rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedBitmapMode")) +#define PROPERTYNAME_REDUCEDBITMAPRESOLUTION rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedBitmapResolution")) +#define PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ReducedBitmapIncludesTransparency")) +#define PROPERTYNAME_CONVERTTOGREYSCALES rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ConvertToGreyscales")) + +bool PrinterOptions::ReadFromConfig( bool i_bFile ) +{ + bool bSuccess = false; + // save old state in case something goes wrong + PrinterOptions aOldValues( *this ); + + // get the configuration service + Reference< XMultiServiceFactory > xConfigProvider; + Reference< XNameAccess > xConfigAccess; + try + { + // get service provider + Reference< XMultiServiceFactory > xSMgr( comphelper::getProcessServiceFactory() ); + // create configuration hierachical access name + if( xSMgr.is() ) + { + try + { + xConfigProvider = Reference< XMultiServiceFactory >( + xSMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.configuration.ConfigurationProvider" ))), + UNO_QUERY ); + if( xConfigProvider.is() ) + { + Sequence< Any > aArgs(1); + PropertyValue aVal; + aVal.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ); + if( i_bFile ) + aVal.Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Print/Option/File" ) ); + else + aVal.Value <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Print/Option/Printer" ) ); + aArgs.getArray()[0] <<= aVal; + xConfigAccess = Reference< XNameAccess >( + xConfigProvider->createInstanceWithArguments( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationAccess" )), aArgs ), + UNO_QUERY ); + if( xConfigAccess.is() ) + { + Reference< XPropertySet > xSet( xConfigAccess, UNO_QUERY ); + if( xSet.is() ) + { + sal_Int32 nValue = 0; + sal_Bool bValue = 0; + if( xSet->getPropertyValue(PROPERTYNAME_REDUCETRANSPARENCY) >>= bValue ) + SetReduceTransparency( bValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDTRANSPARENCYMODE) >>= nValue ) + SetReducedTransparencyMode( (PrinterTransparencyMode)nValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEGRADIENTS) >>= bValue ) + SetReduceGradients( bValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTMODE) >>= nValue ) + SetReducedGradientMode( (PrinterGradientMode)nValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT) >>= nValue ) + SetReducedGradientStepCount( (USHORT)nValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEBITMAPS) >>= bValue ) + SetReduceBitmaps( bValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPMODE) >>= nValue ) + SetReducedBitmapMode( (PrinterBitmapMode)nValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPRESOLUTION) >>= nValue ) + SetReducedBitmapResolution( (USHORT)nValue ); + if( xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY) >>= bValue ) + SetReducedBitmapIncludesTransparency( bValue ); + if( xSet->getPropertyValue(PROPERTYNAME_CONVERTTOGREYSCALES) >>= bValue ) + SetConvertToGreyscales( bValue ); + + bSuccess = true; + } + } + } + } + catch( Exception& ) + { + } + } + } + catch( WrappedTargetException& ) + { + } + + if( ! bSuccess ) + *this = aOldValues; + return bSuccess; +} + // ------------- // - QueueInfo - // ------------- diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx index e557a8427704..afb510b05a17 100755 --- a/vcl/source/gdi/print3.cxx +++ b/vcl/source/gdi/print3.cxx @@ -553,6 +553,7 @@ bool Printer::StartJob( const rtl::OUString& i_rJobName, boost::shared_ptr<vcl:: XubString* pPrintFile = NULL; if ( mbPrintFile ) pPrintFile = &maPrintFile; + mpPrinterOptions->ReadFromConfig( mbPrintFile ); maJobName = i_rJobName; mnCurPage = 1; @@ -733,6 +734,13 @@ void PrinterController::setPrinter( const boost::shared_ptr<Printer>& i_rPrinter mpImplData->mnFixedPaperBin = -1; } +void PrinterController:: resetPrinterOptions( bool i_bFileOutput ) +{ + PrinterOptions aOpt; + aOpt.ReadFromConfig( i_bFileOutput ); + mpImplData->mpPrinter->SetPrinterOptions( aOpt ); +} + bool PrinterController::setupPrinter( Window* i_pParent ) { bool bRet = false; diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index ec80f5628635..0641c49c27f0 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -65,6 +65,7 @@ PrintDialog::PrintPreviewWindow::PrintPreviewWindow( Window* i_pParent, const Re , maOrigSize( 10, 10 ) , maPageVDev( *this ) , maToolTipString( String( VclResId( SV_PRINT_PRINTPREVIEW_TXT ) ) ) + , mbGreyscale( false ) { SetPaintTransparent( TRUE ); SetBackground(); @@ -245,6 +246,11 @@ void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& ) maPageVDev.Erase(); maPageVDev.Push(); maPageVDev.SetMapMode( MAP_100TH_MM ); + ULONG nOldDrawMode = maPageVDev.GetDrawMode(); + if( mbGreyscale ) + maPageVDev.SetDrawMode( maPageVDev.GetDrawMode() | + ( DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_GRAYTEXT | + DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT ) ); aMtf.WindStart(); aMtf.Scale( fScale, fScale ); aMtf.WindStart(); @@ -254,6 +260,7 @@ void PrintDialog::PrintPreviewWindow::Paint( const Rectangle& ) SetMapMode( MAP_PIXEL ); maPageVDev.SetMapMode( MAP_PIXEL ); DrawOutDev( aOffset, maPreviewSize, Point( 0, 0 ), aVDevSize, maPageVDev ); + maPageVDev.SetDrawMode( nOldDrawMode ); DecorationView aVw( this ); Rectangle aFrame( aOffset + Point( -1, -1 ), Size( maPreviewSize.Width() + 2, maPreviewSize.Height() + 2 ) ); @@ -285,7 +292,8 @@ void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPrevi const Size& i_rOrigSize, const rtl::OUString& i_rReplacement, sal_Int32 i_nDPIX, - sal_Int32 i_nDPIY + sal_Int32 i_nDPIY, + bool i_bGreyscale ) { rtl::OUStringBuffer aBuf( 256 ); @@ -306,6 +314,7 @@ void PrintDialog::PrintPreviewWindow::setPreview( const GDIMetaFile& i_rNewPrevi maOrigSize = i_rOrigSize; maReplacementString = i_rReplacement; + mbGreyscale = i_bGreyscale; maPageVDev.SetReferenceDevice( i_nDPIX, i_nDPIY ); maPageVDev.EnableOutput( TRUE ); Resize(); @@ -808,9 +817,6 @@ PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterCont // init reverse print maOptionsPage.maReverseOrderBox.Check( maPController->getReversePrint() ); - // get the first page - preparePreview( true, true ); - // fill printer listbox const std::vector< rtl::OUString >& rQueues( Printer::GetPrinterQueues() ); for( std::vector< rtl::OUString >::const_iterator it = rQueues.begin(); @@ -841,6 +847,12 @@ PrintDialog::PrintDialog( Window* i_pParent, const boost::shared_ptr<PrinterCont maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( Printer::GetDefaultPrinterName() ) ) ); } } + // not printing to file + maPController->resetPrinterOptions( false ); + + // get the first page + preparePreview( true, true ); + // update the text fields for the printer updatePrinterText(); @@ -1024,6 +1036,11 @@ void PrintDialog::readFromSettings() } } maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText ); + if( maOptionsPage.maToFileBox.IsChecked() ) + { + maPController->resetPrinterOptions( true ); + preparePreview( true, true ); + } } void PrintDialog::storeToSettings() @@ -1859,7 +1876,8 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ); maPreviewWindow.setPreview( aMtf, aCurPageSize, nPages > 0 ? rtl::OUString() : maNoPageStr, - aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY() + aPrt->ImplGetDPIX(), aPrt->ImplGetDPIY(), + aPrt->GetPrinterOptions().IsConvertToGreyscales() ); maForwardBtn.Enable( mnCurPage < nPages-1 ); @@ -2046,6 +2064,7 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox*, pBox ) String aNewPrinter( pBox->GetSelectEntry() ); // set new printer maPController->setPrinter( boost::shared_ptr<Printer>( new Printer( aNewPrinter ) ) ); + maPController->resetPrinterOptions( maOptionsPage.maToFileBox.IsChecked() ); // update text fields updatePrinterText(); } @@ -2091,7 +2110,9 @@ IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton ) else if( pButton == &maOptionsPage.maToFileBox ) { maOKButton.SetText( maOptionsPage.maToFileBox.IsChecked() ? maPrintToFileText : maPrintText ); + maPController->resetPrinterOptions( maOptionsPage.maToFileBox.IsChecked() ); maLayout.resize(); + preparePreview( true, true ); } else if( pButton == &maNUpPage.maBrochureBtn ) { |