From a94153b668a4c92201480a5c0cbd68ccfa0fb42c Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 24 Jan 2010 22:19:42 +0000 Subject: [PATCH] CtrlLib: TrayIcon new patch (thanks andrei!) git-svn-id: svn://ultimatepp.org/upp/trunk@1940 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/CtrlUtil.h | 8 ++++---- uppsrc/CtrlLib/TrayIconX11.cpp | 36 +++++++++++----------------------- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/uppsrc/CtrlLib/CtrlUtil.h b/uppsrc/CtrlLib/CtrlUtil.h index f75971eea..98900bc51 100644 --- a/uppsrc/CtrlLib/CtrlUtil.h +++ b/uppsrc/CtrlLib/CtrlUtil.h @@ -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; } diff --git a/uppsrc/CtrlLib/TrayIconX11.cpp b/uppsrc/CtrlLib/TrayIconX11.cpp index 4788c6130..1e552307e 100644 --- a/uppsrc/CtrlLib/TrayIconX11.cpp +++ b/uppsrc/CtrlLib/TrayIconX11.cpp @@ -7,9 +7,7 @@ NAMESPACE_UPP #ifdef PLATFORM_X11 #if !defined(flagNOGTK) - #include - #include - #include + #include #include #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 }