]>
Commit | Line | Data |
---|---|---|
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 | |
dbeddfb9 SC |
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 | { | |
dbeddfb9 SC |
21 | } |
22 | ||
dbeddfb9 SC |
23 | @end |
24 | ||
25 | @implementation wxNSProgressIndicator | |
26 | ||
4dd9fdf8 | 27 | + (void)initialize |
dbeddfb9 | 28 | { |
4dd9fdf8 | 29 | static BOOL initialized = NO; |
03647350 | 30 | if (!initialized) |
4dd9fdf8 SC |
31 | { |
32 | initialized = YES; | |
33 | wxOSXCocoaClassAddWXMethods( self ); | |
34 | } | |
dbeddfb9 SC |
35 | } |
36 | ||
dbeddfb9 SC |
37 | @end |
38 | ||
9d320a7a SC |
39 | @interface NSView(PossibleSizeMethods) |
40 | - (NSControlSize)controlSize; | |
41 | @end | |
42 | ||
43 | namespace | |
44 | { | |
45 | ||
dbeddfb9 SC |
46 | class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl |
47 | { | |
48 | public : | |
49 | wxOSXGaugeCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w ) | |
50 | { | |
51 | } | |
03647350 | 52 | |
dbeddfb9 SC |
53 | void SetMaximum(wxInt32 v) |
54 | { | |
55 | SetDeterminateMode(); | |
56 | wxWidgetCocoaImpl::SetMaximum( v ) ; | |
57 | } | |
03647350 | 58 | |
dbeddfb9 SC |
59 | void SetValue(wxInt32 v) |
60 | { | |
61 | SetDeterminateMode(); | |
62 | wxWidgetCocoaImpl::SetValue( v ) ; | |
63 | } | |
03647350 | 64 | |
dbeddfb9 SC |
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 | } | |
9d320a7a SC |
73 | |
74 | void GetLayoutInset(int &left , int &top , int &right, int &bottom) const | |
75 | { | |
76 | left = top = right = bottom = 0; | |
bab25199 | 77 | NSControlSize size = [(wxNSProgressIndicator*)m_osxView controlSize]; |
9d320a7a SC |
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 | } | |
dbeddfb9 SC |
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 | }; | |
9d320a7a SC |
105 | |
106 | } // anonymous namespace | |
dbeddfb9 | 107 | |
03647350 VZ |
108 | wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer, |
109 | wxWindowMac* WXUNUSED(parent), | |
110 | wxWindowID WXUNUSED(id), | |
dbeddfb9 SC |
111 | wxInt32 value, |
112 | wxInt32 minimum, | |
113 | wxInt32 maximum, | |
03647350 | 114 | const wxPoint& pos, |
dbeddfb9 | 115 | const wxSize& size, |
03647350 | 116 | long WXUNUSED(style), |
d8207702 | 117 | long WXUNUSED(extraStyle)) |
dbeddfb9 | 118 | { |
dbeddfb9 SC |
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]; | |
dbeddfb9 | 126 | wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v ); |
dbeddfb9 SC |
127 | return c; |
128 | } | |
129 | ||
130 | #endif // wxUSE_GAUGE | |
131 |