LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - defltuno.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 178 0.0 %
Date: 2014-04-14 Functions: 0 21 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 <editeng/memberids.hrc>
      21             : #include <svl/smplhint.hxx>
      22             : #include <svl/itemprop.hxx>
      23             : #include <svx/unomid.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <i18nlangtag/languagetag.hxx>
      26             : 
      27             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      28             : 
      29             : #include "scitems.hxx"
      30             : #include "defltuno.hxx"
      31             : #include "miscuno.hxx"
      32             : #include "docsh.hxx"
      33             : #include "docpool.hxx"
      34             : #include "unonames.hxx"
      35             : #include "docoptio.hxx"
      36             : 
      37             : #include <limits>
      38             : 
      39             : using namespace ::com::sun::star;
      40             : 
      41           0 : static const SfxItemPropertyMapEntry* lcl_GetDocDefaultsMap()
      42             : {
      43             :     static const SfxItemPropertyMapEntry aDocDefaultsMap_Impl[] =
      44             :     {
      45           0 :         {OUString(SC_UNONAME_CFCHARS),  ATTR_FONT,          getCppuType((sal_Int16*)0),        0, MID_FONT_CHAR_SET },
      46           0 :         {OUString(SC_UNO_CJK_CFCHARS),  ATTR_CJK_FONT,      getCppuType((sal_Int16*)0),        0, MID_FONT_CHAR_SET },
      47           0 :         {OUString(SC_UNO_CTL_CFCHARS),  ATTR_CTL_FONT,      getCppuType((sal_Int16*)0),        0, MID_FONT_CHAR_SET },
      48           0 :         {OUString(SC_UNONAME_CFFAMIL),  ATTR_FONT,          getCppuType((sal_Int16*)0),        0, MID_FONT_FAMILY },
      49           0 :         {OUString(SC_UNO_CJK_CFFAMIL),  ATTR_CJK_FONT,      getCppuType((sal_Int16*)0),        0, MID_FONT_FAMILY },
      50           0 :         {OUString(SC_UNO_CTL_CFFAMIL),  ATTR_CTL_FONT,      getCppuType((sal_Int16*)0),        0, MID_FONT_FAMILY },
      51           0 :         {OUString(SC_UNONAME_CFNAME),   ATTR_FONT,          getCppuType((OUString*)0),    0, MID_FONT_FAMILY_NAME },
      52           0 :         {OUString(SC_UNO_CJK_CFNAME),   ATTR_CJK_FONT,      getCppuType((OUString*)0),    0, MID_FONT_FAMILY_NAME },
      53           0 :         {OUString(SC_UNO_CTL_CFNAME),   ATTR_CTL_FONT,      getCppuType((OUString*)0),    0, MID_FONT_FAMILY_NAME },
      54           0 :         {OUString(SC_UNONAME_CFPITCH),  ATTR_FONT,          getCppuType((sal_Int16*)0),        0, MID_FONT_PITCH },
      55           0 :         {OUString(SC_UNO_CJK_CFPITCH),  ATTR_CJK_FONT,      getCppuType((sal_Int16*)0),        0, MID_FONT_PITCH },
      56           0 :         {OUString(SC_UNO_CTL_CFPITCH),  ATTR_CTL_FONT,      getCppuType((sal_Int16*)0),        0, MID_FONT_PITCH },
      57           0 :         {OUString(SC_UNONAME_CFSTYLE),  ATTR_FONT,          getCppuType((OUString*)0),    0, MID_FONT_STYLE_NAME },
      58           0 :         {OUString(SC_UNO_CJK_CFSTYLE),  ATTR_CJK_FONT,      getCppuType((OUString*)0),    0, MID_FONT_STYLE_NAME },
      59           0 :         {OUString(SC_UNO_CTL_CFSTYLE),  ATTR_CTL_FONT,      getCppuType((OUString*)0),    0, MID_FONT_STYLE_NAME },
      60           0 :         {OUString(SC_UNONAME_CLOCAL),   ATTR_FONT_LANGUAGE, getCppuType((lang::Locale*)0),     0, MID_LANG_LOCALE },
      61           0 :         {OUString(SC_UNO_CJK_CLOCAL),   ATTR_CJK_FONT_LANGUAGE, getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
      62           0 :         {OUString(SC_UNO_CTL_CLOCAL),   ATTR_CTL_FONT_LANGUAGE, getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE },
      63           0 :         {OUString(SC_UNO_STANDARDDEC),              0,      getCppuType((sal_Int16*)0),        0, 0 },
      64           0 :         {OUString(SC_UNO_TABSTOPDIS),               0,      getCppuType((sal_Int32*)0),        0, 0 },
      65             :         { OUString(), 0, css::uno::Type(), 0, 0 }
      66           0 :     };
      67           0 :     return aDocDefaultsMap_Impl;
      68             : }
      69             : 
      70             : using sc::HMMToTwips;
      71             : using sc::TwipsToHMM;
      72             : using sc::TwipsToEvenHMM;
      73             : 
      74           0 : SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" )
      75             : 
      76           0 : ScDocDefaultsObj::ScDocDefaultsObj(ScDocShell* pDocSh) :
      77             :     pDocShell( pDocSh ),
      78           0 :     aPropertyMap(lcl_GetDocDefaultsMap())
      79             : {
      80           0 :     pDocShell->GetDocument()->AddUnoObject(*this);
      81           0 : }
      82             : 
      83           0 : ScDocDefaultsObj::~ScDocDefaultsObj()
      84             : {
      85           0 :     if (pDocShell)
      86           0 :         pDocShell->GetDocument()->RemoveUnoObject(*this);
      87           0 : }
      88             : 
      89           0 : void ScDocDefaultsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
      90             : {
      91           0 :     if ( rHint.ISA( SfxSimpleHint ) &&
      92           0 :             ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
      93             :     {
      94           0 :         pDocShell = NULL;       // document gone
      95             :     }
      96           0 : }
      97             : 
      98           0 : void ScDocDefaultsObj::ItemsChanged()
      99             : {
     100           0 :     if (pDocShell)
     101             :     {
     102             :         //! if not in XML import, adjust row heights
     103             : 
     104           0 :         pDocShell->PostPaint(ScRange(0, 0, 0, MAXCOL, MAXROW, MAXTAB), PAINT_GRID);
     105             :     }
     106           0 : }
     107             : 
     108             : // XPropertySet
     109             : 
     110           0 : uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo()
     111             :                                                         throw(uno::RuntimeException, std::exception)
     112             : {
     113           0 :     SolarMutexGuard aGuard;
     114             :     static uno::Reference<beans::XPropertySetInfo> aRef = new SfxItemPropertySetInfo(
     115           0 :                                                                         aPropertyMap );
     116           0 :     return aRef;
     117             : }
     118             : 
     119           0 : void SAL_CALL ScDocDefaultsObj::setPropertyValue(
     120             :                         const OUString& aPropertyName, const uno::Any& aValue )
     121             :                 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
     122             :                         lang::IllegalArgumentException, lang::WrappedTargetException,
     123             :                         uno::RuntimeException, std::exception)
     124             : {
     125           0 :     SolarMutexGuard aGuard;
     126             : 
     127           0 :     if ( !pDocShell )
     128           0 :         throw uno::RuntimeException();
     129             : 
     130           0 :     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
     131           0 :     if ( !pEntry )
     132           0 :         throw beans::UnknownPropertyException();
     133           0 :     if(!pEntry->nWID)
     134             :     {
     135           0 :         if(aPropertyName.equalsAscii(SC_UNO_STANDARDDEC) )
     136             :         {
     137           0 :             ScDocument* pDoc = pDocShell->GetDocument();
     138           0 :             if (pDoc)
     139             :             {
     140           0 :                 ScDocOptions aDocOpt(pDoc->GetDocOptions());
     141           0 :                 sal_Int16 nValue = 0;
     142           0 :                 if (aValue >>= nValue)
     143             :                 {
     144           0 :                     aDocOpt.SetStdPrecision(static_cast<sal_uInt16> (nValue));
     145           0 :                     pDoc->SetDocOptions(aDocOpt);
     146           0 :                 }
     147             :             }
     148             :             else
     149           0 :                 throw uno::RuntimeException();
     150             :         }
     151           0 :         else if (aPropertyName.equalsAscii(SC_UNO_TABSTOPDIS) )
     152             :         {
     153           0 :             ScDocument* pDoc = pDocShell->GetDocument();
     154           0 :             if (pDoc)
     155             :             {
     156           0 :                 ScDocOptions aDocOpt(pDoc->GetDocOptions());
     157           0 :                 sal_Int32 nValue = 0;
     158           0 :                 if (aValue >>= nValue)
     159             :                 {
     160           0 :                     aDocOpt.SetTabDistance(static_cast<sal_uInt16>(HMMToTwips(nValue)));
     161           0 :                     pDoc->SetDocOptions(aDocOpt);
     162           0 :                 }
     163             :             }
     164             :             else
     165           0 :                 throw uno::RuntimeException();
     166             :         }
     167             :     }
     168           0 :     else if ( pEntry->nWID == ATTR_FONT_LANGUAGE ||
     169           0 :               pEntry->nWID == ATTR_CJK_FONT_LANGUAGE ||
     170           0 :               pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
     171             :     {
     172             :         //  for getPropertyValue the PoolDefaults are sufficient,
     173             :         //  but setPropertyValue has to be handled differently
     174             : 
     175           0 :         lang::Locale aLocale;
     176           0 :         if ( aValue >>= aLocale )
     177             :         {
     178             :             LanguageType eNew;
     179           0 :             if (!aLocale.Language.isEmpty() || !aLocale.Country.isEmpty())
     180           0 :                 eNew = LanguageTag::convertToLanguageType( aLocale, false);
     181             :             else
     182           0 :                 eNew = LANGUAGE_NONE;
     183             : 
     184           0 :             ScDocument* pDoc = pDocShell->GetDocument();
     185             :             LanguageType eLatin, eCjk, eCtl;
     186           0 :             pDoc->GetLanguage( eLatin, eCjk, eCtl );
     187             : 
     188           0 :             if ( pEntry->nWID == ATTR_CJK_FONT_LANGUAGE )
     189           0 :                 eCjk = eNew;
     190           0 :             else if ( pEntry->nWID == ATTR_CTL_FONT_LANGUAGE )
     191           0 :                 eCtl = eNew;
     192             :             else
     193           0 :                 eLatin = eNew;
     194             : 
     195           0 :             pDoc->SetLanguage( eLatin, eCjk, eCtl );
     196           0 :         }
     197             :     }
     198             :     else
     199             :     {
     200           0 :         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     201           0 :         SfxPoolItem* pNewItem = pPool->GetDefaultItem(pEntry->nWID).Clone();
     202             : 
     203           0 :         if( !pNewItem->PutValue( aValue, pEntry->nMemberId ) )
     204           0 :             throw lang::IllegalArgumentException();
     205             : 
     206           0 :         pPool->SetPoolDefaultItem( *pNewItem );
     207           0 :         delete pNewItem;    // copied in SetPoolDefaultItem
     208             : 
     209           0 :         ItemsChanged();
     210           0 :     }
     211           0 : }
     212             : 
     213           0 : uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const OUString& aPropertyName )
     214             :                 throw(beans::UnknownPropertyException, lang::WrappedTargetException,
     215             :                         uno::RuntimeException, std::exception)
     216             : {
     217             :     //  use pool default if set
     218             : 
     219           0 :     SolarMutexGuard aGuard;
     220             : 
     221           0 :     if ( !pDocShell )
     222           0 :         throw uno::RuntimeException();
     223             : 
     224           0 :     uno::Any aRet;
     225           0 :     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
     226           0 :     if ( !pEntry )
     227           0 :         throw beans::UnknownPropertyException();
     228             : 
     229           0 :     if (!pEntry->nWID)
     230             :     {
     231           0 :         if(aPropertyName.equalsAscii(SC_UNO_STANDARDDEC) )
     232             :         {
     233           0 :             ScDocument* pDoc = pDocShell->GetDocument();
     234           0 :             if (pDoc)
     235             :             {
     236           0 :                 const ScDocOptions& aDocOpt = pDoc->GetDocOptions();
     237           0 :                 sal_uInt16 nPrec = aDocOpt.GetStdPrecision();
     238             :                 // the max value of unsigned 16-bit integer is used as the flag
     239             :                 // value for unlimited precision, c.f.
     240             :                 // SvNumberFormatter::UNLIMITED_PRECISION.
     241           0 :                 if (nPrec <= ::std::numeric_limits<sal_Int16>::max())
     242           0 :                     aRet <<= static_cast<sal_Int16> (nPrec);
     243             :             }
     244             :             else
     245           0 :                 throw uno::RuntimeException();
     246             :         }
     247           0 :         else if (aPropertyName.equalsAscii(SC_UNO_TABSTOPDIS) )
     248             :         {
     249           0 :             ScDocument* pDoc = pDocShell->GetDocument();
     250           0 :             if (pDoc)
     251             :             {
     252           0 :                 const ScDocOptions& aDocOpt = pDoc->GetDocOptions();
     253           0 :                 sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance()));
     254           0 :                 aRet <<= nValue;
     255             :             }
     256             :             else
     257           0 :                 throw uno::RuntimeException();
     258             :         }
     259             :     }
     260             :     else
     261             :     {
     262           0 :         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     263           0 :         const SfxPoolItem& rItem = pPool->GetDefaultItem( pEntry->nWID );
     264           0 :         rItem.QueryValue( aRet, pEntry->nMemberId );
     265             :     }
     266           0 :     return aRet;
     267             : }
     268             : 
     269           0 : SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDocDefaultsObj )
     270             : 
     271             : // XPropertyState
     272             : 
     273           0 : beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const OUString& aPropertyName )
     274             :                                 throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     275             : {
     276           0 :     SolarMutexGuard aGuard;
     277             : 
     278           0 :     if ( !pDocShell )
     279           0 :         throw uno::RuntimeException();
     280             : 
     281           0 :     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
     282           0 :     if ( !pEntry )
     283           0 :         throw beans::UnknownPropertyException();
     284             : 
     285           0 :     beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE;
     286             : 
     287           0 :     sal_uInt16 nWID = pEntry->nWID;
     288           0 :     if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID )
     289             :     {
     290             :         //  static default for font is system-dependent,
     291             :         //  so font default is always treated as "direct value".
     292             : 
     293           0 :         eRet = beans::PropertyState_DIRECT_VALUE;
     294             :     }
     295             :     else
     296             :     {
     297             :         //  check if pool default is set
     298             : 
     299           0 :         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     300           0 :         if ( pPool->GetPoolDefaultItem( nWID ) != NULL )
     301           0 :             eRet = beans::PropertyState_DIRECT_VALUE;
     302             :     }
     303             : 
     304           0 :     return eRet;
     305             : }
     306             : 
     307           0 : uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates(
     308             :                             const uno::Sequence<OUString>& aPropertyNames )
     309             :                     throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     310             : {
     311             :     //  the simple way: call getPropertyState
     312             : 
     313           0 :     SolarMutexGuard aGuard;
     314           0 :     const OUString* pNames = aPropertyNames.getConstArray();
     315           0 :     uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength());
     316           0 :     beans::PropertyState* pStates = aRet.getArray();
     317           0 :     for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++)
     318           0 :         pStates[i] = getPropertyState(pNames[i]);
     319           0 :     return aRet;
     320             : }
     321             : 
     322           0 : void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const OUString& aPropertyName )
     323             :                             throw(beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     324             : {
     325           0 :     SolarMutexGuard aGuard;
     326             : 
     327           0 :     if ( !pDocShell )
     328           0 :         throw uno::RuntimeException();
     329             : 
     330           0 :     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
     331           0 :     if ( !pEntry )
     332           0 :         throw beans::UnknownPropertyException();
     333             : 
     334           0 :     if (pEntry->nWID)
     335             :     {
     336           0 :         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     337           0 :         pPool->ResetPoolDefaultItem( pEntry->nWID );
     338             : 
     339           0 :         ItemsChanged();
     340           0 :     }
     341           0 : }
     342             : 
     343           0 : uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const OUString& aPropertyName )
     344             :                             throw(beans::UnknownPropertyException, lang::WrappedTargetException,
     345             :                                     uno::RuntimeException, std::exception)
     346             : {
     347             :     //  always use static default
     348             : 
     349           0 :     SolarMutexGuard aGuard;
     350             : 
     351           0 :     if ( !pDocShell )
     352           0 :         throw uno::RuntimeException();
     353             : 
     354           0 :     const SfxItemPropertySimpleEntry* pEntry = aPropertyMap.getByName( aPropertyName );
     355           0 :     if ( !pEntry )
     356           0 :         throw beans::UnknownPropertyException();
     357             : 
     358           0 :     uno::Any aRet;
     359           0 :     if (pEntry->nWID)
     360             :     {
     361           0 :         ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool();
     362           0 :         const SfxPoolItem* pItem = pPool->GetItem2( pEntry->nWID, SFX_ITEMS_DEFAULT );
     363           0 :         if (pItem)
     364           0 :             pItem->QueryValue( aRet, pEntry->nMemberId );
     365             :     }
     366           0 :     return aRet;
     367             : }
     368             : 
     369             : 
     370             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10