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