]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/cocoa/gauge.mm
DoGetAsBitmap implementation for Cocoa.
[wxWidgets.git] / src / osx / cocoa / gauge.mm
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: gauge.mm
3// Purpose: wxGauge class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id: gauge.cpp 54820 2008-07-29 20:04:11Z 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{
22 wxWidgetImpl* impl;
23}
24
25- (void)setImplementation: (wxWidgetImpl *) theImplementation;
26- (wxWidgetImpl*) implementation;
27- (BOOL) isFlipped;
28
29@end
30
31@implementation wxNSProgressIndicator
32
33- (id)initWithFrame:(NSRect)frame
34{
35 [super initWithFrame:frame];
36 impl = NULL;
37 return self;
38}
39
40- (void)setImplementation: (wxWidgetImpl *) theImplementation
41{
42 impl = theImplementation;
43}
44
45- (wxWidgetImpl*) implementation
46{
47 return impl;
48}
49
50- (BOOL) isFlipped
51{
52 return YES;
53}
54
55@end
56
57class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl
58{
59public :
60 wxOSXGaugeCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w )
61 {
62 }
63
64 void SetMaximum(wxInt32 v)
65 {
66 SetDeterminateMode();
67 wxWidgetCocoaImpl::SetMaximum( v ) ;
68 }
69
70 void SetValue(wxInt32 v)
71 {
72 SetDeterminateMode();
73 wxWidgetCocoaImpl::SetValue( v ) ;
74 }
75
76 void PulseGauge()
77 {
78 if ( ![(wxNSProgressIndicator*)m_osxView isIndeterminate] )
79 {
80 [(wxNSProgressIndicator*)m_osxView setIndeterminate:YES];
81 [(wxNSProgressIndicator*)m_osxView startAnimation:nil];
82 }
83 }
84protected:
85 void SetDeterminateMode()
86 {
87 // switch back to determinate mode if necessary
88 if ( [(wxNSProgressIndicator*)m_osxView isIndeterminate] )
89 {
90 [(wxNSProgressIndicator*)m_osxView stopAnimation:nil];
91 [(wxNSProgressIndicator*)m_osxView setIndeterminate:NO];
92 }
93 }
94};
95
96
97wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer,
98 wxWindowMac* parent,
99 wxWindowID id,
100 wxInt32 value,
101 wxInt32 minimum,
102 wxInt32 maximum,
103 const wxPoint& pos,
104 const wxSize& size,
105 long style,
106 long extraStyle)
107{
108 NSView* sv = (wxpeer->GetParent()->GetHandle() );
109
110 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
111 wxNSProgressIndicator* v = [[wxNSProgressIndicator alloc] initWithFrame:r];
112
113 [v setMinValue: minimum];
114 [v setMaxValue: maximum];
115 [v setIndeterminate:FALSE];
116 [v setDoubleValue: (double) value];
117 [sv addSubview:v];
118 wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v );
119 [v setImplementation:c];
120 return c;
121}
122
123#endif // wxUSE_GAUGE
124