Force user widget inside screen extents?

All I would need is the actual size of a widget, so I can move it up and/or left, if the extents exceed the screen/viewport dimensions. But all related questions I could find here were unanswered…

I have these context-menu type of widgets that open up where the player clicks. They are just no use, if half of their content is cut off by the screen’s edges. What am I supposed to do here?

And I’ve got another question:

Originally I was planning on keeping the context menu open while RMB is being held. Options should have been selected with LMB. That’s not gonna work, because the GUI doesn’t seem to respond at all, while RMB is being held down.

So now I want the context menu to close either when the cursor has left its extents or when any click-event occurs outside of it. But I need functions for that which I can’t find…

The very least I would need is a function that tells me whether the cursor is currently on top of any widget or “directly exposed” to the 3D scene behind it.

By the way, is there a setting to have all right clicks automatically consumed by widgets like it is with left clicks?