LibreOffice Module writerfilter (master) 1
TblStylePrHandler.cxx
Go to the documentation of this file.
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 "TagLogger.hxx"
22#include "CellMarginHandler.hxx"
23#include "PropertyMap.hxx"
24#include "MeasureHandler.hxx"
25#include <ooxml/resourceids.hxx>
27
28
29using namespace css;
30
31namespace writerfilter::dmapper {
32
34LoggedProperties("TblStylePrHandler"),
35m_rDMapper( rDMapper ),
36m_pTablePropsHandler(new TablePropertiesHandler()),
37m_nType( TBL_STYLE_UNKNOWN ),
38m_pProperties( new PropertyMap )
39{
40}
41
43{
44}
45
47{
48 switch (m_nType)
49 {
50 case TBL_STYLE_WHOLETABLE: return "wholeTable";
51 case TBL_STYLE_FIRSTROW: return "firstRow";
52 case TBL_STYLE_LASTROW: return "lastRow";
53 case TBL_STYLE_FIRSTCOL: return "firstCol";
54 case TBL_STYLE_LASTCOL: return "lastCol";
55 case TBL_STYLE_BAND1VERT: return "band1Vert";
56 case TBL_STYLE_BAND2VERT: return "band2Vert";
57 case TBL_STYLE_BAND1HORZ: return "band1Horz";
58 case TBL_STYLE_BAND2HORZ: return "band2Horz";
59 case TBL_STYLE_NECELL: return "neCell";
60 case TBL_STYLE_NWCELL: return "nwCell";
61 case TBL_STYLE_SECELL: return "seCell";
62 case TBL_STYLE_SWCELL: return "swCell";
63 default: break;
64 }
65 return OUString();
66}
67
69{
70
71 switch ( rName )
72 {
73 case NS_ooxml::LN_CT_TblStyleOverrideType:
74 {
75 switch (rVal.getInt())
76 {
77 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_wholeTable:
79 break;
80 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstRow:
82 break;
83 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastRow:
85 break;
86 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstCol:
88 break;
89 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastCol:
91 break;
92 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Vert:
94 break;
95 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Vert:
97 break;
98 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Horz:
100 break;
101 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Horz:
103 break;
104 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_neCell:
106 break;
107 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_nwCell:
109 break;
110 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_seCell:
112 break;
113 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_swCell:
115 break;
116 }
117 }
118 break;
119 }
120}
121
123{
124#ifdef DBG_UTIL
125 TagLogger::getInstance().startElement("TblStylePrHandler.sprm");
126 TagLogger::getInstance().attribute("sprm", rSprm.toString());
127#endif
128
129 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 std::vector<beans::PropertyValue> aSavedGrabBag;
138 bool bGrabBag = rSprm.getId() == NS_ooxml::LN_CT_PPrBase ||
139 rSprm.getId() == NS_ooxml::LN_EG_RPrBase ||
140 rSprm.getId() == NS_ooxml::LN_CT_TblPrBase ||
141 rSprm.getId() == NS_ooxml::LN_CT_TrPrBase ||
142 rSprm.getId() == NS_ooxml::LN_CT_TcPrBase;
143 if (bGrabBag)
144 {
145 std::swap(aSavedGrabBag, m_aInteropGrabBag);
146 }
147 resolveSprmProps( rSprm );
148 if (bGrabBag)
149 {
150 if (rSprm.getId() == NS_ooxml::LN_CT_PPrBase)
151 aSavedGrabBag.push_back(getInteropGrabBag("pPr"));
152 else if (rSprm.getId() == NS_ooxml::LN_EG_RPrBase)
153 aSavedGrabBag.push_back(getInteropGrabBag("rPr"));
154 else if (rSprm.getId() == NS_ooxml::LN_CT_TblPrBase)
155 aSavedGrabBag.push_back(getInteropGrabBag("tblPr"));
156 else if (rSprm.getId() == NS_ooxml::LN_CT_TrPrBase)
157 aSavedGrabBag.push_back(getInteropGrabBag("trPr"));
158 else if (rSprm.getId() == NS_ooxml::LN_CT_TcPrBase)
159 aSavedGrabBag.push_back(getInteropGrabBag("tcPr"));
160 std::swap(m_aInteropGrabBag, aSavedGrabBag);
161 }
162 }
163 break;
164 case NS_ooxml::LN_CT_TrPrBase_tblHeader:
165 {
166 m_pProperties->Insert( PROP_HEADER_ROW_COUNT, uno::Any(sal_Int32(1)));
167 beans::PropertyValue aValue;
168 aValue.Name = "tblHeader";
169 aValue.Value <<= true;
170 m_aInteropGrabBag.push_back(aValue);
171 }
172 break;
173 case NS_ooxml::LN_CT_TblPrBase_tblInd:
174 {
175 //contains unit and value
177 if( pProperties )
178 {
179 MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
180 pProperties->resolve(*pMeasureHandler);
182 pPropMap->setValue( TablePropertyMap::LEFT_MARGIN, pMeasureHandler->getMeasureValue() );
183 m_pProperties->Insert( PROP_LEFT_MARGIN, uno::Any(pMeasureHandler->getMeasureValue()) );
184 }
185 }
186 break;
187 case NS_ooxml::LN_CT_TblPrBase_tblCellMar:
188 {
190 if ( pProperties )
191 {
192 auto pCellMarginHandler = std::make_shared<CellMarginHandler>();
193 pCellMarginHandler->enableInteropGrabBag("tblCellMar");
194 pProperties->resolve( *pCellMarginHandler );
195 m_aInteropGrabBag.push_back(pCellMarginHandler->getInteropGrabBag());
196
197 if( pCellMarginHandler->m_bTopMarginValid )
198 m_pProperties->Insert( META_PROP_CELL_MAR_TOP, uno::Any(pCellMarginHandler->m_nTopMargin) );
199 if( pCellMarginHandler->m_bBottomMarginValid )
200 m_pProperties->Insert( META_PROP_CELL_MAR_BOTTOM, uno::Any(pCellMarginHandler->m_nBottomMargin) );
201 if( pCellMarginHandler->m_bLeftMarginValid )
202 m_pProperties->Insert( META_PROP_CELL_MAR_LEFT, uno::Any(pCellMarginHandler->m_nLeftMargin) );
203 if( pCellMarginHandler->m_bRightMarginValid )
204 m_pProperties->Insert( META_PROP_CELL_MAR_RIGHT, uno::Any(pCellMarginHandler->m_nRightMargin) );
205 }
206 }
207 break;
208 default:
209 // Tables specific properties have to handled here
210 m_pTablePropsHandler->SetProperties( m_pProperties );
211 m_pTablePropsHandler->SetInteropGrabBag(m_aInteropGrabBag);
212 bool bRet = m_pTablePropsHandler->sprm( rSprm );
213
214 if ( !bRet )
215 {
216 // The DomainMapper can handle some of the properties
218 // Just pass a non-empty string, the array will have a single element anyway.
219 m_rDMapper.enableInteropGrabBag("TblStylePrHandler");
220 m_rDMapper.sprm( rSprm );
222 if (aGrabBag.hasElements())
223 m_aInteropGrabBag.push_back(aGrabBag[0]);
225 }
226 }
227
228#ifdef DBG_UTIL
230#endif
231}
232
234{
236 if( pProperties )
237 pProperties->resolve(*this);
238}
239
240void TblStylePrHandler::appendInteropGrabBag(const OUString& aKey, const OUString& aValue)
241{
242 beans::PropertyValue aProperty;
243 aProperty.Name = aKey;
244 aProperty.Value <<= aValue;
245 m_aInteropGrabBag.push_back(aProperty);
246}
247
248beans::PropertyValue TblStylePrHandler::getInteropGrabBag(const OUString& aName)
249{
250 beans::PropertyValue aRet;
251 aRet.Name = aName;
252
254 return aRet;
255}
256
257}
258
259/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void sprm(Sprm &sprm) override
Receives a SPRM.
An SPRM: Section, Paragraph and Run Modifier.
virtual sal_uInt32 getId() const =0
Returns id of the SPRM.
virtual writerfilter::Reference< Properties >::Pointer_t getProps()=0
Returns reference to properties contained in the SPRM.
virtual std::string toString() const =0
Returns string representation of sprm.
static TagLogger & getInstance()
Definition: TagLogger.cxx:95
void startElement(const std::string &name)
Definition: TagLogger.cxx:140
void attribute(const std::string &name, const std::string &value)
Definition: TagLogger.cxx:150
virtual int getInt() const =0
Returns integer representation of the value.
void enableInteropGrabBag(const OUString &aName)
Enable storing of seen tokens in a named grab bag.
void PopStyleSheetProperties(bool bAffectTableMngr=false)
void PushStyleSheetProperties(const PropertyMapPtr &pStyleProperties, bool bAffectTableMngr=false)
css::beans::PropertyValue getInteropGrabBag()
Get the stored tokens and clear the internal storage.
Handler for sprms that contain a measure and a unit.
std::vector< css::beans::PropertyValue > m_aInteropGrabBag
virtual void lcl_attribute(Id Name, Value &val) override
void appendInteropGrabBag(const OUString &aKey, const OUString &aValue)
std::unique_ptr< TablePropertiesHandler > m_pTablePropsHandler
virtual void lcl_sprm(Sprm &sprm) override
css::beans::PropertyValue getInteropGrabBag(const OUString &aName)
OUString aName
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
sal_uInt32 Id