wizards/source/sfdocuments/SF_Calc.xba | 41 +++++++++++++++++++-------------- wizards/source/sfdocuments/script.xlb | 20 ++++++++-------- 2 files changed, 34 insertions(+), 27 deletions(-)
New commits: commit 50ef4d525676b007c5805e015ff8da6f4768cf12 Author: Jean-Pierre Ledure <[email protected]> AuthorDate: Sun Oct 5 17:39:06 2025 +0200 Commit: Jean-Pierre Ledure <[email protected]> CommitDate: Mon Oct 6 10:57:54 2025 +0200 ScriptForge (Calc) more accurate XRectangle The calc.XRectangle(range) property returns a com.sun.star.awt.Rectangle structure describing the position and size of the range given as a string. The function opens the opportunity to design popup menus in user scripts. The actual implementation has next improvements: 1) When the zoom in the sheet was different from 100%, there was a distorsion of the Height and Width values. Fixed now. 2) When some toolbars were visible, the computation of the Y dimension was under-evaluated. Fixed now. 3) The implementation does not use the deprecated XAccessibleXontext API anymore. The computations have been verified - the worksheet is not maximized - with varying row heights and column widths - with or without a formula bar - with or without toolbars - with different user interfaces The documentation does not need a revision. Change-Id: I06c9ec40d6cdaed74e5935950aaec9dec382b7fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191906 Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <[email protected]> diff --git a/wizards/source/sfdocuments/SF_Calc.xba b/wizards/source/sfdocuments/SF_Calc.xba index 69f17353e2ed..b0eeabf80e4e 100644 --- a/wizards/source/sfdocuments/SF_Calc.xba +++ b/wizards/source/sfdocuments/SF_Calc.xba @@ -5355,17 +5355,22 @@ End Function ' SFDocuments.SF_Calc._QuoteSheetName REM ----------------------------------------------------------------------------- Private Function _RangePosition(ByVal psRange As String) As Object ''' Determine a best guess of the coordinates (in pixels) of the given range +''' The resulting values (X, Y, Width, Height) are computed relatively to the +''' borders of the ContainerWindow, which starts below the title and menu bars. +''' It includes the tabbed bar and the toolbars. ''' Inspired (and enhanced) from https://forum.openoffice.org/en/forum/viewtopic.php?p=308693#p308693 ''' Args: ''' psRange: the range as a string ''' Returns: ''' a com.sun.star.awt.Rectangle UNO structure -Dim oRectOnScreen As New com.sun.star.awt.Rectangle ' Range position versus top-left screen corner (return value) -Dim oRect As New com.sun.star.awt.Rectangle ' Range position versus the A1 cell -Dim oLocation As Object ' com.sun.star.awt.Rectangle -Dim oController As Object ' Current controller +Dim oRectOnScreen As New com.sun.star.awt.Rectangle ' Range position versus top-left corner of the ContainerWindow (return value) +Dim oRect As New com.sun.star.awt.Rectangle ' Range position versus the A1 cell (row/column headers excluded), in 1/100mm +Dim dZoom As Double ' The actual zoom value +Dim oController As Object ' com.sun.star.frame.XController +Dim oContainerWindow As Object ' com.sun.star.awt.XWindow Dim oXRange As Object ' com.sun.star.Table.CellRange +Dim oSize As New com.sun.star.awt.Size ' Size of range in pixels Check: On Local Error GoTo Finally @@ -5373,31 +5378,33 @@ Check: Try: Set oController = _Component.CurrentController Set oXRange = _ParseAddress(psRange).XCellRange - ' Grab the window location on the screen - Select Case ScriptForge.SF_Platform._GetProductName(True) ' Get a sortable release number - Case <= 25.8 - Set oLocation = oController.ComponentWindow.AccessibleContext.LocationOnScreen - Case Else - Set oLocation = oController.ComponentWindow.getProperty("XAccessible").LocationOnScreen - End Select + ' Initialize the range area With oRect .X = oXRange.Position.X .Y = oXRange.Position.Y - .Width = oXRange.Size.Width + .Width = oXRange.Size.Width ' Size is in 1/100mm .Height = oXRange.Size.Height End With - 'Compute the rectangle in pixels (empirical computation) With oController + ' Convert dimensions in pixels + Set oSize = oController.ComponentWindow.convertSizeToPixel(oXRange.Size, com.sun.star.util.MeasureUnit.MM_100TH) + ' Initialize useful data for next computations + dZoom = CDbl(.ZoomValue / 100.0) + Set oContainerWindow = .Frame.ContainerWindow + + ' Compute the rectangle in pixels (empirical computations) oRectOnScreen.X = .VisibleAreaOnScreen.X _ + .VisibleAreaOnScreen.Width * (oRect.X - .VisibleArea.X) / .VisibleArea.Width _ - - oLocation.X + - oContainerWindow.Info.LeftInset _ + - oContainerWindow.PosSize.X oRectOnScreen.Y = .VisibleAreaOnScreen.Y _ + .VisibleAreaOnScreen.Height * (oRect.Y - .VisibleArea.Y) / .VisibleArea.Height _ - - oLocation.Y - oRectOnScreen.Width = oRect.Width * .VisibleAreaOnScreen.Width / .VisibleArea.Width - oRectOnScreen.Height = oRect.Height * .VisibleAreaOnScreen.Height / .VisibleArea.Height + - oContainerWindow.Info.TopInset _ + - oContainerWindow.PosSize.Y + oRectOnScreen.Width = CLng(oSize.Width * dZoom + 0.5) + oRectOnScreen.Height = CLng(oSize.Height * dZoom + 0.5) End With Finally: diff --git a/wizards/source/sfdocuments/script.xlb b/wizards/source/sfdocuments/script.xlb index 8188fd53bb1f..3d2264bd3f6d 100644 --- a/wizards/source/sfdocuments/script.xlb +++ b/wizards/source/sfdocuments/script.xlb @@ -1,15 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd"> <library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDocuments" library:readonly="false" library:passwordprotected="false"> - <library:element library:name="SF_Chart"/> - <library:element library:name="SF_FormDocument"/> - <library:element library:name="SF_FormControl"/> - <library:element library:name="SF_Base"/> - <library:element library:name="SF_Register"/> - <library:element library:name="SF_Writer"/> - <library:element library:name="SF_Calc"/> - <library:element library:name="SF_Document"/> - <library:element library:name="SF_DocumentListener"/> - <library:element library:name="SF_Form"/> <library:element library:name="__License"/> + <library:element library:name="SF_Form"/> + <library:element library:name="SF_DocumentListener"/> + <library:element library:name="SF_Document"/> + <library:element library:name="SF_Calc"/> + <library:element library:name="SF_Writer"/> + <library:element library:name="SF_Register"/> + <library:element library:name="SF_Base"/> + <library:element library:name="SF_FormControl"/> + <library:element library:name="SF_FormDocument"/> + <library:element library:name="SF_Chart"/> </library:library> \ No newline at end of file
