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

Generated by: LCOV version 1.10