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
This commit is contained in:
Vadim Zeitlin
2014-09-14 23:58:22 +00:00
parent 76aa6d5db7
commit 03e245091f
4 changed files with 19 additions and 5 deletions

View File

@@ -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);
};

View File

@@ -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);
};

View File

@@ -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();

View File

@@ -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