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

Generated by: LCOV version 1.10