tdf#173496: use current page for by default range

The patch concerns Writer but it should help for Calc and Impress/Draw later
for adding "Current sheet"/"Current slide" option since we change vcl part too.
I used the help from GPT 5.6 Luna to:
- find root cause (print mechanism is quite complicated)
- find the fix

I made several tests but can't pretend I tested everything (far from it)

There are 2 main parts in the patch:
1) UI : add STR_PRINTOPTUI_PRINTCURRENTPAGE in sw + modify ui file vcl

2) Mechanism
a) in sw part
- add the new choice in SwPrintUIOptions
- take it into account in CalculatePagesForPrinting
- in GetRenderDoc, in case of current page, the current mechanism which uses a temporary doc
for the preview doesn't work so we need to use the whole doc instead of creating a temporary doc

b) in vcl part
- add mnInitialPage to keep in memory the current page when opening the dialog.
I found no other way to have this information once the range has been changed
- initialize mnInitialPage in ctr
- modify PrintDialog::preparePreview to have the right range
- take into account the new choice in UIOption_RadioHdl
(this last one is for the preview, the rendering is ok even without it)

+ add some check on test_printDialog QA test to see if range is ok
when going back to Portrait.

Change-Id: Idff5622601d94c73e53e12af215d5c8ba3e1b04a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/210643
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
This commit is contained in:
Julien Nabet
2026-09-28 09:22:10 +02:00
parent 0dacab6ba7
commit aec77a1a64
8 changed files with 145 additions and 55 deletions
+7
View File
@@ -40,4 +40,11 @@ class printDialog(UITestCase):
xLandscapePageRange = xDialog.getChild("pagerange")
self.assertEqual(get_state_as_dict(xLandscapePageRange)["Text"], "1")
# check that when reselecting Portrait, the range is again 1-2
# Expected: "1-2"
# Actual : "1"
select_by_text(xpageorientationbox, "Portrait")
xPortraitPageRange = xDialog.getChild("pagerange")
self.assertEqual(get_state_as_dict(xPortraitPageRange)["Text"], "1-2")
# vim: set shiftwidth=4 softtabstop=4 expandtab:
+1
View File
@@ -685,6 +685,7 @@
#define STR_PRINTOPTUI_PRINTALLPAGES NC_("STR_PRINTOPTUI_PRINTALLPAGES", "~All Pages")
#define STR_PRINTOPTUI_PRINTPAGES NC_("STR_PRINTOPTUI_PRINTPAGES", "Pa~ges:")
#define STR_PRINTOPTUI_PRINTSELECTION NC_("STR_PRINTOPTUI_PRINTSELECTION", "~Selection")
#define STR_PRINTOPTUI_PRINTCURRENTPAGE NC_("STR_PRINTOPTUI_PRINTCURRENTPAGE", "Current ~Page")
#define STR_PRINTOPTUI_PLACE_MARGINS NC_("STR_PRINTOPTUI_PLACE_MARGINS", "Place in margins")
#define STR_FORMULA_CALC NC_("STR_FORMULA_CALC", "Functions")
+1 -1
View File
@@ -743,7 +743,7 @@ void SwDoc::CalculatePagesForPrinting(
// 0 -> print all pages (default if aPageRange is empty)
// 1 -> print range according to PageRange
// 2 -> print selection
if (1 == nContent)
if (1 == nContent || 3 == nContent)
aPageRange = rOptions.getStringValue( "PageRange" );
if (2 == nContent)
+7 -4
View File
@@ -272,12 +272,15 @@ SwPrintUIOptions::SwPrintUIOptions(
static constexpr OUString aPrintRangeName( u"PrintContent"_ustr );
uno::Sequence< OUString > aChoices{ SwResId( STR_PRINTOPTUI_PRINTALLPAGES ),
SwResId( STR_PRINTOPTUI_PRINTPAGES ),
SwResId( STR_PRINTOPTUI_PRINTSELECTION ) };
uno::Sequence< sal_Bool > aChoicesDisabled{ false, false, !bHasSelection };
SwResId( STR_PRINTOPTUI_PRINTSELECTION ),
SwResId( STR_PRINTOPTUI_PRINTCURRENTPAGE ) };
uno::Sequence< sal_Bool > aChoicesDisabled{ false, false, !bHasSelection, false };
uno::Sequence< OUString > aHelpIds{ u".HelpID:vcl:PrintDialog:PrintContent:RadioButton:0"_ustr,
u".HelpID:vcl:PrintDialog:PrintContent:RadioButton:1"_ustr,
u".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2"_ustr };
uno::Sequence< OUString > aWidgetIds{ u"rbAllPages"_ustr, u"rbRangePages"_ustr, u"rbRangeSelection"_ustr };
u".HelpID:vcl:PrintDialog:PrintContent:RadioButton:2"_ustr,
u".HelpID:vcl:PrintDialog:PrintContent:RadioButton:3"_ustr
};
uno::Sequence< OUString > aWidgetIds{ u"rbAllPages"_ustr, u"rbRangePages"_ustr, u"rbRangeSelection"_ustr, u"rbCurrentPage"_ustr };
m_aUIProperties[nIdx++].Value = setChoiceRadiosControlOpt(aWidgetIds, OUString(),
aHelpIds, aPrintRangeName,
aChoices, 0 /* always default to 'All pages' */,
+5
View File
@@ -2591,6 +2591,11 @@ SwDoc * SwXTextDocument::GetRenderDoc(
uno::Reference< frame::XModel > xModel;
rSelection >>= xModel;
const bool bPrintCurrentPage = m_pPrintUIOptions && m_pPrintUIOptions->getIntValue("PrintContent", 0) == 3;
if (bPrintCurrentPage)
return m_pDocShell->GetDoc();
if (xModel == m_pDocShell->GetModel())
pDoc = m_pDocShell->GetDoc();
else
+1
View File
@@ -190,6 +190,7 @@ namespace vcl
OUString maPageStr;
OUString maNoPageStr;
OUString maNoPreviewStr;
sal_Int32 mnInitialPage;
sal_Int32 mnCurPage;
sal_Int32 mnCachedPages;
+58 -6
View File
@@ -580,12 +580,22 @@ PrintDialog::PrintDialog(weld::Window* i_pWindow, std::shared_ptr<PrinterControl
, maDefPrtText( VclResId( SV_PRINT_DEFPRT_TXT ) )
, maNoPageStr( VclResId( SV_PRINT_NOPAGES ) )
, maNoPreviewStr( VclResId( SV_PRINT_NOPREVIEW ) )
, mnInitialPage( 0 )
, mnCurPage( 0 )
, mnCachedPages( 0 )
, mbShowLayoutFrame( true )
, mbHasCustomPaperEntry( false )
, maUpdatePreviewIdle("Print Dialog Update Preview Idle")
{
// Retrieve current page, it'll be used later in updatePageRange method
PropertyValue* pPageRange = maPController->getValue(u"PageRange"_ustr);
if (pPageRange && pPageRange->Value.hasValue())
{
OUString aPageRange;
pPageRange->Value >>= aPageRange;
mnInitialPage = aPageRange.toInt32();
}
// save printbutton text, gets exchanged occasionally with print to file
maPrintText = mxOKButton->get_label();
@@ -1150,18 +1160,51 @@ void PrintDialog::preparePreview( bool i_bMayUseCache )
void PrintDialog::updatePageRange(sal_Int32 nPages)
{
if (nPages > 0 && !mxPageRangesRadioButton->get_active())
if (nPages <= 0)
return;
PropertyValue* pContentVal = maPController->getValue(u"PrintContent"_ustr);
sal_Int32 nContent = -1;
if (pContentVal)
pContentVal->Value >>= nContent;
if (nContent == 1)
{
OUString sRange;
if (nPages == 1)
sRange = u"1"_ustr;
else
sRange = u"1-"_ustr + OUString::number(nPages);
mxPageRangeEdit->set_text(sRange);
maPController->setValue(u"PageRange"_ustr, Any(sRange));
return;
}
OUString sRange;
if (nContent == 3)
{
// Current page: preserve the document page selected when
// the print dialog was opened.
sRange = OUString::number(mnInitialPage);
}
else if (nContent == 0)
{
// All pages
OUStringBuffer aBuf(32);
aBuf.append("1");
if (nPages > 1)
{
aBuf.append("-" + OUString::number(nPages));
}
OUString sRange = aBuf.makeStringAndClear();
mxPageRangeEdit->set_text(sRange);
maPController->setValue(u"PageRange"_ustr, Any(sRange));
sRange = aBuf.makeStringAndClear();
}
else
{
return;
}
mxPageRangeEdit->set_text(sRange);
maPController->setValue(u"PageRange"_ustr, Any(sRange));
}
void PrintDialog::updatePageSize(int nOrientation)
@@ -2365,6 +2408,15 @@ IMPL_LINK( PrintDialog, UIOption_RadioHdl, weld::Toggleable&, i_rBtn, void )
sal_Int32 nVal = it->second;
pVal->Value <<= nVal;
if (pVal->Name == "PrintContent" && nVal == 3)
{
PropertyValue* pPageRange = maPController->getValue(u"PageRange"_ustr);
if (pPageRange)
{
pPageRange->Value <<= OUString::number(mnInitialPage);
}
}
updateOrientationBox();
checkOptionalControlDependencies();
+65 -44
View File
@@ -546,48 +546,6 @@
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="rbRangePages">
<property name="label" translatable="yes" context="printdialog|rbPageRange">_Pages:</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="halign">start</property>
<property name="margin-top">2</property>
<property name="margin-bottom">2</property>
<property name="use-underline">True</property>
<property name="draw-indicator">True</property>
<property name="group">rbAllPages</property>
<child internal-child="accessible">
<object class="AtkObject" id="rbRangePages-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|rbRangePages">Prints only the pages or slides that you specify in the Pages box.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="pagerange">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="activates-default">True</property>
<property name="truncate-multiline">True</property>
<property name="placeholder-text" translatable="yes" context="printdialog|pagerange">e.g.: 1, 3-5, 7, 9</property>
<child internal-child="accessible">
<object class="AtkObject" id="pagerange-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|pagerange">To print a range of pages, use a format like 3-6. To print single pages, use a format like 7;9;11. You can print a combination of page ranges and single pages, by using a format like 3-6;8;10;12.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="rbRangeSelection">
<property name="label" translatable="yes" context="printdialog|rbRangeSelection">_Selection</property>
@@ -609,6 +567,69 @@
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="rbCurrentPage">
<property name="label" translatable="yes" context="printdialog|rbCurrentPage">_Current page</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="halign">start</property>
<property name="margin-bottom">2</property>
<property name="use-underline">True</property>
<property name="draw-indicator">True</property>
<property name="group">rbAllPages</property>
<child internal-child="accessible">
<object class="AtkObject" id="rbCurrentPage-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|rbCurrentPage">Prints only the current page.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="rbRangePages">
<property name="label" translatable="yes" context="printdialog|rbPageRange">_Pages:</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="halign">start</property>
<property name="margin-top">2</property>
<property name="margin-bottom">2</property>
<property name="use-underline">True</property>
<property name="draw-indicator">True</property>
<property name="group">rbAllPages</property>
<child internal-child="accessible">
<object class="AtkObject" id="rbRangePages-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|rbRangePages">Prints only the pages or slides that you specify in the Pages box.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="pagerange">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="activates-default">True</property>
<property name="truncate-multiline">True</property>
<property name="placeholder-text" translatable="yes" context="printdialog|pagerange">e.g.: 1, 3-5, 7, 9</property>
<child internal-child="accessible">
<object class="AtkObject" id="pagerange-atkobject">
<property name="AtkObject::accessible-description" translatable="yes" context="printdialog|extended_tip|pagerange">To print a range of pages, use a format like 3-6. To print single pages, use a format like 7;9;11. You can print a combination of page ranges and single pages, by using a format like 3-6;8;10;12.</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="labelcopies">
<property name="visible">True</property>
@@ -621,7 +642,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
@@ -643,7 +664,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
</object>