1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/gauge.cpp
3 // Purpose: wxGauge class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 #include "wx/osx/private.h"
20 class wxMacGaugeCarbonControl
: public wxMacControl
23 wxMacGaugeCarbonControl( wxWindowMac
* peer
) : wxMacControl( peer
)
27 void SetMaximum(wxInt32 v
)
29 // switch back to determinate mode if not there already
30 if ( GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != false )
32 SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, (Boolean
)false );
35 wxMacControl::SetMaximum( v
) ;
38 void SetValue(wxInt32 v
)
40 // switch back to determinate mode if not there already
41 if ( GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != false )
43 SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, (Boolean
)false );
46 wxMacControl::SetValue( v
) ;
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
)
52 SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, shouldAnimate
) ;
54 SetNeedsDisplay(NULL
) ;
60 if ( GetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
) != true )
62 SetData
<Boolean
>( kControlNoPart
, kControlProgressBarIndeterminateTag
, true);
65 if ( GetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
) != true )
67 SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, true ) ;
73 wxWidgetImplType
* wxWidgetImpl::CreateGauge( wxWindowMac
* wxpeer
,
75 wxWindowID
WXUNUSED(id
),
82 long WXUNUSED(extraStyle
))
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() );
91 peer
->SetData
<Boolean
>( kControlEntireControl
, kControlProgressBarAnimatingTag
, (Boolean
)false );