Modal/non-modal dialog

Great idea, colleague! Let’s try together (Forum.ods):

Sub Test2
  Dim oDP, oDialog
  StarDeskTop.loadComponentFromUrl ("private:factory/scalc", "_blank", 0, Array())
  oDP=GetProcessServiceManager.createInstanceWithArguments("com.sun.star.awt.DialogProvider", Array(ThisComponent)) 
  oDialog = oDP.createDialog( "vnd.sun.star.script:Standard.Dialog1?location=document")
  oDialog.execute
End Sub

Macro works.

CreateUnoDialog - to the archive. :slightly_smiling_face:

To open a dialog in non-modal mode, you need to replace the line

oDialog.execute

with

oDialog.Visible=True

and make oDialog a global variable.
In this option, the script execution flow is terminated. No need “loop trick”.
To end the dialog, you can use a macro assigned to handle pressing a button, or a listener like @JohnSUN 's.

oDialog.Visible=False
1 Like

Yes, you can make a non-modal dialog. You just need to use the loop trick and .setVisible() instead of .Execute(). Approximately like this:

Dim oDialog As Variant 
Dim bDialogShown As Boolean

Sub ShowDialog()
	DialogLibraries.LoadLibrary("Standard")
	oDialog = CreateUnoDialog(DialogLibraries.GetByName("Standard").GetByName("nonModal"))
	oDialog.addTopWindowlistener(createUnoListener("TopListen_", "com.sun.star.awt.XTopWindowListener")) 
	bDialogShown=True
	While bDialogShown
		oDialog.setVisible(bDialogShown)
		Wait 330
	Wend
	oDialog.dispose()
End Sub
Rem Even though most of the methods do nothing, you must describe them all.
Sub TopListen_WindowClosing
	bDialogShown = False
End Sub
Sub  TopListen_windowOpened
End Sub
Sub  TopListen_windowClosed
End Sub
Sub TopListen_windowMinimized
End Sub
Sub  TopListen_windowNormalized
End Sub
Sub  TopListen_windowActivated
End Sub
Sub  TopListen_windowDeactivated
End Sub
Sub  TopListen_disposing
End Sub
2 Likes

I’m happy how to make a non-modal, John, but can I get controls to work on such?

Why not? Just add routines for each control and define it as an event in the control’s property. For example (not for self-promotion - I just don’t want to waste time creating a separate example) install Bugerra and look at the DialogTools module and the bugerr dialog (Events tab for form controls).

1 Like

Yes, this lets you create interactive “palettes” for LO Calc the same way as can be done with VBA/Excel. For example, you could have dialogues open on a smart board to allow student interaction for a math game or a dialogue with multiple actions at your side to help with monotonous entry. The dialogue will float over LO just as expected.

P.S. Bugerra looks cool. I for one am totally okay with any residual self-promotion at that level!

NonModalDialog.ods (11.5 KB)

1 Like