1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "chart2uno.hxx" 28cdf0e10cSrcweir #include "miscuno.hxx" 29cdf0e10cSrcweir #include "document.hxx" 30cdf0e10cSrcweir #include "unoguard.hxx" 31cdf0e10cSrcweir #include "cell.hxx" 32cdf0e10cSrcweir #include "chartpos.hxx" 33cdf0e10cSrcweir #include "unonames.hxx" 34cdf0e10cSrcweir #include "globstr.hrc" 35cdf0e10cSrcweir #include "convuno.hxx" 36cdf0e10cSrcweir #include "rangeutl.hxx" 37cdf0e10cSrcweir #include "hints.hxx" 38cdf0e10cSrcweir #include "unoreflist.hxx" 39cdf0e10cSrcweir #include "compiler.hxx" 40cdf0e10cSrcweir #include "reftokenhelper.hxx" 41cdf0e10cSrcweir #include "chartlis.hxx" 42cdf0e10cSrcweir 43cdf0e10cSrcweir #include <sfx2/objsh.hxx> 44cdf0e10cSrcweir #include <tools/table.hxx> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp> 47cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> 48cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp> 49cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp> 50cdf0e10cSrcweir #include <com/sun/star/text/XText.hpp> 51cdf0e10cSrcweir #include <comphelper/extract.hxx> 52cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <vector> 55cdf0e10cSrcweir #include <list> 56cdf0e10cSrcweir #include <rtl/math.hxx> 57cdf0e10cSrcweir 58cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScChart2DataProvider, "ScChart2DataProvider", 59cdf0e10cSrcweir "com.sun.star.chart2.data.DataProvider") 60cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScChart2DataSource, "ScChart2DataSource", 61cdf0e10cSrcweir "com.sun.star.chart2.data.DataSource") 62cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScChart2DataSequence, "ScChart2DataSequence", 63cdf0e10cSrcweir "com.sun.star.chart2.data.DataSequence") 64cdf0e10cSrcweir #if USE_CHART2_EMPTYDATASEQUENCE 65cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScChart2EmptyDataSequence, "ScChart2EmptyDataSequence", 66cdf0e10cSrcweir "com.sun.star.chart2.data.DataSequence") 67cdf0e10cSrcweir #endif 68cdf0e10cSrcweir 69cdf0e10cSrcweir using namespace ::com::sun::star; 70cdf0e10cSrcweir using namespace ::formula; 71cdf0e10cSrcweir using ::rtl::OUString; 72cdf0e10cSrcweir using ::rtl::OUStringBuffer; 73cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 74cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 75cdf0e10cSrcweir using ::std::auto_ptr; 76cdf0e10cSrcweir using ::std::vector; 77cdf0e10cSrcweir using ::std::list; 78cdf0e10cSrcweir using ::std::distance; 79cdf0e10cSrcweir using ::std::unary_function; 80cdf0e10cSrcweir using ::std::hash_set; 81cdf0e10cSrcweir using ::boost::shared_ptr; 82cdf0e10cSrcweir 83cdf0e10cSrcweir namespace 84cdf0e10cSrcweir { 85cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDataProviderPropertyMap() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir static SfxItemPropertyMapEntry aDataProviderPropertyMap_Impl[] = 88cdf0e10cSrcweir { 89cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_INCLUDEHIDDENCELLS), 0, &getBooleanCppuType(), 0, 0 }, 90cdf0e10cSrcweir {0,0,0,0,0,0} 91cdf0e10cSrcweir }; 92cdf0e10cSrcweir return aDataProviderPropertyMap_Impl; 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetDataSequencePropertyMap() 96cdf0e10cSrcweir { 97cdf0e10cSrcweir static SfxItemPropertyMapEntry aDataSequencePropertyMap_Impl[] = 98cdf0e10cSrcweir { 99cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_HIDDENVALUES), 0, &getCppuType((uno::Sequence<sal_Int32>*)0 ), 0, 0 }, 100cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_ROLE), 0, &getCppuType((::com::sun::star::chart2::data::DataSequenceRole*)0), 0, 0 }, 101cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_INCLUDEHIDDENCELLS), 0, &getBooleanCppuType(), 0, 0 }, 102cdf0e10cSrcweir {0,0,0,0,0,0} 103cdf0e10cSrcweir }; 104cdf0e10cSrcweir return aDataSequencePropertyMap_Impl; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir template< typename T > 108cdf0e10cSrcweir ::com::sun::star::uno::Sequence< T > lcl_VectorToSequence( 109cdf0e10cSrcweir const ::std::vector< T > & rCont ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir ::com::sun::star::uno::Sequence< T > aResult( rCont.size()); 112cdf0e10cSrcweir ::std::copy( rCont.begin(), rCont.end(), aResult.getArray()); 113cdf0e10cSrcweir return aResult; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir struct lcl_appendTableNumber : public ::std::unary_function< SCTAB, void > 117cdf0e10cSrcweir { 118cdf0e10cSrcweir lcl_appendTableNumber( ::rtl::OUStringBuffer & rBuffer ) : 119cdf0e10cSrcweir m_rBuffer( rBuffer ) 120cdf0e10cSrcweir {} 121cdf0e10cSrcweir void operator() ( SCTAB nTab ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir // there is no append with SCTAB or sal_Int16 124cdf0e10cSrcweir m_rBuffer.append( static_cast< sal_Int32 >( nTab )); 125cdf0e10cSrcweir m_rBuffer.append( sal_Unicode( ' ' )); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir private: 128cdf0e10cSrcweir ::rtl::OUStringBuffer & m_rBuffer; 129cdf0e10cSrcweir }; 130cdf0e10cSrcweir 131cdf0e10cSrcweir ::rtl::OUString lcl_createTableNumberList( const ::std::list< SCTAB > & rTableList ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir ::rtl::OUStringBuffer aBuffer; 134cdf0e10cSrcweir ::std::for_each( rTableList.begin(), rTableList.end(), lcl_appendTableNumber( aBuffer )); 135cdf0e10cSrcweir // remove last trailing ' ' 136cdf0e10cSrcweir if( aBuffer.getLength() > 0 ) 137cdf0e10cSrcweir aBuffer.setLength( aBuffer.getLength() - 1 ); 138cdf0e10cSrcweir return aBuffer.makeStringAndClear(); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir uno::Reference< frame::XModel > lcl_GetXModel( ScDocument * pDoc ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir uno::Reference< frame::XModel > xModel; 144cdf0e10cSrcweir SfxObjectShell * pObjSh( pDoc ? pDoc->GetDocumentShell() : 0 ); 145cdf0e10cSrcweir if( pObjSh ) 146cdf0e10cSrcweir xModel.set( pObjSh->GetModel()); 147cdf0e10cSrcweir return xModel; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir uno::Reference< sheet::XSpreadsheetDocument > lcl_GetSpreadSheetDocument( ScDocument * pDoc ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir return uno::Reference< sheet::XSpreadsheetDocument >( lcl_GetXModel( pDoc ), uno::UNO_QUERY ); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir // ============================================================================ 156cdf0e10cSrcweir 157cdf0e10cSrcweir namespace { 158cdf0e10cSrcweir 159cdf0e10cSrcweir struct DeleteInstance : public unary_function<FormulaToken*, void> 160cdf0e10cSrcweir { 161cdf0e10cSrcweir void operator() (FormulaToken* p) const 162cdf0e10cSrcweir { 163cdf0e10cSrcweir delete p; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir }; 166cdf0e10cSrcweir 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir struct TokenTable 170cdf0e10cSrcweir { 171cdf0e10cSrcweir SCROW mnRowCount; 172cdf0e10cSrcweir SCCOL mnColCount; 173cdf0e10cSrcweir vector<FormulaToken*> maTokens; 174cdf0e10cSrcweir 175cdf0e10cSrcweir void init( SCCOL nColCount, SCROW nRowCount ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir mnColCount = nColCount; 178cdf0e10cSrcweir mnRowCount = nRowCount; 179cdf0e10cSrcweir maTokens.reserve(mnColCount*mnRowCount); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir void clear() 182cdf0e10cSrcweir { 183cdf0e10cSrcweir for_each(maTokens.begin(), maTokens.end(), DeleteInstance()); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir 186cdf0e10cSrcweir void push_back( FormulaToken* pToken ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir maTokens.push_back( pToken ); 189cdf0e10cSrcweir DBG_ASSERT( maTokens.size()<= static_cast<sal_uInt32>( mnColCount*mnRowCount ), "too much tokens" ); 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir sal_uInt32 getIndex(SCCOL nCol, SCROW nRow) const 193cdf0e10cSrcweir { 194cdf0e10cSrcweir DBG_ASSERT( nCol<mnColCount, "wrong column index" ); 195cdf0e10cSrcweir DBG_ASSERT( nRow<mnRowCount, "wrong row index" ); 196cdf0e10cSrcweir sal_uInt32 nRet = static_cast<sal_uInt32>(nCol*mnRowCount + nRow); 197cdf0e10cSrcweir DBG_ASSERT( maTokens.size()>= static_cast<sal_uInt32>( mnColCount*mnRowCount ), "too few tokens" ); 198cdf0e10cSrcweir return nRet; 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir vector<ScSharedTokenRef>* getColRanges(SCCOL nCol) const; 202cdf0e10cSrcweir vector<ScSharedTokenRef>* getRowRanges(SCROW nRow) const; 203cdf0e10cSrcweir vector<ScSharedTokenRef>* getAllRanges() const; 204cdf0e10cSrcweir }; 205cdf0e10cSrcweir 206cdf0e10cSrcweir vector<ScSharedTokenRef>* TokenTable::getColRanges(SCCOL nCol) const 207cdf0e10cSrcweir { 208cdf0e10cSrcweir if (nCol >= mnColCount) 209cdf0e10cSrcweir return NULL; 210cdf0e10cSrcweir if( mnRowCount<=0 ) 211cdf0e10cSrcweir return NULL; 212cdf0e10cSrcweir 213cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pTokens(new vector<ScSharedTokenRef>); 214cdf0e10cSrcweir sal_uInt32 nLast = getIndex(nCol, mnRowCount-1); 215cdf0e10cSrcweir for (sal_uInt32 i = getIndex(nCol, 0); i <= nLast; ++i) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir FormulaToken* p = maTokens[i]; 218cdf0e10cSrcweir if (!p) 219cdf0e10cSrcweir continue; 220cdf0e10cSrcweir 221cdf0e10cSrcweir ScSharedTokenRef pCopy(static_cast<ScToken*>(p->Clone())); 222cdf0e10cSrcweir ScRefTokenHelper::join(*pTokens, pCopy); 223cdf0e10cSrcweir } 224cdf0e10cSrcweir return pTokens.release(); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir vector<ScSharedTokenRef>* TokenTable::getRowRanges(SCROW nRow) const 228cdf0e10cSrcweir { 229cdf0e10cSrcweir if (nRow >= mnRowCount) 230cdf0e10cSrcweir return NULL; 231cdf0e10cSrcweir if( mnColCount<=0 ) 232cdf0e10cSrcweir return NULL; 233cdf0e10cSrcweir 234cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pTokens(new vector<ScSharedTokenRef>); 235cdf0e10cSrcweir sal_uInt32 nLast = getIndex(mnColCount-1, nRow); 236cdf0e10cSrcweir for (sal_uInt32 i = getIndex(0, nRow); i <= nLast; i += mnRowCount) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir FormulaToken* p = maTokens[i]; 239cdf0e10cSrcweir if (!p) 240cdf0e10cSrcweir continue; 241cdf0e10cSrcweir 242cdf0e10cSrcweir ScSharedTokenRef p2(static_cast<ScToken*>(p->Clone())); 243cdf0e10cSrcweir ScRefTokenHelper::join(*pTokens, p2); 244cdf0e10cSrcweir } 245cdf0e10cSrcweir return pTokens.release(); 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir vector<ScSharedTokenRef>* TokenTable::getAllRanges() const 249cdf0e10cSrcweir { 250cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pTokens(new vector<ScSharedTokenRef>); 251cdf0e10cSrcweir sal_uInt32 nStop = mnColCount*mnRowCount; 252cdf0e10cSrcweir for (sal_uInt32 i = 0; i < nStop; i++) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir FormulaToken* p = maTokens[i]; 255cdf0e10cSrcweir if (!p) 256cdf0e10cSrcweir continue; 257cdf0e10cSrcweir 258cdf0e10cSrcweir ScSharedTokenRef p2(static_cast<ScToken*>(p->Clone())); 259cdf0e10cSrcweir ScRefTokenHelper::join(*pTokens, p2); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir return pTokens.release(); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir 264cdf0e10cSrcweir // ============================================================================ 265cdf0e10cSrcweir 266cdf0e10cSrcweir class Chart2PositionMap 267cdf0e10cSrcweir { 268cdf0e10cSrcweir public: 269cdf0e10cSrcweir Chart2PositionMap(SCCOL nColCount, SCROW nRowCount, 270cdf0e10cSrcweir bool bFillRowHeader, bool bFillColumnHeader, Table& rCols, 271cdf0e10cSrcweir ScDocument* pDoc ); 272cdf0e10cSrcweir ~Chart2PositionMap(); 273cdf0e10cSrcweir 274cdf0e10cSrcweir SCCOL getDataColCount() const { return mnDataColCount; } 275cdf0e10cSrcweir SCROW getDataRowCount() const { return mnDataRowCount; } 276cdf0e10cSrcweir 277cdf0e10cSrcweir vector<ScSharedTokenRef>* getLeftUpperCornerRanges() const; 278cdf0e10cSrcweir vector<ScSharedTokenRef>* getAllColHeaderRanges() const; 279cdf0e10cSrcweir vector<ScSharedTokenRef>* getAllRowHeaderRanges() const; 280cdf0e10cSrcweir 281cdf0e10cSrcweir vector<ScSharedTokenRef>* getColHeaderRanges(SCCOL nChartCol) const; 282cdf0e10cSrcweir vector<ScSharedTokenRef>* getRowHeaderRanges(SCROW nChartRow) const; 283cdf0e10cSrcweir 284cdf0e10cSrcweir vector<ScSharedTokenRef>* getDataColRanges(SCCOL nCol) const; 285cdf0e10cSrcweir vector<ScSharedTokenRef>* getDataRowRanges(SCROW nRow) const; 286cdf0e10cSrcweir 287cdf0e10cSrcweir private: 288cdf0e10cSrcweir SCCOL mnDataColCount; 289cdf0e10cSrcweir SCROW mnDataRowCount; 290cdf0e10cSrcweir 291cdf0e10cSrcweir TokenTable maLeftUpperCorner; //nHeaderColCount*nHeaderRowCount 292cdf0e10cSrcweir TokenTable maColHeaders; //mnDataColCount*nHeaderRowCount 293cdf0e10cSrcweir TokenTable maRowHeaders; //nHeaderColCount*mnDataRowCount 294cdf0e10cSrcweir TokenTable maData;//mnDataColCount*mnDataRowCount 295cdf0e10cSrcweir }; 296cdf0e10cSrcweir 297cdf0e10cSrcweir Chart2PositionMap::Chart2PositionMap(SCCOL nAllColCount, SCROW nAllRowCount, 298cdf0e10cSrcweir bool bFillRowHeader, bool bFillColumnHeader, Table& rCols, ScDocument* pDoc) 299cdf0e10cSrcweir { 300cdf0e10cSrcweir // if bFillRowHeader is true, at least the first column serves as a row header. 301cdf0e10cSrcweir // If more than one column is pure text all the first pure text columns are used as header. 302cdf0e10cSrcweir // Likewise, if bFillColumnHeader is true, at least the first row serves as a column header. 303cdf0e10cSrcweir // If more than one row is pure text all the first pure text rows are used as header. 304cdf0e10cSrcweir 305cdf0e10cSrcweir SCROW nHeaderRowCount = (bFillColumnHeader && nAllColCount && nAllRowCount) ? 1 : 0; 306cdf0e10cSrcweir SCCOL nHeaderColCount = (bFillRowHeader && nAllColCount && nAllRowCount) ? 1 : 0; 307cdf0e10cSrcweir 308cdf0e10cSrcweir if( nHeaderColCount || nHeaderRowCount ) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir const SCCOL nInitialHeaderColCount = nHeaderColCount; 311cdf0e10cSrcweir //check whether there is more than one text column or row that should be added to the headers 312cdf0e10cSrcweir SCROW nSmallestValueRowIndex = nAllRowCount; 313cdf0e10cSrcweir bool bFoundValues = false; 314cdf0e10cSrcweir bool bFoundAnything = false; 315cdf0e10cSrcweir Table* pCol = static_cast<Table*>(rCols.First()); 316cdf0e10cSrcweir for (SCCOL nCol = 0; !bFoundValues && nCol < nAllColCount; ++nCol) 317cdf0e10cSrcweir { 318cdf0e10cSrcweir if (pCol && nCol>=nHeaderColCount) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir ScToken* pToken = static_cast<ScToken*>(pCol->First()); 321cdf0e10cSrcweir for (SCROW nRow = 0; !bFoundValues && nRow < nSmallestValueRowIndex; ++nRow) 322cdf0e10cSrcweir { 323cdf0e10cSrcweir if (pToken && nRow>=nHeaderRowCount) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir ScRange aRange; 326cdf0e10cSrcweir bool bExternal = false; 327cdf0e10cSrcweir StackVar eType = pToken->GetType(); 328cdf0e10cSrcweir if( eType==svExternal || eType==svExternalSingleRef || eType==svExternalDoubleRef || eType==svExternalName ) 329cdf0e10cSrcweir bExternal = true;//lllll todo correct? 330cdf0e10cSrcweir ScSharedTokenRef pSharedToken(static_cast<ScToken*>(pToken->Clone())); 331cdf0e10cSrcweir ScRefTokenHelper::getRangeFromToken(aRange, pSharedToken, bExternal ); 332cdf0e10cSrcweir SCCOL nCol1=0, nCol2=0; 333cdf0e10cSrcweir SCROW nRow1=0, nRow2=0; 334cdf0e10cSrcweir SCTAB nTab1=0, nTab2=0; 335cdf0e10cSrcweir aRange.GetVars( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ); 336cdf0e10cSrcweir if (pDoc && pDoc->HasValueData( nCol1, nRow1, nTab1 )) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir bFoundValues = bFoundAnything = true; 339cdf0e10cSrcweir nSmallestValueRowIndex = std::min( nSmallestValueRowIndex, nRow ); 340cdf0e10cSrcweir } 341cdf0e10cSrcweir if( !bFoundAnything ) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir if (pDoc && pDoc->HasData( nCol1, nRow1, nTab1 ) ) 344cdf0e10cSrcweir bFoundAnything = true; 345cdf0e10cSrcweir } 346cdf0e10cSrcweir } 347cdf0e10cSrcweir pToken = static_cast<ScToken*>(pCol->Next()); 348cdf0e10cSrcweir } 349cdf0e10cSrcweir if(!bFoundValues && nHeaderColCount>0) 350cdf0e10cSrcweir nHeaderColCount++; 351cdf0e10cSrcweir } 352cdf0e10cSrcweir pCol = static_cast<Table*>(rCols.Next()); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir if( bFoundAnything ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir if(nHeaderRowCount>0) 357cdf0e10cSrcweir { 358cdf0e10cSrcweir if( bFoundValues ) 359cdf0e10cSrcweir nHeaderRowCount = nSmallestValueRowIndex; 360cdf0e10cSrcweir else if( nAllRowCount>1 ) 361cdf0e10cSrcweir nHeaderRowCount = nAllRowCount-1; 362cdf0e10cSrcweir } 363cdf0e10cSrcweir } 364cdf0e10cSrcweir else //if the cells are completely empty, just use single header rows and columns 365cdf0e10cSrcweir nHeaderColCount = nInitialHeaderColCount; 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir mnDataColCount = nAllColCount - nHeaderColCount; 369cdf0e10cSrcweir mnDataRowCount = nAllRowCount - nHeaderRowCount; 370cdf0e10cSrcweir 371cdf0e10cSrcweir maLeftUpperCorner.init(nHeaderColCount,nHeaderRowCount); 372cdf0e10cSrcweir maColHeaders.init(mnDataColCount,nHeaderRowCount); 373cdf0e10cSrcweir maRowHeaders.init(nHeaderColCount,mnDataRowCount); 374cdf0e10cSrcweir maData.init(mnDataColCount,mnDataRowCount); 375cdf0e10cSrcweir 376cdf0e10cSrcweir Table* pCol = static_cast<Table*>(rCols.First()); 377cdf0e10cSrcweir FormulaToken* pToken = static_cast<FormulaToken*>(pCol->First()); 378cdf0e10cSrcweir for (SCCOL nCol = 0; nCol < nAllColCount; ++nCol) 379cdf0e10cSrcweir { 380cdf0e10cSrcweir if (pCol) 381cdf0e10cSrcweir { 382cdf0e10cSrcweir pToken = static_cast<FormulaToken*>(pCol->First()); 383cdf0e10cSrcweir for (SCROW nRow = 0; nRow < nAllRowCount; ++nRow) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir if( nCol < nHeaderColCount ) 386cdf0e10cSrcweir { 387cdf0e10cSrcweir if( nRow < nHeaderRowCount ) 388cdf0e10cSrcweir maLeftUpperCorner.push_back(pToken); 389cdf0e10cSrcweir else 390cdf0e10cSrcweir maRowHeaders.push_back(pToken); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir else if( nRow < nHeaderRowCount ) 393cdf0e10cSrcweir maColHeaders.push_back(pToken); 394cdf0e10cSrcweir else 395cdf0e10cSrcweir maData.push_back(pToken); 396cdf0e10cSrcweir 397cdf0e10cSrcweir pToken = static_cast<FormulaToken*>(pCol->Next()); 398cdf0e10cSrcweir } 399cdf0e10cSrcweir } 400cdf0e10cSrcweir pCol = static_cast<Table*>(rCols.Next()); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir } 403cdf0e10cSrcweir 404cdf0e10cSrcweir Chart2PositionMap::~Chart2PositionMap() 405cdf0e10cSrcweir { 406cdf0e10cSrcweir maLeftUpperCorner.clear(); 407cdf0e10cSrcweir maColHeaders.clear(); 408cdf0e10cSrcweir maRowHeaders.clear(); 409cdf0e10cSrcweir maData.clear(); 410cdf0e10cSrcweir } 411cdf0e10cSrcweir 412cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getLeftUpperCornerRanges() const 413cdf0e10cSrcweir { 414cdf0e10cSrcweir return maLeftUpperCorner.getAllRanges(); 415cdf0e10cSrcweir } 416cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getAllColHeaderRanges() const 417cdf0e10cSrcweir { 418cdf0e10cSrcweir return maColHeaders.getAllRanges(); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getAllRowHeaderRanges() const 421cdf0e10cSrcweir { 422cdf0e10cSrcweir return maRowHeaders.getAllRanges(); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getColHeaderRanges(SCCOL nCol) const 425cdf0e10cSrcweir { 426cdf0e10cSrcweir return maColHeaders.getColRanges( nCol); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getRowHeaderRanges(SCROW nRow) const 429cdf0e10cSrcweir { 430cdf0e10cSrcweir return maRowHeaders.getRowRanges( nRow); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getDataColRanges(SCCOL nCol) const 434cdf0e10cSrcweir { 435cdf0e10cSrcweir return maData.getColRanges( nCol); 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir vector<ScSharedTokenRef>* Chart2PositionMap::getDataRowRanges(SCROW nRow) const 439cdf0e10cSrcweir { 440cdf0e10cSrcweir return maData.getRowRanges( nRow); 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir // ---------------------------------------------------------------------------- 444cdf0e10cSrcweir 445cdf0e10cSrcweir /** 446cdf0e10cSrcweir * Designed to be a drop-in replacement for ScChartPositioner, in order to 447cdf0e10cSrcweir * handle external references. 448cdf0e10cSrcweir */ 449cdf0e10cSrcweir class Chart2Positioner 450cdf0e10cSrcweir { 451cdf0e10cSrcweir enum GlueType 452cdf0e10cSrcweir { 453cdf0e10cSrcweir GLUETYPE_NA, 454cdf0e10cSrcweir GLUETYPE_NONE, 455cdf0e10cSrcweir GLUETYPE_COLS, 456cdf0e10cSrcweir GLUETYPE_ROWS, 457cdf0e10cSrcweir GLUETYPE_BOTH 458cdf0e10cSrcweir }; 459cdf0e10cSrcweir 460cdf0e10cSrcweir public: 461cdf0e10cSrcweir Chart2Positioner(ScDocument* pDoc, const vector<ScSharedTokenRef>& rRefTokens) : 462cdf0e10cSrcweir mpRefTokens(new vector<ScSharedTokenRef>(rRefTokens)), 463cdf0e10cSrcweir mpPositionMap(NULL), 464cdf0e10cSrcweir meGlue(GLUETYPE_NA), 465cdf0e10cSrcweir mpDoc(pDoc), 466cdf0e10cSrcweir mbColHeaders(false), 467cdf0e10cSrcweir mbRowHeaders(false), 468cdf0e10cSrcweir mbDummyUpperLeft(false) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir } 471cdf0e10cSrcweir 472cdf0e10cSrcweir ~Chart2Positioner() 473cdf0e10cSrcweir { 474cdf0e10cSrcweir } 475cdf0e10cSrcweir 476cdf0e10cSrcweir void setHeaders(bool bColHeaders, bool bRowHeaders) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir mbColHeaders = bColHeaders; 479cdf0e10cSrcweir mbRowHeaders = bRowHeaders; 480cdf0e10cSrcweir } 481cdf0e10cSrcweir 482cdf0e10cSrcweir bool hasColHeaders() const { return mbColHeaders; } 483cdf0e10cSrcweir bool hasRowHeaders() const { return mbRowHeaders; } 484cdf0e10cSrcweir 485cdf0e10cSrcweir Chart2PositionMap* getPositionMap() 486cdf0e10cSrcweir { 487cdf0e10cSrcweir createPositionMap(); 488cdf0e10cSrcweir return mpPositionMap.get(); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir 491cdf0e10cSrcweir private: 492cdf0e10cSrcweir Chart2Positioner(); // disabled 493cdf0e10cSrcweir 494cdf0e10cSrcweir void invalidateGlue(); 495cdf0e10cSrcweir void glueState(); 496cdf0e10cSrcweir void createPositionMap(); 497cdf0e10cSrcweir 498cdf0e10cSrcweir private: 499cdf0e10cSrcweir shared_ptr< vector<ScSharedTokenRef> > mpRefTokens; 500cdf0e10cSrcweir auto_ptr<Chart2PositionMap> mpPositionMap; 501cdf0e10cSrcweir GlueType meGlue; 502cdf0e10cSrcweir SCCOL mnStartCol; 503cdf0e10cSrcweir SCROW mnStartRow; 504cdf0e10cSrcweir ScDocument* mpDoc; 505cdf0e10cSrcweir bool mbColHeaders:1; 506cdf0e10cSrcweir bool mbRowHeaders:1; 507cdf0e10cSrcweir bool mbDummyUpperLeft:1; 508cdf0e10cSrcweir }; 509cdf0e10cSrcweir 510cdf0e10cSrcweir void Chart2Positioner::invalidateGlue() 511cdf0e10cSrcweir { 512cdf0e10cSrcweir meGlue = GLUETYPE_NA; 513cdf0e10cSrcweir mpPositionMap.reset(NULL); 514cdf0e10cSrcweir } 515cdf0e10cSrcweir 516cdf0e10cSrcweir void Chart2Positioner::glueState() 517cdf0e10cSrcweir { 518cdf0e10cSrcweir if (meGlue != GLUETYPE_NA) 519cdf0e10cSrcweir return; 520cdf0e10cSrcweir 521cdf0e10cSrcweir mbDummyUpperLeft = false; 522cdf0e10cSrcweir if (mpRefTokens->size() <= 1) 523cdf0e10cSrcweir { 524cdf0e10cSrcweir const ScSharedTokenRef& p = mpRefTokens->front(); 525cdf0e10cSrcweir ScComplexRefData aData; 526cdf0e10cSrcweir if (ScRefTokenHelper::getDoubleRefDataFromToken(aData, p)) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir if (aData.Ref1.nTab == aData.Ref2.nTab) 529cdf0e10cSrcweir meGlue = GLUETYPE_NONE; 530cdf0e10cSrcweir else 531cdf0e10cSrcweir meGlue = GLUETYPE_COLS; 532cdf0e10cSrcweir mnStartCol = aData.Ref1.nCol; 533cdf0e10cSrcweir mnStartRow = aData.Ref1.nRow; 534cdf0e10cSrcweir } 535cdf0e10cSrcweir else 536cdf0e10cSrcweir { 537cdf0e10cSrcweir invalidateGlue(); 538cdf0e10cSrcweir mnStartCol = 0; 539cdf0e10cSrcweir mnStartRow = 0; 540cdf0e10cSrcweir } 541cdf0e10cSrcweir return; 542cdf0e10cSrcweir } 543cdf0e10cSrcweir 544cdf0e10cSrcweir ScComplexRefData aData; 545cdf0e10cSrcweir ScRefTokenHelper::getDoubleRefDataFromToken(aData, mpRefTokens->front()); 546cdf0e10cSrcweir mnStartCol = aData.Ref1.nCol; 547cdf0e10cSrcweir mnStartRow = aData.Ref1.nRow; 548cdf0e10cSrcweir 549cdf0e10cSrcweir SCCOL nMaxCols = 0, nEndCol = 0; 550cdf0e10cSrcweir SCROW nMaxRows = 0, nEndRow = 0; 551cdf0e10cSrcweir for (vector<ScSharedTokenRef>::const_iterator itr = mpRefTokens->begin(), itrEnd = mpRefTokens->end() 552cdf0e10cSrcweir ; itr != itrEnd; ++itr) 553cdf0e10cSrcweir { 554cdf0e10cSrcweir ScRefTokenHelper::getDoubleRefDataFromToken(aData, *itr); 555cdf0e10cSrcweir SCCOLROW n1 = aData.Ref1.nCol; 556cdf0e10cSrcweir SCCOLROW n2 = aData.Ref2.nCol; 557cdf0e10cSrcweir if (n1 > MAXCOL) 558cdf0e10cSrcweir n1 = MAXCOL; 559cdf0e10cSrcweir if (n2 > MAXCOL) 560cdf0e10cSrcweir n2 = MAXCOL; 561cdf0e10cSrcweir SCCOLROW nTmp = n2 - n1 + 1; 562cdf0e10cSrcweir if (n1 < mnStartCol) 563cdf0e10cSrcweir mnStartCol = static_cast<SCCOL>(n1); 564cdf0e10cSrcweir if (n2 > nEndCol) 565cdf0e10cSrcweir nEndCol = static_cast<SCCOL>(n2); 566cdf0e10cSrcweir if (nTmp > nMaxCols) 567cdf0e10cSrcweir nMaxCols = static_cast<SCCOL>(nTmp); 568cdf0e10cSrcweir 569cdf0e10cSrcweir n1 = aData.Ref1.nRow; 570cdf0e10cSrcweir n2 = aData.Ref2.nRow; 571cdf0e10cSrcweir if (n1 > MAXROW) 572cdf0e10cSrcweir n1 = MAXROW; 573cdf0e10cSrcweir if (n2 > MAXROW) 574cdf0e10cSrcweir n2 = MAXROW; 575cdf0e10cSrcweir nTmp = n2 - n1 + 1; 576cdf0e10cSrcweir 577cdf0e10cSrcweir if (n1 < mnStartRow) 578cdf0e10cSrcweir mnStartRow = static_cast<SCROW>(n1); 579cdf0e10cSrcweir if (n2 > nEndRow) 580cdf0e10cSrcweir nEndRow = static_cast<SCROW>(n2); 581cdf0e10cSrcweir if (nTmp > nMaxRows) 582cdf0e10cSrcweir nMaxRows = static_cast<SCROW>(nTmp); 583cdf0e10cSrcweir } 584cdf0e10cSrcweir 585cdf0e10cSrcweir // total column size ? 586cdf0e10cSrcweir SCCOL nC = nEndCol - mnStartCol + 1; 587cdf0e10cSrcweir if (nC == 1) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir meGlue = GLUETYPE_ROWS; 590cdf0e10cSrcweir return; 591cdf0e10cSrcweir } 592cdf0e10cSrcweir // total row size ? 593cdf0e10cSrcweir SCROW nR = nEndRow - mnStartRow + 1; 594cdf0e10cSrcweir if (nR == 1) 595cdf0e10cSrcweir { 596cdf0e10cSrcweir meGlue = GLUETYPE_COLS; 597cdf0e10cSrcweir return; 598cdf0e10cSrcweir } 599cdf0e10cSrcweir // #i103540# prevent invalid vector size 600cdf0e10cSrcweir if ((nC <= 0) || (nR <= 0)) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir invalidateGlue(); 603cdf0e10cSrcweir mnStartCol = 0; 604cdf0e10cSrcweir mnStartRow = 0; 605cdf0e10cSrcweir return; 606cdf0e10cSrcweir } 607cdf0e10cSrcweir sal_uInt32 nCR = static_cast<sal_uInt32>(nC*nR); 608cdf0e10cSrcweir 609cdf0e10cSrcweir const sal_uInt8 nHole = 0; 610cdf0e10cSrcweir const sal_uInt8 nOccu = 1; 611cdf0e10cSrcweir const sal_uInt8 nFree = 2; 612cdf0e10cSrcweir const sal_uInt8 nGlue = 3; 613cdf0e10cSrcweir 614cdf0e10cSrcweir vector<sal_uInt8> aCellStates(nCR); 615cdf0e10cSrcweir for (vector<ScSharedTokenRef>::const_iterator itr = mpRefTokens->begin(), itrEnd = mpRefTokens->end(); 616cdf0e10cSrcweir itr != itrEnd; ++itr) 617cdf0e10cSrcweir { 618cdf0e10cSrcweir ScRefTokenHelper::getDoubleRefDataFromToken(aData, *itr); 619cdf0e10cSrcweir SCCOL nCol1 = static_cast<SCCOL>(aData.Ref1.nCol) - mnStartCol; 620cdf0e10cSrcweir SCCOL nCol2 = static_cast<SCCOL>(aData.Ref2.nCol) - mnStartCol; 621cdf0e10cSrcweir SCROW nRow1 = static_cast<SCROW>(aData.Ref1.nRow) - mnStartRow; 622cdf0e10cSrcweir SCROW nRow2 = static_cast<SCROW>(aData.Ref2.nRow) - mnStartRow; 623cdf0e10cSrcweir for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol) 624cdf0e10cSrcweir for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow) 625cdf0e10cSrcweir { 626cdf0e10cSrcweir size_t i = nCol*nR + nRow; 627cdf0e10cSrcweir aCellStates[i] = nOccu; 628cdf0e10cSrcweir } 629cdf0e10cSrcweir } 630cdf0e10cSrcweir bool bGlue = true; 631cdf0e10cSrcweir 632cdf0e10cSrcweir size_t i = 0; 633cdf0e10cSrcweir bool bGlueCols = false; 634cdf0e10cSrcweir for (SCCOL nCol = 0; bGlue && nCol < nC; ++nCol) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir for (SCROW nRow = 0; bGlue && nRow < nR; ++nRow) 637cdf0e10cSrcweir { 638cdf0e10cSrcweir i = nCol*nR + nRow; 639cdf0e10cSrcweir if (aCellStates[i] == nOccu) 640cdf0e10cSrcweir { 641cdf0e10cSrcweir if (nRow > 0 && nRow > 0) 642cdf0e10cSrcweir bGlue = false; 643cdf0e10cSrcweir else 644cdf0e10cSrcweir nRow = nR; 645cdf0e10cSrcweir } 646cdf0e10cSrcweir else 647cdf0e10cSrcweir aCellStates[i] = nFree; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir i = (nCol+1)*nR - 1; // index for the last cell in the column. 650cdf0e10cSrcweir if (bGlue && (aCellStates[i] == nFree)) 651cdf0e10cSrcweir { 652cdf0e10cSrcweir aCellStates[i] = nGlue; 653cdf0e10cSrcweir bGlueCols = true; 654cdf0e10cSrcweir } 655cdf0e10cSrcweir } 656cdf0e10cSrcweir 657cdf0e10cSrcweir bool bGlueRows = false; 658cdf0e10cSrcweir for (SCROW nRow = 0; bGlue && nRow < nR; ++nRow) 659cdf0e10cSrcweir { 660cdf0e10cSrcweir i = nRow; 661cdf0e10cSrcweir for (SCCOL nCol = 0; bGlue && nCol < nC; ++nCol, i += nR) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir if (aCellStates[i] == nOccu) 664cdf0e10cSrcweir { 665cdf0e10cSrcweir if (nCol > 0 && nRow > 0) 666cdf0e10cSrcweir bGlue = false; 667cdf0e10cSrcweir else 668cdf0e10cSrcweir nCol = nC; 669cdf0e10cSrcweir } 670cdf0e10cSrcweir else 671cdf0e10cSrcweir aCellStates[i] = nFree; 672cdf0e10cSrcweir } 673cdf0e10cSrcweir i = (nC-1)*nR + nRow; // index for the row position in the last column. 674cdf0e10cSrcweir if (bGlue && aCellStates[i] == nFree) 675cdf0e10cSrcweir { 676cdf0e10cSrcweir aCellStates[i] = nGlue; 677cdf0e10cSrcweir bGlueRows = true; 678cdf0e10cSrcweir } 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir i = 1; 682cdf0e10cSrcweir for (sal_uInt32 n = 1; bGlue && n < nCR; ++n, ++i) 683cdf0e10cSrcweir if (aCellStates[i] == nHole) 684cdf0e10cSrcweir bGlue = false; 685cdf0e10cSrcweir 686cdf0e10cSrcweir if (bGlue) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir if (bGlueCols && bGlueRows) 689cdf0e10cSrcweir meGlue = GLUETYPE_BOTH; 690cdf0e10cSrcweir else if (bGlueRows) 691cdf0e10cSrcweir meGlue = GLUETYPE_ROWS; 692cdf0e10cSrcweir else 693cdf0e10cSrcweir meGlue = GLUETYPE_COLS; 694cdf0e10cSrcweir if (aCellStates.front() != nOccu) 695cdf0e10cSrcweir mbDummyUpperLeft = true; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir else 698cdf0e10cSrcweir meGlue = GLUETYPE_NONE; 699cdf0e10cSrcweir } 700cdf0e10cSrcweir 701cdf0e10cSrcweir void Chart2Positioner::createPositionMap() 702cdf0e10cSrcweir { 703cdf0e10cSrcweir if (meGlue == GLUETYPE_NA && mpPositionMap.get()) 704cdf0e10cSrcweir mpPositionMap.reset(NULL); 705cdf0e10cSrcweir 706cdf0e10cSrcweir if (mpPositionMap.get()) 707cdf0e10cSrcweir return; 708cdf0e10cSrcweir 709cdf0e10cSrcweir glueState(); 710cdf0e10cSrcweir 711cdf0e10cSrcweir bool bNoGlue = (meGlue == GLUETYPE_NONE); 712cdf0e10cSrcweir auto_ptr<Table> pCols(new Table); 713cdf0e10cSrcweir auto_ptr<FormulaToken> pNewAddress; 714cdf0e10cSrcweir auto_ptr<Table> pNewRowTable(new Table); 715cdf0e10cSrcweir Table* pCol = NULL; 716cdf0e10cSrcweir SCROW nNoGlueRow = 0; 717cdf0e10cSrcweir for (vector<ScSharedTokenRef>::const_iterator itr = mpRefTokens->begin(), itrEnd = mpRefTokens->end(); 718cdf0e10cSrcweir itr != itrEnd; ++itr) 719cdf0e10cSrcweir { 720cdf0e10cSrcweir const ScSharedTokenRef& pToken = *itr; 721cdf0e10cSrcweir 722cdf0e10cSrcweir bool bExternal = ScRefTokenHelper::isExternalRef(pToken); 723cdf0e10cSrcweir sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0; 724cdf0e10cSrcweir String aTabName = bExternal ? pToken->GetString() : String(); 725cdf0e10cSrcweir 726cdf0e10cSrcweir ScComplexRefData aData; 727cdf0e10cSrcweir ScRefTokenHelper::getDoubleRefDataFromToken(aData, *itr); 728cdf0e10cSrcweir const ScSingleRefData& s = aData.Ref1; 729cdf0e10cSrcweir const ScSingleRefData& e = aData.Ref2; 730cdf0e10cSrcweir SCCOL nCol1 = s.nCol, nCol2 = e.nCol; 731cdf0e10cSrcweir SCROW nRow1 = s.nRow, nRow2 = e.nRow; 732cdf0e10cSrcweir SCTAB nTab1 = s.nTab, nTab2 = e.nTab; 733cdf0e10cSrcweir 734cdf0e10cSrcweir for (SCTAB nTab = nTab1; nTab <= nTab2; ++nTab) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir // What's this for ??? 737cdf0e10cSrcweir sal_uInt32 nInsCol = (static_cast<sal_uInt32>(nTab) << 16) | 738cdf0e10cSrcweir (bNoGlue ? 0 : static_cast<sal_uInt32>(nCol1)); 739cdf0e10cSrcweir for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol, ++nInsCol) 740cdf0e10cSrcweir { 741cdf0e10cSrcweir if (bNoGlue || meGlue == GLUETYPE_ROWS) 742cdf0e10cSrcweir { 743cdf0e10cSrcweir pCol = static_cast<Table*>(pCols->Get(nInsCol)); 744cdf0e10cSrcweir if (!pCol) 745cdf0e10cSrcweir { 746cdf0e10cSrcweir pCol = pNewRowTable.get(); 747cdf0e10cSrcweir pCols->Insert(nInsCol, pNewRowTable.release()); 748cdf0e10cSrcweir pNewRowTable.reset(new Table); 749cdf0e10cSrcweir } 750cdf0e10cSrcweir } 751cdf0e10cSrcweir else 752cdf0e10cSrcweir { 753cdf0e10cSrcweir if (pCols->Insert(nInsCol, pNewRowTable.get())) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir pCol = pNewRowTable.release(); 756cdf0e10cSrcweir pNewRowTable.reset(new Table); 757cdf0e10cSrcweir } 758cdf0e10cSrcweir else 759cdf0e10cSrcweir pCol = static_cast<Table*>(pCols->Get(nInsCol)); 760cdf0e10cSrcweir } 761cdf0e10cSrcweir 762cdf0e10cSrcweir sal_uInt32 nInsRow = static_cast<sal_uInt32>(bNoGlue ? nNoGlueRow : nRow1); 763cdf0e10cSrcweir for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow, ++nInsRow) 764cdf0e10cSrcweir { 765cdf0e10cSrcweir ScSingleRefData aCellData; 766cdf0e10cSrcweir aCellData.InitFlags(); 767cdf0e10cSrcweir aCellData.SetFlag3D(true); 768cdf0e10cSrcweir aCellData.SetColRel(false); 769cdf0e10cSrcweir aCellData.SetRowRel(false); 770cdf0e10cSrcweir aCellData.SetTabRel(false); 771cdf0e10cSrcweir aCellData.nCol = nCol; 772cdf0e10cSrcweir aCellData.nRow = nRow; 773cdf0e10cSrcweir aCellData.nTab = nTab; 774cdf0e10cSrcweir 775cdf0e10cSrcweir if (bExternal) 776cdf0e10cSrcweir pNewAddress.reset(new ScExternalSingleRefToken(nFileId, aTabName, aCellData)); 777cdf0e10cSrcweir else 778cdf0e10cSrcweir pNewAddress.reset(new ScSingleRefToken(aCellData)); 779cdf0e10cSrcweir 780cdf0e10cSrcweir if (pCol->Insert(nInsRow, pNewAddress.get())) 781cdf0e10cSrcweir pNewAddress.release(); // To prevent the instance from being destroyed. 782cdf0e10cSrcweir } 783cdf0e10cSrcweir } 784cdf0e10cSrcweir } 785cdf0e10cSrcweir nNoGlueRow += nRow2 - nRow1 + 1; 786cdf0e10cSrcweir } 787cdf0e10cSrcweir pNewAddress.reset(NULL); 788cdf0e10cSrcweir pNewRowTable.reset(NULL); 789cdf0e10cSrcweir 790cdf0e10cSrcweir bool bFillRowHeader = mbRowHeaders; 791cdf0e10cSrcweir bool bFillColumnHeader = mbColHeaders; 792cdf0e10cSrcweir 793cdf0e10cSrcweir SCSIZE nAllColCount = static_cast<SCSIZE>(pCols->Count()); 794cdf0e10cSrcweir SCSIZE nAllRowCount = 0; 795cdf0e10cSrcweir pCol = static_cast<Table*>(pCols->First()); 796cdf0e10cSrcweir if (pCol) 797cdf0e10cSrcweir { 798cdf0e10cSrcweir if (mbDummyUpperLeft) 799cdf0e10cSrcweir pCol->Insert(0, NULL); // Dummy fuer Beschriftung 800cdf0e10cSrcweir nAllRowCount = static_cast<SCSIZE>(pCol->Count()); 801cdf0e10cSrcweir } 802cdf0e10cSrcweir 803cdf0e10cSrcweir if( nAllColCount!=0 && nAllRowCount!=0 ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir if (bNoGlue) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir Table* pFirstCol = static_cast<Table*>(pCols->First()); 808cdf0e10cSrcweir sal_uInt32 nCount = pFirstCol->Count(); 809cdf0e10cSrcweir pFirstCol->First(); 810cdf0e10cSrcweir for (sal_uInt32 n = 0; n < nCount; ++n, pFirstCol->Next()) 811cdf0e10cSrcweir { 812cdf0e10cSrcweir sal_uInt32 nKey = pFirstCol->GetCurKey(); 813cdf0e10cSrcweir pCols->First(); 814cdf0e10cSrcweir for (pCol = static_cast<Table*>(pCols->Next()); pCol; pCol = static_cast<Table*>(pCols->Next())) 815cdf0e10cSrcweir pCol->Insert(nKey, NULL); 816cdf0e10cSrcweir } 817cdf0e10cSrcweir } 818cdf0e10cSrcweir } 819cdf0e10cSrcweir mpPositionMap.reset( 820cdf0e10cSrcweir new Chart2PositionMap( 821cdf0e10cSrcweir static_cast<SCCOL>(nAllColCount), static_cast<SCROW>(nAllRowCount), 822cdf0e10cSrcweir bFillRowHeader, bFillColumnHeader, *pCols, mpDoc)); 823cdf0e10cSrcweir 824cdf0e10cSrcweir // Destroy all column instances. 825cdf0e10cSrcweir for (pCol = static_cast<Table*>(pCols->First()); pCol; pCol = static_cast<Table*>(pCols->Next())) 826cdf0e10cSrcweir delete pCol; 827cdf0e10cSrcweir } 828cdf0e10cSrcweir 829cdf0e10cSrcweir // ============================================================================ 830cdf0e10cSrcweir 831cdf0e10cSrcweir /** 832cdf0e10cSrcweir * Function object to create a range string from a token list. 833cdf0e10cSrcweir */ 834cdf0e10cSrcweir class Tokens2RangeString : public unary_function<ScSharedTokenRef, void> 835cdf0e10cSrcweir { 836cdf0e10cSrcweir public: 837cdf0e10cSrcweir Tokens2RangeString(ScDocument* pDoc, FormulaGrammar::Grammar eGram, sal_Unicode cRangeSep) : 838cdf0e10cSrcweir mpRangeStr(new OUStringBuffer), 839cdf0e10cSrcweir mpDoc(pDoc), 840cdf0e10cSrcweir meGrammar(eGram), 841cdf0e10cSrcweir mcRangeSep(cRangeSep), 842cdf0e10cSrcweir mbFirst(true) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir } 845cdf0e10cSrcweir 846cdf0e10cSrcweir Tokens2RangeString(const Tokens2RangeString& r) : 847cdf0e10cSrcweir mpRangeStr(r.mpRangeStr), 848cdf0e10cSrcweir mpDoc(r.mpDoc), 849cdf0e10cSrcweir meGrammar(r.meGrammar), 850cdf0e10cSrcweir mcRangeSep(r.mcRangeSep), 851cdf0e10cSrcweir mbFirst(r.mbFirst) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir void operator() (const ScSharedTokenRef& rToken) 856cdf0e10cSrcweir { 857cdf0e10cSrcweir ScCompiler aCompiler(mpDoc, ScAddress(0,0,0)); 858cdf0e10cSrcweir aCompiler.SetGrammar(meGrammar); 859cdf0e10cSrcweir String aStr; 860cdf0e10cSrcweir aCompiler.CreateStringFromToken(aStr, rToken.get()); 861cdf0e10cSrcweir if (mbFirst) 862cdf0e10cSrcweir mbFirst = false; 863cdf0e10cSrcweir else 864cdf0e10cSrcweir mpRangeStr->append(mcRangeSep); 865cdf0e10cSrcweir mpRangeStr->append(aStr); 866cdf0e10cSrcweir } 867cdf0e10cSrcweir 868cdf0e10cSrcweir void getString(OUString& rStr) 869cdf0e10cSrcweir { 870cdf0e10cSrcweir rStr = mpRangeStr->makeStringAndClear(); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir 873cdf0e10cSrcweir private: 874cdf0e10cSrcweir Tokens2RangeString(); // disabled 875cdf0e10cSrcweir 876cdf0e10cSrcweir private: 877cdf0e10cSrcweir shared_ptr<OUStringBuffer> mpRangeStr; 878cdf0e10cSrcweir ScDocument* mpDoc; 879cdf0e10cSrcweir FormulaGrammar::Grammar meGrammar; 880cdf0e10cSrcweir sal_Unicode mcRangeSep; 881cdf0e10cSrcweir bool mbFirst; 882cdf0e10cSrcweir }; 883cdf0e10cSrcweir 884cdf0e10cSrcweir /** 885cdf0e10cSrcweir * Function object to convert a list of tokens into a string form suitable 886cdf0e10cSrcweir * for ODF export. In ODF, a range is expressed as 887cdf0e10cSrcweir * 888cdf0e10cSrcweir * (start cell address):(end cell address) 889cdf0e10cSrcweir * 890cdf0e10cSrcweir * and each address doesn't include any '$' symbols. 891cdf0e10cSrcweir */ 892cdf0e10cSrcweir class Tokens2RangeStringXML : public unary_function<ScSharedTokenRef, void> 893cdf0e10cSrcweir { 894cdf0e10cSrcweir public: 895cdf0e10cSrcweir Tokens2RangeStringXML(ScDocument* pDoc) : 896cdf0e10cSrcweir mpRangeStr(new OUStringBuffer), 897cdf0e10cSrcweir mpDoc(pDoc), 898cdf0e10cSrcweir mcRangeSep(' '), 899cdf0e10cSrcweir mcAddrSep(':'), 900cdf0e10cSrcweir mbFirst(true) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir } 903cdf0e10cSrcweir 904cdf0e10cSrcweir Tokens2RangeStringXML(const Tokens2RangeStringXML& r) : 905cdf0e10cSrcweir mpRangeStr(r.mpRangeStr), 906cdf0e10cSrcweir mpDoc(r.mpDoc), 907cdf0e10cSrcweir mcRangeSep(r.mcRangeSep), 908cdf0e10cSrcweir mcAddrSep(r.mcAddrSep), 909cdf0e10cSrcweir mbFirst(r.mbFirst) 910cdf0e10cSrcweir { 911cdf0e10cSrcweir } 912cdf0e10cSrcweir 913cdf0e10cSrcweir void operator() (const ScSharedTokenRef& rToken) 914cdf0e10cSrcweir { 915cdf0e10cSrcweir if (mbFirst) 916cdf0e10cSrcweir mbFirst = false; 917cdf0e10cSrcweir else 918cdf0e10cSrcweir mpRangeStr->append(mcRangeSep); 919cdf0e10cSrcweir 920cdf0e10cSrcweir ScSharedTokenRef aStart, aEnd; 921cdf0e10cSrcweir splitRangeToken(rToken, aStart, aEnd); 922cdf0e10cSrcweir ScCompiler aCompiler(mpDoc, ScAddress(0,0,0)); 923cdf0e10cSrcweir aCompiler.SetGrammar(FormulaGrammar::GRAM_ENGLISH); 924cdf0e10cSrcweir { 925cdf0e10cSrcweir String aStr; 926cdf0e10cSrcweir aCompiler.CreateStringFromToken(aStr, aStart.get()); 927cdf0e10cSrcweir mpRangeStr->append(aStr); 928cdf0e10cSrcweir } 929cdf0e10cSrcweir mpRangeStr->append(mcAddrSep); 930cdf0e10cSrcweir { 931cdf0e10cSrcweir String aStr; 932cdf0e10cSrcweir aCompiler.CreateStringFromToken(aStr, aEnd.get()); 933cdf0e10cSrcweir mpRangeStr->append(aStr); 934cdf0e10cSrcweir } 935cdf0e10cSrcweir } 936cdf0e10cSrcweir 937cdf0e10cSrcweir void getString(OUString& rStr) 938cdf0e10cSrcweir { 939cdf0e10cSrcweir rStr = mpRangeStr->makeStringAndClear(); 940cdf0e10cSrcweir } 941cdf0e10cSrcweir 942cdf0e10cSrcweir private: 943cdf0e10cSrcweir Tokens2RangeStringXML(); // disabled 944cdf0e10cSrcweir 945cdf0e10cSrcweir void splitRangeToken(const ScSharedTokenRef& pToken, ScSharedTokenRef& rStart, ScSharedTokenRef& rEnd) const 946cdf0e10cSrcweir { 947cdf0e10cSrcweir ScComplexRefData aData; 948cdf0e10cSrcweir ScRefTokenHelper::getDoubleRefDataFromToken(aData, pToken); 949cdf0e10cSrcweir bool bExternal = ScRefTokenHelper::isExternalRef(pToken); 950cdf0e10cSrcweir sal_uInt16 nFileId = bExternal ? pToken->GetIndex() : 0; 951cdf0e10cSrcweir String aTabName = bExternal ? pToken->GetString() : String(); 952cdf0e10cSrcweir 953cdf0e10cSrcweir // In saving to XML, we don't prepend address with '$'. 954cdf0e10cSrcweir setRelative(aData.Ref1); 955cdf0e10cSrcweir setRelative(aData.Ref2); 956cdf0e10cSrcweir 957cdf0e10cSrcweir // In XML, the end range must explicitly specify sheet name. 958cdf0e10cSrcweir aData.Ref2.SetFlag3D(true); 959cdf0e10cSrcweir 960cdf0e10cSrcweir if (bExternal) 961cdf0e10cSrcweir rStart.reset(new ScExternalSingleRefToken(nFileId, aTabName, aData.Ref1)); 962cdf0e10cSrcweir else 963cdf0e10cSrcweir rStart.reset(new ScSingleRefToken(aData.Ref1)); 964cdf0e10cSrcweir 965cdf0e10cSrcweir if (bExternal) 966cdf0e10cSrcweir rEnd.reset(new ScExternalSingleRefToken(nFileId, aTabName, aData.Ref2)); 967cdf0e10cSrcweir else 968cdf0e10cSrcweir rEnd.reset(new ScSingleRefToken(aData.Ref2)); 969cdf0e10cSrcweir } 970cdf0e10cSrcweir 971cdf0e10cSrcweir void setRelative(ScSingleRefData& rData) const 972cdf0e10cSrcweir { 973cdf0e10cSrcweir rData.SetColRel(true); 974cdf0e10cSrcweir rData.SetRowRel(true); 975cdf0e10cSrcweir rData.SetTabRel(true); 976cdf0e10cSrcweir } 977cdf0e10cSrcweir 978cdf0e10cSrcweir private: 979cdf0e10cSrcweir shared_ptr<OUStringBuffer> mpRangeStr; 980cdf0e10cSrcweir ScDocument* mpDoc; 981cdf0e10cSrcweir sal_Unicode mcRangeSep; 982cdf0e10cSrcweir sal_Unicode mcAddrSep; 983cdf0e10cSrcweir bool mbFirst; 984cdf0e10cSrcweir }; 985cdf0e10cSrcweir 986cdf0e10cSrcweir void lcl_convertTokensToString(OUString& rStr, const vector<ScSharedTokenRef>& rTokens, ScDocument* pDoc) 987cdf0e10cSrcweir { 988cdf0e10cSrcweir const sal_Unicode cRangeSep = ScCompiler::GetNativeSymbol(ocSep).GetChar(0); 989cdf0e10cSrcweir FormulaGrammar::Grammar eGrammar = pDoc->GetGrammar(); 990cdf0e10cSrcweir Tokens2RangeString func(pDoc, eGrammar, cRangeSep); 991cdf0e10cSrcweir func = for_each(rTokens.begin(), rTokens.end(), func); 992cdf0e10cSrcweir func.getString(rStr); 993cdf0e10cSrcweir } 994cdf0e10cSrcweir 995cdf0e10cSrcweir } // anonymous namespace 996cdf0e10cSrcweir 997cdf0e10cSrcweir // DataProvider ============================================================== 998cdf0e10cSrcweir 999cdf0e10cSrcweir ScChart2DataProvider::ScChart2DataProvider( ScDocument* pDoc ) 1000cdf0e10cSrcweir : m_pDocument( pDoc) 1001cdf0e10cSrcweir , m_aPropSet(lcl_GetDataProviderPropertyMap()) 1002cdf0e10cSrcweir , m_bIncludeHiddenCells( sal_True) 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir if ( m_pDocument ) 1005cdf0e10cSrcweir m_pDocument->AddUnoObject( *this); 1006cdf0e10cSrcweir } 1007cdf0e10cSrcweir 1008cdf0e10cSrcweir ScChart2DataProvider::~ScChart2DataProvider() 1009cdf0e10cSrcweir { 1010cdf0e10cSrcweir if ( m_pDocument ) 1011cdf0e10cSrcweir m_pDocument->RemoveUnoObject( *this); 1012cdf0e10cSrcweir } 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir 1015cdf0e10cSrcweir void ScChart2DataProvider::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint) 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && 1018cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 1019cdf0e10cSrcweir { 1020cdf0e10cSrcweir m_pDocument = NULL; 1021cdf0e10cSrcweir } 1022cdf0e10cSrcweir } 1023cdf0e10cSrcweir 1024cdf0e10cSrcweir ::sal_Bool SAL_CALL ScChart2DataProvider::createDataSourcePossible( const uno::Sequence< beans::PropertyValue >& aArguments ) 1025cdf0e10cSrcweir throw (uno::RuntimeException) 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir ScUnoGuard aGuard; 1028cdf0e10cSrcweir if( ! m_pDocument ) 1029cdf0e10cSrcweir return false; 1030cdf0e10cSrcweir 1031cdf0e10cSrcweir rtl::OUString aRangeRepresentation; 1032cdf0e10cSrcweir for(sal_Int32 i = 0; i < aArguments.getLength(); ++i) 1033cdf0e10cSrcweir { 1034cdf0e10cSrcweir rtl::OUString sName(aArguments[i].Name); 1035cdf0e10cSrcweir if (aArguments[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CellRangeRepresentation"))) 1036cdf0e10cSrcweir { 1037cdf0e10cSrcweir aArguments[i].Value >>= aRangeRepresentation; 1038cdf0e10cSrcweir } 1039cdf0e10cSrcweir } 1040cdf0e10cSrcweir 1041cdf0e10cSrcweir vector<ScSharedTokenRef> aTokens; 1042cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation(aTokens, aRangeRepresentation, m_pDocument, m_pDocument->GetGrammar()); 1043cdf0e10cSrcweir return !aTokens.empty(); 1044cdf0e10cSrcweir } 1045cdf0e10cSrcweir 1046cdf0e10cSrcweir namespace 1047cdf0e10cSrcweir { 1048cdf0e10cSrcweir 1049cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > lcl_createLabeledDataSequenceFromTokens( 1050cdf0e10cSrcweir auto_ptr< vector< ScSharedTokenRef > > pValueTokens, auto_ptr< vector< ScSharedTokenRef > > pLabelTokens, 1051cdf0e10cSrcweir ScDocument* pDoc, const Reference< chart2::data::XDataProvider >& xDP, bool bIncludeHiddenCells ) 1052cdf0e10cSrcweir { 1053cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xResult; 1054cdf0e10cSrcweir bool bHasValues = pValueTokens.get() && !pValueTokens->empty(); 1055cdf0e10cSrcweir bool bHasLabel = pLabelTokens.get() && !pLabelTokens->empty(); 1056cdf0e10cSrcweir if( bHasValues || bHasLabel ) 1057cdf0e10cSrcweir { 1058cdf0e10cSrcweir try 1059cdf0e10cSrcweir { 1060cdf0e10cSrcweir Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() ); 1061cdf0e10cSrcweir if ( xContext.is() ) 1062cdf0e10cSrcweir { 1063cdf0e10cSrcweir xResult.set( xContext->getServiceManager()->createInstanceWithContext( 1064cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.chart2.data.LabeledDataSequence" ), 1065cdf0e10cSrcweir xContext ), uno::UNO_QUERY_THROW ); 1066cdf0e10cSrcweir } 1067cdf0e10cSrcweir if ( bHasValues ) 1068cdf0e10cSrcweir { 1069cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xSeq( new ScChart2DataSequence( pDoc, xDP, pValueTokens.release(), bIncludeHiddenCells ) ); 1070cdf0e10cSrcweir xResult->setValues( xSeq ); 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir if ( bHasLabel ) 1073cdf0e10cSrcweir { 1074cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xLabelSeq( new ScChart2DataSequence( pDoc, xDP, pLabelTokens.release(), bIncludeHiddenCells ) ); 1075cdf0e10cSrcweir xResult->setLabel( xLabelSeq ); 1076cdf0e10cSrcweir } 1077cdf0e10cSrcweir } 1078cdf0e10cSrcweir catch( const uno::Exception& ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir } 1081cdf0e10cSrcweir } 1082cdf0e10cSrcweir return xResult; 1083cdf0e10cSrcweir } 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir //---------------------------------------------------- 1086cdf0e10cSrcweir /** 1087cdf0e10cSrcweir * Check the current list of reference tokens, and add the upper left 1088cdf0e10cSrcweir * corner of the minimum range that encloses all ranges if certain 1089cdf0e10cSrcweir * conditions are met. 1090cdf0e10cSrcweir * 1091cdf0e10cSrcweir * @param rRefTokens list of reference tokens 1092cdf0e10cSrcweir * 1093cdf0e10cSrcweir * @return true if the corner was added, false otherwise. 1094cdf0e10cSrcweir */ 1095cdf0e10cSrcweir bool lcl_addUpperLeftCornerIfMissing(vector<ScSharedTokenRef>& rRefTokens, 1096cdf0e10cSrcweir SCROW nCornerRowCount=1, SCCOL nCornerColumnCount=1) 1097cdf0e10cSrcweir { 1098cdf0e10cSrcweir using ::std::max; 1099cdf0e10cSrcweir using ::std::min; 1100cdf0e10cSrcweir 1101cdf0e10cSrcweir if (rRefTokens.empty()) 1102cdf0e10cSrcweir return false; 1103cdf0e10cSrcweir 1104cdf0e10cSrcweir SCCOL nMinCol = MAXCOLCOUNT; 1105cdf0e10cSrcweir SCROW nMinRow = MAXROWCOUNT; 1106cdf0e10cSrcweir SCCOL nMaxCol = 0; 1107cdf0e10cSrcweir SCROW nMaxRow = 0; 1108cdf0e10cSrcweir SCTAB nTab = 0; 1109cdf0e10cSrcweir 1110cdf0e10cSrcweir sal_uInt16 nFileId = 0; 1111cdf0e10cSrcweir String aExtTabName; 1112cdf0e10cSrcweir bool bExternal = false; 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = rRefTokens.begin(), itrEnd = rRefTokens.end(); 1115cdf0e10cSrcweir 1116cdf0e10cSrcweir // Get the first ref token. 1117cdf0e10cSrcweir ScSharedTokenRef pToken = *itr; 1118cdf0e10cSrcweir switch (pToken->GetType()) 1119cdf0e10cSrcweir { 1120cdf0e10cSrcweir case svSingleRef: 1121cdf0e10cSrcweir { 1122cdf0e10cSrcweir const ScSingleRefData& rData = pToken->GetSingleRef(); 1123cdf0e10cSrcweir nMinCol = rData.nCol; 1124cdf0e10cSrcweir nMinRow = rData.nRow; 1125cdf0e10cSrcweir nMaxCol = rData.nCol; 1126cdf0e10cSrcweir nMaxRow = rData.nRow; 1127cdf0e10cSrcweir nTab = rData.nTab; 1128cdf0e10cSrcweir } 1129cdf0e10cSrcweir break; 1130cdf0e10cSrcweir case svDoubleRef: 1131cdf0e10cSrcweir { 1132cdf0e10cSrcweir const ScComplexRefData& rData = pToken->GetDoubleRef(); 1133cdf0e10cSrcweir nMinCol = min(rData.Ref1.nCol, rData.Ref2.nCol); 1134cdf0e10cSrcweir nMinRow = min(rData.Ref1.nRow, rData.Ref2.nRow); 1135cdf0e10cSrcweir nMaxCol = max(rData.Ref1.nCol, rData.Ref2.nCol); 1136cdf0e10cSrcweir nMaxRow = max(rData.Ref1.nRow, rData.Ref2.nRow); 1137cdf0e10cSrcweir nTab = rData.Ref1.nTab; 1138cdf0e10cSrcweir } 1139cdf0e10cSrcweir break; 1140cdf0e10cSrcweir case svExternalSingleRef: 1141cdf0e10cSrcweir { 1142cdf0e10cSrcweir const ScSingleRefData& rData = pToken->GetSingleRef(); 1143cdf0e10cSrcweir nMinCol = rData.nCol; 1144cdf0e10cSrcweir nMinRow = rData.nRow; 1145cdf0e10cSrcweir nMaxCol = rData.nCol; 1146cdf0e10cSrcweir nMaxRow = rData.nRow; 1147cdf0e10cSrcweir nTab = rData.nTab; 1148cdf0e10cSrcweir nFileId = pToken->GetIndex(); 1149cdf0e10cSrcweir aExtTabName = pToken->GetString(); 1150cdf0e10cSrcweir bExternal = true; 1151cdf0e10cSrcweir } 1152cdf0e10cSrcweir break; 1153cdf0e10cSrcweir case svExternalDoubleRef: 1154cdf0e10cSrcweir { 1155cdf0e10cSrcweir const ScComplexRefData& rData = pToken->GetDoubleRef(); 1156cdf0e10cSrcweir nMinCol = min(rData.Ref1.nCol, rData.Ref2.nCol); 1157cdf0e10cSrcweir nMinRow = min(rData.Ref1.nRow, rData.Ref2.nRow); 1158cdf0e10cSrcweir nMaxCol = max(rData.Ref1.nCol, rData.Ref2.nCol); 1159cdf0e10cSrcweir nMaxRow = max(rData.Ref1.nRow, rData.Ref2.nRow); 1160cdf0e10cSrcweir nTab = rData.Ref1.nTab; 1161cdf0e10cSrcweir nFileId = pToken->GetIndex(); 1162cdf0e10cSrcweir aExtTabName = pToken->GetString(); 1163cdf0e10cSrcweir bExternal = true; 1164cdf0e10cSrcweir } 1165cdf0e10cSrcweir break; 1166cdf0e10cSrcweir default: 1167cdf0e10cSrcweir ; 1168cdf0e10cSrcweir } 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir // Determine the minimum range enclosing all data ranges. Also make sure 1171cdf0e10cSrcweir // that they are all on the same table. 1172cdf0e10cSrcweir 1173cdf0e10cSrcweir for (++itr; itr != itrEnd; ++itr) 1174cdf0e10cSrcweir { 1175cdf0e10cSrcweir pToken = *itr; 1176cdf0e10cSrcweir switch (pToken->GetType()) 1177cdf0e10cSrcweir { 1178cdf0e10cSrcweir case svSingleRef: 1179cdf0e10cSrcweir { 1180cdf0e10cSrcweir const ScSingleRefData& rData = pToken->GetSingleRef(); 1181cdf0e10cSrcweir 1182cdf0e10cSrcweir nMinCol = min(nMinCol, rData.nCol); 1183cdf0e10cSrcweir nMinRow = min(nMinRow, rData.nRow); 1184cdf0e10cSrcweir nMaxCol = max(nMaxCol, rData.nCol); 1185cdf0e10cSrcweir nMaxRow = max(nMaxRow, rData.nRow); 1186cdf0e10cSrcweir if (nTab != rData.nTab || bExternal) 1187cdf0e10cSrcweir return false; 1188cdf0e10cSrcweir } 1189cdf0e10cSrcweir break; 1190cdf0e10cSrcweir case svDoubleRef: 1191cdf0e10cSrcweir { 1192cdf0e10cSrcweir const ScComplexRefData& rData = pToken->GetDoubleRef(); 1193cdf0e10cSrcweir 1194cdf0e10cSrcweir nMinCol = min(nMinCol, rData.Ref1.nCol); 1195cdf0e10cSrcweir nMinCol = min(nMinCol, rData.Ref2.nCol); 1196cdf0e10cSrcweir nMinRow = min(nMinRow, rData.Ref1.nRow); 1197cdf0e10cSrcweir nMinRow = min(nMinRow, rData.Ref2.nRow); 1198cdf0e10cSrcweir 1199cdf0e10cSrcweir nMaxCol = max(nMaxCol, rData.Ref1.nCol); 1200cdf0e10cSrcweir nMaxCol = max(nMaxCol, rData.Ref2.nCol); 1201cdf0e10cSrcweir nMaxRow = max(nMaxRow, rData.Ref1.nRow); 1202cdf0e10cSrcweir nMaxRow = max(nMaxRow, rData.Ref2.nRow); 1203cdf0e10cSrcweir 1204cdf0e10cSrcweir if (nTab != rData.Ref1.nTab || bExternal) 1205cdf0e10cSrcweir return false; 1206cdf0e10cSrcweir } 1207cdf0e10cSrcweir break; 1208cdf0e10cSrcweir case svExternalSingleRef: 1209cdf0e10cSrcweir { 1210cdf0e10cSrcweir if (!bExternal) 1211cdf0e10cSrcweir return false; 1212cdf0e10cSrcweir 1213cdf0e10cSrcweir if (nFileId != pToken->GetIndex() || aExtTabName != pToken->GetString()) 1214cdf0e10cSrcweir return false; 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir const ScSingleRefData& rData = pToken->GetSingleRef(); 1217cdf0e10cSrcweir 1218cdf0e10cSrcweir nMinCol = min(nMinCol, rData.nCol); 1219cdf0e10cSrcweir nMinRow = min(nMinRow, rData.nRow); 1220cdf0e10cSrcweir nMaxCol = max(nMaxCol, rData.nCol); 1221cdf0e10cSrcweir nMaxRow = max(nMaxRow, rData.nRow); 1222cdf0e10cSrcweir } 1223cdf0e10cSrcweir break; 1224cdf0e10cSrcweir case svExternalDoubleRef: 1225cdf0e10cSrcweir { 1226cdf0e10cSrcweir if (!bExternal) 1227cdf0e10cSrcweir return false; 1228cdf0e10cSrcweir 1229cdf0e10cSrcweir if (nFileId != pToken->GetIndex() || aExtTabName != pToken->GetString()) 1230cdf0e10cSrcweir return false; 1231cdf0e10cSrcweir 1232cdf0e10cSrcweir const ScComplexRefData& rData = pToken->GetDoubleRef(); 1233cdf0e10cSrcweir 1234cdf0e10cSrcweir nMinCol = min(nMinCol, rData.Ref1.nCol); 1235cdf0e10cSrcweir nMinCol = min(nMinCol, rData.Ref2.nCol); 1236cdf0e10cSrcweir nMinRow = min(nMinRow, rData.Ref1.nRow); 1237cdf0e10cSrcweir nMinRow = min(nMinRow, rData.Ref2.nRow); 1238cdf0e10cSrcweir 1239cdf0e10cSrcweir nMaxCol = max(nMaxCol, rData.Ref1.nCol); 1240cdf0e10cSrcweir nMaxCol = max(nMaxCol, rData.Ref2.nCol); 1241cdf0e10cSrcweir nMaxRow = max(nMaxRow, rData.Ref1.nRow); 1242cdf0e10cSrcweir nMaxRow = max(nMaxRow, rData.Ref2.nRow); 1243cdf0e10cSrcweir } 1244cdf0e10cSrcweir break; 1245cdf0e10cSrcweir default: 1246cdf0e10cSrcweir ; 1247cdf0e10cSrcweir } 1248cdf0e10cSrcweir } 1249cdf0e10cSrcweir 1250cdf0e10cSrcweir if (nMinRow >= nMaxRow || nMinCol >= nMaxCol || 1251cdf0e10cSrcweir nMinRow >= MAXROWCOUNT || nMinCol >= MAXCOLCOUNT || 1252cdf0e10cSrcweir nMaxRow >= MAXROWCOUNT || nMaxCol >= MAXCOLCOUNT) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir // Invalid range. Bail out. 1255cdf0e10cSrcweir return false; 1256cdf0e10cSrcweir } 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir // Check if the following conditions are met: 1259cdf0e10cSrcweir // 1260cdf0e10cSrcweir // 1) The upper-left corner cell is not included. 1261cdf0e10cSrcweir // 2) The three adjacent cells of that corner cell are included. 1262cdf0e10cSrcweir 1263cdf0e10cSrcweir bool bRight = false, bBottom = false, bDiagonal = false; 1264cdf0e10cSrcweir for (itr = rRefTokens.begin(); itr != itrEnd; ++itr) 1265cdf0e10cSrcweir { 1266cdf0e10cSrcweir pToken = *itr; 1267cdf0e10cSrcweir switch (pToken->GetType()) 1268cdf0e10cSrcweir { 1269cdf0e10cSrcweir case svSingleRef: 1270cdf0e10cSrcweir case svExternalSingleRef: 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir const ScSingleRefData& rData = pToken->GetSingleRef(); 1273cdf0e10cSrcweir if (rData.nCol == nMinCol && rData.nRow == nMinRow) 1274cdf0e10cSrcweir // The corner cell is contained. 1275cdf0e10cSrcweir return false; 1276cdf0e10cSrcweir 1277cdf0e10cSrcweir if (rData.nCol == nMinCol+nCornerColumnCount && rData.nRow == nMinRow) 1278cdf0e10cSrcweir bRight = true; 1279cdf0e10cSrcweir 1280cdf0e10cSrcweir if (rData.nCol == nMinCol && rData.nRow == nMinRow+nCornerRowCount) 1281cdf0e10cSrcweir bBottom = true; 1282cdf0e10cSrcweir 1283cdf0e10cSrcweir if (rData.nCol == nMinCol+nCornerColumnCount && rData.nRow == nMinRow+nCornerRowCount) 1284cdf0e10cSrcweir bDiagonal = true; 1285cdf0e10cSrcweir } 1286cdf0e10cSrcweir break; 1287cdf0e10cSrcweir case svDoubleRef: 1288cdf0e10cSrcweir case svExternalDoubleRef: 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir const ScComplexRefData& rData = pToken->GetDoubleRef(); 1291cdf0e10cSrcweir const ScSingleRefData& r1 = rData.Ref1; 1292cdf0e10cSrcweir const ScSingleRefData& r2 = rData.Ref2; 1293cdf0e10cSrcweir if (r1.nCol <= nMinCol && nMinCol <= r2.nCol && 1294cdf0e10cSrcweir r1.nRow <= nMinRow && nMinRow <= r2.nRow) 1295cdf0e10cSrcweir // The corner cell is contained. 1296cdf0e10cSrcweir return false; 1297cdf0e10cSrcweir 1298cdf0e10cSrcweir if (r1.nCol <= nMinCol+nCornerColumnCount && nMinCol+nCornerColumnCount <= r2.nCol && 1299cdf0e10cSrcweir r1.nRow <= nMinRow && nMinRow <= r2.nRow) 1300cdf0e10cSrcweir bRight = true; 1301cdf0e10cSrcweir 1302cdf0e10cSrcweir if (r1.nCol <= nMinCol && nMinCol <= r2.nCol && 1303cdf0e10cSrcweir r1.nRow <= nMinRow+nCornerRowCount && nMinRow+nCornerRowCount <= r2.nRow) 1304cdf0e10cSrcweir bBottom = true; 1305cdf0e10cSrcweir 1306cdf0e10cSrcweir if (r1.nCol <= nMinCol+nCornerColumnCount && nMinCol+nCornerColumnCount <= r2.nCol && 1307cdf0e10cSrcweir r1.nRow <= nMinRow+nCornerRowCount && nMinRow+nCornerRowCount <= r2.nRow) 1308cdf0e10cSrcweir bDiagonal = true; 1309cdf0e10cSrcweir } 1310cdf0e10cSrcweir break; 1311cdf0e10cSrcweir default: 1312cdf0e10cSrcweir ; 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir } 1315cdf0e10cSrcweir 1316cdf0e10cSrcweir if (!bRight || !bBottom || !bDiagonal) 1317cdf0e10cSrcweir // Not all the adjacent cells are included. Bail out. 1318cdf0e10cSrcweir return false; 1319cdf0e10cSrcweir 1320cdf0e10cSrcweir #if 0 // Do we really need to do this ??? 1321cdf0e10cSrcweir if (rRefTokens.size() == 2) 1322cdf0e10cSrcweir { 1323cdf0e10cSrcweir // Make a simple rectangular range if possible. 1324cdf0e10cSrcweir ScRange aRightPart(ScAddress(nMinCol+1, nMinRow, nTab), ScAddress(nMaxCol, nMaxRow, nTab)); 1325cdf0e10cSrcweir ScRange aBottomPart(ScAddress(nMinCol, nMinRow+1, nTab), ScAddress(nMaxCol, nMaxRow, nTab)); 1326cdf0e10cSrcweir vector<ScRange> aRanges; 1327cdf0e10cSrcweir aRanges.reserve(2); 1328cdf0e10cSrcweir aRanges.push_back(aRightPart); 1329cdf0e10cSrcweir aRanges.push_back(aBottomPart); 1330cdf0e10cSrcweir if (lcl_isRangeContained(rRefTokens, aRanges)) 1331cdf0e10cSrcweir { 1332cdf0e10cSrcweir // Consolidate them into a single rectangle. 1333cdf0e10cSrcweir ScComplexRefData aData; 1334cdf0e10cSrcweir aData.InitFlags(); 1335cdf0e10cSrcweir aData.Ref1.SetFlag3D(true); 1336cdf0e10cSrcweir aData.Ref1.SetColRel(false); 1337cdf0e10cSrcweir aData.Ref1.SetRowRel(false); 1338cdf0e10cSrcweir aData.Ref1.SetTabRel(false); 1339cdf0e10cSrcweir aData.Ref2.SetColRel(false); 1340cdf0e10cSrcweir aData.Ref2.SetRowRel(false); 1341cdf0e10cSrcweir aData.Ref2.SetTabRel(false); 1342cdf0e10cSrcweir aData.Ref1.nCol = nMinCol; 1343cdf0e10cSrcweir aData.Ref1.nRow = nMinRow; 1344cdf0e10cSrcweir aData.Ref1.nTab = nTab; 1345cdf0e10cSrcweir aData.Ref2.nCol = nMaxCol; 1346cdf0e10cSrcweir aData.Ref2.nRow = nMaxRow; 1347cdf0e10cSrcweir aData.Ref2.nTab = nTab; 1348cdf0e10cSrcweir vector<ScSharedTokenRef> aNewTokens; 1349cdf0e10cSrcweir aNewTokens.reserve(1); 1350cdf0e10cSrcweir if (bExternal) 1351cdf0e10cSrcweir { 1352cdf0e10cSrcweir ScSharedTokenRef p( 1353cdf0e10cSrcweir new ScExternalDoubleRefToken(nFileId, aExtTabName, aData)); 1354cdf0e10cSrcweir aNewTokens.push_back(p); 1355cdf0e10cSrcweir } 1356cdf0e10cSrcweir else 1357cdf0e10cSrcweir { 1358cdf0e10cSrcweir ScSharedTokenRef p(new ScDoubleRefToken(aData)); 1359cdf0e10cSrcweir aNewTokens.push_back(p); 1360cdf0e10cSrcweir } 1361cdf0e10cSrcweir rRefTokens.swap(aNewTokens); 1362cdf0e10cSrcweir return true; 1363cdf0e10cSrcweir } 1364cdf0e10cSrcweir } 1365cdf0e10cSrcweir #endif 1366cdf0e10cSrcweir 1367cdf0e10cSrcweir ScSingleRefData aData; 1368cdf0e10cSrcweir aData.InitFlags(); 1369cdf0e10cSrcweir aData.SetFlag3D(true); 1370cdf0e10cSrcweir aData.SetColRel(false); 1371cdf0e10cSrcweir aData.SetRowRel(false); 1372cdf0e10cSrcweir aData.SetTabRel(false); 1373cdf0e10cSrcweir aData.nCol = nMinCol; 1374cdf0e10cSrcweir aData.nRow = nMinRow; 1375cdf0e10cSrcweir aData.nTab = nTab; 1376cdf0e10cSrcweir 1377cdf0e10cSrcweir if( nCornerRowCount==1 && nCornerColumnCount==1 ) 1378cdf0e10cSrcweir { 1379cdf0e10cSrcweir if (bExternal) 1380cdf0e10cSrcweir { 1381cdf0e10cSrcweir ScSharedTokenRef pCorner( 1382cdf0e10cSrcweir new ScExternalSingleRefToken(nFileId, aExtTabName, aData)); 1383cdf0e10cSrcweir ScRefTokenHelper::join(rRefTokens, pCorner); 1384cdf0e10cSrcweir } 1385cdf0e10cSrcweir else 1386cdf0e10cSrcweir { 1387cdf0e10cSrcweir ScSharedTokenRef pCorner(new ScSingleRefToken(aData)); 1388cdf0e10cSrcweir ScRefTokenHelper::join(rRefTokens, pCorner); 1389cdf0e10cSrcweir } 1390cdf0e10cSrcweir } 1391cdf0e10cSrcweir else 1392cdf0e10cSrcweir { 1393cdf0e10cSrcweir ScSingleRefData aDataEnd(aData); 1394cdf0e10cSrcweir aDataEnd.nCol += (nCornerColumnCount-1); 1395cdf0e10cSrcweir aDataEnd.nRow += (nCornerRowCount-1); 1396cdf0e10cSrcweir ScComplexRefData r; 1397cdf0e10cSrcweir r.Ref1=aData; 1398cdf0e10cSrcweir r.Ref2=aDataEnd; 1399cdf0e10cSrcweir if (bExternal) 1400cdf0e10cSrcweir { 1401cdf0e10cSrcweir ScSharedTokenRef pCorner( 1402cdf0e10cSrcweir new ScExternalDoubleRefToken(nFileId, aExtTabName, r)); 1403cdf0e10cSrcweir ScRefTokenHelper::join(rRefTokens, pCorner); 1404cdf0e10cSrcweir } 1405cdf0e10cSrcweir else 1406cdf0e10cSrcweir { 1407cdf0e10cSrcweir ScSharedTokenRef pCorner(new ScDoubleRefToken(r)); 1408cdf0e10cSrcweir ScRefTokenHelper::join(rRefTokens, pCorner); 1409cdf0e10cSrcweir } 1410cdf0e10cSrcweir } 1411cdf0e10cSrcweir 1412cdf0e10cSrcweir return true; 1413cdf0e10cSrcweir } 1414cdf0e10cSrcweir 1415cdf0e10cSrcweir } 1416cdf0e10cSrcweir 1417cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource> SAL_CALL 1418cdf0e10cSrcweir ScChart2DataProvider::createDataSource( 1419cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& aArguments ) 1420cdf0e10cSrcweir throw( lang::IllegalArgumentException, uno::RuntimeException) 1421cdf0e10cSrcweir { 1422cdf0e10cSrcweir ScUnoGuard aGuard; 1423cdf0e10cSrcweir if ( ! m_pDocument ) 1424cdf0e10cSrcweir throw uno::RuntimeException(); 1425cdf0e10cSrcweir 1426cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource> xResult; 1427cdf0e10cSrcweir bool bLabel = true; 1428cdf0e10cSrcweir bool bCategories = false; 1429cdf0e10cSrcweir bool bOrientCol = true; 1430cdf0e10cSrcweir ::rtl::OUString aRangeRepresentation; 1431cdf0e10cSrcweir uno::Sequence< sal_Int32 > aSequenceMapping; 1432cdf0e10cSrcweir for(sal_Int32 i = 0; i < aArguments.getLength(); ++i) 1433cdf0e10cSrcweir { 1434cdf0e10cSrcweir rtl::OUString sName(aArguments[i].Name); 1435cdf0e10cSrcweir if (aArguments[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataRowSource"))) 1436cdf0e10cSrcweir { 1437cdf0e10cSrcweir chart::ChartDataRowSource eSource = chart::ChartDataRowSource_COLUMNS; 1438cdf0e10cSrcweir if( ! (aArguments[i].Value >>= eSource)) 1439cdf0e10cSrcweir { 1440cdf0e10cSrcweir sal_Int32 nSource(0); 1441cdf0e10cSrcweir if( aArguments[i].Value >>= nSource ) 1442cdf0e10cSrcweir eSource = (static_cast< chart::ChartDataRowSource >( nSource )); 1443cdf0e10cSrcweir } 1444cdf0e10cSrcweir bOrientCol = (eSource == chart::ChartDataRowSource_COLUMNS); 1445cdf0e10cSrcweir } 1446cdf0e10cSrcweir else if (aArguments[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FirstCellAsLabel"))) 1447cdf0e10cSrcweir { 1448cdf0e10cSrcweir bLabel = ::cppu::any2bool(aArguments[i].Value); 1449cdf0e10cSrcweir } 1450cdf0e10cSrcweir else if (aArguments[i].Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasCategories"))) 1451cdf0e10cSrcweir { 1452cdf0e10cSrcweir bCategories = ::cppu::any2bool(aArguments[i].Value); 1453cdf0e10cSrcweir } 1454cdf0e10cSrcweir else if (aArguments[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("CellRangeRepresentation"))) 1455cdf0e10cSrcweir { 1456cdf0e10cSrcweir aArguments[i].Value >>= aRangeRepresentation; 1457cdf0e10cSrcweir } 1458cdf0e10cSrcweir else if (aArguments[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SequenceMapping"))) 1459cdf0e10cSrcweir { 1460cdf0e10cSrcweir aArguments[i].Value >>= aSequenceMapping; 1461cdf0e10cSrcweir } 1462cdf0e10cSrcweir } 1463cdf0e10cSrcweir 1464cdf0e10cSrcweir vector<ScSharedTokenRef> aRefTokens; 1465cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation(aRefTokens, aRangeRepresentation, m_pDocument, m_pDocument->GetGrammar()); 1466cdf0e10cSrcweir if (aRefTokens.empty()) 1467cdf0e10cSrcweir // Invalid range representation. Bail out. 1468cdf0e10cSrcweir throw lang::IllegalArgumentException(); 1469cdf0e10cSrcweir 1470cdf0e10cSrcweir if (bLabel) 1471cdf0e10cSrcweir lcl_addUpperLeftCornerIfMissing(aRefTokens); //#i90669# 1472cdf0e10cSrcweir 1473cdf0e10cSrcweir bool bColHeaders = (bOrientCol ? bLabel : bCategories ); 1474cdf0e10cSrcweir bool bRowHeaders = (bOrientCol ? bCategories : bLabel ); 1475cdf0e10cSrcweir 1476cdf0e10cSrcweir Chart2Positioner aChPositioner(m_pDocument, aRefTokens); 1477cdf0e10cSrcweir aChPositioner.setHeaders(bColHeaders, bRowHeaders); 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir const Chart2PositionMap* pChartMap = aChPositioner.getPositionMap(); 1480cdf0e10cSrcweir if (!pChartMap) 1481cdf0e10cSrcweir // No chart position map instance. Bail out. 1482cdf0e10cSrcweir return xResult; 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir ScChart2DataSource* pDS = NULL; 1485cdf0e10cSrcweir ::std::list< Reference< chart2::data::XLabeledDataSequence > > aSeqs; 1486cdf0e10cSrcweir 1487cdf0e10cSrcweir // Fill Categories 1488cdf0e10cSrcweir if( bCategories ) 1489cdf0e10cSrcweir { 1490cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pValueTokens(NULL); 1491cdf0e10cSrcweir if (bOrientCol) 1492cdf0e10cSrcweir pValueTokens.reset(pChartMap->getAllRowHeaderRanges()); 1493cdf0e10cSrcweir else 1494cdf0e10cSrcweir pValueTokens.reset(pChartMap->getAllColHeaderRanges()); 1495cdf0e10cSrcweir 1496cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pLabelTokens(NULL); 1497cdf0e10cSrcweir pLabelTokens.reset(pChartMap->getLeftUpperCornerRanges()); 1498cdf0e10cSrcweir 1499cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xCategories = lcl_createLabeledDataSequenceFromTokens( 1500cdf0e10cSrcweir pValueTokens, pLabelTokens, m_pDocument, this, m_bIncludeHiddenCells ); //ownership of pointers is transfered! 1501cdf0e10cSrcweir if ( xCategories.is() ) 1502cdf0e10cSrcweir { 1503cdf0e10cSrcweir aSeqs.push_back( xCategories ); 1504cdf0e10cSrcweir } 1505cdf0e10cSrcweir } 1506cdf0e10cSrcweir 1507cdf0e10cSrcweir // Fill Serieses (values and label) 1508cdf0e10cSrcweir sal_Int32 nCount = bOrientCol ? pChartMap->getDataColCount() : pChartMap->getDataRowCount(); 1509cdf0e10cSrcweir for (sal_Int32 i = 0; i < nCount; ++i) 1510cdf0e10cSrcweir { 1511cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pValueTokens(NULL); 1512cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pLabelTokens(NULL); 1513cdf0e10cSrcweir if (bOrientCol) 1514cdf0e10cSrcweir { 1515cdf0e10cSrcweir pValueTokens.reset(pChartMap->getDataColRanges(static_cast<SCCOL>(i))); 1516cdf0e10cSrcweir pLabelTokens.reset(pChartMap->getColHeaderRanges(static_cast<SCCOL>(i))); 1517cdf0e10cSrcweir } 1518cdf0e10cSrcweir else 1519cdf0e10cSrcweir { 1520cdf0e10cSrcweir pValueTokens.reset(pChartMap->getDataRowRanges(static_cast<SCROW>(i))); 1521cdf0e10cSrcweir pLabelTokens.reset(pChartMap->getRowHeaderRanges(static_cast<SCROW>(i))); 1522cdf0e10cSrcweir } 1523cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xChartSeries = lcl_createLabeledDataSequenceFromTokens( 1524cdf0e10cSrcweir pValueTokens, pLabelTokens, m_pDocument, this, m_bIncludeHiddenCells ); //ownership of pointers is transfered! 1525cdf0e10cSrcweir if ( xChartSeries.is() ) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir aSeqs.push_back( xChartSeries ); 1528cdf0e10cSrcweir } 1529cdf0e10cSrcweir } 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir pDS = new ScChart2DataSource(m_pDocument); 1532cdf0e10cSrcweir ::std::list< Reference< chart2::data::XLabeledDataSequence > >::iterator aItr( aSeqs.begin() ); 1533cdf0e10cSrcweir ::std::list< Reference< chart2::data::XLabeledDataSequence > >::iterator aEndItr( aSeqs.end() ); 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir //reorder labeled sequences according to aSequenceMapping 1536cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aSeqVector; 1537cdf0e10cSrcweir while(aItr != aEndItr) 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir aSeqVector.push_back(*aItr); 1540cdf0e10cSrcweir ++aItr; 1541cdf0e10cSrcweir } 1542cdf0e10cSrcweir 1543cdf0e10cSrcweir ::std::map< sal_Int32, Reference< chart2::data::XLabeledDataSequence > > aSequenceMap; 1544cdf0e10cSrcweir for( sal_Int32 nNewIndex = 0; nNewIndex < aSequenceMapping.getLength(); nNewIndex++ ) 1545cdf0e10cSrcweir { 1546cdf0e10cSrcweir // note: assuming that the values in the sequence mapping are always non-negative 1547cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::size_type nOldIndex( static_cast< sal_uInt32 >( aSequenceMapping[nNewIndex] ) ); 1548cdf0e10cSrcweir if( nOldIndex < aSeqVector.size() ) 1549cdf0e10cSrcweir { 1550cdf0e10cSrcweir pDS->AddLabeledSequence( aSeqVector[nOldIndex] ); 1551cdf0e10cSrcweir aSeqVector[nOldIndex] = 0; 1552cdf0e10cSrcweir } 1553cdf0e10cSrcweir } 1554cdf0e10cSrcweir 1555cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::iterator aVectorItr( aSeqVector.begin() ); 1556cdf0e10cSrcweir ::std::vector< Reference< chart2::data::XLabeledDataSequence > >::iterator aVectorEndItr( aSeqVector.end() ); 1557cdf0e10cSrcweir while(aVectorItr != aVectorEndItr) 1558cdf0e10cSrcweir { 1559cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xSeq( *aVectorItr ); 1560cdf0e10cSrcweir if ( xSeq.is() ) 1561cdf0e10cSrcweir { 1562cdf0e10cSrcweir pDS->AddLabeledSequence( xSeq ); 1563cdf0e10cSrcweir } 1564cdf0e10cSrcweir ++aVectorItr; 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir 1567cdf0e10cSrcweir xResult.set( pDS ); 1568cdf0e10cSrcweir return xResult; 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir 1571cdf0e10cSrcweir namespace 1572cdf0e10cSrcweir { 1573cdf0e10cSrcweir 1574cdf0e10cSrcweir /** 1575cdf0e10cSrcweir * Function object to create a list of table numbers from a token list. 1576cdf0e10cSrcweir */ 1577cdf0e10cSrcweir class InsertTabNumber : public unary_function<ScSharedTokenRef, void> 1578cdf0e10cSrcweir { 1579cdf0e10cSrcweir public: 1580cdf0e10cSrcweir InsertTabNumber() : 1581cdf0e10cSrcweir mpTabNumList(new list<SCTAB>()) 1582cdf0e10cSrcweir { 1583cdf0e10cSrcweir } 1584cdf0e10cSrcweir 1585cdf0e10cSrcweir InsertTabNumber(const InsertTabNumber& r) : 1586cdf0e10cSrcweir mpTabNumList(r.mpTabNumList) 1587cdf0e10cSrcweir { 1588cdf0e10cSrcweir } 1589cdf0e10cSrcweir 1590cdf0e10cSrcweir void operator() (const ScSharedTokenRef& pToken) const 1591cdf0e10cSrcweir { 1592cdf0e10cSrcweir if (!ScRefTokenHelper::isRef(pToken)) 1593cdf0e10cSrcweir return; 1594cdf0e10cSrcweir 1595cdf0e10cSrcweir const ScSingleRefData& r = pToken->GetSingleRef(); 1596cdf0e10cSrcweir mpTabNumList->push_back(r.nTab); 1597cdf0e10cSrcweir } 1598cdf0e10cSrcweir 1599cdf0e10cSrcweir void getList(list<SCTAB>& rList) 1600cdf0e10cSrcweir { 1601cdf0e10cSrcweir mpTabNumList->swap(rList); 1602cdf0e10cSrcweir } 1603cdf0e10cSrcweir private: 1604cdf0e10cSrcweir shared_ptr< list<SCTAB> > mpTabNumList; 1605cdf0e10cSrcweir }; 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir class RangeAnalyzer 1608cdf0e10cSrcweir { 1609cdf0e10cSrcweir public: 1610cdf0e10cSrcweir RangeAnalyzer(); 1611cdf0e10cSrcweir void initRangeAnalyzer( const vector<ScSharedTokenRef>& rTokens ); 1612cdf0e10cSrcweir void analyzeRange( sal_Int32& rnDataInRows, sal_Int32& rnDataInCols, 1613cdf0e10cSrcweir bool& rbRowSourceAmbiguous ) const; 1614cdf0e10cSrcweir bool inSameSingleRow( RangeAnalyzer& rOther ); 1615cdf0e10cSrcweir bool inSameSingleColumn( RangeAnalyzer& rOther ); 1616cdf0e10cSrcweir SCROW getRowCount() { return mnRowCount; } 1617cdf0e10cSrcweir SCCOL getColumnCount() { return mnColumnCount; } 1618cdf0e10cSrcweir 1619cdf0e10cSrcweir private: 1620cdf0e10cSrcweir bool mbEmpty; 1621cdf0e10cSrcweir bool mbAmbiguous; 1622cdf0e10cSrcweir SCROW mnRowCount; 1623cdf0e10cSrcweir SCCOL mnColumnCount; 1624cdf0e10cSrcweir 1625cdf0e10cSrcweir SCCOL mnStartColumn; 1626cdf0e10cSrcweir SCROW mnStartRow; 1627cdf0e10cSrcweir }; 1628cdf0e10cSrcweir 1629cdf0e10cSrcweir RangeAnalyzer::RangeAnalyzer() 1630cdf0e10cSrcweir : mbEmpty(true) 1631cdf0e10cSrcweir , mbAmbiguous(false) 1632cdf0e10cSrcweir , mnRowCount(0) 1633cdf0e10cSrcweir , mnColumnCount(0) 1634cdf0e10cSrcweir , mnStartColumn(-1) 1635cdf0e10cSrcweir , mnStartRow(-1) 1636cdf0e10cSrcweir { 1637cdf0e10cSrcweir } 1638cdf0e10cSrcweir 1639cdf0e10cSrcweir void RangeAnalyzer::initRangeAnalyzer( const vector<ScSharedTokenRef>& rTokens ) 1640cdf0e10cSrcweir { 1641cdf0e10cSrcweir mnRowCount=0; 1642cdf0e10cSrcweir mnColumnCount=0; 1643cdf0e10cSrcweir mnStartColumn = -1; 1644cdf0e10cSrcweir mnStartRow = -1; 1645cdf0e10cSrcweir mbAmbiguous=false; 1646cdf0e10cSrcweir if( rTokens.empty() ) 1647cdf0e10cSrcweir { 1648cdf0e10cSrcweir mbEmpty=true; 1649cdf0e10cSrcweir return; 1650cdf0e10cSrcweir } 1651cdf0e10cSrcweir mbEmpty=false; 1652cdf0e10cSrcweir 1653cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = rTokens.begin(), itrEnd = rTokens.end(); 1654cdf0e10cSrcweir for (; itr != itrEnd ; ++itr) 1655cdf0e10cSrcweir { 1656cdf0e10cSrcweir ScSharedTokenRef aRefToken = *itr; 1657cdf0e10cSrcweir StackVar eVar = aRefToken->GetType(); 1658cdf0e10cSrcweir if (eVar == svDoubleRef || eVar == svExternalDoubleRef) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir const ScComplexRefData& r = aRefToken->GetDoubleRef(); 1661cdf0e10cSrcweir if (r.Ref1.nTab == r.Ref2.nTab) 1662cdf0e10cSrcweir { 1663cdf0e10cSrcweir mnColumnCount = std::max<SCCOL>( mnColumnCount, static_cast<SCCOL>(abs(r.Ref2.nCol - r.Ref1.nCol)+1) ); 1664cdf0e10cSrcweir mnRowCount = std::max<SCROW>( mnRowCount, static_cast<SCROW>(abs(r.Ref2.nRow - r.Ref1.nRow)+1) ); 1665cdf0e10cSrcweir if( mnStartColumn == -1 ) 1666cdf0e10cSrcweir { 1667cdf0e10cSrcweir mnStartColumn = r.Ref1.nCol; 1668cdf0e10cSrcweir mnStartRow = r.Ref1.nRow; 1669cdf0e10cSrcweir } 1670cdf0e10cSrcweir else 1671cdf0e10cSrcweir { 1672cdf0e10cSrcweir if( mnStartColumn != r.Ref1.nCol && mnStartRow != r.Ref1.nRow ) 1673cdf0e10cSrcweir mbAmbiguous=true; 1674cdf0e10cSrcweir } 1675cdf0e10cSrcweir } 1676cdf0e10cSrcweir else 1677cdf0e10cSrcweir mbAmbiguous=true; 1678cdf0e10cSrcweir } 1679cdf0e10cSrcweir else if (eVar == svSingleRef || eVar == svExternalSingleRef) 1680cdf0e10cSrcweir { 1681cdf0e10cSrcweir const ScSingleRefData& r = aRefToken->GetSingleRef(); 1682cdf0e10cSrcweir mnColumnCount = std::max<SCCOL>( mnColumnCount, 1); 1683cdf0e10cSrcweir mnRowCount = std::max<SCROW>( mnRowCount, 1); 1684cdf0e10cSrcweir if( mnStartColumn == -1 ) 1685cdf0e10cSrcweir { 1686cdf0e10cSrcweir mnStartColumn = r.nCol; 1687cdf0e10cSrcweir mnStartRow = r.nRow; 1688cdf0e10cSrcweir } 1689cdf0e10cSrcweir else 1690cdf0e10cSrcweir { 1691cdf0e10cSrcweir if( mnStartColumn != r.nCol && mnStartRow != r.nRow ) 1692cdf0e10cSrcweir mbAmbiguous=true; 1693cdf0e10cSrcweir } 1694cdf0e10cSrcweir } 1695cdf0e10cSrcweir else 1696cdf0e10cSrcweir mbAmbiguous=true; 1697cdf0e10cSrcweir } 1698cdf0e10cSrcweir } 1699cdf0e10cSrcweir 1700cdf0e10cSrcweir void RangeAnalyzer::analyzeRange( sal_Int32& rnDataInRows, 1701cdf0e10cSrcweir sal_Int32& rnDataInCols, 1702cdf0e10cSrcweir bool& rbRowSourceAmbiguous ) const 1703cdf0e10cSrcweir { 1704cdf0e10cSrcweir if(!mbEmpty && !mbAmbiguous) 1705cdf0e10cSrcweir { 1706cdf0e10cSrcweir if( mnRowCount==1 && mnColumnCount>1 ) 1707cdf0e10cSrcweir ++rnDataInRows; 1708cdf0e10cSrcweir else if( mnColumnCount==1 && mnRowCount>1 ) 1709cdf0e10cSrcweir ++rnDataInCols; 1710cdf0e10cSrcweir else if( mnRowCount>1 && mnColumnCount>1 ) 1711cdf0e10cSrcweir rbRowSourceAmbiguous = true; 1712cdf0e10cSrcweir } 1713cdf0e10cSrcweir else if( !mbEmpty ) 1714cdf0e10cSrcweir rbRowSourceAmbiguous = true; 1715cdf0e10cSrcweir } 1716cdf0e10cSrcweir 1717cdf0e10cSrcweir bool RangeAnalyzer::inSameSingleRow( RangeAnalyzer& rOther ) 1718cdf0e10cSrcweir { 1719cdf0e10cSrcweir if( mnStartRow==rOther.mnStartRow && 1720cdf0e10cSrcweir mnRowCount==1 && rOther.mnRowCount==1 ) 1721cdf0e10cSrcweir return true; 1722cdf0e10cSrcweir return false; 1723cdf0e10cSrcweir } 1724cdf0e10cSrcweir 1725cdf0e10cSrcweir bool RangeAnalyzer::inSameSingleColumn( RangeAnalyzer& rOther ) 1726cdf0e10cSrcweir { 1727cdf0e10cSrcweir if( mnStartColumn==rOther.mnStartColumn && 1728cdf0e10cSrcweir mnColumnCount==1 && rOther.mnColumnCount==1 ) 1729cdf0e10cSrcweir return true; 1730cdf0e10cSrcweir return false; 1731cdf0e10cSrcweir } 1732cdf0e10cSrcweir 1733cdf0e10cSrcweir } //end anonymous namespace 1734cdf0e10cSrcweir 1735cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > SAL_CALL ScChart2DataProvider::detectArguments( 1736cdf0e10cSrcweir const uno::Reference< chart2::data::XDataSource >& xDataSource ) 1737cdf0e10cSrcweir throw (uno::RuntimeException) 1738cdf0e10cSrcweir { 1739cdf0e10cSrcweir ::std::vector< beans::PropertyValue > aResult; 1740cdf0e10cSrcweir bool bRowSourceDetected = false; 1741cdf0e10cSrcweir bool bFirstCellAsLabel = false; 1742cdf0e10cSrcweir bool bHasCategories = false; 1743cdf0e10cSrcweir ::rtl::OUString sRangeRep; 1744cdf0e10cSrcweir 1745cdf0e10cSrcweir bool bHasCategoriesLabels = false; 1746cdf0e10cSrcweir vector<ScSharedTokenRef> aAllCategoriesValuesTokens; 1747cdf0e10cSrcweir vector<ScSharedTokenRef> aAllSeriesLabelTokens; 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir chart::ChartDataRowSource eRowSource = chart::ChartDataRowSource_COLUMNS; 1750cdf0e10cSrcweir 1751cdf0e10cSrcweir vector<ScSharedTokenRef> aAllTokens; 1752cdf0e10cSrcweir 1753cdf0e10cSrcweir // parse given data source and collect infos 1754cdf0e10cSrcweir { 1755cdf0e10cSrcweir ScUnoGuard aGuard; 1756cdf0e10cSrcweir DBG_ASSERT( m_pDocument, "No Document -> no detectArguments" ); 1757cdf0e10cSrcweir if(!m_pDocument ||!xDataSource.is()) 1758cdf0e10cSrcweir return lcl_VectorToSequence( aResult ); 1759cdf0e10cSrcweir 1760cdf0e10cSrcweir sal_Int32 nDataInRows = 0; 1761cdf0e10cSrcweir sal_Int32 nDataInCols = 0; 1762cdf0e10cSrcweir bool bRowSourceAmbiguous = false; 1763cdf0e10cSrcweir 1764cdf0e10cSrcweir Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences( xDataSource->getDataSequences()); 1765cdf0e10cSrcweir const sal_Int32 nCount( aSequences.getLength()); 1766cdf0e10cSrcweir RangeAnalyzer aPrevLabel,aPrevValues; 1767cdf0e10cSrcweir for( sal_Int32 nIdx=0; nIdx<nCount; ++nIdx ) 1768cdf0e10cSrcweir { 1769cdf0e10cSrcweir Reference< chart2::data::XLabeledDataSequence > xLS(aSequences[nIdx]); 1770cdf0e10cSrcweir if( xLS.is() ) 1771cdf0e10cSrcweir { 1772cdf0e10cSrcweir bool bThisIsCategories = false; 1773cdf0e10cSrcweir if(!bHasCategories) 1774cdf0e10cSrcweir { 1775cdf0e10cSrcweir Reference< beans::XPropertySet > xSeqProp( xLS->getValues(), uno::UNO_QUERY ); 1776cdf0e10cSrcweir ::rtl::OUString aRole; 1777cdf0e10cSrcweir if( xSeqProp.is() && (xSeqProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Role"))) >>= aRole) && 1778cdf0e10cSrcweir aRole.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("categories")) ) 1779cdf0e10cSrcweir bThisIsCategories = bHasCategories = true; 1780cdf0e10cSrcweir } 1781cdf0e10cSrcweir 1782cdf0e10cSrcweir RangeAnalyzer aLabel,aValues; 1783cdf0e10cSrcweir // label 1784cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xLabel( xLS->getLabel()); 1785cdf0e10cSrcweir if( xLabel.is()) 1786cdf0e10cSrcweir { 1787cdf0e10cSrcweir bFirstCellAsLabel = true; 1788cdf0e10cSrcweir vector<ScSharedTokenRef> aTokens; 1789cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation( aTokens, xLabel->getSourceRangeRepresentation(), m_pDocument, m_pDocument->GetGrammar() ); 1790cdf0e10cSrcweir aLabel.initRangeAnalyzer(aTokens); 1791cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = aTokens.begin(), itrEnd = aTokens.end(); 1792cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 1793cdf0e10cSrcweir { 1794cdf0e10cSrcweir ScRefTokenHelper::join(aAllTokens, *itr); 1795cdf0e10cSrcweir if(!bThisIsCategories) 1796cdf0e10cSrcweir ScRefTokenHelper::join(aAllSeriesLabelTokens, *itr); 1797cdf0e10cSrcweir } 1798cdf0e10cSrcweir if(bThisIsCategories) 1799cdf0e10cSrcweir bHasCategoriesLabels=true; 1800cdf0e10cSrcweir } 1801cdf0e10cSrcweir // values 1802cdf0e10cSrcweir Reference< chart2::data::XDataSequence > xValues( xLS->getValues()); 1803cdf0e10cSrcweir if( xValues.is()) 1804cdf0e10cSrcweir { 1805cdf0e10cSrcweir vector<ScSharedTokenRef> aTokens; 1806cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation( aTokens, xValues->getSourceRangeRepresentation(), m_pDocument, m_pDocument->GetGrammar() ); 1807cdf0e10cSrcweir aValues.initRangeAnalyzer(aTokens); 1808cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = aTokens.begin(), itrEnd = aTokens.end(); 1809cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 1810cdf0e10cSrcweir { 1811cdf0e10cSrcweir ScRefTokenHelper::join(aAllTokens, *itr); 1812cdf0e10cSrcweir if(bThisIsCategories) 1813cdf0e10cSrcweir ScRefTokenHelper::join(aAllCategoriesValuesTokens, *itr); 1814cdf0e10cSrcweir } 1815cdf0e10cSrcweir } 1816cdf0e10cSrcweir //detect row source 1817cdf0e10cSrcweir if(!bThisIsCategories || nCount==1) //categories might span multiple rows *and* columns, so they should be used for detection only if nothing else is available 1818cdf0e10cSrcweir { 1819cdf0e10cSrcweir if (!bRowSourceAmbiguous) 1820cdf0e10cSrcweir { 1821cdf0e10cSrcweir aValues.analyzeRange(nDataInRows,nDataInCols,bRowSourceAmbiguous); 1822cdf0e10cSrcweir aLabel.analyzeRange(nDataInRows,nDataInCols,bRowSourceAmbiguous); 1823cdf0e10cSrcweir if (nDataInRows > 1 && nDataInCols > 1) 1824cdf0e10cSrcweir bRowSourceAmbiguous = true; 1825cdf0e10cSrcweir else if( !bRowSourceAmbiguous && !nDataInRows && !nDataInCols ) 1826cdf0e10cSrcweir { 1827cdf0e10cSrcweir if( aValues.inSameSingleColumn( aLabel ) ) 1828cdf0e10cSrcweir nDataInCols++; 1829cdf0e10cSrcweir else if( aValues.inSameSingleRow( aLabel ) ) 1830cdf0e10cSrcweir nDataInRows++; 1831cdf0e10cSrcweir else 1832cdf0e10cSrcweir { 1833cdf0e10cSrcweir //#i86188# also detect a single column split into rows correctly 1834cdf0e10cSrcweir if( aValues.inSameSingleColumn( aPrevValues ) ) 1835cdf0e10cSrcweir nDataInRows++; 1836cdf0e10cSrcweir else if( aValues.inSameSingleRow( aPrevValues ) ) 1837cdf0e10cSrcweir nDataInCols++; 1838cdf0e10cSrcweir else if( aLabel.inSameSingleColumn( aPrevLabel ) ) 1839cdf0e10cSrcweir nDataInRows++; 1840cdf0e10cSrcweir else if( aLabel.inSameSingleRow( aPrevLabel ) ) 1841cdf0e10cSrcweir nDataInCols++; 1842cdf0e10cSrcweir } 1843cdf0e10cSrcweir } 1844cdf0e10cSrcweir } 1845cdf0e10cSrcweir } 1846cdf0e10cSrcweir aPrevValues=aValues; 1847cdf0e10cSrcweir aPrevLabel=aLabel; 1848cdf0e10cSrcweir } 1849cdf0e10cSrcweir } 1850cdf0e10cSrcweir 1851cdf0e10cSrcweir if (!bRowSourceAmbiguous) 1852cdf0e10cSrcweir { 1853cdf0e10cSrcweir bRowSourceDetected = true; 1854cdf0e10cSrcweir eRowSource = ( nDataInRows > 0 1855cdf0e10cSrcweir ? chart::ChartDataRowSource_ROWS 1856cdf0e10cSrcweir : chart::ChartDataRowSource_COLUMNS ); 1857cdf0e10cSrcweir } 1858cdf0e10cSrcweir else 1859cdf0e10cSrcweir { 1860cdf0e10cSrcweir // set DataRowSource to the better of the two ambiguities 1861cdf0e10cSrcweir eRowSource = ( nDataInRows > nDataInCols 1862cdf0e10cSrcweir ? chart::ChartDataRowSource_ROWS 1863cdf0e10cSrcweir : chart::ChartDataRowSource_COLUMNS ); 1864cdf0e10cSrcweir } 1865cdf0e10cSrcweir 1866cdf0e10cSrcweir } 1867cdf0e10cSrcweir 1868cdf0e10cSrcweir // TableNumberList 1869cdf0e10cSrcweir { 1870cdf0e10cSrcweir list<SCTAB> aTableNumList; 1871cdf0e10cSrcweir InsertTabNumber func; 1872cdf0e10cSrcweir func = for_each(aAllTokens.begin(), aAllTokens.end(), func); 1873cdf0e10cSrcweir func.getList(aTableNumList); 1874cdf0e10cSrcweir aResult.push_back( 1875cdf0e10cSrcweir beans::PropertyValue( ::rtl::OUString::createFromAscii("TableNumberList"), -1, 1876cdf0e10cSrcweir uno::makeAny( lcl_createTableNumberList( aTableNumList ) ), 1877cdf0e10cSrcweir beans::PropertyState_DIRECT_VALUE )); 1878cdf0e10cSrcweir } 1879cdf0e10cSrcweir 1880cdf0e10cSrcweir // DataRowSource (calculated before) 1881cdf0e10cSrcweir if( bRowSourceDetected ) 1882cdf0e10cSrcweir { 1883cdf0e10cSrcweir aResult.push_back( 1884cdf0e10cSrcweir beans::PropertyValue( ::rtl::OUString::createFromAscii("DataRowSource"), -1, 1885cdf0e10cSrcweir uno::makeAny( eRowSource ), beans::PropertyState_DIRECT_VALUE )); 1886cdf0e10cSrcweir } 1887cdf0e10cSrcweir 1888cdf0e10cSrcweir // HasCategories 1889cdf0e10cSrcweir if( bRowSourceDetected ) 1890cdf0e10cSrcweir { 1891cdf0e10cSrcweir aResult.push_back( 1892cdf0e10cSrcweir beans::PropertyValue( ::rtl::OUString::createFromAscii("HasCategories"), -1, 1893cdf0e10cSrcweir uno::makeAny( bHasCategories ), beans::PropertyState_DIRECT_VALUE )); 1894cdf0e10cSrcweir } 1895cdf0e10cSrcweir 1896cdf0e10cSrcweir // FirstCellAsLabel 1897cdf0e10cSrcweir if( bRowSourceDetected ) 1898cdf0e10cSrcweir { 1899cdf0e10cSrcweir aResult.push_back( 1900cdf0e10cSrcweir beans::PropertyValue( ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1, 1901cdf0e10cSrcweir uno::makeAny( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE )); 1902cdf0e10cSrcweir } 1903cdf0e10cSrcweir 1904cdf0e10cSrcweir // Add the left upper corner to the range if it is missing. 1905cdf0e10cSrcweir if (bRowSourceDetected && bFirstCellAsLabel && bHasCategories && !bHasCategoriesLabels ) 1906cdf0e10cSrcweir { 1907cdf0e10cSrcweir RangeAnalyzer aTop,aLeft; 1908cdf0e10cSrcweir if( eRowSource==chart::ChartDataRowSource_COLUMNS ) 1909cdf0e10cSrcweir { 1910cdf0e10cSrcweir aTop.initRangeAnalyzer(aAllSeriesLabelTokens); 1911cdf0e10cSrcweir aLeft.initRangeAnalyzer(aAllCategoriesValuesTokens); 1912cdf0e10cSrcweir } 1913cdf0e10cSrcweir else 1914cdf0e10cSrcweir { 1915cdf0e10cSrcweir aTop.initRangeAnalyzer(aAllCategoriesValuesTokens); 1916cdf0e10cSrcweir aLeft.initRangeAnalyzer(aAllSeriesLabelTokens); 1917cdf0e10cSrcweir } 1918cdf0e10cSrcweir lcl_addUpperLeftCornerIfMissing(aAllTokens, aTop.getRowCount(), aLeft.getColumnCount());//e.g. #i91212# 1919cdf0e10cSrcweir } 1920cdf0e10cSrcweir 1921cdf0e10cSrcweir // Get range string. 1922cdf0e10cSrcweir lcl_convertTokensToString(sRangeRep, aAllTokens, m_pDocument); 1923cdf0e10cSrcweir 1924cdf0e10cSrcweir // add cell range property 1925cdf0e10cSrcweir aResult.push_back( 1926cdf0e10cSrcweir beans::PropertyValue( ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1, 1927cdf0e10cSrcweir uno::makeAny( sRangeRep ), beans::PropertyState_DIRECT_VALUE )); 1928cdf0e10cSrcweir 1929cdf0e10cSrcweir //Sequence Mapping 1930cdf0e10cSrcweir bool bSequencesReordered = true;//todo detect this above or detect this sequence mapping cheaper ... 1931cdf0e10cSrcweir if( bSequencesReordered && bRowSourceDetected ) 1932cdf0e10cSrcweir { 1933cdf0e10cSrcweir bool bDifferentIndexes = false; 1934cdf0e10cSrcweir 1935cdf0e10cSrcweir std::vector< sal_Int32 > aSequenceMappingVector; 1936cdf0e10cSrcweir 1937cdf0e10cSrcweir uno::Reference< chart2::data::XDataSource > xCompareDataSource; 1938cdf0e10cSrcweir try 1939cdf0e10cSrcweir { 1940cdf0e10cSrcweir xCompareDataSource.set( this->createDataSource( lcl_VectorToSequence( aResult ) ) ); 1941cdf0e10cSrcweir } 1942cdf0e10cSrcweir catch( const lang::IllegalArgumentException & ) 1943cdf0e10cSrcweir { 1944cdf0e10cSrcweir // creation of data source to compare didn't work, so we cannot 1945cdf0e10cSrcweir // create a sequence mapping 1946cdf0e10cSrcweir } 1947cdf0e10cSrcweir 1948cdf0e10cSrcweir if( xDataSource.is() && xCompareDataSource.is() ) 1949cdf0e10cSrcweir { 1950cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence> > aOldSequences( 1951cdf0e10cSrcweir xCompareDataSource->getDataSequences() ); 1952cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aNewSequences( 1953cdf0e10cSrcweir xDataSource->getDataSequences()); 1954cdf0e10cSrcweir 1955cdf0e10cSrcweir rtl::OUString aOldLabel; 1956cdf0e10cSrcweir rtl::OUString aNewLabel; 1957cdf0e10cSrcweir rtl::OUString aOldValues; 1958cdf0e10cSrcweir rtl::OUString aNewValues; 1959cdf0e10cSrcweir rtl::OUString aEmpty; 1960cdf0e10cSrcweir 1961cdf0e10cSrcweir for( sal_Int32 nNewIndex = 0; nNewIndex < aNewSequences.getLength(); nNewIndex++ ) 1962cdf0e10cSrcweir { 1963cdf0e10cSrcweir uno::Reference< chart2::data::XLabeledDataSequence> xNew( aNewSequences[nNewIndex] ); 1964cdf0e10cSrcweir for( sal_Int32 nOldIndex = 0; nOldIndex < aOldSequences.getLength(); nOldIndex++ ) 1965cdf0e10cSrcweir { 1966cdf0e10cSrcweir uno::Reference< chart2::data::XLabeledDataSequence> xOld( aOldSequences[nOldIndex] ); 1967cdf0e10cSrcweir 1968cdf0e10cSrcweir if( xOld.is() && xNew.is() ) 1969cdf0e10cSrcweir { 1970cdf0e10cSrcweir aOldLabel = aNewLabel = aOldValues = aNewValues = aEmpty; 1971cdf0e10cSrcweir if( xOld.is() && xOld->getLabel().is() ) 1972cdf0e10cSrcweir aOldLabel = xOld->getLabel()->getSourceRangeRepresentation(); 1973cdf0e10cSrcweir if( xNew.is() && xNew->getLabel().is() ) 1974cdf0e10cSrcweir aNewLabel = xNew->getLabel()->getSourceRangeRepresentation(); 1975cdf0e10cSrcweir if( xOld.is() && xOld->getValues().is() ) 1976cdf0e10cSrcweir aOldValues = xOld->getValues()->getSourceRangeRepresentation(); 1977cdf0e10cSrcweir if( xNew.is() && xNew->getValues().is() ) 1978cdf0e10cSrcweir aNewValues = xNew->getValues()->getSourceRangeRepresentation(); 1979cdf0e10cSrcweir 1980cdf0e10cSrcweir if( aOldLabel.equals(aNewLabel) 1981cdf0e10cSrcweir && ( aOldValues.equals(aNewValues) ) ) 1982cdf0e10cSrcweir { 1983cdf0e10cSrcweir if( nOldIndex!=nNewIndex ) 1984cdf0e10cSrcweir bDifferentIndexes = true; 1985cdf0e10cSrcweir aSequenceMappingVector.push_back(nOldIndex); 1986cdf0e10cSrcweir break; 1987cdf0e10cSrcweir } 1988cdf0e10cSrcweir } 1989cdf0e10cSrcweir } 1990cdf0e10cSrcweir } 1991cdf0e10cSrcweir } 1992cdf0e10cSrcweir 1993cdf0e10cSrcweir if( bDifferentIndexes && aSequenceMappingVector.size() ) 1994cdf0e10cSrcweir { 1995cdf0e10cSrcweir aResult.push_back( 1996cdf0e10cSrcweir beans::PropertyValue( ::rtl::OUString::createFromAscii("SequenceMapping"), -1, 1997cdf0e10cSrcweir uno::makeAny( lcl_VectorToSequence(aSequenceMappingVector) ) 1998cdf0e10cSrcweir , beans::PropertyState_DIRECT_VALUE )); 1999cdf0e10cSrcweir } 2000cdf0e10cSrcweir } 2001cdf0e10cSrcweir 2002cdf0e10cSrcweir return lcl_VectorToSequence( aResult ); 2003cdf0e10cSrcweir } 2004cdf0e10cSrcweir 2005cdf0e10cSrcweir ::sal_Bool SAL_CALL ScChart2DataProvider::createDataSequenceByRangeRepresentationPossible( const ::rtl::OUString& aRangeRepresentation ) 2006cdf0e10cSrcweir throw (uno::RuntimeException) 2007cdf0e10cSrcweir { 2008cdf0e10cSrcweir ScUnoGuard aGuard; 2009cdf0e10cSrcweir if( ! m_pDocument ) 2010cdf0e10cSrcweir return false; 2011cdf0e10cSrcweir 2012cdf0e10cSrcweir vector<ScSharedTokenRef> aTokens; 2013cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation(aTokens, aRangeRepresentation, m_pDocument, m_pDocument->GetGrammar()); 2014cdf0e10cSrcweir return !aTokens.empty(); 2015cdf0e10cSrcweir } 2016cdf0e10cSrcweir 2017cdf0e10cSrcweir uno::Reference< chart2::data::XDataSequence > SAL_CALL 2018cdf0e10cSrcweir ScChart2DataProvider::createDataSequenceByRangeRepresentation( 2019cdf0e10cSrcweir const ::rtl::OUString& aRangeRepresentation ) 2020cdf0e10cSrcweir throw (lang::IllegalArgumentException, 2021cdf0e10cSrcweir uno::RuntimeException) 2022cdf0e10cSrcweir { 2023cdf0e10cSrcweir ScUnoGuard aGuard; 2024cdf0e10cSrcweir uno::Reference< chart2::data::XDataSequence > xResult; 2025cdf0e10cSrcweir 2026cdf0e10cSrcweir DBG_ASSERT( m_pDocument, "No Document -> no createDataSequenceByRangeRepresentation" ); 2027cdf0e10cSrcweir if(!m_pDocument || (aRangeRepresentation.getLength() == 0)) 2028cdf0e10cSrcweir return xResult; 2029cdf0e10cSrcweir 2030cdf0e10cSrcweir // Note: the range representation must be in Calc A1 format. The import 2031cdf0e10cSrcweir // filters use this method to pass data ranges, and they have no idea what 2032cdf0e10cSrcweir // the current formula syntax is. In the future we should add another 2033cdf0e10cSrcweir // method to allow the client code to directly pass tokens representing 2034cdf0e10cSrcweir // ranges. 2035cdf0e10cSrcweir 2036cdf0e10cSrcweir vector<ScSharedTokenRef> aRefTokens; 2037cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation(aRefTokens, aRangeRepresentation, m_pDocument); 2038cdf0e10cSrcweir if (aRefTokens.empty()) 2039cdf0e10cSrcweir return xResult; 2040cdf0e10cSrcweir 2041cdf0e10cSrcweir // ScChart2DataSequence manages the life cycle of pRefTokens. 2042cdf0e10cSrcweir vector<ScSharedTokenRef>* pRefTokens = new vector<ScSharedTokenRef>(); 2043cdf0e10cSrcweir pRefTokens->swap(aRefTokens); 2044cdf0e10cSrcweir xResult.set(new ScChart2DataSequence(m_pDocument, this, pRefTokens, m_bIncludeHiddenCells)); 2045cdf0e10cSrcweir 2046cdf0e10cSrcweir return xResult; 2047cdf0e10cSrcweir } 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir uno::Reference< sheet::XRangeSelection > SAL_CALL ScChart2DataProvider::getRangeSelection() 2050cdf0e10cSrcweir throw (uno::RuntimeException) 2051cdf0e10cSrcweir { 2052cdf0e10cSrcweir uno::Reference< sheet::XRangeSelection > xResult; 2053cdf0e10cSrcweir 2054cdf0e10cSrcweir uno::Reference< frame::XModel > xModel( lcl_GetXModel( m_pDocument )); 2055cdf0e10cSrcweir if( xModel.is()) 2056cdf0e10cSrcweir xResult.set( xModel->getCurrentController(), uno::UNO_QUERY ); 2057cdf0e10cSrcweir 2058cdf0e10cSrcweir return xResult; 2059cdf0e10cSrcweir } 2060cdf0e10cSrcweir 2061cdf0e10cSrcweir /*uno::Reference< util::XNumberFormatsSupplier > SAL_CALL ScChart2DataProvider::getNumberFormatsSupplier() 2062cdf0e10cSrcweir throw (uno::RuntimeException) 2063cdf0e10cSrcweir { 2064cdf0e10cSrcweir return uno::Reference< util::XNumberFormatsSupplier >( lcl_GetXModel( m_pDocument ), uno::UNO_QUERY ); 2065cdf0e10cSrcweir }*/ 2066cdf0e10cSrcweir 2067cdf0e10cSrcweir // XRangeXMLConversion --------------------------------------------------- 2068cdf0e10cSrcweir 2069cdf0e10cSrcweir rtl::OUString SAL_CALL ScChart2DataProvider::convertRangeToXML( const rtl::OUString& sRangeRepresentation ) 2070cdf0e10cSrcweir throw ( uno::RuntimeException, lang::IllegalArgumentException ) 2071cdf0e10cSrcweir { 2072cdf0e10cSrcweir OUString aRet; 2073cdf0e10cSrcweir if (!m_pDocument) 2074cdf0e10cSrcweir return aRet; 2075cdf0e10cSrcweir 2076cdf0e10cSrcweir if (!sRangeRepresentation.getLength()) 2077cdf0e10cSrcweir // Empty data range is allowed. 2078cdf0e10cSrcweir return aRet; 2079cdf0e10cSrcweir 2080cdf0e10cSrcweir vector<ScSharedTokenRef> aRefTokens; 2081cdf0e10cSrcweir ScRefTokenHelper::compileRangeRepresentation(aRefTokens, sRangeRepresentation, m_pDocument, m_pDocument->GetGrammar()); 2082cdf0e10cSrcweir if (aRefTokens.empty()) 2083cdf0e10cSrcweir throw lang::IllegalArgumentException(); 2084cdf0e10cSrcweir 2085cdf0e10cSrcweir Tokens2RangeStringXML converter(m_pDocument); 2086cdf0e10cSrcweir converter = for_each(aRefTokens.begin(), aRefTokens.end(), converter); 2087cdf0e10cSrcweir converter.getString(aRet); 2088cdf0e10cSrcweir 2089cdf0e10cSrcweir return aRet; 2090cdf0e10cSrcweir } 2091cdf0e10cSrcweir 2092cdf0e10cSrcweir rtl::OUString SAL_CALL ScChart2DataProvider::convertRangeFromXML( const rtl::OUString& sXMLRange ) 2093cdf0e10cSrcweir throw ( uno::RuntimeException, lang::IllegalArgumentException ) 2094cdf0e10cSrcweir { 2095cdf0e10cSrcweir const sal_Unicode cSep = ' '; 2096cdf0e10cSrcweir const sal_Unicode cQuote = '\''; 2097cdf0e10cSrcweir 2098cdf0e10cSrcweir if (!m_pDocument) 2099cdf0e10cSrcweir { 2100cdf0e10cSrcweir // #i74062# When loading flat XML, this is called before the referenced sheets are in the document, 2101cdf0e10cSrcweir // so the conversion has to take place directly with the strings, without looking up the sheets. 2102cdf0e10cSrcweir 2103cdf0e10cSrcweir rtl::OUStringBuffer sRet; 2104cdf0e10cSrcweir sal_Int32 nOffset = 0; 2105cdf0e10cSrcweir while( nOffset >= 0 ) 2106cdf0e10cSrcweir { 2107cdf0e10cSrcweir rtl::OUString sToken; 2108cdf0e10cSrcweir ScRangeStringConverter::GetTokenByOffset( sToken, sXMLRange, nOffset, cSep, cQuote ); 2109cdf0e10cSrcweir if( nOffset >= 0 ) 2110cdf0e10cSrcweir { 2111cdf0e10cSrcweir // convert one address (remove dots) 2112cdf0e10cSrcweir 2113cdf0e10cSrcweir String aUIString(sToken); 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir sal_Int32 nIndex = ScRangeStringConverter::IndexOf( sToken, ':', 0, cQuote ); 2116cdf0e10cSrcweir if ( nIndex >= 0 && nIndex < aUIString.Len() - 1 && 2117cdf0e10cSrcweir aUIString.GetChar((xub_StrLen)nIndex + 1) == (sal_Unicode) '.' ) 2118cdf0e10cSrcweir aUIString.Erase( (xub_StrLen)nIndex + 1, 1 ); 2119cdf0e10cSrcweir 2120cdf0e10cSrcweir if ( aUIString.GetChar(0) == (sal_Unicode) '.' ) 2121cdf0e10cSrcweir aUIString.Erase( 0, 1 ); 2122cdf0e10cSrcweir 2123cdf0e10cSrcweir if( sRet.getLength() ) 2124cdf0e10cSrcweir sRet.append( (sal_Unicode) ';' ); 2125cdf0e10cSrcweir sRet.append( aUIString ); 2126cdf0e10cSrcweir } 2127cdf0e10cSrcweir } 2128cdf0e10cSrcweir 2129cdf0e10cSrcweir return sRet.makeStringAndClear(); 2130cdf0e10cSrcweir } 2131cdf0e10cSrcweir 2132cdf0e10cSrcweir OUString aRet; 2133cdf0e10cSrcweir ScRangeStringConverter::GetStringFromXMLRangeString(aRet, sXMLRange, m_pDocument); 2134cdf0e10cSrcweir return aRet; 2135cdf0e10cSrcweir } 2136cdf0e10cSrcweir 2137cdf0e10cSrcweir // DataProvider XPropertySet ------------------------------------------------- 2138cdf0e10cSrcweir 2139cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo> SAL_CALL 2140cdf0e10cSrcweir ScChart2DataProvider::getPropertySetInfo() throw( uno::RuntimeException) 2141cdf0e10cSrcweir { 2142cdf0e10cSrcweir ScUnoGuard aGuard; 2143cdf0e10cSrcweir static uno::Reference<beans::XPropertySetInfo> aRef = 2144cdf0e10cSrcweir new SfxItemPropertySetInfo( m_aPropSet.getPropertyMap() ); 2145cdf0e10cSrcweir return aRef; 2146cdf0e10cSrcweir } 2147cdf0e10cSrcweir 2148cdf0e10cSrcweir 2149cdf0e10cSrcweir void SAL_CALL ScChart2DataProvider::setPropertyValue( 2150cdf0e10cSrcweir const ::rtl::OUString& rPropertyName, const uno::Any& rValue) 2151cdf0e10cSrcweir throw( beans::UnknownPropertyException, 2152cdf0e10cSrcweir beans::PropertyVetoException, 2153cdf0e10cSrcweir lang::IllegalArgumentException, 2154cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 2155cdf0e10cSrcweir { 2156cdf0e10cSrcweir if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS))) 2157cdf0e10cSrcweir { 2158cdf0e10cSrcweir if ( !(rValue >>= m_bIncludeHiddenCells)) 2159cdf0e10cSrcweir throw lang::IllegalArgumentException(); 2160cdf0e10cSrcweir } 2161cdf0e10cSrcweir else 2162cdf0e10cSrcweir throw beans::UnknownPropertyException(); 2163cdf0e10cSrcweir } 2164cdf0e10cSrcweir 2165cdf0e10cSrcweir 2166cdf0e10cSrcweir uno::Any SAL_CALL ScChart2DataProvider::getPropertyValue( 2167cdf0e10cSrcweir const ::rtl::OUString& rPropertyName) 2168cdf0e10cSrcweir throw( beans::UnknownPropertyException, 2169cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 2170cdf0e10cSrcweir { 2171cdf0e10cSrcweir uno::Any aRet; 2172cdf0e10cSrcweir if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS))) 2173cdf0e10cSrcweir aRet <<= m_bIncludeHiddenCells; 2174cdf0e10cSrcweir else 2175cdf0e10cSrcweir throw beans::UnknownPropertyException(); 2176cdf0e10cSrcweir return aRet; 2177cdf0e10cSrcweir } 2178cdf0e10cSrcweir 2179cdf0e10cSrcweir 2180cdf0e10cSrcweir void SAL_CALL ScChart2DataProvider::addPropertyChangeListener( 2181cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 2182cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/) 2183cdf0e10cSrcweir throw( beans::UnknownPropertyException, 2184cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 2185cdf0e10cSrcweir { 2186cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 2187cdf0e10cSrcweir } 2188cdf0e10cSrcweir 2189cdf0e10cSrcweir 2190cdf0e10cSrcweir void SAL_CALL ScChart2DataProvider::removePropertyChangeListener( 2191cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 2192cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/) 2193cdf0e10cSrcweir throw( beans::UnknownPropertyException, 2194cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 2195cdf0e10cSrcweir { 2196cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 2197cdf0e10cSrcweir } 2198cdf0e10cSrcweir 2199cdf0e10cSrcweir 2200cdf0e10cSrcweir void SAL_CALL ScChart2DataProvider::addVetoableChangeListener( 2201cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 2202cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/) 2203cdf0e10cSrcweir throw( beans::UnknownPropertyException, 2204cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 2205cdf0e10cSrcweir { 2206cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 2207cdf0e10cSrcweir } 2208cdf0e10cSrcweir 2209cdf0e10cSrcweir 2210cdf0e10cSrcweir void SAL_CALL ScChart2DataProvider::removeVetoableChangeListener( 2211cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 2212cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/ ) 2213cdf0e10cSrcweir throw( beans::UnknownPropertyException, 2214cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 2215cdf0e10cSrcweir { 2216cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 2217cdf0e10cSrcweir } 2218cdf0e10cSrcweir 2219cdf0e10cSrcweir // DataSource ================================================================ 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir ScChart2DataSource::ScChart2DataSource( ScDocument* pDoc) 2222cdf0e10cSrcweir : m_pDocument( pDoc) 2223cdf0e10cSrcweir { 2224cdf0e10cSrcweir if ( m_pDocument ) 2225cdf0e10cSrcweir m_pDocument->AddUnoObject( *this); 2226cdf0e10cSrcweir } 2227cdf0e10cSrcweir 2228cdf0e10cSrcweir 2229cdf0e10cSrcweir ScChart2DataSource::~ScChart2DataSource() 2230cdf0e10cSrcweir { 2231cdf0e10cSrcweir if ( m_pDocument ) 2232cdf0e10cSrcweir m_pDocument->RemoveUnoObject( *this); 2233cdf0e10cSrcweir } 2234cdf0e10cSrcweir 2235cdf0e10cSrcweir 2236cdf0e10cSrcweir void ScChart2DataSource::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint) 2237cdf0e10cSrcweir { 2238cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && 2239cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 2240cdf0e10cSrcweir { 2241cdf0e10cSrcweir m_pDocument = NULL; 2242cdf0e10cSrcweir } 2243cdf0e10cSrcweir } 2244cdf0e10cSrcweir 2245cdf0e10cSrcweir 2246cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence> > SAL_CALL 2247cdf0e10cSrcweir ScChart2DataSource::getDataSequences() throw ( uno::RuntimeException) 2248cdf0e10cSrcweir { 2249cdf0e10cSrcweir ScUnoGuard aGuard; 2250cdf0e10cSrcweir 2251cdf0e10cSrcweir LabeledList::const_iterator aItr(m_aLabeledSequences.begin()); 2252cdf0e10cSrcweir LabeledList::const_iterator aEndItr(m_aLabeledSequences.end()); 2253cdf0e10cSrcweir 2254cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aRet(m_aLabeledSequences.size()); 2255cdf0e10cSrcweir 2256cdf0e10cSrcweir sal_Int32 i = 0; 2257cdf0e10cSrcweir while (aItr != aEndItr) 2258cdf0e10cSrcweir { 2259cdf0e10cSrcweir aRet[i] = *aItr; 2260cdf0e10cSrcweir ++i; 2261cdf0e10cSrcweir ++aItr; 2262cdf0e10cSrcweir } 2263cdf0e10cSrcweir 2264cdf0e10cSrcweir return aRet; 2265cdf0e10cSrcweir 2266cdf0e10cSrcweir /* typedef ::std::vector< uno::Reference< chart2::data::XLabeledDataSequence > > tVec; 2267cdf0e10cSrcweir tVec aVec; 2268cdf0e10cSrcweir bool bSeries = false; 2269cdf0e10cSrcweir // split into columns - FIXME: different if GlueState() is used 2270cdf0e10cSrcweir for ( ScRangePtr p = m_xRanges->First(); p; p = m_xRanges->Next()) 2271cdf0e10cSrcweir { 2272cdf0e10cSrcweir for ( SCCOL nCol = p->aStart.Col(); nCol <= p->aEnd.Col(); ++nCol) 2273cdf0e10cSrcweir { 2274cdf0e10cSrcweir uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( 2275cdf0e10cSrcweir new ScChart2LabeledDataSequence( m_pDocument)); 2276cdf0e10cSrcweir if( xLabeledSeq.is()) 2277cdf0e10cSrcweir { 2278cdf0e10cSrcweir aVec.push_back( xLabeledSeq ); 2279cdf0e10cSrcweir if( bSeries ) 2280cdf0e10cSrcweir { 2281cdf0e10cSrcweir ScRangeListRef aColRanges = new ScRangeList; 2282cdf0e10cSrcweir // one single sheet selected assumed for now 2283cdf0e10cSrcweir aColRanges->Append( ScRange( nCol, p->aStart.Row(), 2284cdf0e10cSrcweir p->aStart.Tab(), nCol, p->aStart.Row(), 2285cdf0e10cSrcweir p->aStart.Tab())); 2286cdf0e10cSrcweir // TEST: add range two times, once as label, once as data 2287cdf0e10cSrcweir // TODO: create pure Numerical and Text sequences if possible 2288cdf0e10cSrcweir uno::Reference< chart2::data::XDataSequence > xLabel( 2289cdf0e10cSrcweir new ScChart2DataSequence( m_pDocument, aColRanges)); 2290cdf0e10cSrcweir 2291cdf0e10cSrcweir // set role 2292cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xLabel, uno::UNO_QUERY ); 2293cdf0e10cSrcweir if( xProp.is()) 2294cdf0e10cSrcweir xProp->setPropertyValue( 2295cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )), 2296cdf0e10cSrcweir ::uno::makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "label" )))); 2297cdf0e10cSrcweir 2298cdf0e10cSrcweir xLabeledSeq->setLabel( xLabel ); 2299cdf0e10cSrcweir } 2300cdf0e10cSrcweir 2301cdf0e10cSrcweir ScRangeListRef aColRanges = new ScRangeList; 2302cdf0e10cSrcweir 2303cdf0e10cSrcweir // one single sheet selected assumed for now 2304cdf0e10cSrcweir aColRanges->Append( ScRange( nCol, p->aStart.Row() + 1, 2305cdf0e10cSrcweir p->aStart.Tab(), nCol, p->aEnd.Row(), 2306cdf0e10cSrcweir p->aStart.Tab())); 2307cdf0e10cSrcweir uno::Reference< chart2::data::XDataSequence > xData( 2308cdf0e10cSrcweir new ScChart2DataSequence( m_pDocument, aColRanges)); 2309cdf0e10cSrcweir 2310cdf0e10cSrcweir // set role 2311cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xData, uno::UNO_QUERY ); 2312cdf0e10cSrcweir if( xProp.is()) 2313cdf0e10cSrcweir xProp->setPropertyValue( 2314cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Role" )), 2315cdf0e10cSrcweir ::uno::makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "values" )))); 2316cdf0e10cSrcweir 2317cdf0e10cSrcweir xLabeledSeq->setValues( xData ); 2318cdf0e10cSrcweir 2319cdf0e10cSrcweir bSeries = true; 2320cdf0e10cSrcweir } 2321cdf0e10cSrcweir } 2322cdf0e10cSrcweir } 2323cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence> > aSequences( 2324cdf0e10cSrcweir aVec.size()); 2325cdf0e10cSrcweir uno::Reference< chart2::data::XLabeledDataSequence> * pArr = aSequences.getArray(); 2326cdf0e10cSrcweir sal_Int32 j = 0; 2327cdf0e10cSrcweir for ( tVec::const_iterator iSeq = aVec.begin(); iSeq != aVec.end(); 2328cdf0e10cSrcweir ++iSeq, ++j) 2329cdf0e10cSrcweir { 2330cdf0e10cSrcweir pArr[j] = *iSeq; 2331cdf0e10cSrcweir } 2332cdf0e10cSrcweir return aSequences;*/ 2333cdf0e10cSrcweir } 2334cdf0e10cSrcweir 2335cdf0e10cSrcweir void ScChart2DataSource::AddLabeledSequence(const uno::Reference < chart2::data::XLabeledDataSequence >& xNew) 2336cdf0e10cSrcweir { 2337cdf0e10cSrcweir m_aLabeledSequences.push_back(xNew); 2338cdf0e10cSrcweir } 2339cdf0e10cSrcweir 2340cdf0e10cSrcweir 2341cdf0e10cSrcweir // DataSequence ============================================================== 2342cdf0e10cSrcweir 2343cdf0e10cSrcweir ScChart2DataSequence::Item::Item() : 2344cdf0e10cSrcweir mfValue(0.0), mbIsValue(false) 2345cdf0e10cSrcweir { 2346cdf0e10cSrcweir ::rtl::math::setNan(&mfValue); 2347cdf0e10cSrcweir } 2348cdf0e10cSrcweir 2349cdf0e10cSrcweir ScChart2DataSequence::HiddenRangeListener::HiddenRangeListener(ScChart2DataSequence& rParent) : 2350cdf0e10cSrcweir mrParent(rParent) 2351cdf0e10cSrcweir { 2352cdf0e10cSrcweir } 2353cdf0e10cSrcweir 2354cdf0e10cSrcweir ScChart2DataSequence::HiddenRangeListener::~HiddenRangeListener() 2355cdf0e10cSrcweir { 2356cdf0e10cSrcweir } 2357cdf0e10cSrcweir 2358cdf0e10cSrcweir void ScChart2DataSequence::HiddenRangeListener::notify() 2359cdf0e10cSrcweir { 2360cdf0e10cSrcweir mrParent.setDataChangedHint(true); 2361cdf0e10cSrcweir } 2362cdf0e10cSrcweir 2363cdf0e10cSrcweir ScChart2DataSequence::ScChart2DataSequence( ScDocument* pDoc, 2364cdf0e10cSrcweir const uno::Reference < chart2::data::XDataProvider >& xDP, 2365cdf0e10cSrcweir vector<ScSharedTokenRef>* pTokens, 2366cdf0e10cSrcweir bool bIncludeHiddenCells ) 2367cdf0e10cSrcweir : m_bIncludeHiddenCells( bIncludeHiddenCells) 2368cdf0e10cSrcweir , m_nObjectId( 0 ) 2369cdf0e10cSrcweir , m_pDocument( pDoc) 2370cdf0e10cSrcweir , m_pTokens(pTokens) 2371cdf0e10cSrcweir , m_pRangeIndices(NULL) 2372cdf0e10cSrcweir , m_pExtRefListener(NULL) 2373cdf0e10cSrcweir , m_xDataProvider( xDP) 2374cdf0e10cSrcweir , m_aPropSet(lcl_GetDataSequencePropertyMap()) 2375cdf0e10cSrcweir , m_pHiddenListener(NULL) 2376cdf0e10cSrcweir , m_pValueListener( NULL ) 2377cdf0e10cSrcweir , m_bGotDataChangedHint(false) 2378cdf0e10cSrcweir , m_bExtDataRebuildQueued(false) 2379cdf0e10cSrcweir { 2380cdf0e10cSrcweir DBG_ASSERT(pTokens, "reference token list is null"); 2381cdf0e10cSrcweir 2382cdf0e10cSrcweir if ( m_pDocument ) 2383cdf0e10cSrcweir { 2384cdf0e10cSrcweir m_pDocument->AddUnoObject( *this); 2385cdf0e10cSrcweir m_nObjectId = m_pDocument->GetNewUnoId(); 2386cdf0e10cSrcweir } 2387cdf0e10cSrcweir // FIXME: real implementation of identifier and it's mapping to ranges. 2388cdf0e10cSrcweir // Reuse ScChartListener? 2389cdf0e10cSrcweir 2390cdf0e10cSrcweir // BM: don't use names of named ranges but the UI range strings 2391cdf0e10cSrcweir // String aStr; 2392cdf0e10cSrcweir // rRangeList->Format( aStr, SCR_ABS_3D, m_pDocument ); 2393cdf0e10cSrcweir // m_aIdentifier = ::rtl::OUString( aStr ); 2394cdf0e10cSrcweir 2395cdf0e10cSrcweir // m_aIdentifier = ::rtl::OUString::createFromAscii( "ID_"); 2396cdf0e10cSrcweir // static sal_Int32 nID = 0; 2397cdf0e10cSrcweir // m_aIdentifier += ::rtl::OUString::valueOf( ++nID); 2398cdf0e10cSrcweir } 2399cdf0e10cSrcweir 2400cdf0e10cSrcweir ScChart2DataSequence::~ScChart2DataSequence() 2401cdf0e10cSrcweir { 2402cdf0e10cSrcweir if ( m_pDocument ) 2403cdf0e10cSrcweir { 2404cdf0e10cSrcweir m_pDocument->RemoveUnoObject( *this); 2405cdf0e10cSrcweir if (m_pHiddenListener.get()) 2406cdf0e10cSrcweir { 2407cdf0e10cSrcweir ScChartListenerCollection* pCLC = m_pDocument->GetChartListenerCollection(); 2408cdf0e10cSrcweir if (pCLC) 2409cdf0e10cSrcweir pCLC->EndListeningHiddenRange(m_pHiddenListener.get()); 2410cdf0e10cSrcweir } 2411cdf0e10cSrcweir StopListeningToAllExternalRefs(); 2412cdf0e10cSrcweir } 2413cdf0e10cSrcweir 2414cdf0e10cSrcweir delete m_pValueListener; 2415cdf0e10cSrcweir } 2416cdf0e10cSrcweir 2417cdf0e10cSrcweir void ScChart2DataSequence::RefChanged() 2418cdf0e10cSrcweir { 2419cdf0e10cSrcweir if( m_pValueListener && m_aValueListeners.Count() != 0 ) 2420cdf0e10cSrcweir { 2421cdf0e10cSrcweir m_pValueListener->EndListeningAll(); 2422cdf0e10cSrcweir 2423cdf0e10cSrcweir if( m_pDocument ) 2424cdf0e10cSrcweir { 2425cdf0e10cSrcweir ScChartListenerCollection* pCLC = NULL; 2426cdf0e10cSrcweir if (m_pHiddenListener.get()) 2427cdf0e10cSrcweir { 2428cdf0e10cSrcweir pCLC = m_pDocument->GetChartListenerCollection(); 2429cdf0e10cSrcweir if (pCLC) 2430cdf0e10cSrcweir pCLC->EndListeningHiddenRange(m_pHiddenListener.get()); 2431cdf0e10cSrcweir } 2432cdf0e10cSrcweir 2433cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = m_pTokens->begin(), itrEnd = m_pTokens->end(); 2434cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 2435cdf0e10cSrcweir { 2436cdf0e10cSrcweir ScRange aRange; 2437cdf0e10cSrcweir if (!ScRefTokenHelper::getRangeFromToken(aRange, *itr)) 2438cdf0e10cSrcweir continue; 2439cdf0e10cSrcweir 2440cdf0e10cSrcweir m_pDocument->StartListeningArea(aRange, m_pValueListener); 2441cdf0e10cSrcweir if (pCLC) 2442cdf0e10cSrcweir pCLC->StartListeningHiddenRange(aRange, m_pHiddenListener.get()); 2443cdf0e10cSrcweir } 2444cdf0e10cSrcweir } 2445cdf0e10cSrcweir } 2446cdf0e10cSrcweir } 2447cdf0e10cSrcweir 2448cdf0e10cSrcweir void ScChart2DataSequence::BuildDataCache() 2449cdf0e10cSrcweir { 2450cdf0e10cSrcweir m_bExtDataRebuildQueued = false; 2451cdf0e10cSrcweir 2452cdf0e10cSrcweir if (!m_aDataArray.empty()) 2453cdf0e10cSrcweir return; 2454cdf0e10cSrcweir 2455cdf0e10cSrcweir if (!m_pTokens.get()) 2456cdf0e10cSrcweir { 2457cdf0e10cSrcweir DBG_ERROR("m_pTokens == NULL! Something is wrong."); 2458cdf0e10cSrcweir return; 2459cdf0e10cSrcweir } 2460cdf0e10cSrcweir 2461cdf0e10cSrcweir StopListeningToAllExternalRefs(); 2462cdf0e10cSrcweir 2463cdf0e10cSrcweir ::std::list<sal_Int32> aHiddenValues; 2464cdf0e10cSrcweir sal_Int32 nDataCount = 0; 2465cdf0e10cSrcweir sal_Int32 nHiddenValueCount = 0; 2466cdf0e10cSrcweir 2467cdf0e10cSrcweir for (vector<ScSharedTokenRef>::const_iterator itr = m_pTokens->begin(), itrEnd = m_pTokens->end(); 2468cdf0e10cSrcweir itr != itrEnd; ++itr) 2469cdf0e10cSrcweir { 2470cdf0e10cSrcweir if (ScRefTokenHelper::isExternalRef(*itr)) 2471cdf0e10cSrcweir { 2472cdf0e10cSrcweir nDataCount += FillCacheFromExternalRef(*itr); 2473cdf0e10cSrcweir } 2474cdf0e10cSrcweir else 2475cdf0e10cSrcweir { 2476cdf0e10cSrcweir ScRange aRange; 2477cdf0e10cSrcweir if (!ScRefTokenHelper::getRangeFromToken(aRange, *itr)) 2478cdf0e10cSrcweir continue; 2479cdf0e10cSrcweir 2480cdf0e10cSrcweir SCCOL nLastCol = -1; 2481cdf0e10cSrcweir SCROW nLastRow = -1; 2482cdf0e10cSrcweir for (SCTAB nTab = aRange.aStart.Tab(); nTab <= aRange.aEnd.Tab(); ++nTab) 2483cdf0e10cSrcweir { 2484cdf0e10cSrcweir for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol) 2485cdf0e10cSrcweir { 2486cdf0e10cSrcweir for (SCROW nRow = aRange.aStart.Row(); nRow <= aRange.aEnd.Row(); ++nRow) 2487cdf0e10cSrcweir { 2488cdf0e10cSrcweir bool bColHidden = m_pDocument->ColHidden(nCol, nTab, nLastCol); 2489cdf0e10cSrcweir bool bRowHidden = m_pDocument->RowHidden(nRow, nTab, nLastRow); 2490cdf0e10cSrcweir 2491cdf0e10cSrcweir if (bColHidden || bRowHidden) 2492cdf0e10cSrcweir { 2493cdf0e10cSrcweir // hidden cell 2494cdf0e10cSrcweir ++nHiddenValueCount; 2495cdf0e10cSrcweir aHiddenValues.push_back(nDataCount-1); 2496cdf0e10cSrcweir 2497cdf0e10cSrcweir if( !m_bIncludeHiddenCells ) 2498cdf0e10cSrcweir continue; 2499cdf0e10cSrcweir } 2500cdf0e10cSrcweir 2501cdf0e10cSrcweir m_aDataArray.push_back(Item()); 2502cdf0e10cSrcweir Item& rItem = m_aDataArray.back(); 2503cdf0e10cSrcweir ++nDataCount; 2504cdf0e10cSrcweir 2505cdf0e10cSrcweir ScAddress aAdr(nCol, nRow, nTab); 2506cdf0e10cSrcweir ScBaseCell* pCell = m_pDocument->GetCell(aAdr); 2507cdf0e10cSrcweir if (!pCell) 2508cdf0e10cSrcweir continue; 2509cdf0e10cSrcweir 2510cdf0e10cSrcweir if (pCell->HasStringData()) 2511cdf0e10cSrcweir rItem.maString = pCell->GetStringData(); 2512cdf0e10cSrcweir else 2513cdf0e10cSrcweir { 2514cdf0e10cSrcweir String aStr; 2515cdf0e10cSrcweir m_pDocument->GetString(nCol, nRow, nTab, aStr); 2516cdf0e10cSrcweir rItem.maString = aStr; 2517cdf0e10cSrcweir } 2518cdf0e10cSrcweir 2519cdf0e10cSrcweir switch (pCell->GetCellType()) 2520cdf0e10cSrcweir { 2521cdf0e10cSrcweir case CELLTYPE_VALUE: 2522cdf0e10cSrcweir rItem.mfValue = static_cast< ScValueCell*>(pCell)->GetValue(); 2523cdf0e10cSrcweir rItem.mbIsValue = true; 2524cdf0e10cSrcweir break; 2525cdf0e10cSrcweir case CELLTYPE_FORMULA: 2526cdf0e10cSrcweir { 2527cdf0e10cSrcweir ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell); 2528cdf0e10cSrcweir sal_uInt16 nErr = pFCell->GetErrCode(); 2529cdf0e10cSrcweir if (nErr) 2530cdf0e10cSrcweir break; 2531cdf0e10cSrcweir 2532cdf0e10cSrcweir if (pFCell->HasValueData()) 2533cdf0e10cSrcweir { 2534cdf0e10cSrcweir rItem.mfValue = pFCell->GetValue(); 2535cdf0e10cSrcweir rItem.mbIsValue = true; 2536cdf0e10cSrcweir } 2537cdf0e10cSrcweir } 2538cdf0e10cSrcweir break; 2539cdf0e10cSrcweir #if DBG_UTIL 2540cdf0e10cSrcweir case CELLTYPE_DESTROYED: 2541cdf0e10cSrcweir #endif 2542cdf0e10cSrcweir case CELLTYPE_EDIT: 2543cdf0e10cSrcweir case CELLTYPE_NONE: 2544cdf0e10cSrcweir case CELLTYPE_NOTE: 2545cdf0e10cSrcweir case CELLTYPE_STRING: 2546cdf0e10cSrcweir case CELLTYPE_SYMBOLS: 2547cdf0e10cSrcweir default: 2548cdf0e10cSrcweir ; // do nothing 2549cdf0e10cSrcweir } 2550cdf0e10cSrcweir } 2551cdf0e10cSrcweir } 2552cdf0e10cSrcweir } 2553cdf0e10cSrcweir } 2554cdf0e10cSrcweir } 2555cdf0e10cSrcweir 2556cdf0e10cSrcweir // convert the hidden cell list to sequence. 2557cdf0e10cSrcweir m_aHiddenValues.realloc(nHiddenValueCount); 2558cdf0e10cSrcweir sal_Int32* pArr = m_aHiddenValues.getArray(); 2559cdf0e10cSrcweir ::std::list<sal_Int32>::const_iterator itr = aHiddenValues.begin(), itrEnd = aHiddenValues.end(); 2560cdf0e10cSrcweir for (;itr != itrEnd; ++itr, ++pArr) 2561cdf0e10cSrcweir *pArr = *itr; 2562cdf0e10cSrcweir 2563cdf0e10cSrcweir // Clear the data series cache when the array is re-built. 2564cdf0e10cSrcweir m_aMixedDataCache.realloc(0); 2565cdf0e10cSrcweir } 2566cdf0e10cSrcweir 2567cdf0e10cSrcweir void ScChart2DataSequence::RebuildDataCache() 2568cdf0e10cSrcweir { 2569cdf0e10cSrcweir if (!m_bExtDataRebuildQueued) 2570cdf0e10cSrcweir { 2571cdf0e10cSrcweir m_aDataArray.clear(); 2572cdf0e10cSrcweir m_pDocument->BroadcastUno(ScHint(SC_HINT_DATACHANGED, ScAddress(), NULL)); 2573cdf0e10cSrcweir m_bExtDataRebuildQueued = true; 2574cdf0e10cSrcweir m_bGotDataChangedHint = true; 2575cdf0e10cSrcweir } 2576cdf0e10cSrcweir } 2577cdf0e10cSrcweir 2578cdf0e10cSrcweir sal_Int32 ScChart2DataSequence::FillCacheFromExternalRef(const ScSharedTokenRef& pToken) 2579cdf0e10cSrcweir { 2580cdf0e10cSrcweir ScExternalRefManager* pRefMgr = m_pDocument->GetExternalRefManager(); 2581cdf0e10cSrcweir ScRange aRange; 2582cdf0e10cSrcweir if (!ScRefTokenHelper::getRangeFromToken(aRange, pToken, true)) 2583cdf0e10cSrcweir return 0; 2584cdf0e10cSrcweir 2585cdf0e10cSrcweir sal_uInt16 nFileId = pToken->GetIndex(); 2586cdf0e10cSrcweir const String& rTabName = pToken->GetString(); 2587cdf0e10cSrcweir ScExternalRefCache::TokenArrayRef pArray = pRefMgr->getDoubleRefTokens(nFileId, rTabName, aRange, NULL); 2588cdf0e10cSrcweir if (!pArray) 2589cdf0e10cSrcweir // no external data exists for this range. 2590cdf0e10cSrcweir return 0; 2591cdf0e10cSrcweir 2592cdf0e10cSrcweir // Start listening for this external document. 2593cdf0e10cSrcweir ExternalRefListener* pExtRefListener = GetExtRefListener(); 2594cdf0e10cSrcweir pRefMgr->addLinkListener(nFileId, pExtRefListener); 2595cdf0e10cSrcweir pExtRefListener->addFileId(nFileId); 2596cdf0e10cSrcweir 2597cdf0e10cSrcweir ScExternalRefCache::TableTypeRef pTable = pRefMgr->getCacheTable(nFileId, rTabName, false, NULL); 2598cdf0e10cSrcweir sal_Int32 nDataCount = 0; 2599cdf0e10cSrcweir for (FormulaToken* p = pArray->First(); p; p = pArray->Next()) 2600cdf0e10cSrcweir { 2601cdf0e10cSrcweir // Cached external range is always represented as a single 2602cdf0e10cSrcweir // matrix token, although that might change in the future when 2603cdf0e10cSrcweir // we introduce a new token type to store multi-table range 2604cdf0e10cSrcweir // data. 2605cdf0e10cSrcweir 2606cdf0e10cSrcweir if (p->GetType() != svMatrix) 2607cdf0e10cSrcweir { 2608cdf0e10cSrcweir DBG_ERROR("Cached array is not a matrix token."); 2609cdf0e10cSrcweir continue; 2610cdf0e10cSrcweir } 2611cdf0e10cSrcweir 2612cdf0e10cSrcweir const ScMatrix* pMat = static_cast<ScToken*>(p)->GetMatrix(); 2613cdf0e10cSrcweir SCSIZE nCSize, nRSize; 2614cdf0e10cSrcweir pMat->GetDimensions(nCSize, nRSize); 2615cdf0e10cSrcweir for (SCSIZE nC = 0; nC < nCSize; ++nC) 2616cdf0e10cSrcweir { 2617cdf0e10cSrcweir for (SCSIZE nR = 0; nR < nRSize; ++nR) 2618cdf0e10cSrcweir { 2619cdf0e10cSrcweir if (pMat->IsValue(nC, nR) || pMat->IsBoolean(nC, nR)) 2620cdf0e10cSrcweir { 2621cdf0e10cSrcweir m_aDataArray.push_back(Item()); 2622cdf0e10cSrcweir Item& rItem = m_aDataArray.back(); 2623cdf0e10cSrcweir ++nDataCount; 2624cdf0e10cSrcweir 2625cdf0e10cSrcweir rItem.mbIsValue = true; 2626cdf0e10cSrcweir rItem.mfValue = pMat->GetDouble(nC, nR); 2627cdf0e10cSrcweir 2628cdf0e10cSrcweir SvNumberFormatter* pFormatter = m_pDocument->GetFormatTable(); 2629cdf0e10cSrcweir if (pFormatter) 2630cdf0e10cSrcweir { 2631cdf0e10cSrcweir String aStr; 2632cdf0e10cSrcweir const double fVal = rItem.mfValue; 2633cdf0e10cSrcweir Color* pColor = NULL; 2634cdf0e10cSrcweir sal_uInt32 nFmt = 0; 2635cdf0e10cSrcweir if (pTable) 2636cdf0e10cSrcweir { 2637cdf0e10cSrcweir // Get the correct format index from the cache. 2638cdf0e10cSrcweir SCCOL nCol = aRange.aStart.Col() + static_cast<SCCOL>(nC); 2639cdf0e10cSrcweir SCROW nRow = aRange.aStart.Row() + static_cast<SCROW>(nR); 2640cdf0e10cSrcweir pTable->getCell(nCol, nRow, &nFmt); 2641cdf0e10cSrcweir } 2642cdf0e10cSrcweir pFormatter->GetOutputString(fVal, nFmt, aStr, &pColor); 2643cdf0e10cSrcweir rItem.maString = aStr; 2644cdf0e10cSrcweir } 2645cdf0e10cSrcweir } 2646cdf0e10cSrcweir else if (pMat->IsString(nC, nR)) 2647cdf0e10cSrcweir { 2648cdf0e10cSrcweir m_aDataArray.push_back(Item()); 2649cdf0e10cSrcweir Item& rItem = m_aDataArray.back(); 2650cdf0e10cSrcweir ++nDataCount; 2651cdf0e10cSrcweir 2652cdf0e10cSrcweir rItem.mbIsValue = false; 2653cdf0e10cSrcweir rItem.maString = pMat->GetString(nC, nR); 2654cdf0e10cSrcweir } 2655cdf0e10cSrcweir } 2656cdf0e10cSrcweir } 2657cdf0e10cSrcweir } 2658cdf0e10cSrcweir return nDataCount; 2659cdf0e10cSrcweir } 2660cdf0e10cSrcweir 2661cdf0e10cSrcweir void ScChart2DataSequence::UpdateTokensFromRanges(const ScRangeList& rRanges) 2662cdf0e10cSrcweir { 2663cdf0e10cSrcweir if (!m_pRangeIndices.get()) 2664cdf0e10cSrcweir return; 2665cdf0e10cSrcweir 2666cdf0e10cSrcweir sal_uInt32 nCount = rRanges.Count(); 2667cdf0e10cSrcweir for (sal_uInt32 i = 0; i < nCount; ++i) 2668cdf0e10cSrcweir { 2669cdf0e10cSrcweir ScSharedTokenRef pToken; 2670cdf0e10cSrcweir ScRange* pRange = static_cast<ScRange*>(rRanges.GetObject(i)); 2671cdf0e10cSrcweir DBG_ASSERT(pRange, "range object is NULL."); 2672cdf0e10cSrcweir 2673cdf0e10cSrcweir ScRefTokenHelper::getTokenFromRange(pToken, *pRange); 2674cdf0e10cSrcweir sal_uInt32 nOrigPos = (*m_pRangeIndices)[i]; 2675cdf0e10cSrcweir (*m_pTokens)[nOrigPos] = pToken; 2676cdf0e10cSrcweir } 2677cdf0e10cSrcweir 2678cdf0e10cSrcweir RefChanged(); 2679cdf0e10cSrcweir 2680cdf0e10cSrcweir // any change of the range address is broadcast to value (modify) listeners 2681cdf0e10cSrcweir if ( m_aValueListeners.Count() ) 2682cdf0e10cSrcweir m_bGotDataChangedHint = true; 2683cdf0e10cSrcweir } 2684cdf0e10cSrcweir 2685cdf0e10cSrcweir ScChart2DataSequence::ExternalRefListener* ScChart2DataSequence::GetExtRefListener() 2686cdf0e10cSrcweir { 2687cdf0e10cSrcweir if (!m_pExtRefListener.get()) 2688cdf0e10cSrcweir m_pExtRefListener.reset(new ExternalRefListener(*this, m_pDocument)); 2689cdf0e10cSrcweir 2690cdf0e10cSrcweir return m_pExtRefListener.get(); 2691cdf0e10cSrcweir } 2692cdf0e10cSrcweir 2693cdf0e10cSrcweir void ScChart2DataSequence::StopListeningToAllExternalRefs() 2694cdf0e10cSrcweir { 2695cdf0e10cSrcweir if (!m_pExtRefListener.get()) 2696cdf0e10cSrcweir return; 2697cdf0e10cSrcweir 2698cdf0e10cSrcweir const hash_set<sal_uInt16>& rFileIds = m_pExtRefListener->getAllFileIds(); 2699cdf0e10cSrcweir hash_set<sal_uInt16>::const_iterator itr = rFileIds.begin(), itrEnd = rFileIds.end(); 2700cdf0e10cSrcweir ScExternalRefManager* pRefMgr = m_pDocument->GetExternalRefManager(); 2701cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 2702cdf0e10cSrcweir pRefMgr->removeLinkListener(*itr, m_pExtRefListener.get()); 2703cdf0e10cSrcweir 2704cdf0e10cSrcweir m_pExtRefListener.reset(NULL); 2705cdf0e10cSrcweir } 2706cdf0e10cSrcweir 2707cdf0e10cSrcweir void ScChart2DataSequence::CopyData(const ScChart2DataSequence& r) 2708cdf0e10cSrcweir { 2709cdf0e10cSrcweir if (!m_pDocument) 2710cdf0e10cSrcweir { 2711cdf0e10cSrcweir DBG_ERROR("document instance is NULL!?"); 2712cdf0e10cSrcweir return; 2713cdf0e10cSrcweir } 2714cdf0e10cSrcweir 2715cdf0e10cSrcweir list<Item> aDataArray(r.m_aDataArray); 2716cdf0e10cSrcweir m_aDataArray.swap(aDataArray); 2717cdf0e10cSrcweir 2718cdf0e10cSrcweir m_aHiddenValues = r.m_aHiddenValues; 2719cdf0e10cSrcweir m_aRole = r.m_aRole; 2720cdf0e10cSrcweir 2721cdf0e10cSrcweir if (r.m_pRangeIndices.get()) 2722cdf0e10cSrcweir m_pRangeIndices.reset(new vector<sal_uInt32>(*r.m_pRangeIndices)); 2723cdf0e10cSrcweir 2724cdf0e10cSrcweir if (r.m_pExtRefListener.get()) 2725cdf0e10cSrcweir { 2726cdf0e10cSrcweir // Re-register all external files that the old instance was 2727cdf0e10cSrcweir // listening to. 2728cdf0e10cSrcweir 2729cdf0e10cSrcweir ScExternalRefManager* pRefMgr = m_pDocument->GetExternalRefManager(); 2730cdf0e10cSrcweir m_pExtRefListener.reset(new ExternalRefListener(*this, m_pDocument)); 2731cdf0e10cSrcweir const hash_set<sal_uInt16>& rFileIds = r.m_pExtRefListener->getAllFileIds(); 2732cdf0e10cSrcweir hash_set<sal_uInt16>::const_iterator itr = rFileIds.begin(), itrEnd = rFileIds.end(); 2733cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 2734cdf0e10cSrcweir { 2735cdf0e10cSrcweir pRefMgr->addLinkListener(*itr, m_pExtRefListener.get()); 2736cdf0e10cSrcweir m_pExtRefListener->addFileId(*itr); 2737cdf0e10cSrcweir } 2738cdf0e10cSrcweir } 2739cdf0e10cSrcweir } 2740cdf0e10cSrcweir 2741cdf0e10cSrcweir void ScChart2DataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint) 2742cdf0e10cSrcweir { 2743cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) ) 2744cdf0e10cSrcweir { 2745cdf0e10cSrcweir sal_uLong nId = static_cast<const SfxSimpleHint&>(rHint).GetId(); 2746cdf0e10cSrcweir if ( nId ==SFX_HINT_DYING ) 2747cdf0e10cSrcweir { 2748cdf0e10cSrcweir m_pDocument = NULL; 2749cdf0e10cSrcweir } 2750cdf0e10cSrcweir else if ( nId == SFX_HINT_DATACHANGED ) 2751cdf0e10cSrcweir { 2752cdf0e10cSrcweir // delayed broadcast as in ScCellRangesBase 2753cdf0e10cSrcweir 2754cdf0e10cSrcweir if ( m_bGotDataChangedHint && m_pDocument ) 2755cdf0e10cSrcweir { 2756cdf0e10cSrcweir m_aDataArray.clear(); 2757cdf0e10cSrcweir lang::EventObject aEvent; 2758cdf0e10cSrcweir aEvent.Source.set((cppu::OWeakObject*)this); 2759cdf0e10cSrcweir 2760cdf0e10cSrcweir if( m_pDocument ) 2761cdf0e10cSrcweir { 2762cdf0e10cSrcweir for ( sal_uInt16 n=0; n<m_aValueListeners.Count(); n++ ) 2763cdf0e10cSrcweir m_pDocument->AddUnoListenerCall( *m_aValueListeners[n], aEvent ); 2764cdf0e10cSrcweir } 2765cdf0e10cSrcweir 2766cdf0e10cSrcweir m_bGotDataChangedHint = false; 2767cdf0e10cSrcweir } 2768cdf0e10cSrcweir } 2769cdf0e10cSrcweir else if ( nId == SC_HINT_CALCALL ) 2770cdf0e10cSrcweir { 2771cdf0e10cSrcweir // broadcast from DoHardRecalc - set m_bGotDataChangedHint 2772cdf0e10cSrcweir // (SFX_HINT_DATACHANGED follows separately) 2773cdf0e10cSrcweir 2774cdf0e10cSrcweir if ( m_aValueListeners.Count() ) 2775cdf0e10cSrcweir m_bGotDataChangedHint = true; 2776cdf0e10cSrcweir } 2777cdf0e10cSrcweir } 2778cdf0e10cSrcweir else if ( rHint.ISA( ScUpdateRefHint ) ) 2779cdf0e10cSrcweir { 2780cdf0e10cSrcweir // Create a range list from the token list, have the range list 2781cdf0e10cSrcweir // updated, and bring the change back to the token list. 2782cdf0e10cSrcweir 2783cdf0e10cSrcweir ScRangeList aRanges; 2784cdf0e10cSrcweir m_pRangeIndices.reset(new vector<sal_uInt32>()); 2785cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itrBeg = m_pTokens->begin(), itrEnd = m_pTokens->end(); 2786cdf0e10cSrcweir for (vector<ScSharedTokenRef>::const_iterator itr = itrBeg ;itr != itrEnd; ++itr) 2787cdf0e10cSrcweir { 2788cdf0e10cSrcweir if (!ScRefTokenHelper::isExternalRef(*itr)) 2789cdf0e10cSrcweir { 2790cdf0e10cSrcweir ScRange aRange; 2791cdf0e10cSrcweir ScRefTokenHelper::getRangeFromToken(aRange, *itr); 2792cdf0e10cSrcweir aRanges.Append(aRange); 2793cdf0e10cSrcweir sal_uInt32 nPos = distance(itrBeg, itr); 2794cdf0e10cSrcweir m_pRangeIndices->push_back(nPos); 2795cdf0e10cSrcweir } 2796cdf0e10cSrcweir } 2797cdf0e10cSrcweir 2798cdf0e10cSrcweir DBG_ASSERT(m_pRangeIndices->size() == static_cast<size_t>(aRanges.Count()), 2799cdf0e10cSrcweir "range list and range index list have different sizes."); 2800cdf0e10cSrcweir 2801cdf0e10cSrcweir auto_ptr<ScRangeList> pUndoRanges; 2802cdf0e10cSrcweir if ( m_pDocument->HasUnoRefUndo() ) 2803cdf0e10cSrcweir pUndoRanges.reset(new ScRangeList(aRanges)); 2804cdf0e10cSrcweir 2805cdf0e10cSrcweir const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; 2806cdf0e10cSrcweir bool bChanged = aRanges.UpdateReference( 2807cdf0e10cSrcweir rRef.GetMode(), m_pDocument, rRef.GetRange(), rRef.GetDx(), rRef.GetDy(), rRef.GetDz()); 2808cdf0e10cSrcweir 2809cdf0e10cSrcweir if (bChanged) 2810cdf0e10cSrcweir { 2811cdf0e10cSrcweir DBG_ASSERT(m_pRangeIndices->size() == static_cast<size_t>(aRanges.Count()), 2812cdf0e10cSrcweir "range list and range index list have different sizes after the reference update."); 2813cdf0e10cSrcweir 2814cdf0e10cSrcweir // Bring the change back from the range list to the token list. 2815cdf0e10cSrcweir UpdateTokensFromRanges(aRanges); 2816cdf0e10cSrcweir 2817cdf0e10cSrcweir if (pUndoRanges.get()) 2818cdf0e10cSrcweir m_pDocument->AddUnoRefChange(m_nObjectId, *pUndoRanges); 2819cdf0e10cSrcweir } 2820cdf0e10cSrcweir } 2821cdf0e10cSrcweir else if ( rHint.ISA( ScUnoRefUndoHint ) ) 2822cdf0e10cSrcweir { 2823cdf0e10cSrcweir const ScUnoRefUndoHint& rUndoHint = static_cast<const ScUnoRefUndoHint&>(rHint); 2824cdf0e10cSrcweir 2825cdf0e10cSrcweir do 2826cdf0e10cSrcweir { 2827cdf0e10cSrcweir if (rUndoHint.GetObjectId() != m_nObjectId) 2828cdf0e10cSrcweir break; 2829cdf0e10cSrcweir 2830cdf0e10cSrcweir // The hint object provides the old ranges. Restore the old state 2831cdf0e10cSrcweir // from these ranges. 2832cdf0e10cSrcweir 2833cdf0e10cSrcweir if (!m_pRangeIndices.get() || m_pRangeIndices->empty()) 2834cdf0e10cSrcweir { 2835cdf0e10cSrcweir DBG_ERROR(" faulty range indices"); 2836cdf0e10cSrcweir break; 2837cdf0e10cSrcweir } 2838cdf0e10cSrcweir 2839cdf0e10cSrcweir const ScRangeList& rRanges = rUndoHint.GetRanges(); 2840cdf0e10cSrcweir 2841cdf0e10cSrcweir sal_uInt32 nCount = rRanges.Count(); 2842cdf0e10cSrcweir if (nCount != m_pRangeIndices->size()) 2843cdf0e10cSrcweir { 2844cdf0e10cSrcweir DBG_ERROR("range count and range index count differ."); 2845cdf0e10cSrcweir break; 2846cdf0e10cSrcweir } 2847cdf0e10cSrcweir 2848cdf0e10cSrcweir UpdateTokensFromRanges(rRanges); 2849cdf0e10cSrcweir } 2850cdf0e10cSrcweir while (false); 2851cdf0e10cSrcweir } 2852cdf0e10cSrcweir } 2853cdf0e10cSrcweir 2854cdf0e10cSrcweir 2855cdf0e10cSrcweir IMPL_LINK( ScChart2DataSequence, ValueListenerHdl, SfxHint*, pHint ) 2856cdf0e10cSrcweir { 2857cdf0e10cSrcweir if ( m_pDocument && pHint && pHint->ISA( SfxSimpleHint ) && 2858cdf0e10cSrcweir ((const SfxSimpleHint*)pHint)->GetId() & (SC_HINT_DATACHANGED | SC_HINT_DYING) ) 2859cdf0e10cSrcweir { 2860cdf0e10cSrcweir // This may be called several times for a single change, if several formulas 2861cdf0e10cSrcweir // in the range are notified. So only a flag is set that is checked when 2862cdf0e10cSrcweir // SFX_HINT_DATACHANGED is received. 2863cdf0e10cSrcweir 2864cdf0e10cSrcweir setDataChangedHint(true); 2865cdf0e10cSrcweir } 2866cdf0e10cSrcweir return 0; 2867cdf0e10cSrcweir } 2868cdf0e10cSrcweir 2869cdf0e10cSrcweir // ---------------------------------------------------------------------------- 2870cdf0e10cSrcweir 2871cdf0e10cSrcweir ScChart2DataSequence::ExternalRefListener::ExternalRefListener( 2872cdf0e10cSrcweir ScChart2DataSequence& rParent, ScDocument* pDoc) : 2873cdf0e10cSrcweir ScExternalRefManager::LinkListener(), 2874cdf0e10cSrcweir mrParent(rParent), 2875cdf0e10cSrcweir mpDoc(pDoc) 2876cdf0e10cSrcweir { 2877cdf0e10cSrcweir } 2878cdf0e10cSrcweir 2879cdf0e10cSrcweir ScChart2DataSequence::ExternalRefListener::~ExternalRefListener() 2880cdf0e10cSrcweir { 2881cdf0e10cSrcweir if (!mpDoc || mpDoc->IsInDtorClear()) 2882cdf0e10cSrcweir // The document is being destroyed. Do nothing. 2883cdf0e10cSrcweir return; 2884cdf0e10cSrcweir 2885cdf0e10cSrcweir // Make sure to remove all pointers to this object. 2886cdf0e10cSrcweir mpDoc->GetExternalRefManager()->removeLinkListener(this); 2887cdf0e10cSrcweir } 2888cdf0e10cSrcweir 2889cdf0e10cSrcweir void ScChart2DataSequence::ExternalRefListener::notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) 2890cdf0e10cSrcweir { 2891cdf0e10cSrcweir switch (eType) 2892cdf0e10cSrcweir { 2893cdf0e10cSrcweir case ScExternalRefManager::LINK_MODIFIED: 2894cdf0e10cSrcweir { 2895cdf0e10cSrcweir if (maFileIds.count(nFileId)) 2896cdf0e10cSrcweir // We are listening to this external document. 2897cdf0e10cSrcweir mrParent.RebuildDataCache(); 2898cdf0e10cSrcweir } 2899cdf0e10cSrcweir break; 2900cdf0e10cSrcweir case ScExternalRefManager::LINK_BROKEN: 2901cdf0e10cSrcweir removeFileId(nFileId); 2902cdf0e10cSrcweir break; 2903cdf0e10cSrcweir } 2904cdf0e10cSrcweir } 2905cdf0e10cSrcweir 2906cdf0e10cSrcweir void ScChart2DataSequence::ExternalRefListener::addFileId(sal_uInt16 nFileId) 2907cdf0e10cSrcweir { 2908cdf0e10cSrcweir maFileIds.insert(nFileId); 2909cdf0e10cSrcweir } 2910cdf0e10cSrcweir 2911cdf0e10cSrcweir void ScChart2DataSequence::ExternalRefListener::removeFileId(sal_uInt16 nFileId) 2912cdf0e10cSrcweir { 2913cdf0e10cSrcweir maFileIds.erase(nFileId); 2914cdf0e10cSrcweir } 2915cdf0e10cSrcweir 2916cdf0e10cSrcweir const hash_set<sal_uInt16>& ScChart2DataSequence::ExternalRefListener::getAllFileIds() 2917cdf0e10cSrcweir { 2918cdf0e10cSrcweir return maFileIds; 2919cdf0e10cSrcweir } 2920cdf0e10cSrcweir 2921cdf0e10cSrcweir // ---------------------------------------------------------------------------- 2922cdf0e10cSrcweir 2923cdf0e10cSrcweir uno::Sequence< uno::Any> SAL_CALL ScChart2DataSequence::getData() 2924cdf0e10cSrcweir throw ( uno::RuntimeException) 2925cdf0e10cSrcweir { 2926cdf0e10cSrcweir ScUnoGuard aGuard; 2927cdf0e10cSrcweir if ( !m_pDocument) 2928cdf0e10cSrcweir throw uno::RuntimeException(); 2929cdf0e10cSrcweir 2930cdf0e10cSrcweir BuildDataCache(); 2931cdf0e10cSrcweir 2932cdf0e10cSrcweir if (!m_aMixedDataCache.getLength()) 2933cdf0e10cSrcweir { 2934cdf0e10cSrcweir // Build a cache for the 1st time... 2935cdf0e10cSrcweir 2936cdf0e10cSrcweir sal_Int32 nCount = m_aDataArray.size(); 2937cdf0e10cSrcweir m_aMixedDataCache.realloc(nCount); 2938cdf0e10cSrcweir uno::Any* pArr = m_aMixedDataCache.getArray(); 2939cdf0e10cSrcweir ::std::list<Item>::const_iterator itr = m_aDataArray.begin(), itrEnd = m_aDataArray.end(); 2940cdf0e10cSrcweir for (; itr != itrEnd; ++itr, ++pArr) 2941cdf0e10cSrcweir { 2942cdf0e10cSrcweir if (itr->mbIsValue) 2943cdf0e10cSrcweir *pArr <<= itr->mfValue; 2944cdf0e10cSrcweir else 2945cdf0e10cSrcweir *pArr <<= itr->maString; 2946cdf0e10cSrcweir } 2947cdf0e10cSrcweir } 2948cdf0e10cSrcweir return m_aMixedDataCache; 2949cdf0e10cSrcweir } 2950cdf0e10cSrcweir 2951cdf0e10cSrcweir // XNumericalDataSequence -------------------------------------------------- 2952cdf0e10cSrcweir 2953cdf0e10cSrcweir uno::Sequence< double > SAL_CALL ScChart2DataSequence::getNumericalData() 2954cdf0e10cSrcweir throw ( uno::RuntimeException) 2955cdf0e10cSrcweir { 2956cdf0e10cSrcweir ScUnoGuard aGuard; 2957cdf0e10cSrcweir if ( !m_pDocument) 2958cdf0e10cSrcweir throw uno::RuntimeException(); 2959cdf0e10cSrcweir 2960cdf0e10cSrcweir BuildDataCache(); 2961cdf0e10cSrcweir 2962cdf0e10cSrcweir double fNAN; 2963cdf0e10cSrcweir ::rtl::math::setNan(&fNAN); 2964cdf0e10cSrcweir 2965cdf0e10cSrcweir sal_Int32 nCount = m_aDataArray.size(); 2966cdf0e10cSrcweir uno::Sequence<double> aSeq(nCount); 2967cdf0e10cSrcweir double* pArr = aSeq.getArray(); 2968cdf0e10cSrcweir ::std::list<Item>::const_iterator itr = m_aDataArray.begin(), itrEnd = m_aDataArray.end(); 2969cdf0e10cSrcweir for (; itr != itrEnd; ++itr, ++pArr) 2970cdf0e10cSrcweir *pArr = itr->mbIsValue ? itr->mfValue : fNAN; 2971cdf0e10cSrcweir 2972cdf0e10cSrcweir return aSeq; 2973cdf0e10cSrcweir } 2974cdf0e10cSrcweir 2975cdf0e10cSrcweir // XTextualDataSequence -------------------------------------------------- 2976cdf0e10cSrcweir 2977cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL ScChart2DataSequence::getTextualData( ) throw (uno::RuntimeException) 2978cdf0e10cSrcweir { 2979cdf0e10cSrcweir ScUnoGuard aGuard; 2980cdf0e10cSrcweir if ( !m_pDocument) 2981cdf0e10cSrcweir throw uno::RuntimeException(); 2982cdf0e10cSrcweir 2983cdf0e10cSrcweir BuildDataCache(); 2984cdf0e10cSrcweir 2985cdf0e10cSrcweir sal_Int32 nCount = m_aDataArray.size(); 2986cdf0e10cSrcweir uno::Sequence<rtl::OUString> aSeq(nCount); 2987cdf0e10cSrcweir rtl::OUString* pArr = aSeq.getArray(); 2988cdf0e10cSrcweir ::std::list<Item>::const_iterator itr = m_aDataArray.begin(), itrEnd = m_aDataArray.end(); 2989cdf0e10cSrcweir for (; itr != itrEnd; ++itr, ++pArr) 2990cdf0e10cSrcweir *pArr = itr->maString; 2991cdf0e10cSrcweir 2992cdf0e10cSrcweir return aSeq; 2993cdf0e10cSrcweir } 2994cdf0e10cSrcweir 2995cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScChart2DataSequence::getSourceRangeRepresentation() 2996cdf0e10cSrcweir throw ( uno::RuntimeException) 2997cdf0e10cSrcweir { 2998cdf0e10cSrcweir ScUnoGuard aGuard; 2999cdf0e10cSrcweir OUString aStr; 3000cdf0e10cSrcweir DBG_ASSERT( m_pDocument, "No Document -> no SourceRangeRepresentation" ); 3001cdf0e10cSrcweir if (m_pDocument && m_pTokens.get()) 3002cdf0e10cSrcweir lcl_convertTokensToString(aStr, *m_pTokens, m_pDocument); 3003cdf0e10cSrcweir 3004cdf0e10cSrcweir return aStr; 3005cdf0e10cSrcweir } 3006cdf0e10cSrcweir 3007cdf0e10cSrcweir namespace { 3008cdf0e10cSrcweir 3009cdf0e10cSrcweir /** 3010cdf0e10cSrcweir * This function object is used to accumulatively count the numbers of 3011cdf0e10cSrcweir * columns and rows in all reference tokens. 3012cdf0e10cSrcweir */ 3013cdf0e10cSrcweir class AccumulateRangeSize : public unary_function<ScSharedTokenRef, void> 3014cdf0e10cSrcweir { 3015cdf0e10cSrcweir public: 3016cdf0e10cSrcweir AccumulateRangeSize() : 3017cdf0e10cSrcweir mnCols(0), mnRows(0) {} 3018cdf0e10cSrcweir 3019cdf0e10cSrcweir AccumulateRangeSize(const AccumulateRangeSize& r) : 3020cdf0e10cSrcweir mnCols(r.mnCols), mnRows(r.mnRows) {} 3021cdf0e10cSrcweir 3022cdf0e10cSrcweir void operator() (const ScSharedTokenRef& pToken) 3023cdf0e10cSrcweir { 3024cdf0e10cSrcweir ScRange r; 3025cdf0e10cSrcweir bool bExternal = ScRefTokenHelper::isExternalRef(pToken); 3026cdf0e10cSrcweir ScRefTokenHelper::getRangeFromToken(r, pToken, bExternal); 3027cdf0e10cSrcweir r.Justify(); 3028cdf0e10cSrcweir mnCols += r.aEnd.Col() - r.aStart.Col() + 1; 3029cdf0e10cSrcweir mnRows += r.aEnd.Row() - r.aStart.Row() + 1; 3030cdf0e10cSrcweir } 3031cdf0e10cSrcweir 3032cdf0e10cSrcweir SCCOL getCols() const { return mnCols; } 3033cdf0e10cSrcweir SCROW getRows() const { return mnRows; } 3034cdf0e10cSrcweir private: 3035cdf0e10cSrcweir SCCOL mnCols; 3036cdf0e10cSrcweir SCROW mnRows; 3037cdf0e10cSrcweir }; 3038cdf0e10cSrcweir 3039cdf0e10cSrcweir /** 3040cdf0e10cSrcweir * This function object is used to generate label strings from a list of 3041cdf0e10cSrcweir * reference tokens. 3042cdf0e10cSrcweir */ 3043cdf0e10cSrcweir class GenerateLabelStrings : public unary_function<ScSharedTokenRef, void> 3044cdf0e10cSrcweir { 3045cdf0e10cSrcweir public: 3046cdf0e10cSrcweir GenerateLabelStrings(sal_Int32 nSize, chart2::data::LabelOrigin eOrigin, bool bColumn) : 3047cdf0e10cSrcweir mpLabels(new Sequence<OUString>(nSize)), 3048cdf0e10cSrcweir meOrigin(eOrigin), 3049cdf0e10cSrcweir mnCount(0), 3050cdf0e10cSrcweir mbColumn(bColumn) {} 3051cdf0e10cSrcweir 3052cdf0e10cSrcweir GenerateLabelStrings(const GenerateLabelStrings& r) : 3053cdf0e10cSrcweir mpLabels(r.mpLabels), 3054cdf0e10cSrcweir meOrigin(r.meOrigin), 3055cdf0e10cSrcweir mnCount(r.mnCount), 3056cdf0e10cSrcweir mbColumn(r.mbColumn) {} 3057cdf0e10cSrcweir 3058cdf0e10cSrcweir void operator() (const ScSharedTokenRef& pToken) 3059cdf0e10cSrcweir { 3060cdf0e10cSrcweir bool bExternal = ScRefTokenHelper::isExternalRef(pToken); 3061cdf0e10cSrcweir ScRange aRange; 3062cdf0e10cSrcweir ScRefTokenHelper::getRangeFromToken(aRange, pToken, bExternal); 3063cdf0e10cSrcweir OUString* pArr = mpLabels->getArray(); 3064cdf0e10cSrcweir if (mbColumn) 3065cdf0e10cSrcweir { 3066cdf0e10cSrcweir for (SCCOL nCol = aRange.aStart.Col(); nCol <= aRange.aEnd.Col(); ++nCol) 3067cdf0e10cSrcweir { 3068cdf0e10cSrcweir if ( meOrigin != chart2::data::LabelOrigin_LONG_SIDE) 3069cdf0e10cSrcweir { 3070cdf0e10cSrcweir String aString = ScGlobal::GetRscString(STR_COLUMN); 3071cdf0e10cSrcweir aString += ' '; 3072cdf0e10cSrcweir ScAddress aPos( nCol, 0, 0 ); 3073cdf0e10cSrcweir String aColStr; 3074cdf0e10cSrcweir aPos.Format( aColStr, SCA_VALID_COL, NULL ); 3075cdf0e10cSrcweir aString += aColStr; 3076cdf0e10cSrcweir pArr[mnCount] = aString; 3077cdf0e10cSrcweir } 3078cdf0e10cSrcweir else //only indices for categories 3079cdf0e10cSrcweir pArr[mnCount] = String::CreateFromInt32( mnCount+1 ); 3080cdf0e10cSrcweir ++mnCount; 3081cdf0e10cSrcweir } 3082cdf0e10cSrcweir } 3083cdf0e10cSrcweir else 3084cdf0e10cSrcweir { 3085cdf0e10cSrcweir for (sal_Int32 nRow = aRange.aStart.Row(); nRow <= aRange.aEnd.Row(); ++nRow) 3086cdf0e10cSrcweir { 3087cdf0e10cSrcweir if (meOrigin != chart2::data::LabelOrigin_LONG_SIDE) 3088cdf0e10cSrcweir { 3089cdf0e10cSrcweir String aString = ScGlobal::GetRscString(STR_ROW); 3090cdf0e10cSrcweir aString += ' '; 3091cdf0e10cSrcweir aString += String::CreateFromInt32( nRow+1 ); 3092cdf0e10cSrcweir pArr[mnCount] = aString; 3093cdf0e10cSrcweir } 3094cdf0e10cSrcweir else //only indices for categories 3095cdf0e10cSrcweir pArr[mnCount] = String::CreateFromInt32( mnCount+1 ); 3096cdf0e10cSrcweir ++mnCount; 3097cdf0e10cSrcweir } 3098cdf0e10cSrcweir } 3099cdf0e10cSrcweir } 3100cdf0e10cSrcweir 3101cdf0e10cSrcweir Sequence<OUString> getLabels() const { return *mpLabels; } 3102cdf0e10cSrcweir 3103cdf0e10cSrcweir private: 3104cdf0e10cSrcweir GenerateLabelStrings(); // disabled 3105cdf0e10cSrcweir 3106cdf0e10cSrcweir shared_ptr< Sequence<OUString> > mpLabels; 3107cdf0e10cSrcweir chart2::data::LabelOrigin meOrigin; 3108cdf0e10cSrcweir sal_Int32 mnCount; 3109cdf0e10cSrcweir bool mbColumn; 3110cdf0e10cSrcweir }; 3111cdf0e10cSrcweir 3112cdf0e10cSrcweir } 3113cdf0e10cSrcweir 3114cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL ScChart2DataSequence::generateLabel(chart2::data::LabelOrigin eOrigin) 3115cdf0e10cSrcweir throw (uno::RuntimeException) 3116cdf0e10cSrcweir { 3117cdf0e10cSrcweir ScUnoGuard aGuard; 3118cdf0e10cSrcweir if ( !m_pDocument) 3119cdf0e10cSrcweir throw uno::RuntimeException(); 3120cdf0e10cSrcweir 3121cdf0e10cSrcweir if (!m_pTokens.get()) 3122cdf0e10cSrcweir return Sequence<OUString>(); 3123cdf0e10cSrcweir 3124cdf0e10cSrcweir // Determine the total size of all ranges. 3125cdf0e10cSrcweir AccumulateRangeSize func; 3126cdf0e10cSrcweir func = for_each(m_pTokens->begin(), m_pTokens->end(), func); 3127cdf0e10cSrcweir SCCOL nCols = func.getCols(); 3128cdf0e10cSrcweir SCROW nRows = func.getRows(); 3129cdf0e10cSrcweir 3130cdf0e10cSrcweir // Detemine whether this is column-major or row-major. 3131cdf0e10cSrcweir bool bColumn = true; 3132cdf0e10cSrcweir if ((eOrigin == chart2::data::LabelOrigin_SHORT_SIDE) || 3133cdf0e10cSrcweir (eOrigin == chart2::data::LabelOrigin_LONG_SIDE)) 3134cdf0e10cSrcweir { 3135cdf0e10cSrcweir if (nRows > nCols) 3136cdf0e10cSrcweir { 3137cdf0e10cSrcweir if (eOrigin == chart2::data::LabelOrigin_SHORT_SIDE) 3138cdf0e10cSrcweir bColumn = true; 3139cdf0e10cSrcweir else 3140cdf0e10cSrcweir bColumn = false; 3141cdf0e10cSrcweir } 3142cdf0e10cSrcweir else if (nCols > nRows) 3143cdf0e10cSrcweir { 3144cdf0e10cSrcweir if (eOrigin == chart2::data::LabelOrigin_SHORT_SIDE) 3145cdf0e10cSrcweir bColumn = false; 3146cdf0e10cSrcweir else 3147cdf0e10cSrcweir bColumn = true; 3148cdf0e10cSrcweir } 3149cdf0e10cSrcweir else 3150cdf0e10cSrcweir return Sequence<OUString>(); 3151cdf0e10cSrcweir } 3152cdf0e10cSrcweir 3153cdf0e10cSrcweir // Generate label strings based on the info so far. 3154cdf0e10cSrcweir sal_Int32 nCount = bColumn ? nCols : nRows; 3155cdf0e10cSrcweir GenerateLabelStrings genLabels(nCount, eOrigin, bColumn); 3156cdf0e10cSrcweir genLabels = for_each(m_pTokens->begin(), m_pTokens->end(), genLabels); 3157cdf0e10cSrcweir Sequence<OUString> aSeq = genLabels.getLabels(); 3158cdf0e10cSrcweir 3159cdf0e10cSrcweir return aSeq; 3160cdf0e10cSrcweir } 3161cdf0e10cSrcweir 3162cdf0e10cSrcweir ::sal_Int32 SAL_CALL ScChart2DataSequence::getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) 3163cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, 3164cdf0e10cSrcweir uno::RuntimeException) 3165cdf0e10cSrcweir { 3166cdf0e10cSrcweir // index -1 means a heuristic value for the entire sequence 3167cdf0e10cSrcweir bool bGetSeriesFormat = (nIndex == -1); 3168cdf0e10cSrcweir sal_Int32 nResult = 0; 3169cdf0e10cSrcweir 3170cdf0e10cSrcweir ScUnoGuard aGuard; 3171cdf0e10cSrcweir if ( !m_pDocument || !m_pTokens.get()) 3172cdf0e10cSrcweir return nResult; 3173cdf0e10cSrcweir 3174cdf0e10cSrcweir sal_Int32 nCount = 0; 3175cdf0e10cSrcweir bool bFound = false; 3176cdf0e10cSrcweir ScRangePtr p; 3177cdf0e10cSrcweir 3178cdf0e10cSrcweir uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( lcl_GetSpreadSheetDocument( m_pDocument )); 3179cdf0e10cSrcweir if (!xSpreadDoc.is()) 3180cdf0e10cSrcweir return nResult; 3181cdf0e10cSrcweir 3182cdf0e10cSrcweir uno::Reference<container::XIndexAccess> xIndex( xSpreadDoc->getSheets(), uno::UNO_QUERY ); 3183cdf0e10cSrcweir if (!xIndex.is()) 3184cdf0e10cSrcweir return nResult; 3185cdf0e10cSrcweir 3186cdf0e10cSrcweir ScRangeList aRanges; 3187cdf0e10cSrcweir ScRefTokenHelper::getRangeListFromTokens(aRanges, *m_pTokens); 3188cdf0e10cSrcweir uno::Reference< table::XCellRange > xSheet; 3189cdf0e10cSrcweir for ( p = aRanges.First(); p && !bFound; p = aRanges.Next()) 3190cdf0e10cSrcweir { 3191cdf0e10cSrcweir // TODO: use DocIter? 3192cdf0e10cSrcweir table::CellAddress aStart, aEnd; 3193cdf0e10cSrcweir ScUnoConversion::FillApiAddress( aStart, p->aStart ); 3194cdf0e10cSrcweir ScUnoConversion::FillApiAddress( aEnd, p->aEnd ); 3195cdf0e10cSrcweir for ( sal_Int16 nSheet = aStart.Sheet; nSheet <= aEnd.Sheet && !bFound; ++nSheet) 3196cdf0e10cSrcweir { 3197cdf0e10cSrcweir xSheet.set(xIndex->getByIndex(nSheet), uno::UNO_QUERY); 3198cdf0e10cSrcweir for ( sal_Int32 nCol = aStart.Column; nCol <= aEnd.Column && !bFound; ++nCol) 3199cdf0e10cSrcweir { 3200cdf0e10cSrcweir for ( sal_Int32 nRow = aStart.Row; nRow <= aEnd.Row && !bFound; ++nRow) 3201cdf0e10cSrcweir { 3202cdf0e10cSrcweir if( bGetSeriesFormat ) 3203cdf0e10cSrcweir { 3204cdf0e10cSrcweir // TODO: use nicer heuristic 3205cdf0e10cSrcweir // return format of first non-empty cell 3206cdf0e10cSrcweir uno::Reference< text::XText > xText( 3207cdf0e10cSrcweir xSheet->getCellByPosition(nCol, nRow), uno::UNO_QUERY); 3208cdf0e10cSrcweir if (xText.is() && xText->getString().getLength()) 3209cdf0e10cSrcweir { 3210cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp(xText, uno::UNO_QUERY); 3211cdf0e10cSrcweir if( xProp.is()) 3212cdf0e10cSrcweir xProp->getPropertyValue( 3213cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat"))) >>= nResult; 3214cdf0e10cSrcweir bFound = true; 3215cdf0e10cSrcweir break; 3216cdf0e10cSrcweir } 3217cdf0e10cSrcweir } 3218cdf0e10cSrcweir else if( nCount == nIndex ) 3219cdf0e10cSrcweir { 3220cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( 3221cdf0e10cSrcweir xSheet->getCellByPosition(nCol, nRow), uno::UNO_QUERY); 3222cdf0e10cSrcweir if( xProp.is()) 3223cdf0e10cSrcweir xProp->getPropertyValue( 3224cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberFormat"))) >>= nResult; 3225cdf0e10cSrcweir bFound = true; 3226cdf0e10cSrcweir break; 3227cdf0e10cSrcweir } 3228cdf0e10cSrcweir ++nCount; 3229cdf0e10cSrcweir } 3230cdf0e10cSrcweir } 3231cdf0e10cSrcweir } 3232cdf0e10cSrcweir } 3233cdf0e10cSrcweir 3234cdf0e10cSrcweir return nResult; 3235cdf0e10cSrcweir } 3236cdf0e10cSrcweir 3237cdf0e10cSrcweir // XCloneable ================================================================ 3238cdf0e10cSrcweir 3239cdf0e10cSrcweir uno::Reference< util::XCloneable > SAL_CALL ScChart2DataSequence::createClone() 3240cdf0e10cSrcweir throw (uno::RuntimeException) 3241cdf0e10cSrcweir { 3242cdf0e10cSrcweir ScUnoGuard aGuard; 3243cdf0e10cSrcweir 3244cdf0e10cSrcweir auto_ptr< vector<ScSharedTokenRef> > pTokensNew; 3245cdf0e10cSrcweir if (m_pTokens.get()) 3246cdf0e10cSrcweir { 3247cdf0e10cSrcweir // Clone tokens. 3248cdf0e10cSrcweir pTokensNew.reset(new vector<ScSharedTokenRef>); 3249cdf0e10cSrcweir pTokensNew->reserve(m_pTokens->size()); 3250cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = m_pTokens->begin(), itrEnd = m_pTokens->end(); 3251cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 3252cdf0e10cSrcweir { 3253cdf0e10cSrcweir ScSharedTokenRef p(static_cast<ScToken*>((*itr)->Clone())); 3254cdf0e10cSrcweir pTokensNew->push_back(p); 3255cdf0e10cSrcweir } 3256cdf0e10cSrcweir } 3257cdf0e10cSrcweir 3258cdf0e10cSrcweir auto_ptr<ScChart2DataSequence> p(new ScChart2DataSequence(m_pDocument, m_xDataProvider, pTokensNew.release(), m_bIncludeHiddenCells)); 3259cdf0e10cSrcweir p->CopyData(*this); 3260cdf0e10cSrcweir Reference< util::XCloneable > xClone(p.release()); 3261cdf0e10cSrcweir 3262cdf0e10cSrcweir return xClone; 3263cdf0e10cSrcweir } 3264cdf0e10cSrcweir 3265cdf0e10cSrcweir // XModifyBroadcaster ======================================================== 3266cdf0e10cSrcweir 3267cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) 3268cdf0e10cSrcweir throw (uno::RuntimeException) 3269cdf0e10cSrcweir { 3270cdf0e10cSrcweir // like ScCellRangesBase::addModifyListener 3271cdf0e10cSrcweir ScUnoGuard aGuard; 3272cdf0e10cSrcweir if (!m_pTokens.get() || m_pTokens->empty()) 3273cdf0e10cSrcweir return; 3274cdf0e10cSrcweir 3275cdf0e10cSrcweir ScRangeList aRanges; 3276cdf0e10cSrcweir ScRefTokenHelper::getRangeListFromTokens(aRanges, *m_pTokens); 3277cdf0e10cSrcweir uno::Reference<util::XModifyListener> *pObj = 3278cdf0e10cSrcweir new uno::Reference<util::XModifyListener>( aListener ); 3279cdf0e10cSrcweir m_aValueListeners.Insert( pObj, m_aValueListeners.Count() ); 3280cdf0e10cSrcweir 3281cdf0e10cSrcweir if ( m_aValueListeners.Count() == 1 ) 3282cdf0e10cSrcweir { 3283cdf0e10cSrcweir if (!m_pValueListener) 3284cdf0e10cSrcweir m_pValueListener = new ScLinkListener( LINK( this, ScChart2DataSequence, ValueListenerHdl ) ); 3285cdf0e10cSrcweir 3286cdf0e10cSrcweir if (!m_pHiddenListener.get()) 3287cdf0e10cSrcweir m_pHiddenListener.reset(new HiddenRangeListener(*this)); 3288cdf0e10cSrcweir 3289cdf0e10cSrcweir if( m_pDocument ) 3290cdf0e10cSrcweir { 3291cdf0e10cSrcweir ScChartListenerCollection* pCLC = m_pDocument->GetChartListenerCollection(); 3292cdf0e10cSrcweir vector<ScSharedTokenRef>::const_iterator itr = m_pTokens->begin(), itrEnd = m_pTokens->end(); 3293cdf0e10cSrcweir for (; itr != itrEnd; ++itr) 3294cdf0e10cSrcweir { 3295cdf0e10cSrcweir ScRange aRange; 3296cdf0e10cSrcweir if (!ScRefTokenHelper::getRangeFromToken(aRange, *itr)) 3297cdf0e10cSrcweir continue; 3298cdf0e10cSrcweir 3299cdf0e10cSrcweir m_pDocument->StartListeningArea( aRange, m_pValueListener ); 3300cdf0e10cSrcweir if (pCLC) 3301cdf0e10cSrcweir pCLC->StartListeningHiddenRange(aRange, m_pHiddenListener.get()); 3302cdf0e10cSrcweir } 3303cdf0e10cSrcweir } 3304cdf0e10cSrcweir 3305cdf0e10cSrcweir acquire(); // don't lose this object (one ref for all listeners) 3306cdf0e10cSrcweir } 3307cdf0e10cSrcweir } 3308cdf0e10cSrcweir 3309cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener ) 3310cdf0e10cSrcweir throw (uno::RuntimeException) 3311cdf0e10cSrcweir { 3312cdf0e10cSrcweir // like ScCellRangesBase::removeModifyListener 3313cdf0e10cSrcweir 3314cdf0e10cSrcweir ScUnoGuard aGuard; 3315cdf0e10cSrcweir if (!m_pTokens.get() || m_pTokens->empty()) 3316cdf0e10cSrcweir return; 3317cdf0e10cSrcweir 3318cdf0e10cSrcweir acquire(); // in case the listeners have the last ref - released below 3319cdf0e10cSrcweir 3320cdf0e10cSrcweir sal_uInt16 nCount = m_aValueListeners.Count(); 3321cdf0e10cSrcweir for ( sal_uInt16 n=nCount; n--; ) 3322cdf0e10cSrcweir { 3323cdf0e10cSrcweir uno::Reference<util::XModifyListener> *pObj = m_aValueListeners[n]; 3324cdf0e10cSrcweir if ( *pObj == aListener ) 3325cdf0e10cSrcweir { 3326cdf0e10cSrcweir m_aValueListeners.DeleteAndDestroy( n ); 3327cdf0e10cSrcweir 3328cdf0e10cSrcweir if ( m_aValueListeners.Count() == 0 ) 3329cdf0e10cSrcweir { 3330cdf0e10cSrcweir if (m_pValueListener) 3331cdf0e10cSrcweir m_pValueListener->EndListeningAll(); 3332cdf0e10cSrcweir 3333cdf0e10cSrcweir if (m_pHiddenListener.get() && m_pDocument) 3334cdf0e10cSrcweir { 3335cdf0e10cSrcweir ScChartListenerCollection* pCLC = m_pDocument->GetChartListenerCollection(); 3336cdf0e10cSrcweir if (pCLC) 3337cdf0e10cSrcweir pCLC->EndListeningHiddenRange(m_pHiddenListener.get()); 3338cdf0e10cSrcweir } 3339cdf0e10cSrcweir 3340cdf0e10cSrcweir release(); // release the ref for the listeners 3341cdf0e10cSrcweir } 3342cdf0e10cSrcweir 3343cdf0e10cSrcweir break; 3344cdf0e10cSrcweir } 3345cdf0e10cSrcweir } 3346cdf0e10cSrcweir 3347cdf0e10cSrcweir release(); // might delete this object 3348cdf0e10cSrcweir } 3349cdf0e10cSrcweir 3350cdf0e10cSrcweir // DataSequence XPropertySet ------------------------------------------------- 3351cdf0e10cSrcweir 3352cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo> SAL_CALL 3353cdf0e10cSrcweir ScChart2DataSequence::getPropertySetInfo() throw( uno::RuntimeException) 3354cdf0e10cSrcweir { 3355cdf0e10cSrcweir ScUnoGuard aGuard; 3356cdf0e10cSrcweir static uno::Reference<beans::XPropertySetInfo> aRef = 3357cdf0e10cSrcweir new SfxItemPropertySetInfo( m_aPropSet.getPropertyMap() ); 3358cdf0e10cSrcweir return aRef; 3359cdf0e10cSrcweir } 3360cdf0e10cSrcweir 3361cdf0e10cSrcweir 3362cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::setPropertyValue( 3363cdf0e10cSrcweir const ::rtl::OUString& rPropertyName, const uno::Any& rValue) 3364cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3365cdf0e10cSrcweir beans::PropertyVetoException, 3366cdf0e10cSrcweir lang::IllegalArgumentException, 3367cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3368cdf0e10cSrcweir { 3369cdf0e10cSrcweir if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_ROLE))) 3370cdf0e10cSrcweir { 3371cdf0e10cSrcweir if ( !(rValue >>= m_aRole)) 3372cdf0e10cSrcweir throw lang::IllegalArgumentException(); 3373cdf0e10cSrcweir } 3374cdf0e10cSrcweir else if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS))) 3375cdf0e10cSrcweir { 3376cdf0e10cSrcweir sal_Bool bOldValue = m_bIncludeHiddenCells; 3377cdf0e10cSrcweir if ( !(rValue >>= m_bIncludeHiddenCells)) 3378cdf0e10cSrcweir throw lang::IllegalArgumentException(); 3379cdf0e10cSrcweir if( bOldValue != m_bIncludeHiddenCells ) 3380cdf0e10cSrcweir m_aDataArray.clear();//data array is dirty now 3381cdf0e10cSrcweir } 3382cdf0e10cSrcweir else 3383cdf0e10cSrcweir throw beans::UnknownPropertyException(); 3384cdf0e10cSrcweir // TODO: support optional properties 3385cdf0e10cSrcweir } 3386cdf0e10cSrcweir 3387cdf0e10cSrcweir 3388cdf0e10cSrcweir uno::Any SAL_CALL ScChart2DataSequence::getPropertyValue( 3389cdf0e10cSrcweir const ::rtl::OUString& rPropertyName) 3390cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3391cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3392cdf0e10cSrcweir { 3393cdf0e10cSrcweir uno::Any aRet; 3394cdf0e10cSrcweir if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_ROLE))) 3395cdf0e10cSrcweir aRet <<= m_aRole; 3396cdf0e10cSrcweir else if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS))) 3397cdf0e10cSrcweir aRet <<= m_bIncludeHiddenCells; 3398cdf0e10cSrcweir else if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SC_UNONAME_HIDDENVALUES))) 3399cdf0e10cSrcweir { 3400cdf0e10cSrcweir // This property is read-only thus cannot be set externally via 3401cdf0e10cSrcweir // setPropertyValue(...). 3402cdf0e10cSrcweir BuildDataCache(); 3403cdf0e10cSrcweir aRet <<= m_aHiddenValues; 3404cdf0e10cSrcweir } 3405cdf0e10cSrcweir else 3406cdf0e10cSrcweir throw beans::UnknownPropertyException(); 3407cdf0e10cSrcweir // TODO: support optional properties 3408cdf0e10cSrcweir return aRet; 3409cdf0e10cSrcweir } 3410cdf0e10cSrcweir 3411cdf0e10cSrcweir 3412cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::addPropertyChangeListener( 3413cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3414cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/) 3415cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3416cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3417cdf0e10cSrcweir { 3418cdf0e10cSrcweir // FIXME: real implementation 3419cdf0e10cSrcweir // throw uno::RuntimeException(); 3420cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3421cdf0e10cSrcweir } 3422cdf0e10cSrcweir 3423cdf0e10cSrcweir 3424cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::removePropertyChangeListener( 3425cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3426cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/) 3427cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3428cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3429cdf0e10cSrcweir { 3430cdf0e10cSrcweir // FIXME: real implementation 3431cdf0e10cSrcweir // throw uno::RuntimeException(); 3432cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3433cdf0e10cSrcweir } 3434cdf0e10cSrcweir 3435cdf0e10cSrcweir 3436cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::addVetoableChangeListener( 3437cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3438cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/) 3439cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3440cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3441cdf0e10cSrcweir { 3442cdf0e10cSrcweir // FIXME: real implementation 3443cdf0e10cSrcweir // throw uno::RuntimeException(); 3444cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3445cdf0e10cSrcweir } 3446cdf0e10cSrcweir 3447cdf0e10cSrcweir 3448cdf0e10cSrcweir void SAL_CALL ScChart2DataSequence::removeVetoableChangeListener( 3449cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3450cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/) 3451cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3452cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3453cdf0e10cSrcweir { 3454cdf0e10cSrcweir // FIXME: real implementation 3455cdf0e10cSrcweir // throw uno::RuntimeException(); 3456cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3457cdf0e10cSrcweir } 3458cdf0e10cSrcweir 3459cdf0e10cSrcweir void ScChart2DataSequence::setDataChangedHint(bool b) 3460cdf0e10cSrcweir { 3461cdf0e10cSrcweir m_bGotDataChangedHint = b; 3462cdf0e10cSrcweir } 3463cdf0e10cSrcweir 3464cdf0e10cSrcweir // XUnoTunnel 3465cdf0e10cSrcweir 3466cdf0e10cSrcweir // sal_Int64 SAL_CALL ScChart2DataSequence::getSomething( 3467cdf0e10cSrcweir // const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 3468cdf0e10cSrcweir // { 3469cdf0e10cSrcweir // if ( rId.getLength() == 16 && 3470cdf0e10cSrcweir // 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 3471cdf0e10cSrcweir // rId.getConstArray(), 16 ) ) 3472cdf0e10cSrcweir // { 3473cdf0e10cSrcweir // return (sal_Int64)this; 3474cdf0e10cSrcweir // } 3475cdf0e10cSrcweir // return 0; 3476cdf0e10cSrcweir // } 3477cdf0e10cSrcweir 3478cdf0e10cSrcweir // // static 3479cdf0e10cSrcweir // const uno::Sequence<sal_Int8>& ScChart2DataSequence::getUnoTunnelId() 3480cdf0e10cSrcweir // { 3481cdf0e10cSrcweir // static uno::Sequence<sal_Int8> * pSeq = 0; 3482cdf0e10cSrcweir // if( !pSeq ) 3483cdf0e10cSrcweir // { 3484cdf0e10cSrcweir // osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 3485cdf0e10cSrcweir // if( !pSeq ) 3486cdf0e10cSrcweir // { 3487cdf0e10cSrcweir // static uno::Sequence< sal_Int8 > aSeq( 16 ); 3488cdf0e10cSrcweir // rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 3489cdf0e10cSrcweir // pSeq = &aSeq; 3490cdf0e10cSrcweir // } 3491cdf0e10cSrcweir // } 3492cdf0e10cSrcweir // return *pSeq; 3493cdf0e10cSrcweir // } 3494cdf0e10cSrcweir 3495cdf0e10cSrcweir // // static 3496cdf0e10cSrcweir // ScChart2DataSequence* ScChart2DataSequence::getImplementation( const uno::Reference<uno::XInterface> xObj ) 3497cdf0e10cSrcweir // { 3498cdf0e10cSrcweir // ScChart2DataSequence* pRet = NULL; 3499cdf0e10cSrcweir // uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 3500cdf0e10cSrcweir // if (xUT.is()) 3501cdf0e10cSrcweir // pRet = (ScChart2DataSequence*) xUT->getSomething( getUnoTunnelId() ); 3502cdf0e10cSrcweir // return pRet; 3503cdf0e10cSrcweir // } 3504cdf0e10cSrcweir 3505cdf0e10cSrcweir #if USE_CHART2_EMPTYDATASEQUENCE 3506cdf0e10cSrcweir // DataSequence ============================================================== 3507cdf0e10cSrcweir 3508cdf0e10cSrcweir ScChart2EmptyDataSequence::ScChart2EmptyDataSequence( ScDocument* pDoc, 3509cdf0e10cSrcweir const uno::Reference < chart2::data::XDataProvider >& xDP, 3510cdf0e10cSrcweir const ScRangeListRef& rRangeList, 3511cdf0e10cSrcweir sal_Bool bColumn) 3512cdf0e10cSrcweir : m_bIncludeHiddenCells( sal_True) 3513cdf0e10cSrcweir , m_xRanges( rRangeList) 3514cdf0e10cSrcweir , m_pDocument( pDoc) 3515cdf0e10cSrcweir , m_xDataProvider( xDP) 3516cdf0e10cSrcweir , m_aPropSet(lcl_GetDataSequencePropertyMap()) 3517cdf0e10cSrcweir , m_bColumn(bColumn) 3518cdf0e10cSrcweir { 3519cdf0e10cSrcweir if ( m_pDocument ) 3520cdf0e10cSrcweir m_pDocument->AddUnoObject( *this); 3521cdf0e10cSrcweir // FIXME: real implementation of identifier and it's mapping to ranges. 3522cdf0e10cSrcweir // Reuse ScChartListener? 3523cdf0e10cSrcweir 3524cdf0e10cSrcweir // BM: don't use names of named ranges but the UI range strings 3525cdf0e10cSrcweir // String aStr; 3526cdf0e10cSrcweir // rRangeList->Format( aStr, SCR_ABS_3D, m_pDocument ); 3527cdf0e10cSrcweir // m_aIdentifier = ::rtl::OUString( aStr ); 3528cdf0e10cSrcweir 3529cdf0e10cSrcweir // m_aIdentifier = ::rtl::OUString::createFromAscii( "ID_"); 3530cdf0e10cSrcweir // static sal_Int32 nID = 0; 3531cdf0e10cSrcweir // m_aIdentifier += ::rtl::OUString::valueOf( ++nID); 3532cdf0e10cSrcweir } 3533cdf0e10cSrcweir 3534cdf0e10cSrcweir 3535cdf0e10cSrcweir ScChart2EmptyDataSequence::~ScChart2EmptyDataSequence() 3536cdf0e10cSrcweir { 3537cdf0e10cSrcweir if ( m_pDocument ) 3538cdf0e10cSrcweir m_pDocument->RemoveUnoObject( *this); 3539cdf0e10cSrcweir } 3540cdf0e10cSrcweir 3541cdf0e10cSrcweir 3542cdf0e10cSrcweir void ScChart2EmptyDataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint) 3543cdf0e10cSrcweir { 3544cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && 3545cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 3546cdf0e10cSrcweir { 3547cdf0e10cSrcweir m_pDocument = NULL; 3548cdf0e10cSrcweir } 3549cdf0e10cSrcweir } 3550cdf0e10cSrcweir 3551cdf0e10cSrcweir 3552cdf0e10cSrcweir uno::Sequence< uno::Any> SAL_CALL ScChart2EmptyDataSequence::getData() 3553cdf0e10cSrcweir throw ( uno::RuntimeException) 3554cdf0e10cSrcweir { 3555cdf0e10cSrcweir ScUnoGuard aGuard; 3556cdf0e10cSrcweir if ( !m_pDocument) 3557cdf0e10cSrcweir throw uno::RuntimeException(); 3558cdf0e10cSrcweir return uno::Sequence< uno::Any>(); 3559cdf0e10cSrcweir } 3560cdf0e10cSrcweir 3561cdf0e10cSrcweir // XTextualDataSequence -------------------------------------------------- 3562cdf0e10cSrcweir 3563cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL ScChart2EmptyDataSequence::getTextualData( ) throw (uno::RuntimeException) 3564cdf0e10cSrcweir { 3565cdf0e10cSrcweir ScUnoGuard aGuard; 3566cdf0e10cSrcweir if ( !m_pDocument) 3567cdf0e10cSrcweir throw uno::RuntimeException(); 3568cdf0e10cSrcweir 3569cdf0e10cSrcweir sal_Int32 nCount = 0; 3570cdf0e10cSrcweir ScRangePtr p; 3571cdf0e10cSrcweir 3572cdf0e10cSrcweir DBG_ASSERT(m_xRanges->Count() == 1, "not handled count of ranges"); 3573cdf0e10cSrcweir 3574cdf0e10cSrcweir for ( p = m_xRanges->First(); p; p = m_xRanges->Next()) 3575cdf0e10cSrcweir { 3576cdf0e10cSrcweir p->Justify(); 3577cdf0e10cSrcweir // TODO: handle overlaping ranges? 3578cdf0e10cSrcweir nCount += m_bColumn ? p->aEnd.Col() - p->aStart.Col() + 1 : p->aEnd.Row() - p->aStart.Row() + 1; 3579cdf0e10cSrcweir } 3580cdf0e10cSrcweir uno::Sequence< rtl::OUString > aSeq( nCount); 3581cdf0e10cSrcweir rtl::OUString* pArr = aSeq.getArray(); 3582cdf0e10cSrcweir nCount = 0; 3583cdf0e10cSrcweir for ( p = m_xRanges->First(); p; p = m_xRanges->Next()) 3584cdf0e10cSrcweir { 3585cdf0e10cSrcweir if (m_bColumn) 3586cdf0e10cSrcweir { 3587cdf0e10cSrcweir for (SCCOL nCol = p->aStart.Col(); nCol <= p->aEnd.Col(); ++nCol) 3588cdf0e10cSrcweir { 3589cdf0e10cSrcweir String aString = ScGlobal::GetRscString(STR_COLUMN); 3590cdf0e10cSrcweir aString += ' '; 3591cdf0e10cSrcweir ScAddress aPos( nCol, 0, 0 ); 3592cdf0e10cSrcweir String aColStr; 3593cdf0e10cSrcweir aPos.Format( aColStr, SCA_VALID_COL, NULL ); 3594cdf0e10cSrcweir aString += aColStr; 3595cdf0e10cSrcweir pArr[nCount] = aString; 3596cdf0e10cSrcweir ++nCount; 3597cdf0e10cSrcweir } 3598cdf0e10cSrcweir } 3599cdf0e10cSrcweir else 3600cdf0e10cSrcweir { 3601cdf0e10cSrcweir for (sal_Int32 nRow = p->aStart.Row(); nRow <= p->aEnd.Row(); ++nRow) 3602cdf0e10cSrcweir { 3603cdf0e10cSrcweir String aString = ScGlobal::GetRscString(STR_ROW); 3604cdf0e10cSrcweir aString += ' '; 3605cdf0e10cSrcweir aString += String::CreateFromInt32( nRow+1 ); 3606cdf0e10cSrcweir pArr[nCount] = aString; 3607cdf0e10cSrcweir ++nCount; 3608cdf0e10cSrcweir } 3609cdf0e10cSrcweir } 3610cdf0e10cSrcweir } 3611cdf0e10cSrcweir return aSeq; 3612cdf0e10cSrcweir } 3613cdf0e10cSrcweir 3614cdf0e10cSrcweir ::rtl::OUString SAL_CALL ScChart2EmptyDataSequence::getSourceRangeRepresentation() 3615cdf0e10cSrcweir throw ( uno::RuntimeException) 3616cdf0e10cSrcweir { 3617cdf0e10cSrcweir ScUnoGuard aGuard; 3618cdf0e10cSrcweir String aStr; 3619cdf0e10cSrcweir DBG_ASSERT( m_pDocument, "No Document -> no SourceRangeRepresentation" ); 3620cdf0e10cSrcweir if( m_pDocument ) 3621cdf0e10cSrcweir m_xRanges->Format( aStr, SCR_ABS_3D, m_pDocument, m_pDocument->GetAddressConvention() ); 3622cdf0e10cSrcweir return aStr; 3623cdf0e10cSrcweir } 3624cdf0e10cSrcweir 3625cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL ScChart2EmptyDataSequence::generateLabel(chart2::data::LabelOrigin /*nOrigin*/) 3626cdf0e10cSrcweir throw (uno::RuntimeException) 3627cdf0e10cSrcweir { 3628cdf0e10cSrcweir ScUnoGuard aGuard; 3629cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet; 3630cdf0e10cSrcweir return aRet; 3631cdf0e10cSrcweir } 3632cdf0e10cSrcweir 3633cdf0e10cSrcweir ::sal_Int32 SAL_CALL ScChart2EmptyDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 /*nIndex*/ ) 3634cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, 3635cdf0e10cSrcweir uno::RuntimeException) 3636cdf0e10cSrcweir { 3637cdf0e10cSrcweir sal_Int32 nResult = 0; 3638cdf0e10cSrcweir 3639cdf0e10cSrcweir ScUnoGuard aGuard; 3640cdf0e10cSrcweir if ( !m_pDocument) 3641cdf0e10cSrcweir return nResult; 3642cdf0e10cSrcweir 3643cdf0e10cSrcweir return nResult; 3644cdf0e10cSrcweir } 3645cdf0e10cSrcweir 3646cdf0e10cSrcweir // XCloneable ================================================================ 3647cdf0e10cSrcweir 3648cdf0e10cSrcweir uno::Reference< util::XCloneable > SAL_CALL ScChart2EmptyDataSequence::createClone() 3649cdf0e10cSrcweir throw (uno::RuntimeException) 3650cdf0e10cSrcweir { 3651cdf0e10cSrcweir ScUnoGuard aGuard; 3652cdf0e10cSrcweir if (m_xDataProvider.is()) 3653cdf0e10cSrcweir { 3654cdf0e10cSrcweir // copy properties 3655cdf0e10cSrcweir uno::Reference < util::XCloneable > xClone(new ScChart2EmptyDataSequence(m_pDocument, m_xDataProvider, new ScRangeList(*m_xRanges), m_bColumn)); 3656cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( xClone, uno::UNO_QUERY ); 3657cdf0e10cSrcweir if( xProp.is()) 3658cdf0e10cSrcweir { 3659cdf0e10cSrcweir xProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ROLE )), 3660cdf0e10cSrcweir uno::makeAny( m_aRole )); 3661cdf0e10cSrcweir xProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS )), 3662cdf0e10cSrcweir uno::makeAny( m_bIncludeHiddenCells )); 3663cdf0e10cSrcweir } 3664cdf0e10cSrcweir return xClone; 3665cdf0e10cSrcweir } 3666cdf0e10cSrcweir return uno::Reference< util::XCloneable >(); 3667cdf0e10cSrcweir } 3668cdf0e10cSrcweir 3669cdf0e10cSrcweir // XModifyBroadcaster ======================================================== 3670cdf0e10cSrcweir 3671cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::addModifyListener( const uno::Reference< util::XModifyListener >& /*aListener*/ ) 3672cdf0e10cSrcweir throw (uno::RuntimeException) 3673cdf0e10cSrcweir { 3674cdf0e10cSrcweir // TODO: Implement 3675cdf0e10cSrcweir } 3676cdf0e10cSrcweir 3677cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::removeModifyListener( const uno::Reference< util::XModifyListener >& /*aListener*/ ) 3678cdf0e10cSrcweir throw (uno::RuntimeException) 3679cdf0e10cSrcweir { 3680cdf0e10cSrcweir // TODO: Implement 3681cdf0e10cSrcweir } 3682cdf0e10cSrcweir 3683cdf0e10cSrcweir // DataSequence XPropertySet ------------------------------------------------- 3684cdf0e10cSrcweir 3685cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo> SAL_CALL 3686cdf0e10cSrcweir ScChart2EmptyDataSequence::getPropertySetInfo() throw( uno::RuntimeException) 3687cdf0e10cSrcweir { 3688cdf0e10cSrcweir ScUnoGuard aGuard; 3689cdf0e10cSrcweir static uno::Reference<beans::XPropertySetInfo> aRef = 3690cdf0e10cSrcweir new SfxItemPropertySetInfo( m_aPropSet.getPropertyMap() ); 3691cdf0e10cSrcweir return aRef; 3692cdf0e10cSrcweir } 3693cdf0e10cSrcweir 3694cdf0e10cSrcweir 3695cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::setPropertyValue( 3696cdf0e10cSrcweir const ::rtl::OUString& rPropertyName, const uno::Any& rValue) 3697cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3698cdf0e10cSrcweir beans::PropertyVetoException, 3699cdf0e10cSrcweir lang::IllegalArgumentException, 3700cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3701cdf0e10cSrcweir { 3702cdf0e10cSrcweir if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_ROLE))) 3703cdf0e10cSrcweir { 3704cdf0e10cSrcweir if ( !(rValue >>= m_aRole)) 3705cdf0e10cSrcweir throw lang::IllegalArgumentException(); 3706cdf0e10cSrcweir } 3707cdf0e10cSrcweir else if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS))) 3708cdf0e10cSrcweir { 3709cdf0e10cSrcweir if ( !(rValue >>= m_bIncludeHiddenCells)) 3710cdf0e10cSrcweir throw lang::IllegalArgumentException(); 3711cdf0e10cSrcweir } 3712cdf0e10cSrcweir else 3713cdf0e10cSrcweir throw beans::UnknownPropertyException(); 3714cdf0e10cSrcweir // TODO: support optional properties 3715cdf0e10cSrcweir } 3716cdf0e10cSrcweir 3717cdf0e10cSrcweir 3718cdf0e10cSrcweir uno::Any SAL_CALL ScChart2EmptyDataSequence::getPropertyValue( 3719cdf0e10cSrcweir const ::rtl::OUString& rPropertyName) 3720cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3721cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3722cdf0e10cSrcweir { 3723cdf0e10cSrcweir uno::Any aRet; 3724cdf0e10cSrcweir if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_ROLE))) 3725cdf0e10cSrcweir aRet <<= m_aRole; 3726cdf0e10cSrcweir else if ( rPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_UNONAME_INCLUDEHIDDENCELLS))) 3727cdf0e10cSrcweir aRet <<= m_bIncludeHiddenCells; 3728cdf0e10cSrcweir else 3729cdf0e10cSrcweir throw beans::UnknownPropertyException(); 3730cdf0e10cSrcweir // TODO: support optional properties 3731cdf0e10cSrcweir return aRet; 3732cdf0e10cSrcweir } 3733cdf0e10cSrcweir 3734cdf0e10cSrcweir 3735cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::addPropertyChangeListener( 3736cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3737cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener>& /*xListener*/) 3738cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3739cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3740cdf0e10cSrcweir { 3741cdf0e10cSrcweir // FIXME: real implementation 3742cdf0e10cSrcweir // throw uno::RuntimeException(); 3743cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3744cdf0e10cSrcweir } 3745cdf0e10cSrcweir 3746cdf0e10cSrcweir 3747cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::removePropertyChangeListener( 3748cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3749cdf0e10cSrcweir const uno::Reference< beans::XPropertyChangeListener>& /*rListener*/) 3750cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3751cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3752cdf0e10cSrcweir { 3753cdf0e10cSrcweir // FIXME: real implementation 3754cdf0e10cSrcweir // throw uno::RuntimeException(); 3755cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3756cdf0e10cSrcweir } 3757cdf0e10cSrcweir 3758cdf0e10cSrcweir 3759cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::addVetoableChangeListener( 3760cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3761cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/) 3762cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3763cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3764cdf0e10cSrcweir { 3765cdf0e10cSrcweir // FIXME: real implementation 3766cdf0e10cSrcweir // throw uno::RuntimeException(); 3767cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3768cdf0e10cSrcweir } 3769cdf0e10cSrcweir 3770cdf0e10cSrcweir 3771cdf0e10cSrcweir void SAL_CALL ScChart2EmptyDataSequence::removeVetoableChangeListener( 3772cdf0e10cSrcweir const ::rtl::OUString& /*rPropertyName*/, 3773cdf0e10cSrcweir const uno::Reference< beans::XVetoableChangeListener>& /*rListener*/ ) 3774cdf0e10cSrcweir throw( beans::UnknownPropertyException, 3775cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException) 3776cdf0e10cSrcweir { 3777cdf0e10cSrcweir // FIXME: real implementation 3778cdf0e10cSrcweir // throw uno::RuntimeException(); 3779cdf0e10cSrcweir OSL_ENSURE( false, "Not yet implemented" ); 3780cdf0e10cSrcweir } 3781cdf0e10cSrcweir 3782cdf0e10cSrcweir // XUnoTunnel 3783cdf0e10cSrcweir 3784cdf0e10cSrcweir // sal_Int64 SAL_CALL ScChart2EmptyDataSequence::getSomething( 3785cdf0e10cSrcweir // const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) 3786cdf0e10cSrcweir // { 3787cdf0e10cSrcweir // if ( rId.getLength() == 16 && 3788cdf0e10cSrcweir // 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), 3789cdf0e10cSrcweir // rId.getConstArray(), 16 ) ) 3790cdf0e10cSrcweir // { 3791cdf0e10cSrcweir // return (sal_Int64)this; 3792cdf0e10cSrcweir // } 3793cdf0e10cSrcweir // return 0; 3794cdf0e10cSrcweir // } 3795cdf0e10cSrcweir 3796cdf0e10cSrcweir // // static 3797cdf0e10cSrcweir // const uno::Sequence<sal_Int8>& ScChart2EmptyDataSequence::getUnoTunnelId() 3798cdf0e10cSrcweir // { 3799cdf0e10cSrcweir // static uno::Sequence<sal_Int8> * pSeq = 0; 3800cdf0e10cSrcweir // if( !pSeq ) 3801cdf0e10cSrcweir // { 3802cdf0e10cSrcweir // osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); 3803cdf0e10cSrcweir // if( !pSeq ) 3804cdf0e10cSrcweir // { 3805cdf0e10cSrcweir // static uno::Sequence< sal_Int8 > aSeq( 16 ); 3806cdf0e10cSrcweir // rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); 3807cdf0e10cSrcweir // pSeq = &aSeq; 3808cdf0e10cSrcweir // } 3809cdf0e10cSrcweir // } 3810cdf0e10cSrcweir // return *pSeq; 3811cdf0e10cSrcweir // } 3812cdf0e10cSrcweir 3813cdf0e10cSrcweir // // static 3814cdf0e10cSrcweir // ScChart2DataSequence* ScChart2EmptyDataSequence::getImplementation( const uno::Reference<uno::XInterface> xObj ) 3815cdf0e10cSrcweir // { 3816cdf0e10cSrcweir // ScChart2DataSequence* pRet = NULL; 3817cdf0e10cSrcweir // uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); 3818cdf0e10cSrcweir // if (xUT.is()) 3819cdf0e10cSrcweir // pRet = (ScChart2EmptyDataSequence*) xUT->getSomething( getUnoTunnelId() ); 3820cdf0e10cSrcweir // return pRet; 3821cdf0e10cSrcweir // } 3822cdf0e10cSrcweir #endif 3823