]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/gauge.cpp
b2f36abe9574f69147b0b54f7f9c048ade46d667
[wxWidgets.git] / src / osx / 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 // switch back to determinate mode if not there already
65 if ( m_peer->GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false )
66 {
67 m_peer->SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false );
68 }
69
70 m_peer->SetMaximum( GetRange() ) ;
71 }
72 }
73
74 void wxGauge::SetValue(int pos)
75 {
76 // we are going via the base class in case there is
77 // some change behind the values by it
78 wxGaugeBase::SetValue( pos ) ;
79
80 if ( m_peer && m_peer->Ok() )
81 {
82 // switch back to determinate mode if not there already
83 if ( m_peer->GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false )
84 {
85 m_peer->SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false );
86 }
87
88 m_peer->SetValue( GetValue() ) ;
89
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 )
93 {
94 m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ;
95 if ( !shouldAnimate )
96 Refresh() ;
97 }
98 }
99 }
100
101 int wxGauge::GetValue() const
102 {
103 #if 0
104 if ( m_peer && m_peer->Ok() )
105 return m_peer->GetValue() ;
106 #endif
107
108 return m_gaugePos ;
109 }
110
111 void wxGauge::Pulse()
112 {
113 if ( m_peer && m_peer->Ok() )
114 {
115 if ( m_peer->GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != true )
116 {
117 m_peer->SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, true);
118 }
119
120 if ( m_peer->GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != true )
121 {
122 m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ;
123 }
124 }
125 }
126
127 #endif // wxUSE_GAUGE
128