X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/09981ba7981297056da49ceb0eb85d3ac9fc5f6f..46405e36bf9962b251e77e5048e96bf6a54edb15:/src/msw/gauge.cpp diff --git a/src/msw/gauge.cpp b/src/msw/gauge.cpp index 1045bffc61..69286856bc 100644 --- a/src/msw/gauge.cpp +++ b/src/msw/gauge.cpp @@ -177,12 +177,14 @@ WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const wxSize wxGauge::DoGetBestSize() const { - // VZ: no idea where does 28 come from, it was there before my changes and - // as nobody ever complained I guess we can leave it... + // Windows HIG (http://msdn.microsoft.com/en-us/library/aa511279.aspx) + // suggest progress bar size of "107 or 237 x 8 dialog units". Let's use + // the smaller one. + if (HasFlag(wxGA_VERTICAL)) - return wxSize(28, 100); + return ConvertDialogToPixels(wxSize(8, 107)); else - return wxSize(100, 28); + return ConvertDialogToPixels(wxSize(107, 8)); } // ---------------------------------------------------------------------------- @@ -191,8 +193,9 @@ wxSize wxGauge::DoGetBestSize() const void wxGauge::SetRange(int r) { - // switch to determinate mode if required - SetDeterminateMode(); + // Changing range implicitly means we're using determinate mode. + if ( IsInIndeterminateMode() ) + SetDeterminateMode(); m_rangeMax = r; @@ -206,16 +209,16 @@ void wxGauge::SetRange(int r) void wxGauge::SetValue(int pos) { - // Setting the (same) position produces flicker on Vista, - // especially noticable if ownerdrawn - if (GetValue() == pos) return; - - // switch to determinate mode if required - SetDeterminateMode(); + // Setting the value implicitly means that we're using determinate mode. + if ( IsInIndeterminateMode() ) + SetDeterminateMode(); - m_gaugePos = pos; + if ( GetValue() != pos ) + { + m_gaugePos = pos; - ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0); + ::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0); + } } bool wxGauge::SetForegroundColour(const wxColour& col) @@ -238,24 +241,30 @@ bool wxGauge::SetBackgroundColour(const wxColour& col) return true; } -void wxGauge::SetIndeterminateMode() +bool wxGauge::IsInIndeterminateMode() const { - // add the PBS_MARQUEE style to the progress bar - LONG style = ::GetWindowLong(GetHwnd(), GWL_STYLE); - if ((style & PBS_MARQUEE) == 0) - ::SetWindowLong(GetHwnd(), GWL_STYLE, style|PBS_MARQUEE); + return (::GetWindowLong(GetHwnd(), GWL_STYLE) & PBS_MARQUEE) != 0; +} - // now the control can only run in indeterminate mode +void wxGauge::SetIndeterminateMode() +{ + // Switch the control into indeterminate mode if necessary. + if ( !IsInIndeterminateMode() ) + { + const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); + ::SetWindowLong(GetHwnd(), GWL_STYLE, style | PBS_MARQUEE); + ::SendMessage(GetHwnd(), PBM_SETMARQUEE, TRUE, 0); + } } void wxGauge::SetDeterminateMode() { - // remove the PBS_MARQUEE style to the progress bar - LONG style = ::GetWindowLong(GetHwnd(), GWL_STYLE); - if ((style & PBS_MARQUEE) != 0) + if ( IsInIndeterminateMode() ) + { + const long style = ::GetWindowLong(GetHwnd(), GWL_STYLE); + ::SendMessage(GetHwnd(), PBM_SETMARQUEE, FALSE, 0); ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE); - - // now the control can only run in determinate mode + } } void wxGauge::Pulse() @@ -265,10 +274,7 @@ void wxGauge::Pulse() // switch to indeterminate mode if required SetIndeterminateMode(); - // NOTE: when in indeterminate mode, the PBM_SETPOS message will just make - // the bar's blocks move a bit and the WPARAM value is just ignored - // so that we can safely use zero - SendMessage(GetHwnd(), (UINT) PBM_SETPOS, (WPARAM)0, (LPARAM)0); + SendMessage(GetHwnd(), PBM_STEPIT, 0, 0); } else {