OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to recognize a section

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Jeroen
Guest





PostPosted: Tue Mar 23, 2004 5:01 am    Post subject: How to recognize a section Reply with quote

Has someone got an idea of how to recognize if the current cursor-position is in a textsection? I use java...
Back to top
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Tue Mar 23, 2004 12:47 pm    Post subject: Reply with quote

Here is how I do it in BASIC

Code:
  Dim oSels
  Dim oSel
  oSels = ThisComponent.getCurrentSelection()
  oSel = oSels.getByIndex(0)
  If NOT IsEmpty(oSel.TextSection) Then Print "In a text Section"


Because you are using Java, you can not directly access the property, but this property is available through the property set info object...
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Jeroen
Guest





PostPosted: Wed Mar 24, 2004 3:35 am    Post subject: Reply with quote

mmm.... it doesn't seem to work that way in java. The method getCurrentSelection returns an object of type XInterface. But I can't seem to access the TextSection through the XInterface.
Back to top
Jeroen
Guest





PostPosted: Wed Mar 24, 2004 6:23 am    Post subject: Reply with quote

The solution to the problem is this:

Code:

            loXTextCursor = this.getTextDocument().getText().createTextCursor();
            loXTextCursor.gotoRange(this.queryCurrentPosition(), false);

            loXPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, loXTextCursor);

            loXTextSection = (XTextSection)((Any)loXPropertySet.getPropertyValue("TextSection")).getObject();

            if (loXTextSection != null)
            {
                System.out.println("Cursor position within section...");
            }
Back to top
pitonyak
Administrator
Administrator


Joined: 09 Mar 2004
Posts: 3655
Location: Columbus, Ohio, USA

PostPosted: Wed Mar 24, 2004 8:56 am    Post subject: Reply with quote

Excellent! I knew that you had to do that, but I did not know how to do it in Java. This should become easier with OpenOffice.org 2.0 because they will support multiple inheritence.
_________________
--
Andrew Pitonyak
http://www.pitonyak.org/oo.php
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group