widget/windows/TaskbarPreviewButton.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* vim: se cin sw=2 ts=2 et : */
     2 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     3  *
     4  * This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include <windows.h>
     9 #include <strsafe.h>
    11 #include "TaskbarWindowPreview.h"
    12 #include "TaskbarPreviewButton.h"
    13 #include "nsWindowGfx.h"
    14 #include <imgIContainer.h>
    16 namespace mozilla {
    17 namespace widget {
    19 NS_IMPL_ISUPPORTS(TaskbarPreviewButton, nsITaskbarPreviewButton, nsISupportsWeakReference)
    21 TaskbarPreviewButton::TaskbarPreviewButton(TaskbarWindowPreview* preview, uint32_t index)
    22   : mPreview(preview), mIndex(index)
    23 {
    24 }
    26 TaskbarPreviewButton::~TaskbarPreviewButton() {
    27   SetVisible(false);
    28 }
    30 NS_IMETHODIMP
    31 TaskbarPreviewButton::GetTooltip(nsAString &aTooltip) {
    32   aTooltip = mTooltip;
    33   return NS_OK;
    34 }
    36 NS_IMETHODIMP
    37 TaskbarPreviewButton::SetTooltip(const nsAString &aTooltip) {
    38   mTooltip = aTooltip;
    39   size_t destLength = sizeof Button().szTip / (sizeof Button().szTip[0]);
    40   wchar_t *tooltip = &(Button().szTip[0]);
    41   StringCchCopyNW(tooltip,
    42                   destLength,
    43                   mTooltip.get(),
    44                   mTooltip.Length());
    45   return Update();
    46 }
    48 NS_IMETHODIMP
    49 TaskbarPreviewButton::GetDismissOnClick(bool *dismiss) {
    50   *dismiss = (Button().dwFlags & THBF_DISMISSONCLICK) == THBF_DISMISSONCLICK;
    51   return NS_OK;
    52 }
    54 NS_IMETHODIMP
    55 TaskbarPreviewButton::SetDismissOnClick(bool dismiss) {
    56   if (dismiss)
    57     Button().dwFlags |= THBF_DISMISSONCLICK;
    58   else
    59     Button().dwFlags &= ~THBF_DISMISSONCLICK;
    60   return Update();
    61 }
    63 NS_IMETHODIMP
    64 TaskbarPreviewButton::GetHasBorder(bool *hasBorder) {
    65   *hasBorder = (Button().dwFlags & THBF_NOBACKGROUND) != THBF_NOBACKGROUND;
    66   return NS_OK;
    67 }
    69 NS_IMETHODIMP
    70 TaskbarPreviewButton::SetHasBorder(bool hasBorder) {
    71   if (hasBorder)
    72     Button().dwFlags &= ~THBF_NOBACKGROUND;
    73   else
    74     Button().dwFlags |= THBF_NOBACKGROUND;
    75   return Update();
    76 }
    78 NS_IMETHODIMP
    79 TaskbarPreviewButton::GetDisabled(bool *disabled) {
    80   *disabled = (Button().dwFlags & THBF_DISABLED) == THBF_DISABLED;
    81   return NS_OK;
    82 }
    84 NS_IMETHODIMP
    85 TaskbarPreviewButton::SetDisabled(bool disabled) {
    86   if (disabled)
    87     Button().dwFlags |= THBF_DISABLED;
    88   else
    89     Button().dwFlags &= ~THBF_DISABLED;
    90   return Update();
    91 }
    93 NS_IMETHODIMP
    94 TaskbarPreviewButton::GetImage(imgIContainer **img) {
    95   if (mImage)
    96     NS_ADDREF(*img = mImage);
    97   else
    98     *img = nullptr;
    99   return NS_OK;
   100 }
   102 NS_IMETHODIMP
   103 TaskbarPreviewButton::SetImage(imgIContainer *img) {
   104   if (Button().hIcon)
   105     ::DestroyIcon(Button().hIcon);
   106   if (img) {
   107     nsresult rv;
   108     rv = nsWindowGfx::CreateIcon(img, false, 0, 0,
   109                                  nsWindowGfx::GetIconMetrics(nsWindowGfx::kRegularIcon),
   110                                  &Button().hIcon);
   111     NS_ENSURE_SUCCESS(rv, rv);
   112   } else {
   113     Button().hIcon = nullptr;
   114   }
   115   return Update();
   116 }
   118 NS_IMETHODIMP
   119 TaskbarPreviewButton::GetVisible(bool *visible) {
   120   *visible = (Button().dwFlags & THBF_HIDDEN) != THBF_HIDDEN;
   121   return NS_OK;
   122 }
   124 NS_IMETHODIMP
   125 TaskbarPreviewButton::SetVisible(bool visible) {
   126   if (visible)
   127     Button().dwFlags &= ~THBF_HIDDEN;
   128   else
   129     Button().dwFlags |= THBF_HIDDEN;
   130   return Update();
   131 }
   133 THUMBBUTTON&
   134 TaskbarPreviewButton::Button() {
   135   return mPreview->mThumbButtons[mIndex];
   136 }
   138 nsresult
   139 TaskbarPreviewButton::Update() {
   140   return mPreview->UpdateButton(mIndex);
   141 }
   143 } // namespace widget
   144 } // namespace mozilla

mercurial