1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/gauge.cpp
3 // Purpose: wxGauge class
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
17 #include "wx/osx/private.h"
19 class wxMacGaugeCarbonControl
: public wxMacControl
22 wxMacGaugeCarbonControl( wxWindowMac
* peer
) : wxMacControl( peer
)
26 void SetMaximum(wxInt32 v
)
28 // switch back to determinate mode if not there already
29 if ( GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != false )
31 SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, (Boolean
)false );
34 wxMacControl::SetMaximum( v
) ;
37 void SetValue(wxInt32 v
)
39 // switch back to determinate mode if not there already
40 if ( GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != false )
42 SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, (Boolean
)false );
45 wxMacControl::SetValue( v
) ;
47 // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise
48 Boolean shouldAnimate
= ( v
> 0 && v
< GetMaximum() ) ;
49 if ( GetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
) != shouldAnimate
)
51 SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, shouldAnimate
) ;
53 SetNeedsDisplay(NULL
) ;
59 if ( GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != true )
61 SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, true);
64 if ( GetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
) != true )
66 SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, true ) ;
72 wxWidgetImplType
* wxWidgetImpl::CreateGauge( wxWindowMac
* wxpeer
,
74 wxWindowID
WXUNUSED(id
),
81 long WXUNUSED(extraStyle
))
83 Rect bounds
= wxMacGetBoundsForControl( wxpeer
, pos
, size
);
84 wxMacGaugeCarbonControl
* peer
= new wxMacGaugeCarbonControl( wxpeer
);
85 OSStatus err
= CreateProgressBarControl(
86 MAC_WXHWND(parent
->MacGetTopLevelWindowRef()), &bounds
,
87 value
, minimum
, maximum
, false /* not indeterminate */, peer
->GetControlRefAddr() );
90 peer
->SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, (Boolean
)false );