LCOV - code coverage report
Current view: top level - forms/source/component - ImageButton.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 64 101 63.4 %
Date: 2014-04-11 Functions: 14 20 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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>
      25             : #include <comphelper/basicio.hxx>
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <com/sun/star/awt/MouseButton.hpp>
      28             : 
      29             : namespace frm
      30             : {
      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;
      42             : 
      43             : // OImageButtonModel
      44          11 : InterfaceRef SAL_CALL OImageButtonModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      45             : {
      46          11 :      return *(new OImageButtonModel( comphelper::getComponentContext(_rxFactory) ));
      47             : }
      48             : 
      49          11 : OImageButtonModel::OImageButtonModel(const Reference<XComponentContext>& _rxFactory)
      50          11 :                     :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON )
      51             :                                     // use the old control name for compytibility reasons
      52             : {
      53          11 :     m_nClassId = FormComponentType::IMAGEBUTTON;
      54          11 : }
      55             : 
      56           1 : OImageButtonModel::OImageButtonModel( const OImageButtonModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
      57           1 :     :OClickableImageBaseModel( _pOriginal, _rxFactory )
      58             : {
      59           1 :     implInitializeImageURL();
      60           1 : }
      61             : 
      62           1 : IMPLEMENT_DEFAULT_CLONING( OImageButtonModel )
      63             : 
      64          18 : OImageButtonModel::~OImageButtonModel()
      65             : {
      66          18 : }
      67             : 
      68             : // XServiceInfo
      69           5 : StringSequence  OImageButtonModel::getSupportedServiceNames() throw(std::exception)
      70             : {
      71           5 :     StringSequence aSupported = OClickableImageBaseModel::getSupportedServiceNames();
      72           5 :     aSupported.realloc(aSupported.getLength() + 1);
      73             : 
      74           5 :     OUString*pArray = aSupported.getArray();
      75           5 :     pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_IMAGEBUTTON;
      76           5 :     return aSupported;
      77             : }
      78             : 
      79          13 : void OImageButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
      80             : {
      81          13 :     BEGIN_DESCRIBE_PROPERTIES( 5, OClickableImageBaseModel )
      82          13 :         DECL_PROP1(BUTTONTYPE,          FormButtonType,     BOUND);
      83          13 :         DECL_PROP1(DISPATCHURLINTERNAL, sal_Bool,           BOUND);
      84          13 :         DECL_PROP1(TARGET_URL,          OUString,    BOUND);
      85          13 :         DECL_PROP1(TARGET_FRAME,        OUString,    BOUND);
      86          13 :         DECL_PROP1(TABINDEX,            sal_Int16,          BOUND);
      87             :     END_DESCRIBE_PROPERTIES();
      88          13 : }
      89             : 
      90           1 : OUString OImageButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
      91             : {
      92           1 :     return OUString(FRM_COMPONENT_IMAGEBUTTON);   // old (non-sun) name for compatibility !
      93             : }
      94             : 
      95           1 : void OImageButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
      96             : {
      97           1 :     OControlModel::write(_rxOutStream);
      98             : 
      99             :     // Version
     100           1 :     _rxOutStream->writeShort(0x0003);
     101           1 :     _rxOutStream->writeShort((sal_uInt16)m_eButtonType);
     102             : 
     103           1 :     OUString sTmp(INetURLObject::decode( m_sTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS));
     104           1 :     _rxOutStream << sTmp;
     105           1 :     _rxOutStream << m_sTargetFrame;
     106           1 :     writeHelpTextCompatibly(_rxOutStream);
     107           1 : }
     108             : 
     109           1 : void OImageButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception)
     110             : {
     111           1 :     OControlModel::read(_rxInStream);
     112             : 
     113             :     // Version
     114           1 :     sal_uInt16 nVersion = _rxInStream->readShort();
     115             : 
     116           1 :     switch (nVersion)
     117             :     {
     118             :         case 0x0001:
     119             :         {
     120           0 :             m_eButtonType = (FormButtonType)_rxInStream->readShort();
     121             :         }
     122           0 :         break;
     123             :         case 0x0002:
     124             :         {
     125           0 :             m_eButtonType = (FormButtonType)_rxInStream->readShort();
     126           0 :             _rxInStream >> m_sTargetURL;
     127           0 :             _rxInStream >> m_sTargetFrame;
     128             :         }
     129           0 :         break;
     130             :         case 0x0003:
     131             :         {
     132           1 :             m_eButtonType = (FormButtonType)_rxInStream->readShort();
     133           1 :             _rxInStream >> m_sTargetURL;
     134           1 :             _rxInStream >> m_sTargetFrame;
     135           1 :             readHelpTextCompatibly(_rxInStream);
     136             :         }
     137           1 :         break;
     138             : 
     139             :         default :
     140             :             OSL_FAIL("OImageButtonModel::read : unknown version !");
     141           0 :             m_eButtonType = FormButtonType_PUSH;
     142           0 :             m_sTargetURL = OUString();
     143           0 :             m_sTargetFrame = OUString();
     144           0 :             break;
     145             :     }
     146           1 : }
     147             : 
     148             : // OImageButtonControl
     149           9 : InterfaceRef SAL_CALL OImageButtonControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
     150             : {
     151           9 :     return *(new OImageButtonControl( comphelper::getComponentContext(_rxFactory) ));
     152             : }
     153             : 
     154           0 : Sequence<Type> OImageButtonControl::_getTypes()
     155             : {
     156           0 :     static Sequence<Type> aTypes;
     157           0 :     if (!aTypes.getLength())
     158           0 :         aTypes = concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
     159           0 :     return aTypes;
     160             : }
     161             : 
     162           0 : StringSequence  OImageButtonControl::getSupportedServiceNames() throw(std::exception)
     163             : {
     164           0 :     StringSequence aSupported = OClickableImageBaseControl::getSupportedServiceNames();
     165           0 :     aSupported.realloc(aSupported.getLength() + 1);
     166             : 
     167           0 :     OUString*pArray = aSupported.getArray();
     168           0 :     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_IMAGEBUTTON;
     169           0 :     return aSupported;
     170             : }
     171             : 
     172           9 : OImageButtonControl::OImageButtonControl(const Reference<XComponentContext>& _rxFactory)
     173           9 :             :OClickableImageBaseControl(_rxFactory, VCL_CONTROL_IMAGEBUTTON)
     174             : {
     175           9 :     increment(m_refCount);
     176             :     {
     177             :         // als MouseListener anmelden
     178           9 :         Reference< awt::XWindow >  xComp;
     179           9 :         query_aggregation( m_xAggregate, xComp);
     180           9 :         if (xComp.is())
     181           9 :             xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) );
     182             :     }
     183           9 :     decrement(m_refCount);
     184           9 : }
     185             : 
     186             : // UNO Anbindung
     187         649 : Any SAL_CALL OImageButtonControl::queryAggregation(const Type& _rType) throw (RuntimeException, std::exception)
     188             : {
     189         649 :     Any aReturn = OClickableImageBaseControl::queryAggregation(_rType);
     190         649 :     if (!aReturn.hasValue())
     191          17 :         aReturn = OImageButtonControl_BASE::queryInterface(_rType);
     192             : 
     193         649 :     return aReturn;
     194             : }
     195             : 
     196           0 : void OImageButtonControl::mousePressed(const awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     197             : {
     198           0 :     SolarMutexGuard aSolarGuard;
     199             : 
     200           0 :     if (e.Buttons != awt::MouseButton::LEFT)
     201           0 :         return;
     202             : 
     203           0 :     ::osl::ClearableMutexGuard aGuard( m_aMutex );
     204           0 :     if( m_aApproveActionListeners.getLength() )
     205             :     {
     206             :         // if there are listeners, start the action in an own thread, to not allow
     207             :         // them to block us here (we're in the application's main thread)
     208           0 :         getImageProducerThread()->OComponentEventThread::addEvent( &e );
     209             :     }
     210             :     else
     211             :     {
     212             :         // Sonst nicht. Dann darf man aber auf keinen Fal die Listener
     213             :         // benachrichtigen, auch dann nicht, wenn er spaeter hinzukommt.
     214           0 :         aGuard.clear();
     215           0 :         actionPerformed_Impl( sal_False, e );
     216           0 :     }
     217             : }
     218             : 
     219           0 : void SAL_CALL OImageButtonControl::mouseReleased(const awt::MouseEvent& /*e*/) throw ( RuntimeException, std::exception)
     220             : {
     221           0 : }
     222             : 
     223           0 : void SAL_CALL OImageButtonControl::mouseEntered(const awt::MouseEvent& /*e*/) throw ( RuntimeException, std::exception)
     224             : {
     225           0 : }
     226             : 
     227           0 : void SAL_CALL OImageButtonControl::mouseExited(const awt::MouseEvent& /*e*/) throw ( RuntimeException, std::exception)
     228             : {
     229           0 : }
     230             : 
     231             : }   // namespace frm
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10