bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / control / prgsbar.cxx
blob6b7a7007c5993f3e517c4213c3ff68a8bb29fd5f
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 mnPrgsWidth = 0;
34 mnPrgsHeight = 0;
35 mnPercent = 0;
36 mnPercentCount = 0;
37 mbCalcNew = true;
39 ImplInitSettings( true, true, true );
42 static WinBits clearProgressBarBorder( vcl::Window const * pParent, WinBits nOrgStyle )
44 WinBits nOutStyle = nOrgStyle;
45 if( pParent && (nOrgStyle & WB_BORDER) != 0 )
47 if( pParent->IsNativeControlSupported( ControlType::Progress, ControlPart::Entire ) )
48 nOutStyle &= WB_BORDER;
50 return nOutStyle;
53 Size ProgressBar::GetOptimalSize() const
55 return Size(150, 20);
58 ProgressBar::ProgressBar( vcl::Window* pParent, WinBits nWinStyle ) :
59 Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
61 SetOutputSizePixel( GetOptimalSize() );
62 ImplInit();
65 void ProgressBar::ImplInitSettings( bool bFont,
66 bool bForeground, bool bBackground )
68 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
70 /* FIXME: !!! We do not support text output at the moment
71 if ( bFont )
72 ApplyControlFont(*this, rStyleSettings.GetAppFont());
75 if ( bBackground )
77 if( !IsControlBackground() &&
78 IsNativeControlSupported( ControlType::Progress, ControlPart::Entire ) )
80 if( GetStyle() & WB_BORDER )
81 SetBorderStyle( WindowBorderStyle::REMOVEBORDER );
82 EnableChildTransparentMode();
83 SetPaintTransparent( true );
84 SetBackground();
85 SetParentClipMode( ParentClipMode::NoClip );
87 else
89 Color aColor;
90 if ( IsControlBackground() )
91 aColor = GetControlBackground();
92 else
93 aColor = rStyleSettings.GetFaceColor();
94 SetBackground( aColor );
98 if ( !(bForeground || bFont) )
99 return;
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 GetOutDev()->SetLineColor();
112 GetOutDev()->SetFillColor( aColor );
113 /* FIXME: !!! We do not support text output at the moment
114 SetTextColor( aColor );
115 SetTextFillColor();
119 void ProgressBar::ImplDrawProgress(vcl::RenderContext& rRenderContext, sal_uInt16 nNewPerc)
121 if (mbCalcNew)
123 mbCalcNew = false;
125 Size aSize(GetOutputSizePixel());
126 mnPrgsHeight = aSize.Height() - (PROGRESSBAR_WIN_OFFSET * 2);
127 mnPrgsWidth = (mnPrgsHeight * 2) / 3;
128 maPos.setY( PROGRESSBAR_WIN_OFFSET );
129 tools::Long nMaxWidth = aSize.Width() - (PROGRESSBAR_WIN_OFFSET * 2) + PROGRESSBAR_OFFSET;
130 sal_uInt16 nMaxCount = static_cast<sal_uInt16>(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
131 if (nMaxCount <= 1)
133 nMaxCount = 1;
135 else
137 while (((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) > nMaxWidth)
139 nMaxCount--;
142 mnPercentCount = 10000 / nMaxCount;
143 nMaxWidth = ((10000 / (10000 / nMaxCount)) * (mnPrgsWidth + PROGRESSBAR_OFFSET)) - PROGRESSBAR_OFFSET;
144 maPos.setX( (aSize.Width() - nMaxWidth) / 2 );
147 ::DrawProgress(this, rRenderContext, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
148 /*nPercent1=*/0, nNewPerc * 100, mnPercentCount,
149 tools::Rectangle(Point(), GetSizePixel()));
152 void ProgressBar::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
154 ImplDrawProgress(rRenderContext, mnPercent);
157 void ProgressBar::Resize()
159 mbCalcNew = true;
160 if ( IsReallyVisible() )
161 Invalidate();
164 void ProgressBar::SetValue( sal_uInt16 nNewPercent )
166 SAL_WARN_IF( nNewPercent > 100, "vcl", "StatusBar::SetProgressValue(): nPercent > 100" );
168 if ( nNewPercent < mnPercent )
170 mbCalcNew = true;
171 mnPercent = nNewPercent;
172 if ( IsReallyVisible() )
174 Invalidate();
175 PaintImmediately();
178 else if ( mnPercent != nNewPercent )
180 mnPercent = nNewPercent;
181 Invalidate();
183 // Make sure the progressbar is actually painted even if the caller is busy with its task,
184 // so the main loop would not be invoked.
185 Idle aIdle("ProgressBar::SetValue aIdle");
186 aIdle.SetPriority(TaskPriority::POST_PAINT);
187 aIdle.Start();
188 while (aIdle.IsActive() && !Application::IsQuit())
190 Application::Yield();
195 void ProgressBar::StateChanged( StateChangedType nType )
197 /* FIXME: !!! We do not support text output at the moment
198 if ( (nType == StateChangedType::Zoom) ||
199 (nType == StateChangedType::ControlFont) )
201 ImplInitSettings( true, false, false );
202 Invalidate();
204 else
206 if ( nType == StateChangedType::ControlForeground )
208 ImplInitSettings( false, true, false );
209 Invalidate();
211 else if ( nType == StateChangedType::ControlBackground )
213 ImplInitSettings( false, false, true );
214 Invalidate();
217 Window::StateChanged( nType );
220 void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
222 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
223 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
225 ImplInitSettings( true, true, true );
226 Invalidate();
229 Window::DataChanged( rDCEvt );
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */