]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/gauge.mm
todos, cleanups, detabified
[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{
37 if(!CreateControl(parent,winid,pos,size,style,validator,name))
38 return false;
8d656ea9 39 SetNSView([[NSProgressIndicator alloc] initWithFrame: MakeDefaultNSRect(size)]);
24e97652 40 [m_cocoaNSView release];
363f7de0
DE
41
42 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:range];
43 [(NSProgressIndicator*)m_cocoaNSView setIndeterminate:NO];
44
24e97652
DE
45 if(m_parent)
46 m_parent->CocoaAddChild(this);
8d656ea9
DE
47 SetInitialFrameRect(pos,size);
48
24e97652
DE
49 return true;
50}
51
52wxGauge::~wxGauge()
53{
54}
55
363f7de0
DE
56int wxGauge::GetValue() const
57{
2108cc97 58 return (int)[(NSProgressIndicator*)m_cocoaNSView doubleValue];
363f7de0
DE
59}
60
61void wxGauge::SetValue(int value)
62{
63 [(NSProgressIndicator*)m_cocoaNSView setDoubleValue:value];
64}
65
66int wxGauge::GetRange() const
67{
2108cc97 68 return (int)[(NSProgressIndicator*)m_cocoaNSView maxValue];
363f7de0
DE
69}
70
71void wxGauge::SetRange(int maxValue)
72{
73 [(NSProgressIndicator*)m_cocoaNSView setMinValue:0.0];
74 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:maxValue];
75}
76
15bc1a64
DE
77// NSProgressIndicator is not an NSControl but does respond to
78// sizeToFit on OS X >= 10.2
79wxSize wxGauge::DoGetBestSize() const
80{
81 wxAutoNSAutoreleasePool pool;
82 wxASSERT(GetNSProgressIndicator());
83 NSRect storedRect = [m_cocoaNSView frame];
84 bool didFit = false;
85NS_DURING
86 [GetNSProgressIndicator() sizeToFit];
87 didFit = true;
88NS_HANDLER
89 // TODO: if anything other than method not implemented, re-raise
90NS_ENDHANDLER
91 if(didFit)
92 {
93 NSRect cocoaRect = [m_cocoaNSView frame];
94 wxSize size((int)ceilf(cocoaRect.size.width),(int)ceilf(cocoaRect.size.height));
95 [m_cocoaNSView setFrame: storedRect];
96 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxControl=%p::DoGetBestSize()==(%d,%d) from sizeToFit"),this,size.x,size.y);
97 return /*wxConstCast(this, wxControl)->m_bestSize =*/ size;
98 }
99 // Cocoa can't tell us the size
100 float height = NSProgressIndicatorPreferredAquaThickness;
101 return wxSize((int)(height*2),(int)height);
102}
103
24e97652 104#endif // wxUSE_GAUGE