Components in Native window

I’ve successfully added a Juce component to a native Mac window in another application (MaxMSP 4.6 actually) in a similar way to the VST/RTAS plugin code. i.e. something like:

juceWindowComp->setBounds(x, y + WINDOWTITLEBARHEIGHT, w, h);
HIViewRef hiRoot = HIViewGetRoot(theWindow);
juceWindowComp->addToDesktop(0, (void*)hiRoot);

This places the component (in which I have have just one slider) somewhere within the window. The component seems to get all the mousing activity, repaints itself etc. But it inhibits most of the other functionality of the window outside the bounds of the component. Mouse idling seems to work (though Max could be hacking that with a timer of course). Dragging doesn’t. I can add multiple instances to the same window and these all seem to work.

The window doesn’t appear to be compositing (checked the kWindowCompositingAttribute) so I assume that the HIViewFindByID / kHIViewWindowCotentID method won’t work (well I tried and the component doesn’t display itself). The GetRootControl / CreateRootControl method displays the component but doesn’t appear to receive mousing info (and still breaks the remainder of the window as when I add the component to the root).

Any obvious things I should try before giving up?

What would simplest, I guess, is if I can get the component to render into the window but not grab mouse info (and I’ll pass this in myself from the host).

oh, it’s a real can-of-worms, trying to do that kind of thing. There are all kinds of problems because both apps are trying to grab the same events, and almost certainly won’t pass them along nicely.

Is this a window that’s dedicated to the plugin UI, like for a VST? If so you might stand a chance, but if you’re trying to embed it in a window that’s full of other HIViews, then that could be very difficult indeed.

As temporary hack to figure out what’s going on I modified juce_mac_Windowing.cpp at line 2008:

EventTypeSpec viewEvents[] =
                { kEventClassHIObject, kEventHIObjectConstruct },
                { kEventClassHIObject, kEventHIObjectInitialize },
                { kEventClassHIObject, kEventHIObjectDestruct },
                { kEventClassControl, kEventControlInitialize },
                { kEventClassControl, kEventControlDraw }

This stops the view grabbing the mouse events and displays the component but as you say the mouse events now don’t get through the component and get picked up anywhere else. I tried moving the Z order of the views and of course I can then pick up mouse events … but can’t see the component!.

Perhaps I’ll try hacking it with a Timer … then give up since it’ll all be different, probably easier in Max 5.