]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/taskbar.cpp
removed #errors in 2.7 compilation
[wxWidgets.git] / src / gtk / taskbar.cpp
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
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/gtk/taskbarpriv.h"
16 #include "wx/log.h"
17 #include "wx/frame.h"
18 #include "wx/menu.h"
19
20 #include <gdk/gdkx.h>
21
22 #ifdef __WXGTK20__
23 #include <gtk/gtkversion.h>
24 #if GTK_CHECK_VERSION(2, 1, 0)
25
26 #include "gtk/gtk.h"
27
28 #include "eggtrayicon.h"
29
30 wxTaskBarIconAreaBase::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);
36
37 wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec"));
38 }
39
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*/);
46
47 m_invokingWindow = NULL;
48 }
49
50 bool 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);
57
58 wxString name;
59 name.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen));
60 Atom atom = XInternAtom(display, name.ToAscii(), False);
61
62 Window manager = XGetSelectionOwner(display, atom);
63
64 s_supported = (manager != None);
65 }
66
67 return (bool)s_supported;
68 }
69
70 //-----------------------------------------------------------------------------
71 // Pop-up menu stuff
72 //-----------------------------------------------------------------------------
73
74 extern "C" WXDLLIMPEXP_CORE void gtk_pop_hide_callback( GtkWidget *widget, bool* is_waiting );
75
76 extern WXDLLIMPEXP_CORE void SetInvokingWindow( wxMenu *menu, wxWindow* win );
77
78 extern "C" WXDLLIMPEXP_CORE
79 void wxPopupMenuPositionCallback( GtkMenu *menu,
80 gint *x, gint *y,
81 gboolean * WXUNUSED(whatever),
82 gpointer user_data );
83
84 #if wxUSE_MENUS_NATIVE
85 bool 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 }
141 #endif // wxUSE_MENUS_NATIVE
142
143 #endif // __WXGTK20__
144 #endif // GTK_CHECK_VERSION(2, 1, 0)