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

Generated by: LCOV version 1.10