xref: /trunk/main/UnoControls/source/controls/progressbar.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir //____________________________________________________________________________________________________________
28*cdf0e10cSrcweir //  my own includes
29*cdf0e10cSrcweir //____________________________________________________________________________________________________________
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "progressbar.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //____________________________________________________________________________________________________________
34*cdf0e10cSrcweir //  includes of other projects
35*cdf0e10cSrcweir //____________________________________________________________________________________________________________
36*cdf0e10cSrcweir #include <com/sun/star/awt/GradientStyle.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/awt/RasterOperation.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/awt/Gradient.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/awt/XGraphics.hpp>
40*cdf0e10cSrcweir #include <tools/debug.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include <math.h>
44*cdf0e10cSrcweir #include <limits.h>
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir //____________________________________________________________________________________________________________
47*cdf0e10cSrcweir //  includes of my project
48*cdf0e10cSrcweir //____________________________________________________________________________________________________________
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir //____________________________________________________________________________________________________________
51*cdf0e10cSrcweir //  namespace
52*cdf0e10cSrcweir //____________________________________________________________________________________________________________
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using namespace ::cppu                  ;
55*cdf0e10cSrcweir using namespace ::osl                   ;
56*cdf0e10cSrcweir using namespace ::rtl                   ;
57*cdf0e10cSrcweir using namespace ::com::sun::star::uno   ;
58*cdf0e10cSrcweir using namespace ::com::sun::star::lang  ;
59*cdf0e10cSrcweir using namespace ::com::sun::star::awt   ;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir namespace unocontrols{
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //____________________________________________________________________________________________________________
64*cdf0e10cSrcweir //  construct/destruct
65*cdf0e10cSrcweir //____________________________________________________________________________________________________________
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir ProgressBar::ProgressBar( const Reference< XMultiServiceFactory >& xFactory )
68*cdf0e10cSrcweir     : BaseControl           (    xFactory                   )
69*cdf0e10cSrcweir     , m_bHorizontal         (    DEFAULT_HORIZONTAL         )
70*cdf0e10cSrcweir     , m_aBlockSize          (    DEFAULT_BLOCKDIMENSION     )
71*cdf0e10cSrcweir     , m_nForegroundColor    (    DEFAULT_FOREGROUNDCOLOR    )
72*cdf0e10cSrcweir     , m_nBackgroundColor    (    DEFAULT_BACKGROUNDCOLOR    )
73*cdf0e10cSrcweir     , m_nMinRange           (    DEFAULT_MINRANGE           )
74*cdf0e10cSrcweir     , m_nMaxRange           (    DEFAULT_MAXRANGE           )
75*cdf0e10cSrcweir     , m_nBlockValue         (    DEFAULT_BLOCKVALUE         )
76*cdf0e10cSrcweir     , m_nValue              (    DEFAULT_VALUE              )
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir ProgressBar::~ProgressBar()
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir //____________________________________________________________________________________________________________
85*cdf0e10cSrcweir //  XInterface
86*cdf0e10cSrcweir //____________________________________________________________________________________________________________
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir Any SAL_CALL ProgressBar::queryInterface( const Type& rType ) throw( RuntimeException )
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir     // Attention:
91*cdf0e10cSrcweir     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
92*cdf0e10cSrcweir     Any aReturn ;
93*cdf0e10cSrcweir     Reference< XInterface > xDel = BaseControl::impl_getDelegator();
94*cdf0e10cSrcweir     if ( xDel.is() )
95*cdf0e10cSrcweir     {
96*cdf0e10cSrcweir         // If an delegator exist, forward question to his queryInterface.
97*cdf0e10cSrcweir         // Delegator will ask his own queryAggregation!
98*cdf0e10cSrcweir         aReturn = xDel->queryInterface( rType );
99*cdf0e10cSrcweir     }
100*cdf0e10cSrcweir     else
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         // If an delegator unknown, forward question to own queryAggregation.
103*cdf0e10cSrcweir         aReturn = queryAggregation( rType );
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     return aReturn ;
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir //____________________________________________________________________________________________________________
110*cdf0e10cSrcweir //  XInterface
111*cdf0e10cSrcweir //____________________________________________________________________________________________________________
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir void SAL_CALL ProgressBar::acquire() throw()
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     // Attention:
116*cdf0e10cSrcweir     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     // Forward to baseclass
119*cdf0e10cSrcweir     BaseControl::acquire();
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir //____________________________________________________________________________________________________________
123*cdf0e10cSrcweir //  XInterface
124*cdf0e10cSrcweir //____________________________________________________________________________________________________________
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir void SAL_CALL ProgressBar::release() throw()
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     // Attention:
129*cdf0e10cSrcweir     //  Don't use mutex or guard in this method!!! Is a method of XInterface.
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     // Forward to baseclass
132*cdf0e10cSrcweir     BaseControl::release();
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //____________________________________________________________________________________________________________
136*cdf0e10cSrcweir //  XTypeProvider
137*cdf0e10cSrcweir //____________________________________________________________________________________________________________
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir Sequence< Type > SAL_CALL ProgressBar::getTypes() throw( RuntimeException )
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir     // Optimize this method !
142*cdf0e10cSrcweir     // We initialize a static variable only one time. And we don't must use a mutex at every call!
143*cdf0e10cSrcweir     // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
144*cdf0e10cSrcweir     static OTypeCollection* pTypeCollection = NULL ;
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     if ( pTypeCollection == NULL )
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         // Ready for multithreading; get global mutex for first call of this method only! see before
149*cdf0e10cSrcweir         MutexGuard aGuard( Mutex::getGlobalMutex() );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir         // Control these pointer again ... it can be, that another instance will be faster then these!
152*cdf0e10cSrcweir         if ( pTypeCollection == NULL )
153*cdf0e10cSrcweir         {
154*cdf0e10cSrcweir             // Create a static typecollection ...
155*cdf0e10cSrcweir             static OTypeCollection aTypeCollection  (   ::getCppuType(( const Reference< XControlModel  >*)NULL )   ,
156*cdf0e10cSrcweir                                                         ::getCppuType(( const Reference< XProgressBar   >*)NULL )   ,
157*cdf0e10cSrcweir                                                         BaseControl::getTypes()
158*cdf0e10cSrcweir                                                     );
159*cdf0e10cSrcweir             // ... and set his address to static pointer!
160*cdf0e10cSrcweir             pTypeCollection = &aTypeCollection ;
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     return pTypeCollection->getTypes();
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir //____________________________________________________________________________________________________________
168*cdf0e10cSrcweir //  XAggregation
169*cdf0e10cSrcweir //____________________________________________________________________________________________________________
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir Any SAL_CALL ProgressBar::queryAggregation( const Type& aType ) throw( RuntimeException )
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     // Ask for my own supported interfaces ...
174*cdf0e10cSrcweir     // Attention: XTypeProvider and XInterface are supported by OComponentHelper!
175*cdf0e10cSrcweir     Any aReturn ( ::cppu::queryInterface(   aType                                   ,
176*cdf0e10cSrcweir                                             static_cast< XControlModel* > ( this )  ,
177*cdf0e10cSrcweir                                             static_cast< XProgressBar*  > ( this )
178*cdf0e10cSrcweir                                         )
179*cdf0e10cSrcweir                 );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     // If searched interface not supported by this class ...
182*cdf0e10cSrcweir     if ( aReturn.hasValue() == sal_False )
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         // ... ask baseclasses.
185*cdf0e10cSrcweir         aReturn = BaseControl::queryAggregation( aType );
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir     return aReturn ;
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir //____________________________________________________________________________________________________________
192*cdf0e10cSrcweir //  XProgressBar
193*cdf0e10cSrcweir //____________________________________________________________________________________________________________
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir void SAL_CALL ProgressBar::setForegroundColor( sal_Int32 nColor ) throw( RuntimeException )
196*cdf0e10cSrcweir {
197*cdf0e10cSrcweir     // Ready for multithreading
198*cdf0e10cSrcweir     MutexGuard  aGuard (m_aMutex) ;
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     // Safe color for later use.
201*cdf0e10cSrcweir     m_nForegroundColor = nColor ;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     // Repaint control
204*cdf0e10cSrcweir     impl_paint ( 0, 0, impl_getGraphicsPeer() ) ;
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir //____________________________________________________________________________________________________________
208*cdf0e10cSrcweir //  XProgressBar
209*cdf0e10cSrcweir //____________________________________________________________________________________________________________
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir void SAL_CALL ProgressBar::setBackgroundColor ( sal_Int32 nColor ) throw( RuntimeException )
212*cdf0e10cSrcweir {
213*cdf0e10cSrcweir     // Ready for multithreading
214*cdf0e10cSrcweir     MutexGuard  aGuard (m_aMutex) ;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir     // Safe color for later use.
217*cdf0e10cSrcweir     m_nBackgroundColor = nColor ;
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     // Repaint control
220*cdf0e10cSrcweir     impl_paint ( 0, 0, impl_getGraphicsPeer() ) ;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir //____________________________________________________________________________________________________________
224*cdf0e10cSrcweir //  XProgressBar
225*cdf0e10cSrcweir //____________________________________________________________________________________________________________
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir void SAL_CALL ProgressBar::setValue ( sal_Int32 nValue ) throw( RuntimeException )
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     // This method is defined for follow things:
230*cdf0e10cSrcweir     //      1) Values >= _nMinRange
231*cdf0e10cSrcweir     //      2) Values <= _nMaxRange
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     // Ready for multithreading
234*cdf0e10cSrcweir     MutexGuard aGuard (m_aMutex) ;
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     // save impossible cases
237*cdf0e10cSrcweir     // This method is only defined for valid values
238*cdf0e10cSrcweir     DBG_ASSERT ( (( nValue >= m_nMinRange ) && ( nValue <= m_nMaxRange )), "ProgressBar::setValue()\nNot valid value.\n" ) ;
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir     // If new value not valid ... do nothing in release version!
241*cdf0e10cSrcweir     if (
242*cdf0e10cSrcweir         ( nValue >= m_nMinRange ) &&
243*cdf0e10cSrcweir         ( nValue <= m_nMaxRange )
244*cdf0e10cSrcweir        )
245*cdf0e10cSrcweir     {
246*cdf0e10cSrcweir         // New value is ok => save this
247*cdf0e10cSrcweir         m_nValue = nValue ;
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir         // Repaint to display changes
250*cdf0e10cSrcweir         impl_paint ( 0, 0, impl_getGraphicsPeer() ) ;
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir //____________________________________________________________________________________________________________
255*cdf0e10cSrcweir //  XProgressBar
256*cdf0e10cSrcweir //____________________________________________________________________________________________________________
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir void SAL_CALL ProgressBar::setRange ( sal_Int32 nMin, sal_Int32 nMax ) throw( RuntimeException )
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     // This method is defined for follow things:
261*cdf0e10cSrcweir     //      1) All values of sal_Int32
262*cdf0e10cSrcweir     //      2) Min < Max
263*cdf0e10cSrcweir     //      3) Min > Max
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     // save impossible cases
266*cdf0e10cSrcweir     // This method is only defined for valid values
267*cdf0e10cSrcweir     // If you ignore this, the release version wil produce an error "division by zero" in "ProgressBar::setValue()"!
268*cdf0e10cSrcweir     DBG_ASSERT ( ( nMin != nMax ) , "ProgressBar::setRange()\nValues for MIN and MAX are the same. This is not allowed!\n" ) ;
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     // Ready for multithreading
271*cdf0e10cSrcweir     MutexGuard  aGuard (m_aMutex) ;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     // control the values for min and max
274*cdf0e10cSrcweir     if ( nMin < nMax )
275*cdf0e10cSrcweir     {
276*cdf0e10cSrcweir         // Take correct Min and Max
277*cdf0e10cSrcweir         m_nMinRange = nMin  ;
278*cdf0e10cSrcweir         m_nMaxRange = nMax  ;
279*cdf0e10cSrcweir     }
280*cdf0e10cSrcweir     else
281*cdf0e10cSrcweir     {
282*cdf0e10cSrcweir         // Change Min and Max automaticly
283*cdf0e10cSrcweir         m_nMinRange = nMax  ;
284*cdf0e10cSrcweir         m_nMaxRange = nMin  ;
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     // assure that m_nValue is within the range
288*cdf0e10cSrcweir     if (!(m_nMinRange < m_nValue  &&  m_nValue < m_nMaxRange))
289*cdf0e10cSrcweir         m_nValue = m_nMinRange;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     impl_recalcRange () ;
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir     // Do not repaint the control at this place!!!
294*cdf0e10cSrcweir     // An old "m_nValue" is set and can not be correct for this new range.
295*cdf0e10cSrcweir     // Next call of "ProgressBar::setValue()" do this.
296*cdf0e10cSrcweir }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir //____________________________________________________________________________________________________________
299*cdf0e10cSrcweir //  XProgressBar
300*cdf0e10cSrcweir //____________________________________________________________________________________________________________
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir sal_Int32 SAL_CALL ProgressBar::getValue () throw( RuntimeException )
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir     // Ready for multithreading
305*cdf0e10cSrcweir     MutexGuard aGuard (m_aMutex) ;
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir     return ( m_nValue ) ;
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir //____________________________________________________________________________________________________________
311*cdf0e10cSrcweir //  XWindow
312*cdf0e10cSrcweir //____________________________________________________________________________________________________________
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir void SAL_CALL ProgressBar::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags ) throw( RuntimeException )
315*cdf0e10cSrcweir {
316*cdf0e10cSrcweir     // Take old size BEFORE you set the new values at baseclass!
317*cdf0e10cSrcweir     // You will control changes. At the other way, the values are the same!
318*cdf0e10cSrcweir     Rectangle aBasePosSize = getPosSize () ;
319*cdf0e10cSrcweir     BaseControl::setPosSize (nX, nY, nWidth, nHeight, nFlags) ;
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     // Do only, if size has changed.
322*cdf0e10cSrcweir     if (
323*cdf0e10cSrcweir         ( nWidth  != aBasePosSize.Width     ) ||
324*cdf0e10cSrcweir         ( nHeight != aBasePosSize.Height    )
325*cdf0e10cSrcweir        )
326*cdf0e10cSrcweir     {
327*cdf0e10cSrcweir         impl_recalcRange    (                           ) ;
328*cdf0e10cSrcweir         impl_paint          ( 0, 0, impl_getGraphicsPeer () ) ;
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir //____________________________________________________________________________________________________________
333*cdf0e10cSrcweir //  XControl
334*cdf0e10cSrcweir //____________________________________________________________________________________________________________
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir sal_Bool SAL_CALL ProgressBar::setModel( const Reference< XControlModel >& /*xModel*/ ) throw( RuntimeException )
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir     // A model is not possible for this control.
339*cdf0e10cSrcweir     return sal_False ;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir //____________________________________________________________________________________________________________
343*cdf0e10cSrcweir //  XControl
344*cdf0e10cSrcweir //____________________________________________________________________________________________________________
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir Reference< XControlModel > SAL_CALL ProgressBar::getModel() throw( RuntimeException )
347*cdf0e10cSrcweir {
348*cdf0e10cSrcweir     // A model is not possible for this control.
349*cdf0e10cSrcweir     return Reference< XControlModel >();
350*cdf0e10cSrcweir }
351*cdf0e10cSrcweir 
352*cdf0e10cSrcweir //____________________________________________________________________________________________________________
353*cdf0e10cSrcweir //  impl but public method to register service
354*cdf0e10cSrcweir //____________________________________________________________________________________________________________
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir const Sequence< OUString > ProgressBar::impl_getStaticSupportedServiceNames()
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir     MutexGuard aGuard( Mutex::getGlobalMutex() );
359*cdf0e10cSrcweir     Sequence< OUString > seqServiceNames( 1 );
360*cdf0e10cSrcweir     seqServiceNames.getArray() [0] = OUString::createFromAscii( SERVICENAME_PROGRESSBAR );
361*cdf0e10cSrcweir     return seqServiceNames ;
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir //____________________________________________________________________________________________________________
365*cdf0e10cSrcweir //  impl but public method to register service
366*cdf0e10cSrcweir //____________________________________________________________________________________________________________
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir const OUString ProgressBar::impl_getStaticImplementationName()
369*cdf0e10cSrcweir {
370*cdf0e10cSrcweir     return OUString::createFromAscii( IMPLEMENTATIONNAME_PROGRESSBAR );
371*cdf0e10cSrcweir }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir //____________________________________________________________________________________________________________
374*cdf0e10cSrcweir //  protected method
375*cdf0e10cSrcweir //____________________________________________________________________________________________________________
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir void ProgressBar::impl_paint ( sal_Int32 nX, sal_Int32 nY, const Reference< XGraphics > & rGraphics )
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir     // save impossible cases
380*cdf0e10cSrcweir     DBG_ASSERT ( rGraphics.is(), "ProgressBar::paint()\nCalled with invalid Reference< XGraphics > ." ) ;
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir     // This paint method ist not buffered !!
383*cdf0e10cSrcweir     // Every request paint the completely control. ( but only, if peer exist )
384*cdf0e10cSrcweir     if ( rGraphics.is () )
385*cdf0e10cSrcweir     {
386*cdf0e10cSrcweir         MutexGuard  aGuard (m_aMutex) ;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir         // Clear background
389*cdf0e10cSrcweir         // (same color for line and fill)
390*cdf0e10cSrcweir         rGraphics->setFillColor ( m_nBackgroundColor                        ) ;
391*cdf0e10cSrcweir         rGraphics->setLineColor ( m_nBackgroundColor                        ) ;
392*cdf0e10cSrcweir         rGraphics->drawRect     ( nX, nY, impl_getWidth(), impl_getHeight() ) ;
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir         // same color for line and fill for blocks
395*cdf0e10cSrcweir         rGraphics->setFillColor ( m_nForegroundColor ) ;
396*cdf0e10cSrcweir         rGraphics->setLineColor ( m_nForegroundColor ) ;
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir         sal_Int32   nBlockStart     =   0                                                                           ;   // = left site of new block
399*cdf0e10cSrcweir         sal_Int32   nBlockCount     =   m_nBlockValue!=0.00 ? (sal_Int32)((m_nValue-m_nMinRange)/m_nBlockValue) : 0 ;   // = number of next block
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir         // Draw horizontal progressbar
402*cdf0e10cSrcweir         // decision in "recalcRange()"
403*cdf0e10cSrcweir         if (m_bHorizontal)
404*cdf0e10cSrcweir         {
405*cdf0e10cSrcweir             // Step to left side of window
406*cdf0e10cSrcweir             nBlockStart = nX ;
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir             for ( sal_Int16 i=1; i<=nBlockCount; ++i )
409*cdf0e10cSrcweir             {
410*cdf0e10cSrcweir                 // step free field
411*cdf0e10cSrcweir                 nBlockStart +=  FREESPACE   ;
412*cdf0e10cSrcweir                 // paint block
413*cdf0e10cSrcweir                 rGraphics->drawRect (nBlockStart, nY+FREESPACE, m_aBlockSize.Width, m_aBlockSize.Height) ;
414*cdf0e10cSrcweir                 // step next free field
415*cdf0e10cSrcweir                 nBlockStart +=  m_aBlockSize.Width ;
416*cdf0e10cSrcweir             }
417*cdf0e10cSrcweir         }
418*cdf0e10cSrcweir         // draw vertikal progressbar
419*cdf0e10cSrcweir         // decision in "recalcRange()"
420*cdf0e10cSrcweir         else
421*cdf0e10cSrcweir         {
422*cdf0e10cSrcweir             // step to bottom side of window
423*cdf0e10cSrcweir             nBlockStart  =  nY+impl_getHeight() ;
424*cdf0e10cSrcweir             nBlockStart -=  m_aBlockSize.Height ;
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir             for ( sal_Int16 i=1; i<=nBlockCount; ++i )
427*cdf0e10cSrcweir             {
428*cdf0e10cSrcweir                 // step free field
429*cdf0e10cSrcweir                 nBlockStart -=  FREESPACE   ;
430*cdf0e10cSrcweir                 // paint block
431*cdf0e10cSrcweir                 rGraphics->drawRect (nX+FREESPACE, nBlockStart, m_aBlockSize.Width, m_aBlockSize.Height) ;
432*cdf0e10cSrcweir                 // step next free field
433*cdf0e10cSrcweir                 nBlockStart -=  m_aBlockSize.Height;
434*cdf0e10cSrcweir             }
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         // Paint shadow border around the progressbar
438*cdf0e10cSrcweir         rGraphics->setLineColor ( LINECOLOR_SHADOW                          ) ;
439*cdf0e10cSrcweir         rGraphics->drawLine     ( nX, nY, impl_getWidth(), nY               ) ;
440*cdf0e10cSrcweir         rGraphics->drawLine     ( nX, nY, nX             , impl_getHeight() ) ;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir         rGraphics->setLineColor ( LINECOLOR_BRIGHT                                                              ) ;
443*cdf0e10cSrcweir         rGraphics->drawLine     ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY                  ) ;
444*cdf0e10cSrcweir         rGraphics->drawLine     ( impl_getWidth()-1, impl_getHeight()-1, nX               , impl_getHeight()-1  ) ;
445*cdf0e10cSrcweir     }
446*cdf0e10cSrcweir }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir //____________________________________________________________________________________________________________
449*cdf0e10cSrcweir //  protected method
450*cdf0e10cSrcweir //____________________________________________________________________________________________________________
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir void ProgressBar::impl_recalcRange ()
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir     MutexGuard  aGuard (m_aMutex) ;
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir     sal_Int32 nWindowWidth  = impl_getWidth()  ;
457*cdf0e10cSrcweir     sal_Int32 nWindowHeight = impl_getHeight() ;
458*cdf0e10cSrcweir     double    fBlockHeight                     ;
459*cdf0e10cSrcweir     double    fBlockWidth                      ;
460*cdf0e10cSrcweir     double    fMaxBlocks                       ;
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir     if( nWindowWidth > nWindowHeight )
463*cdf0e10cSrcweir     {
464*cdf0e10cSrcweir         m_bHorizontal = sal_True                            ;
465*cdf0e10cSrcweir         fBlockHeight  = (nWindowHeight-(2*FREESPACE))       ;
466*cdf0e10cSrcweir         fBlockWidth   = fBlockHeight                        ;
467*cdf0e10cSrcweir         fMaxBlocks    = nWindowWidth/(fBlockWidth+FREESPACE);
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir     else
470*cdf0e10cSrcweir     {
471*cdf0e10cSrcweir         m_bHorizontal = sal_False                             ;
472*cdf0e10cSrcweir         fBlockWidth   = (nWindowWidth-(2*FREESPACE))          ;
473*cdf0e10cSrcweir         fBlockHeight  = fBlockWidth                           ;
474*cdf0e10cSrcweir         fMaxBlocks    = nWindowHeight/(fBlockHeight+FREESPACE);
475*cdf0e10cSrcweir     }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir     double fRange       = m_nMaxRange-m_nMinRange    ;
478*cdf0e10cSrcweir     double fBlockValue  = fRange/fMaxBlocks          ;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     m_nBlockValue       = fBlockValue            ;
481*cdf0e10cSrcweir     m_aBlockSize.Height = (sal_Int32)fBlockHeight;
482*cdf0e10cSrcweir     m_aBlockSize.Width  = (sal_Int32)fBlockWidth ;
483*cdf0e10cSrcweir /*
484*cdf0e10cSrcweir         // Calculate count of blocks for actual size
485*cdf0e10cSrcweir         // (prevent error "division by zero")
486*cdf0e10cSrcweir         if ( nHeight == 0 )
487*cdf0e10cSrcweir         {
488*cdf0e10cSrcweir             nHeight = 1 ;
489*cdf0e10cSrcweir         }
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir         nMaxBlock    =  nWidth / nHeight    ;
492*cdf0e10cSrcweir         nMaxBlock   *=  2                   ;
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir         // prevent error "division by zero"
495*cdf0e10cSrcweir         if ( nMaxBlock == 0 )
496*cdf0e10cSrcweir         {
497*cdf0e10cSrcweir             nMaxBlock = 1 ;
498*cdf0e10cSrcweir         }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir         // Calculate new value and new size for ONE block.
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir         // Do not a calculation like this: "m_nBlockValue=(m_nMaxRange-m_nMinRange)/nMaxBlock"  !
503*cdf0e10cSrcweir         // If difference between m_nMaxRange and m_nMinRange to large, it give an overflow and a
504*cdf0e10cSrcweir         // following error "division by zero" in method "paint() ... nBlockCount=nDifference/m_nBlockValue ..."
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir         // Overflow ? => example: _I32_MAX - _I32_MIN = -1 and not _UI32_MAX !!!
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir         m_nBlockValue       =   ( m_nMaxRange / nMaxBlock ) - ( m_nMinRange / nMaxBlock ) ;
509*cdf0e10cSrcweir         m_aBlockSize.Height =   ( nHeight - ( FREESPACE * 2 )                           ) ;
510*cdf0e10cSrcweir         m_aBlockSize.Width  =   ( ( nWidth / nMaxBlock ) - FREESPACE                    ) ;
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir     else
513*cdf0e10cSrcweir     {
514*cdf0e10cSrcweir         // Don't forget to save this state! Used in "ProgressBar::paint()"
515*cdf0e10cSrcweir         m_bHorizontal = sal_False ;
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir         double fBlockWidth  = (nHeight-(2*FREESPACE))       ;
518*cdf0e10cSrcweir         double fBlockHeight = fBlockWidth                   ;
519*cdf0e10cSrcweir         double fRange       = m_nMaxRange-m_nMinRange       ;
520*cdf0e10cSrcweir         double fBlockValue  = fRange/(fBlockWidth+FREESPACE);
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir         m_nBlockValue       = fBlockValue            ;
523*cdf0e10cSrcweir         m_aBlockSize.Height = (sal_Int32)fBlockHeight;
524*cdf0e10cSrcweir         m_aBlockSize.Width  = (sal_Int32)fBlockWidth ;
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir         // Calculate count of blocks for actual size
527*cdf0e10cSrcweir         // (prevent error "division by zero")
528*cdf0e10cSrcweir         if ( nWidth == 0 )
529*cdf0e10cSrcweir         {
530*cdf0e10cSrcweir             nWidth = 1 ;
531*cdf0e10cSrcweir         }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir         nMaxBlock    =  nHeight / nWidth    ;
534*cdf0e10cSrcweir         nMaxBlock   *=  2                   ;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir         // prevent error "division by zero"
537*cdf0e10cSrcweir         if ( nMaxBlock == 0 )
538*cdf0e10cSrcweir         {
539*cdf0e10cSrcweir             nMaxBlock = 1 ;
540*cdf0e10cSrcweir         }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir         // Calculate new value and new size for ONE block.
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir         // Do not a calculation like this: "m_nBlockValue=(m_nMaxRange-m_nMinRange)/nMaxBlock"  !
545*cdf0e10cSrcweir         // If difference between m_nMaxRange and m_nMinRange to large, it give an overflow and a
546*cdf0e10cSrcweir         // following error "division by zero" in method "paint() ... nBlockCount=nDifference/m_nBlockValue ..."
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir         // Overflow ? => example: _I32_MAX - _I32_MIN = -1 and not _UI32_MAX !!!
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir         m_nBlockValue       =   ( m_nMaxRange / nMaxBlock ) - ( m_nMinRange / nMaxBlock ) ;
551*cdf0e10cSrcweir         m_aBlockSize.Height =   ( ( nHeight / nMaxBlock ) - FREESPACE                   ) ;
552*cdf0e10cSrcweir         m_aBlockSize.Width  =   ( nWidth - ( FREESPACE * 2 )                            ) ;
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir     }
555*cdf0e10cSrcweir */
556*cdf0e10cSrcweir }
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir }   // namespace unocontrols
559