]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: gauge.cpp | |
3 | // Purpose: wxGauge class | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #include "wx/wxprec.h" |
e9576ca5 | 13 | |
947f3b35 | 14 | #if wxUSE_GAUGE |
e3e817d4 | 15 | |
3d1a4878 SC |
16 | #include "wx/gauge.h" |
17 | ||
e9576ca5 | 18 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) |
e9576ca5 | 19 | |
d497dca4 | 20 | #include "wx/mac/uma.h" |
519cb848 | 21 | |
172da31f DS |
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 ) | |
e9576ca5 | 30 | { |
172da31f | 31 | m_macIsUserPane = false; |
21fd5529 | 32 | |
172da31f | 33 | if ( !wxGaugeBase::Create( parent, id, range, pos, s, style & 0xE0FFFFFF, validator, name ) ) |
b45ed7a2 VZ |
34 | return false; |
35 | ||
172da31f DS |
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 ); | |
2b1fe32e SC |
49 | |
50 | if ( GetValue() == 0 ) | |
172da31f | 51 | m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, (Boolean)false ); |
2b1fe32e | 52 | |
172da31f | 53 | MacPostControlCreate( pos, size ); |
947f3b35 | 54 | |
172da31f | 55 | return true; |
e9576ca5 SC |
56 | } |
57 | ||
e9576ca5 SC |
58 | void wxGauge::SetRange(int r) |
59 | { | |
947f3b35 | 60 | // we are going via the base class in case there is |
21fd5529 | 61 | // some change behind the values by it |
172da31f | 62 | wxGaugeBase::SetRange( r ) ; |
ef78ec37 | 63 | if ( m_peer && m_peer->Ok() ){ |
947f3b35 | 64 | // switch back to determinate mode if not there already |
ef78ec37 KO |
65 | if ( m_peer->GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) |
66 | { | |
67 | m_peer->SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); | |
68 | } | |
947f3b35 | 69 | |
21fd5529 | 70 | m_peer->SetMaximum( GetRange() ) ; |
ef78ec37 | 71 | } |
e9576ca5 SC |
72 | } |
73 | ||
74 | void wxGauge::SetValue(int pos) | |
75 | { | |
947f3b35 | 76 | // we are going via the base class in case there is |
21fd5529 | 77 | // some change behind the values by it |
172da31f DS |
78 | wxGaugeBase::SetValue( pos ) ; |
79 | ||
21fd5529 | 80 | if ( m_peer && m_peer->Ok() ) |
2b1fe32e | 81 | { |
947f3b35 | 82 | // switch back to determinate mode if not there already |
ef78ec37 KO |
83 | if ( m_peer->GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) |
84 | { | |
85 | m_peer->SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); | |
86 | } | |
947f3b35 | 87 | |
21fd5529 | 88 | m_peer->SetValue( GetValue() ) ; |
172da31f DS |
89 | |
90 | // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise | |
2b1fe32e | 91 | Boolean shouldAnimate = ( GetValue() > 0 && GetValue() < GetRange() ) ; |
172da31f | 92 | if ( m_peer->GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != shouldAnimate ) |
2b1fe32e | 93 | { |
172da31f | 94 | m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ; |
2b1fe32e | 95 | if ( !shouldAnimate ) |
2b1fe32e | 96 | Refresh() ; |
2b1fe32e SC |
97 | } |
98 | } | |
e9576ca5 SC |
99 | } |
100 | ||
101 | int wxGauge::GetValue() const | |
102 | { | |
172da31f | 103 | #if 0 |
21fd5529 SC |
104 | if ( m_peer && m_peer->Ok() ) |
105 | return m_peer->GetValue() ; | |
172da31f DS |
106 | #endif |
107 | ||
21fd5529 | 108 | return m_gaugePos ; |
e9576ca5 SC |
109 | } |
110 | ||
fe8635a7 RR |
111 | void wxGauge::Pulse() |
112 | { | |
113 | if ( m_peer && m_peer->Ok() ) | |
114 | { | |
ef78ec37 KO |
115 | if ( m_peer->GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != true ) |
116 | { | |
947f3b35 | 117 | m_peer->SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, true); |
ef78ec37 | 118 | } |
947f3b35 | 119 | |
ef78ec37 KO |
120 | if ( m_peer->GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != true ) |
121 | { | |
122 | m_peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ; | |
123 | } | |
fe8635a7 RR |
124 | } |
125 | } | |
126 | ||
172da31f | 127 | #endif // wxUSE_GAUGE |
e3e817d4 | 128 |