xref: /aoo42x/main/forms/source/component/Button.hxx (revision 2d785d7e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FRM_BUTTON_HXX_
25 #define _FRM_BUTTON_HXX_
26 
27 #include "clickableimage.hxx"
28 #include "togglestate.hxx"
29 #include "formnavigation.hxx"
30 #include "resettable.hxx"
31 
32 #include <com/sun/star/awt/MouseEvent.hpp>
33 #include <com/sun/star/lang/EventObject.hpp>
34 #include <com/sun/star/awt/ActionEvent.hpp>
35 #include <com/sun/star/awt/XActionListener.hpp>
36 #include <com/sun/star/awt/XButton.hpp>
37 #include <com/sun/star/form/XReset.hpp>
38 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
39 
40 #include <cppuhelper/implbase1.hxx>
41 
42 //.........................................................................
43 namespace frm
44 {
45 //.........................................................................
46 
47 //==================================================================
48 // OButtonModel
49 //==================================================================
50 typedef ::cppu::ImplHelper1 <   ::com::sun::star::form::XReset
51                             >   OButtonModel_Base;
52 class OButtonModel  :public OClickableImageBaseModel
53                     ,public OButtonModel_Base
54 {
55 public:
56 	DECLARE_DEFAULT_LEAF_XTOR( OButtonModel );
57 
58     // UNO
59 	DECLARE_UNO3_AGG_DEFAULTS( OButtonModel, OClickableImageBaseModel );
60 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException);
61 
62     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
63 
64 // ::com::sun::star::lang::XServiceInfo
65 	IMPLEMENTATION_NAME(OButtonModel);
66 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
67 
68 // ::com::sun::star::io::XPersistObject
69 	virtual ::rtl::OUString SAL_CALL getServiceName() throw ( ::com::sun::star::uno::RuntimeException);
70 	virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
71 	virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
72 
73     // XReset
74     virtual void SAL_CALL reset(  ) throw (::com::sun::star::uno::RuntimeException);
75     virtual void SAL_CALL addResetListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
76     virtual void SAL_CALL removeResetListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
77 
78     // OControlModel's property handling
79 	virtual void describeFixedProperties(
80 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
81     ) const;
82 
83     // XPropertySet and friends
84     virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
85     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
86                 throw (::com::sun::star::uno::Exception);
87     virtual sal_Bool SAL_CALL convertFastPropertyValue(
88                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
89                 throw (::com::sun::star::lang::IllegalArgumentException);
90     virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const;
91 
92     // OComponentHelper
93     virtual void SAL_CALL disposing();
94 
95 protected:
96 	DECLARE_XCLONEABLE();
97 
98 private:
99     void    impl_resetNoBroadcast_nothrow();
100 
101     using ::cppu::OPropertySetHelper::getFastPropertyValue;
102 
103 private:
104     ResetHelper m_aResetHelper;
105 
106     // <properties>
107     ToggleState m_eDefaultState;          // the default check state
108     // </properties>
109 protected:
110     using OClickableImageBaseModel::disposing;
111 };
112 
113 //==================================================================
114 // OButtonControl
115 //==================================================================
116 typedef ::cppu::ImplHelper3 <   ::com::sun::star::awt::XButton
117                             ,   ::com::sun::star::awt::XActionListener
118                             ,   ::com::sun::star::beans::XPropertyChangeListener
119                             >   OButtonControl_BASE;
120 
121 class OButtonControl	:public OButtonControl_BASE
122                         ,public OClickableImageBaseControl
123                         ,public OFormNavigationHelper
124 {
125 private:
126 	sal_uLong m_nClickEvent;
127     sal_Int16   m_nTargetUrlFeatureId;
128     /// caches the value of the "Enabled" property of our model
129     sal_Bool    m_bEnabledByPropertyValue;
130 
131 protected:
132 
133 	// UNO Anbindung
134 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
135 
136 public:
137 	OButtonControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
138 	virtual ~OButtonControl();
139 
140     // XServiceInfo
141 	IMPLEMENTATION_NAME(OButtonControl);
142 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
143 
144     // UNO Anbindung
145 	DECLARE_UNO3_AGG_DEFAULTS(OButtonControl, OClickableImageBaseControl);
146 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException);
147 
148     // XActionListener
149 	virtual void SAL_CALL actionPerformed(const ::com::sun::star::awt::ActionEvent& rEvent) throw ( ::com::sun::star::uno::RuntimeException);
150 
151     // XButton
152 	virtual void SAL_CALL addActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
153     virtual void SAL_CALL removeActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
154     virtual void SAL_CALL setLabel(const ::rtl::OUString& Label) throw(::com::sun::star::uno::RuntimeException);
155     virtual void SAL_CALL setActionCommand(const ::rtl::OUString& _rCommand) throw(::com::sun::star::uno::RuntimeException);
156 
157     // OComponentHelper
158 	virtual void SAL_CALL disposing();
159 
160     // XPropertyChangeListener
161     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException);
162 
163     // XEventListener
164     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException);
165 
166     // XControl
167 	virtual sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxModel ) throw ( ::com::sun::star::uno::RuntimeException );
168     void SAL_CALL setDesignMode(sal_Bool bOn) throw (::com::sun::star::uno::RuntimeException);
169 
170 protected:
171     // OFormNavigationHelper overriables
172     virtual void    getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds );
173     virtual void    featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled );
174     virtual void    allFeatureStatesChanged( );
175     virtual bool    isEnabled( sal_Int16 _nFeatureId ) const;
176 
177     // XDispatchProviderInterception disambiguaiton
178     virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException);
179     virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException);
180 
181     // OImageControl overridables
182 	virtual void    actionPerformed_Impl( sal_Bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& _rEvt );
183 
184 private:
185 	DECL_LINK( OnClick, void* );
186 
187     /** to be called whenever the feature URL represented by our model has potentially changed
188     */
189     void        modelFeatureUrlPotentiallyChanged( );
190 
191     /** retrieves the feature id (see OFormNavigationHelper) of the TargetURL of
192         the model.
193     */
194     sal_Int16   getModelUrlFeatureId( ) const;
195 
196     /** starts or stops listening for changes in model properties we're interested in
197     */
198     void        startOrStopModelPropertyListening( bool _bStart );
199 };
200 
201 //.........................................................................
202 }	// namespace frm
203 //.........................................................................
204 
205 #endif // _FRM_BUTTON_HXX_
206 
207