bump product version to 4.1.6.2
[LibreOffice.git] / vcl / source / control / prgsbar.cxx
blob000d8212c6b7859740590745a5eef3d115fc893d
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 <tools/debug.hxx>
21 #include <vcl/status.hxx>
22 #include <vcl/prgsbar.hxx>
24 #define PROGRESSBAR_OFFSET 3
25 #define PROGRESSBAR_WIN_OFFSET 2
27 void ProgressBar::ImplInit()
29 mnPercent = 0;
30 mbCalcNew = sal_True;
32 ImplInitSettings( sal_True, sal_True, sal_True );
35 static WinBits clearProgressBarBorder( Window* pParent, WinBits nOrgStyle )
37 WinBits nOutStyle = nOrgStyle;
38 if( pParent && (nOrgStyle & WB_BORDER) != 0 )
40 if( pParent->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
41 nOutStyle &= WB_BORDER;
43 return nOutStyle;
46 ProgressBar::ProgressBar( Window* pParent, WinBits nWinStyle ) :
47 Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
49 SetOutputSizePixel( Size( 150, 20 ) );
50 ImplInit();
53 ProgressBar::ProgressBar( Window* pParent, const ResId& rResId ) :
54 Window( pParent, rResId )
56 ImplInit();
59 ProgressBar::~ProgressBar()
63 void ProgressBar::ImplInitSettings( sal_Bool bFont,
64 sal_Bool bForeground, sal_Bool bBackground )
66 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
68 /* FIXME: !!! We do not support text output at the moment
69 if ( bFont )
71 Font aFont;
72 aFont = rStyleSettings.GetAppFont();
73 if ( IsControlFont() )
74 aFont.Merge( GetControlFont() );
75 SetZoomedPointFont( aFont );
79 if ( bBackground )
81 if( !IsControlBackground() &&
82 IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
84 if( (GetStyle() & WB_BORDER) )
85 SetBorderStyle( WINDOW_BORDER_REMOVEBORDER );
86 EnableChildTransparentMode( sal_True );
87 SetPaintTransparent( sal_True );
88 SetBackground();
89 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
91 else
93 Color aColor;
94 if ( IsControlBackground() )
95 aColor = GetControlBackground();
96 else
97 aColor = rStyleSettings.GetFaceColor();
98 SetBackground( aColor );
102 if ( bForeground || bFont )
104 Color aColor = rStyleSettings.GetHighlightColor();
105 if ( IsControlForeground() )
106 aColor = GetControlForeground();
107 if ( aColor.IsRGBEqual( GetBackground().GetColor() ) )
109 if ( aColor.GetLuminance() > 100 )
110 aColor.DecreaseLuminance( 64 );
111 else
112 aColor.IncreaseLuminance( 64 );
114 SetLineColor();
115 SetFillColor( aColor );
116 /* FIXME: !!! We do not support text output at the moment
117 SetTextColor( aColor );
118 SetTextFillColor();
124 void ProgressBar::ImplDrawProgress( sal_uInt16 nOldPerc, sal_uInt16 nNewPerc )
126 if ( mbCalcNew )
128 mbCalcNew = sal_False;
130 Size aSize = GetOutputSizePixel();
131 mnPrgsHeight = aSize.Height()-(PROGRESSBAR_WIN_OFFSET*2);
132 mnPrgsWidth = (mnPrgsHeight*2)/3;
133 maPos.Y() = PROGRESSBAR_WIN_OFFSET;
134 long nMaxWidth = (aSize.Width()-(PROGRESSBAR_WIN_OFFSET*2)+PROGRESSBAR_OFFSET);
135 sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
136 if ( nMaxCount <= 1 )
137 nMaxCount = 1;
138 else
140 while ( ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET)) > nMaxWidth )
141 nMaxCount--;
143 mnPercentCount = 10000/nMaxCount;
144 nMaxWidth = ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET))-PROGRESSBAR_OFFSET;
145 maPos.X() = (aSize.Width()-nMaxWidth)/2;
148 ::DrawProgress( this, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
149 nOldPerc*100, nNewPerc*100, mnPercentCount,
150 Rectangle( Point(), GetSizePixel() ) );
153 void ProgressBar::Paint( const Rectangle& )
155 ImplDrawProgress( 0, mnPercent );
159 void ProgressBar::Resize()
161 mbCalcNew = sal_True;
162 if ( IsReallyVisible() )
163 Invalidate();
166 void ProgressBar::SetValue( sal_uInt16 nNewPercent )
168 DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
170 if ( nNewPercent < mnPercent )
172 mbCalcNew = sal_True;
173 mnPercent = nNewPercent;
174 if ( IsReallyVisible() )
176 Invalidate();
177 Update();
180 else
182 ImplDrawProgress( mnPercent, nNewPercent );
183 mnPercent = nNewPercent;
187 void ProgressBar::StateChanged( StateChangedType nType )
189 /* FIXME: !!! We do not support text output at the moment
190 if ( (nType == STATE_CHANGE_ZOOM) ||
191 (nType == STATE_CHANGE_CONTROLFONT) )
193 ImplInitSettings( sal_True, sal_False, sal_False );
194 Invalidate();
196 else
198 if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
200 ImplInitSettings( sal_False, sal_True, sal_False );
201 Invalidate();
203 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
205 ImplInitSettings( sal_False, sal_False, sal_True );
206 Invalidate();
209 Window::StateChanged( nType );
212 void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
214 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
215 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
217 ImplInitSettings( sal_True, sal_True, sal_True );
218 Invalidate();
221 Window::DataChanged( rDCEvt );
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */