merge the formfield patch from ooo-build
[ooovba.git] / sc / source / filter / xml / sheetdata.cxx
bloba8b96eb6d768f3d2c8e093f1d3373f3b26540d29
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sheetdata.cxx,v $
10 * $Revision: 1.69.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // INCLUDE ---------------------------------------------------------------
36 #include <xmloff/families.hxx>
37 #include <xmloff/xmlaustp.hxx>
38 #include <xmloff/nmspmap.hxx>
39 #include <tools/string.hxx>
40 #include <tools/debug.hxx>
42 #include "sheetdata.hxx"
44 // -----------------------------------------------------------------------
46 ScSheetSaveData::ScSheetSaveData() :
47 mnStartTab( -1 ),
48 mnStartOffset( -1 ),
49 maPreviousNote( rtl::OUString(), rtl::OUString(), ScAddress(ScAddress::INITIALIZE_INVALID) )
53 ScSheetSaveData::~ScSheetSaveData()
57 void ScSheetSaveData::AddCellStyle( const rtl::OUString& rName, const ScAddress& rCellPos )
59 maCellStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
62 void ScSheetSaveData::AddColumnStyle( const rtl::OUString& rName, const ScAddress& rCellPos )
64 maColumnStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
67 void ScSheetSaveData::AddRowStyle( const rtl::OUString& rName, const ScAddress& rCellPos )
69 maRowStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
72 void ScSheetSaveData::AddTableStyle( const rtl::OUString& rName, const ScAddress& rCellPos )
74 maTableStyles.push_back( ScCellStyleEntry( rName, rCellPos ) );
77 void ScSheetSaveData::HandleNoteStyles( const rtl::OUString& rStyleName, const rtl::OUString& rTextName, const ScAddress& rCellPos )
79 // only consecutive duplicates (most common case) are filtered out here,
80 // the others are found when the styles are created
82 if ( rStyleName == maPreviousNote.maStyleName &&
83 rTextName == maPreviousNote.maTextStyle &&
84 rCellPos.Tab() == maPreviousNote.maCellPos.Tab() )
86 // already stored for the same sheet - ignore
87 return;
90 ScNoteStyleEntry aNewEntry( rStyleName, rTextName, rCellPos );
91 maPreviousNote = aNewEntry;
92 maNoteStyles.push_back( aNewEntry );
95 void ScSheetSaveData::AddNoteContentStyle( sal_uInt16 nFamily, const rtl::OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection )
97 if ( nFamily == XML_STYLE_FAMILY_TEXT_PARAGRAPH )
98 maNoteParaStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
99 else
100 maNoteTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
103 void ScSheetSaveData::AddTextStyle( const rtl::OUString& rName, const ScAddress& rCellPos, const ESelection& rSelection )
105 maTextStyles.push_back( ScTextStyleEntry( rName, rCellPos, rSelection ) );
108 void ScSheetSaveData::BlockSheet( sal_Int32 nTab )
110 if ( nTab >= (sal_Int32)maBlocked.size() )
111 maBlocked.resize( nTab + 1, false ); // fill vector with "false" entries
113 maBlocked[nTab] = true;
116 bool ScSheetSaveData::IsSheetBlocked( sal_Int32 nTab ) const
118 if ( nTab < (sal_Int32)maBlocked.size() )
119 return maBlocked[nTab];
120 else
121 return false;
124 void ScSheetSaveData::AddStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
126 if ( nTab >= (sal_Int32)maStreamEntries.size() )
127 maStreamEntries.resize( nTab + 1 );
129 maStreamEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
132 void ScSheetSaveData::StartStreamPos( sal_Int32 nTab, sal_Int32 nStartOffset )
134 DBG_ASSERT( mnStartTab < 0, "StartStreamPos without EndStreamPos" );
136 mnStartTab = nTab;
137 mnStartOffset = nStartOffset;
140 void ScSheetSaveData::EndStreamPos( sal_Int32 nEndOffset )
142 if ( mnStartTab >= 0 )
144 AddStreamPos( mnStartTab, mnStartOffset, nEndOffset );
145 mnStartTab = -1;
146 mnStartOffset = -1;
150 void ScSheetSaveData::GetStreamPos( sal_Int32 nTab, sal_Int32& rStartOffset, sal_Int32& rEndOffset ) const
152 if ( nTab < (sal_Int32)maStreamEntries.size() )
154 const ScStreamEntry& rEntry = maStreamEntries[nTab];
155 rStartOffset = rEntry.mnStartOffset;
156 rEndOffset = rEntry.mnEndOffset;
158 else
159 rStartOffset = rEndOffset = -1;
162 bool ScSheetSaveData::HasStreamPos( sal_Int32 nTab ) const
164 sal_Int32 nStartOffset = -1;
165 sal_Int32 nEndOffset = -1;
166 GetStreamPos( nTab, nStartOffset, nEndOffset );
167 return ( nStartOffset >= 0 && nEndOffset >= 0 );
170 void ScSheetSaveData::ResetSaveEntries()
172 maSaveEntries.clear();
175 void ScSheetSaveData::AddSavePos( sal_Int32 nTab, sal_Int32 nStartOffset, sal_Int32 nEndOffset )
177 if ( nTab >= (sal_Int32)maSaveEntries.size() )
178 maSaveEntries.resize( nTab + 1 );
180 maSaveEntries[nTab] = ScStreamEntry( nStartOffset, nEndOffset );
183 void ScSheetSaveData::UseSaveEntries()
185 maStreamEntries = maSaveEntries;
188 void ScSheetSaveData::StoreInitialNamespaces( const SvXMLNamespaceMap& rNamespaces )
190 // the initial namespaces are just removed from the list of loaded namespaces,
191 // so only a hash_set of the prefixes is needed.
193 const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
194 NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
195 while (aIter != aEnd)
197 maInitialPrefixes.insert( aIter->first );
198 ++aIter;
202 void ScSheetSaveData::StoreLoadedNamespaces( const SvXMLNamespaceMap& rNamespaces )
204 // store the loaded namespaces, so the prefixes in copied stream fragments remain valid
206 const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
207 NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
208 while (aIter != aEnd)
210 // ignore the initial namespaces
211 if ( maInitialPrefixes.find( aIter->first ) == maInitialPrefixes.end() )
213 const NameSpaceEntry& rEntry = aIter->second.getBody();
214 maLoadedNamespaces.push_back( ScLoadedNamespaceEntry( rEntry.sPrefix, rEntry.sName, rEntry.nKey ) );
216 ++aIter;
220 bool lcl_NameInHash( const NameSpaceHash& rNameHash, const rtl::OUString& rName )
222 NameSpaceHash::const_iterator aIter = rNameHash.begin(), aEnd = rNameHash.end();
223 while (aIter != aEnd)
225 if ( aIter->second->sName == rName )
226 return true;
228 ++aIter;
230 return false; // not found
233 bool ScSheetSaveData::AddLoadedNamespaces( SvXMLNamespaceMap& rNamespaces ) const
235 // Add the loaded namespaces to the name space map.
237 // first loop: only look for conflicts
238 // (if the loaded namespaces were added first, this might not be necessary)
239 const NameSpaceHash& rNameHash = rNamespaces.GetAllEntries();
240 std::vector<ScLoadedNamespaceEntry>::const_iterator aIter = maLoadedNamespaces.begin();
241 std::vector<ScLoadedNamespaceEntry>::const_iterator aEnd = maLoadedNamespaces.end();
242 while (aIter != aEnd)
244 NameSpaceHash::const_iterator aHashIter = rNameHash.find( aIter->maPrefix );
245 if ( aHashIter == rNameHash.end() )
247 if ( lcl_NameInHash( rNameHash, aIter->maName ) )
249 // a second prefix for the same name would confuse SvXMLNamespaceMap lookup,
250 // so this is also considered a conflict
251 return false;
254 else if ( aHashIter->second->sName != aIter->maName )
256 // same prefix, but different name: loaded namespaces can't be used
257 return false;
259 ++aIter;
262 // only if there were no conflicts, add the entries that aren't in the map already
263 // (the key is needed if the same namespace is added later within an element)
264 aIter = maLoadedNamespaces.begin();
265 while (aIter != aEnd)
267 NameSpaceHash::const_iterator aHashIter = rNameHash.find( aIter->maPrefix );
268 if ( aHashIter == rNameHash.end() )
269 rNamespaces.Add( aIter->maPrefix, aIter->maName, aIter->mnKey );
270 ++aIter;
273 return true; // success