lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / writerfilter / source / dmapper / TblStylePrHandler.cxx
blobd2e5bb2054ceb8ef1b5f5dc85e0dba87718c16ad
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "TblStylePrHandler.hxx"
21 #include "PropertyMap.hxx"
22 #include <ooxml/resourceids.hxx>
23 #include <comphelper/sequence.hxx>
26 using namespace css;
28 namespace writerfilter {
29 namespace dmapper {
31 TblStylePrHandler::TblStylePrHandler( DomainMapper & rDMapper ) :
32 LoggedProperties("TblStylePrHandler"),
33 m_rDMapper( rDMapper ),
34 m_pTablePropsHandler(new TablePropertiesHandler()),
35 m_nType( TBL_STYLE_UNKNOWN ),
36 m_pProperties( new PropertyMap )
40 TblStylePrHandler::~TblStylePrHandler( )
44 OUString TblStylePrHandler::getTypeString()
46 switch (m_nType)
48 case TBL_STYLE_WHOLETABLE: return OUString("wholeTable");
49 case TBL_STYLE_FIRSTROW: return OUString("firstRow");
50 case TBL_STYLE_LASTROW: return OUString("lastRow");
51 case TBL_STYLE_FIRSTCOL: return OUString("firstCol");
52 case TBL_STYLE_LASTCOL: return OUString("lastCol");
53 case TBL_STYLE_BAND1VERT: return OUString("band1Vert");
54 case TBL_STYLE_BAND2VERT: return OUString("band2Vert");
55 case TBL_STYLE_BAND1HORZ: return OUString("band1Horz");
56 case TBL_STYLE_BAND2HORZ: return OUString("band2Horz");
57 case TBL_STYLE_NECELL: return OUString("neCell");
58 case TBL_STYLE_NWCELL: return OUString("nwCell");
59 case TBL_STYLE_SECELL: return OUString("seCell");
60 case TBL_STYLE_SWCELL: return OUString("swCell");
61 default: break;
63 return OUString();
66 void TblStylePrHandler::lcl_attribute(Id rName, Value & rVal)
69 switch ( rName )
71 case NS_ooxml::LN_CT_TblStyleOverrideType:
73 switch (rVal.getInt())
75 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_wholeTable:
76 m_nType = TBL_STYLE_WHOLETABLE;
77 break;
78 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstRow:
79 m_nType = TBL_STYLE_FIRSTROW;
80 break;
81 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastRow:
82 m_nType = TBL_STYLE_LASTROW;
83 break;
84 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_firstCol:
85 m_nType = TBL_STYLE_FIRSTCOL;
86 break;
87 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_lastCol:
88 m_nType = TBL_STYLE_LASTCOL;
89 break;
90 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Vert:
91 m_nType = TBL_STYLE_BAND1VERT;
92 break;
93 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Vert:
94 m_nType = TBL_STYLE_BAND2VERT;
95 break;
96 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band1Horz:
97 m_nType = TBL_STYLE_BAND1HORZ;
98 break;
99 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_band2Horz:
100 m_nType = TBL_STYLE_BAND2HORZ;
101 break;
102 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_neCell:
103 m_nType = TBL_STYLE_NECELL;
104 break;
105 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_nwCell:
106 m_nType = TBL_STYLE_NWCELL;
107 break;
108 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_seCell:
109 m_nType = TBL_STYLE_SECELL;
110 break;
111 case NS_ooxml::LN_Value_ST_TblStyleOverrideType_swCell:
112 m_nType = TBL_STYLE_SWCELL;
113 break;
116 break;
120 void TblStylePrHandler::lcl_sprm(Sprm & rSprm)
122 #ifdef DEBUG_WRITERFILTER
123 TagLogger::getInstance().startElement("TblStylePrHandler.sprm");
124 TagLogger::getInstance().attribute("sprm", rSprm.toString());
125 #endif
127 Value::Pointer_t pValue = rSprm.getValue();
128 switch ( rSprm.getId( ) )
130 case NS_ooxml::LN_CT_PPrBase:
131 case NS_ooxml::LN_EG_RPrBase:
132 case NS_ooxml::LN_CT_TblPrBase:
133 case NS_ooxml::LN_CT_TrPrBase:
134 case NS_ooxml::LN_CT_TcPrBase:
136 std::vector<beans::PropertyValue> aSavedGrabBag;
137 bool bGrabBag = rSprm.getId() == NS_ooxml::LN_CT_PPrBase ||
138 rSprm.getId() == NS_ooxml::LN_EG_RPrBase ||
139 rSprm.getId() == NS_ooxml::LN_CT_TblPrBase ||
140 rSprm.getId() == NS_ooxml::LN_CT_TcPrBase;
141 if (bGrabBag)
143 std::swap(aSavedGrabBag, m_aInteropGrabBag);
145 resolveSprmProps( rSprm );
146 if (bGrabBag)
148 if (rSprm.getId() == NS_ooxml::LN_CT_PPrBase)
149 aSavedGrabBag.push_back(getInteropGrabBag("pPr"));
150 else if (rSprm.getId() == NS_ooxml::LN_EG_RPrBase)
151 aSavedGrabBag.push_back(getInteropGrabBag("rPr"));
152 else if (rSprm.getId() == NS_ooxml::LN_CT_TblPrBase)
153 aSavedGrabBag.push_back(getInteropGrabBag("tblPr"));
154 else if (rSprm.getId() == NS_ooxml::LN_CT_TcPrBase)
155 aSavedGrabBag.push_back(getInteropGrabBag("tcPr"));
156 std::swap(m_aInteropGrabBag, aSavedGrabBag);
159 break;
160 default:
161 // Tables specific properties have to handled here
162 m_pTablePropsHandler->SetProperties( m_pProperties );
163 m_pTablePropsHandler->SetInteropGrabBag(m_aInteropGrabBag);
164 bool bRet = m_pTablePropsHandler->sprm( rSprm );
166 if ( !bRet )
168 // The DomainMapper can handle some of the properties
169 m_rDMapper.PushStyleSheetProperties( m_pProperties, true );
170 // Just pass a non-empty string, the array will have a single element anyway.
171 m_rDMapper.enableInteropGrabBag("TblStylePrHandler");
172 m_rDMapper.sprm( rSprm );
173 uno::Sequence<beans::PropertyValue> aGrabBag = m_rDMapper.getInteropGrabBag().Value.get< uno::Sequence<beans::PropertyValue> >();
174 if (aGrabBag.hasElements())
175 m_aInteropGrabBag.push_back(aGrabBag[0]);
176 m_rDMapper.PopStyleSheetProperties( true );
180 #ifdef DEBUG_WRITERFILTER
181 TagLogger::getInstance().endElement();
182 #endif
185 void TblStylePrHandler::resolveSprmProps(Sprm & rSprm)
187 writerfilter::Reference<Properties>::Pointer_t pProperties = rSprm.getProps();
188 if( pProperties.get())
189 pProperties->resolve(*this);
192 void TblStylePrHandler::appendInteropGrabBag(const OUString& aKey, const OUString& aValue)
194 beans::PropertyValue aProperty;
195 aProperty.Name = aKey;
196 aProperty.Value <<= aValue;
197 m_aInteropGrabBag.push_back(aProperty);
200 beans::PropertyValue TblStylePrHandler::getInteropGrabBag(const OUString& aName)
202 beans::PropertyValue aRet;
203 aRet.Name = aName;
205 aRet.Value <<= comphelper::containerToSequence(m_aInteropGrabBag);
206 return aRet;
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */