1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26
27 #include "UndoActions.hxx"
28 #include "DisposeHelper.hxx"
29 #include "CommonFunctors.hxx"
30 #include "PropertyHelper.hxx"
31 #include "ChartModelClone.hxx"
32
33 #include <com/sun/star/chart2/XChartDocument.hpp>
34 #include <com/sun/star/util/XCloneable.hpp>
35 #include <com/sun/star/view/XSelectionSupplier.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37
38 #include <tools/diagnose_ex.h>
39 #include <svx/svdundo.hxx>
40
41 #include <boost/bind.hpp>
42 #include <algorithm>
43
44 using namespace ::com::sun::star;
45
46 using ::rtl::OUString;
47
48 namespace chart
49 {
50 namespace impl
51 {
52
53 /** === begin UNO using === **/
54 using ::com::sun::star::uno::Reference;
55 using ::com::sun::star::uno::XInterface;
56 using ::com::sun::star::uno::UNO_QUERY;
57 using ::com::sun::star::uno::UNO_QUERY_THROW;
58 using ::com::sun::star::uno::UNO_SET_THROW;
59 using ::com::sun::star::uno::Exception;
60 using ::com::sun::star::uno::RuntimeException;
61 using ::com::sun::star::uno::Any;
62 using ::com::sun::star::uno::makeAny;
63 using ::com::sun::star::uno::Sequence;
64 using ::com::sun::star::uno::Type;
65 using ::com::sun::star::frame::XModel;
66 using ::com::sun::star::util::XCloneable;
67 using ::com::sun::star::lang::XComponent;
68 using ::com::sun::star::lang::DisposedException;
69 using ::com::sun::star::view::XSelectionSupplier;
70 using ::com::sun::star::chart2::XChartDocument;
71 using ::com::sun::star::document::UndoFailedException;
72 /** === end UNO using === **/
73
74 // ---------------------------------------------------------------------------------------------------------------------
UndoElement(const OUString & i_actionString,const Reference<XModel> & i_documentModel,const::boost::shared_ptr<ChartModelClone> & i_modelClone)75 UndoElement::UndoElement( const OUString& i_actionString, const Reference< XModel >& i_documentModel, const ::boost::shared_ptr< ChartModelClone >& i_modelClone )
76 :UndoElement_MBase()
77 ,UndoElement_TBase( m_aMutex )
78 ,m_sActionString( i_actionString )
79 ,m_xDocumentModel( i_documentModel )
80 ,m_pModelClone( i_modelClone )
81 {
82 }
83
84 // ---------------------------------------------------------------------------------------------------------------------
~UndoElement()85 UndoElement::~UndoElement()
86 {
87 }
88
89 // ---------------------------------------------------------------------------------------------------------------------
disposing()90 void SAL_CALL UndoElement::disposing()
91 {
92 if ( !!m_pModelClone )
93 m_pModelClone->dispose();
94 m_pModelClone.reset();
95 m_xDocumentModel.clear();
96 }
97
98 // ---------------------------------------------------------------------------------------------------------------------
getTitle()99 ::rtl::OUString SAL_CALL UndoElement::getTitle() throw (RuntimeException)
100 {
101 return m_sActionString;
102 }
103
104 // ---------------------------------------------------------------------------------------------------------------------
impl_toggleModelState()105 void UndoElement::impl_toggleModelState()
106 {
107 // get a snapshot of the current state of our model
108 ::boost::shared_ptr< ChartModelClone > pNewClone( new ChartModelClone( m_xDocumentModel, m_pModelClone->getFacet() ) );
109 // apply the previous snapshot to our model
110 m_pModelClone->applyToModel( m_xDocumentModel );
111 // remember the new snapshot, for the next toggle
112 m_pModelClone = pNewClone;
113 }
114
115 // ---------------------------------------------------------------------------------------------------------------------
undo()116 void SAL_CALL UndoElement::undo( ) throw (UndoFailedException, RuntimeException)
117 {
118 impl_toggleModelState();
119 }
120
121 // ---------------------------------------------------------------------------------------------------------------------
redo()122 void SAL_CALL UndoElement::redo( ) throw (UndoFailedException, RuntimeException)
123 {
124 impl_toggleModelState();
125 }
126
127 // =====================================================================================================================
128 // = ShapeUndoElement
129 // =====================================================================================================================
130
131 // ---------------------------------------------------------------------------------------------------------------------
ShapeUndoElement(SdrUndoAction & i_sdrUndoAction)132 ShapeUndoElement::ShapeUndoElement( SdrUndoAction& i_sdrUndoAction )
133 :ShapeUndoElement_MBase()
134 ,ShapeUndoElement_TBase( m_aMutex )
135 ,m_pAction( &i_sdrUndoAction )
136 {
137 }
138
139 // ---------------------------------------------------------------------------------------------------------------------
~ShapeUndoElement()140 ShapeUndoElement::~ShapeUndoElement()
141 {
142 }
143
144 // ---------------------------------------------------------------------------------------------------------------------
getTitle()145 ::rtl::OUString SAL_CALL ShapeUndoElement::getTitle() throw (RuntimeException)
146 {
147 if ( !m_pAction )
148 throw DisposedException( ::rtl::OUString(), *this );
149 return m_pAction->GetComment();
150 }
151
152 // ---------------------------------------------------------------------------------------------------------------------
undo()153 void SAL_CALL ShapeUndoElement::undo( ) throw (UndoFailedException, RuntimeException)
154 {
155 if ( !m_pAction )
156 throw DisposedException( ::rtl::OUString(), *this );
157 m_pAction->Undo();
158 }
159
160 // ---------------------------------------------------------------------------------------------------------------------
redo()161 void SAL_CALL ShapeUndoElement::redo( ) throw (UndoFailedException, RuntimeException)
162 {
163 if ( !m_pAction )
164 throw DisposedException( ::rtl::OUString(), *this );
165 m_pAction->Redo();
166 }
167
168 // ---------------------------------------------------------------------------------------------------------------------
disposing()169 void SAL_CALL ShapeUndoElement::disposing()
170 {
171 }
172
173 } // namespace impl
174 } // namespace chart
175