]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/taskbar.cpp
added support for <bg> tag for toolbars in XRC
[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 = g_signal_connect (menu->m_menu, "hide",
102 G_CALLBACK (gtk_pop_hide_callback),
103 &is_waiting);
104
105 wxPoint pos;
106 gpointer userdata;
107 GtkMenuPositionFunc posfunc;
108 if ( x == -1 && y == -1 )
109 {
110 // use GTK's default positioning algorithm
111 userdata = NULL;
112 posfunc = NULL;
113 }
114 else
115 {
116 pos = ClientToScreen(wxPoint(x, y));
117 userdata = &pos;
118 posfunc = wxPopupMenuPositionCallback;
119 }
120
121 gtk_menu_popup(
122 GTK_MENU(menu->m_menu),
123 (GtkWidget *) NULL, // parent menu shell
124 (GtkWidget *) NULL, // parent menu item
125 posfunc, // function to position it
126 userdata, // client data
127 0, // button used to activate it
128 gtk_get_current_event_time()
129 );
130
131 while (is_waiting)
132 {
133 gtk_main_iteration();
134 }
135
136 g_signal_handler_disconnect (menu->m_menu, handler);
137
138 return true;
139 }
140 #endif // wxUSE_MENUS_NATIVE
141
142 #endif // __WXGTK20__
143 #endif // GTK_CHECK_VERSION(2, 1, 0)