Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "PageMasterImportContext.hxx"
30 : : #include "xmloff/xmlnmspe.hxx"
31 : : #include <xmloff/xmltoken.hxx>
32 : : #include "PageMasterPropHdl.hxx"
33 : : #include "PagePropertySetContext.hxx"
34 : : #include "PageHeaderFooterContext.hxx"
35 : : #include "PageMasterPropMapper.hxx"
36 : : #include "PageMasterImportPropMapper.hxx"
37 : : #include <xmloff/PageMasterStyleMap.hxx>
38 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 : :
40 : : using namespace ::com::sun::star;
41 : : using namespace ::xmloff::token;
42 : : using namespace ::com::sun::star::uno;
43 : : using namespace ::com::sun::star::lang;
44 : :
45 : 352 : void PageStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
46 : : const rtl::OUString& rLocalName,
47 : : const rtl::OUString& rValue )
48 : : {
49 : : // TODO: use a map here
50 [ + - ][ + + ]: 352 : if( XML_NAMESPACE_STYLE == nPrefixKey && IsXMLToken( rLocalName, XML_PAGE_USAGE ) )
[ + + ]
51 : : {
52 : 61 : sPageUsage = rValue;
53 : : }
54 : : else
55 : : {
56 : 291 : XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
57 : : }
58 : 352 : }
59 : :
60 [ - + ][ + - ]: 933 : TYPEINIT1( PageStyleContext, XMLPropStyleContext );
61 : :
62 : 297 : PageStyleContext::PageStyleContext( SvXMLImport& rImport,
63 : : sal_uInt16 nPrfx, const rtl::OUString& rLName,
64 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList,
65 : : SvXMLStylesContext& rStyles,
66 : : sal_Bool bDefaultStyle) :
67 : : XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XML_STYLE_FAMILY_PAGE_MASTER, bDefaultStyle),
68 : 297 : sPageUsage()
69 : : {
70 : 297 : }
71 : :
72 : 297 : PageStyleContext::~PageStyleContext()
73 : : {
74 [ - + ]: 594 : }
75 : :
76 : 868 : SvXMLImportContext *PageStyleContext::CreateChildContext(
77 : : sal_uInt16 nPrefix,
78 : : const rtl::OUString& rLocalName,
79 : : const uno::Reference< xml::sax::XAttributeList > & xAttrList )
80 : : {
81 : 868 : SvXMLImportContext *pContext = NULL;
82 : :
83 [ + - + + : 2313 : if( XML_NAMESPACE_STYLE == nPrefix &&
+ + ][ + + ]
84 : 868 : ((IsXMLToken(rLocalName, XML_HEADER_STYLE )) ||
85 : 577 : (IsXMLToken(rLocalName, XML_FOOTER_STYLE )) ) )
86 : : {
87 [ + - ]: 582 : sal_Bool bHeader = IsXMLToken(rLocalName, XML_HEADER_STYLE);
88 : : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
89 [ + - ]: 582 : GetStyles()->GetImportPropertyMapper( GetFamily() );
90 [ + - ]: 582 : if( xImpPrMap.is() )
91 : : {
92 [ + - ]: 582 : const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
93 : : sal_Int32 nFlag;
94 [ + + ]: 582 : if (bHeader)
95 : 291 : nFlag = CTF_PM_HEADERFLAG;
96 : : else
97 : 291 : nFlag = CTF_PM_FOOTERFLAG;
98 : 582 : sal_Int32 nStartIndex (-1);
99 : 582 : sal_Int32 nEndIndex (-1);
100 : 582 : sal_Bool bFirst(sal_False);
101 : 582 : sal_Bool bEnd(sal_False);
102 : 582 : sal_Int32 nIndex = 0;
103 [ + - ][ + + ]: 69258 : while ( nIndex < rMapper->GetEntryCount() && !bEnd)
[ + + ][ + + ]
104 : : {
105 [ + - ][ + - ]: 68676 : if ((rMapper->GetEntryContextId( nIndex ) & CTF_PM_FLAGMASK) == nFlag)
[ + + ]
106 : : {
107 [ + + ]: 16878 : if (!bFirst)
108 : : {
109 : 582 : bFirst = sal_True;
110 : 582 : nStartIndex = nIndex;
111 : : }
112 : : }
113 [ + + ]: 51798 : else if (bFirst)
114 : : {
115 : 291 : bEnd = sal_True;
116 : 291 : nEndIndex = nIndex;
117 : : }
118 : 68676 : nIndex++;
119 : : }
120 [ + + ]: 582 : if (!bEnd)
121 : 291 : nEndIndex = nIndex;
122 : 582 : pContext = new PageHeaderFooterContext(GetImport(), nPrefix, rLocalName,
123 [ + - ][ + - ]: 582 : xAttrList, GetProperties(), xImpPrMap, nStartIndex, nEndIndex, bHeader);
124 [ + - ]: 582 : }
125 : : }
126 [ + - + + ]: 1736 : if( XML_NAMESPACE_STYLE == nPrefix &&
[ + + ]
127 : 868 : IsXMLToken(rLocalName, XML_PAGE_LAYOUT_PROPERTIES) )
128 : : {
129 : : UniReference < SvXMLImportPropertyMapper > xImpPrMap =
130 [ + - ]: 286 : GetStyles()->GetImportPropertyMapper( GetFamily() );
131 [ + - ]: 286 : if( xImpPrMap.is() )
132 : : {
133 [ + - ]: 286 : const UniReference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
134 : 286 : sal_Int32 nEndIndex (-1);
135 : 286 : sal_Bool bEnd(sal_False);
136 : 286 : sal_Int32 nIndex = 0;
137 : : sal_Int16 nContextID;
138 [ + - ][ + - ]: 21736 : while ( nIndex < rMapper->GetEntryCount() && !bEnd)
[ + + ][ + + ]
139 : : {
140 [ + - ][ + - ]: 21450 : nContextID = rMapper->GetEntryContextId( nIndex );
141 [ + + ][ + + ]: 21450 : if (nContextID && ((nContextID & CTF_PM_FLAGMASK) != XML_PM_CTF_START))
142 : : {
143 : 286 : nEndIndex = nIndex;
144 : 286 : bEnd = sal_True;
145 : : }
146 : 21450 : nIndex++;
147 : : }
148 [ - + ]: 286 : if (!bEnd)
149 : 0 : nEndIndex = nIndex;
150 : 286 : PageContextType aType = Page;
151 : 286 : pContext = new PagePropertySetContext( GetImport(), nPrefix,
152 : : rLocalName, xAttrList,
153 : : XML_TYPE_PROP_PAGE_LAYOUT,
154 : 286 : GetProperties(),
155 [ + - ][ + - ]: 286 : xImpPrMap, 0, nEndIndex, aType);
156 [ + - ]: 286 : }
157 : : }
158 : :
159 [ - + ]: 868 : if (!pContext)
160 : : pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
161 : 0 : xAttrList );
162 : 868 : return pContext;
163 : : }
164 : :
165 : 317 : void PageStyleContext::FillPropertySet(
166 : : const uno::Reference<beans::XPropertySet > & rPropSet )
167 : : {
168 : 317 : XMLPropStyleContext::FillPropertySet(rPropSet);
169 [ + + ]: 317 : if (!sPageUsage.isEmpty())
170 : : {
171 : 67 : uno::Any aPageUsage;
172 : 67 : XMLPMPropHdl_PageStyleLayout aPageUsageHdl;
173 [ + - ][ + - ]: 67 : if (aPageUsageHdl.importXML(sPageUsage, aPageUsage, GetImport().GetMM100UnitConverter()))
174 [ + - ][ + - ]: 67 : rPropSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyleLayout")), aPageUsage);
[ + - ][ + - ]
175 : : }
176 : 317 : }
177 : :
178 : : // text grid enhancement for better CJK support
179 : : //set default page layout style
180 : 6 : void PageStyleContext::SetDefaults( )
181 : : {
182 [ + - ]: 6 : Reference < XMultiServiceFactory > xFactory ( GetImport().GetModel(), UNO_QUERY);
183 [ + - ]: 6 : if (xFactory.is())
184 : : {
185 [ + - ]: 6 : Reference < XInterface > xInt = xFactory->createInstance (
186 [ + - ][ + - ]: 6 : rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) ) );
187 [ + - ]: 6 : Reference < beans::XPropertySet > xProperties ( xInt, UNO_QUERY );
188 [ + - ]: 6 : if ( xProperties.is() )
189 [ + - ]: 6 : FillPropertySet ( xProperties );
190 : 6 : }
191 : 6 : }
192 : :
193 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|