Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
30 :
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;
35 :
36 81 : void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
37 : const rtl::OUString& rLocalName,
38 : const rtl::OUString& rValue )
39 : {
40 : // TODO: use a map here
41 81 : if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
42 : {
43 13 : sPageUsage = rValue;
44 : }
45 : else
46 : {
47 68 : XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
48 : }
49 81 : }
50 :
51 216 : TYPEINIT1( PageStyleContext, XMLPropStyleContext );
52 :
53 68 : PageStyleContext::PageStyleContext( SvXMLImport& rImport,
54 : sal_uInt16 nPrfx, const rtl::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),
59 68 : sPageUsage()
60 : {
61 68 : }
62 :
63 136 : PageStyleContext::~PageStyleContext()
64 : {
65 136 : }
66 :
67 204 : SvXMLImportContext *PageStyleContext::CreateChildContext(
68 : sal_uInt16 nPrefix,
69 : const rtl::OUString& rLocalName,
70 : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
71 : {
72 204 : SvXMLImportContext *pContext = NULL;
73 :
74 544 : if( XML_NAMESPACE_STYLE == nPrefix &&
75 204 : ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
76 136 : (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
77 : {
78 136 : sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
79 : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
80 136 : GetStyles()->GetImportPropertyMapper( GetFamily() );
81 136 : if( xImpPrMap.is() )
82 : {
83 136 : const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
84 : sal_Int32 nFlag;
85 136 : if (bHeader)
86 68 : nFlag = CTF_PM_HEADERFLAG;
87 : else
88 68 : nFlag = CTF_PM_FOOTERFLAG;
89 136 : sal_Int32 nStartIndex (-1);
90 136 : sal_Int32 nEndIndex (-1);
91 136 : sal_Bool bFirst(sal_False);
92 136 : sal_Bool bEnd(sal_False);
93 136 : sal_Int32 nIndex = 0;
94 16320 : while ( nIndex < rMapper->GetEntryCount() && !bEnd)
95 : {
96 16048 : if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
97 : {
98 3944 : if (!bFirst)
99 : {
100 136 : bFirst = sal_True;
101 136 : nStartIndex = nIndex;
102 : }
103 : }
104 12104 : else if (bFirst)
105 : {
106 68 : bEnd = sal_True;
107 68 : nEndIndex = nIndex;
108 : }
109 16048 : nIndex++;
110 : }
111 136 : if (!bEnd)
112 68 : nEndIndex = nIndex;
113 136 : pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
114 136 : xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
115 136 : }
116 : }
117 408 : if( XML_NAMESPACE_STYLE == nPrefix &&
118 204 : IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
119 : {
120 : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
121 68 : GetStyles()->GetImportPropertyMapper( GetFamily() );
122 68 : if( xImpPrMap.is() )
123 : {
124 68 : const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
125 68 : sal_Int32 nEndIndex (-1);
126 68 : sal_Bool bEnd(sal_False);
127 68 : sal_Int32 nIndex = 0;
128 : sal_Int16 nContextID;
129 5236 : while ( nIndex < rMapper->GetEntryCount() && !bEnd)
130 : {
131 5100 : nContextID = rMapper->GetEntryContextId( nIndex );
132 5100 : if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
133 : {
134 68 : nEndIndex = nIndex;
135 68 : bEnd = sal_True;
136 : }
137 5100 : nIndex++;
138 : }
139 68 : if (!bEnd)
140 0 : nEndIndex = nIndex;
141 68 : PageContextType aType = Page;
142 68 : pContext = new PagePropertySetContext( GetImport(), nPrefix,
143 : rLocalName, xAttrList,
144 : XML_TYPE_PROP_PAGE_LAYOUT,
145 68 : GetProperties(),
146 136 : xImpPrMap, 0, nEndIndex, aType);
147 68 : }
148 : }
149 :
150 204 : if (!pContext)
151 : pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
152 0 : xAttrList );
153 204 : return pContext;
154 : }
155 :
156 72 : void PageStyleContext::FillPropertySet(
157 : const uno::Reference<beans::XPropertySet > & rPropSet )
158 : {
159 72 : XMLPropStyleContext::FillPropertySet(rPropSet);
160 72 : if (!sPageUsage.isEmpty())
161 : {
162 13 : uno::Any aPageUsage;
163 13 : XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
164 13 : if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
165 13 : rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage);
166 : }
167 72 : }
168 :
169 : // text grid enhancement for better CJK support
170 : //set default page layout style
171 0 : void PageStyleContext::SetDefaults( )
172 : {
173 0 : Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
174 0 : if (xFactory.is())
175 : {
176 0 : Reference < XInterface > xInt = xFactory->createInstance (
177 0 : rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
178 0 : Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
179 0 : if ( xProperties.is() )
180 0 : FillPropertySet ( xProperties );
181 0 : }
182 0 : }
183 :
184 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|