mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-28 06:12:53 -06:00
CtrlLib: Gtk TrayIcon finished
git-svn-id: svn://ultimatepp.org/upp/trunk@5716 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
366359733d
commit
b725bf3227
3 changed files with 81 additions and 17 deletions
|
|
@ -360,6 +360,7 @@ void Ctrl::Proc()
|
|||
Ptr<Ctrl> _this = this;
|
||||
bool pressed = false;
|
||||
int kv;
|
||||
static int clicktime = msecs() - 100000;
|
||||
switch(CurrentEvent.type) {
|
||||
case GDK_MOTION_NOTIFY: {
|
||||
GtkMouseEvent(MOUSEMOVE, MOUSEMOVE, 0);
|
||||
|
|
@ -376,13 +377,14 @@ void Ctrl::Proc()
|
|||
ignoremouseup = false;
|
||||
}
|
||||
if(!ignoreclick)
|
||||
GtkButtonEvent(DOWN);
|
||||
GtkButtonEvent(msecs(clicktime) < 250 ? DOUBLE : DOWN);
|
||||
clicktime = msecs();
|
||||
break;
|
||||
case GDK_2BUTTON_PRESS:
|
||||
/* case GDK_2BUTTON_PRESS:
|
||||
if(!ignoreclick)
|
||||
GtkButtonEvent(DOUBLE);
|
||||
break;
|
||||
case GDK_BUTTON_RELEASE:
|
||||
*/ case GDK_BUTTON_RELEASE:
|
||||
if(ignoreclick)
|
||||
EndIgnore();
|
||||
else
|
||||
|
|
|
|||
|
|
@ -152,20 +152,26 @@ private:
|
|||
ImageGdk image;
|
||||
bool active;
|
||||
|
||||
static void PopupMenu(GtkStatusIcon *, guint, guint32, gpointer user_data);
|
||||
static void DoActivate(GtkStatusIcon *, gpointer user_data);
|
||||
static gboolean DoButtonPress(GtkStatusIcon *, GdkEventButton *e, gpointer user_data);
|
||||
static gboolean DoButtonRelease(GtkStatusIcon *, GdkEventButton *e, gpointer user_data);
|
||||
static void PopupMenu(GtkStatusIcon *, guint, guint32, gpointer user_data);
|
||||
static void DoActivate(GtkStatusIcon *, gpointer user_data);
|
||||
|
||||
void DoMenu(Bar& bar);
|
||||
void ExecuteMenu();
|
||||
|
||||
void Sync();
|
||||
|
||||
public:
|
||||
virtual void LeftDouble(); // called by Activate
|
||||
virtual void Activate();
|
||||
virtual void Menu(Bar& bar);
|
||||
void Message(int type, const char *title, const char *text, int timeout);
|
||||
|
||||
Callback WhenActivate;
|
||||
public:
|
||||
virtual void Menu(Bar& bar);
|
||||
virtual void LeftDown();
|
||||
virtual void LeftUp();
|
||||
virtual void LeftDouble();
|
||||
|
||||
Callback WhenLeftDown;
|
||||
Callback WhenLeftUp;
|
||||
Callback WhenLeftDouble;
|
||||
Callback1<Bar&> WhenBar;
|
||||
|
||||
|
|
@ -177,9 +183,9 @@ public:
|
|||
bool IsVisible() const;
|
||||
|
||||
// Not implemented by GTK:
|
||||
void Info(const char *title, const char *text, int timeout = 10) {}
|
||||
void Warning(const char *title, const char *text, int timeout = 10) {}
|
||||
void Error(const char *title, const char *text, int timeout = 10) {}
|
||||
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) { if(image.Set(img)) Sync(); return *this; }
|
||||
TrayIcon& Tip(const char *text) { if(tooltip != text) tooltip = text; Sync(); return *this; }
|
||||
|
|
|
|||
|
|
@ -2,16 +2,51 @@
|
|||
|
||||
#ifdef GUI_GTK
|
||||
|
||||
#include <libnotify/notify.h>
|
||||
#ifdef NOTIFY_CHECK_VERSION
|
||||
#if NOTIFY_CHECK_VERSION(0,7,0)
|
||||
#define NOTIFY_VERSION_GT_0_7_0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
NAMESPACE_UPP
|
||||
|
||||
TrayIcon::TrayIcon()
|
||||
{
|
||||
tray_icon = gtk_status_icon_new ();
|
||||
g_signal_connect(tray_icon, "button-press-event", G_CALLBACK(DoButtonPress), this);
|
||||
g_signal_connect(tray_icon, "button-release-event", G_CALLBACK(DoButtonRelease), this);
|
||||
g_signal_connect(tray_icon, "activate", G_CALLBACK(DoActivate), this);
|
||||
g_signal_connect(tray_icon, "popup-menu", G_CALLBACK(PopupMenu), this);
|
||||
active = true;
|
||||
}
|
||||
|
||||
gboolean TrayIcon::DoButtonPress(GtkStatusIcon *, GdkEventButton *e, gpointer user_data)
|
||||
{
|
||||
TrayIcon *q = (TrayIcon *)user_data;
|
||||
if(e->type == GDK_BUTTON_PRESS) {
|
||||
if(e->button == 1) {
|
||||
static int clicktime = msecs() - 100000;
|
||||
if(msecs(clicktime) < 250)
|
||||
q->LeftDouble();
|
||||
else
|
||||
q->LeftDown();
|
||||
clicktime = msecs();
|
||||
}
|
||||
if(e->button == 3)
|
||||
q->ExecuteMenu();
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean TrayIcon::DoButtonRelease(GtkStatusIcon *, GdkEventButton *e, gpointer user_data)
|
||||
{
|
||||
TrayIcon *q = (TrayIcon *)user_data;
|
||||
if(e->button == 1)
|
||||
q->LeftUp();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void TrayIcon::PopupMenu(GtkStatusIcon *, guint, guint32, gpointer user_data)
|
||||
{
|
||||
((TrayIcon *)user_data)->ExecuteMenu();
|
||||
|
|
@ -19,7 +54,8 @@ void TrayIcon::PopupMenu(GtkStatusIcon *, guint, guint32, gpointer user_data)
|
|||
|
||||
void TrayIcon::DoActivate(GtkStatusIcon *icon, gpointer user_data)
|
||||
{
|
||||
((TrayIcon *)user_data)->Activate();
|
||||
((TrayIcon *)user_data)->LeftDown();
|
||||
((TrayIcon *)user_data)->LeftDouble();
|
||||
}
|
||||
|
||||
void TrayIcon::Sync()
|
||||
|
|
@ -33,6 +69,23 @@ void TrayIcon::DoMenu(Bar& bar)
|
|||
Menu(bar);
|
||||
}
|
||||
|
||||
void TrayIcon::Message(int type, const char *title, const char *text, int timeout)
|
||||
{
|
||||
if(!notify_is_initted() && !notify_init(title))
|
||||
return;
|
||||
GError *error = NULL;
|
||||
NotifyNotification *notification = notify_notification_new (title, text
|
||||
, type == 1 ? "gtk-dialog-info"
|
||||
: type == 2 ? "gtk-dialog-warning"
|
||||
: "gtk-dialog-error"
|
||||
#ifndef NOTIFY_VERSION_GT_0_7_0
|
||||
, NULL
|
||||
#endif
|
||||
);
|
||||
notify_notification_set_timeout(notification, timeout * 1000);
|
||||
notify_notification_show(notification, &error);
|
||||
}
|
||||
|
||||
void TrayIcon::ExecuteMenu()
|
||||
{
|
||||
gint x, y;
|
||||
|
|
@ -61,12 +114,15 @@ bool TrayIcon::IsVisible() const
|
|||
return gtk_status_icon_get_visible(tray_icon);
|
||||
}
|
||||
|
||||
void TrayIcon::Activate()
|
||||
void TrayIcon::LeftDown()
|
||||
{
|
||||
WhenActivate();
|
||||
LeftDouble();
|
||||
WhenLeftDown();
|
||||
}
|
||||
|
||||
void TrayIcon::LeftUp()
|
||||
{
|
||||
WhenLeftUp();
|
||||
}
|
||||
|
||||
void TrayIcon::LeftDouble()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue