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

Generated by: LCOV version 1.10