Hi, I’m using the PopupMenu service from ScriptForge lib. The documentation shows 2 calls to create it. Actually one of them crashes (the one that asks for a MouseEvent object), only "CreateScriptService(“SFWidgets.PopupMenu”,X,Y) works.
I get X,Y from either an EnhancedMouseEvent or a MouseEvent object. While these last two give X,Y referred to the top-left corner of the visible cell area, the popup service refers to the origin of a rectangle that is just the entire client area excluding the menubar. The effect is that the popup is drawn shifted away from the mouse pointer, always with same offset, no matter which cell you click. This indicates that the problem might be solved by applying a proper offset.
Is there any way to automatically calculate the offset between the 2 references?
Thanks
I don’t know a UNO interface that determines the coordinates of a sheet cell. Additional obstacles are to not interfere with the standard behaviours when (double-, right-) clicking on a cell, the potential multiple views and the potential multiple screens. All these make a manual computation of the coordinates and the insertion of a popup menu quite tricky.
My recommendation is to anchor such a popup menu to a custom toolbar and toolbar button, and to access the current selection on the scheet. Maybe a bit less sexy for the user, but easy to script. Look at the help page about the ToolbarButton service.
Ok, so for the moment I reduce the displacement effect by the added fixed offset. The actual position depends on the size of the toolbar, I guess it should be acceptable.
Thanks