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(NO_GCC_PRAGMA)
13 #pragma implementation "taskbarx11.h"
16 // NB: This implementation does *not* work with every X11 window manager.
17 // Currently only GNOME 1.2 and KDE 1,2,3 methods are implemented.
20 // - GNOME 2 support (see www.freedesktop.org for specification;
21 // KDE 3 uses this method as well, even though legacy KDE
22 // method we implement works as well)
23 // - IceWM support (?)
25 // Thanks to Ian Campbell, author of XMMS Status Docklet, for publishing
26 // KDE and GNOME 1.2 methods.
29 // For compilers that support precompilation, includes "wx.h".
30 #include "wx/wxprec.h"
32 #include "wx/taskbar.h"
34 #include "wx/bitmap.h"
35 #include "wx/statbmp.h"
37 #include "wx/dcclient.h"
40 #pragma message disable nosimpint
43 #include <X11/Xatom.h>
45 #pragma message enable nosimpint
48 // ----------------------------------------------------------------------------
49 // toolkit dependent methods to set properties on helper window:
50 // ----------------------------------------------------------------------------
52 #if defined(__WXGTK__)
56 #define GetDisplay() GDK_DISPLAY()
57 #define GetXWindow(wxwin) GDK_WINDOW_XWINDOW((wxwin)->m_widget->window)
58 #elif defined(__WXX11__) || defined(__WXMOTIF__)
59 #include "wx/x11/privx.h"
60 #define GetDisplay() ((Display*)wxGlobalDisplay())
61 #define GetXWindow(wxwin) ((Window)(wxwin)->GetHandle())
63 #error "You must define X11 accessors for this port!"
67 // ----------------------------------------------------------------------------
68 // wxTaskBarIconArea is the real window that shows the icon:
69 // ----------------------------------------------------------------------------
71 class WXDLLIMPEXP_ADV wxTaskBarIconArea
: public wxFrame
74 wxTaskBarIconArea(wxTaskBarIcon
*icon
, const wxBitmap
&bmp
)
75 : wxFrame(NULL
, -1, wxT("taskbar icon"),
76 wxDefaultPosition
, wxDefaultSize
,
77 wxDEFAULT_FRAME_STYLE
| wxFRAME_NO_TASKBAR
|
78 wxSIMPLE_BORDER
| wxFRAME_SHAPED
),
79 m_icon(icon
), m_bmp(bmp
)
82 SetSize(wxSize(bmp
.GetWidth(), bmp
.GetHeight()));
85 bool IsOk() { return true; }
88 void SetWMProperties();
90 void OnPaint(wxPaintEvent
& evt
);
91 void OnWindowCreate(wxWindowCreateEvent
& event
);
92 void OnMouseEvent(wxMouseEvent
& event
);
93 void OnMenuEvent(wxCommandEvent
& event
);
95 wxTaskBarIcon
*m_icon
;
101 BEGIN_EVENT_TABLE(wxTaskBarIconArea
, wxFrame
)
102 EVT_MOUSE_EVENTS(wxTaskBarIconArea::OnMouseEvent
)
103 EVT_MENU(-1, wxTaskBarIconArea::OnMenuEvent
)
104 EVT_PAINT(wxTaskBarIconArea::OnPaint
)
106 EVT_WINDOW_CREATE(wxTaskBarIconArea::OnWindowCreate
)
110 void wxTaskBarIconArea::SetWMProperties()
113 gtk_widget_realize(m_widget
);
119 Atom _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
=
120 XInternAtom(GetDisplay(), "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False
);
122 XChangeProperty(GetDisplay(), GetXWindow(this),
123 _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
,
125 PropModeReplace
, (unsigned char*)data
, 1);
127 // GNOME 1.2 & KDE 1:
128 Atom KWM_DOCKWINDOW
=
129 XInternAtom(GetDisplay(), "KWM_DOCKWINDOW", False
);
131 XChangeProperty(GetDisplay(), GetXWindow(this),
134 PropModeReplace
, (unsigned char*)data
, 1);
137 void wxTaskBarIconArea::OnWindowCreate(wxWindowCreateEvent
& WXUNUSED(event
))
139 SetShape(wxRegion(m_bmp
));
142 void wxTaskBarIconArea::OnPaint(wxPaintEvent
& WXUNUSED(event
))
145 dc
.DrawBitmap(m_bmp
, 0, 0, true);
148 void wxTaskBarIconArea::OnMouseEvent(wxMouseEvent
& event
)
150 wxEventType type
= 0;
151 wxEventType mtype
= event
.GetEventType();
153 if (mtype
== wxEVT_LEFT_DOWN
)
154 type
= wxEVT_TASKBAR_LEFT_DOWN
;
155 else if (mtype
== wxEVT_LEFT_UP
)
156 type
= wxEVT_TASKBAR_LEFT_UP
;
157 else if (mtype
== wxEVT_LEFT_DCLICK
)
158 type
= wxEVT_TASKBAR_LEFT_DCLICK
;
159 else if (mtype
== wxEVT_RIGHT_DOWN
)
160 type
= wxEVT_TASKBAR_RIGHT_DOWN
;
161 else if (mtype
== wxEVT_RIGHT_UP
)
162 type
= wxEVT_TASKBAR_RIGHT_UP
;
163 else if (mtype
== wxEVT_RIGHT_DCLICK
)
164 type
= wxEVT_TASKBAR_RIGHT_DCLICK
;
165 else if (mtype
== wxEVT_MOTION
)
166 type
= wxEVT_TASKBAR_MOVE
;
170 wxTaskBarIconEvent
e(type
, m_icon
);
171 m_icon
->ProcessEvent(e
);
174 void wxTaskBarIconArea::OnMenuEvent(wxCommandEvent
& event
)
176 m_icon
->ProcessEvent(event
);
179 // ----------------------------------------------------------------------------
180 // wxTaskBarIcon class:
181 // ----------------------------------------------------------------------------
183 IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon
, wxEvtHandler
)
185 wxTaskBarIcon::wxTaskBarIcon() : m_iconWnd(NULL
)
189 wxTaskBarIcon::~wxTaskBarIcon()
195 bool wxTaskBarIcon::IsOk() const
200 bool wxTaskBarIcon::IsIconInstalled() const
202 return m_iconWnd
!= NULL
;
205 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
211 bmp
.CopyFromIcon(icon
);
213 m_iconWnd
= new wxTaskBarIconArea(this, bmp
);
216 if (!tooltip
.empty())
217 m_iconWnd
->SetToolTip(tooltip
);
219 if (m_iconWnd
->IsOk())
226 m_iconWnd
->Destroy();
232 bool wxTaskBarIcon::RemoveIcon()
236 m_iconWnd
->Destroy();
241 bool wxTaskBarIcon::PopupMenu(wxMenu
*menu
)
245 wxSize
size(m_iconWnd
->GetClientSize());
246 m_iconWnd
->PopupMenu(menu
, size
.x
/2, size
.y
/2);