LCOV - code coverage report
Current view: top level - extensions/source/propctrlr - commoncontrol.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 56 0.0 %
Date: 2014-11-03 Functions: 0 205 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 INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_COMMONCONTROL_HXX
      21             : #define INCLUDED_EXTENSIONS_SOURCE_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( vcl::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 bool 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             :         vcl::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             :         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             :             vcl::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 = true; }
     129           0 :         inline       vcl::Window* getVclControlWindow()       { return m_pControlWindow; }
     130           0 :         inline const vcl::Window* getVclControlWindow() const { return m_pControlWindow; }
     131             : 
     132             :     public:
     133             :         // XPropertyControl
     134           0 :         ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException) { return m_nControlType; }
     135           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL getControlContext() throw (::com::sun::star::uno::RuntimeException) { return m_xContext; }
     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           0 :         bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException) { return m_bModified; }
     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, vcl::Window* );
     157             :         DECL_LINK( GetFocusHdl, vcl::Window* );
     158             :         DECL_LINK( LoseFocusHdl, vcl::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, vcl::Window* _pParentWindow, WinBits _nWindowStyle, bool _bDoSetHandlers = true );
     195             : 
     196             :         // XPropertyControl - delegated to ->m_aImplControl
     197             :         virtual ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     198             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL getControlContext() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     199             :         virtual void SAL_CALL setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     200             :         virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getControlWindow() throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     201             :         virtual sal_Bool SAL_CALL isModified(  ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     202             :         virtual void SAL_CALL notifyModifiedValue(  ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     203             : 
     204             :         // XComponent
     205             :         virtual void SAL_CALL disposing() SAL_OVERRIDE;
     206             : 
     207             :         // IModifyListener
     208           0 :         virtual void modified() SAL_OVERRIDE
     209           0 :         { m_aImplControl.setModified(); }
     210             : 
     211             :         /// returns a typed pointer to our control window
     212           0 :               WindowType* getTypedControlWindow()       { return static_cast< WindowType* >      ( m_aImplControl.getVclControlWindow() ); }
     213           0 :         const WindowType* getTypedControlWindow() const { return static_cast< const WindowType* >( m_aImplControl.getVclControlWindow() ); }
     214             : 
     215             :     protected:
     216             :         /** checks whether the instance is already disposed
     217             :             @throws DisposedException
     218             :                 if the instance is already disposed
     219             :         */
     220             :         inline void impl_checkDisposed_throw();
     221             :     };
     222             : 
     223             : 
     224             :     //= ControlWindow - implementation
     225             : 
     226             : 
     227             :     template< class WINDOW >
     228           0 :     inline void ControlWindow< WINDOW >::setControlHelper( ControlHelper& _rControlHelper )
     229             :     {
     230           0 :         m_pHelper = &_rControlHelper;
     231           0 :     }
     232             : 
     233             : 
     234             :     template< class WINDOW >
     235           0 :     inline bool ControlWindow< WINDOW >::PreNotify( NotifyEvent& rNEvt )
     236             :     {
     237           0 :         if ( m_pHelper && m_pHelper->handlePreNotify( rNEvt ) )
     238           0 :             return true;
     239           0 :         return WindowType::PreNotify( rNEvt );
     240             :     }
     241             : 
     242             : 
     243             :     //= CommonBehaviourControl - implementation
     244             : 
     245             : 
     246             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     247           0 :     inline CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::CommonBehaviourControl ( sal_Int16 _nControlType, vcl::Window* _pParentWindow, WinBits _nWindowStyle, bool _bDoSetHandlers )
     248             :         :ComponentBaseClass( m_aMutex )
     249           0 :         ,m_aImplControl( new WindowType( _pParentWindow, _nWindowStyle ), _nControlType, *this, this )
     250             :     {
     251           0 :         WindowType* pControlWindow( getTypedControlWindow() );
     252           0 :         pControlWindow->setControlHelper( m_aImplControl );
     253           0 :         if ( _bDoSetHandlers )
     254             :         {
     255           0 :             pControlWindow->SetModifyHdl( LINK( &m_aImplControl, ControlHelper, ModifiedHdl ) );
     256           0 :             pControlWindow->SetGetFocusHdl( LINK( &m_aImplControl, ControlHelper, GetFocusHdl ) );
     257           0 :             pControlWindow->SetLoseFocusHdl( LINK( &m_aImplControl, ControlHelper, LoseFocusHdl ) );
     258             :         }
     259           0 :         m_aImplControl.autoSizeWindow();
     260           0 :     }
     261             : 
     262             : 
     263             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     264           0 :     inline ::sal_Int16 SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlType() throw (::com::sun::star::uno::RuntimeException)
     265             :     {
     266           0 :         return m_aImplControl.getControlType();
     267             :     }
     268             : 
     269             : 
     270             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     271           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)
     272             :     {
     273           0 :         return m_aImplControl.getControlContext();
     274             :     }
     275             : 
     276             : 
     277             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     278           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)
     279             :     {
     280           0 :         m_aImplControl.setControlContext( _controlcontext );
     281           0 :     }
     282             : 
     283             : 
     284             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     285           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)
     286             :     {
     287           0 :         return m_aImplControl.getControlWindow();
     288             :     }
     289             : 
     290             : 
     291             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     292           0 :     inline sal_Bool SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::isModified(  ) throw (::com::sun::star::uno::RuntimeException)
     293             :     {
     294           0 :         return m_aImplControl.isModified();
     295             :     }
     296             : 
     297             : 
     298             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     299           0 :     inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::notifyModifiedValue(  ) throw (::com::sun::star::uno::RuntimeException)
     300             :     {
     301           0 :         m_aImplControl.notifyModifiedValue();
     302           0 :     }
     303             : 
     304             : 
     305             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     306           0 :     inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::disposing()
     307             :     {
     308           0 :         m_aImplControl.dispose();
     309           0 :     }
     310             : 
     311             : 
     312             :     template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
     313           0 :     inline void CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::impl_checkDisposed_throw()
     314             :     {
     315           0 :         if ( ComponentBaseClass::rBHelper.bDisposed )
     316           0 :             throw ::com::sun::star::lang::DisposedException( OUString(), *this );
     317           0 :     }
     318             : 
     319             : 
     320             : } // namespace pcr
     321             : 
     322             : 
     323             : #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_COMMONCONTROL_HXX
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10