+#ifdef HAVE_XSHAPE
+
+ #ifndef WX_PRECOMP
+ #include "wx/bitmap.h"
+ #include "wx/region.h"
+ #endif
+
+ #ifdef __VMS
+ #include "wx/vms_x_fix.h"
+ #include <X11/shape.h>
+ #else
+ #include <X11/extensions/shape.h>
+ #endif
+
+ #include "wx/dcmemory.h"
+#endif
+
+#ifdef HAVE_X11_XKBLIB_H
+ /* under HP-UX and Solaris 2.6, at least, XKBlib.h defines structures with
+ * field named "explicit" - which is, of course, an error for a C++
+ * compiler. To be on the safe side, just redefine it everywhere. */
+ #define explicit __wx_explicit
+
+ #include "X11/XKBlib.h"
+
+ #undef explicit
+#endif // HAVE_X11_XKBLIB_H
+
+
+// ----------------------------------------------------------------------------
+// XShape code
+// ----------------------------------------------------------------------------
+
+#ifdef HAVE_XSHAPE
+
+bool wxDoSetShape( Display* xdisplay,
+ Window xwindow,
+ const wxRegion& region )
+{
+ int dummy1, dummy2;
+
+ if( !XShapeQueryExtension( xdisplay, &dummy1, &dummy2 ) )
+ return false;
+
+ if( region.IsEmpty() )
+ {
+ XShapeCombineMask( xdisplay, xwindow, ShapeBounding, 0, 0,
+ None, ShapeSet );
+ }
+ else
+ {
+ // wxRegion::ConvertToBitmap gives us the wrong Pixmap:
+ // polychrome and with black and white reversed
+ wxRect box = region.GetBox();
+ wxBitmap bmp(box.GetRight(), box.GetBottom(), 1);
+ wxMemoryDC dc;
+ dc.SelectObject(bmp);
+ dc.SetBackground(*wxBLACK_BRUSH);
+ dc.Clear();
+ dc.SetDeviceClippingRegion(region);
+ dc.SetBackground(*wxWHITE_BRUSH);
+ dc.Clear();
+ dc.SelectObject(wxNullBitmap);
+
+ XShapeCombineMask( xdisplay, xwindow, ShapeBounding, 0, 0,
+ (Pixmap)bmp.GetDrawable(), ShapeSet );
+ }
+
+ return true;
+}
+
+#else
+
+bool wxDoSetShape( Display* WXUNUSED(xdisplay),
+ Window WXUNUSED(xwindow),
+ const wxRegion& WXUNUSED(region) )
+{
+ return false;
+}
+
+#endif
+