diff options
author | Daniel Silva <danielfaleirosilva@gmail.com> | 2018-06-29 11:36:03 -0300 |
---|---|---|
committer | Daniel Silva <danielfaleirosilva@gmail.com> | 2018-11-29 13:02:16 -0200 |
commit | ff4896a2af1df6138e9246fe1588dfe8c3748f1a (patch) | |
tree | 73dbd9d54f1a760a14756ecb2259cadf8bc130ee /vcl/source | |
parent | 1a2ebd24e5daaefa209dea7f4b1889a8295b5794 (diff) |
Sets paper sizes listbox in print dialog
Change-Id: Iaeb50f6e854b90c1062d2ed6e3e053a6c26ea520
Reviewed-on: https://gerrit.libreoffice.org/56711
Tested-by: Jenkins
Reviewed-by: Katarina Behrens <Katarina.Behrens@cib.de>
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/gdi/print.cxx | 10 | ||||
-rw-r--r-- | vcl/source/window/printdlg.cxx | 90 |
2 files changed, 94 insertions, 6 deletions
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx index cff0450231f7..32da4f83cf34 100644 --- a/vcl/source/gdi/print.cxx +++ b/vcl/source/gdi/print.cxx @@ -1432,14 +1432,14 @@ OUString Printer::GetPaperName( Paper ePaper ) { static const int PaperIndex[] = { - PAPER_A0, PAPER_A1, PAPER_A2, PAPER_A3, PAPER_A4, PAPER_A5, + PAPER_A0, PAPER_A1, PAPER_A2, PAPER_A3, PAPER_A4, PAPER_A5, PAPER_A6, PAPER_B4_ISO, PAPER_B5_ISO, PAPER_LETTER, PAPER_LEGAL, PAPER_TABLOID, PAPER_USER, PAPER_B6_ISO, PAPER_ENV_C4, PAPER_ENV_C5, PAPER_ENV_C6, PAPER_ENV_C65, PAPER_ENV_DL, PAPER_SLIDE_DIA, PAPER_C, PAPER_D, PAPER_E, PAPER_EXECUTIVE, PAPER_FANFOLD_LEGAL_DE, PAPER_ENV_MONARCH, PAPER_ENV_PERSONAL, PAPER_ENV_9, PAPER_ENV_10, PAPER_ENV_11, PAPER_ENV_12, PAPER_KAI16, PAPER_KAI32, PAPER_KAI32BIG, PAPER_B4_JIS, PAPER_B5_JIS, PAPER_B6_JIS, - PAPER_POSTCARD_JP + PAPER_POSTCARD_JP, PAPER_DOUBLEPOSTCARD_JP }; assert(SAL_N_ELEMENTS(PaperIndex) == SAL_N_ELEMENTS(RID_STR_PAPERNAMES) && "localized paper name count wrong"); for (size_t i = 0; i < SAL_N_ELEMENTS(PaperIndex); ++i) @@ -1470,6 +1470,12 @@ const PaperInfo& Printer::GetPaperInfo( int nPaper ) const return mpInfoPrinter->m_aPaperFormats[nPaper]; } +Size Printer::GetPaperSize( int nPaper ) +{ + PaperInfo aInfo = GetPaperInfo( nPaper ); + return PixelToLogic( Size( aInfo.getWidth(), aInfo.getHeight() ) ); +} + void Printer::SetDuplexMode( DuplexMode eDuplex ) { if ( mbInPrintPage ) diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index d410e62d1261..80df9a54475d 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -564,6 +564,7 @@ PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterCo get(mpNupPagesBox, "pagespersheetbox"); get(mpNupOrientationBox, "pageorientationbox"); get(mpNupOrderTxt, "labelorder"); + get(mpPaperSizeBox, "papersizebox"); get(mpNupOrderBox, "orderbox"); get(mpPagesBtn, "pagespersheetbtn"); get(mpBrochureBtn, "brochure"); @@ -629,6 +630,9 @@ PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterCo // update the text fields for the printer updatePrinterText(); + // set paper sizes listbox + setPaperSizes(); + // setup dependencies checkControlDependencies(); @@ -679,6 +683,7 @@ PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterCo mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); + mpPaperSizeBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); // setup modify hdl mpPageEdit->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); @@ -736,6 +741,7 @@ void PrintDialog::dispose() mpSheetMarginTxt1.clear(); mpSheetMarginEdt.clear(); mpSheetMarginTxt2.clear(); + mpPaperSizeBox.clear(); mpNupOrientationBox.clear(); mpNupOrderBox.clear(); mpNupOrderWin.clear(); @@ -745,6 +751,51 @@ void PrintDialog::dispose() ModalDialog::dispose(); } +void PrintDialog::setPaperSizes() +{ + mpPaperSizeBox->Clear(); + + if ( isPrintToFile() ) + { + mpPaperSizeBox->Enable( false ); + } + else + { + VclPtr<Printer> aPrt( maPController->getPrinter() ); + mePaper = aPrt->GetPaper(); + + for (int nPaper = 0; nPaper < aPrt->GetPaperInfoCount(); nPaper++) + { + PaperInfo aInfo = aPrt->GetPaperInfo( nPaper ); + aInfo.doSloppyFit(); + Paper ePaper = aInfo.getPaper(); + + const LocaleDataWrapper& rLocWrap( GetSettings().GetLocaleDataWrapper() ); + MapUnit eUnit = MapUnit::MapMM; + int nDigits = 0; + if( rLocWrap.getMeasurementSystemEnum() == MeasurementSystem::US ) + { + eUnit = MapUnit::Map100thInch; + nDigits = 2; + } + Size aSize = aPrt->GetPaperSize( nPaper ); + Size aLogicPaperSize( LogicToLogic( aSize, MapMode( MapUnit::Map100thMM ), MapMode( eUnit ) ) ); + + OUString aWidth( rLocWrap.getNum( aLogicPaperSize.Width(), nDigits ) ); + OUString aHeight( rLocWrap.getNum( aLogicPaperSize.Height(), nDigits ) ); + OUString aUnit = eUnit == MapUnit::MapMM ? OUString("mm") : OUString("in"); + OUString aPaperName = Printer::GetPaperName( ePaper ) + " " + aWidth + aUnit + " x " + aHeight + aUnit; + + mpPaperSizeBox->InsertEntry( aPaperName ); + + if ( ePaper == mePaper ) + mpPaperSizeBox->SelectEntryPos( nPaper ); + } + + mpPaperSizeBox->Enable( true ); + } +} + void PrintDialog::updatePrinterText() { const OUString aDefPrt( Printer::GetDefaultPrinterName() ); @@ -787,7 +838,7 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) if ( !hasPreview() ) { mpPreviewWindow->setPreview( aMtf, aCurPageSize, - aPrt->GetPaperName(), + Printer::GetPaperName( mePaper ), maNoPreviewStr, aPrt->GetDPIX(), aPrt->GetDPIY(), aPrt->GetPrinterOptions().IsConvertToGreyscales() @@ -820,7 +871,7 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) } mpPreviewWindow->setPreview( aMtf, aCurPageSize, - aPrt->GetPaperName(), + Printer::GetPaperName( mePaper ), nPages > 0 ? OUString() : maNoPageStr, aPrt->GetDPIX(), aPrt->GetDPIY(), aPrt->GetPrinterOptions().IsConvertToGreyscales() @@ -1687,6 +1738,24 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void ) { maPController->setupPrinter(GetFrameWeld()); + if ( !isPrintToFile() ) + { + VclPtr<Printer> aPrt( maPController->getPrinter() ); + mePaper = aPrt->GetPaper(); + + for (int nPaper = 0; nPaper < aPrt->GetPaperInfoCount(); nPaper++ ) + { + PaperInfo aInfo = aPrt->GetPaperInfo( nPaper ); + aInfo.doSloppyFit(); + Paper ePaper = aInfo.getPaper(); + + if ( mePaper == ePaper ) + { + mpPaperSizeBox->SelectEntryPos( nPaper ); + break; + } + } + } // tdf#63905 don't use cache: page size may change preparePreview(); } @@ -1699,8 +1768,7 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) { if( &rBox == mpPrinters ) { - - if ( rBox.GetSelectedEntryPos() != 0) + if ( !isPrintToFile() ) { OUString aNewPrinter( rBox.GetSelectedEntry() ); // set new printer @@ -1709,6 +1777,7 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) // update text fields mpOKButton->SetText( maPrintText ); updatePrinterText(); + setPaperSizes(); preparePreview(); } else // print to file @@ -1717,6 +1786,7 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) ); mpOKButton->SetText( maPrintToFileText ); maPController->resetPrinterOptions( true ); + setPaperSizes(); preparePreview( true, true ); } } @@ -1730,6 +1800,18 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) mpPagesBtn->Check(); updateNupFromPages(); } + else if ( &rBox == mpPaperSizeBox ) + { + VclPtr<Printer> aPrt( maPController->getPrinter() ); + PaperInfo aInfo = aPrt->GetPaperInfo( rBox.GetSelectedEntryPos() ); + aInfo.doSloppyFit(); + mePaper = aInfo.getPaper(); + aPrt->SetPaper( mePaper ); + if ( mePaper == PAPER_USER ) + aPrt->SetPaperSizeUser( Size( aInfo.getWidth(), aInfo.getHeight() ) ); + + preparePreview(); + } } IMPL_LINK( PrintDialog, ModifyHdl, Edit&, rEdit, void ) |