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 <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()
31 mnPreviousPercent
= 0;
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
;
48 Size
ProgressBar::GetOptimalSize() const
53 ProgressBar::ProgressBar( vcl::Window
* pParent
, WinBits nWinStyle
) :
54 Window( pParent
, clearProgressBarBorder( pParent
, nWinStyle
) )
56 SetOutputSizePixel( GetOptimalSize() );
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
69 aFont = rStyleSettings.GetAppFont();
70 if ( IsControlFont() )
71 aFont.Merge( GetControlFont() );
72 SetZoomedPointFont( aFont );
78 if( !IsControlBackground() &&
79 IsNativeControlSupported( ControlType::Progress
, ControlPart::Entire
) )
81 if( (GetStyle() & WB_BORDER
) )
82 SetBorderStyle( WindowBorderStyle::REMOVEBORDER
);
83 EnableChildTransparentMode();
84 SetPaintTransparent( true );
86 SetParentClipMode( ParentClipMode::NoClip
);
91 if ( IsControlBackground() )
92 aColor
= GetControlBackground();
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 );
109 aColor
.IncreaseLuminance( 64 );
112 SetFillColor( aColor
);
113 /* FIXME: !!! We do not support text output at the moment
114 SetTextColor( aColor );
120 void ProgressBar::ImplDrawProgress(vcl::RenderContext
& rRenderContext
, sal_uInt16 nOldPerc
, sal_uInt16 nNewPerc
)
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
));
138 while (((10000 / (10000 / nMaxCount
)) * (mnPrgsWidth
+ PROGRESSBAR_OFFSET
)) > nMaxWidth
)
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()
161 if ( IsReallyVisible() )
165 void ProgressBar::SetValue( sal_uInt16 nNewPercent
)
167 SAL_WARN_IF( nNewPercent
> 100, "vcl", "StatusBar::SetProgressValue(): nPercent > 100" );
169 if ( nNewPercent
< mnPercent
)
172 mnPercent
= nNewPercent
;
173 mnPreviousPercent
= 0;
174 if ( IsReallyVisible() )
180 else if ( mnPercent
!= nNewPercent
)
182 mnPreviousPercent
= mnPercent
;
183 mnPercent
= nNewPercent
;
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 );
199 if ( nType
== StateChangedType::ControlForeground
)
201 ImplInitSettings( false, true, false );
204 else if ( nType
== StateChangedType::ControlBackground
)
206 ImplInitSettings( false, false, true );
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 );
222 Window::DataChanged( rDCEvt
);
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */