xref: /trunk/main/forms/source/component/Button.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 );
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();
70     virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
71     virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
72 
73     // XReset
74     virtual void SAL_CALL reset(  );
75     virtual void SAL_CALL addResetListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& aListener );
76     virtual void SAL_CALL removeResetListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& aListener );
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     virtual sal_Bool SAL_CALL convertFastPropertyValue(
87                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue );
88     virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const;
89 
90     // OComponentHelper
91     virtual void SAL_CALL disposing();
92 
93 protected:
94     DECLARE_XCLONEABLE();
95 
96 private:
97     void    impl_resetNoBroadcast_nothrow();
98 
99     using ::cppu::OPropertySetHelper::getFastPropertyValue;
100 
101 private:
102     ResetHelper m_aResetHelper;
103 
104     // <properties>
105     ToggleState m_eDefaultState;          // the default check state
106     // </properties>
107 protected:
108     using OClickableImageBaseModel::disposing;
109 };
110 
111 //==================================================================
112 // OButtonControl
113 //==================================================================
114 typedef ::cppu::ImplHelper3 <   ::com::sun::star::awt::XButton
115                             ,   ::com::sun::star::awt::XActionListener
116                             ,   ::com::sun::star::beans::XPropertyChangeListener
117                             >   OButtonControl_BASE;
118 
119 class OButtonControl    :public OButtonControl_BASE
120                         ,public OClickableImageBaseControl
121                         ,public OFormNavigationHelper
122 {
123 private:
124     sal_uLong m_nClickEvent;
125     sal_Int16   m_nTargetUrlFeatureId;
126     /// caches the value of the "Enabled" property of our model
127     sal_Bool    m_bEnabledByPropertyValue;
128 
129 protected:
130 
131     // UNO Anbindung
132     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
133 
134 public:
135     OButtonControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
136     virtual ~OButtonControl();
137 
138     // XServiceInfo
139     IMPLEMENTATION_NAME(OButtonControl);
140     virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
141 
142     // UNO Anbindung
143     DECLARE_UNO3_AGG_DEFAULTS(OButtonControl, OClickableImageBaseControl);
144     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType);
145 
146     // XActionListener
147     virtual void SAL_CALL actionPerformed(const ::com::sun::star::awt::ActionEvent& rEvent);
148 
149     // XButton
150     virtual void SAL_CALL addActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener>& _rxListener);
151     virtual void SAL_CALL removeActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener>& _rxListener);
152     virtual void SAL_CALL setLabel(const ::rtl::OUString& Label);
153     virtual void SAL_CALL setActionCommand(const ::rtl::OUString& _rCommand);
154 
155     // OComponentHelper
156     virtual void SAL_CALL disposing();
157 
158     // XPropertyChangeListener
159     virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt );
160 
161     // XEventListener
162     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource);
163 
164     // XControl
165     virtual sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxModel );
166     void SAL_CALL setDesignMode(sal_Bool bOn);
167 
168 protected:
169     // OFormNavigationHelper overriables
170     virtual void    getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds );
171     virtual void    featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled );
172     virtual void    allFeatureStatesChanged( );
173     virtual bool    isEnabled( sal_Int16 _nFeatureId ) const;
174 
175     // XDispatchProviderInterception disambiguaiton
176     virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor );
177     virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor );
178 
179     // OImageControl overridables
180     virtual void    actionPerformed_Impl( sal_Bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& _rEvt );
181 
182 private:
183     DECL_LINK( OnClick, void* );
184 
185     /** to be called whenever the feature URL represented by our model has potentially changed
186     */
187     void        modelFeatureUrlPotentiallyChanged( );
188 
189     /** retrieves the feature id (see OFormNavigationHelper) of the TargetURL of
190         the model.
191     */
192     sal_Int16   getModelUrlFeatureId( ) const;
193 
194     /** starts or stops listening for changes in model properties we're interested in
195     */
196     void        startOrStopModelPropertyListening( bool _bStart );
197 };
198 
199 //.........................................................................
200 }   // namespace frm
201 //.........................................................................
202 
203 #endif // _FRM_BUTTON_HXX_
204