1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: linkmgr2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
35 #include <tools/debug.hxx>
36 #include <sfx2/linkmgr.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sfx2/lnkbase.hxx>
40 //#include <sfx2/linksrc.hxx>
41 #include "impldde.hxx"
42 //#include "svuidlg.hrc"
43 //#include "iface.hxx"
46 #include "sfxresid.hxx"
48 #define _SVSTDARR_STRINGSDTOR
50 #include <svtools/svstdarr.hxx>
56 SV_IMPL_PTRARR( SvBaseLinks
, SvBaseLinkRefPtr
)
58 SvLinkManager::SvLinkManager()
64 SvLinkManager::~SvLinkManager()
66 SvBaseLinkRef
** ppRef
= (SvBaseLinkRef
**)aLinkTbl
.GetData();
67 for( USHORT n
= aLinkTbl
.Count(); n
; --n
, ++ppRef
)
71 (*(*ppRef
))->Disconnect();
72 (*(*ppRef
))->SetLinkManager( NULL
);
79 /************************************************************************
80 |* SvLinkManager::Remove()
83 *************************************************************************/
85 void SvLinkManager::Remove( SvBaseLink
*pLink
)
87 // keine Links doppelt einfuegen
89 SvBaseLinkRef
** ppRef
= (SvBaseLinkRef
**)aLinkTbl
.GetData();
90 for( USHORT n
= aLinkTbl
.Count(); n
; --n
, ++ppRef
)
92 if( pLink
== *(*ppRef
) )
94 (*(*ppRef
))->Disconnect();
95 (*(*ppRef
))->SetLinkManager( NULL
);
100 // falls noch leere rum stehen sollten, weg damit
101 if( !(*ppRef
)->Is() )
104 aLinkTbl
.Remove( aLinkTbl
.Count() - n
, 1 );
113 void SvLinkManager::Remove( USHORT nPos
, USHORT nCnt
)
115 if( nCnt
&& nPos
< aLinkTbl
.Count() )
117 if( nPos
+ nCnt
> aLinkTbl
.Count() )
118 nCnt
= aLinkTbl
.Count() - nPos
;
120 SvBaseLinkRef
** ppRef
= (SvBaseLinkRef
**)aLinkTbl
.GetData() + nPos
;
121 for( USHORT n
= nCnt
; n
; --n
, ++ppRef
)
125 (*(*ppRef
))->Disconnect();
126 (*(*ppRef
))->SetLinkManager( NULL
);
130 aLinkTbl
.Remove( nPos
, nCnt
);
135 BOOL
SvLinkManager::Insert( SvBaseLink
* pLink
)
137 // keine Links doppelt einfuegen
138 for( USHORT n
= 0; n
< aLinkTbl
.Count(); ++n
)
140 SvBaseLinkRef
* pTmp
= aLinkTbl
[ n
];
142 aLinkTbl
.DeleteAndDestroy( n
-- );
148 SvBaseLinkRef
* pTmp
= new SvBaseLinkRef( pLink
);
149 pLink
->SetLinkManager( this );
150 aLinkTbl
.Insert( pTmp
, aLinkTbl
.Count() );
155 BOOL
SvLinkManager::InsertLink( SvBaseLink
* pLink
,
158 const String
* pName
)
161 pLink
->SetObjType( nObjType
);
163 pLink
->SetName( *pName
);
164 pLink
->SetUpdateMode( nUpdateMode
);
165 return Insert( pLink
);
169 BOOL
SvLinkManager::InsertDDELink( SvBaseLink
* pLink
,
170 const String
& rServer
,
171 const String
& rTopic
,
172 const String
& rItem
)
174 if( !( OBJECT_CLIENT_SO
& pLink
->GetObjType() ) )
178 ::sfx2::MakeLnkName( sCmd
, &rServer
, rTopic
, rItem
);
180 pLink
->SetObjType( OBJECT_CLIENT_DDE
);
181 pLink
->SetName( sCmd
);
182 return Insert( pLink
);
186 BOOL
SvLinkManager::InsertDDELink( SvBaseLink
* pLink
)
188 DBG_ASSERT( OBJECT_CLIENT_SO
& pLink
->GetObjType(), "no OBJECT_CLIENT_SO" );
189 if( !( OBJECT_CLIENT_SO
& pLink
->GetObjType() ) )
192 if( pLink
->GetObjType() == OBJECT_CLIENT_SO
)
193 pLink
->SetObjType( OBJECT_CLIENT_DDE
);
195 return Insert( pLink
);
199 // erfrage die Strings fuer den Dialog
200 BOOL
SvLinkManager::GetDisplayNames( const SvBaseLink
* pLink
,
204 String
* /*pFilter*/ ) const
207 String aLN
= pLink
->GetLinkSourceName();
208 if( aLN
.Len() != 0 && pLink
->GetObjType() == OBJECT_CLIENT_DDE
)
212 String
sServer( sCmd
.GetToken( 0, cTokenSeperator
, nTmp
) );
213 String
sTopic( sCmd
.GetToken( 0, cTokenSeperator
, nTmp
) );
220 *pLinkStr
= sCmd
.Copy( nTmp
);
227 void SvLinkManager::UpdateAllLinks(
229 BOOL
/*bCallErrHdl*/,
230 BOOL bUpdateGrfLinks
,
233 SvStringsDtor aApps
, aTopics
, aItems
;
234 String sApp
, sTopic
, sItem
;
236 // erstmal eine Kopie vom Array machen, damit sich updatende Links in
237 // Links in ... nicht dazwischen funken!!
238 SvPtrarr
aTmpArr( 255, 50 );
240 for( n
= 0; n
< aLinkTbl
.Count(); ++n
)
242 SvBaseLink
* pLink
= *aLinkTbl
[ n
];
248 aTmpArr
.Insert( pLink
, aTmpArr
.Count() );
251 for( n
= 0; n
< aTmpArr
.Count(); ++n
)
253 SvBaseLink
* pLink
= (SvBaseLink
*)aTmpArr
[ n
];
255 // suche erstmal im Array nach dem Eintrag
256 USHORT nFndPos
= USHRT_MAX
;
257 for( USHORT i
= 0; i
< aLinkTbl
.Count(); ++i
)
258 if( pLink
== *aLinkTbl
[ i
] )
264 if( USHRT_MAX
== nFndPos
)
265 continue; // war noch nicht vorhanden!
267 // Graphic-Links noch nicht updaten
268 if( !pLink
->IsVisible() ||
269 ( !bUpdateGrfLinks
&& OBJECT_CLIENT_GRF
== pLink
->GetObjType() ))
274 int nRet
= QueryBox( pParentWin
, WB_YES_NO
| WB_DEF_YES
, SfxResId( STR_QUERY_UPDATE_LINKS
) ).Execute();
275 if( RET_YES
!= nRet
)
276 return ; // es soll nichts geupdatet werden
277 bAskUpdate
= FALSE
; // einmal reicht
284 /************************************************************************
285 |* SvBaseLink::CreateObject()
288 *************************************************************************/
290 SvLinkSourceRef
SvLinkManager::CreateObj( SvBaseLink
* pLink
)
292 if( OBJECT_CLIENT_DDE
== pLink
->GetObjType() )
293 return new SvDDEObject();
294 return SvLinkSourceRef();
297 BOOL
SvLinkManager::InsertServer( SvLinkSource
* pObj
)
299 // keine doppelt einfuegen
300 if( !pObj
|| USHRT_MAX
!= aServerTbl
.GetPos( pObj
) )
303 aServerTbl
.Insert( pObj
, aServerTbl
.Count() );
308 void SvLinkManager::RemoveServer( SvLinkSource
* pObj
)
310 USHORT nPos
= aServerTbl
.GetPos( pObj
);
311 if( USHRT_MAX
!= nPos
)
312 aServerTbl
.Remove( nPos
, 1 );
316 void MakeLnkName( String
& rName
, const String
* pType
, const String
& rFile
,
317 const String
& rLink
, const String
* pFilter
)
320 (rName
= *pType
).EraseLeadingChars().EraseTrailingChars() += cTokenSeperator
;
321 else if( rName
.Len() )
324 ((rName
+= rFile
).EraseLeadingChars().EraseTrailingChars() +=
325 cTokenSeperator
).EraseLeadingChars().EraseTrailingChars() += rLink
;
327 ((rName
+= cTokenSeperator
) += *pFilter
).EraseLeadingChars().EraseTrailingChars();