LCOV - code coverage report
Current view: top level - sc/source/core/data - stlsheet.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 120 75.0 %
Date: 2012-08-25 Functions: 9 19 47.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 93 205 45.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "document.hxx"
      30                 :            : #include "stlsheet.hxx"
      31                 :            : #include "stlpool.hxx"
      32                 :            : 
      33                 :            : #include "scitems.hxx"
      34                 :            : #include <editeng/boxitem.hxx>
      35                 :            : #include <editeng/frmdiritem.hxx>
      36                 :            : #include <editeng/lrspitem.hxx>
      37                 :            : #include <svx/pageitem.hxx>
      38                 :            : #include <editeng/paperinf.hxx>
      39                 :            : #include <editeng/pbinitem.hxx>
      40                 :            : #include <editeng/sizeitem.hxx>
      41                 :            : #include <editeng/ulspitem.hxx>
      42                 :            : #include <sfx2/printer.hxx>
      43                 :            : #include <svl/itempool.hxx>
      44                 :            : #include <svl/itemset.hxx>
      45                 :            : #include <svl/smplhint.hxx>
      46                 :            : #include "attrib.hxx"
      47                 :            : 
      48                 :            : 
      49                 :            : #include <vcl/svapp.hxx>    // GetSettings()
      50                 :            : 
      51                 :            : #include "globstr.hrc"
      52                 :            : #include "sc.hrc"
      53                 :            : //------------------------------------------------------------------------
      54                 :            : 
      55 [ #  # ][ #  # ]:          0 : TYPEINIT1(ScStyleSheet, SfxStyleSheet);
      56                 :            : 
      57                 :            : #define TWO_CM      1134
      58                 :            : #define HFDIST_CM   142
      59                 :            : 
      60                 :            : //========================================================================
      61                 :            : 
      62                 :       3713 : ScStyleSheet::ScStyleSheet( const String&       rName,
      63                 :            :                             ScStyleSheetPool&   rPoolP,
      64                 :            :                             SfxStyleFamily      eFamily,
      65                 :            :                             sal_uInt16              nMaskP )
      66                 :            : 
      67                 :            :     :   SfxStyleSheet   ( rName, rPoolP, eFamily, nMaskP )
      68                 :       3713 :     , eUsage( UNKNOWN )
      69                 :            : {
      70                 :       3713 : }
      71                 :            : 
      72                 :            : //------------------------------------------------------------------------
      73                 :            : 
      74                 :          0 : ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
      75                 :            :     : SfxStyleSheet ( rStyle )
      76                 :          0 :     , eUsage( UNKNOWN )
      77                 :            : {
      78                 :          0 : }
      79                 :            : 
      80                 :            : //------------------------------------------------------------------------
      81                 :            : 
      82                 :       3359 : ScStyleSheet::~ScStyleSheet()
      83                 :            : {
      84         [ -  + ]:       6718 : }
      85                 :            : 
      86                 :            : //------------------------------------------------------------------------
      87                 :            : 
      88                 :          0 : sal_Bool ScStyleSheet::HasFollowSupport() const
      89                 :            : {
      90                 :          0 :     return false;
      91                 :            : }
      92                 :            : 
      93                 :            : //------------------------------------------------------------------------
      94                 :            : 
      95                 :          0 : sal_Bool ScStyleSheet::HasParentSupport () const
      96                 :            : {
      97                 :          0 :     sal_Bool bHasParentSupport = false;
      98                 :            : 
      99      [ #  #  # ]:          0 :     switch ( GetFamily() )
     100                 :            :     {
     101                 :          0 :         case SFX_STYLE_FAMILY_PARA: bHasParentSupport = sal_True;   break;
     102                 :          0 :         case SFX_STYLE_FAMILY_PAGE: bHasParentSupport = false;  break;
     103                 :            :         default:
     104                 :            :         {
     105                 :            :             // added to avoid warnings
     106                 :            :         }
     107                 :            :     }
     108                 :            : 
     109                 :          0 :     return bHasParentSupport;
     110                 :            : }
     111                 :            : 
     112                 :            : //------------------------------------------------------------------------
     113                 :            : 
     114                 :       4889 : sal_Bool ScStyleSheet::SetParent( const String& rParentName )
     115                 :            : {
     116                 :       4889 :     sal_Bool bResult = false;
     117         [ +  - ]:       4889 :     String aEffName = rParentName;
     118         [ +  - ]:       4889 :     SfxStyleSheetBase* pStyle = pPool->Find( aEffName, nFamily );
     119         [ +  + ]:       4889 :     if (!pStyle)
     120                 :            :     {
     121         [ +  - ]:        939 :         SfxStyleSheetIterator* pIter = pPool->CreateIterator( nFamily, SFXSTYLEBIT_ALL );
     122         [ +  - ]:        939 :         pStyle = pIter->First();
     123         [ +  + ]:        939 :         if (pStyle)
     124 [ +  - ][ +  - ]:        903 :             aEffName = pStyle->GetName();
     125                 :            :     }
     126                 :            : 
     127 [ +  + ][ +  - ]:       4889 :     if ( pStyle && aEffName != GetName() )
         [ +  - ][ +  + ]
                 [ +  + ]
     128                 :            :     {
     129         [ +  - ]:       4724 :         bResult = SfxStyleSheet::SetParent( aEffName );
     130         [ +  - ]:       4724 :         if (bResult)
     131                 :            :         {
     132         [ +  - ]:       4724 :             SfxItemSet& rParentSet = pStyle->GetItemSet();
     133         [ +  - ]:       4724 :             GetItemSet().SetParent( &rParentSet );
     134                 :            : 
     135                 :            :             // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
     136                 :            :             // so the repaint has to come from here (after modifying the ItemSet).
     137                 :            :             // RepaintRange checks the document's IsVisible flag and locked repaints.
     138                 :       4724 :             ScDocument* pDoc = static_cast<ScStyleSheetPool&>(GetPool()).GetDocument();
     139         [ +  - ]:       4724 :             if (pDoc)
     140         [ +  - ]:       4724 :                 pDoc->RepaintRange( ScRange( 0,0,0, MAXCOL,MAXROW,MAXTAB ) );
     141                 :            :         }
     142                 :            :     }
     143                 :            : 
     144         [ +  - ]:       4889 :     return bResult;
     145                 :            : }
     146                 :            : 
     147                 :            : //------------------------------------------------------------------------
     148                 :            : 
     149                 :     116811 : SfxItemSet& ScStyleSheet::GetItemSet()
     150                 :            : {
     151         [ +  + ]:     116811 :     if ( !pSet )
     152                 :            :     {
     153         [ +  + ]:       3713 :         switch ( GetFamily() )
     154                 :            :         {
     155                 :            :             case SFX_STYLE_FAMILY_PAGE:
     156                 :            :                 {
     157                 :            :                     // Seitenvorlagen sollen nicht ableitbar sein,
     158                 :            :                     // deshalb werden an dieser Stelle geeignete
     159                 :            :                     // Werte eingestellt. (==Standard-Seitenvorlage)
     160                 :            : 
     161                 :       1055 :                     SfxItemPool& rItemPool = GetPool().GetPool();
     162                 :            :                     pSet = new SfxItemSet( rItemPool,
     163                 :            :                                            ATTR_BACKGROUND, ATTR_BACKGROUND,
     164                 :            :                                            ATTR_BORDER, ATTR_SHADOW,
     165                 :            :                                            ATTR_LRSPACE, ATTR_PAGE_SCALETO,
     166                 :            :                                            ATTR_WRITINGDIR, ATTR_WRITINGDIR,
     167                 :            :                                            ATTR_USERDEF, ATTR_USERDEF,
     168         [ +  - ]:       1055 :                                            0 );
     169                 :            : 
     170                 :            :                     //  Wenn gerade geladen wird, wird auch der Set hinterher aus der Datei
     171                 :            :                     //  gefuellt, es brauchen also keine Defaults gesetzt zu werden.
     172                 :            :                     //  GetPrinter wuerde dann auch einen neuen Printer anlegen, weil der
     173                 :            :                     //  gespeicherte Printer noch nicht geladen ist!
     174                 :            : 
     175                 :       1055 :                     ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
     176         [ +  - ]:       1055 :                     if ( pDoc )
     177                 :            :                     {
     178                 :            :                         // Setzen von sinnvollen Default-Werten:
     179         [ +  - ]:       1055 :                         SvxPageItem     aPageItem( ATTR_PAGE );
     180 [ +  - ][ +  - ]:       1055 :                         SvxSizeItem     aPaperSizeItem( ATTR_PAGE_SIZE, SvxPaperInfo::GetDefaultPaperSize() );
     181                 :            : 
     182                 :            :                         SvxSetItem      aHFSetItem(
     183                 :            :                                             (const SvxSetItem&)
     184 [ +  - ][ +  - ]:       1055 :                                             rItemPool.GetDefaultItem(ATTR_PAGE_HEADERSET) );
     185                 :            : 
     186                 :       1055 :                         SfxItemSet&     rHFSet = aHFSetItem.GetItemSet();
     187                 :            :                         SvxSizeItem     aHFSizeItem( // 0,5 cm + Abstand
     188                 :            :                                             ATTR_PAGE_SIZE,
     189         [ +  - ]:       1055 :                                             Size( 0, (long)( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
     190                 :            : 
     191                 :            :                         SvxULSpaceItem  aHFDistItem ( HFDIST_CM,// nUp
     192                 :            :                                                       HFDIST_CM,// nLow
     193         [ +  - ]:       1055 :                                                       ATTR_ULSPACE );
     194                 :            : 
     195                 :            :                         SvxLRSpaceItem  aLRSpaceItem( TWO_CM,   // nLeft
     196                 :            :                                                       TWO_CM,   // nRight
     197                 :            :                                                       TWO_CM,   // nTLeft
     198                 :            :                                                       0,        // nFirstLineOffset
     199         [ +  - ]:       1055 :                                                       ATTR_LRSPACE );
     200                 :            :                         SvxULSpaceItem  aULSpaceItem( TWO_CM,   // nUp
     201                 :            :                                                       TWO_CM,   // nLow
     202         [ +  - ]:       1055 :                                                       ATTR_ULSPACE );
     203         [ +  - ]:       1055 :                         SvxBoxInfoItem  aBoxInfoItem( ATTR_BORDER_INNER );
     204                 :            : 
     205                 :       1055 :                         aBoxInfoItem.SetTable( false );
     206                 :       1055 :                         aBoxInfoItem.SetDist( sal_True );
     207                 :       1055 :                         aBoxInfoItem.SetValid( VALID_DISTANCE, sal_True );
     208                 :            : 
     209                 :       1055 :                         aPageItem.SetLandscape( false );
     210                 :            : 
     211         [ +  - ]:       1055 :                         rHFSet.Put( aBoxInfoItem );
     212         [ +  - ]:       1055 :                         rHFSet.Put( aHFSizeItem );
     213         [ +  - ]:       1055 :                         rHFSet.Put( aHFDistItem );
     214 [ +  - ][ +  - ]:       1055 :                         rHFSet.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE ) ); // Rand auf Null setzen
                 [ +  - ]
     215                 :            : 
     216         [ +  - ]:       1055 :                         pSet->Put( aHFSetItem, ATTR_PAGE_HEADERSET );
     217         [ +  - ]:       1055 :                         pSet->Put( aHFSetItem, ATTR_PAGE_FOOTERSET );
     218         [ +  - ]:       1055 :                         pSet->Put( aBoxInfoItem ); // PoolDefault wg. Formatvorlagen
     219                 :            :                                                    // nicht ueberschreiben!
     220                 :            : 
     221                 :            :                         //  Writing direction: not as pool default because the default for cells
     222                 :            :                         //  must remain FRMDIR_ENVIRONMENT, and each page style's setting is
     223                 :            :                         //  supposed to be saved in the file format.
     224                 :            :                         //  The page default depends on the system language.
     225         [ +  - ]:       1055 :                         SvxFrameDirection eDirection = ScGlobal::IsSystemRTL() ?
     226         [ -  + ]:       1055 :                                         FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP;
     227 [ +  - ][ +  - ]:       1055 :                         pSet->Put( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ), ATTR_WRITINGDIR );
                 [ +  - ]
     228                 :            : 
     229         [ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( aPageItem );
     230         [ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( aPaperSizeItem );
     231         [ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( aLRSpaceItem );
     232         [ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( aULSpaceItem );
     233 [ +  - ][ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE, 100 ) );
                 [ +  - ]
     234         [ +  - ]:       1055 :                         ScPageScaleToItem aScaleToItem;
     235         [ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( aScaleToItem );
     236 [ +  - ][ +  - ]:       1055 :                         rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, 0 ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     237                 :            :                     }
     238                 :            :                 }
     239                 :       1055 :                 break;
     240                 :            : 
     241                 :            :             case SFX_STYLE_FAMILY_PARA:
     242                 :            :             default:
     243         [ +  - ]:       2658 :                 pSet = new SfxItemSet( GetPool().GetPool(), ATTR_PATTERN_START, ATTR_PATTERN_END );
     244                 :       2658 :                 break;
     245                 :            :         }
     246                 :       3713 :         bMySet = true;
     247                 :            :     }
     248         [ +  + ]:     116811 :     if ( nHelpId == HID_SC_SHEET_CELL_ERG1 )
     249                 :            :     {
     250         [ +  + ]:       5177 :         if ( !pSet->Count() )
     251                 :            :         {
     252                 :        496 :             ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
     253         [ +  + ]:        496 :             if ( pDoc )
     254                 :            :             {
     255                 :        190 :                 sal_uLong nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_CURRENCY,ScGlobal::eLnge );
     256         [ +  - ]:        190 :                 pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
     257                 :            :             }
     258                 :            :         }
     259                 :            :     }
     260                 :            : 
     261                 :     116811 :     return *pSet;
     262                 :            : }
     263                 :            : 
     264                 :            : //------------------------------------------------------------------------
     265                 :            : 
     266                 :         16 : sal_Bool ScStyleSheet::IsUsed() const
     267                 :            : {
     268         [ -  + ]:         16 :     if ( GetFamily() == SFX_STYLE_FAMILY_PARA )
     269                 :            :     {
     270                 :            :         // Always query the document to let it decide if a rescan is necessary,
     271                 :            :         // and store the state.
     272                 :          0 :         ScDocument* pDoc = ((ScStyleSheetPool*)pPool)->GetDocument();
     273 [ #  # ][ #  # ]:          0 :         if ( pDoc && pDoc->IsStyleSheetUsed( *this, sal_True ) )
                 [ #  # ]
     274                 :          0 :             eUsage = USED;
     275                 :            :         else
     276                 :          0 :             eUsage = NOTUSED;
     277                 :          0 :         return eUsage == USED;
     278                 :            :     }
     279                 :            :     else
     280                 :         16 :         return sal_True;
     281                 :            : }
     282                 :            : 
     283                 :            : //------------------------------------------------------------------------
     284                 :            : 
     285                 :       3914 : void ScStyleSheet::Notify( SfxBroadcaster&, const SfxHint& rHint )
     286                 :            : {
     287         [ +  + ]:       3914 :     if ( rHint.ISA(SfxSimpleHint) )
     288         [ +  - ]:       1957 :         if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
     289                 :       1957 :             GetItemSet().SetParent( NULL );
     290                 :       3914 : }
     291                 :            : 
     292                 :            : //------------------------------------------------------------------------
     293                 :            : 
     294                 :            : //  schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
     295                 :            : //  obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
     296                 :            : 
     297                 :     533770 : const String& ScStyleSheet::GetName() const
     298                 :            : {
     299                 :     533770 :     const String& rBase = SfxStyleSheet::GetName();
     300                 :     533770 :     const String* pForceStdName = ((ScStyleSheetPool*)pPool)->GetForceStdName();
     301 [ #  # ][ -  + ]:     533770 :     if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
                 [ -  + ]
     302                 :          0 :         return *pForceStdName;
     303                 :            :     else
     304                 :     533770 :         return rBase;
     305                 :            : }
     306                 :            : 
     307                 :       4965 : const String& ScStyleSheet::GetParent() const
     308                 :            : {
     309                 :       4965 :     const String& rBase = SfxStyleSheet::GetParent();
     310                 :       4965 :     const String* pForceStdName = ((ScStyleSheetPool*)pPool)->GetForceStdName();
     311 [ #  # ][ -  + ]:       4965 :     if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
                 [ -  + ]
     312                 :          0 :         return *pForceStdName;
     313                 :            :     else
     314                 :       4965 :         return rBase;
     315                 :            : }
     316                 :            : 
     317                 :          0 : const String& ScStyleSheet::GetFollow() const
     318                 :            : {
     319                 :          0 :     const String& rBase = SfxStyleSheet::GetFollow();
     320                 :          0 :     const String* pForceStdName = ((ScStyleSheetPool*)pPool)->GetForceStdName();
     321 [ #  # ][ #  # ]:          0 :     if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
                 [ #  # ]
     322                 :          0 :         return *pForceStdName;
     323                 :            :     else
     324                 :          0 :         return rBase;
     325                 :            : }
     326                 :            : 
     327                 :            : //  Verhindern, dass ein Style "Standard" angelegt wird, wenn das nicht der
     328                 :            : //  Standard-Name ist, weil sonst beim Speichern zwei Styles denselben Namen haetten
     329                 :            : //  (Beim Laden wird der Style direkt per Make mit dem Namen erzeugt, so dass diese
     330                 :            : //  Abfrage dann nicht gilt)
     331                 :            : //! Wenn irgendwann aus dem Laden SetName aufgerufen wird, muss fuer das Laden ein
     332                 :            : //! Flag gesetzt und abgefragt werden.
     333                 :            : //! Die ganze Abfrage muss raus, wenn fuer eine neue Datei-Version die Namens-Umsetzung wegfaellt.
     334                 :            : 
     335                 :          0 : sal_Bool ScStyleSheet::SetName( const String& rNew )
     336                 :            : {
     337         [ #  # ]:          0 :     String aFileStdName = rtl::OUString(STRING_STANDARD);
     338 [ #  # ][ #  # ]:          0 :     if ( rNew == aFileStdName && aFileStdName != ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     339                 :          0 :         return false;
     340                 :            :     else
     341 [ #  # ][ #  # ]:          0 :         return SfxStyleSheet::SetName( rNew );
     342                 :            : }
     343                 :            : 
     344                 :            : 
     345                 :            : 
     346                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10