diff --git a/include/wx/msw/taskbarbutton.h b/include/wx/msw/taskbarbutton.h index 9cabaace9d..1f6317a116 100644 --- a/include/wx/msw/taskbarbutton.h +++ b/include/wx/msw/taskbarbutton.h @@ -44,7 +44,7 @@ private: wxTaskBarButtonImpl(WXWidget parent); bool InitOrUpdateThumbBarButtons(); - int GetThumbBarButtonID(size_t index); + wxThumbBarButton* GetThumbBarButtonByIndex(size_t index); WXWidget m_hwnd; ITaskbarList3 *m_taskbarList; diff --git a/include/wx/taskbarbutton.h b/include/wx/taskbarbutton.h index 3bb7d31599..b562139152 100644 --- a/include/wx/taskbarbutton.h +++ b/include/wx/taskbarbutton.h @@ -31,8 +31,9 @@ enum WXDLLIMPEXP_CORE wxTaskBarButtonState wxTASKBAR_BUTTON_PAUSED = 8 }; -class WXDLLIMPEXP_CORE wxThumbBarButton { +class WXDLLIMPEXP_CORE wxThumbBarButton : public wxObject { public: + wxThumbBarButton() { } wxThumbBarButton(int id, const wxIcon& icon, const wxString& tooltip = wxString(), @@ -44,6 +45,14 @@ public: virtual ~wxThumbBarButton() {} + bool Create(int id, + const wxIcon& icon, + const wxString& tooltip = wxString(), + bool enable = true, + bool dismissOnClick = false, + bool hasBackground = true, + bool shown = true, + bool interactive = true); int GetID() const { return m_id; } const wxIcon& GetIcon() const { return m_icon; } const wxString& GetTooltip() const { return m_tooltip; } @@ -62,6 +71,8 @@ private: bool m_hasBackground; bool m_shown; bool m_interactive; + + DECLARE_DYNAMIC_CLASS(wxThumbBarButton) }; class WXDLLIMPEXP_CORE wxTaskBarButton diff --git a/interface/wx/taskbarbutton.h b/interface/wx/taskbarbutton.h index 277495ca94..c4b6a10c7e 100644 --- a/interface/wx/taskbarbutton.h +++ b/interface/wx/taskbarbutton.h @@ -32,6 +32,10 @@ enum WXDLLIMPEXP_CORE wxTaskBarButtonState */ class WXDLLIMPEXP_CORE wxThumbBarButton { public: + /** + Default constructor to allow 2-phase creation. + */ + wxThumbBarButton(); /** Constructs the thumbnail toolbar button. @@ -68,6 +72,15 @@ public: bool shown = true, bool interactive = true); + bool Create(int id, + const wxIcon& icon, + const wxString& tooltip = wxString(), + bool enable = true, + bool dismissOnClick = false, + bool hasBackground = true, + bool shown = true, + bool interactive = true); + virtual ~wxThumbBarButton(); /** diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 7083d502dc..b5718d7bda 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -906,9 +906,12 @@ bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) if ( cmd == wxTHBN_CLICKED && m_taskBarButton ) { wxTaskBarButtonImpl * const - tbButton = reinterpret_cast(m_taskBarButton); - wxCommandEvent event(wxEVT_BUTTON, tbButton->GetThumbBarButtonID(id)); - event.SetEventObject(this); + tbButton = reinterpret_cast(m_taskBarButton); + // we use the index as id when adding thumbnail toolbar button. + wxThumbBarButton * const + thumbBarButton = tbButton->GetThumbBarButtonByIndex(id); + wxCommandEvent event(wxEVT_BUTTON, thumbBarButton->GetID()); + event.SetEventObject(thumbBarButton); return ProcessEvent(event); } #endif // wxUSE_TASKBARBUTTON diff --git a/src/msw/taskbarbutton.cpp b/src/msw/taskbarbutton.cpp index 102fc8bc42..4bfb3b8eb1 100644 --- a/src/msw/taskbarbutton.cpp +++ b/src/msw/taskbarbutton.cpp @@ -52,6 +52,8 @@ THUMBBUTTONFLAGS GetNativeThumbButtonFlags(const wxThumbBarButton& button) } // namespace +IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject) + wxThumbBarButton::wxThumbBarButton(int id, const wxIcon& icon, const wxString& tooltip, @@ -71,6 +73,26 @@ wxThumbBarButton::wxThumbBarButton(int id, { } +bool wxThumbBarButton::Create(int id, + const wxIcon& icon, + const wxString& tooltip, + bool enable, + bool dismissOnClick, + bool hasBackground, + bool shown, + bool interactive) +{ + m_id = id; + m_icon = icon; + m_tooltip = tooltip; + m_enable = enable; + m_dismissOnClick = dismissOnClick; + m_hasBackground = hasBackground; + m_shown = shown; + m_interactive = interactive; + return true; +} + wxTaskBarButtonImpl::wxTaskBarButtonImpl(WXWidget parent) : m_hwnd(parent), m_taskbarList(NULL), @@ -283,12 +305,12 @@ bool wxTaskBarButtonImpl::InitOrUpdateThumbBarButtons() return SUCCEEDED(hr); } -int wxTaskBarButtonImpl::GetThumbBarButtonID(size_t index) +wxThumbBarButton* wxTaskBarButtonImpl::GetThumbBarButtonByIndex(size_t index) { if ( index >= m_thumbBarButtons.size() ) - return -1; + return NULL; - return m_thumbBarButtons[index]->GetID(); + return m_thumbBarButtons[index]; } #endif // wxUSE_TASKBARBUTTON