merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / appl / linkmgr2.cxx
blobde1c524ec7b648b12b9d927e5aabf6929969f0d0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: linkmgr2.cxx,v $
10 * $Revision: 1.8 $
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"
45 #include "app.hrc"
46 #include "sfxresid.hxx"
48 #define _SVSTDARR_STRINGSDTOR
50 #include <svtools/svstdarr.hxx>
53 namespace sfx2
56 SV_IMPL_PTRARR( SvBaseLinks, SvBaseLinkRefPtr )
58 SvLinkManager::SvLinkManager()
59 : pPersist( 0 )
64 SvLinkManager::~SvLinkManager()
66 SvBaseLinkRef** ppRef = (SvBaseLinkRef**)aLinkTbl.GetData();
67 for( USHORT n = aLinkTbl.Count(); n; --n, ++ppRef )
69 if( (*ppRef)->Is() )
71 (*(*ppRef))->Disconnect();
72 (*(*ppRef))->SetLinkManager( NULL );
74 delete *ppRef;
79 /************************************************************************
80 |* SvLinkManager::Remove()
82 |* Beschreibung
83 *************************************************************************/
85 void SvLinkManager::Remove( SvBaseLink *pLink )
87 // keine Links doppelt einfuegen
88 int bFound = FALSE;
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 );
96 (*(*ppRef)).Clear();
97 bFound = TRUE;
100 // falls noch leere rum stehen sollten, weg damit
101 if( !(*ppRef)->Is() )
103 delete *ppRef;
104 aLinkTbl.Remove( aLinkTbl.Count() - n, 1 );
105 if( bFound )
106 return ;
107 --ppRef;
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 )
123 if( (*ppRef)->Is() )
125 (*(*ppRef))->Disconnect();
126 (*(*ppRef))->SetLinkManager( NULL );
128 delete *ppRef;
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 ];
141 if( !pTmp->Is() )
142 aLinkTbl.DeleteAndDestroy( n-- );
144 if( pLink == *pTmp )
145 return FALSE;
148 SvBaseLinkRef* pTmp = new SvBaseLinkRef( pLink );
149 pLink->SetLinkManager( this );
150 aLinkTbl.Insert( pTmp, aLinkTbl.Count() );
151 return TRUE;
155 BOOL SvLinkManager::InsertLink( SvBaseLink * pLink,
156 USHORT nObjType,
157 USHORT nUpdateMode,
158 const String* pName )
160 // unbedingt zuerst
161 pLink->SetObjType( nObjType );
162 if( pName )
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() ) )
175 return FALSE;
177 String sCmd;
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() ) )
190 return FALSE;
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,
201 String* pType,
202 String* pFile,
203 String* pLinkStr,
204 String* /*pFilter*/ ) const
206 BOOL bRet = FALSE;
207 String aLN = pLink->GetLinkSourceName();
208 if( aLN.Len() != 0 && pLink->GetObjType() == OBJECT_CLIENT_DDE )
210 USHORT nTmp = 0;
211 String sCmd( aLN );
212 String sServer( sCmd.GetToken( 0, cTokenSeperator, nTmp ) );
213 String sTopic( sCmd.GetToken( 0, cTokenSeperator, nTmp ) );
215 if( pType )
216 *pType = sServer;
217 if( pFile )
218 *pFile = sTopic;
219 if( pLinkStr )
220 *pLinkStr = sCmd.Copy( nTmp );
221 bRet = TRUE;
223 return bRet;
227 void SvLinkManager::UpdateAllLinks(
228 BOOL bAskUpdate,
229 BOOL /*bCallErrHdl*/,
230 BOOL bUpdateGrfLinks,
231 Window* pParentWin )
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 );
239 USHORT n;
240 for( n = 0; n < aLinkTbl.Count(); ++n )
242 SvBaseLink* pLink = *aLinkTbl[ n ];
243 if( !pLink )
245 Remove( n-- );
246 continue;
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 ] )
260 nFndPos = i;
261 break;
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() ))
270 continue;
272 if( bAskUpdate )
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
280 pLink->Update();
284 /************************************************************************
285 |* SvBaseLink::CreateObject()
287 |* Beschreibung
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 ) )
301 return FALSE;
303 aServerTbl.Insert( pObj, aServerTbl.Count() );
304 return TRUE;
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 )
319 if( pType )
320 (rName = *pType).EraseLeadingChars().EraseTrailingChars() += cTokenSeperator;
321 else if( rName.Len() )
322 rName.Erase();
324 ((rName += rFile).EraseLeadingChars().EraseTrailingChars() +=
325 cTokenSeperator ).EraseLeadingChars().EraseTrailingChars() += rLink;
326 if( pFilter )
327 ((rName += cTokenSeperator ) += *pFilter).EraseLeadingChars().EraseTrailingChars();