LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/unoobj - targuno.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 118 0.0 %
Date: 2012-12-27 Functions: 0 40 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <vcl/image.hxx>
      21             : #include <vcl/virdev.hxx>
      22             : #include <toolkit/unohlp.hxx>
      23             : #include <svl/itemprop.hxx>
      24             : #include <svl/smplhint.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : #include <vcl/settings.hxx>
      27             : #include <com/sun/star/awt/XBitmap.hpp>
      28             : 
      29             : #include "targuno.hxx"
      30             : #include "miscuno.hxx"
      31             : #include "docuno.hxx"
      32             : #include "datauno.hxx"
      33             : #include "nameuno.hxx"
      34             : #include "docsh.hxx"
      35             : #include "content.hxx"
      36             : #include "scresid.hxx"
      37             : #include "sc.hrc"
      38             : #include "unonames.hxx"
      39             : 
      40             : using  namespace ::com::sun::star;
      41             : 
      42             : //------------------------------------------------------------------------
      43             : 
      44             : sal_uInt16 nTypeResIds[SC_LINKTARGETTYPE_COUNT] =
      45             : {
      46             :     SCSTR_CONTENT_TABLE,        // SC_LINKTARGETTYPE_SHEET
      47             :     SCSTR_CONTENT_RANGENAME,    // SC_LINKTARGETTYPE_RANGENAME
      48             :     SCSTR_CONTENT_DBAREA        // SC_LINKTARGETTYPE_DBAREA
      49             : };
      50             : 
      51           0 : static const SfxItemPropertyMapEntry* lcl_GetLinkTargetMap()
      52             : {
      53             :     static SfxItemPropertyMapEntry aLinkTargetMap_Impl[] =
      54             :     {
      55           0 :         {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT),  0,  &getCppuType((const uno::Reference<awt::XBitmap>*)0),   beans::PropertyAttribute::READONLY, 0 },
      56           0 :         {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0,  &getCppuType((const ::rtl::OUString*)0),                beans::PropertyAttribute::READONLY, 0 },
      57             :         {0,0,0,0,0,0}
      58           0 :     };
      59           0 :     return aLinkTargetMap_Impl;
      60             : }
      61             : 
      62             : //------------------------------------------------------------------------
      63             : 
      64             : // service for ScLinkTargetTypeObj is not defined
      65             : //  must not support document::LinkTarget because the target type cannot be used as a target
      66             : 
      67           0 : SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
      68           0 : SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj,  "ScLinkTargetTypeObj",  "com.sun.star.document.LinkTargetSupplier" )
      69           0 : SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj,     "ScLinkTargetsObj",     "com.sun.star.document.LinkTargets" )
      70             : 
      71             : //------------------------------------------------------------------------
      72             : 
      73           0 : ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell* pDocSh) :
      74           0 :     pDocShell( pDocSh )
      75             : {
      76           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
      77             : 
      78           0 :     for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
      79           0 :         aNames[i] = String( ScResId( nTypeResIds[i] ) );
      80           0 : }
      81             : 
      82           0 : ScLinkTargetTypesObj::~ScLinkTargetTypesObj()
      83             : {
      84           0 :     if (pDocShell)
      85           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
      86           0 : }
      87             : 
      88           0 : void ScLinkTargetTypesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      89             : {
      90           0 :     if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
      91           0 :         pDocShell = NULL;       // document gone
      92           0 : }
      93             : 
      94             : // container::XNameAccess
      95             : 
      96           0 : uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const rtl::OUString& aName)
      97             :         throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
      98             : {
      99           0 :     if (pDocShell)
     100             :     {
     101           0 :         String aNameStr(aName);
     102           0 :         for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
     103           0 :             if ( aNames[i] == aNameStr )
     104           0 :                 return uno::makeAny(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i )));
     105             :     }
     106             : 
     107           0 :     throw container::NoSuchElementException();
     108             : }
     109             : 
     110           0 : uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames(void) throw( uno::RuntimeException )
     111             : {
     112           0 :     uno::Sequence<rtl::OUString> aRet(SC_LINKTARGETTYPE_COUNT);
     113           0 :     rtl::OUString* pArray = aRet.getArray();
     114           0 :     for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
     115           0 :         pArray[i] = aNames[i];
     116           0 :     return aRet;
     117             : }
     118             : 
     119           0 : sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException )
     120             : {
     121           0 :     String aNameStr = aName;
     122           0 :     for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
     123           0 :         if ( aNames[i] == aNameStr )
     124           0 :             return sal_True;
     125           0 :     return false;
     126             : }
     127             : 
     128             : // container::XElementAccess
     129             : 
     130           0 : uno::Type SAL_CALL ScLinkTargetTypesObj::getElementType(void) throw( uno::RuntimeException )
     131             : {
     132           0 :     return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);
     133             : }
     134             : 
     135           0 : sal_Bool SAL_CALL ScLinkTargetTypesObj::hasElements(void) throw( uno::RuntimeException )
     136             : {
     137           0 :     return sal_True;
     138             : }
     139             : 
     140             : //------------------------------------------------------------------------
     141             : 
     142           0 : ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell* pDocSh, sal_uInt16 nT) :
     143             :     pDocShell( pDocSh ),
     144           0 :     nType( nT )
     145             : {
     146           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
     147           0 :     aName = String( ScResId( nTypeResIds[nType] ) );    //! on demand?
     148           0 : }
     149             : 
     150           0 : ScLinkTargetTypeObj::~ScLinkTargetTypeObj()
     151             : {
     152           0 :     if (pDocShell)
     153           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
     154           0 : }
     155             : 
     156           0 : void ScLinkTargetTypeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
     157             : {
     158           0 :     if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
     159           0 :         pDocShell = NULL;       // document gone
     160           0 : }
     161             : 
     162             : // document::XLinkTargetSupplier
     163             : 
     164           0 : uno::Reference< container::XNameAccess > SAL_CALL  ScLinkTargetTypeObj::getLinks(void) throw( uno::RuntimeException )
     165             : {
     166           0 :     uno::Reference< container::XNameAccess >  xCollection;
     167             : 
     168           0 :     if ( pDocShell )
     169             :     {
     170           0 :         switch ( nType )
     171             :         {
     172             :             case SC_LINKTARGETTYPE_SHEET:
     173           0 :                 xCollection.set(new ScTableSheetsObj(pDocShell));
     174           0 :                 break;
     175             :             case SC_LINKTARGETTYPE_RANGENAME:
     176           0 :                 xCollection.set(new ScGlobalNamedRangesObj(pDocShell));
     177           0 :                 break;
     178             :             case SC_LINKTARGETTYPE_DBAREA:
     179           0 :                 xCollection.set(new ScDatabaseRangesObj(pDocShell));
     180           0 :                 break;
     181             :             default:
     182             :                 OSL_FAIL("invalid type");
     183             :         }
     184             :     }
     185             : 
     186             :     //  wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
     187             :     //  beans::XPropertySet as ElementType in container::XNameAccess.
     188           0 :     if ( xCollection.is() )
     189           0 :         return new ScLinkTargetsObj( xCollection );
     190           0 :     return NULL;
     191             : }
     192             : 
     193             : // beans::XPropertySet
     194             : 
     195           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL  ScLinkTargetTypeObj::getPropertySetInfo(void) throw( uno::RuntimeException )
     196             : {
     197           0 :     SolarMutexGuard aGuard;
     198           0 :     static uno::Reference< beans::XPropertySetInfo >  aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
     199           0 :     return aRef;
     200             : }
     201             : 
     202           0 : void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const rtl::OUString& /* aPropertyName */,
     203             :             const uno::Any& /* aValue */)
     204             :         throw(  beans::UnknownPropertyException,
     205             :                 beans::PropertyVetoException,
     206             :                 lang::IllegalArgumentException,
     207             :                 lang::WrappedTargetException,
     208             :                  uno::RuntimeException )
     209             : {
     210             :     //  everything is read-only
     211             :     //! exception?
     212           0 : }
     213             : 
     214           0 : void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any& rRet, sal_uInt16 nType )
     215             : {
     216           0 :     sal_uInt16 nImgId = 0;
     217           0 :     switch ( nType )
     218             :     {
     219             :         case SC_LINKTARGETTYPE_SHEET:
     220           0 :             nImgId = SC_CONTENT_TABLE;
     221           0 :             break;
     222             :         case SC_LINKTARGETTYPE_RANGENAME:
     223           0 :             nImgId = SC_CONTENT_RANGENAME;
     224           0 :             break;
     225             :         case SC_LINKTARGETTYPE_DBAREA:
     226           0 :             nImgId = SC_CONTENT_DBAREA;
     227           0 :             break;
     228             :     }
     229           0 :     if (nImgId)
     230             :     {
     231           0 :         ImageList aEntryImages( ScResId( RID_IMAGELIST_NAVCONT ) );
     232           0 :         const Image& rImage = aEntryImages.GetImage( nImgId );
     233           0 :         rRet <<= uno::Reference< awt::XBitmap > (VCLUnoHelper::CreateBitmap( rImage.GetBitmapEx() ));
     234             :     }
     235           0 : }
     236             : 
     237           0 : uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const rtl::OUString& PropertyName)
     238             :         throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
     239             : {
     240           0 :     uno::Any aRet;
     241           0 :     String aNameStr(PropertyName);
     242           0 :     if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPBIT ) )
     243           0 :         SetLinkTargetBitmap( aRet, nType );
     244           0 :     else if ( aNameStr.EqualsAscii( SC_UNO_LINKDISPNAME ) )
     245           0 :         aRet <<= rtl::OUString( aName );
     246             : 
     247           0 :     return aRet;
     248             : }
     249             : 
     250           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj )
     251             : 
     252             : //------------------------------------------------------------------------
     253             : 
     254           0 : ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference< container::XNameAccess > & rColl ) :
     255           0 :     xCollection( rColl )
     256             : {
     257             :     OSL_ENSURE( xCollection.is(), "ScLinkTargetsObj: NULL" );
     258           0 : }
     259             : 
     260           0 : ScLinkTargetsObj::~ScLinkTargetsObj()
     261             : {
     262           0 : }
     263             : 
     264             : // container::XNameAccess
     265             : 
     266           0 : uno::Any SAL_CALL ScLinkTargetsObj::getByName(const rtl::OUString& aName)
     267             :         throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException )
     268             : {
     269           0 :     uno::Reference< beans::XPropertySet >  xProp( ScUnoHelpFunctions::AnyToInterface( xCollection->getByName(aName) ), uno::UNO_QUERY );
     270           0 :     if (xProp.is())
     271           0 :         return uno::makeAny(xProp);
     272             : 
     273           0 :     throw container::NoSuchElementException();
     274             : //    return uno::Any();
     275             : }
     276             : 
     277           0 : uno::Sequence<rtl::OUString> SAL_CALL ScLinkTargetsObj::getElementNames(void) throw( uno::RuntimeException )
     278             : {
     279           0 :     return xCollection->getElementNames();
     280             : }
     281             : 
     282           0 : sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const rtl::OUString& aName) throw( uno::RuntimeException )
     283             : {
     284           0 :     return xCollection->hasByName(aName);
     285             : }
     286             : 
     287             : // container::XElementAccess
     288             : 
     289           0 : uno::Type SAL_CALL ScLinkTargetsObj::getElementType(void) throw( uno::RuntimeException )
     290             : {
     291           0 :     return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0);
     292             : }
     293             : 
     294           0 : sal_Bool SAL_CALL ScLinkTargetsObj::hasElements(void) throw( uno::RuntimeException )
     295             : {
     296           0 :     return xCollection->hasElements();
     297             : }
     298             : 
     299             : 
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10