Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / reportdesign / inc / UndoEnv.hxx
blobb0f3b863534a09cd1619a12ab64f31fbc629756e
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_REPORTDESIGN_INC_UNDOENV_HXX
20 #define INCLUDED_REPORTDESIGN_INC_UNDOENV_HXX
22 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
23 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
24 #include <com/sun/star/container/XContainerListener.hpp>
26 #include <cppuhelper/compbase.hxx>
27 #include <memory>
28 #include <svl/lstner.hxx>
30 namespace rptui
32 class OXUndoEnvironmentImpl;
35 class REPORTDESIGN_DLLPUBLIC OXUndoEnvironment
36 : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener
37 , css::container::XContainerListener
38 , css::util::XModifyListener
40 , public SfxListener
42 const ::std::unique_ptr<OXUndoEnvironmentImpl> m_pImpl;
44 OXUndoEnvironment(const OXUndoEnvironment&) = delete;
45 OXUndoEnvironment& operator=(const OXUndoEnvironment&) = delete;
47 protected:
48 virtual ~OXUndoEnvironment() override;
50 void SetUndoMode(bool _bUndo);
52 public:
53 OXUndoEnvironment(OReportModel& _rModel);
55 /**
56 Create an object ob OUndoEnvLock locks the undo possibility
57 As long as in the OUndoEnvLock scope, no undo is possible for manipulated object.
59 class OUndoEnvLock
61 OXUndoEnvironment& m_rUndoEnv;
62 public:
63 OUndoEnvLock(OXUndoEnvironment& _rUndoEnv): m_rUndoEnv(_rUndoEnv){m_rUndoEnv.Lock();}
64 ~OUndoEnvLock(){ m_rUndoEnv.UnLock(); }
67 /**
68 This is near the same as OUndoEnvLock but it is also possible to ask for the current mode.
69 UndoMode will set if SID_UNDO is called in execute()
71 class OUndoMode
73 OXUndoEnvironment& m_rUndoEnv;
74 public:
75 OUndoMode(OXUndoEnvironment& _rUndoEnv)
76 :m_rUndoEnv(_rUndoEnv)
78 m_rUndoEnv.Lock();
79 m_rUndoEnv.SetUndoMode(true);
81 ~OUndoMode()
83 m_rUndoEnv.SetUndoMode(false);
84 m_rUndoEnv.UnLock();
88 void Lock();
89 void UnLock();
90 bool IsLocked() const;
92 // returns sal_True is we are in UNDO
93 bool IsUndoMode() const;
95 // access control
96 struct Accessor { friend class OReportModel; private: Accessor() { } };
97 void Clear(const Accessor& _r);
99 void AddElement(const css::uno::Reference< css::uno::XInterface>& Element);
100 void RemoveElement(const css::uno::Reference< css::uno::XInterface>& Element);
102 void AddSection( const css::uno::Reference< css::report::XSection>& _xSection);
103 void RemoveSection( const css::uno::Reference< css::report::XSection>& _xSection );
104 /** removes the section from the page out of the undo env
106 * \param _pPage
108 void RemoveSection(OReportPage const * _pPage);
110 protected:
111 // XEventListener
112 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
114 // XPropertyChangeListener
115 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
117 // XContainerListener
118 virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& rEvent) override;
119 virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& rEvent) override;
120 virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& rEvent) override;
122 // XModifyListener
123 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
125 void ModeChanged();
127 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
129 private:
130 void implSetModified();
132 void switchListening( const css::uno::Reference< css::container::XIndexAccess >& _rxContainer, bool _bStartListening );
133 void switchListening( const css::uno::Reference< css::uno::XInterface >& _rxObject, bool _bStartListening );
135 ::std::vector< css::uno::Reference< css::container::XChild> >::const_iterator
136 getSection(const css::uno::Reference< css::container::XChild>& _xContainer) const;
140 #endif
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */