- /*
- Widget drawingArea = (Widget) m_drawingArea;
- // int orig = GetDC()->GetLogicalFunction();
- // GetDC()->SetLogicalFunction (wxCOPY);
-
- // TODO: it may not be necessary to store m_pixmapOffsetX/Y; we
- // should be able to calculate them.
- XCopyArea (XtDisplay (drawingArea), m_backingPixmap, XtWindow (drawingArea), GetDC ()->gc,
- m_pixmapOffsetX, m_pixmapOffsetY,
- m_pixmapWidth, m_pixmapHeight,
- 0, 0);
-
- // GetDC()->SetLogicalFunction (orig);
- */
+ wxPaintDC dc(this);
+
+ GC tempGC = (GC) dc.GetBackingGC();
+
+ Widget widget = (Widget) GetMainWidget();
+
+ int scrollPosX = 0;
+ int scrollPosY = 0;
+
+ // We have to test whether it's a wxScrolledWindow (hack!)
+ // because otherwise we don't know how many pixels have been
+ // scrolled. We might solve this in the future by defining
+ // virtual wxWindow functions to get the scroll position in pixels.
+ // Or, each kind of scrolled window has to implement backing
+ // stores itself, using generic wxWindows code.
+ if (this->IsKindOf(CLASSINFO(wxScrolledWindow)))
+ {
+ wxScrolledWindow* scrolledWindow = (wxScrolledWindow*) this;
+ int x, y;
+ scrolledWindow->CalcScrolledPosition(0, 0, & x, & y);
+
+ scrollPosX = - x;
+ scrollPosY = - y;
+ }
+
+ // TODO: This could be optimized further by only copying the
+ // areas in the current update region.
+
+ // Only blit the part visible in the client area. The backing pixmap
+ // always starts at 0, 0 but we may be looking at only a portion of it.
+ wxSize clientArea = GetClientSize();
+ int toBlitX = m_pixmapWidth - scrollPosX;
+ int toBlitY = m_pixmapHeight - scrollPosY;
+
+ // Copy whichever is samller, the amount of pixmap we have to copy,
+ // or the size of the client area.
+ toBlitX = wxMin(toBlitX, clientArea.x);
+ toBlitY = wxMin(toBlitY, clientArea.y);
+
+ // Make sure we're not negative
+ toBlitX = wxMax(0, toBlitX);
+ toBlitY = wxMax(0, toBlitY);
+
+ XCopyArea (XtDisplay (widget), (Pixmap) m_backingPixmap, XtWindow (widget), tempGC,
+ scrollPosX, scrollPosY, // Start at the scroll position
+ toBlitX, toBlitY, // How much of the pixmap to copy
+ 0, 0); // Destination