From ef78ec37f2472232e0daab83b37380e9cb1eee24 Mon Sep 17 00:00:00 2001 From: Kevin Ollivier Date: Sat, 9 Sep 2006 18:11:48 +0000 Subject: [PATCH] Mac(Carbon) impl of wxGauge::Pulse, also added sample code for Pulse to the widgets sample. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41103 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/gauge.cpp | 14 ++++++++++++-- src/mac/carbon/gauge.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/samples/widgets/gauge.cpp b/samples/widgets/gauge.cpp index 7093f874c4..3f80544e5f 100644 --- a/samples/widgets/gauge.cpp +++ b/samples/widgets/gauge.cpp @@ -115,7 +115,8 @@ protected: // the checkboxes for styles wxCheckBox *m_chkVert, - *m_chkSmooth; + *m_chkSmooth, + *m_chkIndeterminate; // the gauge itself and the sizer it is in wxGauge *m_gauge; @@ -178,7 +179,8 @@ GaugeWidgetsPage::GaugeWidgetsPage(WidgetsBookCtrl *book, m_timer = (wxTimer *)NULL; m_chkVert = - m_chkSmooth = (wxCheckBox *)NULL; + m_chkSmooth = + m_chkIndeterminate = (wxCheckBox *)NULL; m_gauge = (wxGauge *)NULL; m_sizerGauge = (wxSizer *)NULL; @@ -195,6 +197,7 @@ void GaugeWidgetsPage::CreateContent() m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Vertical")); m_chkSmooth = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Smooth")); + m_chkIndeterminate = CreateCheckBoxAndAddToSizer(sizerLeft, _T("&Indeterminate")); sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer @@ -266,6 +269,7 @@ void GaugeWidgetsPage::Reset() { m_chkVert->SetValue(false); m_chkSmooth->SetValue(false); + m_chkIndeterminate->SetValue(false); } void GaugeWidgetsPage::CreateGauge() @@ -293,6 +297,10 @@ void GaugeWidgetsPage::CreateGauge() wxDefaultPosition, wxDefaultSize, flags); m_gauge->SetValue(val); + + if ( m_chkIndeterminate->GetValue() ){ + m_gauge->Pulse(); + } if ( flags & wxGA_VERTICAL ) m_sizerGauge->Add(m_gauge, 0, wxGROW | wxALL, 5); @@ -348,6 +356,7 @@ void GaugeWidgetsPage::OnButtonSetRange(wxCommandEvent& WXUNUSED(event)) m_range = val; m_gauge->SetRange(val); + m_chkIndeterminate->SetValue(0); } void GaugeWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event)) @@ -357,6 +366,7 @@ void GaugeWidgetsPage::OnButtonSetValue(wxCommandEvent& WXUNUSED(event)) return; m_gauge->SetValue(val); + m_chkIndeterminate->SetValue(0); } void GaugeWidgetsPage::OnUpdateUIValueButton(wxUpdateUIEvent& event) diff --git a/src/mac/carbon/gauge.cpp b/src/mac/carbon/gauge.cpp index 531cf003f3..3793d8ed60 100644 --- a/src/mac/carbon/gauge.cpp +++ b/src/mac/carbon/gauge.cpp @@ -60,8 +60,15 @@ void wxGauge::SetRange(int r) // we are going via the base class in case there is // some change behind the values by it wxGaugeBase::SetRange( r ) ; - if ( m_peer && m_peer->Ok() ) + if ( m_peer && m_peer->Ok() ){ + // switch back to determinate mode if not there already + if ( m_peer->GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) + { + m_peer->SetData( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); + } + m_peer->SetMaximum( GetRange() ) ; + } } void wxGauge::SetValue(int pos) @@ -72,6 +79,12 @@ void wxGauge::SetValue(int pos) if ( m_peer && m_peer->Ok() ) { + // switch back to determinate mode if not there already + if ( m_peer->GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != false ) + { + m_peer->SetData( kControlNoPart, kControlProgressBarIndeterminateTag, (Boolean)false ); + } + m_peer->SetValue( GetValue() ) ; // turn off animation in the unnecessary situations as this is consuming a lot of CPU otherwise @@ -99,7 +112,15 @@ void wxGauge::Pulse() { if ( m_peer && m_peer->Ok() ) { - // need to use the animate() method of NSProgressIndicator Class here + if ( m_peer->GetData( kControlNoPart, kControlProgressBarIndeterminateTag ) != true ) + { + m_peer->SetData( kControlNoPart, kControlProgressBarIndeterminateTag, true); + } + + if ( m_peer->GetData( kControlEntireControl, kControlProgressBarAnimatingTag ) != true ) + { + m_peer->SetData( kControlEntireControl, kControlProgressBarAnimatingTag, true ) ; + } } } -- 2.45.2