1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _SCH_XMLTABLECONTEXT_HXX_
28 #define _SCH_XMLTABLECONTEXT_HXX_
29 
30 #include <xmloff/xmlictxt.hxx>
31 #include "SchXMLImport.hxx"
32 // #include "SchXMLChartContext.hxx"
33 #include <com/sun/star/uno/Sequence.hxx>
34 
35 #include <com/sun/star/chart/ChartDataRowSource.hpp>
36 
37 #include "transporttypes.hxx"
38 
39 namespace com { namespace sun { namespace star {
40 	namespace frame {
41 		class XModel;
42 	}
43 	namespace xml { namespace sax {
44 		class XAttributeList;
45 	}}
46 	namespace chart {
47 		class XChartDocument;
48 		struct ChartSeriesAddress;
49 }}}}
50 
51 // ========================================
52 
53 class SchXMLTableContext : public SvXMLImportContext
54 {
55 private:
56 	SchXMLImportHelper& mrImportHelper;
57 	SchXMLTable& mrTable;
58 
59     bool mbHasRowPermutation;
60     bool mbHasColumnPermutation;
61     ::com::sun::star::uno::Sequence< sal_Int32 > maRowPermutation;
62     ::com::sun::star::uno::Sequence< sal_Int32 > maColumnPermutation;
63 
64 public:
65 	SchXMLTableContext( SchXMLImportHelper& rImpHelper,
66 						SvXMLImport& rImport,
67 						const rtl::OUString& rLocalName,
68 						SchXMLTable& aTable );
69 	virtual ~SchXMLTableContext();
70 
71 	virtual SvXMLImportContext* CreateChildContext(
72 		sal_uInt16 nPrefix,
73 		const rtl::OUString& rLocalName,
74 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
75 	virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
76 	virtual void EndElement();
77 
78     void setRowPermutation( const ::com::sun::star::uno::Sequence< sal_Int32 > & rPermutation );
79     void setColumnPermutation( const ::com::sun::star::uno::Sequence< sal_Int32 > & rPermutation );
80 };
81 
82 // ----------------------------------------
83 
84 class SchXMLTableHelper
85 {
86 private:
87 	static void GetCellAddress( const rtl::OUString& rStr, sal_Int32& rCol, sal_Int32& rRow );
88 	static sal_Bool GetCellRangeAddress( const rtl::OUString& rStr, SchNumericCellRangeAddress& rResult );
89 	static void PutTableContentIntoSequence(
90 		const SchXMLTable& rTable,
91 		SchNumericCellRangeAddress& rAddress,
92 		sal_Int32 nSeriesIndex,
93 		com::sun::star::uno::Sequence< com::sun::star::uno::Sequence< double > >& aSequence );
94 	static void AdjustMax( const SchNumericCellRangeAddress& rAddr,
95 						   sal_Int32& nRows, sal_Int32& nColumns );
96 
97 public:
98 	static void applyTableToInternalDataProvider( const SchXMLTable& rTable,
99 							com::sun::star::uno::Reference< com::sun::star::chart2::XChartDocument > xChartDoc );
100 
101     /** This function reorders local data to fit the correct data structure.
102         Call it after the data series got their styles set.
103      */
104 	static void switchRangesFromOuterToInternalIfNecessary( const SchXMLTable& rTable,
105                                   const tSchXMLLSequencesPerIndex & rLSequencesPerIndex,
106                                   com::sun::star::uno::Reference< com::sun::star::chart2::XChartDocument > xChartDoc,
107                                   ::com::sun::star::chart::ChartDataRowSource eDataRowSource );
108 };
109 
110 // ========================================
111 
112 // ----------------------------------------
113 // classes for columns
114 // ----------------------------------------
115 
116 /** With this context all column elements are parsed to
117 	determine the index of the column containing
118 	the row descriptions and probably get an estimate
119 	for the altogether number of columns
120  */
121 class SchXMLTableColumnsContext : public SvXMLImportContext
122 {
123 private:
124 	SchXMLImportHelper& mrImportHelper;
125 	SchXMLTable& mrTable;
126 
127 public:
128 	SchXMLTableColumnsContext( SchXMLImportHelper& rImpHelper,
129 							   SvXMLImport& rImport,
130 							   const rtl::OUString& rLocalName,
131 							   SchXMLTable& aTable );
132 	virtual ~SchXMLTableColumnsContext();
133 
134 	virtual SvXMLImportContext* CreateChildContext(
135 		sal_uInt16 nPrefix,
136 		const rtl::OUString& rLocalName,
137 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
138 };
139 
140 // ----------------------------------------
141 
142 class SchXMLTableColumnContext : public SvXMLImportContext
143 {
144 private:
145 	SchXMLImportHelper& mrImportHelper;
146 	SchXMLTable& mrTable;
147 
148 public:
149 	SchXMLTableColumnContext( SchXMLImportHelper& rImpHelper,
150 							  SvXMLImport& rImport,
151 							  const rtl::OUString& rLocalName,
152 							  SchXMLTable& aTable );
153 	virtual ~SchXMLTableColumnContext();
154 	virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
155 };
156 
157 // ----------------------------------------
158 // classes for rows
159 // ----------------------------------------
160 
161 class SchXMLTableRowsContext : public SvXMLImportContext
162 {
163 private:
164 	SchXMLImportHelper& mrImportHelper;
165 	SchXMLTable& mrTable;
166 
167 public:
168 	SchXMLTableRowsContext( SchXMLImportHelper& rImpHelper,
169 							SvXMLImport& rImport,
170 							const rtl::OUString& rLocalName,
171 							SchXMLTable& aTable );
172 	virtual ~SchXMLTableRowsContext();
173 
174 	virtual SvXMLImportContext* CreateChildContext(
175 		sal_uInt16 nPrefix,
176 		const rtl::OUString& rLocalName,
177 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
178 };
179 
180 // ----------------------------------------
181 
182 class SchXMLTableRowContext : public SvXMLImportContext
183 {
184 private:
185 	SchXMLImportHelper& mrImportHelper;
186 	SchXMLTable& mrTable;
187 
188 public:
189 	SchXMLTableRowContext( SchXMLImportHelper& rImpHelper,
190 						   SvXMLImport& rImport,
191 						   const rtl::OUString& rLocalName,
192 						   SchXMLTable& aTable );
193 	virtual ~SchXMLTableRowContext();
194 
195 	virtual SvXMLImportContext* CreateChildContext(
196 		sal_uInt16 nPrefix,
197 		const rtl::OUString& rLocalName,
198 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
199 };
200 
201 // ----------------------------------------
202 // classes for cells and their content
203 // ----------------------------------------
204 
205 class SchXMLTableCellContext : public SvXMLImportContext
206 {
207 private:
208 	SchXMLImportHelper& mrImportHelper;
209 	SchXMLTable& mrTable;
210 	rtl::OUString maCellContent;
211     rtl::OUString maRangeId;
212 	sal_Bool mbReadText;
213 
214 public:
215 	SchXMLTableCellContext( SchXMLImportHelper& rImpHelper,
216 							SvXMLImport& rImport,
217 							const rtl::OUString& rLocalName,
218 							SchXMLTable& aTable );
219 	virtual ~SchXMLTableCellContext();
220 
221 	virtual SvXMLImportContext* CreateChildContext(
222 		sal_uInt16 nPrefix,
223 		const rtl::OUString& rLocalName,
224 		const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList );
225 	virtual void StartElement( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttrList );
226 	virtual void EndElement();
227 };
228 
229 #endif	// _SCH_XMLTABLECONTEXT_HXX_
230