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