Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/svxids.hrc>
30 : : #include <tools/stream.hxx>
31 : : #include <svl/memberid.hrc>
32 : : #include <basic/sbxvar.hxx>
33 : :
34 : : #include "svx/hlnkitem.hxx"
35 : :
36 : : // -----------------------------------------------------------------------
37 : :
38 [ # # ][ # # ]: 183 : TYPEINIT1_FACTORY(SvxHyperlinkItem, SfxPoolItem, new SvxHyperlinkItem(0));
[ # # ]
39 : :
40 : : // class SvxHyperlinkItem ------------------------------------------------
41 : :
42 : : #define HYPERLINKFF_MARKER 0x599401FE
43 : :
44 : 0 : SvStream& SvxHyperlinkItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
45 : : {
46 : : // store 'simple' data
47 : : // UNICODE: rStrm << sName;
48 [ # # ]: 0 : rStrm.WriteUniOrByteString(sName, rStrm.GetStreamCharSet());
49 : :
50 : : // UNICODE: rStrm << sURL;
51 [ # # ]: 0 : rStrm.WriteUniOrByteString(sURL, rStrm.GetStreamCharSet());
52 : :
53 : : // UNICODE: rStrm << sTarget;
54 [ # # ]: 0 : rStrm.WriteUniOrByteString(sTarget, rStrm.GetStreamCharSet());
55 : :
56 : 0 : rStrm << (sal_uInt32) eType;
57 : :
58 : : // marker for versioninfo
59 : 0 : rStrm << (sal_uInt32) HYPERLINKFF_MARKER;
60 : :
61 : : // new data
62 : : // UNICODE: rStrm << sIntName;
63 [ # # ]: 0 : rStrm.WriteUniOrByteString(sIntName, rStrm.GetStreamCharSet());
64 : :
65 : : // macro-events
66 : 0 : rStrm << nMacroEvents;
67 : :
68 : : // store macros
69 [ # # ]: 0 : sal_uInt16 nCnt = pMacroTable ? (sal_uInt16)pMacroTable->size() : 0;
70 : 0 : sal_uInt16 nMax = nCnt;
71 [ # # ]: 0 : if( nCnt )
72 : : {
73 [ # # ][ # # ]: 0 : for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
[ # # ][ # # ]
74 [ # # ]: 0 : it != pMacroTable->end(); ++it)
75 [ # # ][ # # ]: 0 : if( STARBASIC != it->second.GetScriptType() )
76 : 0 : --nCnt;
77 : : }
78 : :
79 : 0 : rStrm << nCnt;
80 : :
81 [ # # ]: 0 : if( nCnt )
82 : : {
83 : : // 1. StarBasic-Macros
84 [ # # ][ # # ]: 0 : for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
[ # # ][ # # ]
85 [ # # ]: 0 : it != pMacroTable->end(); ++it)
86 : : {
87 [ # # ]: 0 : const SvxMacro& rMac = it->second;
88 [ # # ]: 0 : if( STARBASIC == rMac.GetScriptType() )
89 : : {
90 [ # # ][ # # ]: 0 : rStrm << (sal_uInt16)it->first;
91 : :
92 : : // UNICODE: rStrm << pMac->GetLibName();
93 [ # # ]: 0 : rStrm.WriteUniOrByteString(rMac.GetLibName(), rStrm.GetStreamCharSet());
94 : :
95 : : // UNICODE: rStrm << pMac->GetMacName();
96 [ # # ]: 0 : rStrm.WriteUniOrByteString(rMac.GetMacName(), rStrm.GetStreamCharSet());
97 : : }
98 : : }
99 : : }
100 : :
101 : 0 : nCnt = nMax - nCnt;
102 : 0 : rStrm << nCnt;
103 [ # # ]: 0 : if( nCnt )
104 : : {
105 : : // 2. ::com::sun::star::script::JavaScript-Macros
106 [ # # ][ # # ]: 0 : for ( SvxMacroTable::const_iterator it = pMacroTable->begin();
[ # # ][ # # ]
107 [ # # ]: 0 : it != pMacroTable->end(); ++it)
108 : : {
109 [ # # ]: 0 : const SvxMacro& rMac = it->second;
110 [ # # ]: 0 : if( STARBASIC != rMac.GetScriptType() )
111 : : {
112 [ # # ][ # # ]: 0 : rStrm << (sal_uInt16)it->first;
113 : :
114 : : // UNICODE: rStrm << pMac->GetLibName();
115 [ # # ]: 0 : rStrm.WriteUniOrByteString(rMac.GetLibName(), rStrm.GetStreamCharSet());
116 : :
117 : : // UNICODE: rStrm << pMac->GetMacName();
118 [ # # ]: 0 : rStrm.WriteUniOrByteString(rMac.GetMacName(), rStrm.GetStreamCharSet());
119 : :
120 [ # # ]: 0 : rStrm << (sal_uInt16)rMac.GetScriptType();
121 : : }
122 : : }
123 : : }
124 : :
125 : 0 : return rStrm;
126 : : }
127 : :
128 : 0 : SfxPoolItem* SvxHyperlinkItem::Create( SvStream &rStrm, sal_uInt16 /*nItemVersion*/ ) const
129 : : {
130 [ # # ][ # # ]: 0 : SvxHyperlinkItem* pNew = new SvxHyperlinkItem( Which() );
131 : : sal_uInt32 nType;
132 : :
133 : : // simple data-types
134 : : // UNICODE: rStrm >> pNew->sName;
135 [ # # ][ # # ]: 0 : pNew->sName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
136 : :
137 : : // UNICODE: rStrm >> pNew->sURL;
138 [ # # ][ # # ]: 0 : pNew->sURL = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
139 : :
140 : : // UNICODE: rStrm >> pNew->sTarget;
141 [ # # ][ # # ]: 0 : pNew->sTarget = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
142 : :
143 [ # # ]: 0 : rStrm >> nType;
144 : 0 : pNew->eType = (SvxLinkInsertMode) nType;
145 : :
146 : 0 : sal_uInt32 nPos = rStrm.Tell();
147 : : sal_uInt32 nMarker;
148 [ # # ]: 0 : rStrm >> nMarker;
149 [ # # ]: 0 : if ( nMarker == HYPERLINKFF_MARKER )
150 : : {
151 : : // new data
152 : : // UNICODE: rStrm >> pNew->sIntName;
153 [ # # ][ # # ]: 0 : pNew->sIntName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
154 : :
155 : : // macro-events
156 [ # # ]: 0 : rStrm >> pNew->nMacroEvents;
157 : :
158 : : // macros
159 : : sal_uInt16 nCnt;
160 [ # # ]: 0 : rStrm >> nCnt;
161 [ # # ]: 0 : while( nCnt-- )
162 : : {
163 : : sal_uInt16 nCurKey;
164 [ # # ][ # # ]: 0 : String aLibName, aMacName;
165 : :
166 [ # # ]: 0 : rStrm >> nCurKey;
167 : : // UNICODE: rStrm >> aLibName;
168 [ # # ][ # # ]: 0 : aLibName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
169 : :
170 : : // UNICODE: rStrm >> aMacName;
171 [ # # ][ # # ]: 0 : aMacName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
172 : :
173 [ # # ][ # # ]: 0 : pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName, STARBASIC ) );
[ # # ][ # # ]
[ # # ]
174 [ # # ][ # # ]: 0 : }
175 : :
176 [ # # ]: 0 : rStrm >> nCnt;
177 [ # # ]: 0 : while( nCnt-- )
178 : : {
179 : : sal_uInt16 nCurKey, nScriptType;
180 [ # # ][ # # ]: 0 : String aLibName, aMacName;
181 : :
182 [ # # ]: 0 : rStrm >> nCurKey;
183 : :
184 : : // UNICODE: rStrm >> aLibName;
185 [ # # ][ # # ]: 0 : aLibName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
186 : :
187 : : // UNICODE: rStrm >> aMacName;
188 [ # # ][ # # ]: 0 : aMacName = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
189 : :
190 [ # # ]: 0 : rStrm >> nScriptType;
191 : :
192 : : pNew->SetMacro( nCurKey, SvxMacro( aMacName, aLibName,
193 [ # # ][ # # ]: 0 : (ScriptType)nScriptType ) );
[ # # ][ # # ]
[ # # ]
194 [ # # ][ # # ]: 0 : }
195 : : }
196 : : else
197 [ # # ]: 0 : rStrm.Seek( nPos );
198 : :
199 : 0 : return pNew;
200 : : }
201 : :
202 : 0 : SvxHyperlinkItem::SvxHyperlinkItem( const SvxHyperlinkItem& rHyperlinkItem ):
203 [ # # ][ # # ]: 0 : SfxPoolItem(rHyperlinkItem)
[ # # ][ # # ]
204 : : {
205 [ # # ]: 0 : sName = rHyperlinkItem.sName;
206 [ # # ]: 0 : sURL = rHyperlinkItem.sURL;
207 [ # # ]: 0 : sTarget = rHyperlinkItem.sTarget;
208 : 0 : eType = rHyperlinkItem.eType;
209 [ # # ]: 0 : sIntName = rHyperlinkItem.sIntName;
210 : 0 : nMacroEvents = rHyperlinkItem.nMacroEvents;
211 : :
212 [ # # ]: 0 : if( rHyperlinkItem.GetMacroTbl() )
213 [ # # ][ # # ]: 0 : pMacroTable = new SvxMacroTableDtor( *rHyperlinkItem.GetMacroTbl() );
214 : : else
215 : 0 : pMacroTable=NULL;
216 : :
217 : 0 : };
218 : :
219 : 0 : SvxHyperlinkItem::SvxHyperlinkItem( sal_uInt16 _nWhich, String& rName, String& rURL,
220 : : String& rTarget, String& rIntName, SvxLinkInsertMode eTyp,
221 : : sal_uInt16 nEvents, SvxMacroTableDtor *pMacroTbl ):
222 : : SfxPoolItem (_nWhich),
223 : : sName (rName),
224 : : sURL (rURL),
225 : : sTarget (rTarget),
226 : : eType (eTyp),
227 : : sIntName (rIntName),
228 [ # # ][ # # ]: 0 : nMacroEvents (nEvents)
[ # # ][ # # ]
229 : : {
230 [ # # ]: 0 : if (pMacroTbl)
231 [ # # ][ # # ]: 0 : pMacroTable = new SvxMacroTableDtor ( *pMacroTbl );
232 : : else
233 : 0 : pMacroTable=NULL;
234 : 0 : }
235 : :
236 : 0 : SfxPoolItem* SvxHyperlinkItem::Clone( SfxItemPool* ) const
237 : : {
238 [ # # ]: 0 : return new SvxHyperlinkItem( *this );
239 : : }
240 : :
241 : 0 : int SvxHyperlinkItem::operator==( const SfxPoolItem& rAttr ) const
242 : : {
243 : : DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unterschiedliche Typen" );
244 : :
245 : 0 : const SvxHyperlinkItem& rItem = (const SvxHyperlinkItem&) rAttr;
246 : :
247 : 0 : sal_Bool bRet = ( sName == rItem.sName &&
248 : 0 : sURL == rItem.sURL &&
249 : 0 : sTarget == rItem.sTarget &&
250 : : eType == rItem.eType &&
251 : 0 : sIntName == rItem.sIntName &&
252 [ # # # # ]: 0 : nMacroEvents == rItem.nMacroEvents);
[ # # ][ # #
# # # # ]
253 [ # # ]: 0 : if (!bRet)
254 : 0 : return sal_False;
255 : :
256 : 0 : const SvxMacroTableDtor* pOther = ((SvxHyperlinkItem&)rAttr).pMacroTable;
257 [ # # ]: 0 : if( !pMacroTable )
258 [ # # ][ # # ]: 0 : return ( !pOther || pOther->empty() );
259 [ # # ]: 0 : if( !pOther )
260 : 0 : return pMacroTable->empty();
261 : :
262 : 0 : const SvxMacroTableDtor& rOwn = *pMacroTable;
263 : 0 : const SvxMacroTableDtor& rOther = *pOther;
264 : :
265 : 0 : return rOwn == rOther;
266 : : }
267 : :
268 : 0 : void SvxHyperlinkItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
269 : : {
270 [ # # ]: 0 : if( nEvent < EVENT_SFX_START )
271 : : {
272 [ # # # # ]: 0 : switch( nEvent )
273 : : {
274 : : case HYPERDLG_EVENT_MOUSEOVER_OBJECT:
275 : 0 : nEvent = SFX_EVENT_MOUSEOVER_OBJECT;
276 : 0 : break;
277 : : case HYPERDLG_EVENT_MOUSECLICK_OBJECT:
278 : 0 : nEvent = SFX_EVENT_MOUSECLICK_OBJECT;
279 : 0 : break;
280 : : case HYPERDLG_EVENT_MOUSEOUT_OBJECT:
281 : 0 : nEvent = SFX_EVENT_MOUSEOUT_OBJECT;
282 : 0 : break;
283 : : }
284 : : }
285 : :
286 [ # # ]: 0 : if( !pMacroTable )
287 [ # # ]: 0 : pMacroTable = new SvxMacroTableDtor;
288 : :
289 : 0 : pMacroTable->Insert( nEvent, rMacro);
290 : 0 : }
291 : :
292 : 0 : void SvxHyperlinkItem::SetMacroTable( const SvxMacroTableDtor& rTbl )
293 : : {
294 [ # # ]: 0 : if ( pMacroTable )
295 [ # # ]: 0 : delete pMacroTable;
296 : :
297 [ # # ]: 0 : pMacroTable = new SvxMacroTableDtor ( rTbl );
298 : 0 : }
299 : :
300 : 0 : bool SvxHyperlinkItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const
301 : : {
302 : : // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
303 : 0 : nMemberId &= ~CONVERT_TWIPS;
304 [ # # # # : 0 : switch(nMemberId)
# # ]
305 : : {
306 : : case MID_HLINK_NAME :
307 [ # # ]: 0 : rVal <<= ::rtl::OUString(sIntName.GetBuffer());
308 : 0 : break;
309 : : case MID_HLINK_TEXT :
310 [ # # ]: 0 : rVal <<= ::rtl::OUString(sName.GetBuffer());
311 : 0 : break;
312 : : case MID_HLINK_URL:
313 [ # # ]: 0 : rVal <<= ::rtl::OUString(sURL.GetBuffer());
314 : 0 : break;
315 : : case MID_HLINK_TARGET:
316 [ # # ]: 0 : rVal <<= ::rtl::OUString(sTarget.GetBuffer());
317 : 0 : break;
318 : : case MID_HLINK_TYPE:
319 [ # # ]: 0 : rVal <<= (sal_Int32) eType;
320 : 0 : break;
321 : : default:
322 : 0 : return false;
323 : : }
324 : :
325 : 0 : return true;
326 : : }
327 : :
328 : 0 : bool SvxHyperlinkItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId )
329 : : {
330 : : // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
331 : 0 : nMemberId &= ~CONVERT_TWIPS;
332 : 0 : ::rtl::OUString aStr;
333 : 0 : sal_Int32 nVal = 0;
334 [ # # # # : 0 : switch(nMemberId)
# # ]
335 : : {
336 : : case MID_HLINK_NAME :
337 [ # # ]: 0 : if(!(rVal >>= aStr))
338 : 0 : return sal_False;
339 [ # # ]: 0 : sIntName = aStr.getStr();
340 : 0 : break;
341 : : case MID_HLINK_TEXT :
342 [ # # ]: 0 : if(!(rVal >>= aStr))
343 : 0 : return sal_False;
344 [ # # ]: 0 : sName = aStr.getStr();
345 : 0 : break;
346 : : case MID_HLINK_URL:
347 [ # # ]: 0 : if(!(rVal >>= aStr))
348 : 0 : return sal_False;
349 [ # # ]: 0 : sURL = aStr.getStr();
350 : 0 : break;
351 : : case MID_HLINK_TARGET:
352 [ # # ]: 0 : if(!(rVal >>= aStr))
353 : 0 : return sal_False;
354 [ # # ]: 0 : sTarget = aStr.getStr();
355 : 0 : break;
356 : : case MID_HLINK_TYPE:
357 [ # # ]: 0 : if(!(rVal >>= nVal))
358 : 0 : return sal_False;
359 : 0 : eType = (SvxLinkInsertMode) (sal_uInt16) nVal;
360 : 0 : break;
361 : : default:
362 : 0 : return false;
363 : : }
364 : :
365 : 0 : return true;
366 : : }
367 : :
368 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|