Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX
21 : #define INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX
22 :
23 : #include <svx/svdundo.hxx>
24 : #include <svx/svdouno.hxx>
25 : #include "fmscriptingenv.hxx"
26 :
27 :
28 : #include <com/sun/star/util/XModifyListener.hpp>
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
31 : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
32 : #include <com/sun/star/script/ScriptEvent.hpp>
33 : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
34 : #include <com/sun/star/container/XIndexContainer.hpp>
35 : #include <com/sun/star/container/XContainerListener.hpp>
36 : #include <com/sun/star/container/ContainerEvent.hpp>
37 : #include <com/sun/star/container/XNameContainer.hpp>
38 : #include <cppuhelper/implbase3.hxx>
39 :
40 :
41 : #include <svl/lstner.hxx>
42 : #include <comphelper/uno3.hxx>
43 :
44 : class FmFormModel;
45 : class FmFormObj;
46 : class SdrObject;
47 :
48 11196 : class FmUndoPropertyAction: public SdrUndoAction
49 : {
50 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xObj;
51 : OUString aPropertyName;
52 : ::com::sun::star::uno::Any aNewValue;
53 : ::com::sun::star::uno::Any aOldValue;
54 :
55 : public:
56 : FmUndoPropertyAction(FmFormModel& rMod, const ::com::sun::star::beans::PropertyChangeEvent& evt);
57 :
58 : virtual void Undo() SAL_OVERRIDE;
59 : virtual void Redo() SAL_OVERRIDE;
60 :
61 : virtual OUString GetComment() const SAL_OVERRIDE;
62 :
63 : };
64 :
65 : class FmUndoContainerAction: public SdrUndoAction
66 : {
67 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
68 : m_xContainer; // container which the action applies to
69 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
70 : m_xElement; // object not owned by the action
71 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
72 : m_xOwnElement; // object owned by the action
73 : sal_Int32 m_nIndex; // index of the object within it's container
74 : ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >
75 : m_aEvents; // events of the object
76 :
77 : public:
78 : enum Action
79 : {
80 : Inserted = 1,
81 : Removed = 2
82 : };
83 :
84 : private:
85 : Action m_eAction;
86 :
87 : public:
88 : FmUndoContainerAction(FmFormModel& rMod,
89 : Action _eAction,
90 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& xCont,
91 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xElem,
92 : sal_Int32 nIdx = -1);
93 : virtual ~FmUndoContainerAction();
94 :
95 : virtual void Undo() SAL_OVERRIDE;
96 : virtual void Redo() SAL_OVERRIDE;
97 :
98 : static void DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xElem );
99 :
100 : protected:
101 : void implReInsert( );
102 : void implReRemove( );
103 : };
104 :
105 : class FmUndoModelReplaceAction : public SdrUndoAction
106 : {
107 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> m_xReplaced;
108 : SdrUnoObj* m_pObject;
109 :
110 : public:
111 : FmUndoModelReplaceAction(FmFormModel& rMod, SdrUnoObj* pObject, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced);
112 : virtual ~FmUndoModelReplaceAction();
113 :
114 : virtual void Undo() SAL_OVERRIDE;
115 0 : virtual void Redo() SAL_OVERRIDE { Undo(); }
116 :
117 : virtual OUString GetComment() const SAL_OVERRIDE;
118 :
119 : static void DisposeElement( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>& xReplaced );
120 : };
121 :
122 :
123 : class SVX_DLLPRIVATE FmXUndoEnvironment
124 : : public ::cppu::WeakImplHelper3< ::com::sun::star::beans::XPropertyChangeListener
125 : , ::com::sun::star::container::XContainerListener
126 : , ::com::sun::star::util::XModifyListener
127 : >
128 : , public SfxListener
129 : // public ::cppu::OWeakObject
130 : {
131 : FmFormModel& rModel;
132 :
133 : void* m_pPropertySetCache;
134 : ::svxform::PFormScriptingEnvironment m_pScriptingEnv;
135 : oslInterlockedCount m_Locks;
136 : ::osl::Mutex m_aMutex;
137 : bool bReadOnly;
138 : bool m_bDisposed;
139 :
140 : public:
141 : FmXUndoEnvironment(FmFormModel& _rModel);
142 : virtual ~FmXUndoEnvironment();
143 :
144 : // UNO Anbindung
145 : // SMART_UNO_DECLARATION(FmXUndoEnvironment, ::cppu::OWeakObject);
146 : // virtual sal_Bool queryInterface(UsrUik, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>&);
147 : // virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::reflection::XIdlClass>> getIdlClasses();
148 :
149 956 : void Lock() { osl_atomic_increment( &m_Locks ); }
150 956 : void UnLock() { osl_atomic_decrement( &m_Locks ); }
151 7847 : bool IsLocked() const { return m_Locks != 0; }
152 :
153 : // access control
154 3927 : struct Accessor { friend class FmFormModel; private: Accessor() { } };
155 :
156 : // addition and removal of form collections
157 : void AddForms( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& rForms );
158 : void RemoveForms( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer>& rForms );
159 :
160 : // readonly-ness
161 3927 : void SetReadOnly( bool bRead, const Accessor& ) { bReadOnly = bRead; }
162 3927 : bool IsReadOnly() const {return bReadOnly;}
163 :
164 : protected:
165 : // XEventListener
166 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
167 :
168 : // XPropertyChangeListener
169 : virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 :
171 : // XContainerListener
172 : virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
173 : virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
174 : virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& rEvent) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 :
176 : // XModifyListener
177 : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
178 :
179 : void ModeChanged();
180 : void dispose();
181 :
182 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
183 :
184 : private:
185 : void AddElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
186 : void RemoveElement(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
187 : void TogglePropertyListening(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& Element);
188 :
189 : void implSetModified();
190 :
191 : void switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& _rxContainer, bool _bStartListening );
192 : void switchListening( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject, bool _bStartListening );
193 : ::com::sun::star::uno::Reference< com::sun::star::script::XScriptListener > m_vbaListener;
194 : public:
195 : // Methoden zur Zuordnung von Controls zu Forms,
196 : // werden von der Seite und der UndoUmgebung genutzt
197 : void Inserted(SdrObject* pObj);
198 : void Removed(SdrObject* pObj);
199 :
200 : static void Inserted(FmFormObj* pObj);
201 : static void Removed(FmFormObj* pObj);
202 : };
203 :
204 :
205 : #endif // INCLUDED_SVX_SOURCE_INC_FMUNDO_HXX
206 :
207 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|