1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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::form
;
41 using namespace ::com::sun::star::io
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::util
;
46 OImageButtonModel::OImageButtonModel(const Reference
<XComponentContext
>& _rxFactory
)
47 :OClickableImageBaseModel( _rxFactory
, VCL_CONTROLMODEL_IMAGEBUTTON
, FRM_SUN_CONTROL_IMAGEBUTTON
)
48 // use the old control name for compatibility reasons
50 m_nClassId
= FormComponentType::IMAGEBUTTON
;
53 OImageButtonModel::OImageButtonModel( const OImageButtonModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
54 :OClickableImageBaseModel( _pOriginal
, _rxFactory
)
56 implInitializeImageURL();
59 css::uno::Reference
< css::util::XCloneable
> SAL_CALL
OImageButtonModel::createClone()
61 rtl::Reference
<OImageButtonModel
> pClone
= new OImageButtonModel(this, getContext());
62 pClone
->clonedFrom(this);
66 OImageButtonModel::~OImageButtonModel()
71 css::uno::Sequence
<OUString
> OImageButtonModel::getSupportedServiceNames()
73 css::uno::Sequence
<OUString
> aSupported
= OClickableImageBaseModel::getSupportedServiceNames();
74 aSupported
.realloc(aSupported
.getLength() + 2);
76 OUString
*pArray
= aSupported
.getArray();
77 pArray
[aSupported
.getLength()-2] = FRM_SUN_COMPONENT_IMAGEBUTTON
;
78 pArray
[aSupported
.getLength()-1] = FRM_COMPONENT_IMAGEBUTTON
;
82 void OImageButtonModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
84 OClickableImageBaseModel::describeFixedProperties( _rProps
);
85 sal_Int32 nOldCount
= _rProps
.getLength();
86 _rProps
.realloc( nOldCount
+ 5);
87 css::beans::Property
* pProperties
= _rProps
.getArray() + nOldCount
;
88 *pProperties
++ = css::beans::Property(PROPERTY_BUTTONTYPE
, PROPERTY_ID_BUTTONTYPE
, cppu::UnoType
<FormButtonType
>::get(), css::beans::PropertyAttribute::BOUND
);
89 *pProperties
++ = css::beans::Property(PROPERTY_DISPATCHURLINTERNAL
, PROPERTY_ID_DISPATCHURLINTERNAL
, cppu::UnoType
<sal_Bool
>::get(), css::beans::PropertyAttribute::BOUND
);
90 *pProperties
++ = css::beans::Property(PROPERTY_TARGET_URL
, PROPERTY_ID_TARGET_URL
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::BOUND
);
91 *pProperties
++ = css::beans::Property(PROPERTY_TARGET_FRAME
, PROPERTY_ID_TARGET_FRAME
, cppu::UnoType
<OUString
>::get(), css::beans::PropertyAttribute::BOUND
);
92 *pProperties
++ = css::beans::Property(PROPERTY_TABINDEX
, PROPERTY_ID_TABINDEX
, cppu::UnoType
<sal_Int16
>::get(), css::beans::PropertyAttribute::BOUND
);
93 DBG_ASSERT( pProperties
== _rProps
.getArray() + _rProps
.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
96 OUString
OImageButtonModel::getServiceName()
98 return FRM_COMPONENT_IMAGEBUTTON
; // old (non-sun) name for compatibility !
101 void OImageButtonModel::write(const Reference
<XObjectOutputStream
>& _rxOutStream
)
103 OControlModel::write(_rxOutStream
);
106 _rxOutStream
->writeShort(0x0003);
107 _rxOutStream
->writeShort(static_cast<sal_uInt16
>(m_eButtonType
));
109 OUString
sTmp(INetURLObject::decode( m_sTargetURL
, INetURLObject::DecodeMechanism::Unambiguous
));
110 _rxOutStream
<< sTmp
;
111 _rxOutStream
<< m_sTargetFrame
;
112 writeHelpTextCompatibly(_rxOutStream
);
115 void OImageButtonModel::read(const Reference
<XObjectInputStream
>& _rxInStream
)
117 OControlModel::read(_rxInStream
);
120 sal_uInt16 nVersion
= _rxInStream
->readShort();
126 m_eButtonType
= static_cast<FormButtonType
>(_rxInStream
->readShort());
131 m_eButtonType
= static_cast<FormButtonType
>(_rxInStream
->readShort());
132 _rxInStream
>> m_sTargetURL
;
133 _rxInStream
>> m_sTargetFrame
;
138 m_eButtonType
= static_cast<FormButtonType
>(_rxInStream
->readShort());
139 _rxInStream
>> m_sTargetURL
;
140 _rxInStream
>> m_sTargetFrame
;
141 readHelpTextCompatibly(_rxInStream
);
146 OSL_FAIL("OImageButtonModel::read : unknown version !");
147 m_eButtonType
= FormButtonType_PUSH
;
148 m_sTargetURL
.clear();
149 m_sTargetFrame
.clear();
154 // OImageButtonControl
155 Sequence
<Type
> OImageButtonControl::_getTypes()
157 static Sequence
<Type
> const aTypes
=
158 concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
162 css::uno::Sequence
<OUString
> OImageButtonControl::getSupportedServiceNames()
164 css::uno::Sequence
<OUString
> aSupported
= OClickableImageBaseControl::getSupportedServiceNames();
165 aSupported
.realloc(aSupported
.getLength() + 2);
167 OUString
*pArray
= aSupported
.getArray();
168 pArray
[aSupported
.getLength()-2] = FRM_SUN_CONTROL_IMAGEBUTTON
;
169 pArray
[aSupported
.getLength()-1] = STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON
;
173 OImageButtonControl::OImageButtonControl(const Reference
<XComponentContext
>& _rxFactory
)
174 :OClickableImageBaseControl(_rxFactory
, VCL_CONTROL_IMAGEBUTTON
)
176 osl_atomic_increment(&m_refCount
);
178 // Register as MouseListener
179 if (auto xComp
= query_aggregation
<awt::XWindow
>(m_xAggregate
))
180 xComp
->addMouseListener( static_cast< awt::XMouseListener
* >( this ) );
182 osl_atomic_decrement(&m_refCount
);
186 Any SAL_CALL
OImageButtonControl::queryAggregation(const Type
& _rType
)
188 Any aReturn
= OClickableImageBaseControl::queryAggregation(_rType
);
189 if (!aReturn
.hasValue())
190 aReturn
= OImageButtonControl_BASE::queryInterface(_rType
);
195 void OImageButtonControl::mousePressed(const awt::MouseEvent
& e
)
197 SolarMutexGuard aSolarGuard
;
199 if (e
.Buttons
!= awt::MouseButton::LEFT
)
202 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
203 if( m_aApproveActionListeners
.getLength() )
205 // if there are listeners, start the action in an own thread, to not allow
206 // them to block us here (we're in the application's main thread)
207 getImageProducerThread()->OComponentEventThread::addEvent( std::make_unique
<awt::MouseEvent
>(e
) );
211 // Or else don't; we must not notify the listeners in that case.
212 // Even not if it's added later on.
214 actionPerformed_Impl( false, e
);
218 void SAL_CALL
OImageButtonControl::mouseReleased(const awt::MouseEvent
& /*e*/)
222 void SAL_CALL
OImageButtonControl::mouseEntered(const awt::MouseEvent
& /*e*/)
226 void SAL_CALL
OImageButtonControl::mouseExited(const awt::MouseEvent
& /*e*/)
232 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
233 com_sun_star_form_OImageButtonModel_get_implementation(css::uno::XComponentContext
* component
,
234 css::uno::Sequence
<css::uno::Any
> const &)
236 return cppu::acquire(new frm::OImageButtonModel(component
));
239 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
240 com_sun_star_form_OImageButtonControl_get_implementation(css::uno::XComponentContext
* component
,
241 css::uno::Sequence
<css::uno::Any
> const &)
243 return cppu::acquire(new frm::OImageButtonControl(component
));
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */