nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / PageMasterImportContext.cxx
blob7d70190cec89234996f7531771c630a563140a09
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <PageMasterImportContext.hxx>
21 #include <xmloff/xmlimppr.hxx>
22 #include <xmloff/xmlnamespace.hxx>
23 #include <xmloff/xmlprmap.hxx>
24 #include <xmloff/xmltoken.hxx>
25 #include "PageMasterPropHdl.hxx"
26 #include "PagePropertySetContext.hxx"
27 #include "PageHeaderFooterContext.hxx"
28 #include <PageMasterStyleMap.hxx>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <osl/diagnose.h>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/beans/XPropertySetInfo.hpp>
36 #include <xmloff/xmlerror.hxx>
37 #include <xmloff/XMLTextMasterPageContext.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::xmloff::token;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
47 void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
48 const OUString& rLocalName,
49 const OUString& rValue )
51 // TODO: use a map here
52 if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
54 sPageUsage = rValue;
56 else
58 XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
63 PageStyleContext::PageStyleContext( SvXMLImport& rImport,
64 SvXMLStylesContext& rStyles,
65 bool bDefaultStyle) :
66 XMLPropStyleContext( rImport, rStyles, XmlStyleFamily::PAGE_MASTER, bDefaultStyle),
67 sPageUsage(),
68 m_bIsFillStyleAlreadyConverted(false) //
72 PageStyleContext::~PageStyleContext()
76 css::uno::Reference< css::xml::sax::XFastContextHandler > PageStyleContext::createFastChildContext(
77 sal_Int32 nElement,
78 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
80 if( nElement == XML_ELEMENT(STYLE, XML_HEADER_STYLE) ||
81 nElement == XML_ELEMENT(STYLE, XML_FOOTER_STYLE) )
83 bool bHeader = nElement == XML_ELEMENT(STYLE, XML_HEADER_STYLE);
84 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
85 GetStyles()->GetImportPropertyMapper( GetFamily() );
86 if( xImpPrMap.is() )
88 const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
89 sal_Int32 nFlag;
90 if (bHeader)
91 nFlag = CTF_PM_HEADERFLAG;
92 else
93 nFlag = CTF_PM_FOOTERFLAG;
94 sal_Int32 nStartIndex (-1);
95 sal_Int32 nEndIndex (-1);
96 bool bFirst(false);
97 bool bEnd(false);
98 sal_Int32 nIndex = 0;
99 while ( nIndex < rMapper->GetEntryCount() && !bEnd)
101 if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
103 if (!bFirst)
105 bFirst = true;
106 nStartIndex = nIndex;
109 else if (bFirst)
111 bEnd = true;
112 nEndIndex = nIndex;
114 nIndex++;
116 if (!bEnd)
117 nEndIndex = nIndex;
118 return new PageHeaderFooterContext(GetImport(),
119 GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
123 if( nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_PROPERTIES) )
125 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
126 GetStyles()->GetImportPropertyMapper( GetFamily() );
127 if( xImpPrMap.is() )
129 const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
130 sal_Int32 nEndIndex (-1);
131 bool bEnd(false);
132 sal_Int32 nIndex = 0;
133 sal_Int16 nContextID;
134 while ( nIndex < rMapper->GetEntryCount() && !bEnd)
136 nContextID = rMapper->GetEntryContextId( nIndex );
137 if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
139 nEndIndex = nIndex;
140 bEnd = true;
142 nIndex++;
144 if (!bEnd)
145 nEndIndex = nIndex;
146 return new PagePropertySetContext( GetImport(), nElement,
147 xAttrList,
148 XML_TYPE_PROP_PAGE_LAYOUT,
149 GetProperties(),
150 xImpPrMap, 0, nEndIndex, Page);
154 return XMLPropStyleContext::createFastChildContext(nElement, xAttrList);
157 void PageStyleContext::FillPropertySet(const uno::Reference<beans::XPropertySet > &)
159 assert(false); // don't call this virtual, call function below
162 void PageStyleContext::FillPropertySet_PageStyle(
163 const uno::Reference<beans::XPropertySet> & rPropSet,
164 XMLPropStyleContext *const pDrawingPageStyle)
166 // need to filter out old fill definitions when the new ones are used. The new
167 // ones are used when a FillStyle is defined
168 if(!m_bIsFillStyleAlreadyConverted && !GetProperties().empty())
170 static OUString s_FillStyle("FillStyle");
171 static OUString s_HeaderFillStyle("HeaderFillStyle");
172 static OUString s_FooterFillStyle("FooterFillStyle");
174 // note: the function must only check by property name, not any id/flag!
175 if (doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle)
176 || (pDrawingPageStyle && pDrawingPageStyle->doNewDrawingLayerFillStyleDefinitionsExist(s_FillStyle)))
178 deactivateOldFillStyleDefinitions(getStandardSet());
181 if(doNewDrawingLayerFillStyleDefinitionsExist(s_HeaderFillStyle))
183 deactivateOldFillStyleDefinitions(getHeaderSet());
186 if(doNewDrawingLayerFillStyleDefinitionsExist(s_FooterFillStyle))
188 deactivateOldFillStyleDefinitions(getFooterSet());
191 m_bIsFillStyleAlreadyConverted = true;
194 // do not use XMLPropStyleContext::FillPropertySet, we need to handle this ourselves since
195 // we have properties which use the MID_FLAG_NO_PROPERTY_IMPORT flag since they need some special
196 // handling
197 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper(GetFamily());
199 if(xImpPrMap.is())
201 // properties that need special handling because they need the used name to be translated first
202 struct ContextID_Index_Pair aContextIDs[] =
204 { CTF_PM_FILLGRADIENTNAME, -1 },
205 { CTF_PM_FILLTRANSNAME, -1 },
206 { CTF_PM_FILLHATCHNAME, -1 },
207 { CTF_PM_FILLBITMAPNAME, -1 },
209 // also need to special handling for header entries
210 { CTF_PM_HEADERFILLGRADIENTNAME, -1 },
211 { CTF_PM_HEADERFILLTRANSNAME, -1 },
212 { CTF_PM_HEADERFILLHATCHNAME, -1 },
213 { CTF_PM_HEADERFILLBITMAPNAME, -1 },
215 // also need to special handling for footer entries
216 { CTF_PM_FOOTERFILLGRADIENTNAME, -1 },
217 { CTF_PM_FOOTERFILLTRANSNAME, -1 },
218 { CTF_PM_FOOTERFILLHATCHNAME, -1 },
219 { CTF_PM_FOOTERFILLBITMAPNAME, -1 },
221 {-1, -1}
224 // the style families associated with the same index modulo 4
225 static const XmlStyleFamily aFamilies[] =
227 XmlStyleFamily::SD_GRADIENT_ID,
228 XmlStyleFamily::SD_GRADIENT_ID,
229 XmlStyleFamily::SD_HATCH_ID,
230 XmlStyleFamily::SD_FILL_IMAGE_ID
233 // Fill PropertySet, but let it handle special properties not itself
234 xImpPrMap->FillPropertySet(GetProperties(), rPropSet, aContextIDs);
236 // get property set mapper
237 const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
238 Reference< XPropertySetInfo > xInfo;
240 // handle special attributes which have MID_FLAG_NO_PROPERTY_IMPORT set
241 for(sal_uInt16 i = 0; aContextIDs[i].nContextID != -1; i++)
243 sal_Int32 nIndex = aContextIDs[i].nIndex;
245 if(nIndex != -1)
247 switch(aContextIDs[i].nContextID)
249 case CTF_PM_FILLGRADIENTNAME:
250 case CTF_PM_FILLTRANSNAME:
251 case CTF_PM_FILLHATCHNAME:
252 case CTF_PM_FILLBITMAPNAME:
254 case CTF_PM_HEADERFILLGRADIENTNAME:
255 case CTF_PM_HEADERFILLTRANSNAME:
256 case CTF_PM_HEADERFILLHATCHNAME:
257 case CTF_PM_HEADERFILLBITMAPNAME:
259 case CTF_PM_FOOTERFILLGRADIENTNAME:
260 case CTF_PM_FOOTERFILLTRANSNAME:
261 case CTF_PM_FOOTERFILLHATCHNAME:
262 case CTF_PM_FOOTERFILLBITMAPNAME:
264 struct XMLPropertyState& rState = GetProperties()[nIndex];
265 OUString sStyleName;
266 rState.maValue >>= sStyleName;
268 // translate the used name from ODF intern to the name used in the Model
269 sStyleName = GetImport().GetStyleDisplayName(aFamilies[i%4], sStyleName);
273 // set property
274 const OUString& rPropertyName = rMapper->GetEntryAPIName(rState.mnIndex);
276 if(!xInfo.is())
278 xInfo = rPropSet->getPropertySetInfo();
281 if(xInfo->hasPropertyByName(rPropertyName))
283 rPropSet->setPropertyValue(rPropertyName,Any(sStyleName));
286 catch(css::lang::IllegalArgumentException& e)
288 Sequence<OUString> aSeq { sStyleName };
289 GetImport().SetError(
290 XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
291 aSeq,e.Message,nullptr);
293 break;
299 else
301 OSL_ENSURE(xImpPrMap.is(), "Got no SvXMLImportPropertyMapper (!)");
304 // pDrawingPageStyle overrides this
305 if (pDrawingPageStyle)
307 pDrawingPageStyle->FillPropertySet(rPropSet);
310 // old code, replaced by above stuff
311 // XMLPropStyleContext::FillPropertySet(rPropSet);
313 if (!sPageUsage.isEmpty())
315 uno::Any aPageUsage;
316 XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
317 if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
318 rPropSet->setPropertyValue("PageStyleLayout", aPageUsage);
322 extern ContextID_Index_Pair const g_MasterPageContextIDs[] =
324 { CTF_PM_FILLGRADIENTNAME, -1 },
325 { CTF_PM_FILLTRANSNAME, -1 },
326 { CTF_PM_FILLHATCHNAME, -1 },
327 { CTF_PM_FILLBITMAPNAME, -1 },
329 {-1, -1}
332 extern XmlStyleFamily const g_MasterPageFamilies[] =
334 XmlStyleFamily::SD_GRADIENT_ID,
335 XmlStyleFamily::SD_GRADIENT_ID,
336 XmlStyleFamily::SD_HATCH_ID,
337 XmlStyleFamily::SD_FILL_IMAGE_ID
340 // text grid enhancement for better CJK support
341 //set default page layout style
342 void PageStyleContext::SetDefaults( )
344 Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
345 if (xFactory.is())
347 Reference < XInterface > xInt = xFactory->createInstance( "com.sun.star.text.Defaults" );
348 Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
349 if ( xProperties.is() )
350 FillPropertySet_PageStyle(xProperties, nullptr);
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */