1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_forms.hxx" 30 #include "ImageButton.hxx" 31 #include <tools/debug.hxx> 32 #include <tools/urlobj.hxx> 33 #include <vcl/svapp.hxx> 34 #include <vos/mutex.hxx> 35 #include <comphelper/basicio.hxx> 36 #include <com/sun/star/awt/MouseButton.hpp> 37 38 //......................................................................... 39 namespace frm 40 { 41 //......................................................................... 42 using namespace ::com::sun::star; 43 using namespace ::com::sun::star::uno; 44 using namespace ::com::sun::star::sdb; 45 using namespace ::com::sun::star::sdbc; 46 using namespace ::com::sun::star::sdbcx; 47 using namespace ::com::sun::star::beans; 48 using namespace ::com::sun::star::container; 49 using namespace ::com::sun::star::form; 50 using namespace ::com::sun::star::io; 51 using namespace ::com::sun::star::lang; 52 using namespace ::com::sun::star::util; 53 54 //================================================================== 55 //= OImageButtonModel 56 //================================================================== 57 DBG_NAME(OImageButtonModel) 58 //------------------------------------------------------------------ 59 InterfaceRef SAL_CALL OImageButtonModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 60 { 61 return *(new OImageButtonModel(_rxFactory)); 62 } 63 64 //------------------------------------------------------------------ 65 OImageButtonModel::OImageButtonModel(const Reference<XMultiServiceFactory>& _rxFactory) 66 :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON ) 67 // use the old control name for compytibility reasons 68 { 69 DBG_CTOR(OImageButtonModel, NULL); 70 m_nClassId = FormComponentType::IMAGEBUTTON; 71 } 72 73 //------------------------------------------------------------------ 74 OImageButtonModel::OImageButtonModel( const OImageButtonModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory) 75 :OClickableImageBaseModel( _pOriginal, _rxFactory ) 76 { 77 DBG_CTOR(OImageButtonModel, NULL); 78 implInitializeImageURL(); 79 } 80 81 //------------------------------------------------------------------------------ 82 IMPLEMENT_DEFAULT_CLONING( OImageButtonModel ) 83 84 //------------------------------------------------------------------------------ 85 OImageButtonModel::~OImageButtonModel() 86 { 87 DBG_DTOR(OImageButtonModel, NULL); 88 } 89 90 // XServiceInfo 91 //------------------------------------------------------------------------------ 92 StringSequence OImageButtonModel::getSupportedServiceNames() throw() 93 { 94 StringSequence aSupported = OClickableImageBaseModel::getSupportedServiceNames(); 95 aSupported.realloc(aSupported.getLength() + 1); 96 97 ::rtl::OUString*pArray = aSupported.getArray(); 98 pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_IMAGEBUTTON; 99 return aSupported; 100 } 101 102 //------------------------------------------------------------------------------ 103 void OImageButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const 104 { 105 BEGIN_DESCRIBE_PROPERTIES( 5, OClickableImageBaseModel ) 106 DECL_PROP1(BUTTONTYPE, FormButtonType, BOUND); 107 DECL_PROP1(DISPATCHURLINTERNAL, sal_Bool, BOUND); 108 DECL_PROP1(TARGET_URL, ::rtl::OUString, BOUND); 109 DECL_PROP1(TARGET_FRAME, ::rtl::OUString, BOUND); 110 DECL_PROP1(TABINDEX, sal_Int16, BOUND); 111 END_DESCRIBE_PROPERTIES(); 112 } 113 114 //------------------------------------------------------------------------------ 115 ::rtl::OUString OImageButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) 116 { 117 return FRM_COMPONENT_IMAGEBUTTON; // old (non-sun) name for compatibility ! 118 } 119 120 //------------------------------------------------------------------------------ 121 void OImageButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 122 { 123 OControlModel::write(_rxOutStream); 124 125 // Version 126 _rxOutStream->writeShort(0x0003); 127 _rxOutStream->writeShort((sal_uInt16)m_eButtonType); 128 129 ::rtl::OUString sTmp(INetURLObject::decode( m_sTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS)); 130 _rxOutStream << sTmp; 131 _rxOutStream << m_sTargetFrame; 132 writeHelpTextCompatibly(_rxOutStream); 133 } 134 135 //------------------------------------------------------------------------------ 136 void OImageButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 137 { 138 OControlModel::read(_rxInStream); 139 140 // Version 141 sal_uInt16 nVersion = _rxInStream->readShort(); 142 143 switch (nVersion) 144 { 145 case 0x0001: 146 { 147 m_eButtonType = (FormButtonType)_rxInStream->readShort(); 148 } 149 break; 150 case 0x0002: 151 { 152 m_eButtonType = (FormButtonType)_rxInStream->readShort(); 153 _rxInStream >> m_sTargetURL; 154 _rxInStream >> m_sTargetFrame; 155 } 156 break; 157 case 0x0003: 158 { 159 m_eButtonType = (FormButtonType)_rxInStream->readShort(); 160 _rxInStream >> m_sTargetURL; 161 _rxInStream >> m_sTargetFrame; 162 readHelpTextCompatibly(_rxInStream); 163 } 164 break; 165 166 default : 167 DBG_ERROR("OImageButtonModel::read : unknown version !"); 168 m_eButtonType = FormButtonType_PUSH; 169 m_sTargetURL = ::rtl::OUString(); 170 m_sTargetFrame = ::rtl::OUString(); 171 break; 172 } 173 } 174 175 //================================================================== 176 // OImageButtonControl 177 //================================================================== 178 //------------------------------------------------------------------ 179 InterfaceRef SAL_CALL OImageButtonControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 180 { 181 return *(new OImageButtonControl(_rxFactory)); 182 } 183 184 //------------------------------------------------------------------------------ 185 Sequence<Type> OImageButtonControl::_getTypes() 186 { 187 static Sequence<Type> aTypes; 188 if (!aTypes.getLength()) 189 aTypes = concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes()); 190 return aTypes; 191 } 192 193 //------------------------------------------------------------------------------ 194 StringSequence OImageButtonControl::getSupportedServiceNames() throw() 195 { 196 StringSequence aSupported = OClickableImageBaseControl::getSupportedServiceNames(); 197 aSupported.realloc(aSupported.getLength() + 1); 198 199 ::rtl::OUString*pArray = aSupported.getArray(); 200 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_IMAGEBUTTON; 201 return aSupported; 202 } 203 204 //------------------------------------------------------------------------------ 205 OImageButtonControl::OImageButtonControl(const Reference<XMultiServiceFactory>& _rxFactory) 206 :OClickableImageBaseControl(_rxFactory, VCL_CONTROL_IMAGEBUTTON) 207 { 208 increment(m_refCount); 209 { 210 // als MouseListener anmelden 211 Reference< awt::XWindow > xComp; 212 query_aggregation( m_xAggregate, xComp); 213 if (xComp.is()) 214 xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) ); 215 } 216 decrement(m_refCount); 217 } 218 219 // UNO Anbindung 220 //------------------------------------------------------------------------------ 221 Any SAL_CALL OImageButtonControl::queryAggregation(const Type& _rType) throw (RuntimeException) 222 { 223 Any aReturn = OClickableImageBaseControl::queryAggregation(_rType); 224 if (!aReturn.hasValue()) 225 aReturn = OImageButtonControl_BASE::queryInterface(_rType); 226 227 return aReturn; 228 } 229 230 //------------------------------------------------------------------------------ 231 void OImageButtonControl::mousePressed(const awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException) 232 { 233 ::vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 234 235 if (e.Buttons != awt::MouseButton::LEFT) 236 return; 237 238 ::osl::ClearableMutexGuard aGuard( m_aMutex ); 239 if( m_aApproveActionListeners.getLength() ) 240 { 241 // if there are listeners, start the action in an own thread, to not allow 242 // them to block us here (we're in the application's main thread) 243 getImageProducerThread()->OComponentEventThread::addEvent( &e ); 244 } 245 else 246 { 247 // Sonst nicht. Dann darf man aber auf keinen Fal die Listener 248 // benachrichtigen, auch dann nicht, wenn er spaeter hinzukommt. 249 aGuard.clear(); 250 actionPerformed_Impl( sal_False, e ); 251 } 252 } 253 254 //------------------------------------------------------------------------------ 255 void SAL_CALL OImageButtonControl::mouseReleased(const awt::MouseEvent& /*e*/) throw ( RuntimeException) 256 { 257 } 258 259 //------------------------------------------------------------------------------ 260 void SAL_CALL OImageButtonControl::mouseEntered(const awt::MouseEvent& /*e*/) throw ( RuntimeException) 261 { 262 } 263 264 //------------------------------------------------------------------------------ 265 void SAL_CALL OImageButtonControl::mouseExited(const awt::MouseEvent& /*e*/) throw ( RuntimeException) 266 { 267 } 268 269 270 //......................................................................... 271 } // namespace frm 272 //......................................................................... 273 274