You need check if the right click occurred in the area under a control, then popup if not.
Use GetCtrlAttribute on your control to get the ATTR_LEFT, ATTR_WIDTH, ATTR_TOP and ATTR_HEIGHT.
Create a callback function for your panel.
In the case EVENT_RIGHT_CLICK, check if the right click happened outside of that area. eventData1 is the click Y, eventData2 is the click X. If the click is not in the control area, do your popup.
See the attached project.