From cf78bdcb68264bbf066df00028911ed55f4d2c5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Tue, 30 Sep 2008 20:54:02 +0000 Subject: [PATCH 1/1] added wxTaskBarIcon::IsAvailable git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55991 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/taskbarpriv.h | 2 +- include/wx/taskbar.h | 6 ++++++ interface/wx/taskbar.h | 23 +++++++++++++++++++++++ samples/taskbar/tbtest.cpp | 10 ++++++++++ src/unix/taskbarx11.cpp | 11 ++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/include/wx/gtk/taskbarpriv.h b/include/wx/gtk/taskbarpriv.h index f4bb0a27f8..242d3c6a89 100644 --- a/include/wx/gtk/taskbarpriv.h +++ b/include/wx/gtk/taskbarpriv.h @@ -20,7 +20,7 @@ public: wxTaskBarIconAreaBase(); // Returns true if SYSTRAY protocol is supported by the desktop - bool IsProtocolSupported(); + static bool IsProtocolSupported(); wxEvtHandler *m_invokingWindow; diff --git a/include/wx/taskbar.h b/include/wx/taskbar.h index f3dedd4b6e..a7f523cced 100644 --- a/include/wx/taskbar.h +++ b/include/wx/taskbar.h @@ -29,6 +29,12 @@ class WXDLLIMPEXP_ADV wxTaskBarIconBase : public wxEvtHandler public: wxTaskBarIconBase() { } +#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) + static bool IsAvailable(); +#else + static bool IsAvailable() { return true; }; +#endif + // Operations: virtual bool SetIcon(const wxIcon& icon, const wxString& tooltip = wxEmptyString) = 0; diff --git a/interface/wx/taskbar.h b/interface/wx/taskbar.h index 59f1e91cc0..b4aeaef460 100644 --- a/interface/wx/taskbar.h +++ b/interface/wx/taskbar.h @@ -72,5 +72,28 @@ public: Sets the icon, and optional tooltip text. */ bool SetIcon(const wxIcon& icon, const wxString& tooltip); + + /** + Returns true if system tray is available in the desktop environment the + app runs under. + + On Windows and Mac OS X, the tray is always available and this function + simply returns true. + + On Unix, X11 environment may or may not provide the tray, depending on + user's desktop environment. Most modern desktops support the tray via + the System Tray Protocol by freedesktop.org + (http://freedesktop.org/wiki/Specifications/systemtray-spec). + + @note Tray availability may change during application's lifetime + under X11 and so applications shouldn't cache the result. + + @note wxTaskBarIcon supports older GNOME 1.2 and KDE 1/2 methods of + adding icons to tray, but they are unreliable and this method + doesn't detect them. + + @since 2.9.0 + */ + static bool IsAvailable(); }; diff --git a/samples/taskbar/tbtest.cpp b/samples/taskbar/tbtest.cpp index 397a438fc2..9723e48ae0 100644 --- a/samples/taskbar/tbtest.cpp +++ b/samples/taskbar/tbtest.cpp @@ -60,6 +60,16 @@ bool MyApp::OnInit() if ( !wxApp::OnInit() ) return false; + if ( !wxTaskBarIcon::IsAvailable() ) + { + wxMessageBox + ( + "There appears to be no system tray support in your current environment. This sample may not behave as expected.", + "Warning", + wxOK | wxICON_EXCLAMATION + ); + } + // Create the main window gs_dialog = new MyDialog(wxT("wxTaskBarIcon Test Dialog")); diff --git a/src/unix/taskbarx11.cpp b/src/unix/taskbarx11.cpp index ced3b5e059..7b4ac6890d 100644 --- a/src/unix/taskbarx11.cpp +++ b/src/unix/taskbarx11.cpp @@ -66,7 +66,7 @@ wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR | wxSIMPLE_BORDER | wxFRAME_SHAPED) {} - bool IsProtocolSupported() const { return false; } + static bool IsProtocolSupported() const { return false; } }; #endif @@ -250,6 +250,15 @@ void wxTaskBarIconArea::OnMenuEvent(wxCommandEvent& event) m_icon->ProcessEvent(event); } +// ---------------------------------------------------------------------------- +// wxTaskBarIconBase class: +// ---------------------------------------------------------------------------- + +bool wxTaskBarIconBase::IsAvailable() +{ + return wxTaskBarIconArea::IsProtocolSupported(); +} + // ---------------------------------------------------------------------------- // wxTaskBarIcon class: // ---------------------------------------------------------------------------- -- 2.45.2