Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / main / UndoGuard.hxx
blob5f3331ed63c050a4c02810f9503ae3dba00601c5
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_UNDOGUARD_HXX
20 #define INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_UNDOGUARD_HXX
22 #include "ChartModelClone.hxx"
24 #include <rtl/ustring.hxx>
26 #include <memory>
28 namespace com { namespace sun { namespace star { namespace document { class XUndoManager; } } } }
29 namespace com { namespace sun { namespace star { namespace frame { class XModel; } } } }
31 namespace chart
34 /** A guard which does nothing, unless you explicitly call commitAction. In particular, in its destructor, it
35 does neither auto-commit nor auto-rollback the model changes.
37 class UndoGuard
39 public:
40 explicit UndoGuard(
41 const OUString& i_undoMessage,
42 const css::uno::Reference< css::document::XUndoManager > & i_undoManager,
43 const ModelFacet i_facet = E_MODEL
45 ~UndoGuard();
47 void commit();
48 void rollback();
50 protected:
51 bool isActionPosted() const { return m_bActionPosted; }
53 private:
54 void discardSnapshot();
56 private:
57 const css::uno::Reference< css::frame::XModel > m_xChartModel;
58 const css::uno::Reference< css::document::XUndoManager > m_xUndoManager;
60 std::shared_ptr< ChartModelClone > m_pDocumentSnapshot;
61 OUString m_aUndoString;
62 bool m_bActionPosted;
65 /** A guard which, in its destructor, restores the model state it found in the constructor. If
66 <member>commitAction</member> is called inbetween, the restoration is not performed.
68 class UndoLiveUpdateGuard : public UndoGuard
70 public:
71 explicit UndoLiveUpdateGuard(
72 const OUString& i_undoMessage,
73 const css::uno::Reference< css::document::XUndoManager > & i_undoManager
75 ~UndoLiveUpdateGuard();
78 /** Same as UndoLiveUpdateGuard but with additional storage of the chart's data.
79 Only use this if the data has internal data.
81 class UndoLiveUpdateGuardWithData :
82 public UndoGuard
84 public:
85 explicit UndoLiveUpdateGuardWithData(
86 const OUString& i_undoMessage,
87 const css::uno::Reference< css::document::XUndoManager > & i_undoManager
89 ~UndoLiveUpdateGuardWithData();
92 class UndoGuardWithSelection : public UndoGuard
94 public:
95 explicit UndoGuardWithSelection(
96 const OUString& i_undoMessage,
97 const css::uno::Reference< css::document::XUndoManager > & i_undoManager
99 virtual ~UndoGuardWithSelection();
102 class HiddenUndoContext
104 public:
105 explicit HiddenUndoContext(
106 const css::uno::Reference< css::document::XUndoManager > & i_undoManager
108 ~HiddenUndoContext();
110 private:
111 css::uno::Reference< css::document::XUndoManager > m_xUndoManager;
115 // INCLUDED_CHART2_SOURCE_CONTROLLER_MAIN_UNDOGUARD_HXX
116 #endif
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */