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