Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "UndoActions.hxx"
22 : #include "DisposeHelper.hxx"
23 : #include "CommonFunctors.hxx"
24 : #include "PropertyHelper.hxx"
25 : #include "ChartModelClone.hxx"
26 :
27 : #include <com/sun/star/chart2/XChartDocument.hpp>
28 : #include <com/sun/star/util/XCloneable.hpp>
29 : #include <com/sun/star/view/XSelectionSupplier.hpp>
30 : #include <com/sun/star/lang/DisposedException.hpp>
31 :
32 : #include <tools/diagnose_ex.h>
33 : #include <svx/svdundo.hxx>
34 :
35 : #include <boost/shared_ptr.hpp>
36 : #include <algorithm>
37 :
38 : using namespace ::com::sun::star;
39 :
40 : using ::rtl::OUString;
41 :
42 : namespace chart
43 : {
44 : namespace impl
45 : {
46 :
47 : /** === begin UNO using === **/
48 : using ::com::sun::star::uno::Reference;
49 : using ::com::sun::star::uno::XInterface;
50 : using ::com::sun::star::uno::UNO_QUERY;
51 : using ::com::sun::star::uno::UNO_QUERY_THROW;
52 : using ::com::sun::star::uno::UNO_SET_THROW;
53 : using ::com::sun::star::uno::Exception;
54 : using ::com::sun::star::uno::RuntimeException;
55 : using ::com::sun::star::uno::Any;
56 : using ::com::sun::star::uno::makeAny;
57 : using ::com::sun::star::uno::Sequence;
58 : using ::com::sun::star::uno::Type;
59 : using ::com::sun::star::frame::XModel;
60 : using ::com::sun::star::util::XCloneable;
61 : using ::com::sun::star::lang::XComponent;
62 : using ::com::sun::star::lang::DisposedException;
63 : using ::com::sun::star::view::XSelectionSupplier;
64 : using ::com::sun::star::chart2::XChartDocument;
65 : using ::com::sun::star::document::UndoFailedException;
66 : /** === end UNO using === **/
67 :
68 : // ---------------------------------------------------------------------------------------------------------------------
69 0 : UndoElement::UndoElement( const OUString& i_actionString, const Reference< XModel >& i_documentModel, const ::boost::shared_ptr< ChartModelClone >& i_modelClone )
70 : :UndoElement_MBase()
71 : ,UndoElement_TBase( m_aMutex )
72 : ,m_sActionString( i_actionString )
73 : ,m_xDocumentModel( i_documentModel )
74 0 : ,m_pModelClone( i_modelClone )
75 : {
76 0 : }
77 :
78 : // ---------------------------------------------------------------------------------------------------------------------
79 0 : UndoElement::~UndoElement()
80 : {
81 0 : }
82 :
83 : // ---------------------------------------------------------------------------------------------------------------------
84 0 : void SAL_CALL UndoElement::disposing()
85 : {
86 0 : if ( !!m_pModelClone )
87 0 : m_pModelClone->dispose();
88 0 : m_pModelClone.reset();
89 0 : m_xDocumentModel.clear();
90 0 : }
91 :
92 : // ---------------------------------------------------------------------------------------------------------------------
93 0 : ::rtl::OUString SAL_CALL UndoElement::getTitle() throw (RuntimeException)
94 : {
95 0 : return m_sActionString;
96 : }
97 :
98 : // ---------------------------------------------------------------------------------------------------------------------
99 0 : void UndoElement::impl_toggleModelState()
100 : {
101 : // get a snapshot of the current state of our model
102 0 : ::boost::shared_ptr< ChartModelClone > pNewClone( new ChartModelClone( m_xDocumentModel, m_pModelClone->getFacet() ) );
103 : // apply the previous snapshot to our model
104 0 : m_pModelClone->applyToModel( m_xDocumentModel );
105 : // remember the new snapshot, for the next toggle
106 0 : m_pModelClone = pNewClone;
107 0 : }
108 :
109 : // ---------------------------------------------------------------------------------------------------------------------
110 0 : void SAL_CALL UndoElement::undo( ) throw (UndoFailedException, RuntimeException)
111 : {
112 0 : impl_toggleModelState();
113 0 : }
114 :
115 : // ---------------------------------------------------------------------------------------------------------------------
116 0 : void SAL_CALL UndoElement::redo( ) throw (UndoFailedException, RuntimeException)
117 : {
118 0 : impl_toggleModelState();
119 0 : }
120 :
121 : // =====================================================================================================================
122 : // = ShapeUndoElement
123 : // =====================================================================================================================
124 :
125 : // ---------------------------------------------------------------------------------------------------------------------
126 0 : ShapeUndoElement::ShapeUndoElement( SdrUndoAction& i_sdrUndoAction )
127 : :ShapeUndoElement_MBase()
128 : ,ShapeUndoElement_TBase( m_aMutex )
129 0 : ,m_pAction( &i_sdrUndoAction )
130 : {
131 0 : }
132 :
133 : // ---------------------------------------------------------------------------------------------------------------------
134 0 : ShapeUndoElement::~ShapeUndoElement()
135 : {
136 0 : }
137 :
138 : // ---------------------------------------------------------------------------------------------------------------------
139 0 : ::rtl::OUString SAL_CALL ShapeUndoElement::getTitle() throw (RuntimeException)
140 : {
141 0 : if ( !m_pAction )
142 0 : throw DisposedException( ::rtl::OUString(), *this );
143 0 : return m_pAction->GetComment();
144 : }
145 :
146 : // ---------------------------------------------------------------------------------------------------------------------
147 0 : void SAL_CALL ShapeUndoElement::undo( ) throw (UndoFailedException, RuntimeException)
148 : {
149 0 : if ( !m_pAction )
150 0 : throw DisposedException( ::rtl::OUString(), *this );
151 0 : m_pAction->Undo();
152 0 : }
153 :
154 : // ---------------------------------------------------------------------------------------------------------------------
155 0 : void SAL_CALL ShapeUndoElement::redo( ) throw (UndoFailedException, RuntimeException)
156 : {
157 0 : if ( !m_pAction )
158 0 : throw DisposedException( ::rtl::OUString(), *this );
159 0 : m_pAction->Redo();
160 0 : }
161 :
162 : // ---------------------------------------------------------------------------------------------------------------------
163 0 : void SAL_CALL ShapeUndoElement::disposing()
164 : {
165 0 : }
166 :
167 : } // namespace impl
168 : } // namespace chart
169 :
170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|