Kaydet (Commit) 0f26c6dd authored tarafından Justin Luth's avatar Justin Luth Kaydeden (comit) Miklos Vajna

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: 's avatarJustin Luth <justin_luth@sil.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 59ed21b1
......@@ -1434,7 +1434,11 @@ public:
static void GetRowHeight( const SwCursor& rCursor, SwFormatFrameSize *& rpSz );
void SetRowSplit( const SwCursor& rCursor, const SwFormatRowSplit &rNew );
static void GetRowSplit( const SwCursor& rCursor, SwFormatRowSplit *& rpSz );
bool BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly );
/// Adjustment of Rowheights. Determine via bTstOnly if more than one row is selected.
/// bOptimize: distribute current table height, instead of using the largest row.
/// Call again without bOptimize to ensure equal height in case some row's content didn't fit.
bool BalanceRowHeight( const SwCursor& rCursor, bool bTstOnly, const bool bOptimize );
void SetRowBackground( const SwCursor& rCursor, const SvxBrushItem &rNew );
static bool GetRowBackground( const SwCursor& rCursor, SvxBrushItem &rToFill );
void SetTabBorders( const SwCursor& rCursor, const SfxItemSet& rSet );
......
......@@ -655,8 +655,7 @@ public:
void SetBoxAlign( sal_uInt16 nOrient );
sal_uInt16 GetBoxAlign() const; ///< USHRT_MAX if ambiguous.
/// Adjustment of Rowheights. Determine via bTstOnly if more than one row is selected.
bool BalanceRowHeight( bool bTstOnly );
bool BalanceRowHeight( bool bTstOnly, const bool bOptimize = false );
void SetTabBorders( const SfxItemSet& rSet );
void GetTabBorders( SfxItemSet& rSet) const;
......
......@@ -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())
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment