1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*63bba73cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*63bba73cSAndrew Rist * distributed with this work for additional information
6*63bba73cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*63bba73cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*63bba73cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*63bba73cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist * KIND, either express or implied. See the License for the
17*63bba73cSAndrew Rist * specific language governing permissions and limitations
18*63bba73cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*63bba73cSAndrew Rist *************************************************************/
21*63bba73cSAndrew Rist
22*63bba73cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "PageMasterImportContext.hxx"
29cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
30cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
31cdf0e10cSrcweir #include "PageMasterPropHdl.hxx"
32cdf0e10cSrcweir #include "PagePropertySetContext.hxx"
33cdf0e10cSrcweir #ifndef _XMLOFF_PAGEPHEADERFOOTERCONTEXT_HXX
34cdf0e10cSrcweir #include "PageHeaderFooterContext.hxx"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
37cdf0e10cSrcweir #include "PageMasterPropMapper.hxx"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include "PageMasterImportPropMapper.hxx"
40cdf0e10cSrcweir #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
41cdf0e10cSrcweir #include <xmloff/PageMasterStyleMap.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace ::com::sun::star;
46cdf0e10cSrcweir using namespace ::xmloff::token;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir using namespace ::com::sun::star::lang;
49cdf0e10cSrcweir
SetAttribute(sal_uInt16 nPrefixKey,const rtl::OUString & rLocalName,const rtl::OUString & rValue)50cdf0e10cSrcweir void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
51cdf0e10cSrcweir const rtl::OUString& rLocalName,
52cdf0e10cSrcweir const rtl::OUString& rValue )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir // TODO: use a map here
55cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir sPageUsage = rValue;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir else
60cdf0e10cSrcweir {
61cdf0e10cSrcweir XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
62cdf0e10cSrcweir }
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
65cdf0e10cSrcweir TYPEINIT1( PageStyleContext, XMLPropStyleContext );
66cdf0e10cSrcweir
PageStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const rtl::OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList,SvXMLStylesContext & rStyles,sal_Bool bDefaultStyle)67cdf0e10cSrcweir PageStyleContext::PageStyleContext( SvXMLImport& rImport,
68cdf0e10cSrcweir sal_uInt16 nPrfx, const rtl::OUString& rLName,
69cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & xAttrList,
70cdf0e10cSrcweir SvXMLStylesContext& rStyles,
71cdf0e10cSrcweir sal_Bool bDefaultStyle) :
72cdf0e10cSrcweir XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
73cdf0e10cSrcweir sPageUsage()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
~PageStyleContext()77cdf0e10cSrcweir PageStyleContext::~PageStyleContext()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
CreateChildContext(sal_uInt16 nPrefix,const rtl::OUString & rLocalName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)81cdf0e10cSrcweir SvXMLImportContext *PageStyleContext::CreateChildContext(
82cdf0e10cSrcweir sal_uInt16 nPrefix,
83cdf0e10cSrcweir const rtl::OUString& rLocalName,
84cdf0e10cSrcweir const uno::Reference< xml::sax::XAttributeList > & xAttrList )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir SvXMLImportContext *pContext = NULL;
87cdf0e10cSrcweir
88cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefix &&
89cdf0e10cSrcweir ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
90cdf0e10cSrcweir (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
93cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap =
94cdf0e10cSrcweir GetStyles()->GetImportPropertyMapper( GetFamily() );
95cdf0e10cSrcweir if( xImpPrMap.is() )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
98cdf0e10cSrcweir sal_Int32 nFlag;
99cdf0e10cSrcweir if (bHeader)
100cdf0e10cSrcweir nFlag = CTF_PM_HEADERFLAG;
101cdf0e10cSrcweir else
102cdf0e10cSrcweir nFlag = CTF_PM_FOOTERFLAG;
103cdf0e10cSrcweir sal_Int32 nStartIndex (-1);
104cdf0e10cSrcweir sal_Int32 nEndIndex (-1);
105cdf0e10cSrcweir sal_Bool bFirst(sal_False);
106cdf0e10cSrcweir sal_Bool bEnd(sal_False);
107cdf0e10cSrcweir sal_Int32 nIndex = 0;
108cdf0e10cSrcweir while ( nIndex < rMapper->GetEntryCount() && !bEnd)
109cdf0e10cSrcweir {
110cdf0e10cSrcweir if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if (!bFirst)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir bFirst = sal_True;
115cdf0e10cSrcweir nStartIndex = nIndex;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir else if (bFirst)
119cdf0e10cSrcweir {
120cdf0e10cSrcweir bEnd = sal_True;
121cdf0e10cSrcweir nEndIndex = nIndex;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir nIndex++;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir if (!bEnd)
126cdf0e10cSrcweir nEndIndex = nIndex;
127cdf0e10cSrcweir pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
128cdf0e10cSrcweir xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir if( XML_NAMESPACE_STYLE == nPrefix &&
132cdf0e10cSrcweir IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir UniReference < SvXMLImportPropertyMapper > xImpPrMap =
135cdf0e10cSrcweir GetStyles()->GetImportPropertyMapper( GetFamily() );
136cdf0e10cSrcweir if( xImpPrMap.is() )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
139cdf0e10cSrcweir sal_Int32 nEndIndex (-1);
140cdf0e10cSrcweir sal_Bool bEnd(sal_False);
141cdf0e10cSrcweir sal_Int32 nIndex = 0;
142cdf0e10cSrcweir sal_Int16 nContextID;
143cdf0e10cSrcweir while ( nIndex < rMapper->GetEntryCount() && !bEnd)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir nContextID = rMapper->GetEntryContextId( nIndex );
146cdf0e10cSrcweir if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
147cdf0e10cSrcweir {
148cdf0e10cSrcweir nEndIndex = nIndex;
149cdf0e10cSrcweir bEnd = sal_True;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir nIndex++;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir if (!bEnd)
154cdf0e10cSrcweir nEndIndex = nIndex;
155cdf0e10cSrcweir PageContextType aType = Page;
156cdf0e10cSrcweir pContext = new PagePropertySetContext( GetImport(), nPrefix,
157cdf0e10cSrcweir rLocalName, xAttrList,
158cdf0e10cSrcweir XML_TYPE_PROP_PAGE_LAYOUT,
159cdf0e10cSrcweir GetProperties(),
160cdf0e10cSrcweir xImpPrMap, 0, nEndIndex, aType);
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir if (!pContext)
165cdf0e10cSrcweir pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
166cdf0e10cSrcweir xAttrList );
167cdf0e10cSrcweir return pContext;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
FillPropertySet(const uno::Reference<beans::XPropertySet> & rPropSet)170cdf0e10cSrcweir void PageStyleContext::FillPropertySet(
171cdf0e10cSrcweir const uno::Reference<beans::XPropertySet > & rPropSet )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir XMLPropStyleContext::FillPropertySet(rPropSet);
174cdf0e10cSrcweir if (sPageUsage.getLength())
175cdf0e10cSrcweir {
176cdf0e10cSrcweir uno::Any aPageUsage;
177cdf0e10cSrcweir XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
178cdf0e10cSrcweir if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
179cdf0e10cSrcweir rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir
183cdf0e10cSrcweir // text grid enhancement for better CJK support
184cdf0e10cSrcweir //set default page layout style
SetDefaults()185cdf0e10cSrcweir void PageStyleContext::SetDefaults( )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
188cdf0e10cSrcweir if (xFactory.is())
189cdf0e10cSrcweir {
190cdf0e10cSrcweir Reference < XInterface > xInt = xFactory->createInstance (
191cdf0e10cSrcweir rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
192cdf0e10cSrcweir Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
193cdf0e10cSrcweir if ( xProperties.is() )
194cdf0e10cSrcweir FillPropertySet ( xProperties );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir }
197cdf0e10cSrcweir
198