Save the taskbar object
This commit is contained in:
parent
2d6f8350cb
commit
8da7803f3e
2 changed files with 27 additions and 21 deletions
|
@ -4,12 +4,9 @@
|
||||||
|
|
||||||
#include "atom/browser/ui/win/taskbar_host.h"
|
#include "atom/browser/ui/win/taskbar_host.h"
|
||||||
|
|
||||||
#include <shobjidl.h>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/stl_util.h"
|
#include "base/stl_util.h"
|
||||||
#include "base/win/scoped_comptr.h"
|
|
||||||
#include "base/win/scoped_gdi_object.h"
|
#include "base/win/scoped_gdi_object.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "third_party/skia/include/core/SkBitmap.h"
|
#include "third_party/skia/include/core/SkBitmap.h"
|
||||||
|
@ -57,13 +54,8 @@ TaskbarHost::~TaskbarHost() {
|
||||||
|
|
||||||
bool TaskbarHost::SetThumbarButtons(
|
bool TaskbarHost::SetThumbarButtons(
|
||||||
HWND window, const std::vector<ThumbarButton>& buttons) {
|
HWND window, const std::vector<ThumbarButton>& buttons) {
|
||||||
base::win::ScopedComPtr<ITaskbarList3> taskbar;
|
if (!InitailizeTaskbar())
|
||||||
if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList,
|
|
||||||
nullptr,
|
|
||||||
CLSCTX_INPROC_SERVER)) ||
|
|
||||||
FAILED(taskbar->HrInit())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
callback_map_.clear();
|
callback_map_.clear();
|
||||||
|
|
||||||
|
@ -115,30 +107,26 @@ bool TaskbarHost::SetThumbarButtons(
|
||||||
// Finally add them to taskbar.
|
// Finally add them to taskbar.
|
||||||
HRESULT r;
|
HRESULT r;
|
||||||
if (thumbar_buttons_added_)
|
if (thumbar_buttons_added_)
|
||||||
r = taskbar->ThumbBarUpdateButtons(window, kMaxButtonsCount, thumb_buttons);
|
r = taskbar_->ThumbBarUpdateButtons(window, kMaxButtonsCount,
|
||||||
|
thumb_buttons);
|
||||||
else
|
else
|
||||||
r = taskbar->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons);
|
r = taskbar_->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons);
|
||||||
|
|
||||||
thumbar_buttons_added_ = true;
|
thumbar_buttons_added_ = true;
|
||||||
return SUCCEEDED(r);
|
return SUCCEEDED(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TaskbarHost::SetProgressBar(HWND window, double value) {
|
bool TaskbarHost::SetProgressBar(HWND window, double value) {
|
||||||
base::win::ScopedComPtr<ITaskbarList3> taskbar;
|
if (!InitailizeTaskbar())
|
||||||
if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList,
|
|
||||||
nullptr,
|
|
||||||
CLSCTX_INPROC_SERVER)) ||
|
|
||||||
FAILED(taskbar->HrInit())) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
HRESULT r;
|
HRESULT r;
|
||||||
if (value > 1.0)
|
if (value > 1.0)
|
||||||
r = taskbar->SetProgressState(window, TBPF_INDETERMINATE);
|
r = taskbar_->SetProgressState(window, TBPF_INDETERMINATE);
|
||||||
else if (value < 0)
|
else if (value < 0)
|
||||||
r = taskbar->SetProgressState(window, TBPF_NOPROGRESS);
|
r = taskbar_->SetProgressState(window, TBPF_NOPROGRESS);
|
||||||
else
|
else
|
||||||
r= taskbar->SetProgressValue(window, static_cast<int>(value * 100), 100);
|
r= taskbar_->SetProgressValue(window, static_cast<int>(value * 100), 100);
|
||||||
return SUCCEEDED(r);
|
return SUCCEEDED(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,4 +140,15 @@ bool TaskbarHost::HandleThumbarButtonEvent(int button_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TaskbarHost::InitailizeTaskbar() {
|
||||||
|
if (FAILED(taskbar_.CreateInstance(CLSID_TaskbarList,
|
||||||
|
nullptr,
|
||||||
|
CLSCTX_INPROC_SERVER)) ||
|
||||||
|
FAILED(taskbar_->HrInit())) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
#ifndef ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_
|
#ifndef ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_
|
||||||
#define ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_
|
#define ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_
|
||||||
|
|
||||||
#include <windows.h>
|
#include <shobjidl.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
|
#include "base/win/scoped_comptr.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
@ -39,9 +40,15 @@ class TaskbarHost {
|
||||||
bool HandleThumbarButtonEvent(int button_id);
|
bool HandleThumbarButtonEvent(int button_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Initailize the taskbar object.
|
||||||
|
bool InitailizeTaskbar();
|
||||||
|
|
||||||
using CallbackMap = std::map<int, base::Closure>;
|
using CallbackMap = std::map<int, base::Closure>;
|
||||||
CallbackMap callback_map_;
|
CallbackMap callback_map_;
|
||||||
|
|
||||||
|
// The COM object of taskbar.
|
||||||
|
base::win::ScopedComPtr<ITaskbarList3> taskbar_;
|
||||||
|
|
||||||
// Whether we have already added the buttons to thumbar.
|
// Whether we have already added the buttons to thumbar.
|
||||||
bool thumbar_buttons_added_;
|
bool thumbar_buttons_added_;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue