1 ///////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxTaskBarIcon (src/unix/taskbarx11.cpp) helper for GTK2 
   4 // Author:      Vaclav Slavik 
   8 // Copyright:   (c) Vaclav Slavik, 2004 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////// 
  12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  13 #pragma implementation "taskbarpriv.h" 
  16 // For compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  19 #include "wx/gtk/taskbarpriv.h" 
  27 #include <gtk/gtkversion.h> 
  28 #if GTK_CHECK_VERSION(2, 1, 0) 
  32 #include "eggtrayicon.h" 
  34 wxTaskBarIconAreaBase::wxTaskBarIconAreaBase() 
  36     if (IsProtocolSupported()) 
  38         m_widget 
= GTK_WIDGET(egg_tray_icon_new("systray icon")); 
  39         gtk_window_set_resizable(GTK_WINDOW(m_widget
), false); 
  41         wxLogTrace(_T("systray"), _T("using freedesktop.org systray spec")); 
  44     wxTopLevelWindow::Create( 
  45             NULL
, wxID_ANY
, _T("systray icon"), 
  46             wxDefaultPosition
, wxDefaultSize
, 
  47             wxDEFAULT_FRAME_STYLE 
| wxFRAME_NO_TASKBAR 
| wxSIMPLE_BORDER 
| 
  49             wxEmptyString 
/*eggtray doesn't like setting wmclass*/); 
  51     m_invokingWindow 
= NULL
; 
  54 bool wxTaskBarIconAreaBase::IsProtocolSupported() 
  56     static int s_supported 
= -1; 
  57     if (s_supported 
== -1) 
  59         Display 
*display 
= GDK_DISPLAY(); 
  60         Screen 
*screen 
= DefaultScreenOfDisplay(display
); 
  63         name
.Printf(_T("_NET_SYSTEM_TRAY_S%d"), XScreenNumberOfScreen(screen
)); 
  64         Atom atom 
= XInternAtom(display
, name
.ToAscii(), False
); 
  66         Window manager 
= XGetSelectionOwner(display
, atom
); 
  68         s_supported 
= (manager 
!= None
); 
  71     return (bool)s_supported
; 
  74 //----------------------------------------------------------------------------- 
  76 //----------------------------------------------------------------------------- 
  78 extern "C" void gtk_pop_hide_callback( GtkWidget 
*widget
, bool* is_waiting  
); 
  80 extern void SetInvokingWindow( wxMenu 
*menu
, wxWindow
* win 
); 
  82 extern "C" void wxPopupMenuPositionCallback( GtkMenu 
*menu
, 
  84                                              gboolean 
* WXUNUSED(whatever
), 
  87 #if wxUSE_MENUS_NATIVE 
  88 bool wxTaskBarIconAreaBase::DoPopupMenu( wxMenu 
*menu
, int x
, int y 
) 
  90     wxCHECK_MSG( m_widget 
!= NULL
, false, wxT("invalid window") ); 
  92     wxCHECK_MSG( menu 
!= NULL
, false, wxT("invalid popup-menu") ); 
  94     // NOTE: if you change this code, you need to update 
  95     //       the same code in window.cpp as well. This 
  96     //       is ugly code duplication, I know, 
  98     SetInvokingWindow( menu
, this ); 
 100     menu
->UpdateUI( m_invokingWindow 
); 
 102     bool is_waiting 
= true; 
 104     gulong handler 
= gtk_signal_connect( GTK_OBJECT(menu
->m_menu
), 
 106                                          GTK_SIGNAL_FUNC(gtk_pop_hide_callback
), 
 107                                          (gpointer
)&is_waiting 
); 
 111     GtkMenuPositionFunc posfunc
; 
 112     if ( x 
== -1 && y 
== -1 ) 
 114         // use GTK's default positioning algorithm 
 120         pos 
= ClientToScreen(wxPoint(x
, y
)); 
 122         posfunc 
= wxPopupMenuPositionCallback
; 
 126                   GTK_MENU(menu
->m_menu
), 
 127                   (GtkWidget 
*) NULL
,           // parent menu shell 
 128                   (GtkWidget 
*) NULL
,           // parent menu item 
 129                   posfunc
,                      // function to position it 
 130                   userdata
,                     // client data 
 131                   0,                            // button used to activate it 
 132                   gtk_get_current_event_time() 
 137         gtk_main_iteration(); 
 140     gtk_signal_disconnect(GTK_OBJECT(menu
->m_menu
), handler
); 
 144 #endif // wxUSE_MENUS_NATIVE 
 146 #endif // __WXGTK20__ 
 147 #endif // GTK_CHECK_VERSION(2, 1, 0)