/*! \internal Create's a RegionHandle, it's the caller's responsibility to release. Returns 0 if the QRegion overflows. */ RgnHandle QRegion::toQDRgnForUpdate_sys() const { RgnHandle rgnHandle = qt_mac_get_rgn(); if(d->qt_rgn && d->qt_rgn->numRects) { RgnHandle tmp_rgn = qt_mac_get_rgn(); int n = d->qt_rgn->numRects; const QRect *qt_r = (n == 1) ? &d->qt_rgn->extents : d->qt_rgn->rects.constData(); while (n--) { // detect overflow. Tested for use with HIViewSetNeedsDisplayInRegion // in QWidgetPrivate::update_sys(). enum { HIViewSetNeedsDisplayInRegionOverflow = 10000 }; // empirically determined conservative value if (qt_r->right() > HIViewSetNeedsDisplayInRegionOverflow || qt_r->bottom() > HIViewSetNeedsDisplayInRegionOverflow) { qt_mac_dispose_rgn(tmp_rgn); qt_mac_dispose_rgn(rgnHandle); return 0; } SetRectRgn(tmp_rgn, qMax(SHRT_MIN, qt_r->x()), qMax(SHRT_MIN, qt_r->y()), qMin(SHRT_MAX, qt_r->right() + 1), qMin(SHRT_MAX, qt_r->bottom() + 1)); UnionRgn(rgnHandle, tmp_rgn, rgnHandle); ++qt_r; } qt_mac_dispose_rgn(tmp_rgn); } return rgnHandle; }
QRegion QRegion::fromHIShapeRef(HIShapeRef shape) { QRegion returnRegion; returnRegion.detach(); // Begin gratuitous #if-defery #if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) # ifndef Q_WS_MAC64 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { # endif HIShapeEnumerate(shape, kHIShapeParseFromTopLeft, shape2QRegionHelper, &returnRegion); # ifndef Q_WS_MAC64 } else # endif #endif { #if !defined(Q_WS_MAC64) && !defined(QT_MAC_USE_COCOA) if (ptrHIShapeGetAsQDRgn == 0) { QLibrary library(QLatin1String("/System/Library/Frameworks/Carbon.framework/Carbon")); library.setLoadHints(QLibrary::ExportExternalSymbolsHint); ptrHIShapeGetAsQDRgn = reinterpret_cast<PtrHIShapeGetAsQDRgn>(library.resolve("HIShapeGetAsQDRgn")); } RgnHandle rgn = qt_mac_get_rgn(); ptrHIShapeGetAsQDRgn(shape, rgn); returnRegion = QRegion::fromQDRgn(rgn); qt_mac_dispose_rgn(rgn); #endif } return returnRegion; }
/*! \internal Create's a RegionHandle, it's the caller's responsibility to release. */ RgnHandle QRegion::toQDRgn() const { RgnHandle rgnHandle = qt_mac_get_rgn(); if(d->qt_rgn && d->qt_rgn->numRects) { RgnHandle tmp_rgn = qt_mac_get_rgn(); int n = d->qt_rgn->numRects; const QRect *qt_r = (n == 1) ? &d->qt_rgn->extents : d->qt_rgn->rects.constData(); while (n--) { SetRectRgn(tmp_rgn, qMax(SHRT_MIN, qt_r->x()), qMax(SHRT_MIN, qt_r->y()), qMin(SHRT_MAX, qt_r->right() + 1), qMin(SHRT_MAX, qt_r->bottom() + 1)); UnionRgn(rgnHandle, tmp_rgn, rgnHandle); ++qt_r; } qt_mac_dispose_rgn(tmp_rgn); } return rgnHandle; }
/**************************************************************************** Hacks to glue AGL to an HIView ***************************************************************************/ QRegion qt_mac_get_widget_rgn(const QWidget *widget) { if(!widget->isVisible() || widget->isMinimized()) return QRegion(); const QRect wrect = QRect(qt_mac_posInWindow(widget), widget->size()); if(!wrect.isValid()) return QRegion(); RgnHandle macr = qt_mac_get_rgn(); GetControlRegion((HIViewRef)widget->winId(), kControlStructureMetaPart, macr); OffsetRgn(macr, wrect.x(), wrect.y()); QRegion ret = qt_mac_convert_mac_region(macr); QPoint clip_pos = wrect.topLeft(); for(const QWidget *last_clip = 0, *clip = widget; clip; last_clip = clip, clip = clip->parentWidget()) { if(clip != widget) { GetControlRegion((HIViewRef)clip->winId(), kControlStructureMetaPart, macr); OffsetRgn(macr, clip_pos.x(), clip_pos.y()); ret &= qt_mac_convert_mac_region(macr); } const QObjectList &children = clip->children(); for(int i = children.size()-1; i >= 0; --i) { if(QWidget *child = qobject_cast<QWidget*>(children.at(i))) { if(child == last_clip) break; // This check may seem weird, but when we are using a unified toolbar // The widget is actually being owned by that toolbar and not by Qt. // This means that the geometry it reports will be wrong // and will accidentally cause problems when calculating the region // So, it is better to skip these widgets since they aren't the hierarchy // anyway. if (HIViewGetSuperview(HIViewRef(child->winId())) != HIViewRef(clip->winId())) continue; if(child->isVisible() && !child->isMinimized() && !child->isTopLevel()) { const QRect childRect = QRect(clip_pos+child->pos(), child->size()); if(childRect.isValid() && wrect.intersects(childRect)) { GetControlRegion((HIViewRef)child->winId(), kControlStructureMetaPart, macr); OffsetRgn(macr, childRect.x(), childRect.y()); ret -= qt_mac_convert_mac_region(macr); } } } } if(clip->isWindow()) break; clip_pos -= clip->pos(); } qt_mac_dispose_rgn(macr); return ret; }