LCOV - code coverage report
Current view: top level - vcl/source/control - group.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 102 151 67.5 %
Date: 2012-08-25 Functions: 11 14 78.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 68 180 37.8 %

           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                 :            : 
      30                 :            : #include <tools/rc.h>
      31                 :            : 
      32                 :            : #include <vcl/event.hxx>
      33                 :            : #include <vcl/group.hxx>
      34                 :            : 
      35                 :            : #include <controldata.hxx>
      36                 :            : 
      37                 :            : // =======================================================================
      38                 :            : 
      39                 :            : #define GROUP_BORDER            12
      40                 :            : #define GROUP_TEXT_BORDER       2
      41                 :            : 
      42                 :            : #define GROUP_VIEW_STYLE        (WB_3DLOOK | WB_NOLABEL)
      43                 :            : 
      44                 :            : // =======================================================================
      45                 :            : 
      46                 :         26 : void GroupBox::ImplInit( Window* pParent, WinBits nStyle )
      47                 :            : {
      48                 :         26 :     nStyle = ImplInitStyle( nStyle );
      49                 :         26 :     Control::ImplInit( pParent, nStyle, NULL );
      50                 :         26 :     SetMouseTransparent( sal_True );
      51                 :         26 :     ImplInitSettings( sal_True, sal_True, sal_True );
      52                 :         26 : }
      53                 :            : 
      54                 :            : // -----------------------------------------------------------------------
      55                 :            : 
      56                 :         26 : WinBits GroupBox::ImplInitStyle( WinBits nStyle )
      57                 :            : {
      58         [ +  - ]:         26 :     if ( !(nStyle & WB_NOGROUP) )
      59                 :         26 :         nStyle |= WB_GROUP;
      60                 :         26 :     return nStyle;
      61                 :            : }
      62                 :            : 
      63                 :            : // -----------------------------------------------------------------
      64                 :            : 
      65                 :        455 : const Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
      66                 :            : {
      67                 :        455 :     return _rStyle.GetGroupFont();
      68                 :            : }
      69                 :            : 
      70                 :            : // -----------------------------------------------------------------
      71                 :        455 : const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
      72                 :            : {
      73                 :        455 :     return _rStyle.GetGroupTextColor();
      74                 :            : }
      75                 :            : 
      76                 :            : // -----------------------------------------------------------------------
      77                 :            : 
      78                 :        455 : void GroupBox::ImplInitSettings( sal_Bool bFont,
      79                 :            :                                  sal_Bool bForeground, sal_Bool bBackground )
      80                 :            : {
      81                 :        455 :     Control::ImplInitSettings( bFont, bForeground );
      82                 :            : 
      83         [ +  + ]:        455 :     if ( bBackground )
      84                 :            :     {
      85                 :        236 :         Window* pParent = GetParent();
      86 [ +  - ][ -  +  :        472 :         if ( (pParent->IsChildTransparentModeEnabled() ||
             #  #  +  - ]
      87                 :          0 :               !(pParent->GetStyle() & WB_CLIPCHILDREN) ) &&
      88                 :        236 :              !IsControlBackground() )
      89                 :            :         {
      90                 :        236 :             EnableChildTransparentMode( sal_True );
      91                 :        236 :             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
      92                 :        236 :             SetPaintTransparent( sal_True );
      93                 :        236 :             SetBackground();
      94                 :            :         }
      95                 :            :         else
      96                 :            :         {
      97                 :          0 :             EnableChildTransparentMode( sal_False );
      98                 :          0 :             SetParentClipMode( 0 );
      99                 :          0 :             SetPaintTransparent( sal_False );
     100                 :            : 
     101         [ #  # ]:          0 :             if ( IsControlBackground() )
     102 [ #  # ][ #  # ]:          0 :                 SetBackground( GetControlBackground() );
                 [ #  # ]
     103                 :            :             else
     104                 :          0 :                 SetBackground( pParent->GetBackground() );
     105                 :            :         }
     106                 :            :     }
     107                 :        455 : }
     108                 :            : 
     109                 :            : // -----------------------------------------------------------------------
     110                 :            : 
     111                 :         26 : GroupBox::GroupBox( Window* pParent, WinBits nStyle ) :
     112                 :         26 :     Control( WINDOW_GROUPBOX )
     113                 :            : {
     114         [ +  - ]:         26 :     ImplInit( pParent, nStyle );
     115                 :         26 : }
     116                 :            : 
     117                 :            : // -----------------------------------------------------------------------
     118                 :            : 
     119                 :          0 : GroupBox::GroupBox( Window* pParent, const ResId& rResId ) :
     120                 :          0 :     Control( WINDOW_GROUPBOX )
     121                 :            : {
     122                 :          0 :     rResId.SetRT( RSC_GROUPBOX );
     123         [ #  # ]:          0 :     WinBits nStyle = ImplInitRes( rResId );
     124         [ #  # ]:          0 :     ImplInit( pParent, nStyle );
     125         [ #  # ]:          0 :     ImplLoadRes( rResId );
     126                 :            : 
     127         [ #  # ]:          0 :     if ( !(nStyle & WB_HIDE) )
     128         [ #  # ]:          0 :         Show();
     129                 :          0 : }
     130                 :            : 
     131                 :            : // -----------------------------------------------------------------------
     132                 :            : 
     133                 :        393 : void GroupBox::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
     134                 :            :                          const Point& rPos, const Size& rSize, bool bLayout )
     135                 :            : {
     136                 :            :         OSL_TRACE("GroupBox::ImplDraw Y %d, X %d", rPos.Y(), rPos.X() );
     137                 :            :     long                    nTop;
     138                 :            :     long                    nTextOff;
     139                 :        393 :     const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
     140         [ +  - ]:        393 :     XubString               aText( GetText() );
     141         [ +  - ]:        393 :     Rectangle               aRect( rPos, rSize );
     142                 :        393 :     sal_uInt16                  nTextStyle = TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MNEMONIC;
     143                 :            : 
     144 [ +  - ][ -  + ]:        393 :     if ( GetStyle() & WB_NOLABEL )
     145                 :          0 :         nTextStyle &= ~TEXT_DRAW_MNEMONIC;
     146         [ -  + ]:        393 :     if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC )
     147                 :            :     {
     148         [ #  # ]:          0 :         if ( nTextStyle & TEXT_DRAW_MNEMONIC )
     149                 :            :         {
     150 [ #  # ][ #  # ]:          0 :             aText = GetNonMnemonicString( aText );
                 [ #  # ]
     151                 :          0 :             nTextStyle &= ~TEXT_DRAW_MNEMONIC;
     152                 :            :         }
     153                 :            :     }
     154         [ +  - ]:        393 :     if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
     155                 :            :     {
     156 [ +  - ][ +  + ]:        393 :         if ( !IsEnabled() )
     157                 :         98 :             nTextStyle |= TEXT_DRAW_DISABLE;
     158                 :            :     }
     159   [ +  -  -  + ]:        786 :     if ( (nDrawFlags & WINDOW_DRAW_MONO) ||
                 [ -  + ]
     160                 :        393 :          (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
     161                 :            :     {
     162                 :          0 :         nTextStyle |= TEXT_DRAW_MONO;
     163                 :          0 :         nDrawFlags |= WINDOW_DRAW_MONO;
     164                 :            :     }
     165                 :            : 
     166         [ +  + ]:        393 :     if ( !aText.Len() )
     167                 :            :     {
     168                 :        281 :         nTop = rPos.Y();
     169                 :        281 :         nTextOff = 0;
     170                 :            :     }
     171                 :            :     else
     172                 :            :     {
     173                 :        112 :         aRect.Left() += GROUP_BORDER;
     174                 :        112 :         aRect.Right() -= GROUP_BORDER;
     175         [ +  - ]:        112 :         aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
     176                 :        112 :         nTop = rPos.Y();
     177         [ +  - ]:        112 :         nTop += aRect.GetHeight() / 2;
     178                 :        112 :         nTextOff = GROUP_TEXT_BORDER;
     179                 :            :     }
     180                 :            : 
     181         [ +  - ]:        393 :     if( ! bLayout )
     182                 :            :     {
     183         [ -  + ]:        393 :         if ( nDrawFlags & WINDOW_DRAW_MONO )
     184         [ #  # ]:          0 :             pDev->SetLineColor( Color( COL_BLACK ) );
     185                 :            :         else
     186         [ +  - ]:        393 :             pDev->SetLineColor( rStyleSettings.GetShadowColor() );
     187                 :            : 
     188         [ +  + ]:        393 :         if ( !aText.Len() )
     189         [ +  - ]:        281 :             pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
     190                 :            :         else
     191                 :            :         {
     192         [ +  - ]:        112 :             pDev->DrawLine( Point( rPos.X(), nTop ), Point( aRect.Left()-nTextOff, nTop ) );
     193         [ +  - ]:        112 :             pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
     194                 :            :         }
     195         [ +  - ]:        393 :         pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X(), rPos.Y()+rSize.Height()-2 ) );
     196         [ +  - ]:        393 :         pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ) );
     197         [ +  - ]:        393 :         pDev->DrawLine( Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, nTop ) );
     198                 :            : 
     199                 :        393 :         bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType();
     200                 :            :         // if we're drawing onto a printer, spare the 3D effect
     201                 :            :         // #i46986# / 2005-04-13 / frank.schoenheit@sun.com
     202                 :            : 
     203 [ +  - ][ +  - ]:        393 :         if ( !bIsPrinter && !(nDrawFlags & WINDOW_DRAW_MONO) )
     204                 :            :         {
     205         [ +  - ]:        393 :             pDev->SetLineColor( rStyleSettings.GetLightColor() );
     206         [ +  + ]:        393 :             if ( !aText.Len() )
     207         [ +  - ]:        281 :                 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
     208                 :            :             else
     209                 :            :             {
     210         [ +  - ]:        112 :                 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( aRect.Left()-nTextOff, nTop+1 ) );
     211         [ +  - ]:        112 :                 pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
     212                 :            :             }
     213         [ +  - ]:        393 :             pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+1, rPos.Y()+rSize.Height()-3 ) );
     214         [ +  - ]:        393 :             pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ) );
     215         [ +  - ]:        393 :             pDev->DrawLine( Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, nTop ) );
     216                 :            :         }
     217                 :            :     }
     218                 :            : 
     219         [ -  + ]:        393 :     MetricVector* pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL;
     220         [ -  + ]:        393 :     String* pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL;
     221 [ +  - ][ +  - ]:        393 :     DrawControlText( *pDev, aRect, aText, nTextStyle, pVector, pDisplayText );
     222                 :        393 : }
     223                 :            : 
     224                 :            : // -----------------------------------------------------------------------
     225                 :            : 
     226                 :          0 : void GroupBox::FillLayoutData() const
     227                 :            : {
     228         [ #  # ]:          0 :     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
     229         [ #  # ]:          0 :     const_cast<GroupBox*>(this)->   ImplDraw( const_cast<GroupBox*>(this), 0, Point(), GetOutputSizePixel(), true );
     230                 :          0 : }
     231                 :            : 
     232                 :            : // -----------------------------------------------------------------------
     233                 :            : 
     234                 :        393 : void GroupBox::Paint( const Rectangle& )
     235                 :            : {
     236         [ +  - ]:        393 :     ImplDraw( this, 0, Point(), GetOutputSizePixel() );
     237                 :        393 : }
     238                 :            : 
     239                 :            : // -----------------------------------------------------------------------
     240                 :            : 
     241                 :          0 : void GroupBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
     242                 :            :                      sal_uLong nFlags )
     243                 :            : {
     244         [ #  # ]:          0 :     Point       aPos  = pDev->LogicToPixel( rPos );
     245         [ #  # ]:          0 :     Size        aSize = pDev->LogicToPixel( rSize );
     246         [ #  # ]:          0 :     Font        aFont = GetDrawPixelFont( pDev );
     247                 :            : 
     248         [ #  # ]:          0 :     pDev->Push();
     249         [ #  # ]:          0 :     pDev->SetMapMode();
     250         [ #  # ]:          0 :     pDev->SetFont( aFont );
     251         [ #  # ]:          0 :     if ( nFlags & WINDOW_DRAW_MONO )
     252         [ #  # ]:          0 :         pDev->SetTextColor( Color( COL_BLACK ) );
     253                 :            :     else
     254         [ #  # ]:          0 :         pDev->SetTextColor( GetTextColor() );
     255         [ #  # ]:          0 :     pDev->SetTextFillColor();
     256                 :            : 
     257         [ #  # ]:          0 :     ImplDraw( pDev, nFlags, aPos, aSize );
     258 [ #  # ][ #  # ]:          0 :     pDev->Pop();
     259                 :          0 : }
     260                 :            : 
     261                 :            : // -----------------------------------------------------------------------
     262                 :            : 
     263                 :         30 : void GroupBox::Resize()
     264                 :            : {
     265                 :         30 :     Control::Resize();
     266                 :         30 :     Invalidate();
     267                 :         30 : }
     268                 :            : 
     269                 :            : // -----------------------------------------------------------------------
     270                 :            : 
     271                 :       1162 : void GroupBox::StateChanged( StateChangedType nType )
     272                 :            : {
     273                 :       1162 :     Control::StateChanged( nType );
     274                 :            : 
     275 [ +  + ][ -  + ]:       1162 :     if ( (nType == STATE_CHANGE_ENABLE) ||
                 [ +  + ]
     276                 :            :          (nType == STATE_CHANGE_TEXT) ||
     277                 :            :          (nType == STATE_CHANGE_UPDATEMODE) )
     278                 :            :     {
     279         [ +  - ]:        134 :         if ( IsUpdateMode() )
     280                 :         67 :             Invalidate();
     281                 :            :     }
     282         [ -  + ]:       1095 :     else if ( nType == STATE_CHANGE_STYLE )
     283                 :            :     {
     284                 :          0 :         SetStyle( ImplInitStyle( GetStyle() ) );
     285         [ #  # ]:          0 :         if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
     286                 :          0 :              (GetStyle() & GROUP_VIEW_STYLE) )
     287                 :          0 :             Invalidate();
     288                 :            :     }
     289 [ +  + ][ +  + ]:       1095 :     else if ( (nType == STATE_CHANGE_ZOOM)  ||
     290                 :            :               (nType == STATE_CHANGE_CONTROLFONT) )
     291                 :            :     {
     292                 :        219 :         ImplInitSettings( sal_True, sal_False, sal_False );
     293                 :        219 :         Invalidate();
     294                 :            :     }
     295         [ -  + ]:        876 :     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
     296                 :            :     {
     297                 :          0 :         ImplInitSettings( sal_False, sal_True, sal_False );
     298                 :          0 :         Invalidate();
     299                 :            :     }
     300         [ -  + ]:        876 :     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
     301                 :            :     {
     302                 :          0 :         ImplInitSettings( sal_False, sal_False, sal_True );
     303                 :          0 :         Invalidate();
     304                 :            :     }
     305                 :       1162 : }
     306                 :            : 
     307                 :            : // -----------------------------------------------------------------------
     308                 :            : 
     309                 :        210 : void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
     310                 :            : {
     311                 :        210 :     Control::DataChanged( rDCEvt );
     312                 :            : 
     313 [ +  - ][ +  -  :        840 :     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
          +  -  +  -  +  
                      - ]
     314                 :        210 :          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
     315                 :        210 :          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     316                 :        210 :           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
     317                 :            :     {
     318                 :        210 :         ImplInitSettings( sal_True, sal_True, sal_True );
     319                 :        210 :         Invalidate();
     320                 :            :     }
     321                 :        210 : }
     322                 :            : 
     323                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10