bump product version to 4.1.6.2
[LibreOffice.git] / svl / source / items / macitem.cxx
blobcd812c6c16d0d54333e69bf8235eb4df2a9ade1d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/stream.hxx>
22 #include <svl/macitem.hxx>
24 // STATIC DATA -----------------------------------------------------------
26 DBG_NAME(SvxMacroItem);
28 // -----------------------------------------------------------------------
30 TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0));
32 // -----------------------------------------------------------------------
35 SjJSbxObjectBase::~SjJSbxObjectBase()
39 SjJSbxObjectBase* SjJSbxObjectBase::Clone( void )
41 return NULL;
44 SvxMacro::SvxMacro( const OUString &rMacName, const OUString &rLanguage)
45 : aMacName( rMacName ), aLibName( rLanguage),
46 pFunctionObject(NULL), eType( EXTENDED_STYPE)
48 if ( rLanguage == SVX_MACRO_LANGUAGE_STARBASIC )
49 eType=STARBASIC;
50 else if ( rLanguage == SVX_MACRO_LANGUAGE_JAVASCRIPT )
51 eType=JAVASCRIPT;
55 SvxMacro::~SvxMacro()
57 delete pFunctionObject;
60 OUString SvxMacro::GetLanguage()const
62 if(eType==STARBASIC)
64 return OUString(SVX_MACRO_LANGUAGE_STARBASIC);
66 else if(eType==JAVASCRIPT)
68 return OUString(SVX_MACRO_LANGUAGE_JAVASCRIPT);
70 else if(eType==EXTENDED_STYPE)
72 return OUString(SVX_MACRO_LANGUAGE_SF);
75 return aLibName;
80 SvxMacro& SvxMacro::operator=( const SvxMacro& rBase )
82 if( this != &rBase )
84 aMacName = rBase.aMacName;
85 aLibName = rBase.aLibName;
86 delete pFunctionObject;
87 pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL;
88 eType = rBase.eType;
90 return *this;
93 // -----------------------------------------------------------------------
95 SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl )
97 aSvxMacroTable.clear();
98 aSvxMacroTable.insert(rTbl.aSvxMacroTable.begin(), rTbl.aSvxMacroTable.end());
99 return *this;
102 int SvxMacroTableDtor::operator==( const SvxMacroTableDtor& rOther ) const
104 // Anzahl unterschiedlich => auf jeden Fall ungleich
105 if ( aSvxMacroTable.size() != rOther.aSvxMacroTable.size() )
106 return sal_False;
108 // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig
109 SvxMacroTable::const_iterator it1 = aSvxMacroTable.begin();
110 SvxMacroTable::const_iterator it2 = rOther.aSvxMacroTable.begin();
111 for ( ; it1 != aSvxMacroTable.end(); ++it1, ++it2 )
113 const SvxMacro& rOwnMac = it1->second;
114 const SvxMacro& rOtherMac = it2->second;
115 if ( it1->first != it2->first ||
116 rOwnMac.GetLibName() != rOtherMac.GetLibName() ||
117 rOwnMac.GetMacName() != rOtherMac.GetMacName() )
118 return sal_False;
121 return sal_True;
124 SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, sal_uInt16 nVersion )
126 if( SVX_MACROTBL_VERSION40 <= nVersion )
127 rStrm >> nVersion;
128 short nMacro;
129 rStrm >> nMacro;
131 for( short i = 0; i < nMacro; ++i )
133 sal_uInt16 nCurKey, eType = STARBASIC;
134 String aLibName, aMacName;
135 rStrm >> nCurKey;
136 aLibName = SfxPoolItem::readByteString(rStrm);
137 aMacName = SfxPoolItem::readByteString(rStrm);
139 if( SVX_MACROTBL_VERSION40 <= nVersion )
140 rStrm >> eType;
142 aSvxMacroTable.insert( SvxMacroTable::value_type(nCurKey, SvxMacro( aMacName, aLibName, (ScriptType)eType ) ));
144 return rStrm;
148 SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const
150 sal_uInt16 nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion()
151 ? SVX_MACROTBL_VERSION31
152 : SVX_MACROTBL_AKTVERSION;
154 if( SVX_MACROTBL_VERSION40 <= nVersion )
155 rStream << nVersion;
157 rStream << (sal_uInt16)aSvxMacroTable.size();
159 SvxMacroTable::const_iterator it = aSvxMacroTable.begin();
160 while( it != aSvxMacroTable.end() && rStream.GetError() == SVSTREAM_OK )
162 const SvxMacro& rMac = it->second;
163 rStream << it->first;
164 SfxPoolItem::writeByteString(rStream, rMac.GetLibName());
165 SfxPoolItem::writeByteString(rStream, rMac.GetMacName());
167 if( SVX_MACROTBL_VERSION40 <= nVersion )
168 rStream << (sal_uInt16)rMac.GetScriptType();
169 ++it;
171 return rStream;
174 // returns NULL if no entry exists, or a pointer to the internal value
175 const SvxMacro* SvxMacroTableDtor::Get(sal_uInt16 nEvent) const
177 SvxMacroTable::const_iterator it = aSvxMacroTable.find(nEvent);
178 return it == aSvxMacroTable.end() ? NULL : &(it->second);
181 // returns NULL if no entry exists, or a pointer to the internal value
182 SvxMacro* SvxMacroTableDtor::Get(sal_uInt16 nEvent)
184 SvxMacroTable::iterator it = aSvxMacroTable.find(nEvent);
185 return it == aSvxMacroTable.end() ? NULL : &(it->second);
188 // return true if the key exists
189 bool SvxMacroTableDtor::IsKeyValid(sal_uInt16 nEvent) const
191 SvxMacroTable::const_iterator it = aSvxMacroTable.find(nEvent);
192 return it != aSvxMacroTable.end();
195 // This stores a copy of the rMacro parameter
196 SvxMacro& SvxMacroTableDtor::Insert(sal_uInt16 nEvent, const SvxMacro& rMacro)
198 return aSvxMacroTable.insert( SvxMacroTable::value_type( nEvent, rMacro ) ).first->second;
201 // If the entry exists, remove it from the map and release it's storage
202 sal_Bool SvxMacroTableDtor::Erase(sal_uInt16 nEvent)
204 SvxMacroTable::iterator it = aSvxMacroTable.find(nEvent);
205 if ( it != aSvxMacroTable.end())
207 aSvxMacroTable.erase(it);
208 return sal_True;
210 return sal_False;
213 // -----------------------------------------------------------------------
215 int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const
217 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
219 const SvxMacroTableDtor& rOwn = aMacroTable;
220 const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable;
222 return rOwn == rOther;
225 // -----------------------------------------------------------------------
227 SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const
229 return new SvxMacroItem( *this );
232 //------------------------------------------------------------------------
234 SfxItemPresentation SvxMacroItem::GetPresentation
236 SfxItemPresentation /*ePres*/,
237 SfxMapUnit /*eCoreUnit*/,
238 SfxMapUnit /*ePresUnit*/,
239 OUString& rText,
240 const IntlWrapper *
241 ) const
243 /*!!!
244 SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable();
245 SvxMacro* pMac = rTbl.First();
247 while ( pMac )
249 rText += pMac->GetLibName();
250 rText += cpDelim;
251 rText += pMac->GetMacName();
252 pMac = rTbl.Next();
253 if ( pMac )
254 rText += cpDelim;
257 rText = OUString();
258 return SFX_ITEM_PRESENTATION_NONE;
261 // -----------------------------------------------------------------------
263 SvStream& SvxMacroItem::Store( SvStream& rStrm , sal_uInt16 ) const
265 return aMacroTable.Write( rStrm );
268 // -----------------------------------------------------------------------
270 SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
272 SvxMacroItem* pAttr = new SvxMacroItem( Which() );
273 pAttr->aMacroTable.Read( rStrm, nVersion );
274 return pAttr;
277 // -----------------------------------------------------------------------
279 void SvxMacroItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
281 aMacroTable.Insert( nEvent, rMacro);
284 // -----------------------------------------------------------------------
286 sal_uInt16 SvxMacroItem::GetVersion( sal_uInt16 nFileFormatVersion ) const
288 return SOFFICE_FILEFORMAT_31 == nFileFormatVersion
289 ? 0 : aMacroTable.GetVersion();
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */