1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svl.hxx" 30 #include <tools/stream.hxx> 31 32 #ifndef GCC 33 #endif 34 35 #include <svl/macitem.hxx> 36 37 // STATIC DATA ----------------------------------------------------------- 38 39 DBG_NAME(SvxMacroItem); 40 41 // ----------------------------------------------------------------------- 42 43 TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0)); 44 45 // ----------------------------------------------------------------------- 46 47 48 SjJSbxObjectBase::~SjJSbxObjectBase() 49 { 50 } 51 52 SjJSbxObjectBase* SjJSbxObjectBase::Clone( void ) 53 { 54 return NULL; 55 } 56 57 SvxMacro::SvxMacro( const String &rMacName, const String &rLanguage) 58 : aMacName( rMacName ), aLibName( rLanguage), 59 pFunctionObject(NULL), eType( EXTENDED_STYPE) 60 { 61 if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_STARBASIC)) 62 eType=STARBASIC; 63 else if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT)) 64 eType=JAVASCRIPT; 65 } 66 67 68 SvxMacro::~SvxMacro() 69 { 70 delete pFunctionObject; 71 } 72 73 String SvxMacro::GetLanguage()const 74 { 75 if(eType==STARBASIC) 76 { 77 return UniString::CreateFromAscii( 78 RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_STARBASIC)); 79 } 80 else if(eType==JAVASCRIPT) 81 { 82 return UniString::CreateFromAscii( 83 RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_JAVASCRIPT)); 84 } 85 else if(eType==EXTENDED_STYPE) 86 { 87 return UniString::CreateFromAscii( 88 RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_SF)); 89 90 } 91 return aLibName; 92 } 93 94 95 96 SvxMacro& SvxMacro::operator=( const SvxMacro& rBase ) 97 { 98 if( this != &rBase ) 99 { 100 aMacName = rBase.aMacName; 101 aLibName = rBase.aLibName; 102 delete pFunctionObject; 103 pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL; 104 eType = rBase.eType; 105 } 106 return *this; 107 } 108 109 110 SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl ) 111 { 112 DelDtor(); 113 SvxMacro* pTmp = ((SvxMacroTableDtor&)rTbl).First(); 114 while( pTmp ) 115 { 116 SvxMacro *pNew = new SvxMacro( *pTmp ); 117 Insert( rTbl.GetCurKey(), pNew ); 118 pTmp = ((SvxMacroTableDtor&)rTbl).Next(); 119 } 120 return *this; 121 } 122 123 124 SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, sal_uInt16 nVersion ) 125 { 126 if( SVX_MACROTBL_VERSION40 <= nVersion ) 127 rStrm >> nVersion; 128 short nMacro; 129 rStrm >> nMacro; 130 131 for( short i = 0; i < nMacro; ++i ) 132 { 133 sal_uInt16 nCurKey, eType = STARBASIC; 134 String aLibName, aMacName; 135 rStrm >> nCurKey; 136 SfxPoolItem::readByteString(rStrm, aLibName); 137 SfxPoolItem::readByteString(rStrm, aMacName); 138 139 if( SVX_MACROTBL_VERSION40 <= nVersion ) 140 rStrm >> eType; 141 142 SvxMacro* pNew = new SvxMacro( aMacName, aLibName, (ScriptType)eType ); 143 144 SvxMacro *pOld = Get( nCurKey ); 145 if( pOld ) 146 { 147 delete pOld; 148 Replace( nCurKey, pNew ); 149 } 150 else 151 Insert( nCurKey, pNew ); 152 } 153 return rStrm; 154 } 155 156 157 SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const 158 { 159 sal_uInt16 nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion() 160 ? SVX_MACROTBL_VERSION31 161 : SVX_MACROTBL_AKTVERSION; 162 163 if( SVX_MACROTBL_VERSION40 <= nVersion ) 164 rStream << nVersion; 165 166 rStream << (sal_uInt16)Count(); 167 168 SvxMacro* pMac = ((SvxMacroTableDtor*)this)->First(); 169 while( pMac && rStream.GetError() == SVSTREAM_OK ) 170 { 171 rStream << (short)GetCurKey(); 172 SfxPoolItem::writeByteString(rStream, pMac->GetLibName()); 173 SfxPoolItem::writeByteString(rStream, pMac->GetMacName()); 174 175 if( SVX_MACROTBL_VERSION40 <= nVersion ) 176 rStream << (sal_uInt16)pMac->GetScriptType(); 177 pMac = ((SvxMacroTableDtor*)this)->Next(); 178 } 179 return rStream; 180 } 181 182 // ----------------------------------------------------------------------- 183 184 void SvxMacroTableDtor::DelDtor() 185 { 186 SvxMacro* pTmp = First(); 187 while( pTmp ) 188 { 189 delete pTmp; 190 pTmp = Next(); 191 } 192 Clear(); 193 } 194 195 // ----------------------------------------------------------------------- 196 197 int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const 198 { 199 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); 200 201 const SvxMacroTableDtor& rOwn = aMacroTable; 202 const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable; 203 204 // Anzahl unterschiedlich => auf jeden Fall ungleich 205 if ( rOwn.Count() != rOther.Count() ) 206 return sal_False; 207 208 // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig 209 for ( sal_uInt16 nNo = 0; nNo < rOwn.Count(); ++nNo ) 210 { 211 const SvxMacro *pOwnMac = rOwn.GetObject(nNo); 212 const SvxMacro *pOtherMac = rOther.GetObject(nNo); 213 if ( rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac) || 214 pOwnMac->GetLibName() != pOtherMac->GetLibName() || 215 pOwnMac->GetMacName() != pOtherMac->GetMacName() ) 216 return sal_False; 217 } 218 219 return sal_True; 220 } 221 222 // ----------------------------------------------------------------------- 223 224 SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const 225 { 226 return new SvxMacroItem( *this ); 227 } 228 229 //------------------------------------------------------------------------ 230 231 SfxItemPresentation SvxMacroItem::GetPresentation 232 ( 233 SfxItemPresentation /*ePres*/, 234 SfxMapUnit /*eCoreUnit*/, 235 SfxMapUnit /*ePresUnit*/, 236 XubString& rText, 237 const IntlWrapper * 238 ) const 239 { 240 /*!!! 241 SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable(); 242 SvxMacro* pMac = rTbl.First(); 243 244 while ( pMac ) 245 { 246 rText += pMac->GetLibName(); 247 rText += cpDelim; 248 rText += pMac->GetMacName(); 249 pMac = rTbl.Next(); 250 if ( pMac ) 251 rText += cpDelim; 252 } 253 */ 254 rText.Erase(); 255 return SFX_ITEM_PRESENTATION_NONE; 256 } 257 258 // ----------------------------------------------------------------------- 259 260 SvStream& SvxMacroItem::Store( SvStream& rStrm , sal_uInt16 ) const 261 { 262 return aMacroTable.Write( rStrm ); 263 } 264 265 // ----------------------------------------------------------------------- 266 267 SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const 268 { 269 SvxMacroItem* pAttr = new SvxMacroItem( Which() ); 270 pAttr->aMacroTable.Read( rStrm, nVersion ); 271 return pAttr; 272 } 273 274 // ----------------------------------------------------------------------- 275 276 void SvxMacroItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro ) 277 { 278 SvxMacro *pMacro; 279 if ( 0 != (pMacro=aMacroTable.Get(nEvent)) ) 280 { 281 delete pMacro; 282 aMacroTable.Replace(nEvent, new SvxMacro( rMacro ) ); 283 } 284 else 285 aMacroTable.Insert(nEvent, new SvxMacro( rMacro ) ); 286 } 287 288 // ----------------------------------------------------------------------- 289 290 sal_uInt16 SvxMacroItem::GetVersion( sal_uInt16 nFileFormatVersion ) const 291 { 292 return SOFFICE_FILEFORMAT_31 == nFileFormatVersion 293 ? 0 : aMacroTable.GetVersion(); 294 } 295 296