LCOV - code coverage report
Current view: top level - svx/source/inc - fmcontrolbordermanager.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 11 16 68.8 %
Date: 2015-06-13 12:38:46 Functions: 5 9 55.6 %
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_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
      21             : #define INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
      22             : 
      23             : #include <com/sun/star/awt/VisualEffect.hpp>
      24             : #include <com/sun/star/awt/FontUnderline.hpp>
      25             : #include <com/sun/star/awt/XControl.hpp>
      26             : #include <com/sun/star/awt/XVclWindowPeer.hpp>
      27             : #include <comphelper/stl_types.hxx>
      28             : 
      29             : #include <set>
      30             : 
      31             : namespace com { namespace sun { namespace star { namespace form { namespace validation {
      32             :     class XValidatableFormComponent;
      33             : } } } } }
      34             : 
      35             : 
      36             : namespace svxform
      37             : {
      38             : 
      39             : 
      40             :     typedef sal_Int16 ControlStatus;
      41             : 
      42             :     #define CONTROL_STATUS_NONE         0x00
      43             :     #define CONTROL_STATUS_FOCUSED      0x01
      44             :     #define CONTROL_STATUS_MOUSE_HOVER  0x02
      45             :     #define CONTROL_STATUS_INVALID      0x04
      46             : 
      47             :     struct BorderDescriptor
      48             :     {
      49             :         sal_Int16   nBorderType;
      50             :         sal_Int32   nBorderColor;
      51             : 
      52         232 :         BorderDescriptor()
      53             :             :nBorderType( ::com::sun::star::awt::VisualEffect::FLAT )
      54         232 :             ,nBorderColor( 0x00000000 )
      55             :         {
      56         232 :         }
      57             :         inline void clear()
      58             :         {
      59             :             nBorderType = ::com::sun::star::awt::VisualEffect::FLAT;
      60             :             nBorderColor = 0x00000000;
      61             :         }
      62             :     };
      63             : 
      64             :     struct UnderlineDescriptor
      65             :     {
      66             :         sal_Int16 nUnderlineType;
      67             :         sal_Int32 nUnderlineColor;
      68             : 
      69         232 :         UnderlineDescriptor()
      70             :             :nUnderlineType( ::com::sun::star::awt::FontUnderline::NONE )
      71         232 :             ,nUnderlineColor( 0x00000000 )
      72             :         {
      73         232 :         }
      74             : 
      75           0 :         UnderlineDescriptor( sal_Int16 _nUnderlineType, sal_Int32 _nUnderlineColor )
      76             :             :nUnderlineType( _nUnderlineType )
      77           0 :             ,nUnderlineColor( _nUnderlineColor )
      78             :         {
      79           0 :         }
      80             : 
      81             :         inline void clear()
      82             :         {
      83             :             nUnderlineType = ::com::sun::star::awt::FontUnderline::NONE;
      84             :             nUnderlineColor = 0x00000000;
      85             :         }
      86             :     };
      87             : 
      88         232 :     struct ControlData : public BorderDescriptor, UnderlineDescriptor
      89             :     {
      90             :         ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl > xControl;
      91             :         OUString                                                     sOriginalHelpText;
      92             : 
      93         190 :         ControlData() : BorderDescriptor() { }
      94          42 :         ControlData( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl )
      95          42 :             :xControl( _rxControl )
      96             :         {
      97          42 :         }
      98             :         void clear()
      99             :         {
     100             :             BorderDescriptor::clear();
     101             :             UnderlineDescriptor::clear();
     102             :             xControl.clear();
     103             :             sOriginalHelpText.clear();
     104             :         }
     105             :     };
     106             : 
     107             : 
     108             :     //= ControlBorderManager
     109             : 
     110             :     /** manages the dynamic border color for form controls
     111             : 
     112             :         Used by the <type>FormController</type>, this class manages the dynamic changes in the
     113             :         border color of form controls. For this a set of events have to be forwarded to the manager
     114             :         instance, which then will switch the border color depending on the mouse and focus status
     115             :         of the controls.
     116             :     */
     117             :     class ControlBorderManager
     118             :     {
     119             :     private:
     120             :         struct ControlDataCompare : public ::std::binary_function< ControlData, ControlData, bool >
     121             :         {
     122           0 :            bool operator()( const ControlData& _rLHS, const ControlData& _rRHS ) const
     123             :            {
     124           0 :                return _rLHS.xControl.get() < _rRHS.xControl.get();
     125             :            }
     126             :         };
     127             : 
     128             :         typedef ::std::set< ControlData, ControlDataCompare > ControlBag;
     129             :         typedef ::com::sun::star::awt::XVclWindowPeer                                       WindowPeer;
     130             :         typedef ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >   WindowPeerRef;
     131             :         typedef ::std::set< WindowPeerRef, ::comphelper::OInterfaceCompare< WindowPeer > >  PeerBag;
     132             : 
     133             :         PeerBag     m_aColorableControls;
     134             :         PeerBag     m_aNonColorableControls;
     135             : 
     136             :         ControlData m_aFocusControl;
     137             :         ControlData m_aMouseHoverControl;
     138             :         ControlBag  m_aInvalidControls;
     139             : 
     140             : 
     141             :         // attributes
     142             :         sal_Int32   m_nFocusColor;
     143             :         sal_Int32   m_nMouseHoveColor;
     144             :         sal_Int32   m_nInvalidColor;
     145             :         bool        m_bDynamicBorderColors;
     146             : 
     147             :     public:
     148             :         ControlBorderManager();
     149             :         ~ControlBorderManager();
     150             : 
     151             :     public:
     152             :         void    focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl );
     153             :         void    focusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl );
     154             :         void    mouseEntered( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl );
     155             :         void    mouseExited( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl );
     156             : 
     157             :         void    validityChanged(
     158             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
     159             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::form::validation::XValidatableFormComponent >& _rxValidatable
     160             :                 );
     161             : 
     162             :         /// enables dynamic border color for the controls
     163             :         void    enableDynamicBorderColor( );
     164             :         /// disables dynamic border color for the controls
     165             :         void    disableDynamicBorderColor( );
     166             : 
     167             :         /** sets a color to be used for a given status
     168             :             @param _nStatus
     169             :                 the status which the color should be applied for. Must not be CONTROL_STATUS_NONE
     170             :             @param _nColor
     171             :                 the color to apply for the given status
     172             :         */
     173             :         void    setStatusColor( ControlStatus _nStatus, sal_Int32 _nColor );
     174             : 
     175             :         /** restores all colors of all controls where we possibly changed them
     176             :         */
     177             :         void    restoreAll();
     178             : 
     179             :     private:
     180             :         /** called when a control got one of the two possible statuses (focused, and hovered with the mouse)
     181             :             @param _rxControl
     182             :                 the control which gained the status
     183             :             @param _rControlData
     184             :                 the control's status data, as a reference to our respective member
     185             :         */
     186             :         void    controlStatusGained(
     187             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl,
     188             :                     ControlData& _rControlData
     189             :                 );
     190             : 
     191             :         /** called when a control lost one of the two possible statuses (focused, and hovered with the mouse)
     192             :             @param _rxControl
     193             :                 the control which lost the status
     194             :             @param _rControlData
     195             :                 the control's status data, as a reference to our respective member
     196             :         */
     197             :         void    controlStatusLost( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxControl, ControlData& _rControlData );
     198             : 
     199             :         /** determines whether the border of a given peer can be colored
     200             :             @param _rxPeer
     201             :                 the peer to examine. Must not be <NULL/>
     202             :         */
     203             :         bool    canColorBorder( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer );
     204             : 
     205             :         /** determines the status of the given control
     206             :         */
     207             :         ControlStatus   getControlStatus( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl );
     208             : 
     209             :         /** retrieves the color associated with a given ControlStatus
     210             :             @param _eStatus
     211             :                 the status of the control. Must not be <member>ControlStatus::none</member>
     212             :         */
     213             :         sal_Int32       getControlColorByStatus( ControlStatus _eStatus );
     214             : 
     215             :         /** sets the border color for a given control, depending on its status
     216             :             @param _rxControl
     217             :                 the control to set the border color for. Must not be <NULL/>
     218             :             @param _rxPeer
     219             :                 the peer of the control, to be passed herein for optimization the caller usually needs it, anyway).
     220             :                 Must not be <NULL/>
     221             :             @param _rFallback
     222             :                 the color/type to use when the control has the status CONTROL_STATUS_NONE
     223             :         */
     224             :         void            updateBorderStyle(
     225             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
     226             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >& _rxPeer,
     227             :                             const BorderDescriptor& _rFallback
     228             :                         );
     229             : 
     230             :         /** determines the to-be-remembered original border color and type for a control
     231             : 
     232             :             The method also takes into account that the control may currently have an overwritten
     233             :             border style
     234             : 
     235             :             @param _rxControl
     236             :                 the control to examine. Must not be <NULL/>, and have a non-<NULL/> peer
     237             :         */
     238             :         void determineOriginalBorderStyle(
     239             :                     const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl >& _rxControl,
     240             :                     BorderDescriptor& _rData
     241             :                 ) const;
     242             :     };
     243             : 
     244             : 
     245             : }
     246             : 
     247             : 
     248             : #endif // INCLUDED_SVX_SOURCE_INC_FMCONTROLBORDERMANAGER_HXX
     249             : 
     250             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11