Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #define _SV_PRGSBAR_CXX
22 : :
23 : : #include <tools/debug.hxx>
24 : : #include <vcl/status.hxx>
25 : : #include <svtools/prgsbar.hxx>
26 : :
27 : : // =======================================================================
28 : :
29 : : #define PROGRESSBAR_OFFSET 3
30 : : #define PROGRESSBAR_WIN_OFFSET 2
31 : :
32 : : // =======================================================================
33 : :
34 : 0 : void ProgressBar::ImplInit()
35 : : {
36 : 0 : mnPercent = 0;
37 : 0 : mbCalcNew = sal_True;
38 : :
39 : 0 : ImplInitSettings( sal_True, sal_True, sal_True );
40 : 0 : }
41 : :
42 : 0 : static WinBits clearProgressBarBorder( Window* pParent, WinBits nOrgStyle )
43 : : {
44 : 0 : WinBits nOutStyle = nOrgStyle;
45 [ # # ][ # # ]: 0 : if( pParent && (nOrgStyle & WB_BORDER) != 0 )
46 : : {
47 [ # # ]: 0 : if( pParent->IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
48 : 0 : nOutStyle &= WB_BORDER;
49 : : }
50 : 0 : return nOutStyle;
51 : : }
52 : :
53 : : // -----------------------------------------------------------------------
54 : :
55 : 0 : ProgressBar::ProgressBar( Window* pParent, WinBits nWinStyle ) :
56 : 0 : Window( pParent, clearProgressBarBorder( pParent, nWinStyle ) )
57 : : {
58 [ # # ]: 0 : SetOutputSizePixel( Size( 150, 20 ) );
59 [ # # ]: 0 : ImplInit();
60 : 0 : }
61 : :
62 : : // -----------------------------------------------------------------------
63 : :
64 : 0 : ProgressBar::ProgressBar( Window* pParent, const ResId& rResId ) :
65 : 0 : Window( pParent, rResId )
66 : : {
67 [ # # ]: 0 : ImplInit();
68 : 0 : }
69 : :
70 : : // -----------------------------------------------------------------------
71 : :
72 : 0 : ProgressBar::~ProgressBar()
73 : : {
74 [ # # ]: 0 : }
75 : :
76 : : // -----------------------------------------------------------------------
77 : :
78 : 0 : void ProgressBar::ImplInitSettings( sal_Bool bFont,
79 : : sal_Bool bForeground, sal_Bool bBackground )
80 : : {
81 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
82 : :
83 : : /* !!! Derzeit unterstuetzen wir keine Textausgaben
84 : : if ( bFont )
85 : : {
86 : : Font aFont;
87 : : aFont = rStyleSettings.GetAppFont();
88 : : if ( IsControlFont() )
89 : : aFont.Merge( GetControlFont() );
90 : : SetZoomedPointFont( aFont );
91 : : }
92 : : */
93 : :
94 [ # # ]: 0 : if ( bBackground )
95 : : {
96 [ # # # # ]: 0 : if( !IsControlBackground() &&
[ # # ]
97 : 0 : IsNativeControlSupported( CTRL_PROGRESS, PART_ENTIRE_CONTROL ) )
98 : : {
99 [ # # ]: 0 : if( (GetStyle() & WB_BORDER) )
100 : 0 : SetBorderStyle( WINDOW_BORDER_REMOVEBORDER );
101 : 0 : EnableChildTransparentMode( sal_True );
102 : 0 : SetPaintTransparent( sal_True );
103 : 0 : SetBackground();
104 : 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
105 : : }
106 : : else
107 : : {
108 : 0 : Color aColor;
109 [ # # ][ # # ]: 0 : if ( IsControlBackground() )
110 [ # # ]: 0 : aColor = GetControlBackground();
111 : : else
112 : 0 : aColor = rStyleSettings.GetFaceColor();
113 [ # # ][ # # ]: 0 : SetBackground( aColor );
[ # # ]
114 : : }
115 : : }
116 : :
117 [ # # ][ # # ]: 0 : if ( bForeground || bFont )
118 : : {
119 : 0 : Color aColor = rStyleSettings.GetHighlightColor();
120 [ # # ][ # # ]: 0 : if ( IsControlForeground() )
121 [ # # ]: 0 : aColor = GetControlForeground();
122 [ # # ][ # # ]: 0 : if ( aColor.IsRGBEqual( GetBackground().GetColor() ) )
[ # # ]
123 : : {
124 [ # # ][ # # ]: 0 : if ( aColor.GetLuminance() > 100 )
125 [ # # ]: 0 : aColor.DecreaseLuminance( 64 );
126 : : else
127 [ # # ]: 0 : aColor.IncreaseLuminance( 64 );
128 : : }
129 [ # # ]: 0 : SetLineColor();
130 [ # # ]: 0 : SetFillColor( aColor );
131 : : /* !!! Derzeit unterstuetzen wir keine Textausgaben
132 : : SetTextColor( aColor );
133 : : SetTextFillColor();
134 : : */
135 : : }
136 : 0 : }
137 : :
138 : : // -----------------------------------------------------------------------
139 : :
140 : 0 : void ProgressBar::ImplDrawProgress( sal_uInt16 nOldPerc, sal_uInt16 nNewPerc )
141 : : {
142 [ # # ]: 0 : if ( mbCalcNew )
143 : : {
144 : 0 : mbCalcNew = sal_False;
145 : :
146 : 0 : Size aSize = GetOutputSizePixel();
147 : 0 : mnPrgsHeight = aSize.Height()-(PROGRESSBAR_WIN_OFFSET*2);
148 : 0 : mnPrgsWidth = (mnPrgsHeight*2)/3;
149 : 0 : maPos.Y() = PROGRESSBAR_WIN_OFFSET;
150 : 0 : long nMaxWidth = (aSize.Width()-(PROGRESSBAR_WIN_OFFSET*2)+PROGRESSBAR_OFFSET);
151 : 0 : sal_uInt16 nMaxCount = (sal_uInt16)(nMaxWidth / (mnPrgsWidth+PROGRESSBAR_OFFSET));
152 [ # # ]: 0 : if ( nMaxCount <= 1 )
153 : 0 : nMaxCount = 1;
154 : : else
155 : : {
156 [ # # ]: 0 : while ( ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET)) > nMaxWidth )
157 : 0 : nMaxCount--;
158 : : }
159 : 0 : mnPercentCount = 10000/nMaxCount;
160 : 0 : nMaxWidth = ((10000/(10000/nMaxCount))*(mnPrgsWidth+PROGRESSBAR_OFFSET))-PROGRESSBAR_OFFSET;
161 : 0 : maPos.X() = (aSize.Width()-nMaxWidth)/2;
162 : : }
163 : :
164 : : ::DrawProgress( this, maPos, PROGRESSBAR_OFFSET, mnPrgsWidth, mnPrgsHeight,
165 : : nOldPerc*100, nNewPerc*100, mnPercentCount,
166 [ # # ][ # # ]: 0 : Rectangle( Point(), GetSizePixel() ) );
167 : 0 : }
168 : :
169 : : // -----------------------------------------------------------------------
170 : :
171 : 0 : void ProgressBar::Paint( const Rectangle& )
172 : : {
173 : 0 : ImplDrawProgress( 0, mnPercent );
174 : 0 : }
175 : :
176 : : // -----------------------------------------------------------------------
177 : :
178 : 0 : void ProgressBar::Resize()
179 : : {
180 : 0 : mbCalcNew = sal_True;
181 [ # # ]: 0 : if ( IsReallyVisible() )
182 : 0 : Invalidate();
183 : 0 : }
184 : :
185 : : // -----------------------------------------------------------------------
186 : :
187 : 0 : void ProgressBar::SetValue( sal_uInt16 nNewPercent )
188 : : {
189 : : DBG_ASSERTWARNING( nNewPercent <= 100, "StatusBar::SetProgressValue(): nPercent > 100" );
190 : :
191 [ # # ]: 0 : if ( nNewPercent < mnPercent )
192 : : {
193 : 0 : mbCalcNew = sal_True;
194 : 0 : mnPercent = nNewPercent;
195 [ # # ]: 0 : if ( IsReallyVisible() )
196 : : {
197 : 0 : Invalidate();
198 : 0 : Update();
199 : : }
200 : : }
201 : : else
202 : : {
203 : 0 : ImplDrawProgress( mnPercent, nNewPercent );
204 : 0 : mnPercent = nNewPercent;
205 : : }
206 : 0 : }
207 : :
208 : : // -----------------------------------------------------------------------
209 : :
210 : 0 : void ProgressBar::StateChanged( StateChangedType nType )
211 : : {
212 : : /* !!! Derzeit unterstuetzen wir keine Textausgaben
213 : : if ( (nType == STATE_CHANGE_ZOOM) ||
214 : : (nType == STATE_CHANGE_CONTROLFONT) )
215 : : {
216 : : ImplInitSettings( sal_True, sal_False, sal_False );
217 : : Invalidate();
218 : : }
219 : : else
220 : : */
221 [ # # ]: 0 : if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
222 : : {
223 : 0 : ImplInitSettings( sal_False, sal_True, sal_False );
224 : 0 : Invalidate();
225 : : }
226 [ # # ]: 0 : else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
227 : : {
228 : 0 : ImplInitSettings( sal_False, sal_False, sal_True );
229 : 0 : Invalidate();
230 : : }
231 : :
232 : 0 : Window::StateChanged( nType );
233 : 0 : }
234 : :
235 : : // -----------------------------------------------------------------------
236 : :
237 : 0 : void ProgressBar::DataChanged( const DataChangedEvent& rDCEvt )
238 : : {
239 [ # # # # ]: 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
[ # # ]
240 : 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
241 : : {
242 : 0 : ImplInitSettings( sal_True, sal_True, sal_True );
243 : 0 : Invalidate();
244 : : }
245 : :
246 : 0 : Window::DataChanged( rDCEvt );
247 : 0 : }
248 : :
249 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|