1///////////////////////////////////////////////////////////////////////////// 2// Name: src/osx/cocoa/gauge.mm 3// Purpose: wxGauge class 4// Author: Stefan Csomor 5// Modified by: 6// Created: 1998-01-01 7// Copyright: (c) Stefan Csomor 8// Licence: wxWindows licence 9///////////////////////////////////////////////////////////////////////////// 10 11#include "wx/wxprec.h" 12 13#if wxUSE_GAUGE 14 15#include "wx/gauge.h" 16 17#include "wx/osx/private.h" 18 19@interface wxNSProgressIndicator : NSProgressIndicator 20{ 21} 22 23@end 24 25@implementation wxNSProgressIndicator 26 27+ (void)initialize 28{ 29 static BOOL initialized = NO; 30 if (!initialized) 31 { 32 initialized = YES; 33 wxOSXCocoaClassAddWXMethods( self ); 34 } 35} 36 37@end 38 39@interface NSView(PossibleSizeMethods) 40- (NSControlSize)controlSize; 41@end 42 43namespace 44{ 45 46class wxOSXGaugeCocoaImpl : public wxWidgetCocoaImpl 47{ 48public : 49 wxOSXGaugeCocoaImpl( wxWindowMac* peer, WXWidget w) : wxWidgetCocoaImpl( peer, w ) 50 { 51 } 52 53 void SetMaximum(wxInt32 v) wxOVERRIDE 54 { 55 SetDeterminateMode(); 56 wxWidgetCocoaImpl::SetMaximum( v ) ; 57 } 58 59 void SetValue(wxInt32 v) wxOVERRIDE 60 { 61 SetDeterminateMode(); 62 wxWidgetCocoaImpl::SetValue( v ) ; 63 } 64 65 void PulseGauge() wxOVERRIDE 66 { 67 if ( ![(wxNSProgressIndicator*)m_osxView isIndeterminate] ) 68 { 69 [(wxNSProgressIndicator*)m_osxView setIndeterminate:YES]; 70 [(wxNSProgressIndicator*)m_osxView startAnimation:nil]; 71 } 72 } 73 74 void GetLayoutInset(int &left , int &top , int &right, int &bottom) const wxOVERRIDE 75 { 76 left = top = right = bottom = 0; 77 NSControlSize size = [(wxNSProgressIndicator*)m_osxView controlSize]; 78 79 switch( size ) 80 { 81#if __MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_16 82 case NSControlSizeLarge: 83#endif 84 case NSRegularControlSize: 85 left = right = 2; 86 top = 0; 87 bottom = 3; 88 break; 89 case NSMiniControlSize: 90 case NSSmallControlSize: 91 left = right = 1; 92 top = 0; 93 bottom = 1; 94 break; 95 } 96 } 97protected: 98 void SetDeterminateMode() 99 { 100 // switch back to determinate mode if necessary 101 if ( [(wxNSProgressIndicator*)m_osxView isIndeterminate] ) 102 { 103 [(wxNSProgressIndicator*)m_osxView stopAnimation:nil]; 104 [(wxNSProgressIndicator*)m_osxView setIndeterminate:NO]; 105 } 106 } 107}; 108 109} // anonymous namespace 110 111wxWidgetImplType* wxWidgetImpl::CreateGauge( wxWindowMac* wxpeer, 112 wxWindowMac* WXUNUSED(parent), 113 wxWindowID WXUNUSED(id), 114 wxInt32 value, 115 wxInt32 minimum, 116 wxInt32 maximum, 117 const wxPoint& pos, 118 const wxSize& size, 119 long style, 120 long WXUNUSED(extraStyle)) 121{ 122 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ; 123 wxNSProgressIndicator* v = [[wxNSProgressIndicator alloc] initWithFrame:r]; 124 125 [v setMinValue: minimum]; 126 [v setMaxValue: maximum]; 127 [v setIndeterminate:FALSE]; 128 [v setDoubleValue: (double) value]; 129 if (style & wxGA_VERTICAL) 130 { 131 [v setBoundsRotation:-90.0]; 132 } 133 wxWidgetCocoaImpl* c = new wxOSXGaugeCocoaImpl( wxpeer, v ); 134 return c; 135} 136 137#endif // wxUSE_GAUGE 138 139