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