Hello,
Some time ago I wrote to the list about adding a juce component in a native window.
Looking at the code from juce_VstWrapper.cpp, now I can add and draw my component
in a native window (OSX for the moment) with the following code:
....
if(hostWindow != NULL)
{
SetAutomaticControlDragTrackingEnabledForWindow (hostWindow, true);
WindowAttributes attributes;
GetWindowAttributes (hostWindow, &attributes);
HIViewRef parentView = NULL;
if ((attributes & kWindowCompositingAttribute) != 0)
{
HIViewRef root = HIViewGetRoot (hostWindow);
HIViewFindByID(root, kHIViewWindowContentID, &parentView);
if (parentView == NULL)
parentView = root;
}
else
{
GetRootControl(hostWindow, (ControlRef*) &parentView);
if (parentView == NULL)
CreateRootControl(hostWindow, (ControlRef*) &parentView);
}
if(parentView != NULL)
{
self->juceComp = new JuceTestComponent(self);
self->juceComp->setOpaque(true);
self->juceComp->setBufferedToImage(true);
self->juceComp->setVisible(true);
self->juceComp->addToDesktop(ComponentPeer::windowIsResizable, (void *) parentView);
self->juceComp->setBounds(self->x_rect.left+2, self->x_rect.top+2,
self->x_box.b_rect.right-self->x_box.b_rect.left-4, self->x_box.b_rect.bottom-self->x_box.b_rect.top-4);
self->juceComp->setInterceptsMouseClicks(true, true);
}
}
…
The first problem was with mouse interaction: when the mouse pass over the component the application stop to listen mouse events
(like as the component takes and don’t release mouse events):
I solved this problem adding at the end of handleMouseEvent (in juce_mac_windowing.cpp)
the following line:
CallNextEventHandler(callRef, theEvent);
A second problem was to be able to click on and receive mouse notification in the component.
The only solution I founded was to change the following line in Component::getComponentAt (juce_Component.cpp)
from
if (flags.visibleFlag && x >= 0 && y >= 0 && x < compW_ && y < compH_ && hitTest (x, y))
to
if (flags.visibleFlag && x >= 0 && y >= 0 && x < compX_ + compW_ && y < compY_ + compH_ && hitTest (x, y))
Now my component receives mouseDown/ mouseMove/ mouseEnter/ mouseExtit but not mouseDrag and mouseUp (why?)
I need also that when the component receives a mouse event then pass it to the application and other listeners.
Do you have an idea if it is possible and how to do that?
Many thanks for any help and suggestion
Riccardo