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>
28 //.........................................................................
31 //.........................................................................
32 using namespace ::com::sun::star
;
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::sdb
;
35 using namespace ::com::sun::star::sdbc
;
36 using namespace ::com::sun::star::sdbcx
;
37 using namespace ::com::sun::star::beans
;
38 using namespace ::com::sun::star::container
;
39 using namespace ::com::sun::star::form
;
40 using namespace ::com::sun::star::io
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::util
;
44 //==================================================================
46 //==================================================================
47 DBG_NAME(OImageButtonModel
)
48 //------------------------------------------------------------------
49 InterfaceRef SAL_CALL
OImageButtonModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
51 return *(new OImageButtonModel(_rxFactory
));
54 //------------------------------------------------------------------
55 OImageButtonModel::OImageButtonModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
56 :OClickableImageBaseModel( _rxFactory
, VCL_CONTROLMODEL_IMAGEBUTTON
, FRM_SUN_CONTROL_IMAGEBUTTON
)
57 // use the old control name for compytibility reasons
59 DBG_CTOR(OImageButtonModel
, NULL
);
60 m_nClassId
= FormComponentType::IMAGEBUTTON
;
63 //------------------------------------------------------------------
64 OImageButtonModel::OImageButtonModel( const OImageButtonModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
65 :OClickableImageBaseModel( _pOriginal
, _rxFactory
)
67 DBG_CTOR(OImageButtonModel
, NULL
);
68 implInitializeImageURL();
71 //------------------------------------------------------------------------------
72 IMPLEMENT_DEFAULT_CLONING( OImageButtonModel
)
74 //------------------------------------------------------------------------------
75 OImageButtonModel::~OImageButtonModel()
77 DBG_DTOR(OImageButtonModel
, NULL
);
81 //------------------------------------------------------------------------------
82 StringSequence
OImageButtonModel::getSupportedServiceNames() throw()
84 StringSequence aSupported
= OClickableImageBaseModel::getSupportedServiceNames();
85 aSupported
.realloc(aSupported
.getLength() + 1);
87 OUString
*pArray
= aSupported
.getArray();
88 pArray
[aSupported
.getLength()-1] = FRM_SUN_COMPONENT_IMAGEBUTTON
;
92 //------------------------------------------------------------------------------
93 void OImageButtonModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
95 BEGIN_DESCRIBE_PROPERTIES( 5, OClickableImageBaseModel
)
96 DECL_PROP1(BUTTONTYPE
, FormButtonType
, BOUND
);
97 DECL_PROP1(DISPATCHURLINTERNAL
, sal_Bool
, BOUND
);
98 DECL_PROP1(TARGET_URL
, OUString
, BOUND
);
99 DECL_PROP1(TARGET_FRAME
, OUString
, BOUND
);
100 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
101 END_DESCRIBE_PROPERTIES();
104 //------------------------------------------------------------------------------
105 OUString
OImageButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
107 return OUString(FRM_COMPONENT_IMAGEBUTTON
); // old (non-sun) name for compatibility !
110 //------------------------------------------------------------------------------
111 void OImageButtonModel::write(const Reference
<XObjectOutputStream
>& _rxOutStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
113 OControlModel::write(_rxOutStream
);
116 _rxOutStream
->writeShort(0x0003);
117 _rxOutStream
->writeShort((sal_uInt16
)m_eButtonType
);
119 OUString
sTmp(INetURLObject::decode( m_sTargetURL
, '%', INetURLObject::DECODE_UNAMBIGUOUS
));
120 _rxOutStream
<< sTmp
;
121 _rxOutStream
<< m_sTargetFrame
;
122 writeHelpTextCompatibly(_rxOutStream
);
125 //------------------------------------------------------------------------------
126 void OImageButtonModel::read(const Reference
<XObjectInputStream
>& _rxInStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
128 OControlModel::read(_rxInStream
);
131 sal_uInt16 nVersion
= _rxInStream
->readShort();
137 m_eButtonType
= (FormButtonType
)_rxInStream
->readShort();
142 m_eButtonType
= (FormButtonType
)_rxInStream
->readShort();
143 _rxInStream
>> m_sTargetURL
;
144 _rxInStream
>> m_sTargetFrame
;
149 m_eButtonType
= (FormButtonType
)_rxInStream
->readShort();
150 _rxInStream
>> m_sTargetURL
;
151 _rxInStream
>> m_sTargetFrame
;
152 readHelpTextCompatibly(_rxInStream
);
157 OSL_FAIL("OImageButtonModel::read : unknown version !");
158 m_eButtonType
= FormButtonType_PUSH
;
159 m_sTargetURL
= OUString();
160 m_sTargetFrame
= OUString();
165 //==================================================================
166 // OImageButtonControl
167 //==================================================================
168 //------------------------------------------------------------------
169 InterfaceRef SAL_CALL
OImageButtonControl_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
171 return *(new OImageButtonControl(_rxFactory
));
174 //------------------------------------------------------------------------------
175 Sequence
<Type
> OImageButtonControl::_getTypes()
177 static Sequence
<Type
> aTypes
;
178 if (!aTypes
.getLength())
179 aTypes
= concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
183 //------------------------------------------------------------------------------
184 StringSequence
OImageButtonControl::getSupportedServiceNames() throw()
186 StringSequence aSupported
= OClickableImageBaseControl::getSupportedServiceNames();
187 aSupported
.realloc(aSupported
.getLength() + 1);
189 OUString
*pArray
= aSupported
.getArray();
190 pArray
[aSupported
.getLength()-1] = FRM_SUN_CONTROL_IMAGEBUTTON
;
194 //------------------------------------------------------------------------------
195 OImageButtonControl::OImageButtonControl(const Reference
<XMultiServiceFactory
>& _rxFactory
)
196 :OClickableImageBaseControl(_rxFactory
, VCL_CONTROL_IMAGEBUTTON
)
198 increment(m_refCount
);
200 // als MouseListener anmelden
201 Reference
< awt::XWindow
> xComp
;
202 query_aggregation( m_xAggregate
, xComp
);
204 xComp
->addMouseListener( static_cast< awt::XMouseListener
* >( this ) );
206 decrement(m_refCount
);
210 //------------------------------------------------------------------------------
211 Any SAL_CALL
OImageButtonControl::queryAggregation(const Type
& _rType
) throw (RuntimeException
)
213 Any aReturn
= OClickableImageBaseControl::queryAggregation(_rType
);
214 if (!aReturn
.hasValue())
215 aReturn
= OImageButtonControl_BASE::queryInterface(_rType
);
220 //------------------------------------------------------------------------------
221 void OImageButtonControl::mousePressed(const awt::MouseEvent
& e
) throw ( ::com::sun::star::uno::RuntimeException
)
223 SolarMutexGuard aSolarGuard
;
225 if (e
.Buttons
!= awt::MouseButton::LEFT
)
228 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
229 if( m_aApproveActionListeners
.getLength() )
231 // if there are listeners, start the action in an own thread, to not allow
232 // them to block us here (we're in the application's main thread)
233 getImageProducerThread()->OComponentEventThread::addEvent( &e
);
237 // Sonst nicht. Dann darf man aber auf keinen Fal die Listener
238 // benachrichtigen, auch dann nicht, wenn er spaeter hinzukommt.
240 actionPerformed_Impl( sal_False
, e
);
244 //------------------------------------------------------------------------------
245 void SAL_CALL
OImageButtonControl::mouseReleased(const awt::MouseEvent
& /*e*/) throw ( RuntimeException
)
249 //------------------------------------------------------------------------------
250 void SAL_CALL
OImageButtonControl::mouseEntered(const awt::MouseEvent
& /*e*/) throw ( RuntimeException
)
254 //------------------------------------------------------------------------------
255 void SAL_CALL
OImageButtonControl::mouseExited(const awt::MouseEvent
& /*e*/) throw ( RuntimeException
)
260 //.........................................................................
262 //.........................................................................
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */