diff options
author | Kohei Yoshida <kohei.yoshida@collabora.com> | 2015-01-12 21:59:50 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@collabora.com> | 2015-01-14 22:17:23 -0500 |
commit | 8a0a1fbfc3aacb7e71c79da75c56698c1ea2378d (patch) | |
tree | b5d36a4bd7a6e06525ed2553658c297a993f057e /sc | |
parent | 83e8b259c3c0c0bc593ea0eb60dde0dc8299d970 (diff) |
Implement getDocumentSize(). Cell data only for now.
Change-Id: I31e14f12aaee2d98103d1594ba5b511ebf91e333
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/document.hxx | 11 | ||||
-rw-r--r-- | sc/inc/table.hxx | 1 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 21 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 21 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 24 |
5 files changed, 74 insertions, 4 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 61fa81d00cb9..ddf427d32f26 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1105,6 +1105,16 @@ public: SCROW GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nLastRow ) const; /** + * Return the cell position representing the bottom-right corner of the + * smallest range that includes all non-empty cells for specified sheet. + * + * @param nTab sheet index. + * + * @return address of the last data position. + */ + ScAddress GetLastDataPos( SCTAB nTab ) const; + + /** * Return the smallest area containing at least all contiguous cells * having data. This area is a square containing also empty cells. It may * shrink or extend the area given as input Flags as modifiers: @@ -1520,6 +1530,7 @@ public: SC_DLLPUBLIC void SetManualHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bManual ); SC_DLLPUBLIC sal_uInt16 GetColWidth( SCCOL nCol, SCTAB nTab, bool bHiddenAsZero = true ) const; + SC_DLLPUBLIC sal_uLong GetColWidth( SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bHiddenAsZero = true ) const; SC_DLLPUBLIC sal_uInt16 GetRowHeight( SCROW nRow, SCTAB nTab, bool bHiddenAsZero = true ) const; SC_DLLPUBLIC sal_uInt16 GetRowHeight( SCROW nRow, SCTAB nTab, SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero = true ) const; SC_DLLPUBLIC sal_uLong GetRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bHiddenAsZero = true ) const; diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 89a9a495b2d2..88a046131475 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -721,6 +721,7 @@ public: void SetManualHeight( SCROW nStartRow, SCROW nEndRow, bool bManual ); sal_uInt16 GetColWidth( SCCOL nCol, bool bHiddenAsZero = true ) const; + sal_uLong GetColWidth( SCCOL nStartCol, SCCOL nEndCol, bool bHiddenAsZero = true ) const; SC_DLLPUBLIC sal_uInt16 GetRowHeight( SCROW nRow, SCROW* pStartRow = NULL, SCROW* pEndRow = NULL, bool bHiddenAsZero = true ) const; sal_uLong GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero = true ) const; sal_uLong GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale ) const; diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 64a4284f8dd4..43117b0f304a 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -1045,6 +1045,18 @@ SCROW ScDocument::GetLastDataRow( SCTAB nTab, SCCOL nCol1, SCCOL nCol2, SCROW nL return pTab->GetLastDataRow(nCol1, nCol2, nLastRow); } +ScAddress ScDocument::GetLastDataPos( SCTAB nTab ) const +{ + const ScTable* pTab = FetchTable(nTab); + if (!pTab) + return ScAddress(ScAddress::INITIALIZE_INVALID); + + SCCOL nCol; + SCROW nRow; + pTab->GetLastDataPos(nCol, nRow); + return ScAddress(nCol, nRow, nTab); +} + // connected area void ScDocument::GetDataArea( SCTAB nTab, SCCOL& rStartCol, SCROW& rStartRow, @@ -3894,6 +3906,15 @@ sal_uInt16 ScDocument::GetColWidth( SCCOL nCol, SCTAB nTab, bool bHiddenAsZero ) return 0; } +sal_uLong ScDocument::GetColWidth( SCCOL nStartCol, SCCOL nEndCol, SCTAB nTab, bool bHiddenAsZero ) const +{ + const ScTable* pTab = FetchTable(nTab); + if (!pTab) + return 0; + + return pTab->GetColWidth(nStartCol, nEndCol, bHiddenAsZero); +} + sal_uInt16 ScDocument::GetOriginalWidth( SCCOL nCol, SCTAB nTab ) const { if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index adc16262b117..160da7f0dcc4 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -2837,6 +2837,27 @@ sal_uInt16 ScTable::GetColWidth( SCCOL nCol, bool bHiddenAsZero ) const return (sal_uInt16) STD_COL_WIDTH; } +sal_uLong ScTable::GetColWidth( SCCOL nStartCol, SCCOL nEndCol, bool bHiddenAsZero ) const +{ + if (!ValidCol(nStartCol) || !ValidCol(nEndCol) || nStartCol > nEndCol) + return 0; + + sal_uLong nW = 0; + bool bHidden = false; + SCCOL nLastHiddenCol = -1; + for (SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol) + { + if (bHiddenAsZero && nCol > nLastHiddenCol) + bHidden = ColHidden(nCol, NULL, &nLastHiddenCol); + + if (bHidden) + continue; + + nW += pColWidth[nCol]; + } + return nW; +} + sal_uInt16 ScTable::GetOriginalWidth( SCCOL nCol ) const // immer die eingestellte { OSL_ENSURE(ValidCol(nCol),"wrong column number"); diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 10f50aa3e7db..faf655b4c508 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -488,10 +488,26 @@ int ScModelObj::getPart() Size ScModelObj::getDocumentSize() { - // TODO: not sure what we want to do here, maybe just return the size for a certain - // default minimum number of cells, e.g. 100x100 and more if more cells have - // content? - return Size(); + Size aSize(10, 10); // minimum size + + const ScViewData* pViewData = ScDocShell::GetViewData(); + if (!pViewData) + return aSize; + + SCTAB nTab = pViewData->GetTabNo(); + const ScDocument& rDoc = pDocShell->GetDocument(); + ScAddress aPos = rDoc.GetLastDataPos(nTab); + if (!aPos.IsValid()) + return aSize; + + // TWIPS + sal_uLong nH = rDoc.GetRowHeight(0, aPos.Row(), nTab, true); + sal_uLong nW = rDoc.GetColWidth(0, aPos.Col(), nTab, true); + + aSize.setWidth(nW); + aSize.setHeight(nH); + + return aSize; } uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType ) |