summaryrefslogtreecommitdiff
path: root/svx/source/table/cell.cxx
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2018-09-06 12:17:47 +0300
committerJustin Luth <justin_luth@sil.org>2018-09-21 16:48:13 +0200
commit73859a1c00d443714a1e5f2a1a8d16fe46877944 (patch)
tree20ec8312fef2cd36910989883cee6fd0e3b068da /svx/source/table/cell.cxx
parentf74b888244fcefa7c03fa25db4d42c839ebbf642 (diff)
tdf#117721 draw ui: add .uno::SetOptimalColumnWidth
Optimize column width: Adjusts the width of the selected columns to fit the content, without changing the width of the table. Any leftover space is distributed proportionately, with thin columns growing slightly, and wide columns growing much wider. The implementation and results are different from how Writer does it, but tables themselves are also very different in Draw. So I don't think it needs to be handled identically. Writer's implementation is really "minimalColumnWidth" anyway. Change-Id: Ia10cfa9822d7eef3c4909a82c21535aa6668b143 Reviewed-on: https://gerrit.libreoffice.org/60078 Tested-by: Jenkins Reviewed-by: Justin Luth <justin_luth@sil.org>
Diffstat (limited to 'svx/source/table/cell.cxx')
-rw-r--r--svx/source/table/cell.cxx19
1 files changed, 19 insertions, 0 deletions
diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx
index 4bf5c07f38cf..ba705359f118 100644
--- a/svx/source/table/cell.cxx
+++ b/svx/source/table/cell.cxx
@@ -704,6 +704,25 @@ void Cell::SetMergedItemSetAndBroadcast(const SfxItemSet& rSet, bool bClearAllIt
}
+sal_Int32 Cell::calcPreferredWidth( const Size aSize )
+{
+ if ( !hasText() )
+ return getMinimumWidth();
+
+ Outliner& rOutliner=static_cast< SdrTableObj& >( GetObject() ).ImpGetDrawOutliner();
+ rOutliner.SetPaperSize(aSize);
+ rOutliner.SetUpdateMode(true);
+ ForceOutlinerParaObject( OutlinerMode::TextObject );
+
+ if( GetOutlinerParaObject() )
+ rOutliner.SetText(*GetOutlinerParaObject());
+
+ sal_Int32 nPreferredWidth = const_cast<EditEngine&>(rOutliner.GetEditEngine()).CalcTextWidth();
+ rOutliner.Clear();
+
+ return GetTextLeftDistance() + GetTextRightDistance() + nPreferredWidth;
+}
+
sal_Int32 Cell::getMinimumWidth()
{
return GetTextLeftDistance() + GetTextRightDistance() + 100;