LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/propctrlr - commoncontrol.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 54 0.0 %
Date: 2012-12-27 Functions: 0 202 0.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             : #ifndef _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
      21             : #define _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
      22             : 
      23             : #include <com/sun/star/inspection/XPropertyControl.hpp>
      24             : #include <com/sun/star/lang/DisposedException.hpp>
      25             : #include <cppuhelper/compbase1.hxx>
      26             : #include <comphelper/broadcasthelper.hxx>
      27             : #include <tools/link.hxx>
      28             : #include <vcl/window.hxx>
      29             : 
      30             : class NotifyEvent;
      31             : //............................................................................
      32             : namespace pcr
      33             : {
      34             : //............................................................................
      35             : 
      36             :     class ControlHelper;
      37             :     //========================================================================
      38             :     //= ControlWindow
      39             :     //========================================================================
      40             :     template< class WINDOW >
      41           0 :     class ControlWindow : public WINDOW
      42             :     {
      43             :     protected:
      44             :         typedef WINDOW  WindowType;
      45             : 
      46             :     protected:
      47             :         ControlHelper*  m_pHelper;
      48             : 
      49             :     public:
      50           0 :         ControlWindow( Window* _pParent, WinBits _nStyle )
      51             :             :WindowType( _pParent, _nStyle )
      52           0 :             ,m_pHelper( NULL )
      53             :         {
      54           0 :         }
      55             : 
      56             :         /// sets a ControlHelper instance which some functionality is delegated to
      57             :         inline virtual void setControlHelper( ControlHelper& _rControlHelper );
      58             : 
      59             :     protected:
      60             :         // Window overridables
      61             :         inline virtual long PreNotify( NotifyEvent& rNEvt );
      62             :     };
      63             : 
      64             :     //========================================================================
      65             :     //= IModifyListener
      66             :     //========================================================================
      67           0 :     class SAL_NO_VTABLE IModifyListener
      68             :     {
      69             :     public:
      70             :         virtual void modified() = 0;
      71             : 
      72             :     protected:
      73           0 :         ~IModifyListener() {}
      74             :     };
      75             : 
      76             :     //========================================================================
      77             :     //= ControlHelper
      78             :     //========================================================================
      79             :     /** A helper class for implementing the <type scope="com::sun::star::inspection">XPropertyControl</type>
      80             :         or one of its derived interfaces.
      81             : 
      82             :         This class is intended to be held as member of another class which implements the
      83             :         <type scope="com::sun::star::inspection">XPropertyControl</type> interface. The pointer
      84             :         to this interface is to be passed to the ctor.
      85             :     */
      86             :     class ControlHelper
      87             :     {
      88             :     private:
      89             :         Window*                         m_pControlWindow;
      90             :         sal_Int16                       m_nControlType;
      91             :         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >
      92             :                                         m_xContext;
      93             :         ::com::sun::star::inspection::XPropertyControl&
      94             :                                         m_rAntiImpl;
      95             :         IModifyListener*                m_pModifyListener;
      96             :         sal_Bool                        m_bModified;
      97             : 
      98             :     public:
      99             :         /** creates the instance
     100             :             @param  _rControlWindow
     101             :                 the window which is associated with the <type scope="com::sun::star::inspection">XPropertyControl</type>.
     102             :                 Must not be <NULL/>.<br/>
     103             :                 Ownership for this window is taken by the ControlHelper - it will be deleted in <member>disposing</member>.
     104             :             @param  _nControlType
     105             :                 the type of the control - one of the <type scope="com::sun::star::inspection">PropertyControlType</type>
     106             :                 constants
     107             :             @param _pAntiImpl
     108             :                 Reference to the instance as whose "impl-class" we act. This reference is held during lifetime
     109             :                 of the <type>ControlHelper</type> class, within acquiring it. Thus, the owner of the
     110             :                 <type>ControlHelper</type> is responsible for assuring the lifetime of the instance
     111             :                 pointed to by <arg>_pAntiImpl</arg>.
     112             :             @param _pModifyListener
     113             :                 a listener to be modfied when the user modified the control's value. the
     114             :                 <member>IModifyListener::modified</member> of this listener is called from within our
     115             :                 ModifiedHdl. A default implementation of <member>IModifyListener::modified</member>
     116             :                 would just call our <member>setModified</member>.
     117             :         */
     118             :         ControlHelper(
     119             :             Window* _pControlWindow,
     120             :             sal_Int16 _nControlType,
     121             :             ::com::sun::star::inspection::XPropertyControl& _rAntiImpl,
     122             :             IModifyListener* _pModifyListener );
     123             : 
     124             :         virtual ~ControlHelper();
     125             : 
     126             :         /** sets our "modified" flag to <TRUE/>
     127             :         */
     128           0 :         inline void setModified() { m_bModified = sal_True; }
     129           0 :         inline       Window* getVclControlWindow()       { return m_pControlWindow; }
     130           0 :         inline const Window* getVclControlWindow() const { return m_pControlWindow; }
     131             : 
     132             :     public:
     133             :         // XPropertyControl
     134             :         ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException);
     135             :         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL getControlContext() throw (::com::sun::star::uno::RuntimeException);
     136             :         void SAL_CALL setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException);
     137             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getControlWindow() throw (::com::sun::star::uno::RuntimeException);
     138             :         ::sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException);
     139             :         void SAL_CALL notifyModifiedValue(  ) throw (::com::sun::star::uno::RuntimeException);
     140             : 
     141             :         // XComponent
     142             :         virtual void SAL_CALL dispose();
     143             : 
     144             :         /** (fail-safe) wrapper around calling our context's activateNextControl
     145             :         */
     146           0 :         inline void activateNextControl() const { impl_activateNextControl_nothrow(); }
     147             : 
     148             :     public:
     149             :         /// may be used to implement the default handling in PreNotify; returns sal_True if handled
     150             :         bool handlePreNotify(NotifyEvent& _rNEvt);
     151             : 
     152             :         /// automatically size the window given in the ctor
     153             :         void    autoSizeWindow();
     154             : 
     155             :         /// may be used by derived classes, they forward the event to the PropCtrListener
     156             :         DECL_LINK( ModifiedHdl, Window* );
     157             :         DECL_LINK( GetFocusHdl, Window* );
     158             :         DECL_LINK( LoseFocusHdl, Window* );
     159             : 
     160             :     private:
     161             :         /** fail-safe wrapper around calling our context's activateNextControl
     162             :         */
     163             :         void    impl_activateNextControl_nothrow() const;
     164             :     };
     165             : 
     166             :     //========================================================================
     167             :     //= CommonBehaviourControl
     168             :     //========================================================================
     169             :     /** implements a base class for <type scope="com::sun::star::inspection">XPropertyControl</type>
     170             :         implementations, which delegates the generic functionality of this interface to a
     171             :         <type>ControlHelper</type> member.
     172             : 
     173             :         @param CONTROL_INTERFACE
     174             :             an interface class which is derived from (or identical to) <type scope="com::sun::star::inspection">XPropertyControl</type>
     175             :         @param CONTROL_WINDOW
     176             :             a class which is derived from ControlWindow
     177             :     */
     178             :     template < class CONTROL_INTERFACE, class CONTROL_WINDOW >
     179           0 :     class CommonBehaviourControl    :public ::comphelper::OBaseMutex
     180             :                                     ,public ::cppu::WeakComponentImplHelper1< CONTROL_INTERFACE >
     181             :                                     ,public IModifyListener
     182             :     {
     183             :     protected:
     184             :         typedef CONTROL_INTERFACE   InterfaceType;
     185             :         typedef CONTROL_WINDOW      WindowType;
     186             : 
     187             :         typedef ::comphelper::OBaseMutex                                MutexBaseClass;
     188             :         typedef ::cppu::WeakComponentImplHelper1< CONTROL_INTERFACE >   ComponentBaseClass;
     189             : 
     190             :     protected:
     191             :         ControlHelper   m_aImplControl;
     192             : 
     193             :     protected:
     194             :         inline CommonBehaviourControl( sal_Int16 _nControlType, Window* _pParentWindow, WinBits _nWindowStyle, bool _bDoSetHandlers = true );
     195             : 
     196             :         // XPropertyControl - delegated to ->m_aImplControl
     197             :         inline ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException);
     198             :         inline ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL getControlContext() throw (::com::sun::star::uno::RuntimeException);
     199             :         inline void SAL_CALL setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException);
     200             :         inline ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getControlWindow() throw (::com::sun::star::uno::RuntimeException);
     201             :         inline ::sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException);
     202             :         inline void SAL_CALL notifyModifiedValue(  ) throw (::com::sun::star::uno::RuntimeException);
     203             : 
     204             :         // XComponent
     205             :         inline virtual void SAL_CALL disposing();
     206             : 
     207             :         // IModifyListener
     208             :         inline virtual void modified();
     209             : 
     210             :         /// returns a typed pointer to our control window
     211           0 :               WindowType* getTypedControlWindow()       { return static_cast< WindowType* >      ( m_aImplControl.getVclControlWindow() ); }
     212           0 :         const WindowType* getTypedControlWindow() const { return static_cast< const WindowType* >( m_aImplControl.getVclControlWindow() ); }
     213             : 
     214             :     protected:
     215             :         /** checks whether the instance is already disposed
     216             :             @throws DisposedException
     217             :                 if the instance is already disposed
     218             :         */
     219             :         inline void impl_checkDisposed_throw();
     220             :     };
     221             : 
     222             :     //========================================================================
     223             :     //= ControlWindow - implementation
     224             :     //========================================================================
     225             :     //------------------------------------------------------------------------
     226             :     template< class WINDOW >
     227           0 :     inline void ControlWindow< WINDOW >::setControlHelper( ControlHelper& _rControlHelper )
     228             :     {
     229           0 :         m_pHelper = &_rControlHelper;
     230           0 :     }
     231             : 
     232             :     //------------------------------------------------------------------------
     233             :     template< class WINDOW >
     234           0 :     inline long ControlWindow< WINDOW >::PreNotify( NotifyEvent& rNEvt )
     235             :     {
     236           0 :         if ( m_pHelper && m_pHelper->handlePreNotify( rNEvt ) )
     237           0 :             return 1;
     238           0 :         return WindowType::PreNotify( rNEvt );
     239             :     }
     240             : 
     241             :     //========================================================================
     242             :     //= CommonBehaviourControl - implementation
     243             :     //========================================================================
     244             :     //------------------------------------------------------------------------
     245             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     246           0 :     inline CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::CommonBehaviourControl ( sal_Int16 _nControlType, Window* _pParentWindow, WinBits _nWindowStyle, bool _bDoSetHandlers )
     247             :         :ComponentBaseClass( m_aMutex )
     248           0 :         ,m_aImplControl( new WindowType( _pParentWindow, _nWindowStyle ), _nControlType, *this, this )
     249             :     {
     250           0 :         WindowType* pControlWindow( getTypedControlWindow() );
     251           0 :         pControlWindow->setControlHelper( m_aImplControl );
     252           0 :         if ( _bDoSetHandlers )
     253             :         {
     254           0 :             pControlWindow->SetModifyHdl( LINK( &m_aImplControl, ControlHelper, ModifiedHdl ) );
     255           0 :             pControlWindow->SetGetFocusHdl( LINK( &m_aImplControl, ControlHelper, GetFocusHdl ) );
     256           0 :             pControlWindow->SetLoseFocusHdl( LINK( &m_aImplControl, ControlHelper, LoseFocusHdl ) );
     257             :         }
     258           0 :         m_aImplControl.autoSizeWindow();
     259           0 :     }
     260             : 
     261             :     //--------------------------------------------------------------------
     262             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     263           0 :     inline ::sal_Int16 SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlType() throw (::com::sun::star::uno::RuntimeException)
     264             :     {
     265           0 :         return m_aImplControl.getControlType();
     266             :     }
     267             : 
     268             :     //--------------------------------------------------------------------
     269             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     270           0 :     inline ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlContext() throw (::com::sun::star::uno::RuntimeException)
     271             :     {
     272           0 :         return m_aImplControl.getControlContext();
     273             :     }
     274             : 
     275             :     //--------------------------------------------------------------------
     276             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     277           0 :     inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException)
     278             :     {
     279           0 :         m_aImplControl.setControlContext( _controlcontext );
     280           0 :     }
     281             : 
     282             :     //--------------------------------------------------------------------
     283             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     284           0 :     inline ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlWindow() throw (::com::sun::star::uno::RuntimeException)
     285             :     {
     286           0 :         return m_aImplControl.getControlWindow();
     287             :     }
     288             : 
     289             :     //--------------------------------------------------------------------
     290             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     291           0 :     inline ::sal_Bool SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::isModified(  ) throw (::com::sun::star::uno::RuntimeException)
     292             :     {
     293           0 :         return m_aImplControl.isModified();
     294             :     }
     295             : 
     296             :     //--------------------------------------------------------------------
     297             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     298           0 :     inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::notifyModifiedValue(  ) throw (::com::sun::star::uno::RuntimeException)
     299             :     {
     300           0 :         m_aImplControl.notifyModifiedValue();
     301           0 :     }
     302             : 
     303             :     //--------------------------------------------------------------------
     304             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     305           0 :     inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::disposing()
     306             :     {
     307           0 :         m_aImplControl.dispose();
     308           0 :     }
     309             : 
     310             :     //--------------------------------------------------------------------
     311             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     312           0 :     inline void CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::modified()
     313             :     {
     314           0 :         m_aImplControl.setModified();
     315           0 :     }
     316             : 
     317             :     //--------------------------------------------------------------------
     318             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     319           0 :     inline void CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::impl_checkDisposed_throw()
     320             :     {
     321           0 :         if ( ComponentBaseClass::rBHelper.bDisposed )
     322           0 :             throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *this );
     323           0 :     }
     324             : 
     325             : //............................................................................
     326             : } // namespace pcr
     327             : //............................................................................
     328             : 
     329             : #endif // _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10