summaryrefslogtreecommitdiff
path: root/sw/source/uibase/shells
diff options
context:
space:
mode:
authorOliver Specht <oliver.specht@cib.de>2024-01-30 17:07:46 +0100
committerGabor Kelemen <gabor.kelemen.extern@allotropia.de>2024-02-12 18:17:18 +0100
commit828d2637fd3120bfd342b41548caf9c55fc0f603 (patch)
treed4f14d46abd17c833b574c4ab61d78216d809ced /sw/source/uibase/shells
parente42b2827b5d392479791632877fc00b6add0307d (diff)
tdf#159662 Add table alignment and left/right spacing to sidebar in Writer
Change-Id: I12d898f21ca8c7d581aaa1c587c5b6434a35f516 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162769 Tested-by: Jenkins Reviewed-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
Diffstat (limited to 'sw/source/uibase/shells')
-rw-r--r--sw/source/uibase/shells/tabsh.cxx144
1 files changed, 142 insertions, 2 deletions
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index 8b1280dcbab7..492cd041d081 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -232,8 +232,7 @@ static std::shared_ptr<SwTableRep> lcl_TableParamToItemSet( SfxItemSet& rSet, Sw
SvxLRSpaceItem aLRSpace( pFormat->GetLRSpace() );
SwTwips nLeft = aLRSpace.GetLeft();
SwTwips nRight = aLRSpace.GetRight();
- SwTwips nDiff = pRep->GetSpace() - nRight - nLeft - nWidth;
- if(nAlign != text::HoriOrientation::FULL && std::abs(nDiff) > 2)
+ if(nAlign != text::HoriOrientation::FULL)
{
SwTwips nLR = pRep->GetSpace() - nWidth;
switch ( nAlign )
@@ -1223,6 +1222,96 @@ void SwTableShell::Execute(SfxRequest &rReq)
}
return;
}
+ case SID_ATTR_TABLE_ALIGNMENT:
+ {
+ const SfxUInt16Item* pAlignItem = rReq.GetArg<SfxUInt16Item>(SID_ATTR_TABLE_ALIGNMENT);
+ if (pAlignItem && pAlignItem->GetValue() <= text::HoriOrientation::LEFT_AND_WIDTH)
+ {
+ SfxItemSetFixed<RES_FRMATR_BEGIN, RES_FRMATR_END - 1> aSet( GetPool());
+ rSh.StartUndo(SwUndoId::TABLE_ATTR);
+ SwFormatHoriOrient aAttr( 0, pAlignItem->GetValue());
+
+ const SfxInt32Item* pLeftItem = rReq.GetArg<SfxInt32Item>(SID_ATTR_TABLE_LEFT_SPACE);
+ const SfxInt32Item* pRightItem = rReq.GetArg<SfxInt32Item>(SID_ATTR_TABLE_RIGHT_SPACE);
+
+ SvxLRSpaceItem aLRSpace( RES_LR_SPACE );
+ SwTwips nLeft = pLeftItem ? pLeftItem->GetValue() : 0;
+ SwTwips nRight = pRightItem ? pRightItem->GetValue() : 0;
+ SwTabCols aTabCols;
+ rSh.GetTabCols(aTabCols);
+ tools::Long nSpace = aTabCols.GetRightMax();
+ SwTwips nWidth = nSpace;
+ switch (pAlignItem->GetValue())
+ {
+ case text::HoriOrientation::LEFT:
+ if (MINLAY < nSpace - nRight)
+ nWidth = nSpace - nRight;
+ else
+ {
+ nWidth = MINLAY;
+ nRight = nSpace - MINLAY;
+ }
+ nLeft = 0;
+ break;
+ case text::HoriOrientation::RIGHT:
+ if (MINLAY < nSpace - nLeft)
+ nWidth = nSpace - nLeft;
+ else
+ {
+ nWidth = MINLAY;
+ nLeft = nSpace - MINLAY;
+ }
+ nRight = 0;
+ break;
+ case text::HoriOrientation::LEFT_AND_WIDTH:
+ // width doesn't change
+ nRight = 0;
+ nLeft = std::min(nLeft, nSpace);
+ break;
+ case text::HoriOrientation::FULL:
+ nLeft = nRight = 0;
+ break;
+ case text::HoriOrientation::CENTER:
+ if (MINLAY < nSpace - 2 * nLeft)
+ nWidth = nSpace - 2 * nLeft;
+ else
+ {
+ nWidth = MINLAY;
+ nLeft = nRight = (nSpace - MINLAY) / 2;
+ }
+ break;
+ case text::HoriOrientation::NONE:
+ if (MINLAY < nSpace - nLeft - nRight)
+ nWidth = nSpace - nLeft - nRight;
+ else
+ {
+ nWidth = MINLAY;
+ //TODO: keep the previous value - if possible and reduce the 'new one' only
+ nLeft = nRight = (nSpace - MINLAY) / 2;
+ }
+ break;
+ default:
+ break;
+ }
+ SwFormatFrameSize aSz( SwFrameSize::Variable, nWidth );
+ aSet.Put(aSz);
+
+ aLRSpace.SetLeft(nLeft);
+ aLRSpace.SetRight(nRight);
+ aSet.Put( aLRSpace );
+
+ aSet.Put( aAttr );
+ rSh.SetTableAttr( aSet );
+ rSh.EndUndo(SwUndoId::TABLE_ATTR);
+ static sal_uInt16 aInva[] =
+ { SID_ATTR_TABLE_LEFT_SPACE,
+ SID_ATTR_TABLE_RIGHT_SPACE,
+ 0
+ };
+ GetView().GetViewFrame().GetBindings().Invalidate( aInva );
+ }
+ return;
+ }
default:
bMore = true;
}
@@ -1569,6 +1658,57 @@ void SwTableShell::GetState(SfxItemSet &rSet)
break;
}
+ case SID_ATTR_TABLE_ALIGNMENT:
+ {
+ const sal_uInt16 nAlign = pFormat->GetHoriOrient().GetHoriOrient();
+ rSet.Put(SfxUInt16Item(nSlot, nAlign));
+ break;
+ }
+ case SID_ATTR_TABLE_LEFT_SPACE:
+ case SID_ATTR_TABLE_RIGHT_SPACE:
+ {
+ SwTabCols aTabCols;
+ rSh.GetTabCols(aTabCols);
+ tools::Long nSpace = aTabCols.GetRightMax();
+ SvxLRSpaceItem aLRSpace(pFormat->GetLRSpace());
+ SwTwips nLeft = aLRSpace.GetLeft();
+ SwTwips nRight = aLRSpace.GetRight();
+
+ sal_uInt16 nPercent = 0;
+ auto nWidth = ::GetTableWidth(pFormat, aTabCols, &nPercent, &rSh );
+ // The table width is wrong for relative values.
+ if (nPercent)
+ nWidth = nSpace * nPercent / 100;
+ const sal_uInt16 nAlign = pFormat->GetHoriOrient().GetHoriOrient();
+ if(nAlign != text::HoriOrientation::FULL )
+ {
+ SwTwips nLR = nSpace - nWidth;
+ switch ( nAlign )
+ {
+ case text::HoriOrientation::CENTER:
+ nLeft = nRight = nLR / 2;
+ break;
+ case text::HoriOrientation::LEFT:
+ nRight = nLR;
+ nLeft = 0;
+ break;
+ case text::HoriOrientation::RIGHT:
+ nLeft = nLR;
+ nRight = 0;
+ break;
+ case text::HoriOrientation::LEFT_AND_WIDTH:
+ nRight = nLR - nLeft;
+ break;
+ case text::HoriOrientation::NONE:
+ if(!nPercent)
+ nWidth = nSpace - nLeft - nRight;
+ break;
+ }
+ }
+ rSet.Put(SfxInt32Item(SID_ATTR_TABLE_LEFT_SPACE, nLeft));
+ rSet.Put(SfxInt32Item(SID_ATTR_TABLE_RIGHT_SPACE, nRight));
+ break;
+ }
}
nSlot = aIter.NextWhich();
}