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

Non-modal dialog in OpenOffice

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


Joined: 12 Jan 2009
Posts: 17

PostPosted: Thu Mar 05, 2009 3:30 am    Post subject: Non-modal dialog in OpenOffice Reply with quote

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
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Mar 06, 2009 10:39 am    Post subject: Reply with quote

Have you read this post ?
non-modal dialog(sloved in Java) http://www.oooforum.org/forum/viewtopic.phtml?t=43653
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Sat Mar 07, 2009 11:02 am    Post subject: Reply with quote

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
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Sat Mar 07, 2009 12:02 pm    Post subject: Reply with quote

... 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
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Tue Mar 10, 2009 12:30 am    Post subject: Reply with quote

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 Sad 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 Sad
Back to top
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Tue Mar 10, 2009 12:44 am    Post subject: Reply with quote

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 Sad

By the way, java code examples use constans in XWindowPeer::invalidate() and WindowDescriptor::WindowAttributes() but I can't find their definition for JavaScript Sad
Would the window not being correctly redrawn because I've guessed wrong parameter calls?
Back to top
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Tue Mar 10, 2009 2:28 am    Post subject: Reply with quote

With the following progress update code everything is flashing, yet the same progressbar without any colored background Sad
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
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Tue Mar 10, 2009 2:54 am    Post subject: Reply with quote

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 Sad
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Tue Mar 10, 2009 1:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Tue Mar 10, 2009 1:14 pm    Post subject: Reply with quote

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 Sad 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
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Tue Mar 10, 2009 10:51 pm    Post subject: Reply with quote

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
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Thu Mar 12, 2009 12:06 am    Post subject: Reply with quote

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 Sad 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
View user's profile Send private message
susanspy
Newbie
Newbie


Joined: 13 Mar 2009
Posts: 1

PostPosted: Fri Mar 13, 2009 8:28 am    Post subject: Reply with quote

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
View user's profile Send private message
eysed
General User
General User


Joined: 08 Feb 2009
Posts: 5

PostPosted: Fri Mar 13, 2009 11:47 am    Post subject: Reply with quote

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
View user's profile Send private message
QuestPC
General User
General User


Joined: 12 Jan 2009
Posts: 17

PostPosted: Sat Mar 14, 2009 3:25 am    Post subject: Reply with quote

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