Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / reportdesign / inc / UndoEnv.hxx
blobb36ebea50f44c3838114d38f506c0a00845ccede
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>
25 #include <com/sun/star/report/XReportDefinition.hpp>
27 #include <cppuhelper/compbase.hxx>
28 #include <memory>
29 #include <svl/lstner.hxx>
31 namespace rptui
33 class OXUndoEnvironmentImpl;
36 class REPORTDESIGN_DLLPUBLIC OXUndoEnvironment
37 : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener
38 , css::container::XContainerListener
39 , css::util::XModifyListener
41 , public SfxListener
43 const ::std::unique_ptr<OXUndoEnvironmentImpl> m_pImpl;
45 OXUndoEnvironment(const OXUndoEnvironment&) = delete;
46 OXUndoEnvironment& operator=(const OXUndoEnvironment&) = delete;
48 protected:
49 virtual ~OXUndoEnvironment() override;
51 void SetUndoMode(bool _bUndo);
53 public:
54 OXUndoEnvironment(OReportModel& _rModel);
56 /**
57 Create an object ob OUndoEnvLock locks the undo possibility
58 As long as in the OUndoEnvLock scope, no undo is possible for manipulated object.
60 class OUndoEnvLock
62 OXUndoEnvironment& m_rUndoEnv;
63 public:
64 OUndoEnvLock(OXUndoEnvironment& _rUndoEnv): m_rUndoEnv(_rUndoEnv){m_rUndoEnv.Lock();}
65 ~OUndoEnvLock(){ m_rUndoEnv.UnLock(); }
68 /**
69 This is near the same as OUndoEnvLock but it is also possible to ask for the current mode.
70 UndoMode will set if SID_UNDO is called in execute()
72 class OUndoMode
74 OXUndoEnvironment& m_rUndoEnv;
75 public:
76 OUndoMode(OXUndoEnvironment& _rUndoEnv)
77 :m_rUndoEnv(_rUndoEnv)
79 m_rUndoEnv.Lock();
80 m_rUndoEnv.SetUndoMode(true);
82 ~OUndoMode()
84 m_rUndoEnv.SetUndoMode(false);
85 m_rUndoEnv.UnLock();
89 void Lock();
90 void UnLock();
91 bool IsLocked() const;
93 // returns sal_True is we are in UNDO
94 bool IsUndoMode() const;
96 // access control
97 struct Accessor { friend class OReportModel; private: Accessor() { } };
98 void Clear(const Accessor& _r);
100 void AddElement(const css::uno::Reference< css::uno::XInterface>& Element);
101 void RemoveElement(const css::uno::Reference< css::uno::XInterface>& Element);
103 void AddSection( const css::uno::Reference< css::report::XSection>& _xSection);
104 void RemoveSection( const css::uno::Reference< css::report::XSection>& _xSection );
105 /** removes the section from the page out of the undo env
107 * \param _pPage
109 void RemoveSection(OReportPage* _pPage);
111 protected:
112 // XEventListener
113 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
115 // XPropertyChangeListener
116 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
118 // XContainerListener
119 virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& rEvent) override;
120 virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& rEvent) override;
121 virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& rEvent) override;
123 // XModifyListener
124 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
126 void ModeChanged();
128 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
130 private:
131 void TogglePropertyListening(const css::uno::Reference< css::uno::XInterface>& Element);
133 void implSetModified();
135 void switchListening( const css::uno::Reference< css::container::XIndexAccess >& _rxContainer, bool _bStartListening );
136 void switchListening( const css::uno::Reference< css::uno::XInterface >& _rxObject, bool _bStartListening );
138 ::std::vector< css::uno::Reference< css::container::XChild> >::const_iterator
139 getSection(const css::uno::Reference< css::container::XChild>& _xContainer) const;
143 #endif
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */