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: macitem.cxx,v $
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>
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 )
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
))
66 else if (rLanguage
.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT
))
73 delete pFunctionObject
;
76 String
SvxMacro::GetLanguage()const
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
));
99 SvxMacro
& SvxMacro::operator=( const SvxMacro
& rBase
)
103 aMacName
= rBase
.aMacName
;
104 aLibName
= rBase
.aLibName
;
105 delete pFunctionObject
;
106 pFunctionObject
= rBase
.pFunctionObject
? rBase
.pFunctionObject
->Clone() : NULL
;
113 SvxMacroTableDtor
& SvxMacroTableDtor::operator=( const SvxMacroTableDtor
& rTbl
)
116 SvxMacro
* pTmp
= ((SvxMacroTableDtor
&)rTbl
).First();
119 SvxMacro
*pNew
= new SvxMacro( *pTmp
);
120 Insert( rTbl
.GetCurKey(), pNew
);
121 pTmp
= ((SvxMacroTableDtor
&)rTbl
).Next();
127 SvStream
& SvxMacroTableDtor::Read( SvStream
& rStrm
, USHORT nVersion
)
129 if( SVX_MACROTBL_VERSION40
<= nVersion
)
134 for( short i
= 0; i
< nMacro
; ++i
)
136 USHORT nCurKey
, eType
= STARBASIC
;
137 String aLibName
, aMacName
;
139 SfxPoolItem::readByteString(rStrm
, aLibName
);
140 SfxPoolItem::readByteString(rStrm
, aMacName
);
142 if( SVX_MACROTBL_VERSION40
<= nVersion
)
145 SvxMacro
* pNew
= new SvxMacro( aMacName
, aLibName
, (ScriptType
)eType
);
147 SvxMacro
*pOld
= Get( nCurKey
);
151 Replace( nCurKey
, pNew
);
154 Insert( nCurKey
, pNew
);
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
)
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();
185 // -----------------------------------------------------------------------
187 void SvxMacroTableDtor::DelDtor()
189 SvxMacro
* pTmp
= First();
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() )
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() )
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*/,
244 SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable();
245 SvxMacro* pMac = rTbl.First();
249 rText += pMac->GetLibName();
251 rText += pMac->GetMacName();
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
);
277 // -----------------------------------------------------------------------
279 void SvxMacroItem::SetMacro( USHORT nEvent
, const SvxMacro
& rMacro
)
282 if ( 0 != (pMacro
=aMacroTable
.Get(nEvent
)) )
285 aMacroTable
.Replace(nEvent
, new SvxMacro( rMacro
) );
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();