| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qwindowsurface_mac_p.h"
|
|---|
| 43 |
|
|---|
| 44 | #include <private/qt_mac_p.h>
|
|---|
| 45 | #include <private/qt_cocoa_helpers_mac_p.h>
|
|---|
| 46 | #include <QtGui/qwidget.h>
|
|---|
| 47 |
|
|---|
| 48 | QT_BEGIN_NAMESPACE
|
|---|
| 49 |
|
|---|
| 50 | struct QMacWindowSurfacePrivate
|
|---|
| 51 | {
|
|---|
| 52 | QWidget *widget;
|
|---|
| 53 | QPixmap device;
|
|---|
| 54 | };
|
|---|
| 55 |
|
|---|
| 56 | QMacWindowSurface::QMacWindowSurface(QWidget *widget)
|
|---|
| 57 | : QWindowSurface(widget), d_ptr(new QMacWindowSurfacePrivate)
|
|---|
| 58 | {
|
|---|
| 59 | d_ptr->widget = widget;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | QMacWindowSurface::~QMacWindowSurface()
|
|---|
| 63 | {
|
|---|
| 64 | delete d_ptr;
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | QPaintDevice *QMacWindowSurface::paintDevice()
|
|---|
| 68 | {
|
|---|
| 69 | return &d_ptr->device;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | void QMacWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint &offset)
|
|---|
| 73 | {
|
|---|
| 74 | Q_UNUSED(offset);
|
|---|
| 75 |
|
|---|
| 76 | // Get a context for the widget.
|
|---|
| 77 | #ifndef QT_MAC_USE_COCOA
|
|---|
| 78 | CGContextRef context;
|
|---|
| 79 | CGrafPtr port = GetWindowPort(qt_mac_window_for(widget));
|
|---|
| 80 | QDBeginCGContext(port, &context);
|
|---|
| 81 | #else
|
|---|
| 82 | extern CGContextRef qt_mac_graphicsContextFor(QWidget *);
|
|---|
| 83 | CGContextRef context = qt_mac_graphicsContextFor(widget);
|
|---|
| 84 | #endif
|
|---|
| 85 | CGContextSaveGState(context);
|
|---|
| 86 |
|
|---|
| 87 | // Flip context.
|
|---|
| 88 | CGContextTranslateCTM(context, 0, widget->height());
|
|---|
| 89 | CGContextScaleCTM(context, 1, -1);
|
|---|
| 90 |
|
|---|
| 91 | // Clip to region.
|
|---|
| 92 | const QVector<QRect> &rects = rgn.rects();
|
|---|
| 93 | for (int i = 0; i < rects.size(); ++i) {
|
|---|
| 94 | const QRect &rect = rects.at(i);
|
|---|
| 95 | CGContextAddRect(context, CGRectMake(rect.x(), rect.y(), rect.width(), rect.height()));
|
|---|
| 96 | }
|
|---|
| 97 | CGContextClip(context);
|
|---|
| 98 |
|
|---|
| 99 | // Draw the image onto the window.
|
|---|
| 100 | const CGRect dest = CGRectMake(0, 0, widget->width(), widget->height());
|
|---|
| 101 | const CGImageRef image = d_ptr->device.toMacCGImageRef();
|
|---|
| 102 | qt_mac_drawCGImage(context, &dest, image);
|
|---|
| 103 | CFRelease(image);
|
|---|
| 104 |
|
|---|
| 105 | // Restore context.
|
|---|
| 106 | CGContextRestoreGState(context);
|
|---|
| 107 | #ifndef QT_MAC_USE_COCOA
|
|---|
| 108 | QDEndCGContext(port, &context);
|
|---|
| 109 | #else
|
|---|
| 110 | CGContextFlush(context);
|
|---|
| 111 | #endif
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | void QMacWindowSurface::setGeometry(const QRect &rect)
|
|---|
| 115 | {
|
|---|
| 116 | QWindowSurface::setGeometry(rect);
|
|---|
| 117 | const QSize size = rect.size();
|
|---|
| 118 | if (d_ptr->device.size() != size)
|
|---|
| 119 | d_ptr->device = QPixmap(size);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | bool QMacWindowSurface::scroll(const QRegion &area, int dx, int dy)
|
|---|
| 123 | {
|
|---|
| 124 | if (d_ptr->device.size().isNull())
|
|---|
| 125 | return false;
|
|---|
| 126 |
|
|---|
| 127 | QCFType<CGImageRef> image = d_ptr->device.toMacCGImageRef();
|
|---|
| 128 | const QRect rect(area.boundingRect());
|
|---|
| 129 | const CGRect dest = CGRectMake(rect.x(), rect.y(), rect.width(), rect.height());
|
|---|
| 130 | QCFType<CGImageRef> subimage = CGImageCreateWithImageInRect(image, dest);
|
|---|
| 131 | QCFType<CGContextRef> context = qt_mac_cg_context(&d_ptr->device);
|
|---|
| 132 | CGContextTranslateCTM(context, dx, dy);
|
|---|
| 133 | qt_mac_drawCGImage(context, &dest, subimage);
|
|---|
| 134 | return true;
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | QT_END_NAMESPACE
|
|---|