]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/gauge.mm
Don't try to open clipboard if already open
[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{
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