]> git.saurik.com Git - wxWidgets.git/commitdiff
Use PBM_SETMARQUEE to implement indeterminate mode in wxMSW wxGauge.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Jun 2010 17:43:02 +0000 (17:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Jun 2010 17:43:02 +0000 (17:43 +0000)
The old code which simply used PBM_SETPOS after setting PBS_MARQUEE style
often worked but sometimes apparently didn't, so switch to the officially
sanctioned PBM_SETMARQUEE to implement this.

Also make wxGauge::SetDeterminateMode() and SetIndeterminateMode() methods
private as they are not part of the public class API.

Closes #11357.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64648 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/gauge.h
samples/widgets/gauge.cpp
src/msw/gauge.cpp

index ff9d42d151dbc40b17d8d1ee0a994a02d920be9d..69682c7afb9ee42a3e8d1bf0cdd96e98b47ee47b 100644 (file)
@@ -51,10 +51,7 @@ public:
     virtual bool SetForegroundColour(const wxColour& col);
     virtual bool SetBackgroundColour(const wxColour& col);
 
     virtual bool SetForegroundColour(const wxColour& col);
     virtual bool SetBackgroundColour(const wxColour& col);
 
-
-    void SetIndeterminateMode();
-    void SetDeterminateMode();
-    void Pulse();
+    virtual void Pulse();
 
     WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
 
 
     WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
 
@@ -64,6 +61,15 @@ public:
 protected:
     virtual wxSize DoGetBestSize() const;
 
 protected:
     virtual wxSize DoGetBestSize() const;
 
+private:
+    // returns true if the control is currently in indeterminate (a.k.a.
+    // "marquee") mode
+    bool IsInIndeterminateMode() const;
+
+    // switch to/from indeterminate mode
+    void SetIndeterminateMode();
+    void SetDeterminateMode();
+
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxGauge)
 };
 
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxGauge)
 };
 
index 011702d0c31e20fdaa1cd9a4c9beb46a4b97d27f..6daef590da17d2b6847b4f28c3f6924d02201dbf 100644 (file)
@@ -389,6 +389,8 @@ void GaugeWidgetsPage::OnButtonIndeterminateProgress(wxCommandEvent& event)
     {
         StopTimer(b);
 
     {
         StopTimer(b);
 
+        m_gauge->SetValue(0);
+
         wxLogMessage(wxT("Stopped the timer."));
     }
 }
         wxLogMessage(wxT("Stopped the timer."));
     }
 }
index 1fcc481c80514535790163230f8fa38d4d8c07e0..69286856bcdff214d70fde48306201ad5e563cbb 100644 (file)
@@ -193,8 +193,9 @@ wxSize wxGauge::DoGetBestSize() const
 
 void wxGauge::SetRange(int r)
 {
 
 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;
 
 
     m_rangeMax = r;
 
@@ -208,16 +209,16 @@ void wxGauge::SetRange(int r)
 
 void wxGauge::SetValue(int pos)
 {
 
 void wxGauge::SetValue(int pos)
 {
-    // Setting the (same) position produces flicker on Vista,
-    // especially noticable if ownerdrawn
-    if (GetValue() == pos) return;
+    // Setting the value implicitly means that we're using determinate mode.
+    if ( IsInIndeterminateMode() )
+        SetDeterminateMode();
 
 
-    // switch to determinate mode if required
-    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)
 }
 
 bool wxGauge::SetForegroundColour(const wxColour& col)
@@ -240,24 +241,30 @@ bool wxGauge::SetBackgroundColour(const wxColour& col)
     return true;
 }
 
     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()
 {
 }
 
 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);
         ::SetWindowLong(GetHwnd(), GWL_STYLE, style & ~PBS_MARQUEE);
-
-    // now the control can only run in determinate mode
+    }
 }
 
 void wxGauge::Pulse()
 }
 
 void wxGauge::Pulse()
@@ -267,10 +274,7 @@ void wxGauge::Pulse()
         // switch to indeterminate mode if required
         SetIndeterminateMode();
 
         // 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
     {
     }
     else
     {