LCOV - code coverage report
Current view: top level - svtools/source/control - hyperlabel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 96 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 86 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svtools/hyperlabel.hxx>
      30                 :            : #include <vcl/bitmap.hxx>
      31                 :            : #include <tools/color.hxx>
      32                 :            : 
      33                 :            : #include <vcl/tabpage.hxx>
      34                 :            : 
      35                 :            : 
      36                 :            : //.........................................................................
      37                 :            : namespace svt
      38                 :            : {
      39                 :            : //.........................................................................
      40                 :            : 
      41                 :            :     //=====================================================================
      42                 :            :     //= FontChanger
      43                 :            :     //=====================================================================
      44                 :            :     class FontChanger
      45                 :            :     {
      46                 :            :     protected:
      47                 :            :         OutputDevice*   m_pDev;
      48                 :            : 
      49                 :            :     public:
      50                 :            :         FontChanger( OutputDevice* _pDev, const Font& _rNewFont )
      51                 :            :             :m_pDev( _pDev )
      52                 :            :         {
      53                 :            :             m_pDev->Push( PUSH_FONT );
      54                 :            :             m_pDev->SetFont( _rNewFont );
      55                 :            :         }
      56                 :            : 
      57                 :            :         ~FontChanger()
      58                 :            :         {
      59                 :            :             m_pDev->Pop( );
      60                 :            :         }
      61                 :            :     };
      62                 :            : 
      63                 :            :     class HyperLabelImpl
      64                 :            :     {
      65                 :            :     public:
      66                 :            :         sal_Int16           ID;
      67                 :            :         sal_Int32           Index;
      68                 :            :         sal_Bool            bInteractive;
      69                 :            :         Size                m_aMinSize;
      70                 :            :         sal_Bool            m_bHyperMode;
      71                 :            : 
      72                 :            :         HyperLabelImpl();
      73                 :            :     };
      74                 :            : 
      75                 :            :     //---------------------------------------------------------------------
      76                 :          0 :     HyperLabelImpl::HyperLabelImpl()
      77                 :            :     {
      78                 :          0 :     }
      79                 :            : 
      80                 :          0 :     HyperLabel::HyperLabel( Window* _pParent, WinBits _nWinStyle )
      81                 :            :         :FixedText( _pParent, _nWinStyle )
      82 [ #  # ][ #  # ]:          0 :         ,m_pImpl( new HyperLabelImpl )
      83                 :            :     {
      84         [ #  # ]:          0 :         implInit();
      85                 :          0 :     }
      86                 :            : 
      87                 :          0 :     Size HyperLabel::CalcMinimumSize( long nMaxWidth ) const
      88                 :            :     {
      89                 :          0 :         m_pImpl->m_aMinSize = FixedText::CalcMinimumSize( nMaxWidth );
      90                 :            :         // the MinimumSize is used to size the FocusRectangle
      91                 :            :         // and for the MouseMove method
      92                 :          0 :         m_pImpl->m_aMinSize.Height() += 2;
      93                 :          0 :         m_pImpl->m_aMinSize.Width() += 1;
      94                 :          0 :         return m_pImpl->m_aMinSize;
      95                 :            :     }
      96                 :            : 
      97                 :          0 :     void HyperLabel::implInit()
      98                 :            :     {
      99         [ #  # ]:          0 :         ToggleBackgroundColor( COL_TRANSPARENT );
     100                 :            : 
     101                 :          0 :         WinBits nWinStyle = GetStyle();
     102                 :          0 :         nWinStyle |= WB_EXTRAOFFSET;
     103                 :          0 :         SetStyle( nWinStyle );
     104                 :            : 
     105                 :          0 :         Show();
     106                 :          0 :     }
     107                 :            : 
     108                 :          0 :     void HyperLabel::ToggleBackgroundColor( const Color& _rGBColor )
     109                 :            :     {
     110                 :          0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     111                 :          0 :         SetControlBackground( _rGBColor );
     112         [ #  # ]:          0 :         if (_rGBColor == COL_TRANSPARENT)
     113                 :          0 :             SetTextColor( rStyleSettings.GetFieldTextColor( ) );
     114                 :            :         else
     115                 :          0 :             SetTextColor( rStyleSettings.GetHighlightTextColor( ) );
     116                 :          0 :     }
     117                 :            : 
     118                 :            : 
     119                 :          0 :     void HyperLabel::MouseMove( const MouseEvent& rMEvt )
     120                 :            :     {
     121         [ #  # ]:          0 :            Font aFont = GetControlFont( );
     122                 :          0 :         const Color aColor = GetTextColor();
     123                 :            : 
     124         [ #  # ]:          0 :         if (rMEvt.IsLeaveWindow())
     125                 :            :         {
     126 [ #  # ][ #  # ]:          0 :             DeactivateHyperMode(aFont, aColor);
                 [ #  # ]
     127                 :            :         }
     128                 :            :         else
     129                 :            :         {
     130         [ #  # ]:          0 :             Point aPoint = GetPointerPosPixel();
     131         [ #  # ]:          0 :             if (aPoint.X() < m_pImpl->m_aMinSize.Width())
     132                 :            :             {
     133 [ #  # ][ #  # ]:          0 :                 if ( IsEnabled() && (m_pImpl->bInteractive) )
         [ #  # ][ #  # ]
     134                 :            :                 {
     135 [ #  # ][ #  # ]:          0 :                     ActivateHyperMode( aFont, aColor);
                 [ #  # ]
     136                 :          0 :                     return;
     137                 :            :                 }
     138                 :            :             }
     139 [ #  # ][ #  # ]:          0 :             DeactivateHyperMode(aFont, aColor);
                 [ #  # ]
     140 [ #  # ][ #  # ]:          0 :         }
     141                 :            :     }
     142                 :            : 
     143                 :          0 :     void HyperLabel::ActivateHyperMode(Font aFont, const Color aColor)
     144                 :            :     {
     145                 :          0 :         aFont.SetUnderline(UNDERLINE_SINGLE);
     146                 :          0 :         m_pImpl->m_bHyperMode = sal_True;
     147         [ #  # ]:          0 :         SetPointer( POINTER_REFHAND );
     148                 :          0 :         SetControlFont( aFont);
     149                 :          0 :         SetTextColor( aColor);
     150                 :            : 
     151                 :          0 :     }
     152                 :            : 
     153                 :          0 :     void HyperLabel::DeactivateHyperMode(Font aFont, const Color aColor)
     154                 :            :     {
     155                 :          0 :         m_pImpl->m_bHyperMode = sal_False;
     156                 :          0 :         aFont.SetUnderline(UNDERLINE_NONE);
     157         [ #  # ]:          0 :         SetPointer( POINTER_ARROW );
     158                 :          0 :         SetControlFont( aFont);
     159                 :          0 :         SetTextColor( aColor);
     160                 :          0 :     }
     161                 :            : 
     162                 :          0 :     void HyperLabel::MouseButtonDown( const MouseEvent& )
     163                 :            :     {
     164 [ #  # ][ #  # ]:          0 :         if ( m_pImpl->m_bHyperMode && m_pImpl->bInteractive )
     165                 :            :         {
     166                 :          0 :             maClickHdl.Call( this );
     167                 :            :         }
     168                 :          0 :     }
     169                 :            : 
     170                 :          0 :     void HyperLabel::GetFocus()
     171                 :            :     {
     172 [ #  # ][ #  # ]:          0 :         if ( IsEnabled() && m_pImpl->bInteractive )
                 [ #  # ]
     173                 :            :         {
     174                 :          0 :             Point aPoint(0,0);
     175 [ #  # ][ #  # ]:          0 :             Rectangle rRect(aPoint, Size( m_pImpl->m_aMinSize.Width(), GetSizePixel().Height() ) );
     176         [ #  # ]:          0 :             ShowFocus( rRect );
     177                 :            :         }
     178                 :          0 :     }
     179                 :            : 
     180                 :          0 :     void HyperLabel::LoseFocus()
     181                 :            :     {
     182                 :          0 :         HideFocus();
     183                 :          0 :     }
     184                 :            : 
     185                 :          0 :     HyperLabel::~HyperLabel( )
     186                 :            :     {
     187                 :          0 :         delete m_pImpl;
     188         [ #  # ]:          0 :     }
     189                 :            : 
     190                 :          0 :     void HyperLabel::SetInteractive( sal_Bool _bInteractive )
     191                 :            :     {
     192 [ #  # ][ #  # ]:          0 :         m_pImpl->bInteractive = ( _bInteractive && IsEnabled() );
     193                 :          0 :     }
     194                 :            : 
     195                 :          0 :     sal_Int16 HyperLabel::GetID() const
     196                 :            :     {
     197                 :          0 :         return m_pImpl->ID;
     198                 :            :     }
     199                 :            : 
     200                 :          0 :     sal_Int32 HyperLabel::GetIndex() const
     201                 :            :     {
     202                 :          0 :         return m_pImpl->Index;
     203                 :            :     }
     204                 :            : 
     205                 :          0 :     void HyperLabel::SetID( sal_Int16 _ID )
     206                 :            :     {
     207                 :          0 :         m_pImpl->ID = _ID;
     208                 :          0 :     }
     209                 :            : 
     210                 :          0 :     void HyperLabel::SetIndex( sal_Int32 _Index )
     211                 :            :     {
     212                 :          0 :         m_pImpl->Index = _Index;
     213                 :          0 :     }
     214                 :            : 
     215                 :          0 :     void HyperLabel::SetLabel( const ::rtl::OUString& _rText )
     216                 :            :     {
     217         [ #  # ]:          0 :         SetText(_rText);
     218                 :          0 :     }
     219                 :            : 
     220                 :            : 
     221                 :            :     //------------------------------------------------------------------------------
     222                 :          0 :     void HyperLabel::DataChanged( const DataChangedEvent& rDCEvt )
     223                 :            :     {
     224                 :          0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     225                 :          0 :         FixedText::DataChanged( rDCEvt );
     226 [ #  # ][ #  #  :          0 :         if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
             #  #  #  # ]
     227                 :          0 :             ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
     228                 :          0 :             ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
     229                 :            :         {
     230                 :          0 :             const Color& rGBColor = GetControlBackground();
     231         [ #  # ]:          0 :             if (rGBColor == COL_TRANSPARENT)
     232                 :          0 :                 SetTextColor( rStyleSettings.GetFieldTextColor( ) );
     233                 :            :             else
     234                 :            :             {
     235                 :          0 :                 SetControlBackground(rStyleSettings.GetHighlightColor());
     236                 :          0 :                 SetTextColor( rStyleSettings.GetHighlightTextColor( ) );
     237                 :            :             }
     238                 :          0 :             Invalidate();
     239                 :            :         }
     240                 :          0 :     }
     241                 :            : 
     242                 :            : //.........................................................................
     243                 :            : }   // namespace svt
     244                 :            : //.........................................................................
     245                 :            : 
     246                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10