2009-10-05 19:26:54 -07:00
|
|
|
/* vim: se cin sw=2 ts=2 et : */
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-10-05 19:26:54 -07:00
|
|
|
|
2013-12-08 18:52:54 -08:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
2009-10-05 19:26:54 -07:00
|
|
|
#include <nsITaskbarPreviewController.h>
|
|
|
|
#include "TaskbarWindowPreview.h"
|
|
|
|
#include "WindowHook.h"
|
|
|
|
#include "nsUXThemeData.h"
|
|
|
|
#include "TaskbarPreviewButton.h"
|
|
|
|
#include "nsWindow.h"
|
2011-09-28 11:36:43 -07:00
|
|
|
#include "nsWindowGfx.h"
|
2009-10-05 19:26:54 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
namespace {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool WindowHookProc(void *aContext, HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam, LRESULT *aResult)
|
2009-10-05 19:26:54 -07:00
|
|
|
{
|
|
|
|
TaskbarWindowPreview *preview = reinterpret_cast<TaskbarWindowPreview*>(aContext);
|
|
|
|
*aResult = preview->WndProc(nMsg, wParam, lParam);
|
2011-10-01 19:16:19 -07:00
|
|
|
return true;
|
2009-10-05 19:26:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-28 11:36:43 -07:00
|
|
|
NS_IMPL_ISUPPORTS4(TaskbarWindowPreview, nsITaskbarWindowPreview,
|
|
|
|
nsITaskbarProgress, nsITaskbarOverlayIconController,
|
|
|
|
nsISupportsWeakReference)
|
2009-10-06 12:00:23 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* These correspond directly to the states defined in nsITaskbarProgress.idl, so
|
|
|
|
* they should be kept in sync.
|
|
|
|
*/
|
|
|
|
static TBPFLAG sNativeStates[] =
|
|
|
|
{
|
|
|
|
TBPF_NOPROGRESS,
|
|
|
|
TBPF_INDETERMINATE,
|
|
|
|
TBPF_NORMAL,
|
|
|
|
TBPF_ERROR,
|
|
|
|
TBPF_PAUSED
|
|
|
|
};
|
2009-10-05 19:26:54 -07:00
|
|
|
|
|
|
|
TaskbarWindowPreview::TaskbarWindowPreview(ITaskbarList4 *aTaskbar, nsITaskbarPreviewController *aController, HWND aHWND, nsIDocShell *aShell)
|
|
|
|
: TaskbarPreview(aTaskbar, aController, aHWND, aShell),
|
2011-10-01 19:16:19 -07:00
|
|
|
mCustomDrawing(false),
|
|
|
|
mHaveButtons(false),
|
2009-10-06 12:00:23 -07:00
|
|
|
mState(TBPF_NOPROGRESS),
|
|
|
|
mCurrentValue(0),
|
2011-09-28 11:36:43 -07:00
|
|
|
mMaxValue(0),
|
2013-10-08 11:48:20 -07:00
|
|
|
mOverlayIcon(nullptr)
|
2009-10-05 19:26:54 -07:00
|
|
|
{
|
|
|
|
// Window previews are visible by default
|
2011-10-01 19:16:19 -07:00
|
|
|
(void) SetVisible(true);
|
2009-10-05 19:26:54 -07:00
|
|
|
|
|
|
|
memset(mThumbButtons, 0, sizeof mThumbButtons);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < nsITaskbarWindowPreview::NUM_TOOLBAR_BUTTONS; i++) {
|
2009-10-05 19:26:54 -07:00
|
|
|
mThumbButtons[i].dwMask = THB_FLAGS | THB_ICON | THB_TOOLTIP;
|
|
|
|
mThumbButtons[i].iId = i;
|
|
|
|
mThumbButtons[i].dwFlags = THBF_HIDDEN;
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:00:23 -07:00
|
|
|
WindowHook &hook = GetWindowHook();
|
|
|
|
if (!CanMakeTaskbarCalls())
|
|
|
|
hook.AddMonitor(nsAppShell::GetTaskbarButtonCreatedMessage(),
|
2011-09-28 11:36:43 -07:00
|
|
|
TaskbarWindowHook, this);
|
2009-10-05 19:26:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
TaskbarWindowPreview::~TaskbarWindowPreview() {
|
2011-09-28 11:36:43 -07:00
|
|
|
if (mOverlayIcon) {
|
|
|
|
::DestroyIcon(mOverlayIcon);
|
2013-10-08 11:48:20 -07:00
|
|
|
mOverlayIcon = nullptr;
|
2011-09-28 11:36:43 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 07:02:36 -07:00
|
|
|
if (IsWindowAvailable()) {
|
2010-04-21 12:09:59 -07:00
|
|
|
DetachFromNSWindow();
|
2011-09-28 07:02:36 -07:00
|
|
|
} else {
|
2013-10-08 11:48:20 -07:00
|
|
|
mWnd = nullptr;
|
2011-09-28 07:02:36 -07:00
|
|
|
}
|
2009-10-05 19:26:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
TaskbarWindowPreview::ShowActive(bool active) {
|
2013-10-08 11:48:20 -07:00
|
|
|
return FAILED(mTaskbar->ActivateTab(active ? mWnd : nullptr))
|
2009-10-05 19:26:54 -07:00
|
|
|
? NS_ERROR_FAILURE
|
|
|
|
: NS_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND &
|
|
|
|
TaskbarWindowPreview::PreviewWindow() {
|
|
|
|
return mWnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
TaskbarWindowPreview::GetButton(uint32_t index, nsITaskbarPreviewButton **_retVal) {
|
2009-10-05 19:56:54 -07:00
|
|
|
if (index >= nsITaskbarWindowPreview::NUM_TOOLBAR_BUTTONS)
|
2009-10-05 19:26:54 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITaskbarPreviewButton> button(do_QueryReferent(mWeakButtons[index]));
|
|
|
|
|
|
|
|
if (!button) {
|
|
|
|
// Lost reference
|
|
|
|
button = new TaskbarPreviewButton(this, index);
|
|
|
|
if (!button) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mWeakButtons[index] = do_GetWeakReference(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mHaveButtons) {
|
2011-10-01 19:16:19 -07:00
|
|
|
mHaveButtons = true;
|
2009-10-05 19:26:54 -07:00
|
|
|
|
|
|
|
WindowHook &hook = GetWindowHook();
|
|
|
|
(void) hook.AddHook(WM_COMMAND, WindowHookProc, this);
|
|
|
|
|
2009-10-05 19:56:54 -07:00
|
|
|
if (mVisible && FAILED(mTaskbar->ThumbBarAddButtons(mWnd, nsITaskbarWindowPreview::NUM_TOOLBAR_BUTTONS, mThumbButtons))) {
|
2009-10-05 19:26:54 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
button.forget(_retVal);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
TaskbarWindowPreview::SetEnableCustomDrawing(bool aEnable) {
|
2009-10-05 19:26:54 -07:00
|
|
|
if (aEnable == mCustomDrawing)
|
|
|
|
return NS_OK;
|
|
|
|
mCustomDrawing = aEnable;
|
|
|
|
TaskbarPreview::EnableCustomDrawing(mWnd, aEnable);
|
|
|
|
|
|
|
|
WindowHook &hook = GetWindowHook();
|
|
|
|
if (aEnable) {
|
|
|
|
(void) hook.AddHook(WM_DWMSENDICONICTHUMBNAIL, WindowHookProc, this);
|
|
|
|
(void) hook.AddHook(WM_DWMSENDICONICLIVEPREVIEWBITMAP, WindowHookProc, this);
|
|
|
|
} else {
|
|
|
|
(void) hook.RemoveHook(WM_DWMSENDICONICLIVEPREVIEWBITMAP, WindowHookProc, this);
|
|
|
|
(void) hook.RemoveHook(WM_DWMSENDICONICTHUMBNAIL, WindowHookProc, this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
TaskbarWindowPreview::GetEnableCustomDrawing(bool *aEnable) {
|
2009-10-05 19:26:54 -07:00
|
|
|
*aEnable = mCustomDrawing;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:00:23 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TaskbarWindowPreview::SetProgressState(nsTaskbarProgressState aState,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aCurrentValue,
|
|
|
|
uint64_t aMaxValue)
|
2009-10-06 12:00:23 -07:00
|
|
|
{
|
2013-11-05 09:50:17 -08:00
|
|
|
NS_ENSURE_ARG_RANGE(aState,
|
|
|
|
nsTaskbarProgressState(0),
|
|
|
|
nsTaskbarProgressState(ArrayLength(sNativeStates) - 1));
|
2009-10-06 12:00:23 -07:00
|
|
|
|
|
|
|
TBPFLAG nativeState = sNativeStates[aState];
|
|
|
|
if (nativeState == TBPF_NOPROGRESS || nativeState == TBPF_INDETERMINATE) {
|
|
|
|
NS_ENSURE_TRUE(aCurrentValue == 0, NS_ERROR_INVALID_ARG);
|
|
|
|
NS_ENSURE_TRUE(aMaxValue == 0, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCurrentValue > aMaxValue)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
mState = nativeState;
|
|
|
|
mCurrentValue = aCurrentValue;
|
|
|
|
mMaxValue = aMaxValue;
|
|
|
|
|
|
|
|
// Only update if we can
|
|
|
|
return CanMakeTaskbarCalls() ? UpdateTaskbarProgress() : NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-28 11:36:43 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
TaskbarWindowPreview::SetOverlayIcon(imgIContainer* aStatusIcon,
|
|
|
|
const nsAString& aStatusDescription) {
|
|
|
|
nsresult rv;
|
|
|
|
if (aStatusIcon) {
|
|
|
|
// The image shouldn't be animated
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isAnimated;
|
2011-09-28 11:36:43 -07:00
|
|
|
rv = aStatusIcon->GetAnimated(&isAnimated);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_FALSE(isAnimated, NS_ERROR_INVALID_ARG);
|
|
|
|
}
|
|
|
|
|
2013-10-08 11:48:20 -07:00
|
|
|
HICON hIcon = nullptr;
|
2011-09-28 11:36:43 -07:00
|
|
|
if (aStatusIcon) {
|
|
|
|
rv = nsWindowGfx::CreateIcon(aStatusIcon, false, 0, 0,
|
|
|
|
nsWindowGfx::GetIconMetrics(nsWindowGfx::kSmallIcon),
|
|
|
|
&hIcon);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mOverlayIcon)
|
|
|
|
::DestroyIcon(mOverlayIcon);
|
|
|
|
mOverlayIcon = hIcon;
|
|
|
|
mIconDescription = aStatusDescription;
|
|
|
|
|
|
|
|
// Only update if we can
|
|
|
|
return CanMakeTaskbarCalls() ? UpdateOverlayIcon() : NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-05 19:26:54 -07:00
|
|
|
nsresult
|
|
|
|
TaskbarWindowPreview::UpdateTaskbarProperties() {
|
|
|
|
if (mHaveButtons) {
|
2009-10-05 19:56:54 -07:00
|
|
|
if (FAILED(mTaskbar->ThumbBarAddButtons(mWnd, nsITaskbarWindowPreview::NUM_TOOLBAR_BUTTONS, mThumbButtons)))
|
2009-10-05 19:26:54 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2009-10-06 12:00:23 -07:00
|
|
|
nsresult rv = UpdateTaskbarProgress();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2011-09-28 11:36:43 -07:00
|
|
|
rv = UpdateOverlayIcon();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-10-05 19:26:54 -07:00
|
|
|
return TaskbarPreview::UpdateTaskbarProperties();
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:00:23 -07:00
|
|
|
nsresult
|
|
|
|
TaskbarWindowPreview::UpdateTaskbarProgress() {
|
|
|
|
HRESULT hr = mTaskbar->SetProgressState(mWnd, mState);
|
|
|
|
if (SUCCEEDED(hr) && mState != TBPF_NOPROGRESS &&
|
|
|
|
mState != TBPF_INDETERMINATE)
|
|
|
|
hr = mTaskbar->SetProgressValue(mWnd, mCurrentValue, mMaxValue);
|
|
|
|
|
|
|
|
return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-09-28 11:36:43 -07:00
|
|
|
nsresult
|
|
|
|
TaskbarWindowPreview::UpdateOverlayIcon() {
|
|
|
|
HRESULT hr = mTaskbar->SetOverlayIcon(mWnd, mOverlayIcon,
|
|
|
|
mIconDescription.get());
|
|
|
|
return SUCCEEDED(hr) ? NS_OK : NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-10-05 19:26:54 -07:00
|
|
|
LRESULT
|
|
|
|
TaskbarWindowPreview::WndProc(UINT nMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
nsRefPtr<TaskbarWindowPreview> kungFuDeathGrip(this);
|
|
|
|
switch (nMsg) {
|
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t id = LOWORD(wParam);
|
|
|
|
uint32_t index = id;
|
2009-10-05 19:26:54 -07:00
|
|
|
nsCOMPtr<nsITaskbarPreviewButton> button;
|
|
|
|
nsresult rv = GetButton(index, getter_AddRefs(button));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mController->OnClick(button);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return TaskbarPreview::WndProc(nMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2009-10-06 12:00:23 -07:00
|
|
|
/* static */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2011-09-28 11:36:43 -07:00
|
|
|
TaskbarWindowPreview::TaskbarWindowHook(void *aContext,
|
|
|
|
HWND hWnd, UINT nMsg,
|
|
|
|
WPARAM wParam, LPARAM lParam,
|
|
|
|
LRESULT *aResult)
|
2009-10-06 12:00:23 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(nMsg == nsAppShell::GetTaskbarButtonCreatedMessage(),
|
|
|
|
"Window hook proc called with wrong message");
|
|
|
|
TaskbarWindowPreview *preview =
|
|
|
|
reinterpret_cast<TaskbarWindowPreview*>(aContext);
|
|
|
|
// Now we can make all the calls to mTaskbar
|
2011-09-28 11:36:43 -07:00
|
|
|
preview->UpdateTaskbarProperties();
|
2011-10-01 19:16:19 -07:00
|
|
|
return false;
|
2009-10-06 12:00:23 -07:00
|
|
|
}
|
|
|
|
|
2009-10-05 19:26:54 -07:00
|
|
|
nsresult
|
|
|
|
TaskbarWindowPreview::Enable() {
|
|
|
|
nsresult rv = TaskbarPreview::Enable();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return FAILED(mTaskbar->AddTab(mWnd))
|
|
|
|
? NS_ERROR_FAILURE
|
|
|
|
: NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TaskbarWindowPreview::Disable() {
|
|
|
|
nsresult rv = TaskbarPreview::Disable();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return FAILED(mTaskbar->DeleteTab(mWnd))
|
|
|
|
? NS_ERROR_FAILURE
|
|
|
|
: NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-21 12:09:59 -07:00
|
|
|
TaskbarWindowPreview::DetachFromNSWindow() {
|
|
|
|
// Remove the hooks we have for drawing
|
2011-10-01 19:16:19 -07:00
|
|
|
SetEnableCustomDrawing(false);
|
2009-10-05 19:26:54 -07:00
|
|
|
|
2010-04-21 12:09:59 -07:00
|
|
|
WindowHook &hook = GetWindowHook();
|
|
|
|
(void) hook.RemoveHook(WM_COMMAND, WindowHookProc, this);
|
|
|
|
(void) hook.RemoveMonitor(nsAppShell::GetTaskbarButtonCreatedMessage(),
|
2011-09-28 11:36:43 -07:00
|
|
|
TaskbarWindowHook, this);
|
2009-10-05 19:26:54 -07:00
|
|
|
|
2010-04-21 12:09:59 -07:00
|
|
|
TaskbarPreview::DetachFromNSWindow();
|
2009-10-05 19:26:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
TaskbarWindowPreview::UpdateButtons() {
|
|
|
|
NS_ASSERTION(mVisible, "UpdateButtons called on invisible preview");
|
|
|
|
|
2009-10-05 19:56:54 -07:00
|
|
|
if (FAILED(mTaskbar->ThumbBarUpdateButtons(mWnd, nsITaskbarWindowPreview::NUM_TOOLBAR_BUTTONS, mThumbButtons)))
|
2009-10-05 19:26:54 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
TaskbarWindowPreview::UpdateButton(uint32_t index) {
|
2009-10-05 19:56:54 -07:00
|
|
|
if (index >= nsITaskbarWindowPreview::NUM_TOOLBAR_BUTTONS)
|
2009-10-05 19:26:54 -07:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
if (mVisible) {
|
|
|
|
if (FAILED(mTaskbar->ThumbBarUpdateButtons(mWnd, 1, &mThumbButtons[index])))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|