Allow 2-phase creation of wxThumbBarButton.

Author: Chaobin Zhang

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77588 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Chaobin, Zhang 2014-09-10 09:23:32 +00:00
parent 1c5b9c059f
commit f0269755aa
5 changed files with 57 additions and 8 deletions

View File

@ -44,7 +44,7 @@ private:
wxTaskBarButtonImpl(WXWidget parent); wxTaskBarButtonImpl(WXWidget parent);
bool InitOrUpdateThumbBarButtons(); bool InitOrUpdateThumbBarButtons();
int GetThumbBarButtonID(size_t index); wxThumbBarButton* GetThumbBarButtonByIndex(size_t index);
WXWidget m_hwnd; WXWidget m_hwnd;
ITaskbarList3 *m_taskbarList; ITaskbarList3 *m_taskbarList;

View File

@ -31,8 +31,9 @@ enum WXDLLIMPEXP_CORE wxTaskBarButtonState
wxTASKBAR_BUTTON_PAUSED = 8 wxTASKBAR_BUTTON_PAUSED = 8
}; };
class WXDLLIMPEXP_CORE wxThumbBarButton { class WXDLLIMPEXP_CORE wxThumbBarButton : public wxObject {
public: public:
wxThumbBarButton() { }
wxThumbBarButton(int id, wxThumbBarButton(int id,
const wxIcon& icon, const wxIcon& icon,
const wxString& tooltip = wxString(), const wxString& tooltip = wxString(),
@ -44,6 +45,14 @@ public:
virtual ~wxThumbBarButton() {} 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; } int GetID() const { return m_id; }
const wxIcon& GetIcon() const { return m_icon; } const wxIcon& GetIcon() const { return m_icon; }
const wxString& GetTooltip() const { return m_tooltip; } const wxString& GetTooltip() const { return m_tooltip; }
@ -62,6 +71,8 @@ private:
bool m_hasBackground; bool m_hasBackground;
bool m_shown; bool m_shown;
bool m_interactive; bool m_interactive;
DECLARE_DYNAMIC_CLASS(wxThumbBarButton)
}; };
class WXDLLIMPEXP_CORE wxTaskBarButton class WXDLLIMPEXP_CORE wxTaskBarButton

View File

@ -32,6 +32,10 @@ enum WXDLLIMPEXP_CORE wxTaskBarButtonState
*/ */
class WXDLLIMPEXP_CORE wxThumbBarButton { class WXDLLIMPEXP_CORE wxThumbBarButton {
public: public:
/**
Default constructor to allow 2-phase creation.
*/
wxThumbBarButton();
/** /**
Constructs the thumbnail toolbar button. Constructs the thumbnail toolbar button.
@ -68,6 +72,15 @@ public:
bool shown = true, bool shown = true,
bool interactive = 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(); virtual ~wxThumbBarButton();
/** /**

View File

@ -907,8 +907,11 @@ bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
{ {
wxTaskBarButtonImpl * const wxTaskBarButtonImpl * const
tbButton = reinterpret_cast<wxTaskBarButtonImpl*>(m_taskBarButton); tbButton = reinterpret_cast<wxTaskBarButtonImpl*>(m_taskBarButton);
wxCommandEvent event(wxEVT_BUTTON, tbButton->GetThumbBarButtonID(id)); // we use the index as id when adding thumbnail toolbar button.
event.SetEventObject(this); wxThumbBarButton * const
thumbBarButton = tbButton->GetThumbBarButtonByIndex(id);
wxCommandEvent event(wxEVT_BUTTON, thumbBarButton->GetID());
event.SetEventObject(thumbBarButton);
return ProcessEvent(event); return ProcessEvent(event);
} }
#endif // wxUSE_TASKBARBUTTON #endif // wxUSE_TASKBARBUTTON

View File

@ -52,6 +52,8 @@ THUMBBUTTONFLAGS GetNativeThumbButtonFlags(const wxThumbBarButton& button)
} // namespace } // namespace
IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject)
wxThumbBarButton::wxThumbBarButton(int id, wxThumbBarButton::wxThumbBarButton(int id,
const wxIcon& icon, const wxIcon& icon,
const wxString& tooltip, 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) wxTaskBarButtonImpl::wxTaskBarButtonImpl(WXWidget parent)
: m_hwnd(parent), : m_hwnd(parent),
m_taskbarList(NULL), m_taskbarList(NULL),
@ -283,12 +305,12 @@ bool wxTaskBarButtonImpl::InitOrUpdateThumbBarButtons()
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
int wxTaskBarButtonImpl::GetThumbBarButtonID(size_t index) wxThumbBarButton* wxTaskBarButtonImpl::GetThumbBarButtonByIndex(size_t index)
{ {
if ( index >= m_thumbBarButtons.size() ) if ( index >= m_thumbBarButtons.size() )
return -1; return NULL;
return m_thumbBarButtons[index]->GetID(); return m_thumbBarButtons[index];
} }
#endif // wxUSE_TASKBARBUTTON #endif // wxUSE_TASKBARBUTTON