[api-dev] problem of determining the location in the document

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[api-dev] problem of determining the location in the document

Zbigniew Szot
Hello

I have problem in finding relation between placement of a text section
and a text range .
Things are easy when section and range are placed in main document,
and get complicated when at least one of them is "nested" inside text table.
In this case they belong to differend XText object and
XTextRangeCompare can not be used (exception  would be thrown).
The only reasonable way to do this seems to be to compare of an anchor
of the nested XText with position of the section/range placed in main
document.

Problem is that I don't know which one is nested (posibly both of them
are nested).
My question is: how can I determin relation between two XText objects
which are part of one document.

Finding out that XText is nested and determination of its parent would
be very helpful.

I wouldn't like to "steal" text view cursor from user to figure it
out, and would love to find solution based on "model level" analize.


Best regards
Zbyszek

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Fernand Vanrie
  Zbigniew ,

a Viewcursor tell's you if you are in a TextTable, cell , TextFrame,
Textsection

the Viewcursor.position  is  the position in the document.

Witht this ellements you always know where you are in the document,  no ?

Say you have a Table2 in a cell of Table1

If you know the "start"  and dimensions of Table1 , then you can know if
Table2 is inside or outside Table1

Hope it helps

Fernand

> Hello
>
> I have problem in finding relation between placement of a text section
> and a text range .
> Things are easy when section and range are placed in main document,
> and get complicated when at least one of them is "nested" inside text table.
> In this case they belong to differend XText object and
> XTextRangeCompare can not be used (exception  would be thrown).
> The only reasonable way to do this seems to be to compare of an anchor
> of the nested XText with position of the section/range placed in main
> document.
>
> Problem is that I don't know which one is nested (posibly both of them
> are nested).
> My question is: how can I determin relation between two XText objects
> which are part of one document.
>
> Finding out that XText is nested and determination of its parent would
> be very helpful.
>
> I wouldn't like to "steal" text view cursor from user to figure it
> out, and would love to find solution based on "model level" analize.
>
>
> Best regards
> Zbyszek
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Zbigniew Szot
Thank you for taking interest in my problem.

TextViewCursor/Position is "Controller based" solution.
I would like to stick to "model based" one.

But you brought me an idea, which now seems obvious.
I can query  XText about supported services.
This will give me answer to the question if it is nested.
It's not direct answer, but it's good enough ( I hope).

thank you

Zbyszek

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Andrew Pitonyak


On 01/26/2011 01:53 PM, Zbigniew Szot wrote:
> Thank you for taking interest in my problem.
>
> TextViewCursor/Position is "Controller based" solution.
> I would like to stick to "model based" one.
>
> But you brought me an idea, which now seems obvious.
> I can query  XText about supported services.
> This will give me answer to the question if it is nested.
> It's not direct answer, but it's good enough ( I hope).
Please share any solutions that you find. I see, for example, that if I
take a text object from a cell, that this supports cell properties and
provides the cell name, but, it does not provide a link to the
containing text table. If I create a text cursor from a text object,
however, that provides access to the TextTable property.

 From the text table, you can grab the anchor. My testing stopped there
when I managed to crash OOo.

Off hand, I expect that you should be able to walk backwards until you
finally found the text object  for the document. I suppose that it
should be mostly obvious how to check for an intersecting text object as
it were (as in, where in the tree do they meet).

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Peter Eberlein-3
In reply to this post by Zbigniew Szot
Hi Zbigniew,
Am 26.01.2011 10:28, schrieb Zbigniew Szot:

> Hello
>
> I have problem in finding relation between placement of a text section
> and a text range .
> Things are easy when section and range are placed in main document,
> and get complicated when at least one of them is "nested" inside text table.
> In this case they belong to differend XText object and
> XTextRangeCompare can not be used (exception  would be thrown).
> The only reasonable way to do this seems to be to compare of an anchor
> of the nested XText with position of the section/range placed in main
> document.
>
> Problem is that I don't know which one is nested (posibly both of them
> are nested).
> My question is: how can I determin relation between two XText objects
> which are part of one document.
>
> Finding out that XText is nested and determination of its parent would
> be very helpful.
>
> I wouldn't like to "steal" text view cursor from user to figure it
> out, and would love to find solution based on "model level" analize.
>
Shure.
Maybe you must call the snippet recursively to find out the last parent:
a table can be in a frame, which can be in a section and so on.

if (object instanceof XTextRange) {
       
        XPropertySet xPropertySet = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, object);
        XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo();


        /*
        * check if xTextRange resides in sidea cell, a section or a frame
        */

        XTextSection xTextSection = null;
        XTextFrame xTextFrame = null;
        XCell xCell = null;
        // getPropertyValue gives either null  or adequate object

        if (xPropertySetInfo.hasPropertyByName("TextSection")) {
                xTextSection = (XTextSection)
UnoRuntime.queryInterface(XTextSection.class,
xPropertySet.getPropertyValue("TextSection"));
        }
        if (xPropertySetInfo.hasPropertyByName("TextFrame")) {
                xTextFrame = (XTextFrame) UnoRuntime.queryInterface(XTextFrame.class,
xPropertySet.getPropertyValue("TextFrame"));
        }
        if (xPropertySetInfo.hasPropertyByName("Cell")) {//or TextTable
                xCell = (XCell) UnoRuntime.queryInterface(XCell.class,
xPropertySet.getPropertyValue("Cell"));// or TextTable
        }
}

HTH

Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Zbigniew Szot
The problem is that it is  virtually impossible to determine parent of
an object nested in a table.

The tricky part is to determin Table to which XCell belongs to.
Becouse if we query for XTex of such a range, it will indicate that it
is nested "in itself".

let say we have section1 nested in table1.

step 1) ask textsection1 for its anchor  (so far so good).
step 2) ask "anchor"  for supported  service (or try to query
interface suported by specyfic services) and it says it is a talbe
cell( it is still ok..)
step 3) query cell for XText and grab XTextCursor (it returns a
cursor.. still ok)
step4) query cursor for its properties.
here I get  jammed

Curor property should tell me "who" is a parent of XText object.
What I (and propably Andrew) was expecting is that TextTable property
value  will point me to a table the cell belongs. Becouse this is what
normaly happends.

In this case however  text table property is not set. But TextSection
property is and it points to "textsection1" ( this is what i mean by
"indicate that it is nested in itself")

If we repeat this exercise with texttable2 instead of section1 nested
in texttable1  TextTable property will be set, and will be indicating
"textTable2"

So what I need to find out is : "how to get from cell to a table it belongs to".

Zbyszek

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Zbigniew Szot
In reply to this post by Peter Eberlein-3
Hi again

If i  apply my  " use case" (TextSection nested in textTable) to Your
snippet.  The TextTable property will not be set (will be null) and
the textsection property will be set to "nested" text section.

So its dead loop exacly as in my example.
I'm working bit too long, and started to have problem with
communicating in the clear way.
Thanks for taking interest  Piter.
I hope I've managed to explain where is the catch ;-)

Zbyszek

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [api-dev] problem of determining the location in the document

Andrew Pitonyak
On 01/28/2011 12:09 PM, Zbigniew Szot wrote:

> Hi again
>
> If i  apply my  " use case" (TextSection nested in textTable) to Your
> snippet.  The TextTable property will not be set (will be null) and
> the textsection property will be set to "nested" text section.
>
> So its dead loop exacly as in my example.
> I'm working bit too long, and started to have problem with
> communicating in the clear way.
> Thanks for taking interest  Piter.
> I hope I've managed to explain where is the catch ;-)
>
> Zbyszek
On a whim, I spent another couple hours looking at this and I must agree
that a solution, if it exists, is tricky at best. Part of the problem is
that if you have one object nested in another, then you will likely see
both objects.

I inserted a section in a section in a table in a section.

I can easily walk the parent sections, but, then this totally misses the
table. On the other hand, if I check for the table first, then I miss
the section.

If I walk a sections parents, then I must jump through hoops to find the
table (but I can do it). For example, section in a section in a table. I
can find the table, but, I must do something a wee bit odd (like create
a text cursor).

I might be able to find a solution by inspecting the text object in each
section, but, that would take way more time than I am willing to invest
(since it is not really my problem). This is part of my test code.



Sub TraceParent
   MsgBox
TraceParentFromRange(ThisComponent.CurrentCOntroller.ViewCursor, False)
End Sub

Function TraceParentFromRange(oRangeArg, ignoreTextSection As Boolean)
As String
   If IsNull(oRangeArg) OR IsEmpty(oRangeArg) Then
     TraceParentFromRange = ""
     Exit Function
   End If

   Dim oRange
   oRange = oRangeArg

   Dim oAnchor
   Dim s$
   Dim sParent$
   Dim oSection
   Dim localIgnoreTextSection As Boolean
   s = ""
   localIgnoreTextSection = False
   If NOT IsEmpty(oRange.TextSection) AND NOT ignoreTextSection Then
     localIgnoreTextSection = True
     oSection = oRange.TextSection
     Do While NOT IsEmpty(oSection) AND NOT IsNull(oSection)
       If Len(s) = 0 Then
         s = "TextSection: '" & oSection.getName() & "'"
       Else
         s = s & " Anchored in" & CHR$(10) & "TextSection: '" &
oSection.getName() & "'"
       End If
       oAnchor = oSection.getAnchor()
       oSection = oSection.getParentSection()
     Loop
     'Inspect oAnchor.getText().createTextCursorByRange(oAnchor)
     If
oAnchor.getText().SupportsService("com.sun.star.text.CellProperties") Then
       oAnchor = oAnchor.getText().createTextCursor()
     End If
   End If
   If NOT IsEmpty(oRange.Cell) Then
     If Len(s) > 0 Then
       s = s & CHR$(10)
     End If
     s = s & "Cell " & oRange.Cell.CellName & " in table " &
oRange.TextTable.getName()
     oAnchor =  oRange.TextTable.getAnchor()
   End If
   If s = "" Then
     TraceParentFromRange = "Root"
     Exit Function
   End If
   sParent$ = TraceParentFromRange(oAnchor, localIgnoreTextSection)
   If Len(sParent) = 0 Then
     TraceParentFromRange = s
   Else
     TraceParentFromRange = s & CHR$(10) & "Anchored in: " & sParent
   End If
End Function

--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info:  http://www.pitonyak.org/oo.php


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]