tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / reportdesign / inc / UndoEnv.hxx
blob823c07b2cfc0ee2dd433773e1fa9fa492db28be3
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/container/XIndexAccess.hpp>
26 #include <com/sun/star/util/XModifyListener.hpp>
27 #include <com/sun/star/report/XSection.hpp>
29 #include <memory>
30 #include <cppuhelper/implbase.hxx>
31 #include <svl/lstner.hxx>
32 #include "dllapi.h"
33 #include "RptPage.hxx"
35 namespace rptui
37 class OXUndoEnvironmentImpl;
40 class SAL_DLLPUBLIC_RTTI OXUndoEnvironment final
41 : public ::cppu::WeakImplHelper< css::beans::XPropertyChangeListener
42 , css::container::XContainerListener
43 , css::util::XModifyListener
45 , public SfxListener
47 const ::std::unique_ptr<OXUndoEnvironmentImpl> m_pImpl;
49 OXUndoEnvironment(const OXUndoEnvironment&) = delete;
50 OXUndoEnvironment& operator=(const OXUndoEnvironment&) = delete;
52 virtual ~OXUndoEnvironment() override;
54 REPORTDESIGN_DLLPUBLIC void SetUndoMode(bool _bUndo);
56 public:
57 OXUndoEnvironment(OReportModel& _rModel);
59 /**
60 Create an object ob OUndoEnvLock locks the undo possibility
61 As long as in the OUndoEnvLock scope, no undo is possible for manipulated object.
63 class OUndoEnvLock
65 OXUndoEnvironment& m_rUndoEnv;
66 public:
67 OUndoEnvLock(OXUndoEnvironment& _rUndoEnv): m_rUndoEnv(_rUndoEnv){m_rUndoEnv.Lock();}
68 ~OUndoEnvLock(){ m_rUndoEnv.UnLock(); }
71 /**
72 This is near the same as OUndoEnvLock but it is also possible to ask for the current mode.
73 UndoMode will set if SID_UNDO is called in execute()
75 class OUndoMode
77 OXUndoEnvironment& m_rUndoEnv;
78 public:
79 OUndoMode(OXUndoEnvironment& _rUndoEnv)
80 :m_rUndoEnv(_rUndoEnv)
82 m_rUndoEnv.Lock();
83 m_rUndoEnv.SetUndoMode(true);
85 ~OUndoMode()
87 m_rUndoEnv.SetUndoMode(false);
88 m_rUndoEnv.UnLock();
92 REPORTDESIGN_DLLPUBLIC void Lock();
93 REPORTDESIGN_DLLPUBLIC void UnLock();
94 bool IsLocked() const;
96 // returns sal_True is we are in UNDO
97 bool IsUndoMode() const;
99 // access control
100 struct Accessor { friend class OReportModel; private: Accessor() { } };
101 void Clear(const Accessor& _r);
103 REPORTDESIGN_DLLPUBLIC void AddElement(const css::uno::Reference< css::uno::XInterface>& Element);
104 REPORTDESIGN_DLLPUBLIC void RemoveElement(const css::uno::Reference< css::uno::XInterface>& Element);
106 void AddSection( const css::uno::Reference< css::report::XSection>& _xSection);
107 void RemoveSection( const css::uno::Reference< css::report::XSection>& _xSection );
108 /** removes the section from the page out of the undo env
110 * \param _pPage
112 void RemoveSection(OReportPage const * _pPage);
114 private:
115 // XEventListener
116 virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override;
118 // XPropertyChangeListener
119 virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent& evt) override;
121 // XContainerListener
122 virtual void SAL_CALL elementInserted(const css::container::ContainerEvent& rEvent) override;
123 virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent& rEvent) override;
124 virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent& rEvent) override;
126 // XModifyListener
127 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
129 void ModeChanged();
131 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
133 private:
134 void implSetModified();
136 void switchListening( const css::uno::Reference< css::container::XIndexAccess >& _rxContainer, bool _bStartListening );
137 void switchListening( const css::uno::Reference< css::uno::XInterface >& _rxObject, bool _bStartListening );
139 ::std::vector< css::uno::Reference< css::container::XChild> >::const_iterator
140 getSection(const css::uno::Reference< css::container::XChild>& _xContainer) const;
144 #endif
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */