LCOV - code coverage report
Current view: top level - sc/source/ui/undo - undostyl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 132 0.0 %
Date: 2012-08-25 Functions: 0 35 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 212 0.0 %

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

Generated by: LCOV version 1.10