Move implementation of jump list to class wxJumpListImpl.

Author: Chaobin Zhang

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77619 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Bryan Petty
2014-09-10 14:54:30 +00:00
parent 6795b5c1af
commit de7b819cdc
3 changed files with 175 additions and 53 deletions

View File

@@ -17,7 +17,10 @@
#include "wx/taskbarbutton.h" #include "wx/taskbarbutton.h"
namespace { namespace {
class ITaskbarList3; class WXDLLIMPEXP_FWD_CORE ITaskbarList3;
class WXDLLIMPEXP_FWD_CORE IObjectArray;
class WXDLLIMPEXP_FWD_CORE ICustomDestinationList;
class WXDLLIMPEXP_FWD_CORE IApplicationDocumentLists;
} }
class WXDLLIMPEXP_CORE wxTaskBarButtonImpl : public wxTaskBarButton { class WXDLLIMPEXP_CORE wxTaskBarButtonImpl : public wxTaskBarButton {
@@ -63,6 +66,44 @@ private:
bool m_hasInitThumbnailToolbar; bool m_hasInitThumbnailToolbar;
}; };
class WXDLLIMPEXP_CORE wxJumpListImpl
{
public:
wxJumpListImpl();
virtual ~wxJumpListImpl();
void ShowRecentCategory(bool shown = true);
void HideRecentCategory();
void ShowFrequentCategory(bool shown = true);
void HideFrequentCategory();
wxJumpListCategory* GetTasks();
const wxJumpListCategory* GetFrequentCategory();
const wxJumpListCategory* GetRecentCategory();
const wxJumpListCategories& GetCustomCategories();
void AddCategory(wxJumpListCategory* category);
wxJumpListCategory* RemoveCategory(const wxString& title);
void DeleteCategory(const wxString& title);
void Update();
private:
bool BeginUpdate();
bool CommitUpdate();
void AddTasksToDestinationList();
void AddCustomCategoriesToDestionationList();
void LoadKnownCategory(const wxString& title);
ICustomDestinationList *m_destinationList;
IObjectArray *m_objectArray;
wxScopedPtr<wxJumpListCategory> m_tasks;
wxScopedPtr<wxJumpListCategory> m_frequent;
wxScopedPtr<wxJumpListCategory> m_recent;
wxJumpListCategories m_customCategories;
bool m_recent_visible;
bool m_frequent_visible;
};
#endif // wxUSE_TASKBARBUTTON #endif // wxUSE_TASKBARBUTTON
#endif // _WX_MSW_TASKBARBUTTON_H_ #endif // _WX_MSW_TASKBARBUTTON_H_

View File

@@ -20,12 +20,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxTaskBarButton; class WXDLLIMPEXP_FWD_CORE wxTaskBarButton;
class WXDLLIMPEXP_FWD_CORE wxJumpListImpl;
namespace {
class WXDLLIMPEXP_FWD_CORE IObjectArray;
class WXDLLIMPEXP_FWD_CORE ICustomDestinationList;
class WXDLLIMPEXP_FWD_CORE IApplicationDocumentLists;
}
/** /**
State of the task bar button. State of the task bar button.
@@ -146,7 +141,8 @@ private:
wxScopedPtr<wxTaskBarButton> m_taskBarButton; wxScopedPtr<wxTaskBarButton> m_taskBarButton;
}; };
enum WXDLLIMPEXP_CORE wxJumpListItemType { enum WXDLLIMPEXP_CORE wxJumpListItemType
{
wxJUMP_LIST_SEPARATOR, wxJUMP_LIST_SEPARATOR,
wxJUMP_LIST_TASK, wxJUMP_LIST_TASK,
wxJUMP_LIST_DESTIONATION wxJUMP_LIST_DESTIONATION
@@ -190,8 +186,6 @@ private:
typedef wxVector<wxJumpListItem*> wxJumpListItems; typedef wxVector<wxJumpListItem*> wxJumpListItems;
class WXDLLIMPEXP_FWD_CORE wxJumpList;
class WXDLLIMPEXP_CORE wxJumpListCategory class WXDLLIMPEXP_CORE wxJumpListCategory
{ {
public: public:
@@ -220,38 +214,23 @@ class WXDLLIMPEXP_CORE wxJumpList
public: public:
wxJumpList(); wxJumpList();
virtual ~wxJumpList(); virtual ~wxJumpList();
wxJumpListCategory* GetTasks();
void ShowRecentCategory(bool shown = true); void ShowRecentCategory(bool shown = true);
void HideRecentCategory(); void HideRecentCategory();
void ShowFrequentCategory(bool shown = true); void ShowFrequentCategory(bool shown = true);
void HideFrequentCategory(); void HideFrequentCategory();
wxJumpListCategory* GetTasks();
const wxJumpListCategory* GetFrequentCategory(); const wxJumpListCategory* GetFrequentCategory();
const wxJumpListCategory* GetRecentCategory(); const wxJumpListCategory* GetRecentCategory();
const wxJumpListCategories& GetCustomCategories(); const wxJumpListCategories& GetCustomCategories();
void AddCategory(wxJumpListCategory * catalog); void AddCategory(wxJumpListCategory* category);
wxJumpListCategory* RemoveCategory(const wxString& title); wxJumpListCategory* RemoveCategory(const wxString& title);
void DeleteCategory(const wxString& title); void DeleteCategory(const wxString& title);
void Update(); void Update();
private: private:
bool BeginUpdate(); wxJumpListImpl *m_jumpListImpl;
bool CommitUpdate();
void AddTasksToDestinationList();
void AddCustomCategoriesToDestionationList();
void LoadKnownCategory(const wxString& title);
ICustomDestinationList *m_destinationList;
IObjectArray *m_objectArray;
wxScopedPtr<wxJumpListCategory> m_tasks;
wxScopedPtr<wxJumpListCategory> m_frequent;
wxScopedPtr<wxJumpListCategory> m_recent;
wxJumpListCategories m_customCategories;
bool m_recent_visible;
bool m_frequent_visible;
}; };
#endif // wxUSE_TASKBARBUTTON #endif // wxUSE_TASKBARBUTTON

View File

@@ -27,6 +27,12 @@
#include <shlwapi.h> #include <shlwapi.h>
#include <initguid.h> #include <initguid.h>
// ----------------------------------------------------------------------------
// Redefine the interfaces: ITaskbarList3, IObjectCollection,
// ICustomDestinationList, IShellLink, IShellItem, IApplicationDocumentLists
// etc.
// ----------------------------------------------------------------------------
WINOLEAPI PropVariantClear(PROPVARIANT* pvar); WINOLEAPI PropVariantClear(PROPVARIANT* pvar);
#ifndef PropVariantInit #ifndef PropVariantInit
@@ -220,7 +226,6 @@ DEFINE_GUID(wxIID_IShellLink,
0x000214EE, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46); 0x000214EE, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif // wxUSE_UNICODE #endif // wxUSE_UNICODE
typedef enum _SIGDN typedef enum _SIGDN
{ {
SIGDN_NORMALDISPLAY = 0, SIGDN_NORMALDISPLAY = 0,
@@ -458,7 +463,7 @@ wxJumpListItem* GetItemFromIShellLink(IShellLink* link)
link->GetIconLocation(buffer, bufferSize - 1, &dummyIndex); link->GetIconLocation(buffer, bufferSize - 1, &dummyIndex);
item->SetIconPath(wxString(buffer)); item->SetIconPath(wxString(buffer));
link->GetPath(buffer, bufferSize - 1, NULL, NULL); link->GetPath(buffer, bufferSize - 1, NULL, 0x1);
item->SetFilePath(wxString(buffer)); item->SetFilePath(wxString(buffer));
return item; return item;
@@ -503,6 +508,9 @@ IObjectCollection* CreateObjectCollection()
} // namespace } // namespace
// ----------------------------------------------------------------------------
// wxThumbBarButton Implementation.
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxThumbBarButton, wxObject)
wxThumbBarButton::wxThumbBarButton(int id, wxThumbBarButton::wxThumbBarButton(int id,
@@ -599,6 +607,9 @@ bool wxThumbBarButton::UpdateParentTaskBarButton()
m_taskBarButtonParent)->InitOrUpdateThumbBarButtons(); m_taskBarButtonParent)->InitOrUpdateThumbBarButtons();
} }
// ----------------------------------------------------------------------------
// wxTaskBarButtonImpl Implementation.
// ----------------------------------------------------------------------------
wxTaskBarButtonImpl::wxTaskBarButtonImpl(WXWidget parent) wxTaskBarButtonImpl::wxTaskBarButtonImpl(WXWidget parent)
: m_hwnd(parent), : m_hwnd(parent),
m_taskbarList(NULL), m_taskbarList(NULL),
@@ -841,6 +852,9 @@ wxThumbBarButton* wxTaskBarButtonImpl::GetThumbBarButtonByIndex(size_t index)
return m_thumbBarButtons[index]; return m_thumbBarButtons[index];
} }
// ----------------------------------------------------------------------------
// wxAppProgressIndicator Implementation.
// ----------------------------------------------------------------------------
wxAppProgressIndicator::wxAppProgressIndicator(wxTopLevelWindow *parent, int maxValue) wxAppProgressIndicator::wxAppProgressIndicator(wxTopLevelWindow *parent, int maxValue)
: m_parent(parent), m_maxValue(maxValue) : m_parent(parent), m_maxValue(maxValue)
{ {
@@ -880,6 +894,9 @@ void wxAppProgressIndicator::Init()
} }
} }
// ----------------------------------------------------------------------------
// wxJumpListItem Implementation.
// ----------------------------------------------------------------------------
wxJumpListItem::wxJumpListItem(wxJumpListItemType type, wxJumpListItem::wxJumpListItem(wxJumpListItemType type,
const wxString& title, const wxString& title,
const wxString& filePath, const wxString& filePath,
@@ -968,6 +985,9 @@ void wxJumpListItem::SetIconIndex(int iconIndex)
m_iconIndex = iconIndex; m_iconIndex = iconIndex;
} }
// ----------------------------------------------------------------------------
// wxJumpListCategory Implementation.
// ----------------------------------------------------------------------------
wxJumpListCategory::wxJumpListCategory(const wxString& title) wxJumpListCategory::wxJumpListCategory(const wxString& title)
: m_title(title) : m_title(title)
{ {
@@ -1014,13 +1034,13 @@ wxJumpListItem* wxJumpListCategory::Remove(wxJumpListItem *item)
wxJumpListItem* wxJumpListCategory::FindItemByPosition(size_t pos) const wxJumpListItem* wxJumpListCategory::FindItemByPosition(size_t pos) const
{ {
wxASSERT_MSG(pos < m_items.size(), "invalid pos."); wxASSERT_MSG( pos < m_items.size(), "invalid pos." );
return m_items[pos]; return m_items[pos];
} }
wxJumpListItem* wxJumpListCategory::Insert(size_t pos, wxJumpListItem *item) wxJumpListItem* wxJumpListCategory::Insert(size_t pos, wxJumpListItem *item)
{ {
wxASSERT_MSG(pos <= m_items.size(), "invalid pos."); wxASSERT_MSG( pos <= m_items.size(), "invalid pos." );
m_items.insert(m_items.begin() + pos, item); m_items.insert(m_items.begin() + pos, item);
return item; return item;
} }
@@ -1045,9 +1065,83 @@ const wxJumpListItems& wxJumpListCategory::GetItems() const
return m_items; return m_items;
} }
wxJumpList::wxJumpList() : m_destinationList(NULL) // ----------------------------------------------------------------------------
// wxJumpList Implementation.
// ----------------------------------------------------------------------------
wxJumpList::wxJumpList() : m_jumpListImpl(new wxJumpListImpl())
{ {
}
wxJumpList::~wxJumpList()
{
delete m_jumpListImpl;
}
wxJumpListCategory* wxJumpList::GetTasks()
{
return m_jumpListImpl->GetTasks();
}
void wxJumpList::ShowRecentCategory(bool shown)
{
m_jumpListImpl->ShowRecentCategory(shown);
}
void wxJumpList::HideRecentCategory()
{
m_jumpListImpl->HideRecentCategory();
}
void wxJumpList::ShowFrequentCategory(bool shown)
{
m_jumpListImpl->ShowFrequentCategory(shown);
}
void wxJumpList::HideFrequentCategory()
{
m_jumpListImpl->HideFrequentCategory();
}
const wxJumpListCategory* wxJumpList::GetFrequentCategory()
{
return m_jumpListImpl->GetFrequentCategory();
}
const wxJumpListCategory* wxJumpList::GetRecentCategory()
{
return m_jumpListImpl->GetRecentCategory();
}
const wxJumpListCategories& wxJumpList::GetCustomCategories()
{
return m_jumpListImpl->GetCustomCategories();
}
void wxJumpList::AddCategory(wxJumpListCategory* category)
{
m_jumpListImpl->AddCategory(category);
}
wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title)
{
return m_jumpListImpl->RemoveCategory(title);
}
void wxJumpList::DeleteCategory(const wxString& title)
{
m_jumpListImpl->DeleteCategory(title);
}
void wxJumpList::Update()
{
m_jumpListImpl->Update();
}
// ----------------------------------------------------------------------------
// wxJumpListImpl Implementation.
// ----------------------------------------------------------------------------
wxJumpListImpl::wxJumpListImpl() : m_destinationList(NULL)
{
HRESULT hr = CoCreateInstance HRESULT hr = CoCreateInstance
( (
wxCLSID_DestinationList, wxCLSID_DestinationList,
@@ -1063,7 +1157,7 @@ wxJumpList::wxJumpList() : m_destinationList(NULL)
} }
} }
wxJumpList::~wxJumpList() wxJumpListImpl::~wxJumpListImpl()
{ {
if ( m_destinationList ) if ( m_destinationList )
m_destinationList->Release(); m_destinationList->Release();
@@ -1076,7 +1170,7 @@ wxJumpList::~wxJumpList()
} }
} }
void wxJumpList::Update() void wxJumpListImpl::Update()
{ {
if ( !BeginUpdate() ) if ( !BeginUpdate() )
return; return;
@@ -1090,7 +1184,7 @@ void wxJumpList::Update()
CommitUpdate(); CommitUpdate();
} }
wxJumpListCategory* wxJumpList::GetTasks() wxJumpListCategory* wxJumpListImpl::GetTasks()
{ {
if ( m_tasks.get() == NULL ) if ( m_tasks.get() == NULL )
m_tasks.reset(new wxJumpListCategory(wxT("Tasks"))); m_tasks.reset(new wxJumpListCategory(wxT("Tasks")));
@@ -1098,27 +1192,27 @@ wxJumpListCategory* wxJumpList::GetTasks()
return m_tasks.get(); return m_tasks.get();
} }
void wxJumpList::ShowRecentCategory(bool shown) void wxJumpListImpl::ShowRecentCategory(bool shown)
{ {
m_recent_visible = shown; m_recent_visible = shown;
} }
void wxJumpList::HideRecentCategory() void wxJumpListImpl::HideRecentCategory()
{ {
ShowRecentCategory(false); ShowRecentCategory(false);
} }
void wxJumpList::ShowFrequentCategory(bool shown) void wxJumpListImpl::ShowFrequentCategory(bool shown)
{ {
m_frequent_visible = shown; m_frequent_visible = shown;
} }
void wxJumpList::HideFrequentCategory() void wxJumpListImpl::HideFrequentCategory()
{ {
ShowFrequentCategory(false); ShowFrequentCategory(false);
} }
const wxJumpListCategory* wxJumpList::GetFrequentCategory() const wxJumpListCategory* wxJumpListImpl::GetFrequentCategory()
{ {
wxString title = wxT("Frequent"); wxString title = wxT("Frequent");
if ( m_frequent.get() == NULL ) if ( m_frequent.get() == NULL )
@@ -1127,7 +1221,7 @@ const wxJumpListCategory* wxJumpList::GetFrequentCategory()
return m_frequent.get(); return m_frequent.get();
} }
const wxJumpListCategory* wxJumpList::GetRecentCategory() const wxJumpListCategory* wxJumpListImpl::GetRecentCategory()
{ {
wxString title = wxT("Recent"); wxString title = wxT("Recent");
if ( m_recent.get() == NULL ) if ( m_recent.get() == NULL )
@@ -1136,17 +1230,17 @@ const wxJumpListCategory* wxJumpList::GetRecentCategory()
return m_recent.get(); return m_recent.get();
} }
const wxJumpListCategories& wxJumpList::GetCustomCategories() const wxJumpListCategories& wxJumpListImpl::GetCustomCategories()
{ {
return m_customCategories; return m_customCategories;
} }
void wxJumpList::AddCategory(wxJumpListCategory *catalog) void wxJumpListImpl::AddCategory(wxJumpListCategory *category)
{ {
m_customCategories.push_back(catalog); m_customCategories.push_back(category);
} }
wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title) wxJumpListCategory* wxJumpListImpl::RemoveCategory(const wxString& title)
{ {
for ( wxJumpListCategories::iterator it = m_customCategories.begin(); for ( wxJumpListCategories::iterator it = m_customCategories.begin();
it != m_customCategories.end(); it != m_customCategories.end();
@@ -1162,14 +1256,14 @@ wxJumpListCategory* wxJumpList::RemoveCategory(const wxString& title)
return NULL; return NULL;
} }
void wxJumpList::DeleteCategory(const wxString& title) void wxJumpListImpl::DeleteCategory(const wxString& title)
{ {
wxJumpListCategory* category = RemoveCategory(title); wxJumpListCategory* category = RemoveCategory(title);
if ( category ) if ( category )
delete category; delete category;
} }
bool wxJumpList::BeginUpdate() bool wxJumpListImpl::BeginUpdate()
{ {
if ( m_destinationList == NULL ) if ( m_destinationList == NULL )
return false; return false;
@@ -1181,14 +1275,17 @@ bool wxJumpList::BeginUpdate()
return SUCCEEDED(hr); return SUCCEEDED(hr);
} }
bool wxJumpList::CommitUpdate() bool wxJumpListImpl::CommitUpdate()
{ {
m_objectArray->Release(); m_objectArray->Release();
return SUCCEEDED(m_destinationList->CommitList()); return SUCCEEDED(m_destinationList->CommitList());
} }
void wxJumpList::AddTasksToDestinationList() void wxJumpListImpl::AddTasksToDestinationList()
{ {
if ( !m_tasks.get() )
return;
IObjectCollection* collection = CreateObjectCollection(); IObjectCollection* collection = CreateObjectCollection();
if ( !collection ) if ( !collection )
return; return;
@@ -1198,13 +1295,16 @@ void wxJumpList::AddTasksToDestinationList()
it != tasks.end(); it != tasks.end();
++it ) ++it )
{ {
wxASSERT_MSG( ((*it)->GetType() == wxJUMP_LIST_TASK ||
(*it)->GetType() == wxJUMP_LIST_SEPARATOR),
"Invalid task Item." );
AddShellLink(collection, *(*it)); AddShellLink(collection, *(*it));
} }
m_destinationList->AddUserTasks(collection); m_destinationList->AddUserTasks(collection);
collection->Release(); collection->Release();
} }
void wxJumpList::AddCustomCategoriesToDestionationList() void wxJumpListImpl::AddCustomCategoriesToDestionationList()
{ {
for ( wxJumpListCategories::iterator iter = m_customCategories.begin(); for ( wxJumpListCategories::iterator iter = m_customCategories.begin();
iter != m_customCategories.end(); iter != m_customCategories.end();
@@ -1219,6 +1319,8 @@ void wxJumpList::AddCustomCategoriesToDestionationList()
it != tasks.end(); it != tasks.end();
++it ) ++it )
{ {
wxASSERT_MSG( (*it)->GetType() == wxJUMP_LIST_DESTIONATION,
"Invalid category item." );
AddShellLink(collection, *(*it)); AddShellLink(collection, *(*it));
} }
m_destinationList->AppendCategory((*iter)->GetTitle().wc_str(), m_destinationList->AppendCategory((*iter)->GetTitle().wc_str(),
@@ -1227,7 +1329,7 @@ void wxJumpList::AddCustomCategoriesToDestionationList()
} }
} }
void wxJumpList::LoadKnownCategory(const wxString& title) void wxJumpListImpl::LoadKnownCategory(const wxString& title)
{ {
IApplicationDocumentLists *docList = 0; IApplicationDocumentLists *docList = 0;
HRESULT hr = CoCreateInstance HRESULT hr = CoCreateInstance
@@ -1245,7 +1347,7 @@ void wxJumpList::LoadKnownCategory(const wxString& title)
} }
IObjectArray *array = NULL; IObjectArray *array = NULL;
wxASSERT_MSG(title == "Recent" || title == "Frequent", "Invalid title."); wxASSERT_MSG( title == "Recent" || title == "Frequent", "Invalid title." );
hr = docList->GetList hr = docList->GetList
( (
title == "Recent" ? ADLT_RECENT : ADLT_FREQUENT, title == "Recent" ? ADLT_RECENT : ADLT_FREQUENT,