LCOV - code coverage report
Current view: top level - forms/source/component - ImageButton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 101 63.4 %
Date: 2012-08-25 Functions: 14 20 70.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 37 124 29.8 %

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

Generated by: LCOV version 1.10