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 :
41 : namespace chart
42 : {
43 : namespace impl
44 : {
45 : using ::com::sun::star::uno::Reference;
46 : using ::com::sun::star::uno::XInterface;
47 : using ::com::sun::star::uno::UNO_QUERY;
48 : using ::com::sun::star::uno::UNO_QUERY_THROW;
49 : using ::com::sun::star::uno::UNO_SET_THROW;
50 : using ::com::sun::star::uno::Exception;
51 : using ::com::sun::star::uno::RuntimeException;
52 : using ::com::sun::star::uno::Any;
53 : using ::com::sun::star::uno::makeAny;
54 : using ::com::sun::star::uno::Sequence;
55 : using ::com::sun::star::uno::Type;
56 : using ::com::sun::star::frame::XModel;
57 : using ::com::sun::star::util::XCloneable;
58 : using ::com::sun::star::lang::XComponent;
59 : using ::com::sun::star::lang::DisposedException;
60 : using ::com::sun::star::view::XSelectionSupplier;
61 : using ::com::sun::star::chart2::XChartDocument;
62 : using ::com::sun::star::document::UndoFailedException;
63 :
64 : // ---------------------------------------------------------------------------------------------------------------------
65 0 : UndoElement::UndoElement( const OUString& i_actionString, const Reference< XModel >& i_documentModel, const ::boost::shared_ptr< ChartModelClone >& i_modelClone )
66 : :UndoElement_MBase()
67 : ,UndoElement_TBase( m_aMutex )
68 : ,m_sActionString( i_actionString )
69 : ,m_xDocumentModel( i_documentModel )
70 0 : ,m_pModelClone( i_modelClone )
71 : {
72 0 : }
73 :
74 : // ---------------------------------------------------------------------------------------------------------------------
75 0 : UndoElement::~UndoElement()
76 : {
77 0 : }
78 :
79 : // ---------------------------------------------------------------------------------------------------------------------
80 0 : void SAL_CALL UndoElement::disposing()
81 : {
82 0 : if ( !!m_pModelClone )
83 0 : m_pModelClone->dispose();
84 0 : m_pModelClone.reset();
85 0 : m_xDocumentModel.clear();
86 0 : }
87 :
88 : // ---------------------------------------------------------------------------------------------------------------------
89 0 : OUString SAL_CALL UndoElement::getTitle() throw (RuntimeException)
90 : {
91 0 : return m_sActionString;
92 : }
93 :
94 : // ---------------------------------------------------------------------------------------------------------------------
95 0 : void UndoElement::impl_toggleModelState()
96 : {
97 : // get a snapshot of the current state of our model
98 0 : ::boost::shared_ptr< ChartModelClone > pNewClone( new ChartModelClone( m_xDocumentModel, m_pModelClone->getFacet() ) );
99 : // apply the previous snapshot to our model
100 0 : m_pModelClone->applyToModel( m_xDocumentModel );
101 : // remember the new snapshot, for the next toggle
102 0 : m_pModelClone = pNewClone;
103 0 : }
104 :
105 : // ---------------------------------------------------------------------------------------------------------------------
106 0 : void SAL_CALL UndoElement::undo( ) throw (UndoFailedException, RuntimeException)
107 : {
108 0 : impl_toggleModelState();
109 0 : }
110 :
111 : // ---------------------------------------------------------------------------------------------------------------------
112 0 : void SAL_CALL UndoElement::redo( ) throw (UndoFailedException, RuntimeException)
113 : {
114 0 : impl_toggleModelState();
115 0 : }
116 :
117 : // =====================================================================================================================
118 : // = ShapeUndoElement
119 : // =====================================================================================================================
120 :
121 : // ---------------------------------------------------------------------------------------------------------------------
122 0 : ShapeUndoElement::ShapeUndoElement( SdrUndoAction& i_sdrUndoAction )
123 : :ShapeUndoElement_MBase()
124 : ,ShapeUndoElement_TBase( m_aMutex )
125 0 : ,m_pAction( &i_sdrUndoAction )
126 : {
127 0 : }
128 :
129 : // ---------------------------------------------------------------------------------------------------------------------
130 0 : ShapeUndoElement::~ShapeUndoElement()
131 : {
132 0 : }
133 :
134 : // ---------------------------------------------------------------------------------------------------------------------
135 0 : OUString SAL_CALL ShapeUndoElement::getTitle() throw (RuntimeException)
136 : {
137 0 : if ( !m_pAction )
138 0 : throw DisposedException( OUString(), *this );
139 0 : return m_pAction->GetComment();
140 : }
141 :
142 : // ---------------------------------------------------------------------------------------------------------------------
143 0 : void SAL_CALL ShapeUndoElement::undo( ) throw (UndoFailedException, RuntimeException)
144 : {
145 0 : if ( !m_pAction )
146 0 : throw DisposedException( OUString(), *this );
147 0 : m_pAction->Undo();
148 0 : }
149 :
150 : // ---------------------------------------------------------------------------------------------------------------------
151 0 : void SAL_CALL ShapeUndoElement::redo( ) throw (UndoFailedException, RuntimeException)
152 : {
153 0 : if ( !m_pAction )
154 0 : throw DisposedException( OUString(), *this );
155 0 : m_pAction->Redo();
156 0 : }
157 :
158 : // ---------------------------------------------------------------------------------------------------------------------
159 0 : void SAL_CALL ShapeUndoElement::disposing()
160 : {
161 0 : }
162 :
163 : } // namespace impl
164 : } // namespace chart
165 :
166 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|