Update ooo320-m1
[ooovba.git] / chart2 / source / controller / main / UndoCommandDispatch.cxx
blobd3da8da1de872affafb56b669bcf141963e5cc8d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: UndoCommandDispatch.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "UndoCommandDispatch.hxx"
35 #include "macros.hxx"
37 #include <com/sun/star/chart2/XUndoSupplier.hpp>
38 #include <com/sun/star/util/XModifyBroadcaster.hpp>
40 #include <vos/mutex.hxx>
41 #include <vcl/svapp.hxx>
43 // for ressource strings STR_UNDO and STR_REDO
44 #include <sfx2/sfx.hrc>
46 #include "ResId.hxx"
48 using namespace ::com::sun::star;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Sequence;
52 using ::rtl::OUString;
54 namespace chart
57 UndoCommandDispatch::UndoCommandDispatch(
58 const Reference< uno::XComponentContext > & xContext,
59 const Reference< frame::XModel > & xModel ) :
60 CommandDispatch( xContext ),
61 m_xModel( xModel )
63 Reference< chart2::XUndoSupplier > xUndoSupplier( xModel, uno::UNO_QUERY );
64 OSL_ASSERT( xUndoSupplier.is());
65 if( xUndoSupplier.is())
66 m_xUndoManager.set( xUndoSupplier->getUndoManager());
69 UndoCommandDispatch::~UndoCommandDispatch()
72 void UndoCommandDispatch::initialize()
74 Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
75 if( xBroadcaster.is() )
77 xBroadcaster->addModifyListener( this );
81 void UndoCommandDispatch::fireStatusEvent(
82 const OUString & rURL,
83 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
85 if( m_xUndoManager.is() )
87 bool bFireAll = (rURL.getLength() == 0);
88 uno::Any aUndoState, aRedoState;
89 if( m_xUndoManager->undoPossible())
91 // using assignment for broken gcc 3.3
92 OUString aUndo = OUString( String( SchResId( STR_UNDO )));
93 aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoString());
95 if( m_xUndoManager->redoPossible())
97 // using assignment for broken gcc 3.3
98 OUString aRedo = OUString( String( SchResId( STR_REDO )));
99 aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoString());
102 if( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Undo")))
103 fireStatusEventForURL( C2U(".uno:Undo"), aUndoState, m_xUndoManager->undoPossible(), xSingleListener );
104 if( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Redo")))
105 fireStatusEventForURL( C2U(".uno:Redo"), aRedoState, m_xUndoManager->redoPossible(), xSingleListener );
109 // ____ XDispatch ____
110 void SAL_CALL UndoCommandDispatch::dispatch(
111 const util::URL& URL,
112 const Sequence< beans::PropertyValue >& /* Arguments */ )
113 throw (uno::RuntimeException)
115 if( m_xUndoManager.is() )
117 // why is it necessary to lock the solar mutex here?
118 // /--
119 ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
120 if( URL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Undo" )))
121 m_xUndoManager->undo( m_xModel );
122 else
123 m_xUndoManager->redo( m_xModel );
124 // \--
128 // ____ WeakComponentImplHelperBase ____
129 /// is called when this is disposed
130 void SAL_CALL UndoCommandDispatch::disposing()
132 Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
133 if( xBroadcaster.is() )
135 xBroadcaster->removeModifyListener( this );
138 m_xUndoManager.clear();
139 m_xModel.clear();
142 // ____ XEventListener (base of XModifyListener) ____
143 void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
144 throw (uno::RuntimeException)
146 m_xUndoManager.clear();
147 m_xModel.clear();
150 } // namespace chart