src/gui/painting/qregion_x11.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 <private/qt_x11_p.h>
00025 
00026 #include <limits.h>
00027 
00028 QRegion::QRegionData QRegion::shared_empty = {Q_ATOMIC_INIT(1), 0, 0, 0};
00029 
00030 void QRegion::updateX11Region() const
00031 {
00032     d->rgn = XCreateRegion();
00033     if (!d->qt_rgn)
00034         return;
00035 
00036     for(int i = 0; i < d->qt_rgn->numRects; ++i) {
00037         XRectangle r;
00038         const QRect &rect = d->qt_rgn->rects.at(i);
00039         r.x = qMax(SHRT_MIN, rect.x());
00040         r.y = qMax(SHRT_MIN, rect.y());
00041         r.width = qMin((int)USHRT_MAX, rect.width());
00042         r.height = qMin((int)USHRT_MAX, rect.height());
00043         XUnionRectWithRegion(&r, d->rgn, d->rgn);
00044     }
00045 }
00046 
00047 void *QRegion::clipRectangles(int &num) const
00048 {
00049     if (!d->xrectangles && !(d == &shared_empty || d->qt_rgn->numRects == 0)) {
00050         XRectangle *r = static_cast<XRectangle*>(malloc(d->qt_rgn->numRects * sizeof(XRectangle)));
00051         d->xrectangles = r;
00052         for(int i = 0; i < d->qt_rgn->numRects; ++i) {
00053             const QRect &rect = d->qt_rgn->rects.at(i);
00054             r->x = qMax(SHRT_MIN, rect.x());
00055             r->y = qMax(SHRT_MIN, rect.y());
00056             r->width = qMin((int)USHRT_MAX, rect.width());
00057             r->height = qMin((int)USHRT_MAX, rect.height());
00058             ++r;
00059         }
00060     }
00061     if (d == &shared_empty || d->qt_rgn->numRects == 0)
00062         num = 0;
00063     else
00064         num = d->qt_rgn->numRects;
00065     return d->xrectangles;
00066 }

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