LCOV - code coverage report
Current view: top level - sc/source/ui/undo - undostyl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 133 0.0 %
Date: 2014-04-14 Functions: 0 35 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svl/itemset.hxx>
      21             : #include <vcl/virdev.hxx>
      22             : 
      23             : #include "undostyl.hxx"
      24             : #include "docsh.hxx"
      25             : #include "docpool.hxx"
      26             : #include "stlpool.hxx"
      27             : #include "printfun.hxx"
      28             : #include "scmod.hxx"
      29             : #include "inputhdl.hxx"
      30             : #include "globstr.hrc"
      31             : 
      32           0 : TYPEINIT1(ScUndoModifyStyle, ScSimpleUndo);
      33           0 : TYPEINIT1(ScUndoApplyPageStyle, ScSimpleUndo);
      34             : 
      35             : //      modify style (cell or page style)
      36             : 
      37             : 
      38           0 : ScStyleSaveData::ScStyleSaveData() :
      39           0 :     pItems( NULL )
      40             : {
      41           0 : }
      42             : 
      43           0 : ScStyleSaveData::ScStyleSaveData( const ScStyleSaveData& rOther ) :
      44             :     aName( rOther.aName ),
      45           0 :     aParent( rOther.aParent )
      46             : {
      47           0 :     if (rOther.pItems)
      48           0 :         pItems = new SfxItemSet( *rOther.pItems );
      49             :     else
      50           0 :         pItems = NULL;
      51           0 : }
      52             : 
      53           0 : ScStyleSaveData::~ScStyleSaveData()
      54             : {
      55           0 :     delete pItems;
      56           0 : }
      57             : 
      58           0 : ScStyleSaveData& ScStyleSaveData::operator=( const ScStyleSaveData& rOther )
      59             : {
      60           0 :     aName   = rOther.aName;
      61           0 :     aParent = rOther.aParent;
      62             : 
      63           0 :     delete pItems;
      64           0 :     if (rOther.pItems)
      65           0 :         pItems = new SfxItemSet( *rOther.pItems );
      66             :     else
      67           0 :         pItems = NULL;
      68             : 
      69           0 :     return *this;
      70             : }
      71             : 
      72           0 : void ScStyleSaveData::InitFromStyle( const SfxStyleSheetBase* pSource )
      73             : {
      74           0 :     if ( pSource )
      75             :     {
      76           0 :         aName   = pSource->GetName();
      77           0 :         aParent = pSource->GetParent();
      78           0 :         delete pItems;
      79           0 :         pItems = new SfxItemSet( ((SfxStyleSheetBase*)pSource)->GetItemSet() );
      80             :     }
      81             :     else
      82           0 :         *this = ScStyleSaveData();      // empty
      83           0 : }
      84             : 
      85           0 : ScUndoModifyStyle::ScUndoModifyStyle( ScDocShell* pDocSh, SfxStyleFamily eFam,
      86             :                     const ScStyleSaveData& rOld, const ScStyleSaveData& rNew ) :
      87             :     ScSimpleUndo( pDocSh ),
      88             :     eFamily( eFam ),
      89             :     aOldData( rOld ),
      90           0 :     aNewData( rNew )
      91             : {
      92           0 : }
      93             : 
      94           0 : ScUndoModifyStyle::~ScUndoModifyStyle()
      95             : {
      96           0 : }
      97             : 
      98           0 : OUString ScUndoModifyStyle::GetComment() const
      99             : {
     100           0 :     sal_uInt16 nId = (eFamily == SFX_STYLE_FAMILY_PARA) ?
     101             :                                 STR_UNDO_EDITCELLSTYLE :
     102           0 :                                 STR_UNDO_EDITPAGESTYLE;
     103           0 :     return ScGlobal::GetRscString( nId );
     104             : }
     105             : 
     106           0 : static void lcl_DocStyleChanged( ScDocument* pDoc, SfxStyleSheetBase* pStyle, sal_Bool bRemoved )
     107             : {
     108             :     //! move to document or docshell
     109             : 
     110           0 :     VirtualDevice aVDev;
     111           0 :     Point aLogic = aVDev.LogicToPixel( Point(1000,1000), MAP_TWIP );
     112           0 :     double nPPTX = aLogic.X() / 1000.0;
     113           0 :     double nPPTY = aLogic.Y() / 1000.0;
     114           0 :     Fraction aZoom(1,1);
     115           0 :     pDoc->StyleSheetChanged( pStyle, bRemoved, &aVDev, nPPTX, nPPTY, aZoom, aZoom );
     116             : 
     117           0 :     ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
     118           0 :     if (pHdl)
     119           0 :         pHdl->ForgetLastPattern();
     120           0 : }
     121             : 
     122           0 : void ScUndoModifyStyle::DoChange( ScDocShell* pDocSh, const OUString& rName,
     123             :                                     SfxStyleFamily eStyleFamily, const ScStyleSaveData& rData )
     124             : {
     125           0 :     ScDocument* pDoc = pDocSh->GetDocument();
     126           0 :     ScStyleSheetPool* pStlPool = pDoc->GetStyleSheetPool();
     127           0 :     OUString aNewName = rData.GetName();
     128           0 :     sal_Bool bDelete = aNewName.isEmpty();         // no new name -> delete style
     129           0 :     sal_Bool bNew = ( rName.isEmpty() && !bDelete );   // creating new style
     130             : 
     131           0 :     SfxStyleSheetBase* pStyle = NULL;
     132           0 :     if ( !rName.isEmpty() )
     133             :     {
     134             :         // find old style to modify
     135           0 :         pStyle = pStlPool->Find( rName, eStyleFamily );
     136             :         OSL_ENSURE( pStyle, "style not found" );
     137             : 
     138           0 :         if ( pStyle && !bDelete )
     139             :         {
     140             :             // set new name
     141           0 :             pStyle->SetName( aNewName );
     142             :         }
     143             :     }
     144           0 :     else if ( !bDelete )
     145             :     {
     146             :         // create style (with new name)
     147           0 :         pStyle = &pStlPool->Make( aNewName, eStyleFamily, SFXSTYLEBIT_USERDEF );
     148             : 
     149           0 :         if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
     150           0 :             pDoc->GetPool()->CellStyleCreated( aNewName );
     151             :     }
     152             : 
     153           0 :     if ( pStyle )
     154             :     {
     155           0 :         if ( bDelete )
     156             :         {
     157           0 :             if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
     158           0 :                 lcl_DocStyleChanged( pDoc, pStyle, sal_True );      // TRUE: remove usage of style
     159             :             else
     160           0 :                 pDoc->RemovePageStyleInUse( rName );
     161             : 
     162             :             // delete style
     163           0 :             pStlPool->Remove( pStyle );
     164             :         }
     165             :         else
     166             :         {
     167             :             // modify style
     168             : 
     169           0 :             OUString aNewParent = rData.GetParent();
     170           0 :             if ( aNewParent != pStyle->GetParent() )
     171           0 :                 pStyle->SetParent( aNewParent );
     172             : 
     173           0 :             SfxItemSet& rStyleSet = pStyle->GetItemSet();
     174           0 :             const SfxItemSet* pNewSet = rData.GetItems();
     175             :             OSL_ENSURE( pNewSet, "no ItemSet for style" );
     176           0 :             if (pNewSet)
     177           0 :                 rStyleSet.Set( *pNewSet, false );
     178             : 
     179           0 :             if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
     180             :             {
     181           0 :                 lcl_DocStyleChanged( pDoc, pStyle, false );     // cell styles: row heights
     182             :             }
     183             :             else
     184             :             {
     185             :                 // page styles
     186             : 
     187           0 :                 if ( bNew && aNewName != rName )
     188           0 :                     pDoc->RenamePageStyleInUse( rName, aNewName );
     189             : 
     190           0 :                 if (pNewSet)
     191           0 :                     pDoc->ModifyStyleSheet( *pStyle, *pNewSet );
     192             : 
     193           0 :                 pDocSh->PageStyleModified( aNewName, true );
     194           0 :             }
     195             :         }
     196             :     }
     197             : 
     198           0 :     pDocSh->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT );
     199             : 
     200             :     //! undo/redo document modifications for deleted styles
     201             :     //! undo/redo modifications of number formatter
     202           0 : }
     203             : 
     204           0 : void ScUndoModifyStyle::Undo()
     205             : {
     206           0 :     BeginUndo();
     207           0 :     DoChange( pDocShell, aNewData.GetName(), eFamily, aOldData );
     208           0 :     EndUndo();
     209           0 : }
     210             : 
     211           0 : void ScUndoModifyStyle::Redo()
     212             : {
     213           0 :     BeginRedo();
     214           0 :     DoChange( pDocShell, aOldData.GetName(), eFamily, aNewData );
     215           0 :     EndRedo();
     216           0 : }
     217             : 
     218           0 : void ScUndoModifyStyle::Repeat(SfxRepeatTarget& /* rTarget */)
     219             : {
     220           0 : }
     221             : 
     222           0 : bool ScUndoModifyStyle::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     223             : {
     224           0 :     return false;       // no repeat possible
     225             : }
     226             : 
     227             : //      apply page style
     228             : 
     229           0 : ScUndoApplyPageStyle::ApplyStyleEntry::ApplyStyleEntry( SCTAB nTab, const OUString& rOldStyle ) :
     230             :     mnTab( nTab ),
     231           0 :     maOldStyle( rOldStyle )
     232             : {
     233           0 : }
     234             : 
     235           0 : ScUndoApplyPageStyle::ScUndoApplyPageStyle( ScDocShell* pDocSh, const OUString& rNewStyle ) :
     236             :     ScSimpleUndo( pDocSh ),
     237           0 :     maNewStyle( rNewStyle )
     238             : {
     239           0 : }
     240             : 
     241           0 : ScUndoApplyPageStyle::~ScUndoApplyPageStyle()
     242             : {
     243           0 : }
     244             : 
     245           0 : void ScUndoApplyPageStyle::AddSheetAction( SCTAB nTab, const OUString& rOldStyle )
     246             : {
     247           0 :     maEntries.push_back( ApplyStyleEntry( nTab, rOldStyle ) );
     248           0 : }
     249             : 
     250           0 : OUString ScUndoApplyPageStyle::GetComment() const
     251             : {
     252           0 :     return ScGlobal::GetRscString( STR_UNDO_APPLYPAGESTYLE );
     253             : }
     254             : 
     255           0 : void ScUndoApplyPageStyle::Undo()
     256             : {
     257           0 :     BeginUndo();
     258           0 :     for( ApplyStyleVec::const_iterator aIt = maEntries.begin(), aEnd = maEntries.end(); aIt != aEnd; ++aIt )
     259             :     {
     260           0 :         pDocShell->GetDocument()->SetPageStyle( aIt->mnTab, aIt->maOldStyle );
     261           0 :         ScPrintFunc( pDocShell, pDocShell->GetPrinter(), aIt->mnTab ).UpdatePages();
     262             :     }
     263           0 :     EndUndo();
     264           0 : }
     265             : 
     266           0 : void ScUndoApplyPageStyle::Redo()
     267             : {
     268           0 :     BeginRedo();
     269           0 :     for( ApplyStyleVec::const_iterator aIt = maEntries.begin(), aEnd = maEntries.end(); aIt != aEnd; ++aIt )
     270             :     {
     271           0 :         pDocShell->GetDocument()->SetPageStyle( aIt->mnTab, maNewStyle );
     272           0 :         ScPrintFunc( pDocShell, pDocShell->GetPrinter(), aIt->mnTab ).UpdatePages();
     273             :     }
     274           0 :     EndRedo();
     275           0 : }
     276             : 
     277           0 : void ScUndoApplyPageStyle::Repeat(SfxRepeatTarget& /* rTarget */)
     278             : {
     279             :     //! set same page style to current tab
     280           0 : }
     281             : 
     282           0 : bool ScUndoApplyPageStyle::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     283             : {
     284           0 :     return false;
     285             : }
     286             : 
     287             : 
     288             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10