]>
Commit | Line | Data |
---|---|---|
489468fe SC |
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 | ||
524c47aa | 18 | #include "wx/osx/private.h" |
489468fe | 19 | |
524c47aa | 20 | class wxMacGaugeCarbonControl : public wxMacControl |
489468fe | 21 | { |
524c47aa SC |
22 | public : |
23 | wxMacGaugeCarbonControl( wxWindowMac* peer ) : wxMacControl( peer ) | |
24 | { | |
25 | } | |
26 | ||
27 | void SetMaximum(wxInt32 v) | |
28 | { | |
489468fe | 29 | // switch back to determinate mode if not there already |
524c47aa | 30 | if ( GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) |
489468fe | 31 | { |
524c47aa | 32 | SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); |
489468fe SC |
33 | } |
34 | ||
524c47aa | 35 | wxMacControl::SetMaximum( v ) ; |
489468fe | 36 | } |
524c47aa SC |
37 | |
38 | void SetValue(wxInt32 v) | |
489468fe SC |
39 | { |
40 | // switch back to determinate mode if not there already | |
524c47aa | 41 | if ( GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) |
489468fe | 42 | { |
524c47aa | 43 | SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); |
489468fe SC |
44 | } |
45 | ||
524c47aa | 46 | wxMacControl::SetValue( v ) ; |
489468fe SC |
47 | |
48 | // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise | |
524c47aa SC |
49 | Boolean shouldAnimate = ( v > 0 && v < GetMaximum() ) ; |
50 | if ( GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != shouldAnimate ) | |
489468fe | 51 | { |
524c47aa | 52 | SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ; |
489468fe | 53 | if ( !shouldAnimate ) |
524c47aa | 54 | SetNeedsDisplay(NULL) ; |
489468fe SC |
55 | } |
56 | } | |
524c47aa SC |
57 | |
58 | void PulseGauge() | |
489468fe | 59 | { |
524c47aa | 60 | if ( GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != true ) |
489468fe | 61 | { |
524c47aa | 62 | SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, true); |
489468fe SC |
63 | } |
64 | ||
524c47aa | 65 | if ( GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != true ) |
489468fe | 66 | { |
524c47aa | 67 | SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ; |
489468fe SC |
68 | } |
69 | } | |
524c47aa SC |
70 | }; |
71 | ||
72 | ||
73 | wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer, | |
74 | wxWindowMac* parent, | |
75 | wxWindowID id, | |
76 | wxInt32 value, | |
77 | wxInt32 minimum, | |
78 | wxInt32 maximum, | |
79 | const wxPoint& pos, | |
80 | const wxSize& size, | |
81 | long style, | |
82 | long extraStyle) | |
83 | { | |
84 | Rect bounds = wxMacGetBoundsForControl( wxpeer, pos, size ); | |
85 | wxMacGaugeCarbonControl* peer = new wxMacGaugeCarbonControl( wxpeer ); | |
86 | OSStatus err = CreateProgressBarControl( | |
87 | MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, | |
88 | value, minimum, maximum, false /* not indeterminate */, peer->GetControlRefAddr() ); | |
89 | verify_noerr( err ); | |
90 | if ( value == 0 ) | |
91 | peer->SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, (Boolean)false ); | |
92 | return peer; | |
489468fe SC |
93 | } |
94 | ||
95 | #endif // wxUSE_GAUGE | |
96 |