LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - singledoccontroller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 20 64 31.2 %
Date: 2015-06-13 12:38:46 Functions: 9 15 60.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 <dbaccess/dbaundomanager.hxx>
      21             : #include <dbaccess/dataview.hxx>
      22             : #include "singledoccontroller.hxx"
      23             : #include "browserids.hxx"
      24             : #include "dbu_misc.hrc"
      25             : #include "dbustrings.hrc"
      26             : #include "moduledbu.hxx"
      27             : 
      28             : #include <svl/undo.hxx>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <osl/diagnose.h>
      31             : 
      32             : #include <boost/scoped_ptr.hpp>
      33             : 
      34             : namespace dbaui
      35             : {
      36             : 
      37             :     using ::com::sun::star::uno::Reference;
      38             :     using ::com::sun::star::uno::XInterface;
      39             :     using ::com::sun::star::uno::UNO_QUERY;
      40             :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      41             :     using ::com::sun::star::uno::UNO_SET_THROW;
      42             :     using ::com::sun::star::uno::Exception;
      43             :     using ::com::sun::star::uno::RuntimeException;
      44             :     using ::com::sun::star::uno::Any;
      45             :     using ::com::sun::star::uno::makeAny;
      46             :     using ::com::sun::star::uno::Sequence;
      47             :     using ::com::sun::star::uno::Type;
      48             :     using ::com::sun::star::uno::XComponentContext;
      49             :     using ::com::sun::star::document::XUndoManager;
      50             :     using ::com::sun::star::lang::XMultiServiceFactory;
      51             :     using ::com::sun::star::beans::PropertyValue;
      52             :     using ::com::sun::star::lang::EventObject;
      53             : 
      54             :     // OSingleDocumentController_Data
      55           3 :     struct OSingleDocumentController_Data
      56             :     {
      57             :         ::boost::scoped_ptr< UndoManager >  m_pUndoManager;
      58             : 
      59           3 :         OSingleDocumentController_Data( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex )
      60           3 :             :m_pUndoManager( new UndoManager( i_parent, i_mutex ) )
      61             :         {
      62           3 :         }
      63             :     };
      64             : 
      65             :     // OSingleDocumentController
      66           3 :     OSingleDocumentController::OSingleDocumentController( const Reference< XComponentContext >& _rxORB )
      67             :         :OSingleDocumentController_Base( _rxORB )
      68           3 :         ,m_pData( new OSingleDocumentController_Data( *this, getMutex() ) )
      69             :     {
      70           3 :     }
      71             : 
      72           3 :     OSingleDocumentController::~OSingleDocumentController()
      73             :     {
      74           3 :     }
      75             : 
      76           3 :     void SAL_CALL OSingleDocumentController::disposing()
      77             :     {
      78           3 :         OSingleDocumentController_Base::disposing();
      79           3 :         ClearUndoManager();
      80           3 :         m_pData->m_pUndoManager->disposing();
      81           3 :     }
      82             : 
      83           0 :     void SAL_CALL OSingleDocumentController::disposing( const EventObject& i_event ) throw( RuntimeException, std::exception )
      84             :     {
      85             :         // simply disambiguate
      86           0 :         OSingleDocumentController_Base::disposing( i_event );
      87           0 :     }
      88             : 
      89           3 :     void OSingleDocumentController::ClearUndoManager()
      90             :     {
      91           3 :         GetUndoManager().Clear();
      92           3 :     }
      93             : 
      94           3 :     SfxUndoManager& OSingleDocumentController::GetUndoManager() const
      95             :     {
      96           3 :         return m_pData->m_pUndoManager->GetSfxUndoManager();
      97             :     }
      98             : 
      99           0 :     void OSingleDocumentController::addUndoActionAndInvalidate(SfxUndoAction *_pAction)
     100             :     {
     101             :         // add undo action
     102           0 :         GetUndoManager().AddUndoAction( _pAction );
     103             : 
     104             :         // when we add an undo action the controller was modified
     105           0 :         setModified( sal_True );
     106             : 
     107             :         // now inform me that or states changed
     108           0 :         InvalidateFeature( ID_BROWSER_UNDO );
     109           0 :         InvalidateFeature( ID_BROWSER_REDO );
     110           0 :     }
     111             : 
     112           0 :     Reference< XUndoManager > SAL_CALL OSingleDocumentController::getUndoManager(  ) throw (RuntimeException, std::exception)
     113             :     {
     114           0 :         return m_pData->m_pUndoManager.get();
     115             :     }
     116             : 
     117           0 :     FeatureState OSingleDocumentController::GetState(sal_uInt16 _nId) const
     118             :     {
     119           0 :         FeatureState aReturn;
     120           0 :         switch ( _nId )
     121             :         {
     122             :             case ID_BROWSER_UNDO:
     123           0 :                 aReturn.bEnabled = isEditable() && GetUndoManager().GetUndoActionCount() != 0;
     124           0 :                 if ( aReturn.bEnabled )
     125             :                 {
     126           0 :                     OUString sUndo(ModuleRes(STR_UNDO_COLON));
     127           0 :                     sUndo += " ";
     128           0 :                     sUndo += GetUndoManager().GetUndoActionComment();
     129           0 :                     aReturn.sTitle = sUndo;
     130             :                 }
     131           0 :                 break;
     132             : 
     133             :             case ID_BROWSER_REDO:
     134           0 :                 aReturn.bEnabled = isEditable() && GetUndoManager().GetRedoActionCount() != 0;
     135           0 :                 if ( aReturn.bEnabled )
     136             :                 {
     137           0 :                     OUString sRedo(ModuleRes(STR_REDO_COLON));
     138           0 :                     sRedo += " ";
     139           0 :                     sRedo += GetUndoManager().GetRedoActionComment();
     140           0 :                     aReturn.sTitle = sRedo;
     141             :                 }
     142           0 :                 break;
     143             : 
     144             :             default:
     145           0 :                 aReturn = OSingleDocumentController_Base::GetState(_nId);
     146             :         }
     147           0 :         return aReturn;
     148             :     }
     149           0 :     void OSingleDocumentController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue >& _rArgs )
     150             :     {
     151           0 :         switch ( _nId )
     152             :         {
     153             :             case ID_BROWSER_UNDO:
     154           0 :                 GetUndoManager().Undo();
     155           0 :                 InvalidateFeature( ID_BROWSER_UNDO );
     156           0 :                 InvalidateFeature( ID_BROWSER_REDO );
     157           0 :                 break;
     158             : 
     159             :             case ID_BROWSER_REDO:
     160           0 :                 GetUndoManager().Redo();
     161           0 :                 InvalidateFeature( ID_BROWSER_UNDO );
     162           0 :                 InvalidateFeature( ID_BROWSER_REDO );
     163           0 :                 break;
     164             : 
     165             :             default:
     166           0 :                 OSingleDocumentController_Base::Execute( _nId, _rArgs );
     167           0 :                 break;
     168             :         }
     169           0 :         InvalidateFeature(_nId);
     170           0 :     }
     171             : 
     172          36 : } // namespace dbaui
     173             : 
     174             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11