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 "xmlColumn.hxx"
21 : #include <xmloff/xmluconv.hxx>
22 : #include "xmlfilter.hxx"
23 : #include <xmloff/xmltoken.hxx>
24 : #include <xmloff/xmlnmspe.hxx>
25 : #include <xmloff/nmspmap.hxx>
26 : #include "xmlEnums.hxx"
27 : #include "xmlCell.hxx"
28 : #include <tools/debug.hxx>
29 : #include "xmlStyleImport.hxx"
30 : #include "xmlTable.hxx"
31 : #include <comphelper/namecontainer.hxx>
32 : #include <comphelper/genericpropertyset.hxx>
33 : #include <com/sun/star/beans/PropertyAttribute.hpp>
34 : #include "xmlstrings.hrc"
35 :
36 : #define PROPERTY_ID_WIDTH 1
37 : #define PROPERTY_ID_HEIGHT 2
38 :
39 : namespace rptxml
40 : {
41 : using namespace ::comphelper;
42 : using namespace ::com::sun::star::uno;
43 : using namespace ::com::sun::star::beans;
44 : using namespace ::com::sun::star::xml::sax;
45 :
46 :
47 0 : OXMLRowColumn::OXMLRowColumn( ORptFilter& rImport
48 : ,sal_uInt16 nPrfx
49 : ,const OUString& _sLocalName
50 : ,const Reference< XAttributeList > & _xAttrList
51 : ,OXMLTable* _pContainer
52 : ) :
53 : SvXMLImportContext( rImport, nPrfx, _sLocalName )
54 0 : ,m_pContainer(_pContainer)
55 : {
56 :
57 0 : const SvXMLNamespaceMap& rMap = rImport.GetNamespaceMap();
58 0 : const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
59 :
60 0 : const sal_Int16 nLength = (_xAttrList.is()) ? _xAttrList->getLength() : 0;
61 0 : for(sal_Int16 i = 0; i < nLength; ++i)
62 : {
63 0 : OUString sLocalName;
64 0 : const OUString sAttrName = _xAttrList->getNameByIndex( i );
65 0 : const sal_uInt16 nPrefix = rMap.GetKeyByAttrName( sAttrName,&sLocalName );
66 0 : const OUString sValue = _xAttrList->getValueByIndex( i );
67 :
68 0 : switch( rTokenMap.Get( nPrefix, sLocalName ) )
69 : {
70 : case XML_TOK_COLUMN_STYLE_NAME:
71 0 : fillStyle(sValue);
72 0 : break;
73 : default:
74 0 : break;
75 : }
76 0 : }
77 0 : }
78 :
79 :
80 0 : OXMLRowColumn::~OXMLRowColumn()
81 : {
82 0 : }
83 :
84 0 : SvXMLImportContext* OXMLRowColumn::CreateChildContext(
85 : sal_uInt16 nPrefix,
86 : const OUString& rLocalName,
87 : const Reference< XAttributeList > & xAttrList )
88 : {
89 0 : SvXMLImportContext *pContext = 0;
90 0 : ORptFilter& rImport = GetOwnImport();
91 0 : const SvXMLTokenMap& rTokenMap = rImport.GetColumnTokenMap();
92 :
93 0 : switch( rTokenMap.Get( nPrefix, rLocalName ) )
94 : {
95 : case XML_TOK_COLUMN:
96 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
97 0 : pContext = new OXMLRowColumn( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
98 0 : break;
99 : case XML_TOK_ROW:
100 0 : m_pContainer->incrementRowIndex();
101 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
102 0 : pContext = new OXMLRowColumn( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
103 0 : break;
104 : case XML_TOK_CELL:
105 0 : m_pContainer->incrementColumnIndex();
106 0 : rImport.GetProgressBarHelper()->Increment( PROGRESS_BAR_STEP );
107 0 : pContext = new OXMLCell( rImport, nPrefix, rLocalName,xAttrList,m_pContainer);
108 0 : break;
109 : case XML_TOK_COV_CELL:
110 0 : m_pContainer->incrementColumnIndex();
111 0 : m_pContainer->addCell(NULL);
112 0 : break;
113 : default:
114 0 : break;
115 : }
116 :
117 0 : if( !pContext )
118 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
119 :
120 0 : return pContext;
121 : }
122 :
123 0 : void OXMLRowColumn::fillStyle(const OUString& _sStyleName)
124 : {
125 0 : if ( !_sStyleName.isEmpty() )
126 : {
127 0 : const SvXMLStylesContext* pAutoStyles = GetOwnImport().GetAutoStyles();
128 0 : if ( pAutoStyles )
129 : {
130 0 : PropertySetInfo* pInfo = new PropertySetInfo();
131 : static PropertyMapEntry const pMap[] =
132 : {
133 0 : {OUString(PROPERTY_WIDTH), PROPERTY_ID_WIDTH, ::cppu::UnoType<sal_Int32>::get() ,PropertyAttribute::BOUND,0},
134 0 : {OUString(PROPERTY_HEIGHT), PROPERTY_ID_HEIGHT, ::cppu::UnoType<sal_Int32>::get() ,PropertyAttribute::BOUND,0},
135 : { OUString(), 0, css::uno::Type(), 0, 0 }
136 0 : };
137 0 : pInfo->add(pMap);
138 0 : Reference<XPropertySet> xProp = GenericPropertySet_CreateInstance(pInfo);
139 0 : XMLPropStyleContext* pAutoStyle = const_cast<XMLPropStyleContext*>(PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_COLUMN,_sStyleName)));
140 0 : if ( pAutoStyle )
141 : {
142 0 : pAutoStyle->FillPropertySet(xProp);
143 0 : sal_Int32 nWidth = 0;
144 0 : xProp->getPropertyValue(PROPERTY_WIDTH) >>= nWidth;
145 0 : m_pContainer->addWidth(nWidth);
146 : }
147 : else
148 : {
149 0 : pAutoStyle = const_cast<XMLPropStyleContext*>(PTR_CAST(XMLPropStyleContext,pAutoStyles->FindStyleChildContext(XML_STYLE_FAMILY_TABLE_ROW,_sStyleName)));
150 0 : if ( pAutoStyle )
151 : {
152 0 : pAutoStyle->FillPropertySet(xProp);
153 0 : sal_Int32 nHeight = 0;
154 0 : xProp->getPropertyValue(PROPERTY_HEIGHT) >>= nHeight;
155 0 : m_pContainer->addHeight(nHeight);
156 : }
157 0 : }
158 : }
159 : }
160 0 : }
161 :
162 0 : ORptFilter& OXMLRowColumn::GetOwnImport()
163 : {
164 0 : return static_cast<ORptFilter&>(GetImport());
165 : }
166 :
167 0 : void OXMLRowColumn::EndElement()
168 : {
169 0 : }
170 :
171 : } // namespace rptxml
172 :
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|