https://bugs.documentfoundation.org/show_bug.cgi?id=170796
--- Comment #8 from Roland Baudin <[email protected]> --- I did a bug report that was closed because it is a duplicate of this one. Here below is my bug report. In my TexMaths extension, I need to test if the visible cursor is within a text box or not. In Impress and Draw, this test uses the getAccessibleContext() function. This doesn't work anymore in LibreOffice 26.2 because the getAccessibleContext() is not found. Steps to Reproduce: In Impress or Draw, position the cursor within a tex box (or elsewhere) and run the following isCursorInTextBox macro: ' In Writer, Impress or Draw, test if the visible cursor is in a text box ' Can be used in Writer, Calc, Draw or Impress ' Based on the following posts on the Openoffice forum ' https://forum.openoffice.org/en/forum/viewtopic.php?t=101034 ' https://forum.openoffice.org/en/forum/viewtopic.php?t=81353 Sub isCursorInTextBox Dim oDoc As Variant Dim oController As Variant oDoc = ThisComponent oDocCtrl = oDoc.getCurrentController() ' Writer or Calc document (transferable is only supported in Writer or Calc) If oDoc.SupportsService("com.sun.star.text.TextDocument") Then Dim Transferable as Variant Transferable = oDocCtrl.getTransferable() Dim DataFlavor as new com.sun.star.datatransfer.DataFlavor DataFlavor.mimetype = "text/plain;charset=utf-16" If Not Transferable.isDataFlavorSupported(DataFlavor) Then msgbox "Writer => Cursor is NOT in a text box" else msgbox "Writer => Cursor is in a tex box" End If ' Other document type (Impress or Draw) ' Use a method based on the accessible context tree Else ' Get list of commands Dim oList as Variant GlobalScope.BasicLibraries.LoadLibrary("Tools") oList = GetRegistryKeyContent("org.openoffice.Office.UI.GenericCommands") ' Get localized context label of Insert Symbol command (remove tilde character if present) Dim contextLabel as String contextLabel = RemoveTilde( oList.getByName("UserInterface").getByName("Commands").getByName(".uno:InsertSymbol").ContextLabel ) ' Accessible context Dim oAccessibleContext as Variant oAccessibleContext = oDocCtrl.getFrame().getComponentWindow().getAccessibleContext().getAccessibleParent().getAccessibleContext() ' Recursive function that traverses the accessible context tree Dim inTextBox as Boolean inTextBox = MenuItemStatus(oAccessibleContext, contextLabel) If inTextBox = FALSE Then msgbox "Impress or Draw => Cursor is NOT in a text box" Else msgbox "Impress or Draw => Cursor is in a text box" End If End If End Sub ' In Writer, Impress or Draw, test if the visible cursor' Remove tilde characters in String Function RemoveTilde( ByVal str as String ) as String Dim result as String Dim c as String Dim i as Integer result = "" For i = 1 To Len( str ) c = Mid( str, i, 1 ) If c <> "~" Then result = result & c Next RemoveTilde = result End Function ' Recursive function used by IsInTextbox() Function MenuItemStatus(oAccessibleContext as Variant, contextLabel as String) as Boolean Dim oChild as Variant, oChildAccessibleContext as Variant Dim i as Integer, n as Integer ' Initialize result MenuItemStatus = TRUE ' Loop on childs n = oAccessibleContext.AccessibleChildCount For i = 0 to n - 1 ' Child and its accessible context On Error GoTo EndFunc oChild = oAccessibleContext.getAccessibleChild(i) oChildAccessibleContext = oChild.getAccessibleContext() ' Recurse if there is still childs If oChildAccessibleContext.AccessibleChildCount > 0 Then ' End recursion if menu item found If MenuItemStatus(oChildAccessibleContext, contextLabel) = FALSE Then MenuItemStatus = FALSE Exit For End If End If ' Restrict to menu items If oChildAccessibleContext.getAccessibleRole() = com.sun.star.accessibility.AccessibleRole.MENU_ITEM Then If oChildAccessibleContext.getAccessibleName() = contextLabel Then ' Check state Dim val as Integer val = oChildAccessibleContext.AccessibleStateSet And com.sun.star.accessibility.AccessibleStateType.ENABLED If val = 0 Then MenuItemStatus = FALSE Exit For End If End If End If Next i EndFunc: End Function Actual Results: The macro crashes with the message: Property or method not found: getAccessibleContext(). Expected Results: In LibreOffice pre 26.2 version, the macro should display a message that says if the visible cursor is within a text box or not. Reproducible: Always User Profile Reset: Yes Additional Info: The macro still works in Writer because the getAccessibleContext() function is not used in this case. The TexMaths extension needs to test if the visible cursor is within a text box or not. Indeed, when the cursor is in a text box, generated equations are text and not graphic images. So this test is crucial for TexMaths. TexMaths is used by many teachers and searchers. -- You are receiving this mail because: You are the assignee for the bug.
