Re: [api-dev] Newbie inserting text where the cursor is (java)

2006-11-13 Thread Tobias Krais
Hi Joan,

 But now, how I manage to write something in that position?

I use the method below to paste text on the position of a bookmark. You
will also find the answer to you question in the developers guide.

Greetings, Tobias

-%-
/**
 * Sets the Cursor to a bookmark position and replaces text on this
position.
 * If the bookmark contains more than at least one char, the text is
 * replaced. Otherwise the text is just inserted.
 *
 * @param bookmarkName Name of the Bookmark the cursor should jump to.
 * @param text The text that is going to be insertet on bookmark position
 */
public void replaceStringOnBookmark(String bookmarkName, String text) {
try {
// Get text document out the the general document
XTextDocument xTextDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class, xComponent);
if (xTextDocument == null) {
if (debug  0)
System.out.println(Document is not a Text Document. + 
 Aborting.);
return;
}

// Get bookmark interface from document
XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
UnoRuntime.queryInterface(XBookmarksSupplier.class, xComponent);

// Accessing the Bookmarks collection of the document
XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();

// Find the Bookmark specified in bookmarkName
Object bookmark = null;
try {
bookmark = xNamedBookmarks.getByName(bookmarkName);
} catch (Exception e) {
return;
}
if (bookmark == null) {
return;
}

// Query for XTextContext, the content of the Bookmark
XTextContent xBookmarkContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class, bookmark);

// Get the anchor of the bookmark (its XTextRange)
XTextRange xBookmarkRange = xBookmarkContent.getAnchor();

// Set string at bookmark position
xBookmarkRange.setString(text);
} catch (Exception e) {
return;
}
}

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [api-dev] Newbie inserting text where the cursor is (java)

2006-11-13 Thread Alamo Vallejo, Joan

Do you mean the TextDocuments.java in the guide? It works fine if you
want to go to the start, then jump some sentences and a few words and
then write. But I'd like to write where the cursor (the blinking one)
is, do you think it's possible? Or... Can anybody tell me where to look
for it?

(Imagine OO embedded into an applet and when you click a button, some
text is inserted where the cursor was)

Joan

-Mensaje original-
De: Tobias Krais [mailto:[EMAIL PROTECTED]
Enviado el: lunes, 13 de noviembre de 2006 13:23
Para: dev@api.openoffice.org
Asunto: Re: [api-dev] Newbie inserting text where the cursor is (java)

Hi Joan,

 But now, how I manage to write something in that position?

I use the method below to paste text on the position of a bookmark. You
will also find the answer to you question in the developers guide.

Greetings, Tobias

-%-
/**
 * Sets the Cursor to a bookmark position and replaces text on this
position.
 * If the bookmark contains more than at least one char, the text is
 * replaced. Otherwise the text is just inserted.
 *
 * @param bookmarkName Name of the Bookmark the cursor should jump to.
 * @param text The text that is going to be insertet on bookmark
position
 */
public void replaceStringOnBookmark(String bookmarkName, String text) {
try {
// Get text document out the the general document
XTextDocument xTextDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class,
xComponent);
if (xTextDocument == null) {
if (debug  0)
System.out.println(Document is not a Text
Document. +  Aborting.);
return;
}

// Get bookmark interface from document
XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
UnoRuntime.queryInterface(XBookmarksSupplier.class,
xComponent);

// Accessing the Bookmarks collection of the document
XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();

// Find the Bookmark specified in bookmarkName
Object bookmark = null;
try {
bookmark = xNamedBookmarks.getByName(bookmarkName);
} catch (Exception e) {
return;
}
if (bookmark == null) {
return;
}

// Query for XTextContext, the content of the Bookmark
XTextContent xBookmarkContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class,
bookmark);

// Get the anchor of the bookmark (its XTextRange)
XTextRange xBookmarkRange = xBookmarkContent.getAnchor();

// Set string at bookmark position
xBookmarkRange.setString(text);
} catch (Exception e) {
return;
}
}

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


This e-mail may contain confidential or privileged information. Any unauthorised
copying, use or distribution of this information is strictly prohibited.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [api-dev] Newbie inserting text where the cursor is (java)

2006-11-13 Thread Laurent Godard

Hi


Do you mean the TextDocuments.java in the guide? It works fine if you
want to go to the start, then jump some sentences and a few words and
then write. But I'd like to write where the cursor (the blinking one)
is, do you think it's possible? Or... Can anybody tell me where to look
for it?



instead of playing with a Cursor, play with the ViewCursor object
http://api.openoffice.org/docs/common/ref/com/sun/star/text/XTextViewCursorSupplier.html#getViewCursor

Laurent



--
Laurent Godard [EMAIL PROTECTED] - Ingénierie OpenOffice.org - 
http://www.indesko.com
Nuxeo Enterprise Content Management  http://www.nuxeo.com - 
http://www.nuxeo.org

Livre Programmation OpenOffice.org, Eyrolles 2004-2006

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: [api-dev] Newbie inserting text where the cursor is (java)

2006-11-13 Thread Alamo Vallejo, Joan

Thank you all for the help, finally I could do it... But now I'm facing
another problem: I want to insert an input field instead of text. I got
this far:

XMultiServiceFactory mxDocFactory = (XMultiServiceFactory)
UnoRuntime.queryInterface(XMultiServiceFactory.class,xTextDocument);

XTextField xInputUser = (XTextField) UnoRuntime.queryInterface
(XTextField.class, mxDocFactory.createInstance
(com.sun.star.text.TextField.InputUser ) );

xText.insertTextContent ( xViewCursor, xInputUser, false );

Ok, this seems to insert an empty input field. Do you know how to set a
default value or a text in the grey selection that is shown in the
document?

Thx in advance,
Joan

-Mensaje original-
De: Alamo Vallejo, Joan
Enviado el: lunes, 13 de noviembre de 2006 14:12
Para: dev@api.openoffice.org
Asunto: RE: [api-dev] Newbie inserting text where the cursor is (java)


Do you mean the TextDocuments.java in the guide? It works fine if you
want to go to the start, then jump some sentences and a few words and
then write. But I'd like to write where the cursor (the blinking one)
is, do you think it's possible? Or... Can anybody tell me where to look
for it?

(Imagine OO embedded into an applet and when you click a button, some
text is inserted where the cursor was)

Joan

-Mensaje original-
De: Tobias Krais [mailto:[EMAIL PROTECTED]

Enviado el: lunes, 13 de noviembre de 2006 13:23
Para: dev@api.openoffice.org
Asunto: Re: [api-dev] Newbie inserting text where the cursor is (java)

Hi Joan,

 But now, how I manage to write something in that position?

I use the method below to paste text on the position of a bookmark. You
will also find the answer to you question in the developers guide.

Greetings, Tobias

-%-
/**
 * Sets the Cursor to a bookmark position and replaces text on this
position.
 * If the bookmark contains more than at least one char, the text is
 * replaced. Otherwise the text is just inserted.
 *
 * @param bookmarkName Name of the Bookmark the cursor should jump to.
 * @param text The text that is going to be insertet on bookmark
position
 */
public void replaceStringOnBookmark(String bookmarkName, String text) {
try {
// Get text document out the the general document
XTextDocument xTextDocument = (XTextDocument)
UnoRuntime.queryInterface(XTextDocument.class,
xComponent);
if (xTextDocument == null) {
if (debug  0)
System.out.println(Document is not a Text
Document. +  Aborting.);
return;
}


// Get bookmark interface from document
XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)
UnoRuntime.queryInterface(XBookmarksSupplier.class,
xComponent);


// Accessing the Bookmarks collection of the document
XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();


// Find the Bookmark specified in bookmarkName
Object bookmark = null;
try {
bookmark = xNamedBookmarks.getByName(bookmarkName);
} catch (Exception e) {
return;
}
if (bookmark == null) {
return;
}


// Query for XTextContext, the content of the Bookmark
XTextContent xBookmarkContent = (XTextContent)
UnoRuntime.queryInterface(XTextContent.class,
bookmark);


// Get the anchor of the bookmark (its XTextRange)
XTextRange xBookmarkRange = xBookmarkContent.getAnchor();


// Set string at bookmark position
xBookmarkRange.setString(text);
} catch (Exception e) {
return;
}
}

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


This e-mail may contain confidential or privileged information. Any
unauthorised
copying, use or distribution of this information is strictly prohibited.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


This e-mail may contain confidential or privileged information. Any unauthorised
copying, use or distribution of this information is strictly prohibited.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]