1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3*cdf0e10cSrcweir * 4*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 5*cdf0e10cSrcweir * 6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 7*cdf0e10cSrcweir * 8*cdf0e10cSrcweir * This file is part of OpenOffice.org. 9*cdf0e10cSrcweir * 10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 12*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 13*cdf0e10cSrcweir * 14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 19*cdf0e10cSrcweir * 20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 21*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 23*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 24*cdf0e10cSrcweir * 25*cdf0e10cSrcweir ************************************************************************/ 26*cdf0e10cSrcweir 27*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir #include "dbaundomanager.hxx" 30*cdf0e10cSrcweir #include "singledoccontroller.hxx" 31*cdf0e10cSrcweir #include "browserids.hxx" 32*cdf0e10cSrcweir #include "dbu_misc.hrc" 33*cdf0e10cSrcweir #include "dbustrings.hrc" 34*cdf0e10cSrcweir #include "moduledbu.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** === begin UNO includes === **/ 37*cdf0e10cSrcweir /** === end UNO includes === **/ 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <svl/undo.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <boost/scoped_ptr.hpp> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //...................................................................................................................... 44*cdf0e10cSrcweir namespace dbaui 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir //...................................................................................................................... 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir /** === begin UNO using === **/ 49*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 50*cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 51*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 52*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 53*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 54*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 55*cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 56*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 57*cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 58*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 59*cdf0e10cSrcweir using ::com::sun::star::uno::Type; 60*cdf0e10cSrcweir using ::com::sun::star::document::XUndoManager; 61*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory; 62*cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue; 63*cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 64*cdf0e10cSrcweir /** === end UNO using === **/ 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //================================================================================================================== 67*cdf0e10cSrcweir //= OSingleDocumentController_Data 68*cdf0e10cSrcweir //================================================================================================================== 69*cdf0e10cSrcweir struct OSingleDocumentController_Data 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir ::boost::scoped_ptr< UndoManager > m_pUndoManager; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir OSingleDocumentController_Data( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex ) 74*cdf0e10cSrcweir :m_pUndoManager( new UndoManager( i_parent, i_mutex ) ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir //================================================================================================================== 80*cdf0e10cSrcweir //= OSingleDocumentController 81*cdf0e10cSrcweir //================================================================================================================== 82*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 83*cdf0e10cSrcweir OSingleDocumentController::OSingleDocumentController( const Reference< XMultiServiceFactory >& _rxORB ) 84*cdf0e10cSrcweir :OSingleDocumentController_Base( _rxORB ) 85*cdf0e10cSrcweir ,m_pData( new OSingleDocumentController_Data( *this, getMutex() ) ) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ 90*cdf0e10cSrcweir OSingleDocumentController::~OSingleDocumentController() 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 95*cdf0e10cSrcweir void SAL_CALL OSingleDocumentController::disposing() 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir OSingleDocumentController_Base::disposing(); 98*cdf0e10cSrcweir ClearUndoManager(); 99*cdf0e10cSrcweir m_pData->m_pUndoManager->disposing(); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 103*cdf0e10cSrcweir void SAL_CALL OSingleDocumentController::disposing( const EventObject& i_event ) throw( RuntimeException ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir // simply disambiguate 106*cdf0e10cSrcweir OSingleDocumentController_Base::disposing( i_event ); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 110*cdf0e10cSrcweir void OSingleDocumentController::ClearUndoManager() 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir GetUndoManager().Clear(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 116*cdf0e10cSrcweir SfxUndoManager& OSingleDocumentController::GetUndoManager() const 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir return m_pData->m_pUndoManager->GetSfxUndoManager(); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 122*cdf0e10cSrcweir void OSingleDocumentController::addUndoActionAndInvalidate(SfxUndoAction *_pAction) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir // add undo action 125*cdf0e10cSrcweir GetUndoManager().AddUndoAction( _pAction ); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir // when we add an undo action the controller was modified 128*cdf0e10cSrcweir setModified( sal_True ); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir // now inform me that or states changed 131*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_UNDO ); 132*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_REDO ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 136*cdf0e10cSrcweir Reference< XUndoManager > SAL_CALL OSingleDocumentController::getUndoManager( ) throw (RuntimeException) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir return m_pData->m_pUndoManager.get(); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 142*cdf0e10cSrcweir FeatureState OSingleDocumentController::GetState(sal_uInt16 _nId) const 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir FeatureState aReturn; 145*cdf0e10cSrcweir switch ( _nId ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir case ID_BROWSER_UNDO: 148*cdf0e10cSrcweir aReturn.bEnabled = isEditable() && GetUndoManager().GetUndoActionCount() != 0; 149*cdf0e10cSrcweir if ( aReturn.bEnabled ) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir String sUndo(ModuleRes(STR_UNDO_COLON)); 152*cdf0e10cSrcweir sUndo += String(RTL_CONSTASCII_USTRINGPARAM(" ")); 153*cdf0e10cSrcweir sUndo += GetUndoManager().GetUndoActionComment(); 154*cdf0e10cSrcweir aReturn.sTitle = sUndo; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir break; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir case ID_BROWSER_REDO: 159*cdf0e10cSrcweir aReturn.bEnabled = isEditable() && GetUndoManager().GetRedoActionCount() != 0; 160*cdf0e10cSrcweir if ( aReturn.bEnabled ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir String sRedo(ModuleRes(STR_REDO_COLON)); 163*cdf0e10cSrcweir sRedo += String(RTL_CONSTASCII_USTRINGPARAM(" ")); 164*cdf0e10cSrcweir sRedo += GetUndoManager().GetRedoActionComment(); 165*cdf0e10cSrcweir aReturn.sTitle = sRedo; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir break; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir default: 170*cdf0e10cSrcweir aReturn = OSingleDocumentController_Base::GetState(_nId); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir return aReturn; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 175*cdf0e10cSrcweir void OSingleDocumentController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue >& _rArgs ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir switch ( _nId ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir case ID_BROWSER_UNDO: 180*cdf0e10cSrcweir GetUndoManager().Undo(); 181*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_UNDO ); 182*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_REDO ); 183*cdf0e10cSrcweir break; 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir case ID_BROWSER_REDO: 186*cdf0e10cSrcweir GetUndoManager().Redo(); 187*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_UNDO ); 188*cdf0e10cSrcweir InvalidateFeature( ID_BROWSER_REDO ); 189*cdf0e10cSrcweir break; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir default: 192*cdf0e10cSrcweir OSingleDocumentController_Base::Execute( _nId, _rArgs ); 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir InvalidateFeature(_nId); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir //...................................................................................................................... 199*cdf0e10cSrcweir } // namespace dbaui 200*cdf0e10cSrcweir //...................................................................................................................... 201