editeng/source/editeng/editdoc.cxx |   11 +++++++++++
 editeng/source/items/paraitem.cxx  |   32 ++++++++++++++++++++++++++++++++
 include/editeng/memberids.h        |    1 +
 include/editeng/tstpitem.hxx       |    3 +++
 include/editeng/unoprnms.hxx       |    1 +
 include/editeng/unotext.hxx        |    1 +
 6 files changed, 49 insertions(+)

New commits:
commit cced51a1ed7c140276aabfe857510afb974fcef5
Author:     Sarper Akdemir <sarper.akde...@collabora.com>
AuthorDate: Tue Feb 28 16:13:48 2023 +0300
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Mar 16 11:20:48 2023 +0000

    tdf#102261: introduce editeng paragraph tab stop default distance
    
    Adds mnDefaultDistance to SvxTabStopItem that if defined
    will set a paragraph wide tab stop default distance and
    override the document wide setting.
    
    Also makes editeng consider mnDefaultDistance while getting
    tab stop default distance.
    
    Change-Id: I0fa098f874d6b9c91ddbaa2634224ff55cafcc95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148058
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/editeng/source/editeng/editdoc.cxx 
b/editeng/source/editeng/editdoc.cxx
index 1fbf46de184b..9fff222d9368 100644
--- a/editeng/source/editeng/editdoc.cxx
+++ b/editeng/source/editeng/editdoc.cxx
@@ -857,6 +857,13 @@ void ConvertItem( std::unique_ptr<SfxPoolItem>& rPoolItem, 
MapUnit eSourceUnit,
             assert(dynamic_cast<const SvxTabStopItem *>(rPoolItem.get()) != 
nullptr);
             SvxTabStopItem& rItem = static_cast<SvxTabStopItem&>(*rPoolItem);
             SvxTabStopItem* pNewItem(new SvxTabStopItem(EE_PARA_TABS));
+
+            if (sal_Int32 nDefTabDistance = rItem.GetDefaultDistance())
+            {
+                pNewItem->SetDefaultDistance(
+                    OutputDevice::LogicToLogic(nDefTabDistance, eSourceUnit, 
eDestUnit));
+            }
+
             for ( sal_uInt16 i = 0; i < rItem.Count(); i++ )
             {
                 const SvxTabStop& rTab = rItem[i];
@@ -1821,6 +1828,10 @@ SvxTabStop ContentAttribs::FindTabStop( sal_Int32 
nCurPos, sal_uInt16 nDefTab )
             return rTab;
     }
 
+    // if there's a default tab size defined for this item use that instead
+    if (rTabs.GetDefaultDistance())
+        nDefTab = rTabs.GetDefaultDistance();
+
     // Determine DefTab ...
     SvxTabStop aTabStop;
     const sal_Int32 x = nCurPos / nDefTab + 1;
diff --git a/editeng/source/items/paraitem.cxx 
b/editeng/source/items/paraitem.cxx
index 9368dfdf3c2a..f67ddf599b06 100644
--- a/editeng/source/items/paraitem.cxx
+++ b/editeng/source/items/paraitem.cxx
@@ -821,6 +821,15 @@ sal_uInt16 SvxTabStopItem::GetPos( const sal_Int32 nPos ) 
const
     return it != maTabStops.end() ? it - maTabStops.begin() : SVX_TAB_NOTFOUND;
 }
 
+void SvxTabStopItem::SetDefaultDistance(sal_Int32 nDefaultDistance)
+{
+    mnDefaultDistance = nDefaultDistance;
+}
+
+sal_Int32 SvxTabStopItem::GetDefaultDistance() const
+{
+    return mnDefaultDistance;
+}
 
 bool SvxTabStopItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
 {
@@ -859,6 +868,11 @@ bool SvxTabStopItem::QueryValue( uno::Any& rVal, sal_uInt8 
nMemberId ) const
             rVal <<= static_cast<sal_Int32>(bConvert ? 
convertTwipToMm100(rTab.GetTabPos()) : rTab.GetTabPos());
             break;
         }
+        case MID_TABSTOP_DEFAULT_DISTANCE:
+        {
+            rVal <<= static_cast<sal_Int32>(bConvert ? 
convertTwipToMm100(mnDefaultDistance) : mnDefaultDistance);
+            break;
+        }
     }
     return true;
 }
@@ -956,6 +970,18 @@ bool SvxTabStopItem::PutValue( const uno::Any& rVal, 
sal_uInt8 nMemberId )
             Insert( aNewTab );
             break;
         }
+        case MID_TABSTOP_DEFAULT_DISTANCE:
+        {
+            sal_Int32 nNewDefaultDistance = 0;
+            if (!(rVal >>= nNewDefaultDistance))
+                return false;
+            if (bConvert)
+                nNewDefaultDistance = o3tl::toTwips(nNewDefaultDistance, 
o3tl::Length::mm100);
+            if (nNewDefaultDistance <= 0)
+                return false;
+            mnDefaultDistance = nNewDefaultDistance;
+            break;
+        }
     }
     return true;
 }
@@ -967,6 +993,9 @@ bool SvxTabStopItem::operator==( const SfxPoolItem& rAttr ) 
const
 
     const SvxTabStopItem& rTSI = static_cast<const SvxTabStopItem&>(rAttr);
 
+    if ( mnDefaultDistance != rTSI.GetDefaultDistance() )
+        return false;
+
     if ( Count() != rTSI.Count() )
         return false;
 
@@ -990,6 +1019,7 @@ bool SvxTabStopItem::GetPresentation
 )   const
 {
     rText.clear();
+    // TODO also consider mnDefaultTabDistance here
 
     bool bComma = false;
 
@@ -1038,6 +1068,8 @@ void SvxTabStopItem::Insert( const SvxTabStopItem* pTabs )
 void SvxTabStopItem::dumpAsXml(xmlTextWriterPtr pWriter) const
 {
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTabStopItem"));
+    (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("mnDefaultDistance"),
+                                      
BAD_CAST(OString::number(mnDefaultDistance).getStr()));
     for (const auto& rTabStop : maTabStops)
         rTabStop.dumpAsXml(pWriter);
     (void)xmlTextWriterEndElement(pWriter);
diff --git a/include/editeng/memberids.h b/include/editeng/memberids.h
index 6003ce394ba0..0db3c27d0128 100644
--- a/include/editeng/memberids.h
+++ b/include/editeng/memberids.h
@@ -40,6 +40,7 @@
 // SvxTabStop
 #define MID_TABSTOPS            0
 #define MID_STD_TAB             1
+#define MID_TABSTOP_DEFAULT_DISTANCE 2
 
 //SvxHyphenZoneItem
 #define MID_IS_HYPHEN           0
diff --git a/include/editeng/tstpitem.hxx b/include/editeng/tstpitem.hxx
index b5aab04bc92d..4c015d6677ec 100644
--- a/include/editeng/tstpitem.hxx
+++ b/include/editeng/tstpitem.hxx
@@ -92,6 +92,7 @@ typedef o3tl::sorted_vector<SvxTabStop> SvxTabStopArr;
 class EDITENG_DLLPUBLIC SvxTabStopItem final : public SfxPoolItem
 {
     SvxTabStopArr maTabStops;
+    sal_Int32 mnDefaultDistance = 0;
 
 public:
     static SfxPoolItem* CreateDefault();
@@ -107,6 +108,8 @@ public:
 
     // Returns index of the tab at nPos, or TAB_NOTFOUND
     sal_uInt16          GetPos( const sal_Int32 nPos ) const;
+    void SetDefaultDistance(sal_Int32 nDefaultDistancenDefTabSize);
+    sal_Int32 GetDefaultDistance() const;
 
     // unprivatized:
     sal_uInt16          Count() const { return maTabStops.size(); }
diff --git a/include/editeng/unoprnms.hxx b/include/editeng/unoprnms.hxx
index 300a0a2b7765..a321e54e5a73 100644
--- a/include/editeng/unoprnms.hxx
+++ b/include/editeng/unoprnms.hxx
@@ -295,6 +295,7 @@ inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_LMARGIN 
= u"ParaLeftMargin";
 inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_LINESPACING = 
u"ParaLineSpacing";
 inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_RMARGIN = 
u"ParaRightMargin";
 inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_TAPSTOPS = u"ParaTabStops";
+inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_TABSTOP_DEFAULT_DISTANCE = 
u"ParaTabStopDefaultDistance";
 inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_TMARGIN = u"ParaTopMargin";
 inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_IS_HYPHEN = 
u"ParaIsHyphenation";
 inline constexpr OUStringLiteral UNO_NAME_EDIT_PARA_IS_HANGING_PUNCTUATION = 
u"ParaIsHangingPunctuation";
diff --git a/include/editeng/unotext.hxx b/include/editeng/unotext.hxx
index dec8c4cc50a5..5231219b5a1a 100644
--- a/include/editeng/unotext.hxx
+++ b/include/editeng/unotext.hxx
@@ -147,6 +147,7 @@ struct SfxItemPropertyMapEntry;
     { UNO_NAME_EDIT_PARA_LINESPACING,  EE_PARA_SBL,                
cppu::UnoType<css::style::LineSpacing>::get(),     0, CONVERT_TWIPS}, \
     { UNO_NAME_EDIT_PARA_RMARGIN,      EE_PARA_LRSPACE,    
::cppu::UnoType<sal_Int32>::get(),            0, MID_R_MARGIN, 
PropertyMoreFlags::METRIC_ITEM }, \
     { UNO_NAME_EDIT_PARA_TAPSTOPS,     EE_PARA_TABS,               
cppu::UnoType<css::uno::Sequence< css::style::TabStop >>::get(), 0, 0 }, \
+    { UNO_NAME_EDIT_PARA_TABSTOP_DEFAULT_DISTANCE, EE_PARA_TABS, 
::cppu::UnoType<sal_Int32>::get(), 0, MID_TABSTOP_DEFAULT_DISTANCE }, \
     { UNO_NAME_EDIT_PARA_TMARGIN,      EE_PARA_ULSPACE,            
::cppu::UnoType<sal_Int32>::get(),            0, MID_UP_MARGIN, 
PropertyMoreFlags::METRIC_ITEM },\
     { UNO_NAME_EDIT_PARA_FIRST_LINE_INDENT,     EE_PARA_LRSPACE,   
::cppu::UnoType<sal_Int32>::get(),            0, MID_FIRST_LINE_INDENT, 
PropertyMoreFlags::METRIC_ITEM}, \
     { UNO_NAME_EDIT_PARA_IS_HANGING_PUNCTUATION,EE_PARA_HANGINGPUNCTUATION,  
cppu::UnoType<bool>::get(),                0 ,0 }, \

Reply via email to