2
* Copyright (C) 2010 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Jason Smith <jason.smith@canonical.com>
22
#include "Nux/VScrollBar.h"
23
#include "Nux/HLayout.h"
24
#include "Nux/VLayout.h"
25
#include "Nux/MenuPage.h"
26
#include "Nux/WindowCompositor.h"
27
#include "Nux/BaseWindow.h"
28
#include "Nux/MenuPage.h"
29
#include "NuxCore/Color.h"
31
#include "LauncherIcon.h"
34
#define DEFAULT_ICON "empathy"
36
LauncherIcon::LauncherIcon(Launcher* IconManager)
39
m_IconManager = IconManager;
40
m_TooltipText = "blank";
42
_show_time.tv_sec = 0;
43
_hide_time.tv_sec = 0;
44
_running_time.tv_sec = 0;
45
_urgent_time.tv_sec = 0;
47
_show_time.tv_usec = 0;
48
_hide_time.tv_usec = 0;
49
_running_time.tv_usec = 0;
50
_urgent_time.tv_usec = 0;
59
_background_color = nux::Color::White;
60
_mouse_inside = false;
61
_tooltip = new nux::Tooltip ();
62
_icon_type = LAUNCHER_ICON_TYPE_NONE;
65
MouseEnter.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseEnter));
66
MouseLeave.connect (sigc::mem_fun(this, &LauncherIcon::RecvMouseLeave));
69
LauncherIcon::~LauncherIcon()
73
nux::Color LauncherIcon::BackgroundColor ()
75
return _background_color;
78
nux::BaseTexture * LauncherIcon::TextureForSize (int size)
80
nux::BaseTexture * result = GetTextureForSize (size);
84
nux::Color LauncherIcon::ColorForIcon (GdkPixbuf *pixbuf)
86
unsigned int width = gdk_pixbuf_get_width (pixbuf);
87
unsigned int height = gdk_pixbuf_get_height (pixbuf);
88
unsigned int row_bytes = gdk_pixbuf_get_rowstride (pixbuf);
90
long int rtotal = 0, gtotal = 0, btotal = 0;
94
guchar *img = gdk_pixbuf_get_pixels (pixbuf);
96
for (unsigned int i = 0; i < width; i++)
98
for (unsigned int j = 0; j < height; j++)
100
guchar *pixels = img + ( j * row_bytes + i * 4);
101
guchar r = *(pixels + 0);
102
guchar g = *(pixels + 1);
103
guchar b = *(pixels + 2);
104
guchar a = *(pixels + 3);
106
float saturation = (MAX (r, MAX (g, b)) - MIN (r, MIN (g, b))) / 255.0f;
107
float relevance = .1 + .9 * (a / 255.0f) * saturation;
109
rtotal += (guchar) (r * relevance);
110
gtotal += (guchar) (g * relevance);
111
btotal += (guchar) (b * relevance);
113
total += relevance * 255;
117
float r, g, b, h, s, v;
122
nux::RGBtoHSV (r, g, b, h, s, v);
128
nux::HSVtoRGB (r, g, b, h, s, v);
130
return nux::Color (r, g, b);
133
nux::BaseTexture * LauncherIcon::TextureFromGtkTheme (const char *icon_name, int size)
138
nux::BaseTexture *result;
140
theme = gtk_icon_theme_get_default ();
143
icon_name = g_strdup (DEFAULT_ICON);
145
info = gtk_icon_theme_lookup_icon (theme,
148
(GtkIconLookupFlags) 0);
151
info = gtk_icon_theme_lookup_icon (theme,
154
(GtkIconLookupFlags) 0);
157
if (gtk_icon_info_get_filename (info) == NULL)
159
info = gtk_icon_theme_lookup_icon (theme,
162
(GtkIconLookupFlags) 0);
165
pbuf = gtk_icon_info_load_icon (info, NULL);
166
result = nux::CreateTextureFromPixbuf (pbuf);
168
_background_color = ColorForIcon (pbuf);
170
g_object_unref (pbuf);
175
void LauncherIcon::SetTooltipText(const TCHAR* text)
177
m_TooltipText = text;
178
_tooltip->SetText (m_TooltipText);
181
nux::NString LauncherIcon::GetTooltipText()
183
return m_TooltipText;
187
LauncherIcon::RecvMouseEnter ()
189
int icon_x = _xform_screen_coord[0].x;
190
int icon_y = _xform_screen_coord[0].y;
191
int icon_w = _xform_screen_coord[2].x - _xform_screen_coord[0].x;
192
int icon_h = _xform_screen_coord[2].y - _xform_screen_coord[0].y;
194
_tooltip->SetBaseX (icon_x + icon_w - 10);
195
_tooltip->SetBaseY (icon_y +
196
23 + // TODO: HARCODED, replace m_IconManager->GetBaseY ()
198
(_tooltip->GetBaseHeight () / 2));
199
_tooltip->ShowWindow (true);
202
void LauncherIcon::RecvMouseLeave ()
204
_tooltip->ShowWindow (false);
207
void LauncherIcon::HideTooltip ()
209
_tooltip->ShowWindow (false);
212
struct timeval LauncherIcon::ShowTime ()
217
struct timeval LauncherIcon::HideTime ()
222
struct timeval LauncherIcon::RunningTime ()
224
return _running_time;
227
struct timeval LauncherIcon::UrgentTime ()
233
LauncherIcon::SetVisible (bool visible)
235
if (visible == _visible)
240
needs_redraw.emit (this);
244
gettimeofday (&_show_time, NULL);
249
gettimeofday (&_hide_time, NULL);
255
LauncherIcon::SetActive (bool active)
257
if (active == _active)
261
needs_redraw.emit (this);
264
void LauncherIcon::SetRunning (bool running)
266
if (running == _running)
270
gettimeofday (&_running_time, NULL);
271
needs_redraw.emit (this);
274
void LauncherIcon::SetUrgent (bool urgent)
276
if (urgent == _urgent)
282
gettimeofday (&_urgent_time, NULL);
284
needs_redraw.emit (this);
287
void LauncherIcon::SetRelatedWindows (int windows)
289
if (_related_windows == windows)
292
_related_windows = windows;
293
needs_redraw.emit (this);
296
void LauncherIcon::Remove ()
303
LauncherIcon::SetIconType (LauncherIconType type)
309
LauncherIcon::SetSortPriority (int priority)
311
_sort_priority = priority;
315
LauncherIcon::SortPriority ()
317
return _sort_priority;
321
LauncherIcon::Type ()
327
LauncherIcon::Visible ()
333
LauncherIcon::Active ()
339
LauncherIcon::Running ()
345
LauncherIcon::Urgent ()
351
LauncherIcon::RelatedWindows ()
353
return _related_windows;
356
std::list<DbusmenuClient *> LauncherIcon::Menus ()
361
std::list<DbusmenuClient *> LauncherIcon::GetMenus ()
363
std::list<DbusmenuClient *> result;