1 /////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTaskBarIcon class for common Unix desktops
4 // Author: Vaclav Slavik
8 // Copyright: (c) Vaclav Slavik, 2003
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation "taskbarx11.h"
17 // NB: This implementation does *not* work with every X11 window manager.
18 // Currently only GNOME 1.2 and KDE 1,2,3 methods are implemented.
21 // - GNOME 2 support (see www.freedesktop.org for specification;
22 // KDE 3 uses this method as well, even though legacy KDE
23 // method we implement works as well)
24 // - IceWM and XFCE support (?)
26 // Thanks to Ian Campbell, author of XMMS Status Docklet, for publishing
27 // KDE and GNOME 1.2 methods.
30 // For compilers that support precompilation, includes "wx.h".
31 #include "wx/wxprec.h"
33 #include "wx/taskbar.h"
35 #include "wx/bitmap.h"
36 #include "wx/statbmp.h"
39 #pragma message disable nosimpint
42 #include <X11/Xatom.h>
44 #pragma message enable nosimpint
47 // ----------------------------------------------------------------------------
48 // toolkit dependent methods to set properties on helper window:
49 // ----------------------------------------------------------------------------
51 #if defined(__WXGTK__)
55 #define GetDisplay() GDK_DISPLAY()
56 #define GetXWindow(wxwin) GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
57 #elif defined(__WXX11__) || defined(__WXMOTIF__)
58 #include "wx/x11/privx.h"
59 #define GetDisplay() ((Display*)wxGlobalDisplay())
60 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
62 #error "You must define X11 accessors for this port!"
65 // ----------------------------------------------------------------------------
66 // code for making wxFrame a toolbar icon by setting appropriate properties:
67 // ----------------------------------------------------------------------------
69 static bool wxMakeTaskBarIcon(wxFrame
*wnd
)
72 gtk_widget_realize(wnd
->m_widget
);
78 Atom _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
=
79 XInternAtom(GetDisplay(), "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False
);
81 XChangeProperty(GetDisplay(), GetXWindow(wnd
),
82 _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
,
84 PropModeReplace
, (unsigned char*)data
, 1);
88 XInternAtom(GetDisplay(), "KWM_DOCKWINDOW", False
);
90 XChangeProperty(GetDisplay(), GetXWindow(wnd
),
93 PropModeReplace
, (unsigned char*)data
, 1);
98 // ----------------------------------------------------------------------------
99 // wxTaskBarIconArea is the real window that shows the icon:
100 // ----------------------------------------------------------------------------
102 class wxTaskBarIconArea
: public wxStaticBitmap
105 wxTaskBarIconArea(wxTaskBarIcon
*icon
,
106 wxWindow
*parent
, const wxBitmap
&bmp
)
107 : wxStaticBitmap(parent
, -1, bmp
), m_icon(icon
) {}
110 void OnMouseEvent(wxMouseEvent
& event
);
111 void OnMenuEvent(wxCommandEvent
& event
);
113 wxTaskBarIcon
*m_icon
;
115 DECLARE_EVENT_TABLE()
118 BEGIN_EVENT_TABLE(wxTaskBarIconArea
, wxStaticBitmap
)
119 EVT_MOUSE_EVENTS(wxTaskBarIconArea::OnMouseEvent
)
120 EVT_MENU(-1, wxTaskBarIconArea::OnMenuEvent
)
123 void wxTaskBarIconArea::OnMouseEvent(wxMouseEvent
& event
)
125 wxEventType type
= 0;
126 wxEventType mtype
= event
.GetEventType();
128 if (mtype
== wxEVT_LEFT_DOWN
)
129 type
= wxEVT_TASKBAR_LEFT_DOWN
;
130 else if (mtype
== wxEVT_LEFT_UP
)
131 type
= wxEVT_TASKBAR_LEFT_UP
;
132 else if (mtype
== wxEVT_LEFT_DCLICK
)
133 type
= wxEVT_TASKBAR_LEFT_DCLICK
;
134 else if (mtype
== wxEVT_RIGHT_DOWN
)
135 type
= wxEVT_TASKBAR_RIGHT_DOWN
;
136 else if (mtype
== wxEVT_RIGHT_UP
)
137 type
= wxEVT_TASKBAR_RIGHT_UP
;
138 else if (mtype
== wxEVT_RIGHT_DCLICK
)
139 type
= wxEVT_TASKBAR_RIGHT_DCLICK
;
140 else if (mtype
== wxEVT_MOTION
)
141 type
= wxEVT_TASKBAR_MOVE
;
145 wxTaskBarIconEvent
e(type
, m_icon
);
146 m_icon
->ProcessEvent(e
);
149 void wxTaskBarIconArea::OnMenuEvent(wxCommandEvent
& event
)
151 m_icon
->ProcessEvent(event
);
154 // ----------------------------------------------------------------------------
155 // wxTaskBarIcon class:
156 // ----------------------------------------------------------------------------
158 IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon
, wxEvtHandler
)
160 wxTaskBarIcon::wxTaskBarIcon() : m_iconWnd(NULL
)
164 wxTaskBarIcon::~wxTaskBarIcon()
170 bool wxTaskBarIcon::IsOk() const
175 bool wxTaskBarIcon::IsIconInstalled() const
177 return m_iconWnd
!= NULL
;
180 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
185 m_iconWnd
= new wxFrame(NULL
, -1, wxT("taskbar icon"),
186 wxDefaultPosition
, wxDefaultSize
,
187 wxDEFAULT_FRAME_STYLE
| wxFRAME_NO_TASKBAR
);
189 bmp
.CopyFromIcon(icon
);
190 wxTaskBarIconArea
*area
= new wxTaskBarIconArea(this, m_iconWnd
, bmp
);
191 m_iconWnd
->SetClientSize(area
->GetSize());
193 if (!tooltip
.empty())
194 area
->SetToolTip(tooltip
);
196 if (wxMakeTaskBarIcon(m_iconWnd
))
204 m_iconWnd
->Destroy();
210 bool wxTaskBarIcon::RemoveIcon()
214 m_iconWnd
->Destroy();
219 bool wxTaskBarIcon::PopupMenu(wxMenu
*menu
)
223 wxSize
size(m_iconArea
->GetSize());
224 m_iconArea
->PopupMenu(menu
, size
.x
/2, size
.y
/2);