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

Problem with navigating to the very start of a document

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


Joined: 15 Jan 2004
Posts: 21
Location: Germany, Pliezhausen

PostPosted: Wed Feb 11, 2004 12:40 am    Post subject: Problem with navigating to the very start of a document Reply with quote

I need help on navigating to the the very beginning of a document if my text cursor is placed wthin a table cell. I tried the code below but this moves my cursor only to the begin of the table cell. Not to the begin of my document. I need this to select (mark) the entire document and to copy its contents to the clipboard.
Code:

sub Pos1
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:GoToStartOfDoc", "", 0, Array())

This works either (VB 6.0 code for OLE-Automation):
Code:

Public Sub GotoPos1()

Dim oCursor As Object
Set oCursor = objDocument.getCurrentController().getViewCursor
oCursor.gotoStart False

End Sub

What I could do is to execute my function serveral times till I'm lucky to get to the very beginning of my document (out of possibly nested tables). Is there a better and more elegant way to place the cursor at the very beginning?

Any help would greatley be appreciated
Back to top
View user's profile Send private message Visit poster's website
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Wed Feb 11, 2004 10:30 am    Post subject: Reply with quote

You've already got the document in variable objDocument.

So get a text cursor (not visible on screen), and position it where you want.

oText = objDocument.getText()
oCursor = oText.createTextCursor()
oCursor.gotoStart()

Now, get your view cursor...

Set oViewCursor = objDocument.getCurrentController().getViewCursor

Now make your view cursor go to the same place.

oViewCursor.gotoRange( oCursor, False )

Would that do what you want? This should work even if the view cursor is currently in a deeply nested table or frame. (I haven't tried this, just cobbled it together while typing and clicking through the API docs in another browser window.)
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
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