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 <TblStylePrHandler.hxx>
21 : #include <PropertyMap.hxx>
22 : #include <ooxml/resourceids.hxx>
23 : #include <comphelper/sequence.hxx>
24 :
25 :
26 : using namespace css;
27 :
28 : namespace writerfilter {
29 : namespace dmapper {
30 :
31 5491 : TblStylePrHandler::TblStylePrHandler( DomainMapper & rDMapper ) :
32 : LoggedProperties("TblStylePrHandler"),
33 : m_rDMapper( rDMapper ),
34 0 : m_pTablePropsHandler(new TablePropertiesHandler()),
35 : m_nType( TBL_STYLE_UNKNOWN ),
36 5491 : m_pProperties( new PropertyMap )
37 : {
38 5491 : }
39 :
40 16473 : TblStylePrHandler::~TblStylePrHandler( )
41 : {
42 5491 : delete m_pTablePropsHandler, m_pTablePropsHandler = nullptr;
43 10982 : }
44 :
45 2593 : OUString TblStylePrHandler::getTypeString()
46 : {
47 2593 : switch (m_nType)
48 : {
49 0 : case TBL_STYLE_WHOLETABLE: return OUString("wholeTable");
50 642 : case TBL_STYLE_FIRSTROW: return OUString("firstRow");
51 376 : case TBL_STYLE_LASTROW: return OUString("lastRow");
52 347 : case TBL_STYLE_FIRSTCOL: return OUString("firstCol");
53 308 : case TBL_STYLE_LASTCOL: return OUString("lastCol");
54 143 : case TBL_STYLE_BAND1VERT: return OUString("band1Vert");
55 76 : case TBL_STYLE_BAND2VERT: return OUString("band2Vert");
56 182 : case TBL_STYLE_BAND1HORZ: return OUString("band1Horz");
57 70 : case TBL_STYLE_BAND2HORZ: return OUString("band2Horz");
58 117 : case TBL_STYLE_NECELL: return OUString("neCell");
59 116 : case TBL_STYLE_NWCELL: return OUString("nwCell");
60 27 : case TBL_STYLE_SECELL: return OUString("seCell");
61 189 : case TBL_STYLE_SWCELL: return OUString("swCell");
62 0 : default: break;
63 : }
64 0 : return OUString();
65 : }
66 :
67 2593 : void TblStylePrHandler::lcl_attribute(Id rName, Value & rVal)
68 : {
69 :
70 2593 : switch ( rName )
71 : {
72 : case NS_ooxml::LN_CT_TblStyleOverrideType:
73 : {
74 2593 : switch (rVal.getInt())
75 : {
76 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_wholeTable:
77 0 : m_nType = TBL_STYLE_WHOLETABLE;
78 0 : break;
79 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstRow:
80 642 : m_nType = TBL_STYLE_FIRSTROW;
81 642 : break;
82 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastRow:
83 376 : m_nType = TBL_STYLE_LASTROW;
84 376 : break;
85 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstCol:
86 347 : m_nType = TBL_STYLE_FIRSTCOL;
87 347 : break;
88 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastCol:
89 308 : m_nType = TBL_STYLE_LASTCOL;
90 308 : break;
91 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Vert:
92 143 : m_nType = TBL_STYLE_BAND1VERT;
93 143 : break;
94 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Vert:
95 76 : m_nType = TBL_STYLE_BAND2VERT;
96 76 : break;
97 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Horz:
98 182 : m_nType = TBL_STYLE_BAND1HORZ;
99 182 : break;
100 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Horz:
101 70 : m_nType = TBL_STYLE_BAND2HORZ;
102 70 : break;
103 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_neCell:
104 117 : m_nType = TBL_STYLE_NECELL;
105 117 : break;
106 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_nwCell:
107 116 : m_nType = TBL_STYLE_NWCELL;
108 116 : break;
109 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_seCell:
110 27 : m_nType = TBL_STYLE_SECELL;
111 27 : break;
112 : case NS_ooxml::LN_Value_ST_TblStyleOverrideType_swCell:
113 189 : m_nType = TBL_STYLE_SWCELL;
114 189 : break;
115 : }
116 : }
117 2593 : break;
118 : }
119 2593 : }
120 :
121 21263 : void TblStylePrHandler::lcl_sprm(Sprm & rSprm)
122 : {
123 : #ifdef DEBUG_WRITERFILTER
124 : TagLogger::getInstance().startElement("TblStylePrHandler.sprm");
125 : TagLogger::getInstance().attribute("sprm", rSprm.toString());
126 : #endif
127 :
128 21263 : Value::Pointer_t pValue = rSprm.getValue();
129 21263 : switch ( rSprm.getId( ) )
130 : {
131 : case NS_ooxml::LN_CT_PPrBase:
132 : case NS_ooxml::LN_EG_RPrBase:
133 : case NS_ooxml::LN_CT_TblPrBase:
134 : case NS_ooxml::LN_CT_TrPrBase:
135 : case NS_ooxml::LN_CT_TcPrBase:
136 : {
137 6904 : std::vector<beans::PropertyValue> aSavedGrabBag;
138 13620 : bool bGrabBag = rSprm.getId() == NS_ooxml::LN_CT_PPrBase ||
139 11568 : rSprm.getId() == NS_ooxml::LN_EG_RPrBase ||
140 14176 : rSprm.getId() == NS_ooxml::LN_CT_TblPrBase ||
141 9324 : rSprm.getId() == NS_ooxml::LN_CT_TcPrBase;
142 6904 : if (bGrabBag)
143 : {
144 6864 : aSavedGrabBag = m_aInteropGrabBag;
145 6864 : m_aInteropGrabBag.clear();
146 : }
147 6904 : resolveSprmProps( rSprm );
148 6904 : if (bGrabBag)
149 : {
150 6864 : if (rSprm.getId() == NS_ooxml::LN_CT_PPrBase)
151 188 : aSavedGrabBag.push_back(getInteropGrabBag("pPr"));
152 6676 : else if (rSprm.getId() == NS_ooxml::LN_EG_RPrBase)
153 1864 : aSavedGrabBag.push_back(getInteropGrabBag("rPr"));
154 4812 : else if (rSprm.getId() == NS_ooxml::LN_CT_TblPrBase)
155 2432 : aSavedGrabBag.push_back(getInteropGrabBag("tblPr"));
156 2380 : else if (rSprm.getId() == NS_ooxml::LN_CT_TcPrBase)
157 2380 : aSavedGrabBag.push_back(getInteropGrabBag("tcPr"));
158 6864 : m_aInteropGrabBag = aSavedGrabBag;
159 6904 : }
160 : }
161 6904 : break;
162 : default:
163 : // Tables specific properties have to handled here
164 14359 : m_pTablePropsHandler->SetProperties( m_pProperties );
165 14359 : m_pTablePropsHandler->SetInteropGrabBag(m_aInteropGrabBag);
166 14359 : bool bRet = m_pTablePropsHandler->sprm( rSprm );
167 :
168 14359 : if ( !bRet )
169 : {
170 : // The DomainMapper can handle some of the properties
171 4902 : m_rDMapper.PushStyleSheetProperties( m_pProperties, true );
172 : // Just pass a non-empty string, the array will have a single element anyway.
173 4902 : m_rDMapper.enableInteropGrabBag("TblStylePrHandler");
174 4902 : m_rDMapper.sprm( rSprm );
175 4902 : uno::Sequence<beans::PropertyValue> aGrabBag = m_rDMapper.getInteropGrabBag().Value.get< uno::Sequence<beans::PropertyValue> >();
176 4902 : if (aGrabBag.hasElements())
177 4326 : m_aInteropGrabBag.push_back(aGrabBag[0]);
178 4902 : m_rDMapper.PopStyleSheetProperties( true );
179 : }
180 21263 : }
181 :
182 : #ifdef DEBUG_WRITERFILTER
183 : TagLogger::getInstance().endElement();
184 : #endif
185 21263 : }
186 :
187 6904 : void TblStylePrHandler::resolveSprmProps(Sprm & rSprm)
188 : {
189 6904 : writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
190 6904 : if( pProperties.get())
191 6904 : pProperties->resolve(*this);
192 6904 : }
193 :
194 2593 : void TblStylePrHandler::appendInteropGrabBag(const OUString& aKey, const OUString& aValue)
195 : {
196 2593 : beans::PropertyValue aProperty;
197 2593 : aProperty.Name = aKey;
198 2593 : aProperty.Value = uno::makeAny(aValue);
199 2593 : m_aInteropGrabBag.push_back(aProperty);
200 2593 : }
201 :
202 12355 : beans::PropertyValue TblStylePrHandler::getInteropGrabBag(const OUString& aName)
203 : {
204 12355 : beans::PropertyValue aRet;
205 12355 : aRet.Name = aName;
206 :
207 12355 : aRet.Value = uno::makeAny(comphelper::containerToSequence(m_aInteropGrabBag));
208 12355 : return aRet;
209 : }
210 :
211 : }}
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|