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