]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/taskbar.cpp
added semicolons after wxCHECK()s (part of patch 1450705)
[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
9fa72bd2
MR
101 gulong handler = g_signal_connect (menu->m_menu, "hide",
102 G_CALLBACK (gtk_pop_hide_callback),
103 &is_waiting);
0bd3b8ec
RR
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
9fa72bd2 136 g_signal_handler_disconnect (menu->m_menu, handler);
0bd3b8ec
RR
137
138 return true;
139}
065f010f 140#endif // wxUSE_MENUS_NATIVE
0bd3b8ec 141
33d4eef0 142#endif // __WXGTK20__
6376cdc3 143#endif // GTK_CHECK_VERSION(2, 1, 0)