Version: 3.0.2
wxTaskBarIcon Class Reference

#include <wx/taskbar.h>

+ Inheritance diagram for wxTaskBarIcon:

Detailed Description

This class represents a taskbar icon.

A taskbar icon is an icon that appears in the 'system tray' and responds to mouse clicks, optionally with a tooltip above it to help provide information.

X Window System Note

Under X Window System, the window manager must support either the "System Tray Protocol" (see http://freedesktop.org/wiki/Specifications/systemtray-spec) by freedesktop.org (WMs used by modern desktop environments such as GNOME >= 2, KDE >= 3 and XFCE >= 4 all do) or the older methods used in GNOME 1.2 and KDE 1 and 2.

If it doesn't, the icon will appear as a toplevel window on user's desktop. Because not all window managers have system tray, there's no guarantee that wxTaskBarIcon will work correctly under X Window System and so the applications should use it only as an optional component of their user interface. The user should be required to explicitly enable the taskbar icon on Unix, it shouldn't be on by default.

Events emitted by this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxTaskBarIconEvent& event)

Event macros for events emitted by this class:

Note that not all ports are required to send these events and so it's better to override wxTaskBarIcon::CreatePopupMenu() if all that the application does is that it shows a popup menu in reaction to mouse click.
  • EVT_TASKBAR_MOVE(func):
    Process a wxEVT_TASKBAR_MOVE event.
  • EVT_TASKBAR_LEFT_DOWN(func):
    Process a wxEVT_TASKBAR_LEFT_DOWN event.
  • EVT_TASKBAR_LEFT_UP(func):
    Process a wxEVT_TASKBAR_LEFT_UP event.
  • EVT_TASKBAR_RIGHT_DOWN(func):
    Process a wxEVT_TASKBAR_RIGHT_DOWN event.
  • EVT_TASKBAR_RIGHT_UP(func):
    Process a wxEVT_TASKBAR_RIGHT_UP event.
  • EVT_TASKBAR_LEFT_DCLICK(func):
    Process a wxEVT_TASKBAR_LEFT_DCLICK event.
  • EVT_TASKBAR_RIGHT_DCLICK(func):
    Process a wxEVT_TASKBAR_RIGHT_DCLICK event.
  • EVT_TASKBAR_CLICK(func):
    This is a synonym for either EVT_TASKBAR_RIGHT_DOWN or UP depending on the platform, use this event macro to catch the event which should result in the menu being displayed on the current platform.

Library:  wxAdvanced
Category:  Miscellaneous

Public Member Functions

 wxTaskBarIcon (wxTaskBarIconType iconType=wxTBI_DEFAULT_TYPE)
 Default constructor.
 
virtual ~wxTaskBarIcon ()
 Destroys the wxTaskBarIcon object, removing the icon if not already removed.
 
void Destroy ()
 This method is similar to wxWindow::Destroy and can be used to schedule the task bar icon object for the delayed destruction: it will be deleted during the next event loop iteration, which allows the task bar icon to process any pending events for it before being destroyed.
 
bool IsIconInstalled () const
 Returns true if SetIcon() was called with no subsequent RemoveIcon().
 
bool IsOk () const
 Returns true if the object initialized successfully.
 
virtual bool PopupMenu (wxMenu *menu)
 Pops up a menu at the current mouse position.
 
virtual bool RemoveIcon ()
 Removes the icon previously set with SetIcon().
 
virtual bool SetIcon (const wxIcon &icon, const wxString &tooltip=wxEmptyString)
 Sets the icon, and optional tooltip text.
 
- Public Member Functions inherited from wxEvtHandler
 wxEvtHandler ()
 Constructor.
 
virtual ~wxEvtHandler ()
 Destructor.
 
virtual void QueueEvent (wxEvent *event)
 Queue event for a later processing.
 
virtual void AddPendingEvent (const wxEvent &event)
 Post an event to be processed later.
 
template<typename T , typename T1 , ... >
void CallAfter (void(T::*method)(T1,...), T1 x1,...)
 Asynchronously call the given method.
 
template<typename T >
void CallAfter (const T &functor)
 Asynchronously call the given functor.
 
virtual bool ProcessEvent (wxEvent &event)
 Processes an event, searching event tables and calling zero or more suitable event handler function(s).
 
bool ProcessEventLocally (wxEvent &event)
 Try to process the event in this handler and all those chained to it.
 
bool SafelyProcessEvent (wxEvent &event)
 Processes an event by calling ProcessEvent() and handles any exceptions that occur in the process.
 
void ProcessPendingEvents ()
 Processes the pending events previously queued using QueueEvent() or AddPendingEvent(); you must call this function only if you are sure there are pending events for this handler, otherwise a wxCHECK will fail.
 
void DeletePendingEvents ()
 Deletes all events queued on this event handler using QueueEvent() or AddPendingEvent().
 
virtual bool SearchEventTable (wxEventTable &table, wxEvent &event)
 Searches the event table, executing an event handler function if an appropriate one is found.
 
void Connect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 Connects the given function dynamically with the event handler, id and event type.
 
void Connect (int id, wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
void Connect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Connect(int, int, wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
bool Disconnect (wxEventType eventType, wxObjectEventFunction function, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 Disconnects the given function dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
 
bool Disconnect (int id=wxID_ANY, wxEventType eventType=wxEVT_NULL, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
bool Disconnect (int id, int lastId, wxEventType eventType, wxObjectEventFunction function=NULL, wxObject *userData=NULL, wxEvtHandler *eventSink=NULL)
 See the Disconnect(wxEventType, wxObjectEventFunction, wxObject*, wxEvtHandler*) overload for more info.
 
template<typename EventTag , typename Functor >
void Bind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 Binds the given function, functor or method dynamically with the event.
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
void Bind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 See the Bind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
 
template<typename EventTag , typename Functor >
bool Unbind (const EventTag &eventType, Functor functor, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 Unbinds the given function, functor or method dynamically from the event handler, using the specified parameters as search criteria and returning true if a matching function has been found and removed.
 
template<typename EventTag , typename Class , typename EventArg , typename EventHandler >
bool Unbind (const EventTag &eventType, void(Class::*method)(EventArg &), EventHandler *handler, int id=wxID_ANY, int lastId=wxID_ANY, wxObject *userData=NULL)
 See the Unbind<>(const EventTag&, Functor, int, int, wxObject*) overload for more info.
 
void * GetClientData () const
 Returns user-supplied client data.
 
wxClientDataGetClientObject () const
 Returns a pointer to the user-supplied client data object.
 
void SetClientData (void *data)
 Sets user-supplied client data.
 
void SetClientObject (wxClientData *data)
 Set the client data object.
 
bool GetEvtHandlerEnabled () const
 Returns true if the event handler is enabled, false otherwise.
 
wxEvtHandlerGetNextHandler () const
 Returns the pointer to the next handler in the chain.
 
wxEvtHandlerGetPreviousHandler () const
 Returns the pointer to the previous handler in the chain.
 
void SetEvtHandlerEnabled (bool enabled)
 Enables or disables the event handler.
 
virtual void SetNextHandler (wxEvtHandler *handler)
 Sets the pointer to the next handler.
 
virtual void SetPreviousHandler (wxEvtHandler *handler)
 Sets the pointer to the previous handler.
 
void Unlink ()
 Unlinks this event handler from the chain it's part of (if any); then links the "previous" event handler to the "next" one (so that the chain won't be interrupted).
 
bool IsUnlinked () const
 Returns true if the next and the previous handler pointers of this event handler instance are NULL.
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data.
 
 wxObject (const wxObject &other)
 Copy ctor.
 
virtual ~wxObject ()
 Destructor.
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar).
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object.
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class.
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj.
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone.
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer.
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data.
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public.
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined.
 

Static Public Member Functions

static bool IsAvailable ()
 Returns true if system tray is available in the desktop environment the app runs under.
 
- Static Public Member Functions inherited from wxEvtHandler
static void AddFilter (wxEventFilter *filter)
 Add an event filter whose FilterEvent() method will be called for each and every event processed by wxWidgets.
 
static void RemoveFilter (wxEventFilter *filter)
 Remove a filter previously installed with AddFilter().
 

Protected Member Functions

virtual wxMenuCreatePopupMenu ()
 This method is called by the library when the user requests popup menu (on Windows and Unix platforms, this is when the user right-clicks the icon).
 
- Protected Member Functions inherited from wxEvtHandler
virtual bool TryBefore (wxEvent &event)
 Method called by ProcessEvent() before examining this object event tables.
 
virtual bool TryAfter (wxEvent &event)
 Method called by ProcessEvent() as last resort.
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object.
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it.
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data.
 

Additional Inherited Members

- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data.
 

Constructor & Destructor Documentation

wxTaskBarIcon::wxTaskBarIcon ( wxTaskBarIconType  iconType = wxTBI_DEFAULT_TYPE)

Default constructor.

The iconType is only applicable on wxOSX_Cocoa.

virtual wxTaskBarIcon::~wxTaskBarIcon ( )
virtual

Destroys the wxTaskBarIcon object, removing the icon if not already removed.

Member Function Documentation

virtual wxMenu* wxTaskBarIcon::CreatePopupMenu ( )
protectedvirtual

This method is called by the library when the user requests popup menu (on Windows and Unix platforms, this is when the user right-clicks the icon).

Override this function in order to provide popup menu associated with the icon. If CreatePopupMenu() returns NULL (this happens by default), no menu is shown, otherwise the menu is displayed and then deleted by the library as soon as the user dismisses it.

The events can be handled by a class derived from wxTaskBarIcon.

void wxTaskBarIcon::Destroy ( )

This method is similar to wxWindow::Destroy and can be used to schedule the task bar icon object for the delayed destruction: it will be deleted during the next event loop iteration, which allows the task bar icon to process any pending events for it before being destroyed.

static bool wxTaskBarIcon::IsAvailable ( )
static

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.
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
bool wxTaskBarIcon::IsIconInstalled ( ) const

Returns true if SetIcon() was called with no subsequent RemoveIcon().

bool wxTaskBarIcon::IsOk ( ) const

Returns true if the object initialized successfully.

virtual bool wxTaskBarIcon::PopupMenu ( wxMenu menu)
virtual

Pops up a menu at the current mouse position.

The events can be handled by a class derived from wxTaskBarIcon.

Note
It is recommended to override CreatePopupMenu() callback instead of calling this method from event handler, because some ports (e.g. wxCocoa) may not implement PopupMenu() and mouse click events at all.
virtual bool wxTaskBarIcon::RemoveIcon ( )
virtual

Removes the icon previously set with SetIcon().

virtual bool wxTaskBarIcon::SetIcon ( const wxIcon icon,
const wxString tooltip = wxEmptyString 
)
virtual

Sets the icon, and optional tooltip text.