vcl/inc/printdlg.hxx | 208 +--- vcl/source/gdi/print3.cxx | 11 vcl/source/window/printdlg.cxx | 1562 +++++++----------------------- vcl/uiconfig/ui/printdialog.ui | 2069 +++++++++++++++-------------------------- 4 files changed, 1225 insertions(+), 2625 deletions(-)
New commits: commit 1d5edc87667625d8b97c7cc9f59cbd2c8c96fe36 Author: Daniel <danielfaleirosi...@gmail.com> Date: Sat Jun 2 19:40:52 2018 -0300 New Print Dialog Design Change-Id: Ib92a16ccfab70b84ffea07970a694800ecc16d07 Reviewed-on: https://gerrit.libreoffice.org/55237 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Daniel Silva <danielfaleirosi...@gmail.com> diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx index 0a5b09fd366a..03e01b840003 100644 --- a/vcl/inc/printdlg.hxx +++ b/vcl/inc/printdlg.hxx @@ -17,8 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#ifndef INCLUDED_VCL_INC_PRINTDLG_HXX -#define INCLUDED_VCL_INC_PRINTDLG_HXX +#ifndef VCL_INC_NEWPRINTDLG_HXX +#define VCL_INC_NEWPRINTDLG_HXX #include <vcl/dllapi.h> @@ -91,168 +91,106 @@ namespace vcl } }; - private: - - class NUpTabPage - { - public: - VclPtr<RadioButton> mpPagesBtn; - VclPtr<RadioButton> mpBrochureBtn; - VclPtr<FixedText> mpPagesBoxTitleTxt; - VclPtr<ListBox> mpNupPagesBox; - - // controls for "Custom" page mode - VclPtr<FixedText> mpNupNumPagesTxt; - VclPtr<NumericField> mpNupColEdt; - VclPtr<FixedText> mpNupTimesTxt; - VclPtr<NumericField> mpNupRowsEdt; - VclPtr<FixedText> mpPageMarginTxt1; - VclPtr<MetricField> mpPageMarginEdt; - VclPtr<FixedText> mpPageMarginTxt2; - VclPtr<FixedText> mpSheetMarginTxt1; - VclPtr<MetricField> mpSheetMarginEdt; - VclPtr<FixedText> mpSheetMarginTxt2; - VclPtr<FixedText> mpNupOrientationTxt; - VclPtr<ListBox> mpNupOrientationBox; - - // page order ("left to right, then down") - VclPtr<FixedText> mpNupOrderTxt; - VclPtr<ListBox> mpNupOrderBox; - VclPtr<ShowNupOrderWindow> mpNupOrderWin; - /// border around each page - VclPtr<CheckBox> mpBorderCB; - - NUpTabPage( VclBuilder* ); - - void initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& ); - void enableNupControls( bool bEnable ); - - void showAdvancedControls( bool ); - }; - - class JobTabPage - { - public: - VclPtr<ListBox> mpPrinters; - VclPtr<FixedText> mpStatusTxt; - VclPtr<FixedText> mpLocationTxt; - VclPtr<FixedText> mpCommentTxt; - - VclPtr<PushButton> mpSetupButton; - - VclPtr<NumericField> mpCopyCountField; - VclPtr<CheckBox> mpCollateBox; - VclPtr<FixedImage> mpCollateImage; - VclPtr<CheckBox> mpReverseOrderBox; - - BitmapEx maCollateBmp; - BitmapEx maNoCollateBmp; - - long mnCollateUIMode; - - JobTabPage( VclBuilder* ); - - void readFromSettings(); - void storeToSettings(); - }; - - class OutputOptPage - { - public: - VclPtr<CheckBox> mpCollateSingleJobsBox; - VclPtr<CheckBox> mpPapersizeFromSetup; + PrintDialog( vcl::Window*, const std::shared_ptr< PrinterController >& ); + virtual ~PrintDialog() override; + virtual void dispose() override; - OutputOptPage( VclBuilder* ); + bool isPrintToFile(); + bool isCollate(); + bool hasPreview(); - void readFromSettings(); - void storeToSettings(); - }; + void previewForward(); + void previewBackward(); - std::unique_ptr<VclBuilder> mpCustomOptionsUIBuilder; + private: std::shared_ptr<PrinterController> maPController; - VclPtr<TabControl> mpTabCtrl; - NUpTabPage maNUpPage; - JobTabPage maJobPage; - OutputOptPage maOptionsPage; - VclPtr<PrintPreviewWindow> mpPreviewWindow; - VclPtr<NumericField> mpPageEdit; - VclPtr<FixedText> mpNumPagesText; - VclPtr<PushButton> mpBackwardBtn; - VclPtr<PushButton> mpForwardBtn; - VclPtr<CheckBox> mpPreviewBox; + VclPtr<TabControl> mpTabCtrl; + VclPtr<ListBox> mpPrinters; + VclPtr<FixedText> mpStatusTxt; + VclPtr<PushButton> mpSetupButton; + OUString maPrintToFileText; + OUString maPrintText; + OUString maDefPrtText; + + VclPtr<NumericField> mpCopyCountField; + VclPtr<CheckBox> mpCollateBox; + VclPtr<FixedImage> mpCollateImage; + VclPtr<CheckBox> mpReverseOrderBox; VclPtr<OKButton> mpOKButton; VclPtr<CancelButton> mpCancelButton; VclPtr<HelpButton> mpHelpButton; + VclPtr<PushButton> mpBackwardBtn; + VclPtr<PushButton> mpForwardBtn; + VclPtr<CheckBox> mpPreviewBox; + VclPtr<FixedText> mpNumPagesText; + VclPtr<PrintPreviewWindow> mpPreviewWindow; + VclPtr<NumericField> mpPageEdit; + OUString maPageStr; OUString maNoPageStr; OUString maNoPreviewStr; sal_Int32 mnCurPage; sal_Int32 mnCachedPages; + BitmapEx maCollateBmp; + BitmapEx maNoCollateBmp; + + long mnCollateUIMode; + + VclPtr<RadioButton> mpPagesBtn; + VclPtr<RadioButton> mpBrochureBtn; + VclPtr<FixedText> mpPagesBoxTitleTxt; + VclPtr<ListBox> mpNupPagesBox; + + // controls for "Custom" page mode + VclPtr<FixedText> mpNupNumPagesTxt; + VclPtr<NumericField> mpNupColEdt; + VclPtr<FixedText> mpNupTimesTxt; + VclPtr<NumericField> mpNupRowsEdt; + VclPtr<FixedText> mpPageMarginTxt1; + VclPtr<MetricField> mpPageMarginEdt; + VclPtr<FixedText> mpPageMarginTxt2; + VclPtr<FixedText> mpSheetMarginTxt1; + VclPtr<MetricField> mpSheetMarginEdt; + VclPtr<FixedText> mpSheetMarginTxt2; + VclPtr<ListBox> mpNupOrientationBox; + + // page order ("left to right, then down") + VclPtr<ListBox> mpNupOrderBox; + VclPtr<ShowNupOrderWindow> mpNupOrderWin; + /// border around each page + VclPtr<CheckBox> mpBorderCB; + std::map< VclPtr<vcl::Window>, OUString > maControlToPropertyMap; - std::map< OUString, std::vector< VclPtr<vcl::Window> > > - maPropertyToWindowMap; - std::map< VclPtr<vcl::Window>, sal_Int32 > maControlToNumValMap; - std::set< OUString > maReverseDependencySet; Size maNupPortraitSize; Size maNupLandscapeSize; - /// internal, used for automatic Nup-Portrait/landscape Size maFirstPageSize; - OUString maPrintToFileText; - OUString maPrintText; - OUString maDefPrtText; + DECL_LINK( ClickHdl, Button*, void ); + DECL_LINK( SelectHdl, ListBox&, void ); + DECL_LINK( ModifyHdl, Edit&, void ); + DECL_LINK( ToggleHdl, CheckBox&, void ); + DECL_LINK( ToggleRadioHdl, RadioButton&, void ); - bool mbShowLayoutPage; + css::beans::PropertyValue* getValueForWindow( vcl::Window* ) const; - Size const & getJobPageSize(); - void updateNup(); - void updateNupFromPages(); void preparePreview( bool i_bPrintChanged = true, bool i_bMayUseCache = false ); void setPreviewText(); void updatePrinterText(); void checkControlDependencies(); - void checkOptionalControlDependencies(); - void makeEnabled( vcl::Window* ); - void updateWindowFromProperty( const OUString& ); - void setupOptionalUI(); - void readFromSettings(); - void storeToSettings(); - css::beans::PropertyValue* getValueForWindow( vcl::Window* ) const; - - virtual void Resize() override; - virtual void Command( const CommandEvent& ) override; - virtual void DataChanged( const DataChangedEvent& ) override; - - DECL_LINK( SelectHdl, ListBox&, void ); - DECL_LINK( ClickHdl, Button*, void ); - DECL_LINK( ToggleHdl, CheckBox&, void ); - DECL_LINK( ToggleRadioHdl, RadioButton&, void ); - DECL_LINK( ModifyHdl, Edit&, void ); - - DECL_LINK( UIOption_CheckHdl, CheckBox&, void ); - DECL_LINK( UIOption_RadioHdl, RadioButton&, void ); - DECL_LINK( UIOption_SelectHdl, ListBox&, void ); - DECL_LINK( UIOption_ModifyHdl, Edit&, void ); - - public: - PrintDialog( vcl::Window*, const std::shared_ptr< PrinterController >& ); - virtual ~PrintDialog() override; - virtual void dispose() override; - - bool isPrintToFile(); - bool isCollate(); - bool isSingleJobs(); - bool hasPreview(); + void initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& ); + void showAdvancedControls( bool ); + void updateNup(); + void updateNupFromPages(); + void enableNupControls( bool bEnable ); + Size const & getJobPageSize(); - void previewForward(); - void previewBackward(); }; class PrintProgressDialog : public ModelessDialog @@ -279,6 +217,4 @@ namespace vcl }; } -#endif // INCLUDED_VCL_INC_PRINTDLG_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ +#endif // VCL_INC_NEWPRINTDLG_HXX diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx index 544e07ce02d4..599965f479f5 100644 --- a/vcl/source/gdi/print3.cxx +++ b/vcl/source/gdi/print3.cxx @@ -491,11 +491,12 @@ bool Printer::PreparePrintJob(std::shared_ptr<PrinterController> xController, xController->setValue( "LocalFileName", css::uno::makeAny( aFile ) ); } - else if( aDlg->isSingleJobs() ) - { - xController->setValue( "PrintCollateAsSingleJobs", - css::uno::makeAny( true ) ); - } + // FIXME: single jobs is not implemented yet. + // else if( aDlg->isSingleJobs() ) + // { + // xController->setValue( "PrintCollateAsSingleJobs", + // css::uno::makeAny( true ) ); + // } } catch (const std::bad_alloc&) { diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index e59694ca8c0f..06f3ed8470f0 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -54,6 +54,12 @@ using namespace com::sun::star::lang; using namespace com::sun::star::container; using namespace com::sun::star::beans; +enum +{ + SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT, + SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE +}; + extern "C" SAL_DLLPUBLIC_EXPORT void makePrintPreviewWindow(VclPtr<vcl::Window> & rRet, VclPtr<vcl::Window> & pParent, VclBuilder::stringmap &) { rRet = VclPtr<PrintDialog::PrintPreviewWindow>::Create(pParent); @@ -64,6 +70,13 @@ extern "C" SAL_DLLPUBLIC_EXPORT void makeShowNupOrderWindow(VclPtr<vcl::Window> rRet = VclPtr<PrintDialog::ShowNupOrderWindow>::Create(pParent); } +namespace { + bool lcl_ListBoxCompare( const OUString& rStr1, const OUString& rStr2 ) + { + return ListBox::NaturalSortCompare( rStr1, rStr2 ) < 0; + } +} + PrintDialog::PrintPreviewWindow::PrintPreviewWindow( vcl::Window* i_pParent ) : Window( i_pParent, 0 ) , maMtf() @@ -453,210 +466,36 @@ void PrintDialog::ShowNupOrderWindow::Paint(vcl::RenderContext& rRenderContext, aDecorationView.DrawFrame(tools::Rectangle(Point(0, 0), aOutSize), DrawFrameStyle::Group); } -PrintDialog::NUpTabPage::NUpTabPage( VclBuilder *pUIBuilder ) -{ - pUIBuilder->get(mpPagesBtn, "pagespersheetbtn"); - pUIBuilder->get(mpBrochureBtn, "brochure"); - pUIBuilder->get(mpPagesBoxTitleTxt, "pagespersheettxt"); - pUIBuilder->get(mpNupPagesBox, "paperspersheetlb"); - pUIBuilder->get(mpNupNumPagesTxt, "pagestxt"); - pUIBuilder->get(mpNupColEdt, "pagecols"); - pUIBuilder->get(mpNupTimesTxt, "by"); - pUIBuilder->get(mpNupRowsEdt, "pagerows"); - pUIBuilder->get(mpPageMarginTxt1, "pagemargintxt1"); - pUIBuilder->get(mpPageMarginEdt, "pagemarginsb"); - pUIBuilder->get(mpPageMarginTxt2, "pagemargintxt2"); - pUIBuilder->get(mpSheetMarginTxt1, "sheetmargintxt1"); - pUIBuilder->get(mpSheetMarginEdt, "sheetmarginsb"); - pUIBuilder->get(mpSheetMarginTxt2, "sheetmargintxt2"); - pUIBuilder->get(mpNupOrientationTxt, "orientationtxt"); - pUIBuilder->get(mpNupOrientationBox, "orientationlb"); - pUIBuilder->get(mpNupOrderTxt, "ordertxt"); - pUIBuilder->get(mpNupOrderBox, "orderlb"); - pUIBuilder->get(mpNupOrderWin, "orderpreview"); - pUIBuilder->get(mpBorderCB, "bordercb"); -} - -void PrintDialog::NUpTabPage::enableNupControls( bool bEnable ) -{ - mpNupPagesBox->Enable( bEnable ); - mpNupNumPagesTxt->Enable( bEnable ); - mpNupColEdt->Enable( bEnable ); - mpNupTimesTxt->Enable( bEnable ); - mpNupRowsEdt->Enable( bEnable ); - mpPageMarginTxt1->Enable( bEnable ); - mpPageMarginEdt->Enable( bEnable ); - mpPageMarginTxt2->Enable( bEnable ); - mpSheetMarginTxt1->Enable( bEnable ); - mpSheetMarginEdt->Enable( bEnable ); - mpSheetMarginTxt2->Enable( bEnable ); - mpNupOrientationTxt->Enable( bEnable ); - mpNupOrientationBox->Enable( bEnable ); - mpNupOrderTxt->Enable( bEnable ); - mpNupOrderBox->Enable( bEnable ); - mpNupOrderWin->Enable( bEnable ); - mpBorderCB->Enable( bEnable ); -} - -void PrintDialog::NUpTabPage::showAdvancedControls( bool i_bShow ) -{ - mpNupNumPagesTxt->Show( i_bShow ); - mpNupColEdt->Show( i_bShow ); - mpNupTimesTxt->Show( i_bShow ); - mpNupRowsEdt->Show( i_bShow ); - mpPageMarginTxt1->Show( i_bShow ); - mpPageMarginEdt->Show( i_bShow ); - mpPageMarginTxt2->Show( i_bShow ); - mpSheetMarginTxt1->Show( i_bShow ); - mpSheetMarginEdt->Show( i_bShow ); - mpSheetMarginTxt2->Show( i_bShow ); - mpNupOrientationTxt->Show( i_bShow ); - mpNupOrientationBox->Show( i_bShow ); -} - -void PrintDialog::NUpTabPage::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS ) -{ - mpNupOrderWin->Show(); - mpPagesBtn->Check(); - mpBrochureBtn->Show( false ); - - // setup field units for metric fields - const LocaleDataWrapper& rLocWrap( mpPageMarginEdt->GetLocaleDataWrapper() ); - FieldUnit eUnit = FUNIT_MM; - sal_uInt16 nDigits = 0; - if( rLocWrap.getMeasurementSystemEnum() == MeasurementSystem::US ) - { - eUnit = FUNIT_INCH; - nDigits = 2; - } - // set units - mpPageMarginEdt->SetUnit( eUnit ); - mpSheetMarginEdt->SetUnit( eUnit ); - - // set precision - mpPageMarginEdt->SetDecimalDigits( nDigits ); - mpSheetMarginEdt->SetDecimalDigits( nDigits ); - - mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM ); - mpPageMarginEdt->SetValue( mpPageMarginEdt->Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM ); - mpBorderCB->Check( i_rMPS.bDrawBorder ); - mpNupRowsEdt->SetValue( i_rMPS.nRows ); - mpNupColEdt->SetValue( i_rMPS.nColumns ); - mpNupOrderBox->SelectEntryPos( static_cast<sal_Int32>(i_rMPS.nOrder) ); - if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 ) - { - mpNupPagesBox->SelectEntryPos( mpNupPagesBox->GetEntryCount()-1 ); - showAdvancedControls( true ); - mpNupOrderWin->setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows ); - } -} - -PrintDialog::JobTabPage::JobTabPage( VclBuilder* pUIBuilder ) - : maCollateBmp(SV_PRINT_COLLATE_BMP) - , maNoCollateBmp(SV_PRINT_NOCOLLATE_BMP) - , mnCollateUIMode(0) -{ - pUIBuilder->get(mpPrinters, "printers"); - pUIBuilder->get(mpStatusTxt, "status"); - pUIBuilder->get(mpLocationTxt, "location"); - pUIBuilder->get(mpCommentTxt, "comment"); - pUIBuilder->get(mpSetupButton, "setup"); - pUIBuilder->get(mpCopyCountField, "copycount"); - pUIBuilder->get(mpCollateBox, "collate"); - pUIBuilder->get(mpCollateImage, "collateimage"); - pUIBuilder->get(mpReverseOrderBox, "reverseorder"); - // HACK: this is not a dropdown box, but the dropdown line count - // sets the results of GetOptimalSize in a normal ListBox - mpPrinters->SetDropDownLineCount( 4 ); -} - -void PrintDialog::JobTabPage::readFromSettings() +Size const & PrintDialog::getJobPageSize() { - SettingsConfigItem* pItem = SettingsConfigItem::get(); - OUString aValue; - - aValue = pItem->getValue( "PrintDialog", - "CollateBox" ); - if( aValue.equalsIgnoreAsciiCase("alwaysoff") ) - { - mnCollateUIMode = 1; - mpCollateBox->Check( false ); - mpCollateBox->Enable( false ); - } - else + if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0) { - mnCollateUIMode = 0; - aValue = pItem->getValue( "PrintDialog", - "Collate" ); - mpCollateBox->Check( aValue.equalsIgnoreAsciiCase("true") ); + maFirstPageSize = maNupPortraitSize; + GDIMetaFile aMtf; + if( maPController->getPageCountProtected() > 0 ) + { + PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true ); + maFirstPageSize = aPageSize.aSize; + } } + return maFirstPageSize; } -void PrintDialog::JobTabPage::storeToSettings() -{ - SettingsConfigItem* pItem = SettingsConfigItem::get(); - pItem->setValue( "PrintDialog", - "CopyCount", - mpCopyCountField->GetText() ); - pItem->setValue( "PrintDialog", - "Collate", - mpCollateBox->IsChecked() ? OUString("true") : - OUString("false") ); -} - -PrintDialog::OutputOptPage::OutputOptPage( VclBuilder *pUIBuilder ) -{ - pUIBuilder->get(mpCollateSingleJobsBox, "singleprintjob"); - pUIBuilder->get(mpPapersizeFromSetup, "papersizefromsetup"); -} - -void PrintDialog::OutputOptPage::readFromSettings() -{ - SettingsConfigItem* pItem = SettingsConfigItem::get(); - OUString aValue; - aValue = pItem->getValue( "PrintDialog", - "CollateSingleJobs" ); - if ( aValue.equalsIgnoreAsciiCase("true") ) - { - mpCollateSingleJobsBox->Check(); - } - else - { - mpCollateSingleJobsBox->Check( false ); - } -} +PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterController>& i_rController) -void PrintDialog::OutputOptPage::storeToSettings() +: ModalDialog(i_pWindow, "PrintDialog", "vcl/ui/printdialog.ui") +, maPController( i_rController ) +, maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ) ) +, maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ) ) +, maNoPageStr( VclResId( SV_PRINT_NOPAGES ) ) +, maNoPreviewStr( VclResId( SV_PRINT_NOPREVIEW ) ) +, mnCurPage( 0 ) +, mnCachedPages( 0 ) +, maCollateBmp(SV_PRINT_COLLATE_BMP) +, maNoCollateBmp(SV_PRINT_NOCOLLATE_BMP) +, mnCollateUIMode(0) { - SettingsConfigItem* pItem = SettingsConfigItem::get(); - pItem->setValue( "PrintDialog", - "CollateSingleJobs", - mpCollateSingleJobsBox->IsChecked() ? OUString("true") : - OUString("false") ); -} -namespace { - bool lcl_ListBoxCompare( const OUString& rStr1, const OUString& rStr2 ) - { - return ListBox::NaturalSortCompare( rStr1, rStr2 ) < 0; - } -} - -PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterController>& i_rController ) - : ModalDialog(i_pParent, "PrintDialog", "vcl/ui/printdialog.ui") - , mpCustomOptionsUIBuilder(nullptr) - , maPController( i_rController ) - , maNUpPage(m_pUIBuilder.get()) - , maJobPage(m_pUIBuilder.get()) - , maOptionsPage(m_pUIBuilder.get()) - , maNoPageStr( VclResId( SV_PRINT_NOPAGES ) ) - , maNoPreviewStr( VclResId( SV_PRINT_NOPREVIEW ) ) - , mnCurPage( 0 ) - , mnCachedPages( 0 ) - , maPrintToFileText( VclResId( SV_PRINT_TOFILE_TXT ) ) - , maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ) ) - , mbShowLayoutPage( true ) -{ get(mpOKButton, "ok"); get(mpCancelButton, "cancel"); get(mpHelpButton, "help"); @@ -664,9 +503,33 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC get(mpBackwardBtn, "backward"); get(mpNumPagesText, "totalnumpages"); get(mpPageEdit, "pageedit-nospin"); - get(mpTabCtrl, "tabcontrol"); get(mpPreviewWindow, "preview"); get(mpPreviewBox, "previewbox"); + get(mpPrinters, "printersbox"); + get(mpSetupButton, "setup"); + get(mpStatusTxt, "status"); + get(mpCollateBox, "collate"); + get(mpCollateImage, "collateimage"); + get(mpReverseOrderBox, "reverseorder"); + get(mpCopyCountField, "copycount"); + get(mpNupOrderWin, "orderpreview"); + get(mpNupPagesBox, "pagespersheetbox"); + get(mpNupOrientationBox, "pageorientationbox"); + get(mpNupOrderBox, "orderbox"); + get(mpPagesBtn, "pagespersheetbtn"); + get(mpBrochureBtn, "brochurebtn"); + get(mpPagesBoxTitleTxt, "pagespersheettxt"); + get(mpNupNumPagesTxt, "pagestxt"); + get(mpNupColEdt, "pagecols"); + get(mpNupTimesTxt, "by"); + get(mpNupRowsEdt, "pagerows"); + get(mpPageMarginTxt1, "pagemargintxt1"); + get(mpPageMarginEdt, "pagemarginsb"); + get(mpPageMarginTxt2, "pagemargintxt2"); + get(mpSheetMarginTxt1, "sheetmargintxt1"); + get(mpSheetMarginEdt, "sheetmarginsb"); + get(mpSheetMarginTxt2, "sheetmargintxt2"); + get(mpBorderCB, "bordercb"); // save printbutton text, gets exchanged occasionally with print to file maPrintText = mpOKButton->GetText(); @@ -677,24 +540,21 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC maPageStr = mpNumPagesText->GetText(); - // init reverse print - maJobPage.mpReverseOrderBox->Check( maPController->getReversePrint() ); - Printer::updatePrinters(); - maJobPage.mpPrinters->InsertEntry( maPrintToFileText ); + mpPrinters->InsertEntry( maPrintToFileText ); // fill printer listbox std::vector< OUString > rQueues( Printer::GetPrinterQueues() ); std::sort( rQueues.begin(), rQueues.end(), lcl_ListBoxCompare ); for( std::vector< OUString >::const_iterator it = rQueues.begin(); it != rQueues.end(); ++it ) { - maJobPage.mpPrinters->InsertEntry( *it ); + mpPrinters->InsertEntry( *it ); } // select current printer - if( maJobPage.mpPrinters->GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND ) + if( mpPrinters->GetEntryPos( maPController->getPrinter()->GetName() ) != LISTBOX_ENTRY_NOTFOUND ) { - maJobPage.mpPrinters->SelectEntry( maPController->getPrinter()->GetName() ); + mpPrinters->SelectEntry( maPController->getPrinter()->GetName() ); } else { @@ -702,26 +562,31 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC SettingsConfigItem* pItem = SettingsConfigItem::get(); OUString aValue( pItem->getValue( "PrintDialog", "LastPrinter" ) ); - if( maJobPage.mpPrinters->GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND ) + if( mpPrinters->GetEntryPos( aValue ) != LISTBOX_ENTRY_NOTFOUND ) { - maJobPage.mpPrinters->SelectEntry( aValue ); + mpPrinters->SelectEntry( aValue ); maPController->setPrinter( VclPtrInstance<Printer>( aValue ) ); } else { // fall back to default printer - maJobPage.mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() ); + mpPrinters->SelectEntry( Printer::GetDefaultPrinterName() ); maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) ); } } + // not printing to file maPController->resetPrinterOptions( false ); // update the text fields for the printer updatePrinterText(); - // set a select handler - maJobPage.mpPrinters->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); + // setup dependencies + checkControlDependencies(); + + // set initial focus to "Number of copies" + mpCopyCountField->GrabFocus(); + mpCopyCountField->SetSelection( Selection(0, 0xFFFF) ); // setup sizes for N-Up Size aNupSize( maPController->getPrinter()->PixelToLogic( @@ -736,61 +601,41 @@ PrintDialog::PrintDialog( vcl::Window* i_pParent, const std::shared_ptr<PrinterC maNupPortraitSize = aNupSize; maNupLandscapeSize = Size( aNupSize.Height(), aNupSize.Width() ); } - maNUpPage.initFromMultiPageSetup( maPController->getMultipage() ); - - // setup click handler on the various buttons - mpOKButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - #if OSL_DEBUG_LEVEL > 1 - mpCancelButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - #endif - mpHelpButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - mpForwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - mpBackwardBtn->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - mpPreviewBox->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - - maJobPage.mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); - maJobPage.mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - maNUpPage.mpBorderCB->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - maOptionsPage.mpPapersizeFromSetup->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); - maOptionsPage.mpPapersizeFromSetup->Check( maPController->getPapersizeFromSetup() ); - maJobPage.mpReverseOrderBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); - maOptionsPage.mpCollateSingleJobsBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); - maNUpPage.mpPagesBtn->SetToggleHdl( LINK( this, PrintDialog, ToggleRadioHdl ) ); - // setup modify hdl - mpPageEdit->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - maJobPage.mpCopyCountField->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - maNUpPage.mpNupRowsEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - maNUpPage.mpNupColEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - maNUpPage.mpPageMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - maNUpPage.mpSheetMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - - // setup select hdl - maNUpPage.mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); - maNUpPage.mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); - maNUpPage.mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); - // setup optional UI options set by application - setupOptionalUI(); + initFromMultiPageSetup( maPController->getMultipage() ); - // remove layout page if unwanted - if (!mbShowLayoutPage) - mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(2)); + // setup click hdl + mpOKButton->SetClickHdl(LINK(this, PrintDialog, ClickHdl)); + mpCancelButton->SetClickHdl(LINK(this, PrintDialog, ClickHdl)); + mpHelpButton->SetClickHdl(LINK(this, PrintDialog, ClickHdl)); + mpSetupButton->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); + mpBackwardBtn->SetClickHdl(LINK(this, PrintDialog, ClickHdl)); + mpForwardBtn->SetClickHdl(LINK(this, PrintDialog, ClickHdl)); + mpPreviewBox->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); + mpBorderCB->SetClickHdl( LINK( this, PrintDialog, ClickHdl ) ); - // restore settings from last run - readFromSettings(); + // setup toggle hdl + mpReverseOrderBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); + mpCollateBox->SetToggleHdl( LINK( this, PrintDialog, ToggleHdl ) ); + mpPagesBtn->SetToggleHdl( LINK( this, PrintDialog, ToggleRadioHdl ) ); + mpBrochureBtn->SetToggleHdl( LINK( this, PrintDialog, ToggleRadioHdl ) ); - // setup dependencies - checkControlDependencies(); + // setup select hdl + mpPrinters->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); + mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); + mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); + mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); - if ( maPController->getBoolProperty( "HideHelpButton", false ) ) - mpHelpButton->Hide(); - // set initial focus to "Number of copies" - maJobPage.mpCopyCountField->GrabFocus(); - maJobPage.mpCopyCountField->SetSelection( Selection(0, 0xFFFF) ); + // setup modify hdl + mpPageEdit->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); + mpCopyCountField->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); + mpNupColEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); + mpNupRowsEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - updateNupFromPages(); + preparePreview( true, true ); } + PrintDialog::~PrintDialog() { disposeOnce(); @@ -798,7 +643,7 @@ PrintDialog::~PrintDialog() void PrintDialog::dispose() { - mpCustomOptionsUIBuilder.reset(); + // mpCustomOptionsUIBuilder.reset(); mpTabCtrl.clear(); mpPreviewWindow.clear(); mpPageEdit.clear(); @@ -811,678 +656,234 @@ void PrintDialog::dispose() mpHelpButton.clear(); maPController.reset(); maControlToPropertyMap.clear(); - maControlToNumValMap.clear(); + // maControlToNumValMap.clear(); + mpPrinters.clear(); + mpStatusTxt.clear(); + mpSetupButton.clear(); + mpCopyCountField.clear(); + mpCollateBox.clear(); + mpCollateImage.clear(); + mpReverseOrderBox.clear(); + mpPagesBtn.clear(); + mpBrochureBtn.clear(); + mpPagesBoxTitleTxt.clear(); + mpNupPagesBox.clear(); + mpNupNumPagesTxt.clear(); + mpNupColEdt.clear(); + mpNupTimesTxt.clear(); + mpNupRowsEdt.clear(); + mpPageMarginTxt1.clear(); + mpPageMarginEdt.clear(); + mpPageMarginTxt2.clear(); + mpSheetMarginTxt1.clear(); + mpSheetMarginEdt.clear(); + mpSheetMarginTxt2.clear(); + mpNupOrientationBox.clear(); + mpNupOrderBox.clear(); + mpNupOrderWin.clear(); + mpBorderCB.clear(); ModalDialog::dispose(); } -void PrintDialog::readFromSettings() +void PrintDialog::updatePrinterText() { - maJobPage.readFromSettings(); - maOptionsPage.readFromSettings(); - - // read last selected tab page; if it exists, activate it - SettingsConfigItem* pItem = SettingsConfigItem::get(); - OUString aValue = pItem->getValue( "PrintDialog", - "LastPage" ); - sal_uInt16 nCount = mpTabCtrl->GetPageCount(); - for( sal_uInt16 i = 0; i < nCount; i++ ) - { - sal_uInt16 nPageId = mpTabCtrl->GetPageId( i ); - if( aValue == mpTabCtrl->GetPageText( nPageId ) ) - { - mpTabCtrl->SelectTabPage( nPageId ); - break; - } - } - - aValue = pItem->getValue( "PrintDialog", "HasPreview" ); - if ( aValue.equalsIgnoreAsciiCase("true") ) + const OUString aDefPrt( Printer::GetDefaultPrinterName() ); + const QueueInfo* pInfo = Printer::GetQueueInfo( mpPrinters->GetSelectedEntry(), true ); + if( pInfo ) { - mpPreviewBox->Check(); + // FIXME: status text + OUString aStatus; + if( aDefPrt == pInfo->GetPrinterName() ) + aStatus = maDefPrtText; + mpStatusTxt->SetText( aStatus ); } else { - mpPreviewBox->Check( false ); + mpStatusTxt->SetText( OUString() ); } - - // persistent window state - OUString aWinState( pItem->getValue( "PrintDialog", - "WindowState" ) ); - if( !aWinState.isEmpty() ) - SetWindowState( OUStringToOString( aWinState, RTL_TEXTENCODING_UTF8 ) ); -} - -void PrintDialog::storeToSettings() -{ - maJobPage.storeToSettings(); - maOptionsPage.storeToSettings(); - - // store last selected printer - SettingsConfigItem* pItem = SettingsConfigItem::get(); - pItem->setValue( "PrintDialog", - "ToFile", - isPrintToFile() ? OUString("true") - : OUString("false") ); - pItem->setValue( "PrintDialog", - "LastPrinter", - isPrintToFile() ? Printer::GetDefaultPrinterName() - : maJobPage.mpPrinters->GetSelectedEntry() ); - - pItem->setValue( "PrintDialog", - "LastPage", - mpTabCtrl->GetPageText( mpTabCtrl->GetCurPageId() ) ); - pItem->setValue( "PrintDialog", - "WindowState", - OStringToOUString( GetWindowState(), RTL_TEXTENCODING_UTF8 ) - ); - pItem->setValue( "PrintDialog", - "HasPreview", - hasPreview() ? OUString("true") : OUString("false") ); - pItem->Commit(); -} - -bool PrintDialog::isPrintToFile() -{ - return ( maJobPage.mpPrinters->GetSelectedEntryPos() == 0 ); } -bool PrintDialog::isCollate() +void PrintDialog::setPreviewText() { - return maJobPage.mpCopyCountField->GetValue() > 1 && maJobPage.mpCollateBox->IsChecked(); + OUString aNewText( maPageStr.replaceFirst( "%n", OUString::number( mnCachedPages ) ) ); + mpNumPagesText->SetText( aNewText ); } -bool PrintDialog::isSingleJobs() +void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) { - return maOptionsPage.mpCollateSingleJobsBox->IsChecked(); -} + VclPtr<Printer> aPrt( maPController->getPrinter() ); + Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ); + GDIMetaFile aMtf; -bool PrintDialog::hasPreview() -{ - return mpPreviewBox->IsChecked(); -} + // page range may have changed depending on options + sal_Int32 nPages = maPController->getFilteredPageCount(); + mnCachedPages = nPages; -void setHelpId( vcl::Window* i_pWindow, const Sequence< OUString >& i_rHelpIds, sal_Int32 i_nIndex ) -{ - if( i_nIndex >= 0 && i_nIndex < i_rHelpIds.getLength() ) - i_pWindow->SetHelpId( OUStringToOString( i_rHelpIds.getConstArray()[i_nIndex], RTL_TEXTENCODING_UTF8 ) ); -} + mpPageEdit->SetMin( 1 ); + mpPageEdit->SetMax( nPages ); -static void setHelpText( vcl::Window* i_pWindow, const Sequence< OUString >& i_rHelpTexts, sal_Int32 i_nIndex ) -{ - // without a help text set and the correct smartID, - // help texts will be retrieved from the online help system - if( i_nIndex >= 0 && i_nIndex < i_rHelpTexts.getLength() ) - i_pWindow->SetHelpText( i_rHelpTexts.getConstArray()[i_nIndex] ); -} + setPreviewText(); -void PrintDialog::setupOptionalUI() -{ - const Sequence< PropertyValue >& rOptions( maPController->getUIOptions() ); - for( int i = 0; i < rOptions.getLength(); i++ ) + if ( !hasPreview() ) { - if (rOptions[i].Name == "OptionsUIFile") - { - OUString sOptionsUIFile; - rOptions[i].Value >>= sOptionsUIFile; + mpPreviewWindow->setPreview( aMtf, aCurPageSize, + aPrt->GetPaperName(), + maNoPreviewStr, + aPrt->GetDPIX(), aPrt->GetDPIY(), + aPrt->GetPrinterOptions().IsConvertToGreyscales() + ); + + mpForwardBtn->Enable( false ); + mpBackwardBtn->Enable( false ); + mpPageEdit->Enable( false ); - vcl::Window *pCustom = get<vcl::Window>("customcontents"); + return; + } - mpCustomOptionsUIBuilder.reset(new VclBuilder(pCustom, getUIRootDir(), sOptionsUIFile)); - vcl::Window *pWindow = mpCustomOptionsUIBuilder->get_widget_root(); - pWindow->Show(); - continue; - } + if( mnCurPage >= nPages ) + mnCurPage = nPages-1; + if( mnCurPage < 0 ) + mnCurPage = 0; - Sequence< beans::PropertyValue > aOptProp; - rOptions[i].Value >>= aOptProp; - - // extract ui element - OUString aCtrlType; - OString aID; - OUString aText; - OUString aPropertyName; - Sequence< OUString > aChoices; - Sequence< sal_Bool > aChoicesDisabled; - Sequence< OUString > aHelpTexts; - Sequence< OUString > aIDs; - Sequence< OUString > aHelpIds; - sal_Int64 nMinValue = 0, nMaxValue = 0; - OUString aGroupingHint; - OUString aDependsOnName; - sal_Int32 nDependsOnValue = 0; - bool bUseDependencyRow = false; - - for( int n = 0; n < aOptProp.getLength(); n++ ) + if( i_bNewPage ) + { + const MapMode aMapMode( MapUnit::Map100thMM ); + if( nPages > 0 ) { - const beans::PropertyValue& rEntry( aOptProp[ n ] ); - if ( rEntry.Name == "ID" ) - { - rEntry.Value >>= aIDs; - aID = OUStringToOString(aIDs[0], RTL_TEXTENCODING_UTF8); - } - if ( rEntry.Name == "Text" ) - { - rEntry.Value >>= aText; - } - else if ( rEntry.Name == "ControlType" ) - { - rEntry.Value >>= aCtrlType; - } - else if ( rEntry.Name == "Choices" ) - { - rEntry.Value >>= aChoices; - } - else if ( rEntry.Name == "ChoicesDisabled" ) - { - rEntry.Value >>= aChoicesDisabled; - } - else if ( rEntry.Name == "Property" ) - { - PropertyValue aVal; - rEntry.Value >>= aVal; - aPropertyName = aVal.Name; - } - else if ( rEntry.Name == "Enabled" ) - { - bool bValue = true; - rEntry.Value >>= bValue; - } - else if ( rEntry.Name == "GroupingHint" ) - { - rEntry.Value >>= aGroupingHint; - } - else if ( rEntry.Name == "DependsOnName" ) - { - rEntry.Value >>= aDependsOnName; - } - else if ( rEntry.Name == "DependsOnEntry" ) - { - rEntry.Value >>= nDependsOnValue; - } - else if ( rEntry.Name == "AttachToDependency" ) - { - rEntry.Value >>= bUseDependencyRow; - } - else if ( rEntry.Name == "MinValue" ) - { - rEntry.Value >>= nMinValue; - } - else if ( rEntry.Name == "MaxValue" ) - { - rEntry.Value >>= nMaxValue; - } - else if ( rEntry.Name == "HelpText" ) - { - if( ! (rEntry.Value >>= aHelpTexts) ) - { - OUString aHelpText; - if( rEntry.Value >>= aHelpText ) - { - aHelpTexts.realloc( 1 ); - *aHelpTexts.getArray() = aHelpText; - } - } - } - else if ( rEntry.Name == "HelpId" ) - { - if( ! (rEntry.Value >>= aHelpIds ) ) - { - OUString aHelpId; - if( rEntry.Value >>= aHelpId ) - { - aHelpIds.realloc( 1 ); - *aHelpIds.getArray() = aHelpId; - } - } - } - else if ( rEntry.Name == "HintNoLayoutPage" ) + PrinterController::PageSize aPageSize = + maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache ); + if( ! aPageSize.bFullPaper ) { - bool bNoLayoutPage = false; - rEntry.Value >>= bNoLayoutPage; - mbShowLayoutPage = ! bNoLayoutPage; + Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) ); + aMtf.Move( aOff.X(), aOff.Y() ); } } - if (aCtrlType == "Group" && !aID.isEmpty()) - { - TabPage *pPage = get<TabPage>(aID); - if (!pPage && mpCustomOptionsUIBuilder) - pPage = mpCustomOptionsUIBuilder->get<TabPage>(aID); - - if (!pPage) - continue; + mpPreviewWindow->setPreview( aMtf, aCurPageSize, + aPrt->GetPaperName(), + nPages > 0 ? OUString() : maNoPageStr, + aPrt->GetDPIX(), aPrt->GetDPIY(), + aPrt->GetPrinterOptions().IsConvertToGreyscales() + ); - sal_uInt16 nPageId = mpTabCtrl->GetPageId(*pPage); + mpForwardBtn->Enable( mnCurPage < nPages-1 ); + mpBackwardBtn->Enable( mnCurPage != 0 ); + mpPageEdit->Enable( nPages > 1 ); + } +} - mpTabCtrl->SetPageText(nPageId, aText); +void PrintDialog::checkControlDependencies() +{ - // set help id - if (aHelpIds.getLength() > 0) - mpTabCtrl->SetHelpId(nPageId, OUStringToOString(aHelpIds.getConstArray()[0], RTL_TEXTENCODING_UTF8)); + if( mpCopyCountField->GetValue() > 1 ) + mpCollateBox->Enable( mnCollateUIMode == 0 ); + else + mpCollateBox->Enable( false ); - // set help text - if (aHelpTexts.getLength() > 0) - mpTabCtrl->SetHelpText(nPageId, aHelpTexts.getConstArray()[0]); + Image aImg(mpCollateBox->IsChecked() ? maCollateBmp : maNoCollateBmp); - pPage->Show(); - } - else if (aCtrlType == "Subgroup" && !aID.isEmpty()) - { - vcl::Window *pFrame = get<vcl::Window>(aID); - if (!pFrame && mpCustomOptionsUIBuilder) - pFrame = mpCustomOptionsUIBuilder->get<vcl::Window>(aID); + Size aImgSize( aImg.GetSizePixel() ); - if (!pFrame) - continue; + // adjust size of image + mpCollateImage->SetSizePixel( aImgSize ); + mpCollateImage->SetImage( aImg ); - pFrame->SetText(aText); + // enable setup button only for printers that can be setup + bool bHaveSetup = maPController->getPrinter()->HasSupport( PrinterSupport::SetupDialog ); + mpSetupButton->Enable(bHaveSetup); +} - // set help id - setHelpId(pFrame, aHelpIds, 0); - // set help text - setHelpText(pFrame, aHelpTexts, 0); +void PrintDialog::initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& i_rMPS ) +{ + mpNupOrderWin->Show(); + mpPagesBtn->Check(); + mpBrochureBtn->Show( false ); - pFrame->Show(); - } - // EVIL - else if( aCtrlType == "Bool" && aGroupingHint == "LayoutPage" && aPropertyName == "PrintProspect" ) - { - maNUpPage.mpBrochureBtn->SetText( aText ); - maNUpPage.mpBrochureBtn->Show(); - - bool bVal = false; - PropertyValue* pVal = maPController->getValue( aPropertyName ); - if( pVal ) - pVal->Value >>= bVal; - maNUpPage.mpBrochureBtn->Check( bVal ); - maNUpPage.mpBrochureBtn->Enable( maPController->isUIOptionEnabled( aPropertyName ) && pVal != nullptr ); - maNUpPage.mpBrochureBtn->SetToggleHdl( LINK( this, PrintDialog, ToggleRadioHdl ) ); - - maPropertyToWindowMap[ aPropertyName ].emplace_back(maNUpPage.mpBrochureBtn ); - maControlToPropertyMap[maNUpPage.mpBrochureBtn] = aPropertyName; - - // set help id - setHelpId( maNUpPage.mpBrochureBtn, aHelpIds, 0 ); - // set help text - setHelpText( maNUpPage.mpBrochureBtn, aHelpTexts, 0 ); - } - else if (aCtrlType == "Bool") - { - // add a check box - CheckBox* pNewBox = get<CheckBox>(aID); - if (!pNewBox && mpCustomOptionsUIBuilder) - pNewBox = mpCustomOptionsUIBuilder->get<CheckBox>(aID); - - if (!pNewBox) - continue; - - pNewBox->SetText( aText ); - pNewBox->Show(); - - bool bVal = false; - PropertyValue* pVal = maPController->getValue( aPropertyName ); - if( pVal ) - pVal->Value >>= bVal; - pNewBox->Check( bVal ); - pNewBox->SetToggleHdl( LINK( this, PrintDialog, UIOption_CheckHdl ) ); - - maPropertyToWindowMap[ aPropertyName ].emplace_back(pNewBox ); - maControlToPropertyMap[pNewBox] = aPropertyName; - - // set help id - setHelpId( pNewBox, aHelpIds, 0 ); - // set help text - setHelpText( pNewBox, aHelpTexts, 0 ); - } - else if (aCtrlType == "Radio") - { - sal_Int32 nCurHelpText = 0; - - // iterate options - sal_Int32 nSelectVal = 0; - PropertyValue* pVal = maPController->getValue( aPropertyName ); - if( pVal && pVal->Value.hasValue() ) - pVal->Value >>= nSelectVal; - for( sal_Int32 m = 0; m < aChoices.getLength(); m++ ) - { - aID = OUStringToOString(aIDs[m], RTL_TEXTENCODING_UTF8); - RadioButton* pBtn = get<RadioButton>(aID); - if (!pBtn && mpCustomOptionsUIBuilder) - pBtn = mpCustomOptionsUIBuilder->get<RadioButton>(aID); - - if (!pBtn) - continue; - - pBtn->SetText( aChoices[m] ); - pBtn->Check( m == nSelectVal ); - pBtn->SetToggleHdl( LINK( this, PrintDialog, UIOption_RadioHdl ) ); - if( aChoicesDisabled.getLength() > m && aChoicesDisabled[m] ) - pBtn->Enable( false ); - pBtn->Show(); - maPropertyToWindowMap[ aPropertyName ].emplace_back(pBtn ); - maControlToPropertyMap[pBtn] = aPropertyName; - maControlToNumValMap[pBtn] = m; - - // set help id - setHelpId( pBtn, aHelpIds, nCurHelpText ); - // set help text - setHelpText( pBtn, aHelpTexts, nCurHelpText ); - nCurHelpText++; - } - } - else if ( aCtrlType == "List" ) - { - ListBox* pList = get<ListBox>(aID); - if (!pList && mpCustomOptionsUIBuilder) - pList = mpCustomOptionsUIBuilder->get<ListBox>(aID); - - if (!pList) - continue; - - // iterate options - for( sal_Int32 m = 0; m < aChoices.getLength(); m++ ) - { - pList->InsertEntry( aChoices[m] ); - } - sal_Int32 nSelectVal = 0; - PropertyValue* pVal = maPController->getValue( aPropertyName ); - if( pVal && pVal->Value.hasValue() ) - pVal->Value >>= nSelectVal; - pList->SelectEntryPos( static_cast<sal_uInt16>(nSelectVal) ); - pList->SetSelectHdl( LINK( this, PrintDialog, UIOption_SelectHdl ) ); - pList->SetDropDownLineCount( static_cast<sal_uInt16>(aChoices.getLength()) ); - pList->Show(); - - // set help id - setHelpId( pList, aHelpIds, 0 ); - // set help text - setHelpText( pList, aHelpTexts, 0 ); - - maPropertyToWindowMap[ aPropertyName ].emplace_back(pList ); - maControlToPropertyMap[pList] = aPropertyName; - } - else if ( aCtrlType == "Range" ) - { - NumericField* pField = get<NumericField>(aID); - if (!pField && mpCustomOptionsUIBuilder) - pField = mpCustomOptionsUIBuilder->get<NumericField>(aID); - - if (!pField) - continue; - - // set min/max and current value - if( nMinValue != nMaxValue ) - { - pField->SetMin( nMinValue ); - pField->SetMax( nMaxValue ); - } - sal_Int64 nCurVal = 0; - PropertyValue* pVal = maPController->getValue( aPropertyName ); - if( pVal && pVal->Value.hasValue() ) - pVal->Value >>= nCurVal; - pField->SetValue( nCurVal ); - pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) ); - pField->Show(); - - // set help id - setHelpId( pField, aHelpIds, 0 ); - // set help text - setHelpText( pField, aHelpTexts, 0 ); - - maPropertyToWindowMap[ aPropertyName ].emplace_back(pField ); - maControlToPropertyMap[pField] = aPropertyName; - } - else if (aCtrlType == "Edit") - { - Edit *pField = get<Edit>(aID); - if (!pField && mpCustomOptionsUIBuilder) - pField = mpCustomOptionsUIBuilder->get<Edit>(aID); - - if (!pField) - continue; - - OUString aCurVal; - PropertyValue* pVal = maPController->getValue( aPropertyName ); - if( pVal && pVal->Value.hasValue() ) - pVal->Value >>= aCurVal; - pField->SetText( aCurVal ); - pField->SetModifyHdl( LINK( this, PrintDialog, UIOption_ModifyHdl ) ); - pField->Show(); - - // set help id - setHelpId( pField, aHelpIds, 0 ); - // set help text - setHelpText( pField, aHelpTexts, 0 ); - - maPropertyToWindowMap[ aPropertyName ].emplace_back(pField ); - maControlToPropertyMap[pField] = aPropertyName; - } - else - { - SAL_WARN( "vcl", "Unsupported UI option: \"" << aCtrlType << '"'); - } - } - - // #i106506# if no brochure button, then the singular Pages radio button - // makes no sense, so replace it by a FixedText label - if (!maNUpPage.mpBrochureBtn->IsVisible() && maNUpPage.mpPagesBtn->IsVisible()) - { - maNUpPage.mpPagesBoxTitleTxt->SetText( maNUpPage.mpPagesBtn->GetText() ); - maNUpPage.mpPagesBoxTitleTxt->Show(); - maNUpPage.mpPagesBtn->Show( false ); - } - - // update enable states - checkOptionalControlDependencies(); - - vcl::Window *pPageRange = get<vcl::Window>("pagerange"); - - // print range not shown (currently math only) -> hide spacer line and reverse order - if (!pPageRange || !pPageRange->IsVisible()) - { - maJobPage.mpReverseOrderBox->Show( false ); - } - - if (!mpCustomOptionsUIBuilder) - mpTabCtrl->RemovePage(mpTabCtrl->GetPageId(1)); -} - -void PrintDialog::DataChanged( const DataChangedEvent& i_rDCEvt ) -{ - // react on settings changed - if( i_rDCEvt.GetType() == DataChangedEventType::SETTINGS ) - checkControlDependencies(); - ModalDialog::DataChanged( i_rDCEvt ); -} - -void PrintDialog::checkControlDependencies() -{ - if( maJobPage.mpCopyCountField->GetValue() > 1 ) - maJobPage.mpCollateBox->Enable( maJobPage.mnCollateUIMode == 0 ); - else - maJobPage.mpCollateBox->Enable( false ); - - Image aImg(maJobPage.mpCollateBox->IsChecked() ? maJobPage.maCollateBmp : maJobPage.maNoCollateBmp); - - Size aImgSize( aImg.GetSizePixel() ); - - // adjust size of image - maJobPage.mpCollateImage->SetSizePixel( aImgSize ); - maJobPage.mpCollateImage->SetImage( aImg ); - - // enable setup button only for printers that can be setup - bool bHaveSetup = maPController->getPrinter()->HasSupport( PrinterSupport::SetupDialog ); - maJobPage.mpSetupButton->Enable(bHaveSetup); -} - -void PrintDialog::checkOptionalControlDependencies() -{ - for( auto it = maControlToPropertyMap.begin(); - it != maControlToPropertyMap.end(); ++it ) + // setup field units for metric fields + const LocaleDataWrapper& rLocWrap( mpPageMarginEdt->GetLocaleDataWrapper() ); + FieldUnit eUnit = FUNIT_MM; + sal_uInt16 nDigits = 0; + if( rLocWrap.getMeasurementSystemEnum() == MeasurementSystem::US ) { - bool bShouldbeEnabled = maPController->isUIOptionEnabled( it->second ); - if( ! bShouldbeEnabled ) - { - // enable controls that are directly attached to a dependency anyway - // if the normally disabled controls get modified, change the dependency - // so the control would be enabled - // example: in print range "Print All" is selected, "Page Range" is then of course - // not selected and the Edit for the Page Range would be disabled - // as a convenience we should enable the Edit anyway and automatically select - // "Page Range" instead of "Print All" if the Edit gets modified - if( maReverseDependencySet.find( it->second ) != maReverseDependencySet.end() ) - { - OUString aDep( maPController->getDependency( it->second ) ); - // if the dependency is at least enabled, then enable this control anyway - if( !aDep.isEmpty() && maPController->isUIOptionEnabled( aDep ) ) - bShouldbeEnabled = true; - } - } - - if( bShouldbeEnabled && dynamic_cast<RadioButton*>(it->first.get()) ) - { - auto r_it = maControlToNumValMap.find( it->first ); - if( r_it != maControlToNumValMap.end() ) - { - bShouldbeEnabled = maPController->isUIChoiceEnabled( it->second, r_it->second ); - } - } - - bool bIsEnabled = it->first->IsEnabled(); - // Enable does not do a change check first, so can be less cheap than expected - if( bShouldbeEnabled != bIsEnabled ) - it->first->Enable( bShouldbeEnabled ); + eUnit = FUNIT_INCH; + nDigits = 2; } -} + // set units + mpPageMarginEdt->SetUnit( eUnit ); + mpSheetMarginEdt->SetUnit( eUnit ); -static OUString searchAndReplace( const OUString& i_rOrig, const char* i_pRepl, sal_Int32 i_nReplLen, const OUString& i_rRepl ) -{ - sal_Int32 nPos = i_rOrig.indexOfAsciiL( i_pRepl, i_nReplLen ); - if( nPos != -1 ) - { - OUStringBuffer aBuf( i_rOrig.getLength() ); - aBuf.append( i_rOrig.getStr(), nPos ); - aBuf.append( i_rRepl ); - if( nPos + i_nReplLen < i_rOrig.getLength() ) - aBuf.append( i_rOrig.getStr() + nPos + i_nReplLen ); - return aBuf.makeStringAndClear(); - } - return i_rOrig; -} + // set precision + mpPageMarginEdt->SetDecimalDigits( nDigits ); + mpSheetMarginEdt->SetDecimalDigits( nDigits ); -void PrintDialog::updatePrinterText() -{ - const OUString aDefPrt( Printer::GetDefaultPrinterName() ); - const QueueInfo* pInfo = Printer::GetQueueInfo( maJobPage.mpPrinters->GetSelectedEntry(), true ); - if( pInfo ) - { - maJobPage.mpLocationTxt->SetText( pInfo->GetLocation() ); - maJobPage.mpCommentTxt->SetText( pInfo->GetComment() ); - // FIXME: status text - OUString aStatus; - if( aDefPrt == pInfo->GetPrinterName() ) - aStatus = maDefPrtText; - maJobPage.mpStatusTxt->SetText( aStatus ); - } - else + mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( i_rMPS.nLeftMargin ), FUNIT_100TH_MM ); + mpPageMarginEdt->SetValue( mpPageMarginEdt->Normalize( i_rMPS.nHorizontalSpacing ), FUNIT_100TH_MM ); + mpBorderCB->Check( i_rMPS.bDrawBorder ); + mpNupRowsEdt->SetValue( i_rMPS.nRows ); + mpNupColEdt->SetValue( i_rMPS.nColumns ); + mpNupOrderBox->SelectEntryPos( static_cast<sal_Int32>(i_rMPS.nOrder) ); + if( i_rMPS.nRows != 1 || i_rMPS.nColumns != 1 ) { - maJobPage.mpLocationTxt->SetText( OUString() ); - maJobPage.mpCommentTxt->SetText( OUString() ); - maJobPage.mpStatusTxt->SetText( OUString() ); + mpNupPagesBox->SelectEntryPos( mpNupPagesBox->GetEntryCount()-1 ); + showAdvancedControls( true ); + mpNupOrderWin->setValues( i_rMPS.nOrder, i_rMPS.nColumns, i_rMPS.nRows ); } } -void PrintDialog::setPreviewText() +void PrintDialog::updateNup() { - OUString aNewText( searchAndReplace( maPageStr, "%n", 2, OUString::number( mnCachedPages ) ) ); - mpNumPagesText->SetText( aNewText ); -} + int nRows = int(mpNupRowsEdt->GetValue()); + int nCols = int(mpNupColEdt->GetValue()); + long nPageMargin = mpPageMarginEdt->Denormalize(mpPageMarginEdt->GetValue( FUNIT_100TH_MM )); + long nSheetMargin = mpSheetMarginEdt->Denormalize(mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )); -void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) -{ - VclPtr<Printer> aPrt( maPController->getPrinter() ); - Size aCurPageSize = aPrt->PixelToLogic( aPrt->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) ); - GDIMetaFile aMtf; + PrinterController::MultiPageSetup aMPS; + aMPS.nRows = nRows; + aMPS.nColumns = nCols; + aMPS.nLeftMargin = + aMPS.nTopMargin = + aMPS.nRightMargin = + aMPS.nBottomMargin = nSheetMargin; - // page range may have changed depending on options - sal_Int32 nPages = maPController->getFilteredPageCount(); - mnCachedPages = nPages; + aMPS.nHorizontalSpacing = + aMPS.nVerticalSpacing = nPageMargin; - mpPageEdit->SetMin( 1 ); - mpPageEdit->SetMax( nPages ); + aMPS.bDrawBorder = mpBorderCB->IsChecked(); - setPreviewText(); + aMPS.nOrder = static_cast<NupOrderType>(mpNupOrderBox->GetSelectedEntryPos()); - if ( !hasPreview() ) + int nOrientationMode = mpNupOrientationBox->GetSelectedEntryPos(); + if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE ) + aMPS.aPaperSize = maNupLandscapeSize; + else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT ) + aMPS.aPaperSize = maNupPortraitSize; + else // automatic mode { - mpPreviewWindow->setPreview( aMtf, aCurPageSize, - aPrt->GetPaperName(), - maNoPreviewStr, - aPrt->GetDPIX(), aPrt->GetDPIY(), - aPrt->GetPrinterOptions().IsConvertToGreyscales() - ); - - mpForwardBtn->Enable( false ); - mpBackwardBtn->Enable( false ); - mpPageEdit->Enable( false ); + // get size of first real page to see if it is portrait or landscape + // we assume same page sizes for all the pages for this + Size aPageSize = getJobPageSize(); - return; + Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows ); + if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape + aMPS.aPaperSize = maNupLandscapeSize; + else + aMPS.aPaperSize = maNupPortraitSize; } - if( mnCurPage >= nPages ) - mnCurPage = nPages-1; - if( mnCurPage < 0 ) - mnCurPage = 0; - - if( i_bNewPage ) - { - const MapMode aMapMode( MapUnit::Map100thMM ); - if( nPages > 0 ) - { - PrinterController::PageSize aPageSize = - maPController->getFilteredPageFile( mnCurPage, aMtf, i_bMayUseCache ); - if( ! aPageSize.bFullPaper ) - { - Point aOff( aPrt->PixelToLogic( aPrt->GetPageOffsetPixel(), aMapMode ) ); - aMtf.Move( aOff.X(), aOff.Y() ); - } - } + maPController->setMultipage( aMPS ); - mpPreviewWindow->setPreview( aMtf, aCurPageSize, - aPrt->GetPaperName(), - nPages > 0 ? OUString() : maNoPageStr, - aPrt->GetDPIX(), aPrt->GetDPIY(), - aPrt->GetPrinterOptions().IsConvertToGreyscales() - ); + mpNupOrderWin->setValues( aMPS.nOrder, nCols, nRows ); - mpForwardBtn->Enable( mnCurPage < nPages-1 ); - mpBackwardBtn->Enable( mnCurPage != 0 ); - mpPageEdit->Enable( nPages > 1 ); - } -} - -Size const & PrintDialog::getJobPageSize() -{ - if( maFirstPageSize.Width() == 0 && maFirstPageSize.Height() == 0) - { - maFirstPageSize = maNupPortraitSize; - GDIMetaFile aMtf; - if( maPController->getPageCountProtected() > 0 ) - { - PrinterController::PageSize aPageSize = maPController->getPageFile( 0, aMtf, true ); - maFirstPageSize = aPageSize.aSize; - } - } - return maFirstPageSize; + preparePreview( true, true ); } void PrintDialog::updateNupFromPages() { - sal_IntPtr nPages = sal_IntPtr(maNUpPage.mpNupPagesBox->GetSelectedEntryData()); - int nRows = int(maNUpPage.mpNupRowsEdt->GetValue()); - int nCols = int(maNUpPage.mpNupColEdt->GetValue()); - long nPageMargin = maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )); - long nSheetMargin = maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )); + sal_IntPtr nPages = sal_IntPtr(mpNupPagesBox->GetSelectedEntryData()); + int nRows = int(mpNupRowsEdt->GetValue()); + int nCols = int(mpNupColEdt->GetValue()); + long nPageMargin = mpPageMarginEdt->Denormalize(mpPageMarginEdt->GetValue( FUNIT_100TH_MM )); + long nSheetMargin = mpSheetMarginEdt->Denormalize(mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )); bool bCustom = false; if( nPages == 1 ) @@ -1546,8 +947,8 @@ void PrintDialog::updateNupFromPages() if( nSheetMargin > nVertMax ) nSheetMargin = nVertMax; - maNUpPage.mpSheetMarginEdt->SetMax( - maNUpPage.mpSheetMarginEdt->Normalize( + mpSheetMarginEdt->SetMax( + mpSheetMarginEdt->Normalize( std::min(nHorzMax, nVertMax) ), FUNIT_100TH_MM ); // maximum page distance @@ -1563,123 +964,81 @@ void PrintDialog::updateNupFromPages() if( nPageMargin > nVertMax ) nPageMargin = nVertMax; - maNUpPage.mpPageMarginEdt->SetMax( - maNUpPage.mpSheetMarginEdt->Normalize( + mpPageMarginEdt->SetMax( + mpSheetMarginEdt->Normalize( std::min(nHorzMax, nVertMax ) ), FUNIT_100TH_MM ); } - maNUpPage.mpNupRowsEdt->SetValue( nRows ); - maNUpPage.mpNupColEdt->SetValue( nCols ); - maNUpPage.mpPageMarginEdt->SetValue( maNUpPage.mpPageMarginEdt->Normalize( nPageMargin ), FUNIT_100TH_MM ); - maNUpPage.mpSheetMarginEdt->SetValue( maNUpPage.mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM ); + mpNupRowsEdt->SetValue( nRows ); + mpNupColEdt->SetValue( nCols ); + mpPageMarginEdt->SetValue( mpPageMarginEdt->Normalize( nPageMargin ), FUNIT_100TH_MM ); + mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM ); - maNUpPage.showAdvancedControls( bCustom ); + showAdvancedControls( bCustom ); updateNup(); } -#define SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT 1 -#define SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE 2 - -void PrintDialog::updateNup() +void PrintDialog::showAdvancedControls( bool i_bShow ) { - int nRows = int(maNUpPage.mpNupRowsEdt->GetValue()); - int nCols = int(maNUpPage.mpNupColEdt->GetValue()); - long nPageMargin = maNUpPage.mpPageMarginEdt->Denormalize(maNUpPage.mpPageMarginEdt->GetValue( FUNIT_100TH_MM )); - long nSheetMargin = maNUpPage.mpSheetMarginEdt->Denormalize(maNUpPage.mpSheetMarginEdt->GetValue( FUNIT_100TH_MM )); - - PrinterController::MultiPageSetup aMPS; - aMPS.nRows = nRows; - aMPS.nColumns = nCols; - aMPS.nLeftMargin = - aMPS.nTopMargin = - aMPS.nRightMargin = - aMPS.nBottomMargin = nSheetMargin; - - aMPS.nHorizontalSpacing = - aMPS.nVerticalSpacing = nPageMargin; - - aMPS.bDrawBorder = maNUpPage.mpBorderCB->IsChecked(); - - aMPS.nOrder = static_cast<NupOrderType>(maNUpPage.mpNupOrderBox->GetSelectedEntryPos()); - - int nOrientationMode = maNUpPage.mpNupOrientationBox->GetSelectedEntryPos(); - if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE ) - aMPS.aPaperSize = maNupLandscapeSize; - else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT ) - aMPS.aPaperSize = maNupPortraitSize; - else // automatic mode - { - // get size of first real page to see if it is portrait or landscape - // we assume same page sizes for all the pages for this - Size aPageSize = getJobPageSize(); - - Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows ); - if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape - aMPS.aPaperSize = maNupLandscapeSize; - else - aMPS.aPaperSize = maNupPortraitSize; - } - - maPController->setMultipage( aMPS ); + mpNupNumPagesTxt->Show( i_bShow ); + mpNupColEdt->Show( i_bShow ); + mpNupTimesTxt->Show( i_bShow ); + mpNupRowsEdt->Show( i_bShow ); + mpPageMarginTxt1->Show( i_bShow ); + mpPageMarginEdt->Show( i_bShow ); + mpPageMarginTxt2->Show( i_bShow ); + mpSheetMarginTxt1->Show( i_bShow ); + mpSheetMarginEdt->Show( i_bShow ); + mpSheetMarginTxt2->Show( i_bShow ); +} - maNUpPage.mpNupOrderWin->setValues( aMPS.nOrder, nCols, nRows ); +bool PrintDialog::isPrintToFile() +{ + return ( mpPrinters->GetSelectedEntryPos() == 0 ); +} - preparePreview( true, true ); +bool PrintDialog::isCollate() +{ + return mpCopyCountField->GetValue() > 1 && mpCollateBox->IsChecked(); } -IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) +bool PrintDialog::hasPreview() { - if( &rBox == maJobPage.mpPrinters ) - { + return mpPreviewBox->IsChecked(); +} - if ( rBox.GetSelectedEntryPos() != 0) - { - OUString aNewPrinter( rBox.GetSelectedEntry() ); - // set new printer - maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) ); - maPController->resetPrinterOptions( false ); - // update text fields - mpOKButton->SetText( maPrintText ); - updatePrinterText(); - preparePreview(); - } - else // print to file - { - // use the default printer or FIXME: the last used one? - maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) ); - mpOKButton->SetText( maPrintToFileText ); - maPController->resetPrinterOptions( true ); - preparePreview( true, true ); - } - } - else if( &rBox == maNUpPage.mpNupOrientationBox || &rBox == maNUpPage.mpNupOrderBox ) +PropertyValue* PrintDialog::getValueForWindow( vcl::Window* i_pWindow ) const +{ + PropertyValue* pVal = nullptr; + auto it = maControlToPropertyMap.find( i_pWindow ); + if( it != maControlToPropertyMap.end() ) { - updateNup(); + pVal = maPController->getValue( it->second ); + SAL_WARN_IF( !pVal, "vcl", "property value not found" ); } - else if( &rBox == maNUpPage.mpNupPagesBox ) + else { - if( !maNUpPage.mpPagesBtn->IsChecked() ) - maNUpPage.mpPagesBtn->Check(); - updateNupFromPages(); + OSL_FAIL( "changed control not in property map" ); } + return pVal; } -IMPL_LINK( PrintDialog, ToggleRadioHdl, RadioButton&, rButton, void ) +IMPL_LINK( PrintDialog, ToggleHdl, CheckBox&, rButton, void ) { - ClickHdl(static_cast<Button*>(&rButton)); + ClickHdl(&rButton); } -IMPL_LINK( PrintDialog, ToggleHdl, CheckBox&, rButton, void ) +IMPL_LINK( PrintDialog, ToggleRadioHdl, RadioButton&, rButton, void ) { - ClickHdl(&rButton); + ClickHdl(static_cast<Button*>(&rButton)); } -IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton, void ) +IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void ) { if( pButton == mpOKButton || pButton == mpCancelButton ) { - storeToSettings(); + //storeToSettings(); EndDialog( pButton == mpOKButton ? RET_OK : RET_CANCEL ); } else if( pButton == mpHelpButton ) @@ -1703,61 +1062,53 @@ IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton, void ) { previewBackward(); } - else if( pButton == maOptionsPage.mpPapersizeFromSetup ) - { - bool bChecked = maOptionsPage.mpPapersizeFromSetup->IsChecked(); - maPController->setPapersizeFromSetup( bChecked ); - maPController->setValue( "PapersizeFromSetup", - makeAny( bChecked ) ); - preparePreview( true, true ); - } - else if( pButton == maNUpPage.mpBrochureBtn ) + else if( pButton == mpBrochureBtn ) { PropertyValue* pVal = getValueForWindow( pButton ); if( pVal ) { - bool bVal = maNUpPage.mpBrochureBtn->IsChecked(); + bool bVal = mpBrochureBtn->IsChecked(); pVal->Value <<= bVal; - checkOptionalControlDependencies(); + //checkOptionalControlDependencies(); // update preview and page settings preparePreview(); } - if( maNUpPage.mpBrochureBtn->IsChecked() ) + if( mpBrochureBtn->IsChecked() ) { - maNUpPage.mpNupPagesBox->SelectEntryPos( 0 ); + mpNupPagesBox->SelectEntryPos( 0 ); updateNupFromPages(); - maNUpPage.showAdvancedControls( false ); - maNUpPage.enableNupControls( false ); + showAdvancedControls( false ); + //enableNupControls( false ); } } - else if( pButton == maNUpPage.mpPagesBtn ) + else if( pButton == mpPagesBtn ) { - maNUpPage.enableNupControls( true ); + //enableNupControls( true ); updateNupFromPages(); } - else if( pButton == maJobPage.mpCollateBox ) + else if( pButton == mpCollateBox ) { maPController->setValue( "Collate", makeAny( isCollate() ) ); checkControlDependencies(); } - else if( pButton == maJobPage.mpReverseOrderBox ) + else if( pButton == mpReverseOrderBox ) { - bool bChecked = maJobPage.mpReverseOrderBox->IsChecked(); + bool bChecked = mpReverseOrderBox->IsChecked(); maPController->setReversePrint( bChecked ); maPController->setValue( "PrintReverse", makeAny( bChecked ) ); preparePreview( true, true ); } - else if( pButton == maNUpPage.mpBorderCB ) + else if( pButton == mpBorderCB ) { updateNup(); } else { - if( pButton == maJobPage.mpSetupButton ) + if( pButton == mpSetupButton ) { maPController->setupPrinter(GetFrameWeld()); @@ -1766,233 +1117,69 @@ IMPL_LINK( PrintDialog, ClickHdl, Button*, pButton, void ) } checkControlDependencies(); } -} -IMPL_LINK( PrintDialog, ModifyHdl, Edit&, rEdit, void ) -{ - checkControlDependencies(); - if( &rEdit == maNUpPage.mpNupRowsEdt || &rEdit == maNUpPage.mpNupColEdt || - &rEdit == maNUpPage.mpSheetMarginEdt || &rEdit == maNUpPage.mpPageMarginEdt - ) - { - updateNupFromPages(); - } - else if( &rEdit == mpPageEdit ) - { - mnCurPage = sal_Int32( mpPageEdit->GetValue() - 1 ); - preparePreview( true, true ); - } - else if( &rEdit == maJobPage.mpCopyCountField ) - { - maPController->setValue( "CopyCount", - makeAny( sal_Int32(maJobPage.mpCopyCountField->GetValue()) ) ); - maPController->setValue( "Collate", - makeAny( isCollate() ) ); - } } -PropertyValue* PrintDialog::getValueForWindow( vcl::Window* i_pWindow ) const +IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) { - PropertyValue* pVal = nullptr; - auto it = maControlToPropertyMap.find( i_pWindow ); - if( it != maControlToPropertyMap.end() ) - { - pVal = maPController->getValue( it->second ); - SAL_WARN_IF( !pVal, "vcl", "property value not found" ); - } - else + if( &rBox == mpPrinters ) { - OSL_FAIL( "changed control not in property map" ); - } - return pVal; -} -void PrintDialog::updateWindowFromProperty( const OUString& i_rProperty ) -{ - beans::PropertyValue* pValue = maPController->getValue( i_rProperty ); - auto it = maPropertyToWindowMap.find( i_rProperty ); - if( pValue && it != maPropertyToWindowMap.end() ) - { - const std::vector< VclPtr<vcl::Window> >& rWindows( it->second ); - if( ! rWindows.empty() ) + if ( rBox.GetSelectedEntryPos() != 0) { - bool bVal = false; - sal_Int32 nVal = -1; - if( pValue->Value >>= bVal ) - { - // we should have a CheckBox for this one - CheckBox* pBox = dynamic_cast< CheckBox* >( rWindows.front().get() ); - if( pBox ) - { - pBox->Check( bVal ); - } - else if ( i_rProperty == "PrintProspect" ) - { - // EVIL special case - if( bVal ) - maNUpPage.mpBrochureBtn->Check(); - else - maNUpPage.mpPagesBtn->Check(); - } - else - { - SAL_WARN( "vcl", "missing a checkbox" ); - } - } - else if( pValue->Value >>= nVal ) - { - // this could be a ListBox or a RadioButtonGroup - ListBox* pList = dynamic_cast< ListBox* >( rWindows.front().get() ); - if( pList ) - { - pList->SelectEntryPos( static_cast< sal_uInt16 >(nVal) ); - } - else if( nVal >= 0 && nVal < sal_Int32(rWindows.size() ) ) - { - RadioButton* pBtn = dynamic_cast< RadioButton* >( rWindows[nVal].get() ); - SAL_WARN_IF( !pBtn, "vcl", "unexpected control for property" ); - if( pBtn ) - pBtn->Check(); - } - } + OUString aNewPrinter( rBox.GetSelectedEntry() ); + // set new printer + maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) ); + maPController->resetPrinterOptions( false ); + // update text fields + mpOKButton->SetText( maPrintText ); + updatePrinterText(); + preparePreview(); + } + else // print to file + { + // use the default printer or FIXME: the last used one? + maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) ); + mpOKButton->SetText( maPrintToFileText ); + maPController->resetPrinterOptions( true ); + preparePreview( true, true ); } } -} - -void PrintDialog::makeEnabled( vcl::Window* i_pWindow ) -{ - auto it = maControlToPropertyMap.find( i_pWindow ); - if( it != maControlToPropertyMap.end() ) + else if( &rBox == mpNupOrientationBox || &rBox == mpNupOrderBox ) { - OUString aDependency( maPController->makeEnabled( it->second ) ); - if( !aDependency.isEmpty() ) - updateWindowFromProperty( aDependency ); + updateNup(); } -} - -IMPL_LINK( PrintDialog, UIOption_CheckHdl, CheckBox&, i_rBox, void ) -{ - PropertyValue* pVal = getValueForWindow( &i_rBox ); - if( pVal ) + else if( &rBox == mpNupPagesBox ) { - makeEnabled( &i_rBox ); - - bool bVal = i_rBox.IsChecked(); - pVal->Value <<= bVal; - - checkOptionalControlDependencies(); - - // update preview and page settings - preparePreview(); - } -} - -IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton&, i_rBtn, void ) -{ - // this handler gets called for all radiobuttons that get unchecked, too - // however we only want one notification for the new value (that is for - // the button that gets checked) - if( i_rBtn.IsChecked() ) - { - PropertyValue* pVal = getValueForWindow( &i_rBtn ); - auto it = maControlToNumValMap.find( &i_rBtn ); - if( pVal && it != maControlToNumValMap.end() ) - { - makeEnabled( &i_rBtn ); - - sal_Int32 nVal = it->second; - pVal->Value <<= nVal; - - // tdf#63905 use paper size set in printer properties - if (pVal->Name == "PageOptions") - maPController->resetPaperToLastConfigured(); - - checkOptionalControlDependencies(); - - // update preview and page settings - preparePreview(); - } + if( !mpPagesBtn->IsChecked() ) + mpPagesBtn->Check(); + updateNupFromPages(); } } -IMPL_LINK( PrintDialog, UIOption_SelectHdl, ListBox&, i_rBox, void ) +IMPL_LINK( PrintDialog, ModifyHdl, Edit&, rEdit, void ) { - PropertyValue* pVal = getValueForWindow( &i_rBox ); - if( pVal ) + checkControlDependencies(); + if( &rEdit == mpNupRowsEdt || &rEdit == mpNupColEdt || + &rEdit == mpSheetMarginEdt || &rEdit == mpPageMarginEdt + ) { - makeEnabled( &i_rBox ); - - sal_Int32 nVal( i_rBox.GetSelectedEntryPos() ); - pVal->Value <<= nVal; - - //If we are in impress we start in print slides mode and get a - //maFirstPageSize for slides which are usually landscape mode, if we - //change to notes which are usually in portrait mode, and then visit - //n-up print, we will assume notes are in landscape unless we throw - //away maFirstPageSize when we change page content type - if (pVal->Name == "PageContentType") - maFirstPageSize = Size(); - - checkOptionalControlDependencies(); - - // update preview and page settings - preparePreview(); + updateNupFromPages(); } -} - -IMPL_LINK( PrintDialog, UIOption_ModifyHdl, Edit&, i_rBox, void ) -{ - PropertyValue* pVal = getValueForWindow( &i_rBox ); - if( pVal ) + else if( &rEdit == mpPageEdit ) { - makeEnabled( &i_rBox ); - - NumericField* pNum = dynamic_cast<NumericField*>(&i_rBox); - MetricField* pMetric = dynamic_cast<MetricField*>(&i_rBox); - if( pNum ) - { - sal_Int64 nVal = pNum->GetValue(); - pVal->Value <<= nVal; - } - else if( pMetric ) - { - sal_Int64 nVal = pMetric->GetValue(); - pVal->Value <<= nVal; - } - else - { - OUString aVal( i_rBox.GetText() ); - pVal->Value <<= aVal; - } - - checkOptionalControlDependencies(); - - // update preview and page settings - preparePreview(); + mnCurPage = sal_Int32( mpPageEdit->GetValue() - 1 ); + preparePreview( true, true ); } -} - -void PrintDialog::Command( const CommandEvent& rEvt ) -{ - if( rEvt.GetCommand() == CommandEventId::Wheel ) + else if( &rEdit == mpCopyCountField ) { - const CommandWheelData* pWheelData = rEvt.GetWheelData(); - if( pWheelData->GetDelta() > 0 ) - previewForward(); - else if( pWheelData->GetDelta() < 0 ) - previewBackward(); + maPController->setValue( "CopyCount", + makeAny( sal_Int32(mpCopyCountField->GetValue()) ) ); + maPController->setValue( "Collate", + makeAny( isCollate() ) ); } } -void PrintDialog::Resize() -{ - // maLayout.setManagedArea( Rectangle( Point( 0, 0 ), GetSizePixel() ) ); - // and do the preview; however the metafile does not need to be gotten anew - preparePreview( false ); - - Dialog::Resize(); -} - void PrintDialog::previewForward() { mpPageEdit->Up(); @@ -2003,6 +1190,7 @@ void PrintDialog::previewBackward() mpPageEdit->Down(); } + // PrintProgressDialog PrintProgressDialog::PrintProgressDialog(vcl::Window* i_pParent, int i_nMax) @@ -2022,8 +1210,8 @@ PrintProgressDialog::PrintProgressDialog(vcl::Window* i_pParent, int i_nMax) //just multiply largest value by 10 and take the width of that string as //the max size we will want - OUString aNewText( searchAndReplace( maStr, "%p", 2, OUString::number( mnMax * 10 ) ) ); - aNewText = searchAndReplace( aNewText, "%n", 2, OUString::number( mnMax * 10 ) ); + OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnMax * 10 ) ) ); + aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax * 10 ) ); mpText->SetText( aNewText ); mpText->set_width_request(mpText->get_preferred_size().Width()); @@ -2062,8 +1250,8 @@ void PrintProgressDialog::setProgress( int i_nCurrent ) mpProgress->SetValue(mnCur*100/mnMax); - OUString aNewText( searchAndReplace( maStr, "%p", 2, OUString::number( mnCur ) ) ); - aNewText = searchAndReplace( aNewText, "%n", 2, OUString::number( mnMax ) ); + OUString aNewText( maStr.replaceFirst( "%p", OUString::number( mnCur ) ) ); + aNewText = aNewText.replaceFirst( "%n", OUString::number( mnMax ) ); mpText->SetText( aNewText ); } @@ -2078,5 +1266,3 @@ void PrintProgressDialog::reset() mbCanceled = false; setProgress( 0 ); } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/uiconfig/ui/printdialog.ui b/vcl/uiconfig/ui/printdialog.ui index 47790fbcff83..7ffbf497a23c 100644 --- a/vcl/uiconfig/ui/printdialog.ui +++ b/vcl/uiconfig/ui/printdialog.ui @@ -4,24 +4,19 @@ <requires lib="gtk+" version="3.18"/> <requires lib="LibreOffice" version="1.0"/> <object class="GtkAdjustment" id="adjustment1"> - <property name="lower">1</property> - <property name="upper">16384</property> - <property name="value">1</property> + <property name="lower">10</property> + <property name="upper">200</property> + <property name="value">100</property> <property name="step_increment">1</property> <property name="page_increment">10</property> </object> <object class="GtkAdjustment" id="adjustment2"> <property name="lower">1</property> - <property name="upper">32</property> + <property name="upper">16384</property> <property name="value">1</property> <property name="step_increment">1</property> <property name="page_increment">10</property> </object> - <object class="GtkAdjustment" id="adjustment3"> - <property name="upper">100</property> - <property name="step_increment">1</property> - <property name="page_increment">10</property> - </object> <object class="GtkImage" id="image1"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -34,259 +29,313 @@ <property name="stock">gtk-media-next</property> <property name="icon_size">1</property> </object> - <object class="GtkListStore" id="liststore1"> - <columns> - <!-- column-name gchararray1 --> - <column type="gchararray"/> - <!-- column-name gint1 --> - <column type="gint"/> - </columns> - <data> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">1</col> - <col id="1">1</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">2</col> - <col id="1">2</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">4</col> - <col id="1">4</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">6</col> - <col id="1">6</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">9</col> - <col id="1">9</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">16</col> - <col id="1">16</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore1">Custom</col> - <col id="1">65535</col> - </row> - </data> - </object> - <object class="GtkListStore" id="liststore2"> - <columns> - <!-- column-name gchararray1 --> - <column type="gchararray"/> - </columns> - <data> - <row> - <col id="0" translatable="yes" context="printdialog|liststore2">left to right, then down</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore2">top to bottom, then right</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore2">top to bottom, then left</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore2">right to left, then down</col> - </row> - </data> - </object> - <object class="GtkListStore" id="liststore3"> - <columns> - <!-- column-name gchararray1 --> - <column type="gchararray"/> - </columns> - <data> - <row> - <col id="0" translatable="yes" context="printdialog|liststore3">Automatic</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore3">Portrait</col> - </row> - <row> - <col id="0" translatable="yes" context="printdialog|liststore3">Landscape</col> - </row> - </data> - </object> <object class="GtkDialog" id="PrintDialog"> <property name="can_focus">False</property> - <property name="border_width">6</property> - <property name="title" translatable="yes" context="printdialog|PrintDialog">Print</property> <property name="type_hint">dialog</property> <child internal-child="vbox"> - <object class="GtkBox" id="dialog-vbox1"> + <object class="GtkBox" id="PrintDialogBox"> <property name="can_focus">False</property> <property name="orientation">vertical</property> - <property name="spacing">12</property> + <property name="spacing">2</property> <child internal-child="action_area"> - <object class="GtkButtonBox" id="dialog-action_area1"> + <object class="GtkButtonBox" id="internalarea"> <property name="can_focus">False</property> <property name="layout_style">end</property> <child> - <object class="GtkButton" id="ok"> - <property name="label">gtk-ok</property> + <object class="GtkButton" id="help"> + <property name="label">gtk-help</property> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="has_default">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> - <property name="expand">False</property> + <property name="expand">True</property> <property name="fill">True</property> <property name="position">0</property> - <property name="non_homogeneous">True</property> + <property name="secondary">True</property> </packing> </child> <child> - <object class="GtkButton" id="cancel"> - <property name="label">gtk-cancel</property> + <object class="GtkButton" id="moreoptions"> + <property name="label" translatable="yes" context="printdialog|moreoptions">More Options...</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> - <property name="use_stock">True</property> + <property name="margin_left">50</property> + <property name="margin_right">50</property> </object> <packing> - <property name="expand">False</property> + <property name="expand">True</property> <property name="fill">True</property> <property name="position">1</property> - <property name="non_homogeneous">True</property> </packing> </child> <child> - <object class="GtkButton" id="help"> - <property name="label">gtk-help</property> + <object class="GtkButton" id="ok"> + <property name="label">gtk-ok</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="use_stock">True</property> </object> <packing> - <property name="expand">False</property> + <property name="expand">True</property> <property name="fill">True</property> <property name="position">2</property> - <property name="secondary">True</property> - <property name="non_homogeneous">True</property> + </packing> + </child> + <child> + <object class="GtkButton" id="cancel"> + <property name="label">gtk-cancel</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_stock">True</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">3</property> </packing> </child> </object> <packing> <property name="expand">False</property> - <property name="fill">True</property> - <property name="pack_type">end</property> - <property name="position">0</property> + <property name="fill">False</property> + <property name="position">1</property> </packing> </child> <child> - <object class="GtkBox" id="box1"> + <object class="GtkBox" id="box0"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="hexpand">True</property> - <property name="vexpand">True</property> - <property name="spacing">6</property> + <property name="margin_left">5</property> + <property name="margin_right">5</property> + <property name="margin_top">5</property> + <property name="margin_bottom">5</property> <child> - <object class="GtkBox" id="box2"> + <object class="GtkBox" id="box1"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="hexpand">True</property> - <property name="vexpand">True</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="vcllo-PrintPreviewWindow" id="preview"> - <property name="width_request">235</property> - <property name="height_request">331</property> - <property name="visible">True</property> - <property name="can_focus">False</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> <child> - <object class="GtkBox" id="box8"> + <object class="GtkBox" id="box2"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_left">30</property> - <property name="margin_right">30</property> + <property name="can_focus">True</property> + <property name="orientation">vertical</property> <property name="spacing">6</property> <child> - <object class="GtkSpinButton" id="pageedit-nospin"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="xalign">1</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="totalnumpages"> + <object class="GtkBox"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes" context="printdialog|totalnumpages">/ %n</property> + <property name="orientation">vertical</property> + <child> + <object class="vcllo-PrintPreviewWindow" id="preview"> + <property name="width_request">427</property> + <property name="height_request">600</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">1</property> + <property name="position">0</property> </packing> </child> <child> - <object class="GtkButton" id="forward"> + <object class="GtkCheckButton" id="previewbox"> + <property name="label" translatable="yes" context="printdialog|previewbox">Preview</property> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="image">image2</property> + <property name="receives_default">False</property> + <property name="halign">center</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> <property name="pack_type">end</property> - <property name="position">2</property> + <property name="position">1</property> </packing> </child> <child> - <object class="GtkButton" id="backward"> + <object class="GtkBox" id="box3"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="image">image1</property> + <property name="can_focus">False</property> + <property name="spacing">25</property> + <child> ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits