merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / PageMasterImportContext.cxx
blob1f26064a4a57d812a80c78ccbb701a9c042f1203
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PageMasterImportContext.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
35 #include "PageMasterImportContext.hxx"
36 #include "xmlnmspe.hxx"
37 #include <xmloff/xmltoken.hxx>
38 #include "PageMasterPropHdl.hxx"
39 #include "PagePropertySetContext.hxx"
40 #ifndef _XMLOFF_PAGEPHEADERFOOTERCONTEXT_HXX
41 #include "PageHeaderFooterContext.hxx"
42 #endif
43 #ifndef _XMLOFF_PAGEMASTERPROPMAPPER_HXX
44 #include "PageMasterPropMapper.hxx"
45 #endif
46 #include "PageMasterImportPropMapper.hxx"
47 #ifndef _XMLOFF_PAGEMASTERSTYLEMAP_HXX
48 #include <xmloff/PageMasterStyleMap.hxx>
49 #endif
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 using namespace ::com::sun::star;
53 using namespace ::xmloff::token;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::lang;
57 void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
58 const rtl::OUString& rLocalName,
59 const rtl::OUString& rValue )
61 // TODO: use a map here
62 if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
64 sPageUsage = rValue;
66 else
68 XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
72 TYPEINIT1( PageStyleContext, XMLPropStyleContext );
74 PageStyleContext::PageStyleContext( SvXMLImport& rImport,
75 sal_uInt16 nPrfx, const rtl::OUString& rLName,
76 const uno::Reference< xml::sax::XAttributeList > & xAttrList,
77 SvXMLStylesContext& rStyles,
78 sal_Bool bDefaultStyle) :
79 XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
80 sPageUsage()
84 PageStyleContext::~PageStyleContext()
88 SvXMLImportContext *PageStyleContext::CreateChildContext(
89 sal_uInt16 nPrefix,
90 const rtl::OUString& rLocalName,
91 const uno::Reference< xml::sax::XAttributeList > & xAttrList )
93 SvXMLImportContext *pContext = NULL;
95 if( XML_NAMESPACE_STYLE == nPrefix &&
96 ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
97 (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
99 sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
100 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
101 GetStyles()->GetImportPropertyMapper( GetFamily() );
102 if( xImpPrMap.is() )
104 const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
105 sal_Int32 nFlag;
106 if (bHeader)
107 nFlag = CTF_PM_HEADERFLAG;
108 else
109 nFlag = CTF_PM_FOOTERFLAG;
110 sal_Int32 nStartIndex (-1);
111 sal_Int32 nEndIndex (-1);
112 sal_Bool bFirst(sal_False);
113 sal_Bool bEnd(sal_False);
114 sal_Int32 nIndex = 0;
115 while ( nIndex < rMapper->GetEntryCount() && !bEnd)
117 if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
119 if (!bFirst)
121 bFirst = sal_True;
122 nStartIndex = nIndex;
125 else if (bFirst)
127 bEnd = sal_True;
128 nEndIndex = nIndex;
130 nIndex++;
132 if (!bEnd)
133 nEndIndex = nIndex;
134 pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
135 xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
138 if( XML_NAMESPACE_STYLE == nPrefix &&
139 IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
141 UniReference < SvXMLImportPropertyMapper > xImpPrMap =
142 GetStyles()->GetImportPropertyMapper( GetFamily() );
143 if( xImpPrMap.is() )
145 const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
146 sal_Int32 nEndIndex (-1);
147 sal_Bool bEnd(sal_False);
148 sal_Int32 nIndex = 0;
149 sal_Int16 nContextID;
150 while ( nIndex < rMapper->GetEntryCount() && !bEnd)
152 nContextID = rMapper->GetEntryContextId( nIndex );
153 if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
155 nEndIndex = nIndex;
156 bEnd = sal_True;
158 nIndex++;
160 if (!bEnd)
161 nEndIndex = nIndex;
162 PageContextType aType = Page;
163 pContext = new PagePropertySetContext( GetImport(), nPrefix,
164 rLocalName, xAttrList,
165 XML_TYPE_PROP_PAGE_LAYOUT,
166 GetProperties(),
167 xImpPrMap, 0, nEndIndex, aType);
171 if (!pContext)
172 pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
173 xAttrList );
174 return pContext;
177 void PageStyleContext::FillPropertySet(
178 const uno::Reference<beans::XPropertySet > & rPropSet )
180 XMLPropStyleContext::FillPropertySet(rPropSet);
181 if (sPageUsage.getLength())
183 uno::Any aPageUsage;
184 XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
185 if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
186 rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage);
190 // text grid enhancement for better CJK support
191 //set default page layout style
192 void PageStyleContext::SetDefaults( )
194 Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
195 if (xFactory.is())
197 Reference < XInterface > xInt = xFactory->createInstance (
198 rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
199 Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
200 if ( xProperties.is() )
201 FillPropertySet ( xProperties );