LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/config - compatibility.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 157 319 49.2 %
Date: 2012-12-27 Functions: 38 64 59.4 %
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 <unotools/compatibility.hxx>
      21             : #include <unotools/configmgr.hxx>
      22             : #include <unotools/configitem.hxx>
      23             : #include <unotools/syslocale.hxx>
      24             : #include <tools/debug.hxx>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/uno/Sequence.hxx>
      27             : 
      28             : #include <vector>
      29             : 
      30             : #include <itemholder1.hxx>
      31             : 
      32             : #include <algorithm>
      33             : 
      34             : //_________________________________________________________________________________________________________________
      35             : //  namespaces
      36             : //_________________________________________________________________________________________________________________
      37             : 
      38             : using namespace ::std;
      39             : using namespace ::utl;
      40             : using namespace ::rtl;
      41             : using namespace ::osl;
      42             : using namespace ::com::sun::star::uno;
      43             : using namespace ::com::sun::star::beans;
      44             : 
      45             : #define ROOTNODE_OPTIONS        OUString( RTL_CONSTASCII_USTRINGPARAM( "Office.Compatibility/" ) )
      46             : #define PATHDELIMITER           OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) )
      47             : #define SETNODE_ALLFILEFORMATS  OUString( RTL_CONSTASCII_USTRINGPARAM( "AllFileFormats" ) )
      48             : 
      49             : #define PROPERTYNAME_NAME               COMPATIBILITY_PROPERTYNAME_NAME
      50             : #define PROPERTYNAME_MODULE             COMPATIBILITY_PROPERTYNAME_MODULE
      51             : #define PROPERTYNAME_USEPRTMETRICS      COMPATIBILITY_PROPERTYNAME_USEPRTMETRICS
      52             : #define PROPERTYNAME_ADDSPACING         COMPATIBILITY_PROPERTYNAME_ADDSPACING
      53             : #define PROPERTYNAME_ADDSPACINGATPAGES  COMPATIBILITY_PROPERTYNAME_ADDSPACINGATPAGES
      54             : #define PROPERTYNAME_USEOURTABSTOPS     COMPATIBILITY_PROPERTYNAME_USEOURTABSTOPS
      55             : #define PROPERTYNAME_NOEXTLEADING       COMPATIBILITY_PROPERTYNAME_NOEXTLEADING
      56             : #define PROPERTYNAME_USELINESPACING     COMPATIBILITY_PROPERTYNAME_USELINESPACING
      57             : #define PROPERTYNAME_ADDTABLESPACING    COMPATIBILITY_PROPERTYNAME_ADDTABLESPACING
      58             : #define PROPERTYNAME_USEOBJPOS          COMPATIBILITY_PROPERTYNAME_USEOBJECTPOSITIONING
      59             : #define PROPERTYNAME_USEOURTEXTWRAP     COMPATIBILITY_PROPERTYNAME_USEOURTEXTWRAPPING
      60             : #define PROPERTYNAME_CONSIDERWRAPSTYLE  COMPATIBILITY_PROPERTYNAME_CONSIDERWRAPPINGSTYLE
      61             : #define PROPERTYNAME_EXPANDWORDSPACE    COMPATIBILITY_PROPERTYNAME_EXPANDWORDSPACE
      62             : 
      63             : #define PROPERTYCOUNT                   13
      64             : 
      65             : #define OFFSET_NAME                     0
      66             : #define OFFSET_MODULE                   1
      67             : #define OFFSET_USEPRTMETRICS            2
      68             : #define OFFSET_ADDSPACING               3
      69             : #define OFFSET_ADDSPACINGATPAGES        4
      70             : #define OFFSET_USEOURTABSTOPS           5
      71             : #define OFFSET_NOEXTLEADING             6
      72             : #define OFFSET_USELINESPACING           7
      73             : #define OFFSET_ADDTABLESPACING          8
      74             : #define OFFSET_USEOBJPOS                9
      75             : #define OFFSET_USEOURTEXTWRAPPING       10
      76             : #define OFFSET_CONSIDERWRAPPINGSTYLE    11
      77             : #define OFFSET_EXPANDWORDSPACE          12
      78             : 
      79             : //_________________________________________________________________________________________________________________
      80             : //  private declarations!
      81             : //_________________________________________________________________________________________________________________
      82             : 
      83             : /*-****************************************************************************************************************
      84             :     @descr  struct to hold information about one compatibility entry
      85             : ****************************************************************************************************************-*/
      86          90 : struct SvtCompatibilityEntry
      87             : {
      88             :     public:
      89          20 :         SvtCompatibilityEntry() :
      90             :             bUsePrtMetrics( false ), bAddSpacing( false ),
      91             :             bAddSpacingAtPages( false ), bUseOurTabStops( false ),
      92             :             bNoExtLeading( false ), bUseLineSpacing( false ),
      93             :             bAddTableSpacing( false ), bUseObjPos( false ),
      94             :             bUseOurTextWrapping( false ), bConsiderWrappingStyle( false ),
      95          20 :             bExpandWordSpace( true ) {}
      96           0 :         SvtCompatibilityEntry(
      97             :             const OUString& _rName, const OUString& _rNewModule ) :
      98             :                 sName( _rName ), sModule( _rNewModule ),
      99             :                 bUsePrtMetrics( false ), bAddSpacing( false ),
     100             :                 bAddSpacingAtPages( false ), bUseOurTabStops( false ),
     101             :                 bNoExtLeading( false ), bUseLineSpacing( false ),
     102             :                 bAddTableSpacing( false ), bUseObjPos( false ),
     103             :                 bUseOurTextWrapping( false ), bConsiderWrappingStyle( false ),
     104           0 :                 bExpandWordSpace( true ) {}
     105             : 
     106           0 :         inline void     SetUsePrtMetrics( bool _bSet ) { bUsePrtMetrics = _bSet; }
     107           0 :         inline void     SetAddSpacing( bool _bSet ) { bAddSpacing = _bSet; }
     108           0 :         inline void     SetAddSpacingAtPages( bool _bSet ) { bAddSpacingAtPages = _bSet; }
     109           0 :         inline void     SetUseOurTabStops( bool _bSet ) { bUseOurTabStops = _bSet; }
     110           0 :         inline void     SetNoExtLeading( bool _bSet ) { bNoExtLeading = _bSet; }
     111           0 :         inline void     SetUseLineSpacing( bool _bSet ) { bUseLineSpacing = _bSet; }
     112           0 :         inline void     SetAddTableSpacing( bool _bSet ) { bAddTableSpacing = _bSet; }
     113           0 :         inline void     SetUseObjPos( bool _bSet ) { bUseObjPos = _bSet; }
     114           0 :         inline void     SetUseOurTextWrapping( bool _bSet ) { bUseOurTextWrapping = _bSet; }
     115           0 :         inline void     SetConsiderWrappingStyle( bool _bSet ) { bConsiderWrappingStyle = _bSet; }
     116           0 :         inline void     SetExpandWordSpace( bool _bSet ) { bExpandWordSpace = _bSet; }
     117             : 
     118             :     public:
     119             :         OUString    sName;
     120             :         OUString    sModule;
     121             :         bool        bUsePrtMetrics;
     122             :         bool        bAddSpacing;
     123             :         bool        bAddSpacingAtPages;
     124             :         bool        bUseOurTabStops;
     125             :         bool        bNoExtLeading;
     126             :         bool        bUseLineSpacing;
     127             :         bool        bAddTableSpacing;
     128             :         bool        bUseObjPos;
     129             :         bool        bUseOurTextWrapping;
     130             :         bool        bConsiderWrappingStyle;
     131             :         bool        bExpandWordSpace;
     132             : };
     133             : 
     134             : /*-****************************************************************************************************************
     135             :     @descr  support simple menu structures and operations on it
     136             : ****************************************************************************************************************-*/
     137          20 : class SvtCompatibility
     138             : {
     139             :     public:
     140             :         //---------------------------------------------------------------------------------------------------------
     141             :         // append one entry
     142          20 :         void AppendEntry( const SvtCompatibilityEntry& rEntry )
     143             :         {
     144          20 :             lEntries.push_back( rEntry );
     145          20 :         }
     146             : 
     147             :         //---------------------------------------------------------------------------------------------------------
     148             :         // the only way to free memory!
     149           0 :         void Clear()
     150             :         {
     151           0 :             lEntries.clear();
     152           0 :         }
     153             : 
     154             :         //---------------------------------------------------------------------------------------------------------
     155             :         // convert internal list to external format
     156           0 :         Sequence< Sequence< PropertyValue > > GetList() const
     157             :         {
     158           0 :             sal_Int32 nCount = (sal_Int32)lEntries.size();
     159           0 :             sal_Int32 nStep = 0;
     160           0 :             Sequence< PropertyValue > lProperties( PROPERTYCOUNT );
     161           0 :             Sequence< Sequence< PropertyValue > > lResult( nCount );
     162           0 :             const vector< SvtCompatibilityEntry >* pList = &lEntries;
     163             : 
     164           0 :             lProperties[ OFFSET_NAME ].Name = PROPERTYNAME_NAME;
     165           0 :             lProperties[ OFFSET_MODULE ].Name = PROPERTYNAME_MODULE;
     166           0 :             lProperties[ OFFSET_USEPRTMETRICS ].Name = PROPERTYNAME_USEPRTMETRICS;
     167           0 :             lProperties[ OFFSET_ADDSPACING ].Name = PROPERTYNAME_ADDSPACING;
     168           0 :             lProperties[ OFFSET_ADDSPACINGATPAGES ].Name = PROPERTYNAME_ADDSPACINGATPAGES;
     169           0 :             lProperties[ OFFSET_USEOURTABSTOPS ].Name = PROPERTYNAME_USEOURTABSTOPS;
     170           0 :             lProperties[ OFFSET_NOEXTLEADING ].Name = PROPERTYNAME_NOEXTLEADING;
     171           0 :             lProperties[ OFFSET_USELINESPACING ].Name = PROPERTYNAME_USELINESPACING;
     172           0 :             lProperties[ OFFSET_ADDTABLESPACING ].Name = PROPERTYNAME_ADDTABLESPACING;
     173           0 :             lProperties[ OFFSET_USEOBJPOS ].Name = PROPERTYNAME_USEOBJPOS;
     174           0 :             lProperties[ OFFSET_USEOURTEXTWRAPPING ].Name = PROPERTYNAME_USEOURTEXTWRAP;
     175           0 :             lProperties[ OFFSET_CONSIDERWRAPPINGSTYLE ].Name = PROPERTYNAME_CONSIDERWRAPSTYLE;
     176           0 :             lProperties[ OFFSET_EXPANDWORDSPACE ].Name = PROPERTYNAME_EXPANDWORDSPACE;
     177             : 
     178           0 :             for ( vector< SvtCompatibilityEntry >::const_iterator pItem = pList->begin();
     179           0 :                   pItem != pList->end(); ++pItem )
     180             :             {
     181           0 :                 lProperties[ OFFSET_NAME ].Value <<= pItem->sName;
     182           0 :                 lProperties[ OFFSET_MODULE ].Value <<= pItem->sModule;
     183           0 :                 lProperties[ OFFSET_USEPRTMETRICS ].Value <<= pItem->bUsePrtMetrics;
     184           0 :                 lProperties[ OFFSET_ADDSPACING ].Value <<= pItem->bAddSpacing;
     185           0 :                 lProperties[ OFFSET_ADDSPACINGATPAGES ].Value <<= pItem->bAddSpacingAtPages;
     186           0 :                 lProperties[ OFFSET_USEOURTABSTOPS ].Value <<= pItem->bUseOurTabStops;
     187           0 :                 lProperties[ OFFSET_NOEXTLEADING ].Value <<= pItem->bNoExtLeading;
     188           0 :                 lProperties[ OFFSET_USELINESPACING ].Value <<= pItem->bUseLineSpacing;
     189           0 :                 lProperties[ OFFSET_ADDTABLESPACING ].Value <<= pItem->bAddTableSpacing;
     190           0 :                 lProperties[ OFFSET_USEOBJPOS ].Value <<= pItem->bUseObjPos;
     191           0 :                 lProperties[ OFFSET_USEOURTEXTWRAPPING ].Value <<= pItem->bUseOurTextWrapping;
     192           0 :                 lProperties[ OFFSET_CONSIDERWRAPPINGSTYLE ].Value <<= pItem->bConsiderWrappingStyle;
     193           0 :                 lProperties[ OFFSET_EXPANDWORDSPACE ].Value <<= pItem->bExpandWordSpace;
     194           0 :                 lResult[ nStep ] = lProperties;
     195           0 :                 ++nStep;
     196             :             }
     197             : 
     198           0 :             return lResult;
     199             :         }
     200             : 
     201           0 :         int size() const
     202             :         {
     203           0 :             return lEntries.size();
     204             :         }
     205             : 
     206           0 :         const SvtCompatibilityEntry& operator[]( int i ) const
     207             :         {
     208           0 :             return lEntries[i];
     209             :         }
     210             : 
     211             :     private:
     212             :         vector< SvtCompatibilityEntry > lEntries;
     213             : };
     214             : 
     215             : class SvtCompatibilityOptions_Impl : public ConfigItem
     216             : {
     217             :     //-------------------------------------------------------------------------------------------------------------
     218             :     //  public methods
     219             :     //-------------------------------------------------------------------------------------------------------------
     220             : 
     221             :     public:
     222             : 
     223             :         //---------------------------------------------------------------------------------------------------------
     224             :         //  constructor / destructor
     225             :         //---------------------------------------------------------------------------------------------------------
     226             : 
     227             :          SvtCompatibilityOptions_Impl();
     228             :         ~SvtCompatibilityOptions_Impl();
     229             : 
     230             :         void SetDefault( OUString sName, bool bValue );
     231             : 
     232             :         //---------------------------------------------------------------------------------------------------------
     233             :         //  overloaded methods of baseclass
     234             :         //---------------------------------------------------------------------------------------------------------
     235             : 
     236             :         /*-****************************************************************************************************//**
     237             :             @short      called for notify of configmanager
     238             :             @descr      These method is called from the ConfigManager before application ends or from the
     239             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
     240             :                         internal values.
     241             : 
     242             :             @seealso    baseclass ConfigItem
     243             : 
     244             :             @param      "lPropertyNames" is the list of properties which should be updated.
     245             :             @return     -
     246             : 
     247             :             @onerror    -
     248             :         *//*-*****************************************************************************************************/
     249             : 
     250             :         virtual void Notify( const Sequence< OUString >& lPropertyNames );
     251             : 
     252             :         /*-****************************************************************************************************//**
     253             :             @short      write changes to configuration
     254             :             @descr      These method writes the changed values into the sub tree
     255             :                         and should always called in our destructor to guarantee consistency of config data.
     256             : 
     257             :             @seealso    baseclass ConfigItem
     258             : 
     259             :             @param      -
     260             :             @return     -
     261             : 
     262             :             @onerror    -
     263             :         *//*-*****************************************************************************************************/
     264             : 
     265             :         virtual void Commit();
     266             : 
     267             :         //---------------------------------------------------------------------------------------------------------
     268             :         //  public interface
     269             :         //---------------------------------------------------------------------------------------------------------
     270             : 
     271             :         /*-****************************************************************************************************//**
     272             :             @short      base implementation of public interface for "SvtCompatibilityOptions"!
     273             :             @descr      These class is used as static member of "SvtCompatibilityOptions" ...
     274             :                         => The code exist only for one time and isn't duplicated for every instance!
     275             : 
     276             :             @seealso    -
     277             : 
     278             :             @param      -
     279             :             @return     -
     280             : 
     281             :             @onerror    -
     282             :         *//*-*****************************************************************************************************/
     283             : 
     284             :         void                                    Clear();
     285             :         Sequence< Sequence< PropertyValue > >   GetList() const;
     286             :         void                                    AppendItem( const ::rtl::OUString& _sName,
     287             :                                                             const ::rtl::OUString& _sModule,
     288             :                                                             bool _bUsePrtMetrics,
     289             :                                                             bool _bAddSpacing,
     290             :                                                             bool _bAddSpacingAtPages,
     291             :                                                             bool _bUseOurTabStops,
     292             :                                                             bool _bNoExtLeading,
     293             :                                                             bool _bUseLineSpacing,
     294             :                                                             bool _bAddTableSpacing,
     295             :                                                             bool _bUseObjPos,
     296             :                                                             bool _bUseOurTextWrapping,
     297             :                                                             bool _bConsiderWrappingStyle,
     298             :                                                             bool _bExpandWordSpace );
     299             : 
     300         276 :         inline bool IsUsePrtDevice() const { return m_aDefOptions.bUsePrtMetrics; }
     301         276 :         inline bool IsAddSpacing() const { return m_aDefOptions.bAddSpacing; }
     302         276 :         inline bool IsAddSpacingAtPages() const { return m_aDefOptions.bAddSpacingAtPages; }
     303         276 :         inline bool IsUseOurTabStops() const { return m_aDefOptions.bUseOurTabStops; }
     304         276 :         inline bool IsNoExtLeading() const { return m_aDefOptions.bNoExtLeading; }
     305         276 :         inline bool IsUseLineSpacing() const { return m_aDefOptions.bUseLineSpacing; }
     306         276 :         inline bool IsAddTableSpacing() const { return m_aDefOptions.bAddTableSpacing; }
     307         276 :         inline bool IsUseObjPos() const { return m_aDefOptions.bUseObjPos; }
     308         276 :         inline bool IsUseOurTextWrapping() const { return m_aDefOptions.bUseOurTextWrapping; }
     309         276 :         inline bool IsConsiderWrappingStyle() const { return m_aDefOptions.bConsiderWrappingStyle; }
     310         276 :         inline bool IsExpandWordSpace() const { return m_aDefOptions.bExpandWordSpace; }
     311             : 
     312             :     //-------------------------------------------------------------------------------------------------------------
     313             :     //  private methods
     314             :     //-------------------------------------------------------------------------------------------------------------
     315             : 
     316             :     private:
     317             : 
     318             :         /*-****************************************************************************************************//**
     319             :             @short      return list of key names of our configuration management which represent one module tree
     320             :             @descr      These methods return the current list of key names! We need it to get needed values from our
     321             :                         configuration management and support dynamical menu item lists!
     322             : 
     323             :             @seealso    -
     324             : 
     325             :             @param      -
     326             :             @return     A list of configuration key names is returned.
     327             : 
     328             :             @onerror    -
     329             :         *//*-*****************************************************************************************************/
     330             : 
     331             :         Sequence< OUString > impl_GetPropertyNames( Sequence< OUString >& rItems );
     332             : 
     333             :         /*-****************************************************************************************************//**
     334             :             @short      expand the list for all well known properties to destination
     335             :             @descr      -
     336             :             @attention  -
     337             : 
     338             :             @seealso    method impl_GetPropertyNames()
     339             : 
     340             :             @param      "lSource"      ,   original list
     341             :             @param      "lDestination" ,   destination of operation
     342             :             @return     A list of configuration key names is returned.
     343             : 
     344             :             @onerror    -
     345             :         *//*-*****************************************************************************************************/
     346             : 
     347             :         void impl_ExpandPropertyNames( const Sequence< OUString >& lSource,
     348             :                                              Sequence< OUString >& lDestination );
     349             : 
     350             :     //-------------------------------------------------------------------------------------------------------------
     351             :     //  private member
     352             :     //-------------------------------------------------------------------------------------------------------------
     353             : 
     354             :     private:
     355             : 
     356             :         SvtCompatibility        m_aOptions;
     357             :         SvtCompatibilityEntry   m_aDefOptions;
     358             : };
     359             : 
     360             : //*****************************************************************************************************************
     361             : //  constructor
     362             : //*****************************************************************************************************************
     363          10 : SvtCompatibilityOptions_Impl::SvtCompatibilityOptions_Impl()
     364             :     // Init baseclasses first
     365          10 :     :   ConfigItem( ROOTNODE_OPTIONS )
     366             :     // Init member then...
     367             : {
     368             :     // Get names and values of all accessable menu entries and fill internal structures.
     369             :     // See impl_GetPropertyNames() for further informations.
     370          10 :     Sequence< OUString > lNodes;
     371          10 :     Sequence< OUString > lNames = impl_GetPropertyNames( lNodes );
     372          10 :     sal_uInt32 nCount = lNodes.getLength();
     373          10 :     Sequence< Any > lValues = GetProperties( lNames );
     374             : 
     375             :     // Safe impossible cases.
     376             :     // We need values from ALL configuration keys.
     377             :     // Follow assignment use order of values in relation to our list of key names!
     378             :     DBG_ASSERT( !( lNames.getLength()!=lValues.getLength() ), "SvtCompatibilityOptions_Impl::SvtCompatibilityOptions_Impl()\nI miss some values of configuration keys!\n" );
     379             : 
     380          10 :     SvtCompatibilityEntry aItem;
     381          10 :     sal_uInt32 nItem = 0;
     382          10 :     sal_uInt32 nPosition = 0;
     383             : 
     384             :     // Get names/values for new menu.
     385             :     // 4 subkeys for every item!
     386          10 :     bool bDefaultFound = false;
     387          30 :     for( nItem = 0; nItem < nCount; ++nItem )
     388             :     {
     389          20 :         aItem.sName = lNodes[ nItem ];
     390          20 :         lValues[ nPosition++ ] >>= aItem.sModule;
     391          20 :         lValues[ nPosition++ ] >>= aItem.bUsePrtMetrics;
     392          20 :         lValues[ nPosition++ ] >>= aItem.bAddSpacing;
     393          20 :         lValues[ nPosition++ ] >>= aItem.bAddSpacingAtPages;
     394          20 :         lValues[ nPosition++ ] >>= aItem.bUseOurTabStops;
     395          20 :         lValues[ nPosition++ ] >>= aItem.bNoExtLeading;
     396          20 :         lValues[ nPosition++ ] >>= aItem.bUseLineSpacing;
     397          20 :         lValues[ nPosition++ ] >>= aItem.bAddTableSpacing;
     398          20 :         lValues[ nPosition++ ] >>= aItem.bUseObjPos;
     399          20 :         lValues[ nPosition++ ] >>= aItem.bUseOurTextWrapping;
     400          20 :         lValues[ nPosition++ ] >>= aItem.bConsiderWrappingStyle;
     401          20 :         lValues[ nPosition++ ] >>= aItem.bExpandWordSpace;
     402          20 :         m_aOptions.AppendEntry( aItem );
     403             : 
     404          20 :         if ( !bDefaultFound && aItem.sName.equals( COMPATIBILITY_DEFAULT_NAME ) != sal_False )
     405             :         {
     406          10 :             SvtSysLocale aSysLocale;
     407          10 :             com::sun::star::lang::Locale aLocale = aSysLocale.GetLanguageTag().getLocale();
     408          10 :             if ( aLocale.Language == "zh" || aLocale.Language == "ja" || aLocale.Language == "ko" )
     409           0 :                 aItem.bExpandWordSpace = false;
     410             : 
     411          10 :             m_aDefOptions = aItem;
     412          10 :             bDefaultFound = true;
     413             :         }
     414          10 :     }
     415          10 : }
     416             : 
     417             : //*****************************************************************************************************************
     418             : //  destructor
     419             : //*****************************************************************************************************************
     420          30 : SvtCompatibilityOptions_Impl::~SvtCompatibilityOptions_Impl()
     421             : {
     422             :     // We must save our current values .. if user forget it!
     423          10 :     if( IsModified() == sal_True )
     424             :     {
     425           0 :         Commit();
     426             :     }
     427          20 : }
     428             : 
     429           0 : void SvtCompatibilityOptions_Impl::SetDefault( OUString sName, bool bValue )
     430             : {
     431           0 :     if ( COMPATIBILITY_PROPERTYNAME_USEPRTMETRICS.equals( sName ) )
     432           0 :         m_aDefOptions.SetUsePrtMetrics( bValue );
     433           0 :     else if ( COMPATIBILITY_PROPERTYNAME_ADDSPACING.equals( sName ) )
     434           0 :         m_aDefOptions.SetAddSpacing( bValue );
     435           0 :     else if ( COMPATIBILITY_PROPERTYNAME_ADDSPACINGATPAGES.equals( sName ) )
     436           0 :         m_aDefOptions.SetAddSpacingAtPages( bValue );
     437           0 :     else if ( COMPATIBILITY_PROPERTYNAME_USEOURTABSTOPS.equals( sName ) )
     438           0 :         m_aDefOptions.SetUseOurTabStops( bValue );
     439           0 :     else if ( COMPATIBILITY_PROPERTYNAME_NOEXTLEADING.equals( sName ) )
     440           0 :         m_aDefOptions.SetNoExtLeading( bValue );
     441           0 :     else if ( COMPATIBILITY_PROPERTYNAME_USELINESPACING.equals( sName ) )
     442           0 :         m_aDefOptions.SetUseLineSpacing( bValue );
     443           0 :     else if ( COMPATIBILITY_PROPERTYNAME_ADDTABLESPACING.equals( sName ) )
     444           0 :         m_aDefOptions.SetAddTableSpacing( bValue );
     445           0 :     else if ( COMPATIBILITY_PROPERTYNAME_USEOBJECTPOSITIONING.equals( sName ) )
     446           0 :         m_aDefOptions.SetUseObjPos( bValue );
     447           0 :     else if ( COMPATIBILITY_PROPERTYNAME_USEOURTEXTWRAPPING.equals( sName ) )
     448           0 :         m_aDefOptions.SetUseOurTextWrapping( bValue );
     449           0 :     else if ( COMPATIBILITY_PROPERTYNAME_CONSIDERWRAPPINGSTYLE.equals( sName ) )
     450           0 :         m_aDefOptions.SetConsiderWrappingStyle( bValue );
     451           0 :     else if ( COMPATIBILITY_PROPERTYNAME_EXPANDWORDSPACE.equals( sName ) )
     452           0 :         m_aDefOptions.SetExpandWordSpace( bValue );
     453           0 : }
     454             : 
     455             : //*****************************************************************************************************************
     456             : //  public method
     457             : //*****************************************************************************************************************
     458           0 : void SvtCompatibilityOptions_Impl::Notify( const Sequence< OUString >& )
     459             : {
     460             :     DBG_ASSERT( sal_False, "SvtCompatibilityOptions_Impl::Notify()\nNot implemented yet! I don't know how I can handle a dynamical list of unknown properties ...\n" );
     461           0 : }
     462             : 
     463             : //*****************************************************************************************************************
     464             : //  public method
     465             : //*****************************************************************************************************************
     466           0 : void SvtCompatibilityOptions_Impl::Commit()
     467             : {
     468             :     // Write all properties!
     469             :     // Delete complete set first.
     470           0 :     ClearNodeSet( SETNODE_ALLFILEFORMATS );
     471             : 
     472           0 :     SvtCompatibilityEntry aItem;
     473           0 :     OUString sNode;
     474           0 :     Sequence< PropertyValue > lPropertyValues( PROPERTYCOUNT - 1 );
     475           0 :     sal_uInt32 nItem = 0;
     476           0 :     sal_uInt32 nNewCount = m_aOptions.size();
     477           0 :     for( nItem = 0; nItem < nNewCount; ++nItem )
     478             :     {
     479           0 :         aItem = m_aOptions[ nItem ];
     480           0 :         sNode = SETNODE_ALLFILEFORMATS + PATHDELIMITER + aItem.sName + PATHDELIMITER;
     481             : 
     482           0 :         lPropertyValues[ OFFSET_MODULE - 1                  ].Name = sNode + PROPERTYNAME_MODULE;
     483           0 :         lPropertyValues[ OFFSET_USEPRTMETRICS - 1           ].Name = sNode + PROPERTYNAME_USEPRTMETRICS;
     484           0 :         lPropertyValues[ OFFSET_ADDSPACING - 1              ].Name = sNode + PROPERTYNAME_ADDSPACING;
     485           0 :         lPropertyValues[ OFFSET_ADDSPACINGATPAGES - 1       ].Name = sNode + PROPERTYNAME_ADDSPACINGATPAGES;
     486           0 :         lPropertyValues[ OFFSET_USEOURTABSTOPS - 1          ].Name = sNode + PROPERTYNAME_USEOURTABSTOPS;
     487           0 :         lPropertyValues[ OFFSET_NOEXTLEADING - 1            ].Name = sNode + PROPERTYNAME_NOEXTLEADING;
     488           0 :         lPropertyValues[ OFFSET_USELINESPACING - 1          ].Name = sNode + PROPERTYNAME_USELINESPACING;
     489           0 :         lPropertyValues[ OFFSET_ADDTABLESPACING - 1         ].Name = sNode + PROPERTYNAME_ADDTABLESPACING;
     490           0 :         lPropertyValues[ OFFSET_USEOBJPOS - 1               ].Name = sNode + PROPERTYNAME_USEOBJPOS;
     491           0 :         lPropertyValues[ OFFSET_USEOURTEXTWRAPPING - 1      ].Name = sNode + PROPERTYNAME_USEOURTEXTWRAP;
     492           0 :         lPropertyValues[ OFFSET_CONSIDERWRAPPINGSTYLE - 1   ].Name = sNode + PROPERTYNAME_CONSIDERWRAPSTYLE;
     493           0 :         lPropertyValues[ OFFSET_EXPANDWORDSPACE - 1         ].Name = sNode + PROPERTYNAME_EXPANDWORDSPACE;
     494             : 
     495           0 :         lPropertyValues[ OFFSET_MODULE - 1                  ].Value <<= aItem.sModule;
     496           0 :         lPropertyValues[ OFFSET_USEPRTMETRICS - 1           ].Value <<= aItem.bUsePrtMetrics;
     497           0 :         lPropertyValues[ OFFSET_ADDSPACING - 1              ].Value <<= aItem.bAddSpacing;
     498           0 :         lPropertyValues[ OFFSET_ADDSPACINGATPAGES - 1       ].Value <<= aItem.bAddSpacingAtPages;
     499           0 :         lPropertyValues[ OFFSET_USEOURTABSTOPS - 1          ].Value <<= aItem.bUseOurTabStops;
     500           0 :         lPropertyValues[ OFFSET_NOEXTLEADING - 1            ].Value <<= aItem.bNoExtLeading;
     501           0 :         lPropertyValues[ OFFSET_USELINESPACING - 1          ].Value <<= aItem.bUseLineSpacing;
     502           0 :         lPropertyValues[ OFFSET_ADDTABLESPACING - 1         ].Value <<= aItem.bAddTableSpacing;
     503           0 :         lPropertyValues[ OFFSET_USEOBJPOS - 1               ].Value <<= aItem.bUseObjPos;
     504           0 :         lPropertyValues[ OFFSET_USEOURTEXTWRAPPING - 1      ].Value <<= aItem.bUseOurTextWrapping;
     505           0 :         lPropertyValues[ OFFSET_CONSIDERWRAPPINGSTYLE - 1   ].Value <<= aItem.bConsiderWrappingStyle;
     506           0 :         lPropertyValues[ OFFSET_EXPANDWORDSPACE - 1         ].Value <<= aItem.bExpandWordSpace;
     507             : 
     508           0 :         SetSetProperties( SETNODE_ALLFILEFORMATS, lPropertyValues );
     509           0 :     }
     510           0 : }
     511             : 
     512             : //*****************************************************************************************************************
     513             : //  public method
     514             : //*****************************************************************************************************************
     515           0 : void SvtCompatibilityOptions_Impl::Clear()
     516             : {
     517           0 :     m_aOptions.Clear();
     518           0 :     SetModified();
     519           0 : }
     520             : 
     521             : //*****************************************************************************************************************
     522             : //  public method
     523             : //*****************************************************************************************************************
     524           0 : Sequence< Sequence< PropertyValue > > SvtCompatibilityOptions_Impl::GetList() const
     525             : {
     526           0 :     Sequence< Sequence< PropertyValue > > lReturn;
     527           0 :     lReturn = m_aOptions.GetList();
     528           0 :     return lReturn;
     529             : }
     530             : 
     531             : //*****************************************************************************************************************
     532             : //  public method
     533             : //*****************************************************************************************************************
     534             : 
     535           0 : void SvtCompatibilityOptions_Impl::AppendItem(  const ::rtl::OUString& _sName,
     536             :                                                 const ::rtl::OUString& _sModule,
     537             :                                                 bool _bUsePrtMetrics,
     538             :                                                 bool _bAddSpacing,
     539             :                                                 bool _bAddSpacingAtPages,
     540             :                                                 bool _bUseOurTabStops,
     541             :                                                 bool _bNoExtLeading,
     542             :                                                 bool _bUseLineSpacing,
     543             :                                                 bool _bAddTableSpacing,
     544             :                                                 bool _bUseObjPos,
     545             :                                                 bool _bUseOurTextWrapping,
     546             :                                                 bool _bConsiderWrappingStyle,
     547             :                                                 bool _bExpandWordSpace )
     548             : {
     549           0 :     SvtCompatibilityEntry aItem( _sName, _sModule );
     550           0 :     aItem.SetUsePrtMetrics( _bUsePrtMetrics );
     551           0 :     aItem.SetAddSpacing( _bAddSpacing );
     552           0 :     aItem.SetAddSpacingAtPages( _bAddSpacingAtPages );
     553           0 :     aItem.SetUseOurTabStops( _bUseOurTabStops );
     554           0 :     aItem.SetNoExtLeading( _bNoExtLeading );
     555           0 :     aItem.SetUseLineSpacing( _bUseLineSpacing );
     556           0 :     aItem.SetAddTableSpacing( _bAddTableSpacing );
     557           0 :     aItem.SetUseObjPos( _bUseObjPos );
     558           0 :     aItem.SetUseOurTextWrapping( _bUseOurTextWrapping );
     559           0 :     aItem.SetConsiderWrappingStyle( _bConsiderWrappingStyle );
     560           0 :     aItem.SetExpandWordSpace( _bExpandWordSpace );
     561           0 :     m_aOptions.AppendEntry( aItem );
     562             : 
     563             :     // default item reset?
     564           0 :     if ( _sName.equals( COMPATIBILITY_DEFAULT_NAME ) != sal_False )
     565           0 :         m_aDefOptions = aItem;
     566             : 
     567           0 :     SetModified();
     568           0 : }
     569             : 
     570             : //*****************************************************************************************************************
     571             : //  private method
     572             : //*****************************************************************************************************************
     573          10 : Sequence< OUString > SvtCompatibilityOptions_Impl::impl_GetPropertyNames( Sequence< OUString >& rItems )
     574             : {
     575             :     // First get ALL names of current existing list items in configuration!
     576          10 :     rItems = GetNodeNames( SETNODE_ALLFILEFORMATS );
     577             :     // expand list to result list ...
     578          10 :     Sequence< OUString > lProperties( rItems.getLength() * ( PROPERTYCOUNT - 1 ) );
     579          10 :     impl_ExpandPropertyNames( rItems, lProperties );
     580             :     // Return result.
     581          10 :     return lProperties;
     582             : }
     583             : 
     584             : //*****************************************************************************************************************
     585             : //  private method
     586             : //*****************************************************************************************************************
     587          10 : void SvtCompatibilityOptions_Impl::impl_ExpandPropertyNames(
     588             :     const Sequence< OUString >& lSource, Sequence< OUString >& lDestination )
     589             : {
     590          10 :     OUString sFixPath;
     591          10 :     sal_Int32 nDestStep = 0;
     592          10 :     sal_Int32 nSourceCount = lSource.getLength();
     593             :     // Copy entries to destination and expand every item with 2 supported sub properties.
     594          30 :     for( sal_Int32 nSourceStep = 0; nSourceStep < nSourceCount; ++nSourceStep )
     595             :     {
     596          20 :         sFixPath = SETNODE_ALLFILEFORMATS;
     597          20 :         sFixPath += PATHDELIMITER;
     598          20 :         sFixPath += lSource[ nSourceStep ];
     599          20 :         sFixPath += PATHDELIMITER;
     600             : 
     601          20 :         lDestination[nDestStep] = sFixPath;
     602          20 :         lDestination[nDestStep] += PROPERTYNAME_MODULE;
     603          20 :         ++nDestStep;
     604          20 :         lDestination[nDestStep] = sFixPath;
     605          20 :         lDestination[nDestStep] += PROPERTYNAME_USEPRTMETRICS;
     606          20 :         ++nDestStep;
     607          20 :         lDestination[nDestStep] = sFixPath;
     608          20 :         lDestination[nDestStep] += PROPERTYNAME_ADDSPACING;
     609          20 :         ++nDestStep;
     610          20 :         lDestination[nDestStep] = sFixPath;
     611          20 :         lDestination[nDestStep] += PROPERTYNAME_ADDSPACINGATPAGES;
     612          20 :         ++nDestStep;
     613          20 :         lDestination[nDestStep] = sFixPath;
     614          20 :         lDestination[nDestStep] += PROPERTYNAME_USEOURTABSTOPS;
     615          20 :         ++nDestStep;
     616          20 :         lDestination[nDestStep] = sFixPath;
     617          20 :         lDestination[nDestStep] += PROPERTYNAME_NOEXTLEADING;
     618          20 :         ++nDestStep;
     619          20 :         lDestination[nDestStep] = sFixPath;
     620          20 :         lDestination[nDestStep] += PROPERTYNAME_USELINESPACING;
     621          20 :         ++nDestStep;
     622          20 :         lDestination[nDestStep] = sFixPath;
     623          20 :         lDestination[nDestStep] += PROPERTYNAME_ADDTABLESPACING;
     624          20 :         ++nDestStep;
     625          20 :         lDestination[nDestStep] = sFixPath;
     626          20 :         lDestination[nDestStep] += PROPERTYNAME_USEOBJPOS;
     627          20 :         ++nDestStep;
     628          20 :         lDestination[nDestStep] = sFixPath;
     629          20 :         lDestination[nDestStep] += PROPERTYNAME_USEOURTEXTWRAP;
     630          20 :         ++nDestStep;
     631          20 :         lDestination[nDestStep] = sFixPath;
     632          20 :         lDestination[nDestStep] += PROPERTYNAME_CONSIDERWRAPSTYLE;
     633          20 :         ++nDestStep;
     634          20 :         lDestination[nDestStep] = sFixPath;
     635          20 :         lDestination[nDestStep] += PROPERTYNAME_EXPANDWORDSPACE;
     636          20 :         ++nDestStep;
     637          10 :     }
     638          10 : }
     639             : 
     640             : //*****************************************************************************************************************
     641             : //  initialize static member
     642             : //  DON'T DO IT IN YOUR HEADER!
     643             : //  see definition for further informations
     644             : //*****************************************************************************************************************
     645             : SvtCompatibilityOptions_Impl*   SvtCompatibilityOptions::m_pDataContainer = NULL;
     646             : sal_Int32                       SvtCompatibilityOptions::m_nRefCount = 0;
     647             : 
     648             : //*****************************************************************************************************************
     649             : //  constructor
     650             : //*****************************************************************************************************************
     651         286 : SvtCompatibilityOptions::SvtCompatibilityOptions()
     652             : {
     653             :     // Global access, must be guarded (multithreading!).
     654         286 :     MutexGuard aGuard( GetOwnStaticMutex() );
     655             :     // Increase ouer refcount ...
     656         286 :     ++m_nRefCount;
     657             :     // ... and initialize ouer data container only if it not already exist!
     658         286 :     if( m_pDataContainer == NULL )
     659             :     {
     660          10 :         m_pDataContainer = new SvtCompatibilityOptions_Impl;
     661          10 :         ItemHolder1::holdConfigItem(E_COMPATIBILITY);
     662         286 :     }
     663         286 : }
     664             : 
     665             : //*****************************************************************************************************************
     666             : //  destructor
     667             : //*****************************************************************************************************************
     668         582 : SvtCompatibilityOptions::~SvtCompatibilityOptions()
     669             : {
     670             :     // Global access, must be guarded (multithreading!)
     671         286 :     MutexGuard aGuard( GetOwnStaticMutex() );
     672             :     // Decrease ouer refcount.
     673         286 :     --m_nRefCount;
     674             :     // If last instance was deleted ...
     675             :     // we must destroy ouer static data container!
     676         286 :     if( m_nRefCount <= 0 )
     677             :     {
     678          10 :         delete m_pDataContainer;
     679          10 :         m_pDataContainer = NULL;
     680         286 :     }
     681         296 : }
     682             : 
     683             : //*****************************************************************************************************************
     684             : //  public method
     685             : //*****************************************************************************************************************
     686           0 : void SvtCompatibilityOptions::Clear()
     687             : {
     688           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     689           0 :     m_pDataContainer->Clear();
     690           0 : }
     691             : 
     692           0 : void SvtCompatibilityOptions::SetDefault( ::rtl::OUString sName, bool bValue )
     693             : {
     694           0 :     m_pDataContainer->SetDefault( sName, bValue );
     695           0 : }
     696             : 
     697             : //*****************************************************************************************************************
     698             : //  public method
     699             : //*****************************************************************************************************************
     700           0 : void SvtCompatibilityOptions::AppendItem( const ::rtl::OUString& sName,
     701             :                                           const ::rtl::OUString& sModule,
     702             :                                           bool bUsePrtMetrics,
     703             :                                           bool bAddSpacing,
     704             :                                           bool bAddSpacingAtPages,
     705             :                                           bool bUseOurTabStops,
     706             :                                           bool bNoExtLeading,
     707             :                                           bool bUseLineSpacing,
     708             :                                           bool bAddTableSpacing,
     709             :                                           bool bUseObjPos,
     710             :                                           bool bUseOurTextWrapping,
     711             :                                           bool bConsiderWrappingStyle,
     712             :                                           bool bExpandWordSpace )
     713             : {
     714           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     715             :     m_pDataContainer->AppendItem(
     716             :         sName, sModule, bUsePrtMetrics, bAddSpacing,
     717             :         bAddSpacingAtPages, bUseOurTabStops, bNoExtLeading,
     718             :         bUseLineSpacing, bAddTableSpacing, bUseObjPos,
     719           0 :         bUseOurTextWrapping, bConsiderWrappingStyle, bExpandWordSpace );
     720           0 : }
     721             : 
     722         276 : bool SvtCompatibilityOptions::IsUsePrtDevice() const
     723             : {
     724         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     725         276 :     return m_pDataContainer->IsUsePrtDevice();
     726             : }
     727             : 
     728         276 : bool SvtCompatibilityOptions::IsAddSpacing() const
     729             : {
     730         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     731         276 :     return m_pDataContainer->IsAddSpacing();
     732             : }
     733             : 
     734         276 : bool SvtCompatibilityOptions::IsAddSpacingAtPages() const
     735             : {
     736         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     737         276 :     return m_pDataContainer->IsAddSpacingAtPages();
     738             : }
     739             : 
     740         276 : bool SvtCompatibilityOptions::IsUseOurTabStops() const
     741             : {
     742         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     743         276 :     return m_pDataContainer->IsUseOurTabStops();
     744             : }
     745             : 
     746         276 : bool SvtCompatibilityOptions::IsNoExtLeading() const
     747             : {
     748         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     749         276 :     return m_pDataContainer->IsNoExtLeading();
     750             : }
     751             : 
     752         276 : bool SvtCompatibilityOptions::IsUseLineSpacing() const
     753             : {
     754         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     755         276 :     return m_pDataContainer->IsUseLineSpacing();
     756             : }
     757             : 
     758         276 : bool SvtCompatibilityOptions::IsAddTableSpacing() const
     759             : {
     760         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     761         276 :     return m_pDataContainer->IsAddTableSpacing();
     762             : }
     763             : 
     764         276 : bool SvtCompatibilityOptions::IsUseObjectPositioning() const
     765             : {
     766         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     767         276 :     return m_pDataContainer->IsUseObjPos();
     768             : }
     769             : 
     770         276 : bool SvtCompatibilityOptions::IsUseOurTextWrapping() const
     771             : {
     772         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     773         276 :     return m_pDataContainer->IsUseOurTextWrapping();
     774             : }
     775             : 
     776         276 : bool SvtCompatibilityOptions::IsConsiderWrappingStyle() const
     777             : {
     778         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     779         276 :     return m_pDataContainer->IsConsiderWrappingStyle();
     780             : }
     781             : 
     782         276 : bool SvtCompatibilityOptions::IsExpandWordSpace() const
     783             : {
     784         276 :     MutexGuard aGuard( GetOwnStaticMutex() );
     785         276 :     return m_pDataContainer->IsExpandWordSpace();
     786             : }
     787             : 
     788           0 : Sequence< Sequence< PropertyValue > > SvtCompatibilityOptions::GetList() const
     789             : {
     790           0 :     MutexGuard aGuard( GetOwnStaticMutex() );
     791           0 :     return m_pDataContainer->GetList();
     792             : }
     793             : 
     794             : namespace
     795             : {
     796             :     class theCompatibilityOptionsMutex : public rtl::Static<osl::Mutex, theCompatibilityOptionsMutex>{};
     797             : }
     798             : 
     799             : //*****************************************************************************************************************
     800             : //  private method
     801             : //*****************************************************************************************************************
     802        3608 : Mutex& SvtCompatibilityOptions::GetOwnStaticMutex()
     803             : {
     804        3608 :     return theCompatibilityOptionsMutex::get();
     805             : }
     806             : 
     807             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10