summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/status_icons/status_icon_gtk.cc
blob: 3dacfbc78215a79355235e28d71c967a21beab86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/gtk/status_icons/status_icon_gtk.h"

#include "base/string16.h"
#include "base/logging.h"
#include "base/utf_string_conversions.h"
#include "gfx/gtk_util.h"
#include "third_party/skia/include/core/SkBitmap.h"

StatusIconGtk::StatusIconGtk() {
  icon_ = gtk_status_icon_new();
  gtk_status_icon_set_visible(icon_, TRUE);

  g_signal_connect(icon_, "activate",
                   G_CALLBACK(OnClickThunk), this);
}

StatusIconGtk::~StatusIconGtk() {
  g_object_unref(icon_);
}

void StatusIconGtk::SetImage(const SkBitmap& image) {
  if (image.isNull())
    return;

  GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&image);
  gtk_status_icon_set_from_pixbuf(icon_, pixbuf);
  g_object_unref(pixbuf);
}

void StatusIconGtk::SetPressedImage(const SkBitmap& image) {
  // Ignore pressed images, since the standard on Linux is to not highlight
  // pressed status icons.
}

void StatusIconGtk::SetToolTip(const string16& tool_tip) {
  gtk_status_icon_set_tooltip(icon_, UTF16ToUTF8(tool_tip).c_str());
}

void StatusIconGtk::OnClick(GtkWidget* widget) {
  DispatchClickEvent();
}