]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/gauge.cpp
wxPalmOS build fix.
[wxWidgets.git] / src / mac / carbon / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gauge.cpp
3 // Purpose: wxGauge class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_GAUGE
15
16 #include "wx/gauge.h"
17
18 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
19
20 #include "wx/mac/uma.h"
21
22 bool wxGauge::Create( wxWindow *parent,
23 wxWindowID id,
24 int range,
25 const wxPoint& pos,
26 const wxSize& s,
27 long style,
28 const wxValidator& validator,
29 const wxString& name )
30 {
31 m_macIsUserPane = false;
32
33 if ( !wxGaugeBase::Create( parent, id, range, pos, s, style & 0xE0FFFFFF, validator, name ) )
34 return false;
35
36 wxSize size = s;
37
38 #if 0
39 if (size.x == wxDefaultCoord && size.y == wxDefaultCoord)
40 size = wxSize( 200 , 16 );
41 #endif
42
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() );
48 verify_noerr( err );
49
50 if ( GetValue() == 0 )
51 m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, (Boolean)false );
52
53 MacPostControlCreate( pos, size );
54
55 return true;
56 }
57
58 void wxGauge::SetRange(int r)
59 {
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() ) ;
65 }
66
67 void wxGauge::SetValue(int pos)
68 {
69 // we are going via the base class in case there is
70 // some change behind the values by it
71 wxGaugeBase::SetValue( pos ) ;
72
73 if ( m_peer && m_peer->Ok() )
74 {
75 m_peer->SetValue( GetValue() ) ;
76
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 )
80 {
81 m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ;
82 if ( !shouldAnimate )
83 Refresh() ;
84 }
85 }
86 }
87
88 int wxGauge::GetValue() const
89 {
90 #if 0
91 if ( m_peer && m_peer->Ok() )
92 return m_peer->GetValue() ;
93 #endif
94
95 return m_gaugePos ;
96 }
97
98 #endif // wxUSE_GAUGE
99