Ask Your Question

Access MediaDescriptor properties in loaded document

asked 2016-12-28 22:17:05 +0200

Durre gravatar image

Hello all,

I have the below sub assigned to a button on a switchboard .odt document for my database. When clicked, it opens a document called "AddTransaction.odt", which contains some forms.

Sub OpenAddTransDoc_

Globalscope.BasicLibraries.LoadLibrary( "MRILib" )

REM Define properties for MediaDescriptor service
Dim DocProperties(2) As New
DocProperties(0).Name = "ReadOnly"
DocProperties(0).Value = True
DocProperties(1).Name = "Referer"
DocProperties(1).Value = ThisComponent.URL
DocProperties(2).Name = "MacroExecutionMode"
DocProperties(2).Value = 4

Dim DocURL As String
DocURL = ConvertToURL("F:\Mattias Durnez\Documents HDD\Business\Finances_database\frontend\forms\AddTransaction.odt")

ThisDoc = StarDesktop.loadComponentFromURL(DocURL,"_default",0,DocProperties)

End Sub

After opening the "AddTransaction.odt" document, I inspect its model using MRI. When I retrieve the .Args property of the model with getArgs() I can see the values that I set for MacroExecutionMode (4) and ReadOnly (True). However, I can't see the URL that I specified for the Referer property. I failed to locate the Referer URL even after manually stepping through all properties/methods using MRI.

My question is: how can I access the Referer property, if even possible at all?

Also, when I add the following additional property ...

DocProperties(3).Name = "DocumentTitle"
DocProperties(3).Value = "NewTestTitle"

... it appears correctly in .Args as "DocumentTitle" with value "NewTestTitle" BUT the actual title displayed in the loaded document has NOT changed. In fact, .Args contains another property called "Title" which contains the title displayed by the document. This seems odd behaviour or am I missing something?

Many thanks for any help/insights!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-12-29 08:33:02 +0200

Ratslinger gravatar image

updated 2016-12-29 08:45:58 +0200

I always like to look into things I don't understand and this is one I hadn't looked at before, so take this with a grain of salt.

I found little on the subject anywhere. Service Reference and some sparse info in OOME (pdf here) on page 314 (document page 317). I also added the following code to yours after ThisDoc... and just before the MRI inspection:

    On Error Resume Next
Dim vArgs   'Media descriptor as an array of'
Dim s$      'Display string'
Dim i%      'Index variable'
REM Obtain the media descriptor. It turns out that this
REM can be represented as an array of PropertyValue services.
vArgs = ThisComponent.getArgs()
For i = 0 To UBound(vArgs)          'For each property'
    s = s & vArgs(i).Name & " = "       'Add the property name and an equals sign'
    s = s & vArgs(i).Value              'Obtaining the value may fail!'
    s = s & CHR$(10)                    'Add a new-line character'
MsgBox s,0, "Args"

Code is from OOME book. Display 1:

image description

Notice DocumentTitle. Although my code specified "NewTestTitle", "Form1" was the actual sending document AND when args was viewed in MRI it showed "NewTestTitle". Other items like "ReadOnly" set to "False" didn't do anything.

Based on the limited information available the most important item was from the noted OOME:

If you know how to open a document using the GUI, but are uncertain how the arguments must be set to load the document using loadComponentFromURL, then first load the document using the GUI, then inspect the document's media descriptor. Hint: look at FilterOptions.

From what I can see, arguments sent are only what is necessary to open the document. There seem to be a select few as optional (such as "ReadOnly" and "MacroExecutionMode") but I haven't tried them all.

This doesn't answer all your questions (nor mine) but hopefully a bit more understanding and maybe direction.

edit flag offensive delete link more


Thanks for your reply! I actually have the same code from OOME in my sub, but left it out to keep the question simple. FYI: you displayed the Args from the sending document with your code, because you referred to ThisComponent. To display the Args from the loaded document, you should replace it with ThisDoc. That's why setting the "DocumentTitle" or "ReadOnly" didn't 'seem' to do anything for you. Here is the output from my code: (didn't set readonly).

Durre gravatar imageDurre ( 2016-12-29 17:48:31 +0200 )edit

@Durre Thanks, I missed that. However upon changing, if "ReadOnly" is set to "True" it appears, "False" does not. And still can't figure "Referer" - nothing there no matter the entry. I'll continue as time permits, may even try the source code at some point.

Ratslinger gravatar imageRatslinger ( 2016-12-29 18:31:06 +0200 )edit

@Ratslinger Yes indeed, to me it feels like inconsistent behaviour. I can't for the life of me figure out why "Referer" does not appear in the list and how/why "DocumentTitle" is any different from "Title". You talk about trying the source code. Do you know where to find it/how to access it? All I've found so far is mediadescriptor.cxx but that wasn't too helpful. I can't seem to find anything with regards to the implementation of loadcomponentfromurl().

Durre gravatar imageDurre ( 2016-12-29 18:49:18 +0200 )edit

@Durre Downloaded & compiled using method found here. Be aware you can spend the better part of a day completing a first compiled version but it drastically improves after that. For an IDE I'm using KDevelop. Using Eclipse for other things. Until last year, hadn't used C++ for 15 years so still rusty at it.

Ratslinger gravatar imageRatslinger ( 2016-12-29 19:22:51 +0200 )edit

@Ratslinger Thanks a lot for the help, I appreciate it :-)

Durre gravatar imageDurre ( 2016-12-29 19:44:18 +0200 )edit

@Durre Just as I was about to go to the source, I discover this link from the LO MediaDescriptor page:click here. Of particular note is the second paragraph: If a media descriptor is used, only a few of the members are specified. The others assume default values. Strings default to empty strings in general and interface references default to empty references. For all other properties..... !

Ratslinger gravatar imageRatslinger ( 2016-12-30 00:48:42 +0200 )edit

@Durre Found code on-line so you don't have to download. See the following: MediaDescriptor & the Cross Reference but I see you already have the last one.

Ratslinger gravatar imageRatslinger ( 2016-12-30 02:00:23 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-12-28 22:17:05 +0200

Seen: 96 times

Last updated: Dec 29 '16