1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <svl/smplhint.hxx>
30cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "linkuno.hxx"
33cdf0e10cSrcweir #include "miscuno.hxx"
34cdf0e10cSrcweir #include "convuno.hxx"
35cdf0e10cSrcweir #include "docsh.hxx"
36cdf0e10cSrcweir #include "docfunc.hxx"
37cdf0e10cSrcweir #include "collect.hxx"
38cdf0e10cSrcweir #include "tablink.hxx"
39cdf0e10cSrcweir #include "arealink.hxx"
40cdf0e10cSrcweir #include "unoguard.hxx"
41cdf0e10cSrcweir #include "hints.hxx"
42cdf0e10cSrcweir #include "unonames.hxx"
43cdf0e10cSrcweir #include "rangeseq.hxx"
44cdf0e10cSrcweir #include "token.hxx"
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include <vector>
47cdf0e10cSrcweir #include <climits>
48cdf0e10cSrcweir
49cdf0e10cSrcweir using namespace com::sun::star;
50cdf0e10cSrcweir using namespace formula;
51cdf0e10cSrcweir using ::com::sun::star::uno::Any;
52cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
53cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
54cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
55cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
56cdf0e10cSrcweir using ::com::sun::star::lang::IllegalArgumentException;
57cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
58cdf0e10cSrcweir using ::rtl::OUString;
59cdf0e10cSrcweir using ::std::vector;
60cdf0e10cSrcweir
61cdf0e10cSrcweir //------------------------------------------------------------------------
62cdf0e10cSrcweir
63cdf0e10cSrcweir // fuer Sheet- und Area-Links benutzt:
lcl_GetSheetLinkMap()64cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetSheetLinkMap()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir static SfxItemPropertyMapEntry aSheetLinkMap_Impl[] =
67cdf0e10cSrcweir {
68cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_FILTER), 0, &getCppuType((rtl::OUString*)0), 0, 0 },
69cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_FILTOPT), 0, &getCppuType((rtl::OUString*)0), 0, 0 },
70cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_LINKURL), 0, &getCppuType((rtl::OUString*)0), 0, 0 },
71cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_REFDELAY), 0, &getCppuType((sal_Int32*)0), 0, 0 },
72cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNONAME_REFPERIOD), 0, &getCppuType((sal_Int32*)0), 0, 0 },
73cdf0e10cSrcweir {0,0,0,0,0,0}
74cdf0e10cSrcweir };
75cdf0e10cSrcweir return aSheetLinkMap_Impl;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
78cdf0e10cSrcweir //------------------------------------------------------------------------
79cdf0e10cSrcweir
80cdf0e10cSrcweir SV_IMPL_PTRARR( XRefreshListenerArr_Impl, XRefreshListenerPtr );
81cdf0e10cSrcweir
82cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAreaLinkObj, "ScAreaLinkObj", "com.sun.star.sheet.CellAreaLink" )
83cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScAreaLinksObj, "ScAreaLinksObj", "com.sun.star.sheet.CellAreaLinks" )
84cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDDELinkObj, "ScDDELinkObj", "com.sun.star.sheet.DDELink" )
85cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScDDELinksObj, "ScDDELinksObj", "com.sun.star.sheet.DDELinks" )
86cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScSheetLinkObj, "ScSheetLinkObj", "com.sun.star.sheet.SheetLink" )
87cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScSheetLinksObj, "ScSheetLinksObj", "com.sun.star.sheet.SheetLinks" )
88cdf0e10cSrcweir
89cdf0e10cSrcweir //------------------------------------------------------------------------
90cdf0e10cSrcweir
ScSheetLinkObj(ScDocShell * pDocSh,const String & rName)91cdf0e10cSrcweir ScSheetLinkObj::ScSheetLinkObj(ScDocShell* pDocSh, const String& rName) :
92cdf0e10cSrcweir aPropSet( lcl_GetSheetLinkMap() ),
93cdf0e10cSrcweir pDocShell( pDocSh ),
94cdf0e10cSrcweir aFileName( rName )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this);
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
~ScSheetLinkObj()99cdf0e10cSrcweir ScSheetLinkObj::~ScSheetLinkObj()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir if (pDocShell)
102cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this);
103cdf0e10cSrcweir }
104cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)105cdf0e10cSrcweir void ScSheetLinkObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir //! notify if links in document are changed
108cdf0e10cSrcweir // UpdateRef is not needed here
109cdf0e10cSrcweir
110cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if ( ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
113cdf0e10cSrcweir pDocShell = NULL; // pointer is invalid
114cdf0e10cSrcweir }
115cdf0e10cSrcweir else if ( rHint.ISA( ScLinkRefreshedHint ) )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir const ScLinkRefreshedHint& rLH = (const ScLinkRefreshedHint&) rHint;
118cdf0e10cSrcweir if ( rLH.GetLinkType() == SC_LINKREFTYPE_SHEET && rLH.GetUrl() == aFileName )
119cdf0e10cSrcweir Refreshed_Impl();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
GetLink_Impl() const123cdf0e10cSrcweir ScTableLink* ScSheetLinkObj::GetLink_Impl() const
124cdf0e10cSrcweir {
125cdf0e10cSrcweir if (pDocShell)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir sfx2::LinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager();
128cdf0e10cSrcweir sal_uInt16 nCount = pLinkManager->GetLinks().Count();
129cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[i];
132cdf0e10cSrcweir if (pBase->ISA(ScTableLink))
133cdf0e10cSrcweir {
134cdf0e10cSrcweir ScTableLink* pTabLink = (ScTableLink*)pBase;
135cdf0e10cSrcweir if ( pTabLink->GetFileName() == aFileName )
136cdf0e10cSrcweir return pTabLink;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir return NULL; // nicht gefunden
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
143cdf0e10cSrcweir // XNamed
144cdf0e10cSrcweir
getName()145cdf0e10cSrcweir rtl::OUString SAL_CALL ScSheetLinkObj::getName() throw(uno::RuntimeException)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir ScUnoGuard aGuard;
148cdf0e10cSrcweir return getFileName(); // Name ist der Dateiname (URL)
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
setName(const rtl::OUString & aName)151cdf0e10cSrcweir void SAL_CALL ScSheetLinkObj::setName( const rtl::OUString& aName ) throw(uno::RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir ScUnoGuard aGuard;
154cdf0e10cSrcweir setFileName(aName); // Name ist der Dateiname (URL)
155cdf0e10cSrcweir }
156cdf0e10cSrcweir
157cdf0e10cSrcweir // XRefreshable
158cdf0e10cSrcweir
refresh()159cdf0e10cSrcweir void SAL_CALL ScSheetLinkObj::refresh() throw(uno::RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir ScUnoGuard aGuard;
162cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
163cdf0e10cSrcweir if (pLink)
164cdf0e10cSrcweir pLink->Refresh( pLink->GetFileName(), pLink->GetFilterName(), NULL, pLink->GetRefreshDelay() );
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
addRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)167cdf0e10cSrcweir void SAL_CALL ScSheetLinkObj::addRefreshListener(
168cdf0e10cSrcweir const uno::Reference<util::XRefreshListener >& xListener )
169cdf0e10cSrcweir throw(uno::RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir ScUnoGuard aGuard;
172cdf0e10cSrcweir uno::Reference<util::XRefreshListener>* pObj =
173cdf0e10cSrcweir new uno::Reference<util::XRefreshListener>( xListener );
174cdf0e10cSrcweir aRefreshListeners.Insert( pObj, aRefreshListeners.Count() );
175cdf0e10cSrcweir
176cdf0e10cSrcweir // hold one additional ref to keep this object alive as long as there are listeners
177cdf0e10cSrcweir if ( aRefreshListeners.Count() == 1 )
178cdf0e10cSrcweir acquire();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
removeRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)181cdf0e10cSrcweir void SAL_CALL ScSheetLinkObj::removeRefreshListener(
182cdf0e10cSrcweir const uno::Reference<util::XRefreshListener >& xListener )
183cdf0e10cSrcweir throw(uno::RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir ScUnoGuard aGuard;
186cdf0e10cSrcweir sal_uInt16 nCount = aRefreshListeners.Count();
187cdf0e10cSrcweir for ( sal_uInt16 n=nCount; n--; )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n];
190cdf0e10cSrcweir if ( *pObj == xListener )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir aRefreshListeners.DeleteAndDestroy( n );
193cdf0e10cSrcweir if ( aRefreshListeners.Count() == 0 )
194cdf0e10cSrcweir release(); // release ref for listeners
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir }
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
Refreshed_Impl()200cdf0e10cSrcweir void ScSheetLinkObj::Refreshed_Impl()
201cdf0e10cSrcweir {
202cdf0e10cSrcweir lang::EventObject aEvent;
203cdf0e10cSrcweir aEvent.Source.set((cppu::OWeakObject*)this);
204cdf0e10cSrcweir for ( sal_uInt16 n=0; n<aRefreshListeners.Count(); n++ )
205cdf0e10cSrcweir (*aRefreshListeners[n])->refreshed( aEvent );
206cdf0e10cSrcweir }
207cdf0e10cSrcweir
ModifyRefreshDelay_Impl(sal_Int32 nRefresh)208cdf0e10cSrcweir void ScSheetLinkObj::ModifyRefreshDelay_Impl( sal_Int32 nRefresh )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
211cdf0e10cSrcweir if( pLink )
212cdf0e10cSrcweir pLink->SetRefreshDelay( (sal_uLong) nRefresh );
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir // XPropertySet
216cdf0e10cSrcweir
getPropertySetInfo()217cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSheetLinkObj::getPropertySetInfo()
218cdf0e10cSrcweir throw(uno::RuntimeException)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir ScUnoGuard aGuard;
221cdf0e10cSrcweir static uno::Reference<beans::XPropertySetInfo> aRef(
222cdf0e10cSrcweir new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
223cdf0e10cSrcweir return aRef;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)226cdf0e10cSrcweir void SAL_CALL ScSheetLinkObj::setPropertyValue(
227cdf0e10cSrcweir const rtl::OUString& aPropertyName, const uno::Any& aValue )
228cdf0e10cSrcweir throw(beans::UnknownPropertyException, beans::PropertyVetoException,
229cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException,
230cdf0e10cSrcweir uno::RuntimeException)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir ScUnoGuard aGuard;
233cdf0e10cSrcweir String aNameString(aPropertyName);
234cdf0e10cSrcweir rtl::OUString aValStr;
235cdf0e10cSrcweir if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir if ( aValue >>= aValStr )
238cdf0e10cSrcweir setFileName( aValStr );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir if ( aValue >>= aValStr )
243cdf0e10cSrcweir setFilter( aValStr );
244cdf0e10cSrcweir }
245cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir if ( aValue >>= aValStr )
248cdf0e10cSrcweir setFilterOptions( aValStr );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFPERIOD ) )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir sal_Int32 nRefresh = 0;
253cdf0e10cSrcweir if ( aValue >>= nRefresh )
254cdf0e10cSrcweir setRefreshDelay( nRefresh );
255cdf0e10cSrcweir }
256cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir sal_Int32 nRefresh = 0;
259cdf0e10cSrcweir if ( aValue >>= nRefresh )
260cdf0e10cSrcweir setRefreshDelay( nRefresh );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
getPropertyValue(const rtl::OUString & aPropertyName)264cdf0e10cSrcweir uno::Any SAL_CALL ScSheetLinkObj::getPropertyValue( const rtl::OUString& aPropertyName )
265cdf0e10cSrcweir throw(beans::UnknownPropertyException, lang::WrappedTargetException,
266cdf0e10cSrcweir uno::RuntimeException)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir ScUnoGuard aGuard;
269cdf0e10cSrcweir String aNameString(aPropertyName);
270cdf0e10cSrcweir uno::Any aRet;
271cdf0e10cSrcweir if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) )
272cdf0e10cSrcweir aRet <<= getFileName();
273cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) )
274cdf0e10cSrcweir aRet <<= getFilter();
275cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) )
276cdf0e10cSrcweir aRet <<= getFilterOptions();
277cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFPERIOD ) )
278cdf0e10cSrcweir aRet <<= getRefreshDelay();
279cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) )
280cdf0e10cSrcweir aRet <<= getRefreshDelay();
281cdf0e10cSrcweir return aRet;
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScSheetLinkObj)284cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSheetLinkObj )
285cdf0e10cSrcweir
286cdf0e10cSrcweir // internal:
287cdf0e10cSrcweir
288cdf0e10cSrcweir rtl::OUString ScSheetLinkObj::getFileName(void) const
289cdf0e10cSrcweir {
290cdf0e10cSrcweir ScUnoGuard aGuard;
291cdf0e10cSrcweir return aFileName;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir
setFileName(const rtl::OUString & rNewName)294cdf0e10cSrcweir void ScSheetLinkObj::setFileName(const rtl::OUString& rNewName)
295cdf0e10cSrcweir {
296cdf0e10cSrcweir ScUnoGuard aGuard;
297cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
298cdf0e10cSrcweir if (pLink)
299cdf0e10cSrcweir {
300cdf0e10cSrcweir // pLink->Refresh mit neuem Dateinamen bringt sfx2::LinkManager durcheinander
301cdf0e10cSrcweir // darum per Hand die Tabellen umsetzen und Link per UpdateLinks neu erzeugen
302cdf0e10cSrcweir
303cdf0e10cSrcweir String aNewStr(ScGlobal::GetAbsDocName( String(rNewName), pDocShell ));
304cdf0e10cSrcweir
305cdf0e10cSrcweir // zuerst Tabellen umsetzen
306cdf0e10cSrcweir
307cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
308cdf0e10cSrcweir SCTAB nTabCount = pDoc->GetTableCount();
309cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
310cdf0e10cSrcweir if ( pDoc->IsLinked(nTab) && pDoc->GetLinkDoc(nTab) == aFileName ) // alte Datei
311cdf0e10cSrcweir pDoc->SetLink( nTab, pDoc->GetLinkMode(nTab), aNewStr,
312cdf0e10cSrcweir pDoc->GetLinkFlt(nTab), pDoc->GetLinkOpt(nTab),
313cdf0e10cSrcweir pDoc->GetLinkTab(nTab),
314cdf0e10cSrcweir pDoc->GetLinkRefreshDelay(nTab) ); // nur Datei aendern
315cdf0e10cSrcweir
316cdf0e10cSrcweir // Links updaten
317cdf0e10cSrcweir //! Undo !!!
318cdf0e10cSrcweir
319cdf0e10cSrcweir pLink = NULL; // wird bei UpdateLinks ungueltig
320cdf0e10cSrcweir pDocShell->UpdateLinks(); // alter Link raus, evtl. neuen Link anlegen
321cdf0e10cSrcweir
322cdf0e10cSrcweir // Daten kopieren
323cdf0e10cSrcweir
324cdf0e10cSrcweir aFileName = aNewStr;
325cdf0e10cSrcweir pLink = GetLink_Impl(); // neuer Link mit neuem Namen
326cdf0e10cSrcweir if (pLink)
327cdf0e10cSrcweir pLink->Update(); // inkl. Paint & Undo fuer Daten
328cdf0e10cSrcweir }
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
getFilter(void) const331cdf0e10cSrcweir rtl::OUString ScSheetLinkObj::getFilter(void) const
332cdf0e10cSrcweir {
333cdf0e10cSrcweir ScUnoGuard aGuard;
334cdf0e10cSrcweir rtl::OUString aRet;
335cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
336cdf0e10cSrcweir if (pLink)
337cdf0e10cSrcweir aRet = pLink->GetFilterName();
338cdf0e10cSrcweir return aRet;
339cdf0e10cSrcweir }
340cdf0e10cSrcweir
setFilter(const rtl::OUString & Filter)341cdf0e10cSrcweir void ScSheetLinkObj::setFilter(const rtl::OUString& Filter)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir ScUnoGuard aGuard;
344cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
345cdf0e10cSrcweir if (pLink)
346cdf0e10cSrcweir {
347cdf0e10cSrcweir String aFilterStr(Filter);
348cdf0e10cSrcweir pLink->Refresh( aFileName, aFilterStr, NULL, pLink->GetRefreshDelay() );
349cdf0e10cSrcweir }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir
getFilterOptions(void) const352cdf0e10cSrcweir rtl::OUString ScSheetLinkObj::getFilterOptions(void) const
353cdf0e10cSrcweir {
354cdf0e10cSrcweir ScUnoGuard aGuard;
355cdf0e10cSrcweir rtl::OUString aRet;
356cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
357cdf0e10cSrcweir if (pLink)
358cdf0e10cSrcweir aRet = pLink->GetOptions();
359cdf0e10cSrcweir return aRet;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
setFilterOptions(const rtl::OUString & FilterOptions)362cdf0e10cSrcweir void ScSheetLinkObj::setFilterOptions(const rtl::OUString& FilterOptions)
363cdf0e10cSrcweir {
364cdf0e10cSrcweir ScUnoGuard aGuard;
365cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
366cdf0e10cSrcweir if (pLink)
367cdf0e10cSrcweir {
368cdf0e10cSrcweir String aOptStr(FilterOptions);
369cdf0e10cSrcweir pLink->Refresh( aFileName, pLink->GetFilterName(), &aOptStr, pLink->GetRefreshDelay() );
370cdf0e10cSrcweir }
371cdf0e10cSrcweir }
372cdf0e10cSrcweir
getRefreshDelay(void) const373cdf0e10cSrcweir sal_Int32 ScSheetLinkObj::getRefreshDelay(void) const
374cdf0e10cSrcweir {
375cdf0e10cSrcweir ScUnoGuard aGuard;
376cdf0e10cSrcweir sal_Int32 nRet = 0;
377cdf0e10cSrcweir ScTableLink* pLink = GetLink_Impl();
378cdf0e10cSrcweir if (pLink)
379cdf0e10cSrcweir nRet = (sal_Int32) pLink->GetRefreshDelay();
380cdf0e10cSrcweir return nRet;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
setRefreshDelay(sal_Int32 nRefreshDelay)383cdf0e10cSrcweir void ScSheetLinkObj::setRefreshDelay(sal_Int32 nRefreshDelay)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir ScUnoGuard aGuard;
386cdf0e10cSrcweir ModifyRefreshDelay_Impl( nRefreshDelay );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir
389cdf0e10cSrcweir //------------------------------------------------------------------------
390cdf0e10cSrcweir
ScSheetLinksObj(ScDocShell * pDocSh)391cdf0e10cSrcweir ScSheetLinksObj::ScSheetLinksObj(ScDocShell* pDocSh) :
392cdf0e10cSrcweir pDocShell( pDocSh )
393cdf0e10cSrcweir {
394cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this);
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
~ScSheetLinksObj()397cdf0e10cSrcweir ScSheetLinksObj::~ScSheetLinksObj()
398cdf0e10cSrcweir {
399cdf0e10cSrcweir if (pDocShell)
400cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this);
401cdf0e10cSrcweir }
402cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)403cdf0e10cSrcweir void ScSheetLinksObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
404cdf0e10cSrcweir {
405cdf0e10cSrcweir // Referenz-Update interessiert hier nicht
406cdf0e10cSrcweir
407cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) &&
408cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
409cdf0e10cSrcweir {
410cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden
411cdf0e10cSrcweir }
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir // XSheetLinks
415cdf0e10cSrcweir
GetObjectByIndex_Impl(sal_Int32 nIndex)416cdf0e10cSrcweir ScSheetLinkObj* ScSheetLinksObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir if (pDocShell)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir sal_Int32 nCount = 0;
421cdf0e10cSrcweir ScStrCollection aNames; // um doppelte wegzulassen
422cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
423cdf0e10cSrcweir SCTAB nTabCount = pDoc->GetTableCount();
424cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
425cdf0e10cSrcweir if (pDoc->IsLinked(nTab))
426cdf0e10cSrcweir {
427cdf0e10cSrcweir String aLinkDoc = pDoc->GetLinkDoc( nTab );
428cdf0e10cSrcweir StrData* pData = new StrData(aLinkDoc);
429cdf0e10cSrcweir if (aNames.Insert(pData))
430cdf0e10cSrcweir {
431cdf0e10cSrcweir if ( nCount == nIndex )
432cdf0e10cSrcweir return new ScSheetLinkObj( pDocShell, aLinkDoc );
433cdf0e10cSrcweir ++nCount;
434cdf0e10cSrcweir }
435cdf0e10cSrcweir else
436cdf0e10cSrcweir delete pData;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir }
439cdf0e10cSrcweir return NULL; // kein Dokument oder Index zu gross
440cdf0e10cSrcweir }
441cdf0e10cSrcweir
GetObjectByName_Impl(const rtl::OUString & aName)442cdf0e10cSrcweir ScSheetLinkObj* ScSheetLinksObj::GetObjectByName_Impl(const rtl::OUString& aName)
443cdf0e10cSrcweir {
444cdf0e10cSrcweir // Name ist der Dateiname
445cdf0e10cSrcweir
446cdf0e10cSrcweir if (pDocShell)
447cdf0e10cSrcweir {
448cdf0e10cSrcweir String aNameStr(aName);
449cdf0e10cSrcweir
450cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
451cdf0e10cSrcweir SCTAB nTabCount = pDoc->GetTableCount();
452cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
453cdf0e10cSrcweir if (pDoc->IsLinked(nTab))
454cdf0e10cSrcweir {
455cdf0e10cSrcweir //! case-insensitiv ???
456cdf0e10cSrcweir String aLinkDoc = pDoc->GetLinkDoc( nTab );
457cdf0e10cSrcweir if ( aLinkDoc == aNameStr )
458cdf0e10cSrcweir return new ScSheetLinkObj( pDocShell, aNameStr );
459cdf0e10cSrcweir }
460cdf0e10cSrcweir }
461cdf0e10cSrcweir
462cdf0e10cSrcweir return NULL;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir
465cdf0e10cSrcweir // XEnumerationAccess
466cdf0e10cSrcweir
createEnumeration()467cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScSheetLinksObj::createEnumeration()
468cdf0e10cSrcweir throw(uno::RuntimeException)
469cdf0e10cSrcweir {
470cdf0e10cSrcweir ScUnoGuard aGuard;
471cdf0e10cSrcweir return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SheetLinksEnumeration")));
472cdf0e10cSrcweir }
473cdf0e10cSrcweir
474cdf0e10cSrcweir // XIndexAccess
475cdf0e10cSrcweir
getCount()476cdf0e10cSrcweir sal_Int32 SAL_CALL ScSheetLinksObj::getCount() throw(uno::RuntimeException)
477cdf0e10cSrcweir {
478cdf0e10cSrcweir ScUnoGuard aGuard;
479cdf0e10cSrcweir sal_Int32 nCount = 0;
480cdf0e10cSrcweir if (pDocShell)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir ScStrCollection aNames; // um doppelte wegzulassen
483cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
484cdf0e10cSrcweir SCTAB nTabCount = pDoc->GetTableCount();
485cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
486cdf0e10cSrcweir if (pDoc->IsLinked(nTab))
487cdf0e10cSrcweir {
488cdf0e10cSrcweir String aLinkDoc(pDoc->GetLinkDoc( nTab ));
489cdf0e10cSrcweir StrData* pData = new StrData(aLinkDoc);
490cdf0e10cSrcweir if (aNames.Insert(pData))
491cdf0e10cSrcweir ++nCount;
492cdf0e10cSrcweir else
493cdf0e10cSrcweir delete pData;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir }
496cdf0e10cSrcweir return nCount;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
getByIndex(sal_Int32 nIndex)499cdf0e10cSrcweir uno::Any SAL_CALL ScSheetLinksObj::getByIndex( sal_Int32 nIndex )
500cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException,
501cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException)
502cdf0e10cSrcweir {
503cdf0e10cSrcweir ScUnoGuard aGuard;
504cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xLink(GetObjectByIndex_Impl(nIndex));
505cdf0e10cSrcweir if (xLink.is())
506cdf0e10cSrcweir return uno::makeAny(xLink);
507cdf0e10cSrcweir else
508cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
509cdf0e10cSrcweir // return uno::Any();
510cdf0e10cSrcweir }
511cdf0e10cSrcweir
getElementType()512cdf0e10cSrcweir uno::Type SAL_CALL ScSheetLinksObj::getElementType() throw(uno::RuntimeException)
513cdf0e10cSrcweir {
514cdf0e10cSrcweir ScUnoGuard aGuard;
515cdf0e10cSrcweir return getCppuType((uno::Reference<beans::XPropertySet>*)0);
516cdf0e10cSrcweir }
517cdf0e10cSrcweir
hasElements()518cdf0e10cSrcweir sal_Bool SAL_CALL ScSheetLinksObj::hasElements() throw(uno::RuntimeException)
519cdf0e10cSrcweir {
520cdf0e10cSrcweir ScUnoGuard aGuard;
521cdf0e10cSrcweir return ( getCount() != 0 );
522cdf0e10cSrcweir }
523cdf0e10cSrcweir
getByName(const rtl::OUString & aName)524cdf0e10cSrcweir uno::Any SAL_CALL ScSheetLinksObj::getByName( const rtl::OUString& aName )
525cdf0e10cSrcweir throw(container::NoSuchElementException,
526cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException)
527cdf0e10cSrcweir {
528cdf0e10cSrcweir ScUnoGuard aGuard;
529cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xLink(GetObjectByName_Impl(aName));
530cdf0e10cSrcweir if (xLink.is())
531cdf0e10cSrcweir return uno::makeAny(xLink);
532cdf0e10cSrcweir else
533cdf0e10cSrcweir throw container::NoSuchElementException();
534cdf0e10cSrcweir // return uno::Any();
535cdf0e10cSrcweir }
536cdf0e10cSrcweir
hasByName(const rtl::OUString & aName)537cdf0e10cSrcweir sal_Bool SAL_CALL ScSheetLinksObj::hasByName( const rtl::OUString& aName )
538cdf0e10cSrcweir throw(uno::RuntimeException)
539cdf0e10cSrcweir {
540cdf0e10cSrcweir ScUnoGuard aGuard;
541cdf0e10cSrcweir // Name ist der Dateiname
542cdf0e10cSrcweir
543cdf0e10cSrcweir if (pDocShell)
544cdf0e10cSrcweir {
545cdf0e10cSrcweir String aNameStr(aName);
546cdf0e10cSrcweir
547cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
548cdf0e10cSrcweir SCTAB nTabCount = pDoc->GetTableCount();
549cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
550cdf0e10cSrcweir if (pDoc->IsLinked(nTab))
551cdf0e10cSrcweir {
552cdf0e10cSrcweir //! case-insensitiv ???
553cdf0e10cSrcweir String aLinkDoc(pDoc->GetLinkDoc( nTab ));
554cdf0e10cSrcweir if ( aLinkDoc == aNameStr )
555cdf0e10cSrcweir return sal_True;
556cdf0e10cSrcweir }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir return sal_False;
559cdf0e10cSrcweir }
560cdf0e10cSrcweir
getElementNames()561cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScSheetLinksObj::getElementNames() throw(uno::RuntimeException)
562cdf0e10cSrcweir {
563cdf0e10cSrcweir ScUnoGuard aGuard;
564cdf0e10cSrcweir // Name ist der Dateiname
565cdf0e10cSrcweir
566cdf0e10cSrcweir if (pDocShell)
567cdf0e10cSrcweir {
568cdf0e10cSrcweir ScStrCollection aNames; // um doppelte wegzulassen
569cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
570cdf0e10cSrcweir SCTAB nTabCount = pDoc->GetTableCount();
571cdf0e10cSrcweir String aName;
572cdf0e10cSrcweir
573cdf0e10cSrcweir sal_Int32 nLinkCount = getCount();
574cdf0e10cSrcweir uno::Sequence<rtl::OUString> aSeq(nLinkCount);
575cdf0e10cSrcweir rtl::OUString* pAry = aSeq.getArray();
576cdf0e10cSrcweir sal_uInt16 nPos = 0;
577cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
578cdf0e10cSrcweir {
579cdf0e10cSrcweir if (pDoc->IsLinked(nTab))
580cdf0e10cSrcweir {
581cdf0e10cSrcweir String aLinkDoc(pDoc->GetLinkDoc( nTab ));
582cdf0e10cSrcweir StrData* pData = new StrData(aLinkDoc);
583cdf0e10cSrcweir if (aNames.Insert(pData))
584cdf0e10cSrcweir pAry[nPos++] = aLinkDoc;
585cdf0e10cSrcweir else
586cdf0e10cSrcweir delete pData;
587cdf0e10cSrcweir }
588cdf0e10cSrcweir }
589cdf0e10cSrcweir DBG_ASSERT( nPos==nLinkCount, "verzaehlt" );
590cdf0e10cSrcweir return aSeq;
591cdf0e10cSrcweir }
592cdf0e10cSrcweir return uno::Sequence<rtl::OUString>();
593cdf0e10cSrcweir }
594cdf0e10cSrcweir
595cdf0e10cSrcweir //------------------------------------------------------------------------
596cdf0e10cSrcweir
lcl_GetAreaLink(ScDocShell * pDocShell,sal_uInt16 nPos)597cdf0e10cSrcweir ScAreaLink* lcl_GetAreaLink( ScDocShell* pDocShell, sal_uInt16 nPos )
598cdf0e10cSrcweir {
599cdf0e10cSrcweir if (pDocShell)
600cdf0e10cSrcweir {
601cdf0e10cSrcweir sfx2::LinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager();
602cdf0e10cSrcweir sal_uInt16 nTotalCount = pLinkManager->GetLinks().Count();
603cdf0e10cSrcweir sal_uInt16 nAreaCount = 0;
604cdf0e10cSrcweir for (sal_uInt16 i=0; i<nTotalCount; i++)
605cdf0e10cSrcweir {
606cdf0e10cSrcweir ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[i];
607cdf0e10cSrcweir if (pBase->ISA(ScAreaLink))
608cdf0e10cSrcweir {
609cdf0e10cSrcweir if ( nAreaCount == nPos )
610cdf0e10cSrcweir return (ScAreaLink*)pBase;
611cdf0e10cSrcweir ++nAreaCount;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir }
614cdf0e10cSrcweir }
615cdf0e10cSrcweir return NULL; // nicht gefunden
616cdf0e10cSrcweir }
617cdf0e10cSrcweir
ScAreaLinkObj(ScDocShell * pDocSh,sal_uInt16 nP)618cdf0e10cSrcweir ScAreaLinkObj::ScAreaLinkObj(ScDocShell* pDocSh, sal_uInt16 nP) :
619cdf0e10cSrcweir aPropSet( lcl_GetSheetLinkMap() ),
620cdf0e10cSrcweir pDocShell( pDocSh ),
621cdf0e10cSrcweir nPos( nP )
622cdf0e10cSrcweir {
623cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this);
624cdf0e10cSrcweir }
625cdf0e10cSrcweir
~ScAreaLinkObj()626cdf0e10cSrcweir ScAreaLinkObj::~ScAreaLinkObj()
627cdf0e10cSrcweir {
628cdf0e10cSrcweir if (pDocShell)
629cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this);
630cdf0e10cSrcweir }
631cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)632cdf0e10cSrcweir void ScAreaLinkObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
633cdf0e10cSrcweir {
634cdf0e10cSrcweir //! notify if links in document are changed
635cdf0e10cSrcweir // UpdateRef is not needed here
636cdf0e10cSrcweir
637cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) )
638cdf0e10cSrcweir {
639cdf0e10cSrcweir if ( ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
640cdf0e10cSrcweir pDocShell = NULL; // pointer is invalid
641cdf0e10cSrcweir }
642cdf0e10cSrcweir else if ( rHint.ISA( ScLinkRefreshedHint ) )
643cdf0e10cSrcweir {
644cdf0e10cSrcweir const ScLinkRefreshedHint& rLH = (const ScLinkRefreshedHint&) rHint;
645cdf0e10cSrcweir if ( rLH.GetLinkType() == SC_LINKREFTYPE_AREA )
646cdf0e10cSrcweir {
647cdf0e10cSrcweir // get this link to compare dest position
648cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
649cdf0e10cSrcweir if ( pLink && pLink->GetDestArea().aStart == rLH.GetDestPos() )
650cdf0e10cSrcweir Refreshed_Impl();
651cdf0e10cSrcweir }
652cdf0e10cSrcweir }
653cdf0e10cSrcweir }
654cdf0e10cSrcweir
655cdf0e10cSrcweir // XFileLink
656cdf0e10cSrcweir
Modify_Impl(const rtl::OUString * pNewFile,const rtl::OUString * pNewFilter,const rtl::OUString * pNewOptions,const rtl::OUString * pNewSource,const table::CellRangeAddress * pNewDest)657cdf0e10cSrcweir void ScAreaLinkObj::Modify_Impl( const rtl::OUString* pNewFile, const rtl::OUString* pNewFilter,
658cdf0e10cSrcweir const rtl::OUString* pNewOptions, const rtl::OUString* pNewSource,
659cdf0e10cSrcweir const table::CellRangeAddress* pNewDest )
660cdf0e10cSrcweir {
661cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
662cdf0e10cSrcweir if (pLink)
663cdf0e10cSrcweir {
664cdf0e10cSrcweir String aFile (pLink->GetFile());
665cdf0e10cSrcweir String aFilter (pLink->GetFilter());
666cdf0e10cSrcweir String aOptions (pLink->GetOptions());
667cdf0e10cSrcweir String aSource (pLink->GetSource());
668cdf0e10cSrcweir ScRange aDest (pLink->GetDestArea());
669cdf0e10cSrcweir sal_uLong nRefresh = pLink->GetRefreshDelay();
670cdf0e10cSrcweir
671cdf0e10cSrcweir //! Undo fuer Loeschen
672cdf0e10cSrcweir //! Undo zusammenfassen
673cdf0e10cSrcweir
674cdf0e10cSrcweir sfx2::LinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager();
675cdf0e10cSrcweir pLinkManager->Remove( pLink );
676cdf0e10cSrcweir pLink = NULL; // bei Remove geloescht
677cdf0e10cSrcweir
678cdf0e10cSrcweir sal_Bool bFitBlock = sal_True; // verschieben, wenn durch Update Groesse geaendert
679cdf0e10cSrcweir if (pNewFile)
680cdf0e10cSrcweir {
681cdf0e10cSrcweir aFile = String( *pNewFile );
682cdf0e10cSrcweir aFile = ScGlobal::GetAbsDocName( aFile, pDocShell ); //! in InsertAreaLink?
683cdf0e10cSrcweir }
684cdf0e10cSrcweir if (pNewFilter)
685cdf0e10cSrcweir aFilter = String( *pNewFilter );
686cdf0e10cSrcweir if (pNewOptions)
687cdf0e10cSrcweir aOptions = String( *pNewOptions );
688cdf0e10cSrcweir if (pNewSource)
689cdf0e10cSrcweir aSource = String( *pNewSource );
690cdf0e10cSrcweir if (pNewDest)
691cdf0e10cSrcweir {
692cdf0e10cSrcweir ScUnoConversion::FillScRange( aDest, *pNewDest );
693cdf0e10cSrcweir bFitBlock = sal_False; // neuer Bereich angegeben -> keine Inhalte verschieben
694cdf0e10cSrcweir }
695cdf0e10cSrcweir
696cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell);
697cdf0e10cSrcweir aFunc.InsertAreaLink( aFile, aFilter, aOptions, aSource, aDest, nRefresh, bFitBlock, sal_True );
698cdf0e10cSrcweir }
699cdf0e10cSrcweir }
700cdf0e10cSrcweir
ModifyRefreshDelay_Impl(sal_Int32 nRefresh)701cdf0e10cSrcweir void ScAreaLinkObj::ModifyRefreshDelay_Impl( sal_Int32 nRefresh )
702cdf0e10cSrcweir {
703cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink( pDocShell, nPos );
704cdf0e10cSrcweir if( pLink )
705cdf0e10cSrcweir pLink->SetRefreshDelay( (sal_uLong) nRefresh );
706cdf0e10cSrcweir }
707cdf0e10cSrcweir
708cdf0e10cSrcweir // XRefreshable
709cdf0e10cSrcweir
refresh()710cdf0e10cSrcweir void SAL_CALL ScAreaLinkObj::refresh() throw(uno::RuntimeException)
711cdf0e10cSrcweir {
712cdf0e10cSrcweir ScUnoGuard aGuard;
713cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
714cdf0e10cSrcweir if (pLink)
715cdf0e10cSrcweir pLink->Refresh( pLink->GetFile(), pLink->GetFilter(), pLink->GetSource(), pLink->GetRefreshDelay() );
716cdf0e10cSrcweir }
717cdf0e10cSrcweir
addRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)718cdf0e10cSrcweir void SAL_CALL ScAreaLinkObj::addRefreshListener(
719cdf0e10cSrcweir const uno::Reference<util::XRefreshListener >& xListener )
720cdf0e10cSrcweir throw(uno::RuntimeException)
721cdf0e10cSrcweir {
722cdf0e10cSrcweir ScUnoGuard aGuard;
723cdf0e10cSrcweir uno::Reference<util::XRefreshListener>* pObj =
724cdf0e10cSrcweir new uno::Reference<util::XRefreshListener>( xListener );
725cdf0e10cSrcweir aRefreshListeners.Insert( pObj, aRefreshListeners.Count() );
726cdf0e10cSrcweir
727cdf0e10cSrcweir // hold one additional ref to keep this object alive as long as there are listeners
728cdf0e10cSrcweir if ( aRefreshListeners.Count() == 1 )
729cdf0e10cSrcweir acquire();
730cdf0e10cSrcweir }
731cdf0e10cSrcweir
removeRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)732cdf0e10cSrcweir void SAL_CALL ScAreaLinkObj::removeRefreshListener(
733cdf0e10cSrcweir const uno::Reference<util::XRefreshListener >& xListener )
734cdf0e10cSrcweir throw(uno::RuntimeException)
735cdf0e10cSrcweir {
736cdf0e10cSrcweir ScUnoGuard aGuard;
737cdf0e10cSrcweir sal_uInt16 nCount = aRefreshListeners.Count();
738cdf0e10cSrcweir for ( sal_uInt16 n=nCount; n--; )
739cdf0e10cSrcweir {
740cdf0e10cSrcweir uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n];
741cdf0e10cSrcweir if ( *pObj == xListener )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir aRefreshListeners.DeleteAndDestroy( n );
744cdf0e10cSrcweir if ( aRefreshListeners.Count() == 0 )
745cdf0e10cSrcweir release(); // release ref for listeners
746cdf0e10cSrcweir break;
747cdf0e10cSrcweir }
748cdf0e10cSrcweir }
749cdf0e10cSrcweir }
750cdf0e10cSrcweir
Refreshed_Impl()751cdf0e10cSrcweir void ScAreaLinkObj::Refreshed_Impl()
752cdf0e10cSrcweir {
753cdf0e10cSrcweir lang::EventObject aEvent;
754cdf0e10cSrcweir aEvent.Source.set((cppu::OWeakObject*)this);
755cdf0e10cSrcweir for ( sal_uInt16 n=0; n<aRefreshListeners.Count(); n++ )
756cdf0e10cSrcweir (*aRefreshListeners[n])->refreshed( aEvent );
757cdf0e10cSrcweir }
758cdf0e10cSrcweir
759cdf0e10cSrcweir // XPropertySet
760cdf0e10cSrcweir
getPropertySetInfo()761cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAreaLinkObj::getPropertySetInfo()
762cdf0e10cSrcweir throw(uno::RuntimeException)
763cdf0e10cSrcweir {
764cdf0e10cSrcweir ScUnoGuard aGuard;
765cdf0e10cSrcweir static uno::Reference<beans::XPropertySetInfo> aRef(
766cdf0e10cSrcweir new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ));
767cdf0e10cSrcweir return aRef;
768cdf0e10cSrcweir }
769cdf0e10cSrcweir
setPropertyValue(const rtl::OUString & aPropertyName,const uno::Any & aValue)770cdf0e10cSrcweir void SAL_CALL ScAreaLinkObj::setPropertyValue(
771cdf0e10cSrcweir const rtl::OUString& aPropertyName, const uno::Any& aValue )
772cdf0e10cSrcweir throw(beans::UnknownPropertyException, beans::PropertyVetoException,
773cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException,
774cdf0e10cSrcweir uno::RuntimeException)
775cdf0e10cSrcweir {
776cdf0e10cSrcweir ScUnoGuard aGuard;
777cdf0e10cSrcweir String aNameString(aPropertyName);
778cdf0e10cSrcweir rtl::OUString aValStr;
779cdf0e10cSrcweir if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir if ( aValue >>= aValStr )
782cdf0e10cSrcweir setFileName( aValStr );
783cdf0e10cSrcweir }
784cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) )
785cdf0e10cSrcweir {
786cdf0e10cSrcweir if ( aValue >>= aValStr )
787cdf0e10cSrcweir setFilter( aValStr );
788cdf0e10cSrcweir }
789cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) )
790cdf0e10cSrcweir {
791cdf0e10cSrcweir if ( aValue >>= aValStr )
792cdf0e10cSrcweir setFilterOptions( aValStr );
793cdf0e10cSrcweir }
794cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFPERIOD ) )
795cdf0e10cSrcweir {
796cdf0e10cSrcweir sal_Int32 nRefresh = 0;
797cdf0e10cSrcweir if ( aValue >>= nRefresh )
798cdf0e10cSrcweir setRefreshDelay( nRefresh );
799cdf0e10cSrcweir }
800cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) )
801cdf0e10cSrcweir {
802cdf0e10cSrcweir sal_Int32 nRefresh = 0;
803cdf0e10cSrcweir if ( aValue >>= nRefresh )
804cdf0e10cSrcweir setRefreshDelay( nRefresh );
805cdf0e10cSrcweir }
806cdf0e10cSrcweir }
807cdf0e10cSrcweir
getPropertyValue(const rtl::OUString & aPropertyName)808cdf0e10cSrcweir uno::Any SAL_CALL ScAreaLinkObj::getPropertyValue( const rtl::OUString& aPropertyName )
809cdf0e10cSrcweir throw(beans::UnknownPropertyException, lang::WrappedTargetException,
810cdf0e10cSrcweir uno::RuntimeException)
811cdf0e10cSrcweir {
812cdf0e10cSrcweir ScUnoGuard aGuard;
813cdf0e10cSrcweir String aNameString(aPropertyName);
814cdf0e10cSrcweir uno::Any aRet;
815cdf0e10cSrcweir if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) )
816cdf0e10cSrcweir aRet <<= getFileName();
817cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) )
818cdf0e10cSrcweir aRet <<= getFilter();
819cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) )
820cdf0e10cSrcweir aRet <<= getFilterOptions();
821cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFPERIOD ) )
822cdf0e10cSrcweir aRet <<= getRefreshDelay();
823cdf0e10cSrcweir else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) )
824cdf0e10cSrcweir aRet <<= getRefreshDelay();
825cdf0e10cSrcweir return aRet;
826cdf0e10cSrcweir }
827cdf0e10cSrcweir
SC_IMPL_DUMMY_PROPERTY_LISTENER(ScAreaLinkObj)828cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAreaLinkObj )
829cdf0e10cSrcweir
830cdf0e10cSrcweir // internal:
831cdf0e10cSrcweir
832cdf0e10cSrcweir rtl::OUString ScAreaLinkObj::getFileName(void) const
833cdf0e10cSrcweir {
834cdf0e10cSrcweir ScUnoGuard aGuard;
835cdf0e10cSrcweir rtl::OUString aRet;
836cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
837cdf0e10cSrcweir if (pLink)
838cdf0e10cSrcweir aRet = pLink->GetFile();
839cdf0e10cSrcweir return aRet;
840cdf0e10cSrcweir }
841cdf0e10cSrcweir
setFileName(const rtl::OUString & rNewName)842cdf0e10cSrcweir void ScAreaLinkObj::setFileName(const rtl::OUString& rNewName)
843cdf0e10cSrcweir {
844cdf0e10cSrcweir ScUnoGuard aGuard;
845cdf0e10cSrcweir Modify_Impl( &rNewName, NULL, NULL, NULL, NULL );
846cdf0e10cSrcweir }
847cdf0e10cSrcweir
getFilter(void) const848cdf0e10cSrcweir rtl::OUString ScAreaLinkObj::getFilter(void) const
849cdf0e10cSrcweir {
850cdf0e10cSrcweir ScUnoGuard aGuard;
851cdf0e10cSrcweir rtl::OUString aRet;
852cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
853cdf0e10cSrcweir if (pLink)
854cdf0e10cSrcweir aRet = pLink->GetFilter();
855cdf0e10cSrcweir return aRet;
856cdf0e10cSrcweir }
857cdf0e10cSrcweir
setFilter(const rtl::OUString & Filter)858cdf0e10cSrcweir void ScAreaLinkObj::setFilter(const rtl::OUString& Filter)
859cdf0e10cSrcweir {
860cdf0e10cSrcweir ScUnoGuard aGuard;
861cdf0e10cSrcweir Modify_Impl( NULL, &Filter, NULL, NULL, NULL );
862cdf0e10cSrcweir }
863cdf0e10cSrcweir
getFilterOptions(void) const864cdf0e10cSrcweir rtl::OUString ScAreaLinkObj::getFilterOptions(void) const
865cdf0e10cSrcweir {
866cdf0e10cSrcweir ScUnoGuard aGuard;
867cdf0e10cSrcweir rtl::OUString aRet;
868cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
869cdf0e10cSrcweir if (pLink)
870cdf0e10cSrcweir aRet = pLink->GetOptions();
871cdf0e10cSrcweir return aRet;
872cdf0e10cSrcweir }
873cdf0e10cSrcweir
setFilterOptions(const rtl::OUString & FilterOptions)874cdf0e10cSrcweir void ScAreaLinkObj::setFilterOptions(const rtl::OUString& FilterOptions)
875cdf0e10cSrcweir {
876cdf0e10cSrcweir ScUnoGuard aGuard;
877cdf0e10cSrcweir Modify_Impl( NULL, NULL, &FilterOptions, NULL, NULL );
878cdf0e10cSrcweir }
879cdf0e10cSrcweir
getRefreshDelay(void) const880cdf0e10cSrcweir sal_Int32 ScAreaLinkObj::getRefreshDelay(void) const
881cdf0e10cSrcweir {
882cdf0e10cSrcweir ScUnoGuard aGuard;
883cdf0e10cSrcweir sal_Int32 nRet = 0;
884cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
885cdf0e10cSrcweir if (pLink)
886cdf0e10cSrcweir nRet = (sal_Int32) pLink->GetRefreshDelay();
887cdf0e10cSrcweir return nRet;
888cdf0e10cSrcweir }
889cdf0e10cSrcweir
setRefreshDelay(sal_Int32 nRefreshDelay)890cdf0e10cSrcweir void ScAreaLinkObj::setRefreshDelay(sal_Int32 nRefreshDelay)
891cdf0e10cSrcweir {
892cdf0e10cSrcweir ScUnoGuard aGuard;
893cdf0e10cSrcweir ModifyRefreshDelay_Impl( nRefreshDelay );
894cdf0e10cSrcweir }
895cdf0e10cSrcweir
896cdf0e10cSrcweir // XAreaLink
897cdf0e10cSrcweir
getSourceArea()898cdf0e10cSrcweir rtl::OUString SAL_CALL ScAreaLinkObj::getSourceArea() throw(uno::RuntimeException)
899cdf0e10cSrcweir {
900cdf0e10cSrcweir ScUnoGuard aGuard;
901cdf0e10cSrcweir rtl::OUString aRet;
902cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
903cdf0e10cSrcweir if (pLink)
904cdf0e10cSrcweir aRet = pLink->GetSource();
905cdf0e10cSrcweir return aRet;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir
setSourceArea(const rtl::OUString & aSourceArea)908cdf0e10cSrcweir void SAL_CALL ScAreaLinkObj::setSourceArea( const rtl::OUString& aSourceArea )
909cdf0e10cSrcweir throw(uno::RuntimeException)
910cdf0e10cSrcweir {
911cdf0e10cSrcweir ScUnoGuard aGuard;
912cdf0e10cSrcweir Modify_Impl( NULL, NULL, NULL, &aSourceArea, NULL );
913cdf0e10cSrcweir }
914cdf0e10cSrcweir
getDestArea()915cdf0e10cSrcweir table::CellRangeAddress SAL_CALL ScAreaLinkObj::getDestArea() throw(uno::RuntimeException)
916cdf0e10cSrcweir {
917cdf0e10cSrcweir ScUnoGuard aGuard;
918cdf0e10cSrcweir table::CellRangeAddress aRet;
919cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos);
920cdf0e10cSrcweir if (pLink)
921cdf0e10cSrcweir ScUnoConversion::FillApiRange( aRet, pLink->GetDestArea() );
922cdf0e10cSrcweir return aRet;
923cdf0e10cSrcweir }
924cdf0e10cSrcweir
setDestArea(const table::CellRangeAddress & aDestArea)925cdf0e10cSrcweir void SAL_CALL ScAreaLinkObj::setDestArea( const table::CellRangeAddress& aDestArea )
926cdf0e10cSrcweir throw(uno::RuntimeException)
927cdf0e10cSrcweir {
928cdf0e10cSrcweir ScUnoGuard aGuard;
929cdf0e10cSrcweir Modify_Impl( NULL, NULL, NULL, NULL, &aDestArea );
930cdf0e10cSrcweir }
931cdf0e10cSrcweir
932cdf0e10cSrcweir //------------------------------------------------------------------------
933cdf0e10cSrcweir
ScAreaLinksObj(ScDocShell * pDocSh)934cdf0e10cSrcweir ScAreaLinksObj::ScAreaLinksObj(ScDocShell* pDocSh) :
935cdf0e10cSrcweir pDocShell( pDocSh )
936cdf0e10cSrcweir {
937cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this);
938cdf0e10cSrcweir }
939cdf0e10cSrcweir
~ScAreaLinksObj()940cdf0e10cSrcweir ScAreaLinksObj::~ScAreaLinksObj()
941cdf0e10cSrcweir {
942cdf0e10cSrcweir if (pDocShell)
943cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this);
944cdf0e10cSrcweir }
945cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)946cdf0e10cSrcweir void ScAreaLinksObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
947cdf0e10cSrcweir {
948cdf0e10cSrcweir // Referenz-Update interessiert hier nicht
949cdf0e10cSrcweir
950cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) &&
951cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
952cdf0e10cSrcweir {
953cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden
954cdf0e10cSrcweir }
955cdf0e10cSrcweir }
956cdf0e10cSrcweir
957cdf0e10cSrcweir // XAreaLinks
958cdf0e10cSrcweir
GetObjectByIndex_Impl(sal_Int32 nIndex)959cdf0e10cSrcweir ScAreaLinkObj* ScAreaLinksObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
960cdf0e10cSrcweir {
961cdf0e10cSrcweir if ( pDocShell && nIndex >= 0 && nIndex < getCount() )
962cdf0e10cSrcweir return new ScAreaLinkObj( pDocShell, (sal_uInt16)nIndex );
963cdf0e10cSrcweir
964cdf0e10cSrcweir return NULL; // nicht gefunden
965cdf0e10cSrcweir }
966cdf0e10cSrcweir
insertAtPosition(const table::CellAddress & aDestPos,const rtl::OUString & aFileName,const rtl::OUString & aSourceArea,const rtl::OUString & aFilter,const rtl::OUString & aFilterOptions)967cdf0e10cSrcweir void SAL_CALL ScAreaLinksObj::insertAtPosition( const table::CellAddress& aDestPos,
968cdf0e10cSrcweir const rtl::OUString& aFileName,
969cdf0e10cSrcweir const rtl::OUString& aSourceArea,
970cdf0e10cSrcweir const rtl::OUString& aFilter,
971cdf0e10cSrcweir const rtl::OUString& aFilterOptions )
972cdf0e10cSrcweir throw(uno::RuntimeException)
973cdf0e10cSrcweir {
974cdf0e10cSrcweir ScUnoGuard aGuard;
975cdf0e10cSrcweir if (pDocShell)
976cdf0e10cSrcweir {
977cdf0e10cSrcweir String aFileStr (aFileName);
978cdf0e10cSrcweir String aFilterStr (aFilter);
979cdf0e10cSrcweir String aOptionStr (aFilterOptions);
980cdf0e10cSrcweir String aSourceStr (aSourceArea);
981cdf0e10cSrcweir ScAddress aDestAddr( (SCCOL)aDestPos.Column, (SCROW)aDestPos.Row, aDestPos.Sheet );
982cdf0e10cSrcweir
983cdf0e10cSrcweir aFileStr = ScGlobal::GetAbsDocName( aFileStr, pDocShell ); //! in InsertAreaLink ???
984cdf0e10cSrcweir
985cdf0e10cSrcweir ScDocFunc aFunc(*pDocShell);
986cdf0e10cSrcweir aFunc.InsertAreaLink( aFileStr, aFilterStr, aOptionStr,
987cdf0e10cSrcweir aSourceStr, ScRange(aDestAddr),
988cdf0e10cSrcweir 0, sal_False, sal_True ); // keine Inhalte verschieben
989cdf0e10cSrcweir }
990cdf0e10cSrcweir }
991cdf0e10cSrcweir
removeByIndex(sal_Int32 nIndex)992cdf0e10cSrcweir void SAL_CALL ScAreaLinksObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException)
993cdf0e10cSrcweir {
994cdf0e10cSrcweir ScUnoGuard aGuard;
995cdf0e10cSrcweir ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, (sal_uInt16)nIndex);
996cdf0e10cSrcweir if (pLink)
997cdf0e10cSrcweir {
998cdf0e10cSrcweir //! SetAddUndo oder so
999cdf0e10cSrcweir
1000cdf0e10cSrcweir sfx2::LinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager();
1001cdf0e10cSrcweir pLinkManager->Remove( pLink );
1002cdf0e10cSrcweir }
1003cdf0e10cSrcweir }
1004cdf0e10cSrcweir
1005cdf0e10cSrcweir // XEnumerationAccess
1006cdf0e10cSrcweir
createEnumeration()1007cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScAreaLinksObj::createEnumeration()
1008cdf0e10cSrcweir throw(uno::RuntimeException)
1009cdf0e10cSrcweir {
1010cdf0e10cSrcweir ScUnoGuard aGuard;
1011cdf0e10cSrcweir return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.CellAreaLinksEnumeration")));
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir
1014cdf0e10cSrcweir // XIndexAccess
1015cdf0e10cSrcweir
getCount()1016cdf0e10cSrcweir sal_Int32 SAL_CALL ScAreaLinksObj::getCount() throw(uno::RuntimeException)
1017cdf0e10cSrcweir {
1018cdf0e10cSrcweir ScUnoGuard aGuard;
1019cdf0e10cSrcweir sal_Int32 nAreaCount = 0;
1020cdf0e10cSrcweir if (pDocShell)
1021cdf0e10cSrcweir {
1022cdf0e10cSrcweir sfx2::LinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager();
1023cdf0e10cSrcweir sal_uInt16 nTotalCount = pLinkManager->GetLinks().Count();
1024cdf0e10cSrcweir for (sal_uInt16 i=0; i<nTotalCount; i++)
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[i];
1027cdf0e10cSrcweir if (pBase->ISA(ScAreaLink))
1028cdf0e10cSrcweir ++nAreaCount;
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir return nAreaCount;
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir
getByIndex(sal_Int32 nIndex)1034cdf0e10cSrcweir uno::Any SAL_CALL ScAreaLinksObj::getByIndex( sal_Int32 nIndex )
1035cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException,
1036cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException)
1037cdf0e10cSrcweir {
1038cdf0e10cSrcweir ScUnoGuard aGuard;
1039cdf0e10cSrcweir uno::Reference<sheet::XAreaLink> xLink(GetObjectByIndex_Impl(nIndex));
1040cdf0e10cSrcweir if (xLink.is())
1041cdf0e10cSrcweir return uno::makeAny(xLink);
1042cdf0e10cSrcweir else
1043cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
1044cdf0e10cSrcweir // return uno::Any();
1045cdf0e10cSrcweir }
1046cdf0e10cSrcweir
getElementType()1047cdf0e10cSrcweir uno::Type SAL_CALL ScAreaLinksObj::getElementType() throw(uno::RuntimeException)
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir ScUnoGuard aGuard;
1050cdf0e10cSrcweir return getCppuType((uno::Reference<sheet::XAreaLink>*)0);
1051cdf0e10cSrcweir }
1052cdf0e10cSrcweir
hasElements()1053cdf0e10cSrcweir sal_Bool SAL_CALL ScAreaLinksObj::hasElements() throw(uno::RuntimeException)
1054cdf0e10cSrcweir {
1055cdf0e10cSrcweir ScUnoGuard aGuard;
1056cdf0e10cSrcweir return ( getCount() != 0 );
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir //------------------------------------------------------------------------
1060cdf0e10cSrcweir
ScDDELinkObj(ScDocShell * pDocSh,const String & rA,const String & rT,const String & rI)1061cdf0e10cSrcweir ScDDELinkObj::ScDDELinkObj(ScDocShell* pDocSh, const String& rA,
1062cdf0e10cSrcweir const String& rT, const String& rI) :
1063cdf0e10cSrcweir pDocShell( pDocSh ),
1064cdf0e10cSrcweir aAppl( rA ),
1065cdf0e10cSrcweir aTopic( rT ),
1066cdf0e10cSrcweir aItem( rI )
1067cdf0e10cSrcweir {
1068cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this);
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir
~ScDDELinkObj()1071cdf0e10cSrcweir ScDDELinkObj::~ScDDELinkObj()
1072cdf0e10cSrcweir {
1073cdf0e10cSrcweir if (pDocShell)
1074cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this);
1075cdf0e10cSrcweir }
1076cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)1077cdf0e10cSrcweir void ScDDELinkObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1078cdf0e10cSrcweir {
1079cdf0e10cSrcweir //! notify if links in document are changed
1080cdf0e10cSrcweir // UpdateRef is not needed here
1081cdf0e10cSrcweir
1082cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) )
1083cdf0e10cSrcweir {
1084cdf0e10cSrcweir if ( ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1085cdf0e10cSrcweir pDocShell = NULL; // pointer is invalid
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir else if ( rHint.ISA( ScLinkRefreshedHint ) )
1088cdf0e10cSrcweir {
1089cdf0e10cSrcweir const ScLinkRefreshedHint& rLH = (const ScLinkRefreshedHint&) rHint;
1090cdf0e10cSrcweir if ( rLH.GetLinkType() == SC_LINKREFTYPE_DDE &&
1091cdf0e10cSrcweir rLH.GetDdeAppl() == aAppl &&
1092cdf0e10cSrcweir rLH.GetDdeTopic() == aTopic &&
1093cdf0e10cSrcweir rLH.GetDdeItem() == aItem ) //! mode is ignored
1094cdf0e10cSrcweir Refreshed_Impl();
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir }
1097cdf0e10cSrcweir
1098cdf0e10cSrcweir // XNamed
1099cdf0e10cSrcweir
lcl_BuildDDEName(const String & rAppl,const String & rTopic,const String & rItem)1100cdf0e10cSrcweir String lcl_BuildDDEName( const String& rAppl, const String& rTopic, const String& rItem )
1101cdf0e10cSrcweir {
1102cdf0e10cSrcweir // Appl|Topic!Item (wie Excel)
1103cdf0e10cSrcweir String aRet = rAppl;
1104cdf0e10cSrcweir aRet += '|';
1105cdf0e10cSrcweir aRet += rTopic;
1106cdf0e10cSrcweir aRet += '!';
1107cdf0e10cSrcweir aRet += rItem;
1108cdf0e10cSrcweir return aRet;
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir
getName()1111cdf0e10cSrcweir rtl::OUString SAL_CALL ScDDELinkObj::getName() throw(uno::RuntimeException)
1112cdf0e10cSrcweir {
1113cdf0e10cSrcweir ScUnoGuard aGuard;
1114cdf0e10cSrcweir return lcl_BuildDDEName( aAppl, aTopic, aItem );
1115cdf0e10cSrcweir }
1116cdf0e10cSrcweir
setName(const rtl::OUString &)1117cdf0e10cSrcweir void SAL_CALL ScDDELinkObj::setName( const rtl::OUString& /* aName */ ) throw(uno::RuntimeException)
1118cdf0e10cSrcweir {
1119cdf0e10cSrcweir // name can't be changed (formulas wouldn't find the link)
1120cdf0e10cSrcweir throw uno::RuntimeException();
1121cdf0e10cSrcweir }
1122cdf0e10cSrcweir
1123cdf0e10cSrcweir // XDDELink
1124cdf0e10cSrcweir
getApplication()1125cdf0e10cSrcweir rtl::OUString SAL_CALL ScDDELinkObj::getApplication() throw(uno::RuntimeException)
1126cdf0e10cSrcweir {
1127cdf0e10cSrcweir ScUnoGuard aGuard;
1128cdf0e10cSrcweir //! Test, ob Link noch im Dokument enthalten?
1129cdf0e10cSrcweir
1130cdf0e10cSrcweir return aAppl;
1131cdf0e10cSrcweir }
1132cdf0e10cSrcweir
getTopic()1133cdf0e10cSrcweir rtl::OUString SAL_CALL ScDDELinkObj::getTopic() throw(uno::RuntimeException)
1134cdf0e10cSrcweir {
1135cdf0e10cSrcweir ScUnoGuard aGuard;
1136cdf0e10cSrcweir //! Test, ob Link noch im Dokument enthalten?
1137cdf0e10cSrcweir
1138cdf0e10cSrcweir return aTopic;
1139cdf0e10cSrcweir }
1140cdf0e10cSrcweir
getItem()1141cdf0e10cSrcweir rtl::OUString SAL_CALL ScDDELinkObj::getItem() throw(uno::RuntimeException)
1142cdf0e10cSrcweir {
1143cdf0e10cSrcweir ScUnoGuard aGuard;
1144cdf0e10cSrcweir //! Test, ob Link noch im Dokument enthalten?
1145cdf0e10cSrcweir
1146cdf0e10cSrcweir return aItem;
1147cdf0e10cSrcweir }
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir // XRefreshable
1150cdf0e10cSrcweir
refresh()1151cdf0e10cSrcweir void SAL_CALL ScDDELinkObj::refresh() throw(uno::RuntimeException)
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir ScUnoGuard aGuard;
1154cdf0e10cSrcweir if (pDocShell)
1155cdf0e10cSrcweir {
1156cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1157cdf0e10cSrcweir (void)pDoc->UpdateDdeLink( aAppl, aTopic, aItem );
1158cdf0e10cSrcweir //! Fehler abfragen
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir
addRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)1162cdf0e10cSrcweir void SAL_CALL ScDDELinkObj::addRefreshListener(
1163cdf0e10cSrcweir const uno::Reference<util::XRefreshListener >& xListener )
1164cdf0e10cSrcweir throw(uno::RuntimeException)
1165cdf0e10cSrcweir {
1166cdf0e10cSrcweir ScUnoGuard aGuard;
1167cdf0e10cSrcweir uno::Reference<util::XRefreshListener>* pObj =
1168cdf0e10cSrcweir new uno::Reference<util::XRefreshListener>( xListener );
1169cdf0e10cSrcweir aRefreshListeners.Insert( pObj, aRefreshListeners.Count() );
1170cdf0e10cSrcweir
1171cdf0e10cSrcweir // hold one additional ref to keep this object alive as long as there are listeners
1172cdf0e10cSrcweir if ( aRefreshListeners.Count() == 1 )
1173cdf0e10cSrcweir acquire();
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir
removeRefreshListener(const uno::Reference<util::XRefreshListener> & xListener)1176cdf0e10cSrcweir void SAL_CALL ScDDELinkObj::removeRefreshListener(
1177cdf0e10cSrcweir const uno::Reference<util::XRefreshListener >& xListener )
1178cdf0e10cSrcweir throw(uno::RuntimeException)
1179cdf0e10cSrcweir {
1180cdf0e10cSrcweir ScUnoGuard aGuard;
1181cdf0e10cSrcweir sal_uInt16 nCount = aRefreshListeners.Count();
1182cdf0e10cSrcweir for ( sal_uInt16 n=nCount; n--; )
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n];
1185cdf0e10cSrcweir if ( *pObj == xListener )
1186cdf0e10cSrcweir {
1187cdf0e10cSrcweir aRefreshListeners.DeleteAndDestroy( n );
1188cdf0e10cSrcweir if ( aRefreshListeners.Count() == 0 )
1189cdf0e10cSrcweir release(); // release ref for listeners
1190cdf0e10cSrcweir break;
1191cdf0e10cSrcweir }
1192cdf0e10cSrcweir }
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir
1195cdf0e10cSrcweir // XDDELinkResults
1196cdf0e10cSrcweir
getResults()1197cdf0e10cSrcweir uno::Sequence< uno::Sequence< uno::Any > > ScDDELinkObj::getResults( )
1198cdf0e10cSrcweir throw (uno::RuntimeException)
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir ScUnoGuard aGuard;
1201cdf0e10cSrcweir uno::Sequence< uno::Sequence< uno::Any > > aReturn;
1202cdf0e10cSrcweir bool bSuccess = false;
1203cdf0e10cSrcweir
1204cdf0e10cSrcweir if ( pDocShell )
1205cdf0e10cSrcweir {
1206cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1207cdf0e10cSrcweir if ( pDoc )
1208cdf0e10cSrcweir {
1209cdf0e10cSrcweir sal_uInt16 nPos = 0;
1210cdf0e10cSrcweir if ( pDoc->FindDdeLink( aAppl, aTopic, aItem, SC_DDE_IGNOREMODE, nPos ) )
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir const ScMatrix* pMatrix = pDoc->GetDdeLinkResultMatrix( nPos );
1213cdf0e10cSrcweir if ( pMatrix )
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir uno::Any aAny;
1216cdf0e10cSrcweir if ( ScRangeToSequence::FillMixedArray( aAny, pMatrix, true ) )
1217cdf0e10cSrcweir {
1218cdf0e10cSrcweir aAny >>= aReturn;
1219cdf0e10cSrcweir }
1220cdf0e10cSrcweir }
1221cdf0e10cSrcweir bSuccess = true;
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir }
1224cdf0e10cSrcweir }
1225cdf0e10cSrcweir
1226cdf0e10cSrcweir if ( !bSuccess )
1227cdf0e10cSrcweir {
1228cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1229cdf0e10cSrcweir "ScDDELinkObj::getResults: failed to get results!" ) ),
1230cdf0e10cSrcweir uno::Reference< uno::XInterface >() );
1231cdf0e10cSrcweir }
1232cdf0e10cSrcweir
1233cdf0e10cSrcweir return aReturn;
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir
setResults(const uno::Sequence<uno::Sequence<uno::Any>> & aResults)1236cdf0e10cSrcweir void ScDDELinkObj::setResults( const uno::Sequence< uno::Sequence< uno::Any > >& aResults )
1237cdf0e10cSrcweir throw (uno::RuntimeException)
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir ScUnoGuard aGuard;
1240cdf0e10cSrcweir bool bSuccess = false;
1241cdf0e10cSrcweir
1242cdf0e10cSrcweir if ( pDocShell )
1243cdf0e10cSrcweir {
1244cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1245cdf0e10cSrcweir if ( pDoc )
1246cdf0e10cSrcweir {
1247cdf0e10cSrcweir sal_uInt16 nPos = 0;
1248cdf0e10cSrcweir if ( pDoc->FindDdeLink( aAppl, aTopic, aItem, SC_DDE_IGNOREMODE, nPos ) )
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir uno::Any aAny;
1251cdf0e10cSrcweir aAny <<= aResults;
1252cdf0e10cSrcweir ScMatrixRef xMatrix = ScSequenceToMatrix::CreateMixedMatrix( aAny );
1253cdf0e10cSrcweir bSuccess = pDoc->SetDdeLinkResultMatrix( nPos, xMatrix );
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir }
1256cdf0e10cSrcweir }
1257cdf0e10cSrcweir
1258cdf0e10cSrcweir if ( !bSuccess )
1259cdf0e10cSrcweir {
1260cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1261cdf0e10cSrcweir "ScDDELinkObj::setResults: failed to set results!" ) ),
1262cdf0e10cSrcweir uno::Reference< uno::XInterface >() );
1263cdf0e10cSrcweir }
1264cdf0e10cSrcweir }
1265cdf0e10cSrcweir
Refreshed_Impl()1266cdf0e10cSrcweir void ScDDELinkObj::Refreshed_Impl()
1267cdf0e10cSrcweir {
1268cdf0e10cSrcweir lang::EventObject aEvent;
1269cdf0e10cSrcweir aEvent.Source.set((cppu::OWeakObject*)this);
1270cdf0e10cSrcweir for ( sal_uInt16 n=0; n<aRefreshListeners.Count(); n++ )
1271cdf0e10cSrcweir (*aRefreshListeners[n])->refreshed( aEvent );
1272cdf0e10cSrcweir }
1273cdf0e10cSrcweir
1274cdf0e10cSrcweir //------------------------------------------------------------------------
1275cdf0e10cSrcweir
ScDDELinksObj(ScDocShell * pDocSh)1276cdf0e10cSrcweir ScDDELinksObj::ScDDELinksObj(ScDocShell* pDocSh) :
1277cdf0e10cSrcweir pDocShell( pDocSh )
1278cdf0e10cSrcweir {
1279cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this);
1280cdf0e10cSrcweir }
1281cdf0e10cSrcweir
~ScDDELinksObj()1282cdf0e10cSrcweir ScDDELinksObj::~ScDDELinksObj()
1283cdf0e10cSrcweir {
1284cdf0e10cSrcweir if (pDocShell)
1285cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this);
1286cdf0e10cSrcweir }
1287cdf0e10cSrcweir
Notify(SfxBroadcaster &,const SfxHint & rHint)1288cdf0e10cSrcweir void ScDDELinksObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
1289cdf0e10cSrcweir {
1290cdf0e10cSrcweir // Referenz-Update interessiert hier nicht
1291cdf0e10cSrcweir
1292cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) &&
1293cdf0e10cSrcweir ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
1294cdf0e10cSrcweir {
1295cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden
1296cdf0e10cSrcweir }
1297cdf0e10cSrcweir }
1298cdf0e10cSrcweir
1299cdf0e10cSrcweir // XDDELinks
1300cdf0e10cSrcweir
GetObjectByIndex_Impl(sal_Int32 nIndex)1301cdf0e10cSrcweir ScDDELinkObj* ScDDELinksObj::GetObjectByIndex_Impl(sal_Int32 nIndex)
1302cdf0e10cSrcweir {
1303cdf0e10cSrcweir if (pDocShell)
1304cdf0e10cSrcweir {
1305cdf0e10cSrcweir String aAppl, aTopic, aItem;
1306cdf0e10cSrcweir if ( nIndex <= USHRT_MAX &&
1307cdf0e10cSrcweir pDocShell->GetDocument()->GetDdeLinkData( (sal_uInt16)nIndex, aAppl, aTopic, aItem ) )
1308cdf0e10cSrcweir return new ScDDELinkObj( pDocShell, aAppl, aTopic, aItem );
1309cdf0e10cSrcweir }
1310cdf0e10cSrcweir return NULL;
1311cdf0e10cSrcweir }
1312cdf0e10cSrcweir
GetObjectByName_Impl(const rtl::OUString & aName)1313cdf0e10cSrcweir ScDDELinkObj* ScDDELinksObj::GetObjectByName_Impl(const rtl::OUString& aName)
1314cdf0e10cSrcweir {
1315cdf0e10cSrcweir if (pDocShell)
1316cdf0e10cSrcweir {
1317cdf0e10cSrcweir String aNamStr(aName);
1318cdf0e10cSrcweir String aAppl, aTopic, aItem;
1319cdf0e10cSrcweir
1320cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1321cdf0e10cSrcweir sal_uInt16 nCount = pDoc->GetDdeLinkCount();
1322cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem );
1325cdf0e10cSrcweir if ( lcl_BuildDDEName(aAppl, aTopic, aItem) == aNamStr )
1326cdf0e10cSrcweir return new ScDDELinkObj( pDocShell, aAppl, aTopic, aItem );
1327cdf0e10cSrcweir }
1328cdf0e10cSrcweir }
1329cdf0e10cSrcweir return NULL;
1330cdf0e10cSrcweir }
1331cdf0e10cSrcweir
1332cdf0e10cSrcweir // XEnumerationAccess
1333cdf0e10cSrcweir
createEnumeration()1334cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScDDELinksObj::createEnumeration()
1335cdf0e10cSrcweir throw(uno::RuntimeException)
1336cdf0e10cSrcweir {
1337cdf0e10cSrcweir ScUnoGuard aGuard;
1338cdf0e10cSrcweir return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DDELinksEnumeration")));
1339cdf0e10cSrcweir }
1340cdf0e10cSrcweir
1341cdf0e10cSrcweir // XIndexAccess
1342cdf0e10cSrcweir
getCount()1343cdf0e10cSrcweir sal_Int32 SAL_CALL ScDDELinksObj::getCount() throw(uno::RuntimeException)
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir ScUnoGuard aGuard;
1346cdf0e10cSrcweir sal_Int32 nAreaCount = 0;
1347cdf0e10cSrcweir if (pDocShell)
1348cdf0e10cSrcweir nAreaCount = pDocShell->GetDocument()->GetDdeLinkCount();
1349cdf0e10cSrcweir return nAreaCount;
1350cdf0e10cSrcweir }
1351cdf0e10cSrcweir
getByIndex(sal_Int32 nIndex)1352cdf0e10cSrcweir uno::Any SAL_CALL ScDDELinksObj::getByIndex( sal_Int32 nIndex )
1353cdf0e10cSrcweir throw(lang::IndexOutOfBoundsException,
1354cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException)
1355cdf0e10cSrcweir {
1356cdf0e10cSrcweir ScUnoGuard aGuard;
1357cdf0e10cSrcweir uno::Reference<sheet::XDDELink> xLink(GetObjectByIndex_Impl(nIndex));
1358cdf0e10cSrcweir if (xLink.is())
1359cdf0e10cSrcweir return uno::makeAny(xLink);
1360cdf0e10cSrcweir else
1361cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
1362cdf0e10cSrcweir // return uno::Any();
1363cdf0e10cSrcweir }
1364cdf0e10cSrcweir
getElementType()1365cdf0e10cSrcweir uno::Type SAL_CALL ScDDELinksObj::getElementType() throw(uno::RuntimeException)
1366cdf0e10cSrcweir {
1367cdf0e10cSrcweir ScUnoGuard aGuard;
1368cdf0e10cSrcweir return getCppuType((uno::Reference<sheet::XDDELink>*)0);
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir
hasElements()1371cdf0e10cSrcweir sal_Bool SAL_CALL ScDDELinksObj::hasElements() throw(uno::RuntimeException)
1372cdf0e10cSrcweir {
1373cdf0e10cSrcweir ScUnoGuard aGuard;
1374cdf0e10cSrcweir return ( getCount() != 0 );
1375cdf0e10cSrcweir }
1376cdf0e10cSrcweir
getByName(const rtl::OUString & aName)1377cdf0e10cSrcweir uno::Any SAL_CALL ScDDELinksObj::getByName( const rtl::OUString& aName )
1378cdf0e10cSrcweir throw(container::NoSuchElementException,
1379cdf0e10cSrcweir lang::WrappedTargetException, uno::RuntimeException)
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir ScUnoGuard aGuard;
1382cdf0e10cSrcweir uno::Reference<sheet::XDDELink> xLink(GetObjectByName_Impl(aName));
1383cdf0e10cSrcweir if (xLink.is())
1384cdf0e10cSrcweir return uno::makeAny(xLink);
1385cdf0e10cSrcweir else
1386cdf0e10cSrcweir throw container::NoSuchElementException();
1387cdf0e10cSrcweir // return uno::Any();
1388cdf0e10cSrcweir }
1389cdf0e10cSrcweir
getElementNames()1390cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScDDELinksObj::getElementNames() throw(uno::RuntimeException)
1391cdf0e10cSrcweir {
1392cdf0e10cSrcweir ScUnoGuard aGuard;
1393cdf0e10cSrcweir if (pDocShell)
1394cdf0e10cSrcweir {
1395cdf0e10cSrcweir String aAppl, aTopic, aItem;
1396cdf0e10cSrcweir
1397cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1398cdf0e10cSrcweir sal_uInt16 nCount = pDoc->GetDdeLinkCount();
1399cdf0e10cSrcweir uno::Sequence<rtl::OUString> aSeq(nCount);
1400cdf0e10cSrcweir rtl::OUString* pAry = aSeq.getArray();
1401cdf0e10cSrcweir
1402cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
1403cdf0e10cSrcweir {
1404cdf0e10cSrcweir pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem );
1405cdf0e10cSrcweir pAry[i] = lcl_BuildDDEName(aAppl, aTopic, aItem);
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir return aSeq;
1408cdf0e10cSrcweir }
1409cdf0e10cSrcweir return uno::Sequence<rtl::OUString>();
1410cdf0e10cSrcweir }
1411cdf0e10cSrcweir
hasByName(const rtl::OUString & aName)1412cdf0e10cSrcweir sal_Bool SAL_CALL ScDDELinksObj::hasByName( const rtl::OUString& aName )
1413cdf0e10cSrcweir throw(uno::RuntimeException)
1414cdf0e10cSrcweir {
1415cdf0e10cSrcweir ScUnoGuard aGuard;
1416cdf0e10cSrcweir if (pDocShell)
1417cdf0e10cSrcweir {
1418cdf0e10cSrcweir String aNamStr(aName);
1419cdf0e10cSrcweir String aAppl, aTopic, aItem;
1420cdf0e10cSrcweir
1421cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1422cdf0e10cSrcweir sal_uInt16 nCount = pDoc->GetDdeLinkCount();
1423cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
1424cdf0e10cSrcweir {
1425cdf0e10cSrcweir pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem );
1426cdf0e10cSrcweir if ( lcl_BuildDDEName(aAppl, aTopic, aItem) == aNamStr )
1427cdf0e10cSrcweir return sal_True;
1428cdf0e10cSrcweir }
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir return sal_False;
1431cdf0e10cSrcweir }
1432cdf0e10cSrcweir
1433cdf0e10cSrcweir // XDDELinks
1434cdf0e10cSrcweir
addDDELink(const::rtl::OUString & aApplication,const::rtl::OUString & aTopic,const::rtl::OUString & aItem,::com::sun::star::sheet::DDELinkMode nMode)1435cdf0e10cSrcweir uno::Reference< sheet::XDDELink > ScDDELinksObj::addDDELink(
1436cdf0e10cSrcweir const ::rtl::OUString& aApplication, const ::rtl::OUString& aTopic,
1437cdf0e10cSrcweir const ::rtl::OUString& aItem, ::com::sun::star::sheet::DDELinkMode nMode )
1438cdf0e10cSrcweir throw (uno::RuntimeException)
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir ScUnoGuard aGuard;
1441cdf0e10cSrcweir uno::Reference< sheet::XDDELink > xLink;
1442cdf0e10cSrcweir
1443cdf0e10cSrcweir if ( pDocShell )
1444cdf0e10cSrcweir {
1445cdf0e10cSrcweir ScDocument* pDoc = pDocShell->GetDocument();
1446cdf0e10cSrcweir if ( pDoc )
1447cdf0e10cSrcweir {
1448cdf0e10cSrcweir sal_uInt8 nMod = SC_DDE_DEFAULT;
1449cdf0e10cSrcweir switch ( nMode )
1450cdf0e10cSrcweir {
1451cdf0e10cSrcweir case sheet::DDELinkMode_DEFAULT:
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir nMod = SC_DDE_DEFAULT;
1454cdf0e10cSrcweir }
1455cdf0e10cSrcweir break;
1456cdf0e10cSrcweir case sheet::DDELinkMode_ENGLISH:
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir nMod = SC_DDE_ENGLISH;
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir break;
1461cdf0e10cSrcweir case sheet::DDELinkMode_TEXT:
1462cdf0e10cSrcweir {
1463cdf0e10cSrcweir nMod = SC_DDE_TEXT;
1464cdf0e10cSrcweir }
1465cdf0e10cSrcweir break;
1466cdf0e10cSrcweir default:
1467cdf0e10cSrcweir {
1468cdf0e10cSrcweir }
1469cdf0e10cSrcweir break;
1470cdf0e10cSrcweir }
1471cdf0e10cSrcweir
1472cdf0e10cSrcweir if ( pDoc->CreateDdeLink( aApplication, aTopic, aItem, nMod ) )
1473cdf0e10cSrcweir {
1474cdf0e10cSrcweir const ::rtl::OUString aName( lcl_BuildDDEName( aApplication, aTopic, aItem ) );
1475cdf0e10cSrcweir xLink.set( GetObjectByName_Impl( aName ) );
1476cdf0e10cSrcweir }
1477cdf0e10cSrcweir }
1478cdf0e10cSrcweir }
1479cdf0e10cSrcweir
1480cdf0e10cSrcweir if ( !xLink.is() )
1481cdf0e10cSrcweir {
1482cdf0e10cSrcweir throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
1483cdf0e10cSrcweir "ScDDELinksObj::addDDELink: cannot add DDE link!" ) ),
1484cdf0e10cSrcweir uno::Reference< uno::XInterface >() );
1485cdf0e10cSrcweir }
1486cdf0e10cSrcweir
1487cdf0e10cSrcweir return xLink;
1488cdf0e10cSrcweir }
1489cdf0e10cSrcweir
1490cdf0e10cSrcweir // ============================================================================
1491cdf0e10cSrcweir
ScExternalSheetCacheObj(ScExternalRefCache::TableTypeRef pTable,size_t nIndex)1492cdf0e10cSrcweir ScExternalSheetCacheObj::ScExternalSheetCacheObj(ScExternalRefCache::TableTypeRef pTable, size_t nIndex) :
1493cdf0e10cSrcweir mpTable(pTable),
1494cdf0e10cSrcweir mnIndex(nIndex)
1495cdf0e10cSrcweir {
1496cdf0e10cSrcweir }
1497cdf0e10cSrcweir
~ScExternalSheetCacheObj()1498cdf0e10cSrcweir ScExternalSheetCacheObj::~ScExternalSheetCacheObj()
1499cdf0e10cSrcweir {
1500cdf0e10cSrcweir }
1501cdf0e10cSrcweir
setCellValue(sal_Int32 nCol,sal_Int32 nRow,const Any & rValue)1502cdf0e10cSrcweir void SAL_CALL ScExternalSheetCacheObj::setCellValue(sal_Int32 nCol, sal_Int32 nRow, const Any& rValue)
1503cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException)
1504cdf0e10cSrcweir {
1505cdf0e10cSrcweir ScUnoGuard aGuard;
1506cdf0e10cSrcweir if (nRow < 0 || nCol < 0)
1507cdf0e10cSrcweir throw IllegalArgumentException();
1508cdf0e10cSrcweir
1509cdf0e10cSrcweir ScExternalRefCache::TokenRef pToken;
1510cdf0e10cSrcweir double fVal = 0.0;
1511cdf0e10cSrcweir OUString aVal;
1512cdf0e10cSrcweir if (rValue >>= fVal)
1513cdf0e10cSrcweir pToken.reset(new FormulaDoubleToken(fVal));
1514cdf0e10cSrcweir else if (rValue >>= aVal)
1515cdf0e10cSrcweir pToken.reset(new FormulaStringToken(aVal));
1516cdf0e10cSrcweir else
1517cdf0e10cSrcweir // unidentified value type.
1518cdf0e10cSrcweir return;
1519cdf0e10cSrcweir
1520cdf0e10cSrcweir mpTable->setCell(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), pToken);
1521cdf0e10cSrcweir }
1522cdf0e10cSrcweir
getCellValue(sal_Int32 nCol,sal_Int32 nRow)1523cdf0e10cSrcweir Any SAL_CALL ScExternalSheetCacheObj::getCellValue(sal_Int32 nCol, sal_Int32 nRow)
1524cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException)
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir ScUnoGuard aGuard;
1527cdf0e10cSrcweir if (nRow < 0 || nCol < 0)
1528cdf0e10cSrcweir throw IllegalArgumentException();
1529cdf0e10cSrcweir
1530cdf0e10cSrcweir FormulaToken* pToken = mpTable->getCell(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow)).get();
1531cdf0e10cSrcweir if (!pToken)
1532cdf0e10cSrcweir throw IllegalArgumentException();
1533cdf0e10cSrcweir
1534cdf0e10cSrcweir Any aValue;
1535cdf0e10cSrcweir switch (pToken->GetType())
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir case svDouble:
1538cdf0e10cSrcweir {
1539cdf0e10cSrcweir double fVal = pToken->GetDouble();
1540cdf0e10cSrcweir aValue <<= fVal;
1541cdf0e10cSrcweir }
1542cdf0e10cSrcweir break;
1543cdf0e10cSrcweir case svString:
1544cdf0e10cSrcweir {
1545cdf0e10cSrcweir OUString aVal = pToken->GetString();
1546cdf0e10cSrcweir aValue <<= aVal;
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir break;
1549cdf0e10cSrcweir default:
1550cdf0e10cSrcweir throw IllegalArgumentException();
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir return aValue;
1553cdf0e10cSrcweir }
1554cdf0e10cSrcweir
getAllRows()1555cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL ScExternalSheetCacheObj::getAllRows()
1556cdf0e10cSrcweir throw (RuntimeException)
1557cdf0e10cSrcweir {
1558cdf0e10cSrcweir ScUnoGuard aGuard;
1559cdf0e10cSrcweir vector<SCROW> aRows;
1560cdf0e10cSrcweir mpTable->getAllRows(aRows);
1561cdf0e10cSrcweir size_t nSize = aRows.size();
1562cdf0e10cSrcweir Sequence<sal_Int32> aRowsSeq(nSize);
1563cdf0e10cSrcweir for (size_t i = 0; i < nSize; ++i)
1564cdf0e10cSrcweir aRowsSeq[i] = aRows[i];
1565cdf0e10cSrcweir
1566cdf0e10cSrcweir return aRowsSeq;
1567cdf0e10cSrcweir }
1568cdf0e10cSrcweir
getAllColumns(sal_Int32 nRow)1569cdf0e10cSrcweir Sequence< sal_Int32 > SAL_CALL ScExternalSheetCacheObj::getAllColumns(sal_Int32 nRow)
1570cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException)
1571cdf0e10cSrcweir {
1572cdf0e10cSrcweir ScUnoGuard aGuard;
1573cdf0e10cSrcweir if (nRow < 0)
1574cdf0e10cSrcweir throw IllegalArgumentException();
1575cdf0e10cSrcweir
1576cdf0e10cSrcweir vector<SCCOL> aCols;
1577cdf0e10cSrcweir mpTable->getAllCols(static_cast<SCROW>(nRow), aCols);
1578cdf0e10cSrcweir size_t nSize = aCols.size();
1579cdf0e10cSrcweir Sequence<sal_Int32> aColsSeq(nSize);
1580cdf0e10cSrcweir for (size_t i = 0; i < nSize; ++i)
1581cdf0e10cSrcweir aColsSeq[i] = aCols[i];
1582cdf0e10cSrcweir
1583cdf0e10cSrcweir return aColsSeq;
1584cdf0e10cSrcweir }
1585cdf0e10cSrcweir
getTokenIndex()1586cdf0e10cSrcweir sal_Int32 SAL_CALL ScExternalSheetCacheObj::getTokenIndex()
1587cdf0e10cSrcweir throw (RuntimeException)
1588cdf0e10cSrcweir {
1589cdf0e10cSrcweir return static_cast< sal_Int32 >( mnIndex );
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir
1592cdf0e10cSrcweir // ============================================================================
1593cdf0e10cSrcweir
ScExternalDocLinkObj(ScExternalRefManager * pRefMgr,sal_uInt16 nFileId)1594cdf0e10cSrcweir ScExternalDocLinkObj::ScExternalDocLinkObj(ScExternalRefManager* pRefMgr, sal_uInt16 nFileId) :
1595cdf0e10cSrcweir mpRefMgr(pRefMgr), mnFileId(nFileId)
1596cdf0e10cSrcweir {
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir
~ScExternalDocLinkObj()1599cdf0e10cSrcweir ScExternalDocLinkObj::~ScExternalDocLinkObj()
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir }
1602cdf0e10cSrcweir
addSheetCache(const OUString & aSheetName,sal_Bool bDynamicCache)1603cdf0e10cSrcweir Reference< sheet::XExternalSheetCache > SAL_CALL ScExternalDocLinkObj::addSheetCache(
1604cdf0e10cSrcweir const OUString& aSheetName, sal_Bool bDynamicCache )
1605cdf0e10cSrcweir throw (RuntimeException)
1606cdf0e10cSrcweir {
1607cdf0e10cSrcweir ScUnoGuard aGuard;
1608cdf0e10cSrcweir size_t nIndex = 0;
1609cdf0e10cSrcweir ScExternalRefCache::TableTypeRef pTable = mpRefMgr->getCacheTable(mnFileId, aSheetName, true, &nIndex);
1610cdf0e10cSrcweir if (!bDynamicCache)
1611cdf0e10cSrcweir // Set the whole table cached to prevent access to the source document.
1612cdf0e10cSrcweir pTable->setWholeTableCached();
1613cdf0e10cSrcweir
1614cdf0e10cSrcweir Reference< sheet::XExternalSheetCache > aSheetCache(new ScExternalSheetCacheObj(pTable, nIndex));
1615cdf0e10cSrcweir return aSheetCache;
1616cdf0e10cSrcweir }
1617cdf0e10cSrcweir
getByName(const::rtl::OUString & aName)1618cdf0e10cSrcweir Any SAL_CALL ScExternalDocLinkObj::getByName(const::rtl::OUString &aName)
1619cdf0e10cSrcweir throw (container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
1620cdf0e10cSrcweir {
1621cdf0e10cSrcweir ScUnoGuard aGuard;
1622cdf0e10cSrcweir size_t nIndex = 0;
1623cdf0e10cSrcweir ScExternalRefCache::TableTypeRef pTable = mpRefMgr->getCacheTable(mnFileId, aName, false, &nIndex);
1624cdf0e10cSrcweir if (!pTable)
1625cdf0e10cSrcweir throw container::NoSuchElementException();
1626cdf0e10cSrcweir
1627cdf0e10cSrcweir Reference< sheet::XExternalSheetCache > aSheetCache(new ScExternalSheetCacheObj(pTable, nIndex));
1628cdf0e10cSrcweir
1629cdf0e10cSrcweir Any aAny;
1630cdf0e10cSrcweir aAny <<= aSheetCache;
1631cdf0e10cSrcweir return aAny;
1632cdf0e10cSrcweir }
1633cdf0e10cSrcweir
getElementNames()1634cdf0e10cSrcweir Sequence< OUString > SAL_CALL ScExternalDocLinkObj::getElementNames()
1635cdf0e10cSrcweir throw (RuntimeException)
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir ScUnoGuard aGuard;
1638cdf0e10cSrcweir vector<String> aTabNames;
1639cdf0e10cSrcweir mpRefMgr->getAllCachedTableNames(mnFileId, aTabNames);
1640cdf0e10cSrcweir
1641cdf0e10cSrcweir // #i116940# be consistent with getByName: include only table names which have a cache already
1642cdf0e10cSrcweir vector<String> aValidNames;
1643cdf0e10cSrcweir for (vector<String>::const_iterator aIter = aTabNames.begin(); aIter != aTabNames.end(); ++aIter)
1644cdf0e10cSrcweir if (mpRefMgr->getCacheTable(mnFileId, *aIter, false))
1645cdf0e10cSrcweir aValidNames.push_back(*aIter);
1646cdf0e10cSrcweir
1647cdf0e10cSrcweir size_t n = aValidNames.size();
1648cdf0e10cSrcweir Sequence<OUString> aSeq(n);
1649cdf0e10cSrcweir for (size_t i = 0; i < n; ++i)
1650cdf0e10cSrcweir aSeq[i] = aValidNames[i];
1651cdf0e10cSrcweir return aSeq;
1652cdf0e10cSrcweir }
1653cdf0e10cSrcweir
hasByName(const OUString & aName)1654cdf0e10cSrcweir sal_Bool SAL_CALL ScExternalDocLinkObj::hasByName(const OUString &aName)
1655cdf0e10cSrcweir throw (RuntimeException)
1656cdf0e10cSrcweir {
1657cdf0e10cSrcweir ScUnoGuard aGuard;
1658cdf0e10cSrcweir
1659cdf0e10cSrcweir // #i116940# be consistent with getByName: allow only table names which have a cache already
1660cdf0e10cSrcweir ScExternalRefCache::TableTypeRef pTable = mpRefMgr->getCacheTable(mnFileId, aName, false);
1661cdf0e10cSrcweir return (pTable.get() != NULL);
1662cdf0e10cSrcweir }
1663cdf0e10cSrcweir
getCount()1664cdf0e10cSrcweir sal_Int32 SAL_CALL ScExternalDocLinkObj::getCount()
1665cdf0e10cSrcweir throw (RuntimeException)
1666cdf0e10cSrcweir {
1667cdf0e10cSrcweir ScUnoGuard aGuard;
1668cdf0e10cSrcweir
1669cdf0e10cSrcweir // #i116940# be consistent with getByName: count only table names which have a cache already
1670cdf0e10cSrcweir return getElementNames().getLength();
1671cdf0e10cSrcweir }
1672cdf0e10cSrcweir
getByIndex(sal_Int32 nApiIndex)1673cdf0e10cSrcweir Any SAL_CALL ScExternalDocLinkObj::getByIndex(sal_Int32 nApiIndex)
1674cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, RuntimeException)
1675cdf0e10cSrcweir {
1676cdf0e10cSrcweir ScUnoGuard aGuard;
1677cdf0e10cSrcweir
1678cdf0e10cSrcweir // #i116940# Can't use nApiIndex as index for the ref manager, because the API counts only
1679cdf0e10cSrcweir // the entries which have a cache already. Quick solution: Use getElementNames.
1680cdf0e10cSrcweir
1681cdf0e10cSrcweir Sequence< OUString > aNames( getElementNames() );
1682cdf0e10cSrcweir if (nApiIndex < 0 || nApiIndex >= aNames.getLength())
1683cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
1684cdf0e10cSrcweir
1685cdf0e10cSrcweir size_t nIndex = 0;
1686cdf0e10cSrcweir ScExternalRefCache::TableTypeRef pTable = mpRefMgr->getCacheTable(mnFileId, aNames[nApiIndex], false, &nIndex);
1687cdf0e10cSrcweir if (!pTable)
1688cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
1689cdf0e10cSrcweir
1690cdf0e10cSrcweir Reference< sheet::XExternalSheetCache > aSheetCache(new ScExternalSheetCacheObj(pTable, nIndex));
1691cdf0e10cSrcweir
1692cdf0e10cSrcweir Any aAny;
1693cdf0e10cSrcweir aAny <<= aSheetCache;
1694cdf0e10cSrcweir return aAny;
1695cdf0e10cSrcweir }
1696cdf0e10cSrcweir
createEnumeration()1697cdf0e10cSrcweir Reference< container::XEnumeration > SAL_CALL ScExternalDocLinkObj::createEnumeration()
1698cdf0e10cSrcweir throw (RuntimeException)
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir ScUnoGuard aGuard;
1701cdf0e10cSrcweir Reference< container::XEnumeration > aRef(
1702cdf0e10cSrcweir new ScIndexEnumeration(this, OUString::createFromAscii(
1703cdf0e10cSrcweir "com.sun.star.sheet.ExternalDocLink")));
1704cdf0e10cSrcweir return aRef;
1705cdf0e10cSrcweir }
1706cdf0e10cSrcweir
getElementType()1707cdf0e10cSrcweir uno::Type SAL_CALL ScExternalDocLinkObj::getElementType()
1708cdf0e10cSrcweir throw (RuntimeException)
1709cdf0e10cSrcweir {
1710cdf0e10cSrcweir ScUnoGuard aGuard;
1711cdf0e10cSrcweir return getCppuType(static_cast<Reference<sheet::XExternalDocLink>*>(0));
1712cdf0e10cSrcweir }
1713cdf0e10cSrcweir
hasElements()1714cdf0e10cSrcweir sal_Bool SAL_CALL ScExternalDocLinkObj::hasElements()
1715cdf0e10cSrcweir throw (RuntimeException)
1716cdf0e10cSrcweir {
1717cdf0e10cSrcweir ScUnoGuard aGuard;
1718cdf0e10cSrcweir
1719cdf0e10cSrcweir // #i116940# be consistent with getByName: count only table names which have a cache already
1720cdf0e10cSrcweir return ( getElementNames().getLength() > 0 );
1721cdf0e10cSrcweir }
1722cdf0e10cSrcweir
getTokenIndex()1723cdf0e10cSrcweir sal_Int32 SAL_CALL ScExternalDocLinkObj::getTokenIndex()
1724cdf0e10cSrcweir throw (RuntimeException)
1725cdf0e10cSrcweir {
1726cdf0e10cSrcweir return static_cast<sal_Int32>(mnFileId);
1727cdf0e10cSrcweir }
1728cdf0e10cSrcweir
1729cdf0e10cSrcweir // ============================================================================
1730cdf0e10cSrcweir
ScExternalDocLinksObj(ScDocShell * pDocShell)1731cdf0e10cSrcweir ScExternalDocLinksObj::ScExternalDocLinksObj(ScDocShell* pDocShell) :
1732cdf0e10cSrcweir mpDocShell(pDocShell),
1733cdf0e10cSrcweir mpRefMgr(pDocShell->GetDocument()->GetExternalRefManager())
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir }
1736cdf0e10cSrcweir
~ScExternalDocLinksObj()1737cdf0e10cSrcweir ScExternalDocLinksObj::~ScExternalDocLinksObj()
1738cdf0e10cSrcweir {
1739cdf0e10cSrcweir }
1740cdf0e10cSrcweir
addDocLink(const OUString & aDocName)1741cdf0e10cSrcweir Reference< sheet::XExternalDocLink > SAL_CALL ScExternalDocLinksObj::addDocLink(
1742cdf0e10cSrcweir const OUString& aDocName )
1743cdf0e10cSrcweir throw (RuntimeException)
1744cdf0e10cSrcweir {
1745cdf0e10cSrcweir ScUnoGuard aGuard;
1746cdf0e10cSrcweir sal_uInt16 nFileId = mpRefMgr->getExternalFileId(aDocName);
1747cdf0e10cSrcweir Reference< sheet::XExternalDocLink > aDocLink(new ScExternalDocLinkObj(mpRefMgr, nFileId));
1748cdf0e10cSrcweir return aDocLink;
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir
getByName(const::rtl::OUString & aName)1751cdf0e10cSrcweir Any SAL_CALL ScExternalDocLinksObj::getByName(const::rtl::OUString &aName)
1752cdf0e10cSrcweir throw (container::NoSuchElementException, lang::WrappedTargetException, RuntimeException)
1753cdf0e10cSrcweir {
1754cdf0e10cSrcweir ScUnoGuard aGuard;
1755cdf0e10cSrcweir if (!mpRefMgr->hasExternalFile(aName))
1756cdf0e10cSrcweir throw container::NoSuchElementException();
1757cdf0e10cSrcweir
1758cdf0e10cSrcweir sal_uInt16 nFileId = mpRefMgr->getExternalFileId(aName);
1759cdf0e10cSrcweir Reference< sheet::XExternalDocLink > aDocLink(new ScExternalDocLinkObj(mpRefMgr, nFileId));
1760cdf0e10cSrcweir
1761cdf0e10cSrcweir Any aAny;
1762cdf0e10cSrcweir aAny <<= aDocLink;
1763cdf0e10cSrcweir return aAny;
1764cdf0e10cSrcweir }
1765cdf0e10cSrcweir
getElementNames()1766cdf0e10cSrcweir Sequence< OUString > SAL_CALL ScExternalDocLinksObj::getElementNames()
1767cdf0e10cSrcweir throw (RuntimeException)
1768cdf0e10cSrcweir {
1769cdf0e10cSrcweir ScUnoGuard aGuard;
1770cdf0e10cSrcweir sal_uInt16 n = mpRefMgr->getExternalFileCount();
1771cdf0e10cSrcweir Sequence<OUString> aSeq(n);
1772cdf0e10cSrcweir for (sal_uInt16 i = 0; i < n; ++i)
1773cdf0e10cSrcweir {
1774cdf0e10cSrcweir const String* pName = mpRefMgr->getExternalFileName(i);
1775cdf0e10cSrcweir aSeq[i] = pName ? *pName : EMPTY_STRING;
1776cdf0e10cSrcweir }
1777cdf0e10cSrcweir
1778cdf0e10cSrcweir return aSeq;
1779cdf0e10cSrcweir }
1780cdf0e10cSrcweir
hasByName(const OUString & aName)1781cdf0e10cSrcweir sal_Bool SAL_CALL ScExternalDocLinksObj::hasByName(const OUString &aName)
1782cdf0e10cSrcweir throw (RuntimeException)
1783cdf0e10cSrcweir {
1784cdf0e10cSrcweir ScUnoGuard aGuard;
1785cdf0e10cSrcweir return mpRefMgr->hasExternalFile(aName);
1786cdf0e10cSrcweir }
1787cdf0e10cSrcweir
getCount()1788cdf0e10cSrcweir sal_Int32 SAL_CALL ScExternalDocLinksObj::getCount()
1789cdf0e10cSrcweir throw (RuntimeException)
1790cdf0e10cSrcweir {
1791cdf0e10cSrcweir ScUnoGuard aGuard;
1792cdf0e10cSrcweir return mpRefMgr->getExternalFileCount();
1793cdf0e10cSrcweir }
1794cdf0e10cSrcweir
getByIndex(sal_Int32 nIndex)1795cdf0e10cSrcweir Any SAL_CALL ScExternalDocLinksObj::getByIndex(sal_Int32 nIndex)
1796cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, RuntimeException)
1797cdf0e10cSrcweir {
1798cdf0e10cSrcweir ScUnoGuard aGuard;
1799cdf0e10cSrcweir if (nIndex > ::std::numeric_limits<sal_uInt16>::max() || nIndex < ::std::numeric_limits<sal_uInt16>::min())
1800cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
1801cdf0e10cSrcweir
1802cdf0e10cSrcweir sal_uInt16 nFileId = static_cast<sal_uInt16>(nIndex);
1803cdf0e10cSrcweir
1804cdf0e10cSrcweir if (!mpRefMgr->hasExternalFile(nFileId))
1805cdf0e10cSrcweir throw lang::IndexOutOfBoundsException();
1806cdf0e10cSrcweir
1807cdf0e10cSrcweir Reference< sheet::XExternalDocLink > aDocLink(new ScExternalDocLinkObj(mpRefMgr, nFileId));
1808cdf0e10cSrcweir Any aAny;
1809cdf0e10cSrcweir aAny <<= aDocLink;
1810cdf0e10cSrcweir return aAny;
1811cdf0e10cSrcweir }
1812cdf0e10cSrcweir
createEnumeration()1813cdf0e10cSrcweir Reference< container::XEnumeration > SAL_CALL ScExternalDocLinksObj::createEnumeration()
1814cdf0e10cSrcweir throw (RuntimeException)
1815cdf0e10cSrcweir {
1816cdf0e10cSrcweir ScUnoGuard aGuard;
1817cdf0e10cSrcweir Reference< container::XEnumeration > aRef(
1818cdf0e10cSrcweir new ScIndexEnumeration(this, OUString::createFromAscii(
1819cdf0e10cSrcweir "com.sun.star.sheet.ExternalDocLinks")));
1820cdf0e10cSrcweir return aRef;
1821cdf0e10cSrcweir }
1822cdf0e10cSrcweir
getElementType()1823cdf0e10cSrcweir uno::Type SAL_CALL ScExternalDocLinksObj::getElementType()
1824cdf0e10cSrcweir throw (RuntimeException)
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir ScUnoGuard aGuard;
1827cdf0e10cSrcweir return getCppuType(static_cast<Reference<sheet::XExternalDocLinks>*>(0));
1828cdf0e10cSrcweir }
1829cdf0e10cSrcweir
hasElements()1830cdf0e10cSrcweir sal_Bool SAL_CALL ScExternalDocLinksObj::hasElements()
1831cdf0e10cSrcweir throw (RuntimeException)
1832cdf0e10cSrcweir {
1833cdf0e10cSrcweir ScUnoGuard aGuard;
1834cdf0e10cSrcweir return mpRefMgr->getExternalFileCount() > 0;
1835cdf0e10cSrcweir }
1836cdf0e10cSrcweir
1837