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

Generated by: LCOV version 1.10