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

Generated by: LCOV version 1.11