fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / docshell / documentlinkmgr.cxx
blob42745eb3f3442e0b6de05b1ba2210ed50c7c370a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <documentlinkmgr.hxx>
21 #include <datastream.hxx>
22 #include <ddelink.hxx>
23 #include <sc.hrc>
24 #include <scresid.hxx>
26 #include <sfx2/linkmgr.hxx>
27 #include <vcl/layout.hxx>
29 #include <boost/noncopyable.hpp>
30 #include <boost/scoped_ptr.hpp>
32 namespace sc {
34 struct DocumentLinkManagerImpl : boost::noncopyable
36 ScDocument& mrDoc;
37 SfxObjectShell* mpShell;
38 boost::scoped_ptr<DataStream> mpDataStream;
39 boost::scoped_ptr<sfx2::LinkManager> mpLinkManager;
41 DocumentLinkManagerImpl( ScDocument& rDoc, SfxObjectShell* pShell ) :
42 mrDoc(rDoc), mpShell(pShell), mpDataStream(NULL), mpLinkManager(NULL) {}
44 ~DocumentLinkManagerImpl()
46 // Shared base links
47 if (mpLinkManager)
49 sfx2::SvLinkSources aTemp = mpLinkManager->GetServers();
50 for (sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it)
51 (*it)->Closed();
53 if (!mpLinkManager->GetLinks().empty())
54 mpLinkManager->Remove(0, mpLinkManager->GetLinks().size());
59 DocumentLinkManager::DocumentLinkManager( ScDocument& rDoc, SfxObjectShell* pShell ) :
60 mpImpl(new DocumentLinkManagerImpl(rDoc, pShell)) {}
62 DocumentLinkManager::~DocumentLinkManager()
64 delete mpImpl;
67 void DocumentLinkManager::setDataStream( DataStream* p )
69 mpImpl->mpDataStream.reset(p);
72 DataStream* DocumentLinkManager::getDataStream()
74 return mpImpl->mpDataStream.get();
77 const DataStream* DocumentLinkManager::getDataStream() const
79 return mpImpl->mpDataStream.get();
82 sfx2::LinkManager* DocumentLinkManager::getLinkManager( bool bCreate )
84 if (!mpImpl->mpLinkManager && bCreate && mpImpl->mpShell)
85 mpImpl->mpLinkManager.reset(new sfx2::LinkManager(mpImpl->mpShell));
86 return mpImpl->mpLinkManager.get();
89 const sfx2::LinkManager* DocumentLinkManager::getExistingLinkManager() const
91 return mpImpl->mpLinkManager.get();
94 bool DocumentLinkManager::idleCheckLinks()
96 if (!mpImpl->mpLinkManager)
97 return false;
99 bool bAnyLeft = false;
100 const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
101 for (size_t i = 0, n = rLinks.size(); i < n; ++i)
103 sfx2::SvBaseLink* pBase = *rLinks[i];
104 ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
105 if (!pDdeLink || !pDdeLink->NeedsUpdate())
106 continue;
108 pDdeLink->TryUpdate();
109 if (pDdeLink->NeedsUpdate()) // Was not successful?
110 bAnyLeft = true;
113 return bAnyLeft;
116 bool DocumentLinkManager::hasDdeLinks() const
118 if (!mpImpl->mpLinkManager)
119 return false;
121 const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
122 for (size_t i = 0, n = rLinks.size(); i < n; ++i)
124 sfx2::SvBaseLink* pBase = *rLinks[i];
125 if (dynamic_cast<ScDdeLink*>(pBase))
126 return true;
129 return false;
132 bool DocumentLinkManager::updateDdeLinks( vcl::Window* pWin )
134 if (!mpImpl->mpLinkManager)
135 return false;
137 sfx2::LinkManager* pMgr = mpImpl->mpLinkManager.get();
138 const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
140 // If the update takes longer, reset all values so that nothing
141 // old (wrong) is left behind
142 bool bAny = false;
143 for (size_t i = 0, n = rLinks.size(); i < n; ++i)
145 sfx2::SvBaseLink* pBase = *rLinks[i];
146 ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
147 if (!pDdeLink)
148 continue;
150 if (pDdeLink->Update())
151 bAny = true;
152 else
154 // Update failed. Notify the user.
155 OUString aFile = pDdeLink->GetTopic();
156 OUString aElem = pDdeLink->GetItem();
157 OUString aType = pDdeLink->GetAppl();
159 OUStringBuffer aBuf;
160 aBuf.append(OUString(ScResId(SCSTR_DDEDOC_NOT_LOADED)));
161 aBuf.appendAscii("\n\n");
162 aBuf.appendAscii("Source : ");
163 aBuf.append(aFile);
164 aBuf.appendAscii("\nElement : ");
165 aBuf.append(aElem);
166 aBuf.appendAscii("\nType : ");
167 aBuf.append(aType);
168 ScopedVclPtrInstance< MessageDialog > aBox(pWin, aBuf.makeStringAndClear());
169 aBox->Execute();
173 pMgr->CloseCachedComps();
175 return bAny;
178 bool DocumentLinkManager::updateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem )
180 if (!mpImpl->mpLinkManager)
181 return false;
183 sfx2::LinkManager* pMgr = mpImpl->mpLinkManager.get();
184 const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
186 bool bFound = false;
187 for (size_t i = 0, n = rLinks.size(); i < n; ++i)
189 ::sfx2::SvBaseLink* pBase = *rLinks[i];
190 ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
191 if (!pDdeLink)
192 continue;
194 if ( OUString(pDdeLink->GetAppl()) == rAppl &&
195 OUString(pDdeLink->GetTopic()) == rTopic &&
196 OUString(pDdeLink->GetItem()) == rItem )
198 pDdeLink->TryUpdate();
199 bFound = true; // Could be multiple (Mode), so continue searching
203 return bFound;
206 size_t DocumentLinkManager::getDdeLinkCount() const
208 if (!mpImpl->mpLinkManager)
209 return 0;
211 size_t nDdeCount = 0;
212 const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
213 for (size_t i = 0, n = rLinks.size(); i < n; ++i)
215 ::sfx2::SvBaseLink* pBase = *rLinks[i];
216 ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
217 if (!pDdeLink)
218 continue;
220 ++nDdeCount;
223 return nDdeCount;
226 void DocumentLinkManager::disconnectDdeLinks()
228 if (!mpImpl->mpLinkManager)
229 return;
231 const sfx2::SvBaseLinks& rLinks = mpImpl->mpLinkManager->GetLinks();
232 for (size_t i = 0, n = rLinks.size(); i < n; ++i)
234 ::sfx2::SvBaseLink* pBase = *rLinks[i];
235 ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>(pBase);
236 if (pDdeLink)
237 pDdeLink->Disconnect();
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */