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

Why page 20 something instead of 2.

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


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Thu Feb 23, 2006 6:35 pm    Post subject: Why page 20 something instead of 2. Reply with quote

In my 1st effort at the macro post here http://www.oooforum.org/forum/viewtopic.phtml?p=129055#129055
I used this code instead of that in the remarked section which works. Why doesn't this current code which ends several pages from the start when it should end up on the next page?
Code:
Sub StartInMiddleOfPage 'Horizonal & vertical center
oDoc = thisComponent
oVC = oDoc.CurrentController.getViewCursor
oVC.jumpToStartOfPage
pb = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
StartPage = oVC.getPage
Do While oVC.getPage = StartPage
 cnt = cnt + 1
 oDoc.Text.insertControlCharacter(oVC,pb,False)
 'oDoc.Text.insertControlCharacter(oVC,pb,true)
 'oVC.goDown(1,false)
Loop
Print "Start = " & StartPage & "  End = " & oVC.Page
End Sub
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Fri Feb 24, 2006 1:44 am    Post subject: Reply with quote

(Third and, hopefully, final post)
Finally, the following had the desired result.
Code:
'Begins as per code posted
StartPage = oVC.getPage
ThisPage = oVC.getPage
Do While ThisPage = StartPage
 cnt = cnt + 1 'Could not see what this does
 oDoc.Text.insertControlCharacter(oVC,pb,False)
 'oDoc.Text.insertControlCharacter(oVC,pb,true)
 'oVC.goDown(1,false)
 Wait 1 'I got the Wait period this low and stopped reducing it.
 ThisPage = oVC.getPage
Loop
'Continues as per previous code.

It looks as though Wait is necessary. A separate variable for this page seems to assist. Shocked
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Fri Feb 24, 2006 5:35 am    Post subject: Reply with quote

Hum, the only time I have every had to use a Wait statement before was if I had the dispatcher paste something into the document which caused a major reformat of the document.

Here all I'm doing is effectively tapping the Enter key yet on my slow computer it took 2-3 pages to react and on my fast one 20 some.
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Fri Feb 24, 2006 6:56 am    Post subject: Reply with quote

What I see is that if you add
Code:
oDoc.lockControllers

before your While loop and
Code:
oDoc.unlockControllers

after, the process is infinite, it creates new pages on your doc until ... (OOo crashes?, not tested)


Antoine.
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Fri Feb 24, 2006 6:59 am    Post subject: Reply with quote

I think I found it! Very Happy

At the end of your loop you must add
Code:
oDoc.refresh()


So your code is now:
Code:
Sub StartInMiddleOfPage 'Horizonal & vertical center
oDoc = thisComponent
oVC = oDoc.CurrentController.getViewCursor
oVC.jumpToStartOfPage
pb = com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK
StartPage = oVC.getPage
Do While oVC.getPage = StartPage
 cnt = cnt + 1
 oDoc.Text.insertControlCharacter(oVC,pb,False)
 oDoc.refresh()
Loop
Print "Start = " & StartPage & "  End = " & oVC.Page
End Sub


Antoine.
Back to top
View user's profile Send private message
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Sun Feb 26, 2006 11:09 am    Post subject: Reply with quote

Antoine,

That certainly works but the question is why.

The SDK documentation says that refresh, "refreshes the data of the object from the connected data source" and, of course, I have no data source connected to this document.

On the other hand the illusive reformat is suppose to, "reformats the contents of the document" and it does not work and I would think it should.

Are we just taking up some time much like Wait 1 or perhaps my commented code that does work by using 2 steps instead of 1?
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Sun Feb 26, 2006 5:53 pm    Post subject: Reply with quote

Quote:
on my slow computer it took 2-3 pages to react and on my fast one 20 some.

That seems to say it all. I cannot quite work out whether it's the same or the other side of the issue in this thread.
Quote:
Here all I'm doing is effectively tapping the Enter key

The thing is, you cannot tap as fast as the computer processes your code.
Back to top
View user's profile Send private message
Pitounet
OOo Enthusiast
OOo Enthusiast


Joined: 26 May 2005
Posts: 172
Location: Toulouse / France

PostPosted: Mon Feb 27, 2006 2:23 am    Post subject: Reply with quote

Hi,

I think a TextViewCursor is linked to the current display and the MVC (Model View Controller) architecture in OOo.
So I think you need to repaint this component to have its values refreshed.

A solution with Wait is more Dirty as in fact you just wait for the automatic refresh of your document (and TextViewCursor) instead of forcing it.

The main problem of the refresh is it can be slow as the TextDocument (maybe just what has changed?) will refresh itself.
The 2 steps solution is maybe the better choice if it always forces the refresh of the TextViewCursor object.

Antoine.
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