diff --git a/include/wx/taskbarbutton.h b/include/wx/taskbarbutton.h index 59332aab73..986c39b399 100644 --- a/include/wx/taskbarbutton.h +++ b/include/wx/taskbarbutton.h @@ -214,6 +214,8 @@ private: wxString m_title; }; +typedef wxVector wxJumpListCategories; + class WXDLLIMPEXP_CORE wxJumpList { public: @@ -227,10 +229,11 @@ public: const wxJumpListCategory* GetFrequentCategory(); const wxJumpListCategory* GetRecentCategory(); - const wxVector& GetCustomCategories(); + const wxJumpListCategories& GetCustomCategories(); void AddCategory(wxJumpListCategory * catalog); wxJumpListCategory* RemoveCategory(const wxString& title); + void DeleteCategory(const wxString& title); void Update(); @@ -238,6 +241,7 @@ private: bool BeginUpdate(); bool CommitUpdate(); void AddTasksToDestinationList(); + void AddCustomCategoriesToDestionationList(); void LoadKnownCategory(const wxString& title); ICustomDestinationList *m_destinationList; @@ -246,7 +250,7 @@ private: wxScopedPtr m_tasks; wxScopedPtr m_frequent; wxScopedPtr m_recent; - wxVector m_customCategories; + wxJumpListCategories m_customCategories; bool m_recent_visible; bool m_frequent_visible; }; diff --git a/samples/taskbarbutton/taskbarbutton.cpp b/samples/taskbarbutton/taskbarbutton.cpp index 41a4608e49..13289c712f 100644 --- a/samples/taskbarbutton/taskbarbutton.cpp +++ b/samples/taskbarbutton/taskbarbutton.cpp @@ -161,6 +161,19 @@ bool MyApp::OnInit() jumpList.GetTasks()->Append(item2); jumpList.ShowRecentCategory(); jumpList.ShowFrequentCategory(); + + wxJumpListItem* item3 = new wxJumpListItem( + wxJUMP_LIST_DESTIONATION, + wxT("Custom Item - Help"), + wxStandardPaths::Get().GetExecutablePath(), + wxT("--help"), + wxT("Test Custom Category."), + wxStandardPaths::Get().GetExecutablePath(), + 0); + wxJumpListCategory* customCategory = new wxJumpListCategory(wxT("Custom")); + customCategory->Append(item3); + jumpList.AddCategory(customCategory); + jumpList.Update(); const wxJumpListCategory* category = jumpList.GetFrequentCategory(); diff --git a/src/msw/taskbarbutton.cpp b/src/msw/taskbarbutton.cpp index c02adf3354..50b67369b9 100644 --- a/src/msw/taskbarbutton.cpp +++ b/src/msw/taskbarbutton.cpp @@ -364,7 +364,8 @@ bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item) return false; } - if ( item.GetType() == wxJUMP_LIST_TASK ) + if ( item.GetType() == wxJUMP_LIST_TASK || + item.GetType() == wxJUMP_LIST_DESTIONATION ) { if ( !item.GetFilePath().IsEmpty() ) shellLink->SetPath(item.GetFilePath().wc_str()); @@ -389,7 +390,8 @@ bool AddShellLink(IObjectCollection *collection, const wxJumpListItem& item) } PROPVARIANT pv; - if ( item.GetType() == wxJUMP_LIST_TASK ) + if ( item.GetType() == wxJUMP_LIST_TASK || + item.GetType() == wxJUMP_LIST_DESTIONATION ) { hr = InitPropVariantFromString(item.GetTitle().wc_str(), &pv); if ( SUCCEEDED(hr) ) @@ -474,6 +476,29 @@ wxJumpListItem* GetItemFromIShellItem(IShellItem *shellItem) return item; } +IObjectCollection* CreateObjectCollection() +{ + IObjectCollection* collection; + + HRESULT hr; + hr = CoCreateInstance + ( + wxCLSID_EnumerableObjectCollection, + NULL, + CLSCTX_INPROC, + wxIID_IObjectCollection, + reinterpret_cast(&(collection)) + ); + if ( FAILED(hr) ) + { + wxLogApiError("CoCreateInstance(wxCLSID_EnumerableObjectCollection)", + hr); + return NULL; + } + + return collection; +} + } // namespace IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject) @@ -1040,6 +1065,13 @@ wxJumpList::~wxJumpList() { if ( m_destinationList ) m_destinationList->Release(); + + for ( wxJumpListCategories::iterator it = m_customCategories.begin(); + it != m_customCategories.end(); + ++it ) + { + delete *it; + } } void wxJumpList::Update() @@ -1048,6 +1080,7 @@ void wxJumpList::Update() return; AddTasksToDestinationList(); + AddCustomCategoriesToDestionationList(); if ( m_recent_visible ) m_destinationList->AppendKnownCategory(KDC_RECENT); if ( m_frequent_visible ) @@ -1101,7 +1134,7 @@ const wxJumpListCategory* wxJumpList::GetRecentCategory() return m_recent.get(); } -const wxVector& wxJumpList::GetCustomCategories() +const wxJumpListCategories& wxJumpList::GetCustomCategories() { return m_customCategories; } @@ -1113,7 +1146,7 @@ void wxJumpList::AddCategory(wxJumpListCategory *catalog) wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title) { - for ( wxVector::iterator it = m_customCategories.begin(); + for ( wxJumpListCategories::iterator it = m_customCategories.begin(); it != m_customCategories.end(); ++it ) { @@ -1127,6 +1160,13 @@ wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title) return NULL; } +void wxJumpList::DeleteCategory(const wxString& title) +{ + wxJumpListCategory* category = RemoveCategory(title); + if ( category ) + delete category; +} + bool wxJumpList::BeginUpdate() { if ( m_destinationList == NULL ) @@ -1147,27 +1187,9 @@ bool wxJumpList::CommitUpdate() void wxJumpList::AddTasksToDestinationList() { - IObjectArray* objectArray; - IObjectCollection* collection; - - HRESULT hr; - hr = CoCreateInstance - ( - wxCLSID_EnumerableObjectCollection, - NULL, - CLSCTX_INPROC, - wxIID_IObjectCollection, - reinterpret_cast(&(collection)) - ); - if ( FAILED(hr) ) - { - wxLogApiError("CoCreateInstance(wxCLSID_EnumerableObjectCollection)", - hr); + IObjectCollection* collection = CreateObjectCollection(); + if ( !collection ) return; - } - - hr = collection->QueryInterface(wxIID_IObjectArray, - reinterpret_cast(&(objectArray))); const wxJumpListItems& tasks = m_tasks->GetItems(); for ( wxJumpListItems::const_iterator it = tasks.begin(); @@ -1176,12 +1198,33 @@ void wxJumpList::AddTasksToDestinationList() { AddShellLink(collection, *(*it)); } - m_destinationList->AddUserTasks(objectArray); - - objectArray->Release(); + m_destinationList->AddUserTasks(collection); collection->Release(); } +void wxJumpList::AddCustomCategoriesToDestionationList() +{ + for ( wxJumpListCategories::iterator iter = m_customCategories.begin(); + iter != m_customCategories.end(); + ++iter ) + { + IObjectCollection* collection = CreateObjectCollection(); + if ( !collection ) + continue; + + const wxJumpListItems& tasks = (*iter)->GetItems(); + for ( wxJumpListItems::const_iterator it = tasks.begin(); + it != tasks.end(); + ++it ) + { + AddShellLink(collection, *(*it)); + } + m_destinationList->AppendCategory((*iter)->GetTitle().wc_str(), + collection); + collection->Release(); + } +} + void wxJumpList::LoadKnownCategory(const wxString& title) { IApplicationDocumentLists *docList = 0;