1d119d52dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3d119d52dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4d119d52dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5d119d52dSAndrew Rist * distributed with this work for additional information 6d119d52dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7d119d52dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8d119d52dSAndrew Rist * "License"); you may not use this file except in compliance 9d119d52dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11d119d52dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13d119d52dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14d119d52dSAndrew Rist * software distributed under the License is distributed on an 15d119d52dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16d119d52dSAndrew Rist * KIND, either express or implied. See the License for the 17d119d52dSAndrew Rist * specific language governing permissions and limitations 18d119d52dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20d119d52dSAndrew Rist *************************************************************/ 21d119d52dSAndrew Rist 22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 23cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include <sfx2/linkmgr.hxx> 26cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp> 27cdf0e10cSrcweir #include <sfx2/objsh.hxx> 28cdf0e10cSrcweir #include <svl/urihelper.hxx> 29cdf0e10cSrcweir #include <sot/formats.hxx> 30cdf0e10cSrcweir #include <tools/urlobj.hxx> 31cdf0e10cSrcweir #include <sot/exchange.hxx> 32cdf0e10cSrcweir #include <tools/debug.hxx> 33cdf0e10cSrcweir #include <vcl/msgbox.hxx> 34cdf0e10cSrcweir #include <sfx2/lnkbase.hxx> 35cdf0e10cSrcweir #include <sfx2/app.hxx> 36cdf0e10cSrcweir #include <vcl/graph.hxx> 37cdf0e10cSrcweir #include <svl/stritem.hxx> 38cdf0e10cSrcweir #include <svl/eitem.hxx> 39cdf0e10cSrcweir #include <svl/intitem.hxx> 40cdf0e10cSrcweir #include <unotools/localfilehelper.hxx> 41cdf0e10cSrcweir #include <i18npool/mslangid.hxx> 42cdf0e10cSrcweir #include <sfx2/request.hxx> 4345fd3b9aSArmin Le Grand #include <vcl/dibtools.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir #include "fileobj.hxx" 46cdf0e10cSrcweir #include "impldde.hxx" 47cdf0e10cSrcweir #include "app.hrc" 48cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 49cdf0e10cSrcweir 50cdf0e10cSrcweir #define _SVSTDARR_STRINGSDTOR 51cdf0e10cSrcweir #include <svl/svstdarr.hxx> 52cdf0e10cSrcweir 53cdf0e10cSrcweir namespace sfx2 54cdf0e10cSrcweir { 55cdf0e10cSrcweir 56cdf0e10cSrcweir class SvxInternalLink : public sfx2::SvLinkSource 57cdf0e10cSrcweir { 58cdf0e10cSrcweir public: 59cdf0e10cSrcweir SvxInternalLink() {} 60cdf0e10cSrcweir 61cdf0e10cSrcweir virtual sal_Bool Connect( sfx2::SvBaseLink* ); 62cdf0e10cSrcweir }; 63cdf0e10cSrcweir 64cdf0e10cSrcweir 65cdf0e10cSrcweir SV_IMPL_PTRARR( SvBaseLinks, SvBaseLinkRefPtr ) 66cdf0e10cSrcweir 67cdf0e10cSrcweir LinkManager::LinkManager(SfxObjectShell* p) 68b0c1db7eSPatricia Shanahan : pPersist(p), 69*3f92111aSArrigo Marchiori mAutoAskUpdateAllLinks(sal_False), 70*3f92111aSArrigo Marchiori mUpdateAsked(sal_False) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir LinkManager::~LinkManager() 75cdf0e10cSrcweir { 76cdf0e10cSrcweir SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData(); 77cdf0e10cSrcweir for( sal_uInt16 n = aLinkTbl.Count(); n; --n, ++ppRef ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir if( (*ppRef)->Is() ) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir (*(*ppRef))->Disconnect(); 82cdf0e10cSrcweir (*(*ppRef))->SetLinkManager( NULL ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir delete *ppRef; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir 89cdf0e10cSrcweir /************************************************************************ 90cdf0e10cSrcweir |* LinkManager::Remove() 91cdf0e10cSrcweir |* 925799d6dbSmarcus |* Description 93cdf0e10cSrcweir *************************************************************************/ 94cdf0e10cSrcweir 95cdf0e10cSrcweir void LinkManager::Remove( SvBaseLink *pLink ) 96cdf0e10cSrcweir { 975799d6dbSmarcus // do not insert links double 98cdf0e10cSrcweir int bFound = sal_False; 99cdf0e10cSrcweir SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData(); 100cdf0e10cSrcweir for( sal_uInt16 n = aLinkTbl.Count(); n; --n, ++ppRef ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if( pLink == *(*ppRef) ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir (*(*ppRef))->Disconnect(); 105cdf0e10cSrcweir (*(*ppRef))->SetLinkManager( NULL ); 106cdf0e10cSrcweir (*(*ppRef)).Clear(); 107cdf0e10cSrcweir bFound = sal_True; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 1105799d6dbSmarcus // if there are still some empty ones, get rid of them 111cdf0e10cSrcweir if( !(*ppRef)->Is() ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir delete *ppRef; 114cdf0e10cSrcweir aLinkTbl.Remove( aLinkTbl.Count() - n, 1 ); 115cdf0e10cSrcweir if( bFound ) 116cdf0e10cSrcweir return ; 117cdf0e10cSrcweir --ppRef; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir void LinkManager::Remove( sal_uInt16 nPos, sal_uInt16 nCnt ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if( nCnt && nPos < aLinkTbl.Count() ) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir if( nPos + nCnt > aLinkTbl.Count() ) 128cdf0e10cSrcweir nCnt = aLinkTbl.Count() - nPos; 129cdf0e10cSrcweir 130cdf0e10cSrcweir SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData() + nPos; 131cdf0e10cSrcweir for( sal_uInt16 n = nCnt; n; --n, ++ppRef ) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir if( (*ppRef)->Is() ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir (*(*ppRef))->Disconnect(); 136cdf0e10cSrcweir (*(*ppRef))->SetLinkManager( NULL ); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir delete *ppRef; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir aLinkTbl.Remove( nPos, nCnt ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir 145cdf0e10cSrcweir sal_Bool LinkManager::Insert( SvBaseLink* pLink ) 146cdf0e10cSrcweir { 147b0c1db7eSPatricia Shanahan 1485799d6dbSmarcus // do not insert links double 149cdf0e10cSrcweir for( sal_uInt16 n = 0; n < aLinkTbl.Count(); ++n ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir SvBaseLinkRef* pTmp = aLinkTbl[ n ]; 152cdf0e10cSrcweir if( !pTmp->Is() ) 153cdf0e10cSrcweir aLinkTbl.DeleteAndDestroy( n-- ); 154cdf0e10cSrcweir 155cdf0e10cSrcweir if( pLink == *pTmp ) 156cdf0e10cSrcweir return sal_False; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir SvBaseLinkRef* pTmp = new SvBaseLinkRef( pLink ); 160cdf0e10cSrcweir pLink->SetLinkManager( this ); 161cdf0e10cSrcweir aLinkTbl.Insert( pTmp, aLinkTbl.Count() ); 162b0c1db7eSPatricia Shanahan if (mAutoAskUpdateAllLinks) 163b0c1db7eSPatricia Shanahan { 164789caf29SPatricia Shanahan Window *parent = NULL; 165789caf29SPatricia Shanahan SfxObjectShell* persist = GetPersist(); 166789caf29SPatricia Shanahan if (persist != NULL) 167789caf29SPatricia Shanahan parent = GetPersist()->GetDialogParent(); 168789caf29SPatricia Shanahan 169b0c1db7eSPatricia Shanahan SetUserAllowsLinkUpdate(pLink, GetUserAllowsLinkUpdate(parent)); 170b0c1db7eSPatricia Shanahan } 171b0c1db7eSPatricia Shanahan 172cdf0e10cSrcweir return sal_True; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir sal_Bool LinkManager::InsertLink( SvBaseLink * pLink, 177cdf0e10cSrcweir sal_uInt16 nObjType, 178cdf0e10cSrcweir sal_uInt16 nUpdateMode, 179cdf0e10cSrcweir const String* pName ) 180cdf0e10cSrcweir { 1815799d6dbSmarcus // in any case: do this first 182cdf0e10cSrcweir pLink->SetObjType( nObjType ); 183cdf0e10cSrcweir if( pName ) 184cdf0e10cSrcweir pLink->SetName( *pName ); 185cdf0e10cSrcweir pLink->SetUpdateMode( nUpdateMode ); 186cdf0e10cSrcweir return Insert( pLink ); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir 190cdf0e10cSrcweir sal_Bool LinkManager::InsertDDELink( SvBaseLink * pLink, 191cdf0e10cSrcweir const String& rServer, 192cdf0e10cSrcweir const String& rTopic, 193cdf0e10cSrcweir const String& rItem ) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir if( !( OBJECT_CLIENT_SO & pLink->GetObjType() ) ) 196cdf0e10cSrcweir return sal_False; 197cdf0e10cSrcweir 198cdf0e10cSrcweir String sCmd; 199cdf0e10cSrcweir ::sfx2::MakeLnkName( sCmd, &rServer, rTopic, rItem ); 200cdf0e10cSrcweir 201cdf0e10cSrcweir pLink->SetObjType( OBJECT_CLIENT_DDE ); 202cdf0e10cSrcweir pLink->SetName( sCmd ); 203cdf0e10cSrcweir return Insert( pLink ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir 207cdf0e10cSrcweir sal_Bool LinkManager::InsertDDELink( SvBaseLink * pLink ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir DBG_ASSERT( OBJECT_CLIENT_SO & pLink->GetObjType(), "no OBJECT_CLIENT_SO" ); 210cdf0e10cSrcweir if( !( OBJECT_CLIENT_SO & pLink->GetObjType() ) ) 211cdf0e10cSrcweir return sal_False; 212cdf0e10cSrcweir 213cdf0e10cSrcweir if( pLink->GetObjType() == OBJECT_CLIENT_SO ) 214cdf0e10cSrcweir pLink->SetObjType( OBJECT_CLIENT_DDE ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir return Insert( pLink ); 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir 2205799d6dbSmarcus // ask for the strings to be used in the dialog 221cdf0e10cSrcweir sal_Bool LinkManager::GetDisplayNames( const SvBaseLink * pLink, 222cdf0e10cSrcweir String* pType, 223cdf0e10cSrcweir String* pFile, 224cdf0e10cSrcweir String* pLinkStr, 225cdf0e10cSrcweir String* pFilter ) const 226cdf0e10cSrcweir { 227cdf0e10cSrcweir sal_Bool bRet = sal_False; 228cdf0e10cSrcweir const String sLNm( pLink->GetLinkSourceName() ); 229cdf0e10cSrcweir if( sLNm.Len() ) 230cdf0e10cSrcweir { 231cdf0e10cSrcweir switch( pLink->GetObjType() ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir case OBJECT_CLIENT_FILE: 234cdf0e10cSrcweir case OBJECT_CLIENT_GRF: 235cdf0e10cSrcweir case OBJECT_CLIENT_OLE: 236cdf0e10cSrcweir { 237cdf0e10cSrcweir sal_uInt16 nPos = 0; 238cdf0e10cSrcweir String sFile( sLNm.GetToken( 0, ::sfx2::cTokenSeperator, nPos ) ); 239cdf0e10cSrcweir String sRange( sLNm.GetToken( 0, ::sfx2::cTokenSeperator, nPos ) ); 240cdf0e10cSrcweir 241cdf0e10cSrcweir if( pFile ) 242cdf0e10cSrcweir *pFile = sFile; 243cdf0e10cSrcweir if( pLinkStr ) 244cdf0e10cSrcweir *pLinkStr = sRange; 245cdf0e10cSrcweir if( pFilter ) 246cdf0e10cSrcweir *pFilter = sLNm.Copy( nPos ); 247cdf0e10cSrcweir 248cdf0e10cSrcweir if( pType ) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir sal_uInt16 nObjType = pLink->GetObjType(); 251cdf0e10cSrcweir *pType = String( SfxResId( 252cdf0e10cSrcweir ( OBJECT_CLIENT_FILE == nObjType || OBJECT_CLIENT_OLE == nObjType ) 253cdf0e10cSrcweir ? RID_SVXSTR_FILELINK 254cdf0e10cSrcweir : RID_SVXSTR_GRAFIKLINK )); 255cdf0e10cSrcweir } 256cdf0e10cSrcweir bRet = sal_True; 257cdf0e10cSrcweir } 258cdf0e10cSrcweir break; 259cdf0e10cSrcweir case OBJECT_CLIENT_DDE: 260cdf0e10cSrcweir { 261cdf0e10cSrcweir sal_uInt16 nTmp = 0; 262cdf0e10cSrcweir String sCmd( sLNm ); 263cdf0e10cSrcweir String sServer( sCmd.GetToken( 0, cTokenSeperator, nTmp ) ); 264cdf0e10cSrcweir String sTopic( sCmd.GetToken( 0, cTokenSeperator, nTmp ) ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir if( pType ) 267cdf0e10cSrcweir *pType = sServer; 268cdf0e10cSrcweir if( pFile ) 269cdf0e10cSrcweir *pFile = sTopic; 270cdf0e10cSrcweir if( pLinkStr ) 271cdf0e10cSrcweir *pLinkStr = sCmd.Copy( nTmp ); 272cdf0e10cSrcweir bRet = sal_True; 273cdf0e10cSrcweir } 274cdf0e10cSrcweir break; 275cdf0e10cSrcweir default: 276cdf0e10cSrcweir break; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir return bRet; 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283b0c1db7eSPatricia Shanahan void LinkManager::SetAutoAskUpdateAllLinks() 284b0c1db7eSPatricia Shanahan { 285b0c1db7eSPatricia Shanahan mAutoAskUpdateAllLinks = sal_True; 286*3f92111aSArrigo Marchiori mUpdateAsked = sal_False; 287*3f92111aSArrigo Marchiori } 288*3f92111aSArrigo Marchiori 289*3f92111aSArrigo Marchiori void LinkManager::SetNeverAskUpdateAllLinks() 290*3f92111aSArrigo Marchiori { 291*3f92111aSArrigo Marchiori mAutoAskUpdateAllLinks = sal_False; 292*3f92111aSArrigo Marchiori mAllowUpdate = sal_True; 293*3f92111aSArrigo Marchiori mUpdateAsked = sal_True; 294b0c1db7eSPatricia Shanahan } 295b0c1db7eSPatricia Shanahan 296b0c1db7eSPatricia Shanahan sal_Bool LinkManager::GetUserAllowsLinkUpdate(Window *pParentWin) 297b0c1db7eSPatricia Shanahan { 298b0c1db7eSPatricia Shanahan if (!mUpdateAsked) 299b0c1db7eSPatricia Shanahan { 300b0c1db7eSPatricia Shanahan if (QueryBox(pParentWin, WB_YES_NO | WB_DEF_NO, SfxResId(STR_QUERY_UPDATE_LINKS)).Execute() == RET_YES) 301b0c1db7eSPatricia Shanahan mAllowUpdate = sal_True; 302b0c1db7eSPatricia Shanahan else 303b0c1db7eSPatricia Shanahan mAllowUpdate = sal_False; 304b0c1db7eSPatricia Shanahan mUpdateAsked = sal_True; 305b0c1db7eSPatricia Shanahan } 306b0c1db7eSPatricia Shanahan return mAllowUpdate; 307b0c1db7eSPatricia Shanahan } 308b0c1db7eSPatricia Shanahan 309b0c1db7eSPatricia Shanahan void LinkManager::SetUserAllowsLinkUpdate(SvBaseLink *pLink, sal_Bool allows) 310b0c1db7eSPatricia Shanahan { 311b0c1db7eSPatricia Shanahan SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist(); 312b0c1db7eSPatricia Shanahan 313b0c1db7eSPatricia Shanahan if (pShell) 314b0c1db7eSPatricia Shanahan { 315b0c1db7eSPatricia Shanahan comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = pShell->getEmbeddedObjectContainer(); 316b0c1db7eSPatricia Shanahan rEmbeddedObjectContainer.setUserAllowsLinkUpdate(allows); 317b0c1db7eSPatricia Shanahan } 318b0c1db7eSPatricia Shanahan } 319b0c1db7eSPatricia Shanahan 320cdf0e10cSrcweir 321cdf0e10cSrcweir void LinkManager::UpdateAllLinks( 322cdf0e10cSrcweir sal_Bool bAskUpdate, 323cdf0e10cSrcweir sal_Bool /*bCallErrHdl*/, 324cdf0e10cSrcweir sal_Bool bUpdateGrfLinks, 325cdf0e10cSrcweir Window* pParentWin ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir SvStringsDtor aApps, aTopics, aItems; 328cdf0e10cSrcweir String sApp, sTopic, sItem; 329cdf0e10cSrcweir 3305799d6dbSmarcus // first create a copy of the array, so that updated links to not interfere with ... in between!! 331cdf0e10cSrcweir SvPtrarr aTmpArr( 255, 50 ); 332cdf0e10cSrcweir sal_uInt16 n; 333cdf0e10cSrcweir for( n = 0; n < aLinkTbl.Count(); ++n ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir SvBaseLink* pLink = *aLinkTbl[ n ]; 336cdf0e10cSrcweir if( !pLink ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir Remove( n-- ); 339cdf0e10cSrcweir continue; 340cdf0e10cSrcweir } 341cdf0e10cSrcweir aTmpArr.Insert( pLink, aTmpArr.Count() ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir for( n = 0; n < aTmpArr.Count(); ++n ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir SvBaseLink* pLink = (SvBaseLink*)aTmpArr[ n ]; 347cdf0e10cSrcweir 3485799d6dbSmarcus // first search the entry in the array 349cdf0e10cSrcweir sal_uInt16 nFndPos = USHRT_MAX; 350cdf0e10cSrcweir for( sal_uInt16 i = 0; i < aLinkTbl.Count(); ++i ) 351cdf0e10cSrcweir if( pLink == *aLinkTbl[ i ] ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir nFndPos = i; 354cdf0e10cSrcweir break; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir if( USHRT_MAX == nFndPos ) 3585799d6dbSmarcus continue; // was not already existing! 359cdf0e10cSrcweir 3605799d6dbSmarcus // do not update graphic links yet 361cdf0e10cSrcweir if( !pLink->IsVisible() || 362cdf0e10cSrcweir ( !bUpdateGrfLinks && OBJECT_CLIENT_GRF == pLink->GetObjType() )) 363cdf0e10cSrcweir continue; 364cdf0e10cSrcweir 365b0c1db7eSPatricia Shanahan sal_Bool allows = sal_True; 366b0c1db7eSPatricia Shanahan 367cdf0e10cSrcweir if (bAskUpdate) 368cdf0e10cSrcweir { 369b0c1db7eSPatricia Shanahan allows = GetUserAllowsLinkUpdate(pParentWin); 370963c6022SArmin Le Grand } 371963c6022SArmin Le Grand 372b0c1db7eSPatricia Shanahan SetUserAllowsLinkUpdate(pLink, allows); 3735799d6dbSmarcus bAskUpdate = sal_False; // one time is OK 374cdf0e10cSrcweir 375b0c1db7eSPatricia Shanahan if (allows) 376cdf0e10cSrcweir pLink->Update(); 377cdf0e10cSrcweir } 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir /************************************************************************ 381cdf0e10cSrcweir |* SvBaseLink::CreateObject() 382cdf0e10cSrcweir |* 3835799d6dbSmarcus |* Description 384cdf0e10cSrcweir *************************************************************************/ 385cdf0e10cSrcweir 386cdf0e10cSrcweir SvLinkSourceRef LinkManager::CreateObj( SvBaseLink * pLink ) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir switch( pLink->GetObjType() ) 389cdf0e10cSrcweir { 390cdf0e10cSrcweir case OBJECT_CLIENT_FILE: 391cdf0e10cSrcweir case OBJECT_CLIENT_GRF: 392cdf0e10cSrcweir case OBJECT_CLIENT_OLE: 393cdf0e10cSrcweir return new SvFileObject; 394cdf0e10cSrcweir case OBJECT_INTERN: 395cdf0e10cSrcweir return new SvxInternalLink; 396cdf0e10cSrcweir case OBJECT_CLIENT_DDE: 397cdf0e10cSrcweir return new SvDDEObject; 398cdf0e10cSrcweir default: 399cdf0e10cSrcweir return SvLinkSourceRef(); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir } 402cdf0e10cSrcweir 403cdf0e10cSrcweir sal_Bool LinkManager::InsertServer( SvLinkSource* pObj ) 404cdf0e10cSrcweir { 4055799d6dbSmarcus // do not insert double 406cdf0e10cSrcweir if( !pObj || USHRT_MAX != aServerTbl.GetPos( pObj ) ) 407cdf0e10cSrcweir return sal_False; 408cdf0e10cSrcweir 409cdf0e10cSrcweir aServerTbl.Insert( pObj, aServerTbl.Count() ); 410cdf0e10cSrcweir return sal_True; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir 413cdf0e10cSrcweir 414cdf0e10cSrcweir void LinkManager::RemoveServer( SvLinkSource* pObj ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir sal_uInt16 nPos = aServerTbl.GetPos( pObj ); 417cdf0e10cSrcweir if( USHRT_MAX != nPos ) 418cdf0e10cSrcweir aServerTbl.Remove( nPos, 1 ); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir 422cdf0e10cSrcweir void MakeLnkName( String& rName, const String* pType, const String& rFile, 423cdf0e10cSrcweir const String& rLink, const String* pFilter ) 424cdf0e10cSrcweir { 425cdf0e10cSrcweir if( pType ) 426cdf0e10cSrcweir (rName = *pType).EraseLeadingChars().EraseTrailingChars() += cTokenSeperator; 427cdf0e10cSrcweir else if( rName.Len() ) 428cdf0e10cSrcweir rName.Erase(); 429cdf0e10cSrcweir 430cdf0e10cSrcweir ((rName += rFile).EraseLeadingChars().EraseTrailingChars() += 431cdf0e10cSrcweir cTokenSeperator ).EraseLeadingChars().EraseTrailingChars() += rLink; 432cdf0e10cSrcweir if( pFilter ) 433cdf0e10cSrcweir ((rName += cTokenSeperator ) += *pFilter).EraseLeadingChars().EraseTrailingChars(); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir sal_Bool LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink, 437cdf0e10cSrcweir sal_uInt16 nFileType, 438cdf0e10cSrcweir const String& rFileNm, 439cdf0e10cSrcweir const String* pFilterNm, 440cdf0e10cSrcweir const String* pRange ) 441cdf0e10cSrcweir { 442cdf0e10cSrcweir if( !( OBJECT_CLIENT_SO & rLink.GetObjType() )) 443cdf0e10cSrcweir return sal_False; 444cdf0e10cSrcweir 445cdf0e10cSrcweir String sCmd( rFileNm ); 446cdf0e10cSrcweir sCmd += ::sfx2::cTokenSeperator; 447cdf0e10cSrcweir if( pRange ) 448cdf0e10cSrcweir sCmd += *pRange; 449cdf0e10cSrcweir if( pFilterNm ) 450cdf0e10cSrcweir ( sCmd += ::sfx2::cTokenSeperator ) += *pFilterNm; 451cdf0e10cSrcweir 452cdf0e10cSrcweir return InsertLink( &rLink, nFileType, sfx2::LINKUPDATE_ONCALL, &sCmd ); 453cdf0e10cSrcweir } 454cdf0e10cSrcweir 455cdf0e10cSrcweir sal_Bool LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink ) 456cdf0e10cSrcweir { 457cdf0e10cSrcweir if( OBJECT_CLIENT_FILE == ( OBJECT_CLIENT_FILE & rLink.GetObjType() )) 458cdf0e10cSrcweir return InsertLink( &rLink, rLink.GetObjType(), sfx2::LINKUPDATE_ONCALL ); 459cdf0e10cSrcweir return sal_False; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 4625799d6dbSmarcus // a transfer will be discontinued, therefore cancel all DownloadMedia 4635799d6dbSmarcus // (at the moment only interesting for the FileLinks!) 464cdf0e10cSrcweir void LinkManager::CancelTransfers() 465cdf0e10cSrcweir { 466cdf0e10cSrcweir SvFileObject* pFileObj; 467cdf0e10cSrcweir sfx2::SvBaseLink* pLnk; 468cdf0e10cSrcweir 469cdf0e10cSrcweir const sfx2::SvBaseLinks& rLnks = GetLinks(); 470cdf0e10cSrcweir for( sal_uInt16 n = rLnks.Count(); n; ) 471cdf0e10cSrcweir if( 0 != ( pLnk = &(*rLnks[ --n ])) && 472cdf0e10cSrcweir OBJECT_CLIENT_FILE == (OBJECT_CLIENT_FILE & pLnk->GetObjType()) && 473cdf0e10cSrcweir 0 != ( pFileObj = (SvFileObject*)pLnk->GetObj() ) ) 474cdf0e10cSrcweir // 0 != ( pFileObj = (SvFileObject*)SvFileObject::ClassFactory()-> 475cdf0e10cSrcweir // CastAndAddRef( pLnk->GetObj() )) ) 476cdf0e10cSrcweir pFileObj->CancelTransfers(); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir 4795799d6dbSmarcus // to send status information from the FileObject to the BaseLink, there is an own ClipboardId. 4805799d6dbSmarcus // The SvData object has then the respective information as string. 4815799d6dbSmarcus // Currently this will be used for FileObject in connection with JavaScript 4825799d6dbSmarcus // - that needs information about Load/Abort/Error 483cdf0e10cSrcweir sal_uIntPtr LinkManager::RegisterStatusInfoId() 484cdf0e10cSrcweir { 485cdf0e10cSrcweir static sal_uIntPtr nFormat = 0; 486cdf0e10cSrcweir 487cdf0e10cSrcweir if( !nFormat ) 488cdf0e10cSrcweir { 4895799d6dbSmarcus // how does the new interface look like? 490cdf0e10cSrcweir // nFormat = Exchange::RegisterFormatName( "StatusInfo vom SvxInternalLink" ); 491cdf0e10cSrcweir nFormat = SotExchange::RegisterFormatName( 492cdf0e10cSrcweir String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( 493cdf0e10cSrcweir "StatusInfo vom SvxInternalLink" ))); 494cdf0e10cSrcweir } 495cdf0e10cSrcweir return nFormat; 496cdf0e10cSrcweir } 497cdf0e10cSrcweir 498cdf0e10cSrcweir // ---------------------------------------------------------------------- 499cdf0e10cSrcweir 500cdf0e10cSrcweir sal_Bool LinkManager::GetGraphicFromAny( const String& rMimeType, 501cdf0e10cSrcweir const ::com::sun::star::uno::Any & rValue, 502cdf0e10cSrcweir Graphic& rGrf ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir sal_Bool bRet = sal_False; 505cdf0e10cSrcweir ::com::sun::star::uno::Sequence< sal_Int8 > aSeq; 506cdf0e10cSrcweir if( rValue.hasValue() && ( rValue >>= aSeq ) ) 507cdf0e10cSrcweir { 508cdf0e10cSrcweir SvMemoryStream aMemStm( (void*)aSeq.getConstArray(), aSeq.getLength(), 509cdf0e10cSrcweir STREAM_READ ); 510cdf0e10cSrcweir aMemStm.Seek( 0 ); 511cdf0e10cSrcweir 512cdf0e10cSrcweir switch( SotExchange::GetFormatIdFromMimeType( rMimeType ) ) 513cdf0e10cSrcweir { 514cdf0e10cSrcweir case SOT_FORMATSTR_ID_SVXB: 515cdf0e10cSrcweir { 516cdf0e10cSrcweir aMemStm >> rGrf; 517cdf0e10cSrcweir bRet = sal_True; 518cdf0e10cSrcweir } 519cdf0e10cSrcweir break; 520cdf0e10cSrcweir case FORMAT_GDIMETAFILE: 521cdf0e10cSrcweir { 522cdf0e10cSrcweir GDIMetaFile aMtf; 523cdf0e10cSrcweir aMtf.Read( aMemStm ); 524cdf0e10cSrcweir rGrf = aMtf; 525cdf0e10cSrcweir bRet = sal_True; 526cdf0e10cSrcweir } 527cdf0e10cSrcweir break; 528cdf0e10cSrcweir case FORMAT_BITMAP: 529cdf0e10cSrcweir { 530cdf0e10cSrcweir Bitmap aBmp; 53145fd3b9aSArmin Le Grand ReadDIB(aBmp, aMemStm, true); 532cdf0e10cSrcweir rGrf = aBmp; 533cdf0e10cSrcweir bRet = sal_True; 534cdf0e10cSrcweir } 535cdf0e10cSrcweir break; 536cdf0e10cSrcweir } 537cdf0e10cSrcweir } 538cdf0e10cSrcweir return bRet; 539cdf0e10cSrcweir } 540cdf0e10cSrcweir 541cdf0e10cSrcweir 542cdf0e10cSrcweir // ---------------------------------------------------------------------- 543cdf0e10cSrcweir String lcl_DDE_RelToAbs( const String& rTopic, const String& rBaseURL ) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir String sRet; 546cdf0e10cSrcweir INetURLObject aURL( rTopic ); 547cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() ) 548cdf0e10cSrcweir utl::LocalFileHelper::ConvertSystemPathToURL( rTopic, rBaseURL, sRet ); 549cdf0e10cSrcweir if( !sRet.Len() ) 550cdf0e10cSrcweir sRet = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), rTopic, URIHelper::GetMaybeFileHdl(), true ); 551cdf0e10cSrcweir return sRet; 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554cdf0e10cSrcweir sal_Bool SvxInternalLink::Connect( sfx2::SvBaseLink* pLink ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir SfxObjectShell* pFndShell = 0; 557cdf0e10cSrcweir sal_uInt16 nUpdateMode = com::sun::star::document::UpdateDocMode::NO_UPDATE; 558cdf0e10cSrcweir String sTopic, sItem, sReferer; 559cdf0e10cSrcweir if( pLink->GetLinkManager() && 560cdf0e10cSrcweir pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sTopic, &sItem ) 561cdf0e10cSrcweir && sTopic.Len() ) 562cdf0e10cSrcweir { 5635799d6dbSmarcus // for the moment run through the DocumentShells and search for the ones with names: 564cdf0e10cSrcweir 565cdf0e10cSrcweir com::sun::star::lang::Locale aLocale; 566cdf0e10cSrcweir MsLangId::convertLanguageToLocale( LANGUAGE_SYSTEM, aLocale ); 567cdf0e10cSrcweir CharClass aCC( aLocale ); 568cdf0e10cSrcweir 569cdf0e10cSrcweir String sNm( sTopic ), sTmp; 570cdf0e10cSrcweir aCC.toLower( sNm ); 571cdf0e10cSrcweir 572cdf0e10cSrcweir TypeId aType( TYPE(SfxObjectShell) ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir sal_Bool bFirst = sal_True; 575cdf0e10cSrcweir SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist(); 576cdf0e10cSrcweir if( pShell && pShell->GetMedium() ) 577cdf0e10cSrcweir { 578cdf0e10cSrcweir sReferer = pShell->GetMedium()->GetBaseURL(); 579cdf0e10cSrcweir SFX_ITEMSET_ARG( pShell->GetMedium()->GetItemSet(), pItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False ); 580cdf0e10cSrcweir if ( pItem ) 581cdf0e10cSrcweir nUpdateMode = pItem->GetValue(); 582cdf0e10cSrcweir } 583cdf0e10cSrcweir 584cdf0e10cSrcweir String sNmURL( lcl_DDE_RelToAbs( sTopic, sReferer ) ); 585cdf0e10cSrcweir aCC.toLower( sNmURL ); 586cdf0e10cSrcweir 587cdf0e10cSrcweir if ( !pShell ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir bFirst = sal_False; 590cdf0e10cSrcweir pShell = SfxObjectShell::GetFirst( &aType, sal_False ); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir while( pShell ) 594cdf0e10cSrcweir { 595cdf0e10cSrcweir if( !sTmp.Len() ) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir sTmp = pShell->GetTitle( SFX_TITLE_FULLNAME ); 598cdf0e10cSrcweir sTmp = lcl_DDE_RelToAbs(sTmp, sReferer ); 599cdf0e10cSrcweir } 600cdf0e10cSrcweir 601cdf0e10cSrcweir 602cdf0e10cSrcweir aCC.toLower( sTmp ); 6035799d6dbSmarcus if( sTmp == sNmURL ) // these we want to have 604cdf0e10cSrcweir { 605cdf0e10cSrcweir pFndShell = pShell; 606cdf0e10cSrcweir break; 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir if( bFirst ) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir bFirst = sal_False; 612cdf0e10cSrcweir pShell = SfxObjectShell::GetFirst( &aType, sal_False ); 613cdf0e10cSrcweir } 614cdf0e10cSrcweir else 615cdf0e10cSrcweir pShell = SfxObjectShell::GetNext( *pShell, &aType, sal_False ); 616cdf0e10cSrcweir 617cdf0e10cSrcweir sTmp.Erase(); 618cdf0e10cSrcweir } 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir // empty topics are not allowed - which document is it 622cdf0e10cSrcweir if( !sTopic.Len() ) 623cdf0e10cSrcweir return sal_False; 624cdf0e10cSrcweir 625cdf0e10cSrcweir if( !pFndShell ) 626cdf0e10cSrcweir { 6275799d6dbSmarcus // try to load the file: 628cdf0e10cSrcweir INetURLObject aURL( sTopic ); 629cdf0e10cSrcweir INetProtocol eOld = aURL.GetProtocol(); 630cdf0e10cSrcweir aURL.SetURL( sTopic = lcl_DDE_RelToAbs( sTopic, sReferer ) ); 631cdf0e10cSrcweir if( INET_PROT_NOT_VALID != eOld || 632cdf0e10cSrcweir INET_PROT_HTTP != aURL.GetProtocol() ) 633cdf0e10cSrcweir { 634cdf0e10cSrcweir SfxStringItem aName( SID_FILE_NAME, sTopic ); 635cdf0e10cSrcweir SfxBoolItem aMinimized(SID_MINIMIZED, sal_True); 636cdf0e10cSrcweir SfxBoolItem aHidden(SID_HIDDEN, sal_True); 637cdf0e10cSrcweir SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") ); 638cdf0e10cSrcweir SfxStringItem aReferer( SID_REFERER, sReferer ); 639cdf0e10cSrcweir SfxUInt16Item aUpdate( SID_UPDATEDOCMODE, nUpdateMode ); 640cdf0e10cSrcweir SfxBoolItem aReadOnly(SID_DOC_READONLY, sal_True); 641cdf0e10cSrcweir 642cdf0e10cSrcweir // #i14200# (DDE-link crashes wordprocessor) 643cdf0e10cSrcweir SfxAllItemSet aArgs( SFX_APP()->GetPool() ); 644cdf0e10cSrcweir aArgs.Put(aReferer); 645cdf0e10cSrcweir aArgs.Put(aTarget); 646cdf0e10cSrcweir aArgs.Put(aHidden); 647cdf0e10cSrcweir aArgs.Put(aMinimized); 648cdf0e10cSrcweir aArgs.Put(aName); 649cdf0e10cSrcweir aArgs.Put(aUpdate); 650cdf0e10cSrcweir aArgs.Put(aReadOnly); 651cdf0e10cSrcweir pFndShell = SfxObjectShell::CreateAndLoadObject( aArgs ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir } 654cdf0e10cSrcweir 655cdf0e10cSrcweir sal_Bool bRet = sal_False; 656cdf0e10cSrcweir if( pFndShell ) 657cdf0e10cSrcweir { 658cdf0e10cSrcweir sfx2::SvLinkSource* pNewSrc = pFndShell->DdeCreateLinkSource( sItem ); 659cdf0e10cSrcweir if( pNewSrc ) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir bRet = sal_True; 662cdf0e10cSrcweir 663cdf0e10cSrcweir ::com::sun::star::datatransfer::DataFlavor aFl; 664cdf0e10cSrcweir SotExchange::GetFormatDataFlavor( pLink->GetContentType(), aFl ); 665cdf0e10cSrcweir 666cdf0e10cSrcweir pLink->SetObj( pNewSrc ); 667cdf0e10cSrcweir pNewSrc->AddDataAdvise( pLink, aFl.MimeType, 668cdf0e10cSrcweir sfx2::LINKUPDATE_ONCALL == pLink->GetUpdateMode() 669cdf0e10cSrcweir ? ADVISEMODE_ONLYONCE 670cdf0e10cSrcweir : 0 ); 671cdf0e10cSrcweir } 672cdf0e10cSrcweir } 673cdf0e10cSrcweir return bRet; 674cdf0e10cSrcweir } 675cdf0e10cSrcweir 676cdf0e10cSrcweir 677cdf0e10cSrcweir } 678cdf0e10cSrcweir 679