]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/gauge.mm
Add missing WXK constants for the control keys
[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 // RCS-ID: $Id$
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 {
22 }
23
24 @end
25
26 @implementation wxNSProgressIndicator
27
28 + (void)initialize
29 {
30 static BOOL initialized = NO;
31 if (!initialized)
32 {
33 initialized = YES;
34 wxOSXCocoaClassAddWXMethods( self );
35 }
36 }
37
38 @end
39
40 @interface NSView(PossibleSizeMethods)
41 - (NSControlSize)controlSize;
42 @end
43
44 namespace
45 {
46
47 class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
48 {
49 public :
50 wxOSXGaugeCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
51 {
52 }
53
54 void SetMaximum(wxInt32 v)
55 {
56 SetDeterminateMode();
57 wxWidgetCocoaImpl::SetMaximum( v ) ;
58 }
59
60 void SetValue(wxInt32 v)
61 {
62 SetDeterminateMode();
63 wxWidgetCocoaImpl::SetValue( v ) ;
64 }
65
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 }
74
75 void GetLayoutInset(int &left , int &top , int &right, int &bottom) const
76 {
77 left = top = right = bottom = 0;
78 NSControlSize size = [(wxNSProgressIndicator*)m_osxView controlSize];
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 }
95 protected:
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 };
106
107 } // anonymous namespace
108
109 wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
110 wxWindowMac* WXUNUSED(parent),
111 wxWindowID WXUNUSED(id),
112 wxInt32 value,
113 wxInt32 minimum,
114 wxInt32 maximum,
115 const wxPoint& pos,
116 const wxSize& size,
117 long WXUNUSED(style),
118 long WXUNUSED(extraStyle))
119 {
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];
127 wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
128 return c;
129 }
130
131 #endif // wxUSE_GAUGE
132