1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: prgsbar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _SV_PRGSBAR_CXX
36 #ifndef _TOOLS_DEBUGS_HXX
37 #include <tools/debug.hxx>
39 #ifndef _VCL_STATUS_HXX
40 #include <vcl/status.hxx>
42 #include <prgsbar.hxx>
44 // =======================================================================
46 #define PROGRESSBAR_OFFSET 3
47 #define PROGRESSBAR_WIN_OFFSET 2
49 // =======================================================================
51 void ProgressBar::ImplInit()
56 ImplInitSettings( TRUE
, TRUE
, TRUE
);
59 static WinBits
clearProgressBarBorder( Window
* pParent
, WinBits nOrgStyle
)
61 WinBits nOutStyle
= nOrgStyle
;
62 if( pParent
&& (nOrgStyle
& WB_BORDER
) != 0 )
64 if( pParent
->IsNativeControlSupported( CTRL_PROGRESS
, PART_ENTIRE_CONTROL
) )
65 nOutStyle
&= WB_BORDER
;
70 // -----------------------------------------------------------------------
72 ProgressBar::ProgressBar( Window
* pParent
, WinBits nWinStyle
) :
73 Window( pParent
, clearProgressBarBorder( pParent
, nWinStyle
) )
75 SetOutputSizePixel( Size( 150, 20 ) );
79 // -----------------------------------------------------------------------
81 ProgressBar::ProgressBar( Window
* pParent
, const ResId
& rResId
) :
82 Window( pParent
, rResId
)
87 // -----------------------------------------------------------------------
89 ProgressBar::~ProgressBar()
93 // -----------------------------------------------------------------------
95 void ProgressBar::ImplInitSettings( BOOL bFont
,
96 BOOL bForeground
, BOOL bBackground
)
98 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
100 /* !!! Derzeit unterstuetzen wir keine Textausgaben
104 aFont = rStyleSettings.GetAppFont();
105 if ( IsControlFont() )
106 aFont.Merge( GetControlFont() );
107 SetZoomedPointFont( aFont );
113 if( !IsControlBackground() &&
114 IsNativeControlSupported( CTRL_PROGRESS
, PART_ENTIRE_CONTROL
) )
116 if( (GetStyle() & WB_BORDER
) )
117 SetBorderStyle( WINDOW_BORDER_REMOVEBORDER
);
118 EnableChildTransparentMode( TRUE
);
119 SetPaintTransparent( TRUE
);
121 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
126 if ( IsControlBackground() )
127 aColor
= GetControlBackground();
129 aColor
= rStyleSettings
.GetFaceColor();
130 SetBackground( aColor
);
134 if ( bForeground
|| bFont
)
136 Color aColor
= rStyleSettings
.GetHighlightColor();
137 if ( IsControlForeground() )
138 aColor
= GetControlForeground();
139 if ( aColor
.IsRGBEqual( GetBackground().GetColor() ) )
141 if ( aColor
.GetLuminance() > 100 )
142 aColor
.DecreaseLuminance( 64 );
144 aColor
.IncreaseLuminance( 64 );
147 SetFillColor( aColor
);
148 /* !!! Derzeit unterstuetzen wir keine Textausgaben
149 SetTextColor( aColor );
155 // -----------------------------------------------------------------------
157 void ProgressBar::ImplDrawProgress( USHORT nOldPerc
, USHORT nNewPerc
)
163 Size aSize
= GetOutputSizePixel();
164 mnPrgsHeight
= aSize
.Height()-(PROGRESSBAR_WIN_OFFSET
*2);
165 mnPrgsWidth
= (mnPrgsHeight
*2)/3;
166 maPos
.Y() = PROGRESSBAR_WIN_OFFSET
;
167 long nMaxWidth
= (aSize
.Width()-(PROGRESSBAR_WIN_OFFSET
*2)+PROGRESSBAR_OFFSET
);
168 USHORT nMaxCount
= (USHORT
)(nMaxWidth
/ (mnPrgsWidth
+PROGRESSBAR_OFFSET
));
169 if ( nMaxCount
<= 1 )
173 while ( ((10000/(10000/nMaxCount
))*(mnPrgsWidth
+PROGRESSBAR_OFFSET
)) > nMaxWidth
)
176 mnPercentCount
= 10000/nMaxCount
;
177 nMaxWidth
= ((10000/(10000/nMaxCount
))*(mnPrgsWidth
+PROGRESSBAR_OFFSET
))-PROGRESSBAR_OFFSET
;
178 maPos
.X() = (aSize
.Width()-nMaxWidth
)/2;
181 ::DrawProgress( this, maPos
, PROGRESSBAR_OFFSET
, mnPrgsWidth
, mnPrgsHeight
,
182 nOldPerc
*100, nNewPerc
*100, mnPercentCount
,
183 Rectangle( Point(), GetSizePixel() ) );
186 // -----------------------------------------------------------------------
188 void ProgressBar::Paint( const Rectangle
& )
190 ImplDrawProgress( 0, mnPercent
);
193 // -----------------------------------------------------------------------
195 void ProgressBar::Resize()
198 if ( IsReallyVisible() )
202 // -----------------------------------------------------------------------
204 void ProgressBar::SetValue( USHORT nNewPercent
)
206 DBG_ASSERTWARNING( nNewPercent
<= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
208 if ( nNewPercent
< mnPercent
)
211 mnPercent
= nNewPercent
;
212 if ( IsReallyVisible() )
220 ImplDrawProgress( mnPercent
, nNewPercent
);
221 mnPercent
= nNewPercent
;
225 // -----------------------------------------------------------------------
227 void ProgressBar::StateChanged( StateChangedType nType
)
229 /* !!! Derzeit unterstuetzen wir keine Textausgaben
230 if ( (nType == STATE_CHANGE_ZOOM) ||
231 (nType == STATE_CHANGE_CONTROLFONT) )
233 ImplInitSettings( TRUE, FALSE, FALSE );
238 if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
240 ImplInitSettings( FALSE
, TRUE
, FALSE
);
243 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
245 ImplInitSettings( FALSE
, FALSE
, TRUE
);
249 Window::StateChanged( nType
);
252 // -----------------------------------------------------------------------
254 void ProgressBar::DataChanged( const DataChangedEvent
& rDCEvt
)
256 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
257 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
259 ImplInitSettings( TRUE
, TRUE
, TRUE
);
263 Window::DataChanged( rDCEvt
);