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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_xmloff.hxx"
24
25 #include "PageMasterImportContext.hxx"
26 #include "xmloff/xmlnmspe.hxx"
27 #include <xmloff/xmltoken.hxx>
28 #include "PageMasterPropHdl.hxx"
29 #include "PagePropertySetContext.hxx"
30 #include "PageHeaderFooterContext.hxx"
31 #include "PageMasterPropMapper.hxx"
32 #include "PageMasterImportPropMapper.hxx"
33 #include <xmloff/PageMasterStyleMap.hxx>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35
36 //UUUU
37 #include <xmlsdtypes.hxx>
38 #include <com/sun/star/beans/XPropertySetInfo.hpp>
39 #include <xmloff/xmlerror.hxx>
40
41 using namespace ::com::sun::star;
42 using namespace ::xmloff::token;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45
46 //UUUU
47 using namespace ::com::sun::star::beans;
48
SetAttribute(sal_uInt16 nPrefixKey,const rtl::OUString & rLocalName,const rtl::OUString & rValue)49 void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
50 const rtl::OUString& rLocalName,
51 const rtl::OUString& rValue )
52 {
53 // TODO: use a map here
54 if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
55 {
56 sPageUsage = rValue;
57 }
58 else
59 {
60 XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
61 }
62 }
63
64 TYPEINIT1( PageStyleContext, XMLPropStyleContext );
65
PageStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_Bool bDefaultStyle)66 PageStyleContext::PageStyleContext( SvXMLImport& rImport,
67 sal_uInt16 nPrfx, const rtl::OUString& rLName,
68 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
69 SvXMLStylesContext& rStyles,
70 sal_Bool bDefaultStyle) :
71 XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
72 sPageUsage(),
73 m_bIsFillStyleAlreadyConverted(false) //UUUU
74 {
75 }
76
~PageStyleContext()77 PageStyleContext::~PageStyleContext()
78 {
79 }
80
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)81 SvXMLImportContext *PageStyleContext::CreateChildContext(
82 sal_uInt16 nPrefix,
83 const rtl::OUString& rLocalName,
84 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
85 {
86 SvXMLImportContext *pContext = NULL;
87
88 if( XML_NAMESPACE_STYLE == nPrefix &&
89 ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
90 (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
91 {
92 sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
93 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
94 GetStyles()->GetImportPropertyMapper( GetFamily() );
95 if( xImpPrMap.is() )
96 {
97 const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
98 sal_Int32 nFlag;
99 if (bHeader)
100 nFlag = CTF_PM_HEADERFLAG;
101 else
102 nFlag = CTF_PM_FOOTERFLAG;
103 sal_Int32 nStartIndex (-1);
104 sal_Int32 nEndIndex (-1);
105 sal_Bool bFirst(sal_False);
106 sal_Bool bEnd(sal_False);
107 sal_Int32 nIndex = 0;
108 while ( nIndex < rMapper->GetEntryCount() && !bEnd)
109 {
110 if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
111 {
112 if (!bFirst)
113 {
114 bFirst = sal_True;
115 nStartIndex = nIndex;
116 }
117 }
118 else if (bFirst)
119 {
120 bEnd = sal_True;
121 nEndIndex = nIndex;
122 }
123 nIndex++;
124 }
125 if (!bEnd)
126 nEndIndex = nIndex;
127 pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
128 xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
129 }
130 }
131 if( XML_NAMESPACE_STYLE == nPrefix &&
132 IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
133 {
134 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
135 GetStyles()->GetImportPropertyMapper( GetFamily() );
136 if( xImpPrMap.is() )
137 {
138 const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
139 sal_Int32 nEndIndex (-1);
140 sal_Bool bEnd(sal_False);
141 sal_Int32 nIndex = 0;
142 sal_Int16 nContextID;
143 while ( nIndex < rMapper->GetEntryCount() && !bEnd)
144 {
145 nContextID = rMapper->GetEntryContextId( nIndex );
146 if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
147 {
148 nEndIndex = nIndex;
149 bEnd = sal_True;
150 }
151 nIndex++;
152 }
153 if (!bEnd)
154 nEndIndex = nIndex;
155 PageContextType aType = Page;
156 pContext = new PagePropertySetContext( GetImport(), nPrefix,
157 rLocalName, xAttrList,
158 XML_TYPE_PROP_PAGE_LAYOUT,
159 GetProperties(),
160 xImpPrMap, 0, nEndIndex, aType);
161 }
162 }
163
164 if (!pContext)
165 pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
166 xAttrList );
167 return pContext;
168 }
169
FillPropertySet(const uno::Reference<beans::XPropertySet> & rPropSet)170 void PageStyleContext::FillPropertySet(const uno::Reference<beans::XPropertySet > & rPropSet)
171 {
172 //UUUU need to filter out old fill definitions when the new ones are used. The new
173 // ones are used when a FillStyle is defined
174 if(!m_bIsFillStyleAlreadyConverted && GetProperties().size())
175 {
176 static ::rtl::OUString s_FillStyle(RTL_CONSTASCII_USTRINGPARAM("FillStyle"));
177 static ::rtl::OUString s_HeaderFillStyle(RTL_CONSTASCII_USTRINGPARAM("HeaderFillStyle"));
178 static ::rtl::OUString s_FooterFillStyle(RTL_CONSTASCII_USTRINGPARAM("FooterFillStyle"));
179
180 if(doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle))
181 {
182 deactivateOldFillStyleDefinitions(getStandardSet());
183 }
184
185 if(doNewDrawingLayerFillStyleDefinitionsExist(s_HeaderFillStyle))
186 {
187 deactivateOldFillStyleDefinitions(getHeaderSet());
188 }
189
190 if(doNewDrawingLayerFillStyleDefinitionsExist(s_FooterFillStyle))
191 {
192 deactivateOldFillStyleDefinitions(getFooterSet());
193 }
194
195 m_bIsFillStyleAlreadyConverted = true;
196 }
197
198 //UUUU do not use XMLPropStyleContext::FillPropertySet, we need to handle this ourselves since
199 // we have properties which use the MID_FLAG_NO_PROPERTY_IMPORT flag since they need some special
200 // handling
201 UniReference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper(GetFamily());
202
203 if(xImpPrMap.is())
204 {
205 // properties that need special handling because they need the used name to be translated first
206 struct _ContextID_Index_Pair aContextIDs[] =
207 {
208 { CTF_PM_FILLGRADIENTNAME, -1 },
209 { CTF_PM_FILLTRANSNAME, -1 },
210 { CTF_PM_FILLHATCHNAME, -1 },
211 { CTF_PM_FILLBITMAPNAME, -1 },
212
213 // also need to special handling for header entries
214 { CTF_PM_HEADERFILLGRADIENTNAME, -1 },
215 { CTF_PM_HEADERFILLTRANSNAME, -1 },
216 { CTF_PM_HEADERFILLHATCHNAME, -1 },
217 { CTF_PM_HEADERFILLBITMAPNAME, -1 },
218
219 // also need to special handling for footer entries
220 { CTF_PM_FOOTERFILLGRADIENTNAME, -1 },
221 { CTF_PM_FOOTERFILLTRANSNAME, -1 },
222 { CTF_PM_FOOTERFILLHATCHNAME, -1 },
223 { CTF_PM_FOOTERFILLBITMAPNAME, -1 },
224
225 {-1, -1}
226 };
227
228 // the style families associated with the same index modulo 4
229 static sal_uInt16 aFamilies[] =
230 {
231 XML_STYLE_FAMILY_SD_GRADIENT_ID,
232 XML_STYLE_FAMILY_SD_GRADIENT_ID,
233 XML_STYLE_FAMILY_SD_HATCH_ID,
234 XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
235 };
236
237 //UUUU Fill PropertySet, but let it handle special properties not itself
238 xImpPrMap->FillPropertySet(GetProperties(), rPropSet, aContextIDs);
239
240 // get property set mapper
241 const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
242 Reference< XPropertySetInfo > xInfo;
243
244 //UUUU handle special attributes which have MID_FLAG_NO_PROPERTY_IMPORT set
245 for(sal_uInt16 i = 0; aContextIDs[i].nContextID != -1; i++)
246 {
247 sal_Int32 nIndex = aContextIDs[i].nIndex;
248
249 if(nIndex != -1)
250 {
251 switch(aContextIDs[i].nContextID)
252 {
253 case CTF_PM_FILLGRADIENTNAME:
254 case CTF_PM_FILLTRANSNAME:
255 case CTF_PM_FILLHATCHNAME:
256 case CTF_PM_FILLBITMAPNAME:
257
258 case CTF_PM_HEADERFILLGRADIENTNAME:
259 case CTF_PM_HEADERFILLTRANSNAME:
260 case CTF_PM_HEADERFILLHATCHNAME:
261 case CTF_PM_HEADERFILLBITMAPNAME:
262
263 case CTF_PM_FOOTERFILLGRADIENTNAME:
264 case CTF_PM_FOOTERFILLTRANSNAME:
265 case CTF_PM_FOOTERFILLHATCHNAME:
266 case CTF_PM_FOOTERFILLBITMAPNAME:
267 {
268 struct XMLPropertyState& rState = GetProperties()[nIndex];
269 rtl::OUString sStyleName;
270 rState.maValue >>= sStyleName;
271
272 //UUUU translate the used name from ODF intern to the name used in the Model
273 sStyleName = GetImport().GetStyleDisplayName(aFamilies[i%4], sStyleName);
274
275 try
276 {
277 // set property
278 const rtl::OUString& rPropertyName = rMapper->GetEntryAPIName(rState.mnIndex);
279
280 if(!xInfo.is())
281 {
282 xInfo = rPropSet->getPropertySetInfo();
283 }
284
285 if(xInfo->hasPropertyByName(rPropertyName))
286 {
287 rPropSet->setPropertyValue(rPropertyName,Any(sStyleName));
288 }
289 }
290 catch(::com::sun::star::lang::IllegalArgumentException& e)
291 {
292 Sequence< rtl::OUString > aSeq(1);
293 aSeq[0] = sStyleName;
294 GetImport().SetError(
295 XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
296 aSeq,e.Message,NULL);
297 }
298 break;
299 }
300 }
301 }
302 }
303 }
304 else
305 {
306 OSL_ENSURE(xImpPrMap.is(), "Got no SvXMLImportPropertyMapper (!)");
307 }
308
309 //UUUU old code, replaced by above stuff
310 // XMLPropStyleContext::FillPropertySet(rPropSet);
311
312 if (sPageUsage.getLength())
313 {
314 uno::Any aPageUsage;
315 XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
316 if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
317 rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage);
318 }
319 }
320
321 // text grid enhancement for better CJK support
322 //set default page layout style
SetDefaults()323 void PageStyleContext::SetDefaults( )
324 {
325 Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
326 if (xFactory.is())
327 {
328 Reference < XInterface > xInt = xFactory->createInstance (
329 rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
330 Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
331 if ( xProperties.is() )
332 FillPropertySet ( xProperties );
333 }
334 }
335
336 //eof
337