1cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5cde9e8dcSAndrew Rist * distributed with this work for additional information
6cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10cde9e8dcSAndrew Rist *
11cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cde9e8dcSAndrew Rist *
13cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18cde9e8dcSAndrew Rist * under the License.
19cde9e8dcSAndrew Rist *
20cde9e8dcSAndrew Rist *************************************************************/
21cde9e8dcSAndrew Rist
22cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "UndoCommandDispatch.hxx"
28cdf0e10cSrcweir #include "ResId.hxx"
29cdf0e10cSrcweir #include "macros.hxx"
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
32cdf0e10cSrcweir #include <com/sun/star/document/XUndoManagerSupplier.hpp>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <vos/mutex.hxx>
35cdf0e10cSrcweir #include <vcl/svapp.hxx>
36cdf0e10cSrcweir #include <tools/diagnose_ex.h>
37cdf0e10cSrcweir
38cdf0e10cSrcweir // for ressource strings STR_UNDO and STR_REDO
39cdf0e10cSrcweir #include <svtools/svtools.hrc>
40cdf0e10cSrcweir #include <svtools/svtdata.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
46cdf0e10cSrcweir using ::rtl::OUString;
47cdf0e10cSrcweir
48cdf0e10cSrcweir namespace chart
49cdf0e10cSrcweir {
50cdf0e10cSrcweir
UndoCommandDispatch(const Reference<uno::XComponentContext> & xContext,const Reference<frame::XModel> & xModel)51cdf0e10cSrcweir UndoCommandDispatch::UndoCommandDispatch(
52cdf0e10cSrcweir const Reference< uno::XComponentContext > & xContext,
53cdf0e10cSrcweir const Reference< frame::XModel > & xModel ) :
54cdf0e10cSrcweir CommandDispatch( xContext ),
55cdf0e10cSrcweir m_xModel( xModel )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
58cdf0e10cSrcweir m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
~UndoCommandDispatch()61cdf0e10cSrcweir UndoCommandDispatch::~UndoCommandDispatch()
62cdf0e10cSrcweir {}
63cdf0e10cSrcweir
initialize()64cdf0e10cSrcweir void UndoCommandDispatch::initialize()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
67cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
68cdf0e10cSrcweir xBroadcaster->addModifyListener( this );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
fireStatusEvent(const OUString & rURL,const Reference<frame::XStatusListener> & xSingleListener)71cdf0e10cSrcweir void UndoCommandDispatch::fireStatusEvent(
72cdf0e10cSrcweir const OUString & rURL,
73cdf0e10cSrcweir const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir if( m_xUndoManager.is() )
76cdf0e10cSrcweir {
77*9ec58d04SHerbert Dürr const bool bFireAll = rURL.isEmpty();
78cdf0e10cSrcweir uno::Any aUndoState, aRedoState;
79cdf0e10cSrcweir if( m_xUndoManager->isUndoPossible())
80cdf0e10cSrcweir {
81cdf0e10cSrcweir // using assignment for broken gcc 3.3
82cdf0e10cSrcweir OUString aUndo = OUString( String( SvtResId( STR_UNDO )));
83cdf0e10cSrcweir aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
84cdf0e10cSrcweir }
85cdf0e10cSrcweir if( m_xUndoManager->isRedoPossible())
86cdf0e10cSrcweir {
87cdf0e10cSrcweir // using assignment for broken gcc 3.3
88cdf0e10cSrcweir OUString aRedo = OUString( String( SvtResId( STR_REDO )));
89cdf0e10cSrcweir aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir if( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Undo")))
93cdf0e10cSrcweir fireStatusEventForURL( C2U(".uno:Undo"), aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
94cdf0e10cSrcweir if( bFireAll || rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Redo")))
95cdf0e10cSrcweir fireStatusEventForURL( C2U(".uno:Redo"), aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir // ____ XDispatch ____
dispatch(const util::URL & URL,const Sequence<beans::PropertyValue> &)100cdf0e10cSrcweir void SAL_CALL UndoCommandDispatch::dispatch(
101cdf0e10cSrcweir const util::URL& URL,
102cdf0e10cSrcweir const Sequence< beans::PropertyValue >& /* Arguments */ )
103cdf0e10cSrcweir throw (uno::RuntimeException)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir if( m_xUndoManager.is() )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir // why is it necessary to lock the solar mutex here?
108cdf0e10cSrcweir // /--
109cdf0e10cSrcweir ::vos::OGuard aSolarGuard( Application::GetSolarMutex());
110cdf0e10cSrcweir try
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if( URL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Undo" )))
113cdf0e10cSrcweir m_xUndoManager->undo();
114cdf0e10cSrcweir else
115cdf0e10cSrcweir m_xUndoManager->redo();
116cdf0e10cSrcweir }
117cdf0e10cSrcweir catch( const document::UndoFailedException& )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir // silently ignore
120cdf0e10cSrcweir }
121cdf0e10cSrcweir catch( const uno::Exception& )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir // \--
126cdf0e10cSrcweir }
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
129cdf0e10cSrcweir // ____ WeakComponentImplHelperBase ____
130cdf0e10cSrcweir /// is called when this is disposed
disposing()131cdf0e10cSrcweir void SAL_CALL UndoCommandDispatch::disposing()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
134cdf0e10cSrcweir OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
135cdf0e10cSrcweir if( xBroadcaster.is() )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir xBroadcaster->removeModifyListener( this );
138cdf0e10cSrcweir }
139cdf0e10cSrcweir
140cdf0e10cSrcweir m_xUndoManager.clear();
141cdf0e10cSrcweir m_xModel.clear();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
144cdf0e10cSrcweir // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)145cdf0e10cSrcweir void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
146cdf0e10cSrcweir throw (uno::RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir m_xUndoManager.clear();
149cdf0e10cSrcweir m_xModel.clear();
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir } // namespace chart
153