void wxTaskBarJumpListImpl::AddCustomCategoriesToDestionationList() { for ( wxTaskBarJumpListCategories::iterator it = m_customCategories.begin(); it != m_customCategories.end(); ++it ) { IObjectCollection* collection = CreateObjectCollection(); if ( !collection ) continue; const wxTaskBarJumpListItems& tasks = (*it)->GetItems(); for ( wxTaskBarJumpListItems::const_iterator iter = tasks.begin(); iter != tasks.end(); ++iter ) { wxASSERT_MSG( (*iter)->GetType() == wxTASKBAR_JUMP_LIST_DESTIONATION, "Invalid category item." ); AddShellLink(collection, *(*iter)); } m_destinationList->AppendCategory((*it)->GetTitle().wc_str(), collection); collection->Release(); } }
void wxTaskBarJumpListImpl::AddTasksToDestinationList() { if ( !m_tasks.get() ) return; IObjectCollection* collection = CreateObjectCollection(); if ( !collection ) return; const wxTaskBarJumpListItems& tasks = m_tasks->GetItems(); for ( wxTaskBarJumpListItems::const_iterator it = tasks.begin(); it != tasks.end(); ++it ) { wxASSERT_MSG( ((*it)->GetType() == wxTASKBAR_JUMP_LIST_TASK || (*it)->GetType() == wxTASKBAR_JUMP_LIST_SEPARATOR), "Invalid task Item." ); AddShellLink(collection, *(*it)); } m_destinationList->AddUserTasks(collection); collection->Release(); }
// This helper creates the scope object that is a collection of shell items that // define where the search will operate. HRESULT CreateScope(IShellItemArray **ppsia) { *ppsia = NULL; IObjectCollection *pObjects; HRESULT hr = CreateShellItemArray(IID_PPV_ARGS(&pObjects)); if (SUCCEEDED(hr)) { IShellItem *psi; if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_DocumentsLibrary, 0, NULL, IID_PPV_ARGS(&psi)))) { pObjects->AddObject(psi); psi->Release(); } // Other items can be added to pObjects similar to the code above. hr = pObjects->QueryInterface(ppsia); pObjects->Release(); } return hr; }
// Adds a custom category to the Jump List. Each item that should be in the category is added to // an ordered collection, and then the category is appended to the Jump List as a whole. HRESULT _AddCategoryToList(ICustomDestinationList *pcdl, IObjectArray *poaRemoved) { IObjectCollection *poc; HRESULT hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc)); if (SUCCEEDED(hr)) { for (UINT i = 0; i < ARRAYSIZE(c_rgpszFiles); i++) { IShellItem *psi; if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_Documents, KF_FLAG_DEFAULT, c_rgpszFiles[i], IID_PPV_ARGS(&psi)))) { // Items listed in the removed list may not be re-added to the Jump List during this // list-building transaction. They should not be re-added to the Jump List until // the user has used the item again. The AppendCategory call below will fail if // an attempt to add an item in the removed list is made. if (!_IsItemInArray(psi, poaRemoved)) { poc->AddObject(psi); } psi->Release(); } } IObjectArray *poa; hr = poc->QueryInterface(IID_PPV_ARGS(&poa)); if (SUCCEEDED(hr)) { // Add the category to the Jump List. If there were more categories, they would appear // from top to bottom in the order they were appended. hr = pcdl->AppendCategory(L"Custom Category", poa); poa->Release(); } poc->Release(); } return hr; }
void CWin7::CreateTasksList() { if ( m_DestList ) { if ( m_List ) { IObjectCollection *poc; HRESULT hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc)); if (SUCCEEDED(hr)) { IShellLink * psl; hr = _CreateShellLink("/Tab-Favs", L"Favourites", "Open Favourites Tab", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } hr = _CreateShellLink("/Tab-Internet", L"Internet", "Open Internet Tab", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } hr = _CreateShellLink("/Tab-Official", L"Official", "Open Official Tab", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } #ifndef _NO_HISTORY hr = _CreateShellLink("/Tab-History", L"History", "Open History Tab", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } #endif #ifndef _NO_LAN_MODE hr = _CreateShellLink("/Tab-Lan", L"LAN", "Open LAN Tab", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } #endif if (SUCCEEDED(hr)) { hr = _CreateSeparatorLink(&psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } } hr = _CreateShellLink("/Win-Settings", L"Settings", "Open the Settings dialog", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } hr = _CreateShellLink("/Win-Help", L"Help", "Get Help & Support and the forums", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } if (SUCCEEDED(hr)) { IObjectArray * poa; hr = poc->QueryInterface(IID_PPV_ARGS(&poa)); if (SUCCEEDED(hr)) { // Add the tasks to the Jump List. Tasks always appear in the canonical "Tasks" // category that is displayed at the bottom of the Jump List, after all other // categories. hr = m_DestList->AddUserTasks(poa); poa->Release(); } } poc->Release(); } } } }
// Builds the collection of task items and adds them to the Task section of the Jump List. All tasks // should be added to the canonical "Tasks" category by calling ICustomDestinationList::AddUserTasks. HRESULT _AddTasksToList(ICustomDestinationList *pcdl) { IObjectCollection *poc; HRESULT hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc)); if (SUCCEEDED(hr)) { IShellLink * psl; hr = _CreateShellLink(L"/Task1", L"Task 1", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } if (SUCCEEDED(hr)) { hr = _CreateShellLink(L"/Task2", L"Second Task", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } } if (SUCCEEDED(hr)) { hr = _CreateSeparatorLink(&psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } } if (SUCCEEDED(hr)) { hr = _CreateShellLink(L"/Task3", L"Task 3", &psl); if (SUCCEEDED(hr)) { hr = poc->AddObject(psl); psl->Release(); } } if (SUCCEEDED(hr)) { IObjectArray * poa; hr = poc->QueryInterface(IID_PPV_ARGS(&poa)); if (SUCCEEDED(hr)) { // Add the tasks to the Jump List. Tasks always appear in the canonical "Tasks" // category that is displayed at the bottom of the Jump List, after all other // categories. hr = pcdl->AddUserTasks(poa); poa->Release(); } } poc->Release(); } return hr; }
STDMETHODIMP CTaskbar7::CommitList() { // Do nothing on XP & Vista if (!m_isWindows7) return S_OK; UINT uMaxSlots = 20; IObjectArray *poaRemoved; if (!m_appID.empty()) m_pCustomDestinationList->SetAppID(m_appID.c_str()); HRESULT hr = m_pCustomDestinationList->BeginList(&uMaxSlots, IID_PPV_ARGS(&poaRemoved)); // Iterate over the lists to create map<wstring, vector<Destination>>::iterator iterator = destinations.begin(); while (iterator != destinations.end()) { // category wstring category = (*iterator).first; // Special case for known categories if (category.compare(DESTINATION_FREQUENT) == 0 || category.compare(DESTINATION_RECENT) == 0) { KNOWNDESTCATEGORY knownDestination; category.compare(DESTINATION_FREQUENT) == 0 ? knownDestination = KDC_FREQUENT : knownDestination = KDC_RECENT; HRESULT hr = m_pCustomDestinationList->AppendKnownCategory(knownDestination); if (FAILED(hr)) // Should not happen continue; iterator++; continue; } // Create a collection of IShellLink IObjectCollection *poc; hr = CoCreateInstance(CLSID_EnumerableObjectCollection, NULL, CLSCTX_INPROC, IID_PPV_ARGS(&poc)); if (FAILED(hr)) // Should not happen continue; vector<Destination>::iterator destinationIterator = (*iterator).second.begin(); while (destinationIterator != (*iterator).second.end()) { IShellLink *link; if ((*destinationIterator).type == Separator) hr = CreateSeparatorLink(&link); else hr = CreateShellLink(*destinationIterator, &link); if (SUCCEEDED(hr)) { poc->AddObject(link); link->Release(); } ++destinationIterator; } IObjectArray * poa; hr = poc->QueryInterface(IID_PPV_ARGS(&poa)); if (SUCCEEDED(hr)) { // Special treatment for tasks if (category.compare(DESTINATION_TASKS) == 0) hr = m_pCustomDestinationList->AddUserTasks(poa); else hr = m_pCustomDestinationList->AppendCategory(category.c_str(), poa); //int err = GetLastError(); poa->Release(); } poc->Release(); ++iterator; } // Commit the list! hr = m_pCustomDestinationList->CommitList(); SAFE_RELEASE(poaRemoved); destinations.clear(); return S_OK; }