xref: /trunk/main/svtools/source/control/prgsbar.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _SV_PRGSBAR_CXX
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/debug.hxx>
30cdf0e10cSrcweir #include <vcl/status.hxx>
31cdf0e10cSrcweir #include <svtools/prgsbar.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // =======================================================================
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #define PROGRESSBAR_OFFSET          3
36cdf0e10cSrcweir #define PROGRESSBAR_WIN_OFFSET      2
37cdf0e10cSrcweir 
38cdf0e10cSrcweir // =======================================================================
39cdf0e10cSrcweir 
ImplInit()40cdf0e10cSrcweir void ProgressBar::ImplInit()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     mnPercent   = 0;
43cdf0e10cSrcweir     mbCalcNew   = sal_True;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     ImplInitSettings( sal_True, sal_True, sal_True );
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
clearProgressBarBorder(Window * pParent,WinBits nOrgStyle)48cdf0e10cSrcweir static WinBits clearProgressBarBorder( Window* pParent, WinBits nOrgStyle )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     WinBits nOutStyle = nOrgStyle;
51cdf0e10cSrcweir     if( pParent && (nOrgStyle & WB_BORDER) != 0 )
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         if( pParent->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
54cdf0e10cSrcweir             nOutStyle &= WB_BORDER;
55cdf0e10cSrcweir     }
56cdf0e10cSrcweir     return nOutStyle;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir // -----------------------------------------------------------------------
60cdf0e10cSrcweir 
ProgressBar(Window * pParent,WinBits nWinStyle)61cdf0e10cSrcweir ProgressBar::ProgressBar( Window* pParent, WinBits nWinStyle ) :
62cdf0e10cSrcweir     Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     SetOutputSizePixel( Size( 150, 20 ) );
65cdf0e10cSrcweir     ImplInit();
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir // -----------------------------------------------------------------------
69cdf0e10cSrcweir 
ProgressBar(Window * pParent,const ResId & rResId)70cdf0e10cSrcweir ProgressBar::ProgressBar( Window* pParent, const ResId& rResId ) :
71cdf0e10cSrcweir     Window( pParent, rResId )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     ImplInit();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // -----------------------------------------------------------------------
77cdf0e10cSrcweir 
~ProgressBar()78cdf0e10cSrcweir ProgressBar::~ProgressBar()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // -----------------------------------------------------------------------
83cdf0e10cSrcweir 
ImplInitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)84cdf0e10cSrcweir void ProgressBar::ImplInitSettings( sal_Bool bFont,
85cdf0e10cSrcweir                                     sal_Bool bForeground, sal_Bool bBackground )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir /* !!! Derzeit unterstuetzen wir keine Textausgaben
90cdf0e10cSrcweir     if ( bFont )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         Font aFont;
93cdf0e10cSrcweir         aFont = rStyleSettings.GetAppFont();
94cdf0e10cSrcweir         if ( IsControlFont() )
95cdf0e10cSrcweir             aFont.Merge( GetControlFont() );
96cdf0e10cSrcweir         SetZoomedPointFont( aFont );
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir */
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     if ( bBackground )
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         if( !IsControlBackground() &&
103cdf0e10cSrcweir             IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             if( (GetStyle() & WB_BORDER) )
106cdf0e10cSrcweir                 SetBorderStyle( WINDOW_BORDER_REMOVEBORDER );
107cdf0e10cSrcweir             EnableChildTransparentMode( sal_True );
108cdf0e10cSrcweir             SetPaintTransparent( sal_True );
109cdf0e10cSrcweir             SetBackground();
110cdf0e10cSrcweir             SetParentClipMode( PARENTCLIPMODE_NOCLIP );
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir         else
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             Color aColor;
115cdf0e10cSrcweir             if ( IsControlBackground() )
116cdf0e10cSrcweir                 aColor = GetControlBackground();
117cdf0e10cSrcweir             else
118cdf0e10cSrcweir                 aColor = rStyleSettings.GetFaceColor();
119cdf0e10cSrcweir             SetBackground( aColor );
120cdf0e10cSrcweir         }
121cdf0e10cSrcweir     }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     if ( bForeground || bFont )
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         Color aColor = rStyleSettings.GetHighlightColor();
126cdf0e10cSrcweir         if ( IsControlForeground() )
127cdf0e10cSrcweir             aColor = GetControlForeground();
128cdf0e10cSrcweir         if ( aColor.IsRGBEqual( GetBackground().GetColor() ) )
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir             if ( aColor.GetLuminance() > 100 )
131cdf0e10cSrcweir                 aColor.DecreaseLuminance( 64 );
132cdf0e10cSrcweir             else
133cdf0e10cSrcweir                 aColor.IncreaseLuminance( 64 );
134cdf0e10cSrcweir         }
135cdf0e10cSrcweir         SetLineColor();
136cdf0e10cSrcweir         SetFillColor( aColor );
137cdf0e10cSrcweir /* !!! Derzeit unterstuetzen wir keine Textausgaben
138cdf0e10cSrcweir         SetTextColor( aColor );
139cdf0e10cSrcweir         SetTextFillColor();
140cdf0e10cSrcweir */
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // -----------------------------------------------------------------------
145cdf0e10cSrcweir 
ImplDrawProgress(sal_uInt16 nOldPerc,sal_uInt16 nNewPerc)146cdf0e10cSrcweir void ProgressBar::ImplDrawProgress( sal_uInt16 nOldPerc, sal_uInt16 nNewPerc )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     if ( mbCalcNew )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         mbCalcNew = sal_False;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         Size aSize = GetOutputSizePixel();
153cdf0e10cSrcweir         mnPrgsHeight = aSize.Height()-(PROGRESSBAR_WIN_OFFSET*2);
154cdf0e10cSrcweir         mnPrgsWidth = (mnPrgsHeight*2)/3;
155cdf0e10cSrcweir         maPos.Y() = PROGRESSBAR_WIN_OFFSET;
156cdf0e10cSrcweir         long nMaxWidth = (aSize.Width()-(PROGRESSBAR_WIN_OFFSET*2)+PROGRESSBAR_OFFSET);
157cdf0e10cSrcweir         sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
158cdf0e10cSrcweir         if ( nMaxCount <= 1 )
159cdf0e10cSrcweir             nMaxCount = 1;
160cdf0e10cSrcweir         else
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir             while ( ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET)) > nMaxWidth )
163cdf0e10cSrcweir                 nMaxCount--;
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir         mnPercentCount = 10000/nMaxCount;
166cdf0e10cSrcweir         nMaxWidth = ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET))-PROGRESSBAR_OFFSET;
167cdf0e10cSrcweir         maPos.X() = (aSize.Width()-nMaxWidth)/2;
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     ::DrawProgress( this, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
171cdf0e10cSrcweir                     nOldPerc*100, nNewPerc*100, mnPercentCount,
172cdf0e10cSrcweir                     Rectangle( Point(), GetSizePixel() ) );
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir // -----------------------------------------------------------------------
176cdf0e10cSrcweir 
Paint(const Rectangle &)177cdf0e10cSrcweir void ProgressBar::Paint( const Rectangle& )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     ImplDrawProgress( 0, mnPercent );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir // -----------------------------------------------------------------------
183cdf0e10cSrcweir 
Resize()184cdf0e10cSrcweir void ProgressBar::Resize()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir     mbCalcNew = sal_True;
187cdf0e10cSrcweir     if ( IsReallyVisible() )
188cdf0e10cSrcweir         Invalidate();
189cdf0e10cSrcweir }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir // -----------------------------------------------------------------------
192cdf0e10cSrcweir 
SetValue(sal_uInt16 nNewPercent)193cdf0e10cSrcweir void ProgressBar::SetValue( sal_uInt16 nNewPercent )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     if ( nNewPercent < mnPercent )
198cdf0e10cSrcweir     {
199cdf0e10cSrcweir         mbCalcNew = sal_True;
200cdf0e10cSrcweir         mnPercent = nNewPercent;
201cdf0e10cSrcweir         if ( IsReallyVisible() )
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             Invalidate();
204cdf0e10cSrcweir             Update();
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir     else
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         ImplDrawProgress( mnPercent, nNewPercent );
210cdf0e10cSrcweir         mnPercent = nNewPercent;
211cdf0e10cSrcweir     }
212cdf0e10cSrcweir }
213cdf0e10cSrcweir 
214cdf0e10cSrcweir // -----------------------------------------------------------------------
215cdf0e10cSrcweir 
StateChanged(StateChangedType nType)216cdf0e10cSrcweir void ProgressBar::StateChanged( StateChangedType nType )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir /* !!! Derzeit unterstuetzen wir keine Textausgaben
219cdf0e10cSrcweir     if ( (nType == STATE_CHANGE_ZOOM) ||
220cdf0e10cSrcweir          (nType == STATE_CHANGE_CONTROLFONT) )
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_False, sal_False );
223cdf0e10cSrcweir         Invalidate();
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir     else
226cdf0e10cSrcweir */
227cdf0e10cSrcweir     if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_True, sal_False );
230cdf0e10cSrcweir         Invalidate();
231cdf0e10cSrcweir     }
232cdf0e10cSrcweir     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         ImplInitSettings( sal_False, sal_False, sal_True );
235cdf0e10cSrcweir         Invalidate();
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     Window::StateChanged( nType );
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir // -----------------------------------------------------------------------
242cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)243cdf0e10cSrcweir void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
246cdf0e10cSrcweir          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         ImplInitSettings( sal_True, sal_True, sal_True );
249cdf0e10cSrcweir         Invalidate();
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
253cdf0e10cSrcweir }
254