Expose APIs that can update the behavior of wxThumbBarButton.

- void Enable(bool enable = true);
  void Disable();
- void EnableDismissOnClick(bool enable = true);
  void DisableDimissOnClick();
- void SetHasBackground(bool has = true);
- void Show(bool shown = true);
  void Hide();
- void EnableInteractive(bool interactive = true);
  void DisableInteractive();

Author: Chaobin Zhang

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77608 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2014-09-10 14:52:33 +00:00
parent 183b0f4664
commit 1f849ebcdd
3 changed files with 87 additions and 3 deletions

View File

@@ -41,6 +41,8 @@ public:
private: private:
friend class wxFrame; friend class wxFrame;
friend class wxThumbBarButton;
wxTaskBarButtonImpl(WXWidget parent); wxTaskBarButtonImpl(WXWidget parent);
bool InitOrUpdateThumbBarButtons(); bool InitOrUpdateThumbBarButtons();

View File

@@ -19,6 +19,8 @@
// wxTaskBarButton: define wxTaskBarButton interface. // wxTaskBarButton: define wxTaskBarButton interface.
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxTaskBarButton;
/** /**
State of the task bar button. State of the task bar button.
*/ */
@@ -33,7 +35,7 @@ enum WXDLLIMPEXP_CORE wxTaskBarButtonState
class WXDLLIMPEXP_CORE wxThumbBarButton : public wxObject { class WXDLLIMPEXP_CORE wxThumbBarButton : public wxObject {
public: public:
wxThumbBarButton() { } wxThumbBarButton() : m_taskBarButtonParent(NULL) { }
wxThumbBarButton(int id, wxThumbBarButton(int id,
const wxIcon& icon, const wxIcon& icon,
const wxString& tooltip = wxString(), const wxString& tooltip = wxString(),
@@ -56,13 +58,32 @@ public:
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; }
bool IsEnable() const { return m_enable; } bool IsEnable() const { return m_enable; }
void Enable(bool enable = true);
void Disable() { Enable(false); }
bool IsDismissOnClick() const { return m_dismissOnClick; } bool IsDismissOnClick() const { return m_dismissOnClick; }
void EnableDismissOnClick(bool enable = true);
void DisableDimissOnClick() { EnableDismissOnClick(false); }
bool HasBackground() const { return m_hasBackground; } bool HasBackground() const { return m_hasBackground; }
void SetHasBackground(bool has = true);
bool IsShown() const { return m_shown; } bool IsShown() const { return m_shown; }
void Show(bool shown = true);
void Hide() { Show(false); }
bool IsInteractive() const { return m_interactive; } bool IsInteractive() const { return m_interactive; }
void EnableInteractive(bool interactive = true);
void DisableInteractive() { EnableInteractive(false); }
void SetParent(wxTaskBarButton *parent) { m_taskBarButtonParent = parent; }
wxTaskBarButton* GetParent() const { return m_taskBarButtonParent; }
private: private:
bool UpdateParentTaskBarButton();
int m_id; int m_id;
wxIcon m_icon; wxIcon m_icon;
wxString m_tooltip; wxString m_tooltip;
@@ -71,6 +92,7 @@ private:
bool m_hasBackground; bool m_hasBackground;
bool m_shown; bool m_shown;
bool m_interactive; bool m_interactive;
wxTaskBarButton *m_taskBarButtonParent;
DECLARE_DYNAMIC_CLASS(wxThumbBarButton) DECLARE_DYNAMIC_CLASS(wxThumbBarButton)
}; };

View File

@@ -69,7 +69,8 @@ wxThumbBarButton::wxThumbBarButton(int id,
m_dismissOnClick(dismissOnClick), m_dismissOnClick(dismissOnClick),
m_hasBackground(hasBackground), m_hasBackground(hasBackground),
m_shown(shown), m_shown(shown),
m_interactive(interactive) m_interactive(interactive),
m_taskBarButtonParent(NULL)
{ {
} }
@@ -93,6 +94,60 @@ bool wxThumbBarButton::Create(int id,
return true; return true;
} }
void wxThumbBarButton::Enable(bool enable)
{
if ( m_enable != enable )
{
m_enable = enable;
UpdateParentTaskBarButton();
}
}
void wxThumbBarButton::SetHasBackground(bool has)
{
if ( m_hasBackground != has )
{
m_hasBackground = has;
UpdateParentTaskBarButton();
}
}
void wxThumbBarButton::EnableDismissOnClick(bool enable)
{
if ( m_dismissOnClick != enable )
{
m_dismissOnClick = enable;
UpdateParentTaskBarButton();
}
}
void wxThumbBarButton::Show(bool shown)
{
if ( m_shown != shown )
{
m_shown = shown;
UpdateParentTaskBarButton();
}
}
void wxThumbBarButton::EnableInteractive(bool interactive)
{
if ( m_interactive != interactive )
{
m_interactive = interactive;
UpdateParentTaskBarButton();
}
}
bool wxThumbBarButton::UpdateParentTaskBarButton()
{
if ( !m_taskBarButtonParent )
return false;
return static_cast<wxTaskBarButtonImpl*>(
m_taskBarButtonParent)->InitOrUpdateThumbBarButtons();
}
wxTaskBarButtonImpl::wxTaskBarButtonImpl(WXWidget parent) wxTaskBarButtonImpl::wxTaskBarButtonImpl(WXWidget parent)
: m_hwnd(parent), : m_hwnd(parent),
m_taskbarList(NULL), m_taskbarList(NULL),
@@ -200,6 +255,7 @@ bool wxTaskBarButtonImpl::AppendThumbBarButton(wxThumbBarButton *button)
wxASSERT_MSG( m_thumbBarButtons.size() < MAX_BUTTON_COUNT, wxASSERT_MSG( m_thumbBarButtons.size() < MAX_BUTTON_COUNT,
"Number of thumb buttons is limited to 7" ); "Number of thumb buttons is limited to 7" );
button->SetParent(this);
m_thumbBarButtons.push_back(button); m_thumbBarButtons.push_back(button);
return InitOrUpdateThumbBarButtons(); return InitOrUpdateThumbBarButtons();
} }
@@ -212,11 +268,13 @@ bool wxTaskBarButtonImpl::InsertThumbBarButton(size_t pos,
wxASSERT_MSG( pos <= m_thumbBarButtons.size(), wxASSERT_MSG( pos <= m_thumbBarButtons.size(),
"Invalid index when inserting the button" ); "Invalid index when inserting the button" );
button->SetParent(this);
m_thumbBarButtons.insert(m_thumbBarButtons.begin() + pos, button); m_thumbBarButtons.insert(m_thumbBarButtons.begin() + pos, button);
return InitOrUpdateThumbBarButtons(); return InitOrUpdateThumbBarButtons();
} }
wxThumbBarButton* wxTaskBarButtonImpl::RemoveThumbBarButton(wxThumbBarButton *button) wxThumbBarButton* wxTaskBarButtonImpl::RemoveThumbBarButton(
wxThumbBarButton *button)
{ {
for ( wxThumbBarButtons::iterator iter = m_thumbBarButtons.begin(); for ( wxThumbBarButtons::iterator iter = m_thumbBarButtons.begin();
iter != m_thumbBarButtons.end(); iter != m_thumbBarButtons.end();
@@ -225,6 +283,7 @@ wxThumbBarButton* wxTaskBarButtonImpl::RemoveThumbBarButton(wxThumbBarButton *bu
if ( button == *iter ) if ( button == *iter )
{ {
m_thumbBarButtons.erase(iter); m_thumbBarButtons.erase(iter);
button->SetParent(NULL);
InitOrUpdateThumbBarButtons(); InitOrUpdateThumbBarButtons();
return *iter; return *iter;
} }
@@ -242,6 +301,7 @@ wxThumbBarButton* wxTaskBarButtonImpl::RemoveThumbBarButton(int id)
if ( id == (*iter)->GetID() ) if ( id == (*iter)->GetID() )
{ {
m_thumbBarButtons.erase(iter); m_thumbBarButtons.erase(iter);
(*iter)->SetParent(NULL);
InitOrUpdateThumbBarButtons(); InitOrUpdateThumbBarButtons();
return *iter; return *iter;
} }