1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGauge class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
20 #include "wx/mac/uma.h"
22 bool wxGauge::Create( wxWindow
*parent
,
28 const wxValidator
& validator
,
29 const wxString
& name
)
31 m_macIsUserPane
= false;
33 if ( !wxGaugeBase::Create( parent
, id
, range
, pos
, s
, style
& 0xE0FFFFFF, validator
, name
) )
39 if (size
.x
== wxDefaultCoord
&& size
.y
== wxDefaultCoord
)
40 size
= wxSize( 200 , 16 );
43 Rect bounds
= wxMacGetBoundsForControl( this, pos
, size
);
44 m_peer
= new wxMacControl( this );
45 OSStatus err
= CreateProgressBarControl(
46 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
47 GetValue(), 0, GetRange(), false /* not indeterminate */, m_peer
->GetControlRefAddr() );
50 if ( GetValue() == 0 )
51 m_peer
->SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, (Boolean
)false );
53 MacPostControlCreate( pos
, size
);
58 void wxGauge::SetRange(int r
)
60 // we are going via the base class in case there is
61 // some change behind the values by it
62 wxGaugeBase::SetRange( r
) ;
63 if ( m_peer
&& m_peer
->Ok() )
64 m_peer
->SetMaximum( GetRange() ) ;
67 void wxGauge::SetValue(int pos
)
69 // we are going via the base class in case there is
70 // some change behind the values by it
71 wxGaugeBase::SetValue( pos
) ;
73 if ( m_peer
&& m_peer
->Ok() )
75 m_peer
->SetValue( GetValue() ) ;
77 // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise
78 Boolean shouldAnimate
= ( GetValue() > 0 && GetValue() < GetRange() ) ;
79 if ( m_peer
->GetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
) != shouldAnimate
)
81 m_peer
->SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, shouldAnimate
) ;
88 int wxGauge::GetValue() const
91 if ( m_peer
&& m_peer
->Ok() )
92 return m_peer
->GetValue() ;