| View previous topic :: View next topic |
| Author |
Message |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Thu Feb 23, 2006 6:35 pm Post subject: Why page 20 something instead of 2. |
|
|
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 |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Fri Feb 24, 2006 1:44 am Post subject: |
|
|
(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.  |
|
| Back to top |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Fri Feb 24, 2006 5:35 am Post subject: |
|
|
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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Fri Feb 24, 2006 6:56 am Post subject: |
|
|
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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Fri Feb 24, 2006 6:59 am Post subject: |
|
|
I think I found it!
At the end of your loop you must add
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 |
|
 |
JohnV Administrator

Joined: 07 Mar 2003 Posts: 8979 Location: Lexinton, Kentucky, USA
|
Posted: Sun Feb 26, 2006 11:09 am Post subject: |
|
|
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 |
|
 |
noranthon Super User

Joined: 07 Jul 2005 Posts: 3318
|
Posted: Sun Feb 26, 2006 5:53 pm Post subject: |
|
|
| 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 |
|
 |
Pitounet OOo Enthusiast


Joined: 26 May 2005 Posts: 172 Location: Toulouse / France
|
Posted: Mon Feb 27, 2006 2:23 am Post subject: |
|
|
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 |
|
 |
|