+}
+
+#endif // wxUSE_SPLINE
+
+
+
+// ----------------------------------------------------------------------------
+// wxPaintDC
+// ----------------------------------------------------------------------------
+
+wxPaintDC::wxPaintDC(wxWindow* win) : wxWindowDC(win)
+{
+ wxRegion* region = NULL;
+
+ // Combine all the update rects into a region
+ const wxRectList& updateRects(win->GetUpdateRects());
+ if ( updateRects.GetCount() != 0 )
+ {
+ for ( wxRectList::Node *node = updateRects.GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ wxRect* rect = node->GetData();
+
+ if (!region)
+ region = new wxRegion(*rect);
+ else
+ // TODO: is this correct? In SetDCClipping above,
+ // XIntersectRegion is used to combine paint and user
+ // regions. XIntersectRegion appears to work in that case...
+ region->Union(*rect);
+ }
+ }
+ else
+ {
+ int cw, ch;
+ win->GetClientSize(&cw, &ch);
+ region = new wxRegion(wxRect(0, 0, cw, ch));
+ }
+
+ win->SetUpdateRegion(*region);
+
+ // Set the clipping region. Any user-defined region will be combined with this
+ // one in SetDCClipping.
+ XSetRegion ((Display*) m_display, (GC) m_gc, (Region) region->GetXRegion());
+
+ delete region;
+}
+
+wxPaintDC::~wxPaintDC()
+{
+ XSetClipMask ((Display*) m_display, (GC) m_gc, None);
+ if (m_window)
+ m_window->ClearUpdateRegion();
+}
+
+// ----------------------------------------------------------------------------
+// private functions
+// ----------------------------------------------------------------------------
+
+/*
+ Used when copying between drawables on different (Display*) m_displays. Not
+ very fast, but better than giving up.
+*/
+
+static void XCopyRemote(Display *src_display, Display *dest_display,
+ Drawable src, Drawable dest,
+ GC destgc,
+ int srcx, int srcy,
+ unsigned int w, unsigned int h,
+ int destx, int desty,
+ bool more, XImage **cache)
+{
+ XImage *image, *destimage;
+ Colormap destcm, srccm;
+ static const int CACHE_SIZE = 256;
+
+ unsigned int i, j;
+ unsigned long cachesrc[CACHE_SIZE], cachedest[CACHE_SIZE];
+ int k, cache_pos, all_cache;
+
+ if (!cache || !*cache)
+ image = XGetImage(src_display, src, srcx, srcy, w, h, AllPlanes, ZPixmap);
+ else
+ image = *cache;
+
+ destimage = XGetImage(dest_display, dest, destx, desty, w, h, AllPlanes, ZPixmap);
+
+ srccm = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) src_display);
+ destcm = (Colormap) wxTheApp->GetMainColormap((WXDisplay*) dest_display);
+
+ cache_pos = 0;
+ all_cache = FALSE;
+
+ for (i = 0; i < w; i++)
+ for (j = 0; j < h; j++) {
+ unsigned long pixel;
+ XColor xcol;
+
+ pixel = XGetPixel(image, i, j);
+ for (k = cache_pos; k--; )
+ if (cachesrc[k] == pixel) {
+ pixel = cachedest[k];
+ goto install;
+ }
+ if (all_cache)
+ for (k = CACHE_SIZE; k-- > cache_pos; )
+ if (cachesrc[k] == pixel) {
+ pixel = cachedest[k];
+ goto install;
+ }
+
+ cachesrc[cache_pos] = xcol.pixel = pixel;
+ XQueryColor(src_display, srccm, &xcol);
+ if (!XAllocColor(dest_display, destcm, &xcol))
+ xcol.pixel = 0;
+ cachedest[cache_pos] = pixel = xcol.pixel;
+
+ if (++cache_pos >= CACHE_SIZE) {
+ cache_pos = 0;
+ all_cache = TRUE;
+ }
+
+install:
+ XPutPixel(destimage, i, j, pixel);
+ }
+
+ XPutImage(dest_display, dest, destgc, destimage, 0, 0, destx, desty, w, h);
+ XDestroyImage(destimage);
+
+ if (more)
+ *cache = image;
+ else
+ XDestroyImage(image);
+}
+
+#if 0
+
+/* Helper function for 16-bit fonts */
+static int str16len(const char *s)
+{
+ int count = 0;
+
+ while (s[0] && s[1]) {
+ count++;
+ s += 2;
+ }
+
+ return count;
+}
+
+#endif // 0