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

Generated by: LCOV version 1.11