1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/svxids.hrc>
21 #include <tools/stream.hxx>
22 #include <svl/memberid.hrc>
23 #include <basic/sbxvar.hxx>
25 #include "svx/hlnkitem.hxx"
27 // -----------------------------------------------------------------------
29 TYPEINIT1_FACTORY(SvxHyperlinkItem
, SfxPoolItem
, new SvxHyperlinkItem(0));
31 // class SvxHyperlinkItem ------------------------------------------------
33 #define HYPERLINKFF_MARKER 0x599401FE
35 SvStream
& SvxHyperlinkItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
37 // store 'simple' data
38 // UNICODE: rStrm << sName;
39 rStrm
.WriteUniOrByteString(sName
, rStrm
.GetStreamCharSet());
41 // UNICODE: rStrm << sURL;
42 rStrm
.WriteUniOrByteString(sURL
, rStrm
.GetStreamCharSet());
44 // UNICODE: rStrm << sTarget;
45 rStrm
.WriteUniOrByteString(sTarget
, rStrm
.GetStreamCharSet());
47 rStrm
<< (sal_uInt32
) eType
;
49 // marker for versioninfo
50 rStrm
<< (sal_uInt32
) HYPERLINKFF_MARKER
;
53 // UNICODE: rStrm << sIntName;
54 rStrm
.WriteUniOrByteString(sIntName
, rStrm
.GetStreamCharSet());
57 rStrm
<< nMacroEvents
;
60 sal_uInt16 nCnt
= pMacroTable
? (sal_uInt16
)pMacroTable
->size() : 0;
61 sal_uInt16 nMax
= nCnt
;
64 for ( SvxMacroTable::const_iterator it
= pMacroTable
->begin();
65 it
!= pMacroTable
->end(); ++it
)
66 if( STARBASIC
!= it
->second
.GetScriptType() )
74 // 1. StarBasic-Macros
75 for ( SvxMacroTable::const_iterator it
= pMacroTable
->begin();
76 it
!= pMacroTable
->end(); ++it
)
78 const SvxMacro
& rMac
= it
->second
;
79 if( STARBASIC
== rMac
.GetScriptType() )
81 rStrm
<< (sal_uInt16
)it
->first
;
83 // UNICODE: rStrm << pMac->GetLibName();
84 rStrm
.WriteUniOrByteString(rMac
.GetLibName(), rStrm
.GetStreamCharSet());
86 // UNICODE: rStrm << pMac->GetMacName();
87 rStrm
.WriteUniOrByteString(rMac
.GetMacName(), rStrm
.GetStreamCharSet());
96 // 2. ::com::sun::star::script::JavaScript-Macros
97 for ( SvxMacroTable::const_iterator it
= pMacroTable
->begin();
98 it
!= pMacroTable
->end(); ++it
)
100 const SvxMacro
& rMac
= it
->second
;
101 if( STARBASIC
!= rMac
.GetScriptType() )
103 rStrm
<< (sal_uInt16
)it
->first
;
105 // UNICODE: rStrm << pMac->GetLibName();
106 rStrm
.WriteUniOrByteString(rMac
.GetLibName(), rStrm
.GetStreamCharSet());
108 // UNICODE: rStrm << pMac->GetMacName();
109 rStrm
.WriteUniOrByteString(rMac
.GetMacName(), rStrm
.GetStreamCharSet());
111 rStrm
<< (sal_uInt16
)rMac
.GetScriptType();
119 SfxPoolItem
* SvxHyperlinkItem::Create( SvStream
&rStrm
, sal_uInt16
/*nItemVersion*/ ) const
121 SvxHyperlinkItem
* pNew
= new SvxHyperlinkItem( Which() );
125 // UNICODE: rStrm >> pNew->sName;
126 pNew
->sName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
128 // UNICODE: rStrm >> pNew->sURL;
129 pNew
->sURL
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
131 // UNICODE: rStrm >> pNew->sTarget;
132 pNew
->sTarget
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
135 pNew
->eType
= (SvxLinkInsertMode
) nType
;
137 sal_uInt32 nPos
= rStrm
.Tell();
140 if ( nMarker
== HYPERLINKFF_MARKER
)
143 // UNICODE: rStrm >> pNew->sIntName;
144 pNew
->sIntName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
147 rStrm
>> pNew
->nMacroEvents
;
155 String aLibName
, aMacName
;
158 // UNICODE: rStrm >> aLibName;
159 aLibName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
161 // UNICODE: rStrm >> aMacName;
162 aMacName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
164 pNew
->SetMacro( nCurKey
, SvxMacro( aMacName
, aLibName
, STARBASIC
) );
170 sal_uInt16 nCurKey
, nScriptType
;
171 String aLibName
, aMacName
;
175 // UNICODE: rStrm >> aLibName;
176 aLibName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
178 // UNICODE: rStrm >> aMacName;
179 aMacName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
181 rStrm
>> nScriptType
;
183 pNew
->SetMacro( nCurKey
, SvxMacro( aMacName
, aLibName
,
184 (ScriptType
)nScriptType
) );
193 SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem
& rHyperlinkItem
):
194 SfxPoolItem(rHyperlinkItem
)
196 sName
= rHyperlinkItem
.sName
;
197 sURL
= rHyperlinkItem
.sURL
;
198 sTarget
= rHyperlinkItem
.sTarget
;
199 eType
= rHyperlinkItem
.eType
;
200 sIntName
= rHyperlinkItem
.sIntName
;
201 nMacroEvents
= rHyperlinkItem
.nMacroEvents
;
203 if( rHyperlinkItem
.GetMacroTbl() )
204 pMacroTable
= new SvxMacroTableDtor( *rHyperlinkItem
.GetMacroTbl() );
210 SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich
, String
& rName
, String
& rURL
,
211 String
& rTarget
, String
& rIntName
, SvxLinkInsertMode eTyp
,
212 sal_uInt16 nEvents
, SvxMacroTableDtor
*pMacroTbl
):
213 SfxPoolItem (_nWhich
),
219 nMacroEvents (nEvents
)
222 pMacroTable
= new SvxMacroTableDtor ( *pMacroTbl
);
227 SfxPoolItem
* SvxHyperlinkItem::Clone( SfxItemPool
* ) const
229 return new SvxHyperlinkItem( *this );
232 int SvxHyperlinkItem::operator==( const SfxPoolItem
& rAttr
) const
234 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unterschiedliche Typen" );
236 const SvxHyperlinkItem
& rItem
= (const SvxHyperlinkItem
&) rAttr
;
238 bool bRet
= ( sName
== rItem
.sName
&&
239 sURL
== rItem
.sURL
&&
240 sTarget
== rItem
.sTarget
&&
241 eType
== rItem
.eType
&&
242 sIntName
== rItem
.sIntName
&&
243 nMacroEvents
== rItem
.nMacroEvents
);
247 const SvxMacroTableDtor
* pOther
= ((SvxHyperlinkItem
&)rAttr
).pMacroTable
;
249 return ( !pOther
|| pOther
->empty() );
251 return pMacroTable
->empty();
253 const SvxMacroTableDtor
& rOwn
= *pMacroTable
;
254 const SvxMacroTableDtor
& rOther
= *pOther
;
256 return rOwn
== rOther
;
259 void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent
, const SvxMacro
& rMacro
)
261 if( nEvent
< EVENT_SFX_START
)
265 case HYPERDLG_EVENT_MOUSEOVER_OBJECT
:
266 nEvent
= SFX_EVENT_MOUSEOVER_OBJECT
;
268 case HYPERDLG_EVENT_MOUSECLICK_OBJECT
:
269 nEvent
= SFX_EVENT_MOUSECLICK_OBJECT
;
271 case HYPERDLG_EVENT_MOUSEOUT_OBJECT
:
272 nEvent
= SFX_EVENT_MOUSEOUT_OBJECT
;
278 pMacroTable
= new SvxMacroTableDtor
;
280 pMacroTable
->Insert( nEvent
, rMacro
);
283 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor
& rTbl
)
287 pMacroTable
= new SvxMacroTableDtor ( rTbl
);
290 bool SvxHyperlinkItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
292 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
293 nMemberId
&= ~CONVERT_TWIPS
;
296 case MID_HLINK_NAME
:
297 rVal
<<= OUString(sIntName
.GetBuffer());
299 case MID_HLINK_TEXT
:
300 rVal
<<= OUString(sName
.GetBuffer());
303 rVal
<<= OUString(sURL
.GetBuffer());
305 case MID_HLINK_TARGET
:
306 rVal
<<= OUString(sTarget
.GetBuffer());
309 rVal
<<= (sal_Int32
) eType
;
318 bool SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
320 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
321 nMemberId
&= ~CONVERT_TWIPS
;
326 case MID_HLINK_NAME
:
329 sIntName
= aStr
.getStr();
331 case MID_HLINK_TEXT
:
334 sName
= aStr
.getStr();
339 sURL
= aStr
.getStr();
341 case MID_HLINK_TARGET
:
344 sTarget
= aStr
.getStr();
349 eType
= (SvxLinkInsertMode
) (sal_uInt16
) nVal
;
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */