void timerCallback() { // Wait for the moment when PT deigns to allow our view to // take up its actual location (see rant above) HIViewRef content = 0; HIViewFindByID (HIViewGetRoot ((WindowRef) hostWindow), kHIViewWindowContentID, &content); HIPoint p = { 0.0f, 0.0f }; HIViewRef v = HIViewGetFirstSubview (parentView); HIViewConvertPoint (&p, v, content); if (p.y > 12) { if (p.x != titleW || p.y != titleH) { GrafPtr oldport; GetPort (&oldport); SetPort (owner->GetViewPort()); SetOrigin (-titleW, -titleH); SetPort (oldport); } HIViewRef v = HIViewGetFirstSubview (parentView); SetControlSupervisor (v, 0); stopTimer(); forcedRepaintTimer = new RepaintCheckTimer (*this); } }
// ----------------------------------------------------------------------------- // HITestViewTrack // ----------------------------------------------------------------------------- // This is overkill, and probably #ifdef'd out, but is here as an example of // a custom tracking handler. // OSStatus HITestViewTrack( EventRef inEvent, HITestViewData* inData ) { OSStatus err; HIRect bounds; HIPoint where; ControlPartCode part; Boolean inside; Boolean wasInside; Point qdPt; MouseTrackingResult mouseResult; PixMapHandle portPixMap; // Extract the mouse location err = GetEventParameter( inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof( HIPoint ), NULL, &where ); require_noerr( err, ParameterMissing ); // Is the mouse location in the view? err = HIViewGetBounds( inData->view, &bounds ); if ( CGRectContainsPoint( bounds, where ) ) part = 1; else part = kControlNoPart; HiliteControl( inData->view, part ); wasInside = true; // Need the port's pixMap's bounds to convert the mouse location portPixMap = GetPortPixMap( GetWindowPort( GetControlOwner( inData->view ) ) ); // The tracking loop while ( true ) { // Check again to see if the mouse is in the view if ( CGRectContainsPoint( bounds, where ) ) part = 1; else part = kControlNoPart; inside = ( part != kControlNoPart ); // If that changed, update if ( inside != wasInside ) HiliteControl( inData->view, part ); wasInside = inside; // Watch the mouse for change err = TrackMouseLocation( (GrafPtr)-1L, &qdPt, &mouseResult ); // Need to convert from global QDGlobalToLocalPoint( GetWindowPort( GetControlOwner( inData->view ) ), &qdPt ); where.x = qdPt.h - (**portPixMap).bounds.left; where.y = qdPt.v - (**portPixMap).bounds.top; HIViewConvertPoint( &where, NULL, inData->view ); // Bail out when the mouse is released if ( mouseResult == kMouseTrackingMouseReleased ) break; } // Restore the original highlight HiliteControl( inData->view, kControlNoPart ); // Send back the part upon which the mouse was released err = SetEventParameter( inEvent, kEventParamControlPart, typeControlPartCode, sizeof( ControlPartCode ), &part ); ParameterMissing: return err; }
static pascal OSStatus CustomSpotViewHandler(EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon) { OSStatus result = eventNotHandledErr; CustomSpotViewData* myData = (CustomSpotViewData*)inRefcon; switch (GetEventClass(inEvent)) { case kEventClassHIObject: switch (GetEventKind(inEvent)) { case kEventHIObjectConstruct: { myData = (CustomSpotViewData*) calloc(1, sizeof(CustomSpotViewData)); GetEventParameter(inEvent, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(myData->view), NULL, &myData->view); result = SetEventParameter(inEvent, kEventParamHIObjectInstance, typeVoidPtr, sizeof(myData), &myData); break; } case kEventHIObjectInitialize: { HIRect bounds; GetEventParameter(inEvent, kEventParamBounds, typeHIRect, NULL, sizeof(bounds), NULL, &bounds); myData->spot.x = CGRectGetMidX(bounds) - CGRectGetMinX(bounds); myData->spot.y = CGRectGetMidY(bounds) - CGRectGetMinY(bounds); HIViewSetVisible(myData->view, true); break; } case kEventHIObjectDestruct: { free(myData); result = noErr; break; } default: break; } break; case kEventClassControl: switch (GetEventKind(inEvent)) { case kEventControlDraw: { CGContextRef context; HIRect bounds; result = GetEventParameter(inEvent, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(context), NULL, &context); HIViewGetBounds(myData->view, &bounds); if (!IsControlActive(myData->view)) { CGContextSetGrayStrokeColor(context, 0.5, 0.3); CGContextSetGrayFillColor(context, 0.5, 0.3); } else { CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.7); CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.7); } CGContextSetLineWidth(context, 3.0); CGContextStrokeRect(context, bounds); HIRect spot = { {myData->spot.x - 4.0, myData->spot.y - 4.0}, {8.0, 8.0} }; CGContextFillRect(context, spot); result = noErr; break; } case kEventControlBoundsChanged: { HIRect newHIBounds; GetEventParameter(inEvent, kEventParamCurrentBounds, typeHIRect, NULL, sizeof(newHIBounds), NULL, &newHIBounds); myData->spot.x = CGRectGetMidX(newHIBounds) - CGRectGetMinX(newHIBounds); myData->spot.y = CGRectGetMidY(newHIBounds) - CGRectGetMinY(newHIBounds); break; } case kEventControlHitTest: { HIPoint pt; HIRect bounds; GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(pt), NULL, &pt); HIViewGetBounds(myData->view, &bounds); ControlPartCode part = (CGRectContainsPoint(bounds, pt))?kControlButtonPart:kControlNoPart; result = SetEventParameter(inEvent, kEventParamControlPart, typeControlPartCode, sizeof(part), &part); break; } case kEventControlTrack: { Point qdPoint; Rect qdWindowBounds; HIPoint hiPoint; HIRect hiViewBounds; MouseTrackingResult mouseStatus = kMouseTrackingMouseDown; HIViewGetBounds(myData->view, &hiViewBounds); GetWindowBounds(GetControlOwner(myData->view), kWindowStructureRgn, &qdWindowBounds); // handle the first mouseDown before moving GetEventParameter(inEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(hiPoint), NULL, &hiPoint); while (mouseStatus != kMouseTrackingMouseUp) { if (CGRectContainsPoint(hiViewBounds, hiPoint)) { if (hiPoint.x < hiViewBounds.origin.x+4) hiPoint.x = hiViewBounds.origin.x+4; if (hiPoint.x > hiViewBounds.origin.x+hiViewBounds.size.width-4) hiPoint.x = hiViewBounds.origin.x+hiViewBounds.size.width-4; if (hiPoint.y < hiViewBounds.origin.y+4) hiPoint.y = hiViewBounds.origin.y+4; if (hiPoint.y > hiViewBounds.origin.y+hiViewBounds.size.height-4) hiPoint.y = hiViewBounds.origin.y+hiViewBounds.size.height-4; myData->spot = hiPoint; HIViewSetNeedsDisplay(myData->view, true); } // a -1 GrafPtr to TrackMouseLocation yields global coordinates TrackMouseLocation((GrafPtr)-1L, &qdPoint, &mouseStatus); // convert to window-relative coordinates hiPoint.x = qdPoint.h - qdWindowBounds.left; hiPoint.y = qdPoint.v - qdWindowBounds.top; // convert to view-relative coordinates HIViewConvertPoint(&hiPoint, NULL, myData->view); } break; } default: break; } break; default: break; } return result; }
void QGLContext::updatePaintDevice() { Q_D(QGLContext); d->update = false; #if 0 //(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) { if(d->paintDevice->devType() == QInternal::Widget) { QWidget *w = (QWidget *)d->paintDevice; aglSetHIViewRef((AGLContext)d->cx, (HIViewRef)w->winId()); } else if(d->paintDevice->devType() == QInternal::Pixmap) { QPixmap *pm = (QPixmap *)d->paintDevice; aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(), qt_mac_pixmap_get_bytes_per_line(pm), qt_mac_pixmap_get_base(pm)); } else { qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!"); } } else #endif { #ifndef Q_OS_MAC64 if(d->paintDevice->devType() == QInternal::Widget) { //get control information QWidget *w = (QWidget *)d->paintDevice; HIViewRef hiview = (HIViewRef)w->winId(); WindowPtr window = qt_mac_window_for(hiview); #ifdef DEBUG_OPENGL_REGION_UPDATE static int serial_no_gl = 0; qDebug("[%d] %p setting on %s::%s %p/%p [%s]", ++serial_no_gl, w, w->metaObject()->className(), w->objectName().toLatin1().constData(), hiview, window, w->handle() ? "Inside" : "Outside"); #endif //update drawable if(0 && w->isWindow() && w->isFullScreen()) { aglSetDrawable((AGLContext)d->cx, 0); aglSetFullScreen((AGLContext)d->cx, w->width(), w->height(), 0, QApplication::desktop()->screenNumber(w)); w->hide(); } else { AGLDrawable old_draw = aglGetDrawable((AGLContext)d->cx), new_draw = GetWindowPort(window); if(old_draw != new_draw) aglSetDrawable((AGLContext)d->cx, new_draw); } if(!w->isWindow()) { QRegion clp = qt_mac_get_widget_rgn(w); //get drawable area #ifdef DEBUG_OPENGL_REGION_UPDATE if(clp.isEmpty()) { qDebug(" Empty area!"); } else { QVector<QRect> rs = clp.rects(); for(int i = 0; i < rs.count(); i++) qDebug(" %d %d %d %d", rs[i].x(), rs[i].y(), rs[i].width(), rs[i].height()); } #endif //update the clip if(!aglIsEnabled((AGLContext)d->cx, AGL_BUFFER_RECT)) aglEnable((AGLContext)d->cx, AGL_BUFFER_RECT); if(clp.isEmpty()) { GLint offs[4] = { 0, 0, 0, 0 }; aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs); if(aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION)) aglDisable((AGLContext)d->cx, AGL_CLIP_REGION); } else { HIPoint origin = { 0., 0. }; HIViewConvertPoint(&origin, HIViewRef(w->winId()), 0); const GLint offs[4] = { qRound(origin.x), w->window()->frameGeometry().height() - (qRound(origin.y) + w->height()), w->width(), w->height() }; aglSetInteger((AGLContext)d->cx, AGL_BUFFER_RECT, offs); aglSetInteger((AGLContext)d->cx, AGL_CLIP_REGION, (const GLint *)clp.handle(true)); if(!aglIsEnabled((AGLContext)d->cx, AGL_CLIP_REGION)) aglEnable((AGLContext)d->cx, AGL_CLIP_REGION); } } } else if(d->paintDevice->devType() == QInternal::Pixmap) { QPixmap *pm = (QPixmap *)d->paintDevice; PixMapHandle mac_pm = GetGWorldPixMap((GWorldPtr)pm->macQDHandle()); aglSetOffScreen((AGLContext)d->cx, pm->width(), pm->height(), GetPixRowBytes(mac_pm), GetPixBaseAddr(mac_pm)); } else { qWarning("QGLContext::updatePaintDevice(): Not sure how to render OpenGL on this device!"); } #endif // Q_OS_MAC64 } aglUpdateContext((AGLContext)d->cx); }