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_svx.hxx" 26 27 // include --------------------------------------------------------------- 28 #define _SVX_HLNKITEM_CXX 29 30 #ifndef _SVX_SVXIDS_HRC 31 #include <svx/svxids.hrc> 32 #endif 33 #include <tools/stream.hxx> 34 35 #ifndef _MEMBERID_HRC 36 #include <svx/memberid.hrc> 37 #endif 38 39 #ifndef __SBX_SBXVARIABLE_HXX 40 #include <basic/sbxvar.hxx> 41 #endif 42 43 #include "svx/hlnkitem.hxx" 44 45 // ----------------------------------------------------------------------- 46 47 TYPEINIT1_FACTORY(SvxHyperlinkItem, SfxPoolItem, new SvxHyperlinkItem(0)); 48 49 // class SvxHyperlinkItem ------------------------------------------------ 50 51 /*-------------------------------------------------------------------- 52 Beschreibung: 53 --------------------------------------------------------------------*/ 54 55 #define HYPERLINKFF_MARKER 0x599401FE 56 57 SvStream& SvxHyperlinkItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const 58 { 59 // store 'simple' data 60 // UNICODE: rStrm << sName; 61 rStrm.WriteByteString(sName); 62 63 // UNICODE: rStrm << sURL; 64 rStrm.WriteByteString(sURL); 65 66 // UNICODE: rStrm << sTarget; 67 rStrm.WriteByteString(sTarget); 68 69 rStrm << (sal_uInt32) eType; 70 71 // marker for versioninfo 72 rStrm << (sal_uInt32) HYPERLINKFF_MARKER; 73 74 // new data 75 // UNICODE: rStrm << sIntName; 76 rStrm.WriteByteString(sIntName); 77 78 // macro-events 79 rStrm << nMacroEvents; 80 81 // store macros 82 sal_uInt16 nCnt = pMacroTable ? (sal_uInt16)pMacroTable->Count() : 0; 83 sal_uInt16 nMax = nCnt; 84 if( nCnt ) 85 { 86 for( SvxMacro* pMac = pMacroTable->First(); pMac; pMac = pMacroTable->Next() ) 87 if( STARBASIC != pMac->GetScriptType() ) 88 --nCnt; 89 } 90 91 rStrm << nCnt; 92 93 if( nCnt ) 94 { 95 // 1. StarBasic-Macros 96 for( SvxMacro* pMac = pMacroTable->First(); pMac; pMac = pMacroTable->Next() ) 97 { 98 if( STARBASIC == pMac->GetScriptType() ) 99 { 100 rStrm << (sal_uInt16)pMacroTable->GetCurKey(); 101 102 // UNICODE: rStrm << pMac->GetLibName(); 103 rStrm.WriteByteString(pMac->GetLibName()); 104 105 // UNICODE: rStrm << pMac->GetMacName(); 106 rStrm.WriteByteString(pMac->GetMacName()); 107 } 108 } 109 } 110 111 nCnt = nMax - nCnt; 112 rStrm << nCnt; 113 if( nCnt ) 114 { 115 // 2. ::com::sun::star::script::JavaScript-Macros 116 for( SvxMacro* pMac = pMacroTable->First(); pMac; pMac = pMacroTable->Next() ) 117 { 118 if( STARBASIC != pMac->GetScriptType() ) 119 { 120 rStrm << (sal_uInt16)pMacroTable->GetCurKey(); 121 122 // UNICODE: rStrm << pMac->GetLibName(); 123 rStrm.WriteByteString(pMac->GetLibName()); 124 125 // UNICODE: rStrm << pMac->GetMacName(); 126 rStrm.WriteByteString(pMac->GetMacName()); 127 128 rStrm << (sal_uInt16)pMac->GetScriptType(); 129 } 130 } 131 } 132 133 return rStrm; 134 } 135 136 /*-------------------------------------------------------------------- 137 Beschreibung: 138 --------------------------------------------------------------------*/ 139 140 SfxPoolItem* SvxHyperlinkItem::Create( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const 141 { 142 SvxHyperlinkItem* pNew = new SvxHyperlinkItem( Which() ); 143 sal_uInt32 nType; 144 145 // simple data-types 146 // UNICODE: rStrm >> pNew->sName; 147 rStrm.ReadByteString(pNew->sName); 148 149 // UNICODE: rStrm >> pNew->sURL; 150 rStrm.ReadByteString(pNew->sURL); 151 152 // UNICODE: rStrm >> pNew->sTarget; 153 rStrm.ReadByteString(pNew->sTarget); 154 155 rStrm >> nType; 156 pNew->eType = (SvxLinkInsertMode) nType; 157 158 sal_uInt32 nPos = rStrm.Tell(); 159 sal_uInt32 nMarker; 160 rStrm >> nMarker; 161 if ( nMarker == HYPERLINKFF_MARKER ) 162 { 163 // new data 164 // UNICODE: rStrm >> pNew->sIntName; 165 rStrm.ReadByteString(pNew->sIntName); 166 167 // macro-events 168 rStrm >> pNew->nMacroEvents; 169 170 // macros 171 sal_uInt16 nCnt; 172 rStrm >> nCnt; 173 while( nCnt-- ) 174 { 175 sal_uInt16 nCurKey; 176 String aLibName, aMacName; 177 178 rStrm >> nCurKey; 179 // UNICODE: rStrm >> aLibName; 180 rStrm.ReadByteString(aLibName); 181 182 // UNICODE: rStrm >> aMacName; 183 rStrm.ReadByteString(aMacName); 184 185 pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName, STARBASIC ) ); 186 } 187 188 rStrm >> nCnt; 189 while( nCnt-- ) 190 { 191 sal_uInt16 nCurKey, nScriptType; 192 String aLibName, aMacName; 193 194 rStrm >> nCurKey; 195 196 // UNICODE: rStrm >> aLibName; 197 rStrm.ReadByteString(aLibName); 198 199 // UNICODE: rStrm >> aMacName; 200 rStrm.ReadByteString(aMacName); 201 202 rStrm >> nScriptType; 203 204 pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName, 205 (ScriptType)nScriptType ) ); 206 } 207 } 208 else 209 rStrm.Seek( nPos ); 210 211 return pNew; 212 } 213 214 /*-------------------------------------------------------------------- 215 Beschreibung: 216 --------------------------------------------------------------------*/ 217 218 SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& rHyperlinkItem ): 219 SfxPoolItem(rHyperlinkItem) 220 { 221 sName = rHyperlinkItem.sName; 222 sURL = rHyperlinkItem.sURL; 223 sTarget = rHyperlinkItem.sTarget; 224 eType = rHyperlinkItem.eType; 225 sIntName = rHyperlinkItem.sIntName; 226 nMacroEvents = rHyperlinkItem.nMacroEvents; 227 228 if( rHyperlinkItem.GetMacroTbl() ) 229 pMacroTable = new SvxMacroTableDtor( *rHyperlinkItem.GetMacroTbl() ); 230 else 231 pMacroTable=NULL; 232 233 }; 234 235 /*-------------------------------------------------------------------- 236 Beschreibung: 237 --------------------------------------------------------------------*/ 238 239 SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich, String& rName, String& rURL, 240 String& rTarget, String& rIntName, SvxLinkInsertMode eTyp, 241 sal_uInt16 nEvents, SvxMacroTableDtor *pMacroTbl ): 242 SfxPoolItem (_nWhich), 243 sName (rName), 244 sURL (rURL), 245 sTarget (rTarget), 246 eType (eTyp), 247 sIntName (rIntName), 248 nMacroEvents (nEvents) 249 { 250 if (pMacroTbl) 251 pMacroTable = new SvxMacroTableDtor ( *pMacroTbl ); 252 else 253 pMacroTable=NULL; 254 } 255 256 /*-------------------------------------------------------------------- 257 Beschreibung: 258 --------------------------------------------------------------------*/ 259 260 SfxPoolItem* SvxHyperlinkItem::Clone( SfxItemPool* ) const 261 { 262 return new SvxHyperlinkItem( *this ); 263 } 264 265 /*-------------------------------------------------------------------- 266 Beschreibung: 267 --------------------------------------------------------------------*/ 268 269 int SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) const 270 { 271 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unterschiedliche Typen" ); 272 273 const SvxHyperlinkItem& rItem = (const SvxHyperlinkItem&) rAttr; 274 275 sal_Bool bRet = ( sName == rItem.sName && 276 sURL == rItem.sURL && 277 sTarget == rItem.sTarget && 278 eType == rItem.eType && 279 sIntName == rItem.sIntName && 280 nMacroEvents == rItem.nMacroEvents); 281 if (!bRet) 282 return sal_False; 283 284 const SvxMacroTableDtor* pOther = ((SvxHyperlinkItem&)rAttr).pMacroTable; 285 if( !pMacroTable ) 286 return ( !pOther || !pOther->Count() ); 287 if( !pOther ) 288 return 0 == pMacroTable->Count(); 289 290 const SvxMacroTableDtor& rOwn = *pMacroTable; 291 const SvxMacroTableDtor& rOther = *pOther; 292 293 // Anzahl unterschiedlich => auf jeden Fall ungleich 294 if( rOwn.Count() != rOther.Count() ) 295 return sal_False; 296 297 // einzeln vergleichen; wegen Performance ist die Reihenfolge wichtig 298 for( sal_uInt16 nNo = 0; nNo < rOwn.Count(); ++nNo ) 299 { 300 const SvxMacro *pOwnMac = rOwn.GetObject(nNo); 301 const SvxMacro *pOtherMac = rOther.GetObject(nNo); 302 if ( rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac) || 303 pOwnMac->GetLibName() != pOtherMac->GetLibName() || 304 pOwnMac->GetMacName() != pOtherMac->GetMacName() ) 305 return sal_False; 306 } 307 308 return sal_True; 309 } 310 311 312 /*-------------------------------------------------------------------- 313 Beschreibung: 314 --------------------------------------------------------------------*/ 315 316 void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro ) 317 { 318 if( nEvent < EVENT_SFX_START ) 319 { 320 switch( nEvent ) 321 { 322 case HYPERDLG_EVENT_MOUSEOVER_OBJECT: 323 nEvent = SFX_EVENT_MOUSEOVER_OBJECT; 324 break; 325 case HYPERDLG_EVENT_MOUSECLICK_OBJECT: 326 nEvent = SFX_EVENT_MOUSECLICK_OBJECT; 327 break; 328 case HYPERDLG_EVENT_MOUSEOUT_OBJECT: 329 nEvent = SFX_EVENT_MOUSEOUT_OBJECT; 330 break; 331 } 332 } 333 334 if( !pMacroTable ) 335 pMacroTable = new SvxMacroTableDtor; 336 337 SvxMacro *pOldMacro; 338 if( 0 != ( pOldMacro = pMacroTable->Get( nEvent )) ) 339 { 340 delete pOldMacro; 341 pMacroTable->Replace( nEvent, new SvxMacro( rMacro ) ); 342 } 343 else 344 pMacroTable->Insert( nEvent, new SvxMacro( rMacro ) ); 345 } 346 347 /*-------------------------------------------------------------------- 348 Beschreibung: 349 --------------------------------------------------------------------*/ 350 351 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl ) 352 { 353 if ( pMacroTable ) 354 delete pMacroTable; 355 356 pMacroTable = new SvxMacroTableDtor ( rTbl ); 357 } 358 359 sal_Bool SvxHyperlinkItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const 360 { 361 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 362 nMemberId &= ~CONVERT_TWIPS; 363 switch(nMemberId) 364 { 365 case MID_HLINK_NAME : 366 rVal <<= ::rtl::OUString(sIntName.GetBuffer()); 367 break; 368 case MID_HLINK_TEXT : 369 rVal <<= ::rtl::OUString(sName.GetBuffer()); 370 break; 371 case MID_HLINK_URL: 372 rVal <<= ::rtl::OUString(sURL.GetBuffer()); 373 break; 374 case MID_HLINK_TARGET: 375 rVal <<= ::rtl::OUString(sTarget.GetBuffer()); 376 break; 377 case MID_HLINK_TYPE: 378 rVal <<= (sal_Int32) eType; 379 break; 380 default: 381 return sal_False; 382 } 383 384 return sal_True; 385 } 386 387 sal_Bool SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) 388 { 389 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 390 nMemberId &= ~CONVERT_TWIPS; 391 ::rtl::OUString aStr; 392 sal_Int32 nVal = 0; 393 switch(nMemberId) 394 { 395 case MID_HLINK_NAME : 396 if(!(rVal >>= aStr)) 397 return sal_False; 398 sIntName = aStr.getStr(); 399 break; 400 case MID_HLINK_TEXT : 401 if(!(rVal >>= aStr)) 402 return sal_False; 403 sName = aStr.getStr(); 404 break; 405 case MID_HLINK_URL: 406 if(!(rVal >>= aStr)) 407 return sal_False; 408 sURL = aStr.getStr(); 409 break; 410 case MID_HLINK_TARGET: 411 if(!(rVal >>= aStr)) 412 return sal_False; 413 sTarget = aStr.getStr(); 414 break; 415 case MID_HLINK_TYPE: 416 if(!(rVal >>= nVal)) 417 return sal_False; 418 eType = (SvxLinkInsertMode) (sal_uInt16) nVal; 419 break; 420 default: 421 return sal_False; 422 } 423 424 return sal_True; 425 } 426 427