Hi,

I've taken the Audio Unit (AU) code for carbon overlay windows over a cocoa view and modified it for my purposes as a proof of concept test. I needed to make some changes to improve the AU code in my case (the left edge of the cocoa view can move because it is on the right side of a split view).

I have managed to remove the problems associated with the code except for one which is some tearing during redrawing in the carbon window when the cocoa window is being grown vertically and horizontally rapidly. Does anyone have some ideas as to how to remove the tearing.

I've included the relevant bits of the proof of concept code below which is part of a class overriding a NSView. There is one odd thing about the code, and that is I load a carbon window with the defined views from a nib file, I then create the overlay window, insert the views into the created overlay window, then dispose of the nib window, and then add the overlay window into the cocoa window group.

Thanks
Kevin

// -----------------------------------------------------------------------------
//      fitCarbonWindowToCocoaView
// -----------------------------------------------------------------------------

- (void)fitCarbonWindowToCocoaView
{
        NSRect cocoaViewFrame = [self frame];
        HIRect windowRect, cocoaWindowRect;
//      windowRect.size.width = cocoaViewFrame.size.width+0.5;
//      windowRect.size.height = cocoaViewFrame.size.height+0.5;
        windowRect.size.width = cocoaViewFrame.size.width;
        windowRect.size.height = cocoaViewFrame.size.height;
NSPoint position = [[[self window] contentView] convertPoint:[self frame].origin
                                                                                
                        fromView:self];
HIWindowGetBounds((WindowRef)[[self window] windowRef], kWindowContentRgn,
                                                kHICoordSpaceScreenPixel, 
&cocoaWindowRect);
        windowRect.origin.x = cocoaWindowRect.origin.x + position.x / 2;
windowRect.origin.y = (cocoaWindowRect.origin.y + cocoaWindowRect.size.height)
                                                        - (position.y + 
cocoaViewFrame.size.height);
HIWindowSetBounds(carbonWindow, kWindowContentRgn, kHICoordSpaceScreenPixel,
                                                                                    
                            &windowRect);
}

// -----------------------------------------------------------------------------
//      setFrame
// -----------------------------------------------------------------------------

- (void)setFrame:(NSRect)theFrame
{
        [super setFrame:theFrame];
        [self fitCarbonWindowToCocoaView];
}

// -----------------------------------------------------------------------------
//      createCarbonOverlayWindow
// -----------------------------------------------------------------------------

- (void)createCarbonOverlayWindow
{
        HIViewRef carbonWindowRootControl;
        HIViewRef tmpWindowRootControl;
        HIViewRef viewToSwitchWindow;
        OSStatus result1, result2;
        WindowRef tempWindow = MyCreateWindow();
        Rect bounds = {0,0,373,480};
        
        if (!tempWindow)
        {
NSLog(@"createCarbonOverlayWindow: Could not load carbon window from nib.");
                return;
        }
        HideWindow(tempWindow);
        result1 = CreateNewWindow(kOverlayWindowClass,
                 kWindowStandardHandlerAttribute | kWindowCompositingAttribute |
                 kWindowOpaqueForEventsAttribute, &bounds, &carbonWindow);
        
        SetThemeWindowBackground(carbonWindow, kThemeTextColorWhite, YES);
SetWindowActivationScope(carbonWindow, kWindowActivationScopeIndependent);
        if (result1)
        {
NSLog(@"createCarbonOverlayWindow: window creation failed result1= %d, result2=%d", result1, result2);
                return;
        }
        result1 = GetRootControl(carbonWindow, &carbonWindowRootControl);
        result2 = GetRootControl(tempWindow, &tmpWindowRootControl);
        if (result1 || result2)
NSLog(@"createCarbonOverlayWindow: Error getting root control result1=%d, result2=%d", result1, result2);
        viewToSwitchWindow = HIViewGetFirstSubview(tmpWindowRootControl);
        if (!viewToSwitchWindow)
        {
                NSLog(@"Failure to get subview");
                return;
        }
result1 = HIViewAddSubview(carbonWindowRootControl, viewToSwitchWindow);
        if (result1)
        {
                NSLog(@"createCarbonOverlayWindow: failed to add the hiview");
                return;
        }
//      PrintToConsoleCarbonHIViewTree(carbonWindowRootControl, 0);
        [self fitCarbonWindowToCocoaView];
        NSWindow *cocoaWindow = [self window];
        WindowRef cocoaWindowRef = (WindowRef)[cocoaWindow windowRef];
NSWindow *mixedWindow = [[NSWindow alloc] initWithWindowRef:carbonWindow];
        
        WindowGroupRef group;
        
        CreateWindowGroup(0, &group);
        SetWindowGroupParent(group, GetWindowGroup(cocoaWindowRef));
        ChangeWindowGroupAttributes(group,      kWindowGroupAttrLayerTogether |
                                                                                
kWindowGroupAttrSharedActivation |
                                                                                
kWindowGroupAttrHideOnCollapse, 0);
        SetWindowGroup(cocoaWindowRef, group);
        SetWindowGroup(carbonWindow, group);
        [cocoaWindow addChildWindow:mixedWindow ordered:NSWindowAbove];
        DisposeWindow(tempWindow);
        ShowWindow(carbonWindow);
}



_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to