Page 1 of 1

[Solved] Visually select text

Posted: Mon Mar 17, 2008 3:41 pm
by HWO
Hi I am very new at OOo programming

I'm using OpenOffice.org 2.3 SDK and OpenOffice.org 2.3 on windows xp with Java 1.6.0.

I want to visually select text (Like when you are holding SHIFT and pressing on another point) that is currently selected by XSentenceCursor to display to the user. Here is a code segmant of the selection process. Or any other implementation would work. I just need the user to press a button and the process should start and select the text and show it visually:

xSentenceCursor.gotoPreviousSentence(false);
boolean hasNextSentence = true;

while(hasNextSentence)
{
xSentenceCursor.gotoEndOfSentence(true);
textTextPos = xSentenceCursor.getString();
System.out.println("Checking: " + textTextPos + "\n");
hasNextSentence = xSentenceCursor.gotoNextSentence(false);
}

This wil be changed (maybe without the while or at least with a break.)
Could anybody plz help me?

Re: visually select text [Java]

Posted: Mon Mar 17, 2008 5:37 pm
by acknak
[Moved to Macros and UNO API; add "[Java]" to title]

Re: visually select text [Java]

Posted: Mon Mar 17, 2008 6:24 pm
by hol.sten
HWO wrote:Could anybody plz help me?
I think, I missed the point of the question. What exactly is your problem? What are you trying to achieve?

Re: visually select text [Java]

Posted: Tue Mar 18, 2008 8:23 am
by HWO
I'm sorry I thought it might be a little vague.

What I want to do in code is to show a selection of text. That is, I want to show to the user the text I've selected using the XSentenceCursor (or any XTextCursor for that matter) as if the user had selected it using his/her mouse or the shift key and arrows. The only function of this code is therefore to inicate to the user the text that is currently being used as input to a function. I've thought about changing the format of the text, but I don't really want to do that as it might impact the working of another module that I'm (trying) to develop.

Re: visually select text [Java]

Posted: Wed Mar 19, 2008 1:11 pm
by hol.sten
HWO wrote:What I want to do in code is to show a selection of text.
I think I've got the point now. But after some digging I think what you have to deal with is a tough task. What you cannot use is the well known text cursor, because all the selections you apply to a text cursor don't get visual feedback in the GUI. So what you should use is the so called view cursor. But all I have found are some perhaps not so promising links:
- Copying a Paragraph from one Writer Document to Another: http://user.services.openoffice.org/en/ ... 760#p13760
- How to copy and paste a text? [solved]: http://www.oooforum.org/forum/viewtopic ... viewcursor
- [Java] Problem enumerating document content: http://www.oooforum.org/forum/viewtopic ... viewcursor

Additionally I played around a little with a simple OOo Basic sample:

Code: Select all

Sub Cursors

rem ---------------------------------------------------------------------------
rem - Get access to the document
dim document as object
document = ThisComponent

rem ---------------------------------------------------------------------------
rem - Get the view cursor
viewCursor = document.getCurrentController().getViewCursor()
MsgBox(viewCursor.string)

viewCursor.gotoStart(false)
viewCursor.gotoEnd(true)
MsgBox(viewCursor.string)

rem ---------------------------------------------------------------------------
rem - Create a text cursor
textCursor = document.Text.createTextCursor
textCursor.gotoStart(false)
textCursor.gotoEndOfWord(true)
MsgBox(textCursor.string)

End Sub
The problem with both cursors is, that they don't implement the same interfaces:
viewCursor: XLineCursor, XViewCursor, XScreenCursor, XPageCursor, XTextViewCursor
textCursor: XParagraphCursor, XWordCursor, XSentenceCursor
So you cannot call the same functions/methods on both of them. The capabilities of each interface are documented in the IDL reference. Look for them for example in the IDL reference index for the letter X.

Re: visually select text [SOLVED]

Posted: Mon Mar 31, 2008 3:56 pm
by HWO
Thanks I shall try this :D