| View previous topic :: View next topic |
| Author |
Message |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Thu Mar 05, 2009 3:30 am Post subject: Non-modal dialog in OpenOffice |
|
|
I need a non-modal dialog with progressbar for my Writer Javascript macros because it's slowly processes long texts.
I've "translated" SDK java dialog creation sample from Java to Javascript and then put a progressbar into the dialog. I just can't find the way to make it non-modal.
| Code: |
oContext = XSCRIPTCONTEXT.getComponentContext();
oCompServMgr = oContext.getServiceManager();
oDialogModel = oCompServMgr.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", oContext );
oDialServMgr = UnoRuntime.queryInterface(XMultiServiceFactory, oDialogModel );
oDialogProps = UnoRuntime.queryInterface( XPropertySet, oDialogModel );
oDialogProps.setPropertyValue( "PositionX", new java.lang.Integer( 100 ) );
oDialogProps.setPropertyValue( "PositionY", new java.lang.Integer( 100 ) );
oDialogProps.setPropertyValue( "Width", new java.lang.Integer( 100 ) );
oDialogProps.setPropertyValue( "Height", new java.lang.Integer( 20 ) );
oDialogProps.setPropertyValue( "Title", "Runtime Dialog Demo" );
oProgressBarModel = oDialServMgr.createInstance( "com.sun.star.awt.UnoControlProgressBarModel" );
oProgressBarProps = UnoRuntime.queryInterface( XPropertySet, oProgressBarModel );
oProgressBarProps.setPropertyValue( "PositionX", new java.lang.Integer( 0 ) );
oProgressBarProps.setPropertyValue( "PositionY", new java.lang.Integer( 0 ) );
oProgressBarProps.setPropertyValue( "Width", new java.lang.Integer( 100 ) );
oProgressBarProps.setPropertyValue( "Height", new java.lang.Integer( 20 ) );
oProgressBarProps.setPropertyValue( "ProgressValueMin", new java.lang.Integer( 0 ) );
oProgressBarProps.setPropertyValue( "ProgressValueMax", new java.lang.Integer( 100 ) );
oProgressBarProps.setPropertyValue( "ProgressValue", new java.lang.Integer( ProgressValue ) );
// insert the controls models into the dialog model
oDialNameContainer = UnoRuntime.queryInterface( XNameContainer, oDialogModel );
oDialNameContainer.insertByName( "myProgressBarName", oProgressBarModel );
// create the dialog control and set the model
oDialog = oCompServMgr.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", oContext );
oControlModel = UnoRuntime.queryInterface( XControlModel, oDialogModel );
oControl = UnoRuntime.queryInterface( XControl, oDialog );
oControl.setModel( oControlModel );
// create a peer
oToolkit = oCompServMgr.createInstanceWithContext( "com.sun.star.awt.Toolkit", oContext );
oXToolkit = UnoRuntime.queryInterface( XToolkit, oToolkit );
oXWindow = UnoRuntime.queryInterface( XWindow, oControl );
oXWindow.setVisible( true );
oControl.createPeer( oXToolkit, null );
// execute it
xDialog = UnoRuntime.queryInterface( XDialog, oDialog );
xDialog.execute();
// dispose the dialog
oXComponent = UnoRuntime.queryInterface( XComponent, oDialog );
oXComponent.dispose();
|
When I remove xDialog.execute() and oXComponent.dispose() the dialog window is being displayed, yet progress is not updated.
SDK has a suggestion to use UNO Forms, but the samples are C++ and OOO Basic and are very incomplete, I can't find out how to build UNO Form in Javascript (or, at least in Java). |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Sat Mar 07, 2009 11:02 am Post subject: |
|
|
Hi,
if you use the standard UnoControl... Services, you do not need to create a peer window.
The following works in OO Basic. Please note that you cannot use the "X" in the frame's upper right corner to close the window. You have to put oDialog into a global variable and later close it by code.
Good luck,
ms777
| Code: | Sub Main
oDialogModel = createUnoService( "com.sun.star.awt.UnoControlDialogModel")
oDialogModel.PositionX = 100
oDialogModel.PositionY = 100
oDialogModel.Width = 100
oDialogModel.Height = 20
oDialogModel.Title = "Runtime Dialog Demo"
'oDialogModel.DesktopAsParent = true
oProgressBarModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlProgressBarModel" )
oProgressBarModel.PositionX = 0
oProgressBarModel.PositionY = 0
oProgressBarModel.Width = 120
oProgressBarModel.Height = 20
oProgressBarModel.ProgressValueMin = 0
oProgressBarModel.ProgressValueMax = 100
oProgressBarModel.ProgressValue = 50
' insert the controls models into the dialog model
oDialogModel.insertByName( "myProgressBarName", oProgressBarModel )
' create the dialog control and set the model
oDialog = createUnoService( "com.sun.star.awt.UnoControlDialog")
oDialog.setModel( oDialogModel )
oDialog.setVisible( true )
for k=0 to 100 step 20
oProgressBarModel.ProgressValue = k
wait(1000)
next k
' dispose the dialog
oDialog.dispose()
End Sub |
|
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Sat Mar 07, 2009 12:02 pm Post subject: |
|
|
... if you want to retain the functionality of the X to close your progress bar window, you can generate the container window by hand and insert the progressbar (not the complete dialog) into it. This is somewhat more complex.
Good luck,
ms777
| Code: | Sub Main
oDialogModel = createUnoService( "com.sun.star.awt.UnoControlDialogModel")
oProgressBarModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlProgressBarModel" )
oProgressBarModel.PositionX = 0
oProgressBarModel.PositionY = 0
oProgressBarModel.Width = 60
oProgressBarModel.Height = 20
oProgressBarModel.ProgressValueMin = 0
oProgressBarModel.ProgressValueMax = 100
oProgressBarModel.ProgressValue = 0
' insert the controls models into the dialog model
oDialogModel.insertByName( "myProgressBarName", oProgressBarModel )
' create the dialog control and set the model
oDialog = createUnoService( "com.sun.star.awt.UnoControlDialog")
oDialog.setModel( oDialogModel )
oProgressBarControl = oDialog.Controls(0)
'now generate the container Window
oToolkit = createUnoService("com.sun.star.awt.Toolkit")
Dim rBounds as new com.sun.star.awt.Rectangle
rBounds.X = 0
rBounds.Y = 0
rBounds.width = oProgressBarControl.PosSize.Width
rBounds.height = oProgressBarControl.PosSize.Height
Dim wd as new com.sun.star.awt.WindowDescriptor
wd.Type = com.sun.star.awt.WindowClass.TOP
wd.Bounds = rBounds
with com.sun.star.awt.WindowAttribute
wd.WindowAttributes = .BORDER + .MOVEABLE + .SIZEABLE + .CLOSEABLE
end with
wd.WindowServiceName = "dialog"
oContWin = oToolkit.createWindow(wd)
'now put it into a frame. This is to be able to close it.
oFrame = createUnoService("com.sun.star.frame.Frame")
oFrame.initialize(oContWin)
StarDesktop.Frames.append(oFrame)
oFrame.Name = "ms777Frame"
oFrame.Title = "ms7Title"
'last but not least let the progress bar show itself with the container window as the parent
oProgressBarControl.createPeer(oToolkit, oContWin)
oContWin.setVisible(True)
for k=0 to 100 step 20
oProgressBarModel.ProgressValue = k
wait(500)
next k
' the following lines can be called from everywhere to close the progress frame. No global var needed.
for k= StarDesktop.Frames.Count-1 to 0 step -1
oF = StarDesktop.Frames.getByIndex(k)
if oF.Name = "ms777Frame" then
oF.dispose
endif
next k
End Sub |
|
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Tue Mar 10, 2009 12:30 am Post subject: |
|
|
First of all, many thanks for the answers!
Of course I was unpatient enough and didn't wait for long for the answer. I've found an OOO Basic example very similar to ms777 posted and through try, trial and errors converted it into javascript by myself. But really thanks anyway.
Searching this forum is not easy. Even with Google site:oooforum.org I wasn't able to find the link posted by SergeM, which would save some of my hours.
My biggest question - why seem to nobody write macros in Javascript? Rhino debugger really helped me few times already (type match, class browsing).. Built-in into Office, so you won't need to install Eclipse or some another environment. I'd use Python, but it has no debugger!
Now I've encountered a bigger problem - when I run the javascript macro from debugger the non-modal window is painted (displyaed) correctly - with background. But, when I run the macro from Writer toolbar button, only progressbar is updated, the window is completely transparent I even tried to place a large FixedText under ProgressBar with background and dynamically changable text. It's not being shown anyway. How can I make window refresh (paint, display non transparent) during my macro operation?
Creation, definition:
| Code: |
oDoc = UnoRuntime.queryInterface( XModel, XSCRIPTCONTEXT.getInvocationContext() );
if ( !oDoc )
oDoc = XSCRIPTCONTEXT.getDocument();
xDocAsFactory = UnoRuntime.queryInterface( XMultiServiceFactory, oDoc );
oContext = XSCRIPTCONTEXT.getComponentContext();
oCompServMgr = oContext.getServiceManager();
oController = oDoc.getCurrentController();
oFrame = oController.getFrame();
oContainerWindow = oFrame.getContainerWindow();
oContWindowPeer = UnoRuntime.queryInterface( XWindowPeer, oContainerWindow );
oToolkit = oCompServMgr.createInstanceWithContext( "com.sun.star.awt.Toolkit", oContext );
xToolkit = UnoRuntime.queryInterface( XToolkit, oToolkit );
aWinDesc = new WindowDescriptor();
aWinDesc.WindowServiceName = "window";
aWinDesc.ParentIndex = -1;
aWinDesc.Parent = oContWindowPeer;
aWinDesc.Bounds = new Rectangle( 0, 0, 210, 50 );
aWinDesc.WindowAttributes = 0;
oSubPeer = xToolkit.createWindow( aWinDesc );
oSubWindow = UnoRuntime.queryInterface( XWindow, oSubPeer );
oFrameTask = oCompServMgr.createInstanceWithContext( "com.sun.star.frame.Frame", oContext );
oSubFrame = UnoRuntime.queryInterface( XFrame, oFrameTask );
oSubFrame.initialize( oSubWindow );
xDesktop = oCompServMgr.createInstanceWithContext( "com.sun.star.frame.Desktop", oContext );
xTreeRoot = UnoRuntime.queryInterface( XFramesSupplier, xDesktop );
xChildContainer = xTreeRoot.getFrames();
xChildContainer.append( oSubFrame );
oContainer = oCompServMgr.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", oContext );
oContainerModel = oCompServMgr.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", oContext );
oContainerServMgr = UnoRuntime.queryInterface(XMultiServiceFactory, oContainerModel );
oContainerModelProps = UnoRuntime.queryInterface( XPropertySet, oContainerModel );
PropInfo = oContainerModelProps.getPropertySetInfo();
Props = PropInfo.getProperties();
Prop1 = oContainerModelProps.getPropertyValue( "DefaultControl" );
oContainerModelProps.setPropertyValue( "Closeable", false );
oContainerModelProps.setPropertyValue( "Moveable", false );
oContainerModelProps.setPropertyValue( "Sizeable", false );
oContainerModelProps.setPropertyValue( "BackgroundColor", new java.lang.Integer( 0xEEEEEE ) );
oContainerModelProps.setPropertyValue( "PositionX", new java.lang.Integer( 0 ) );
oContainerModelProps.setPropertyValue( "PositionY", new java.lang.Integer( 0 ) );
oContainerModelProps.setPropertyValue( "Width", new java.lang.Integer( 210 ) );
oContainerModelProps.setPropertyValue( "Height", new java.lang.Integer( 50 ) );
oContainerModelProps.setPropertyValue( "Title", "Свежий взгляд" );
oContainerControlModel = UnoRuntime.queryInterface( XControlModel, oContainerModel );
oContainerControl = UnoRuntime.queryInterface( XControl, oContainer );
oContainerControl.setModel( oContainerControlModel );
oSubWindow.setPosSize( 0, 0, 210, 50, 0 );
oContainerControl.createPeer( xToolkit, oSubPeer );
oProgressBarModel = oContainerServMgr.createInstance( "com.sun.star.awt.UnoControlProgressBarModel" );
oProgressBarProps = UnoRuntime.queryInterface( XPropertySet, oProgressBarModel );
oProgressBarProps.setPropertyValue( "PositionX", new java.lang.Integer( 5 ) );
oProgressBarProps.setPropertyValue( "PositionY", new java.lang.Integer( 25 ) );
oProgressBarProps.setPropertyValue( "Width", new java.lang.Integer( 200 ) );
oProgressBarProps.setPropertyValue( "Height", new java.lang.Integer( 20 ) );
oProgressBarProps.setPropertyValue( "ProgressValueMin", new java.lang.Integer( 0 ) );
oProgressBarProps.setPropertyValue( "ProgressValueMax", new java.lang.Integer( 200 ) );
oProgressBarProps.setPropertyValue( "ProgressValue", new java.lang.Integer( ProgressValue ) );
oLabelModel = oContainerServMgr.createInstance( "com.sun.star.awt.UnoControlFixedTextModel" );
oLabelProps = UnoRuntime.queryInterface( XPropertySet, oLabelModel );
PropInfo = oLabelProps.getPropertySetInfo();
Props = PropInfo.getProperties();
oLabelProps.setPropertyValue( "BackgroundColor", new java.lang.Integer( 0xEEEEEE ) );
oLabelProps.setPropertyValue( "PositionX", new java.lang.Integer( 5 ) );
oLabelProps.setPropertyValue( "PositionY", new java.lang.Integer( 5 ) );
oLabelProps.setPropertyValue( "Width", new java.lang.Integer( 205 ) );
oLabelProps.setPropertyValue( "Height", new java.lang.Integer( 45 ) );
oLabelProps.setPropertyValue( "Name", "myLabelName" );
oLabelProps.setPropertyValue( "Label", "myLabelName myLabelName myLabelName myLabelName myLabelName myLabelName " );
// insert the controls models into the dialog model
//oContainer.addControl( "progressbar", oProgressBar );
oNameContainer = UnoRuntime.queryInterface( XNameContainer, oContainerModel );
//oNameContainer.insertByName( "ProgressBar1", oProgressBarModel );
oNameContainer.insertByName( "myLabelName", oLabelModel );
|
Update code (during the script run):
| Code: |
ProgressValue += 8;
oProgressBarProps.setPropertyValue( "ProgressValue", new java.lang.Integer( ProgressValue ) );
oLabelProps.setPropertyValue( "Label", ProgressValue + "" );
oLabelProps.setPropertyValue( "BackgroundColor", new java.lang.Integer( 0xEFEFEF ) );
|
progressbar is displayed without background, so it looks really ugly  |
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Tue Mar 10, 2009 12:44 am Post subject: |
|
|
Now, I've tried to invalidate window to redraw it, even both my and parent window
| Code: |
ProgressValue += 8;
oProgressBarProps.setPropertyValue( "ProgressValue", new java.lang.Integer( ProgressValue ) );
oLabelProps.setPropertyValue( "Label", ProgressValue + "" );
oLabelProps.setPropertyValue( "BackgroundColor", new java.lang.Integer( 0xEFEFEF ) );
oContWindowPeer.invalidate( 1 );
oSubPeer.invalidate( 1 );
|
No luck! The parent Writer window "re-flashes" with it's buttons and toolbars by my window displays only transparent progressbar
By the way, java code examples use constans in XWindowPeer::invalidate() and WindowDescriptor::WindowAttributes() but I can't find their definition for JavaScript
Would the window not being correctly redrawn because I've guessed wrong parameter calls? |
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Tue Mar 10, 2009 2:28 am Post subject: |
|
|
With the following progress update code everything is flashing, yet the same progressbar without any colored background
| Code: |
oSubWindow.setVisible( false );
ProgressValue += 8;
oProgressBarProps.setPropertyValue( "ProgressValue", new java.lang.Integer( ProgressValue ) );
oLabelProps.setPropertyValue( "Label", ProgressValue + "" );
oLabelProps.setPropertyValue( "BackgroundColor", new java.lang.Integer( 0xEFEFEF ) );
oSubPeer.setBackground( new java.lang.Integer( 0xEFEFEF ) );
oContWindowPeer.invalidate( 8 );
oSubPeer.invalidate( 8 );
oSubWindow.setVisible( true );
|
I've found out that invalidate( 8 ) should cause immediare re-draw while searching this forum.
I wonder if some messaging (winapi-like) is needed? But I've thought that OOo macros is much higher level. Very strange.... |
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Tue Mar 10, 2009 2:54 am Post subject: |
|
|
Not even this one
| Code: |
oSubPeer.invalidate( 8 );
oSubWindow.setVisible( false );
oContainerModelProps.setPropertyValue( "Enabled", false );
oLabelProps.setPropertyValue( "Enabled", false );
oContainerModelProps.setPropertyValue( "Enabled", true );
oLabelProps.setPropertyValue( "Enabled", true );
oSubWindow.setVisible( true );
oSubPeer.invalidate( 8 );
ProgressValue += 8;
oProgressBarProps.setPropertyValue( "ProgressValue", new java.lang.Integer( ProgressValue ) );
oLabelProps.setPropertyValue( "Label", ProgressValue + "" );
oLabelProps.setPropertyValue( "BackgroundColor", new java.lang.Integer( 0xEFEFEF ) );
oSubPeer.setBackground( new java.lang.Integer( 0xEFEFEF ) );
|
To me, the window looks like the redraw messages aren't properly processed. That's strange, because when you set breakpoint in debugger then continue to run and switch to Writer, the progressbar window is redrawn correctly. Such behaviour happen when I run from toolbar button  |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Mar 10, 2009 1:11 pm Post subject: |
|
|
| QuestPC wrote: |
...
My biggest question - why seem to nobody write macros in Javascript? Rhino debugger really helped me few times already (type match, class browsing).. Built-in into Office, so you won't need to install Eclipse or some another environment. I'd use Python, but it has no debugger!
...
|
I am using OOBasic because of the easyness of the IDE, the presence of XRay, and the lack of these UNORuntime.queryinterface calls ...
If I want to interface to Java external jars, I use beanshell. This is quick turnaround, but no debugger. |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Tue Mar 10, 2009 1:14 pm Post subject: |
|
|
| QuestPC wrote: |
Now I've encountered a bigger problem - when I run the javascript macro from debugger the non-modal window is painted (displyaed) correctly - with background. But, when I run the macro from Writer toolbar button, only progressbar is updated, the window is completely transparent I even tried to place a large FixedText under ProgressBar with background and dynamically changable text. It's not being shown anyway. How can I make window refresh (paint, display non transparent) during my macro operation?
|
I did not observe this problem with my OO Basic code, but I have no idea why. Maybe it is the WindowServicename ? I defined these three subs as menu items, and everything redraws beautifully
| Code: | Global oProgressBarModel
Sub Increment
' xray oProgressBarModel
oProgressBarModel.ProgressValue = oProgressBarModel.ProgressValue + 10
if oProgressBarModel.ProgressValue > oProgressBarModel.ProgressValueMax then
oProgressBarModel.ProgressValue = oProgressBarModel.ProgressValue - oProgressBarModel.ProgressValueMax
endif
end sub
Sub Run
oDialogModel = createUnoService( "com.sun.star.awt.UnoControlDialogModel")
oProgressBarModel = oDialogModel.createInstance( "com.sun.star.awt.UnoControlProgressBarModel" )
oProgressBarModel.PositionX = 0
oProgressBarModel.PositionY = 0
oProgressBarModel.Width = 300
oProgressBarModel.Height = 20
oProgressBarModel.ProgressValueMin = 0
oProgressBarModel.ProgressValueMax = 100
oProgressBarModel.ProgressValue = 0
' insert the controls models into the dialog model
oDialogModel.insertByName( "myProgressBarName", oProgressBarModel )
' create the dialog control and set the model
oDialog = createUnoService( "com.sun.star.awt.UnoControlDialog")
oDialog.setModel( oDialogModel )
oProgressBarControl = oDialog.Controls(0)
'now generate the container Window
oToolkit = createUnoService("com.sun.star.awt.Toolkit")
Dim rBounds as new com.sun.star.awt.Rectangle
rBounds.X = 0
rBounds.Y = 0
rBounds.width = oProgressBarControl.PosSize.Width
rBounds.height = oProgressBarControl.PosSize.Height
Dim wd as new com.sun.star.awt.WindowDescriptor
wd.Type = com.sun.star.awt.WindowClass.TOP
wd.Bounds = rBounds
with com.sun.star.awt.WindowAttribute
wd.WindowAttributes = .BORDER + .MOVEABLE + .SIZEABLE + .CLOSEABLE
end with
wd.WindowServiceName = "dialog"
oContWin = oToolkit.createWindow(wd)
'now put it into a frame. This is to be able to close it.
oFrame = createUnoService("com.sun.star.frame.Frame")
oFrame.initialize(oContWin)
StarDesktop.Frames.append(oFrame)
oFrame.Name = "ms777Frame"
oFrame.Title = "ms7Title"
'last but not least let the progress bar show itself with the container window as the parent
oProgressBarControl.createPeer(oToolkit, oContWin)
oContWin.setVisible(True)
for k=0 to 100 step 5
oProgressBarModel.ProgressValue = k
wait(500)
next k
End Sub
Sub StopProgress
' the following lines can be called from everywhere to close the progress frame. No global var needed.
for k= StarDesktop.Frames.Count-1 to 0 step -1
oF = StarDesktop.Frames.getByIndex(k)
if oF.Name = "ms777Frame" then
oF.dispose
endif
next k
End Sub |
|
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Tue Mar 10, 2009 10:51 pm Post subject: |
|
|
| Quote: | | I did not observe this problem with my OO Basic code, but I have no idea why. Maybe it is the WindowServicename ? I defined these three subs as menu items, and everything redraws beautifully |
Well, I've finally found where these constants for setting WindowAttributes, WindowServicename and XWindowPeer::invalidate() are located. I primarily use "StarOffice8 developers guide" in pdf format. These are barely mentioned there. My guess was that SDK should have definitions in C++ headers files (*.h). No luck! Finally found all of these in SDK html help files. Still, no luck even with the following codes
| Code: |
aWinDesc.WindowServiceName = "messbox"; // I've tried MANY different values of this!
aWinDesc.WindowAttributes = 16+32+64+128;
|
| Code: |
oSubPeer.invalidate( 1+4+8+16 );
|
*Sigh* I probably should try converting my macro to Java. But that requires too much of the time and my time is limited (another work awaits).
Maybe the lack of window redraw when running from toolbar button is only related to Javascript macroses, I don't know :-/
OO Basic is easy it's just turned out to be too bloated code for my Writer statistical macro, which uses lots of arrays. That's why I've choosed Rhino and Javascript. |
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Thu Mar 12, 2009 12:06 am Post subject: |
|
|
I've checked out the sample by the link given by SergeM
The only two real differences between that code and mine is value of WindowDescriptor.Type and WindowDescriptor.Parent.
When I call xDialog::execute() it becomes an modal in any case anyway (Strange, I wonder if that worked in that case?)
By the way, that code results WindowDescriptor.Parent to be set null, which is suspicious to me. I think my code is more correct. Anyway, I've tried both ways and none seem to redraw correctly I give up and leave it as is. Here's my code, maybe it will be useful to someone:
Init:
| Code: |
// window definitions
var Progress = { value: 0, max: 0 };
var nonmodRect = { posx: 0, posy: 0, width: 210, height: 20 };
var nonmodProps = [
{name: "Name", value: "NonModDialog"},
{name: "Closeable", value: false},
{name: "Moveable", value: true},
{name: "Sizeable", value: true},
{name: "Title", value: "Свежий взгляд - пожалуйста подождите..."},
{name: "BackgroundColor", value: new java.lang.Integer( 0xEEEEEE )},
{name: "PositionX", value: new java.lang.Integer( 0 )},
{name: "PositionY", value: new java.lang.Integer( 0 )},
{name: "Width", value: new java.lang.Integer( nonmodRect.width )},
{name: "Height", value: new java.lang.Integer( nonmodRect.height )}
];
var progressProps = [
{name: "Name", value: "ProgressBar1"},
{name: "PositionX", value: new java.lang.Integer( 5 )},
{name: "PositionY", value: new java.lang.Integer( 5 )},
{name: "Width", value: new java.lang.Integer( nonmodRect.width - 5 )},
{name: "Height", value: new java.lang.Integer( nonmodRect.height -5 )},
{name: "ProgressValueMin", value: new java.lang.Integer( 0 )},
{name: "ProgressValueMax", value: new java.lang.Integer( 200 )},
{name: "ProgressValue", value: new java.lang.Integer( Progress.value )}
];
// code
oDoc = UnoRuntime.queryInterface( XModel, XSCRIPTCONTEXT.getInvocationContext() );
if ( !oDoc )
oDoc = XSCRIPTCONTEXT.getDocument();
oContext=XSCRIPTCONTEXT.getComponentContext()
oController = oDoc.getCurrentController();
oFrame = oController.getFrame();
oContainerWindow = oFrame.getContainerWindow();
oContWindowPeer = UnoRuntime.queryInterface( XWindowPeer, oContainerWindow );
ProcessWnd = new NonModalWnd( oContext, oContWindowPeer, nonmodRect );
ProcessWnd.invalidate( InvalidateStyle.UPDATE );
ProcessWnd.createDialog( nonmodProps );
//ProcessWnd.executeDialog();
ProcessWnd.addControl( "ProgressBar", progressProps );
ProcessWnd.Hide();
ProcessWnd.Show();
// get text from the document
xTextDoc = UnoRuntime.queryInterface( XTextDocument, oDoc );
xText = xTextDoc.getText();
main(xText);
ProcessWnd.Hide();
ProcessWnd.Destroy();
function NonModalWnd( Context, ContWinPeer, Rect ) {
this.contextInstance = function( InstName ) {
return this.CompServMgr.createInstanceWithContext( InstName, this.Context );
}
this.createDialog = function( Props ) {
var Dialog = this.contextInstance( "com.sun.star.awt.UnoControlDialog" );
this.xDialog = UnoRuntime.queryInterface( XDialog, Dialog );
this.DialogModel = this.contextInstance( "com.sun.star.awt.UnoControlDialogModel" );
this.DialogServMgr = UnoRuntime.queryInterface( XMultiServiceFactory, this.DialogModel );
var oDialogModelProps = UnoRuntime.queryInterface( XPropertySet, this.DialogModel );
//PropInfo = oDialogModelProps.getPropertySetInfo();
//Props = PropInfo.getProperties();
//Prop1 = oDialogModelProps.getPropertyValue( "DefaultControl" );
this.setControlProps( oDialogModelProps, Props );
var oDialogControlModel = UnoRuntime.queryInterface( XControlModel, this.DialogModel );
var oDialogControl = UnoRuntime.queryInterface( XControl, Dialog );
oDialogControl.setModel( oDialogControlModel );
// insert dialog into subwindow
oDialogControl.createPeer( this.xToolkit, this.SubPeer );
}
this.executeDialog = function() {
this.xDialog.execute();
}
// returns XPropertySet of the previousely added control with name ControlName
this.getControlPropsByName = function( ControlName ) {
var Control;
for ( var i in this.controls ) {
Control = this.controls[i];
if ( Control.name == ControlName ) {
return UnoRuntime.queryInterface( XPropertySet, Control.model );
}
}
return null;
}
// returns string value of "Name" property, if found, otherwise empty string
this.setControlProps = function( ControlProps, Props ) {
var NameVal = "";
var Prop;
for ( var i in Props ) {
Prop = Props[i];
ControlProps.setPropertyValue( Prop.name, Prop.value );
if ( Prop.name == "Name") {
NameVal = Prop.value;
}
}
return NameVal;
}
this.setControlPropsByName = function( ControlName, Props) {
var ControlProps = this.getControlPropsByName( ControlName );
if ( ControlProps !=null ) {
this.setControlProps( ControlProps, Props );
}
}
this.addControl = function( ControlType, Props ) {
var oControlModel = this.DialogServMgr.createInstance( "com.sun.star.awt.UnoControl" + ControlType + "Model" );
var ControlName = ControlType; // used by default when the name is not set in Props
var oControlProps = UnoRuntime.queryInterface( XPropertySet, oControlModel );
var name=this.setControlProps( oControlProps, Props );
if ( name != "") {
ControlName = name;
}
this.controls[ this.controls.length ] = {name: ControlName, model: oControlModel};
// insert the controls models into the dialog model
var xDialogNameContainer = UnoRuntime.queryInterface( XNameContainer, this.DialogModel );
xDialogNameContainer.insertByName( ControlName, oControlModel );
}
this.Show = function() {
this.SubWindow.setVisible( true );
}
this.Hide = function() {
this.SubWindow.setVisible( false );
}
this.setBgr = function( bgr ) {
this.SubPeer.setBackground( new java.lang.Integer( bgr ) );
}
this.invalidate = function( mode ) {
this.SubPeer.invalidate( mode );
}
this.Destroy = function() {
this.xTreeRoot.getFrames().remove( this.SubFrame );
this.SubWindow.dispose();
}
this.Context = Context;
this.CompServMgr = Context.getServiceManager()
this.ContWinPeer = ContWinPeer;
this.rect = Rect;
this.controls = new Array();
var oToolkit = this.contextInstance( "com.sun.star.awt.Toolkit" );
this.xToolkit = UnoRuntime.queryInterface( XToolkit, oToolkit );
var aWinDesc = new WindowDescriptor();
aWinDesc.Type = WindowClass.TOP;
aWinDesc.WindowServiceName = "";
aWinDesc.ParentIndex = -1;
aWinDesc.Parent = ContWinPeer;
//aWinDesc.Parent = this.xToolkit.getDesktopWindow();
aWinDesc.Bounds = new Rectangle( Rect.posx, Rect.posy, Rect.width, Rect.height );
aWinDesc.WindowAttributes = WindowAttribute.FULLSIZE;
this.SubPeer = this.xToolkit.createWindow( aWinDesc );
this.SubWindow = UnoRuntime.queryInterface( XWindow, this.SubPeer );
var oFrameTask = this.contextInstance( "com.sun.star.frame.Frame" );
this.SubFrame = UnoRuntime.queryInterface( XFrame, oFrameTask );
// create subwindow as a parent of document window
this.SubFrame.initialize( this.SubWindow );
var xDesktop = this.contextInstance( "com.sun.star.frame.Desktop" );
this.xTreeRoot = UnoRuntime.queryInterface( XFramesSupplier, xDesktop );
var xChildContainer = this.xTreeRoot.getFrames();
xChildContainer.append( this.SubFrame );
this.SubWindow.setPosSize( Rect.posx, Rect.posy, Rect.width, Rect.height, 0 );
}
|
Update:
| Code: |
// update progressbar
Progress.value += 8;
ProcessWnd.setControlPropsByName( "ProgressBar1",
[ {name: "ProgressValue", value: new java.lang.Integer( Progress.value )} ] );
ProcessWnd.setBgr( 0xEFEFEF );
ProcessWnd.invalidate( InvalidateStyle.UPDATE |
InvalidateStyle.CHILDREN |
InvalidateStyle.TRANSPARENT |
InvalidateStyle.NOCLIPCHILDREN );
|
|
|
| Back to top |
|
 |
susanspy Newbie

Joined: 13 Mar 2009 Posts: 1
|
Posted: Fri Mar 13, 2009 8:28 am Post subject: |
|
|
Hello all,
Susan here, i am new here & so to openoffice as well so please bare with my easy questions. this is the issue i am facing When I remove xDialog.execute() and oXComponent.dispose() the dialog window is being displayed, yet progress is not updated.
any updates on the same>?
all help appreciated.
Cheers!!! _________________ keyword tools~search keywords
Keyword Tracking Tool~overture tool
Last edited by susanspy on Sun Mar 29, 2009 1:35 am; edited 1 time in total |
|
| Back to top |
|
 |
eysed General User

Joined: 08 Feb 2009 Posts: 5
|
Posted: Fri Mar 13, 2009 11:47 am Post subject: |
|
|
| Can those problems be because of a global variable with the same name as one of your variables? Try to give all your variables more specific names such as oDialogxznn or oDlg0123, not just oDialog. If you have backups of libraries with repeated names they can conflict with each other. The problem can be caused by a variable with a common name like "a", "b". |
|
| Back to top |
|
 |
QuestPC General User

Joined: 12 Jan 2009 Posts: 17
|
Posted: Sat Mar 14, 2009 3:25 am Post subject: |
|
|
Well, it seems that few different persons reported running non-modal dialogs succesfully in OO Basic. You may use that as example. But, basic language is not very suitable for my needs. And I have no time to try in Java (project deadline).
It seems that if you want to get similicity - use OO Basic. If you want the power, use Java. It also seems that OpenOffice itself has built on top of Java objects, to speed up probably uses direct interaction in C++ (Java itself is probably written with C++).
I probably made mistake choosing Javascript over Java. My arguments were though, that OpenOffice is WYSIWYG application, so built-in debugger is the must.
Only OO Basic and Javascript has built-in debugger, so I've used Javascript.
If I had to rewrite my macros, I'd go for Java and Eclipse. |
|
| Back to top |
|
 |
|
|
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
|