]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/gauge.mm
Add implementation of Objective-C class name uniquifying.
[wxWidgets.git] / src / cocoa / gauge.mm
CommitLineData
24e97652 1/////////////////////////////////////////////////////////////////////////////
9d2c19f1 2// Name: src/cocoa/gauge.mm
24e97652
DE
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
9d2c19f1 9// Licence: wxWidgets licence
24e97652
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673 12#include "wx/wxprec.h"
9d2c19f1 13
24e97652
DE
14#if wxUSE_GAUGE
15
9d2c19f1
WS
16#include "wx/gauge.h"
17
449c5673
DE
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
15bc1a64 20 #include "wx/log.h"
449c5673 21#endif //WX_PRECOMP
24e97652 22
15bc1a64
DE
23#include "wx/cocoa/autorelease.h"
24
24e97652 25#import <AppKit/NSProgressIndicator.h>
15bc1a64
DE
26#import <Foundation/NSException.h>
27
28#include <math.h>
24e97652
DE
29
30IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
9d2c19f1 31
24e97652
DE
32BEGIN_EVENT_TABLE(wxGauge, wxGaugeBase)
33END_EVENT_TABLE()
34// WX_IMPLEMENT_COCOA_OWNER(wxGauge,NSProgressIndicator,NSView,NSView)
35
36bool wxGauge::Create(wxWindow *parent, wxWindowID winid, int range,
37 const wxPoint& pos, const wxSize& size, long style,
38 const wxValidator& validator, const wxString& name)
39{
f22c3fa8 40 // NOTE: wxGA_SMOOTH flag is simply ignored (gauges are ALWAYS smooth)
24e97652
DE
41 if(!CreateControl(parent,winid,pos,size,style,validator,name))
42 return false;
8d656ea9 43 SetNSView([[NSProgressIndicator alloc] initWithFrame: MakeDefaultNSRect(size)]);
24e97652 44 [m_cocoaNSView release];
363f7de0 45
f22c3fa8
DE
46 // TODO: DoGetBestSize is likely totally wrong for vertical gauges but
47 // this actually makes the widgets sample work so it's better than nothing.
48 if(style & wxGA_VERTICAL)
49 {
2e11bb42 50 wxLogDebug(wxT("wxGA_VERTICAL may not work correctly. See src/cocoa/gauge.mm"));
f22c3fa8
DE
51 [m_cocoaNSView setBoundsRotation:-90.0];
52 }
53
363f7de0
DE
54 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:range];
55 [(NSProgressIndicator*)m_cocoaNSView setIndeterminate:NO];
56
24e97652
DE
57 if(m_parent)
58 m_parent->CocoaAddChild(this);
8d656ea9
DE
59 SetInitialFrameRect(pos,size);
60
24e97652
DE
61 return true;
62}
63
64wxGauge::~wxGauge()
65{
66}
67
363f7de0
DE
68int wxGauge::GetValue() const
69{
2108cc97 70 return (int)[(NSProgressIndicator*)m_cocoaNSView doubleValue];
363f7de0
DE
71}
72
73void wxGauge::SetValue(int value)
74{
75 [(NSProgressIndicator*)m_cocoaNSView setDoubleValue:value];
76}
77
78int wxGauge::GetRange() const
79{
2108cc97 80 return (int)[(NSProgressIndicator*)m_cocoaNSView maxValue];
363f7de0
DE
81}
82
83void wxGauge::SetRange(int maxValue)
84{
85 [(NSProgressIndicator*)m_cocoaNSView setMinValue:0.0];
86 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:maxValue];
87}
88
15bc1a64
DE
89// NSProgressIndicator is not an NSControl but does respond to
90// sizeToFit on OS X >= 10.2
91wxSize wxGauge::DoGetBestSize() const
92{
93 wxAutoNSAutoreleasePool pool;
94 wxASSERT(GetNSProgressIndicator());
95 NSRect storedRect = [m_cocoaNSView frame];
96 bool didFit = false;
97NS_DURING
98 [GetNSProgressIndicator() sizeToFit];
99 didFit = true;
100NS_HANDLER
101 // TODO: if anything other than method not implemented, re-raise
102NS_ENDHANDLER
103 if(didFit)
104 {
105 NSRect cocoaRect = [m_cocoaNSView frame];
c05c7cb5 106 wxSize size((int)ceil(cocoaRect.size.width),(int)ceil(cocoaRect.size.height));
15bc1a64
DE
107 [m_cocoaNSView setFrame: storedRect];
108 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxControl=%p::DoGetBestSize()==(%d,%d) from sizeToFit"),this,size.x,size.y);
109 return /*wxConstCast(this, wxControl)->m_bestSize =*/ size;
110 }
111 // Cocoa can't tell us the size
112 float height = NSProgressIndicatorPreferredAquaThickness;
113 return wxSize((int)(height*2),(int)height);
114}
115
24e97652 116#endif // wxUSE_GAUGE