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()
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
;
53 Size
ProgressBar::GetOptimalSize() const
58 ProgressBar::ProgressBar( vcl::Window
* pParent
, WinBits nWinStyle
) :
59 Window( pParent
, clearProgressBarBorder( pParent
, nWinStyle
) )
61 SetOutputSizePixel( GetOptimalSize() );
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
72 ApplyControlFont(*this, rStyleSettings.GetAppFont());
77 if( !IsControlBackground() &&
78 IsNativeControlSupported( ControlType::Progress
, ControlPart::Entire
) )
80 if( GetStyle() & WB_BORDER
)
81 SetBorderStyle( WindowBorderStyle::REMOVEBORDER
);
82 EnableChildTransparentMode();
83 SetPaintTransparent( true );
85 SetParentClipMode( ParentClipMode::NoClip
);
90 if ( IsControlBackground() )
91 aColor
= GetControlBackground();
93 aColor
= rStyleSettings
.GetFaceColor();
94 SetBackground( aColor
);
98 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 );
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 );
119 void ProgressBar::ImplDrawProgress(vcl::RenderContext
& rRenderContext
, sal_uInt16 nNewPerc
)
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
));
137 while (((10000 / (10000 / nMaxCount
)) * (mnPrgsWidth
+ PROGRESSBAR_OFFSET
)) > nMaxWidth
)
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()
160 if ( IsReallyVisible() )
164 void ProgressBar::SetValue( sal_uInt16 nNewPercent
)
166 SAL_WARN_IF( nNewPercent
> 100, "vcl", "StatusBar::SetProgressValue(): nPercent > 100" );
168 if ( nNewPercent
< mnPercent
)
171 mnPercent
= nNewPercent
;
172 if ( IsReallyVisible() )
178 else if ( mnPercent
!= nNewPercent
)
180 mnPercent
= nNewPercent
;
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
);
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 );
206 if ( nType
== StateChangedType::ControlForeground
)
208 ImplInitSettings( false, true, false );
211 else if ( nType
== StateChangedType::ControlBackground
)
213 ImplInitSettings( false, false, true );
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 );
229 Window::DataChanged( rDCEvt
);
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */