xref: /AOO41X/main/extensions/source/propctrlr/eventhandler.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
29*cdf0e10cSrcweir #define EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "pcrcomponentcontext.hxx"
32*cdf0e10cSrcweir #include "pcrcommontypes.hxx"
33*cdf0e10cSrcweir #include "pcrcommon.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir /** === begin UNO includes === **/
36*cdf0e10cSrcweir #include <com/sun/star/script/ScriptEventDescriptor.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/inspection/XPropertyHandler.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
41*cdf0e10cSrcweir /** === end UNO includes === **/
42*cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx>
43*cdf0e10cSrcweir #include <comphelper/listenernotification.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir //........................................................................
46*cdf0e10cSrcweir namespace pcr
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir //........................................................................
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir     //====================================================================
51*cdf0e10cSrcweir     //= EventDescription
52*cdf0e10cSrcweir     //====================================================================
53*cdf0e10cSrcweir     typedef sal_Int32   EventId;
54*cdf0e10cSrcweir     struct EventDescription
55*cdf0e10cSrcweir     {
56*cdf0e10cSrcweir     public:
57*cdf0e10cSrcweir         ::rtl::OUString sDisplayName;
58*cdf0e10cSrcweir         ::rtl::OUString sListenerClassName;
59*cdf0e10cSrcweir         ::rtl::OUString sListenerMethodName;
60*cdf0e10cSrcweir         ::rtl::OString  sHelpId;
61*cdf0e10cSrcweir         ::rtl::OString  sUniqueBrowseId;
62*cdf0e10cSrcweir         EventId         nId;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir         EventDescription()
65*cdf0e10cSrcweir             :nId( 0 )
66*cdf0e10cSrcweir             {
67*cdf0e10cSrcweir             }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir         EventDescription(
70*cdf0e10cSrcweir             EventId _nId,
71*cdf0e10cSrcweir             const sal_Char* _pListenerNamespaceAscii,
72*cdf0e10cSrcweir             const sal_Char* _pListenerClassAsciiName,
73*cdf0e10cSrcweir             const sal_Char* _pListenerMethodAsciiName,
74*cdf0e10cSrcweir             sal_uInt16 _nDisplayNameResId,
75*cdf0e10cSrcweir             const rtl::OString& _sHelpId,
76*cdf0e10cSrcweir             const rtl::OString& _sUniqueBrowseId );
77*cdf0e10cSrcweir     };
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir     typedef ::std::hash_map< ::rtl::OUString, EventDescription, ::rtl::OUStringHash >   EventMap;
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     //====================================================================
82*cdf0e10cSrcweir     //= EventHandler
83*cdf0e10cSrcweir     //====================================================================
84*cdf0e10cSrcweir     typedef ::cppu::WeakComponentImplHelper2    <   ::com::sun::star::inspection::XPropertyHandler
85*cdf0e10cSrcweir                                                 ,   ::com::sun::star::lang::XServiceInfo
86*cdf0e10cSrcweir                                                 >   EventHandler_Base;
87*cdf0e10cSrcweir     class EventHandler : public EventHandler_Base
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir     private:
90*cdf0e10cSrcweir         mutable ::osl::Mutex    m_aMutex;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         /// the context in which the instance was created
93*cdf0e10cSrcweir         ComponentContext                                                            m_aContext;
94*cdf0e10cSrcweir         /// the properties of the object we're handling
95*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >   m_xComponent;
96*cdf0e10cSrcweir         /// our XPropertyChangeListener(s)
97*cdf0e10cSrcweir         PropertyChangeListeners                                                     m_aPropertyListeners;
98*cdf0e10cSrcweir         /// cache of the events we found at our introspectee
99*cdf0e10cSrcweir         EventMap                                                                    m_aEvents;
100*cdf0e10cSrcweir         /// has m_aEvents been initialized?
101*cdf0e10cSrcweir         bool                                                                        m_bEventsMapInitialized;
102*cdf0e10cSrcweir         /// is our introspectee a dialog element?
103*cdf0e10cSrcweir         bool                                                                        m_bIsDialogElement;
104*cdf0e10cSrcweir             // TODO: move different handling into different derived classes?
105*cdf0e10cSrcweir         /// (FormComponent) type of the grid column being inspected, or -1 if we're not inspecting a grid column
106*cdf0e10cSrcweir         sal_Int16                                                                   m_nGridColumnType;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir     public:
109*cdf0e10cSrcweir         // XServiceInfo - static versions
110*cdf0e10cSrcweir         static ::rtl::OUString SAL_CALL getImplementationName_static(  ) throw (::com::sun::star::uno::RuntimeException);
111*cdf0e10cSrcweir         static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(  ) throw (::com::sun::star::uno::RuntimeException);
112*cdf0e10cSrcweir         static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > Create( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     protected:
115*cdf0e10cSrcweir         EventHandler(
116*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext
117*cdf0e10cSrcweir        );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         ~EventHandler();
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     protected:
122*cdf0e10cSrcweir         // XPropertyHandler overridables
123*cdf0e10cSrcweir         virtual void                                                SAL_CALL inspect( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxIntrospectee ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
124*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any                          SAL_CALL getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
125*cdf0e10cSrcweir         virtual void                                                SAL_CALL setPropertyValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
126*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any                          SAL_CALL convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rControlValue ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
127*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Any                          SAL_CALL convertToControlValue( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Any& _rPropertyValue, const ::com::sun::star::uno::Type& _rControlValueType ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
128*cdf0e10cSrcweir         virtual ::com::sun::star::beans::PropertyState              SAL_CALL getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
129*cdf0e10cSrcweir         virtual void                                                SAL_CALL addPropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
130*cdf0e10cSrcweir         virtual void                                                SAL_CALL removePropertyChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
131*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >
132*cdf0e10cSrcweir                                                                     SAL_CALL getSupportedProperties() throw (::com::sun::star::uno::RuntimeException);
133*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >  SAL_CALL getSupersededProperties( ) throw (::com::sun::star::uno::RuntimeException);
134*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >  SAL_CALL getActuatingProperties( ) throw (::com::sun::star::uno::RuntimeException);
135*cdf0e10cSrcweir         virtual ::com::sun::star::inspection::LineDescriptor        SAL_CALL describePropertyLine( const ::rtl::OUString& _rPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlFactory >& _rxControlFactory ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
136*cdf0e10cSrcweir         virtual ::sal_Bool                                          SAL_CALL isComposable( const ::rtl::OUString& _rPropertyName ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException);
137*cdf0e10cSrcweir         virtual ::com::sun::star::inspection::InteractiveSelectionResult
138*cdf0e10cSrcweir                                                                     SAL_CALL onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, ::com::sun::star::uno::Any& _rData, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI ) throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
139*cdf0e10cSrcweir         virtual void                                                SAL_CALL actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const ::com::sun::star::uno::Any& _rNewValue, const ::com::sun::star::uno::Any& _rOldValue, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
140*cdf0e10cSrcweir         virtual sal_Bool                                            SAL_CALL suspend( sal_Bool _bSuspend ) throw (::com::sun::star::uno::RuntimeException);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir         // XComponent
143*cdf0e10cSrcweir         DECLARE_XCOMPONENT()
144*cdf0e10cSrcweir         virtual void                                                SAL_CALL disposing();
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir         // XServiceInfo
147*cdf0e10cSrcweir         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
148*cdf0e10cSrcweir         virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
149*cdf0e10cSrcweir         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     private:
152*cdf0e10cSrcweir         /** returns the script events associated with our introspectee
153*cdf0e10cSrcweir             @param  _out_rEvents
154*cdf0e10cSrcweir                 Takes, upon successfull return, the events currently associated with the introspectee
155*cdf0e10cSrcweir             @precond
156*cdf0e10cSrcweir                 Our introspectee is a form component
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         void    impl_getFormComponentScriptEvents_nothrow(
159*cdf0e10cSrcweir                     ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
160*cdf0e10cSrcweir                 ) const;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         /** returns the script events associated with our introspectee
163*cdf0e10cSrcweir             @param  _out_rEvents
164*cdf0e10cSrcweir                 Takes, upon successfull return, the events currently associated with the introspectee
165*cdf0e10cSrcweir             @precond
166*cdf0e10cSrcweir                 Our introspectee is a dialog element
167*cdf0e10cSrcweir         */
168*cdf0e10cSrcweir         void    impl_getDialogElementScriptEvents_nothrow(
169*cdf0e10cSrcweir                     ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
170*cdf0e10cSrcweir                 ) const;
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir         /** returns the script events associated with our introspectee
173*cdf0e10cSrcweir             @param  _out_rEvents
174*cdf0e10cSrcweir                 Takes, the events currently associated with the introspectee
175*cdf0e10cSrcweir         */
176*cdf0e10cSrcweir         inline void impl_getComponentScriptEvents_nothrow(
177*cdf0e10cSrcweir                     ::com::sun::star::uno::Sequence< ::com::sun::star::script::ScriptEventDescriptor >& _out_rEvents
178*cdf0e10cSrcweir                 ) const
179*cdf0e10cSrcweir         {
180*cdf0e10cSrcweir             if ( m_bIsDialogElement )
181*cdf0e10cSrcweir                 impl_getDialogElementScriptEvents_nothrow( _out_rEvents );
182*cdf0e10cSrcweir             else
183*cdf0e10cSrcweir                 impl_getFormComponentScriptEvents_nothrow( _out_rEvents );
184*cdf0e10cSrcweir         }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         /** returns the types of the listeners which can be registered at our introspectee
187*cdf0e10cSrcweir             @param  _out_rTypes
188*cdf0e10cSrcweir                 Takes, upon successfull return, the types of possible listeners at the introspectee
189*cdf0e10cSrcweir         */
190*cdf0e10cSrcweir         void    impl_getCopmonentListenerTypes_nothrow(
191*cdf0e10cSrcweir                     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >& _out_rTypes
192*cdf0e10cSrcweir                 ) const;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         /** returns a secondary component to be used for event inspection
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir             In the UI, we want to mix events for the control model with events for the control.
197*cdf0e10cSrcweir             Since our introspectee is a model, this method creates a control for it (if possible).
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir             @return
200*cdf0e10cSrcweir                 the secondary component whose events should be mixed with the introspectee's events
201*cdf0e10cSrcweir                 The caller takes the ownership of the component (if not <NULL/>).
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir             @throws
204*cdf0e10cSrcweir                 if an unexpected error occurs during creation of the secondary component.
205*cdf0e10cSrcweir                 A <NULL/> component to be returned is not unexpected, but allowed
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir             @precond
208*cdf0e10cSrcweir                 ->m_xComponent is not <NULL/>
209*cdf0e10cSrcweir         */
210*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
211*cdf0e10cSrcweir                 impl_getSecondaryComponentForEventInspection_throw( ) const;
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir         /** returns the event description for the given (programmatic) property name
214*cdf0e10cSrcweir             @param  _rPropertyName
215*cdf0e10cSrcweir                 the name whose event description should be looked up
216*cdf0e10cSrcweir             @return
217*cdf0e10cSrcweir                 the event description for the property name
218*cdf0e10cSrcweir             @throws ::com::sun::star::beans::UnknownPropertyException
219*cdf0e10cSrcweir                 if our introspectee does not have an event with the given logical name (see ->getSupportedProperties)
220*cdf0e10cSrcweir         */
221*cdf0e10cSrcweir         const EventDescription&
222*cdf0e10cSrcweir                 impl_getEventForName_throw( const ::rtl::OUString& _rPropertyName ) const;
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir         /** returns the index of our component within its parent, if this parent can be
225*cdf0e10cSrcweir             obtained  (XChild::getParent) and supports an ->XIndexAccess interface
226*cdf0e10cSrcweir         */
227*cdf0e10cSrcweir         sal_Int32   impl_getComponentIndexInParent_throw() const;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir         /** sets a given script event as event handler at a form component
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir             @param  _rScriptEvent
232*cdf0e10cSrcweir                 the script event to set
233*cdf0e10cSrcweir         */
234*cdf0e10cSrcweir         void    impl_setFormComponentScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent );
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir         /** sets a given script event as event handler at a dialog component
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir             @param  _rScriptEvent
239*cdf0e10cSrcweir                 the script event to set
240*cdf0e10cSrcweir         */
241*cdf0e10cSrcweir         void    impl_setDialogElementScriptEvent_nothrow( const ::com::sun::star::script::ScriptEventDescriptor& _rScriptEvent );
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir         /** returns the frame associated with our context document
244*cdf0e10cSrcweir         */
245*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >
246*cdf0e10cSrcweir                 impl_getContextFrame_nothrow() const;
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir         /** approves or denies a certain method to be included in the UI
249*cdf0e10cSrcweir             @return
250*cdf0e10cSrcweir                 <TRUE/> if and only if the given method is allowed.
251*cdf0e10cSrcweir         */
252*cdf0e10cSrcweir         bool    impl_filterMethod_nothrow( const EventDescription& _rEvent ) const;
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir     private:
255*cdf0e10cSrcweir         EventHandler();                                 // never implemented
256*cdf0e10cSrcweir         EventHandler( const EventHandler& );            // never implemented
257*cdf0e10cSrcweir         EventHandler& operator=( const EventHandler& ); // never implemented
258*cdf0e10cSrcweir     };
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir //........................................................................
261*cdf0e10cSrcweir } // namespace pcr
262*cdf0e10cSrcweir //........................................................................
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir #endif // EXTENSIONS_SOURCE_PROPCTRLR_EVENTHANDLER_HXX
265*cdf0e10cSrcweir 
266