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: hlnkitem.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_svx.hxx"
34 // include ---------------------------------------------------------------
35 #define _SVX_HLNKITEM_CXX
37 #ifndef _SVX_SVXIDS_HRC
38 #include <svx/svxids.hrc>
40 #include <tools/stream.hxx>
43 #include <svx/memberid.hrc>
46 #ifndef __SBX_SBXVARIABLE_HXX
47 #include <basic/sbxvar.hxx>
50 #include "hlnkitem.hxx"
52 // -----------------------------------------------------------------------
54 TYPEINIT1_FACTORY(SvxHyperlinkItem
, SfxPoolItem
, new SvxHyperlinkItem(0));
56 // class SvxHyperlinkItem ------------------------------------------------
58 /*--------------------------------------------------------------------
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
;
82 // UNICODE: rStrm << sIntName;
83 rStrm
.WriteByteString(sIntName
);
86 rStrm
<< nMacroEvents
;
89 sal_uInt16 nCnt
= pMacroTable
? (sal_uInt16
)pMacroTable
->Count() : 0;
90 sal_uInt16 nMax
= nCnt
;
93 for( SvxMacro
* pMac
= pMacroTable
->First(); pMac
; pMac
= pMacroTable
->Next() )
94 if( STARBASIC
!= pMac
->GetScriptType() )
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());
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();
143 /*--------------------------------------------------------------------
145 --------------------------------------------------------------------*/
147 SfxPoolItem
* SvxHyperlinkItem::Create( SvStream
&rStrm
, sal_uInt16
/*nItemVersion*/ ) const
149 SvxHyperlinkItem
* pNew
= new SvxHyperlinkItem( Which() );
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
);
163 pNew
->eType
= (SvxLinkInsertMode
) nType
;
165 sal_uInt32 nPos
= rStrm
.Tell();
168 if ( nMarker
== HYPERLINKFF_MARKER
)
171 // UNICODE: rStrm >> pNew->sIntName;
172 rStrm
.ReadByteString(pNew
->sIntName
);
175 rStrm
>> pNew
->nMacroEvents
;
183 String aLibName
, aMacName
;
186 // UNICODE: rStrm >> aLibName;
187 rStrm
.ReadByteString(aLibName
);
189 // UNICODE: rStrm >> aMacName;
190 rStrm
.ReadByteString(aMacName
);
192 pNew
->SetMacro( nCurKey
, SvxMacro( aMacName
, aLibName
, STARBASIC
) );
198 sal_uInt16 nCurKey
, nScriptType
;
199 String aLibName
, aMacName
;
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
) );
221 /*--------------------------------------------------------------------
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() );
242 /*--------------------------------------------------------------------
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
),
255 nMacroEvents (nEvents
)
258 pMacroTable
= new SvxMacroTableDtor ( *pMacroTbl
);
263 /*--------------------------------------------------------------------
265 --------------------------------------------------------------------*/
267 SfxPoolItem
* SvxHyperlinkItem::Clone( SfxItemPool
* ) const
269 return new SvxHyperlinkItem( *this );
272 /*--------------------------------------------------------------------
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
);
291 const SvxMacroTableDtor
* pOther
= ((SvxHyperlinkItem
&)rAttr
).pMacroTable
;
293 return ( !pOther
|| !pOther
->Count() );
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() )
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() )
319 /*--------------------------------------------------------------------
321 --------------------------------------------------------------------*/
323 void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent
, const SvxMacro
& rMacro
)
325 if( nEvent
< EVENT_SFX_START
)
329 case HYPERDLG_EVENT_MOUSEOVER_OBJECT
:
330 nEvent
= SFX_EVENT_MOUSEOVER_OBJECT
;
332 case HYPERDLG_EVENT_MOUSECLICK_OBJECT
:
333 nEvent
= SFX_EVENT_MOUSECLICK_OBJECT
;
335 case HYPERDLG_EVENT_MOUSEOUT_OBJECT
:
336 nEvent
= SFX_EVENT_MOUSEOUT_OBJECT
;
342 pMacroTable
= new SvxMacroTableDtor
;
345 if( 0 != ( pOldMacro
= pMacroTable
->Get( nEvent
)) )
348 pMacroTable
->Replace( nEvent
, new SvxMacro( rMacro
) );
351 pMacroTable
->Insert( nEvent
, new SvxMacro( rMacro
) );
354 /*--------------------------------------------------------------------
356 --------------------------------------------------------------------*/
358 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor
& rTbl
)
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
;
372 case MID_HLINK_NAME
:
373 rVal
<<= ::rtl::OUString(sIntName
.GetBuffer());
375 case MID_HLINK_TEXT
:
376 rVal
<<= ::rtl::OUString(sName
.GetBuffer());
379 rVal
<<= ::rtl::OUString(sURL
.GetBuffer());
381 case MID_HLINK_TARGET
:
382 rVal
<<= ::rtl::OUString(sTarget
.GetBuffer());
385 rVal
<<= (sal_Int32
) eType
;
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
;
402 case MID_HLINK_NAME
:
405 sIntName
= aStr
.getStr();
407 case MID_HLINK_TEXT
:
410 sName
= aStr
.getStr();
415 sURL
= aStr
.getStr();
417 case MID_HLINK_TARGET
:
420 sTarget
= aStr
.getStr();
425 eType
= (SvxLinkInsertMode
) (sal_uInt16
) nVal
;