]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/gauge.mm
Solaris fix is in config.py now
[wxWidgets.git] / src / cocoa / gauge.mm
CommitLineData
24e97652
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: cocoa/gauge.mm
3// Purpose: wxGauge
4// Author: David Elliott
5// Modified by:
6// Created: 2003/07/15
7// RCS-ID: $Id$
8// Copyright: (c) 2003 David Elliott
065e208e 9// Licence: wxWidgets licence
24e97652
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673 12#include "wx/wxprec.h"
24e97652
DE
13#if wxUSE_GAUGE
14
449c5673
DE
15#ifndef WX_PRECOMP
16 #include "wx/app.h"
17 #include "wx/gauge.h"
15bc1a64 18 #include "wx/log.h"
449c5673 19#endif //WX_PRECOMP
24e97652 20
15bc1a64
DE
21#include "wx/cocoa/autorelease.h"
22
24e97652 23#import <AppKit/NSProgressIndicator.h>
15bc1a64
DE
24#import <Foundation/NSException.h>
25
26#include <math.h>
24e97652
DE
27
28IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
29BEGIN_EVENT_TABLE(wxGauge, wxGaugeBase)
30END_EVENT_TABLE()
31// WX_IMPLEMENT_COCOA_OWNER(wxGauge,NSProgressIndicator,NSView,NSView)
32
33bool wxGauge::Create(wxWindow *parent, wxWindowID winid, int range,
34 const wxPoint& pos, const wxSize& size, long style,
35 const wxValidator& validator, const wxString& name)
36{
571b0b13
RN
37 //flag checking
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.
42
24e97652
DE
43 if(!CreateControl(parent,winid,pos,size,style,validator,name))
44 return false;
8d656ea9 45 SetNSView([[NSProgressIndicator alloc] initWithFrame: MakeDefaultNSRect(size)]);
24e97652 46 [m_cocoaNSView release];
363f7de0
DE
47
48 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:range];
49 [(NSProgressIndicator*)m_cocoaNSView setIndeterminate:NO];
50
24e97652
DE
51 if(m_parent)
52 m_parent->CocoaAddChild(this);
8d656ea9
DE
53 SetInitialFrameRect(pos,size);
54
24e97652
DE
55 return true;
56}
57
58wxGauge::~wxGauge()
59{
60}
61
363f7de0
DE
62int wxGauge::GetValue() const
63{
2108cc97 64 return (int)[(NSProgressIndicator*)m_cocoaNSView doubleValue];
363f7de0
DE
65}
66
67void wxGauge::SetValue(int value)
68{
69 [(NSProgressIndicator*)m_cocoaNSView setDoubleValue:value];
70}
71
72int wxGauge::GetRange() const
73{
2108cc97 74 return (int)[(NSProgressIndicator*)m_cocoaNSView maxValue];
363f7de0
DE
75}
76
77void wxGauge::SetRange(int maxValue)
78{
79 [(NSProgressIndicator*)m_cocoaNSView setMinValue:0.0];
80 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:maxValue];
81}
82
15bc1a64
DE
83// NSProgressIndicator is not an NSControl but does respond to
84// sizeToFit on OS X >= 10.2
85wxSize wxGauge::DoGetBestSize() const
86{
87 wxAutoNSAutoreleasePool pool;
88 wxASSERT(GetNSProgressIndicator());
89 NSRect storedRect = [m_cocoaNSView frame];
90 bool didFit = false;
91NS_DURING
92 [GetNSProgressIndicator() sizeToFit];
93 didFit = true;
94NS_HANDLER
95 // TODO: if anything other than method not implemented, re-raise
96NS_ENDHANDLER
97 if(didFit)
98 {
99 NSRect cocoaRect = [m_cocoaNSView frame];
c05c7cb5 100 wxSize size((int)ceil(cocoaRect.size.width),(int)ceil(cocoaRect.size.height));
15bc1a64
DE
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;
104 }
105 // Cocoa can't tell us the size
106 float height = NSProgressIndicatorPreferredAquaThickness;
107 return wxSize((int)(height*2),(int)height);
108}
109
24e97652 110#endif // wxUSE_GAUGE