Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "xmlcoli.hxx"
30 : : #include "xmlimprt.hxx"
31 : : #include "global.hxx"
32 : : #include "xmlstyli.hxx"
33 : : #include "document.hxx"
34 : : #include "docuno.hxx"
35 : : #include "olinetab.hxx"
36 : : #include "sheetdata.hxx"
37 : : #include "unonames.hxx"
38 : :
39 : : #include <xmloff/xmltkmap.hxx>
40 : : #include <xmloff/nmspmap.hxx>
41 : : #include <xmloff/xmlnmspe.hxx>
42 : : #include <xmloff/families.hxx>
43 : : #include <xmloff/xmltoken.hxx>
44 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
45 : : #include <com/sun/star/sheet/XSpreadsheet.hpp>
46 : : #include <com/sun/star/table/XColumnRowRange.hpp>
47 : : #include <com/sun/star/sheet/XPrintAreas.hpp>
48 : :
49 : : using namespace com::sun::star;
50 : : using namespace xmloff::token;
51 : :
52 : : //------------------------------------------------------------------
53 : :
54 : 329 : ScXMLTableColContext::ScXMLTableColContext( ScXMLImport& rImport,
55 : : sal_uInt16 nPrfx,
56 : : const ::rtl::OUString& rLName,
57 : : const ::com::sun::star::uno::Reference<
58 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) :
59 : : SvXMLImportContext( rImport, nPrfx, rLName ),
60 [ + - ]: 329 : sVisibility(GetXMLToken(XML_VISIBLE))
61 : : {
62 : 329 : nColCount = 1;
63 [ + - ][ + - ]: 329 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ + - ]
64 [ + - ]: 329 : const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableColAttrTokenMap();
65 : :
66 [ + + ]: 1139 : for( sal_Int16 i=0; i < nAttrCount; ++i )
67 : : {
68 [ + - ][ + - ]: 810 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
69 : 810 : rtl::OUString aLocalName;
70 : 810 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
71 [ + - ]: 810 : sAttrName, &aLocalName );
72 [ + - ][ + - ]: 810 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
73 : :
74 [ + - ][ + + : 810 : switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
- + - ]
75 : : {
76 : : case XML_TOK_TABLE_COL_ATTR_REPEATED:
77 : : {
78 : 152 : nColCount = sValue.toInt32();
79 : : }
80 : 152 : break;
81 : : case XML_TOK_TABLE_COL_ATTR_STYLE_NAME:
82 : : {
83 : 329 : sStyleName = sValue;
84 : : }
85 : 329 : break;
86 : : case XML_TOK_TABLE_COL_ATTR_VISIBILITY:
87 : : {
88 : 0 : sVisibility = sValue;
89 : : }
90 : 0 : break;
91 : : case XML_TOK_TABLE_COL_ATTR_DEFAULT_CELL_STYLE_NAME:
92 : : {
93 : 329 : sCellStyleName = sValue;
94 : : }
95 : 329 : break;
96 : : }
97 : 810 : }
98 : 329 : }
99 : :
100 : 329 : ScXMLTableColContext::~ScXMLTableColContext()
101 : : {
102 [ - + ]: 658 : }
103 : :
104 : 0 : SvXMLImportContext *ScXMLTableColContext::CreateChildContext( sal_uInt16 nPrefix,
105 : : const ::rtl::OUString& rLName,
106 : : const ::com::sun::star::uno::Reference<
107 : : ::com::sun::star::xml::sax::XAttributeList>& /* xAttrList */ )
108 : : {
109 : 0 : SvXMLImportContext *pContext = 0;
110 : :
111 [ # # ]: 0 : if( !pContext )
112 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
113 : :
114 : 0 : return pContext;
115 : : }
116 : :
117 : 329 : void ScXMLTableColContext::EndElement()
118 : : {
119 : 329 : ScXMLImport& rXMLImport = GetScImport();
120 : 329 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
121 : 329 : sal_Int32 nCurrentColumn = rXMLImport.GetTables().GetCurrentColCount();
122 [ + - ]: 329 : uno::Reference<sheet::XSpreadsheet> xSheet(rXMLImport.GetTables().GetCurrentXSheet());
123 [ + - ]: 329 : if(xSheet.is())
124 : : {
125 : 329 : sal_Int32 nLastColumn(nCurrentColumn + nColCount - 1);
126 [ - + ]: 329 : if (nLastColumn > MAXCOL)
127 : 0 : nLastColumn = MAXCOL;
128 [ - + ]: 329 : if (nCurrentColumn > MAXCOL)
129 : 0 : nCurrentColumn = MAXCOL;
130 [ + - ][ + - ]: 329 : uno::Reference<table::XColumnRowRange> xColumnRowRange (xSheet->getCellRangeByPosition(nCurrentColumn, 0, nLastColumn, 0), uno::UNO_QUERY);
[ + - ]
131 [ + - ]: 329 : if (xColumnRowRange.is())
132 : : {
133 [ + - ][ + - ]: 329 : uno::Reference <beans::XPropertySet> xColumnProperties(xColumnRowRange->getColumns(), uno::UNO_QUERY);
[ + - ]
134 [ + - ]: 329 : if (xColumnProperties.is())
135 : : {
136 [ + - ]: 329 : if (!sStyleName.isEmpty())
137 : : {
138 [ + - ]: 329 : XMLTableStylesContext *pStyles = (XMLTableStylesContext *)rXMLImport.GetAutoStyles();
139 [ + - ]: 329 : if ( pStyles )
140 : : {
141 : : XMLTableStyleContext* pStyle = (XMLTableStyleContext *)pStyles->FindStyleChildContext(
142 [ + - ]: 329 : XML_STYLE_FAMILY_TABLE_COLUMN, sStyleName, true);
143 [ + - ]: 329 : if (pStyle)
144 : : {
145 [ + - ]: 329 : pStyle->FillPropertySet(xColumnProperties);
146 : :
147 [ + + ]: 329 : if ( nSheet != pStyle->GetLastSheet() )
148 : : {
149 [ + - ][ + - ]: 304 : ScSheetSaveData* pSheetData = ScModelObj::getImplementation(rXMLImport.GetModel())->GetSheetSaveData();
150 [ + - ]: 304 : pSheetData->AddColumnStyle( sStyleName, ScAddress( (SCCOL)nCurrentColumn, 0, nSheet ) );
151 : 304 : pStyle->SetLastSheet(nSheet);
152 : : }
153 : : }
154 : : }
155 : : }
156 [ + - ]: 329 : rtl::OUString sVisible(RTL_CONSTASCII_USTRINGPARAM(SC_UNONAME_CELLVIS));
157 : 329 : bool bValue(true);
158 [ + - ][ - + ]: 329 : if (!IsXMLToken(sVisibility, XML_VISIBLE))
159 : 0 : bValue = false;
160 [ + - ][ + - ]: 329 : xColumnProperties->setPropertyValue(sVisible, uno::makeAny(bValue));
[ + - ]
161 : 329 : }
162 : 329 : }
163 : : }
164 : :
165 : : // #i57915# ScXMLImport::SetStyleToRange can't handle empty style names.
166 : : // The default for a column if there is no attribute is the style "Default" (programmatic API name).
167 [ - + ]: 329 : if ( sCellStyleName.isEmpty() )
168 [ # # ]: 0 : sCellStyleName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Default" ));
169 : :
170 [ + - ]: 329 : GetScImport().GetTables().AddColStyle(nColCount, sCellStyleName);
171 : 329 : }
172 : :
173 : 0 : ScXMLTableColsContext::ScXMLTableColsContext( ScXMLImport& rImport,
174 : : sal_uInt16 nPrfx,
175 : : const ::rtl::OUString& rLName,
176 : : const ::com::sun::star::uno::Reference<
177 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList,
178 : : const bool bTempHeader, const bool bTempGroup) :
179 : : SvXMLImportContext( rImport, nPrfx, rLName ),
180 : : nHeaderStartCol(0),
181 : : nHeaderEndCol(0),
182 : : nGroupStartCol(0),
183 : : nGroupEndCol(0),
184 : : bHeader(bTempHeader),
185 : : bGroup(bTempGroup),
186 : 0 : bGroupDisplay(true)
187 : : {
188 : : // don't have any attributes
189 [ # # ]: 0 : if (bHeader)
190 : 0 : nHeaderStartCol = rImport.GetTables().GetCurrentColCount();
191 [ # # ]: 0 : else if (bGroup)
192 : : {
193 : 0 : nGroupStartCol = rImport.GetTables().GetCurrentColCount();
194 [ # # ][ # # ]: 0 : sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
[ # # ]
195 [ # # ]: 0 : for( sal_Int16 i=0; i < nAttrCount; ++i )
196 : : {
197 [ # # ][ # # ]: 0 : const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
198 : 0 : rtl::OUString aLocalName;
199 : 0 : sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
200 [ # # ]: 0 : sAttrName, &aLocalName );
201 [ # # ][ # # ]: 0 : const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
202 : :
203 [ # # ][ # # ]: 0 : if (nPrefix == XML_NAMESPACE_TABLE && IsXMLToken(aLocalName, XML_DISPLAY))
[ # # ][ # # ]
204 : : {
205 [ # # ][ # # ]: 0 : if (IsXMLToken(sValue, XML_FALSE))
206 : 0 : bGroupDisplay = false;
207 : : }
208 : 0 : }
209 : : }
210 : 0 : }
211 : :
212 : 0 : ScXMLTableColsContext::~ScXMLTableColsContext()
213 : : {
214 [ # # ]: 0 : }
215 : :
216 : 0 : SvXMLImportContext *ScXMLTableColsContext::CreateChildContext( sal_uInt16 nPrefix,
217 : : const ::rtl::OUString& rLName,
218 : : const ::com::sun::star::uno::Reference<
219 : : ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
220 : : {
221 : 0 : SvXMLImportContext *pContext = 0;
222 : :
223 : 0 : const SvXMLTokenMap& rTokenMap = GetScImport().GetTableColsElemTokenMap();
224 [ # # # # : 0 : switch( rTokenMap.Get( nPrefix, rLName ) )
# ]
225 : : {
226 : : case XML_TOK_TABLE_COLS_COL_GROUP:
227 : : pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
228 : : rLName, xAttrList,
229 [ # # ]: 0 : false, true );
230 : 0 : break;
231 : : case XML_TOK_TABLE_COLS_HEADER_COLS:
232 : : pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
233 : : rLName, xAttrList,
234 [ # # ]: 0 : true, false );
235 : 0 : break;
236 : : case XML_TOK_TABLE_COLS_COLS:
237 : : pContext = new ScXMLTableColsContext( GetScImport(), nPrefix,
238 : : rLName, xAttrList,
239 [ # # ]: 0 : false, false );
240 : 0 : break;
241 : : case XML_TOK_TABLE_COLS_COL:
242 : : pContext = new ScXMLTableColContext( GetScImport(), nPrefix,
243 : : rLName, xAttrList//,
244 : : //this
245 [ # # ]: 0 : );
246 : 0 : break;
247 : : }
248 : :
249 [ # # ]: 0 : if( !pContext )
250 [ # # ]: 0 : pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
251 : :
252 : 0 : return pContext;
253 : : }
254 : :
255 : 0 : void ScXMLTableColsContext::EndElement()
256 : : {
257 : 0 : ScXMLImport& rXMLImport = GetScImport();
258 [ # # ]: 0 : if (bHeader)
259 : : {
260 : 0 : nHeaderEndCol = rXMLImport.GetTables().GetCurrentColCount();
261 : 0 : nHeaderEndCol--;
262 [ # # ]: 0 : if (nHeaderStartCol <= nHeaderEndCol)
263 : : {
264 [ # # ][ # # ]: 0 : uno::Reference <sheet::XPrintAreas> xPrintAreas (rXMLImport.GetTables().GetCurrentXSheet(), uno::UNO_QUERY);
265 [ # # ]: 0 : if (xPrintAreas.is())
266 : : {
267 [ # # ][ # # ]: 0 : if (!xPrintAreas->getPrintTitleColumns())
[ # # ]
268 : : {
269 [ # # ][ # # ]: 0 : xPrintAreas->setPrintTitleColumns(true);
270 : 0 : table::CellRangeAddress aColumnHeaderRange;
271 : 0 : aColumnHeaderRange.StartColumn = nHeaderStartCol;
272 : 0 : aColumnHeaderRange.EndColumn = nHeaderEndCol;
273 [ # # ][ # # ]: 0 : xPrintAreas->setTitleColumns(aColumnHeaderRange);
274 : : }
275 : : else
276 : : {
277 [ # # ][ # # ]: 0 : table::CellRangeAddress aColumnHeaderRange(xPrintAreas->getTitleColumns());
278 : 0 : aColumnHeaderRange.EndColumn = nHeaderEndCol;
279 [ # # ][ # # ]: 0 : xPrintAreas->setTitleColumns(aColumnHeaderRange);
280 : : }
281 : 0 : }
282 : : }
283 : : }
284 [ # # ]: 0 : else if (bGroup)
285 : : {
286 : 0 : SCTAB nSheet = rXMLImport.GetTables().GetCurrentSheet();
287 : 0 : nGroupEndCol = rXMLImport.GetTables().GetCurrentColCount();
288 : 0 : nGroupEndCol--;
289 [ # # ]: 0 : if (nGroupStartCol <= nGroupEndCol)
290 : : {
291 : 0 : ScDocument* pDoc = GetScImport().GetDocument();
292 [ # # ]: 0 : if (pDoc)
293 : : {
294 [ # # ]: 0 : ScXMLImport::MutexGuard aGuard(GetScImport());
295 [ # # ]: 0 : ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(nSheet, true);
296 [ # # ]: 0 : ScOutlineArray* pColArray = pOutlineTable ? pOutlineTable->GetColArray() : NULL;
297 [ # # ]: 0 : if (pColArray)
298 : : {
299 : : bool bResized;
300 [ # # ]: 0 : pColArray->Insert(static_cast<SCCOL>(nGroupStartCol), static_cast<SCCOL>(nGroupEndCol), bResized, !bGroupDisplay, true);
301 [ # # ]: 0 : }
302 : : }
303 : : }
304 : : }
305 : 0 : }
306 : :
307 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|