src/gui/painting/qwindowsurface_raster.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #include <qglobal.h> // for Q_WS_WIN define (non-PCH)
00025 #ifdef Q_WS_WIN
00026 #include <qt_windows.h>
00027 #endif
00028 
00029 #include <QtGui/QPaintDevice>
00030 #include <QtGui/QWidget>
00031 
00032 #include "private/qwindowsurface_raster_p.h"
00033 #include "private/qpaintengine_raster_p.h"
00034 
00035 class MetricAccessor : public QWidget {
00036 public:
00037     int metric(PaintDeviceMetric m) const { return QWidget::metric(m); }
00038 };
00039 
00040 class QRasterPaintDevice : public QPaintDevice
00041 {
00042 public:
00043     QRasterPaintDevice()
00044     {
00045         m_window = 0;
00046         m_engine.setFlushOnEnd(false);
00047     }
00048 
00049     QWidget *window() const
00050     {
00051         return m_window;
00052     }
00053 
00054     void setWindow(QWidget *window)
00055     {
00056         m_window = window;
00057     }
00058 
00059     QSize size() const
00060     {
00061         return m_engine.size();
00062     }
00063 
00064     virtual int metric(PaintDeviceMetric m) const
00065     {
00066         Q_ASSERT(m_window);
00067         return ((MetricAccessor *) m_window)->metric(m);
00068     }
00069 
00070     QPaintEngine *paintEngine() const
00071     {
00072         return const_cast<QRasterPaintEngine *>(&m_engine);
00073     }
00074 
00075 private:
00076     QRasterPaintEngine m_engine;
00077     QWidget *m_window;
00078 };
00079 
00080 
00081 struct QRasterWindowSurfacePrivate
00082 {
00083     QRasterPaintDevice device;
00084 };
00085 
00086 QRasterWindowSurface::QRasterWindowSurface(QWidget *window)
00087     : d_ptr(new QRasterWindowSurfacePrivate)
00088 {
00089     Q_ASSERT(window->isTopLevel());
00090     d_ptr->device.setWindow(window);
00091 }
00092 
00093 
00094 QRasterWindowSurface::~QRasterWindowSurface()
00095 {
00096     delete d_ptr;
00097 }
00098 
00099 QPaintDevice *QRasterWindowSurface::paintDevice()
00100 {
00101     return &d_ptr->device;
00102 }
00103 
00104 
00105 void QRasterWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
00106 {
00107 #ifdef Q_WS_WIN
00108     QPoint wOffset = qt_qwidget_data(widget)->wrect.topLeft();
00109 
00110     QRasterPaintEngine *engine = static_cast<QRasterPaintEngine *>(d_ptr->device.paintEngine());
00111     HDC engine_dc = engine->getDC();
00112     HDC widget_dc = widget->getDC();
00113 
00114     QRect br = rgn.boundingRect();
00115     QRect wbr = br.translated(-wOffset);
00116     BitBlt(widget_dc, wbr.x(), wbr.y(), wbr.width(), wbr.height(),
00117            engine_dc, br.x() + offset.x(), br.y() + offset.y(), SRCCOPY);
00118 
00119     widget->releaseDC(widget_dc);
00120     engine->releaseDC(engine_dc);
00121 #else
00122     Q_UNUSED(widget);
00123     Q_UNUSED(rgn);
00124     Q_UNUSED(offset);
00125 #endif
00126 
00127 }
00128 
00129 void QRasterWindowSurface::setGeometry(const QRect &rect)
00130 {
00131     const QSize size = static_cast<QRasterPaintEngine*>(d_ptr->device.paintEngine())->size();
00132     if (size == rect.size())
00133         return;
00134     QRasterWindowSurface::release();
00135 }
00136 
00137 void QRasterWindowSurface::release()
00138 {
00139     static_cast<QRasterPaintEngine *>(d_ptr->device.paintEngine())->releaseBuffer();
00140 }
00141 
00142 
00143 void QRasterWindowSurface::scroll(const QRegion &area, int dx, int dy)
00144 {
00145 #ifdef Q_WS_WIN
00146     QRect rect = area.boundingRect();
00147 
00148     QRasterPaintEngine *engine = static_cast<QRasterPaintEngine *>(d_ptr->device.paintEngine());
00149     HDC engine_dc = engine->getDC();
00150     if (!engine_dc)
00151         return;
00152 
00153     BitBlt(engine_dc, rect.x()+dx, rect.y()+dy, rect.width(), rect.height(),
00154            engine_dc, rect.x(), rect.y(), SRCCOPY);
00155 
00156     engine->releaseDC(engine_dc);
00157 #else
00158     Q_UNUSED(area);
00159     Q_UNUSED(dx);
00160     Q_UNUSED(dy);
00161 #endif
00162 }
00163 
00164 QRect QRasterWindowSurface::geometry() const
00165 {
00166     const QPoint offset = d_ptr->device.window()->geometry().topLeft();
00167     const QSize size = static_cast<QRasterPaintEngine *>(d_ptr->device.paintEngine())->size();
00168     return QRect(offset, size);
00169 }

Generated on Thu Mar 15 11:55:39 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1