LCOV - code coverage report
Current view: top level - vcl/source/control - prgsbar.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 99 1.0 %
Date: 2014-11-03 Functions: 2 15 13.3 %
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/debug.hxx>
      21             : #include <vcl/status.hxx>
      22             : #include <vcl/prgsbar.hxx>
      23             : #include <vcl/settings.hxx>
      24             : 
      25             : #define PROGRESSBAR_OFFSET          3
      26             : #define PROGRESSBAR_WIN_OFFSET      2
      27             : 
      28           0 : void ProgressBar::ImplInit()
      29             : {
      30           0 :     mnPercent   = 0;
      31           0 :     mbCalcNew   = true;
      32             : 
      33           0 :     ImplInitSettings( true, true, true );
      34           0 : }
      35             : 
      36           0 : static WinBits clearProgressBarBorder( vcl::Window* pParent, WinBits nOrgStyle )
      37             : {
      38           0 :     WinBits nOutStyle = nOrgStyle;
      39           0 :     if( pParent && (nOrgStyle & WB_BORDER) != 0 )
      40             :     {
      41           0 :         if( pParent->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
      42           0 :             nOutStyle &= WB_BORDER;
      43             :     }
      44           0 :     return nOutStyle;
      45             : }
      46             : 
      47           0 : Size ProgressBar::GetOptimalSize() const
      48             : {
      49           0 :     return Size(150, 20);
      50             : }
      51             : 
      52           0 : ProgressBar::ProgressBar( vcl::Window* pParent, WinBits nWinStyle ) :
      53           0 :     Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
      54             : {
      55           0 :     SetOutputSizePixel( GetOptimalSize() );
      56           0 :     ImplInit();
      57           0 : }
      58             : 
      59           0 : ProgressBar::~ProgressBar()
      60             : {
      61           0 : }
      62             : 
      63           0 : void ProgressBar::ImplInitSettings( bool bFont,
      64             :                                     bool bForeground, bool bBackground )
      65             : {
      66           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
      67             : 
      68             : /* FIXME: !!! We do not support text output at the moment
      69             :     if ( bFont )
      70             :     {
      71             :         Font aFont;
      72             :         aFont = rStyleSettings.GetAppFont();
      73             :         if ( IsControlFont() )
      74             :             aFont.Merge( GetControlFont() );
      75             :         SetZoomedPointFont( aFont );
      76             :     }
      77             : */
      78             : 
      79           0 :     if ( bBackground )
      80             :     {
      81           0 :         if( !IsControlBackground() &&
      82           0 :             IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
      83             :         {
      84           0 :             if( (GetStyle() & WB_BORDER) )
      85           0 :                 SetBorderStyle( WindowBorderStyle::REMOVEBORDER );
      86           0 :             EnableChildTransparentMode( true );
      87           0 :             SetPaintTransparent( true );
      88           0 :             SetBackground();
      89           0 :             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
      90             :         }
      91             :         else
      92             :         {
      93           0 :             Color aColor;
      94           0 :             if ( IsControlBackground() )
      95           0 :                 aColor = GetControlBackground();
      96             :             else
      97           0 :                 aColor = rStyleSettings.GetFaceColor();
      98           0 :             SetBackground( aColor );
      99             :         }
     100             :     }
     101             : 
     102           0 :     if ( bForeground || bFont )
     103             :     {
     104           0 :         Color aColor = rStyleSettings.GetHighlightColor();
     105           0 :         if ( IsControlForeground() )
     106           0 :             aColor = GetControlForeground();
     107           0 :         if ( aColor.IsRGBEqual( GetBackground().GetColor() ) )
     108             :         {
     109           0 :             if ( aColor.GetLuminance() > 100 )
     110           0 :                 aColor.DecreaseLuminance( 64 );
     111             :             else
     112           0 :                 aColor.IncreaseLuminance( 64 );
     113             :         }
     114           0 :         SetLineColor();
     115           0 :         SetFillColor( aColor );
     116             : /* FIXME: !!! We do not support text output at the moment
     117             :         SetTextColor( aColor );
     118             :         SetTextFillColor();
     119             : */
     120             :     }
     121           0 : }
     122             : 
     123           0 : void ProgressBar::ImplDrawProgress( sal_uInt16 nOldPerc, sal_uInt16 nNewPerc )
     124             : {
     125           0 :     if ( mbCalcNew )
     126             :     {
     127           0 :         mbCalcNew = false;
     128             : 
     129           0 :         Size aSize = GetOutputSizePixel();
     130           0 :         mnPrgsHeight = aSize.Height()-(PROGRESSBAR_WIN_OFFSET*2);
     131           0 :         mnPrgsWidth = (mnPrgsHeight*2)/3;
     132           0 :         maPos.Y() = PROGRESSBAR_WIN_OFFSET;
     133           0 :         long nMaxWidth = (aSize.Width()-(PROGRESSBAR_WIN_OFFSET*2)+PROGRESSBAR_OFFSET);
     134           0 :         sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
     135           0 :         if ( nMaxCount <= 1 )
     136           0 :             nMaxCount = 1;
     137             :         else
     138             :         {
     139           0 :             while ( ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET)) > nMaxWidth )
     140           0 :                 nMaxCount--;
     141             :         }
     142           0 :         mnPercentCount = 10000/nMaxCount;
     143           0 :         nMaxWidth = ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET))-PROGRESSBAR_OFFSET;
     144           0 :         maPos.X() = (aSize.Width()-nMaxWidth)/2;
     145             :     }
     146             : 
     147             :     ::DrawProgress( this, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
     148             :                     nOldPerc*100, nNewPerc*100, mnPercentCount,
     149           0 :                     Rectangle( Point(), GetSizePixel() ) );
     150           0 : }
     151             : 
     152           0 : void ProgressBar::Paint( const Rectangle& )
     153             : {
     154           0 :     ImplDrawProgress( 0, mnPercent );
     155           0 : }
     156             : 
     157           0 : void ProgressBar::Resize()
     158             : {
     159           0 :     mbCalcNew = true;
     160           0 :     if ( IsReallyVisible() )
     161           0 :         Invalidate();
     162           0 : }
     163             : 
     164           0 : void ProgressBar::SetValue( sal_uInt16 nNewPercent )
     165             : {
     166             :     DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
     167             : 
     168           0 :     if ( nNewPercent < mnPercent )
     169             :     {
     170           0 :         mbCalcNew = true;
     171           0 :         mnPercent = nNewPercent;
     172           0 :         if ( IsReallyVisible() )
     173             :         {
     174           0 :             Invalidate();
     175           0 :             Update();
     176             :         }
     177             :     }
     178             :     else
     179             :     {
     180           0 :         ImplDrawProgress( mnPercent, nNewPercent );
     181           0 :         mnPercent = nNewPercent;
     182             :     }
     183           0 : }
     184             : 
     185           0 : void ProgressBar::StateChanged( StateChangedType nType )
     186             : {
     187             : /* FIXME: !!! We do not support text output at the moment
     188             :     if ( (nType == StateChangedType::ZOOM) ||
     189             :          (nType == StateChangedType::CONTROLFONT) )
     190             :     {
     191             :         ImplInitSettings( true, false, false );
     192             :         Invalidate();
     193             :     }
     194             :     else
     195             : */
     196           0 :     if ( nType == StateChangedType::CONTROLFOREGROUND )
     197             :     {
     198           0 :         ImplInitSettings( false, true, false );
     199           0 :         Invalidate();
     200             :     }
     201           0 :     else if ( nType == StateChangedType::CONTROLBACKGROUND )
     202             :     {
     203           0 :         ImplInitSettings( false, false, true );
     204           0 :         Invalidate();
     205             :     }
     206             : 
     207           0 :     Window::StateChanged( nType );
     208           0 : }
     209             : 
     210           0 : void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
     211             : {
     212           0 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     213           0 :          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     214             :     {
     215           0 :         ImplInitSettings( true, true, true );
     216           0 :         Invalidate();
     217             :     }
     218             : 
     219           0 :     Window::DataChanged( rDCEvt );
     220        1233 : }
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10