bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / ImageButton.cxx
blob7a677d5b2f1fa54310143dbf984e23574b8261f2
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/urlobj.hxx>
22 #include <vcl/svapp.hxx>
23 #include <osl/mutex.hxx>
24 #include <comphelper/basicio.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <com/sun/star/awt/MouseButton.hpp>
28 namespace frm
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::sdb;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::form;
39 using namespace ::com::sun::star::io;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::util;
43 // OImageButtonModel
44 OImageButtonModel::OImageButtonModel(const Reference<XComponentContext>& _rxFactory)
45 :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON )
46 // use the old control name for compytibility reasons
48 m_nClassId = FormComponentType::IMAGEBUTTON;
51 OImageButtonModel::OImageButtonModel( const OImageButtonModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
52 :OClickableImageBaseModel( _pOriginal, _rxFactory )
54 implInitializeImageURL();
57 IMPLEMENT_DEFAULT_CLONING( OImageButtonModel )
59 OImageButtonModel::~OImageButtonModel()
63 // XServiceInfo
64 StringSequence OImageButtonModel::getSupportedServiceNames() throw(std::exception)
66 StringSequence aSupported = OClickableImageBaseModel::getSupportedServiceNames();
67 aSupported.realloc(aSupported.getLength() + 2);
69 OUString*pArray = aSupported.getArray();
70 pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_IMAGEBUTTON;
71 pArray[aSupported.getLength()-1] = FRM_COMPONENT_IMAGEBUTTON;
72 return aSupported;
75 void OImageButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
77 BEGIN_DESCRIBE_PROPERTIES( 5, OClickableImageBaseModel )
78 DECL_PROP1(BUTTONTYPE, FormButtonType, BOUND);
79 DECL_PROP1(DISPATCHURLINTERNAL, sal_Bool, BOUND);
80 DECL_PROP1(TARGET_URL, OUString, BOUND);
81 DECL_PROP1(TARGET_FRAME, OUString, BOUND);
82 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
83 END_DESCRIBE_PROPERTIES();
86 OUString OImageButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
88 return OUString(FRM_COMPONENT_IMAGEBUTTON); // old (non-sun) name for compatibility !
91 void OImageButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
93 OControlModel::write(_rxOutStream);
95 // Version
96 _rxOutStream->writeShort(0x0003);
97 _rxOutStream->writeShort((sal_uInt16)m_eButtonType);
99 OUString sTmp(INetURLObject::decode( m_sTargetURL, INetURLObject::DECODE_UNAMBIGUOUS));
100 _rxOutStream << sTmp;
101 _rxOutStream << m_sTargetFrame;
102 writeHelpTextCompatibly(_rxOutStream);
105 void OImageButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
107 OControlModel::read(_rxInStream);
109 // Version
110 sal_uInt16 nVersion = _rxInStream->readShort();
112 switch (nVersion)
114 case 0x0001:
116 m_eButtonType = (FormButtonType)_rxInStream->readShort();
118 break;
119 case 0x0002:
121 m_eButtonType = (FormButtonType)_rxInStream->readShort();
122 _rxInStream >> m_sTargetURL;
123 _rxInStream >> m_sTargetFrame;
125 break;
126 case 0x0003:
128 m_eButtonType = (FormButtonType)_rxInStream->readShort();
129 _rxInStream >> m_sTargetURL;
130 _rxInStream >> m_sTargetFrame;
131 readHelpTextCompatibly(_rxInStream);
133 break;
135 default :
136 OSL_FAIL("OImageButtonModel::read : unknown version !");
137 m_eButtonType = FormButtonType_PUSH;
138 m_sTargetURL.clear();
139 m_sTargetFrame.clear();
140 break;
144 // OImageButtonControl
145 Sequence<Type> OImageButtonControl::_getTypes()
147 static Sequence<Type> aTypes;
148 if (!aTypes.getLength())
149 aTypes = concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
150 return aTypes;
153 StringSequence OImageButtonControl::getSupportedServiceNames() throw(std::exception)
155 StringSequence aSupported = OClickableImageBaseControl::getSupportedServiceNames();
156 aSupported.realloc(aSupported.getLength() + 2);
158 OUString*pArray = aSupported.getArray();
159 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_IMAGEBUTTON;
160 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON;
161 return aSupported;
164 OImageButtonControl::OImageButtonControl(const Reference<XComponentContext>& _rxFactory)
165 :OClickableImageBaseControl(_rxFactory, VCL_CONTROL_IMAGEBUTTON)
167 osl_atomic_increment(&m_refCount);
169 // Register as MouseListener
170 Reference< awt::XWindow > xComp;
171 query_aggregation( m_xAggregate, xComp);
172 if (xComp.is())
173 xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) );
175 osl_atomic_decrement(&m_refCount);
178 // UNO Binding
179 Any SAL_CALL OImageButtonControl::queryAggregation(const Type& _rType) throw (RuntimeException, std::exception)
181 Any aReturn = OClickableImageBaseControl::queryAggregation(_rType);
182 if (!aReturn.hasValue())
183 aReturn = OImageButtonControl_BASE::queryInterface(_rType);
185 return aReturn;
188 void OImageButtonControl::mousePressed(const awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
190 SolarMutexGuard aSolarGuard;
192 if (e.Buttons != awt::MouseButton::LEFT)
193 return;
195 ::osl::ClearableMutexGuard aGuard( m_aMutex );
196 if( m_aApproveActionListeners.getLength() )
198 // if there are listeners, start the action in an own thread, to not allow
199 // them to block us here (we're in the application's main thread)
200 getImageProducerThread()->OComponentEventThread::addEvent( &e );
202 else
204 // Or else don't; we must not notify the listeners in that case.
205 // Even not if its added later on.
206 aGuard.clear();
207 actionPerformed_Impl( false, e );
211 void SAL_CALL OImageButtonControl::mouseReleased(const awt::MouseEvent& /*e*/) throw ( RuntimeException, std::exception)
215 void SAL_CALL OImageButtonControl::mouseEntered(const awt::MouseEvent& /*e*/) throw ( RuntimeException, std::exception)
219 void SAL_CALL OImageButtonControl::mouseExited(const awt::MouseEvent& /*e*/) throw ( RuntimeException, std::exception)
223 } // namespace frm
225 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
226 com_sun_star_form_OImageButtonModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
227 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
229 return cppu::acquire(new frm::OImageButtonModel(component));
232 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
233 com_sun_star_form_OImageButtonControl_get_implementation(::com::sun::star::uno::XComponentContext* component,
234 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
236 return cppu::acquire(new frm::OImageButtonControl(component));
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */