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"
29 TYPEINIT1_FACTORY(SvxHyperlinkItem
, SfxPoolItem
, new SvxHyperlinkItem(0));
31 #define HYPERLINKFF_MARKER 0x599401FE
33 SvStream
& SvxHyperlinkItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
35 // store 'simple' data
36 // UNICODE: rStrm << sName;
37 rStrm
.WriteUniOrByteString(sName
, rStrm
.GetStreamCharSet());
39 // UNICODE: rStrm << sURL;
40 rStrm
.WriteUniOrByteString(sURL
, rStrm
.GetStreamCharSet());
42 // UNICODE: rStrm << sTarget;
43 rStrm
.WriteUniOrByteString(sTarget
, rStrm
.GetStreamCharSet());
45 rStrm
.WriteUInt32( eType
);
47 // marker for versioninfo
48 rStrm
.WriteUInt32( HYPERLINKFF_MARKER
);
51 // UNICODE: rStrm << sIntName;
52 rStrm
.WriteUniOrByteString(sIntName
, rStrm
.GetStreamCharSet());
55 rStrm
.WriteUInt16( nMacroEvents
);
58 sal_uInt16 nCnt
= pMacroTable
? (sal_uInt16
)pMacroTable
->size() : 0;
59 sal_uInt16 nMax
= nCnt
;
62 for ( SvxMacroTable::const_iterator it
= pMacroTable
->begin();
63 it
!= pMacroTable
->end(); ++it
)
64 if( STARBASIC
!= it
->second
.GetScriptType() )
68 rStrm
.WriteUInt16( nCnt
);
72 // 1. StarBasic-Macros
73 for ( SvxMacroTable::const_iterator it
= pMacroTable
->begin();
74 it
!= pMacroTable
->end(); ++it
)
76 const SvxMacro
& rMac
= it
->second
;
77 if( STARBASIC
== rMac
.GetScriptType() )
79 rStrm
.WriteUInt16( it
->first
);
81 // UNICODE: rStrm << pMac->GetLibName();
82 rStrm
.WriteUniOrByteString(rMac
.GetLibName(), rStrm
.GetStreamCharSet());
84 // UNICODE: rStrm << pMac->GetMacName();
85 rStrm
.WriteUniOrByteString(rMac
.GetMacName(), rStrm
.GetStreamCharSet());
91 rStrm
.WriteUInt16( nCnt
);
94 // 2. ::com::sun::star::script::JavaScript-Macros
95 for ( SvxMacroTable::const_iterator it
= pMacroTable
->begin();
96 it
!= pMacroTable
->end(); ++it
)
98 const SvxMacro
& rMac
= it
->second
;
99 if( STARBASIC
!= rMac
.GetScriptType() )
101 rStrm
.WriteUInt16( it
->first
);
103 // UNICODE: rStrm << pMac->GetLibName();
104 rStrm
.WriteUniOrByteString(rMac
.GetLibName(), rStrm
.GetStreamCharSet());
106 // UNICODE: rStrm << pMac->GetMacName();
107 rStrm
.WriteUniOrByteString(rMac
.GetMacName(), rStrm
.GetStreamCharSet());
109 rStrm
.WriteUInt16( rMac
.GetScriptType() );
117 SfxPoolItem
* SvxHyperlinkItem::Create( SvStream
&rStrm
, sal_uInt16
/*nItemVersion*/ ) const
119 SvxHyperlinkItem
* pNew
= new SvxHyperlinkItem( Which() );
123 // UNICODE: rStrm >> pNew->sName;
124 pNew
->sName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
126 // UNICODE: rStrm >> pNew->sURL;
127 pNew
->sURL
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
129 // UNICODE: rStrm >> pNew->sTarget;
130 pNew
->sTarget
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
132 rStrm
.ReadUInt32( nType
);
133 pNew
->eType
= (SvxLinkInsertMode
) nType
;
135 sal_uInt32 nPos
= rStrm
.Tell();
137 rStrm
.ReadUInt32( nMarker
);
138 if ( nMarker
== HYPERLINKFF_MARKER
)
141 // UNICODE: rStrm >> pNew->sIntName;
142 pNew
->sIntName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
145 rStrm
.ReadUInt16( pNew
->nMacroEvents
);
149 rStrm
.ReadUInt16( nCnt
);
153 OUString aLibName
, aMacName
;
155 rStrm
.ReadUInt16( nCurKey
);
156 // UNICODE: rStrm >> aLibName;
157 aLibName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
159 // UNICODE: rStrm >> aMacName;
160 aMacName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
162 pNew
->SetMacro( nCurKey
, SvxMacro( aMacName
, aLibName
, STARBASIC
) );
165 rStrm
.ReadUInt16( nCnt
);
168 sal_uInt16 nCurKey
, nScriptType
;
169 OUString aLibName
, aMacName
;
171 rStrm
.ReadUInt16( nCurKey
);
173 // UNICODE: rStrm >> aLibName;
174 aLibName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
176 // UNICODE: rStrm >> aMacName;
177 aMacName
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
179 rStrm
.ReadUInt16( nScriptType
);
181 pNew
->SetMacro( nCurKey
, SvxMacro( aMacName
, aLibName
,
182 (ScriptType
)nScriptType
) );
191 SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem
& rHyperlinkItem
):
192 SfxPoolItem(rHyperlinkItem
)
194 sName
= rHyperlinkItem
.sName
;
195 sURL
= rHyperlinkItem
.sURL
;
196 sTarget
= rHyperlinkItem
.sTarget
;
197 eType
= rHyperlinkItem
.eType
;
198 sIntName
= rHyperlinkItem
.sIntName
;
199 nMacroEvents
= rHyperlinkItem
.nMacroEvents
;
201 if( rHyperlinkItem
.GetMacroTable() )
202 pMacroTable
= new SvxMacroTableDtor( *rHyperlinkItem
.GetMacroTable() );
208 SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich
, const OUString
& rName
, const OUString
& rURL
,
209 const OUString
& rTarget
, const OUString
& rIntName
, SvxLinkInsertMode eTyp
,
210 sal_uInt16 nEvents
, SvxMacroTableDtor
*pMacroTbl
):
211 SfxPoolItem (_nWhich
),
217 nMacroEvents (nEvents
)
220 pMacroTable
= new SvxMacroTableDtor ( *pMacroTbl
);
225 SfxPoolItem
* SvxHyperlinkItem::Clone( SfxItemPool
* ) const
227 return new SvxHyperlinkItem( *this );
230 bool SvxHyperlinkItem::operator==( const SfxPoolItem
& rAttr
) const
232 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unterschiedliche Typen" );
234 const SvxHyperlinkItem
& rItem
= static_cast<const SvxHyperlinkItem
&>(rAttr
);
236 bool bRet
= ( sName
== rItem
.sName
&&
237 sURL
== rItem
.sURL
&&
238 sTarget
== rItem
.sTarget
&&
239 eType
== rItem
.eType
&&
240 sIntName
== rItem
.sIntName
&&
241 nMacroEvents
== rItem
.nMacroEvents
);
245 const SvxMacroTableDtor
* pOther
= static_cast<const SvxHyperlinkItem
&>(rAttr
).pMacroTable
;
247 return ( !pOther
|| pOther
->empty() );
249 return pMacroTable
->empty();
251 const SvxMacroTableDtor
& rOwn
= *pMacroTable
;
252 const SvxMacroTableDtor
& rOther
= *pOther
;
254 return rOwn
== rOther
;
257 void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent
, const SvxMacro
& rMacro
)
259 if( nEvent
< EVENT_SFX_START
)
263 case HYPERDLG_EVENT_MOUSEOVER_OBJECT
:
264 nEvent
= SFX_EVENT_MOUSEOVER_OBJECT
;
266 case HYPERDLG_EVENT_MOUSECLICK_OBJECT
:
267 nEvent
= SFX_EVENT_MOUSECLICK_OBJECT
;
269 case HYPERDLG_EVENT_MOUSEOUT_OBJECT
:
270 nEvent
= SFX_EVENT_MOUSEOUT_OBJECT
;
276 pMacroTable
= new SvxMacroTableDtor
;
278 pMacroTable
->Insert( nEvent
, rMacro
);
281 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor
& rTbl
)
285 pMacroTable
= new SvxMacroTableDtor ( rTbl
);
288 bool SvxHyperlinkItem::QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
) const
290 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
291 nMemberId
&= ~CONVERT_TWIPS
;
294 case MID_HLINK_NAME
:
297 case MID_HLINK_TEXT
:
303 case MID_HLINK_TARGET
:
307 rVal
<<= (sal_Int32
) eType
;
316 bool SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt8 nMemberId
)
318 nMemberId
&= ~CONVERT_TWIPS
;
323 case MID_HLINK_NAME
:
328 case MID_HLINK_TEXT
:
336 sURL
= aStr
.getStr();
338 case MID_HLINK_TARGET
:
346 eType
= (SvxLinkInsertMode
) (sal_uInt16
) nVal
;
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */