1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "UndoCommandDispatch.hxx"
34 #include <com/sun/star/chart2/XUndoSupplier.hpp>
35 #include <com/sun/star/util/XModifyBroadcaster.hpp>
37 #include <vos/mutex.hxx>
38 #include <vcl/svapp.hxx>
40 // for ressource strings STR_UNDO and STR_REDO
41 #include <sfx2/sfx.hrc>
45 using namespace ::com::sun::star
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Sequence
;
49 using ::rtl::OUString
;
54 UndoCommandDispatch::UndoCommandDispatch(
55 const Reference
< uno::XComponentContext
> & xContext
,
56 const Reference
< frame::XModel
> & xModel
) :
57 CommandDispatch( xContext
),
60 Reference
< chart2::XUndoSupplier
> xUndoSupplier( xModel
, uno::UNO_QUERY
);
61 OSL_ASSERT( xUndoSupplier
.is());
62 if( xUndoSupplier
.is())
63 m_xUndoManager
.set( xUndoSupplier
->getUndoManager());
66 UndoCommandDispatch::~UndoCommandDispatch()
69 void UndoCommandDispatch::initialize()
71 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xUndoManager
, uno::UNO_QUERY
);
72 if( xBroadcaster
.is() )
74 xBroadcaster
->addModifyListener( this );
78 void UndoCommandDispatch::fireStatusEvent(
79 const OUString
& rURL
,
80 const Reference
< frame::XStatusListener
> & xSingleListener
/* = 0 */ )
82 if( m_xUndoManager
.is() )
84 bool bFireAll
= (rURL
.getLength() == 0);
85 uno::Any aUndoState
, aRedoState
;
86 if( m_xUndoManager
->undoPossible())
88 // using assignment for broken gcc 3.3
89 OUString aUndo
= OUString( String( SchResId( STR_UNDO
)));
90 aUndoState
<<= ( aUndo
+ m_xUndoManager
->getCurrentUndoString());
92 if( m_xUndoManager
->redoPossible())
94 // using assignment for broken gcc 3.3
95 OUString aRedo
= OUString( String( SchResId( STR_REDO
)));
96 aRedoState
<<= ( aRedo
+ m_xUndoManager
->getCurrentRedoString());
99 if( bFireAll
|| rURL
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Undo")))
100 fireStatusEventForURL( C2U(".uno:Undo"), aUndoState
, m_xUndoManager
->undoPossible(), xSingleListener
);
101 if( bFireAll
|| rURL
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(".uno:Redo")))
102 fireStatusEventForURL( C2U(".uno:Redo"), aRedoState
, m_xUndoManager
->redoPossible(), xSingleListener
);
106 // ____ XDispatch ____
107 void SAL_CALL
UndoCommandDispatch::dispatch(
108 const util::URL
& URL
,
109 const Sequence
< beans::PropertyValue
>& /* Arguments */ )
110 throw (uno::RuntimeException
)
112 if( m_xUndoManager
.is() )
114 // why is it necessary to lock the solar mutex here?
116 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
117 if( URL
.Path
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Undo" )))
118 m_xUndoManager
->undo( m_xModel
);
120 m_xUndoManager
->redo( m_xModel
);
125 // ____ WeakComponentImplHelperBase ____
126 /// is called when this is disposed
127 void SAL_CALL
UndoCommandDispatch::disposing()
129 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xUndoManager
, uno::UNO_QUERY
);
130 if( xBroadcaster
.is() )
132 xBroadcaster
->removeModifyListener( this );
135 m_xUndoManager
.clear();
139 // ____ XEventListener (base of XModifyListener) ____
140 void SAL_CALL
UndoCommandDispatch::disposing( const lang::EventObject
& /* Source */ )
141 throw (uno::RuntimeException
)
143 m_xUndoManager
.clear();