]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/gauge.mm
Fix wxHtmlHelpData::SetTempDir() to behave correctly without trailing slash.
[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
24e97652 7// Copyright: (c) 2003 David Elliott
526954c5 8// Licence: wxWindows licence
24e97652
DE
9/////////////////////////////////////////////////////////////////////////////
10
449c5673 11#include "wx/wxprec.h"
9d2c19f1 12
24e97652
DE
13#if wxUSE_GAUGE
14
9d2c19f1
WS
15#include "wx/gauge.h"
16
449c5673
DE
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
15bc1a64 19 #include "wx/log.h"
449c5673 20#endif //WX_PRECOMP
24e97652 21
15bc1a64
DE
22#include "wx/cocoa/autorelease.h"
23
24e97652 24#import <AppKit/NSProgressIndicator.h>
15bc1a64
DE
25#import <Foundation/NSException.h>
26
27#include <math.h>
24e97652 28
24e97652
DE
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{
f22c3fa8 37 // NOTE: wxGA_SMOOTH flag is simply ignored (gauges are ALWAYS smooth)
24e97652
DE
38 if(!CreateControl(parent,winid,pos,size,style,validator,name))
39 return false;
8d656ea9 40 SetNSView([[NSProgressIndicator alloc] initWithFrame: MakeDefaultNSRect(size)]);
24e97652 41 [m_cocoaNSView release];
363f7de0 42
f22c3fa8
DE
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 {
2e11bb42 47 wxLogDebug(wxT("wxGA_VERTICAL may not work correctly. See src/cocoa/gauge.mm"));
f22c3fa8
DE
48 [m_cocoaNSView setBoundsRotation:-90.0];
49 }
50
363f7de0
DE
51 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:range];
52 [(NSProgressIndicator*)m_cocoaNSView setIndeterminate:NO];
53
24e97652
DE
54 if(m_parent)
55 m_parent->CocoaAddChild(this);
8d656ea9
DE
56 SetInitialFrameRect(pos,size);
57
24e97652
DE
58 return true;
59}
60
61wxGauge::~wxGauge()
62{
63}
64
363f7de0
DE
65int wxGauge::GetValue() const
66{
2108cc97 67 return (int)[(NSProgressIndicator*)m_cocoaNSView doubleValue];
363f7de0
DE
68}
69
70void wxGauge::SetValue(int value)
71{
72 [(NSProgressIndicator*)m_cocoaNSView setDoubleValue:value];
73}
74
75int wxGauge::GetRange() const
76{
2108cc97 77 return (int)[(NSProgressIndicator*)m_cocoaNSView maxValue];
363f7de0
DE
78}
79
80void wxGauge::SetRange(int maxValue)
81{
82 [(NSProgressIndicator*)m_cocoaNSView setMinValue:0.0];
83 [(NSProgressIndicator*)m_cocoaNSView setMaxValue:maxValue];
84}
85
15bc1a64
DE
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];
c05c7cb5 103 wxSize size((int)ceil(cocoaRect.size.width),(int)ceil(cocoaRect.size.height));
15bc1a64
DE
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
24e97652 113#endif // wxUSE_GAUGE