Ejemplo n.º 1
0
/*!
    \internal
     Create's a mutable shape, it's the caller's responsibility to release.
     WARNING: this function clamps the coordinates to SHRT_MIN/MAX on 10.4 and below.
*/
HIMutableShapeRef QRegion::toHIMutableShape() const
{
    HIMutableShapeRef shape = HIShapeCreateMutable();
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
    if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_5) {
        if (d->qt_rgn && d->qt_rgn->numRects) {
            int n = d->qt_rgn->numRects;
            const QRect *qt_r = (n == 1) ? &d->qt_rgn->extents : d->qt_rgn->rects.constData();
            while (n--) {
                CGRect cgRect = CGRectMake(qt_r->x(), qt_r->y(), qt_r->width(), qt_r->height());
                HIShapeUnionWithRect(shape, &cgRect);
                ++qt_r;
            }
        }
    } else
#endif
    {
#ifndef QT_MAC_USE_COCOA
        QCFType<HIShapeRef> qdShape = HIShapeCreateWithQDRgn(QMacSmartQuickDrawRegion(toQDRgn()));
        HIShapeUnion(qdShape, shape, shape);
#endif
    }
    return shape;
}
Ejemplo n.º 2
0
void
TkMacOSXUpdateClipRgn(
    TkWindow *winPtr)
{
    MacDrawable *macWin;

    if (winPtr == NULL) {
	return;
    }
    macWin = winPtr->privatePtr;
    if (macWin && macWin->flags & TK_CLIP_INVALID) {
	TkWindow *win2Ptr;

	if (Tk_IsMapped(winPtr)) {
	    int rgnChanged = 0;
	    CGRect bounds;
	    HIMutableShapeRef rgn;

	    /*
	     * Start with a region defined by the window bounds.
	     */

	    TkMacOSXWinCGBounds(winPtr, &bounds);
	    rgn = TkMacOSXHIShapeCreateMutableWithRect(&bounds);

	    /*
	     * Clip away the area of any windows that may obscure this window.
	     * For a non-toplevel window, first, clip to the parents visible
	     * clip region. Second, clip away any siblings that are higher in
	     * the stacking order. For an embedded toplevel, just clip to the
	     * container's visible clip region. Remember, we only allow one
	     * contained window in a frame, and don't support any other widgets
	     * in the frame either. This is not currently enforced, however.
	     */

	    if (!Tk_IsTopLevel(winPtr)) {
		TkMacOSXUpdateClipRgn(winPtr->parentPtr);
		if (winPtr->parentPtr) {
		    ChkErr(HIShapeIntersect,
			    winPtr->parentPtr->privatePtr->aboveVisRgn,
			    rgn, rgn);
		}
		win2Ptr = winPtr;
		while ((win2Ptr = win2Ptr->nextPtr)) {
		    if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
			continue;
		    }
		    TkMacOSXWinCGBounds(win2Ptr, &bounds);
		    ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		}
	    } else if (Tk_IsEmbedded(winPtr)) {
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    TkMacOSXUpdateClipRgn(win2Ptr);
		    ChkErr(HIShapeIntersect,
			    win2Ptr->privatePtr->aboveVisRgn, rgn, rgn);
		} else if (tkMacOSXEmbedHandler != NULL) {
		    HIShapeRef visRgn;

		    TkMacOSXCheckTmpQdRgnEmpty();
		    tkMacOSXEmbedHandler->getClipProc((Tk_Window) winPtr,
			    tkMacOSXtmpQdRgn);
		    visRgn = HIShapeCreateWithQDRgn(tkMacOSXtmpQdRgn);
		    SetEmptyRgn(tkMacOSXtmpQdRgn);
		    ChkErr(HIShapeIntersect, visRgn, rgn, rgn);
		}

		/*
		 * TODO: Here we should handle out of process embedding.
		 */
	    } else if (winPtr->wmInfoPtr->attributes &
		    kWindowResizableAttribute) {
		HIViewRef growBoxView;
		OSErr err = HIViewFindByID(HIViewGetRoot(
			TkMacOSXDrawableWindow(winPtr->window)),
			kHIViewWindowGrowBoxID, &growBoxView);

		if (err == noErr) {
		    ChkErr(HIViewGetFrame, growBoxView, &bounds);
		    bounds = CGRectOffset(bounds,
			    -winPtr->wmInfoPtr->xInParent,
			    -winPtr->wmInfoPtr->yInParent);
		    ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		}
	    }
	    macWin->aboveVisRgn = HIShapeCreateCopy(rgn);

	    /*
	     * The final clip region is the aboveVis region (or visible region)
	     * minus all the children of this window. If the window is a
	     * container, we must also subtract the region of the embedded
	     * window.
	     */

	    win2Ptr = winPtr->childList;
	    while (win2Ptr) {
		if (Tk_IsTopLevel(win2Ptr) || !Tk_IsMapped(win2Ptr)) {
		    win2Ptr = win2Ptr->nextPtr;
		    continue;
		}
		TkMacOSXWinCGBounds(win2Ptr, &bounds);
		ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
		rgnChanged = 1;
		win2Ptr = win2Ptr->nextPtr;
	    }

	    if (Tk_IsContainer(winPtr)) {
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    if (Tk_IsMapped(win2Ptr)) {
			TkMacOSXWinCGBounds(win2Ptr, &bounds);
			ChkErr(TkMacOSHIShapeDifferenceWithRect, rgn, &bounds);
			rgnChanged = 1;
		    }
		}

		/*
		 * TODO: Here we should handle out of process embedding.
		 */
	    }

	    if (rgnChanged) {
		HIShapeRef diffRgn = HIShapeCreateDifference(
			macWin->aboveVisRgn, rgn);

		if (!HIShapeIsEmpty(diffRgn)) {
		    macWin->visRgn = HIShapeCreateCopy(rgn);
		}
		CFRelease(diffRgn);
	    }
	    CFRelease(rgn);
	} else {
	    /*
	     * An unmapped window has empty clip regions to prevent any
	     * (erroneous) drawing into it or its children from becoming
	     * visible. [Bug 940117]
	     */

	    if (!Tk_IsTopLevel(winPtr)) {
		TkMacOSXUpdateClipRgn(winPtr->parentPtr);
	    } else if (Tk_IsEmbedded(winPtr)) {
		win2Ptr = TkpGetOtherWindow(winPtr);
		if (win2Ptr) {
		    TkMacOSXUpdateClipRgn(win2Ptr);
		}
	    }
	    macWin->aboveVisRgn = TkMacOSXHIShapeCreateEmpty();
	}
	if (!macWin->visRgn) {
	    macWin->visRgn = HIShapeCreateCopy(macWin->aboveVisRgn);
	}
	macWin->flags &= ~TK_CLIP_INVALID;

#ifdef TK_MAC_DEBUG_CLIP_REGIONS
	TkMacOSXDebugFlashRegion((Drawable) macWin, macWin->visRgn);
#endif /* TK_MAC_DEBUG_CLIP_REGIONS */
    }
}
Ejemplo n.º 3
0
OSStatus HIRevolutionStackViewHandler(EventHandlerCallRef p_call_ref, EventRef p_event, void *p_data)
{
	OSStatus t_status;
	t_status = eventNotHandledErr;
	
	UInt32 t_event_class;
	t_event_class = GetEventClass(p_event);
	
	UInt32 t_event_kind;
	t_event_kind = GetEventKind(p_event);
	
	HIRevolutionStackViewData *t_context;
	t_context = (HIRevolutionStackViewData *)p_data;
	
	switch(t_event_class)
	{
	case 'revo':
		switch(t_event_kind)
		{
			case 'rlnk':
				GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack);
			break;
		}
	break;
	
	case kEventClassHIObject:
		switch(t_event_kind)
		{
		case kEventHIObjectConstruct:
		{
			HIRevolutionStackViewData *t_data;
			t_data = new HIRevolutionStackViewData;
			t_data -> stack = NULL;
			GetEventParameter(p_event, kEventParamHIObjectInstance, typeHIObjectRef, NULL, sizeof(HIObjectRef), NULL, (HIObjectRef *)&t_data -> view);
			SetEventParameter(p_event, kEventParamHIObjectInstance, typeVoidPtr, sizeof(HIRevolutionStackViewData *), &t_data);
			t_status = noErr;
		}
		break;
		
		case kEventHIObjectInitialize:
		{
			GetEventParameter(p_event, 'Stak', typeVoidPtr, NULL, sizeof(void *), NULL, &t_context -> stack);
			
			Rect t_bounds;
			t_bounds . left = 0;
			// MW-2011-09-12: [[ MacScroll ]] Make sure the top of the HIView takes into
			//   account the scroll.
			t_bounds . top = -t_context -> stack -> getscroll();
			t_bounds . right = t_context -> stack -> getrect() . width;
			t_bounds . bottom = t_context -> stack -> getrect() . height;
			SetControlBounds((ControlRef)t_context -> view, &t_bounds);
			
			t_status = noErr;
		}
		break;
		
		case kEventHIObjectDestruct:
		{
			delete t_context;
			t_status = noErr;
		}
		break;
		}
	break;
	
	case kEventClassControl:
		switch(t_event_kind)
		{
		case kEventControlInitialize:
		{
			t_status = noErr;
		}
		break;
		
		case kEventControlDraw:
		{
			CGContextRef t_graphics;
			GetEventParameter(p_event, kEventParamCGContextRef, typeCGContextRef, NULL, sizeof(CGContextRef), NULL, &t_graphics);
			
			RgnHandle t_dirty_rgn;
			GetEventParameter(p_event, kEventParamRgnHandle, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_dirty_rgn);

			if (t_context -> stack != NULL)
			{
				// Compute the clip region for players.
				RgnHandle t_clip_rgn, t_rect_rgn;
				t_clip_rgn = NULL;
				t_rect_rgn = NULL;
				for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer())
					if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering())
					{
						MCRectangle t_rect;
						Rect t_mac_rect;
						
						t_rect = t_player -> getactiverect();
						
						if (t_clip_rgn == NULL)
						{
							t_clip_rgn = NewRgn();
							CopyRgn((RgnHandle)t_dirty_rgn, t_clip_rgn);
							t_rect_rgn = NewRgn();
						}
						
						SetRect(&t_mac_rect, t_rect . x, t_rect . y, t_rect . x + t_rect . width, t_rect . y + t_rect . height);
						RectRgn(t_rect_rgn, &t_mac_rect);
						DiffRgn(t_clip_rgn, t_rect_rgn, t_clip_rgn);
						
					}
				
				// We don't need the rect rgn anymore.
				if (t_rect_rgn != NULL)
					DisposeRgn(t_rect_rgn);

				// If the clip region is non-nil, then apply it.
				if (t_clip_rgn != NULL)
				{
					// As we can't clip to empty path, if the region is empty, we set the context
					// to nil.
					if (!EmptyRgn(t_clip_rgn))
					{
						HIShapeRef t_shape;
						t_shape = HIShapeCreateWithQDRgn(t_clip_rgn);
						HIShapeReplacePathInCGContext(t_shape, t_graphics);
						CGContextClip(t_graphics);
						CFRelease(t_shape);
					}
					else
						t_graphics = nil;
					DisposeRgn(t_clip_rgn);
				}

				// If the graphics context is non-nil (i.e. we aren't completely occluded) then
				// draw something.
				if (t_graphics != nil)
				{
					// HIView gives us a context in top-left origin mode which isn't so good
					// for our CG rendering so, revert back to bottom-left.
					CGContextScaleCTM(t_graphics, 1.0, -1.0);
					CGContextTranslateCTM(t_graphics, 0.0, -t_context -> stack -> getcurcard() -> getrect() . height);
					
					// Save the context state
					CGContextSaveGState(t_graphics);
					
					// If we don't have an update pixmap, then use redrawwindow.
					if (s_update_pixmap == nil)
					{
						MCMacStackSurface t_surface(t_context -> stack, (MCRegionRef)t_dirty_rgn, t_graphics);
						t_context -> stack -> redrawwindow(&t_surface, (MCRegionRef)t_dirty_rgn);
					}
					else
					{
						int32_t t_height;
						t_height = t_context -> stack -> getcurcard() -> getrect() . height;
						
						MCRectangle t_rect;
						t_rect = MCRegionGetBoundingBox((MCRegionRef)t_dirty_rgn);
						
						CGRect t_area;
						t_area = CGRectMake(t_rect . x, t_height - (t_rect . y + t_rect . height), t_rect . width, t_rect . height);
						
						CGContextClearRect(t_graphics, t_area);

						void *t_bits;
						uint32_t t_stride;
						MCscreen -> lockpixmap(s_update_pixmap, t_bits, t_stride);
						MCMacRenderBitsToCG(t_graphics, t_area, t_bits, t_stride, t_context -> stack -> getwindowshape() != nil ? true : false);
						MCscreen -> unlockpixmap(s_update_pixmap, t_bits, t_stride);
					}

					// Restore the context state
					CGContextRestoreGState(t_graphics);
				}
				
				// MW-2011-11-23: [[ Bug ]] Force a redraw of the players on the stack
				//   after we've drawn the rest of the content. This ensures players
				//   which are just appearing don't disappear behind said content.
				for(MCPlayer *t_player = MCplayers; t_player != NULL; t_player = t_player -> getnextplayer())
					if (t_player -> isvisible() && t_player -> getcard() == t_context -> stack -> getcurcard() && !t_player -> isbuffering())
						MCDoAction((MovieController)t_player -> getMovieController(), mcActionDraw, t_context -> stack -> getqtwindow());
			}
			
			t_status = noErr;
		}
		break;
		
		case kEventControlHitTest:
		break;
		
		case kEventControlGetPartRegion:
		{
			ControlPartCode t_part;
			GetEventParameter(p_event, kEventParamControlPart, typeControlPartCode, NULL, sizeof(ControlPartCode), NULL, &t_part);
			
			RgnHandle t_region;
			GetEventParameter(p_event, kEventParamControlRegion, typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &t_region);
		}
		break;
		
		case kEventControlHiliteChanged:
		break;
		
		case kEventControlActivate:
		break;
		
		case kEventControlDeactivate:
		break;
		}
	break;
	}

	return t_status;
}