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