API reference for ThisComponent in libreoffice calc Basic macros?

The XrayTool is a “extension like” library. It has not a regular “extension format” (.oxt), but you can install it by usage the downloaded .odt file. After restart the LibreOffice you can use it “in situ” in your BASIC macro code:

xray ThisComponent

You must load the XrayTool befofe you use it: you can do it manually in the IDE by double click on the library name in the Object Catalog of the IDE, or by a macro code:

Sub LoadXray

	If (Not GlobalScope.BasicLibraries.isLibraryLoaded("XrayTool")) Then
		GlobalScope.BasicLibraries.LoadLibrary("XrayTool")
	End If
end sub
1 Like

Perfect, thank you very much for explaining. This is really helpful. Just to be sure, do you think that this link posted on the openoffice wiki website is still up to date? Extensions development basic - Apache OpenOffice Wiki

Or if it has source code available anywhere?

I’ve checked on https://extensions.libreoffice.org for “XrayTool”, but it returned 0 results.

XrayTool works for me with all of the permanently installed and portable LibreOffice versions. Yes, the XrayTool is not present in the extension page, because the distributed format is not a real “extension” (.oxt).

The last version is availabe on the linked site (the author: Bernard Marcelly’s site)

1 Like

I see, thank you for confirming. What concerns me slightly is that it is distributed as an .odt file. I’ve tried to inspect these files with binwalk before running, but it is not easy, they are composed of multiple formats. From security point of view it would be much better if they had source code available somewhere.

Disable the macro running and then open the .odt file. You can check the macro code manually, visually in the BASIC Libraries inside the file.

1 Like

Thank you again, that is a really good advice. I am just looking for a way to disable macros completely - in the Preferences > Options > LibreOffice > Security > Macro Security there is an option to disable all macros except for the ones in “trusted locations”. Do you know if there is a way to disable all macros completely (including those from “trusted locations”)?

Use the “Very high” option. If you have not set any “trusted location” then it means: all of the macros will be disabled.

1 Like

Oh I see, you are right, the second tab lists them and by default they are empty:

IMO, the Xray is really outdated and impossibly awkward to use compared to more advanced and convenient MRI. Also, there is a new ToolsDevelopment Tools (but unrelated to ThisComponent object, also documented in Basic Guide, where the existence of this special Basic-only, not API, feature is explained).

2 Likes

https://extensions.libreoffice.org/en/extensions/show/mri-uno-object-inspection-tool

… but note that that extension page lists an outdated version, and I couldn’t negotiate if MRI author wanted to take over that extension page ownership. So - please use the official plugin homepage.

2 Likes

Can I ask you a bit unrelated question, but would mean a ton to me - where do you find methods and properties of ThisComponent? I’ve been struggling for a day to find this out. Are they documented anywhere on the internet or do you have to use MRI? I’ve tried printing ThisComponent.DBG_properties, but there was no way to filter that long list in the pop-up window.

This is quite easy in the IDE: just use the “Watch” function, and expand ThisComponent there.

And for that:

  1. The link to the built-in Help that I provided above has relevant references: it discusses what ThisComponent is, and then links to API documentation for different services representing different document types. This already gives much of the supported methods, browsing the included interfaces.
  2. Indeed, you may use any of the introspection tools (Xray/MRI/Development Tools) to see the properties/methods of the current document.
  3. Let me describe a hard way below, but that is available without any additional tools.

If you have your UNO object in the Basic IDE’s “Watch” panel, expanding it, you would find a “Types” node somewhere close to the bottom of the tree.

This is where all the introspection information may be manually found. Yes, it may be an intimidating task, e.g. Writer shows 111 types there in its list (i.e., it implements 111 UNO interfaces), but I promised that it will be the hard way, didn’t I? :wink:

So every “type” (UNO interface) contains its list of methods (among other things); first three of them in each type are identical (queryInterface/acquire/release of XInterface); and the rest is the interesting part of this interface API.

Indeed, looking at all this reveals how awful the UI of the IDE is… :slight_smile:

2 Likes

Thank you very much, this is very helpful. Sorry, but could you please explain how this should be done? I’ve tried Watch ThisComponent, but got:
image

I can see a dialog at the bottom, which says “Watch”, so I hoped that it will appear there, but nothing happened:
image

1 Like

Select a name → F7

Or enter the name there manually → Enter (/me would think, one could try that)

1 Like

I see, but the listed variables didn’t show any properties? I’ve tried a sample script (shows contents of selected cells):

Sub Main
Set oRange = ThisComponent.CurrentSelection
    For i = 0 To oRange.Rows.getCount() - 1             
        For j = 0 To oRange.Columns.getCount() - 1
            Set oCell = oRange.getCellByPosition( j, i )
            Print oCell.String
        Next
    Next 
End Sub

but that’s all it showed (there were no context menus or options available to expand them):
image

1 Like

Oh yes, they would show anything only when the code runs. Put a breakpoint (even at the very start of a function), and run it.

2 Likes

ooooh now it makes sense :slight_smile:

Thank you very much, that changes the game completely :clap:

This reminds me of IDE from Rhino, a lot, it worked similarly (I’m sure a lot of built-in code editors are like that as well). Sorry, I could have thought about this sooner :person_facepalming:

1 Like

ThisComponent isn’t an API service or interface, but a predefined Basic variable.
What services it supports depends fundamentally on the case.

Please don’t try to get your single-student-programmimg-class here.

Sorry, I didn’t mean to spam the forum, but after a day of searching I was still stuck - the above recommendation to use the “Watch” panel is an absolute game changer and it allows you to investigate the object model much more independently, so it shouldn’t happen again.