[Libreoffice-commits] core.git: Branch 'distro/vector/vector-7.0' - 4 commits - sw/qa sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jun 11 15:22:22 UTC 2021
sw/qa/uibase/frmdlg/data/image.png |binary
sw/qa/uibase/frmdlg/frmdlg.cxx | 27 ++++++++++++++++++++++++
sw/qa/uibase/uiview/data/keep-ratio.fodt | 21 +++++++++++++++++++
sw/qa/uibase/uiview/uiview.cxx | 34 +++++++++++++++++++++++++++++++
sw/source/ui/frmdlg/frmpage.cxx | 13 +++++++----
sw/source/uibase/app/docst.cxx | 25 +++++++++++++++++++++-
sw/source/uibase/app/docstyle.cxx | 1
sw/source/uibase/frmdlg/frmmgr.cxx | 14 +++++++++++-
sw/source/uibase/uiview/view.cxx | 18 ++++++++++++++++
9 files changed, 146 insertions(+), 7 deletions(-)
New commits:
commit b56cc6fb887a09cd9a652640e7988ff4d7ccce67
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jun 11 11:41:41 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jun 11 17:20:35 2021 +0200
sw image anchor type: consider a style-based custom value
The anchor type is determined during insertion, it's stored as direct
formatting after that.
We used to have a user-profile default for the anchor type. This commit
allows customizing the Graphics or OLE styles: if they specify a custom
anchor type, then that is user instead of the user profile setting.
This allows creating templates where the default depends on the used
template and not on the user profile.
The UI for this was added in commit
5951da5175b9d7e5b3b47bd0d90989d2ef528c79 (sw image anchor type: add
style UI for this, 2021-06-10).
(cherry picked from commit 7413cc96d239f5fd5a588f13784ccb82b6968bac)
Change-Id: Id05342a5f38dc6267cdbe68b248dc50b87854ce2
diff --git a/sw/qa/uibase/frmdlg/data/image.png b/sw/qa/uibase/frmdlg/data/image.png
new file mode 100644
index 000000000000..fdad35484e7c
Binary files /dev/null and b/sw/qa/uibase/frmdlg/data/image.png differ
diff --git a/sw/qa/uibase/frmdlg/frmdlg.cxx b/sw/qa/uibase/frmdlg/frmdlg.cxx
index 3700abb9d946..7a6546186574 100644
--- a/sw/qa/uibase/frmdlg/frmdlg.cxx
+++ b/sw/qa/uibase/frmdlg/frmdlg.cxx
@@ -9,6 +9,8 @@
#include <swmodeltestbase.hxx>
+#include <comphelper/propertyvalue.hxx>
+
#include <com/sun/star/text/TextContentAnchorType.hpp>
char const DATA_DIRECTORY[] = "/sw/qa/uibase/frmdlg/data/";
@@ -46,6 +48,31 @@ CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testWrappedMathObject)
getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType"));
}
+CPPUNIT_TEST_FIXTURE(SwUibaseFrmdlgTest, testAnchorTypeFromStyle)
+{
+ // Given a document with aGraphics style with anchor type set to as-character:
+ createDoc();
+ uno::Reference<beans::XPropertySet> xGraphics(getStyles("FrameStyles")->getByName("Graphics"),
+ uno::UNO_QUERY);
+ xGraphics->setPropertyValue("AnchorType",
+ uno::makeAny(text::TextContentAnchorType_AS_CHARACTER));
+
+ // When inserting an image:
+ OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "image.png";
+ uno::Sequence<beans::PropertyValue> aArgs = {
+ comphelper::makePropertyValue("FileName", aImageURL),
+ };
+ dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
+
+ // Then make sure the image's anchor type is as-char:
+ auto eActual = getProperty<text::TextContentAnchorType>(getShape(1), "AnchorType");
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 1 (AS_CHARACTER)
+ // - Actual : 4 (AT_CHARACTER)
+ // i.e. the anchor type from the style was ignored.
+ CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, eActual);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/frmdlg/frmmgr.cxx b/sw/source/uibase/frmdlg/frmmgr.cxx
index ff72e7ae3f4d..9560884e7151 100644
--- a/sw/source/uibase/frmdlg/frmmgr.cxx
+++ b/sw/source/uibase/frmdlg/frmmgr.cxx
@@ -91,7 +91,19 @@ SwFlyFrameAttrMgr::SwFlyFrameAttrMgr( bool bNew, SwWrtShell* pSh, Frmmgr_Type nT
{
// Default anchor for new graphics and objects is at-char, except for Math objects.
SwViewOption aViewOpt(*pSh->GetViewOptions());
- m_aSet.Put(SwFormatAnchor(aViewOpt.GetDefaultAnchorType()));//RndStdIds::FLY_AT_CHAR
+
+ RndStdIds eAnchorType = aViewOpt.GetDefaultAnchorType();
+
+ const SwFormatAnchor rStyleAnchor
+ = m_pOwnSh->GetFormatFromPool(nId)->GetAttrSet().GetAnchor();
+ if (rStyleAnchor.GetAnchorId() != RndStdIds::FLY_AT_PARA)
+ {
+ // The style has a custom anchor type, prefer that over the user profile
+ // default.
+ eAnchorType = rStyleAnchor.GetAnchorId();
+ }
+
+ m_aSet.Put(SwFormatAnchor(eAnchorType));
}
}
}
commit 955dd1659436b849f01dd2adf1f4786c45b4de1a
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Thu Jun 10 15:11:03 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jun 11 17:18:58 2021 +0200
sw image anchor type: add style UI for this
A frame style contains RES_ANCHOR, and SwFormatAnchor::m_eAnchorId
already describes an anchor type. This is even exposed on the UNO API as
the AnchorType property and its ODF import/export is also implemented.
Enable UI for this, so that templates can decide the default anchor type
when inserting images. Still keep the "to frame" anchor type disabled as
its meaning is unclear for frame styles.
(cherry picked from commit 5951da5175b9d7e5b3b47bd0d90989d2ef528c79)
Change-Id: I5d8ef63af9c8f2efa6485c4ec827ba9aef9b8956
diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx
index 7abea6ae137e..404dba4c91a5 100644
--- a/sw/source/ui/frmdlg/frmpage.cxx
+++ b/sw/source/ui/frmdlg/frmpage.cxx
@@ -881,8 +881,8 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
if (m_bFormat)
{
- // at formats no anchor editing
- m_xAnchorFrame->set_sensitive(false);
+ // at formats no to-fly anchor
+ m_xAnchorAtFrameRB->set_sensitive(false);
if (rSet->GetItemState(FN_KEEP_ASPECT_RATIO) != SfxItemState::SET)
{
m_xFixedRatioCB->set_sensitive(false);
@@ -1044,7 +1044,7 @@ bool SwFramePage::FillItemSet(SfxItemSet *rSet)
RndStdIds eAnchorId = GetAnchor();
- if ( !m_bFormat )
+ if ( !m_bFormat || eAnchorId != RndStdIds::FLY_AT_FLY )
{
pOldItem = GetOldItem(*rSet, RES_ANCHOR);
if (m_bNew || !pOldItem || eAnchorId != static_cast<const SwFormatAnchor*>(pOldItem)->GetAnchorId())
@@ -2285,7 +2285,7 @@ void SwFramePage::SetFormatUsed(bool bFormatUsed)
{
m_bFormat = bFormatUsed;
if (m_bFormat)
- m_xAnchorFrame->hide();
+ m_xAnchorAtFrameRB->hide();
}
void SwFramePage::EnableVerticalPositioning( bool bEnable )
commit 133777311ff1d4e4878132351c87b38a81916bf8
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jun 9 17:59:08 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jun 11 17:17:56 2021 +0200
sw keep aspect ratio: add style UI for this setting
It's a per-document setting, but it was only possible to set/get this for a
direct formatting dialog. Allow it for styles as well.
(cherry picked from commit 4895a92e67ffbbee87ec5ee1e2394cdc5b833fcb)
Conflicts:
sw/source/uibase/app/docst.cxx
Change-Id: Iafe1cab37be1eb741b895fe3c6613c21bc63f0d5
diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx
index c9fd24297e02..7abea6ae137e 100644
--- a/sw/source/ui/frmdlg/frmpage.cxx
+++ b/sw/source/ui/frmdlg/frmpage.cxx
@@ -883,8 +883,11 @@ void SwFramePage::Reset( const SfxItemSet *rSet )
{
// at formats no anchor editing
m_xAnchorFrame->set_sensitive(false);
+ if (rSet->GetItemState(FN_KEEP_ASPECT_RATIO) != SfxItemState::SET)
+ {
m_xFixedRatioCB->set_sensitive(false);
}
+ }
else
{
if (rAnchor.GetAnchorId() != RndStdIds::FLY_AT_FLY && !pSh->IsFlyInFly())
@@ -1202,7 +1205,7 @@ bool SwFramePage::FillItemSet(SfxItemSet *rSet)
aSz.SetWidthSizeType( eFrameSize );
}
}
- if (!m_bFormat && m_xFixedRatioCB->get_state_changed_from_saved())
+ if (m_xFixedRatioCB->get_state_changed_from_saved())
bRet |= nullptr != rSet->Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, m_xFixedRatioCB->get_active()));
pOldItem = GetOldItem(*rSet, RES_FRM_SIZE);
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index 6886b548ba56..2bfa0a0f12bd 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -605,6 +605,22 @@ IMPL_LINK_NOARG(ApplyStyle, ApplyHdl, LinkParamNone*, void)
if( aTmpSet.GetItemState( m_rDocSh.GetPool().GetTrueWhich( SID_ATTR_FRAMEDIRECTION, false ) , true, &pItem ) == SfxItemState::SET )
SwChartHelper::DoUpdateAllCharts( pDoc );
}
+
+ if (m_nFamily == SfxStyleFamily::Frame)
+ {
+ const SfxPoolItem* pItem = nullptr;
+ if (aTmpSet.HasItem(FN_KEEP_ASPECT_RATIO, &pItem))
+ {
+ const auto& rBoolItem = static_cast<const SfxBoolItem&>(*pItem);
+ const SwViewOption* pVOpt = pWrtShell->GetViewOptions();
+ SwViewOption aUsrPref(*pVOpt);
+ aUsrPref.SetKeepRatio(rBoolItem.GetValue());
+ if (rBoolItem.GetValue() != pVOpt->IsKeepRatio())
+ {
+ SW_MOD()->ApplyUsrPref(aUsrPref, &pWrtShell->GetView());
+ }
+ }
+ }
}
if(m_bNew)
@@ -869,6 +885,14 @@ void SwDocShell::Edit(
rSet.Put(SvxPatternListItem(pDrawModel->GetPatternList(), SID_PATTERN_LIST));
}
+ SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell;
+ if (nFamily == SfxStyleFamily::Frame)
+ {
+ SfxItemSet& rSet = xTmp->GetItemSet();
+ const SwViewOption* pVOpt = pCurrShell->GetViewOptions();
+ rSet.Put(SfxBoolItem(FN_KEEP_ASPECT_RATIO, pVOpt->IsKeepRatio()));
+ }
+
if (!bBasic)
{
// prior to the dialog the HtmlMode at the DocShell is being sunk
@@ -877,7 +901,6 @@ void SwDocShell::Edit(
// In HTML mode, we do not always have a printer. In order to show
// the correct page size in the Format - Page dialog, we have to
// get one here.
- SwWrtShell* pCurrShell = pActShell ? pActShell : m_pWrtShell;
if( ( HTMLMODE_ON & nHtmlMode ) &&
!pCurrShell->getIDocumentDeviceAccess().getPrinter( false ) )
pCurrShell->InitPrt( pCurrShell->getIDocumentDeviceAccess().getPrinter( true ) );
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index 693ae7f20b14..ea40a8319c6f 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -483,6 +483,7 @@ SwDocStyleSheet::SwDocStyleSheet( SwDoc& rDocument,
SID_ATTR_NUMBERING_RULE, SID_ATTR_NUMBERING_RULE,
SID_ATTR_AUTO_STYLE_UPDATE, SID_ATTR_AUTO_STYLE_UPDATE,
FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
+ FN_KEEP_ASPECT_RATIO, FN_KEEP_ASPECT_RATIO,
FN_COND_COLL, FN_COND_COLL>{}),
bPhysical(false)
{
commit 72eebe3154e453aca6206cd1d350b849d35b578f
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Jun 7 18:03:33 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jun 11 17:15:04 2021 +0200
sw keep aspect ratio: add filter for this setting
SwViewOption::IsKeepRatio() was only in-memory, so ticking that checkbox
and restarting soffice disabled it again.
Handle this similar to e.g. the zoom factor which is mapped to a
view-specific settings.xml key.
(cherry picked from commit 02c435082058ecf7f9d4d73cb47d31d0218dc10d)
Conflicts:
sw/qa/uibase/uiview/uiview.cxx
Change-Id: I8d2de7d2c7ae0dbf34230e2011f6b07f63e02fbb
diff --git a/sw/qa/uibase/uiview/data/keep-ratio.fodt b/sw/qa/uibase/uiview/data/keep-ratio.fodt
new file mode 100644
index 000000000000..7cfffbec567a
--- /dev/null
+++ b/sw/qa/uibase/uiview/data/keep-ratio.fodt
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:settings>
+ <config:config-item-set config:name="ooo:view-settings">
+ <config:config-item-map-indexed config:name="Views">
+ <config:config-item-map-entry>
+ <config:config-item config:name="VisibleLeft" config:type="long">0</config:config-item>
+ <config:config-item config:name="VisibleTop" config:type="long">0</config:config-item>
+ <config:config-item config:name="VisibleRight" config:type="long">40190</config:config-item>
+ <config:config-item config:name="VisibleBottom" config:type="long">22728</config:config-item>
+ <config:config-item config:name="KeepRatio" config:type="boolean">true</config:config-item>
+ </config:config-item-map-entry>
+ </config:config-item-map-indexed>
+ </config:config-item-set>
+ </office:settings>
+ <office:body>
+ <office:text>
+ <text:p/>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 4d622aafaa5f..b7826bc9ad52 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -13,6 +13,7 @@
#include <comphelper/processfactory.hxx>
#include <osl/file.hxx>
#include <comphelper/propertyvalue.hxx>
+#include <comphelper/scopeguard.hxx>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -23,6 +24,7 @@
#include <docsh.hxx>
#include <wrtsh.hxx>
#include <swdtflvr.hxx>
+#include <swmodule.hxx>
char const DATA_DIRECTORY[] = "/sw/qa/uibase/uiview/data/";
@@ -112,6 +114,38 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testUpdateReplacementNosetting)
CPPUNIT_ASSERT(xNameAccess->hasByName("ObjectReplacements/Components"));
}
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testKeepRatio)
+{
+ // Given a document with a custom KeepRatio:
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "keep-ratio.fodt";
+
+ // When loading that document:
+ mxComponent = loadFromDesktop(aURL);
+
+ // Then make sure we read the custom value:
+ auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+ const SwViewOption* pViewOption = pWrtShell->GetViewOptions();
+ comphelper::ScopeGuard g([pWrtShell, pViewOption] {
+ SwViewOption aViewOption(*pViewOption);
+ aViewOption.SetKeepRatio(false);
+ SW_MOD()->ApplyUsrPref(aViewOption, &pWrtShell->GetView());
+ });
+ // Without the accompanying fix in place, this test would have failed, because KeepRatio was not
+ // mapped to settings.xml
+ CPPUNIT_ASSERT(pViewOption->IsKeepRatio());
+
+ // Then export as well:
+ uno::Reference<frame::XStorable2> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreArgs = {
+ comphelper::makePropertyValue("FilterName", OUString("writer8")),
+ };
+ xStorable->storeToURL(maTempFile.GetURL(), aStoreArgs);
+ mbExported = true;
+ xmlDocUniquePtr pXmlDoc = parseExport("settings.xml");
+ assertXPathContent(pXmlDoc, "//config:config-item[@config:name='KeepRatio']", "true");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index d7837c800bfb..d9c3c793ec01 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1302,6 +1302,8 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
bGotZoomFactor = false, bGotIsSelectedFrame = false,
bGotViewLayoutColumns = false, bGotViewLayoutBookMode = false,
bBrowseMode = false, bGotBrowseMode = false;
+ bool bKeepRatio = pVOpt->IsKeepRatio();
+ bool bGotKeepRatio = false;
for (const beans::PropertyValue& rValue : rSequence)
{
@@ -1369,6 +1371,11 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
rValue.Value >>= bBrowseMode;
bGotBrowseMode = true;
}
+ else if (rValue.Name == "KeepRatio")
+ {
+ rValue.Value >>= bKeepRatio;
+ bGotKeepRatio = true;
+ }
// Fallback to common SdrModel processing
else
GetDocShell()->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->ReadUserDataSequenceValue(&rValue);
@@ -1443,6 +1450,14 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
m_pWrtShell->SetMacroExecAllowed( bSavedFlagValue );
}
+ if (bGotKeepRatio && bKeepRatio != pVOpt->IsKeepRatio())
+ {
+ // Got a custom value, then it makes sense to trigger notifications.
+ SwViewOption aUsrPref(*pVOpt);
+ aUsrPref.SetKeepRatio(bKeepRatio);
+ SW_MOD()->ApplyUsrPref(aUsrPref, this);
+ }
+
// Set ViewLayoutSettings
const bool bSetViewLayoutSettings = bGotViewLayoutColumns && bGotViewLayoutBookMode &&
( pVOpt->GetViewLayoutColumns() != nViewLayoutColumns || pVOpt->IsViewLayoutBookMode() != bViewLayoutBookMode );
@@ -1543,6 +1558,9 @@ void SwView::WriteUserDataSequence ( uno::Sequence < beans::PropertyValue >& rSe
aVector.push_back(comphelper::makePropertyValue("IsSelectedFrame", FrameTypeFlags::NONE != m_pWrtShell->GetSelFrameType()));
+ aVector.push_back(
+ comphelper::makePropertyValue("KeepRatio", m_pWrtShell->GetViewOptions()->IsKeepRatio()));
+
rSequence = comphelper::containerToSequence(aVector);
// Common SdrModel processing
More information about the Libreoffice-commits
mailing list