Obtain the textFrame containing a form starting from the reference object of the form only

Hello everyone. I wanted to ask if in the listener event of a button (mousereleased) it is possible to obtain in addition to the form it belongs to (this is not a problem) also the eventual textFrame that contains the form.
I am already able to do this by creating a table that relates the name of each textFrame to the name of the form it contains, or simply by using a portion of the form name to retrieve the name of the textFrame that contains it.
I was wondering if in the form properties there is one that allows you to define the belonging textFrame in a more general way or if there are alternative techniques to do so.
So far I have not found anything either in the form properties or solutions on the net
Thanks in departure for any suggestions

PS: I don’t also even understand if it is possible, known the textFrame, to define whether or not it contains a form
And this is strange because programmatically the form inserts itself into the textFrame as a textContent.

Write the frame name as “Additional Info” of your form control and then get the document’s frame by name.

sFrame = ev.Model.Tag
2 Likes

Inserting the name of the text frame (or a significant part of it) in the name of the form is the technique I had already pointed out in my post and it is the one I have been using ever since.
This information, string type, can also be inserted in other properties of the form (eg description, tooltip, title).
I did not know the tag property of the model, and this becomes the fifth choice
But the problem I posed is different: if with macro it is possible to insert a form in the textContent of a textFrame, why there is not a property of the textFrame that signals it?
And once a form has been inserted in a textFrame, why there is no kind of “anchor” associated with the parent textFrame?
How does writer know that a form is inserted in a textFrame and if a textFrame contains a form?

May be you can get the form control’s anchor paragraph. Or write some test if the control’s position and size is within the borders of a frame.
Hidden controls can be used as named configuration tags for entire forms.

sForm = ev.Source.Model.Parent.getByControl("FormName").HiddenValue

I’m running out of ideas.

1 Like

Thanks for both replies
Hiddenvalue is also a technique that I did not know, now I will try to deepen it
The important thing is that the problem I posed can be solved with a minimum of programming and / or organization of the information that can be associated with the form by saving string identifiers in the form
However, I wanted to point out the problem because it seemed to me an interesting topic to deal with, it seems curious to me that in the design of the forms a property that points directly to the container of the form has not been provided.
In fact, the parent property of a form points to the thisComponent.drawpage.forms collection, not to the container
In the dom model of javascript it is very easy to associate an object with any other
In UNO object hierarchy it is quite simple, very often, to introduce additional information in string form (in objects that support userdefinedattributes is very simple), while I could not find a way to insert in a UNO object references to other UNO objects using user properties, always if it exists
If it were possible to do so when inserting the form, I would insert it as the user property of the textFrame

what is form control’s anchor paragraph ?

All I know is that you can anchor a shape to a paragraph. I don’t know if you can get that anchor.

A graphic object constructed by the user (eg a rectangle) I think it is possible to anchor it to a character, paragraph, etc., but it is a problem that I have never studied
In the properties of the control, looking through everything that seems associated with a graphic container (a shape) I do not see for now anything that looks like an anchor to a paragraph, from which with the textFrames property I would solve the problem
I will continue to work on it

Frame_Form.odt (10.4 KB)
Like all text documents, the attached document has one DrawPage.
This DrawPage has 3 shapes. 1 shape supports com.sun.star.text.TextFrame, the other 2 shapes support com.sun.star.drawing.ControlShape
Each shape has an AnchorType and an Anchor object.

1 Like

You are right! Thank you!
I was persistent in looking for the answer in the form properties, when on the contrary every control form controls support references indirect to textFrame containing as anchor to paragraph of the textFrame (anchor property of the control if anchored to the paragraph) or directly to the textFrame (anchorFrame property of the control if anchored to the textFrame) .
The same anchorFrame property is also used in the case of nested textFrame to access the parent textFrame.
This can be seen well with the UNO object inspector from versions 7.0 onwards.
As for the initial problem I posed (deriving the textFrame container starting from the form) your moving the problem from form to controls answers my question and therefore constitutes a solution.
I will then try to encode it taking into account the possible different anchors to paragraphs and to textFrame.
I suspect that the choice not to support an anchor to the form is due to the fact that seem to me that the controls of a form can be included in different containers (eg textFrame).
Instead I have to understand if from the textFrame it is possible to determine the existence of controls inside it, for now I have not found anything