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 <vcl/image.hxx> 34*cdf0e10cSrcweir #include <vcl/virdev.hxx> 35*cdf0e10cSrcweir //#include <toolkit/unoiface.hxx> 36*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 37*cdf0e10cSrcweir #include <svl/itemprop.hxx> 38*cdf0e10cSrcweir #include <svl/smplhint.hxx> 39*cdf0e10cSrcweir #include <vcl/svapp.hxx> 40*cdf0e10cSrcweir #include <vcl/settings.hxx> 41*cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include "targuno.hxx" 44*cdf0e10cSrcweir #include "miscuno.hxx" 45*cdf0e10cSrcweir #include "docuno.hxx" 46*cdf0e10cSrcweir #include "datauno.hxx" 47*cdf0e10cSrcweir #include "nameuno.hxx" 48*cdf0e10cSrcweir #include "docsh.hxx" 49*cdf0e10cSrcweir #include "content.hxx" 50*cdf0e10cSrcweir #include "unoguard.hxx" 51*cdf0e10cSrcweir #include "scresid.hxx" 52*cdf0e10cSrcweir #include "sc.hrc" 53*cdf0e10cSrcweir #include "unonames.hxx" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir using namespace ::com::sun::star; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir //------------------------------------------------------------------------ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir sal_uInt16 nTypeResIds[SC_LINKTARGETTYPE_COUNT] = 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir SCSTR_CONTENT_TABLE, // SC_LINKTARGETTYPE_SHEET 62*cdf0e10cSrcweir SCSTR_CONTENT_RANGENAME, // SC_LINKTARGETTYPE_RANGENAME 63*cdf0e10cSrcweir SCSTR_CONTENT_DBAREA // SC_LINKTARGETTYPE_DBAREA 64*cdf0e10cSrcweir }; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir const SfxItemPropertyMapEntry* lcl_GetLinkTargetMap() 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir static SfxItemPropertyMapEntry aLinkTargetMap_Impl[] = 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((const uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 }, 71*cdf0e10cSrcweir {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, 72*cdf0e10cSrcweir {0,0,0,0,0,0} 73*cdf0e10cSrcweir }; 74*cdf0e10cSrcweir return aLinkTargetMap_Impl; 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //------------------------------------------------------------------------ 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir // service for ScLinkTargetTypeObj is not defined 80*cdf0e10cSrcweir // must not support document::LinkTarget because the target type cannot be used as a target 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" ) 83*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj, "ScLinkTargetTypeObj", "com.sun.star.document.LinkTargetSupplier" ) 84*cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj, "ScLinkTargetsObj", "com.sun.star.document.LinkTargets" ) 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir //------------------------------------------------------------------------ 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell* pDocSh) : 89*cdf0e10cSrcweir pDocShell( pDocSh ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 94*cdf0e10cSrcweir aNames[i] = String( ScResId( nTypeResIds[i] ) ); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir ScLinkTargetTypesObj::~ScLinkTargetTypesObj() 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir if (pDocShell) 100*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void ScLinkTargetTypesObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 106*cdf0e10cSrcweir pDocShell = NULL; // document gone 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // container::XNameAccess 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const rtl::OUString& aName) 112*cdf0e10cSrcweir throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir if (pDocShell) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir String aNameStr(aName); 117*cdf0e10cSrcweir for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 118*cdf0e10cSrcweir if ( aNames[i] == aNameStr ) 119*cdf0e10cSrcweir return uno::makeAny(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i ))); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir throw container::NoSuchElementException(); 123*cdf0e10cSrcweir // return uno::Any(); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames(void) throw( uno::RuntimeException ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir uno::Sequence<rtl::OUString> aRet(SC_LINKTARGETTYPE_COUNT); 129*cdf0e10cSrcweir rtl::OUString* pArray = aRet.getArray(); 130*cdf0e10cSrcweir for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 131*cdf0e10cSrcweir pArray[i] = aNames[i]; 132*cdf0e10cSrcweir return aRet; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir String aNameStr = aName; 138*cdf0e10cSrcweir for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++) 139*cdf0e10cSrcweir if ( aNames[i] == aNameStr ) 140*cdf0e10cSrcweir return sal_True; 141*cdf0e10cSrcweir return sal_False; 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // container::XElementAccess 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir uno::Type SAL_CALL ScLinkTargetTypesObj::getElementType(void) throw( uno::RuntimeException ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetTypesObj::hasElements(void) throw( uno::RuntimeException ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir return sal_True; 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //------------------------------------------------------------------------ 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell* pDocSh, sal_uInt16 nT) : 159*cdf0e10cSrcweir pDocShell( pDocSh ), 160*cdf0e10cSrcweir nType( nT ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 163*cdf0e10cSrcweir aName = String( ScResId( nTypeResIds[nType] ) ); //! on demand? 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ScLinkTargetTypeObj::~ScLinkTargetTypeObj() 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir if (pDocShell) 169*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir void ScLinkTargetTypeObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) 175*cdf0e10cSrcweir pDocShell = NULL; // document gone 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // document::XLinkTargetSupplier 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir uno::Reference< container::XNameAccess > SAL_CALL ScLinkTargetTypeObj::getLinks(void) throw( uno::RuntimeException ) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xCollection; 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir if ( pDocShell ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir switch ( nType ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir case SC_LINKTARGETTYPE_SHEET: 189*cdf0e10cSrcweir xCollection.set(new ScTableSheetsObj(pDocShell)); 190*cdf0e10cSrcweir break; 191*cdf0e10cSrcweir case SC_LINKTARGETTYPE_RANGENAME: 192*cdf0e10cSrcweir xCollection.set(new ScNamedRangesObj(pDocShell)); 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir case SC_LINKTARGETTYPE_DBAREA: 195*cdf0e10cSrcweir xCollection.set(new ScDatabaseRangesObj(pDocShell)); 196*cdf0e10cSrcweir break; 197*cdf0e10cSrcweir default: 198*cdf0e10cSrcweir DBG_ERROR("invalid type"); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // wrap collection in ScLinkTargetsObj because service document::LinkTargets requires 203*cdf0e10cSrcweir // beans::XPropertySet as ElementType in container::XNameAccess. 204*cdf0e10cSrcweir if ( xCollection.is() ) 205*cdf0e10cSrcweir return new ScLinkTargetsObj( xCollection ); 206*cdf0e10cSrcweir return NULL; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // beans::XPropertySet 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL ScLinkTargetTypeObj::getPropertySetInfo(void) throw( uno::RuntimeException ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir ScUnoGuard aGuard; 214*cdf0e10cSrcweir static uno::Reference< beans::XPropertySetInfo > aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() )); 215*cdf0e10cSrcweir return aRef; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const rtl::OUString& /* aPropertyName */, 219*cdf0e10cSrcweir const uno::Any& /* aValue */) 220*cdf0e10cSrcweir throw( beans::UnknownPropertyException, 221*cdf0e10cSrcweir beans::PropertyVetoException, 222*cdf0e10cSrcweir lang::IllegalArgumentException, 223*cdf0e10cSrcweir lang::WrappedTargetException, 224*cdf0e10cSrcweir uno::RuntimeException ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir // everything is read-only 227*cdf0e10cSrcweir //! exception? 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir // static 231*cdf0e10cSrcweir void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any& rRet, sal_uInt16 nType ) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir sal_uInt16 nImgId = 0; 234*cdf0e10cSrcweir switch ( nType ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir case SC_LINKTARGETTYPE_SHEET: 237*cdf0e10cSrcweir nImgId = SC_CONTENT_TABLE; 238*cdf0e10cSrcweir break; 239*cdf0e10cSrcweir case SC_LINKTARGETTYPE_RANGENAME: 240*cdf0e10cSrcweir nImgId = SC_CONTENT_RANGENAME; 241*cdf0e10cSrcweir break; 242*cdf0e10cSrcweir case SC_LINKTARGETTYPE_DBAREA: 243*cdf0e10cSrcweir nImgId = SC_CONTENT_DBAREA; 244*cdf0e10cSrcweir break; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir if (nImgId) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir sal_Bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode(); 249*cdf0e10cSrcweir ImageList aEntryImages( ScResId( bHighContrast ? RID_IMAGELIST_H_NAVCONT : RID_IMAGELIST_NAVCONT ) ); 250*cdf0e10cSrcweir const Image& rImage = aEntryImages.GetImage( nImgId ); 251*cdf0e10cSrcweir rRet <<= uno::Reference< awt::XBitmap > (VCLUnoHelper::CreateBitmap( rImage.GetBitmapEx() )); 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const rtl::OUString& PropertyName) 256*cdf0e10cSrcweir throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException ) 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir uno::Any aRet; 259*cdf0e10cSrcweir String aNameStr(PropertyName); 260*cdf0e10cSrcweir if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPBIT ) ) 261*cdf0e10cSrcweir SetLinkTargetBitmap( aRet, nType ); 262*cdf0e10cSrcweir else if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPNAME ) ) 263*cdf0e10cSrcweir aRet <<= rtl::OUString( aName ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir return aRet; 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj ) 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir //------------------------------------------------------------------------ 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference< container::XNameAccess > & rColl ) : 273*cdf0e10cSrcweir xCollection( rColl ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir DBG_ASSERT( xCollection.is(), "ScLinkTargetsObj: NULL" ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir ScLinkTargetsObj::~ScLinkTargetsObj() 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // container::XNameAccess 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir uno::Any SAL_CALL ScLinkTargetsObj::getByName(const rtl::OUString& aName) 285*cdf0e10cSrcweir throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( ScUnoHelpFunctions::AnyToInterface( xCollection->getByName(aName) ), uno::UNO_QUERY ); 288*cdf0e10cSrcweir if (xProp.is()) 289*cdf0e10cSrcweir return uno::makeAny(xProp); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir throw container::NoSuchElementException(); 292*cdf0e10cSrcweir // return uno::Any(); 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetsObj::getElementNames(void) throw( uno::RuntimeException ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir return xCollection->getElementNames(); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir return xCollection->hasByName(aName); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir // container::XElementAccess 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir uno::Type SAL_CALL ScLinkTargetsObj::getElementType(void) throw( uno::RuntimeException ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir sal_Bool SAL_CALL ScLinkTargetsObj::hasElements(void) throw( uno::RuntimeException ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir return xCollection->hasElements(); 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir 319