Update ooo320-m1
[ooovba.git] / svx / source / items / hlnkitem.cxx
blob1af7e32f80d246bd10a9f3aa9f7822f178ae56fe
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: hlnkitem.cxx,v $
10 * $Revision: 1.12 $
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_svx.hxx"
34 // include ---------------------------------------------------------------
35 #define _SVX_HLNKITEM_CXX
37 #ifndef _SVX_SVXIDS_HRC
38 #include <svx/svxids.hrc>
39 #endif
40 #include <tools/stream.hxx>
42 #ifndef _MEMBERID_HRC
43 #include <svx/memberid.hrc>
44 #endif
46 #ifndef __SBX_SBXVARIABLE_HXX
47 #include <basic/sbxvar.hxx>
48 #endif
50 #include "hlnkitem.hxx"
52 // -----------------------------------------------------------------------
54 TYPEINIT1_FACTORY(SvxHyperlinkItem, SfxPoolItem, new SvxHyperlinkItem(0));
56 // class SvxHyperlinkItem ------------------------------------------------
58 /*--------------------------------------------------------------------
59 Beschreibung:
60 --------------------------------------------------------------------*/
62 #define HYPERLINKFF_MARKER 0x599401FE
64 SvStream& SvxHyperlinkItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
66 // store 'simple' data
67 // UNICODE: rStrm << sName;
68 rStrm.WriteByteString(sName);
70 // UNICODE: rStrm << sURL;
71 rStrm.WriteByteString(sURL);
73 // UNICODE: rStrm << sTarget;
74 rStrm.WriteByteString(sTarget);
76 rStrm << (sal_uInt32) eType;
78 // marker for versioninfo
79 rStrm << (sal_uInt32) HYPERLINKFF_MARKER;
81 // new data
82 // UNICODE: rStrm << sIntName;
83 rStrm.WriteByteString(sIntName);
85 // macro-events
86 rStrm << nMacroEvents;
88 // store macros
89 sal_uInt16 nCnt = pMacroTable ? (sal_uInt16)pMacroTable->Count() : 0;
90 sal_uInt16 nMax = nCnt;
91 if( nCnt )
93 for( SvxMacro* pMac = pMacroTable->First(); pMac; pMac = pMacroTable->Next() )
94 if( STARBASIC != pMac->GetScriptType() )
95 --nCnt;
98 rStrm << nCnt;
100 if( nCnt )
102 // 1. StarBasic-Macros
103 for( SvxMacro* pMac = pMacroTable->First(); pMac; pMac = pMacroTable->Next() )
105 if( STARBASIC == pMac->GetScriptType() )
107 rStrm << (sal_uInt16)pMacroTable->GetCurKey();
109 // UNICODE: rStrm << pMac->GetLibName();
110 rStrm.WriteByteString(pMac->GetLibName());
112 // UNICODE: rStrm << pMac->GetMacName();
113 rStrm.WriteByteString(pMac->GetMacName());
118 nCnt = nMax - nCnt;
119 rStrm << nCnt;
120 if( nCnt )
122 // 2. ::com::sun::star::script::JavaScript-Macros
123 for( SvxMacro* pMac = pMacroTable->First(); pMac; pMac = pMacroTable->Next() )
125 if( STARBASIC != pMac->GetScriptType() )
127 rStrm << (sal_uInt16)pMacroTable->GetCurKey();
129 // UNICODE: rStrm << pMac->GetLibName();
130 rStrm.WriteByteString(pMac->GetLibName());
132 // UNICODE: rStrm << pMac->GetMacName();
133 rStrm.WriteByteString(pMac->GetMacName());
135 rStrm << (sal_uInt16)pMac->GetScriptType();
140 return rStrm;
143 /*--------------------------------------------------------------------
144 Beschreibung:
145 --------------------------------------------------------------------*/
147 SfxPoolItem* SvxHyperlinkItem::Create( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
149 SvxHyperlinkItem* pNew = new SvxHyperlinkItem( Which() );
150 sal_uInt32 nType;
152 // simple data-types
153 // UNICODE: rStrm >> pNew->sName;
154 rStrm.ReadByteString(pNew->sName);
156 // UNICODE: rStrm >> pNew->sURL;
157 rStrm.ReadByteString(pNew->sURL);
159 // UNICODE: rStrm >> pNew->sTarget;
160 rStrm.ReadByteString(pNew->sTarget);
162 rStrm >> nType;
163 pNew->eType = (SvxLinkInsertMode) nType;
165 sal_uInt32 nPos = rStrm.Tell();
166 sal_uInt32 nMarker;
167 rStrm >> nMarker;
168 if ( nMarker == HYPERLINKFF_MARKER )
170 // new data
171 // UNICODE: rStrm >> pNew->sIntName;
172 rStrm.ReadByteString(pNew->sIntName);
174 // macro-events
175 rStrm >> pNew->nMacroEvents;
177 // macros
178 sal_uInt16 nCnt;
179 rStrm >> nCnt;
180 while( nCnt-- )
182 sal_uInt16 nCurKey;
183 String aLibName, aMacName;
185 rStrm >> nCurKey;
186 // UNICODE: rStrm >> aLibName;
187 rStrm.ReadByteString(aLibName);
189 // UNICODE: rStrm >> aMacName;
190 rStrm.ReadByteString(aMacName);
192 pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName, STARBASIC ) );
195 rStrm >> nCnt;
196 while( nCnt-- )
198 sal_uInt16 nCurKey, nScriptType;
199 String aLibName, aMacName;
201 rStrm >> nCurKey;
203 // UNICODE: rStrm >> aLibName;
204 rStrm.ReadByteString(aLibName);
206 // UNICODE: rStrm >> aMacName;
207 rStrm.ReadByteString(aMacName);
209 rStrm >> nScriptType;
211 pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName,
212 (ScriptType)nScriptType ) );
215 else
216 rStrm.Seek( nPos );
218 return pNew;
221 /*--------------------------------------------------------------------
222 Beschreibung:
223 --------------------------------------------------------------------*/
225 SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& rHyperlinkItem ):
226 SfxPoolItem(rHyperlinkItem)
228 sName = rHyperlinkItem.sName;
229 sURL = rHyperlinkItem.sURL;
230 sTarget = rHyperlinkItem.sTarget;
231 eType = rHyperlinkItem.eType;
232 sIntName = rHyperlinkItem.sIntName;
233 nMacroEvents = rHyperlinkItem.nMacroEvents;
235 if( rHyperlinkItem.GetMacroTbl() )
236 pMacroTable = new SvxMacroTableDtor( *rHyperlinkItem.GetMacroTbl() );
237 else
238 pMacroTable=NULL;
242 /*--------------------------------------------------------------------
243 Beschreibung:
244 --------------------------------------------------------------------*/
246 SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich, String& rName, String& rURL,
247 String& rTarget, String& rIntName, SvxLinkInsertMode eTyp,
248 sal_uInt16 nEvents, SvxMacroTableDtor *pMacroTbl ):
249 SfxPoolItem (_nWhich),
250 sName (rName),
251 sURL (rURL),
252 sTarget (rTarget),
253 eType (eTyp),
254 sIntName (rIntName),
255 nMacroEvents (nEvents)
257 if (pMacroTbl)
258 pMacroTable = new SvxMacroTableDtor ( *pMacroTbl );
259 else
260 pMacroTable=NULL;
263 /*--------------------------------------------------------------------
264 Beschreibung:
265 --------------------------------------------------------------------*/
267 SfxPoolItem* SvxHyperlinkItem::Clone( SfxItemPool* ) const
269 return new SvxHyperlinkItem( *this );
272 /*--------------------------------------------------------------------
273 Beschreibung:
274 --------------------------------------------------------------------*/
276 int SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) const
278 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unterschiedliche Typen" );
280 const SvxHyperlinkItem& rItem = (const SvxHyperlinkItem&) rAttr;
282 sal_Bool bRet = ( sName == rItem.sName &&
283 sURL == rItem.sURL &&
284 sTarget == rItem.sTarget &&
285 eType == rItem.eType &&
286 sIntName == rItem.sIntName &&
287 nMacroEvents == rItem.nMacroEvents);
288 if (!bRet)
289 return sal_False;
291 const SvxMacroTableDtor* pOther = ((SvxHyperlinkItem&)rAttr).pMacroTable;
292 if( !pMacroTable )
293 return ( !pOther || !pOther->Count() );
294 if( !pOther )
295 return 0 == pMacroTable->Count();
297 const SvxMacroTableDtor& rOwn = *pMacroTable;
298 const SvxMacroTableDtor& rOther = *pOther;
300 // Anzahl unterschiedlich => auf jeden Fall ungleich
301 if( rOwn.Count() != rOther.Count() )
302 return sal_False;
304 // einzeln vergleichen; wegen Performance ist die Reihenfolge wichtig
305 for( sal_uInt16 nNo = 0; nNo < rOwn.Count(); ++nNo )
307 const SvxMacro *pOwnMac = rOwn.GetObject(nNo);
308 const SvxMacro *pOtherMac = rOther.GetObject(nNo);
309 if ( rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac) ||
310 pOwnMac->GetLibName() != pOtherMac->GetLibName() ||
311 pOwnMac->GetMacName() != pOtherMac->GetMacName() )
312 return sal_False;
315 return sal_True;
319 /*--------------------------------------------------------------------
320 Beschreibung:
321 --------------------------------------------------------------------*/
323 void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
325 if( nEvent < EVENT_SFX_START )
327 switch( nEvent )
329 case HYPERDLG_EVENT_MOUSEOVER_OBJECT:
330 nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
331 break;
332 case HYPERDLG_EVENT_MOUSECLICK_OBJECT:
333 nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
334 break;
335 case HYPERDLG_EVENT_MOUSEOUT_OBJECT:
336 nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
337 break;
341 if( !pMacroTable )
342 pMacroTable = new SvxMacroTableDtor;
344 SvxMacro *pOldMacro;
345 if( 0 != ( pOldMacro = pMacroTable->Get( nEvent )) )
347 delete pOldMacro;
348 pMacroTable->Replace( nEvent, new SvxMacro( rMacro ) );
350 else
351 pMacroTable->Insert( nEvent, new SvxMacro( rMacro ) );
354 /*--------------------------------------------------------------------
355 Beschreibung:
356 --------------------------------------------------------------------*/
358 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl )
360 if ( pMacroTable )
361 delete pMacroTable;
363 pMacroTable = new SvxMacroTableDtor ( rTbl );
366 BOOL SvxHyperlinkItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE nMemberId ) const
368 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
369 nMemberId &= ~CONVERT_TWIPS;
370 switch(nMemberId)
372 case MID_HLINK_NAME :
373 rVal <<= ::rtl::OUString(sIntName.GetBuffer());
374 break;
375 case MID_HLINK_TEXT :
376 rVal <<= ::rtl::OUString(sName.GetBuffer());
377 break;
378 case MID_HLINK_URL:
379 rVal <<= ::rtl::OUString(sURL.GetBuffer());
380 break;
381 case MID_HLINK_TARGET:
382 rVal <<= ::rtl::OUString(sTarget.GetBuffer());
383 break;
384 case MID_HLINK_TYPE:
385 rVal <<= (sal_Int32) eType;
386 break;
387 default:
388 return FALSE;
391 return TRUE;
394 BOOL SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE nMemberId )
396 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
397 nMemberId &= ~CONVERT_TWIPS;
398 ::rtl::OUString aStr;
399 sal_Int32 nVal = 0;
400 switch(nMemberId)
402 case MID_HLINK_NAME :
403 if(!(rVal >>= aStr))
404 return sal_False;
405 sIntName = aStr.getStr();
406 break;
407 case MID_HLINK_TEXT :
408 if(!(rVal >>= aStr))
409 return sal_False;
410 sName = aStr.getStr();
411 break;
412 case MID_HLINK_URL:
413 if(!(rVal >>= aStr))
414 return sal_False;
415 sURL = aStr.getStr();
416 break;
417 case MID_HLINK_TARGET:
418 if(!(rVal >>= aStr))
419 return sal_False;
420 sTarget = aStr.getStr();
421 break;
422 case MID_HLINK_TYPE:
423 if(!(rVal >>= nVal))
424 return sal_False;
425 eType = (SvxLinkInsertMode) (sal_uInt16) nVal;
426 break;
427 default:
428 return FALSE;
431 return TRUE;