1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xmlnmspe.hxx"
22 #include <xmloff/xmltoken.hxx>
23 #include "PageMasterPropHdl.hxx"
24 #include "PagePropertySetContext.hxx"
25 #include "PageHeaderFooterContext.hxx"
26 #include "PageMasterPropMapper.hxx"
27 #include "PageMasterImportPropMapper.hxx"
28 #include <xmloff/PageMasterStyleMap.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 using namespace ::com::sun::star
;
32 using namespace ::xmloff::token
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
36 void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey
,
37 const OUString
& rLocalName
,
38 const OUString
& rValue
)
40 // TODO: use a map here
41 if( XML_NAMESPACE_STYLE
== nPrefixKey
&& IsXMLToken( rLocalName
, XML_PAGE_USAGE
) )
47 XMLPropStyleContext::SetAttribute( nPrefixKey
, rLocalName
, rValue
);
51 TYPEINIT1( PageStyleContext
, XMLPropStyleContext
);
53 PageStyleContext::PageStyleContext( SvXMLImport
& rImport
,
54 sal_uInt16 nPrfx
, const OUString
& rLName
,
55 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
,
56 SvXMLStylesContext
& rStyles
,
57 sal_Bool bDefaultStyle
) :
58 XMLPropStyleContext( rImport
, nPrfx
, rLName
, xAttrList
, rStyles
, XML_STYLE_FAMILY_PAGE_MASTER
, bDefaultStyle
),
63 PageStyleContext::~PageStyleContext()
67 SvXMLImportContext
*PageStyleContext::CreateChildContext(
69 const OUString
& rLocalName
,
70 const uno::Reference
< xml::sax::XAttributeList
> & xAttrList
)
72 SvXMLImportContext
*pContext
= NULL
;
74 if( XML_NAMESPACE_STYLE
== nPrefix
&&
75 ((IsXMLToken(rLocalName
, XML_HEADER_STYLE
)) ||
76 (IsXMLToken(rLocalName
, XML_FOOTER_STYLE
)) ) )
78 sal_Bool bHeader
= IsXMLToken(rLocalName
, XML_HEADER_STYLE
);
79 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
80 GetStyles()->GetImportPropertyMapper( GetFamily() );
83 const UniReference
< XMLPropertySetMapper
>& rMapper
= xImpPrMap
->getPropertySetMapper();
86 nFlag
= CTF_PM_HEADERFLAG
;
88 nFlag
= CTF_PM_FOOTERFLAG
;
89 sal_Int32
nStartIndex (-1);
90 sal_Int32
nEndIndex (-1);
91 sal_Bool
bFirst(sal_False
);
92 sal_Bool
bEnd(sal_False
);
94 while ( nIndex
< rMapper
->GetEntryCount() && !bEnd
)
96 if ((rMapper
->GetEntryContextId( nIndex
) & CTF_PM_FLAGMASK
) == nFlag
)
101 nStartIndex
= nIndex
;
113 pContext
= new PageHeaderFooterContext(GetImport(), nPrefix
, rLocalName
,
114 xAttrList
, GetProperties(), xImpPrMap
, nStartIndex
, nEndIndex
, bHeader
);
117 if( XML_NAMESPACE_STYLE
== nPrefix
&&
118 IsXMLToken(rLocalName
, XML_PAGE_LAYOUT_PROPERTIES
) )
120 UniReference
< SvXMLImportPropertyMapper
> xImpPrMap
=
121 GetStyles()->GetImportPropertyMapper( GetFamily() );
124 const UniReference
< XMLPropertySetMapper
>& rMapper
= xImpPrMap
->getPropertySetMapper();
125 sal_Int32
nEndIndex (-1);
126 sal_Bool
bEnd(sal_False
);
127 sal_Int32 nIndex
= 0;
128 sal_Int16 nContextID
;
129 while ( nIndex
< rMapper
->GetEntryCount() && !bEnd
)
131 nContextID
= rMapper
->GetEntryContextId( nIndex
);
132 if (nContextID
&& ((nContextID
& CTF_PM_FLAGMASK
) != XML_PM_CTF_START
))
141 PageContextType aType
= Page
;
142 pContext
= new PagePropertySetContext( GetImport(), nPrefix
,
143 rLocalName
, xAttrList
,
144 XML_TYPE_PROP_PAGE_LAYOUT
,
146 xImpPrMap
, 0, nEndIndex
, aType
);
151 pContext
= XMLPropStyleContext::CreateChildContext( nPrefix
, rLocalName
,
156 void PageStyleContext::FillPropertySet(
157 const uno::Reference
<beans::XPropertySet
> & rPropSet
)
159 XMLPropStyleContext::FillPropertySet(rPropSet
);
160 if (!sPageUsage
.isEmpty())
163 XMLPMPropHdl_PageStyleLayout aPageUsageHdl
;
164 if (aPageUsageHdl
.importXML(sPageUsage
, aPageUsage
, GetImport().GetMM100UnitConverter()))
165 rPropSet
->setPropertyValue(OUString("PageStyleLayout"), aPageUsage
);
169 // text grid enhancement for better CJK support
170 //set default page layout style
171 void PageStyleContext::SetDefaults( )
173 Reference
< XMultiServiceFactory
> xFactory ( GetImport().GetModel(), UNO_QUERY
);
176 Reference
< XInterface
> xInt
= xFactory
->createInstance (
177 OUString ( "com.sun.star.text.Defaults" ) );
178 Reference
< beans::XPropertySet
> xProperties ( xInt
, UNO_QUERY
);
179 if ( xProperties
.is() )
180 FillPropertySet ( xProperties
);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */