fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / UndoCommandDispatch.cxx
blob88e700aaa6c0db761865f42a45fa850b9f38ea61
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "UndoCommandDispatch.hxx"
21 #include "ResId.hxx"
22 #include "macros.hxx"
24 #include <com/sun/star/util/XModifyBroadcaster.hpp>
25 #include <com/sun/star/document/XUndoManagerSupplier.hpp>
27 #include <osl/mutex.hxx>
28 #include <vcl/svapp.hxx>
29 #include <tools/diagnose_ex.h>
31 #include <svtools/svtools.hrc>
32 #include <svtools/svtresid.hxx>
34 using namespace ::com::sun::star;
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::Sequence;
39 namespace chart
42 UndoCommandDispatch::UndoCommandDispatch(
43 const Reference< uno::XComponentContext > & xContext,
44 const Reference< frame::XModel > & xModel ) :
45 CommandDispatch( xContext ),
46 m_xModel( xModel )
48 uno::Reference< document::XUndoManagerSupplier > xSuppUndo( m_xModel, uno::UNO_QUERY_THROW );
49 m_xUndoManager.set( xSuppUndo->getUndoManager(), uno::UNO_QUERY_THROW );
52 UndoCommandDispatch::~UndoCommandDispatch()
55 void UndoCommandDispatch::initialize()
57 Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
58 ENSURE_OR_RETURN_VOID( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
59 xBroadcaster->addModifyListener( this );
62 void UndoCommandDispatch::fireStatusEvent(
63 const OUString & rURL,
64 const Reference< frame::XStatusListener > & xSingleListener /* = 0 */ )
66 if( m_xUndoManager.is() )
68 const bool bFireAll = rURL.isEmpty();
69 uno::Any aUndoState, aRedoState;
70 if( m_xUndoManager->isUndoPossible())
72 // using assignment for broken gcc 3.3
73 OUString aUndo = SvtResId( STR_UNDO ).toString();
74 aUndoState <<= ( aUndo + m_xUndoManager->getCurrentUndoActionTitle());
76 if( m_xUndoManager->isRedoPossible())
78 // using assignment for broken gcc 3.3
79 OUString aRedo = SvtResId( STR_REDO ).toString();
80 aRedoState <<= ( aRedo + m_xUndoManager->getCurrentRedoActionTitle());
83 if( bFireAll || rURL == ".uno:Undo" )
84 fireStatusEventForURL( ".uno:Undo", aUndoState, m_xUndoManager->isUndoPossible(), xSingleListener );
85 if( bFireAll || rURL == ".uno:Redo" )
86 fireStatusEventForURL( ".uno:Redo", aRedoState, m_xUndoManager->isRedoPossible(), xSingleListener );
90 // ____ XDispatch ____
91 void SAL_CALL UndoCommandDispatch::dispatch(
92 const util::URL& URL,
93 const Sequence< beans::PropertyValue >& /* Arguments */ )
94 throw (uno::RuntimeException, std::exception)
96 if( m_xUndoManager.is() )
98 // why is it necessary to lock the solar mutex here?
99 SolarMutexGuard aSolarGuard;
102 if ( URL.Path == "Undo" )
103 m_xUndoManager->undo();
104 else
105 m_xUndoManager->redo();
107 catch( const document::UndoFailedException& )
109 // silently ignore
111 catch( const uno::Exception& )
113 DBG_UNHANDLED_EXCEPTION();
115 // \--
119 // ____ WeakComponentImplHelperBase ____
120 /// is called when this is disposed
121 void SAL_CALL UndoCommandDispatch::disposing()
123 Reference< util::XModifyBroadcaster > xBroadcaster( m_xUndoManager, uno::UNO_QUERY );
124 OSL_ENSURE( xBroadcaster.is(), "UndoCommandDispatch::initialize: missing modification broadcaster interface!" );
125 if( xBroadcaster.is() )
127 xBroadcaster->removeModifyListener( this );
130 m_xUndoManager.clear();
131 m_xModel.clear();
134 // ____ XEventListener (base of XModifyListener) ____
135 void SAL_CALL UndoCommandDispatch::disposing( const lang::EventObject& /* Source */ )
136 throw (uno::RuntimeException, std::exception)
138 m_xUndoManager.clear();
139 m_xModel.clear();
142 } // namespace chart
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */