]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/gauge.mm
If there is a sizer then use it's calculated minimum in wxStaticBox::DoGetBestSize
[wxWidgets.git] / src / osx / cocoa / gauge.mm
CommitLineData
dbeddfb9 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/cocoa/gauge.mm
dbeddfb9
SC
3// Purpose: wxGauge class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
a9a4f229 7// RCS-ID: $Id$
dbeddfb9
SC
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@interface wxNSProgressIndicator : NSProgressIndicator
21{
dbeddfb9
SC
22}
23
dbeddfb9
SC
24@end
25
26@implementation wxNSProgressIndicator
27
4dd9fdf8 28+ (void)initialize
dbeddfb9 29{
4dd9fdf8 30 static BOOL initialized = NO;
03647350 31 if (!initialized)
4dd9fdf8
SC
32 {
33 initialized = YES;
34 wxOSXCocoaClassAddWXMethods( self );
35 }
dbeddfb9
SC
36}
37
dbeddfb9
SC
38@end
39
9d320a7a
SC
40@interface NSView(PossibleSizeMethods)
41- (NSControlSize)controlSize;
42@end
43
44namespace
45{
46
dbeddfb9
SC
47class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
48{
49public :
50 wxOSXGaugeCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
51 {
52 }
03647350 53
dbeddfb9
SC
54 void SetMaximum(wxInt32 v)
55 {
56 SetDeterminateMode();
57 wxWidgetCocoaImpl::SetMaximum( v ) ;
58 }
03647350 59
dbeddfb9
SC
60 void SetValue(wxInt32 v)
61 {
62 SetDeterminateMode();
63 wxWidgetCocoaImpl::SetValue( v ) ;
64 }
03647350 65
dbeddfb9
SC
66 void PulseGauge()
67 {
68 if ( ![(wxNSProgressIndicator*)m_osxView isIndeterminate] )
69 {
70 [(wxNSProgressIndicator*)m_osxView setIndeterminate:YES];
71 [(wxNSProgressIndicator*)m_osxView startAnimation:nil];
72 }
73 }
9d320a7a
SC
74
75 void GetLayoutInset(int &left , int &top , int &right, int &bottom) const
76 {
77 left = top = right = bottom = 0;
bab25199 78 NSControlSize size = [(wxNSProgressIndicator*)m_osxView controlSize];
9d320a7a
SC
79
80 switch( size )
81 {
82 case NSRegularControlSize:
83 left = right = 2;
84 top = 0;
85 bottom = 4;
86 break;
87 case NSMiniControlSize:
88 case NSSmallControlSize:
89 left = right = 1;
90 top = 0;
91 bottom = 2;
92 break;
93 }
94 }
dbeddfb9
SC
95protected:
96 void SetDeterminateMode()
97 {
98 // switch back to determinate mode if necessary
99 if ( [(wxNSProgressIndicator*)m_osxView isIndeterminate] )
100 {
101 [(wxNSProgressIndicator*)m_osxView stopAnimation:nil];
102 [(wxNSProgressIndicator*)m_osxView setIndeterminate:NO];
103 }
104 }
105};
9d320a7a
SC
106
107} // anonymous namespace
dbeddfb9 108
03647350
VZ
109wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
110 wxWindowMac* WXUNUSED(parent),
111 wxWindowID WXUNUSED(id),
dbeddfb9
SC
112 wxInt32 value,
113 wxInt32 minimum,
114 wxInt32 maximum,
03647350 115 const wxPoint& pos,
dbeddfb9 116 const wxSize& size,
03647350 117 long WXUNUSED(style),
d8207702 118 long WXUNUSED(extraStyle))
dbeddfb9 119{
dbeddfb9
SC
120 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
121 wxNSProgressIndicator* v = [[wxNSProgressIndicator alloc] initWithFrame:r];
122
123 [v setMinValue: minimum];
124 [v setMaxValue: maximum];
125 [v setIndeterminate:FALSE];
126 [v setDoubleValue: (double) value];
dbeddfb9 127 wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
dbeddfb9
SC
128 return c;
129}
130
131#endif // wxUSE_GAUGE
132