LCOV - code coverage report
Current view: top level - sw/source/core/edit - edundo.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 62 95 65.3 %
Date: 2014-11-03 Functions: 6 8 75.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 <svx/svdview.hxx>
      21             : 
      22             : #include <editsh.hxx>
      23             : #include <fesh.hxx>
      24             : #include <doc.hxx>
      25             : #include <IDocumentUndoRedo.hxx>
      26             : #include <IDocumentContentOperations.hxx>
      27             : #include <IDocumentRedlineAccess.hxx>
      28             : #include <pam.hxx>
      29             : #include <UndoCore.hxx>
      30             : #include <swundo.hxx>
      31             : #include <dcontact.hxx>
      32             : #include <flyfrm.hxx>
      33             : #include <frmfmt.hxx>
      34             : #include <viewimp.hxx>
      35             : #include <docsh.hxx>
      36             : #include <pagefrm.hxx>
      37             : 
      38             : /** helper function to select all objects in an SdrMarkList;
      39             :  * implementation: see below */
      40             : static void lcl_SelectSdrMarkList( SwEditShell* pShell,
      41             :                             const SdrMarkList* pSdrMarkList );
      42             : 
      43         112 : bool SwEditShell::CursorsLocked() const
      44             : {
      45         112 :     return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked();
      46             : }
      47             : 
      48          52 : void SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext)
      49             : {
      50             :     // do nothing if somebody has locked controllers!
      51          52 :     if (CursorsLocked())
      52             :     {
      53          52 :         return;
      54             :     }
      55             : 
      56          52 :     SwFrmFmt * pSelFmt(0);
      57          52 :     SdrMarkList * pMarkList(0);
      58          52 :     rContext.GetSelections(pSelFmt, pMarkList);
      59             : 
      60          52 :     if (pSelFmt) // select frame
      61             :     {
      62           0 :         if (RES_DRAWFRMFMT == pSelFmt->Which())
      63             :         {
      64           0 :             SdrObject* pSObj = pSelFmt->FindSdrObject();
      65             :             static_cast<SwFEShell*>(this)->SelectObj(
      66           0 :                     pSObj->GetCurrentBoundRect().Center() );
      67             :         }
      68             :         else
      69             :         {
      70           0 :             Point aPt;
      71             :             SwFlyFrm *const pFly =
      72           0 :                 static_cast<SwFlyFrmFmt*>(pSelFmt)->GetFrm(& aPt, false);
      73           0 :             if (pFly)
      74             :             {
      75             :                 // fdo#36681: Invalidate the content and layout to refresh
      76             :                 // the picture anchoring properly
      77           0 :                 SwPageFrm* pPageFrm = pFly->FindPageFrmOfAnchor();
      78           0 :                 pPageFrm->InvalidateFlyLayout();
      79           0 :                 pPageFrm->InvalidateCntnt();
      80             : 
      81           0 :                 static_cast<SwFEShell*>(this)->SelectFlyFrm(*pFly, true);
      82             :             }
      83             :         }
      84             :     }
      85          52 :     else if (pMarkList)
      86             :     {
      87           0 :         lcl_SelectSdrMarkList( this, pMarkList );
      88             :     }
      89          52 :     else if (GetCrsr()->GetNext() != GetCrsr())
      90             :     {
      91             :         // current cursor is the last one:
      92             :         // go around the ring, to the first cursor
      93           0 :         GoNextCrsr();
      94             :     }
      95             : }
      96             : 
      97           6 : bool SwEditShell::Undo(sal_uInt16 const nCount)
      98             : {
      99           6 :     SET_CURR_SHELL( this );
     100             : 
     101             :     // current undo state was not saved
     102          12 :     ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
     103           6 :     bool bRet = false;
     104             : 
     105           6 :     StartAllAction();
     106             :     {
     107             :         // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
     108             :         // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
     109           6 :         KillPams();
     110           6 :         SetMark();          // Bound1 and Bound2 in the same Node
     111           6 :         ClearMark();
     112             : 
     113             :         // Keep Cursor - so that we're able to set it at
     114             :         // the same position for autoformat or autocorrection
     115           6 :         SwUndoId nLastUndoId(UNDO_EMPTY);
     116           6 :         GetLastUndoInfo(0, & nLastUndoId);
     117             :         const bool bRestoreCrsr = nCount == 1
     118           6 :                                   && ( UNDO_AUTOFORMAT == nLastUndoId
     119           6 :                                        || UNDO_AUTOCORRECT == nLastUndoId
     120          12 :                                        || UNDO_SETDEFTATTR == nLastUndoId );
     121           6 :         Push();
     122             : 
     123             :         // Destroy stored TableBoxPtr. A dection is only permitted for the new "Box"!
     124           6 :         ClearTblBoxCntnt();
     125             : 
     126           6 :         const RedlineMode_t eOld = GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
     127             : 
     128             :         try {
     129          10 :             for (sal_uInt16 i = 0; i < nCount; ++i)
     130             :             {
     131           6 :                 bRet = GetDoc()->GetIDocumentUndoRedo().Undo()
     132           4 :                     || bRet;
     133             :             }
     134           2 :         } catch (const ::com::sun::star::uno::Exception & e) {
     135             :             OSL_TRACE("SwEditShell::Undo(): exception caught:\n %s",
     136             :                 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
     137             :                     .getStr());
     138             :         }
     139             : 
     140           6 :         if (bRestoreCrsr)
     141             :         {   // fdo#39003 Pop does not touch the rest of the cursor ring
     142           0 :             KillPams(); // so call this first to get rid of unwanted cursors
     143             :         }
     144           6 :         Pop( !bRestoreCrsr );
     145             : 
     146           6 :         GetDoc()->getIDocumentRedlineAccess().SetRedlineMode( eOld );
     147           6 :         GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
     148             : 
     149             :         // automatic detection of the new "Box"
     150           6 :         SaveTblBoxCntnt();
     151             :     }
     152           6 :     EndAllAction();
     153             : 
     154          12 :     return bRet;
     155             : }
     156             : 
     157           2 : bool SwEditShell::Redo(sal_uInt16 const nCount)
     158             : {
     159           2 :     SET_CURR_SHELL( this );
     160             : 
     161           2 :     bool bRet = false;
     162             : 
     163             :     // undo state was not saved
     164           4 :     ::sw::UndoGuard const undoGuard(GetDoc()->GetIDocumentUndoRedo());
     165             : 
     166           2 :     StartAllAction();
     167             : 
     168             :     {
     169             :         // Actually it should be enough to just work on the current Cursor, i.e. if there is a cycle
     170             :         // cancel the latter temporarily, so that an insert during Undo is not done in all areas.
     171           2 :         KillPams();
     172           2 :         SetMark();          // Bound1 and Bound2 in the same Node
     173           2 :         ClearMark();
     174             : 
     175           2 :         SwUndoId nFirstRedoId(UNDO_EMPTY);
     176           2 :         GetDoc()->GetIDocumentUndoRedo().GetFirstRedoInfo(0, & nFirstRedoId);
     177           2 :         const bool bRestoreCrsr = nCount == 1 && UNDO_SETDEFTATTR == nFirstRedoId;
     178           2 :         Push();
     179             : 
     180             :         // Destroy stored TableBoxPtr. A dection is only permitted for the new "Box"!
     181           2 :         ClearTblBoxCntnt();
     182             : 
     183           2 :         RedlineMode_t eOld = GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
     184             : 
     185             :         try {
     186           2 :             for (sal_uInt16 i = 0; i < nCount; ++i)
     187             :             {
     188           2 :                 bRet = GetDoc()->GetIDocumentUndoRedo().Redo()
     189           0 :                     || bRet;
     190             :             }
     191           2 :         } catch (const ::com::sun::star::uno::Exception & e) {
     192             :             OSL_TRACE("SwEditShell::Redo(): exception caught:\n %s",
     193             :                 OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
     194             :                     .getStr());
     195             :         }
     196             : 
     197           2 :         Pop( !bRestoreCrsr );
     198             : 
     199           2 :         GetDoc()->getIDocumentRedlineAccess().SetRedlineMode( eOld );
     200           2 :         GetDoc()->getIDocumentRedlineAccess().CompressRedlines();
     201             : 
     202             :         // automatic detection of the new "Box"
     203           2 :         SaveTblBoxCntnt();
     204             :     }
     205             : 
     206           2 :     EndAllAction();
     207             : 
     208           4 :     return bRet;
     209             : }
     210             : 
     211           0 : bool SwEditShell::Repeat(sal_uInt16 const nCount)
     212             : {
     213           0 :     SET_CURR_SHELL( this );
     214             : 
     215           0 :     bool bRet = false;
     216           0 :     StartAllAction();
     217             : 
     218             :     try {
     219           0 :         ::sw::RepeatContext context(*GetDoc(), *GetCrsr());
     220           0 :         bRet = GetDoc()->GetIDocumentUndoRedo().Repeat( context, nCount )
     221           0 :             || bRet;
     222           0 :     } catch (const ::com::sun::star::uno::Exception & e) {
     223             :         OSL_TRACE("SwEditShell::Repeat(): exception caught:\n %s",
     224             :             OUStringToOString(e.Message, RTL_TEXTENCODING_UTF8)
     225             :                 .getStr());
     226             :     }
     227             : 
     228           0 :     EndAllAction();
     229           0 :     return bRet;
     230             : }
     231             : 
     232           0 : static void lcl_SelectSdrMarkList( SwEditShell* pShell,
     233             :                             const SdrMarkList* pSdrMarkList )
     234             : {
     235             :     OSL_ENSURE( pShell != NULL, "need shell!" );
     236             :     OSL_ENSURE( pSdrMarkList != NULL, "need mark list" );
     237             : 
     238           0 :     if( pShell->ISA( SwFEShell ) )
     239             :     {
     240           0 :         SwFEShell* pFEShell = static_cast<SwFEShell*>( pShell );
     241           0 :         bool bFirst = true;
     242           0 :         for( size_t i = 0; i < pSdrMarkList->GetMarkCount(); ++i )
     243             :         {
     244           0 :             SdrObject *pObj = pSdrMarkList->GetMark( i )->GetMarkedSdrObj();
     245           0 :             if( pObj )
     246             :             {
     247           0 :                 pFEShell->SelectObj( Point(), bFirst ? 0 : SW_ADD_SELECT, pObj );
     248           0 :                 bFirst = false;
     249             :             }
     250             :         }
     251             : 
     252             :         // the old implementation would always unselect
     253             :         // objects, even if no new ones were selected. If this
     254             :         // is a problem, we need to re-work this a little.
     255             :         OSL_ENSURE( pSdrMarkList->GetMarkCount() != 0, "empty mark list" );
     256             :     }
     257         270 : }
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10