Intergrate wxAppProgressIndicator into wxGuage.
Update the progress bar of taskbar button if wxGuage has wxGA_PROGRESS style. Author: Chaobin Zhang git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77631 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -29,6 +29,10 @@
|
||||
// QT only, display current completed percentage (text default format "%p%")
|
||||
#define wxGA_TEXT 0x0040
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
#define wxGA_PROGRESS 0x0010
|
||||
#endif
|
||||
|
||||
// GTK and Mac always have native implementation of the indeterminate mode
|
||||
// wxMSW has native implementation only if comctl32.dll >= 6.00
|
||||
#if !defined(__WXGTK20__) && !defined(__WXMAC__)
|
||||
|
@@ -15,6 +15,10 @@
|
||||
|
||||
extern WXDLLIMPEXP_DATA_CORE(const char) wxGaugeNameStr[];
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
class WXDLLIMPEXP_FWD_CORE wxAppProgressIndicator;
|
||||
#endif
|
||||
|
||||
// Group box
|
||||
class WXDLLIMPEXP_CORE wxGauge : public wxGaugeBase
|
||||
{
|
||||
@@ -33,6 +37,10 @@ public:
|
||||
(void)Create(parent, id, range, pos, size, style, validator, name);
|
||||
}
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
virtual ~wxGauge();
|
||||
#endif
|
||||
|
||||
bool Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
int range,
|
||||
@@ -69,6 +77,10 @@ private:
|
||||
void SetIndeterminateMode();
|
||||
void SetDeterminateMode();
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
wxAppProgressIndicator* m_appProgressIndicator;
|
||||
#endif
|
||||
|
||||
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGauge)
|
||||
};
|
||||
|
||||
|
@@ -130,17 +130,17 @@ private:
|
||||
class WXDLLIMPEXP_CORE wxAppProgressIndicator
|
||||
{
|
||||
public:
|
||||
wxAppProgressIndicator(wxTopLevelWindow *parent, int maxValue);
|
||||
wxAppProgressIndicator(WXWidget parent, int maxValue);
|
||||
virtual ~wxAppProgressIndicator();
|
||||
bool Update(int value);
|
||||
bool Pulse();
|
||||
void SetValue(int value);
|
||||
void SetRange(int range);
|
||||
void Pulse();
|
||||
void Reset();
|
||||
|
||||
private:
|
||||
void Init();
|
||||
|
||||
wxTopLevelWindow *m_parent;
|
||||
int m_maxValue;
|
||||
wxScopedPtr<wxTaskBarButton> m_taskBarButton;
|
||||
WXWidget m_parent;
|
||||
wxTaskBarButton* m_taskBarButton;
|
||||
};
|
||||
|
||||
enum WXDLLIMPEXP_CORE wxTaskBarJumpListItemType
|
||||
|
@@ -33,8 +33,6 @@ enum
|
||||
RestoreThumbnailClipBtn,
|
||||
AddThumbBarButtonBtn,
|
||||
RemoveThumbBarButtonBtn,
|
||||
ShowProgressDialogBtn,
|
||||
PulseProgressDialogBtn,
|
||||
};
|
||||
|
||||
enum
|
||||
@@ -121,8 +119,6 @@ private:
|
||||
void OnAddThubmBarButton(wxCommandEvent& WXUNUSED(event));
|
||||
void OnRemoveThubmBarButton(wxCommandEvent& WXUNUSED(event));
|
||||
void OnThumbnailToolbarBtnClicked(wxCommandEvent& event);
|
||||
void OnShowProgressDialog(wxCommandEvent& WXUNUSED(event));
|
||||
void OnPulseProgressDialog(wxCommandEvent& WXUNUSED(event));
|
||||
|
||||
wxSlider *m_slider;
|
||||
wxRadioBox *m_visibilityRadioBox;
|
||||
@@ -286,16 +282,6 @@ MyFrame::MyFrame(const wxString& title)
|
||||
ttbSizer->Add(addThumbBarButtonBtn, 1, wxEXPAND | wxALL, 2);
|
||||
ttbSizer->Add(showThumbnailToolbarBtn, 1, wxEXPAND | wxALL, 2);
|
||||
|
||||
// wxAppProgressIndicator section.
|
||||
wxStaticBoxSizer *indicatorSizer =
|
||||
new wxStaticBoxSizer(wxVERTICAL, panel, wxT("wxAppProgressIndicator"));
|
||||
wxButton *showProgressDialogBtn =
|
||||
new wxButton(panel, ShowProgressDialogBtn, wxT("Show Progress dialog"));
|
||||
wxButton *pulseProgressDialigBtn =
|
||||
new wxButton(panel, PulseProgressDialogBtn, wxT("Pulse Progress dialog"));
|
||||
indicatorSizer->Add(showProgressDialogBtn, 1, wxEXPAND | wxALL, 2);
|
||||
indicatorSizer->Add(pulseProgressDialigBtn, 1, wxEXPAND | wxALL, 2);
|
||||
|
||||
gs->Add(spvSizer, 0, wxEXPAND);
|
||||
gs->Add(m_visibilityRadioBox, 0, wxEXPAND);
|
||||
gs->Add(sttSizer, 0, wxEXPAND);
|
||||
@@ -303,7 +289,6 @@ MyFrame::MyFrame(const wxString& title)
|
||||
gs->Add(soiSizer, 0, wxEXPAND);
|
||||
gs->Add(stcSizer, 0, wxEXPAND);
|
||||
gs->Add(ttbSizer, 0, wxEXPAND);
|
||||
gs->Add(indicatorSizer, 0, wxEXPAND);
|
||||
|
||||
wxStaticText *text = new wxStaticText(
|
||||
panel, wxID_ANY, wxT("Welcome to wxTaskBarButton sample"));
|
||||
@@ -328,8 +313,6 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_BUTTON(RestoreThumbnailClipBtn, MyFrame::OnSetOrRestoreThumbnailClip)
|
||||
EVT_BUTTON(AddThumbBarButtonBtn, MyFrame::OnAddThubmBarButton)
|
||||
EVT_BUTTON(RemoveThumbBarButtonBtn, MyFrame::OnRemoveThubmBarButton)
|
||||
EVT_BUTTON(ShowProgressDialogBtn, MyFrame::OnShowProgressDialog)
|
||||
EVT_BUTTON(PulseProgressDialogBtn, MyFrame::OnPulseProgressDialog)
|
||||
EVT_BUTTON(ThumbnailToolbarBtn_0, MyFrame::OnThumbnailToolbarBtnClicked)
|
||||
EVT_BUTTON(ThumbnailToolbarBtn_1, MyFrame::OnThumbnailToolbarBtnClicked)
|
||||
EVT_BUTTON(ThumbnailToolbarBtn_2, MyFrame::OnThumbnailToolbarBtnClicked)
|
||||
@@ -447,43 +430,3 @@ void MyFrame::OnThumbnailToolbarBtnClicked(wxCommandEvent& event)
|
||||
{
|
||||
wxLogMessage("Thumbnail Toolbar Button %d is clicked.", event.GetId());
|
||||
}
|
||||
|
||||
void MyFrame::OnShowProgressDialog(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
const int PROGRESS_COUNT = 100;
|
||||
wxProgressDialog dlg(
|
||||
"Progress in progress",
|
||||
"Please wait, starting...",
|
||||
PROGRESS_COUNT,
|
||||
NULL,
|
||||
wxPD_AUTO_HIDE
|
||||
);
|
||||
wxAppProgressIndicator indicator(this, PROGRESS_COUNT);
|
||||
for ( int i = 0; i <= PROGRESS_COUNT; i++ )
|
||||
{
|
||||
if ( !dlg.Update(i) )
|
||||
break;
|
||||
indicator.Update(i);
|
||||
wxMilliSleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::OnPulseProgressDialog(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
const int PROGRESS_COUNT = 100;
|
||||
wxProgressDialog dlg(
|
||||
"Progress in progress",
|
||||
"Please wait, starting...",
|
||||
PROGRESS_COUNT,
|
||||
NULL,
|
||||
wxPD_AUTO_HIDE
|
||||
);
|
||||
wxAppProgressIndicator indicator(this, PROGRESS_COUNT);
|
||||
for ( int i = 0; i <= PROGRESS_COUNT; i++ )
|
||||
{
|
||||
if ( !dlg.Pulse() )
|
||||
break;
|
||||
indicator.Pulse();
|
||||
wxMilliSleep(50);
|
||||
}
|
||||
}
|
||||
|
@@ -121,7 +121,8 @@ protected:
|
||||
|
||||
// the checkboxes for styles
|
||||
wxCheckBox *m_chkVert,
|
||||
*m_chkSmooth;
|
||||
*m_chkSmooth,
|
||||
*m_chkProgress;
|
||||
|
||||
// the gauge itself and the sizer it is in
|
||||
wxGauge *m_gauge;
|
||||
@@ -186,7 +187,8 @@ GaugeWidgetsPage::GaugeWidgetsPage(WidgetsBookCtrl *book,
|
||||
m_timer = (wxTimer *)NULL;
|
||||
|
||||
m_chkVert =
|
||||
m_chkSmooth = (wxCheckBox *)NULL;
|
||||
m_chkSmooth =
|
||||
m_chkProgress = (wxCheckBox *)NULL;
|
||||
|
||||
m_gauge = (wxGauge *)NULL;
|
||||
m_sizerGauge = (wxSizer *)NULL;
|
||||
@@ -203,6 +205,7 @@ void GaugeWidgetsPage::CreateContent()
|
||||
|
||||
m_chkVert = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Vertical"));
|
||||
m_chkSmooth = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Smooth"));
|
||||
m_chkProgress = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Progress"));
|
||||
|
||||
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
||||
|
||||
@@ -275,6 +278,7 @@ void GaugeWidgetsPage::Reset()
|
||||
{
|
||||
m_chkVert->SetValue(false);
|
||||
m_chkSmooth->SetValue(false);
|
||||
m_chkProgress->SetValue(false);
|
||||
}
|
||||
|
||||
void GaugeWidgetsPage::CreateGauge()
|
||||
@@ -289,6 +293,11 @@ void GaugeWidgetsPage::CreateGauge()
|
||||
if ( m_chkSmooth->GetValue() )
|
||||
flags |= wxGA_SMOOTH;
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
if ( m_chkProgress->GetValue() )
|
||||
flags |= wxGA_PROGRESS;
|
||||
#endif
|
||||
|
||||
int val = 0;
|
||||
if ( m_gauge )
|
||||
{
|
||||
@@ -431,7 +440,8 @@ void GaugeWidgetsPage::OnUpdateUIRangeButton(wxUpdateUIEvent& event)
|
||||
|
||||
void GaugeWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
|
||||
{
|
||||
event.Enable( m_chkVert->GetValue() || m_chkSmooth->GetValue() );
|
||||
event.Enable( m_chkVert->GetValue() || m_chkSmooth->GetValue() ||
|
||||
m_chkProgress->GetValue() );
|
||||
}
|
||||
|
||||
void GaugeWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
|
||||
|
@@ -77,6 +77,9 @@ wxFLAGS_MEMBER(wxHSCROLL)
|
||||
wxFLAGS_MEMBER(wxGA_HORIZONTAL)
|
||||
wxFLAGS_MEMBER(wxGA_VERTICAL)
|
||||
wxFLAGS_MEMBER(wxGA_SMOOTH)
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
wxFLAGS_MEMBER(wxGA_PROGRESS)
|
||||
#endif
|
||||
wxEND_FLAGS( wxGaugeStyle )
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxGauge, wxControl, "wx/gauge.h")
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#endif
|
||||
|
||||
#include "wx/msw/private.h"
|
||||
#include "wx/taskbarbutton.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
@@ -91,14 +92,42 @@ bool wxGauge::Create(wxWindow *parent,
|
||||
if ( !MSWCreateControl(PROGRESS_CLASS, wxEmptyString, pos, size) )
|
||||
return false;
|
||||
|
||||
SetRange(range);
|
||||
|
||||
// in case we need to emulate indeterminate mode...
|
||||
m_nDirection = wxRIGHT;
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
m_appProgressIndicator = NULL;
|
||||
if ( (style & wxGA_PROGRESS) != 0 )
|
||||
{
|
||||
wxWindow* topParent = GetParent();
|
||||
while (topParent != NULL && topParent->GetParent() != NULL)
|
||||
{
|
||||
topParent = topParent->GetParent();
|
||||
}
|
||||
if ( topParent != NULL )
|
||||
{
|
||||
m_appProgressIndicator =
|
||||
new wxAppProgressIndicator(topParent->GetHandle(), range);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SetRange(range);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
wxGauge::~wxGauge()
|
||||
{
|
||||
if ( m_appProgressIndicator )
|
||||
{
|
||||
delete m_appProgressIndicator;
|
||||
m_appProgressIndicator = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
WXDWORD wxGauge::MSWGetStyle(long style, WXDWORD *exstyle) const
|
||||
{
|
||||
WXDWORD msStyle = wxControl::MSWGetStyle(style, exstyle);
|
||||
@@ -146,6 +175,11 @@ void wxGauge::SetRange(int r)
|
||||
// fall back to PBM_SETRANGE (limited to 16 bits)
|
||||
::SendMessage(GetHwnd(), PBM_SETRANGE, 0, MAKELPARAM(0, r));
|
||||
#endif // PBM_SETRANGE32/!PBM_SETRANGE32
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
if ( m_appProgressIndicator )
|
||||
m_appProgressIndicator->SetRange(m_rangeMax);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxGauge::SetValue(int pos)
|
||||
@@ -159,6 +193,17 @@ void wxGauge::SetValue(int pos)
|
||||
m_gaugePos = pos;
|
||||
|
||||
::SendMessage(GetHwnd(), PBM_SETPOS, pos, 0);
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
if ( m_appProgressIndicator )
|
||||
{
|
||||
m_appProgressIndicator->SetValue(pos);
|
||||
if ( pos == 0 )
|
||||
{
|
||||
m_appProgressIndicator->Reset();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +267,11 @@ void wxGauge::Pulse()
|
||||
// emulate indeterminate mode
|
||||
wxGaugeBase::Pulse();
|
||||
}
|
||||
|
||||
#if wxUSE_TASKBARBUTTON
|
||||
if ( m_appProgressIndicator )
|
||||
m_appProgressIndicator->Pulse();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // wxUSE_GAUGE
|
||||
|
@@ -910,45 +910,42 @@ wxThumbBarButton* wxTaskBarButtonImpl::GetThumbBarButtonByIndex(size_t index)
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxAppProgressIndicator Implementation.
|
||||
// ----------------------------------------------------------------------------
|
||||
wxAppProgressIndicator::wxAppProgressIndicator(wxTopLevelWindow *parent,
|
||||
int maxValue)
|
||||
wxAppProgressIndicator::wxAppProgressIndicator(WXWidget parent, int maxValue)
|
||||
: m_parent(parent),
|
||||
m_maxValue(maxValue)
|
||||
{
|
||||
m_taskBarButton = new wxTaskBarButtonImpl(m_parent);
|
||||
Reset();
|
||||
SetRange(m_maxValue);
|
||||
}
|
||||
|
||||
wxAppProgressIndicator::~wxAppProgressIndicator()
|
||||
{
|
||||
m_taskBarButton->SetProgressState(wxTASKBAR_BUTTON_NO_PROGRESS);
|
||||
delete m_taskBarButton;
|
||||
}
|
||||
|
||||
bool wxAppProgressIndicator::Update(int value)
|
||||
void wxAppProgressIndicator::SetValue(int value)
|
||||
{
|
||||
wxASSERT_MSG( value <= m_maxValue, wxT("invalid progress value") );
|
||||
Init();
|
||||
|
||||
m_taskBarButton->SetProgressValue(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxAppProgressIndicator::Pulse()
|
||||
void wxAppProgressIndicator::SetRange(int range)
|
||||
{
|
||||
m_maxValue = range;
|
||||
m_taskBarButton->SetProgressRange(range);
|
||||
}
|
||||
|
||||
void wxAppProgressIndicator::Pulse()
|
||||
{
|
||||
Init();
|
||||
m_taskBarButton->PulseProgress();
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxAppProgressIndicator::Init()
|
||||
void wxAppProgressIndicator::Reset()
|
||||
{
|
||||
if ( m_taskBarButton.get() == NULL )
|
||||
{
|
||||
// Sleep 100 milliseconds to wait for creation of taskbar button.
|
||||
// TODO(zhchbin): Do not use sleep since it will block the UI thread.
|
||||
// Currently it is used to make sure the API works correctlly.
|
||||
wxMilliSleep(100);
|
||||
m_taskBarButton.reset(new wxTaskBarButtonImpl(m_parent->GetHandle()));
|
||||
m_taskBarButton->SetProgressRange(m_maxValue);
|
||||
}
|
||||
m_taskBarButton->SetProgressState(wxTASKBAR_BUTTON_NO_PROGRESS);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user