nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / control / prgsbar.cxx
blobe861d66bcb03f08e71d7a5cd843cdc871b293116
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 <vcl/event.hxx>
21 #include <vcl/status.hxx>
22 #include <vcl/toolkit/prgsbar.hxx>
23 #include <vcl/settings.hxx>
24 #include <sal/log.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/idle.hxx>
28 #define PROGRESSBAR_OFFSET 3
29 #define PROGRESSBAR_WIN_OFFSET 2
31 void ProgressBar::ImplInit()
33 mnPercent = 0;
34 mbCalcNew = true;
36 ImplInitSettings( true, true, true );
39 static WinBits clearProgressBarBorder( vcl::Window const * pParent, WinBits nOrgStyle )
41 WinBits nOutStyle = nOrgStyle;
42 if( pParent && (nOrgStyle & WB_BORDER) != 0 )
44 if( pParent->IsNativeControlSupported( ControlType::Progress, ControlPart::Entire ) )
45 nOutStyle &= WB_BORDER;
47 return nOutStyle;
50 Size ProgressBar::GetOptimalSize() const
52 return Size(150, 20);
55 ProgressBar::ProgressBar( vcl::Window* pParent, WinBits nWinStyle ) :
56 Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
58 SetOutputSizePixel( GetOptimalSize() );
59 ImplInit();
62 void ProgressBar::ImplInitSettings( bool bFont,
63 bool bForeground, bool bBackground )
65 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
67 /* FIXME: !!! We do not support text output at the moment
68 if ( bFont )
69 ApplyControlFont(*this, rStyleSettings.GetAppFont());
72 if ( bBackground )
74 if( !IsControlBackground() &&
75 IsNativeControlSupported( ControlType::Progress, ControlPart::Entire ) )
77 if( GetStyle() & WB_BORDER )
78 SetBorderStyle( WindowBorderStyle::REMOVEBORDER );
79 EnableChildTransparentMode();
80 SetPaintTransparent( true );
81 SetBackground();
82 SetParentClipMode( ParentClipMode::NoClip );
84 else
86 Color aColor;
87 if ( IsControlBackground() )
88 aColor = GetControlBackground();
89 else
90 aColor = rStyleSettings.GetFaceColor();
91 SetBackground( aColor );
95 if ( !(bForeground || bFont) )
96 return;
98 Color aColor = rStyleSettings.GetHighlightColor();
99 if ( IsControlForeground() )
100 aColor = GetControlForeground();
101 if ( aColor.IsRGBEqual( GetBackground().GetColor() ) )
103 if ( aColor.GetLuminance() > 100 )
104 aColor.DecreaseLuminance( 64 );
105 else
106 aColor.IncreaseLuminance( 64 );
108 SetLineColor();
109 SetFillColor( aColor );
110 /* FIXME: !!! We do not support text output at the moment
111 SetTextColor( aColor );
112 SetTextFillColor();
116 void ProgressBar::ImplDrawProgress(vcl::RenderContext& rRenderContext, sal_uInt16 nNewPerc)
118 if (mbCalcNew)
120 mbCalcNew = false;
122 Size aSize(GetOutputSizePixel());
123 mnPrgsHeight = aSize.Height() - (PROGRESSBAR_WIN_OFFSET * 2);
124 mnPrgsWidth = (mnPrgsHeight * 2) / 3;
125 maPos.setY( PROGRESSBAR_WIN_OFFSET );
126 tools::Long nMaxWidth = aSize.Width() - (PROGRESSBAR_WIN_OFFSET * 2) + PROGRESSBAR_OFFSET;
127 sal_uInt16 nMaxCount = static_cast<sal_uInt16>(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
128 if (nMaxCount <= 1)
130 nMaxCount = 1;
132 else
134 while (((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) > nMaxWidth)
136 nMaxCount--;
139 mnPercentCount = 10000 / nMaxCount;
140 nMaxWidth = ((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) - PROGRESSBAR_OFFSET;
141 maPos.setX( (aSize.Width() - nMaxWidth) / 2 );
144 ::DrawProgress(this, rRenderContext, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
145 /*nPercent1=*/0, nNewPerc * 100, mnPercentCount,
146 tools::Rectangle(Point(), GetSizePixel()));
149 void ProgressBar::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
151 ImplDrawProgress(rRenderContext, mnPercent);
154 void ProgressBar::Resize()
156 mbCalcNew = true;
157 if ( IsReallyVisible() )
158 Invalidate();
161 void ProgressBar::SetValue( sal_uInt16 nNewPercent )
163 SAL_WARN_IF( nNewPercent > 100, "vcl", "StatusBar::SetProgressValue(): nPercent > 100" );
165 if ( nNewPercent < mnPercent )
167 mbCalcNew = true;
168 mnPercent = nNewPercent;
169 if ( IsReallyVisible() )
171 Invalidate();
172 PaintImmediately();
175 else if ( mnPercent != nNewPercent )
177 mnPercent = nNewPercent;
178 Invalidate();
180 // Make sure the progressbar is actually painted even if the caller is busy with its task,
181 // so the main loop would not be invoked.
182 Idle aIdle("ProgressBar::SetValue aIdle");
183 aIdle.SetPriority(TaskPriority::POST_PAINT);
184 aIdle.Start();
185 while (aIdle.IsActive())
187 Application::Yield();
192 void ProgressBar::StateChanged( StateChangedType nType )
194 /* FIXME: !!! We do not support text output at the moment
195 if ( (nType == StateChangedType::Zoom) ||
196 (nType == StateChangedType::ControlFont) )
198 ImplInitSettings( true, false, false );
199 Invalidate();
201 else
203 if ( nType == StateChangedType::ControlForeground )
205 ImplInitSettings( false, true, false );
206 Invalidate();
208 else if ( nType == StateChangedType::ControlBackground )
210 ImplInitSettings( false, false, true );
211 Invalidate();
214 Window::StateChanged( nType );
217 void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
219 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
220 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
222 ImplInitSettings( true, true, true );
223 Invalidate();
226 Window::DataChanged( rDCEvt );
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */