LCOV - code coverage report
Current view: top level - sc/source/core/data - stlsheet.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 90 120 75.0 %
Date: 2014-04-11 Functions: 9 19 47.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 "document.hxx"
      21             : #include "stlsheet.hxx"
      22             : #include "stlpool.hxx"
      23             : 
      24             : #include "scitems.hxx"
      25             : #include <editeng/boxitem.hxx>
      26             : #include <editeng/frmdiritem.hxx>
      27             : #include <editeng/lrspitem.hxx>
      28             : #include <svx/pageitem.hxx>
      29             : #include <editeng/paperinf.hxx>
      30             : #include <editeng/pbinitem.hxx>
      31             : #include <editeng/sizeitem.hxx>
      32             : #include <editeng/ulspitem.hxx>
      33             : #include <sfx2/printer.hxx>
      34             : #include <svl/itempool.hxx>
      35             : #include <svl/itemset.hxx>
      36             : #include <svl/smplhint.hxx>
      37             : #include "attrib.hxx"
      38             : 
      39             : 
      40             : #include <vcl/svapp.hxx>
      41             : 
      42             : #include "globstr.hrc"
      43             : #include "sc.hrc"
      44             : 
      45             : 
      46           0 : TYPEINIT1(ScStyleSheet, SfxStyleSheet);
      47             : 
      48             : #define TWO_CM      1134
      49             : #define HFDIST_CM   142
      50             : 
      51        3676 : ScStyleSheet::ScStyleSheet( const OUString&     rName,
      52             :                             ScStyleSheetPool&   rPoolP,
      53             :                             SfxStyleFamily      eFamily,
      54             :                             sal_uInt16          nMaskP )
      55             : 
      56             :     : SfxStyleSheet   ( rName, rPoolP, eFamily, nMaskP )
      57        3676 :     , eUsage( UNKNOWN )
      58             : {
      59        3676 : }
      60             : 
      61           0 : ScStyleSheet::ScStyleSheet( const ScStyleSheet& rStyle )
      62             :     : SfxStyleSheet ( rStyle )
      63           0 :     , eUsage( UNKNOWN )
      64             : {
      65           0 : }
      66             : 
      67        7036 : ScStyleSheet::~ScStyleSheet()
      68             : {
      69        7036 : }
      70             : 
      71           0 : bool ScStyleSheet::HasFollowSupport() const
      72             : {
      73           0 :     return false;
      74             : }
      75             : 
      76           0 : bool ScStyleSheet::HasParentSupport () const
      77             : {
      78           0 :     bool bHasParentSupport = false;
      79             : 
      80           0 :     switch ( GetFamily() )
      81             :     {
      82           0 :     case SFX_STYLE_FAMILY_PARA: bHasParentSupport = true;   break;
      83           0 :     case SFX_STYLE_FAMILY_PAGE: bHasParentSupport = false;  break;
      84             :     default:
      85             :         {
      86             :             // added to avoid warnings
      87             :         }
      88             :     }
      89             : 
      90           0 :     return bHasParentSupport;
      91             : }
      92             : 
      93        4779 : bool ScStyleSheet::SetParent( const OUString& rParentName )
      94             : {
      95        4779 :     bool bResult = false;
      96        4779 :     OUString aEffName = rParentName;
      97        4779 :     SfxStyleSheetBase* pStyle = pPool->Find( aEffName, nFamily );
      98        4779 :     if (!pStyle)
      99             :     {
     100         819 :         SfxStyleSheetIteratorPtr pIter = pPool->CreateIterator( nFamily, SFXSTYLEBIT_ALL );
     101         819 :         pStyle = pIter->First();
     102         819 :         if (pStyle)
     103         802 :             aEffName = pStyle->GetName();
     104             :     }
     105             : 
     106        4779 :     if ( pStyle && aEffName != GetName() )
     107             :     {
     108        4638 :         bResult = SfxStyleSheet::SetParent( aEffName );
     109        4638 :         if (bResult)
     110             :         {
     111        4638 :             SfxItemSet& rParentSet = pStyle->GetItemSet();
     112        4638 :             GetItemSet().SetParent( &rParentSet );
     113             : 
     114             :             // #i113491# Drag&Drop in the stylist's hierarchical view doesn't execute a slot,
     115             :             // so the repaint has to come from here (after modifying the ItemSet).
     116             :             // RepaintRange checks the document's IsVisible flag and locked repaints.
     117        4638 :             ScDocument* pDoc = static_cast<ScStyleSheetPool&>(GetPool()).GetDocument();
     118        4638 :             if (pDoc)
     119        4638 :                 pDoc->RepaintRange( ScRange( 0,0,0, MAXCOL,MAXROW,MAXTAB ) );
     120             :         }
     121             :     }
     122             : 
     123        4779 :     return bResult;
     124             : }
     125             : 
     126      598472 : SfxItemSet& ScStyleSheet::GetItemSet()
     127             : {
     128      598472 :     if ( !pSet )
     129             :     {
     130        3676 :         switch ( GetFamily() )
     131             :         {
     132             :             case SFX_STYLE_FAMILY_PAGE:
     133             :                 {
     134             :                     // Seitenvorlagen sollen nicht ableitbar sein,
     135             :                     // deshalb werden an dieser Stelle geeignete
     136             :                     // Werte eingestellt. (==Standard-Seitenvorlage)
     137             : 
     138        1062 :                     SfxItemPool& rItemPool = GetPool().GetPool();
     139             :                     pSet = new SfxItemSet( rItemPool,
     140             :                                            ATTR_BACKGROUND, ATTR_BACKGROUND,
     141             :                                            ATTR_BORDER, ATTR_SHADOW,
     142             :                                            ATTR_LRSPACE, ATTR_PAGE_SCALETO,
     143             :                                            ATTR_WRITINGDIR, ATTR_WRITINGDIR,
     144             :                                            ATTR_USERDEF, ATTR_USERDEF,
     145        1062 :                                            0 );
     146             : 
     147             :                     //  Wenn gerade geladen wird, wird auch der Set hinterher aus der Datei
     148             :                     //  gefuellt, es brauchen also keine Defaults gesetzt zu werden.
     149             :                     //  GetPrinter wuerde dann auch einen neuen Printer anlegen, weil der
     150             :                     //  gespeicherte Printer noch nicht geladen ist!
     151             : 
     152        1062 :                     ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
     153        1062 :                     if ( pDoc )
     154             :                     {
     155             :                         // Setzen von sinnvollen Default-Werten:
     156        1062 :                         SvxPageItem     aPageItem( ATTR_PAGE );
     157        2124 :                         SvxSizeItem     aPaperSizeItem( ATTR_PAGE_SIZE, SvxPaperInfo::GetDefaultPaperSize() );
     158             : 
     159             :                         SvxSetItem      aHFSetItem(
     160             :                                             (const SvxSetItem&)
     161        2124 :                                             rItemPool.GetDefaultItem(ATTR_PAGE_HEADERSET) );
     162             : 
     163        1062 :                         SfxItemSet&     rHFSet = aHFSetItem.GetItemSet();
     164             :                         SvxSizeItem     aHFSizeItem( // 0,5 cm + Abstand
     165             :                                             ATTR_PAGE_SIZE,
     166        2124 :                                             Size( 0, (long)( 500 / HMM_PER_TWIPS ) + HFDIST_CM ) );
     167             : 
     168             :                         SvxULSpaceItem  aHFDistItem ( HFDIST_CM,// nUp
     169             :                                                       HFDIST_CM,// nLow
     170        2124 :                                                       ATTR_ULSPACE );
     171             : 
     172             :                         SvxLRSpaceItem  aLRSpaceItem( TWO_CM,   // nLeft
     173             :                                                       TWO_CM,   // nRight
     174             :                                                       TWO_CM,   // nTLeft
     175             :                                                       0,        // nFirstLineOffset
     176        2124 :                                                       ATTR_LRSPACE );
     177             :                         SvxULSpaceItem  aULSpaceItem( TWO_CM,   // nUp
     178             :                                                       TWO_CM,   // nLow
     179        2124 :                                                       ATTR_ULSPACE );
     180        2124 :                         SvxBoxInfoItem  aBoxInfoItem( ATTR_BORDER_INNER );
     181             : 
     182        1062 :                         aBoxInfoItem.SetTable( false );
     183        1062 :                         aBoxInfoItem.SetDist( true );
     184        1062 :                         aBoxInfoItem.SetValid( VALID_DISTANCE, true );
     185             : 
     186        1062 :                         aPageItem.SetLandscape( false );
     187             : 
     188        1062 :                         rHFSet.Put( aBoxInfoItem );
     189        1062 :                         rHFSet.Put( aHFSizeItem );
     190        1062 :                         rHFSet.Put( aHFDistItem );
     191        1062 :                         rHFSet.Put( SvxLRSpaceItem( 0,0,0,0, ATTR_LRSPACE ) ); // Rand auf Null setzen
     192             : 
     193        1062 :                         pSet->Put( aHFSetItem, ATTR_PAGE_HEADERSET );
     194        1062 :                         pSet->Put( aHFSetItem, ATTR_PAGE_FOOTERSET );
     195        1062 :                         pSet->Put( aBoxInfoItem ); // PoolDefault wg. Formatvorlagen
     196             :                                                    // nicht ueberschreiben!
     197             : 
     198             :                         //  Writing direction: not as pool default because the default for cells
     199             :                         //  must remain FRMDIR_ENVIRONMENT, and each page style's setting is
     200             :                         //  supposed to be saved in the file format.
     201             :                         //  The page default depends on the system language.
     202        1062 :                         SvxFrameDirection eDirection = ScGlobal::IsSystemRTL() ?
     203        1062 :                                         FRMDIR_HORI_RIGHT_TOP : FRMDIR_HORI_LEFT_TOP;
     204        1062 :                         pSet->Put( SvxFrameDirectionItem( eDirection, ATTR_WRITINGDIR ), ATTR_WRITINGDIR );
     205             : 
     206        1062 :                         rItemPool.SetPoolDefaultItem( aPageItem );
     207        1062 :                         rItemPool.SetPoolDefaultItem( aPaperSizeItem );
     208        1062 :                         rItemPool.SetPoolDefaultItem( aLRSpaceItem );
     209        1062 :                         rItemPool.SetPoolDefaultItem( aULSpaceItem );
     210        1062 :                         rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALE, 100 ) );
     211        2124 :                         ScPageScaleToItem aScaleToItem;
     212        1062 :                         rItemPool.SetPoolDefaultItem( aScaleToItem );
     213        2124 :                         rItemPool.SetPoolDefaultItem( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, 0 ) );
     214             :                     }
     215             :                 }
     216        1062 :                 break;
     217             : 
     218             :             case SFX_STYLE_FAMILY_PARA:
     219             :             default:
     220        2614 :                 pSet = new SfxItemSet( GetPool().GetPool(), ATTR_PATTERN_START, ATTR_PATTERN_END );
     221        2614 :                 break;
     222             :         }
     223        3676 :         bMySet = true;
     224             :     }
     225      598472 :     if ( nHelpId == HID_SC_SHEET_CELL_ERG1 )
     226             :     {
     227        6453 :         if ( !pSet->Count() )
     228             :         {
     229         491 :             ScDocument* pDoc = ((ScStyleSheetPool&)GetPool()).GetDocument();
     230         491 :             if ( pDoc )
     231             :             {
     232         219 :                 sal_uLong nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( NUMBERFORMAT_CURRENCY,ScGlobal::eLnge );
     233         219 :                 pSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNumFmt ) );
     234             :             }
     235             :         }
     236             :     }
     237             : 
     238      598472 :     return *pSet;
     239             : }
     240             : 
     241          74 : bool ScStyleSheet::IsUsed() const
     242             : {
     243          74 :     if ( GetFamily() == SFX_STYLE_FAMILY_PARA )
     244             :     {
     245             :         // Always query the document to let it decide if a rescan is necessary,
     246             :         // and store the state.
     247           0 :         ScDocument* pDoc = ((ScStyleSheetPool*)pPool)->GetDocument();
     248           0 :         if ( pDoc && pDoc->IsStyleSheetUsed( *this, true ) )
     249           0 :             eUsage = USED;
     250             :         else
     251           0 :             eUsage = NOTUSED;
     252           0 :         return eUsage == USED;
     253             :     }
     254             :     else
     255          74 :         return true;
     256             : }
     257             : 
     258        4186 : void ScStyleSheet::Notify( SfxBroadcaster&, const SfxHint& rHint )
     259             : {
     260        4186 :     if ( rHint.ISA(SfxSimpleHint) )
     261        2093 :         if ( ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
     262        2093 :             GetItemSet().SetParent( NULL );
     263        4186 : }
     264             : 
     265             : //  schmutzige Tricks, um die Standard-Vorlage immer als "Standard" zu speichern,
     266             : //  obwohl der fuer den Benutzer sichtbare Name uebersetzt ist:
     267             : 
     268      821422 : const OUString& ScStyleSheet::GetName() const
     269             : {
     270      821422 :     const OUString& rBase = SfxStyleSheet::GetName();
     271      821422 :     const OUString* pForceStdName = ((ScStyleSheetPool*)pPool)->GetForceStdName();
     272      821422 :     if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
     273           0 :         return *pForceStdName;
     274             :     else
     275      821422 :         return rBase;
     276             : }
     277             : 
     278        5134 : const OUString& ScStyleSheet::GetParent() const
     279             : {
     280        5134 :     const OUString& rBase = SfxStyleSheet::GetParent();
     281        5134 :     const OUString* pForceStdName = ((ScStyleSheetPool*)pPool)->GetForceStdName();
     282        5134 :     if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
     283           0 :         return *pForceStdName;
     284             :     else
     285        5134 :         return rBase;
     286             : }
     287             : 
     288           0 : const OUString& ScStyleSheet::GetFollow() const
     289             : {
     290           0 :     const OUString& rBase = SfxStyleSheet::GetFollow();
     291           0 :     const OUString* pForceStdName = ((ScStyleSheetPool*)pPool)->GetForceStdName();
     292           0 :     if ( pForceStdName && rBase == ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
     293           0 :         return *pForceStdName;
     294             :     else
     295           0 :         return rBase;
     296             : }
     297             : 
     298             : //  Verhindern, dass ein Style "Standard" angelegt wird, wenn das nicht der
     299             : //  Standard-Name ist, weil sonst beim Speichern zwei Styles denselben Namen haetten
     300             : //  (Beim Laden wird der Style direkt per Make mit dem Namen erzeugt, so dass diese
     301             : //  Abfrage dann nicht gilt)
     302             : //! Wenn irgendwann aus dem Laden SetName aufgerufen wird, muss fuer das Laden ein
     303             : //! Flag gesetzt und abgefragt werden.
     304             : //! Die ganze Abfrage muss raus, wenn fuer eine neue Datei-Version die Namens-Umsetzung wegfaellt.
     305             : 
     306           0 : bool ScStyleSheet::SetName( const OUString& rNew )
     307             : {
     308           0 :     OUString aFileStdName = OUString(STRING_STANDARD);
     309           0 :     if ( rNew == aFileStdName && aFileStdName != ScGlobal::GetRscString(STR_STYLENAME_STANDARD) )
     310           0 :         return false;
     311             :     else
     312           0 :         return SfxStyleSheet::SetName( rNew );
     313             : }
     314             : 
     315             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10