fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / main / UndoGuard.cxx
blob3617366e574b3c3b10f9aa2ff1adeca157c7d7cb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "UndoGuard.hxx"
21 #include "ChartModelClone.hxx"
22 #include "UndoActions.hxx"
24 #include <com/sun/star/container/XChild.hpp>
26 #include <tools/diagnose_ex.h>
28 using namespace ::com::sun::star;
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::Sequence;
33 namespace chart
36 UndoGuard::UndoGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager > & i_undoManager,
37 const ModelFacet i_facet )
38 :m_xChartModel( i_undoManager->getParent(), uno::UNO_QUERY_THROW )
39 ,m_xUndoManager( i_undoManager )
40 ,m_pDocumentSnapshot()
41 ,m_aUndoString( i_undoString )
42 ,m_bActionPosted( false )
44 m_pDocumentSnapshot.reset( new ChartModelClone( m_xChartModel, i_facet ) );
47 UndoGuard::~UndoGuard()
49 if ( !!m_pDocumentSnapshot )
50 discardSnapshot();
53 void UndoGuard::commit()
55 if ( !m_bActionPosted && !!m_pDocumentSnapshot )
57 try
59 const Reference< document::XUndoAction > xAction( new impl::UndoElement( m_aUndoString, m_xChartModel, m_pDocumentSnapshot ) );
60 m_pDocumentSnapshot.reset(); // don't dispose, it's data went over to the UndoElement
61 m_xUndoManager->addUndoAction( xAction );
63 catch( const uno::Exception& )
65 DBG_UNHANDLED_EXCEPTION();
68 m_bActionPosted = true;
71 void UndoGuard::rollback()
73 ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" );
74 m_pDocumentSnapshot->applyToModel( m_xChartModel );
75 discardSnapshot();
78 void UndoGuard::discardSnapshot()
80 ENSURE_OR_RETURN_VOID( !!m_pDocumentSnapshot, "no snapshot!" );
81 m_pDocumentSnapshot->dispose();
82 m_pDocumentSnapshot.reset();
85 UndoLiveUpdateGuard::UndoLiveUpdateGuard( const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager )
86 :UndoGuard( i_undoString, i_undoManager, E_MODEL )
90 UndoLiveUpdateGuard::~UndoLiveUpdateGuard()
92 if ( !isActionPosted() )
93 rollback();
96 UndoLiveUpdateGuardWithData::UndoLiveUpdateGuardWithData(
97 const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager )
98 :UndoGuard( i_undoString, i_undoManager, E_MODEL_WITH_DATA )
102 UndoLiveUpdateGuardWithData::~UndoLiveUpdateGuardWithData()
104 if ( !isActionPosted() )
105 rollback();
108 UndoGuardWithSelection::UndoGuardWithSelection(
109 const OUString& i_undoString, const uno::Reference< document::XUndoManager >& i_undoManager )
110 :UndoGuard( i_undoString, i_undoManager, E_MODEL_WITH_SELECTION )
114 UndoGuardWithSelection::~UndoGuardWithSelection()
116 if ( !isActionPosted() )
117 rollback();
120 HiddenUndoContext::HiddenUndoContext( const Reference< document::XUndoManager > & i_undoManager )
121 :m_xUndoManager( i_undoManager )
123 ENSURE_OR_THROW( m_xUndoManager.is(), "invalid undo manager!" );
126 m_xUndoManager->enterHiddenUndoContext();
128 catch( const uno::Exception& )
130 DBG_UNHANDLED_EXCEPTION();
131 m_xUndoManager.clear();
132 // prevents the leaveUndoContext in the dtor
136 HiddenUndoContext::~HiddenUndoContext()
140 if ( m_xUndoManager.is() )
141 m_xUndoManager->leaveUndoContext();
143 catch( const uno::Exception& )
145 DBG_UNHANDLED_EXCEPTION();
149 } // namespace chart
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */