LibreOffice Module forms (master) 1
ImageButton.cxx
Go to the documentation of this file.
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#include "ImageButton.hxx"
21#include <tools/debug.hxx>
22#include <tools/urlobj.hxx>
23#include <vcl/svapp.hxx>
24#include <osl/mutex.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>
31
32namespace frm
33{
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::uno;
37using namespace ::com::sun::star::sdb;
38using namespace ::com::sun::star::sdbc;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::container;
41using namespace ::com::sun::star::form;
42using namespace ::com::sun::star::io;
43using namespace ::com::sun::star::lang;
44using namespace ::com::sun::star::util;
45
46// OImageButtonModel
47OImageButtonModel::OImageButtonModel(const Reference<XComponentContext>& _rxFactory)
48 :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON )
49 // use the old control name for compytibility reasons
50{
51 m_nClassId = FormComponentType::IMAGEBUTTON;
52}
53
54OImageButtonModel::OImageButtonModel( const OImageButtonModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
55 :OClickableImageBaseModel( _pOriginal, _rxFactory )
56{
57 implInitializeImageURL();
58}
59
60css::uno::Reference< css::util::XCloneable > SAL_CALL OImageButtonModel::createClone()
61{
62 rtl::Reference<OImageButtonModel> pClone = new OImageButtonModel(this, getContext());
63 pClone->clonedFrom(this);
64 return pClone;
65}
66
67OImageButtonModel::~OImageButtonModel()
68{
69}
70
71// XServiceInfo
72css::uno::Sequence<OUString> OImageButtonModel::getSupportedServiceNames()
73{
74 css::uno::Sequence<OUString> aSupported = OClickableImageBaseModel::getSupportedServiceNames();
75 aSupported.realloc(aSupported.getLength() + 2);
76
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;
81}
82
83void OImageButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
84{
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 ?");
95}
96
97OUString OImageButtonModel::getServiceName()
98{
99 return FRM_COMPONENT_IMAGEBUTTON; // old (non-sun) name for compatibility !
100}
101
102void OImageButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream)
103{
104 OControlModel::write(_rxOutStream);
105
106 // Version
107 _rxOutStream->writeShort(0x0003);
108 _rxOutStream->writeShort(static_cast<sal_uInt16>(m_eButtonType));
109
111 _rxOutStream << sTmp;
112 _rxOutStream << m_sTargetFrame;
113 writeHelpTextCompatibly(_rxOutStream);
114}
115
116void OImageButtonModel::read(const Reference<XObjectInputStream>& _rxInStream)
117{
118 OControlModel::read(_rxInStream);
119
120 // Version
121 sal_uInt16 nVersion = _rxInStream->readShort();
122
123 switch (nVersion)
124 {
125 case 0x0001:
126 {
127 m_eButtonType = static_cast<FormButtonType>(_rxInStream->readShort());
128 }
129 break;
130 case 0x0002:
131 {
132 m_eButtonType = static_cast<FormButtonType>(_rxInStream->readShort());
133 _rxInStream >> m_sTargetURL;
134 _rxInStream >> m_sTargetFrame;
135 }
136 break;
137 case 0x0003:
138 {
139 m_eButtonType = static_cast<FormButtonType>(_rxInStream->readShort());
140 _rxInStream >> m_sTargetURL;
141 _rxInStream >> m_sTargetFrame;
142 readHelpTextCompatibly(_rxInStream);
143 }
144 break;
145
146 default :
147 OSL_FAIL("OImageButtonModel::read : unknown version !");
148 m_eButtonType = FormButtonType_PUSH;
149 m_sTargetURL.clear();
150 m_sTargetFrame.clear();
151 break;
152 }
153}
154
155// OImageButtonControl
156Sequence<Type> OImageButtonControl::_getTypes()
157{
158 static Sequence<Type> const aTypes =
159 concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
160 return aTypes;
161}
162
163css::uno::Sequence<OUString> OImageButtonControl::getSupportedServiceNames()
164{
165 css::uno::Sequence<OUString> aSupported = OClickableImageBaseControl::getSupportedServiceNames();
166 aSupported.realloc(aSupported.getLength() + 2);
167
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;
172}
173
174OImageButtonControl::OImageButtonControl(const Reference<XComponentContext>& _rxFactory)
176{
177 osl_atomic_increment(&m_refCount);
178 {
179 // Register as MouseListener
180 Reference< awt::XWindow > xComp;
182 if (xComp.is())
183 xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) );
184 }
185 osl_atomic_decrement(&m_refCount);
186}
187
188// UNO Binding
190{
192 if (!aReturn.hasValue())
194
195 return aReturn;
196}
197
198void OImageButtonControl::mousePressed(const awt::MouseEvent& e)
199{
200 SolarMutexGuard aSolarGuard;
201
202 if (e.Buttons != awt::MouseButton::LEFT)
203 return;
204
205 ::osl::ClearableMutexGuard aGuard( m_aMutex );
207 {
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) );
211 }
212 else
213 {
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 );
218 }
219}
220
221void SAL_CALL OImageButtonControl::mouseReleased(const awt::MouseEvent& /*e*/)
222{
223}
224
225void SAL_CALL OImageButtonControl::mouseEntered(const awt::MouseEvent& /*e*/)
226{
227}
228
229void SAL_CALL OImageButtonControl::mouseExited(const awt::MouseEvent& /*e*/)
230{
231}
232
233} // namespace frm
234
235extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
236com_sun_star_form_OImageButtonModel_get_implementation(css::uno::XComponentContext* component,
237 css::uno::Sequence<css::uno::Any> const &)
238{
239 return cppu::acquire(new frm::OImageButtonModel(component));
240}
241
242extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
243com_sun_star_form_OImageButtonControl_get_implementation(css::uno::XComponentContext* component,
244 css::uno::Sequence<css::uno::Any> const &)
245{
246 return cppu::acquire(new frm::OImageButtonControl(component));
247}
248
249/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OImageButtonControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OImageButtonModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
oslInterlockedCount m_refCount
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
OImageProducerThread_Impl * getImageProducerThread()
retrieves (and if necessary creates) the image producer thread.
virtual void actionPerformed_Impl(bool bNotifyListener, const css::awt::MouseEvent &rEvt)
::comphelper::OInterfaceContainerHelper3< css::form::XApproveActionListener > m_aApproveActionListeners
css::uno::Reference< css::uno::XAggregation > m_xAggregate
::osl::Mutex m_aMutex
virtual void SAL_CALL mousePressed(const css::awt::MouseEvent &e) override
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &_rType) override
virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent &e) override
virtual void SAL_CALL mouseExited(const css::awt::MouseEvent &e) override
virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent &e) override
OImageButtonModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
#define DBG_ASSERT(sCon, aError)
sal_Int16 nVersion
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_TARGET_URL
Definition: frm_strings.hxx:49
constexpr OUStringLiteral PROPERTY_DISPATCHURLINTERNAL
constexpr OUStringLiteral PROPERTY_TARGET_FRAME
Definition: frm_strings.hxx:50
constexpr OUStringLiteral PROPERTY_BUTTONTYPE
Definition: frm_strings.hxx:61
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool query_aggregation(const css::uno::Reference< css::uno::XAggregation > &_rxAggregate, css::uno::Reference< iface > &_rxOut)
Type
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
#define PROPERTY_ID_DISPATCHURLINTERNAL
Definition: property.hxx:248
#define PROPERTY_ID_TARGET_FRAME
Definition: property.hxx:154
#define PROPERTY_ID_TARGET_URL
Definition: property.hxx:153
#define PROPERTY_ID_BUTTONTYPE
Definition: property.hxx:105
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
constexpr OUStringLiteral VCL_CONTROLMODEL_IMAGEBUTTON
Definition: services.hxx:47
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_IMAGEBUTTON
Definition: services.hxx:98
constexpr OUStringLiteral FRM_COMPONENT_IMAGEBUTTON
Definition: services.hxx:76
constexpr OUStringLiteral FRM_SUN_CONTROL_IMAGEBUTTON
Definition: services.hxx:158
constexpr OUStringLiteral VCL_CONTROL_IMAGEBUTTON
Definition: services.hxx:30
constexpr OUStringLiteral FRM_SUN_COMPONENT_IMAGEBUTTON
Definition: services.hxx:122
const SvXMLTokenMapEntry aTypes[]