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