API reference for ThisComponent in libreoffice calc Basic macros?

How do you find all available functions on ThisComponent in libreoffice calc basic macro editor? There doesn’t seem to be a stable autocompletion available and googling for “ThisComponent” doesn’t show any results in API docs. I assume that’s because it’s only an alias for another object, but I can’t figure out how to find it?

I’ve tried ThisComponent.DBG_properties, but the resulting dialog with long list of properties isn’t searchable or selectable to copy it into another text editor.

I assume that a lot of these problems are caused by my lack of experience with this development environment. If someone could please advise what would be best way to set it up I would really appreciate that. A tutorial would be ideal - I couldn’t find any resources so far.

I suggest you to use an Object Inspection Tool: XrayTool or MRI. Then you will able to list the existing properties and methods of the programming object, like the ThisComponent.

1 Like

thank you, I will try that.

I am using the XrayTool:
https://berma.pagesperso-orange.fr/index2.html

Sorry it may be stupid question, but I can’t seem to find it after 6 minutes of searching. I understand that XrayTool is builtin. How do you access it? Is it the same as Tools > Development Tools?

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:

1 Like

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

Select a name → F7

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