LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - targuno.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 22 123 17.9 %
Date: 2015-06-13 12:38:46 Functions: 7 43 16.3 %
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/helper/vclunohelper.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             : sal_uInt16 nTypeResIds[SC_LINKTARGETTYPE_COUNT] =
      43             : {
      44             :     SCSTR_CONTENT_TABLE,        // SC_LINKTARGETTYPE_SHEET
      45             :     SCSTR_CONTENT_RANGENAME,    // SC_LINKTARGETTYPE_RANGENAME
      46             :     SCSTR_CONTENT_DBAREA        // SC_LINKTARGETTYPE_DBAREA
      47             : };
      48             : 
      49           0 : static const SfxItemPropertyMapEntry* lcl_GetLinkTargetMap()
      50             : {
      51             :     static const SfxItemPropertyMapEntry aLinkTargetMap_Impl[] =
      52             :     {
      53           0 :         {OUString(SC_UNO_LINKDISPBIT),  0,  cppu::UnoType<awt::XBitmap>::get(),   beans::PropertyAttribute::READONLY, 0 },
      54           0 :         {OUString(SC_UNO_LINKDISPNAME), 0,  cppu::UnoType<OUString>::get(),                beans::PropertyAttribute::READONLY, 0 },
      55             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      56           0 :     };
      57           0 :     return aLinkTargetMap_Impl;
      58             : }
      59             : 
      60             : // service for ScLinkTargetTypeObj is not defined
      61             : //  must not support document::LinkTarget because the target type cannot be used as a target
      62             : 
      63           0 : SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypesObj, "ScLinkTargetTypesObj", "com.sun.star.document.LinkTargets" )
      64           0 : SC_SIMPLE_SERVICE_INFO( ScLinkTargetTypeObj,  "ScLinkTargetTypeObj",  "com.sun.star.document.LinkTargetSupplier" )
      65           0 : SC_SIMPLE_SERVICE_INFO( ScLinkTargetsObj,     "ScLinkTargetsObj",     "com.sun.star.document.LinkTargets" )
      66             : 
      67           1 : ScLinkTargetTypesObj::ScLinkTargetTypesObj(ScDocShell* pDocSh) :
      68           1 :     pDocShell( pDocSh )
      69             : {
      70           1 :     pDocShell->GetDocument().AddUnoObject(*this);
      71             : 
      72           4 :     for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
      73           3 :         aNames[i] = ScResId( nTypeResIds[i] );
      74           1 : }
      75             : 
      76           3 : ScLinkTargetTypesObj::~ScLinkTargetTypesObj()
      77             : {
      78           1 :     SolarMutexGuard g;
      79             : 
      80           1 :     if (pDocShell)
      81           1 :         pDocShell->GetDocument().RemoveUnoObject(*this);
      82           2 : }
      83             : 
      84           3 : void ScLinkTargetTypesObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      85             : {
      86           3 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
      87           3 :     if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
      88           0 :         pDocShell = NULL;       // document gone
      89           3 : }
      90             : 
      91             : // container::XNameAccess
      92             : 
      93           0 : uno::Any SAL_CALL ScLinkTargetTypesObj::getByName(const OUString& aName)
      94             :         throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
      95             : {
      96           0 :     if (pDocShell)
      97             :     {
      98           0 :         OUString aNameStr(aName);
      99           0 :         for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
     100           0 :             if ( aNames[i] == aNameStr )
     101           0 :                 return uno::makeAny(uno::Reference< beans::XPropertySet >(new ScLinkTargetTypeObj( pDocShell, i )));
     102             :     }
     103             : 
     104           0 :     throw container::NoSuchElementException();
     105             : }
     106             : 
     107           1 : uno::Sequence<OUString> SAL_CALL ScLinkTargetTypesObj::getElementNames() throw( uno::RuntimeException, std::exception )
     108             : {
     109           1 :     uno::Sequence<OUString> aRet(SC_LINKTARGETTYPE_COUNT);
     110           1 :     OUString* pArray = aRet.getArray();
     111           4 :     for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
     112           3 :         pArray[i] = aNames[i];
     113           1 :     return aRet;
     114             : }
     115             : 
     116           0 : sal_Bool SAL_CALL ScLinkTargetTypesObj::hasByName(const OUString& aName) throw( uno::RuntimeException, std::exception )
     117             : {
     118           0 :     OUString aNameStr = aName;
     119           0 :     for (sal_uInt16 i=0; i<SC_LINKTARGETTYPE_COUNT; i++)
     120           0 :         if ( aNames[i] == aNameStr )
     121           0 :             return sal_True;
     122           0 :     return false;
     123             : }
     124             : 
     125             : // container::XElementAccess
     126             : 
     127           0 : uno::Type SAL_CALL ScLinkTargetTypesObj::getElementType() throw( uno::RuntimeException, std::exception )
     128             : {
     129           0 :     return cppu::UnoType<beans::XPropertySet>::get();
     130             : }
     131             : 
     132           0 : sal_Bool SAL_CALL ScLinkTargetTypesObj::hasElements() throw( uno::RuntimeException, std::exception )
     133             : {
     134           0 :     return sal_True;
     135             : }
     136             : 
     137           0 : ScLinkTargetTypeObj::ScLinkTargetTypeObj(ScDocShell* pDocSh, sal_uInt16 nT) :
     138             :     pDocShell( pDocSh ),
     139           0 :     nType( nT )
     140             : {
     141           0 :     pDocShell->GetDocument().AddUnoObject(*this);
     142           0 :     aName = ScResId( nTypeResIds[nType] );    //! on demand?
     143           0 : }
     144             : 
     145           0 : ScLinkTargetTypeObj::~ScLinkTargetTypeObj()
     146             : {
     147           0 :     SolarMutexGuard g;
     148             : 
     149           0 :     if (pDocShell)
     150           0 :         pDocShell->GetDocument().RemoveUnoObject(*this);
     151           0 : }
     152             : 
     153           0 : void ScLinkTargetTypeObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
     154             : {
     155           0 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     156           0 :     if ( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DYING )
     157           0 :         pDocShell = NULL;       // document gone
     158           0 : }
     159             : 
     160             : // document::XLinkTargetSupplier
     161             : 
     162           0 : uno::Reference< container::XNameAccess > SAL_CALL  ScLinkTargetTypeObj::getLinks() throw( uno::RuntimeException, std::exception )
     163             : {
     164           0 :     uno::Reference< container::XNameAccess >  xCollection;
     165             : 
     166           0 :     if ( pDocShell )
     167             :     {
     168           0 :         switch ( nType )
     169             :         {
     170             :             case SC_LINKTARGETTYPE_SHEET:
     171           0 :                 xCollection.set(new ScTableSheetsObj(pDocShell));
     172           0 :                 break;
     173             :             case SC_LINKTARGETTYPE_RANGENAME:
     174           0 :                 xCollection.set(new ScGlobalNamedRangesObj(pDocShell));
     175           0 :                 break;
     176             :             case SC_LINKTARGETTYPE_DBAREA:
     177           0 :                 xCollection.set(new ScDatabaseRangesObj(pDocShell));
     178           0 :                 break;
     179             :             default:
     180             :                 OSL_FAIL("invalid type");
     181             :         }
     182             :     }
     183             : 
     184             :     //  wrap collection in ScLinkTargetsObj because service document::LinkTargets requires
     185             :     //  beans::XPropertySet as ElementType in container::XNameAccess.
     186           0 :     if ( xCollection.is() )
     187           0 :         return new ScLinkTargetsObj( xCollection );
     188           0 :     return NULL;
     189             : }
     190             : 
     191             : // beans::XPropertySet
     192             : 
     193           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL  ScLinkTargetTypeObj::getPropertySetInfo() throw( uno::RuntimeException, std::exception )
     194             : {
     195           0 :     SolarMutexGuard aGuard;
     196           0 :     static uno::Reference< beans::XPropertySetInfo >  aRef(new SfxItemPropertySetInfo( lcl_GetLinkTargetMap() ));
     197           0 :     return aRef;
     198             : }
     199             : 
     200           0 : void SAL_CALL ScLinkTargetTypeObj::setPropertyValue(const OUString& /* aPropertyName */,
     201             :             const uno::Any& /* aValue */)
     202             :         throw(  beans::UnknownPropertyException,
     203             :                 beans::PropertyVetoException,
     204             :                 lang::IllegalArgumentException,
     205             :                 lang::WrappedTargetException,
     206             :                  uno::RuntimeException, std::exception )
     207             : {
     208             :     //  everything is read-only
     209             :     //! exception?
     210           0 : }
     211             : 
     212           0 : void ScLinkTargetTypeObj::SetLinkTargetBitmap( uno::Any& rRet, sal_uInt16 nType )
     213             : {
     214           0 :     sal_uInt16 nImgId = 0;
     215           0 :     switch ( nType )
     216             :     {
     217             :         case SC_LINKTARGETTYPE_SHEET:
     218           0 :             nImgId = SC_CONTENT_TABLE;
     219           0 :             break;
     220             :         case SC_LINKTARGETTYPE_RANGENAME:
     221           0 :             nImgId = SC_CONTENT_RANGENAME;
     222           0 :             break;
     223             :         case SC_LINKTARGETTYPE_DBAREA:
     224           0 :             nImgId = SC_CONTENT_DBAREA;
     225           0 :             break;
     226             :     }
     227           0 :     if (nImgId)
     228             :     {
     229           0 :         ImageList aEntryImages( ScResId( RID_IMAGELIST_NAVCONT ) );
     230           0 :         const Image& rImage = aEntryImages.GetImage( nImgId );
     231           0 :         rRet <<= uno::Reference< awt::XBitmap > (VCLUnoHelper::CreateBitmap( rImage.GetBitmapEx() ));
     232             :     }
     233           0 : }
     234             : 
     235           0 : uno::Any SAL_CALL ScLinkTargetTypeObj::getPropertyValue(const OUString& PropertyName)
     236             :         throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     237             : {
     238           0 :     uno::Any aRet;
     239           0 :     OUString aNameStr(PropertyName);
     240           0 :     if ( aNameStr == SC_UNO_LINKDISPBIT )
     241           0 :         SetLinkTargetBitmap( aRet, nType );
     242           0 :     else if ( aNameStr == SC_UNO_LINKDISPNAME )
     243           0 :         aRet <<= OUString( aName );
     244             : 
     245           0 :     return aRet;
     246             : }
     247             : 
     248           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScLinkTargetTypeObj )
     249             : 
     250           0 : ScLinkTargetsObj::ScLinkTargetsObj( const uno::Reference< container::XNameAccess > & rColl ) :
     251           0 :     xCollection( rColl )
     252             : {
     253             :     OSL_ENSURE( xCollection.is(), "ScLinkTargetsObj: NULL" );
     254           0 : }
     255             : 
     256           0 : ScLinkTargetsObj::~ScLinkTargetsObj()
     257             : {
     258           0 : }
     259             : 
     260             : // container::XNameAccess
     261             : 
     262           0 : uno::Any SAL_CALL ScLinkTargetsObj::getByName(const OUString& aName)
     263             :         throw( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception )
     264             : {
     265           0 :     uno::Reference< beans::XPropertySet >  xProp( ScUnoHelpFunctions::AnyToInterface( xCollection->getByName(aName) ), uno::UNO_QUERY );
     266           0 :     if (xProp.is())
     267           0 :         return uno::makeAny(xProp);
     268             : 
     269           0 :     throw container::NoSuchElementException();
     270             : //    return uno::Any();
     271             : }
     272             : 
     273           0 : uno::Sequence<OUString> SAL_CALL ScLinkTargetsObj::getElementNames() throw( uno::RuntimeException, std::exception )
     274             : {
     275           0 :     return xCollection->getElementNames();
     276             : }
     277             : 
     278           0 : sal_Bool SAL_CALL ScLinkTargetsObj::hasByName(const OUString& aName) throw( uno::RuntimeException, std::exception )
     279             : {
     280           0 :     return xCollection->hasByName(aName);
     281             : }
     282             : 
     283             : // container::XElementAccess
     284             : 
     285           0 : uno::Type SAL_CALL ScLinkTargetsObj::getElementType() throw( uno::RuntimeException, std::exception )
     286             : {
     287           0 :     return cppu::UnoType<beans::XPropertySet>::get();
     288             : }
     289             : 
     290           0 : sal_Bool SAL_CALL ScLinkTargetsObj::hasElements() throw( uno::RuntimeException, std::exception )
     291             : {
     292           0 :     return xCollection->hasElements();
     293         156 : }
     294             : 
     295             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11