1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svtools.hxx" 30 31 #define _SV_PRGSBAR_CXX 32 33 #include <tools/debug.hxx> 34 #include <vcl/status.hxx> 35 #include <svtools/prgsbar.hxx> 36 37 // ======================================================================= 38 39 #define PROGRESSBAR_OFFSET 3 40 #define PROGRESSBAR_WIN_OFFSET 2 41 42 // ======================================================================= 43 44 void ProgressBar::ImplInit() 45 { 46 mnPercent = 0; 47 mbCalcNew = sal_True; 48 49 ImplInitSettings( sal_True, sal_True, sal_True ); 50 } 51 52 static WinBits clearProgressBarBorder( Window* pParent, WinBits nOrgStyle ) 53 { 54 WinBits nOutStyle = nOrgStyle; 55 if( pParent && (nOrgStyle & WB_BORDER) != 0 ) 56 { 57 if( pParent->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) ) 58 nOutStyle &= WB_BORDER; 59 } 60 return nOutStyle; 61 } 62 63 // ----------------------------------------------------------------------- 64 65 ProgressBar::ProgressBar( Window* pParent, WinBits nWinStyle ) : 66 Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) ) 67 { 68 SetOutputSizePixel( Size( 150, 20 ) ); 69 ImplInit(); 70 } 71 72 // ----------------------------------------------------------------------- 73 74 ProgressBar::ProgressBar( Window* pParent, const ResId& rResId ) : 75 Window( pParent, rResId ) 76 { 77 ImplInit(); 78 } 79 80 // ----------------------------------------------------------------------- 81 82 ProgressBar::~ProgressBar() 83 { 84 } 85 86 // ----------------------------------------------------------------------- 87 88 void ProgressBar::ImplInitSettings( sal_Bool bFont, 89 sal_Bool bForeground, sal_Bool bBackground ) 90 { 91 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 92 93 /* !!! Derzeit unterstuetzen wir keine Textausgaben 94 if ( bFont ) 95 { 96 Font aFont; 97 aFont = rStyleSettings.GetAppFont(); 98 if ( IsControlFont() ) 99 aFont.Merge( GetControlFont() ); 100 SetZoomedPointFont( aFont ); 101 } 102 */ 103 104 if ( bBackground ) 105 { 106 if( !IsControlBackground() && 107 IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) ) 108 { 109 if( (GetStyle() & WB_BORDER) ) 110 SetBorderStyle( WINDOW_BORDER_REMOVEBORDER ); 111 EnableChildTransparentMode( sal_True ); 112 SetPaintTransparent( sal_True ); 113 SetBackground(); 114 SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 115 } 116 else 117 { 118 Color aColor; 119 if ( IsControlBackground() ) 120 aColor = GetControlBackground(); 121 else 122 aColor = rStyleSettings.GetFaceColor(); 123 SetBackground( aColor ); 124 } 125 } 126 127 if ( bForeground || bFont ) 128 { 129 Color aColor = rStyleSettings.GetHighlightColor(); 130 if ( IsControlForeground() ) 131 aColor = GetControlForeground(); 132 if ( aColor.IsRGBEqual( GetBackground().GetColor() ) ) 133 { 134 if ( aColor.GetLuminance() > 100 ) 135 aColor.DecreaseLuminance( 64 ); 136 else 137 aColor.IncreaseLuminance( 64 ); 138 } 139 SetLineColor(); 140 SetFillColor( aColor ); 141 /* !!! Derzeit unterstuetzen wir keine Textausgaben 142 SetTextColor( aColor ); 143 SetTextFillColor(); 144 */ 145 } 146 } 147 148 // ----------------------------------------------------------------------- 149 150 void ProgressBar::ImplDrawProgress( sal_uInt16 nOldPerc, sal_uInt16 nNewPerc ) 151 { 152 if ( mbCalcNew ) 153 { 154 mbCalcNew = sal_False; 155 156 Size aSize = GetOutputSizePixel(); 157 mnPrgsHeight = aSize.Height()-(PROGRESSBAR_WIN_OFFSET*2); 158 mnPrgsWidth = (mnPrgsHeight*2)/3; 159 maPos.Y() = PROGRESSBAR_WIN_OFFSET; 160 long nMaxWidth = (aSize.Width()-(PROGRESSBAR_WIN_OFFSET*2)+PROGRESSBAR_OFFSET); 161 sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET)); 162 if ( nMaxCount <= 1 ) 163 nMaxCount = 1; 164 else 165 { 166 while ( ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET)) > nMaxWidth ) 167 nMaxCount--; 168 } 169 mnPercentCount = 10000/nMaxCount; 170 nMaxWidth = ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET))-PROGRESSBAR_OFFSET; 171 maPos.X() = (aSize.Width()-nMaxWidth)/2; 172 } 173 174 ::DrawProgress( this, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight, 175 nOldPerc*100, nNewPerc*100, mnPercentCount, 176 Rectangle( Point(), GetSizePixel() ) ); 177 } 178 179 // ----------------------------------------------------------------------- 180 181 void ProgressBar::Paint( const Rectangle& ) 182 { 183 ImplDrawProgress( 0, mnPercent ); 184 } 185 186 // ----------------------------------------------------------------------- 187 188 void ProgressBar::Resize() 189 { 190 mbCalcNew = sal_True; 191 if ( IsReallyVisible() ) 192 Invalidate(); 193 } 194 195 // ----------------------------------------------------------------------- 196 197 void ProgressBar::SetValue( sal_uInt16 nNewPercent ) 198 { 199 DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" ); 200 201 if ( nNewPercent < mnPercent ) 202 { 203 mbCalcNew = sal_True; 204 mnPercent = nNewPercent; 205 if ( IsReallyVisible() ) 206 { 207 Invalidate(); 208 Update(); 209 } 210 } 211 else 212 { 213 ImplDrawProgress( mnPercent, nNewPercent ); 214 mnPercent = nNewPercent; 215 } 216 } 217 218 // ----------------------------------------------------------------------- 219 220 void ProgressBar::StateChanged( StateChangedType nType ) 221 { 222 /* !!! Derzeit unterstuetzen wir keine Textausgaben 223 if ( (nType == STATE_CHANGE_ZOOM) || 224 (nType == STATE_CHANGE_CONTROLFONT) ) 225 { 226 ImplInitSettings( sal_True, sal_False, sal_False ); 227 Invalidate(); 228 } 229 else 230 */ 231 if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 232 { 233 ImplInitSettings( sal_False, sal_True, sal_False ); 234 Invalidate(); 235 } 236 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 237 { 238 ImplInitSettings( sal_False, sal_False, sal_True ); 239 Invalidate(); 240 } 241 242 Window::StateChanged( nType ); 243 } 244 245 // ----------------------------------------------------------------------- 246 247 void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt ) 248 { 249 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 250 (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 251 { 252 ImplInitSettings( sal_True, sal_True, sal_True ); 253 Invalidate(); 254 } 255 256 Window::DataChanged( rDCEvt ); 257 } 258 259