| View previous topic :: View next topic |
| Author |
Message |
Jeroen Guest
|
Posted: Tue Mar 23, 2004 5:01 am Post subject: How to recognize a section |
|
|
| 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


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Tue Mar 23, 2004 12:47 pm Post subject: |
|
|
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 |
|
 |
Jeroen Guest
|
Posted: Wed Mar 24, 2004 3:35 am Post subject: |
|
|
| 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
|
Posted: Wed Mar 24, 2004 6:23 am Post subject: |
|
|
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


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Wed Mar 24, 2004 8:56 am Post subject: |
|
|
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 |
|
 |
|