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

Need to know if its in preview mode

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


Joined: 14 Mar 2006
Posts: 30

PostPosted: Mon Mar 20, 2006 3:29 am    Post subject: Need to know if its in preview mode Reply with quote

hi,
how can i know if my document is in preview mode ?

i load a OOo doc (writer or calc) and i exceute the uno commands : .uno.PrintPreview
but i would like to know when the user quit this mode.
On Msoffice i used to do (i'm in delphi, by the way):
Code:
WdDoc.PrintPreview;      // call the preview mode
WdApp.Visible := True;   // the document is visible
WdDoc.ActiveWindow.View.Zoom.Percentage := 100;

// watch the boolean flag to know if the user is always in preview mode
while WdApp.PrintPreview do
begin
   Application.ProcessMessages;      // to handle refresh
   Sleep(250);                     // wait 0.250 millisecondes
end;


is there a boolean flag that would fit as 'PrintPreview' in MsOffice OLE ?
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Mon Mar 20, 2006 3:51 am    Post subject: Reply with quote

P.S : Any langage is welcome, it's not reserved to delphi's developpers Wink
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Tue Mar 21, 2006 3:40 am    Post subject: Reply with quote

Please is there anybody who knows ??
Even if the code is in macro, basic, java, c++...i need just a hint or way to search Idea
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Tue Mar 21, 2006 4:10 am    Post subject: Reply with quote

It's getting too late for me to go further. What I have found is that ThisComponent.CurrentController.Frame.LayoutManager.Elements include private:resource/toolbar/previewbar. I have not found what language might be used to test that. HTH.
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Tue Mar 21, 2006 4:20 am    Post subject: Reply with quote

thx, i'll go further Wink
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Tue Mar 21, 2006 7:39 am    Post subject: Reply with quote

thanks to noranthon, i found a way to look for : LayoutManager and its property Element
This property is a array of the elements contained in the OpenIffice container.
So when i launch an openoffice document I've got :
Element(0) : private:resource/toolbar/standardbar
Element(1) : private:resource/toolbar/textobjectbar
Element(2) : private:resource/toolbar/formdesign
Element(3) : private:resource/menubar/menubar
Element(4) : private:resource/statusbar/statusbar


these name can be get by the property of an element : ResourceURL ('Element(0).ResourceURL')

And when switch to previewmode I've go :
Element(0) : private:resource/toolbar/standardbar
Element(1) : private:resource/toolbar/previewobjectbar <-- here it is !!
Element(3) : private:resource/menubar/menubar
Element(4) : private:resource/statusbar/statusbar


I got it, to know if I'm in preview mode I have to check if this bar is visible :
Code:

OOoFrame := ThisComponent.getCurrentController.getFrame;
if OOoFrame.LayoutManager.isElementVisible('private:resource/toolbar/previewobjectbar') then
begin
....
end;


for more details on Elements proerties i used XRay tool
Have fun an thanks again to noranthon
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Tue Mar 21, 2006 7:10 pm    Post subject: Reply with quote

You're welcome. I looked only at Calc. I unfortunately had hit the wall when posting and thought of the isElementVisible test later. It also occurred to me that you could use something like this (for Calc):

Code:
On error goto InPreview : If oDoc.CurrentController.supportsService _
   ( "com.sun.star.sheet.SpreadsheetView" ) Then
Msgbox "In spreadsheet view mode" : End If : Exit Sub

InPreview:
Msgbox "In preview mode"
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Wed Mar 22, 2006 12:03 am    Post subject: Reply with quote

why not ?
but i need'nt to have a specific code in my software (I open writer or calc), i'd rather keep the first method.
Nevertheless, if someone got an idea to find the equivalent Msoffice code Very Happy :
Code:
while WdApp.PrintPreview do
begin
..
end;
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Wed Mar 22, 2006 12:40 am    Post subject: Reply with quote

I said things too fast !! Embarassed
the code :
Code:
OOoFrame := ThisComponent.getCurrentController.getFrame;
if OOoFrame.LayoutManager.isElementVisible('private:resource/toolbar/previewobjectbar') then
begin
....
end;

only works for writer !
Because for calc getFrame don't exist there is only the property Frame and the preview bar isn't called previewobjectbar but previewbar (Very Happy funny isn't it !)
so....for calc i use the code :
Code:
OOoFrame := ThisComponent.getCurrentController.Frame;
if OOoFrame.LayoutManager.isElementVisible('private:resource/toolbar/previewbar') then
begin
....
end;

Evil or Very Mad
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Wed Mar 22, 2006 2:56 am    Post subject: Reply with quote

getCurrentController and getFrame are available methods of the document and Controller, respectively, in Calc also. Likewise, Writer seems to have corresponding properties. The following is returning the correct result in Calc:
Code:
If oDoc.getCurrentController.getFrame.LayoutManager.isElementVisible _
   ( "private:resource/toolbar/previewbar" ) Then
Msgbox "In preview mode" : End If


It seems that you need only to establish different strings for Writer and Calc using the method you favour:
If oDoc.supportsService( "com.sun.star.text.TextDocument" ) Then sString = "...previewobjectbar"
Else [if oDoc.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) Then]
sString = "...previewbar" : End If [:End If]
If [NOT] oDoc....isElementVisible( sString ) Then
[code]
End If
A little pain. I find it strange that you are writing code to cover both Writer and Calc. Because of the differences between the two modules, I would not have thought that feasible.

If you want to use the other method, the corresponding service for Writer seems to be "com.sun.star.text.TextDocumentView". Shocked
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Wed Mar 22, 2006 3:17 am    Post subject: Reply with quote

You're right:
Quote:
getCurrentController and getFrame are available methods of the document and Controller, respectively, in Calc also. Likewise, Writer seems to have corresponding properties


And yes it's a little pain to manage both...but I had to, it works well with M$ and it "had to" works well with OOo ! Laughing

I tested your other method but I have an exception when i'm in preview mode and i call :
Code:
IsPreview := OoDocument.CurrentController.supportsService('com.sun.star.sheet.SpreadsheetView');

besides before entering preview mode it returns me True, so...
Back to top
View user's profile Send private message
noranthon
Super User
Super User


Joined: 07 Jul 2005
Posts: 3318

PostPosted: Wed Mar 22, 2006 3:37 am    Post subject: Reply with quote

Yes. That's why I had the On Error statement first. In Basic, On Error goto InPreview results in a call to the subroutine (inside the sub) called InPreview. The subroutine heading needs to be followed by a colon. I tested the method in both Preview and ordinary view. It's laid out like this:
Code:
Sub Whatever
On Error goto InPreview
If [document is in ordinary view mode] Then [marvellous things] : End If
Exit Sub ' to make sure InPreview is only executed when called by On Error.
InPreview:
[different marvellous things]
End Sub

Only useful to you, of course, if your language has something similar to On Error goto.
Back to top
View user's profile Send private message
humantool
General User
General User


Joined: 14 Mar 2006
Posts: 30

PostPosted: Wed Mar 22, 2006 3:46 am    Post subject: Reply with quote

Yes there is
Code:
try
...
except
...
end;

but I 'd rather do the first method finally... Very Happy

thanks
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