fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / undo / areasave.cxx
blob23f5881e42289ab84585e18dbbc155c822546b10
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 <sfx2/linkmgr.hxx>
22 #include "areasave.hxx"
23 #include "arealink.hxx"
24 #include "document.hxx"
25 #include <documentlinkmgr.hxx>
27 ScAreaLinkSaver::ScAreaLinkSaver( const ScAreaLink& rSource ) :
28 aFileName ( rSource.GetFile() ),
29 aFilterName ( rSource.GetFilter() ),
30 aOptions ( rSource.GetOptions() ),
31 aSourceArea ( rSource.GetSource() ),
32 aDestArea ( rSource.GetDestArea() ),
33 nRefresh ( rSource.GetRefreshDelay() ) // seconds
37 ScAreaLinkSaver::ScAreaLinkSaver( const ScAreaLinkSaver& rCopy ) :
38 aFileName ( rCopy.aFileName ),
39 aFilterName ( rCopy.aFilterName ),
40 aOptions ( rCopy.aOptions ),
41 aSourceArea ( rCopy.aSourceArea ),
42 aDestArea ( rCopy.aDestArea ),
43 nRefresh ( rCopy.nRefresh )
47 ScAreaLinkSaver::~ScAreaLinkSaver() {}
49 bool ScAreaLinkSaver::IsEqualSource( const ScAreaLink& rCompare ) const
51 return ( aFileName.equals(rCompare.GetFile()) &&
52 aFilterName.equals(rCompare.GetFilter()) &&
53 aOptions.equals(rCompare.GetOptions()) &&
54 aSourceArea.equals(rCompare.GetSource()) &&
55 nRefresh == rCompare.GetRefreshDelay() );
58 bool ScAreaLinkSaver::IsEqual( const ScAreaLink& rCompare ) const
60 return ( IsEqualSource( rCompare ) &&
61 aDestArea == rCompare.GetDestArea() );
64 void ScAreaLinkSaver::WriteToLink( ScAreaLink& rLink ) const
66 rLink.SetDestArea( aDestArea );
69 void ScAreaLinkSaver::InsertNewLink( ScDocument* pDoc )
71 // (see ScUndoRemoveAreaLink::Undo)
73 sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
74 SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
76 if ( pLinkManager && pObjSh )
78 ScAreaLink* pLink = new ScAreaLink( pObjSh, aFileName, aFilterName, aOptions,
79 aSourceArea, aDestArea.aStart, nRefresh );
80 pLink->SetInCreate( true );
81 pLink->SetDestArea( aDestArea );
82 OUString aTmp1(aFilterName), aTmp2(aSourceArea);
83 pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aFileName, &aTmp1, &aTmp2 );
84 pLink->Update();
85 pLink->SetInCreate( false );
89 ScAreaLinkSaveCollection::ScAreaLinkSaveCollection() {}
91 ScAreaLinkSaveCollection::ScAreaLinkSaveCollection( const ScAreaLinkSaveCollection& r ) :
92 maData(r.maData) {}
94 ScAreaLinkSaveCollection::~ScAreaLinkSaveCollection() {}
96 bool ScAreaLinkSaveCollection::IsEqual( const ScDocument* pDoc ) const
98 // IsEqual can be checked in sequence.
99 // Neither ref-update nor removing links will change the order.
101 const sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
102 if (pLinkManager)
104 size_t nPos = 0;
105 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
106 sal_uInt16 nLinkCount = rLinks.size();
107 for (sal_uInt16 i=0; i<nLinkCount; i++)
109 ::sfx2::SvBaseLink* pBase = *rLinks[i];
110 if (pBase->ISA(ScAreaLink))
112 if ( nPos >= size() || !(*this)[nPos]->IsEqual( *static_cast<ScAreaLink*>(pBase) ) )
113 return false;
115 ++nPos;
118 if ( nPos < size() )
119 return false; // fewer links in the document than in the save collection
122 return true;
125 static ScAreaLink* lcl_FindLink( const ::sfx2::SvBaseLinks& rLinks, const ScAreaLinkSaver& rSaver )
127 sal_uInt16 nLinkCount = rLinks.size();
128 for (sal_uInt16 i=0; i<nLinkCount; i++)
130 ::sfx2::SvBaseLink* pBase = *rLinks[i];
131 if ( pBase->ISA(ScAreaLink) &&
132 rSaver.IsEqualSource( *static_cast<ScAreaLink*>(pBase) ) )
134 return static_cast<ScAreaLink*>(pBase); // found
137 return NULL; // not found
140 void ScAreaLinkSaveCollection::Restore( ScDocument* pDoc )
142 // The save collection may contain additional entries that are not in the document.
143 // They must be inserted again.
144 // Entries from the save collection must be searched via source data, as the order
145 // of links changes if deleted entries are re-added to the link manager (always at the end).
147 sfx2::LinkManager* pLinkManager = pDoc->GetDocLinkManager().getLinkManager(false);
148 if (pLinkManager)
150 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
151 size_t nSaveCount = size();
152 for (size_t nPos=0; nPos<nSaveCount; ++nPos)
154 ScAreaLinkSaver* pSaver = (*this)[nPos];
155 ScAreaLink* pLink = lcl_FindLink( rLinks, *pSaver );
156 if ( pLink )
157 pSaver->WriteToLink( *pLink ); // restore output position
158 else
159 pSaver->InsertNewLink( pDoc ); // re-insert deleted link
164 ScAreaLinkSaveCollection* ScAreaLinkSaveCollection::CreateFromDoc( const ScDocument* pDoc )
166 ScAreaLinkSaveCollection* pColl = NULL;
168 sfx2::LinkManager* pLinkManager = const_cast<ScDocument*>(pDoc)->GetLinkManager();
169 if (pLinkManager)
171 const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
172 sal_uInt16 nLinkCount = rLinks.size();
173 for (sal_uInt16 i=0; i<nLinkCount; i++)
175 ::sfx2::SvBaseLink* pBase = *rLinks[i];
176 if (pBase->ISA(ScAreaLink))
178 if (!pColl)
179 pColl = new ScAreaLinkSaveCollection;
181 ScAreaLinkSaver* pSaver = new ScAreaLinkSaver( *static_cast<ScAreaLink*>(pBase ));
182 pColl->push_back(pSaver);
187 return pColl;
190 ScAreaLinkSaver* ScAreaLinkSaveCollection::operator [](size_t nIndex)
192 return &maData[nIndex];
195 const ScAreaLinkSaver* ScAreaLinkSaveCollection::operator [](size_t nIndex) const
197 return &maData[nIndex];
200 size_t ScAreaLinkSaveCollection::size() const
202 return maData.size();
205 void ScAreaLinkSaveCollection::push_back(ScAreaLinkSaver* p)
207 maData.push_back(p);
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */