APIs to support setting overlay icon, tooltip, thumbnail clip, progress state.
Author: Chaobin Zhang git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -21,8 +21,12 @@ public:
|
|||||||
virtual ~wxTaskBarButtonImpl();
|
virtual ~wxTaskBarButtonImpl();
|
||||||
|
|
||||||
virtual void SetProgressValue(int value) wxOVERRIDE;
|
virtual void SetProgressValue(int value) wxOVERRIDE;
|
||||||
virtual void ShowInTaskbar() wxOVERRIDE;
|
virtual void Show() wxOVERRIDE;
|
||||||
virtual void HideInTaskbar() wxOVERRIDE;
|
virtual void Hide() wxOVERRIDE;
|
||||||
|
virtual void SetThumbnailTooltip(const wxString& tooltip) wxOVERRIDE;
|
||||||
|
virtual void SetProgressState(wxTaskBarButtonState state) wxOVERRIDE;
|
||||||
|
virtual void SetOverlayIcon(const wxIcon& icon) wxOVERRIDE;
|
||||||
|
virtual void SetThumbnailClip(const wxRect& rect) wxOVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class wxTopLevelWindowMSW;
|
friend class wxTopLevelWindowMSW;
|
||||||
|
@@ -17,6 +17,18 @@
|
|||||||
// wxTaskBarButton: define wxTaskBarButton interface.
|
// wxTaskBarButton: define wxTaskBarButton interface.
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
State of the task bar button.
|
||||||
|
*/
|
||||||
|
enum wxTaskBarButtonState
|
||||||
|
{
|
||||||
|
wxTASKBAR_BUTTON_NO_PROGRESS = 0,
|
||||||
|
wxTASKBAR_BUTTON_INDETERMINATE = 1,
|
||||||
|
wxTASKBAR_BUTTON_NORMAL = 2,
|
||||||
|
wxTASKBAR_BUTTON_ERROR = 4,
|
||||||
|
wxTASKBAR_BUTTON_PAUSED = 8
|
||||||
|
};
|
||||||
|
|
||||||
class WXDLLIMPEXP_ADV wxTaskBarButton
|
class WXDLLIMPEXP_ADV wxTaskBarButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -25,8 +37,12 @@ public:
|
|||||||
|
|
||||||
// Operations:
|
// Operations:
|
||||||
virtual void SetProgressValue(int value) = 0;
|
virtual void SetProgressValue(int value) = 0;
|
||||||
virtual void ShowInTaskbar() = 0;
|
virtual void Show() = 0;
|
||||||
virtual void HideInTaskbar() = 0;
|
virtual void Hide() = 0;
|
||||||
|
virtual void SetThumbnailTooltip(const wxString& tooltip) = 0;
|
||||||
|
virtual void SetProgressState(wxTaskBarButtonState state) = 0;
|
||||||
|
virtual void SetOverlayIcon(const wxIcon& icon) = 0;
|
||||||
|
virtual void SetThumbnailClip(const wxRect& rect) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDECLARE_NO_COPY_CLASS(wxTaskBarButton);
|
wxDECLARE_NO_COPY_CLASS(wxTaskBarButton);
|
||||||
|
@@ -23,8 +23,62 @@ enum
|
|||||||
{
|
{
|
||||||
ProgressValueSlider = wxID_HIGHEST,
|
ProgressValueSlider = wxID_HIGHEST,
|
||||||
VisibilityRadio,
|
VisibilityRadio,
|
||||||
|
ThumbnailTooltipSetBtn,
|
||||||
|
ProgressStateChoice,
|
||||||
|
SetOverlayIconBtn,
|
||||||
|
ClearOverlayIconBtn,
|
||||||
|
SetThumbnailClipBtn,
|
||||||
|
RestoreThumbnailClipBtn,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
wxBitmap CreateBitmap(const wxColour& colour, int w, int h)
|
||||||
|
{
|
||||||
|
wxMemoryDC dc;
|
||||||
|
wxBitmap bmp(w, h);
|
||||||
|
dc.SelectObject(bmp);
|
||||||
|
|
||||||
|
// Draw transparent background
|
||||||
|
wxColour magic(255, 0, 255);
|
||||||
|
wxBrush magicBrush(magic);
|
||||||
|
dc.SetBrush(magicBrush);
|
||||||
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
|
dc.DrawRectangle(0, 0, w, h);
|
||||||
|
|
||||||
|
// Draw image content
|
||||||
|
dc.SetBrush(wxBrush(colour));
|
||||||
|
dc.DrawCircle(h / 2, h / 2 + 1, h / 2);
|
||||||
|
dc.SelectObject(wxNullBitmap);
|
||||||
|
|
||||||
|
// Finalize transparency with a mask
|
||||||
|
wxMask *mask = new wxMask(bmp, magic);
|
||||||
|
bmp.SetMask(mask);
|
||||||
|
return bmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxIcon CreateRandomIcon()
|
||||||
|
{
|
||||||
|
static int counter = 0;
|
||||||
|
static const wxColour* colours[] =
|
||||||
|
{
|
||||||
|
wxBLACK,
|
||||||
|
wxWHITE,
|
||||||
|
wxRED,
|
||||||
|
wxBLUE,
|
||||||
|
wxGREEN,
|
||||||
|
wxCYAN,
|
||||||
|
wxLIGHT_GREY
|
||||||
|
};
|
||||||
|
|
||||||
|
wxIcon icon;
|
||||||
|
icon.CopyFromBitmap(CreateBitmap(*(colours[counter]), 16, 16));
|
||||||
|
counter = (++counter) % WXSIZEOF(colours);
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
class MyApp : public wxApp
|
class MyApp : public wxApp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -41,9 +95,16 @@ private:
|
|||||||
|
|
||||||
void OnSetProgressValue(wxScrollEvent& WXUNUSED(event));
|
void OnSetProgressValue(wxScrollEvent& WXUNUSED(event));
|
||||||
void OnVisibilityChange(wxCommandEvent& WXUNUSED(event));
|
void OnVisibilityChange(wxCommandEvent& WXUNUSED(event));
|
||||||
|
void OnSetThumbnailTooltipBtn(wxCommandEvent& WXUNUSED(event));
|
||||||
|
void OnChoice(wxCommandEvent& event);
|
||||||
|
void OnSetOverlayIcon(wxCommandEvent& WXUNUSED(event));
|
||||||
|
void OnClearOverlayIcon(wxCommandEvent& WXUNUSED(event));
|
||||||
|
void OnSetOrRestoreThumbnailClip(wxCommandEvent& event);
|
||||||
|
|
||||||
wxSlider *m_slider;
|
wxSlider *m_slider;
|
||||||
wxRadioBox *m_visibilityRadioBox;
|
wxRadioBox *m_visibilityRadioBox;
|
||||||
|
wxTextCtrl *m_textCtrl;
|
||||||
|
wxChoice *m_stateChoice;
|
||||||
};
|
};
|
||||||
|
|
||||||
IMPLEMENT_APP(MyApp)
|
IMPLEMENT_APP(MyApp)
|
||||||
@@ -87,9 +148,57 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
WXSIZEOF(labels), labels,
|
WXSIZEOF(labels), labels,
|
||||||
1, wxRA_SPECIFY_ROWS);
|
1, wxRA_SPECIFY_ROWS);
|
||||||
|
// SetThumbnailTooltip section.
|
||||||
|
wxStaticBoxSizer *sttSizer =
|
||||||
|
new wxStaticBoxSizer(wxVERTICAL, panel, wxT("SetThumbnailTooltip"));
|
||||||
|
m_textCtrl = new wxTextCtrl(panel, wxID_ANY);
|
||||||
|
wxButton *btn = new wxButton(panel, ThumbnailTooltipSetBtn, wxT("Set"));
|
||||||
|
sttSizer->Add(m_textCtrl, 1, wxEXPAND | wxALL, 2);
|
||||||
|
sttSizer->Add(btn, 1, wxEXPAND | wxALL, 2);
|
||||||
|
|
||||||
|
// SetProgressState section.
|
||||||
|
wxStaticBoxSizer *spsSizer =
|
||||||
|
new wxStaticBoxSizer(wxVERTICAL, panel, wxT("SetProgressState"));
|
||||||
|
const wxString choices[] =
|
||||||
|
{
|
||||||
|
"wxNoProgress",
|
||||||
|
"wxIndeterminate",
|
||||||
|
"wxNormal",
|
||||||
|
"wxError",
|
||||||
|
"wxPaused"
|
||||||
|
};
|
||||||
|
m_stateChoice = new wxChoice(panel, ProgressStateChoice,
|
||||||
|
wxDefaultPosition, wxDefaultSize,
|
||||||
|
WXSIZEOF(choices), choices);
|
||||||
|
spsSizer->Add(m_stateChoice, 0, wxALL | wxGROW, 5);
|
||||||
|
|
||||||
|
// SetOverlayIcon section.
|
||||||
|
wxStaticBoxSizer *soiSizer =
|
||||||
|
new wxStaticBoxSizer(wxVERTICAL, panel, wxT("SetOverlayIcon"));
|
||||||
|
wxButton *setOverlayIconBtn =
|
||||||
|
new wxButton(panel, SetOverlayIconBtn, wxT("Set Overlay Icon"));
|
||||||
|
wxButton *clearOverlayIconBtn =
|
||||||
|
new wxButton(panel, ClearOverlayIconBtn, wxT("Clear Overlay Icon"));
|
||||||
|
soiSizer->Add(setOverlayIconBtn, 1, wxEXPAND | wxALL, 2);
|
||||||
|
soiSizer->Add(clearOverlayIconBtn, 1, wxEXPAND | wxALL, 2);
|
||||||
|
|
||||||
|
// SetThumbnailClip section.
|
||||||
|
wxStaticBoxSizer *stcSizer =
|
||||||
|
new wxStaticBoxSizer(wxVERTICAL, panel, wxT("SetThumbnailClip"));
|
||||||
|
wxButton *setThumbnailClipBtn =
|
||||||
|
new wxButton(panel, SetThumbnailClipBtn, wxT("Set Thumbnail Clip"));
|
||||||
|
wxButton *restoreThumbnailClipBtn =
|
||||||
|
new wxButton(panel, RestoreThumbnailClipBtn,
|
||||||
|
wxT("Restore Thumbnail Clip"));
|
||||||
|
stcSizer->Add(setThumbnailClipBtn, 1, wxEXPAND | wxALL, 2);
|
||||||
|
stcSizer->Add(restoreThumbnailClipBtn, 1, wxEXPAND | wxALL, 2);
|
||||||
|
|
||||||
gs->Add(spvSizer, 0, wxEXPAND);
|
gs->Add(spvSizer, 0, wxEXPAND);
|
||||||
gs->Add(m_visibilityRadioBox, 0, wxEXPAND);
|
gs->Add(m_visibilityRadioBox, 0, wxEXPAND);
|
||||||
|
gs->Add(sttSizer, 0, wxEXPAND);
|
||||||
|
gs->Add(spsSizer, 0, wxEXPAND);
|
||||||
|
gs->Add(soiSizer, 0, wxEXPAND);
|
||||||
|
gs->Add(stcSizer, 0, wxEXPAND);
|
||||||
|
|
||||||
wxStaticText *text = new wxStaticText(
|
wxStaticText *text = new wxStaticText(
|
||||||
panel, wxID_ANY, wxT("Welcome to wxTaskbarButton sample"));
|
panel, wxID_ANY, wxT("Welcome to wxTaskbarButton sample"));
|
||||||
@@ -106,6 +215,12 @@ MyFrame::MyFrame(const wxString& title)
|
|||||||
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_COMMAND_SCROLL_CHANGED(ProgressValueSlider, MyFrame::OnSetProgressValue)
|
EVT_COMMAND_SCROLL_CHANGED(ProgressValueSlider, MyFrame::OnSetProgressValue)
|
||||||
EVT_RADIOBOX(VisibilityRadio, MyFrame::OnVisibilityChange)
|
EVT_RADIOBOX(VisibilityRadio, MyFrame::OnVisibilityChange)
|
||||||
|
EVT_BUTTON(ThumbnailTooltipSetBtn, MyFrame::OnSetThumbnailTooltipBtn)
|
||||||
|
EVT_CHOICE(ProgressStateChoice, MyFrame::OnChoice)
|
||||||
|
EVT_BUTTON(SetOverlayIconBtn, MyFrame::OnSetOverlayIcon)
|
||||||
|
EVT_BUTTON(ClearOverlayIconBtn, MyFrame::OnClearOverlayIcon)
|
||||||
|
EVT_BUTTON(SetThumbnailClipBtn, MyFrame::OnSetOrRestoreThumbnailClip)
|
||||||
|
EVT_BUTTON(RestoreThumbnailClipBtn, MyFrame::OnSetOrRestoreThumbnailClip)
|
||||||
wxEND_EVENT_TABLE()
|
wxEND_EVENT_TABLE()
|
||||||
|
|
||||||
void MyFrame::OnSetProgressValue(wxScrollEvent& WXUNUSED(event))
|
void MyFrame::OnSetProgressValue(wxScrollEvent& WXUNUSED(event))
|
||||||
@@ -116,7 +231,68 @@ void MyFrame::OnSetProgressValue(wxScrollEvent& WXUNUSED(event))
|
|||||||
void MyFrame::OnVisibilityChange(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnVisibilityChange(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
if ( m_visibilityRadioBox->GetSelection() == 0 )
|
if ( m_visibilityRadioBox->GetSelection() == 0 )
|
||||||
MSWGetTaskBarButton()->ShowInTaskbar();
|
MSWGetTaskBarButton()->Show();
|
||||||
else
|
else
|
||||||
MSWGetTaskBarButton()->HideInTaskbar();
|
MSWGetTaskBarButton()->Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnSetThumbnailTooltipBtn(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
MSWGetTaskBarButton()->SetThumbnailTooltip(m_textCtrl->GetLineText(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnChoice(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
int sel = event.GetSelection();
|
||||||
|
wxTaskBarButtonState state;
|
||||||
|
switch(sel)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
state = wxTASKBAR_BUTTON_NO_PROGRESS;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
state = wxTASKBAR_BUTTON_INDETERMINATE;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
state = wxTASKBAR_BUTTON_NORMAL;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
state = wxTASKBAR_BUTTON_ERROR;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
state = wxTASKBAR_BUTTON_PAUSED;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
state = wxTASKBAR_BUTTON_NO_PROGRESS;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
MSWGetTaskBarButton()->SetProgressState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnSetOverlayIcon(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
MSWGetTaskBarButton()->SetOverlayIcon(CreateRandomIcon());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnClearOverlayIcon(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
MSWGetTaskBarButton()->SetOverlayIcon(wxNullIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnSetOrRestoreThumbnailClip(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
wxRect rect;
|
||||||
|
if ( event.GetId() == SetThumbnailClipBtn )
|
||||||
|
{
|
||||||
|
static const int CLIP_LENGTH = 100;
|
||||||
|
int height, width;
|
||||||
|
GetClientSize(&width, &height);
|
||||||
|
rect.SetX((width - CLIP_LENGTH) / 2);
|
||||||
|
rect.SetY((height - CLIP_LENGTH) / 2);
|
||||||
|
rect.SetHeight(CLIP_LENGTH);
|
||||||
|
rect.SetWidth(CLIP_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
MSWGetTaskBarButton()->SetThumbnailClip(rect);
|
||||||
}
|
}
|
||||||
|
@@ -61,14 +61,36 @@ void wxTaskBarButtonImpl::SetProgressValue(int value)
|
|||||||
m_taskbarList->SetProgressValue(m_hwnd, value, 100);
|
m_taskbarList->SetProgressValue(m_hwnd, value, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTaskBarButtonImpl::ShowInTaskbar()
|
void wxTaskBarButtonImpl::Show()
|
||||||
{
|
{
|
||||||
m_taskbarList->AddTab(m_hwnd);
|
m_taskbarList->AddTab(m_hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxTaskBarButtonImpl::HideInTaskbar()
|
void wxTaskBarButtonImpl::Hide()
|
||||||
{
|
{
|
||||||
m_taskbarList->DeleteTab(m_hwnd);
|
m_taskbarList->DeleteTab(m_hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxTaskBarButtonImpl::SetThumbnailTooltip(const wxString& tooltip)
|
||||||
|
{
|
||||||
|
m_taskbarList->SetThumbnailTooltip(m_hwnd, tooltip.wc_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTaskBarButtonImpl::SetProgressState(wxTaskBarButtonState state)
|
||||||
|
{
|
||||||
|
m_taskbarList->SetProgressState(m_hwnd, static_cast<TBPFLAG>(state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTaskBarButtonImpl::SetOverlayIcon(const wxIcon& icon)
|
||||||
|
{
|
||||||
|
m_taskbarList->SetOverlayIcon(m_hwnd, GetHiconOf(icon), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxTaskBarButtonImpl::SetThumbnailClip(const wxRect& rect)
|
||||||
|
{
|
||||||
|
RECT rc;
|
||||||
|
wxCopyRectToRECT(rect, rc);
|
||||||
|
m_taskbarList->SetThumbnailClip(m_hwnd, rect.IsEmpty() ? NULL : &rc);
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_TASKBARBUTTON
|
#endif // wxUSE_TASKBARBUTTON
|
||||||
|
Reference in New Issue
Block a user