1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/gauge.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
21 #include "wx/cocoa/autorelease.h"
23 #import <AppKit/NSProgressIndicator.h>
24 #import <Foundation/NSException.h>
28 IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
29 BEGIN_EVENT_TABLE(wxGauge, wxGaugeBase)
31 // WX_IMPLEMENT_COCOA_OWNER(wxGauge,NSProgressIndicator,NSView,NSView)
33 bool wxGauge::Create(wxWindow *parent, wxWindowID winid, int range,
34 const wxPoint& pos, const wxSize& size, long style,
35 const wxValidator& validator, const wxString& name)
38 wxASSERT_MSG( !(style & wxGA_HORIZONTAL), wxT("Horizontal gauge not supported on cocoa"));//*
39 wxASSERT_MSG( !(style & wxGA_SMOOTH), wxT("Smooth gauge not supported on cocoa"));
40 //* - GNUStep made isVertical and setVertical part of thier framework, but its specific to them
41 //the way they do it is just handle that flag in drawRect.
43 if(!CreateControl(parent,winid,pos,size,style,validator,name))
45 SetNSView([[NSProgressIndicator alloc] initWithFrame: MakeDefaultNSRect(size)]);
46 [m_cocoaNSView release];
48 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:range];
49 [(NSProgressIndicator*)m_cocoaNSView setIndeterminate:NO];
52 m_parent->CocoaAddChild(this);
53 SetInitialFrameRect(pos,size);
62 int wxGauge::GetValue() const
64 return (int)[(NSProgressIndicator*)m_cocoaNSView doubleValue];
67 void wxGauge::SetValue(int value)
69 [(NSProgressIndicator*)m_cocoaNSView setDoubleValue:value];
72 int wxGauge::GetRange() const
74 return (int)[(NSProgressIndicator*)m_cocoaNSView maxValue];
77 void wxGauge::SetRange(int maxValue)
79 [(NSProgressIndicator*)m_cocoaNSView setMinValue:0.0];
80 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:maxValue];
83 // NSProgressIndicator is not an NSControl but does respond to
84 // sizeToFit on OS X >= 10.2
85 wxSize wxGauge::DoGetBestSize() const
87 wxAutoNSAutoreleasePool pool;
88 wxASSERT(GetNSProgressIndicator());
89 NSRect storedRect = [m_cocoaNSView frame];
92 [GetNSProgressIndicator() sizeToFit];
95 // TODO: if anything other than method not implemented, re-raise
99 NSRect cocoaRect = [m_cocoaNSView frame];
100 wxSize size((int)ceilf(cocoaRect.size.width),(int)ceilf(cocoaRect.size.height));
101 [m_cocoaNSView setFrame: storedRect];
102 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxControl=%p::DoGetBestSize()==(%d,%d) from sizeToFit"),this,size.x,size.y);
103 return /*wxConstCast(this, wxControl)->m_bestSize =*/ size;
105 // Cocoa can't tell us the size
106 float height = NSProgressIndicatorPreferredAquaThickness;
107 return wxSize((int)(height*2),(int)height);
110 #endif // wxUSE_GAUGE