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 <com/sun/star/style/XStyle.hpp>
21 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 : #include <com/sun/star/style/PageStyleLayout.hpp>
23 : #include <com/sun/star/beans/XMultiPropertyStates.hpp>
24 : #include <xmloff/nmspmap.hxx>
25 : #include "xmloff/xmlnmspe.hxx"
26 : #include <xmloff/xmltoken.hxx>
27 : #include <xmloff/XMLTextMasterPageContext.hxx>
28 : #include "XMLTextHeaderFooterContext.hxx"
29 : #include <xmloff/xmlimp.hxx>
30 : #include "PageMasterImportContext.hxx"
31 :
32 :
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::xml::sax;
37 : using namespace ::com::sun::star::style;
38 : using namespace ::com::sun::star::text;
39 : using namespace ::com::sun::star::beans;
40 : using namespace ::com::sun::star::container;
41 : using namespace ::com::sun::star::lang;
42 : using namespace ::xmloff::token;
43 :
44 17 : Reference < XStyle > XMLTextMasterPageContext::Create()
45 : {
46 17 : Reference < XStyle > xNewStyle;
47 :
48 17 : Reference< XMultiServiceFactory > xFactory( GetImport().GetModel(),
49 34 : UNO_QUERY );
50 17 : if( xFactory.is() )
51 : {
52 : Reference < XInterface > xIfc =
53 17 : xFactory->createInstance("com.sun.star.style.PageStyle");
54 17 : if( xIfc.is() )
55 17 : xNewStyle = Reference < XStyle >( xIfc, UNO_QUERY );
56 : }
57 :
58 34 : return xNewStyle;
59 : }
60 0 : TYPEINIT1( XMLTextMasterPageContext, SvXMLStyleContext );
61 :
62 232 : XMLTextMasterPageContext::XMLTextMasterPageContext( SvXMLImport& rImport,
63 : sal_uInt16 nPrfx, const OUString& rLName,
64 : const Reference< XAttributeList > & xAttrList,
65 : sal_Bool bOverwrite )
66 : : SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, XML_STYLE_FAMILY_MASTER_PAGE )
67 : , sIsPhysical( "IsPhysical" )
68 : , sPageStyleLayout( "PageStyleLayout" )
69 : , sFollowStyle( "FollowStyle" )
70 : , bInsertHeader( sal_False )
71 : , bInsertFooter( sal_False )
72 : , bInsertHeaderLeft( sal_False )
73 : , bInsertFooterLeft( sal_False )
74 : , bInsertHeaderFirst( sal_False )
75 : , bInsertFooterFirst( sal_False )
76 : , bHeaderInserted( sal_False )
77 : , bFooterInserted( sal_False )
78 : , bHeaderLeftInserted( sal_False )
79 : , bFooterLeftInserted( sal_False )
80 : , bHeaderFirstInserted( sal_False )
81 232 : , bFooterFirstInserted( sal_False )
82 : {
83 464 : OUString sName, sDisplayName;
84 232 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
85 714 : for( sal_Int16 i=0; i < nAttrCount; i++ )
86 : {
87 482 : const OUString& rAttrName = xAttrList->getNameByIndex( i );
88 964 : OUString aLocalName;
89 482 : sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, &aLocalName );
90 482 : if( XML_NAMESPACE_STYLE == nPrefix )
91 : {
92 482 : if( IsXMLToken( aLocalName, XML_NAME ) )
93 : {
94 232 : sName = xAttrList->getValueByIndex( i );
95 : }
96 250 : else if( IsXMLToken( aLocalName, XML_DISPLAY_NAME ) )
97 : {
98 13 : sDisplayName = xAttrList->getValueByIndex( i );
99 : }
100 237 : else if( IsXMLToken( aLocalName, XML_NEXT_STYLE_NAME ) )
101 : {
102 5 : sFollow = xAttrList->getValueByIndex( i );
103 : }
104 232 : else if( IsXMLToken( aLocalName, XML_PAGE_LAYOUT_NAME ) )
105 : {
106 232 : sPageMasterName = xAttrList->getValueByIndex( i );
107 : }
108 : }
109 482 : }
110 :
111 232 : if( !sDisplayName.isEmpty() )
112 : {
113 : rImport.AddStyleDisplayName( XML_STYLE_FAMILY_MASTER_PAGE, sName,
114 13 : sDisplayName );
115 : }
116 : else
117 : {
118 219 : sDisplayName = sName;
119 : }
120 :
121 232 : if( sDisplayName.isEmpty() )
122 0 : return;
123 :
124 : Reference < XNameContainer > xPageStyles =
125 464 : GetImport().GetTextImport()->GetPageStyles();
126 232 : if( !xPageStyles.is() )
127 0 : return;
128 :
129 464 : Any aAny;
130 232 : sal_Bool bNew = sal_False;
131 232 : if( xPageStyles->hasByName( sDisplayName ) )
132 : {
133 215 : aAny = xPageStyles->getByName( sDisplayName );
134 215 : aAny >>= xStyle;
135 : }
136 : else
137 : {
138 17 : xStyle = Create();
139 17 : if( !xStyle.is() )
140 0 : return;
141 :
142 17 : aAny <<= xStyle;
143 17 : xPageStyles->insertByName( sDisplayName, aAny );
144 17 : bNew = sal_True;
145 : }
146 :
147 464 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
148 : Reference< XPropertySetInfo > xPropSetInfo =
149 464 : xPropSet->getPropertySetInfo();
150 232 : if( !bNew && xPropSetInfo->hasPropertyByName( sIsPhysical ) )
151 : {
152 65 : aAny = xPropSet->getPropertyValue( sIsPhysical );
153 65 : bNew = !*(sal_Bool *)aAny.getValue();
154 : }
155 232 : SetNew( bNew );
156 :
157 232 : if( bOverwrite || bNew )
158 : {
159 : Reference < XMultiPropertyStates > xMultiStates( xPropSet,
160 232 : UNO_QUERY );
161 : OSL_ENSURE( xMultiStates.is(),
162 : "text page style does not support multi property set" );
163 232 : if( xMultiStates.is() )
164 232 : xMultiStates->setAllPropertiesToDefault();
165 :
166 232 : bInsertHeader = bInsertFooter = sal_True;
167 232 : bInsertHeaderLeft = bInsertFooterLeft = sal_True;
168 232 : bInsertHeaderFirst = bInsertFooterFirst = sal_True;
169 232 : }
170 : }
171 :
172 308 : XMLTextMasterPageContext::~XMLTextMasterPageContext()
173 : {
174 308 : }
175 :
176 639 : SvXMLImportContext *XMLTextMasterPageContext::CreateChildContext(
177 : sal_uInt16 nPrefix,
178 : const OUString& rLocalName,
179 : const Reference< XAttributeList > & xAttrList )
180 : {
181 639 : SvXMLImportContext *pContext = 0;
182 :
183 : const SvXMLTokenMap& rTokenMap =
184 639 : GetImport().GetTextImport()->GetTextMasterPageElemTokenMap();
185 :
186 639 : sal_Bool bInsert = sal_False, bFooter = sal_False, bLeft = sal_False, bFirst = sal_False;
187 639 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
188 : {
189 : case XML_TOK_TEXT_MP_HEADER:
190 165 : if( bInsertHeader && !bHeaderInserted )
191 : {
192 165 : bInsert = sal_True;
193 165 : bHeaderInserted = sal_True;
194 : }
195 165 : break;
196 : case XML_TOK_TEXT_MP_FOOTER:
197 166 : if( bInsertFooter && !bFooterInserted )
198 : {
199 166 : bInsert = bFooter = sal_True;
200 166 : bFooterInserted = sal_True;
201 : }
202 166 : break;
203 : case XML_TOK_TEXT_MP_HEADER_LEFT:
204 150 : if( bInsertHeaderLeft && bHeaderInserted && !bHeaderLeftInserted )
205 150 : bInsert = bLeft = sal_True;
206 150 : break;
207 : case XML_TOK_TEXT_MP_FOOTER_LEFT:
208 150 : if( bInsertFooterLeft && bFooterInserted && !bFooterLeftInserted )
209 150 : bInsert = bFooter = bLeft = sal_True;
210 150 : break;
211 : case XML_TOK_TEXT_MP_HEADER_FIRST:
212 4 : if( bInsertHeaderFirst && bHeaderInserted && !bHeaderFirstInserted )
213 4 : bInsert = bFirst = sal_True;
214 4 : break;
215 : case XML_TOK_TEXT_MP_FOOTER_FIRST:
216 4 : if( bInsertFooterFirst && bFooterInserted && !bFooterFirstInserted )
217 4 : bInsert = bFooter = bFirst = sal_True;
218 4 : break;
219 : }
220 :
221 639 : if( bInsert && xStyle.is() )
222 : {
223 : pContext = CreateHeaderFooterContext( nPrefix, rLocalName,
224 : xAttrList,
225 639 : bFooter, bLeft, bFirst );
226 : }
227 : else
228 : {
229 : pContext = SvXMLStyleContext::CreateChildContext( nPrefix, rLocalName,
230 0 : xAttrList );
231 : }
232 :
233 639 : return pContext;
234 : }
235 :
236 35 : SvXMLImportContext *XMLTextMasterPageContext::CreateHeaderFooterContext(
237 : sal_uInt16 nPrefix,
238 : const OUString& rLocalName,
239 : const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList,
240 : const sal_Bool bFooter,
241 : const sal_Bool bLeft,
242 : const sal_Bool bFirst )
243 : {
244 35 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
245 35 : return new XMLTextHeaderFooterContext( GetImport(),
246 : nPrefix, rLocalName,
247 : xAttrList,
248 : xPropSet,
249 35 : bFooter, bLeft, bFirst );
250 : }
251 :
252 232 : void XMLTextMasterPageContext::Finish( sal_Bool bOverwrite )
253 : {
254 232 : if( xStyle.is() && (IsNew() || bOverwrite) )
255 : {
256 232 : Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
257 232 : if( !sPageMasterName.isEmpty() )
258 : {
259 : XMLPropStyleContext* pStyle =
260 232 : GetImport().GetTextImport()->FindPageMaster( sPageMasterName );
261 232 : if (pStyle)
262 : {
263 232 : pStyle->FillPropertySet(xPropSet);
264 : }
265 : }
266 :
267 : Reference < XNameContainer > xPageStyles =
268 464 : GetImport().GetTextImport()->GetPageStyles();
269 232 : if( !xPageStyles.is() )
270 232 : return;
271 :
272 : Reference< XPropertySetInfo > xPropSetInfo =
273 464 : xPropSet->getPropertySetInfo();
274 232 : if( xPropSetInfo->hasPropertyByName( sFollowStyle ) )
275 : {
276 : OUString sDisplayFollow(
277 76 : GetImport().GetStyleDisplayName(
278 152 : XML_STYLE_FAMILY_MASTER_PAGE, sFollow ) );
279 81 : if( sDisplayFollow.isEmpty() ||
280 5 : !xPageStyles->hasByName( sDisplayFollow ) )
281 71 : sDisplayFollow = xStyle->getName();
282 :
283 152 : Any aAny = xPropSet->getPropertyValue( sFollowStyle );
284 152 : OUString sCurrFollow;
285 76 : aAny >>= sCurrFollow;
286 76 : if( sCurrFollow != sDisplayFollow )
287 : {
288 4 : aAny <<= sDisplayFollow;
289 4 : xPropSet->setPropertyValue( sFollowStyle, aAny );
290 76 : }
291 : }
292 :
293 232 : if ( xPropSetInfo->hasPropertyByName( "Hidden" ) )
294 : {
295 232 : xPropSet->setPropertyValue( "Hidden", uno::makeAny( IsHidden( ) ) );
296 232 : }
297 : }
298 : }
299 :
300 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|