1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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()
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
;
50 Size
ProgressBar::GetOptimalSize() const
55 ProgressBar::ProgressBar( vcl::Window
* pParent
, WinBits nWinStyle
) :
56 Window( pParent
, clearProgressBarBorder( pParent
, nWinStyle
) )
58 SetOutputSizePixel( GetOptimalSize() );
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
69 ApplyControlFont(*this, rStyleSettings.GetAppFont());
74 if( !IsControlBackground() &&
75 IsNativeControlSupported( ControlType::Progress
, ControlPart::Entire
) )
77 if( GetStyle() & WB_BORDER
)
78 SetBorderStyle( WindowBorderStyle::REMOVEBORDER
);
79 EnableChildTransparentMode();
80 SetPaintTransparent( true );
82 SetParentClipMode( ParentClipMode::NoClip
);
87 if ( IsControlBackground() )
88 aColor
= GetControlBackground();
90 aColor
= rStyleSettings
.GetFaceColor();
91 SetBackground( aColor
);
95 if ( !(bForeground
|| bFont
) )
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 );
106 aColor
.IncreaseLuminance( 64 );
109 SetFillColor( aColor
);
110 /* FIXME: !!! We do not support text output at the moment
111 SetTextColor( aColor );
116 void ProgressBar::ImplDrawProgress(vcl::RenderContext
& rRenderContext
, sal_uInt16 nNewPerc
)
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
));
134 while (((10000 / (10000 / nMaxCount
)) * (mnPrgsWidth
+ PROGRESSBAR_OFFSET
)) > nMaxWidth
)
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()
157 if ( IsReallyVisible() )
161 void ProgressBar::SetValue( sal_uInt16 nNewPercent
)
163 SAL_WARN_IF( nNewPercent
> 100, "vcl", "StatusBar::SetProgressValue(): nPercent > 100" );
165 if ( nNewPercent
< mnPercent
)
168 mnPercent
= nNewPercent
;
169 if ( IsReallyVisible() )
175 else if ( mnPercent
!= nNewPercent
)
177 mnPercent
= nNewPercent
;
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
);
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 );
203 if ( nType
== StateChangedType::ControlForeground
)
205 ImplInitSettings( false, true, false );
208 else if ( nType
== StateChangedType::ControlBackground
)
210 ImplInitSettings( false, false, true );
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 );
226 Window::DataChanged( rDCEvt
);
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */