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_FORMS_SOURCE_COMPONENT_BUTTON_HXX
21 #define INCLUDED_FORMS_SOURCE_COMPONENT_BUTTON_HXX
22 
23 #include "clickableimage.hxx"
24 #include <togglestate.hxx>
25 #include <formnavigation.hxx>
26 #include <resettable.hxx>
27 
28 #include <com/sun/star/awt/MouseEvent.hpp>
29 #include <com/sun/star/lang/EventObject.hpp>
30 #include <com/sun/star/awt/ActionEvent.hpp>
31 #include <com/sun/star/awt/XActionListener.hpp>
32 #include <com/sun/star/awt/XButton.hpp>
33 #include <com/sun/star/form/XReset.hpp>
34 #include <com/sun/star/beans/PropertyChangeEvent.hpp>
35 
36 #include <cppuhelper/implbase1.hxx>
37 
38 struct ImplSVEvent;
39 
40 namespace frm
41 {
42 
43 typedef ::cppu::ImplHelper1 <   css::form::XReset
44                             >   OButtonModel_Base;
45 class OButtonModel  :public OClickableImageBaseModel
46                     ,public OButtonModel_Base
47 {
48 public:
49     DECLARE_DEFAULT_LEAF_XTOR( OButtonModel );
50 
51     // UNO
52     DECLARE_UNO3_AGG_DEFAULTS( OButtonModel, OClickableImageBaseModel )
53     virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& _rType ) override;
54 
55     css::uno::Sequence< css::uno::Type> _getTypes() override;
56 
57 // css::lang::XServiceInfo
getImplementationName()58     OUString SAL_CALL getImplementationName() override
59     { return "com.sun.star.form.OButtonModel"; }
60 
61     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
62 
63 // css::io::XPersistObject
64     virtual OUString SAL_CALL getServiceName() override;
65     virtual void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream>& _rxOutStream) override;
66     virtual void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream>& _rxInStream) override;
67 
68     // XReset
69     virtual void SAL_CALL reset(  ) override;
70     virtual void SAL_CALL addResetListener( const css::uno::Reference< css::form::XResetListener >& aListener ) override;
71     virtual void SAL_CALL removeResetListener( const css::uno::Reference< css::form::XResetListener >& aListener ) override;
72 
73     // OControlModel's property handling
74     virtual void describeFixedProperties(
75         css::uno::Sequence< css::beans::Property >& /* [out] */ _rProps
76     ) const override;
77 
78     // XPropertySet and friends
79     virtual void SAL_CALL getFastPropertyValue(css::uno::Any& rValue, sal_Int32 nHandle) const override;
80     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override;
81     virtual sal_Bool SAL_CALL convertFastPropertyValue(
82                 css::uno::Any& _rConvertedValue, css::uno::Any& _rOldValue, sal_Int32 _nHandle, const css::uno::Any& _rValue ) override;
83     virtual css::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const override;
84 
85     // OComponentHelper
86     virtual void SAL_CALL disposing() override;
87 
88 protected:
89     virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone(  ) override;
90 
91 private:
92     void    impl_resetNoBroadcast_nothrow();
93 
94     using ::cppu::OPropertySetHelper::getFastPropertyValue;
95 
96 private:
97     ResetHelper m_aResetHelper;
98 
99     // <properties>
100     ToggleState m_eDefaultState; // the default check state
101     // </properties>
102 protected:
103     using OClickableImageBaseModel::disposing;
104 };
105 
106 
107 // OButtonControl
108 
109 typedef ::cppu::ImplHelper3 <   css::awt::XButton
110                             ,   css::awt::XActionListener
111                             ,   css::beans::XPropertyChangeListener
112                             >   OButtonControl_BASE;
113 
114 class OButtonControl    :public OButtonControl_BASE
115                         ,public OClickableImageBaseControl
116                         ,public OFormNavigationHelper
117 {
118 private:
119     ImplSVEvent * m_nClickEvent;
120     sal_Int16   m_nTargetUrlFeatureId;
121     /// caches the value of the "Enabled" property of our model
122     bool    m_bEnabledByPropertyValue;
123 
124 protected:
125 
126     // UNO binding
127     virtual css::uno::Sequence< css::uno::Type> _getTypes() override;
128 
129 public:
130     explicit OButtonControl(const css::uno::Reference< css::uno::XComponentContext>& _rxFactory);
131     virtual ~OButtonControl() override;
132 
133     // XServiceInfo
getImplementationName()134     OUString SAL_CALL getImplementationName() override
135     { return "com.sun.star.form.OButtonControl"; }
136 
137     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
138 
139     // UNO binding
140     DECLARE_UNO3_AGG_DEFAULTS(OButtonControl, OClickableImageBaseControl)
141     virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type& _rType) override;
142 
143     // XActionListener
144     virtual void SAL_CALL actionPerformed(const css::awt::ActionEvent& rEvent) override;
145 
146     // XButton
147     virtual void SAL_CALL addActionListener(const css::uno::Reference< css::awt::XActionListener>& _rxListener) override;
148     virtual void SAL_CALL removeActionListener(const css::uno::Reference< css::awt::XActionListener>& _rxListener) override;
149     virtual void SAL_CALL setLabel(const OUString& Label) override;
150     virtual void SAL_CALL setActionCommand(const OUString& _rCommand) override;
151 
152     // OComponentHelper
153     virtual void SAL_CALL disposing() override;
154 
155     // XPropertyChangeListener
156     virtual void SAL_CALL propertyChange( const css::beans::PropertyChangeEvent& evt ) override;
157 
158     // XEventListener
159     virtual void SAL_CALL disposing(const css::lang::EventObject& _rSource) override;
160 
161     // XControl
162     virtual sal_Bool SAL_CALL setModel( const css::uno::Reference< css::awt::XControlModel >& _rxModel ) override;
163     void SAL_CALL setDesignMode(sal_Bool bOn) override;
164 
165 protected:
166     // OFormNavigationHelper overriables
167     virtual void    getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds ) override;
168     virtual void    featureStateChanged( sal_Int16 _nFeatureId, bool _bEnabled ) override;
169     virtual void    allFeatureStatesChanged( ) override;
170     virtual bool    isEnabled( sal_Int16 _nFeatureId ) const override;
171 
172     // XDispatchProviderInterception disambiguation
173     virtual void SAL_CALL registerDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& Interceptor ) override;
174     virtual void SAL_CALL releaseDispatchProviderInterceptor( const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& Interceptor ) override;
175 
176     // OImageControl overridables
177     virtual void    actionPerformed_Impl( bool bNotifyListener, const css::awt::MouseEvent& _rEvt ) override;
178 
179 private:
180     DECL_LINK( OnClick, void*, void );
181 
182     /// to be called whenever the feature URL represented by our model has potentially changed
183     void        modelFeatureUrlPotentiallyChanged( );
184 
185     /// retrieves the feature id (see OFormNavigationHelper) of the TargetURL of the model.
186     sal_Int16   getModelUrlFeatureId( ) const;
187 
188     /// starts or stops listening for changes in model properties we're interested in
189     void        startOrStopModelPropertyListening( bool _bStart );
190 };
191 
192 
193 }   // namespace frm
194 
195 
196 #endif // INCLUDED_FORMS_SOURCE_COMPONENT_BUTTON_HXX
197 
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
199