]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/taskbar.cpp
Cleanup
[wxWidgets.git] / src / gtk / taskbar.cpp
CommitLineData
33d4eef0
VS
1/////////////////////////////////////////////////////////////////////////
2// File: taskbar.cpp
3// Purpose: wxTaskBarIcon (src/unix/taskbarx11.cpp) helper for GTK2
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2004/05/29
7// RCS-ID: $Id$
8// Copyright: (c) Vaclav Slavik, 2004
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////
11
33d4eef0
VS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
e1bf3ad3 15#include "wx/gtk/taskbarpriv.h"
33d4eef0
VS
16#include "wx/log.h"
17#include "wx/frame.h"
0bd3b8ec 18#include "wx/menu.h"
33d4eef0 19
5dc22463 20#include <gdk/gdkx.h>
5dc22463 21
6376cdc3
RD
22#ifdef __WXGTK20__
23#include <gtk/gtkversion.h>
24#if GTK_CHECK_VERSION(2, 1, 0)
33d4eef0 25
0bd3b8ec
RR
26#include "gtk/gtk.h"
27
33d4eef0
VS
28#include "eggtrayicon.h"
29
30wxTaskBarIconAreaBase::wxTaskBarIconAreaBase()
31{
32 if (IsProtocolSupported())
33 {
34 m_widget = GTK_WIDGET(egg_tray_icon_new("systray icon"));
35 gtk_window_set_resizable(GTK_WINDOW(m_widget), false);
3d257b8d 36
33d4eef0
VS
37 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
38 }
3d257b8d 39
33d4eef0
VS
40 wxTopLevelWindow::Create(
41 NULL, wxID_ANY, _T("systray icon"),
42 wxDefaultPosition, wxDefaultSize,
43 wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR | wxSIMPLE_BORDER |
44 wxFRAME_SHAPED,
45 wxEmptyString /*eggtray doesn't like setting wmclass*/);
3d257b8d 46
0bd3b8ec 47 m_invokingWindow = NULL;
33d4eef0
VS
48}
49
50bool wxTaskBarIconAreaBase::IsProtocolSupported()
51{
52 static int s_supported = -1;
53 if (s_supported == -1)
54 {
55 Display *display = GDK_DISPLAY();
56 Screen *screen = DefaultScreenOfDisplay(display);
3d257b8d 57
33d4eef0
VS
58 wxString name;
59 name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen));
60 Atom atom = XInternAtom(display, name.ToAscii(), False);
3d257b8d 61
33d4eef0 62 Window manager = XGetSelectionOwner(display, atom);
3d257b8d 63
33d4eef0
VS
64 s_supported = (manager != None);
65 }
3d257b8d 66
33d4eef0
VS
67 return (bool)s_supported;
68}
69
0bd3b8ec
RR
70//-----------------------------------------------------------------------------
71// Pop-up menu stuff
72//-----------------------------------------------------------------------------
73
20123d49 74extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
0bd3b8ec 75
20123d49 76extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
0bd3b8ec 77
20123d49
MW
78extern "C" WXDLLIMPEXP_CORE
79 void wxPopupMenuPositionCallback( GtkMenu *menu,
80 gint *x, gint *y,
81 gboolean * WXUNUSED(whatever),
82 gpointer user_data );
0bd3b8ec 83
065f010f 84#if wxUSE_MENUS_NATIVE
0bd3b8ec
RR
85bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu *menu, int x, int y )
86{
87 wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
88
89 wxCHECK_MSG( menu != NULL, false, wxT("invalid popup-menu") );
90
91 // NOTE: if you change this code, you need to update
92 // the same code in window.cpp as well. This
93 // is ugly code duplication, I know,
94
95 SetInvokingWindow( menu, this );
96
97 menu->UpdateUI( m_invokingWindow );
98
99 bool is_waiting = true;
100
101 gulong handler = gtk_signal_connect( GTK_OBJECT(menu->m_menu),
102 "hide",
103 GTK_SIGNAL_FUNC(gtk_pop_hide_callback),
104 (gpointer)&is_waiting );
105
106 wxPoint pos;
107 gpointer userdata;
108 GtkMenuPositionFunc posfunc;
109 if ( x == -1 && y == -1 )
110 {
111 // use GTK's default positioning algorithm
112 userdata = NULL;
113 posfunc = NULL;
114 }
115 else
116 {
117 pos = ClientToScreen(wxPoint(x, y));
118 userdata = &pos;
119 posfunc = wxPopupMenuPositionCallback;
120 }
121
122 gtk_menu_popup(
123 GTK_MENU(menu->m_menu),
124 (GtkWidget *) NULL, // parent menu shell
125 (GtkWidget *) NULL, // parent menu item
126 posfunc, // function to position it
127 userdata, // client data
128 0, // button used to activate it
129 gtk_get_current_event_time()
130 );
131
132 while (is_waiting)
133 {
134 gtk_main_iteration();
135 }
136
137 gtk_signal_disconnect(GTK_OBJECT(menu->m_menu), handler);
138
139 return true;
140}
065f010f 141#endif // wxUSE_MENUS_NATIVE
0bd3b8ec 142
33d4eef0 143#endif // __WXGTK20__
6376cdc3 144#endif // GTK_CHECK_VERSION(2, 1, 0)