michael@0: /* vim: se cin sw=2 ts=2 et : */ michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "TaskbarWindowPreview.h" michael@0: #include "TaskbarPreviewButton.h" michael@0: #include "nsWindowGfx.h" michael@0: #include michael@0: michael@0: namespace mozilla { michael@0: namespace widget { michael@0: michael@0: NS_IMPL_ISUPPORTS(TaskbarPreviewButton, nsITaskbarPreviewButton, nsISupportsWeakReference) michael@0: michael@0: TaskbarPreviewButton::TaskbarPreviewButton(TaskbarWindowPreview* preview, uint32_t index) michael@0: : mPreview(preview), mIndex(index) michael@0: { michael@0: } michael@0: michael@0: TaskbarPreviewButton::~TaskbarPreviewButton() { michael@0: SetVisible(false); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::GetTooltip(nsAString &aTooltip) { michael@0: aTooltip = mTooltip; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::SetTooltip(const nsAString &aTooltip) { michael@0: mTooltip = aTooltip; michael@0: size_t destLength = sizeof Button().szTip / (sizeof Button().szTip[0]); michael@0: wchar_t *tooltip = &(Button().szTip[0]); michael@0: StringCchCopyNW(tooltip, michael@0: destLength, michael@0: mTooltip.get(), michael@0: mTooltip.Length()); michael@0: return Update(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::GetDismissOnClick(bool *dismiss) { michael@0: *dismiss = (Button().dwFlags & THBF_DISMISSONCLICK) == THBF_DISMISSONCLICK; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::SetDismissOnClick(bool dismiss) { michael@0: if (dismiss) michael@0: Button().dwFlags |= THBF_DISMISSONCLICK; michael@0: else michael@0: Button().dwFlags &= ~THBF_DISMISSONCLICK; michael@0: return Update(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::GetHasBorder(bool *hasBorder) { michael@0: *hasBorder = (Button().dwFlags & THBF_NOBACKGROUND) != THBF_NOBACKGROUND; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::SetHasBorder(bool hasBorder) { michael@0: if (hasBorder) michael@0: Button().dwFlags &= ~THBF_NOBACKGROUND; michael@0: else michael@0: Button().dwFlags |= THBF_NOBACKGROUND; michael@0: return Update(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::GetDisabled(bool *disabled) { michael@0: *disabled = (Button().dwFlags & THBF_DISABLED) == THBF_DISABLED; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::SetDisabled(bool disabled) { michael@0: if (disabled) michael@0: Button().dwFlags |= THBF_DISABLED; michael@0: else michael@0: Button().dwFlags &= ~THBF_DISABLED; michael@0: return Update(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::GetImage(imgIContainer **img) { michael@0: if (mImage) michael@0: NS_ADDREF(*img = mImage); michael@0: else michael@0: *img = nullptr; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::SetImage(imgIContainer *img) { michael@0: if (Button().hIcon) michael@0: ::DestroyIcon(Button().hIcon); michael@0: if (img) { michael@0: nsresult rv; michael@0: rv = nsWindowGfx::CreateIcon(img, false, 0, 0, michael@0: nsWindowGfx::GetIconMetrics(nsWindowGfx::kRegularIcon), michael@0: &Button().hIcon); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: } else { michael@0: Button().hIcon = nullptr; michael@0: } michael@0: return Update(); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::GetVisible(bool *visible) { michael@0: *visible = (Button().dwFlags & THBF_HIDDEN) != THBF_HIDDEN; michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: TaskbarPreviewButton::SetVisible(bool visible) { michael@0: if (visible) michael@0: Button().dwFlags &= ~THBF_HIDDEN; michael@0: else michael@0: Button().dwFlags |= THBF_HIDDEN; michael@0: return Update(); michael@0: } michael@0: michael@0: THUMBBUTTON& michael@0: TaskbarPreviewButton::Button() { michael@0: return mPreview->mThumbButtons[mIndex]; michael@0: } michael@0: michael@0: nsresult michael@0: TaskbarPreviewButton::Update() { michael@0: return mPreview->UpdateButton(mIndex); michael@0: } michael@0: michael@0: } // namespace widget michael@0: } // namespace mozilla michael@0: