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

Generated by: LCOV version 1.11