0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the QtGui module of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
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
|