Implement wxAppProgressIndicator.
An helper class used for updating the progress of taskbar button. Author: Chaobin Zhang git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77612 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -45,6 +45,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
friend class wxFrame;
|
friend class wxFrame;
|
||||||
friend class wxThumbBarButton;
|
friend class wxThumbBarButton;
|
||||||
|
friend class wxAppProgressIndicator;
|
||||||
|
|
||||||
wxTaskBarButtonImpl(WXWidget parent);
|
wxTaskBarButtonImpl(WXWidget parent);
|
||||||
|
|
||||||
|
@@ -162,6 +162,22 @@ private:
|
|||||||
int m_iconIndex;
|
int m_iconIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_CORE wxAppProgressIndicator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxAppProgressIndicator(wxTopLevelWindow *parent, int maxValue);
|
||||||
|
virtual ~wxAppProgressIndicator() { }
|
||||||
|
bool Update(int value);
|
||||||
|
bool Pulse();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Init();
|
||||||
|
|
||||||
|
wxTopLevelWindow *m_parent;
|
||||||
|
int m_maxValue;
|
||||||
|
wxScopedPtr<wxTaskBarButton> m_taskBarButton;
|
||||||
|
};
|
||||||
|
|
||||||
typedef wxVector<wxJumpListItem> wxJumpListItems;
|
typedef wxVector<wxJumpListItem> wxJumpListItems;
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxJumpList
|
class WXDLLIMPEXP_CORE wxJumpList
|
||||||
|
@@ -14,11 +14,12 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/progdlg.h"
|
||||||
|
#include "wx/stdpaths.h"
|
||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/taskbarbutton.h"
|
#include "wx/taskbarbutton.h"
|
||||||
#include "wx/stdpaths.h"
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@@ -32,6 +33,8 @@ enum
|
|||||||
RestoreThumbnailClipBtn,
|
RestoreThumbnailClipBtn,
|
||||||
AddThumbBarButtonBtn,
|
AddThumbBarButtonBtn,
|
||||||
RemoveThumbBarButtonBtn,
|
RemoveThumbBarButtonBtn,
|
||||||
|
ShowProgressDialogBtn,
|
||||||
|
PulseProgressDialogBtn,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
@@ -118,6 +121,8 @@ private:
|
|||||||
void OnAddThubmBarButton(wxCommandEvent& WXUNUSED(event));
|
void OnAddThubmBarButton(wxCommandEvent& WXUNUSED(event));
|
||||||
void OnRemoveThubmBarButton(wxCommandEvent& WXUNUSED(event));
|
void OnRemoveThubmBarButton(wxCommandEvent& WXUNUSED(event));
|
||||||
void OnThumbnailToolbarBtnClicked(wxCommandEvent& event);
|
void OnThumbnailToolbarBtnClicked(wxCommandEvent& event);
|
||||||
|
void OnShowProgressDialog(wxCommandEvent& WXUNUSED(event));
|
||||||
|
void OnPulseProgressDialog(wxCommandEvent& WXUNUSED(event));
|
||||||
|
|
||||||
wxSlider *m_slider;
|
wxSlider *m_slider;
|
||||||
wxRadioBox *m_visibilityRadioBox;
|
wxRadioBox *m_visibilityRadioBox;
|
||||||
@@ -235,6 +240,16 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
ttbSizer->Add(addThumbBarButtonBtn, 1, wxEXPAND | wxALL, 2);
|
ttbSizer->Add(addThumbBarButtonBtn, 1, wxEXPAND | wxALL, 2);
|
||||||
ttbSizer->Add(showThumbnailToolbarBtn, 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(spvSizer, 0, wxEXPAND);
|
||||||
gs->Add(m_visibilityRadioBox, 0, wxEXPAND);
|
gs->Add(m_visibilityRadioBox, 0, wxEXPAND);
|
||||||
gs->Add(sttSizer, 0, wxEXPAND);
|
gs->Add(sttSizer, 0, wxEXPAND);
|
||||||
@@ -242,6 +257,7 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
gs->Add(soiSizer, 0, wxEXPAND);
|
gs->Add(soiSizer, 0, wxEXPAND);
|
||||||
gs->Add(stcSizer, 0, wxEXPAND);
|
gs->Add(stcSizer, 0, wxEXPAND);
|
||||||
gs->Add(ttbSizer, 0, wxEXPAND);
|
gs->Add(ttbSizer, 0, wxEXPAND);
|
||||||
|
gs->Add(indicatorSizer, 0, wxEXPAND);
|
||||||
|
|
||||||
wxStaticText *text = new wxStaticText(
|
wxStaticText *text = new wxStaticText(
|
||||||
panel, wxID_ANY, wxT("Welcome to wxTaskBarButton sample"));
|
panel, wxID_ANY, wxT("Welcome to wxTaskBarButton sample"));
|
||||||
@@ -266,6 +282,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_BUTTON(RestoreThumbnailClipBtn, MyFrame::OnSetOrRestoreThumbnailClip)
|
EVT_BUTTON(RestoreThumbnailClipBtn, MyFrame::OnSetOrRestoreThumbnailClip)
|
||||||
EVT_BUTTON(AddThumbBarButtonBtn, MyFrame::OnAddThubmBarButton)
|
EVT_BUTTON(AddThumbBarButtonBtn, MyFrame::OnAddThubmBarButton)
|
||||||
EVT_BUTTON(RemoveThumbBarButtonBtn, MyFrame::OnRemoveThubmBarButton)
|
EVT_BUTTON(RemoveThumbBarButtonBtn, MyFrame::OnRemoveThubmBarButton)
|
||||||
|
EVT_BUTTON(ShowProgressDialogBtn, MyFrame::OnShowProgressDialog)
|
||||||
|
EVT_BUTTON(PulseProgressDialogBtn, MyFrame::OnPulseProgressDialog)
|
||||||
EVT_BUTTON(ThumbnailToolbarBtn_0, MyFrame::OnThumbnailToolbarBtnClicked)
|
EVT_BUTTON(ThumbnailToolbarBtn_0, MyFrame::OnThumbnailToolbarBtnClicked)
|
||||||
EVT_BUTTON(ThumbnailToolbarBtn_1, MyFrame::OnThumbnailToolbarBtnClicked)
|
EVT_BUTTON(ThumbnailToolbarBtn_1, MyFrame::OnThumbnailToolbarBtnClicked)
|
||||||
EVT_BUTTON(ThumbnailToolbarBtn_2, MyFrame::OnThumbnailToolbarBtnClicked)
|
EVT_BUTTON(ThumbnailToolbarBtn_2, MyFrame::OnThumbnailToolbarBtnClicked)
|
||||||
@@ -383,3 +401,43 @@ void MyFrame::OnThumbnailToolbarBtnClicked(wxCommandEvent& event)
|
|||||||
{
|
{
|
||||||
wxLogMessage("Thumbnail Toolbar Button %d is clicked.", event.GetId());
|
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(&dlg, 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(&dlg, PROGRESS_COUNT);
|
||||||
|
for ( int i = 0; i <= PROGRESS_COUNT; i++ )
|
||||||
|
{
|
||||||
|
if ( !dlg.Pulse() )
|
||||||
|
break;
|
||||||
|
indicator.Pulse();
|
||||||
|
wxMilliSleep(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -70,7 +70,7 @@
|
|||||||
#endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE
|
#endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE
|
||||||
|
|
||||||
#if wxUSE_TASKBARBUTTON
|
#if wxUSE_TASKBARBUTTON
|
||||||
static WXUINT gs_msgTaskbarButtonCreated = 0;
|
WXUINT wxMsgTaskbarButtonCreated = 0;
|
||||||
#define wxTHBN_CLICKED 0x1800
|
#define wxTHBN_CLICKED 0x1800
|
||||||
#endif // wxUSE_TASKBARBUTTON
|
#endif // wxUSE_TASKBARBUTTON
|
||||||
|
|
||||||
@@ -144,14 +144,19 @@ bool wxFrame::Create(wxWindow *parent,
|
|||||||
|
|
||||||
#if wxUSE_TASKBARBUTTON
|
#if wxUSE_TASKBARBUTTON
|
||||||
m_taskBarButton = NULL;
|
m_taskBarButton = NULL;
|
||||||
static bool s_registered = false;
|
static bool s_taskbarButtonCreatedMsgRegistered = false;
|
||||||
if ( !s_registered )
|
if ( !s_taskbarButtonCreatedMsgRegistered )
|
||||||
{
|
{
|
||||||
gs_msgTaskbarButtonCreated =
|
s_taskbarButtonCreatedMsgRegistered = true;
|
||||||
|
wxMsgTaskbarButtonCreated =
|
||||||
::RegisterWindowMessage(wxT("TaskbarButtonCreated"));
|
::RegisterWindowMessage(wxT("TaskbarButtonCreated"));
|
||||||
s_registered = true;
|
|
||||||
|
// In case the application is run elevated, allow the
|
||||||
|
// TaskbarButtonCreated and WM_COMMAND messages through.
|
||||||
|
ChangeWindowMessageFilter(wxMsgTaskbarButtonCreated, MSGFLT_ADD);
|
||||||
|
ChangeWindowMessageFilter(WM_COMMAND, MSGFLT_ADD);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // wxUSE_TASKBARBUTTON
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -971,7 +976,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
|
|||||||
#endif // !__WXMICROWIN__
|
#endif // !__WXMICROWIN__
|
||||||
}
|
}
|
||||||
#if wxUSE_TASKBARBUTTON
|
#if wxUSE_TASKBARBUTTON
|
||||||
if ( message == gs_msgTaskbarButtonCreated )
|
if ( message == wxMsgTaskbarButtonCreated )
|
||||||
{
|
{
|
||||||
m_taskBarButton = new wxTaskBarButtonImpl(GetHandle());
|
m_taskBarButton = new wxTaskBarButtonImpl(GetHandle());
|
||||||
processed = true;
|
processed = true;
|
||||||
|
@@ -605,6 +605,40 @@ wxThumbBarButton* wxTaskBarButtonImpl::GetThumbBarButtonByIndex(size_t index)
|
|||||||
return m_thumbBarButtons[index];
|
return m_thumbBarButtons[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxAppProgressIndicator::wxAppProgressIndicator(wxTopLevelWindow *parent, int maxValue)
|
||||||
|
: m_parent(parent), m_maxValue(maxValue)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxAppProgressIndicator::Update(int value)
|
||||||
|
{
|
||||||
|
wxASSERT_MSG( value <= m_maxValue, wxT("invalid progress value") );
|
||||||
|
Init();
|
||||||
|
|
||||||
|
m_taskBarButton->SetProgressValue(value);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxAppProgressIndicator::Pulse()
|
||||||
|
{
|
||||||
|
Init();
|
||||||
|
m_taskBarButton->PulseProgress();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxAppProgressIndicator::Init()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wxJumpListItem::wxJumpListItem(const wxString& title,
|
wxJumpListItem::wxJumpListItem(const wxString& title,
|
||||||
const wxString& filePath,
|
const wxString& filePath,
|
||||||
const wxString& arguments,
|
const wxString& arguments,
|
||||||
|
Reference in New Issue
Block a user