android: Update app-specific/MIME type icons
[LibreOffice.git] / forms / source / component / ImageButton.cxx
blob57bbe396965d95c6a2b11cf58874b83695f9e2a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ImageButton.hxx"
21 #include <tools/debug.hxx>
22 #include <tools/urlobj.hxx>
23 #include <vcl/svapp.hxx>
24 #include <osl/mutex.hxx>
25 #include <comphelper/basicio.hxx>
26 #include <com/sun/star/awt/MouseButton.hpp>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/form/FormComponentType.hpp>
29 #include <property.hxx>
30 #include <services.hxx>
32 namespace frm
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::form;
42 using namespace ::com::sun::star::io;
43 using namespace ::com::sun::star::lang;
44 using namespace ::com::sun::star::util;
46 // OImageButtonModel
47 OImageButtonModel::OImageButtonModel(const Reference<XComponentContext>& _rxFactory)
48 :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON )
49 // use the old control name for compytibility reasons
51 m_nClassId = FormComponentType::IMAGEBUTTON;
54 OImageButtonModel::OImageButtonModel( const OImageButtonModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
55 :OClickableImageBaseModel( _pOriginal, _rxFactory )
57 implInitializeImageURL();
60 css::uno::Reference< css::util::XCloneable > SAL_CALL OImageButtonModel::createClone()
62 rtl::Reference<OImageButtonModel> pClone = new OImageButtonModel(this, getContext());
63 pClone->clonedFrom(this);
64 return pClone;
67 OImageButtonModel::~OImageButtonModel()
71 // XServiceInfo
72 css::uno::Sequence<OUString> OImageButtonModel::getSupportedServiceNames()
74 css::uno::Sequence<OUString> aSupported = OClickableImageBaseModel::getSupportedServiceNames();
75 aSupported.realloc(aSupported.getLength() + 2);
77 OUString*pArray = aSupported.getArray();
78 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_IMAGEBUTTON;
79 pArray[aSupported.getLength()-1] = FRM_COMPONENT_IMAGEBUTTON;
80 return aSupported;
83 void OImageButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
85 OClickableImageBaseModel::describeFixedProperties( _rProps );
86 sal_Int32 nOldCount = _rProps.getLength();
87 _rProps.realloc( nOldCount + 5);
88 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
89 *pProperties++ = css::beans::Property(PROPERTY_BUTTONTYPE, PROPERTY_ID_BUTTONTYPE, cppu::UnoType<FormButtonType>::get(), css::beans::PropertyAttribute::BOUND);
90 *pProperties++ = css::beans::Property(PROPERTY_DISPATCHURLINTERNAL, PROPERTY_ID_DISPATCHURLINTERNAL, cppu::UnoType<sal_Bool>::get(), css::beans::PropertyAttribute::BOUND);
91 *pProperties++ = css::beans::Property(PROPERTY_TARGET_URL, PROPERTY_ID_TARGET_URL, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND);
92 *pProperties++ = css::beans::Property(PROPERTY_TARGET_FRAME, PROPERTY_ID_TARGET_FRAME, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::BOUND);
93 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
94 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
97 OUString OImageButtonModel::getServiceName()
99 return FRM_COMPONENT_IMAGEBUTTON; // old (non-sun) name for compatibility !
102 void OImageButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream)
104 OControlModel::write(_rxOutStream);
106 // Version
107 _rxOutStream->writeShort(0x0003);
108 _rxOutStream->writeShort(static_cast<sal_uInt16>(m_eButtonType));
110 OUString sTmp(INetURLObject::decode( m_sTargetURL, INetURLObject::DecodeMechanism::Unambiguous));
111 _rxOutStream << sTmp;
112 _rxOutStream << m_sTargetFrame;
113 writeHelpTextCompatibly(_rxOutStream);
116 void OImageButtonModel::read(const Reference<XObjectInputStream>& _rxInStream)
118 OControlModel::read(_rxInStream);
120 // Version
121 sal_uInt16 nVersion = _rxInStream->readShort();
123 switch (nVersion)
125 case 0x0001:
127 m_eButtonType = static_cast<FormButtonType>(_rxInStream->readShort());
129 break;
130 case 0x0002:
132 m_eButtonType = static_cast<FormButtonType>(_rxInStream->readShort());
133 _rxInStream >> m_sTargetURL;
134 _rxInStream >> m_sTargetFrame;
136 break;
137 case 0x0003:
139 m_eButtonType = static_cast<FormButtonType>(_rxInStream->readShort());
140 _rxInStream >> m_sTargetURL;
141 _rxInStream >> m_sTargetFrame;
142 readHelpTextCompatibly(_rxInStream);
144 break;
146 default :
147 OSL_FAIL("OImageButtonModel::read : unknown version !");
148 m_eButtonType = FormButtonType_PUSH;
149 m_sTargetURL.clear();
150 m_sTargetFrame.clear();
151 break;
155 // OImageButtonControl
156 Sequence<Type> OImageButtonControl::_getTypes()
158 static Sequence<Type> const aTypes =
159 concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
160 return aTypes;
163 css::uno::Sequence<OUString> OImageButtonControl::getSupportedServiceNames()
165 css::uno::Sequence<OUString> aSupported = OClickableImageBaseControl::getSupportedServiceNames();
166 aSupported.realloc(aSupported.getLength() + 2);
168 OUString*pArray = aSupported.getArray();
169 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_IMAGEBUTTON;
170 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON;
171 return aSupported;
174 OImageButtonControl::OImageButtonControl(const Reference<XComponentContext>& _rxFactory)
175 :OClickableImageBaseControl(_rxFactory, VCL_CONTROL_IMAGEBUTTON)
177 osl_atomic_increment(&m_refCount);
179 // Register as MouseListener
180 Reference< awt::XWindow > xComp;
181 query_aggregation( m_xAggregate, xComp);
182 if (xComp.is())
183 xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) );
185 osl_atomic_decrement(&m_refCount);
188 // UNO Binding
189 Any SAL_CALL OImageButtonControl::queryAggregation(const Type& _rType)
191 Any aReturn = OClickableImageBaseControl::queryAggregation(_rType);
192 if (!aReturn.hasValue())
193 aReturn = OImageButtonControl_BASE::queryInterface(_rType);
195 return aReturn;
198 void OImageButtonControl::mousePressed(const awt::MouseEvent& e)
200 SolarMutexGuard aSolarGuard;
202 if (e.Buttons != awt::MouseButton::LEFT)
203 return;
205 ::osl::ClearableMutexGuard aGuard( m_aMutex );
206 if( m_aApproveActionListeners.getLength() )
208 // if there are listeners, start the action in an own thread, to not allow
209 // them to block us here (we're in the application's main thread)
210 getImageProducerThread()->OComponentEventThread::addEvent( std::make_unique<awt::MouseEvent>(e) );
212 else
214 // Or else don't; we must not notify the listeners in that case.
215 // Even not if it's added later on.
216 aGuard.clear();
217 actionPerformed_Impl( false, e );
221 void SAL_CALL OImageButtonControl::mouseReleased(const awt::MouseEvent& /*e*/)
225 void SAL_CALL OImageButtonControl::mouseEntered(const awt::MouseEvent& /*e*/)
229 void SAL_CALL OImageButtonControl::mouseExited(const awt::MouseEvent& /*e*/)
233 } // namespace frm
235 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
236 com_sun_star_form_OImageButtonModel_get_implementation(css::uno::XComponentContext* component,
237 css::uno::Sequence<css::uno::Any> const &)
239 return cppu::acquire(new frm::OImageButtonModel(component));
242 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
243 com_sun_star_form_OImageButtonControl_get_implementation(css::uno::XComponentContext* component,
244 css::uno::Sequence<css::uno::Any> const &)
246 return cppu::acquire(new frm::OImageButtonControl(component));
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */