Bump for 3.6-28
[LibreOffice.git] / chart2 / source / controller / main / UndoActions.cxx
blob43c180ce723cc1addc31bdecc3c805b964094f02
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "UndoActions.hxx"
31 #include "DisposeHelper.hxx"
32 #include "CommonFunctors.hxx"
33 #include "PropertyHelper.hxx"
34 #include "ChartModelClone.hxx"
36 #include <com/sun/star/chart2/XChartDocument.hpp>
37 #include <com/sun/star/util/XCloneable.hpp>
38 #include <com/sun/star/view/XSelectionSupplier.hpp>
39 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <tools/diagnose_ex.h>
42 #include <svx/svdundo.hxx>
44 #include <boost/shared_ptr.hpp>
45 #include <algorithm>
47 using namespace ::com::sun::star;
49 using ::rtl::OUString;
51 namespace chart
53 namespace impl
56 /** === begin UNO using === **/
57 using ::com::sun::star::uno::Reference;
58 using ::com::sun::star::uno::XInterface;
59 using ::com::sun::star::uno::UNO_QUERY;
60 using ::com::sun::star::uno::UNO_QUERY_THROW;
61 using ::com::sun::star::uno::UNO_SET_THROW;
62 using ::com::sun::star::uno::Exception;
63 using ::com::sun::star::uno::RuntimeException;
64 using ::com::sun::star::uno::Any;
65 using ::com::sun::star::uno::makeAny;
66 using ::com::sun::star::uno::Sequence;
67 using ::com::sun::star::uno::Type;
68 using ::com::sun::star::frame::XModel;
69 using ::com::sun::star::util::XCloneable;
70 using ::com::sun::star::lang::XComponent;
71 using ::com::sun::star::lang::DisposedException;
72 using ::com::sun::star::view::XSelectionSupplier;
73 using ::com::sun::star::chart2::XChartDocument;
74 using ::com::sun::star::document::UndoFailedException;
75 /** === end UNO using === **/
77 // ---------------------------------------------------------------------------------------------------------------------
78 UndoElement::UndoElement( const OUString& i_actionString, const Reference< XModel >& i_documentModel, const ::boost::shared_ptr< ChartModelClone >& i_modelClone )
79 :UndoElement_MBase()
80 ,UndoElement_TBase( m_aMutex )
81 ,m_sActionString( i_actionString )
82 ,m_xDocumentModel( i_documentModel )
83 ,m_pModelClone( i_modelClone )
87 // ---------------------------------------------------------------------------------------------------------------------
88 UndoElement::~UndoElement()
92 // ---------------------------------------------------------------------------------------------------------------------
93 void SAL_CALL UndoElement::disposing()
95 if ( !!m_pModelClone )
96 m_pModelClone->dispose();
97 m_pModelClone.reset();
98 m_xDocumentModel.clear();
101 // ---------------------------------------------------------------------------------------------------------------------
102 ::rtl::OUString SAL_CALL UndoElement::getTitle() throw (RuntimeException)
104 return m_sActionString;
107 // ---------------------------------------------------------------------------------------------------------------------
108 void UndoElement::impl_toggleModelState()
110 // get a snapshot of the current state of our model
111 ::boost::shared_ptr< ChartModelClone > pNewClone( new ChartModelClone( m_xDocumentModel, m_pModelClone->getFacet() ) );
112 // apply the previous snapshot to our model
113 m_pModelClone->applyToModel( m_xDocumentModel );
114 // remember the new snapshot, for the next toggle
115 m_pModelClone = pNewClone;
118 // ---------------------------------------------------------------------------------------------------------------------
119 void SAL_CALL UndoElement::undo( ) throw (UndoFailedException, RuntimeException)
121 impl_toggleModelState();
124 // ---------------------------------------------------------------------------------------------------------------------
125 void SAL_CALL UndoElement::redo( ) throw (UndoFailedException, RuntimeException)
127 impl_toggleModelState();
130 // =====================================================================================================================
131 // = ShapeUndoElement
132 // =====================================================================================================================
134 // ---------------------------------------------------------------------------------------------------------------------
135 ShapeUndoElement::ShapeUndoElement( SdrUndoAction& i_sdrUndoAction )
136 :ShapeUndoElement_MBase()
137 ,ShapeUndoElement_TBase( m_aMutex )
138 ,m_pAction( &i_sdrUndoAction )
142 // ---------------------------------------------------------------------------------------------------------------------
143 ShapeUndoElement::~ShapeUndoElement()
147 // ---------------------------------------------------------------------------------------------------------------------
148 ::rtl::OUString SAL_CALL ShapeUndoElement::getTitle() throw (RuntimeException)
150 if ( !m_pAction )
151 throw DisposedException( ::rtl::OUString(), *this );
152 return m_pAction->GetComment();
155 // ---------------------------------------------------------------------------------------------------------------------
156 void SAL_CALL ShapeUndoElement::undo( ) throw (UndoFailedException, RuntimeException)
158 if ( !m_pAction )
159 throw DisposedException( ::rtl::OUString(), *this );
160 m_pAction->Undo();
163 // ---------------------------------------------------------------------------------------------------------------------
164 void SAL_CALL ShapeUndoElement::redo( ) throw (UndoFailedException, RuntimeException)
166 if ( !m_pAction )
167 throw DisposedException( ::rtl::OUString(), *this );
168 m_pAction->Redo();
171 // ---------------------------------------------------------------------------------------------------------------------
172 void SAL_CALL ShapeUndoElement::disposing()
176 } // namespace impl
177 } // namespace chart
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */