]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/gauge.cpp
No changes, synchronised source names that appear commented at the top of files with...
[wxWidgets.git] / src / osx / carbon / gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/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 #include "wx/osx/private.h"
19
20 class wxMacGaugeCarbonControl : public wxMacControl
21 {
22 public :
23 wxMacGaugeCarbonControl( wxWindowMac* peer ) : wxMacControl( peer )
24 {
25 }
26
27 void SetMaximum(wxInt32 v)
28 {
29 // switch back to determinate mode if not there already
30 if ( GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false )
31 {
32 SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false );
33 }
34
35 wxMacControl::SetMaximum( v ) ;
36 }
37
38 void SetValue(wxInt32 v)
39 {
40 // switch back to determinate mode if not there already
41 if ( GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != false )
42 {
43 SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false );
44 }
45
46 wxMacControl::SetValue( v ) ;
47
48 // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise
49 Boolean shouldAnimate = ( v > 0 && v < GetMaximum() ) ;
50 if ( GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != shouldAnimate )
51 {
52 SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, shouldAnimate ) ;
53 if ( !shouldAnimate )
54 SetNeedsDisplay(NULL) ;
55 }
56 }
57
58 void PulseGauge()
59 {
60 if ( GetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag ) != true )
61 {
62 SetData<Boolean>( kControlNoPart, kControlProgressBarIndeterminateTag, true);
63 }
64
65 if ( GetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag ) != true )
66 {
67 SetData<Boolean>( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ;
68 }
69 }
70 };
71
72
73 wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
74 wxWindowMac* parent,
75 wxWindowID WXUNUSED(id),
76 wxInt32 value,
77 wxInt32 minimum,
78 wxInt32 maximum,
79 const wxPoint& pos,
80 const wxSize& size,
81 long WXUNUSED(style),
82 long WXUNUSED(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;
93 }
94
95 #endif // wxUSE_GAUGE
96