merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items / macitem.cxx
blob255989c73a1a19f5e9a6e68031291edade26afb6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: macitem.cxx,v $
10 * $Revision: 1.11 $
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_svtools.hxx"
33 #include <tools/stream.hxx>
35 #ifndef GCC
36 #endif
38 #include <svtools/macitem.hxx>
40 // STATIC DATA -----------------------------------------------------------
42 DBG_NAME(SvxMacroItem);
44 // -----------------------------------------------------------------------
46 TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0));
48 // -----------------------------------------------------------------------
51 SjJSbxObjectBase::~SjJSbxObjectBase()
55 SjJSbxObjectBase* SjJSbxObjectBase::Clone( void )
57 return NULL;
60 SvxMacro::SvxMacro( const String &rMacName, const String &rLanguage)
61 : aMacName( rMacName ), aLibName( rLanguage),
62 pFunctionObject(NULL), eType( EXTENDED_STYPE)
64 if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_STARBASIC))
65 eType=STARBASIC;
66 else if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT))
67 eType=JAVASCRIPT;
71 SvxMacro::~SvxMacro()
73 delete pFunctionObject;
76 String SvxMacro::GetLanguage()const
78 if(eType==STARBASIC)
80 return UniString::CreateFromAscii(
81 RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_STARBASIC));
83 else if(eType==JAVASCRIPT)
85 return UniString::CreateFromAscii(
86 RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_JAVASCRIPT));
88 else if(eType==EXTENDED_STYPE)
90 return UniString::CreateFromAscii(
91 RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_SF));
94 return aLibName;
99 SvxMacro& SvxMacro::operator=( const SvxMacro& rBase )
101 if( this != &rBase )
103 aMacName = rBase.aMacName;
104 aLibName = rBase.aLibName;
105 delete pFunctionObject;
106 pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL;
107 eType = rBase.eType;
109 return *this;
113 SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl )
115 DelDtor();
116 SvxMacro* pTmp = ((SvxMacroTableDtor&)rTbl).First();
117 while( pTmp )
119 SvxMacro *pNew = new SvxMacro( *pTmp );
120 Insert( rTbl.GetCurKey(), pNew );
121 pTmp = ((SvxMacroTableDtor&)rTbl).Next();
123 return *this;
127 SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, USHORT nVersion )
129 if( SVX_MACROTBL_VERSION40 <= nVersion )
130 rStrm >> nVersion;
131 short nMacro;
132 rStrm >> nMacro;
134 for( short i = 0; i < nMacro; ++i )
136 USHORT nCurKey, eType = STARBASIC;
137 String aLibName, aMacName;
138 rStrm >> nCurKey;
139 SfxPoolItem::readByteString(rStrm, aLibName);
140 SfxPoolItem::readByteString(rStrm, aMacName);
142 if( SVX_MACROTBL_VERSION40 <= nVersion )
143 rStrm >> eType;
145 SvxMacro* pNew = new SvxMacro( aMacName, aLibName, (ScriptType)eType );
147 SvxMacro *pOld = Get( nCurKey );
148 if( pOld )
150 delete pOld;
151 Replace( nCurKey, pNew );
153 else
154 Insert( nCurKey, pNew );
156 return rStrm;
160 SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const
162 USHORT nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion()
163 ? SVX_MACROTBL_VERSION31
164 : SVX_MACROTBL_AKTVERSION;
166 if( SVX_MACROTBL_VERSION40 <= nVersion )
167 rStream << nVersion;
169 rStream << (USHORT)Count();
171 SvxMacro* pMac = ((SvxMacroTableDtor*)this)->First();
172 while( pMac && rStream.GetError() == SVSTREAM_OK )
174 rStream << (short)GetCurKey();
175 SfxPoolItem::writeByteString(rStream, pMac->GetLibName());
176 SfxPoolItem::writeByteString(rStream, pMac->GetMacName());
178 if( SVX_MACROTBL_VERSION40 <= nVersion )
179 rStream << (USHORT)pMac->GetScriptType();
180 pMac = ((SvxMacroTableDtor*)this)->Next();
182 return rStream;
185 // -----------------------------------------------------------------------
187 void SvxMacroTableDtor::DelDtor()
189 SvxMacro* pTmp = First();
190 while( pTmp )
192 delete pTmp;
193 pTmp = Next();
195 Clear();
198 // -----------------------------------------------------------------------
200 int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const
202 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
204 const SvxMacroTableDtor& rOwn = aMacroTable;
205 const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable;
207 // Anzahl unterschiedlich => auf jeden Fall ungleich
208 if ( rOwn.Count() != rOther.Count() )
209 return FALSE;
211 // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig
212 for ( USHORT nNo = 0; nNo < rOwn.Count(); ++nNo )
214 const SvxMacro *pOwnMac = rOwn.GetObject(nNo);
215 const SvxMacro *pOtherMac = rOther.GetObject(nNo);
216 if ( rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac) ||
217 pOwnMac->GetLibName() != pOtherMac->GetLibName() ||
218 pOwnMac->GetMacName() != pOtherMac->GetMacName() )
219 return FALSE;
222 return TRUE;
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 XubString& 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.Erase();
258 return SFX_ITEM_PRESENTATION_NONE;
261 // -----------------------------------------------------------------------
263 SvStream& SvxMacroItem::Store( SvStream& rStrm , USHORT ) const
265 return aMacroTable.Write( rStrm );
268 // -----------------------------------------------------------------------
270 SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, USHORT nVersion ) const
272 SvxMacroItem* pAttr = new SvxMacroItem( Which() );
273 pAttr->aMacroTable.Read( rStrm, nVersion );
274 return pAttr;
277 // -----------------------------------------------------------------------
279 void SvxMacroItem::SetMacro( USHORT nEvent, const SvxMacro& rMacro )
281 SvxMacro *pMacro;
282 if ( 0 != (pMacro=aMacroTable.Get(nEvent)) )
284 delete pMacro;
285 aMacroTable.Replace(nEvent, new SvxMacro( rMacro ) );
287 else
288 aMacroTable.Insert(nEvent, new SvxMacro( rMacro ) );
291 // -----------------------------------------------------------------------
293 USHORT SvxMacroItem::GetVersion( USHORT nFileFormatVersion ) const
295 return SOFFICE_FILEFORMAT_31 == nFileFormatVersion
296 ? 0 : aMacroTable.GetVersion();