summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2016-06-08 15:36:24 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-06-08 15:04:14 +0000
commitc8f3cffb91d72e68827450a46b22eb7f852feadd (patch)
tree6ce4cd47e4e0d62ea7885953786229be142b7d11 /svx
parente73fc92829bbb4c06c951006fc7577131564ed67 (diff)
tdf#100269 svx: fix undo of table column resize
SdrTableObjImpl::LayoutTable() assumed no re-layout is needed in case the total width of the table and the number of columns is the same, but undo of resize is a situation where we also need to check the individual widths of the columns, otherwise layout won't be up to date. (cherry picked from commits a106165e7fd39215c4717e1486aef05f6af9180f and 9cea9137b2534da4056f72d3c8a07f85a02f85be) Change-Id: Ia5ebb05af79dda1c0d8c5bb10e7f37f81ee1d035 Reviewed-on: https://gerrit.libreoffice.org/26071 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/table/svdotable.cxx40
-rw-r--r--svx/source/table/tablecolumn.cxx9
-rw-r--r--svx/source/table/tablecolumn.hxx5
-rw-r--r--svx/source/table/tablelayouter.cxx29
-rw-r--r--svx/source/table/tablelayouter.hxx2
-rw-r--r--svx/source/table/tablemodel.cxx7
-rw-r--r--svx/source/table/tablemodel.hxx2
-rw-r--r--svx/source/table/tableundo.cxx3
8 files changed, 96 insertions, 1 deletions
diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx
index 2ea9c8abe954..8793f83928ec 100644
--- a/svx/source/table/svdotable.cxx
+++ b/svx/source/table/svdotable.cxx
@@ -57,6 +57,7 @@
#include "svx/xflftrit.hxx"
#include "svx/xfltrit.hxx"
#include <cppuhelper/implbase.hxx>
+#include <libxml/xmlwriter.h>
using ::com::sun::star::uno::Any;
@@ -221,6 +222,8 @@ public:
void dispose();
sal_Int32 getColumnCount() const;
+ /// Get widths of the columns in the table.
+ std::vector<sal_Int32> getColumnWidths() const;
sal_Int32 getRowCount() const;
void DragEdge( bool mbHorizontal, int nEdge, sal_Int32 nOffset );
@@ -238,6 +241,7 @@ public:
void connectTableStyle();
void disconnectTableStyle();
virtual bool isInUse() override;
+ void dumpAsXml(struct _xmlTextWriter* pWriter) const;
private:
static SdrTableObjImpl* lastLayoutTable;
static Rectangle lastLayoutInputRectangle;
@@ -247,6 +251,7 @@ private:
static WritingMode lastLayoutMode;
static sal_Int32 lastRowCount;
static sal_Int32 lastColCount;
+ static std::vector<sal_Int32> lastColWidths;
};
SdrTableObjImpl* SdrTableObjImpl::lastLayoutTable = nullptr;
@@ -257,6 +262,7 @@ bool SdrTableObjImpl::lastLayoutFitHeight;
WritingMode SdrTableObjImpl::lastLayoutMode;
sal_Int32 SdrTableObjImpl::lastRowCount;
sal_Int32 SdrTableObjImpl::lastColCount;
+std::vector<sal_Int32> SdrTableObjImpl::lastColWidths;
SdrTableObjImpl::SdrTableObjImpl()
: mpTableObj( nullptr )
@@ -624,6 +630,14 @@ bool SdrTableObjImpl::isInUse()
return mpTableObj && mpTableObj->IsInserted();
}
+void SdrTableObjImpl::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+ xmlTextWriterStartElement(pWriter, BAD_CAST("sdrTableObjImpl"));
+ if (mpLayouter)
+ mpLayouter->dumpAsXml(pWriter);
+ xmlTextWriterEndElement(pWriter);
+}
+
// XEventListener
@@ -661,6 +675,15 @@ sal_Int32 SdrTableObjImpl::getColumnCount() const
return mxTable.is() ? mxTable->getColumnCount() : 0;
}
+std::vector<sal_Int32> SdrTableObjImpl::getColumnWidths() const
+{
+ std::vector<sal_Int32> aRet;
+
+ if (mxTable.is())
+ aRet = mxTable->getColumnWidths();
+
+ return aRet;
+}
sal_Int32 SdrTableObjImpl::getRowCount() const
{
@@ -681,7 +704,8 @@ void SdrTableObjImpl::LayoutTable( Rectangle& rArea, bool bFitWidth, bool bFitHe
|| lastLayoutFitWidth != bFitWidth || lastLayoutFitHeight != bFitHeight
|| lastLayoutMode != writingMode
|| lastRowCount != getRowCount()
- || lastColCount != getColumnCount() )
+ || lastColCount != getColumnCount()
+ || lastColWidths != getColumnWidths() )
{
lastLayoutTable = this;
lastLayoutInputRectangle = rArea;
@@ -690,6 +714,9 @@ void SdrTableObjImpl::LayoutTable( Rectangle& rArea, bool bFitWidth, bool bFitHe
lastLayoutMode = writingMode;
lastRowCount = getRowCount();
lastColCount = getColumnCount();
+ // Column resize, when the total width and column count of the
+ // table is unchanged, but re-layout is still needed.
+ lastColWidths = getColumnWidths();
TableModelNotifyGuard aGuard( mxTable.get() );
mpLayouter->LayoutTable( rArea, bFitWidth, bFitHeight );
lastLayoutResultRectangle = rArea;
@@ -2500,6 +2527,17 @@ void SdrTableObj::uno_unlock()
mpImpl->mxTable->unlockBroadcasts();
}
+void SdrTableObj::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+ xmlTextWriterStartElement(pWriter, BAD_CAST("sdrTableObj"));
+ xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
+
+ SdrObject::dumpAsXml(pWriter);
+
+ mpImpl->dumpAsXml(pWriter);
+
+ xmlTextWriterEndElement(pWriter);
+}
} }
diff --git a/svx/source/table/tablecolumn.cxx b/svx/source/table/tablecolumn.cxx
index 597da0bb6d3b..c5ceadee0680 100644
--- a/svx/source/table/tablecolumn.cxx
+++ b/svx/source/table/tablecolumn.cxx
@@ -283,6 +283,15 @@ rtl::Reference< FastPropertySetInfo > TableColumn::getStaticPropertySetInfo()
return xInfo;
}
+TableModelRef TableColumn::getModel() const
+{
+ return mxTableModel;
+}
+
+sal_Int32 TableColumn::getWidth() const
+{
+ return mnWidth;
+}
} }
diff --git a/svx/source/table/tablecolumn.hxx b/svx/source/table/tablecolumn.hxx
index 9c81c69d718c..0c5083d5ce8f 100644
--- a/svx/source/table/tablecolumn.hxx
+++ b/svx/source/table/tablecolumn.hxx
@@ -58,6 +58,11 @@ public:
virtual void SAL_CALL setFastPropertyValue( ::sal_Int32 nHandle, const css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
virtual css::uno::Any SAL_CALL getFastPropertyValue( ::sal_Int32 nHandle ) throw (css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
+ /// Get the table that owns this column.
+ TableModelRef getModel() const;
+ /// Get the width of this column.
+ sal_Int32 getWidth() const;
+
private:
static rtl::Reference< FastPropertySetInfo > getStaticPropertySetInfo();
diff --git a/svx/source/table/tablelayouter.cxx b/svx/source/table/tablelayouter.cxx
index 0f6208c54f1d..ae87f5044ad3 100644
--- a/svx/source/table/tablelayouter.cxx
+++ b/svx/source/table/tablelayouter.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/table/XMergeableCell.hpp>
#include <tools/gen.hxx>
+#include <libxml/xmlwriter.h>
#include "cell.hxx"
#include "cellrange.hxx"
@@ -1121,6 +1122,34 @@ void TableLayouter::DistributeRows( ::Rectangle& rArea, sal_Int32 nFirstRow, sal
}
}
+void TableLayouter::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+ xmlTextWriterStartElement(pWriter, BAD_CAST("tableLayouter"));
+
+ xmlTextWriterStartElement(pWriter, BAD_CAST("columns"));
+ for (const auto& rColumn : maColumns)
+ rColumn.dumpAsXml(pWriter);
+ xmlTextWriterEndElement(pWriter);
+
+ xmlTextWriterStartElement(pWriter, BAD_CAST("rows"));
+ for (const auto& rRow : maRows)
+ rRow.dumpAsXml(pWriter);
+ xmlTextWriterEndElement(pWriter);
+
+ xmlTextWriterEndElement(pWriter);
+}
+
+void TableLayouter::Layout::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+ xmlTextWriterStartElement(pWriter, BAD_CAST("layout"));
+
+ xmlTextWriterWriteAttribute(pWriter, BAD_CAST("pos"), BAD_CAST(OString::number(mnPos).getStr()));
+ xmlTextWriterWriteAttribute(pWriter, BAD_CAST("size"), BAD_CAST(OString::number(mnSize).getStr()));
+ xmlTextWriterWriteAttribute(pWriter, BAD_CAST("minSize"), BAD_CAST(OString::number(mnMinSize).getStr()));
+
+ xmlTextWriterEndElement(pWriter);
+}
+
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/table/tablelayouter.hxx b/svx/source/table/tablelayouter.hxx
index b38345588a54..0ab692c2591c 100644
--- a/svx/source/table/tablelayouter.hxx
+++ b/svx/source/table/tablelayouter.hxx
@@ -96,6 +96,7 @@ public:
void DistributeColumns( ::Rectangle& rArea, sal_Int32 nFirstCol, sal_Int32 nLastCol );
void DistributeRows( ::Rectangle& rArea, sal_Int32 nFirstRow, sal_Int32 nLastRow );
+ void dumpAsXml(struct _xmlTextWriter* pWriter) const;
private:
CellRef getCell( const CellPos& rPos ) const;
@@ -125,6 +126,7 @@ private:
Layout() : mnPos( 0 ), mnSize( 0 ), mnMinSize( 0 ) {}
void clear() { mnPos = 0; mnSize = 0; mnMinSize = 0; }
+ void dumpAsXml(struct _xmlTextWriter* pWriter) const;
};
typedef std::vector< Layout > LayoutVector;
diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx
index b6dd24579eb3..e7062289ca48 100644
--- a/svx/source/table/tablemodel.cxx
+++ b/svx/source/table/tablemodel.cxx
@@ -321,6 +321,13 @@ sal_Int32 SAL_CALL TableModel::getColumnCount() throw (RuntimeException, std::ex
return getColumnCountImpl();
}
+std::vector<sal_Int32> TableModel::getColumnWidths()
+{
+ std::vector<sal_Int32> aRet;
+ for (const TableColumnRef& xColumn : maColumns)
+ aRet.push_back(xColumn->getWidth());
+ return aRet;
+}
// XComponent
diff --git a/svx/source/table/tablemodel.hxx b/svx/source/table/tablemodel.hxx
index 66263e64cfe7..411bf2f97c59 100644
--- a/svx/source/table/tablemodel.hxx
+++ b/svx/source/table/tablemodel.hxx
@@ -81,6 +81,8 @@ public:
/// merges the cell at the given position with the given span
void merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan );
+ /// Get the width of all columns in this table.
+ std::vector<sal_Int32> getColumnWidths();
// ICellRange
virtual sal_Int32 getLeft() override;
diff --git a/svx/source/table/tableundo.cxx b/svx/source/table/tableundo.cxx
index 3a60ab02d0c2..cb0093fbc80e 100644
--- a/svx/source/table/tableundo.cxx
+++ b/svx/source/table/tableundo.cxx
@@ -400,6 +400,9 @@ void TableColumnUndo::setData( const Data& rData )
mxCol->mbIsVisible = rData.mbIsVisible;
mxCol->mbIsStartOfNewPage = rData.mbIsStartOfNewPage;
mxCol->maName = rData.maName;
+
+ // Trigger re-layout of the table.
+ mxCol->getModel()->setModified(true);
}