From 6b527d5eca3b6ce60b69a97ff47a560cd25a7595 Mon Sep 17 00:00:00 2001 From: Bryan Petty Date: Wed, 10 Sep 2014 14:55:21 +0000 Subject: [PATCH] Add parent pointer of the classes: item -> category -> jump list. The parent of wxTaskBarJumpListItem is wxTaskBarJumpListCategory, the parent of wxTaskBarJumpListCategory is wxTaskBarJumpList. After this change, users do not need to call the update method of jump list manually. Author: Chaobin Zhang git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77624 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/taskbarbutton.h | 5 +- include/wx/taskbarbutton.h | 32 +++++++---- interface/wx/taskbarbutton.h | 39 ++++++++++---- samples/taskbarbutton/taskbarbutton.cpp | 11 ++-- src/msw/taskbarbutton.cpp | 72 ++++++++++++++++++++----- 5 files changed, 121 insertions(+), 38 deletions(-) diff --git a/include/wx/msw/taskbarbutton.h b/include/wx/msw/taskbarbutton.h index 04a368281e..444fd8d351 100644 --- a/include/wx/msw/taskbarbutton.h +++ b/include/wx/msw/taskbarbutton.h @@ -69,7 +69,8 @@ private: class WXDLLIMPEXP_CORE wxTaskBarJumpListImpl { public: - wxTaskBarJumpListImpl(const wxString& appID = wxEmptyString); + wxTaskBarJumpListImpl(wxTaskBarJumpList *jumpList = NULL, + const wxString& appID = wxEmptyString); virtual ~wxTaskBarJumpListImpl(); void ShowRecentCategory(bool shown = true); void HideRecentCategory(); @@ -93,6 +94,8 @@ private: void AddCustomCategoriesToDestionationList(); void LoadKnownCategory(const wxString& title); + wxTaskBarJumpList *m_jumpList; + ICustomDestinationList *m_destinationList; IObjectArray *m_objectArray; diff --git a/include/wx/taskbarbutton.h b/include/wx/taskbarbutton.h index c6fa6a23ee..b6b404efe0 100644 --- a/include/wx/taskbarbutton.h +++ b/include/wx/taskbarbutton.h @@ -20,6 +20,8 @@ // ---------------------------------------------------------------------------- class WXDLLIMPEXP_FWD_CORE wxTaskBarButton; +class WXDLLIMPEXP_FWD_CORE wxTaskBarJumpListCategory; +class WXDLLIMPEXP_FWD_CORE wxTaskBarJumpList; class WXDLLIMPEXP_FWD_CORE wxTaskBarJumpListImpl; /** @@ -151,13 +153,14 @@ enum WXDLLIMPEXP_CORE wxTaskBarJumpListItemType class WXDLLIMPEXP_CORE wxTaskBarJumpListItem { public: - wxTaskBarJumpListItem(wxTaskBarJumpListItemType type, - const wxString& title = wxEmptyString, - const wxString& filePath = wxEmptyString, - const wxString& arguments = wxEmptyString, - const wxString& tooltip = wxEmptyString, - const wxString& iconPath = wxEmptyString, - int iconIndex = 0); + wxTaskBarJumpListItem(wxTaskBarJumpListCategory *parentCategory = NULL, + wxTaskBarJumpListItemType type = wxTASKBAR_JUMP_LIST_SEPARATOR, + const wxString& title = wxEmptyString, + const wxString& filePath = wxEmptyString, + const wxString& arguments = wxEmptyString, + const wxString& tooltip = wxEmptyString, + const wxString& iconPath = wxEmptyString, + int iconIndex = 0); wxTaskBarJumpListItemType GetType() const; void SetType(wxTaskBarJumpListItemType type); @@ -173,8 +176,11 @@ public: void SetIconPath(const wxString& iconPath); int GetIconIndex() const; void SetIconIndex(int iconIndex); + wxTaskBarJumpListCategory* GetCategory() const; + void SetCategory(wxTaskBarJumpListCategory *category); private: + wxTaskBarJumpListCategory *m_parentCategory; wxTaskBarJumpListItemType m_type; wxString m_title; wxString m_filePath; @@ -189,7 +195,8 @@ typedef wxVector wxTaskBarJumpListItems; class WXDLLIMPEXP_CORE wxTaskBarJumpListCategory { public: - wxTaskBarJumpListCategory(const wxString& title = wxEmptyString); + wxTaskBarJumpListCategory(wxTaskBarJumpList *parent = NULL, + const wxString& title = wxEmptyString); virtual ~wxTaskBarJumpListCategory(); wxTaskBarJumpListItem* Append(wxTaskBarJumpListItem *item); @@ -203,6 +210,11 @@ public: const wxTaskBarJumpListItems& GetItems() const; private: + friend class wxTaskBarJumpListItem; + + void Update(); + + wxTaskBarJumpList *m_parent; wxTaskBarJumpListItems m_items; wxString m_title; }; @@ -228,9 +240,11 @@ public: wxTaskBarJumpListCategory* RemoveCustomCategory(const wxString& title); void DeleteCustomCategory(const wxString& title); - void Update(); private: + friend class wxTaskBarJumpListCategory; + + void Update(); wxTaskBarJumpListImpl *m_jumpListImpl; }; diff --git a/interface/wx/taskbarbutton.h b/interface/wx/taskbarbutton.h index c15e242774..594f7a30e2 100644 --- a/interface/wx/taskbarbutton.h +++ b/interface/wx/taskbarbutton.h @@ -399,6 +399,9 @@ public: /** Constructs a jump list item. + @param parentCategory + Category that the jump list item belongs to. Can be NULL if the item + is going to be added to the category later. @param type The type for this item. @param title @@ -419,13 +422,14 @@ public: @param iconIndex The index of the icon, which is specified by iconPath. */ - wxTaskBarJumpListItem(wxTaskBarJumpListItemType type, - const wxString& title = wxEmptyString, - const wxString& filePath = wxEmptyString, - const wxString& arguments = wxEmptyString, - const wxString& tooltip = wxEmptyString, - const wxString& iconPath = wxEmptyString, - int iconIndex = 0); + wxTaskBarJumpListItem(wxTaskBarJumpListCategory *parentCategory = NULL, + wxTaskBarJumpListItemType type = wxTASKBAR_JUMP_LIST_SEPARATOR, + const wxString& title = wxEmptyString, + const wxString& filePath = wxEmptyString, + const wxString& arguments = wxEmptyString, + const wxString& tooltip = wxEmptyString, + const wxString& iconPath = wxEmptyString, + int iconIndex = 0); /** Returns the type of this item. @@ -496,6 +500,17 @@ public: Sets the icon index of icon in this item. */ void SetIconIndex(int iconIndex); + + /** + Returns the category this jump list item is in, or NULL if this jump + list item is not attached. + */ + wxTaskBarJumpListCategory* GetCategory() const; + + /** + Sets the parent category which will contain this jump list item. + */ + void SetCategory(wxTaskBarJumpListCategory *category); }; /** @@ -523,17 +538,21 @@ public: /** Constructs the jump list category. + @param parent + Jump list that the jump list category belongs to. Can be NULL if + the category is going to be added to the jump list later. @param title The title of the category. */ - wxTaskBarJumpListCategory(const wxString& title = wxEmptyString); + wxTaskBarJumpListCategory(wxTaskBarJumpList *parent = NULL, + const wxString& title = wxEmptyString); virtual ~wxTaskBarJumpListCategory(); /** Append a jump list item. @param item - The jump list item to be appended. It will be owned by the + The jump list item to be appended. It will be owned by the wxTaskBarJumpListCategory object after this function is called, so do not delete it yourself. @@ -619,6 +638,4 @@ public: void AddCustomCategory(wxTaskBarJumpListCategory* category); wxTaskBarJumpListCategory* RemoveCustomCategory(const wxString& title); void DeleteCustomCategory(const wxString& title); - - void Update(); }; diff --git a/samples/taskbarbutton/taskbarbutton.cpp b/samples/taskbarbutton/taskbarbutton.cpp index a339bdea10..9d87b8e41a 100644 --- a/samples/taskbarbutton/taskbarbutton.cpp +++ b/samples/taskbarbutton/taskbarbutton.cpp @@ -142,6 +142,7 @@ bool MyApp::OnInit() wxTaskBarJumpList jumpList; wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem( + NULL, wxTASKBAR_JUMP_LIST_TASK, wxT("Task 1"), wxStandardPaths::Get().GetExecutablePath(), @@ -150,6 +151,7 @@ bool MyApp::OnInit() wxStandardPaths::Get().GetExecutablePath(), 0); wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem( + NULL, wxTASKBAR_JUMP_LIST_TASK, wxT("Task 2"), wxStandardPaths::Get().GetExecutablePath(), @@ -159,12 +161,15 @@ bool MyApp::OnInit() 0); jumpList.GetTasks().Append(item1); jumpList.GetTasks().Append( - new wxTaskBarJumpListItem(wxTASKBAR_JUMP_LIST_SEPARATOR)); + new wxTaskBarJumpListItem(NULL, wxTASKBAR_JUMP_LIST_SEPARATOR)); jumpList.GetTasks().Append(item2); jumpList.ShowRecentCategory(); jumpList.ShowFrequentCategory(); + wxTaskBarJumpListCategory* customCategory = + new wxTaskBarJumpListCategory(&jumpList, wxT("Custom")); wxTaskBarJumpListItem* item3 = new wxTaskBarJumpListItem( + customCategory, wxTASKBAR_JUMP_LIST_DESTIONATION, wxT("Help"), wxStandardPaths::Get().GetExecutablePath(), @@ -172,13 +177,9 @@ bool MyApp::OnInit() wxT("wxTaskBarButton help."), wxStandardPaths::Get().GetExecutablePath(), 0); - wxTaskBarJumpListCategory* customCategory = - new wxTaskBarJumpListCategory(wxT("Custom")); customCategory->Append(item3); jumpList.AddCustomCategory(customCategory); - jumpList.Update(); - const wxTaskBarJumpListCategory& frequentCategory = jumpList.GetFrequentCategory(); const wxTaskBarJumpListItems& frequentItems = frequentCategory.GetItems(); diff --git a/src/msw/taskbarbutton.cpp b/src/msw/taskbarbutton.cpp index 3c3ee5b235..651678311e 100644 --- a/src/msw/taskbarbutton.cpp +++ b/src/msw/taskbarbutton.cpp @@ -435,7 +435,7 @@ wxTaskBarJumpListItem* GetItemFromIShellLink(IShellLink* link) return NULL; wxTaskBarJumpListItem* item = - new wxTaskBarJumpListItem(wxTASKBAR_JUMP_LIST_DESTIONATION); + new wxTaskBarJumpListItem(NULL, wxTASKBAR_JUMP_LIST_DESTIONATION); IPropertyStore *linkProps; HRESULT hr = link->QueryInterface @@ -477,7 +477,7 @@ wxTaskBarJumpListItem* GetItemFromIShellItem(IShellItem *shellItem) return NULL; wxTaskBarJumpListItem *item = - new wxTaskBarJumpListItem(wxTASKBAR_JUMP_LIST_DESTIONATION); + new wxTaskBarJumpListItem(NULL, wxTASKBAR_JUMP_LIST_DESTIONATION); wchar_t *name; shellItem->GetDisplayName(SIGDN_FILESYSPATH, &name); @@ -902,14 +902,16 @@ void wxAppProgressIndicator::Init() // ---------------------------------------------------------------------------- // wxTaskBarJumpListItem Implementation. // ---------------------------------------------------------------------------- -wxTaskBarJumpListItem::wxTaskBarJumpListItem(wxTaskBarJumpListItemType type, +wxTaskBarJumpListItem::wxTaskBarJumpListItem(wxTaskBarJumpListCategory *parent, + wxTaskBarJumpListItemType type, const wxString& title, const wxString& filePath, const wxString& arguments, const wxString& tooltip, const wxString& iconPath, int iconIndex) - : m_type(type), + : m_parentCategory(parent), + m_type(type), m_title(title), m_filePath(filePath), m_arguments(arguments), @@ -927,6 +929,8 @@ wxTaskBarJumpListItemType wxTaskBarJumpListItem::GetType() const void wxTaskBarJumpListItem::SetType(wxTaskBarJumpListItemType type) { m_type = type; + if ( m_parentCategory ) + m_parentCategory->Update(); } const wxString& wxTaskBarJumpListItem::GetTitle() const @@ -937,6 +941,8 @@ const wxString& wxTaskBarJumpListItem::GetTitle() const void wxTaskBarJumpListItem::SetTitle(const wxString& title) { m_title = title; + if ( m_parentCategory ) + m_parentCategory->Update(); } const wxString& wxTaskBarJumpListItem::GetFilePath() const @@ -947,6 +953,8 @@ const wxString& wxTaskBarJumpListItem::GetFilePath() const void wxTaskBarJumpListItem::SetFilePath(const wxString& filePath) { m_filePath = filePath; + if ( m_parentCategory ) + m_parentCategory->Update(); } const wxString& wxTaskBarJumpListItem::GetArguments() const @@ -957,6 +965,8 @@ const wxString& wxTaskBarJumpListItem::GetArguments() const void wxTaskBarJumpListItem::SetArguments(const wxString& arguments) { m_arguments = arguments; + if ( m_parentCategory ) + m_parentCategory->Update(); } const wxString& wxTaskBarJumpListItem::GetTooltip() const @@ -967,6 +977,8 @@ const wxString& wxTaskBarJumpListItem::GetTooltip() const void wxTaskBarJumpListItem::SetTooltip(const wxString& tooltip) { m_tooltip = tooltip; + if ( m_parentCategory ) + m_parentCategory->Update(); } const wxString& wxTaskBarJumpListItem::GetIconPath() const @@ -977,6 +989,8 @@ const wxString& wxTaskBarJumpListItem::GetIconPath() const void wxTaskBarJumpListItem::SetIconPath(const wxString& iconPath) { m_iconPath = iconPath; + if ( m_parentCategory ) + m_parentCategory->Update(); } int wxTaskBarJumpListItem::GetIconIndex() const @@ -987,13 +1001,27 @@ int wxTaskBarJumpListItem::GetIconIndex() const void wxTaskBarJumpListItem::SetIconIndex(int iconIndex) { m_iconIndex = iconIndex; + if ( m_parentCategory ) + m_parentCategory->Update(); +} + +wxTaskBarJumpListCategory* wxTaskBarJumpListItem::GetCategory() const +{ + return m_parentCategory; +} + +void wxTaskBarJumpListItem::SetCategory(wxTaskBarJumpListCategory *category) +{ + m_parentCategory = category; } // ---------------------------------------------------------------------------- // wxTaskBarJumpListCategory Implementation. // ---------------------------------------------------------------------------- -wxTaskBarJumpListCategory::wxTaskBarJumpListCategory(const wxString& title) - : m_title(title) +wxTaskBarJumpListCategory::wxTaskBarJumpListCategory(wxTaskBarJumpList *parent, + const wxString& title) + : m_parent(parent), + m_title(title) { } @@ -1011,12 +1039,18 @@ wxTaskBarJumpListItem* wxTaskBarJumpListCategory::Append(wxTaskBarJumpListItem *item) { m_items.push_back(item); + item->SetCategory(this); + Update(); + return item; } void wxTaskBarJumpListCategory::Delete(wxTaskBarJumpListItem *item) { item = Remove(item); + item->SetCategory(NULL); + Update(); + if ( item ) delete item; } @@ -1031,6 +1065,8 @@ wxTaskBarJumpListCategory::Remove(wxTaskBarJumpListItem *item) if ( *it == item ) { m_items.erase(it); + item->SetCategory(NULL); + Update(); return item; } } @@ -1050,6 +1086,9 @@ wxTaskBarJumpListCategory::Insert(size_t pos, wxTaskBarJumpListItem *item) { wxASSERT_MSG( pos <= m_items.size(), "invalid pos." ); m_items.insert(m_items.begin() + pos, item); + item->SetCategory(this); + Update(); + return item; } @@ -1062,6 +1101,7 @@ wxTaskBarJumpListCategory::Prepend(wxTaskBarJumpListItem *item) void wxTaskBarJumpListCategory::SetTitle(const wxString& title) { m_title = title; + Update(); } const wxString& wxTaskBarJumpListCategory::GetTitle() const @@ -1074,11 +1114,17 @@ const wxTaskBarJumpListItems& wxTaskBarJumpListCategory::GetItems() const return m_items; } +void wxTaskBarJumpListCategory::Update() +{ + if ( m_parent ) + m_parent->Update(); +} + // ---------------------------------------------------------------------------- // wxTaskBarJumpList Implementation. // ---------------------------------------------------------------------------- wxTaskBarJumpList::wxTaskBarJumpList(const wxString& appID) - : m_jumpListImpl(new wxTaskBarJumpListImpl(appID)) + : m_jumpListImpl(new wxTaskBarJumpListImpl(this, appID)) { } @@ -1152,8 +1198,10 @@ void wxTaskBarJumpList::Update() // ---------------------------------------------------------------------------- // wxTaskBarJumpListImpl Implementation. // ---------------------------------------------------------------------------- -wxTaskBarJumpListImpl::wxTaskBarJumpListImpl(const wxString& appID) - : m_appID(appID), +wxTaskBarJumpListImpl::wxTaskBarJumpListImpl(wxTaskBarJumpList *jumpList, + const wxString& appID) + : m_jumpList(jumpList), + m_appID(appID), m_destinationList(NULL) { HRESULT hr = CoCreateInstance @@ -1201,7 +1249,7 @@ void wxTaskBarJumpListImpl::Update() wxTaskBarJumpListCategory& wxTaskBarJumpListImpl::GetTasks() { if ( m_tasks.get() == NULL ) - m_tasks.reset(new wxTaskBarJumpListCategory(wxT("Tasks"))); + m_tasks.reset(new wxTaskBarJumpListCategory(m_jumpList, wxT("Tasks"))); return *(m_tasks.get()); } @@ -1230,7 +1278,7 @@ const wxTaskBarJumpListCategory& wxTaskBarJumpListImpl::GetFrequentCategory() { wxString title = wxT("Frequent"); if ( m_frequent.get() == NULL ) - m_frequent.reset(new wxTaskBarJumpListCategory(title)); + m_frequent.reset(new wxTaskBarJumpListCategory(m_jumpList, title)); LoadKnownCategory(title); return *m_frequent.get(); @@ -1240,7 +1288,7 @@ const wxTaskBarJumpListCategory& wxTaskBarJumpListImpl::GetRecentCategory() { wxString title = wxT("Recent"); if ( m_recent.get() == NULL ) - m_recent.reset(new wxTaskBarJumpListCategory(title)); + m_recent.reset(new wxTaskBarJumpListCategory(m_jumpList, title)); LoadKnownCategory(title); return *m_recent.get();