sw/inc/doc.hxx                    |    6 +++++-
 sw/inc/fesh.hxx                   |    3 +--
 sw/source/core/docnode/ndtbl1.cxx |    9 +++++++--
 sw/source/core/frmedt/fetab.cxx   |    4 ++--
 sw/source/uibase/shells/tabsh.cxx |   18 +++++++++---------
 5 files changed, 24 insertions(+), 16 deletions(-)

New commits:
commit 0f26c6ddda31221364b011a0b89286ecea303d89
Author:     Justin Luth <justin_l...@sil.org>
AuthorDate: Fri Sep 21 16:31:26 2018 +0300
Commit:     Miklos Vajna <vmik...@collabora.co.uk>
CommitDate: Thu Oct 11 09:45:59 2018 +0200

    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_l...@sil.org>
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index b06048cbadbc..bdff80442ebe 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -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 );
diff --git a/sw/inc/fesh.hxx b/sw/inc/fesh.hxx
index 0fb81347dccd..f01fb6d9022a 100644
--- a/sw/inc/fesh.hxx
+++ b/sw/inc/fesh.hxx
@@ -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;
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;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to