CtrlLib: TrayIcon new patch (thanks andrei!)

git-svn-id: svn://ultimatepp.org/upp/trunk@1940 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2010-01-24 22:19:42 +00:00
parent 3be3c79e2f
commit a94153b668
2 changed files with 15 additions and 29 deletions

View file

@ -96,7 +96,7 @@ private:
Image icon;
void DoMenu(Bar& bar);
void Call(int code, unsigned long d1, unsigned long d2, unsigned long d3);
void Message(const char *title, const char *text, int timeout);
void Message(int type, const char *title, const char *text, int timeout);
public:
virtual void LeftDown();
@ -124,9 +124,9 @@ public:
void Hide() { Show(false); }
bool IsVisible() const { return true; }
void Info(const char *title, const char *text, int timeout = 10) { Message(title, text, timeout); }
void Warning(const char *title, const char *text, int timeout = 10) { Message(title, text, timeout); }
void Error(const char *title, const char *text, int timeout = 10) { Message(title, text, timeout); }
void Info(const char *title, const char *text, int timeout = 10) { Message(1, title, text, timeout); }
void Warning(const char *title, const char *text, int timeout = 10) { Message(2, title, text, timeout); }
void Error(const char *title, const char *text, int timeout = 10) { Message(3, title, text, timeout); }
TrayIcon& Icon(const Image &img) { icon = img; Refresh(); return *this; }
TrayIcon& Tip(const char *text) { Ctrl::Tip(text); return *this; }

View file

@ -7,9 +7,7 @@ NAMESPACE_UPP
#ifdef PLATFORM_X11
#if !defined(flagNOGTK)
#include <limits.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <glib.h>
#include <libnotify/notify.h>
#endif
@ -73,7 +71,7 @@ void TrayIcon::AddToTray()
XFree(size_hints);
}
void TrayIcon::Message(const char *title, const char *text, int timeout)
void TrayIcon::Message(int type, const char *title, const char *text, int timeout)
{
if(!traywin)
return;
@ -98,30 +96,18 @@ void TrayIcon::Message(const char *title, const char *text, int timeout)
}
UntrapX11Errors(x11trap);
#else
Size size = this->icon.GetSize();
GdkPixmap *pixmap = NULL;
GdkPixbuf *nicon = NULL;
GError* error = NULL;
if (!notify_init (title))
return;
NotifyNotification* notification;
ImageDraw iw(size);
iw.DrawRect(0, 0, size.cx, size.cy, Color(255, 0, 255)); // fuchsia color used for transparency
iw.DrawImage(0, 0, this->icon);
pixmap = gdk_pixmap_foreign_new(iw.GetDrawable());
if (!pixmap)
return;
nicon = gdk_pixbuf_get_from_drawable(NULL, pixmap, gdk_colormap_get_system(), 0, 0, 0, 0, icon.GetSize().cx, icon.GetSize().cy);
nicon = gdk_pixbuf_add_alpha(nicon, TRUE, 255, 0, 255);
if (!notify_init (GetAppName().Begin()))
return;
notification = notify_notification_new (title, text, NULL , NULL);
if (nicon)
notify_notification_set_icon_from_pixbuf (notification, nicon);
GError* error = NULL;
notification = notify_notification_new (title, text
, type == 1 ? "gtk-dialog-info"
: type == 2 ? "gtk-dialog-warning"
: "gtk-dialog-error", NULL);
notify_notification_set_timeout(notification, timeout * 1000);
notify_notification_show (notification, &error);
notify_uninit ();
g_object_unref(pixmap);
g_object_unref(nicon);
#endif
}