LCOV - code coverage report
Current view: top level - sc/source/ui/undo - undostyl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 134 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 37 5.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 <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           0 : ScStyleSaveData::ScStyleSaveData() :
      38           0 :     pItems( NULL )
      39             : {
      40           0 : }
      41             : 
      42           0 : ScStyleSaveData::ScStyleSaveData( const ScStyleSaveData& rOther ) :
      43             :     aName( rOther.aName ),
      44           0 :     aParent( rOther.aParent )
      45             : {
      46           0 :     if (rOther.pItems)
      47           0 :         pItems = new SfxItemSet( *rOther.pItems );
      48             :     else
      49           0 :         pItems = NULL;
      50           0 : }
      51             : 
      52           0 : ScStyleSaveData::~ScStyleSaveData()
      53             : {
      54           0 :     delete pItems;
      55           0 : }
      56             : 
      57           0 : ScStyleSaveData& ScStyleSaveData::operator=( const ScStyleSaveData& rOther )
      58             : {
      59           0 :     aName   = rOther.aName;
      60           0 :     aParent = rOther.aParent;
      61             : 
      62           0 :     delete pItems;
      63           0 :     if (rOther.pItems)
      64           0 :         pItems = new SfxItemSet( *rOther.pItems );
      65             :     else
      66           0 :         pItems = NULL;
      67             : 
      68           0 :     return *this;
      69             : }
      70             : 
      71           0 : void ScStyleSaveData::InitFromStyle( const SfxStyleSheetBase* pSource )
      72             : {
      73           0 :     if ( pSource )
      74             :     {
      75           0 :         aName   = pSource->GetName();
      76           0 :         aParent = pSource->GetParent();
      77           0 :         delete pItems;
      78           0 :         pItems = new SfxItemSet( const_cast<SfxStyleSheetBase*>(pSource)->GetItemSet() );
      79             :     }
      80             :     else
      81           0 :         *this = ScStyleSaveData();      // empty
      82           0 : }
      83             : 
      84           0 : ScUndoModifyStyle::ScUndoModifyStyle( ScDocShell* pDocSh, SfxStyleFamily eFam,
      85             :                     const ScStyleSaveData& rOld, const ScStyleSaveData& rNew ) :
      86             :     ScSimpleUndo( pDocSh ),
      87             :     eFamily( eFam ),
      88             :     aOldData( rOld ),
      89           0 :     aNewData( rNew )
      90             : {
      91           0 : }
      92             : 
      93           0 : ScUndoModifyStyle::~ScUndoModifyStyle()
      94             : {
      95           0 : }
      96             : 
      97           0 : OUString ScUndoModifyStyle::GetComment() const
      98             : {
      99           0 :     sal_uInt16 nId = (eFamily == SFX_STYLE_FAMILY_PARA) ?
     100             :                                 STR_UNDO_EDITCELLSTYLE :
     101           0 :                                 STR_UNDO_EDITPAGESTYLE;
     102           0 :     return ScGlobal::GetRscString( nId );
     103             : }
     104             : 
     105           0 : static void lcl_DocStyleChanged( ScDocument* pDoc, SfxStyleSheetBase* pStyle, bool bRemoved )
     106             : {
     107             :     //! move to document or docshell
     108             : 
     109           0 :     ScopedVclPtrInstance< VirtualDevice > pVDev;
     110           0 :     Point aLogic = pVDev->LogicToPixel( Point(1000,1000), MAP_TWIP );
     111           0 :     double nPPTX = aLogic.X() / 1000.0;
     112           0 :     double nPPTY = aLogic.Y() / 1000.0;
     113           0 :     Fraction aZoom(1,1);
     114           0 :     pDoc->StyleSheetChanged( pStyle, bRemoved, pVDev, nPPTX, nPPTY, aZoom, aZoom );
     115             : 
     116           0 :     ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
     117           0 :     if (pHdl)
     118           0 :         pHdl->ForgetLastPattern();
     119           0 : }
     120             : 
     121           0 : void ScUndoModifyStyle::DoChange( ScDocShell* pDocSh, const OUString& rName,
     122             :                                     SfxStyleFamily eStyleFamily, const ScStyleSaveData& rData )
     123             : {
     124           0 :     ScDocument& rDoc = pDocSh->GetDocument();
     125           0 :     ScStyleSheetPool* pStlPool = rDoc.GetStyleSheetPool();
     126           0 :     OUString aNewName = rData.GetName();
     127           0 :     bool bDelete = aNewName.isEmpty();         // no new name -> delete style
     128           0 :     bool bNew = ( rName.isEmpty() && !bDelete );   // creating new style
     129             : 
     130           0 :     SfxStyleSheetBase* pStyle = NULL;
     131           0 :     if ( !rName.isEmpty() )
     132             :     {
     133             :         // find old style to modify
     134           0 :         pStyle = pStlPool->Find( rName, eStyleFamily );
     135             :         OSL_ENSURE( pStyle, "style not found" );
     136             : 
     137           0 :         if ( pStyle && !bDelete )
     138             :         {
     139             :             // set new name
     140           0 :             pStyle->SetName( aNewName );
     141             :         }
     142             :     }
     143           0 :     else if ( !bDelete )
     144             :     {
     145             :         // create style (with new name)
     146           0 :         pStyle = &pStlPool->Make( aNewName, eStyleFamily, SFXSTYLEBIT_USERDEF );
     147             : 
     148           0 :         if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
     149           0 :             rDoc.GetPool()->CellStyleCreated( aNewName, &rDoc );
     150             :     }
     151             : 
     152           0 :     if ( pStyle )
     153             :     {
     154           0 :         if ( bDelete )
     155             :         {
     156           0 :             if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
     157           0 :                 lcl_DocStyleChanged( &rDoc, pStyle, true );      // TRUE: remove usage of style
     158             :             else
     159           0 :                 rDoc.RemovePageStyleInUse( rName );
     160             : 
     161             :             // delete style
     162           0 :             pStlPool->Remove( pStyle );
     163             :         }
     164             :         else
     165             :         {
     166             :             // modify style
     167             : 
     168           0 :             OUString aNewParent = rData.GetParent();
     169           0 :             if ( aNewParent != pStyle->GetParent() )
     170           0 :                 pStyle->SetParent( aNewParent );
     171             : 
     172           0 :             SfxItemSet& rStyleSet = pStyle->GetItemSet();
     173           0 :             const SfxItemSet* pNewSet = rData.GetItems();
     174             :             OSL_ENSURE( pNewSet, "no ItemSet for style" );
     175           0 :             if (pNewSet)
     176           0 :                 rStyleSet.Set( *pNewSet, false );
     177             : 
     178           0 :             if ( eStyleFamily == SFX_STYLE_FAMILY_PARA )
     179             :             {
     180           0 :                 lcl_DocStyleChanged( &rDoc, pStyle, false );     // cell styles: row heights
     181             :             }
     182             :             else
     183             :             {
     184             :                 // page styles
     185             : 
     186           0 :                 if ( bNew && aNewName != rName )
     187           0 :                     rDoc.RenamePageStyleInUse( rName, aNewName );
     188             : 
     189           0 :                 if (pNewSet)
     190           0 :                     rDoc.ModifyStyleSheet( *pStyle, *pNewSet );
     191             : 
     192           0 :                 pDocSh->PageStyleModified( aNewName, true );
     193           0 :             }
     194             :         }
     195             :     }
     196             : 
     197           0 :     pDocSh->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT );
     198             : 
     199             :     //! undo/redo document modifications for deleted styles
     200             :     //! undo/redo modifications of number formatter
     201           0 : }
     202             : 
     203           0 : void ScUndoModifyStyle::Undo()
     204             : {
     205           0 :     BeginUndo();
     206           0 :     DoChange( pDocShell, aNewData.GetName(), eFamily, aOldData );
     207           0 :     EndUndo();
     208           0 : }
     209             : 
     210           0 : void ScUndoModifyStyle::Redo()
     211             : {
     212           0 :     BeginRedo();
     213           0 :     DoChange( pDocShell, aOldData.GetName(), eFamily, aNewData );
     214           0 :     EndRedo();
     215           0 : }
     216             : 
     217           0 : void ScUndoModifyStyle::Repeat(SfxRepeatTarget& /* rTarget */)
     218             : {
     219           0 : }
     220             : 
     221           0 : bool ScUndoModifyStyle::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     222             : {
     223           0 :     return false;       // no repeat possible
     224             : }
     225             : 
     226             : //      apply page style
     227             : 
     228           0 : ScUndoApplyPageStyle::ApplyStyleEntry::ApplyStyleEntry( SCTAB nTab, const OUString& rOldStyle ) :
     229             :     mnTab( nTab ),
     230           0 :     maOldStyle( rOldStyle )
     231             : {
     232           0 : }
     233             : 
     234           0 : ScUndoApplyPageStyle::ScUndoApplyPageStyle( ScDocShell* pDocSh, const OUString& rNewStyle ) :
     235             :     ScSimpleUndo( pDocSh ),
     236           0 :     maNewStyle( rNewStyle )
     237             : {
     238           0 : }
     239             : 
     240           0 : ScUndoApplyPageStyle::~ScUndoApplyPageStyle()
     241             : {
     242           0 : }
     243             : 
     244           0 : void ScUndoApplyPageStyle::AddSheetAction( SCTAB nTab, const OUString& rOldStyle )
     245             : {
     246           0 :     maEntries.push_back( ApplyStyleEntry( nTab, rOldStyle ) );
     247           0 : }
     248             : 
     249           0 : OUString ScUndoApplyPageStyle::GetComment() const
     250             : {
     251           0 :     return ScGlobal::GetRscString( STR_UNDO_APPLYPAGESTYLE );
     252             : }
     253             : 
     254           0 : void ScUndoApplyPageStyle::Undo()
     255             : {
     256           0 :     BeginUndo();
     257           0 :     for( ApplyStyleVec::const_iterator aIt = maEntries.begin(), aEnd = maEntries.end(); aIt != aEnd; ++aIt )
     258             :     {
     259           0 :         pDocShell->GetDocument().SetPageStyle( aIt->mnTab, aIt->maOldStyle );
     260           0 :         ScPrintFunc( pDocShell, pDocShell->GetPrinter(), aIt->mnTab ).UpdatePages();
     261             :     }
     262           0 :     EndUndo();
     263           0 : }
     264             : 
     265           0 : void ScUndoApplyPageStyle::Redo()
     266             : {
     267           0 :     BeginRedo();
     268           0 :     for( ApplyStyleVec::const_iterator aIt = maEntries.begin(), aEnd = maEntries.end(); aIt != aEnd; ++aIt )
     269             :     {
     270           0 :         pDocShell->GetDocument().SetPageStyle( aIt->mnTab, maNewStyle );
     271           0 :         ScPrintFunc( pDocShell, pDocShell->GetPrinter(), aIt->mnTab ).UpdatePages();
     272             :     }
     273           0 :     EndRedo();
     274           0 : }
     275             : 
     276           0 : void ScUndoApplyPageStyle::Repeat(SfxRepeatTarget& /* rTarget */)
     277             : {
     278             :     //! set same page style to current tab
     279           0 : }
     280             : 
     281           0 : bool ScUndoApplyPageStyle::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     282             : {
     283           0 :     return false;
     284         156 : }
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11