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

Generated by: LCOV version 1.10