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 // switch back to determinate mode if not there already
65 if ( m_peer
->GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != false )
67 m_peer
->SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, (Boolean
)false );
70 m_peer
->SetMaximum( GetRange() ) ;
74 void wxGauge::SetValue(int pos
)
76 // we are going via the base class in case there is
77 // some change behind the values by it
78 wxGaugeBase::SetValue( pos
) ;
80 if ( m_peer
&& m_peer
->Ok() )
82 // switch back to determinate mode if not there already
83 if ( m_peer
->GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != false )
85 m_peer
->SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, (Boolean
)false );
88 m_peer
->SetValue( GetValue() ) ;
90 // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise
91 Boolean shouldAnimate
= ( GetValue() > 0 && GetValue() < GetRange() ) ;
92 if ( m_peer
->GetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
) != shouldAnimate
)
94 m_peer
->SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, shouldAnimate
) ;
101 int wxGauge::GetValue() const
104 if ( m_peer
&& m_peer
->Ok() )
105 return m_peer
->GetValue() ;
111 void wxGauge::Pulse()
113 if ( m_peer
&& m_peer
->Ok() )
115 if ( m_peer
->GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != true )
117 m_peer
->SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, true);
120 if ( m_peer
->GetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
) != true )
122 m_peer
->SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, true ) ;
127 #endif // wxUSE_GAUGE