bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / items / hlnkitem.cxx
blobb1b5b39b4195968ad7eccb8751be67200d736463
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 );
50 // new data
51 // UNICODE: rStrm << sIntName;
52 rStrm.WriteUniOrByteString(sIntName, rStrm.GetStreamCharSet());
54 // macro-events
55 rStrm.WriteUInt16( nMacroEvents );
57 // store macros
58 sal_uInt16 nCnt = pMacroTable ? (sal_uInt16)pMacroTable->size() : 0;
59 sal_uInt16 nMax = nCnt;
60 if( nCnt )
62 for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
63 it != pMacroTable->end(); ++it)
64 if( STARBASIC != it->second.GetScriptType() )
65 --nCnt;
68 rStrm.WriteUInt16( nCnt );
70 if( 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());
90 nCnt = nMax - nCnt;
91 rStrm.WriteUInt16( nCnt );
92 if( 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() );
114 return rStrm;
117 SfxPoolItem* SvxHyperlinkItem::Create( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
119 SvxHyperlinkItem* pNew = new SvxHyperlinkItem( Which() );
120 sal_uInt32 nType;
122 // simple data-types
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();
136 sal_uInt32 nMarker;
137 rStrm.ReadUInt32( nMarker );
138 if ( nMarker == HYPERLINKFF_MARKER )
140 // new data
141 // UNICODE: rStrm >> pNew->sIntName;
142 pNew->sIntName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
144 // macro-events
145 rStrm.ReadUInt16( pNew->nMacroEvents );
147 // macros
148 sal_uInt16 nCnt;
149 rStrm.ReadUInt16( nCnt );
150 while( nCnt-- )
152 sal_uInt16 nCurKey;
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 );
166 while( 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 ) );
185 else
186 rStrm.Seek( nPos );
188 return pNew;
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() );
203 else
204 pMacroTable=NULL;
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),
212 sName (rName),
213 sURL (rURL),
214 sTarget (rTarget),
215 eType (eTyp),
216 sIntName (rIntName),
217 nMacroEvents (nEvents)
219 if (pMacroTbl)
220 pMacroTable = new SvxMacroTableDtor ( *pMacroTbl );
221 else
222 pMacroTable=NULL;
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);
242 if (!bRet)
243 return false;
245 const SvxMacroTableDtor* pOther = static_cast<const SvxHyperlinkItem&>(rAttr).pMacroTable;
246 if( !pMacroTable )
247 return ( !pOther || pOther->empty() );
248 if( !pOther )
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 )
261 switch( nEvent )
263 case HYPERDLG_EVENT_MOUSEOVER_OBJECT:
264 nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
265 break;
266 case HYPERDLG_EVENT_MOUSECLICK_OBJECT:
267 nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
268 break;
269 case HYPERDLG_EVENT_MOUSEOUT_OBJECT:
270 nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
271 break;
275 if( !pMacroTable )
276 pMacroTable = new SvxMacroTableDtor;
278 pMacroTable->Insert( nEvent, rMacro);
281 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl )
283 delete pMacroTable;
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;
292 switch(nMemberId)
294 case MID_HLINK_NAME :
295 rVal <<= sIntName;
296 break;
297 case MID_HLINK_TEXT :
298 rVal <<= sName;
299 break;
300 case MID_HLINK_URL:
301 rVal <<= sURL;
302 break;
303 case MID_HLINK_TARGET:
304 rVal <<= sTarget;
305 break;
306 case MID_HLINK_TYPE:
307 rVal <<= (sal_Int32) eType;
308 break;
309 default:
310 return false;
313 return true;
316 bool SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
318 nMemberId &= ~CONVERT_TWIPS;
319 OUString aStr;
320 sal_Int32 nVal = 0;
321 switch(nMemberId)
323 case MID_HLINK_NAME :
324 if(!(rVal >>= aStr))
325 return false;
326 sIntName = aStr;
327 break;
328 case MID_HLINK_TEXT :
329 if(!(rVal >>= aStr))
330 return false;
331 sName = aStr;
332 break;
333 case MID_HLINK_URL:
334 if(!(rVal >>= aStr))
335 return false;
336 sURL = aStr.getStr();
337 break;
338 case MID_HLINK_TARGET:
339 if(!(rVal >>= aStr))
340 return false;
341 sTarget = aStr;
342 break;
343 case MID_HLINK_TYPE:
344 if(!(rVal >>= nVal))
345 return false;
346 eType = (SvxLinkInsertMode) (sal_uInt16) nVal;
347 break;
348 default:
349 return false;
352 return true;
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */