summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2018-09-21 16:31:26 +0300
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-10-11 09:45:59 +0200
commit0f26c6ddda31221364b011a0b89286ecea303d89 (patch)
tree4afacc551f6b3a59b11431a915ffae85254db463 /sw/source
parent59ed21b1720db5fd0326e1b723483b288725e662 (diff)
tdf#64242 sw optimal row height, not minimize
The previous optimal implementation was cloned as a new uno:MinimalColumnWidth function. Optimal should try to keep the table the same size, but ultimately the ideal row/table height will be balanced, so grow to achieve that if necessary. Optimize row height: Adjust the height of the selected rows to match the height of the tallest row in the selection (fit to content), without shrinking the table. This option is the same as minimizing row height and then distributing rows evenly except that it adds the benefit of preventing the table from shrinking. Change-Id: Ib772ae4943127d17a915cdae8cd6000db3a9d164 Reviewed-on: https://gerrit.libreoffice.org/60903 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/docnode/ndtbl1.cxx9
-rw-r--r--sw/source/core/frmedt/fetab.cxx4
-rw-r--r--sw/source/uibase/shells/tabsh.cxx18
3 files changed, 18 insertions, 13 deletions
diff --git a/sw/source/core/docnode/ndtbl1.cxx b/sw/source/core/docnode/ndtbl1.cxx
index a5ee3f383cce..70ca0acd17b4 100644
--- a/sw/source/core/docnode/ndtbl1.cxx
+++ b/sw/source/core/docnode/ndtbl1.cxx
@@ -438,7 +438,7 @@ void SwDoc::GetRowHeight( const SwCursor& rCursor, SwFormatFrameSize *& rpSz )
}
}
-bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly )
+bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly, const bool bOptimize )
{
bool bRet = false;
SwTableNode* pTableNd = rCursor.GetPoint()->nNode.GetNode().FindTableNode();
@@ -452,7 +452,7 @@ bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly )
if( !bTstOnly )
{
long nHeight = 0;
-
+ sal_Int32 nTotalHeight = 0;
for ( auto pLn : aRowArr )
{
SwIterator<SwFrame,SwFormat> aIter( *pLn->GetFrameFormat() );
@@ -462,7 +462,12 @@ bool SwDoc::BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly )
nHeight = std::max( nHeight, pFrame->getFrameArea().Height() );
pFrame = aIter.Next();
}
+ nTotalHeight += nHeight;
}
+
+ if ( bOptimize )
+ nHeight = nTotalHeight / aRowArr.size();
+
SwFormatFrameSize aNew( ATT_MIN_SIZE, 0, nHeight );
if (GetIDocumentUndoRedo().DoesUndo())
diff --git a/sw/source/core/frmedt/fetab.cxx b/sw/source/core/frmedt/fetab.cxx
index 3a21ae2ccdfe..e51f1e4e96e1 100644
--- a/sw/source/core/frmedt/fetab.cxx
+++ b/sw/source/core/frmedt/fetab.cxx
@@ -736,12 +736,12 @@ void SwFEShell::GetRowHeight( SwFormatFrameSize *& rpSz ) const
SwDoc::GetRowHeight( *getShellCursor( false ), rpSz );
}
-bool SwFEShell::BalanceRowHeight( bool bTstOnly )
+bool SwFEShell::BalanceRowHeight( bool bTstOnly, const bool bOptimize )
{
SET_CURR_SHELL( this );
if( !bTstOnly )
StartAllAction();
- bool bRet = GetDoc()->BalanceRowHeight( *getShellCursor( false ), bTstOnly );
+ bool bRet = GetDoc()->BalanceRowHeight( *getShellCursor( false ), bTstOnly, bOptimize );
if( !bTstOnly )
EndAllActionAndCall();
return bRet;
diff --git a/sw/source/uibase/shells/tabsh.cxx b/sw/source/uibase/shells/tabsh.cxx
index 75ec7e57c888..a849013d9dbb 100644
--- a/sw/source/uibase/shells/tabsh.cxx
+++ b/sw/source/uibase/shells/tabsh.cxx
@@ -711,13 +711,6 @@ void SwTableShell::Execute(SfxRequest &rReq)
rSh.UpdateTable();
bCallDone = true;
break;
- case FN_TABLE_OPTIMAL_HEIGHT:
- {
- const SwFormatFrameSize aSz;
- rSh.SetRowHeight( aSz );
- bCallDone = true;
- break;
- }
case FN_TABLE_DELETE_COL:
if ( rSh.DeleteCol() && rSh.HasSelection() )
rSh.EnterStdMode();
@@ -795,6 +788,13 @@ void SwTableShell::Execute(SfxRequest &rReq)
bCallDone = true;
break;
}
+ case FN_TABLE_OPTIMAL_HEIGHT:
+ {
+ rSh.BalanceRowHeight(/*bTstOnly=*/false, /*bOptimize=*/true);
+ rSh.BalanceRowHeight(/*bTstOnly=*/false, /*bOptimize=*/false);
+ bCallDone = true;
+ break;
+ }
case FN_TABLE_BALANCE_ROWS:
if ( rSh.BalanceRowHeight(true) )
rSh.BalanceRowHeight(false);
@@ -1240,9 +1240,10 @@ void SwTableShell::GetState(SfxItemSet &rSet)
rSet.DisableItem(FN_TABLE_BALANCE_CELLS);
break;
+ case FN_TABLE_OPTIMAL_HEIGHT:
case FN_TABLE_BALANCE_ROWS:
if ( !rSh.BalanceRowHeight(true) )
- rSet.DisableItem(FN_TABLE_BALANCE_ROWS);
+ rSet.DisableItem(nSlot);
break;
case FN_OPTIMIZE_TABLE:
if ( !rSh.IsTableMode() &&
@@ -1267,7 +1268,6 @@ void SwTableShell::GetState(SfxItemSet &rSet)
break;
case SID_TABLE_MINIMAL_ROW_HEIGHT:
- case FN_TABLE_OPTIMAL_HEIGHT:
{
// Disable if auto height already is enabled.
SwFormatFrameSize *pSz;