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