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 "xmlcoli.hxx"
21 : #include "xmlimprt.hxx"
22 : #include "global.hxx"
23 : #include "xmlstyli.hxx"
24 : #include "document.hxx"
25 : #include "docuno.hxx"
26 : #include "olinetab.hxx"
27 : #include "sheetdata.hxx"
28 : #include "unonames.hxx"
29 :
30 : #include <xmloff/xmltkmap.hxx>
31 : #include <xmloff/nmspmap.hxx>
32 : #include <xmloff/xmlnmspe.hxx>
33 : #include <xmloff/families.hxx>
34 : #include <xmloff/xmltoken.hxx>
35 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
37 : #include <com/sun/star/table/XColumnRowRange.hpp>
38 : #include <com/sun/star/sheet/XPrintAreas.hpp>
39 :
40 : using namespace com::sun::star;
41 : using namespace xmloff::token;
42 :
43 1310 : ScXMLTableColContext::ScXMLTableColContext( ScXMLImport& rImport,
44 : sal_uInt16 nPrfx,
45 : const OUString& rLName,
46 : const ::com::sun::star::uno::Reference<
47 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
48 : SvXMLImportContext( rImport, nPrfx, rLName ),
49 1310 : sVisibility(GetXMLToken(XML_VISIBLE))
50 : {
51 1310 : nColCount = 1;
52 1310 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
53 1310 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableColAttrTokenMap();
54 :
55 3439 : for( sal_Int16 i=0; i < nAttrCount; ++i )
56 : {
57 2129 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
58 4258 : OUString aLocalName;
59 2129 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
60 2129 : sAttrName, &aLocalName );
61 4258 : const OUString& sValue(xAttrList->getValueByIndex( i ));
62 :
63 2129 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
64 : {
65 : case XML_TOK_TABLE_COL_ATTR_REPEATED:
66 : {
67 218 : nColCount = std::max<sal_Int32>(sValue.toInt32(), 1);
68 218 : nColCount = std::min<sal_Int32>(nColCount, MAXCOLCOUNT);
69 : }
70 218 : break;
71 : case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
72 : {
73 1310 : sStyleName = sValue;
74 : }
75 1310 : break;
76 : case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
77 : {
78 3 : sVisibility = sValue;
79 : }
80 3 : break;
81 : case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
82 : {
83 598 : sCellStyleName = sValue;
84 : }
85 598 : break;
86 : }
87 2129 : }
88 1310 : }
89 :
90 2620 : ScXMLTableColContext::~ScXMLTableColContext()
91 : {
92 2620 : }
93 :
94 0 : SvXMLImportContext *ScXMLTableColContext::CreateChildContext( sal_uInt16 nPrefix,
95 : const OUString& rLName,
96 : const ::com::sun::star::uno::Reference<
97 : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
98 : {
99 0 : SvXMLImportContext *pContext = 0;
100 :
101 0 : if( !pContext )
102 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
103 :
104 0 : return pContext;
105 : }
106 :
107 1310 : void ScXMLTableColContext::EndElement()
108 : {
109 1310 : ScXMLImport& rXMLImport = GetScImport();
110 1310 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
111 1310 : sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColCount();
112 1310 : uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
113 1310 : if(xSheet.is())
114 : {
115 1310 : sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
116 1310 : if (nLastColumn > MAXCOL)
117 0 : nLastColumn = MAXCOL;
118 1310 : if (nCurrentColumn > MAXCOL)
119 0 : nCurrentColumn = MAXCOL;
120 1310 : uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
121 1310 : if (xColumnRowRange.is())
122 : {
123 1310 : uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
124 1310 : if (xColumnProperties.is())
125 : {
126 1310 : if (!sStyleName.isEmpty())
127 : {
128 1310 : XMLTableStylesContext *pStyles = static_cast<XMLTableStylesContext *>(rXMLImport.GetAutoStyles());
129 1310 : if ( pStyles )
130 : {
131 : XMLTableStyleContext* pStyle = const_cast<XMLTableStyleContext*>(static_cast<const XMLTableStyleContext *>(pStyles->FindStyleChildContext(
132 1310 : XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, true)));
133 1310 : if (pStyle)
134 : {
135 1310 : pStyle->FillPropertySet(xColumnProperties);
136 :
137 1310 : if ( nSheet != pStyle->GetLastSheet() )
138 : {
139 1198 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
140 1198 : pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, nSheet ) );
141 1198 : pStyle->SetLastSheet(nSheet);
142 : }
143 : }
144 : }
145 : }
146 1310 : OUString sVisible(SC_UNONAME_CELLVIS);
147 1310 : bool bValue(true);
148 1310 : if (!IsXMLToken(sVisibility, XML_VISIBLE))
149 3 : bValue = false;
150 1310 : xColumnProperties->setPropertyValue(sVisible, uno::makeAny(bValue));
151 1310 : }
152 1310 : }
153 : }
154 :
155 : // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
156 : // The default for a column if there is no attribute is the style "Default" (programmatic API name).
157 1310 : if ( sCellStyleName.isEmpty() )
158 712 : sCellStyleName = "Default";
159 :
160 1310 : GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName);
161 1310 : }
162 :
163 8 : ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport& rImport,
164 : sal_uInt16 nPrfx,
165 : const OUString& rLName,
166 : const ::com::sun::star::uno::Reference<
167 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
168 : const bool bTempHeader, const bool bTempGroup) :
169 : SvXMLImportContext( rImport, nPrfx, rLName ),
170 : nHeaderStartCol(0),
171 : nHeaderEndCol(0),
172 : nGroupStartCol(0),
173 : nGroupEndCol(0),
174 : bHeader(bTempHeader),
175 : bGroup(bTempGroup),
176 8 : bGroupDisplay(true)
177 : {
178 : // don't have any attributes
179 8 : if (bHeader)
180 0 : nHeaderStartCol = rImport.GetTables().GetCurrentColCount();
181 8 : else if (bGroup)
182 : {
183 8 : nGroupStartCol = rImport.GetTables().GetCurrentColCount();
184 8 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
185 9 : for( sal_Int16 i=0; i < nAttrCount; ++i )
186 : {
187 1 : const OUString& sAttrName(xAttrList->getNameByIndex( i ));
188 2 : OUString aLocalName;
189 1 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
190 1 : sAttrName, &aLocalName );
191 2 : const OUString& sValue(xAttrList->getValueByIndex( i ));
192 :
193 1 : if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DISPLAY))
194 : {
195 1 : if (IsXMLToken(sValue, XML_FALSE))
196 1 : bGroupDisplay = false;
197 : }
198 1 : }
199 : }
200 8 : }
201 :
202 16 : ScXMLTableColsContext::~ScXMLTableColsContext()
203 : {
204 16 : }
205 :
206 20 : SvXMLImportContext *ScXMLTableColsContext::CreateChildContext( sal_uInt16 nPrefix,
207 : const OUString& rLName,
208 : const ::com::sun::star::uno::Reference<
209 : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
210 : {
211 20 : SvXMLImportContext *pContext = 0;
212 :
213 20 : const SvXMLTokenMap& rTokenMap = GetScImport().GetTableColsElemTokenMap();
214 20 : switch( rTokenMap.Get( nPrefix, rLName ) )
215 : {
216 : case XML_TOK_TABLE_COLS_COL_GROUP:
217 : pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
218 : rLName, xAttrList,
219 6 : false, true );
220 6 : break;
221 : case XML_TOK_TABLE_COLS_HEADER_COLS:
222 : pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
223 : rLName, xAttrList,
224 0 : true, false );
225 0 : break;
226 : case XML_TOK_TABLE_COLS_COLS:
227 : pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
228 : rLName, xAttrList,
229 0 : false, false );
230 0 : break;
231 : case XML_TOK_TABLE_COLS_COL:
232 : pContext = new ScXMLTableColContext( GetScImport(), nPrefix,
233 : rLName, xAttrList//,
234 : //this
235 14 : );
236 14 : break;
237 : }
238 :
239 20 : if( !pContext )
240 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
241 :
242 20 : return pContext;
243 : }
244 :
245 8 : void ScXMLTableColsContext::EndElement()
246 : {
247 8 : ScXMLImport& rXMLImport = GetScImport();
248 8 : if (bHeader)
249 : {
250 0 : nHeaderEndCol = rXMLImport.GetTables().GetCurrentColCount();
251 0 : nHeaderEndCol--;
252 0 : if (nHeaderStartCol <= nHeaderEndCol)
253 : {
254 0 : uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
255 0 : if (xPrintAreas.is())
256 : {
257 0 : if (!xPrintAreas->getPrintTitleColumns())
258 : {
259 0 : xPrintAreas->setPrintTitleColumns(true);
260 0 : table::CellRangeAddress aColumnHeaderRange;
261 0 : aColumnHeaderRange.StartColumn = nHeaderStartCol;
262 0 : aColumnHeaderRange.EndColumn = nHeaderEndCol;
263 0 : xPrintAreas->setTitleColumns(aColumnHeaderRange);
264 : }
265 : else
266 : {
267 0 : table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
268 0 : aColumnHeaderRange.EndColumn = nHeaderEndCol;
269 0 : xPrintAreas->setTitleColumns(aColumnHeaderRange);
270 : }
271 0 : }
272 : }
273 : }
274 8 : else if (bGroup)
275 : {
276 8 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
277 8 : nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
278 8 : nGroupEndCol--;
279 8 : if (nGroupStartCol <= nGroupEndCol)
280 : {
281 8 : ScDocument* pDoc = GetScImport().GetDocument();
282 8 : if (pDoc)
283 : {
284 8 : ScXMLImport::MutexGuard aGuard(GetScImport());
285 8 : ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
286 8 : if (pOutlineTable)
287 : {
288 8 : ScOutlineArray& rColArray = pOutlineTable->GetColArray();
289 : bool bResized;
290 8 : rColArray.Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, true);
291 8 : }
292 : }
293 : }
294 : }
295 164 : }
296 :
297 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|