]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/gauge.cpp
Cygwin compile 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "gauge.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #if wxUSE_GAUGE
19
20 #include "wx/gauge.h"
21
22 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
23
24 #include "wx/mac/uma.h"
25
26 bool wxGauge::Create(wxWindow *parent, wxWindowID id,
27 int range,
28 const wxPoint& pos,
29 const wxSize& s,
30 long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 m_macIsUserPane = FALSE ;
35
36 if ( !wxGaugeBase::Create(parent, id, range, pos, s, style & 0xE0FFFFFF, validator, name) )
37 return false;
38
39 wxSize size = s ;
40 /*
41 if ( size.x == wxDefaultCoord && size.y == wxDefaultCoord)
42 {
43 size = wxSize( 200 , 16 ) ;
44 }
45 */
46 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
47 m_peer = new wxMacControl(this) ;
48 verify_noerr ( CreateProgressBarControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds ,
49 GetValue() , 0 , GetRange() , false /* not indeterminate */ , m_peer->GetControlRefAddr() ) );
50
51 if ( GetValue() == 0 )
52 m_peer->SetData<Boolean>( kControlEntireControl , kControlProgressBarAnimatingTag , (Boolean) false ) ;
53
54 MacPostControlCreate(pos,size) ;
55
56 return TRUE;
57 }
58
59 void wxGauge::SetRange(int r)
60 {
61 // we are going via the base class in case there is
62 // some change behind the values by it
63 wxGaugeBase::SetRange(r) ;
64 if ( m_peer && m_peer->Ok() )
65 m_peer->SetMaximum( GetRange() ) ;
66 }
67
68 void wxGauge::SetValue(int pos)
69 {
70 // we are going via the base class in case there is
71 // some change behind the values by it
72 wxGaugeBase::SetValue(pos) ;
73 if ( m_peer && m_peer->Ok() )
74 {
75 m_peer->SetValue( GetValue() ) ;
76 // we turn off animation in the unnecessary situations as this is eating a lot of CPU otherwise
77 Boolean shouldAnimate = ( GetValue() > 0 && GetValue() < GetRange() ) ;
78 if ( m_peer->GetData<Boolean>( kControlEntireControl , kControlProgressBarAnimatingTag ) != shouldAnimate )
79 {
80 m_peer->SetData<Boolean>( kControlEntireControl , kControlProgressBarAnimatingTag , shouldAnimate ) ;
81 if ( !shouldAnimate )
82 {
83 Refresh() ;
84 }
85 }
86 }
87 }
88
89 int wxGauge::GetValue() const
90 {
91 /*
92 if ( m_peer && m_peer->Ok() )
93 return m_peer->GetValue() ;
94 */
95 return m_gaugePos ;
96 }
97
98 #endif // wxUSE_GAUGE
99