]> git.saurik.com Git - wxWidgets.git/commitdiff
use shaped window for taskbar icon, so that background shows correctly behind icons...
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 29 May 2004 17:01:57 +0000 (17:01 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 29 May 2004 17:01:57 +0000 (17:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/unix/taskbarx11.h
src/unix/taskbarx11.cpp

index ce9b661a85b1dcc8c150ed64a99e20f1b4bda09e..fb2aeb776301d46ea83c14fcf42d27337f6cd49c 100644 (file)
@@ -20,7 +20,9 @@ class WXDLLEXPORT wxIcon;
 class WXDLLEXPORT wxFrame;
 class WXDLLEXPORT wxWindow;
 
-class WXDLLEXPORT wxTaskBarIcon: public wxTaskBarIconBase
+class WXDLLIMPEXP_ADV wxTaskBarIconArea;
+
+class WXDLLIMPEXP_ADV wxTaskBarIcon: public wxTaskBarIconBase
 {
 public:
     wxTaskBarIcon();
@@ -36,8 +38,7 @@ public:
     bool PopupMenu(wxMenu *menu);
 
 protected:
-    wxFrame *m_iconWnd;
-    wxWindow *m_iconArea;
+    wxTaskBarIconArea *m_iconWnd;
 
     DECLARE_DYNAMIC_CLASS(wxTaskBarIcon)
 };
index 52d44d68a24f8fc335d8161b2d5be5a2dd0b106d..3611d4dc129edc0cef18b21d133a39aac13c54b3 100644 (file)
@@ -13,7 +13,6 @@
 #pragma implementation "taskbarx11.h"
 #endif
 
-
 // NB: This implementation does *not* work with every X11 window manager.
 //     Currently only GNOME 1.2 and KDE 1,2,3 methods are implemented.
 //
@@ -21,7 +20,7 @@
 //               - GNOME 2 support (see www.freedesktop.org for specification;
 //                 KDE 3 uses this method as well, even though legacy KDE
 //                 method we implement works as well)
-//               - IceWM and XFCE support (?)
+//               - IceWM support (?)
 //
 //     Thanks to Ian Campbell, author of XMMS Status Docklet, for publishing
 //     KDE and GNOME 1.2 methods.
@@ -35,6 +34,7 @@
 #include "wx/bitmap.h"
 #include "wx/statbmp.h"
 #include "wx/sizer.h"
+#include "wx/dcclient.h"
 
 #ifdef __VMS
 #pragma message disable nosimpint
     #error "You must define X11 accessors for this port!"
 #endif
 
+    
 // ----------------------------------------------------------------------------
-// code for making wxFrame a toolbar icon by setting appropriate properties:
+// wxTaskBarIconArea is the real window that shows the icon:
 // ----------------------------------------------------------------------------
 
-static bool wxMakeTaskBarIcon(wxFrame *wnd)
+class WXDLLIMPEXP_ADV wxTaskBarIconArea : public wxFrame
+{
+public:
+    wxTaskBarIconArea(wxTaskBarIcon *icon, const wxBitmap &bmp)
+        : wxFrame(NULL, -1, wxT("taskbar icon"),
+                  wxDefaultPosition, wxDefaultSize,
+                  wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR |
+                  wxSIMPLE_BORDER | wxFRAME_SHAPED),
+          m_icon(icon), m_bmp(bmp)
+    {
+        SetWMProperties();
+        SetSize(wxSize(bmp.GetWidth(), bmp.GetHeight()));
+    }
+
+    bool IsOk() { return true; }
+    
+protected:
+    void SetWMProperties();
+    
+    void OnPaint(wxPaintEvent& evt);
+    void OnWindowCreate(wxWindowCreateEvent& event);
+    void OnMouseEvent(wxMouseEvent& event);
+    void OnMenuEvent(wxCommandEvent& event);
+
+    wxTaskBarIcon *m_icon;
+    wxBitmap m_bmp;
+    
+    DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxTaskBarIconArea, wxFrame)
+    EVT_MOUSE_EVENTS(wxTaskBarIconArea::OnMouseEvent)
+    EVT_MENU(-1, wxTaskBarIconArea::OnMenuEvent)
+    EVT_PAINT(wxTaskBarIconArea::OnPaint)
+#ifdef __WXGTK__
+    EVT_WINDOW_CREATE(wxTaskBarIconArea::OnWindowCreate)
+#endif
+END_EVENT_TABLE()
+
+void wxTaskBarIconArea::SetWMProperties()
 { 
 #ifdef __WXGTK__
-    gtk_widget_realize(wnd->m_widget);
+    gtk_widget_realize(m_widget);
 #endif
     
     long data[1];
@@ -79,7 +119,7 @@ static bool wxMakeTaskBarIcon(wxFrame *wnd)
     Atom _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR =
         XInternAtom(GetDisplay(), "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False);
     data[0] = 0;
-    XChangeProperty(GetDisplay(), GetXWindow(wnd),
+    XChangeProperty(GetDisplay(), GetXWindow(this),
                     _KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR,
                     XA_WINDOW, 32,
                     PropModeReplace, (unsigned char*)data, 1);
@@ -88,38 +128,22 @@ static bool wxMakeTaskBarIcon(wxFrame *wnd)
     Atom KWM_DOCKWINDOW =
         XInternAtom(GetDisplay(), "KWM_DOCKWINDOW", False);
     data[0] = 1;
-    XChangeProperty(GetDisplay(), GetXWindow(wnd),
+    XChangeProperty(GetDisplay(), GetXWindow(this),
                     KWM_DOCKWINDOW,
                     KWM_DOCKWINDOW, 32,
                     PropModeReplace, (unsigned char*)data, 1);
-
-    return true;
 }
     
-// ----------------------------------------------------------------------------
-// wxTaskBarIconArea is the real window that shows the icon:
-// ----------------------------------------------------------------------------
-
-class wxTaskBarIconArea : public wxStaticBitmap
+void wxTaskBarIconArea::OnWindowCreate(wxWindowCreateEvent& WXUNUSED(event))
 {
-public:
-    wxTaskBarIconArea(wxTaskBarIcon *icon,
-                      wxWindow *parent, const wxBitmap &bmp)
-        : wxStaticBitmap(parent, -1, bmp), m_icon(icon) {}
-
-protected:
-    void OnMouseEvent(wxMouseEvent& event);
-    void OnMenuEvent(wxCommandEvent& event);
-
-    wxTaskBarIcon *m_icon;
-    
-    DECLARE_EVENT_TABLE()
-};
+    SetShape(wxRegion(m_bmp));
+}
 
-BEGIN_EVENT_TABLE(wxTaskBarIconArea, wxStaticBitmap)    
-    EVT_MOUSE_EVENTS(wxTaskBarIconArea::OnMouseEvent)
-    EVT_MENU(-1, wxTaskBarIconArea::OnMenuEvent)
-END_EVENT_TABLE()
+void wxTaskBarIconArea::OnPaint(wxPaintEvent& WXUNUSED(event))
+{
+    wxPaintDC dc(this);
+    dc.DrawBitmap(m_bmp, 0, 0, true);
+}
     
 void wxTaskBarIconArea::OnMouseEvent(wxMouseEvent& event)
 {
@@ -183,30 +207,18 @@ bool wxTaskBarIcon::SetIcon(const wxIcon& icon, const wxString& tooltip)
     if (m_iconWnd)
         RemoveIcon();
 
-    m_iconWnd = new wxFrame(NULL, -1, wxT("taskbar icon"),
-                            wxDefaultPosition, wxDefaultSize,
-                            wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR);
     wxBitmap bmp;
     bmp.CopyFromIcon(icon);
-    wxTaskBarIconArea *area = new wxTaskBarIconArea(this, m_iconWnd, bmp);
-
-    // make a sizer to keep the icon centered, in case it is smaller than the
-    // alotted space.
-    wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
-    sizer->Add(0,0,1);
-    sizer->Add(area, 0, wxALIGN_CENTER);
-    sizer->Add(0,0,1);
-    m_iconWnd->SetSizer(sizer);
     
-    m_iconWnd->SetClientSize(area->GetSize());
+    m_iconWnd = new wxTaskBarIconArea(this, bmp);
+
 #if wxUSE_TOOLTIPS
     if (!tooltip.empty())
-        area->SetToolTip(tooltip);
+        m_iconWnd->SetToolTip(tooltip);
 #endif
-    if (wxMakeTaskBarIcon(m_iconWnd))
+    if (m_iconWnd->IsOk())
     {
         m_iconWnd->Show();
-        m_iconArea = area;
         return true;
     }
     else
@@ -230,7 +242,7 @@ bool wxTaskBarIcon::PopupMenu(wxMenu *menu)
 {
     if (!m_iconWnd)
         return false;
-    wxSize size(m_iconArea->GetSize());
-    m_iconArea->PopupMenu(menu, size.x/2, size.y/2);
+    wxSize size(m_iconWnd->GetClientSize());
+    m_iconWnd->PopupMenu(menu, size.x/2, size.y/2);
     return true;
 }