1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _FRM_BUTTON_HXX_ 29 #define _FRM_BUTTON_HXX_ 30 31 #include "clickableimage.hxx" 32 #include "togglestate.hxx" 33 #include "formnavigation.hxx" 34 #include "resettable.hxx" 35 36 #include <com/sun/star/awt/MouseEvent.hpp> 37 #include <com/sun/star/lang/EventObject.hpp> 38 #include <com/sun/star/awt/ActionEvent.hpp> 39 #include <com/sun/star/awt/XActionListener.hpp> 40 #include <com/sun/star/awt/XButton.hpp> 41 #include <com/sun/star/form/XReset.hpp> 42 #include <com/sun/star/beans/PropertyChangeEvent.hpp> 43 44 #include <cppuhelper/implbase1.hxx> 45 46 //......................................................................... 47 namespace frm 48 { 49 //......................................................................... 50 51 //================================================================== 52 // OButtonModel 53 //================================================================== 54 typedef ::cppu::ImplHelper1 < ::com::sun::star::form::XReset 55 > OButtonModel_Base; 56 class OButtonModel :public OClickableImageBaseModel 57 ,public OButtonModel_Base 58 { 59 public: 60 DECLARE_DEFAULT_LEAF_XTOR( OButtonModel ); 61 62 // UNO 63 DECLARE_UNO3_AGG_DEFAULTS( OButtonModel, OClickableImageBaseModel ); 64 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException); 65 66 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes(); 67 68 // ::com::sun::star::lang::XServiceInfo 69 IMPLEMENTATION_NAME(OButtonModel); 70 virtual StringSequence SAL_CALL getSupportedServiceNames() throw(); 71 72 // ::com::sun::star::io::XPersistObject 73 virtual ::rtl::OUString SAL_CALL getServiceName() throw ( ::com::sun::star::uno::RuntimeException); 74 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); 75 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); 76 77 // XReset 78 virtual void SAL_CALL reset( ) throw (::com::sun::star::uno::RuntimeException); 79 virtual void SAL_CALL addResetListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 80 virtual void SAL_CALL removeResetListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::XResetListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); 81 82 // OControlModel's property handling 83 virtual void describeFixedProperties( 84 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps 85 ) const; 86 87 // XPropertySet and friends 88 virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const; 89 virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) 90 throw (::com::sun::star::uno::Exception); 91 virtual sal_Bool SAL_CALL convertFastPropertyValue( 92 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue ) 93 throw (::com::sun::star::lang::IllegalArgumentException); 94 virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const; 95 96 // OComponentHelper 97 virtual void SAL_CALL disposing(); 98 99 protected: 100 DECLARE_XCLONEABLE(); 101 102 private: 103 void impl_resetNoBroadcast_nothrow(); 104 105 using ::cppu::OPropertySetHelper::getFastPropertyValue; 106 107 private: 108 ResetHelper m_aResetHelper; 109 110 // <properties> 111 ToggleState m_eDefaultState; // the default check state 112 // </properties> 113 protected: 114 using OClickableImageBaseModel::disposing; 115 }; 116 117 //================================================================== 118 // OButtonControl 119 //================================================================== 120 typedef ::cppu::ImplHelper3 < ::com::sun::star::awt::XButton 121 , ::com::sun::star::awt::XActionListener 122 , ::com::sun::star::beans::XPropertyChangeListener 123 > OButtonControl_BASE; 124 125 class OButtonControl :public OButtonControl_BASE 126 ,public OClickableImageBaseControl 127 ,public OFormNavigationHelper 128 { 129 private: 130 sal_uLong m_nClickEvent; 131 sal_Int16 m_nTargetUrlFeatureId; 132 /// caches the value of the "Enabled" property of our model 133 sal_Bool m_bEnabledByPropertyValue; 134 135 protected: 136 137 // UNO Anbindung 138 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes(); 139 140 public: 141 OButtonControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory); 142 virtual ~OButtonControl(); 143 144 // XServiceInfo 145 IMPLEMENTATION_NAME(OButtonControl); 146 virtual StringSequence SAL_CALL getSupportedServiceNames() throw(); 147 148 // UNO Anbindung 149 DECLARE_UNO3_AGG_DEFAULTS(OButtonControl, OClickableImageBaseControl); 150 virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType) throw(::com::sun::star::uno::RuntimeException); 151 152 // XActionListener 153 virtual void SAL_CALL actionPerformed(const ::com::sun::star::awt::ActionEvent& rEvent) throw ( ::com::sun::star::uno::RuntimeException); 154 155 // XButton 156 virtual void SAL_CALL addActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException); 157 virtual void SAL_CALL removeActionListener(const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException); 158 virtual void SAL_CALL setLabel(const ::rtl::OUString& Label) throw(::com::sun::star::uno::RuntimeException); 159 virtual void SAL_CALL setActionCommand(const ::rtl::OUString& _rCommand) throw(::com::sun::star::uno::RuntimeException); 160 161 // OComponentHelper 162 virtual void SAL_CALL disposing(); 163 164 // XPropertyChangeListener 165 virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw(::com::sun::star::uno::RuntimeException); 166 167 // XEventListener 168 virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException); 169 170 // XControl 171 virtual sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxModel ) throw ( ::com::sun::star::uno::RuntimeException ); 172 void SAL_CALL setDesignMode(sal_Bool bOn) throw (::com::sun::star::uno::RuntimeException); 173 174 protected: 175 // OFormNavigationHelper overriables 176 virtual void getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds ); 177 virtual void featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled ); 178 virtual void allFeatureStatesChanged( ); 179 virtual bool isEnabled( sal_Int16 _nFeatureId ) const; 180 181 // XDispatchProviderInterception disambiguaiton 182 virtual void SAL_CALL registerDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); 183 virtual void SAL_CALL releaseDispatchProviderInterceptor( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProviderInterceptor >& Interceptor ) throw (::com::sun::star::uno::RuntimeException); 184 185 // OImageControl overridables 186 virtual void actionPerformed_Impl( sal_Bool bNotifyListener, const ::com::sun::star::awt::MouseEvent& _rEvt ); 187 188 private: 189 DECL_LINK( OnClick, void* ); 190 191 /** to be called whenever the feature URL represented by our model has potentially changed 192 */ 193 void modelFeatureUrlPotentiallyChanged( ); 194 195 /** retrieves the feature id (see OFormNavigationHelper) of the TargetURL of 196 the model. 197 */ 198 sal_Int16 getModelUrlFeatureId( ) const; 199 200 /** starts or stops listening for changes in model properties we're interested in 201 */ 202 void startOrStopModelPropertyListening( bool _bStart ); 203 }; 204 205 //......................................................................... 206 } // namespace frm 207 //......................................................................... 208 209 #endif // _FRM_BUTTON_HXX_ 210 211