xref: /trunk/main/sc/source/filter/xml/xmlstyli.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_XMLSTYLI_HXX
25 #define SC_XMLSTYLI_HXX
26 
27 #include <rtl/ustring.hxx>
28 #include <vector>
29 #include <xmloff/xmlimp.hxx>
30 #include <xmloff/xmlictxt.hxx>
31 #include <xmloff/maptype.hxx>
32 #include <xmloff/prstylei.hxx>
33 #include <xmloff/xmlimppr.hxx>
34 #include <xmloff/XMLTextMasterPageContext.hxx>
35 #include <xmloff/XMLTextMasterStylesContext.hxx>
36 #include <xmloff/txtstyli.hxx>
37 #include <com/sun/star/sheet/ConditionOperator.hpp>
38 #include "xmlimprt.hxx"
39 
40 class ScSheetSaveData;
41 
42 class ScXMLCellImportPropertyMapper : public SvXMLImportPropertyMapper
43 {
44 protected:
45 
46 public:
47 
48 	ScXMLCellImportPropertyMapper(
49 			const UniReference< XMLPropertySetMapper >& rMapper,
50             SvXMLImport& rImport);
51 	virtual ~ScXMLCellImportPropertyMapper();
52 
53 	/** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */
54 /*	virtual sal_Bool handleSpecialItem(
55 			XMLPropertyState& rProperty,
56 			::std::vector< XMLPropertyState >& rProperties,
57 			const ::rtl::OUString& rValue,
58 			const SvXMLUnitConverter& rUnitConverter,
59 			const SvXMLNamespaceMap& rNamespaceMap ) const;*/
60 
61 	/** this method is called for every item that has the MID_FLAG_NO_ITEM_IMPORT flag set */
62 /*	virtual sal_Bool handleNoItem(
63 			sal_Int32 nIndex,
64 			::std::vector< XMLPropertyState >& rProperties,
65 		   	const ::rtl::OUString& rValue,
66 		   	const SvXMLUnitConverter& rUnitConverter,
67 		   	const SvXMLNamespaceMap& rNamespaceMap ) const;*/
68 
69 	/** This method is called when all attributes have been processed. It may be used to remove items that are incomplete */
70 	virtual void finished(
71 			::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const;
72 };
73 
74 class ScXMLRowImportPropertyMapper : public SvXMLImportPropertyMapper
75 {
76 protected:
77 
78 public:
79 
80 	ScXMLRowImportPropertyMapper(
81 			const UniReference< XMLPropertySetMapper >& rMapper,
82             SvXMLImport& rImport);
83 	virtual ~ScXMLRowImportPropertyMapper();
84 
85 	/** This method is called when all attributes have been processed. It may be used to remove items that are incomplete */
86 	virtual void finished(
87 			::std::vector< XMLPropertyState >& rProperties, sal_Int32 nStartIndex, sal_Int32 nEndIndex ) const;
88 };
89 struct ScXMLMapContent;
90 
91 class XMLTableStyleContext : public XMLPropStyleContext
92 {
93 	::rtl::OUString				sDataStyleName;
94 	rtl::OUString				sPageStyle;
95 	const rtl::OUString			sNumberFormat;
96 	SvXMLStylesContext*			pStyles;
97 	std::vector<ScXMLMapContent>	aMaps;
98 	com::sun::star::uno::Any	aConditionalFormat;
99 	sal_Int32					nNumberFormat;
100     sal_Int32                   nLastSheet;
101 	sal_Bool					bConditionalFormatCreated;
102 	sal_Bool					bParentSet;
103 
GetScImport() const104 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()105 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
106 
107     void SetOperator(
108             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProps,
109             ::com::sun::star::sheet::ConditionOperator eOp ) const;
110 
111     void SetBaseCellAddress(
112             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProps,
113             const ::rtl::OUString& rBaseCell ) const;
114 
115     void SetStyle(
116             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProps,
117             const ::rtl::OUString& rApplyStyle ) const;
118 
119     void SetFormula(
120         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rProps,
121         sal_Int32 nFormulaIdx, const ::rtl::OUString& rFormula,
122         const ::rtl::OUString& rFormulaNmsp, ::formula::FormulaGrammar::Grammar eGrammar, bool bHasNmsp ) const;
123 
124 	void GetConditionalFormat(
125 		::com::sun::star::uno::Any& aAny, const rtl::OUString& sCondition,
126 		const rtl::OUString& sApplyStyle, const rtl::OUString& sBaseCell) const;
127 protected:
128 
129 	virtual void SetAttribute( sal_uInt16 nPrefixKey,
130 							   const ::rtl::OUString& rLocalName,
131 							   const ::rtl::OUString& rValue );
132 
133 public:
134 
135 	TYPEINFO();
136 
137 	XMLTableStyleContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
138 			const ::rtl::OUString& rLName,
139 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
140 			SvXMLStylesContext& rStyles, sal_uInt16 nFamily, sal_Bool bDefaultStyle = sal_False );
141 	virtual ~XMLTableStyleContext();
142 
143 	virtual SvXMLImportContext *CreateChildContext(
144 			sal_uInt16 nPrefix,
145 			const ::rtl::OUString& rLocalName,
146 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
147 
148 	virtual void FillPropertySet(const ::com::sun::star::uno::Reference<
149 				::com::sun::star::beans::XPropertySet > & rPropSet );
150 
151 	virtual void SetDefaults();
152 
153   	void AddProperty(sal_Int16 nContextID, const com::sun::star::uno::Any& aValue);
154     XMLPropertyState* FindProperty(const sal_Int16 nContextID);
155 
156 	sal_Int32 GetNumberFormat();// { return nNumberFormat; }
157 
GetLastSheet() const158     sal_Int32 GetLastSheet() const       { return nLastSheet; }
SetLastSheet(sal_Int32 nNew)159     void SetLastSheet(sal_Int32 nNew)    { nLastSheet = nNew; }
160 
161 private:
162     using XMLPropStyleContext::SetStyle;
163 };
164 
165 class XMLTableStylesContext : public SvXMLStylesContext
166 {
167 	::com::sun::star::uno::Reference <
168 					::com::sun::star::container::XNameContainer > xCellStyles;
169 	::com::sun::star::uno::Reference <
170 					::com::sun::star::container::XNameContainer > xColumnStyles;
171 	::com::sun::star::uno::Reference <
172 					::com::sun::star::container::XNameContainer > xRowStyles;
173 	::com::sun::star::uno::Reference <
174 					::com::sun::star::container::XNameContainer > xTableStyles;
175 	const ::rtl::OUString sCellStyleServiceName;
176 	const ::rtl::OUString sColumnStyleServiceName;
177 	const ::rtl::OUString sRowStyleServiceName;
178 	const ::rtl::OUString sTableStyleServiceName;
179 	sal_Int32 nNumberFormatIndex;
180 	sal_Int32 nConditionalFormatIndex;
181 	sal_Int32 nCellStyleIndex;
182 	sal_Int32 nMasterPageNameIndex;
183 	sal_Bool bAutoStyles;
184 
185 	UniReference < SvXMLImportPropertyMapper > xCellImpPropMapper;
186 	UniReference < SvXMLImportPropertyMapper > xColumnImpPropMapper;
187 	UniReference < SvXMLImportPropertyMapper > xRowImpPropMapper;
188 	UniReference < SvXMLImportPropertyMapper > xTableImpPropMapper;
189 
GetScImport() const190 	const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()191 	ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
192 
193 protected:
194 
195 	// Create a style context.
196 	virtual SvXMLStyleContext *CreateStyleStyleChildContext(
197 			sal_uInt16 nFamily,
198 			sal_uInt16 nPrefix,
199 			const ::rtl::OUString& rLocalName,
200 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
201 
202 	virtual SvXMLStyleContext *CreateDefaultStyleStyleChildContext(
203 		sal_uInt16 nFamily, sal_uInt16 nPrefix,
204 		const ::rtl::OUString& rLocalName,
205 		const ::com::sun::star::uno::Reference<
206 			::com::sun::star::xml::sax::XAttributeList > & xAttrList );
207 
208 //	virtual SvXMLImportPropertyMapper *GetImpPropMapper();
209 
210 public:
211 
212 	XMLTableStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx ,
213 			const ::rtl::OUString& rLName ,
214 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
215 			const sal_Bool bAutoStyles );
216 	virtual ~XMLTableStylesContext();
217 
218 	// Create child element.
219 /*	virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
220 		const ::rtl::OUString& rLocalName,
221 		const ::com::sun::star::uno::Reference<
222 			::com::sun::star::xml::sax::XAttributeList > & xAttrList );*/
223 
224 	virtual void EndElement();
225 
226 	virtual UniReference < SvXMLImportPropertyMapper > GetImportPropertyMapper(
227 						sal_uInt16 nFamily ) const;
228 	virtual ::com::sun::star::uno::Reference <
229 					::com::sun::star::container::XNameContainer >
230 		GetStylesContainer( sal_uInt16 nFamily ) const;
231 	virtual ::rtl::OUString GetServiceName( sal_uInt16 nFamily ) const;
232 
233 	sal_Int32 GetIndex(const sal_Int16 nContextID);
234 };
235 
236 class ScXMLMasterStylesContext : public SvXMLStylesContext
237 {
238 protected:
239 	virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix,
240 		const ::rtl::OUString& rLocalName,
241 		const ::com::sun::star::uno::Reference<
242 			::com::sun::star::xml::sax::XAttributeList > & xAttrList );
243 
244 	virtual SvXMLStyleContext *CreateStyleStyleChildContext( sal_uInt16 nFamily,
245 		sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName,
246 		const ::com::sun::star::uno::Reference<
247 			::com::sun::star::xml::sax::XAttributeList > & xAttrList );
248 
249 	virtual sal_Bool InsertStyleFamily( sal_uInt16 nFamily ) const;
250 
251 public:
252 	TYPEINFO();
253 
254 	ScXMLMasterStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
255 		const ::rtl::OUString& rLName,
256 		const ::com::sun::star::uno::Reference<
257 			::com::sun::star::xml::sax::XAttributeList > & xAttrList);
258 
259 	virtual ~ScXMLMasterStylesContext();
260 	virtual void EndElement();
261 };
262 
263 namespace com { namespace sun { namespace star {
264 	namespace style { class XStyle; }
265 } } }
266 
267 class ScMasterPageContext : public XMLTextMasterPageContext
268 {
269 	com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> xPropSet;
270 	const rtl::OUString		sEmpty;
271 	sal_Bool				bContainsRightHeader;
272 	sal_Bool				bContainsRightFooter;
273 
274 	void ClearContent(const rtl::OUString& rContent);
275 public:
276 
277 	TYPEINFO();
278 
279 	ScMasterPageContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
280 			const ::rtl::OUString& rLName,
281 			const ::com::sun::star::uno::Reference<
282 				::com::sun::star::xml::sax::XAttributeList > & xAttrList,
283 			sal_Bool bOverwrite );
284 	virtual ~ScMasterPageContext();
285 
286 	virtual SvXMLImportContext *CreateChildContext(
287 			sal_uInt16 nPrefix,
288 			const ::rtl::OUString& rLocalName,
289 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList );
290 
291 	virtual SvXMLImportContext *CreateHeaderFooterContext(
292 			sal_uInt16 nPrefix,
293 			const ::rtl::OUString& rLocalName,
294 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
295 			const sal_Bool bFooter,
296 			const sal_Bool bLeft );
297 
298 	virtual void Finish( sal_Bool bOverwrite );
299 };
300 
301 class ScCellTextStyleContext : public XMLTextStyleContext
302 {
303     sal_Int32   nLastSheet;
304 
GetScImport() const305     const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); }
GetScImport()306     ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); }
307 
308 public:
309     ScCellTextStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
310             const ::rtl::OUString& rLName,
311             const ::com::sun::star::uno::Reference<
312                 ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
313             SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
314             sal_Bool bDefaultStyle = sal_False );
315     virtual ~ScCellTextStyleContext();
316 
317     // overload FillPropertySet to store style information
318     virtual void FillPropertySet(
319             const ::com::sun::star::uno::Reference<
320                 ::com::sun::star::beans::XPropertySet > & rPropSet );
321 };
322 
323 
324 #endif
325 
326