sd/source/ui/view/drtxtob1.cxx       |   21 ++++++++++++++++-----
 sw/source/uibase/shells/drwtxtex.cxx |   17 +++++++++++++----
 sw/source/uibase/uiview/viewtab.cxx  |   14 ++++++++++++--
 3 files changed, 41 insertions(+), 11 deletions(-)

New commits:
commit 4cc532c0393914a743c11e806bd25dfa3d28fb5c
Author:     Kira Tubo <kira.t...@gmail.com>
AuthorDate: Thu Sep 26 22:15:15 2024 -0700
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Sep 29 02:40:18 2024 +0200

    tdf#156374: Create hanging indent on paragraph without one
    
    If the paragraph has no First Line Indent applied, create a hanging
    indent.
    - In Writer: the indentation distance is based on the default tab
      distance.
    - In Draw/Impress: the indentation distance is based on the distance set
      for the Increase/Decrease Indent buttons (1000 twips), which is
    different from the default tab distance.
    
    Change-Id: Ifc36c63ad7e6aa852a4b10aca22b7b4de6e10e95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174001
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sd/source/ui/view/drtxtob1.cxx b/sd/source/ui/view/drtxtob1.cxx
index 210362f16de1..7a4e49e6177b 100644
--- a/sd/source/ui/view/drtxtob1.cxx
+++ b/sd/source/ui/view/drtxtob1.cxx
@@ -47,6 +47,7 @@
 #include <editeng/writingmodeitem.hxx>
 #include <editeng/frmdiritem.hxx>
 #include <editeng/cmapitem.hxx>
+#include <editeng/tstpitem.hxx>
 
 #include <app.hrc>
 #include <strings.hrc>
@@ -82,6 +83,9 @@ void TextObjectBar::ExecuteImpl(ViewShell* mpViewShell, 
::sd::View* mpView, SfxR
     sal_uInt16 nSlot = rReq.GetSlot();
     OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
 
+    // Default indent used e.g. in SID_DEC_INDENT, SID_INC_INDENT and 
SID_HANGING_INDENT
+    const ::tools::Long nIndentDefaultDist = 1000; // 1000 twips
+
     std::unique_ptr<OutlineViewModelChangeGuard, 
o3tl::default_delete<OutlineViewModelChangeGuard>> aGuard;
 
     assert(mpViewShell);
@@ -155,10 +159,10 @@ void TextObjectBar::ExecuteImpl(ViewShell* mpViewShell, 
::sd::View* mpView, SfxR
 
                         ::tools::Long nLeft = pNewItem->GetLeft();
                         if( nSlot == SID_INC_INDENT )
-                            nLeft += 1000;
+                            nLeft += nIndentDefaultDist;
                         else
                         {
-                            nLeft -= 1000;
+                            nLeft -= nIndentDefaultDist;
                             nLeft = std::max<::tools::Long>( nLeft, 0 );
                         }
                         pNewItem->SetLeftValue( static_cast<sal_uInt16>(nLeft) 
);
@@ -341,9 +345,16 @@ void TextObjectBar::ExecuteImpl(ViewShell* mpViewShell, 
::sd::View* mpView, SfxR
             SvxLRSpaceItem aParaMargin( aLRSpaceSet.Get( EE_PARA_LRSPACE ) );
 
             SvxLRSpaceItem aNewMargin( EE_PARA_LRSPACE );
-            aNewMargin.SetTextLeft( aParaMargin.GetTextLeft() + 
aParaMargin.GetTextFirstLineOffset() );
-            aNewMargin.SetRight( aParaMargin.GetRight() );
-            aNewMargin.SetTextFirstLineOffset( ( 
aParaMargin.GetTextFirstLineOffset() ) * -1 );
+
+            ::tools::Long nIndentDist = aParaMargin.GetTextFirstLineOffset();
+
+            if (nIndentDist == 0)
+                nIndentDist = nIndentDefaultDist;
+
+            aNewMargin.SetTextLeft(aParaMargin.GetTextLeft() + nIndentDist);
+            aNewMargin.SetRight(aParaMargin.GetRight());
+            aNewMargin.SetTextFirstLineOffset(nIndentDist * -1);
+
             aLRSpaceSet.Put( aNewMargin );
             mpView->SetAttributes( aLRSpaceSet );
 
diff --git a/sw/source/uibase/shells/drwtxtex.cxx 
b/sw/source/uibase/shells/drwtxtex.cxx
index e3dff9857c0a..c53fa4b8bfc8 100644
--- a/sw/source/uibase/shells/drwtxtex.cxx
+++ b/sw/source/uibase/shells/drwtxtex.cxx
@@ -209,10 +209,19 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
                 {
                     SvxLRSpaceItem aParaMargin = aEditAttr.Get( 
EE_PARA_LRSPACE );
                     aParaMargin.SetWhich( EE_PARA_LRSPACE );
-                    short int nFirstLineOffset = 
aParaMargin.GetTextFirstLineOffset();
-                    aParaMargin.SetTextLeft( aParaMargin.GetTextLeft() + 
nFirstLineOffset );
-                    aParaMargin.SetRight( aParaMargin.GetRight() );
-                    aParaMargin.SetTextFirstLineOffset( nFirstLineOffset * -1 
);
+
+                    tools::Long nIndentDist = 
aParaMargin.GetTextFirstLineOffset();
+
+                    if (nIndentDist == 0)
+                    {
+                        const SvxTabStopItem& rDefTabItem = 
rSh.GetDefault(RES_PARATR_TABSTOP);
+                        nIndentDist = ::GetTabDist(rDefTabItem);
+                    }
+
+                    aParaMargin.SetTextLeft(aParaMargin.GetTextLeft() + 
nIndentDist);
+                    aParaMargin.SetRight(aParaMargin.GetRight());
+                    aParaMargin.SetTextFirstLineOffset(nIndentDist * -1);
+
                     aNewAttr.Put(aParaMargin);
                     rReq.Done();
                 }
diff --git a/sw/source/uibase/uiview/viewtab.cxx 
b/sw/source/uibase/uiview/viewtab.cxx
index fb1cec99c40c..761df9d72f59 100644
--- a/sw/source/uibase/uiview/viewtab.cxx
+++ b/sw/source/uibase/uiview/viewtab.cxx
@@ -732,8 +732,18 @@ void SwView::ExecTabWin( SfxRequest const & rReq )
         rSh.GetCurAttr( aLRSpaceSet );
         SvxFirstLineIndentItem 
firstLine(aLRSpaceSet.Get(RES_MARGIN_FIRSTLINE));
         SvxTextLeftMarginItem leftMargin(aLRSpaceSet.Get(RES_MARGIN_TEXTLEFT));
-        leftMargin.SetTextLeft(leftMargin.GetTextLeft() + 
firstLine.GetTextFirstLineOffset());
-        firstLine.SetTextFirstLineOffset((firstLine.GetTextFirstLineOffset()) 
* -1);
+
+        tools::Long nIndentDist = firstLine.GetTextFirstLineOffset();
+
+        if (nIndentDist == 0)
+        {
+            const SvxTabStopItem& rDefTabItem = 
rSh.GetDefault(RES_PARATR_TABSTOP);
+            nIndentDist = ::GetTabDist(rDefTabItem);
+        }
+
+        leftMargin.SetTextLeft(leftMargin.GetTextLeft() + nIndentDist);
+        firstLine.SetTextFirstLineOffset(nIndentDist * -1);
+
         firstLine.SetAutoFirst(false); // old code would do this, is it wanted?
         rSh.SetAttrItem(firstLine);
         rSh.SetAttrItem(leftMargin);

Reply via email to