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