sw/qa/extras/uiwriter/uiwriter.cxx | 35 +++++++++++++++++++++++++++++++++++ sw/sdi/swriter.sdi | 4 +++- sw/source/uibase/shells/textsh.cxx | 13 ++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-)
New commits: commit c549d491f3ca8caae5e4cd2f51a890442cabed62 Author: shlok3640 <[email protected]> AuthorDate: Tue Dec 9 18:36:53 2025 +0000 Commit: Mike Kaganski <[email protected]> CommitDate: Sat Dec 20 20:53:44 2025 +0100 tdf#168272 Allow InsertPageBreak to accept a Page Style Currently, the .uno:InsertPageBreak command (FN_INSERT_PAGEBREAK) ignores all arguments and simply inserts a default page break. This limits the ability of macros and UI elements to specify a target page style when breaking the page. This patch: 1. Updates the SDI definition in swriter.sdi to change the return type from SfxVoidItem to SfxStringItem, and adds a string parameter PageStyle (mapped to FN_PARAM_1). 2. Updates the execution logic in textsh.cxx to check for this parameter. If a style name is provided, it passes it to SwWrtShell::InsertPageBreak, allowing the page break and style switch to happen immediately. This enables users (via macros) to insert a break and switch to "Landscape" or other styles in a single command. Change-Id: I8de15cd7ddd037420e3b3f4f482f11e1efb02c4a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195326 Reviewed-by: Mike Kaganski <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 28f950f65854..7eac156eca13 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -12,6 +12,9 @@ #include <com/sun/star/document/XDocumentInsertable.hpp> #include <com/sun/star/drawing/GraphicExportFilter.hpp> #include <com/sun/star/i18n/TextConversionOption.hpp> +#include <com/sun/star/text/XPageCursor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <comphelper/propertyvalue.hxx> #include <swmodeltestbase.hxx> #include <ndtxt.hxx> #include <wrtsh.hxx> @@ -2127,6 +2130,38 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf81995) } } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf168272) +{ + createSwDoc(); + + // Use "Landscape" - this is the standard name in a default English template + uno::Sequence<beans::PropertyValue> aPropertyValues = { + comphelper::makePropertyValue(u"PageStyleName"_ustr, u"Landscape"_ustr), + }; + + dispatchCommand(mxComponent, ".uno:InsertPageBreak", aPropertyValues); + + // Refresh layout + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + xModel->lockControllers(); + xModel->unlockControllers(); + + uno::Reference<text::XTextViewCursorSupplier> xViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference<text::XPageCursor> xPageCursor(xViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); + xPageCursor->jumpToLastPage(); + + // Verify page number + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(2), xPageCursor->getPage()); + + // Verify style + uno::Reference<beans::XPropertySet> xCursorProps(xViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); + OUString sActualStyle; + xCursorProps->getPropertyValue("PageStyleName") >>= sActualStyle; + + // This should now match "Landscape" + CPPUNIT_ASSERT_EQUAL(u"Landscape"_ustr, sActualStyle); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi index cd6598cd3996..1b2eb90d94fe 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -3499,7 +3499,9 @@ SfxVoidItem InsertObjectStarMath FN_INSERT_SMA ] SfxVoidItem InsertPagebreak FN_INSERT_PAGEBREAK -() +( + SfxStringItem PageStyleName FN_PARAM_1 +) [ AutoUpdate = FALSE, FastCall = FALSE, diff --git a/sw/source/uibase/shells/textsh.cxx b/sw/source/uibase/shells/textsh.cxx index 32946033210e..3f9c3915eb39 100644 --- a/sw/source/uibase/shells/textsh.cxx +++ b/sw/source/uibase/shells/textsh.cxx @@ -217,7 +217,18 @@ void SwTextShell::ExecInsert(SfxRequest &rReq) break; case FN_INSERT_PAGEBREAK: - rSh.InsertPageBreak(); + if (const SfxStringItem* pStyleItem = rReq.GetArg<SfxStringItem>(FN_PARAM_1)) + { + UIName aStyleName(pStyleItem->GetValue()); + if (!aStyleName.isEmpty()) + rSh.InsertPageBreak(&aStyleName); + else + rSh.InsertPageBreak(); + } + else + { + rSh.InsertPageBreak(); + } rReq.Done(); break;
