Kaydet (Commit) 07e4261c authored tarafından Daniel Silva's avatar Daniel Silva

Sets page orientation box in print dialog

Change-Id: If12b833db5db372738ce02d1ed0d77145f3ffa0f
Reviewed-on: https://gerrit.libreoffice.org/57131
Tested-by: Jenkins
Reviewed-by: 's avatarDaniel Silva <danielfaleirosilva@gmail.com>
üst cff219f7
......@@ -2368,6 +2368,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 );
}
......
......@@ -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();
......
......@@ -815,6 +815,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
......@@ -862,6 +863,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());
}
......
......@@ -58,8 +58,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 &)
......@@ -563,7 +564,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");
......@@ -689,7 +690,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 ) );
......@@ -701,7 +702,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();
}
......@@ -751,7 +752,7 @@ void PrintDialog::dispose()
mpSheetMarginEdt.clear();
mpSheetMarginTxt2.clear();
mpPaperSizeBox.clear();
mpNupOrientationBox.clear();
mpOrientationBox.clear();
mpNupOrderBox.clear();
mpNupOrderWin.clear();
mpNupOrderTxt.clear();
......@@ -1008,6 +1009,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()
{
......@@ -1106,7 +1145,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());
......@@ -1128,10 +1167,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
{
......@@ -1141,19 +1180,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());
......@@ -1251,7 +1296,7 @@ void PrintDialog::updateNupFromPages()
mpSheetMarginEdt->SetValue( mpSheetMarginEdt->Normalize( nSheetMargin ), FUNIT_100TH_MM );
showAdvancedControls( bCustom );
updateNup();
updateNup( i_bMayUseCache );
}
void PrintDialog::enableNupControls( bool bEnable )
......@@ -1823,6 +1868,8 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void )
}
if( mpBrochureBtn->IsChecked() )
{
mpOrientationBox->Enable( false );
mpOrientationBox->SelectEntryPos( ORIENTATION_LANDSCAPE );
mpNupPagesBox->SelectEntryPos( 0 );
updateNupFromPages();
showAdvancedControls( false );
......@@ -1831,6 +1878,8 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void )
}
else if( pButton == mpPagesBtn )
{
mpOrientationBox->Enable( true );
mpOrientationBox->SelectEntryPos( ORIENTATION_AUTOMATIC );
enableNupControls( true );
updateNupFromPages();
}
......@@ -1881,6 +1930,9 @@ IMPL_LINK ( PrintDialog, ClickHdl, Button*, pButton, void )
}
}
}
updateOrientationBox( false );
// tdf#63905 don't use cache: page size may change
preparePreview();
}
......@@ -1899,6 +1951,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();
......@@ -1911,7 +1966,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 );
}
......@@ -1922,15 +1979,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 )
{
......@@ -2009,6 +2074,8 @@ IMPL_LINK( PrintDialog, UIOption_RadioHdl, RadioButton&, i_rBtn, void )
if (pVal->Name == "PageOptions")
maPController->resetPaperToLastConfigured();
updateOrientationBox();
checkOptionalControlDependencies();
// update preview and page settings
......
......@@ -87,12 +87,29 @@
</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>
......@@ -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>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment