From 03e245091f41e0951e88a4c357042e39890da55f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 14 Sep 2014 23:58:22 +0000 Subject: [PATCH] Use factory function for wxTaskBarButton creation. This allows to encapsulate checking for errors, which should be handled when using this class as task bar buttons API is not available under Windows XP. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77705 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/taskbarbutton.h | 6 +++++- include/wx/taskbarbutton.h | 8 +++++++- src/msw/appprogress.cpp | 8 ++++++-- src/msw/frame.cpp | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/include/wx/msw/taskbarbutton.h b/include/wx/msw/taskbarbutton.h index 0535d74941..4ef0f609a6 100644 --- a/include/wx/msw/taskbarbutton.h +++ b/include/wx/msw/taskbarbutton.h @@ -22,7 +22,6 @@ class WXDLLIMPEXP_FWD_CORE wxITaskbarList3; class WXDLLIMPEXP_CORE wxTaskBarButtonImpl : public wxTaskBarButton { public: - wxTaskBarButtonImpl(wxWindow* parent); virtual ~wxTaskBarButtonImpl(); virtual void SetProgressRange(int range) wxOVERRIDE; @@ -47,6 +46,9 @@ public: bool InitOrUpdateThumbBarButtons(); private: + // This ctor is only used by wxTaskBarButton::New() + wxTaskBarButtonImpl(wxITaskbarList3* taskbarList, wxWindow* parent); + WXHWND m_hwnd; wxITaskbarList3 *m_taskbarList; @@ -56,6 +58,8 @@ private: int m_progressRange; bool m_hasInitThumbnailToolbar; + friend wxTaskBarButton* wxTaskBarButton::New(wxWindow*); + wxDECLARE_NO_COPY_CLASS(wxTaskBarButtonImpl); }; diff --git a/include/wx/taskbarbutton.h b/include/wx/taskbarbutton.h index 6470253356..1652cc560f 100644 --- a/include/wx/taskbarbutton.h +++ b/include/wx/taskbarbutton.h @@ -106,7 +106,10 @@ private: class WXDLLIMPEXP_CORE wxTaskBarButton { public: - wxTaskBarButton() { } + // Factory function, may return NULL if task bar buttons are not supported + // by the current system. + static wxTaskBarButton* New(wxWindow* parent); + virtual ~wxTaskBarButton() { } // Operations: @@ -127,6 +130,9 @@ public: virtual wxThumbBarButton* RemoveThumbBarButton(wxThumbBarButton *button) = 0; virtual wxThumbBarButton* RemoveThumbBarButton(int id) = 0; +protected: + wxTaskBarButton() { } + private: wxDECLARE_NO_COPY_CLASS(wxTaskBarButton); }; diff --git a/src/msw/appprogress.cpp b/src/msw/appprogress.cpp index dd68ec9694..f23836bee1 100644 --- a/src/msw/appprogress.cpp +++ b/src/msw/appprogress.cpp @@ -33,12 +33,16 @@ wxAppProgressIndicator::wxAppProgressIndicator(wxWindow* parent, int maxValue) it != wxTopLevelWindows.end(); ++it ) { - m_taskBarButtons.push_back(new wxTaskBarButtonImpl(*it)); + wxTaskBarButton* const button = wxTaskBarButton::New(*it); + if ( button ) + m_taskBarButtons.push_back(button); } } else { - m_taskBarButtons.push_back(new wxTaskBarButtonImpl(parent)); + wxTaskBarButton* const button = wxTaskBarButton::New(parent); + if ( button ) + m_taskBarButtons.push_back(button); } Reset(); diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 7e9273c964..0114feba9f 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -991,7 +991,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara #if wxUSE_TASKBARBUTTON if ( message == wxMsgTaskbarButtonCreated ) { - m_taskBarButton = new wxTaskBarButtonImpl(this); + m_taskBarButton = wxTaskBarButton::New(this); processed = true; } #endif