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