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