bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / items / hlnkitem.cxx
blob4919251e09ba773377e1066aea222adfcf522117
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"
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;
52 // new data
53 // UNICODE: rStrm << sIntName;
54 rStrm.WriteUniOrByteString(sIntName, rStrm.GetStreamCharSet());
56 // macro-events
57 rStrm << nMacroEvents;
59 // store macros
60 sal_uInt16 nCnt = pMacroTable ? (sal_uInt16)pMacroTable->size() : 0;
61 sal_uInt16 nMax = nCnt;
62 if( nCnt )
64 for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
65 it != pMacroTable->end(); ++it)
66 if( STARBASIC != it->second.GetScriptType() )
67 --nCnt;
70 rStrm << nCnt;
72 if( nCnt )
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());
92 nCnt = nMax - nCnt;
93 rStrm << nCnt;
94 if( nCnt )
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();
116 return rStrm;
119 SfxPoolItem* SvxHyperlinkItem::Create( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
121 SvxHyperlinkItem* pNew = new SvxHyperlinkItem( Which() );
122 sal_uInt32 nType;
124 // simple data-types
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());
134 rStrm >> nType;
135 pNew->eType = (SvxLinkInsertMode) nType;
137 sal_uInt32 nPos = rStrm.Tell();
138 sal_uInt32 nMarker;
139 rStrm >> nMarker;
140 if ( nMarker == HYPERLINKFF_MARKER )
142 // new data
143 // UNICODE: rStrm >> pNew->sIntName;
144 pNew->sIntName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
146 // macro-events
147 rStrm >> pNew->nMacroEvents;
149 // macros
150 sal_uInt16 nCnt;
151 rStrm >> nCnt;
152 while( nCnt-- )
154 sal_uInt16 nCurKey;
155 String aLibName, aMacName;
157 rStrm >> nCurKey;
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 ) );
167 rStrm >> nCnt;
168 while( nCnt-- )
170 sal_uInt16 nCurKey, nScriptType;
171 String aLibName, aMacName;
173 rStrm >> nCurKey;
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 ) );
187 else
188 rStrm.Seek( nPos );
190 return pNew;
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() );
205 else
206 pMacroTable=NULL;
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),
214 sName (rName),
215 sURL (rURL),
216 sTarget (rTarget),
217 eType (eTyp),
218 sIntName (rIntName),
219 nMacroEvents (nEvents)
221 if (pMacroTbl)
222 pMacroTable = new SvxMacroTableDtor ( *pMacroTbl );
223 else
224 pMacroTable=NULL;
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);
244 if (!bRet)
245 return sal_False;
247 const SvxMacroTableDtor* pOther = ((SvxHyperlinkItem&)rAttr).pMacroTable;
248 if( !pMacroTable )
249 return ( !pOther || pOther->empty() );
250 if( !pOther )
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 )
263 switch( nEvent )
265 case HYPERDLG_EVENT_MOUSEOVER_OBJECT:
266 nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
267 break;
268 case HYPERDLG_EVENT_MOUSECLICK_OBJECT:
269 nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
270 break;
271 case HYPERDLG_EVENT_MOUSEOUT_OBJECT:
272 nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
273 break;
277 if( !pMacroTable )
278 pMacroTable = new SvxMacroTableDtor;
280 pMacroTable->Insert( nEvent, rMacro);
283 void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl )
285 delete pMacroTable;
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;
294 switch(nMemberId)
296 case MID_HLINK_NAME :
297 rVal <<= OUString(sIntName.GetBuffer());
298 break;
299 case MID_HLINK_TEXT :
300 rVal <<= OUString(sName.GetBuffer());
301 break;
302 case MID_HLINK_URL:
303 rVal <<= OUString(sURL.GetBuffer());
304 break;
305 case MID_HLINK_TARGET:
306 rVal <<= OUString(sTarget.GetBuffer());
307 break;
308 case MID_HLINK_TYPE:
309 rVal <<= (sal_Int32) eType;
310 break;
311 default:
312 return false;
315 return true;
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;
322 OUString aStr;
323 sal_Int32 nVal = 0;
324 switch(nMemberId)
326 case MID_HLINK_NAME :
327 if(!(rVal >>= aStr))
328 return sal_False;
329 sIntName = aStr.getStr();
330 break;
331 case MID_HLINK_TEXT :
332 if(!(rVal >>= aStr))
333 return sal_False;
334 sName = aStr.getStr();
335 break;
336 case MID_HLINK_URL:
337 if(!(rVal >>= aStr))
338 return sal_False;
339 sURL = aStr.getStr();
340 break;
341 case MID_HLINK_TARGET:
342 if(!(rVal >>= aStr))
343 return sal_False;
344 sTarget = aStr.getStr();
345 break;
346 case MID_HLINK_TYPE:
347 if(!(rVal >>= nVal))
348 return sal_False;
349 eType = (SvxLinkInsertMode) (sal_uInt16) nVal;
350 break;
351 default:
352 return false;
355 return true;
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */