sw/source/uibase/uno/unotxdoc.cxx | 57 +++++++++++++++++---- vcl/inc/printdlg.hxx | 9 ++- vcl/source/gdi/print3.cxx | 2 vcl/source/window/printdlg.cxx | 99 +++++++++++++++++++++++++++++++------- vcl/uiconfig/ui/printdialog.ui | 20 +++++++ 5 files changed, 155 insertions(+), 32 deletions(-)
New commits: commit 484843082084060ffd8b5c079da721093820bf21 Author: Daniel Silva <danielfaleirosi...@gmail.com> AuthorDate: Sat Jul 7 09:42:07 2018 -0300 Commit: Daniel Silva <danielfaleirosi...@gmail.com> CommitDate: Sat Aug 11 15:50:45 2018 +0200 Sets page orientation box in print dialog Change-Id: If12b833db5db372738ce02d1ed0d77145f3ffa0f Reviewed-on: https://gerrit.libreoffice.org/57131 Tested-by: Jenkins Reviewed-by: Daniel Silva <danielfaleirosi...@gmail.com> diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 0a22921c96e6..ac47ce2e78d0 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -2367,6 +2367,43 @@ static bool lcl_SeqHasProperty( return bRes; } +static bool lcl_GetBoolProperty( + const uno::Sequence< beans::PropertyValue >& rOptions, + const sal_Char *pPropName ) +{ + bool bRes = false; + const sal_Int32 nLen = rOptions.getLength(); + const beans::PropertyValue *pProps = rOptions.getConstArray(); + for ( sal_Int32 i = 0; i < nLen; ++i ) + { + if ( pProps[i].Name.equalsAscii( pPropName ) ) + { + pProps[i].Value >>= bRes; + break; + } + } + return bRes; +} + +static sal_Int32 lcl_GetIntProperty( + const uno::Sequence< beans::PropertyValue >& rOptions, + const sal_Char *pPropName, + sal_Int32 nDefault ) +{ + sal_Int32 nRes = nDefault; + const sal_Int32 nLen = rOptions.getLength(); + const beans::PropertyValue *pProps = rOptions.getConstArray(); + for ( sal_Int32 i = 0; i < nLen; ++i ) + { + if ( pProps[i].Name.equalsAscii( pPropName ) ) + { + pProps[i].Value >>= nRes; + break; + } + } + return nRes; +} + SfxViewShell * SwXTextDocument::GetRenderView( bool &rbIsSwSrcView, const uno::Sequence< beans::PropertyValue >& rOptions, @@ -2561,6 +2598,13 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( if (!pViewShell || !pViewShell->GetLayout()) return 0; + // make sure document orientation matches printer paper orientation + sal_Int32 nLandscape = lcl_GetIntProperty( rxOptions, "IsLandscape", -1 ); + if ( nLandscape == 1 ) + pViewShell->ChgAllPageOrientation( Orientation::Landscape ); + else if ( nLandscape == 0 ) + pViewShell->ChgAllPageOrientation( Orientation::Portrait ); + if (bFormat) { // #i38289 @@ -2603,18 +2647,7 @@ sal_Int32 SAL_CALL SwXTextDocument::getRendererCount( ? nullptr : m_pRenderData->GetSwPrtOptions(); bool setShowPlaceHoldersInPDF = false; if(bIsPDFExport) - { - const sal_Int32 nLen = rxOptions.getLength(); - const beans::PropertyValue *pProps = rxOptions.getConstArray(); - for (sal_Int32 i = 0; i < nLen; ++i) - { - if (pProps[i].Name == "ExportPlaceholders") - { - pProps[i].Value >>= setShowPlaceHoldersInPDF; - break; - } - } - } + setShowPlaceHoldersInPDF = lcl_GetBoolProperty( rxOptions, "ExportPlaceholders" ); m_pRenderData->ViewOptionAdjust( pPrtOptions, setShowPlaceHoldersInPDF ); } diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx index 3edc2ceb3c69..3b6ad1827fa3 100644 --- a/vcl/inc/printdlg.hxx +++ b/vcl/inc/printdlg.hxx @@ -186,7 +186,7 @@ namespace vcl VclPtr<MetricField> mpSheetMarginEdt; VclPtr<FixedText> mpSheetMarginTxt2; VclPtr<ListBox> mpPaperSizeBox; - VclPtr<ListBox> mpNupOrientationBox; + VclPtr<ListBox> mpOrientationBox; // page order ("left to right, then down") VclPtr<FixedText> mpNupOrderTxt; @@ -230,6 +230,9 @@ namespace vcl void setupPaperSidesBox(); void storeToSettings(); void readFromSettings(); + void setPaperOrientation( Orientation eOrientation ); + void updateOrientationBox( bool bAutomatic = true ); + bool hasOrientationChanged() const; void setPreviewText(); void updatePrinterText(); void checkControlDependencies(); @@ -238,8 +241,8 @@ namespace vcl void updateWindowFromProperty( const OUString& ); void initFromMultiPageSetup( const vcl::PrinterController::MultiPageSetup& ); void showAdvancedControls( bool ); - void updateNup(); - void updateNupFromPages(); + void updateNup( bool i_bMayUseCache = true ); + void updateNupFromPages( bool i_bMayUseCache = true ); void enableNupControls( bool bEnable ); void setupOptionalUI(); Size const & getJobPageSize(); diff --git a/vcl/source/gdi/print3.cxx b/vcl/source/gdi/print3.cxx index 0405aeecabfb..b56a5740a5fd 100644 --- a/vcl/source/gdi/print3.cxx +++ b/vcl/source/gdi/print3.cxx @@ -817,6 +817,7 @@ void PrinterController::setupPrinter( weld::Window* i_pParent ) // get current data Size aPaperSize(xPrinter->GetPaperSize()); + Orientation eOrientation = xPrinter->GetOrientation(); sal_uInt16 nPaperBin = xPrinter->GetPaperBin(); // reset paper size back to last configured size, not @@ -864,6 +865,7 @@ void PrinterController::setupPrinter( weld::Window* i_pParent ) else { //restore to whatever it was before we entered this method + xPrinter->SetOrientation( eOrientation ); if (aPaperSize != aNewPaperSize) xPrinter->SetPaperSizeUser(aPaperSize, !mpImplData->isFixedPageSize()); } diff --git a/vcl/source/window/printdlg.cxx b/vcl/source/window/printdlg.cxx index 4546a8ff000f..8308f11f7272 100644 --- a/vcl/source/window/printdlg.cxx +++ b/vcl/source/window/printdlg.cxx @@ -56,8 +56,9 @@ using namespace com::sun::star::beans; enum { - SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT, - SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE + ORIENTATION_AUTOMATIC, + ORIENTATION_PORTRAIT, + ORIENTATION_LANDSCAPE }; extern "C" SAL_DLLPUBLIC_EXPORT void makePrintPreviewWindow(VclPtr<vcl::Window> & rRet, VclPtr<vcl::Window> & pParent, VclBuilder::stringmap &) @@ -561,7 +562,7 @@ PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterCo get(mpCopyCountField, "copycount"); get(mpNupOrderWin, "orderpreview"); get(mpNupPagesBox, "pagespersheetbox"); - get(mpNupOrientationBox, "pageorientationbox"); + get(mpOrientationBox, "pageorientationbox"); get(mpNupOrderTxt, "labelorder"); get(mpPaperSizeBox, "papersizebox"); get(mpNupOrderBox, "orderbox"); @@ -688,7 +689,7 @@ PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterCo mpPrinters->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); mpPaperSidesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); mpNupPagesBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); - mpNupOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); + mpOrientationBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); mpNupOrderBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); mpPaperSizeBox->SetSelectHdl( LINK( this, PrintDialog, SelectHdl ) ); @@ -700,7 +701,7 @@ PrintDialog::PrintDialog(vcl::Window* i_pWindow, const std::shared_ptr<PrinterCo mpPageMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); mpSheetMarginEdt->SetModifyHdl( LINK( this, PrintDialog, ModifyHdl ) ); - preparePreview( true, true ); + updateNupFromPages(); } @@ -750,7 +751,7 @@ void PrintDialog::dispose() mpSheetMarginEdt.clear(); mpSheetMarginTxt2.clear(); mpPaperSizeBox.clear(); - mpNupOrientationBox.clear(); + mpOrientationBox.clear(); mpNupOrderBox.clear(); mpNupOrderWin.clear(); mpNupOrderTxt.clear(); @@ -1007,6 +1008,44 @@ void PrintDialog::preparePreview( bool i_bNewPage, bool i_bMayUseCache ) } } +void PrintDialog::updateOrientationBox( const bool bAutomatic ) +{ + Orientation eOrientation = maPController->getPrinter()->GetOrientation(); + if ( !bAutomatic ) + { + mpOrientationBox->SelectEntryPos( static_cast<sal_Int32>(eOrientation) + 1 ); + + maPController->setValue( "IsLandscape", + makeAny( static_cast<sal_Int32>(eOrientation) ) ); + } + else if ( hasOrientationChanged() ) + { + mpOrientationBox->SelectEntryPos( ORIENTATION_AUTOMATIC ); + + // used to make sure document orientation matches printer paper orientation + maPController->setValue( "IsLandscape", + makeAny( static_cast<sal_Int32>(eOrientation) ) ); + } +} + +bool PrintDialog::hasOrientationChanged() const +{ + const int nOrientation = mpOrientationBox->GetSelectedEntryPos(); + const Orientation eOrientation = maPController->getPrinter()->GetOrientation(); + + return (nOrientation == ORIENTATION_LANDSCAPE && eOrientation == Orientation::Portrait) + || (nOrientation == ORIENTATION_PORTRAIT && eOrientation == Orientation::Landscape); +} + +// Always use this function to set paper orientation in +// order to update document orientation as well +void PrintDialog::setPaperOrientation( Orientation eOrientation ) +{ + maPController->getPrinter()->SetOrientation( eOrientation ); + maPController->setValue( "IsLandscape", + makeAny( static_cast<sal_Int32>(eOrientation) ) ); +} + void PrintDialog::checkControlDependencies() { @@ -1105,7 +1144,7 @@ void PrintDialog::initFromMultiPageSetup( const vcl::PrinterController::MultiPag } } -void PrintDialog::updateNup() +void PrintDialog::updateNup( bool i_bMayUseCache ) { int nRows = int(mpNupRowsEdt->GetValue()); int nCols = int(mpNupColEdt->GetValue()); @@ -1127,10 +1166,10 @@ void PrintDialog::updateNup() aMPS.nOrder = static_cast<NupOrderType>(mpNupOrderBox->GetSelectedEntryPos()); - int nOrientationMode = mpNupOrientationBox->GetSelectedEntryPos(); - if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_LANDSCAPE ) + int nOrientationMode = mpOrientationBox->GetSelectedEntryPos(); + if( nOrientationMode == ORIENTATION_LANDSCAPE ) aMPS.aPaperSize = maNupLandscapeSize; - else if( nOrientationMode == SV_PRINT_PRT_NUP_ORIENTATION_PORTRAIT ) + else if( nOrientationMode == ORIENTATION_PORTRAIT ) aMPS.aPaperSize = maNupPortraitSize; else // automatic mode { @@ -1140,19 +1179,25 @@ void PrintDialog::updateNup() Size aMultiSize( aPageSize.Width() * nCols, aPageSize.Height() * nRows ); if( aMultiSize.Width() > aMultiSize.Height() ) // fits better on landscape + { aMPS.aPaperSize = maNupLandscapeSize; + setPaperOrientation( Orientation::Landscape ); + } else + { aMPS.aPaperSize = maNupPortraitSize; + setPaperOrientation( Orientation::Portrait ); + } } maPController->setMultipage( aMPS ); mpNupOrderWin->setValues( aMPS.nOrder, nCols, nRows ); - preparePreview( true, true ); + preparePreview( true, i_bMayUseCache ); } -void PrintDialog::updateNupFromPages() +void PrintDialog::updateNupFromPages( bool i_bMayUseCache ) { sal_IntPtr nPages = sal_IntPtr(mpNupPagesBox->GetSelectedEntryData()); int nRows = int(mpNupRowsEdt->GetValue()); @@ -1250,7 +1295,7 @@ void PrintDialog::updateNupFromPages() mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM ); showAdvancedControls( bCustom ); - updateNup(); + updateNup( i_bMayUseCache ); } void PrintDialog::enableNupControls( bool bEnable ) @@ -1822,6 +1867,8 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void ) } if( mpBrochureBtn->IsChecked() ) { + mpOrientationBox->Enable( false ); + mpOrientationBox->SelectEntryPos( ORIENTATION_LANDSCAPE ); mpNupPagesBox->SelectEntryPos( 0 ); updateNupFromPages(); showAdvancedControls( false ); @@ -1830,6 +1877,8 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void ) } else if( pButton == mpPagesBtn ) { + mpOrientationBox->Enable( true ); + mpOrientationBox->SelectEntryPos( ORIENTATION_AUTOMATIC ); enableNupControls( true ); updateNupFromPages(); } @@ -1880,6 +1929,9 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void ) } } } + + updateOrientationBox( false ); + // tdf#63905 don't use cache: page size may change preparePreview(); } @@ -1898,6 +1950,9 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) // set new printer maPController->setPrinter( VclPtrInstance<Printer>( aNewPrinter ) ); maPController->resetPrinterOptions( false ); + + updateOrientationBox(); + // update text fields mpOKButton->SetText( maPrintText ); updatePrinterText(); @@ -1910,7 +1965,9 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) maPController->setPrinter( VclPtrInstance<Printer>( Printer::GetDefaultPrinterName() ) ); mpOKButton->SetText( maPrintToFileText ); maPController->resetPrinterOptions( true ); + setPaperSizes(); + updateOrientationBox(); preparePreview( true, true ); } @@ -1921,15 +1978,23 @@ IMPL_LINK( PrintDialog, SelectHdl, ListBox&, rBox, void ) DuplexMode eDuplex = static_cast<DuplexMode>(mpPaperSidesBox->GetSelectedEntryPos() + 1); maPController->getPrinter()->SetDuplexMode( eDuplex ); } - else if( &rBox == mpNupOrientationBox || &rBox == mpNupOrderBox ) + else if( &rBox == mpOrientationBox ) { - updateNup(); + int nOrientation = mpOrientationBox->GetSelectedEntryPos(); + if ( nOrientation != ORIENTATION_AUTOMATIC ) + setPaperOrientation( static_cast<Orientation>( nOrientation - 1 ) ); + + updateNup( false ); + } + else if ( &rBox == mpNupOrderBox ) + { + updateNup(); } else if( &rBox == mpNupPagesBox ) { if( !mpPagesBtn->IsChecked() ) mpPagesBtn->Check(); - updateNupFromPages(); + updateNupFromPages( false ); } else if ( &rBox == mpPaperSizeBox ) { @@ -2008,6 +2073,8 @@ IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton&, i_rBtn, void ) if (pVal->Name == "PageOptions") maPController->resetPaperToLastConfigured(); + updateOrientationBox(); + checkOptionalControlDependencies(); // update preview and page settings diff --git a/vcl/uiconfig/ui/printdialog.ui b/vcl/uiconfig/ui/printdialog.ui index 2e5118c24cd4..f3ec99e83817 100644 --- a/vcl/uiconfig/ui/printdialog.ui +++ b/vcl/uiconfig/ui/printdialog.ui @@ -87,13 +87,30 @@ </row> </data> </object> - <object class="GtkListStore" id="liststore4"> + <object class="GtkListStore" id="liststore3"> <columns> <!-- column-name gchararray --> <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="GtkListStore" id="liststore4"> + <columns> + <!-- column-name gchararray --> + <column type="gchararray"/> + </columns> + <data> + <row> <col id="0" translatable="yes" context="printdialog|liststore4">Print only in one side</col> </row> <row> @@ -878,6 +895,7 @@ <object class="GtkComboBox" id="pageorientationbox"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="model">liststore3</property> </object> <packing> <property name="left_attach">1</property> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits