xref: /trunk/main/sfx2/source/appl/linkmgr2.cxx (revision 789caf29f943fc92f381d52f7415d53ab2ea879c)
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),
69b0c1db7eSPatricia Shanahan     mUpdateAsked(sal_False),
70b0c1db7eSPatricia Shanahan     mAutoAskUpdateAllLinks(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     {
164*789caf29SPatricia Shanahan         Window *parent = NULL;
165*789caf29SPatricia Shanahan         SfxObjectShell* persist = GetPersist();
166*789caf29SPatricia Shanahan         if (persist != NULL)
167*789caf29SPatricia Shanahan             parent = GetPersist()->GetDialogParent();
168*789caf29SPatricia 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;
286b0c1db7eSPatricia Shanahan }
287b0c1db7eSPatricia Shanahan 
288b0c1db7eSPatricia Shanahan sal_Bool LinkManager::GetUserAllowsLinkUpdate(Window *pParentWin)
289b0c1db7eSPatricia Shanahan {
290b0c1db7eSPatricia Shanahan     if (!mUpdateAsked)
291b0c1db7eSPatricia Shanahan     {
292b0c1db7eSPatricia Shanahan         if (QueryBox(pParentWin, WB_YES_NO | WB_DEF_NO, SfxResId(STR_QUERY_UPDATE_LINKS)).Execute() == RET_YES)
293b0c1db7eSPatricia Shanahan             mAllowUpdate = sal_True;
294b0c1db7eSPatricia Shanahan         else
295b0c1db7eSPatricia Shanahan             mAllowUpdate = sal_False;
296b0c1db7eSPatricia Shanahan         mUpdateAsked = sal_True;
297b0c1db7eSPatricia Shanahan     }
298b0c1db7eSPatricia Shanahan     return mAllowUpdate;
299b0c1db7eSPatricia Shanahan }
300b0c1db7eSPatricia Shanahan 
301b0c1db7eSPatricia Shanahan void LinkManager::SetUserAllowsLinkUpdate(SvBaseLink *pLink, sal_Bool allows)
302b0c1db7eSPatricia Shanahan {
303b0c1db7eSPatricia Shanahan     SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist();
304b0c1db7eSPatricia Shanahan 
305b0c1db7eSPatricia Shanahan     if (pShell)
306b0c1db7eSPatricia Shanahan     {
307b0c1db7eSPatricia Shanahan         comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = pShell->getEmbeddedObjectContainer();
308b0c1db7eSPatricia Shanahan         rEmbeddedObjectContainer.setUserAllowsLinkUpdate(allows);
309b0c1db7eSPatricia Shanahan     }
310b0c1db7eSPatricia Shanahan }
311b0c1db7eSPatricia Shanahan 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir void LinkManager::UpdateAllLinks(
314cdf0e10cSrcweir     sal_Bool bAskUpdate,
315cdf0e10cSrcweir     sal_Bool /*bCallErrHdl*/,
316cdf0e10cSrcweir     sal_Bool bUpdateGrfLinks,
317cdf0e10cSrcweir     Window* pParentWin )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     SvStringsDtor aApps, aTopics, aItems;
320cdf0e10cSrcweir     String sApp, sTopic, sItem;
321cdf0e10cSrcweir 
3225799d6dbSmarcus     // first create a copy of the array, so that updated links to not interfere with ... in between!!
323cdf0e10cSrcweir     SvPtrarr aTmpArr( 255, 50 );
324cdf0e10cSrcweir     sal_uInt16 n;
325cdf0e10cSrcweir     for( n = 0; n < aLinkTbl.Count(); ++n )
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         SvBaseLink* pLink = *aLinkTbl[ n ];
328cdf0e10cSrcweir         if( !pLink )
329cdf0e10cSrcweir         {
330cdf0e10cSrcweir             Remove( n-- );
331cdf0e10cSrcweir             continue;
332cdf0e10cSrcweir         }
333cdf0e10cSrcweir         aTmpArr.Insert( pLink, aTmpArr.Count() );
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     for( n = 0; n < aTmpArr.Count(); ++n )
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         SvBaseLink* pLink = (SvBaseLink*)aTmpArr[ n ];
339cdf0e10cSrcweir 
3405799d6dbSmarcus         // first search the entry in the array
341cdf0e10cSrcweir         sal_uInt16 nFndPos = USHRT_MAX;
342cdf0e10cSrcweir         for( sal_uInt16 i = 0; i < aLinkTbl.Count(); ++i )
343cdf0e10cSrcweir             if( pLink == *aLinkTbl[ i ] )
344cdf0e10cSrcweir             {
345cdf0e10cSrcweir                 nFndPos = i;
346cdf0e10cSrcweir                 break;
347cdf0e10cSrcweir             }
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         if( USHRT_MAX == nFndPos )
3505799d6dbSmarcus             continue;                   // was not already existing!
351cdf0e10cSrcweir 
3525799d6dbSmarcus         // do not update graphic links yet
353cdf0e10cSrcweir         if( !pLink->IsVisible() ||
354cdf0e10cSrcweir             ( !bUpdateGrfLinks && OBJECT_CLIENT_GRF == pLink->GetObjType() ))
355cdf0e10cSrcweir             continue;
356cdf0e10cSrcweir 
357b0c1db7eSPatricia Shanahan         sal_Bool allows = sal_True;
358b0c1db7eSPatricia Shanahan 
359cdf0e10cSrcweir         if (bAskUpdate)
360cdf0e10cSrcweir         {
361b0c1db7eSPatricia Shanahan             allows = GetUserAllowsLinkUpdate(pParentWin);
362963c6022SArmin Le Grand         }
363963c6022SArmin Le Grand 
364b0c1db7eSPatricia Shanahan         SetUserAllowsLinkUpdate(pLink, allows);
3655799d6dbSmarcus         bAskUpdate = sal_False;     // one time is OK
366cdf0e10cSrcweir 
367b0c1db7eSPatricia Shanahan         if (allows)
368cdf0e10cSrcweir             pLink->Update();
369cdf0e10cSrcweir     }
370cdf0e10cSrcweir }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir /************************************************************************
373cdf0e10cSrcweir |*    SvBaseLink::CreateObject()
374cdf0e10cSrcweir |*
3755799d6dbSmarcus |*    Description
376cdf0e10cSrcweir *************************************************************************/
377cdf0e10cSrcweir 
378cdf0e10cSrcweir SvLinkSourceRef LinkManager::CreateObj( SvBaseLink * pLink )
379cdf0e10cSrcweir {
380cdf0e10cSrcweir     switch( pLink->GetObjType() )
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir         case OBJECT_CLIENT_FILE:
383cdf0e10cSrcweir         case OBJECT_CLIENT_GRF:
384cdf0e10cSrcweir         case OBJECT_CLIENT_OLE:
385cdf0e10cSrcweir             return new SvFileObject;
386cdf0e10cSrcweir         case OBJECT_INTERN:
387cdf0e10cSrcweir             return new SvxInternalLink;
388cdf0e10cSrcweir         case OBJECT_CLIENT_DDE:
389cdf0e10cSrcweir             return new SvDDEObject;
390cdf0e10cSrcweir         default:
391cdf0e10cSrcweir             return SvLinkSourceRef();
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir sal_Bool LinkManager::InsertServer( SvLinkSource* pObj )
396cdf0e10cSrcweir {
3975799d6dbSmarcus     // do not insert double
398cdf0e10cSrcweir     if( !pObj || USHRT_MAX != aServerTbl.GetPos( pObj ) )
399cdf0e10cSrcweir         return sal_False;
400cdf0e10cSrcweir 
401cdf0e10cSrcweir     aServerTbl.Insert( pObj, aServerTbl.Count() );
402cdf0e10cSrcweir     return sal_True;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 
406cdf0e10cSrcweir void LinkManager::RemoveServer( SvLinkSource* pObj )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     sal_uInt16 nPos = aServerTbl.GetPos( pObj );
409cdf0e10cSrcweir     if( USHRT_MAX != nPos )
410cdf0e10cSrcweir         aServerTbl.Remove( nPos, 1 );
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 
414cdf0e10cSrcweir void MakeLnkName( String& rName, const String* pType, const String& rFile,
415cdf0e10cSrcweir                     const String& rLink, const String* pFilter )
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     if( pType )
418cdf0e10cSrcweir         (rName = *pType).EraseLeadingChars().EraseTrailingChars() += cTokenSeperator;
419cdf0e10cSrcweir     else if( rName.Len() )
420cdf0e10cSrcweir         rName.Erase();
421cdf0e10cSrcweir 
422cdf0e10cSrcweir     ((rName += rFile).EraseLeadingChars().EraseTrailingChars() +=
423cdf0e10cSrcweir         cTokenSeperator ).EraseLeadingChars().EraseTrailingChars() += rLink;
424cdf0e10cSrcweir     if( pFilter )
425cdf0e10cSrcweir         ((rName += cTokenSeperator ) += *pFilter).EraseLeadingChars().EraseTrailingChars();
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir sal_Bool LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink,
429cdf0e10cSrcweir                                     sal_uInt16 nFileType,
430cdf0e10cSrcweir                                     const String& rFileNm,
431cdf0e10cSrcweir                                     const String* pFilterNm,
432cdf0e10cSrcweir                                     const String* pRange )
433cdf0e10cSrcweir {
434cdf0e10cSrcweir     if( !( OBJECT_CLIENT_SO & rLink.GetObjType() ))
435cdf0e10cSrcweir         return sal_False;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     String sCmd( rFileNm );
438cdf0e10cSrcweir     sCmd += ::sfx2::cTokenSeperator;
439cdf0e10cSrcweir     if( pRange )
440cdf0e10cSrcweir         sCmd += *pRange;
441cdf0e10cSrcweir     if( pFilterNm )
442cdf0e10cSrcweir         ( sCmd += ::sfx2::cTokenSeperator ) += *pFilterNm;
443cdf0e10cSrcweir 
444cdf0e10cSrcweir     return InsertLink( &rLink, nFileType, sfx2::LINKUPDATE_ONCALL, &sCmd );
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir sal_Bool LinkManager::InsertFileLink( sfx2::SvBaseLink& rLink )
448cdf0e10cSrcweir {
449cdf0e10cSrcweir     if( OBJECT_CLIENT_FILE == ( OBJECT_CLIENT_FILE & rLink.GetObjType() ))
450cdf0e10cSrcweir         return InsertLink( &rLink, rLink.GetObjType(), sfx2::LINKUPDATE_ONCALL );
451cdf0e10cSrcweir     return sal_False;
452cdf0e10cSrcweir }
453cdf0e10cSrcweir 
4545799d6dbSmarcus // a transfer will be discontinued, therefore cancel all DownloadMedia
4555799d6dbSmarcus // (at the moment only interesting for the FileLinks!)
456cdf0e10cSrcweir void LinkManager::CancelTransfers()
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     SvFileObject* pFileObj;
459cdf0e10cSrcweir     sfx2::SvBaseLink* pLnk;
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     const sfx2::SvBaseLinks& rLnks = GetLinks();
462cdf0e10cSrcweir     for( sal_uInt16 n = rLnks.Count(); n; )
463cdf0e10cSrcweir         if( 0 != ( pLnk = &(*rLnks[ --n ])) &&
464cdf0e10cSrcweir             OBJECT_CLIENT_FILE == (OBJECT_CLIENT_FILE & pLnk->GetObjType()) &&
465cdf0e10cSrcweir             0 != ( pFileObj = (SvFileObject*)pLnk->GetObj() ) )
466cdf0e10cSrcweir //          0 != ( pFileObj = (SvFileObject*)SvFileObject::ClassFactory()->
467cdf0e10cSrcweir //                                  CastAndAddRef( pLnk->GetObj() )) )
468cdf0e10cSrcweir             pFileObj->CancelTransfers();
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
4715799d6dbSmarcus     // to send status information from the FileObject to the BaseLink, there is an own ClipboardId.
4725799d6dbSmarcus     // The SvData object has then the respective information as string.
4735799d6dbSmarcus     // Currently this will be used for FileObject in connection with JavaScript
4745799d6dbSmarcus     // - that needs information about Load/Abort/Error
475cdf0e10cSrcweir sal_uIntPtr LinkManager::RegisterStatusInfoId()
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     static sal_uIntPtr nFormat = 0;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir     if( !nFormat )
480cdf0e10cSrcweir     {
4815799d6dbSmarcus // how does the new interface look like?
482cdf0e10cSrcweir //      nFormat = Exchange::RegisterFormatName( "StatusInfo vom SvxInternalLink" );
483cdf0e10cSrcweir         nFormat = SotExchange::RegisterFormatName(
484cdf0e10cSrcweir                     String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM(
485cdf0e10cSrcweir                                 "StatusInfo vom SvxInternalLink" )));
486cdf0e10cSrcweir     }
487cdf0e10cSrcweir     return nFormat;
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir // ----------------------------------------------------------------------
491cdf0e10cSrcweir 
492cdf0e10cSrcweir sal_Bool LinkManager::GetGraphicFromAny( const String& rMimeType,
493cdf0e10cSrcweir                                 const ::com::sun::star::uno::Any & rValue,
494cdf0e10cSrcweir                                 Graphic& rGrf )
495cdf0e10cSrcweir {
496cdf0e10cSrcweir     sal_Bool bRet = sal_False;
497cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
498cdf0e10cSrcweir     if( rValue.hasValue() && ( rValue >>= aSeq ) )
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         SvMemoryStream aMemStm( (void*)aSeq.getConstArray(), aSeq.getLength(),
501cdf0e10cSrcweir                                 STREAM_READ );
502cdf0e10cSrcweir         aMemStm.Seek( 0 );
503cdf0e10cSrcweir 
504cdf0e10cSrcweir         switch( SotExchange::GetFormatIdFromMimeType( rMimeType ) )
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir         case SOT_FORMATSTR_ID_SVXB:
507cdf0e10cSrcweir             {
508cdf0e10cSrcweir                 aMemStm >> rGrf;
509cdf0e10cSrcweir                 bRet = sal_True;
510cdf0e10cSrcweir             }
511cdf0e10cSrcweir             break;
512cdf0e10cSrcweir         case FORMAT_GDIMETAFILE:
513cdf0e10cSrcweir             {
514cdf0e10cSrcweir                 GDIMetaFile aMtf;
515cdf0e10cSrcweir                 aMtf.Read( aMemStm );
516cdf0e10cSrcweir                 rGrf = aMtf;
517cdf0e10cSrcweir                 bRet = sal_True;
518cdf0e10cSrcweir             }
519cdf0e10cSrcweir             break;
520cdf0e10cSrcweir         case FORMAT_BITMAP:
521cdf0e10cSrcweir             {
522cdf0e10cSrcweir                 Bitmap aBmp;
52345fd3b9aSArmin Le Grand                 ReadDIB(aBmp, aMemStm, true);
524cdf0e10cSrcweir                 rGrf = aBmp;
525cdf0e10cSrcweir                 bRet = sal_True;
526cdf0e10cSrcweir             }
527cdf0e10cSrcweir             break;
528cdf0e10cSrcweir         }
529cdf0e10cSrcweir     }
530cdf0e10cSrcweir     return bRet;
531cdf0e10cSrcweir }
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 
534cdf0e10cSrcweir // ----------------------------------------------------------------------
535cdf0e10cSrcweir String lcl_DDE_RelToAbs( const String& rTopic, const String& rBaseURL )
536cdf0e10cSrcweir {
537cdf0e10cSrcweir     String sRet;
538cdf0e10cSrcweir     INetURLObject aURL( rTopic );
539cdf0e10cSrcweir     if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
540cdf0e10cSrcweir         utl::LocalFileHelper::ConvertSystemPathToURL( rTopic, rBaseURL, sRet );
541cdf0e10cSrcweir     if( !sRet.Len() )
542cdf0e10cSrcweir         sRet = URIHelper::SmartRel2Abs( INetURLObject(rBaseURL), rTopic, URIHelper::GetMaybeFileHdl(), true );
543cdf0e10cSrcweir     return sRet;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir sal_Bool SvxInternalLink::Connect( sfx2::SvBaseLink* pLink )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir     SfxObjectShell* pFndShell = 0;
549cdf0e10cSrcweir     sal_uInt16 nUpdateMode = com::sun::star::document::UpdateDocMode::NO_UPDATE;
550cdf0e10cSrcweir     String sTopic, sItem, sReferer;
551cdf0e10cSrcweir     if( pLink->GetLinkManager() &&
552cdf0e10cSrcweir         pLink->GetLinkManager()->GetDisplayNames( pLink, 0, &sTopic, &sItem )
553cdf0e10cSrcweir         && sTopic.Len() )
554cdf0e10cSrcweir     {
5555799d6dbSmarcus         // for the moment run through the DocumentShells and search for the ones with names:
556cdf0e10cSrcweir 
557cdf0e10cSrcweir         com::sun::star::lang::Locale aLocale;
558cdf0e10cSrcweir         MsLangId::convertLanguageToLocale( LANGUAGE_SYSTEM, aLocale );
559cdf0e10cSrcweir         CharClass aCC( aLocale );
560cdf0e10cSrcweir 
561cdf0e10cSrcweir         String sNm( sTopic ), sTmp;
562cdf0e10cSrcweir         aCC.toLower( sNm );
563cdf0e10cSrcweir 
564cdf0e10cSrcweir         TypeId aType( TYPE(SfxObjectShell) );
565cdf0e10cSrcweir 
566cdf0e10cSrcweir         sal_Bool bFirst = sal_True;
567cdf0e10cSrcweir         SfxObjectShell* pShell = pLink->GetLinkManager()->GetPersist();
568cdf0e10cSrcweir         if( pShell && pShell->GetMedium() )
569cdf0e10cSrcweir         {
570cdf0e10cSrcweir             sReferer = pShell->GetMedium()->GetBaseURL();
571cdf0e10cSrcweir             SFX_ITEMSET_ARG( pShell->GetMedium()->GetItemSet(), pItem, SfxUInt16Item, SID_UPDATEDOCMODE, sal_False );
572cdf0e10cSrcweir             if ( pItem )
573cdf0e10cSrcweir                 nUpdateMode = pItem->GetValue();
574cdf0e10cSrcweir         }
575cdf0e10cSrcweir 
576cdf0e10cSrcweir         String sNmURL( lcl_DDE_RelToAbs( sTopic, sReferer ) );
577cdf0e10cSrcweir         aCC.toLower( sNmURL );
578cdf0e10cSrcweir 
579cdf0e10cSrcweir         if ( !pShell )
580cdf0e10cSrcweir         {
581cdf0e10cSrcweir             bFirst = sal_False;
582cdf0e10cSrcweir             pShell = SfxObjectShell::GetFirst( &aType, sal_False );
583cdf0e10cSrcweir         }
584cdf0e10cSrcweir 
585cdf0e10cSrcweir         while( pShell )
586cdf0e10cSrcweir         {
587cdf0e10cSrcweir             if( !sTmp.Len() )
588cdf0e10cSrcweir             {
589cdf0e10cSrcweir                 sTmp = pShell->GetTitle( SFX_TITLE_FULLNAME );
590cdf0e10cSrcweir                 sTmp = lcl_DDE_RelToAbs(sTmp, sReferer );
591cdf0e10cSrcweir             }
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 
594cdf0e10cSrcweir             aCC.toLower( sTmp );
5955799d6dbSmarcus             if( sTmp == sNmURL )        // these we want to have
596cdf0e10cSrcweir             {
597cdf0e10cSrcweir                 pFndShell = pShell;
598cdf0e10cSrcweir                 break;
599cdf0e10cSrcweir             }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir             if( bFirst )
602cdf0e10cSrcweir             {
603cdf0e10cSrcweir                 bFirst = sal_False;
604cdf0e10cSrcweir                 pShell = SfxObjectShell::GetFirst( &aType, sal_False );
605cdf0e10cSrcweir             }
606cdf0e10cSrcweir             else
607cdf0e10cSrcweir                 pShell = SfxObjectShell::GetNext( *pShell, &aType, sal_False );
608cdf0e10cSrcweir 
609cdf0e10cSrcweir             sTmp.Erase();
610cdf0e10cSrcweir         }
611cdf0e10cSrcweir     }
612cdf0e10cSrcweir 
613cdf0e10cSrcweir     // empty topics are not allowed - which document is it
614cdf0e10cSrcweir     if( !sTopic.Len() )
615cdf0e10cSrcweir         return sal_False;
616cdf0e10cSrcweir 
617cdf0e10cSrcweir     if( !pFndShell )
618cdf0e10cSrcweir     {
6195799d6dbSmarcus         // try to load the file:
620cdf0e10cSrcweir         INetURLObject aURL( sTopic );
621cdf0e10cSrcweir         INetProtocol eOld = aURL.GetProtocol();
622cdf0e10cSrcweir         aURL.SetURL( sTopic = lcl_DDE_RelToAbs( sTopic, sReferer ) );
623cdf0e10cSrcweir         if( INET_PROT_NOT_VALID != eOld ||
624cdf0e10cSrcweir             INET_PROT_HTTP != aURL.GetProtocol() )
625cdf0e10cSrcweir         {
626cdf0e10cSrcweir             SfxStringItem aName( SID_FILE_NAME, sTopic );
627cdf0e10cSrcweir             SfxBoolItem aMinimized(SID_MINIMIZED, sal_True);
628cdf0e10cSrcweir             SfxBoolItem aHidden(SID_HIDDEN, sal_True);
629cdf0e10cSrcweir             SfxStringItem aTarget( SID_TARGETNAME, String::CreateFromAscii("_blank") );
630cdf0e10cSrcweir             SfxStringItem aReferer( SID_REFERER, sReferer );
631cdf0e10cSrcweir             SfxUInt16Item aUpdate( SID_UPDATEDOCMODE, nUpdateMode );
632cdf0e10cSrcweir             SfxBoolItem aReadOnly(SID_DOC_READONLY, sal_True);
633cdf0e10cSrcweir 
634cdf0e10cSrcweir             // #i14200# (DDE-link crashes wordprocessor)
635cdf0e10cSrcweir             SfxAllItemSet aArgs( SFX_APP()->GetPool() );
636cdf0e10cSrcweir             aArgs.Put(aReferer);
637cdf0e10cSrcweir             aArgs.Put(aTarget);
638cdf0e10cSrcweir             aArgs.Put(aHidden);
639cdf0e10cSrcweir             aArgs.Put(aMinimized);
640cdf0e10cSrcweir             aArgs.Put(aName);
641cdf0e10cSrcweir             aArgs.Put(aUpdate);
642cdf0e10cSrcweir             aArgs.Put(aReadOnly);
643cdf0e10cSrcweir             pFndShell = SfxObjectShell::CreateAndLoadObject( aArgs );
644cdf0e10cSrcweir         }
645cdf0e10cSrcweir     }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     sal_Bool bRet = sal_False;
648cdf0e10cSrcweir     if( pFndShell )
649cdf0e10cSrcweir     {
650cdf0e10cSrcweir         sfx2::SvLinkSource* pNewSrc = pFndShell->DdeCreateLinkSource( sItem );
651cdf0e10cSrcweir         if( pNewSrc )
652cdf0e10cSrcweir         {
653cdf0e10cSrcweir             bRet = sal_True;
654cdf0e10cSrcweir 
655cdf0e10cSrcweir             ::com::sun::star::datatransfer::DataFlavor aFl;
656cdf0e10cSrcweir             SotExchange::GetFormatDataFlavor( pLink->GetContentType(), aFl );
657cdf0e10cSrcweir 
658cdf0e10cSrcweir             pLink->SetObj( pNewSrc );
659cdf0e10cSrcweir             pNewSrc->AddDataAdvise( pLink, aFl.MimeType,
660cdf0e10cSrcweir                                 sfx2::LINKUPDATE_ONCALL == pLink->GetUpdateMode()
661cdf0e10cSrcweir                                     ? ADVISEMODE_ONLYONCE
662cdf0e10cSrcweir                                     : 0 );
663cdf0e10cSrcweir         }
664cdf0e10cSrcweir     }
665cdf0e10cSrcweir     return bRet;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
671