Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <comphelper/string.hxx>
21 : #include <sfx2/linkmgr.hxx>
22 : #include <com/sun/star/document/UpdateDocMode.hpp>
23 : #include <sfx2/objsh.hxx>
24 : #include <svl/urihelper.hxx>
25 : #include <sot/formats.hxx>
26 : #include <tools/urlobj.hxx>
27 : #include <sot/exchange.hxx>
28 : #include <tools/debug.hxx>
29 : #include <vcl/msgbox.hxx>
30 : #include <sfx2/lnkbase.hxx>
31 : #include <sfx2/app.hxx>
32 : #include <vcl/graph.hxx>
33 : #include <svl/stritem.hxx>
34 : #include <svl/eitem.hxx>
35 : #include <svl/intitem.hxx>
36 : #include <unotools/localfilehelper.hxx>
37 : #include <i18nlangtag/languagetag.hxx>
38 : #include <sfx2/request.hxx>
39 : #include <vcl/dibtools.hxx>
40 :
41 : #include "fileobj.hxx"
42 : #include "impldde.hxx"
43 : #include "app.hrc"
44 : #include "sfx2/sfxresid.hxx"
45 :
46 : #include <com/sun/star/lang/XComponent.hpp>
47 : #include <com/sun/star/util/XCloseable.hpp>
48 :
49 : using ::com::sun::star::uno::UNO_QUERY;
50 : using ::com::sun::star::uno::Reference;
51 : using ::com::sun::star::lang::XComponent;
52 : using ::com::sun::star::util::XCloseable;
53 :
54 : namespace sfx2
55 : {
56 :
57 16 : class SvxInternalLink : public sfx2::SvLinkSource
58 : {
59 : public:
60 8 : SvxInternalLink() {}
61 :
62 : virtual sal_Bool Connect( sfx2::SvBaseLink* );
63 : };
64 :
65 :
66 1564 : LinkManager::LinkManager(SfxObjectShell* p)
67 1564 : : pPersist( p )
68 : {
69 1564 : }
70 :
71 :
72 2898 : LinkManager::~LinkManager()
73 : {
74 1449 : for( size_t n = 0; n < aLinkTbl.size(); ++n)
75 : {
76 0 : SvBaseLinkRef* pTmp = aLinkTbl[ n ];
77 0 : if( pTmp->Is() )
78 : {
79 0 : (*pTmp)->Disconnect();
80 0 : (*pTmp)->SetLinkManager( NULL );
81 : }
82 0 : delete pTmp;
83 : }
84 1449 : }
85 :
86 0 : void LinkManager::InsertCachedComp(const Reference<XComponent>& xComp)
87 : {
88 0 : maCachedComps.push_back(xComp);
89 0 : }
90 :
91 20 : void LinkManager::CloseCachedComps()
92 : {
93 20 : CompVector::iterator itr = maCachedComps.begin(), itrEnd = maCachedComps.end();
94 20 : for (; itr != itrEnd; ++itr)
95 : {
96 0 : Reference<XCloseable> xCloseable(*itr, UNO_QUERY);
97 0 : if (!xCloseable.is())
98 0 : continue;
99 :
100 0 : xCloseable->close(true);
101 0 : }
102 20 : maCachedComps.clear();
103 20 : }
104 :
105 : //--------------------------------------------------------------------------
106 :
107 40 : void LinkManager::Remove( SvBaseLink *pLink )
108 : {
109 : // No duplicate links inserted
110 40 : int bFound = sal_False;
111 80 : for( size_t n = 0; n < aLinkTbl.size(); )
112 : {
113 26 : SvBaseLinkRef* pTmp = aLinkTbl[ n ];
114 26 : if( pLink == *pTmp )
115 : {
116 26 : (*pTmp)->Disconnect();
117 26 : (*pTmp)->SetLinkManager( NULL );
118 26 : (*pTmp).Clear();
119 26 : bFound = sal_True;
120 : }
121 :
122 : // Remove empty ones if they exist
123 26 : if( !pTmp->Is() )
124 : {
125 26 : delete pTmp;
126 26 : aLinkTbl.erase( aLinkTbl.begin() + n );
127 26 : if( bFound )
128 66 : return ;
129 : }
130 : else
131 0 : ++n;
132 : }
133 : }
134 :
135 :
136 12 : void LinkManager::Remove( size_t nPos, size_t nCnt )
137 : {
138 12 : if( nCnt && nPos < aLinkTbl.size() )
139 : {
140 12 : if (sal::static_int_cast<size_t>(nPos + nCnt) > aLinkTbl.size())
141 0 : nCnt = aLinkTbl.size() - nPos;
142 :
143 24 : for( size_t n = nPos; n < nPos + nCnt; ++n)
144 : {
145 12 : SvBaseLinkRef* pTmp = aLinkTbl[ n ];
146 12 : if( pTmp->Is() )
147 : {
148 12 : (*pTmp)->Disconnect();
149 12 : (*pTmp)->SetLinkManager( NULL );
150 : }
151 12 : delete pTmp;
152 : }
153 12 : aLinkTbl.erase( aLinkTbl.begin() + nPos, aLinkTbl.begin() + nPos + nCnt );
154 : }
155 12 : }
156 :
157 :
158 40 : sal_Bool LinkManager::Insert( SvBaseLink* pLink )
159 : {
160 40 : for( size_t n = 0; n < aLinkTbl.size(); ++n )
161 : {
162 0 : SvBaseLinkRef* pTmp = aLinkTbl[ n ];
163 0 : if( !pTmp->Is() )
164 : {
165 0 : delete pTmp;
166 0 : aLinkTbl.erase( aLinkTbl.begin() + n-- );
167 : }
168 0 : else if( pLink == *pTmp )
169 0 : return sal_False; // No duplicate links inserted
170 : }
171 :
172 40 : SvBaseLinkRef* pTmp = new SvBaseLinkRef( pLink );
173 40 : pLink->SetLinkManager( this );
174 40 : aLinkTbl.push_back( pTmp );
175 40 : return sal_True;
176 : }
177 :
178 :
179 28 : sal_Bool LinkManager::InsertLink( SvBaseLink * pLink,
180 : sal_uInt16 nObjType,
181 : sal_uInt16 nUpdateMode,
182 : const String* pName )
183 : {
184 : // This First
185 28 : pLink->SetObjType( nObjType );
186 28 : if( pName )
187 28 : pLink->SetName( *pName );
188 28 : pLink->SetUpdateMode( nUpdateMode );
189 28 : return Insert( pLink );
190 : }
191 :
192 :
193 6 : sal_Bool LinkManager::InsertDDELink( SvBaseLink * pLink,
194 : const String& rServer,
195 : const String& rTopic,
196 : const String& rItem )
197 : {
198 6 : if( !( OBJECT_CLIENT_SO & pLink->GetObjType() ) )
199 0 : return sal_False;
200 :
201 6 : String sCmd;
202 6 : ::sfx2::MakeLnkName( sCmd, &rServer, rTopic, rItem );
203 :
204 6 : pLink->SetObjType( OBJECT_CLIENT_DDE );
205 6 : pLink->SetName( sCmd );
206 6 : return Insert( pLink );
207 : }
208 :
209 :
210 6 : sal_Bool LinkManager::InsertDDELink( SvBaseLink * pLink )
211 : {
212 : DBG_ASSERT( OBJECT_CLIENT_SO & pLink->GetObjType(), "no OBJECT_CLIENT_SO" );
213 6 : if( !( OBJECT_CLIENT_SO & pLink->GetObjType() ) )
214 0 : return sal_False;
215 :
216 6 : if( pLink->GetObjType() == OBJECT_CLIENT_SO )
217 1 : pLink->SetObjType( OBJECT_CLIENT_DDE );
218 :
219 6 : return Insert( pLink );
220 : }
221 :
222 :
223 : // Obtain the string for the dialog
224 181 : bool LinkManager::GetDisplayNames( const SvBaseLink * pLink,
225 : String* pType,
226 : String* pFile,
227 : String* pLinkStr,
228 : String* pFilter ) const
229 : {
230 181 : bool bRet = false;
231 181 : const String sLNm( pLink->GetLinkSourceName() );
232 181 : if( sLNm.Len() )
233 : {
234 181 : switch( pLink->GetObjType() )
235 : {
236 : case OBJECT_CLIENT_FILE:
237 : case OBJECT_CLIENT_GRF:
238 : case OBJECT_CLIENT_OLE:
239 : {
240 163 : sal_Int32 nPos = 0;
241 163 : String sFile( sLNm.GetToken( 0, ::sfx2::cTokenSeparator, nPos ) );
242 326 : String sRange( sLNm.GetToken( 0, ::sfx2::cTokenSeparator, nPos ) );
243 :
244 163 : if( pFile )
245 161 : *pFile = sFile;
246 163 : if( pLinkStr )
247 63 : *pLinkStr = sRange;
248 163 : if( pFilter )
249 107 : *pFilter = sLNm.Copy( nPos );
250 :
251 163 : if( pType )
252 : {
253 25 : sal_uInt16 nObjType = pLink->GetObjType();
254 75 : *pType = SfxResId(
255 0 : ( OBJECT_CLIENT_FILE == nObjType || OBJECT_CLIENT_OLE == nObjType )
256 : ? RID_SVXSTR_FILELINK
257 25 : : RID_SVXSTR_GRAFIKLINK).toString();
258 : }
259 326 : bRet = true;
260 : }
261 163 : break;
262 : case OBJECT_CLIENT_DDE:
263 : {
264 18 : sal_Int32 nTmp = 0;
265 18 : String sCmd( sLNm );
266 36 : String sServer( sCmd.GetToken( 0, cTokenSeparator, nTmp ) );
267 36 : String sTopic( sCmd.GetToken( 0, cTokenSeparator, nTmp ) );
268 :
269 18 : if( pType )
270 10 : *pType = sServer;
271 18 : if( pFile )
272 18 : *pFile = sTopic;
273 18 : if( pLinkStr )
274 18 : *pLinkStr = sCmd.Copy( nTmp );
275 36 : bRet = true;
276 : }
277 18 : break;
278 : default:
279 0 : break;
280 : }
281 : }
282 :
283 181 : return bRet;
284 : }
285 :
286 29 : bool LinkManager::GetDisplayNames(
287 : const SvBaseLink* pLink, OUString* pType, OUString* pFile,
288 : OUString* pLinkStr, OUString* pFilter) const
289 : {
290 58 : String aType, aFile, aLinkStr, aFilter;
291 29 : bool bRet = GetDisplayNames(pLink, &aType, &aFile, &aLinkStr, &aFilter);
292 29 : if (pType)
293 9 : *pType = aType;
294 29 : if (pFile)
295 20 : *pFile = aFile;
296 29 : if (pLinkStr)
297 16 : *pLinkStr = aLinkStr;
298 29 : if (pFilter)
299 20 : *pFilter = aFilter;
300 58 : return bRet;
301 : }
302 :
303 0 : void LinkManager::UpdateAllLinks(
304 : bool bAskUpdate,
305 : bool /*bCallErrHdl*/,
306 : bool bUpdateGrfLinks,
307 : Window* pParentWin )
308 : {
309 : // First make a copy of the array in order to update links
310 : // links in ... no contact between them!
311 0 : std::vector<SvBaseLink*> aTmpArr;
312 0 : for( size_t n = 0; n < aLinkTbl.size(); ++n )
313 : {
314 0 : SvBaseLink* pLink = *aLinkTbl[ n ];
315 0 : if( !pLink )
316 : {
317 0 : Remove( n-- );
318 0 : continue;
319 : }
320 0 : aTmpArr.push_back( pLink );
321 : }
322 :
323 0 : for( size_t n = 0; n < aTmpArr.size(); ++n )
324 : {
325 0 : SvBaseLink* pLink = aTmpArr[ n ];
326 :
327 : // search first in the array after the entry
328 0 : bool bFound = false;
329 0 : for( size_t i = 0; i < aLinkTbl.size(); ++i )
330 0 : if( pLink == *aLinkTbl[ i ] )
331 : {
332 0 : bFound = true;
333 0 : break;
334 : }
335 :
336 0 : if( !bFound )
337 0 : continue; // was not available!
338 :
339 : // Graphic-Links not to update yet
340 0 : if( !pLink->IsVisible() ||
341 0 : ( !bUpdateGrfLinks && OBJECT_CLIENT_GRF == pLink->GetObjType() ))
342 0 : continue;
343 :
344 0 : if( bAskUpdate )
345 : {
346 0 : int nRet = QueryBox( pParentWin, WB_YES_NO | WB_DEF_YES, SfxResId( STR_QUERY_UPDATE_LINKS ).toString() ).Execute();
347 0 : if( RET_YES != nRet )
348 0 : return ; // nothing should be updated
349 0 : bAskUpdate = false; // once is enough
350 : }
351 :
352 0 : pLink->Update();
353 : }
354 0 : CloseCachedComps();
355 : }
356 :
357 : //--------------------------------------------------------------------------
358 :
359 47 : SvLinkSourceRef LinkManager::CreateObj( SvBaseLink * pLink )
360 : {
361 47 : switch( pLink->GetObjType() )
362 : {
363 : case OBJECT_CLIENT_FILE:
364 : case OBJECT_CLIENT_GRF:
365 : case OBJECT_CLIENT_OLE:
366 38 : return new SvFileObject;
367 : case OBJECT_INTERN:
368 8 : return new SvxInternalLink;
369 : case OBJECT_CLIENT_DDE:
370 1 : return new SvDDEObject;
371 : default:
372 0 : return SvLinkSourceRef();
373 : }
374 : }
375 :
376 8 : sal_Bool LinkManager::InsertServer( SvLinkSource* pObj )
377 : {
378 : // no duplicate inserts
379 8 : if( !pObj )
380 0 : return sal_False;
381 :
382 8 : return aServerTbl.insert( pObj ).second;
383 : }
384 :
385 :
386 8 : void LinkManager::RemoveServer( SvLinkSource* pObj )
387 : {
388 8 : aServerTbl.erase( pObj );
389 8 : }
390 :
391 :
392 7 : void MakeLnkName( String& rName, const String* pType, const String& rFile,
393 : const String& rLink, const String* pFilter )
394 : {
395 7 : if( pType )
396 : {
397 6 : rName = comphelper::string::strip(*pType, ' ');
398 6 : rName += cTokenSeparator;
399 : }
400 1 : else if( rName.Len() )
401 1 : rName.Erase();
402 :
403 7 : rName += rFile;
404 :
405 7 : rName = comphelper::string::strip(rName, ' ');
406 7 : rName += cTokenSeparator;
407 7 : rName = comphelper::string::strip(rName, ' ');
408 7 : rName += rLink;
409 7 : if( pFilter )
410 : {
411 1 : rName += cTokenSeparator;
412 1 : rName += *pFilter;
413 1 : rName = comphelper::string::strip(rName, ' ');
414 : }
415 7 : }
416 :
417 244 : void LinkManager::ReconnectDdeLink(SfxObjectShell& rServer)
418 : {
419 244 : SfxMedium* pMed = rServer.GetMedium();
420 244 : if (!pMed)
421 244 : return;
422 :
423 244 : const ::sfx2::SvBaseLinks& rLinks = GetLinks();
424 244 : size_t n = rLinks.size();
425 :
426 249 : for (size_t i = 0; i < n; ++i)
427 : {
428 5 : ::sfx2::SvBaseLink* p = *rLinks[i];
429 5 : String aType, aFile, aLink, aFilter;
430 5 : if (!GetDisplayNames(p, &aType, &aFile, &aLink, &aFilter))
431 0 : continue;
432 :
433 5 : if (!aType.EqualsAscii("soffice"))
434 : // DDE connections between OOo apps are always named 'soffice'.
435 5 : continue;
436 :
437 0 : OUString aTmp;
438 0 : OUString aURL = aFile;
439 0 : if (utl::LocalFileHelper::ConvertPhysicalNameToURL(aFile, aTmp))
440 0 : aURL = aTmp;
441 :
442 0 : if (!aURL.equalsIgnoreAsciiCase(pMed->GetName()))
443 : // This DDE link is not associated with this server shell... Skip it.
444 0 : continue;
445 :
446 0 : if (!aLink.Len())
447 0 : continue;
448 :
449 0 : LinkServerShell(aLink, rServer, *p);
450 0 : }
451 : }
452 :
453 0 : void LinkManager::LinkServerShell(const OUString& rPath, SfxObjectShell& rServer, ::sfx2::SvBaseLink& rLink) const
454 : {
455 0 : ::sfx2::SvLinkSource* pSrvSrc = rServer.DdeCreateLinkSource(rPath);
456 0 : if (pSrvSrc)
457 : {
458 0 : ::com::sun::star::datatransfer::DataFlavor aFl;
459 0 : SotExchange::GetFormatDataFlavor(rLink.GetContentType(), aFl);
460 0 : rLink.SetObj(pSrvSrc);
461 : pSrvSrc->AddDataAdvise(
462 : &rLink, aFl.MimeType,
463 0 : sfx2::LINKUPDATE_ONCALL == rLink.GetUpdateMode() ? ADVISEMODE_ONLYONCE : 0);
464 : }
465 0 : }
466 :
467 26 : bool LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink,
468 : sal_uInt16 nFileType,
469 : const String& rFileNm,
470 : const String* pFilterNm,
471 : const String* pRange )
472 : {
473 26 : if( !( OBJECT_CLIENT_SO & rLink.GetObjType() ))
474 0 : return false;
475 :
476 26 : String sCmd( rFileNm );
477 26 : sCmd += ::sfx2::cTokenSeparator;
478 26 : if( pRange )
479 17 : sCmd += *pRange;
480 26 : if( pFilterNm )
481 18 : ( sCmd += ::sfx2::cTokenSeparator ) += *pFilterNm;
482 :
483 26 : return InsertLink( &rLink, nFileType, sfx2::LINKUPDATE_ONCALL, &sCmd );
484 : }
485 :
486 2 : bool LinkManager::InsertFileLink(
487 : sfx2::SvBaseLink& rLink, sal_uInt16 nFileType, const OUString& rFileNm,
488 : const OUString* pFilterNm, const OUString* pRange)
489 : {
490 2 : if (!(OBJECT_CLIENT_SO & rLink.GetObjType()))
491 0 : return false;
492 :
493 2 : OUStringBuffer aBuf;
494 2 : aBuf.append(rFileNm);
495 2 : aBuf.append(sfx2::cTokenSeparator);
496 :
497 2 : if (pRange)
498 0 : aBuf.append(*pRange);
499 :
500 2 : if (pFilterNm)
501 : {
502 2 : aBuf.append(sfx2::cTokenSeparator);
503 2 : aBuf.append(*pFilterNm);
504 : }
505 :
506 4 : String aCmd = aBuf.makeStringAndClear();
507 4 : return InsertLink(&rLink, nFileType, sfx2::LINKUPDATE_ONCALL, &aCmd);
508 : }
509 :
510 : // A transfer is aborted, so cancel all download media
511 : // (for now this is only of interest for the file links!)
512 789 : void LinkManager::CancelTransfers()
513 : {
514 : SvFileObject* pFileObj;
515 : sfx2::SvBaseLink* pLnk;
516 :
517 789 : const sfx2::SvBaseLinks& rLnks = GetLinks();
518 1582 : for( size_t n = rLnks.size(); n; )
519 12 : if( 0 != ( pLnk = &(*rLnks[ --n ])) &&
520 12 : OBJECT_CLIENT_FILE == (OBJECT_CLIENT_FILE & pLnk->GetObjType()) &&
521 : 0 != ( pFileObj = (SvFileObject*)pLnk->GetObj() ) )
522 4 : pFileObj->CancelTransfers();
523 789 : }
524 : // For the purpose of sending Status information from the file object to
525 : // the base link, there exist a dedicated ClipBoardId. The SvData-object
526 : // gets the appropriate information as a string
527 : // For now this is required for file object in conjunction with JavaScript
528 : // - needs information about Load/Abort/Error
529 36 : sal_uIntPtr LinkManager::RegisterStatusInfoId()
530 : {
531 : static sal_uIntPtr nFormat = 0;
532 :
533 36 : if( !nFormat )
534 : {
535 : nFormat = SotExchange::RegisterFormatName(
536 1 : OUString("StatusInfo from SvxInternalLink"));
537 : }
538 36 : return nFormat;
539 : }
540 :
541 : // ----------------------------------------------------------------------
542 :
543 14 : sal_Bool LinkManager::GetGraphicFromAny( const String& rMimeType,
544 : const ::com::sun::star::uno::Any & rValue,
545 : Graphic& rGrf )
546 : {
547 14 : sal_Bool bRet = sal_False;
548 14 : ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
549 14 : if( rValue.hasValue() && ( rValue >>= aSeq ) )
550 : {
551 28 : SvMemoryStream aMemStm( (void*)aSeq.getConstArray(), aSeq.getLength(),
552 28 : STREAM_READ );
553 14 : aMemStm.Seek( 0 );
554 :
555 14 : switch( SotExchange::GetFormatIdFromMimeType( rMimeType ) )
556 : {
557 : case SOT_FORMATSTR_ID_SVXB:
558 : {
559 14 : aMemStm >> rGrf;
560 14 : bRet = sal_True;
561 : }
562 14 : break;
563 : case FORMAT_GDIMETAFILE:
564 : {
565 0 : GDIMetaFile aMtf;
566 0 : aMtf.Read( aMemStm );
567 0 : rGrf = aMtf;
568 0 : bRet = sal_True;
569 : }
570 0 : break;
571 : case FORMAT_BITMAP:
572 : {
573 0 : Bitmap aBmp;
574 0 : ReadDIB(aBmp, aMemStm, true);
575 0 : rGrf = aBmp;
576 0 : bRet = sal_True;
577 : }
578 0 : break;
579 14 : }
580 : }
581 14 : return bRet;
582 : }
583 :
584 :
585 : // ----------------------------------------------------------------------
586 32 : String lcl_DDE_RelToAbs( const OUString& rTopic, const OUString& rBaseURL )
587 : {
588 32 : OUString sRet;
589 64 : INetURLObject aURL( rTopic );
590 32 : if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
591 32 : utl::LocalFileHelper::ConvertSystemPathToURL( rTopic, rBaseURL, sRet );
592 32 : if( sRet.isEmpty() )
593 32 : sRet = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), rTopic, URIHelper::GetMaybeFileHdl(), true );
594 64 : return String(sRet);
595 : }
596 :
597 8 : sal_Bool SvxInternalLink::Connect( sfx2::SvBaseLink* pLink )
598 : {
599 8 : SfxObjectShell* pFndShell = 0;
600 8 : sal_uInt16 nUpdateMode = com::sun::star::document::UpdateDocMode::NO_UPDATE;
601 16 : String sTopic, sItem, sReferer;
602 8 : LinkManager* pLinkMgr = pLink->GetLinkManager();
603 8 : if (pLinkMgr && pLinkMgr->GetDisplayNames(pLink, 0, &sTopic, &sItem) && sTopic.Len())
604 : {
605 : // first only loop over the DocumentShells the shells and find those
606 : // with the name:
607 8 : CharClass aCC( LanguageTag( LANGUAGE_SYSTEM) );
608 :
609 8 : TypeId aType( TYPE(SfxObjectShell) );
610 :
611 8 : sal_Bool bFirst = sal_True;
612 8 : SfxObjectShell* pShell = pLinkMgr->GetPersist();
613 8 : if( pShell && pShell->GetMedium() )
614 : {
615 8 : sReferer = pShell->GetMedium()->GetBaseURL();
616 8 : SFX_ITEMSET_ARG( pShell->GetMedium()->GetItemSet(), pItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False );
617 8 : if ( pItem )
618 8 : nUpdateMode = pItem->GetValue();
619 : }
620 :
621 16 : String sNmURL(aCC.lowercase(lcl_DDE_RelToAbs(sTopic, sReferer)));
622 :
623 8 : if ( !pShell )
624 : {
625 0 : bFirst = sal_False;
626 0 : pShell = SfxObjectShell::GetFirst( &aType, sal_False );
627 : }
628 :
629 16 : String sTmp;
630 32 : while( pShell )
631 : {
632 24 : if( !sTmp.Len() )
633 : {
634 24 : sTmp = pShell->GetTitle( SFX_TITLE_FULLNAME );
635 24 : sTmp = lcl_DDE_RelToAbs(sTmp, sReferer );
636 : }
637 :
638 :
639 24 : sTmp = aCC.lowercase( sTmp );
640 24 : if( sTmp == sNmURL ) // we want these
641 : {
642 8 : pFndShell = pShell;
643 8 : break;
644 : }
645 :
646 16 : if( bFirst )
647 : {
648 8 : bFirst = sal_False;
649 8 : pShell = SfxObjectShell::GetFirst( &aType, sal_False );
650 : }
651 : else
652 8 : pShell = SfxObjectShell::GetNext( *pShell, &aType, sal_False );
653 :
654 16 : sTmp.Erase();
655 8 : }
656 : }
657 :
658 : // empty topics are not allowed - which document is it
659 8 : if( !sTopic.Len() )
660 0 : return sal_False;
661 :
662 8 : if (pFndShell)
663 : {
664 8 : sfx2::SvLinkSource* pNewSrc = pFndShell->DdeCreateLinkSource( sItem );
665 8 : if( pNewSrc )
666 : {
667 8 : ::com::sun::star::datatransfer::DataFlavor aFl;
668 8 : SotExchange::GetFormatDataFlavor( pLink->GetContentType(), aFl );
669 :
670 8 : pLink->SetObj( pNewSrc );
671 : pNewSrc->AddDataAdvise( pLink, aFl.MimeType,
672 8 : sfx2::LINKUPDATE_ONCALL == pLink->GetUpdateMode()
673 : ? ADVISEMODE_ONLYONCE
674 8 : : 0 );
675 8 : return true;
676 : }
677 : }
678 : else
679 : {
680 : // then try to download the file:
681 0 : INetURLObject aURL( sTopic );
682 0 : INetProtocol eOld = aURL.GetProtocol();
683 0 : aURL.SetURL( sTopic = lcl_DDE_RelToAbs( sTopic, sReferer ) );
684 0 : if( INET_PROT_NOT_VALID != eOld ||
685 0 : INET_PROT_HTTP != aURL.GetProtocol() )
686 : {
687 0 : SfxStringItem aName( SID_FILE_NAME, sTopic );
688 0 : SfxBoolItem aMinimized(SID_MINIMIZED, sal_True);
689 0 : SfxBoolItem aHidden(SID_HIDDEN, sal_True);
690 0 : SfxStringItem aTarget( SID_TARGETNAME, OUString("_blank") );
691 0 : SfxStringItem aReferer( SID_REFERER, sReferer );
692 0 : SfxUInt16Item aUpdate( SID_UPDATEDOCMODE, nUpdateMode );
693 0 : SfxBoolItem aReadOnly(SID_DOC_READONLY, false);
694 :
695 : // Disable automatic re-connection to avoid this link instance
696 : // being destroyed at re-connection.
697 0 : SfxBoolItem aDdeConnect(SID_DDE_RECONNECT_ONLOAD, false);
698 :
699 : // #i14200# (DDE-link crashes wordprocessor)
700 0 : SfxAllItemSet aArgs( SFX_APP()->GetPool() );
701 0 : aArgs.Put(aReferer);
702 0 : aArgs.Put(aTarget);
703 0 : aArgs.Put(aHidden);
704 0 : aArgs.Put(aMinimized);
705 0 : aArgs.Put(aName);
706 0 : aArgs.Put(aUpdate);
707 0 : aArgs.Put(aReadOnly);
708 0 : aArgs.Put(aDdeConnect);
709 0 : Reference<XComponent> xComp = SfxObjectShell::CreateAndLoadComponent(aArgs);
710 0 : pFndShell = SfxObjectShell::GetShellFromComponent(xComp);
711 0 : if (xComp.is() && pFndShell)
712 : {
713 0 : pLinkMgr->InsertCachedComp(xComp);
714 0 : pLinkMgr->LinkServerShell(sItem, *pFndShell, *pLink);
715 0 : return true;
716 0 : }
717 0 : }
718 : }
719 :
720 8 : return false;
721 : }
722 :
723 :
724 408 : }
725 :
726 :
727 :
728 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|