build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / control / prgsbar.cxx
blob67619d8d85a7334523f0926d8e78fc2a2576204d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/debug.hxx>
21 #include <vcl/status.hxx>
22 #include <vcl/prgsbar.hxx>
23 #include <vcl/settings.hxx>
25 #define PROGRESSBAR_OFFSET 3
26 #define PROGRESSBAR_WIN_OFFSET 2
28 void ProgressBar::ImplInit()
30 mnPercent = 0;
31 mnPreviousPercent = 0;
32 mbCalcNew = true;
34 ImplInitSettings( true, true, true );
37 static WinBits clearProgressBarBorder( vcl::Window* pParent, WinBits nOrgStyle )
39 WinBits nOutStyle = nOrgStyle;
40 if( pParent && (nOrgStyle & WB_BORDER) != 0 )
42 if( pParent->IsNativeControlSupported( ControlType::Progress, ControlPart::Entire ) )
43 nOutStyle &= WB_BORDER;
45 return nOutStyle;
48 Size ProgressBar::GetOptimalSize() const
50 return Size(150, 20);
53 ProgressBar::ProgressBar( vcl::Window* pParent, WinBits nWinStyle ) :
54 Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
56 SetOutputSizePixel( GetOptimalSize() );
57 ImplInit();
60 void ProgressBar::ImplInitSettings( bool bFont,
61 bool bForeground, bool bBackground )
63 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
65 /* FIXME: !!! We do not support text output at the moment
66 if ( bFont )
68 Font aFont;
69 aFont = rStyleSettings.GetAppFont();
70 if ( IsControlFont() )
71 aFont.Merge( GetControlFont() );
72 SetZoomedPointFont( aFont );
76 if ( bBackground )
78 if( !IsControlBackground() &&
79 IsNativeControlSupported( ControlType::Progress, ControlPart::Entire ) )
81 if( (GetStyle() & WB_BORDER) )
82 SetBorderStyle( WindowBorderStyle::REMOVEBORDER );
83 EnableChildTransparentMode();
84 SetPaintTransparent( true );
85 SetBackground();
86 SetParentClipMode( ParentClipMode::NoClip );
88 else
90 Color aColor;
91 if ( IsControlBackground() )
92 aColor = GetControlBackground();
93 else
94 aColor = rStyleSettings.GetFaceColor();
95 SetBackground( aColor );
99 if ( bForeground || bFont )
101 Color aColor = rStyleSettings.GetHighlightColor();
102 if ( IsControlForeground() )
103 aColor = GetControlForeground();
104 if ( aColor.IsRGBEqual( GetBackground().GetColor() ) )
106 if ( aColor.GetLuminance() > 100 )
107 aColor.DecreaseLuminance( 64 );
108 else
109 aColor.IncreaseLuminance( 64 );
111 SetLineColor();
112 SetFillColor( aColor );
113 /* FIXME: !!! We do not support text output at the moment
114 SetTextColor( aColor );
115 SetTextFillColor();
120 void ProgressBar::ImplDrawProgress(vcl::RenderContext& rRenderContext, sal_uInt16 nOldPerc, sal_uInt16 nNewPerc)
122 if (mbCalcNew)
124 mbCalcNew = false;
126 Size aSize(GetOutputSizePixel());
127 mnPrgsHeight = aSize.Height() - (PROGRESSBAR_WIN_OFFSET * 2);
128 mnPrgsWidth = (mnPrgsHeight * 2) / 3;
129 maPos.Y() = PROGRESSBAR_WIN_OFFSET;
130 long nMaxWidth = (aSize.Width() - (PROGRESSBAR_WIN_OFFSET * 2) + PROGRESSBAR_OFFSET);
131 sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
132 if (nMaxCount <= 1)
134 nMaxCount = 1;
136 else
138 while (((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) > nMaxWidth)
140 nMaxCount--;
143 mnPercentCount = 10000 / nMaxCount;
144 nMaxWidth = ((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) - PROGRESSBAR_OFFSET;
145 maPos.X() = (aSize.Width() - nMaxWidth) / 2;
148 ::DrawProgress(this, rRenderContext, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
149 nOldPerc * 100, nNewPerc * 100, mnPercentCount,
150 Rectangle(Point(), GetSizePixel()));
153 void ProgressBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
155 ImplDrawProgress(rRenderContext, mnPreviousPercent, mnPercent);
158 void ProgressBar::Resize()
160 mbCalcNew = true;
161 if ( IsReallyVisible() )
162 Invalidate();
165 void ProgressBar::SetValue( sal_uInt16 nNewPercent )
167 SAL_WARN_IF( nNewPercent > 100, "vcl", "StatusBar::SetProgressValue(): nPercent > 100" );
169 if ( nNewPercent < mnPercent )
171 mbCalcNew = true;
172 mnPercent = nNewPercent;
173 mnPreviousPercent = 0;
174 if ( IsReallyVisible() )
176 Invalidate();
177 Update();
180 else if ( mnPercent != nNewPercent )
182 mnPreviousPercent = mnPercent;
183 mnPercent = nNewPercent;
184 Invalidate();
188 void ProgressBar::StateChanged( StateChangedType nType )
190 /* FIXME: !!! We do not support text output at the moment
191 if ( (nType == StateChangedType::Zoom) ||
192 (nType == StateChangedType::ControlFont) )
194 ImplInitSettings( true, false, false );
195 Invalidate();
197 else
199 if ( nType == StateChangedType::ControlForeground )
201 ImplInitSettings( false, true, false );
202 Invalidate();
204 else if ( nType == StateChangedType::ControlBackground )
206 ImplInitSettings( false, false, true );
207 Invalidate();
210 Window::StateChanged( nType );
213 void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
215 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
216 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
218 ImplInitSettings( true, true, true );
219 Invalidate();
222 Window::DataChanged( rDCEvt );
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */