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"
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"
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!"
66 // ----------------------------------------------------------------------------
67 // code for making wxFrame a toolbar icon by setting appropriate properties:
68 // ----------------------------------------------------------------------------
70 static bool wxMakeTaskBarIcon(wxFrame
*wnd
)
73 gtk_widget_realize(wnd
->m_widget
);
79 Atom _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
=
80 XInternAtom(GetDisplay(), "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False
);
82 XChangeProperty(GetDisplay(), GetXWindow(wnd
),
83 _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR
,
85 PropModeReplace
, (unsigned char*)data
, 1);
89 XInternAtom(GetDisplay(), "KWM_DOCKWINDOW", False
);
91 XChangeProperty(GetDisplay(), GetXWindow(wnd
),
94 PropModeReplace
, (unsigned char*)data
, 1);
99 // ----------------------------------------------------------------------------
100 // wxTaskBarIconArea is the real window that shows the icon:
101 // ----------------------------------------------------------------------------
103 class wxTaskBarIconArea
: public wxStaticBitmap
106 wxTaskBarIconArea(wxTaskBarIcon
*icon
,
107 wxWindow
*parent
, const wxBitmap
&bmp
)
108 : wxStaticBitmap(parent
, -1, bmp
), m_icon(icon
) {}
111 void OnMouseEvent(wxMouseEvent
& event
);
112 void OnMenuEvent(wxCommandEvent
& event
);
114 wxTaskBarIcon
*m_icon
;
116 DECLARE_EVENT_TABLE()
119 BEGIN_EVENT_TABLE(wxTaskBarIconArea
, wxStaticBitmap
)
120 EVT_MOUSE_EVENTS(wxTaskBarIconArea::OnMouseEvent
)
121 EVT_MENU(-1, wxTaskBarIconArea::OnMenuEvent
)
124 void wxTaskBarIconArea::OnMouseEvent(wxMouseEvent
& event
)
126 wxEventType type
= 0;
127 wxEventType mtype
= event
.GetEventType();
129 if (mtype
== wxEVT_LEFT_DOWN
)
130 type
= wxEVT_TASKBAR_LEFT_DOWN
;
131 else if (mtype
== wxEVT_LEFT_UP
)
132 type
= wxEVT_TASKBAR_LEFT_UP
;
133 else if (mtype
== wxEVT_LEFT_DCLICK
)
134 type
= wxEVT_TASKBAR_LEFT_DCLICK
;
135 else if (mtype
== wxEVT_RIGHT_DOWN
)
136 type
= wxEVT_TASKBAR_RIGHT_DOWN
;
137 else if (mtype
== wxEVT_RIGHT_UP
)
138 type
= wxEVT_TASKBAR_RIGHT_UP
;
139 else if (mtype
== wxEVT_RIGHT_DCLICK
)
140 type
= wxEVT_TASKBAR_RIGHT_DCLICK
;
141 else if (mtype
== wxEVT_MOTION
)
142 type
= wxEVT_TASKBAR_MOVE
;
146 wxTaskBarIconEvent
e(type
, m_icon
);
147 m_icon
->ProcessEvent(e
);
150 void wxTaskBarIconArea::OnMenuEvent(wxCommandEvent
& event
)
152 m_icon
->ProcessEvent(event
);
155 // ----------------------------------------------------------------------------
156 // wxTaskBarIcon class:
157 // ----------------------------------------------------------------------------
159 IMPLEMENT_DYNAMIC_CLASS(wxTaskBarIcon
, wxEvtHandler
)
161 wxTaskBarIcon::wxTaskBarIcon() : m_iconWnd(NULL
)
165 wxTaskBarIcon::~wxTaskBarIcon()
171 bool wxTaskBarIcon::IsOk() const
176 bool wxTaskBarIcon::IsIconInstalled() const
178 return m_iconWnd
!= NULL
;
181 bool wxTaskBarIcon::SetIcon(const wxIcon
& icon
, const wxString
& tooltip
)
186 m_iconWnd
= new wxFrame(NULL
, -1, wxT("taskbar icon"),
187 wxDefaultPosition
, wxDefaultSize
,
188 wxDEFAULT_FRAME_STYLE
| wxFRAME_NO_TASKBAR
);
190 bmp
.CopyFromIcon(icon
);
191 wxTaskBarIconArea
*area
= new wxTaskBarIconArea(this, m_iconWnd
, bmp
);
193 // make a sizer to keep the icon centered, in case it is smaller than the
195 wxBoxSizer
* sizer
= new wxBoxSizer(wxVERTICAL
);
197 sizer
->Add(area
, 0, wxALIGN_CENTER
);
199 m_iconWnd
->SetSizer(sizer
);
201 m_iconWnd
->SetClientSize(area
->GetSize());
203 if (!tooltip
.empty())
204 area
->SetToolTip(tooltip
);
206 if (wxMakeTaskBarIcon(m_iconWnd
))
214 m_iconWnd
->Destroy();
220 bool wxTaskBarIcon::RemoveIcon()
224 m_iconWnd
->Destroy();
229 bool wxTaskBarIcon::PopupMenu(wxMenu
*menu
)
233 wxSize
size(m_iconArea
->GetSize());
234 m_iconArea
->PopupMenu(menu
, size
.x
/2, size
.y
/2);