Support adding a separator in the task list when setting jump list.

Author: Chaobin Zhang

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77613 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2014-09-10 14:53:28 +00:00
parent b8815e8ac3
commit d73285aeb3
3 changed files with 87 additions and 32 deletions

View File

@@ -130,16 +130,25 @@ private:
wxDECLARE_NO_COPY_CLASS(wxTaskBarButton); wxDECLARE_NO_COPY_CLASS(wxTaskBarButton);
}; };
enum WXDLLIMPEXP_CORE wxJumpListItemType {
wxJUMP_LIST_SEPARATOR,
wxJUMP_LIST_TASK,
wxJUMP_LIST_DESTIONATION
};
class WXDLLIMPEXP_CORE wxJumpListItem class WXDLLIMPEXP_CORE wxJumpListItem
{ {
public: public:
wxJumpListItem(const wxString& title = wxEmptyString, wxJumpListItem(wxJumpListItemType type,
const wxString& title = wxEmptyString,
const wxString& filePath = wxEmptyString, const wxString& filePath = wxEmptyString,
const wxString& arguments = wxEmptyString, const wxString& arguments = wxEmptyString,
const wxString& tooltip = wxEmptyString, const wxString& tooltip = wxEmptyString,
const wxString& iconPath = wxEmptyString, const wxString& iconPath = wxEmptyString,
int iconIndex = 0); int iconIndex = 0);
wxJumpListItemType GetType() const;
void SetType(wxJumpListItemType type);
const wxString& GetTitle() const; const wxString& GetTitle() const;
void SetTitle(const wxString& title); void SetTitle(const wxString& title);
const wxString& GetFilePath() const; const wxString& GetFilePath() const;
@@ -154,6 +163,7 @@ public:
void SetIconIndex(int iconIndex); void SetIconIndex(int iconIndex);
private: private:
wxJumpListItemType m_type;
wxString m_title; wxString m_title;
wxString m_filePath; wxString m_filePath;
wxString m_arguments; wxString m_arguments;

View File

@@ -141,13 +141,23 @@ bool MyApp::OnInit()
return false; return false;
wxJumpList jump; wxJumpList jump;
wxJumpListItems tasks; wxJumpListItems tasks;
wxJumpListItem item(wxT("Task 1"), wxJumpListItem item1(wxJUMP_LIST_TASK,
wxStandardPaths::Get().GetExecutablePath(), wxT("Task 1"),
wxEmptyString, wxStandardPaths::Get().GetExecutablePath(),
wxT("Test Task"), wxEmptyString,
wxStandardPaths::Get().GetExecutablePath(), wxT("Test Task"),
0); wxStandardPaths::Get().GetExecutablePath(),
tasks.push_back(item); 0);
wxJumpListItem item2(wxJUMP_LIST_TASK,
wxT("Task 2"),
wxStandardPaths::Get().GetExecutablePath(),
wxEmptyString,
wxT("Test Task"),
wxStandardPaths::Get().GetExecutablePath(),
0);
tasks.push_back(item1);
tasks.push_back(wxJumpListItem(wxJUMP_LIST_SEPARATOR));
tasks.push_back(item2);
jump.SetTasks(tasks); jump.SetTasks(tasks);
MyFrame *frame = new MyFrame("wxTaskBarButton App"); MyFrame *frame = new MyFrame("wxTaskBarButton App");

View File

@@ -122,7 +122,6 @@ public:
virtual HRESULT wxSTDCALL SetThumbnailClip(HWND, RECT *) = 0; virtual HRESULT wxSTDCALL SetThumbnailClip(HWND, RECT *) = 0;
}; };
class IShellLinkA : public IUnknown class IShellLinkA : public IUnknown
{ {
public: public:
@@ -214,7 +213,7 @@ THUMBBUTTONFLAGS GetNativeThumbButtonFlags(const wxThumbBarButton& button)
return static_cast<THUMBBUTTONFLAGS>(flags); return static_cast<THUMBBUTTONFLAGS>(flags);
} }
IShellLink* CreateShellLink(const wxJumpListItem& item) bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item)
{ {
IShellLink* shellLink = NULL; IShellLink* shellLink = NULL;
IPropertyStore* propertyStore = NULL; IPropertyStore* propertyStore = NULL;
@@ -230,39 +229,62 @@ IShellLink* CreateShellLink(const wxJumpListItem& item)
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
wxLogApiError("CoCreateInstance(wxCLSID_ShellLink)", hr); wxLogApiError("CoCreateInstance(wxCLSID_ShellLink)", hr);
return shellLink; return false;
} }
if ( !item.GetFilePath().IsEmpty() ) if ( item.GetType() == wxJUMP_LIST_TASK )
shellLink->SetPath(item.GetFilePath().wc_str());
if ( !item.GetArguments().IsEmpty() )
shellLink->SetArguments(item.GetArguments().wc_str());
if ( !item.GetIconPath().IsEmpty() )
{ {
shellLink->SetIconLocation(item.GetIconPath().wc_str(), if ( !item.GetFilePath().IsEmpty() )
item.GetIconIndex()); shellLink->SetPath(item.GetFilePath().wc_str());
if ( !item.GetArguments().IsEmpty() )
shellLink->SetArguments(item.GetArguments().wc_str());
if ( !item.GetIconPath().IsEmpty() )
{
shellLink->SetIconLocation(item.GetIconPath().wc_str(),
item.GetIconIndex());
}
if ( !item.GetTooltip().IsEmpty() )
shellLink->SetDescription(item.GetTooltip().wc_str());
} }
if ( !item.GetTooltip().IsEmpty() )
shellLink->SetDescription(item.GetTooltip().wc_str());
hr = shellLink->QueryInterface(IID_IPropertyStore, hr = shellLink->QueryInterface(IID_IPropertyStore,
reinterpret_cast<void**>(&(propertyStore))); reinterpret_cast<void**>(&(propertyStore)));
if ( SUCCEEDED(hr )) if ( FAILED(hr) )
{
wxLogApiError("IShellLink(QueryInterface)", hr);
shellLink->Release();
return false;
}
PROPVARIANT pv;
if ( item.GetType() == wxJUMP_LIST_TASK )
{ {
PROPVARIANT pv;
hr = InitPropVariantFromString(item.GetTitle().wc_str(), &pv); hr = InitPropVariantFromString(item.GetTitle().wc_str(), &pv);
if ( SUCCEEDED(hr) ) if ( SUCCEEDED(hr) )
{ {
hr = propertyStore->SetValue(PKEY_Title, pv); hr = propertyStore->SetValue(PKEY_Title, pv);
} }
}
//Save the changes we made to the property store else if ( item.GetType() == wxJUMP_LIST_SEPARATOR )
propertyStore->Commit(); {
propertyStore->Release(); hr = InitPropVariantFromBoolean(TRUE, &pv);
PropVariantClear(&pv); if ( SUCCEEDED(hr) )
{
hr = propertyStore->SetValue(PKEY_AppUserModel_IsDestListSeparator,
pv);
}
} }
return shellLink; // Save the changes we made to the property store.
propertyStore->Commit();
propertyStore->Release();
PropVariantClear(&pv);
// Add this IShellLink object to the given collection.
hr = collection->AddObject(shellLink);
shellLink->Release();
return SUCCEEDED(hr);
} }
} // namespace } // namespace
@@ -639,13 +661,15 @@ void wxAppProgressIndicator::Init()
} }
} }
wxJumpListItem::wxJumpListItem(const wxString& title, wxJumpListItem::wxJumpListItem(wxJumpListItemType type,
const wxString& title,
const wxString& filePath, const wxString& filePath,
const wxString& arguments, const wxString& arguments,
const wxString& tooltip, const wxString& tooltip,
const wxString& iconPath, const wxString& iconPath,
int iconIndex) int iconIndex)
: m_title(title), : m_type(type),
m_title(title),
m_filePath(filePath), m_filePath(filePath),
m_arguments(arguments), m_arguments(arguments),
m_tooltip(tooltip), m_tooltip(tooltip),
@@ -654,6 +678,17 @@ wxJumpListItem::wxJumpListItem(const wxString& title,
{ {
} }
wxJumpListItemType wxJumpListItem::GetType() const
{
return m_type;
}
void wxJumpListItem::SetType(wxJumpListItemType type)
{
m_type = type;
}
const wxString& wxJumpListItem::GetTitle() const const wxString& wxJumpListItem::GetTitle() const
{ {
return m_title; return m_title;
@@ -793,7 +828,7 @@ void wxJumpList::AddTasksToDestinationList()
iter != m_tasks.end(); iter != m_tasks.end();
++iter ) ++iter )
{ {
collection->AddObject(CreateShellLink(*iter)); AddShellLink(collection, *iter);
} }
m_destinationList->AddUserTasks(objectArray); m_destinationList->AddUserTasks(objectArray);