diff --git a/include/wx/msw/taskbarbutton.h b/include/wx/msw/taskbarbutton.h index bb5faf4102..d3cd7194ea 100644 --- a/include/wx/msw/taskbarbutton.h +++ b/include/wx/msw/taskbarbutton.h @@ -45,6 +45,7 @@ public: private: friend class wxFrame; friend class wxThumbBarButton; + friend class wxAppProgressIndicator; wxTaskBarButtonImpl(WXWidget parent); diff --git a/include/wx/taskbarbutton.h b/include/wx/taskbarbutton.h index 7b43516fb4..8b88f438a8 100644 --- a/include/wx/taskbarbutton.h +++ b/include/wx/taskbarbutton.h @@ -162,6 +162,22 @@ private: 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 m_taskBarButton; +}; + typedef wxVector wxJumpListItems; class WXDLLIMPEXP_CORE wxJumpList diff --git a/samples/taskbarbutton/taskbarbutton.cpp b/samples/taskbarbutton/taskbarbutton.cpp index 1de39ece64..123f5c2c80 100644 --- a/samples/taskbarbutton/taskbarbutton.cpp +++ b/samples/taskbarbutton/taskbarbutton.cpp @@ -14,11 +14,12 @@ #endif #ifndef WX_PRECOMP + #include "wx/progdlg.h" + #include "wx/stdpaths.h" #include "wx/wx.h" #endif #include "wx/taskbarbutton.h" -#include "wx/stdpaths.h" enum { @@ -32,6 +33,8 @@ enum RestoreThumbnailClipBtn, AddThumbBarButtonBtn, RemoveThumbBarButtonBtn, + ShowProgressDialogBtn, + PulseProgressDialogBtn, }; enum @@ -118,6 +121,8 @@ 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; @@ -235,6 +240,16 @@ 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); @@ -242,6 +257,7 @@ 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")); @@ -266,6 +282,8 @@ 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) @@ -383,3 +401,43 @@ 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(&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); + } +} diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index b5718d7bda..f0acd7402e 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -70,7 +70,7 @@ #endif // wxUSE_MENUS || wxUSE_MENUS_NATIVE #if wxUSE_TASKBARBUTTON - static WXUINT gs_msgTaskbarButtonCreated = 0; + WXUINT wxMsgTaskbarButtonCreated = 0; #define wxTHBN_CLICKED 0x1800 #endif // wxUSE_TASKBARBUTTON @@ -144,14 +144,19 @@ bool wxFrame::Create(wxWindow *parent, #if wxUSE_TASKBARBUTTON m_taskBarButton = NULL; - static bool s_registered = false; - if ( !s_registered ) + static bool s_taskbarButtonCreatedMsgRegistered = false; + if ( !s_taskbarButtonCreatedMsgRegistered ) { - gs_msgTaskbarButtonCreated = + s_taskbarButtonCreatedMsgRegistered = true; + wxMsgTaskbarButtonCreated = ::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; } @@ -971,7 +976,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara #endif // !__WXMICROWIN__ } #if wxUSE_TASKBARBUTTON - if ( message == gs_msgTaskbarButtonCreated ) + if ( message == wxMsgTaskbarButtonCreated ) { m_taskBarButton = new wxTaskBarButtonImpl(GetHandle()); processed = true; diff --git a/src/msw/taskbarbutton.cpp b/src/msw/taskbarbutton.cpp index 072f305226..a5bb94007b 100644 --- a/src/msw/taskbarbutton.cpp +++ b/src/msw/taskbarbutton.cpp @@ -605,6 +605,40 @@ wxThumbBarButton* wxTaskBarButtonImpl::GetThumbBarButtonByIndex(size_t 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, const wxString& filePath, const wxString& arguments,