summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTibor Nagy <tibor.nagy.extern@allotropia.de>2024-01-31 16:49:24 +0100
committerNagy Tibor <tibor.nagy.extern@allotropia.de>2024-02-09 12:06:01 +0100
commita67cd7b3cf03163f87811f7080cabc49750c4fd5 (patch)
treedcafe31ec7a97310ae2d94b822924769d50f9cb9 /sc
parent7327752ef5d1fa2239cdd8355fb78da41c282717 (diff)
tdf#155218 sc: fix different page orientation in print dialog
The page orientation is correct if you set it in the page style first. However, if you change it in the Print dialog the page layout and size refresh but the content orientation remains the same. Change-Id: I5e494a0714e398221bee00744d7e25c419a41df7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162845 Tested-by: Jenkins Reviewed-by: Nagy Tibor <tibor.nagy.extern@allotropia.de>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/uitest/calc_dialogs/printDialog.py38
-rw-r--r--sc/qa/uitest/data/tdf155218.odsbin0 -> 9753 bytes
-rw-r--r--sc/source/ui/inc/pfuncache.hxx7
-rw-r--r--sc/source/ui/inc/printfun.hxx18
-rw-r--r--sc/source/ui/unoobj/docuno.cxx53
-rw-r--r--sc/source/ui/view/pfuncache.cxx15
-rw-r--r--sc/source/ui/view/printfun.cxx41
7 files changed, 143 insertions, 29 deletions
diff --git a/sc/qa/uitest/calc_dialogs/printDialog.py b/sc/qa/uitest/calc_dialogs/printDialog.py
new file mode 100644
index 000000000000..3e1290b9c8af
--- /dev/null
+++ b/sc/qa/uitest/calc_dialogs/printDialog.py
@@ -0,0 +1,38 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file, select_by_text
+
+class printDialog(UITestCase):
+ def test_printDialog(self):
+ with self.ui_test.load_file(get_url_for_data_file("tdf155218.ods")):
+ with self.ui_test.execute_dialog_through_command(".uno:Print", close_button="cancel") as xDialog:
+
+ xPortraiTotalNumberPages = xDialog.getChild("totalnumpages")
+ self.assertEqual(get_state_as_dict(xPortraiTotalNumberPages)["Text"], "/ 2")
+
+ xPortraiPageRange = xDialog.getChild("pagerange")
+ self.assertEqual(get_state_as_dict(xPortraiPageRange)["Text"], "1-2")
+
+ xpageorientationbox = xDialog.getChild("pageorientationbox")
+ select_by_text(xpageorientationbox, "Landscape")
+
+ # Without the fix in place, this test would have failed with
+ # Expected: "/ 1"
+ # Actual : "/ 2"
+ xLandscapeTotalNumberPages = xDialog.getChild("totalnumpages")
+ self.assertEqual(get_state_as_dict(xLandscapeTotalNumberPages)["Text"], "/ 1")
+
+ # Without the fix in place, this test would have failed with
+ # Expected: "1"
+ # Actual : "1-2"
+ xLandscapePageRange = xDialog.getChild("pagerange")
+ self.assertEqual(get_state_as_dict(xLandscapePageRange)["Text"], "1")
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sc/qa/uitest/data/tdf155218.ods b/sc/qa/uitest/data/tdf155218.ods
new file mode 100644
index 000000000000..cd6417973972
--- /dev/null
+++ b/sc/qa/uitest/data/tdf155218.ods
Binary files differ
diff --git a/sc/source/ui/inc/pfuncache.hxx b/sc/source/ui/inc/pfuncache.hxx
index 5621cd2628ac..7cd286f39223 100644
--- a/sc/source/ui/inc/pfuncache.hxx
+++ b/sc/source/ui/inc/pfuncache.hxx
@@ -90,10 +90,13 @@ class ScPrintFuncCache
std::vector<tools::Long> nFirstAttr;
std::vector<ScPrintPageLocation> aLocations;
bool bLocInitialized;
+ Size aPrintPageSize; // print page size in Print dialog
+ bool bPrintPageLandscape; // print page orientation in Print dialog
+ bool bUsePrintDialogSetting; // use Print dialog setting
public:
- ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
- ScPrintSelectionStatus aStatus );
+ ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark, ScPrintSelectionStatus aStatus,
+ Size aPageSize = {}, bool bLandscape = false, bool bUse = false);
~ScPrintFuncCache();
bool IsSameSelection( const ScPrintSelectionStatus& rStatus ) const;
diff --git a/sc/source/ui/inc/printfun.hxx b/sc/source/ui/inc/printfun.hxx
index f9780bd0e53c..2e9dd7bb49d1 100644
--- a/sc/source/ui/inc/printfun.hxx
+++ b/sc/source/ui/inc/printfun.hxx
@@ -312,15 +312,25 @@ private:
ScPageBreakData* pPageData; // for recording the breaks etc.
+ Size aPrintPageSize; // print page size in Print dialog
+ bool bPrintPageLandscape; // print page orientation in Print dialog
+ bool bUsePrintDialogSetting; // use Print dialog setting
+
public:
ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
tools::Long nPage = 0, tools::Long nDocP = 0,
const ScRange* pArea = nullptr,
const ScPrintOptions* pOptions = nullptr,
- ScPageBreakData* pData = nullptr );
+ ScPageBreakData* pData = nullptr,
+ Size aPrintPageSize = {},
+ bool bPrintPageLandscape = false,
+ bool bUsePrintDialogSetting = false );
ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter,
- const ScPrintState& rState, const ScPrintOptions* pOptions );
+ const ScPrintState& rState, const ScPrintOptions* pOptions,
+ Size aPrintPageSize = {},
+ bool bPrintPageLandscape = false,
+ bool bUsePrintDialogSetting = false );
// ctors for device other than printer - for preview and pdf:
@@ -331,7 +341,9 @@ public:
ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
const ScPrintState& rState,
- const ScPrintOptions* pOptions );
+ const ScPrintOptions* pOptions, Size aPrintPageSize = {},
+ bool bPrintPageLandscape = false,
+ bool bUsePrintDialogSetting = false);
~ScPrintFunc();
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index f92864e76ece..e45ef91d2246 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1615,6 +1615,24 @@ static bool lcl_ParseTarget( const OUString& rTarget, ScRange& rTargetRange, too
return bRangeValid;
}
+ static void lcl_SetPrintPage(const uno::Sequence<beans::PropertyValue>& rOptions, Size& aSize,
+ bool& bLandscape, bool& bUsed)
+{
+ OutputDevice* pDev = lcl_GetRenderDevice(rOptions);
+ if (pDev && pDev->GetOutDevType() == OUTDEV_PRINTER)
+ {
+ Printer* pPrinter = dynamic_cast<Printer*>(pDev);
+ if (pPrinter && pPrinter->IsUsePrintDialogSetting())
+ {
+ bUsed = true;
+ bLandscape = (pPrinter->GetOrientation() == Orientation::Landscape);
+ aSize = pPrinter->GetPrintPageSize();
+ aSize.setWidth(o3tl::convert(aSize.Width(), o3tl::Length::mm100, o3tl::Length::twip));
+ aSize.setHeight(o3tl::convert(aSize.Height(), o3tl::Length::mm100, o3tl::Length::twip));
+ }
+ }
+}
+
bool ScModelObj::FillRenderMarkData( const uno::Any& aSelection,
const uno::Sequence< beans::PropertyValue >& rOptions,
ScMarkData& rMark,
@@ -1801,13 +1819,19 @@ sal_Int32 SAL_CALL ScModelObj::getRendererCount(const uno::Any& aSelection,
if ( !FillRenderMarkData( aSelection, rOptions, aMark, aStatus, aPagesStr, bRenderToGraphic ) )
return 0;
+ Size aPrintPageSize;
+ bool bPrintPageLandscape = false;
+ bool bUsePrintDialogSetting = false;
+ lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting);
+
// The same ScPrintFuncCache object in pPrintFuncCache is used as long as
// the same selection is used (aStatus) and the document isn't changed
// (pPrintFuncCache is cleared in Notify handler)
- if ( !pPrintFuncCache || !pPrintFuncCache->IsSameSelection( aStatus ) )
+ if (!pPrintFuncCache || !pPrintFuncCache->IsSameSelection(aStatus) || bUsePrintDialogSetting)
{
- pPrintFuncCache.reset(new ScPrintFuncCache( pDocShell, aMark, aStatus ));
+ pPrintFuncCache.reset(new ScPrintFuncCache(pDocShell, aMark, aStatus, aPrintPageSize,
+ bPrintPageLandscape, bUsePrintDialogSetting));
}
sal_Int32 nPages = pPrintFuncCache->GetPageCount();
@@ -2033,12 +2057,23 @@ uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32
}
else
{
+ Size aPrintPageSize;
+ bool bPrintPageLandscape = false;
+ bool bUsePrintDialogSetting = false;
+ lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting);
+
std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc;
if (m_pPrintState && m_pPrintState->nPrintTab == nTab)
- pPrintFunc.reset(new ScPrintFunc(pDocShell, pDocShell->GetPrinter(), *m_pPrintState, &aStatus.GetOptions()));
+ pPrintFunc.reset(new ScPrintFunc(pDocShell, pDocShell->GetPrinter(), *m_pPrintState,
+ &aStatus.GetOptions(), aPrintPageSize,
+ bPrintPageLandscape,
+ bUsePrintDialogSetting));
else
pPrintFunc.reset(new ScPrintFunc(pDocShell, pDocShell->GetPrinter(), nTab,
- pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions()));
+ pPrintFuncCache->GetFirstAttr(nTab), nTotalPages,
+ pSelRange, &aStatus.GetOptions(), nullptr,
+ aPrintPageSize, bPrintPageLandscape,
+ bUsePrintDialogSetting));
pPrintFunc->SetRenderFlag( true );
sal_Int32 nContent = 0;
@@ -2443,14 +2478,20 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec
aDrawViewKeeper.mpDrawView->SetPrintPreview();
}
+ Size aPrintPageSize;
+ bool bPrintPageLandscape = false;
+ bool bUsePrintDialogSetting = false;
+ lcl_SetPrintPage(rOptions, aPrintPageSize, bPrintPageLandscape, bUsePrintDialogSetting);
+
// to increase performance, ScPrintState might be used here for subsequent
// pages of the same sheet
-
std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc;
if (m_pPrintState && m_pPrintState->nPrintTab == nTab
&& ! pSelRange) // tdf#120161 use selection to set required printed area
- pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, *m_pPrintState, &aStatus.GetOptions()));
+ pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, *m_pPrintState, &aStatus.GetOptions(),
+ aPrintPageSize, bPrintPageLandscape,
+ bUsePrintDialogSetting));
else
pPrintFunc.reset(new ScPrintFunc(pDev, pDocShell, nTab, pPrintFuncCache->GetFirstAttr(nTab), nTotalPages, pSelRange, &aStatus.GetOptions()));
diff --git a/sc/source/ui/view/pfuncache.cxx b/sc/source/ui/view/pfuncache.cxx
index fe563ba961df..078633da5da0 100644
--- a/sc/source/ui/view/pfuncache.cxx
+++ b/sc/source/ui/view/pfuncache.cxx
@@ -27,12 +27,17 @@
#include <prevloc.hxx>
#include <utility>
-ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
- ScPrintSelectionStatus aStatus ) :
+ScPrintFuncCache::ScPrintFuncCache(ScDocShell* pD, const ScMarkData& rMark,
+ ScPrintSelectionStatus aStatus, Size aPageSize, bool bLandscape,
+ bool bUsed)
+ :
aSelection(std::move( aStatus )),
pDocSh( pD ),
nTotalPages( 0 ),
- bLocInitialized( false )
+ bLocInitialized( false ),
+ aPrintPageSize( aPageSize ),
+ bPrintPageLandscape( bLandscape ),
+ bUsePrintDialogSetting( bUsed )
{
// page count uses the stored cell widths for the printer anyway,
// so ScPrintFunc with the document's printer can be used to count
@@ -62,7 +67,9 @@ ScPrintFuncCache::ScPrintFuncCache( ScDocShell* pD, const ScMarkData& rMark,
tools::Long nThisTab = 0;
if ( rMark.GetTableSelect( nTab ) )
{
- ScPrintFunc aFunc( pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange, &aSelection.GetOptions() );
+ ScPrintFunc aFunc(pDocSh, pPrinter, nTab, nAttrPage, 0, pSelRange,
+ &aSelection.GetOptions(), nullptr, aPrintPageSize,
+ bPrintPageLandscape, bUsePrintDialogSetting);
nThisTab = aFunc.GetTotalPages();
nFirstAttr.push_back( aFunc.GetFirstPageNo() ); // from page style or previous sheet
}
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 86a8fff947f3..a4e934280a28 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -196,10 +196,9 @@ void ScPrintFunc::Construct( const ScPrintOptions* pOptions )
pPageData = nullptr; // is only needed for initialisation
}
-ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab,
- tools::Long nPage, tools::Long nDocP, const ScRange* pArea,
- const ScPrintOptions* pOptions,
- ScPageBreakData* pData )
+ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTab, tools::Long nPage,
+ tools::Long nDocP, const ScRange* pArea, const ScPrintOptions* pOptions,
+ ScPageBreakData* pData, Size aSize, bool bPrintLandscape, bool bUsed)
: pDocShell ( pShell ),
rDoc(pDocShell->GetDocument()),
pPrinter ( pNewPrinter ),
@@ -216,7 +215,10 @@ ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTa
nTabPages ( 0 ),
nTotalPages ( 0 ),
bPrintAreaValid ( false ),
- pPageData ( pData )
+ pPageData ( pData ),
+ aPrintPageSize ( aSize ),
+ bPrintPageLandscape ( bPrintLandscape ),
+ bUsePrintDialogSetting ( bUsed )
{
pDev = pPrinter.get();
aSrcOffset = pPrinter->PixelToLogic(pPrinter->GetPageOffsetPixel(), MapMode(MapUnit::Map100thMM));
@@ -226,8 +228,9 @@ ScPrintFunc::ScPrintFunc( ScDocShell* pShell, SfxPrinter* pNewPrinter, SCTAB nTa
Construct( pOptions );
}
-ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
- const ScPrintState& rState, const ScPrintOptions* pOptions)
+ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter, const ScPrintState& rState,
+ const ScPrintOptions* pOptions, Size aSize, bool bPrintLandscape,
+ bool bUsed)
: pDocShell ( pShell ),
rDoc(pDocShell->GetDocument()),
pPrinter ( pNewPrinter ),
@@ -237,7 +240,10 @@ ScPrintFunc::ScPrintFunc(ScDocShell* pShell, SfxPrinter* pNewPrinter,
bPrintCurrentTable ( false ),
bMultiArea ( false ),
mbHasPrintRange(true),
- pPageData ( nullptr )
+ pPageData ( nullptr ),
+ aPrintPageSize ( aSize ),
+ bPrintPageLandscape ( bPrintLandscape ),
+ bUsePrintDialogSetting ( bUsed )
{
pDev = pPrinter.get();
@@ -294,7 +300,10 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
nTabPages ( 0 ),
nTotalPages ( 0 ),
bPrintAreaValid ( false ),
- pPageData ( nullptr )
+ pPageData ( nullptr ),
+ aPrintPageSize ( Size() ),
+ bPrintPageLandscape ( false ),
+ bUsePrintDialogSetting ( false )
{
pDev = pOutDev;
m_aRanges.m_xPageEndX = std::make_shared<std::vector<SCCOL>>();
@@ -303,8 +312,9 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell, SCTAB nTab,
Construct( pOptions );
}
-ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
- const ScPrintState& rState, const ScPrintOptions* pOptions )
+ScPrintFunc::ScPrintFunc(OutputDevice* pOutDev, ScDocShell* pShell, const ScPrintState& rState,
+ const ScPrintOptions* pOptions, Size aSize, bool bPrintLandscape,
+ bool bUsed)
: pDocShell ( pShell ),
rDoc(pDocShell->GetDocument()),
pPrinter ( nullptr ),
@@ -314,7 +324,10 @@ ScPrintFunc::ScPrintFunc( OutputDevice* pOutDev, ScDocShell* pShell,
bPrintCurrentTable ( false ),
bMultiArea ( false ),
mbHasPrintRange(true),
- pPageData ( nullptr )
+ pPageData ( nullptr ),
+ aPrintPageSize ( aSize ),
+ bPrintPageLandscape ( bPrintLandscape ),
+ bUsePrintDialogSetting ( bUsed )
{
pDev = pOutDev;
@@ -896,13 +909,13 @@ void ScPrintFunc::InitParam( const ScPrintOptions* pOptions )
const SvxPageItem* pPageItem = &pParamSet->Get( ATTR_PAGE );
nPageUsage = pPageItem->GetPageUsage();
- bLandscape = pPageItem->IsLandscape();
+ bLandscape = bUsePrintDialogSetting ? bPrintPageLandscape : pPageItem->IsLandscape();
aFieldData.eNumType = pPageItem->GetNumType();
bCenterHor = pParamSet->Get(ATTR_PAGE_HORCENTER).GetValue();
bCenterVer = pParamSet->Get(ATTR_PAGE_VERCENTER).GetValue();
- aPageSize = pParamSet->Get(ATTR_PAGE_SIZE).GetSize();
+ aPageSize = bUsePrintDialogSetting ? aPrintPageSize : pParamSet->Get(ATTR_PAGE_SIZE).GetSize();
if ( !aPageSize.Width() || !aPageSize.Height() )
{
OSL_FAIL("PageSize Null ?!?!?");