Page 1 of 1

[Solved] Non-modal Dialog

Posted: Thu Jan 28, 2016 12:09 pm
by mikephillips
Most links here do not appear to work to threads about this - PHP script broken.

I wish to have a Dialog which is non-modal to allow scrolling of a spreadsheet behind.

Re: Non-modal Dialog

Posted: Thu Jan 28, 2016 3:26 pm
by FJCC
I had the attached file lying around with a very simple example.

Re: Non-modal Dialog

Posted: Thu Jan 28, 2016 7:02 pm
by mikephillips
Hmm! Thanks for digging that out, FJCC, but I am out of my depth here. I see a Command button on the sheet which initially opens Xray and when that is closed a non-modal Dialog1 (good - just what I want!). Could you please explain (very patiently) to me where is the code to open Dialog1 and what makes it non-modal? The sheet is opening 'Read Only' for me so I cannot examine it.

Re: Non-modal Dialog

Posted: Thu Jan 28, 2016 10:04 pm
by FJCC
I changed the code so there is a variable called Modal. If it is true, The dialog will come up but you can't interact with the spreadsheet and the dialog as it exists is useless. If you set Modal to False, you can click on the sheet and change the content of the text box in the dialog. Note that in the Modal version, the dialog is closed with the OK button and in the non-modal version you have to click on the radio button. The Do loop in the code is watching the state of the radio button. Of course, you normally make a dialog for only one of these situations.

Re: Non-modal Dialog

Posted: Thu Jan 28, 2016 10:36 pm
by mikephillips
Thanks for that - I'm almost there!

Re: Non-modal Dialog

Posted: Sat Jan 30, 2016 4:58 pm
by mikephillips
For those, like me - beginners - who do not want the 'Mickey Mouse' soultions sometimes offered (and with thanks to FJCC) this is the simple code I am using to produce a non-Modal dialogue (d1) over my Calc sheet. '

Code: Select all

d1.visible = true
	do        
           wait (100)
	loop
Incredibly simple but VERY difficult to track down, and it should not be! A non-modal option should be a 'bread and butter' requirement for any GUI with dialogues. I am amazed it does not exist in OO. NB I have not bothered with an 'exit' from the non-modal loop since I have a 'Close Programme 'option on d1 anyway for when I no longer need the other functions on it.

Re: [Solved] Non-modal Dialog

Posted: Thu Jun 11, 2020 1:18 am
by JeJe
Resurrecting this old thread in case anyone new looks for this.

This is how to do this without a Wait timer:

Code: Select all

'your library with this code has to be in MyMacros not in the document or the URI will give an error.

Sub Test
	oParent = ThisComponent.getCurrentController().getFrame().getContainerWindow()
	dlg = CreateNonModalDialog(oparent,"JeTest.Dialog1",true) 'example library called JeTest and Dialog called Dialog1
	dlg.setpossize 100,100,500,500,15
	dlg.setvisible true
End Sub

Function CreateNonModalDialog(oParent,DialogParam, Closeable as boolean) As Variant
	dim dlg,CWP,sURL As String
	sURL = "vnd.sun.star.script:" & DialogParam & "?location=" & "application"
	CWP = CreateUnoService("com.sun.star.awt.ContainerWindowProvider")
	dlg = CWP.createContainerWindow(sURL, "", oParent, nothing)
	if Closeable then 'if want closeable need this
	dlg.addTopWindowListener(CreateUnoListener("NonModalWindowListener_", "com.sun.star.awt.XTopWindowListener"))
	end if
	CreateNonModalDialog = dlg
End Function

'XTopWindowListener subs
Sub NonModalWindowListener_disposing(ev) 
End Sub
Sub NonModalWindowListener_windowOpened(ev)
End Sub
Sub NonModalWindowListener_windowClosing(ev) 
ev.source.dispose 'if want closeable need this
End Sub
Sub NonModalWindowListener_windowClosed(ev)
End Sub
Sub NonModalWindowListener_windowMinimized(ev)
End Sub
Sub NonModalWindowListener_windowNormalized(ev)
End Sub
Sub NonModalWindowListener_windowActivated(ev)
End Sub
Sub NonModalWindowListener_windowDeactivated(ev)
End Sub
'/XTopWindowListener subs

sub commandclose(ev) 'if window is not closeable you might want a button perhaps to close it
ev.source.context.dispose
end sub


Re: [Solved] Non-modal Dialog

Posted: Thu Jun 11, 2020 9:11 am
by mikephillips
Jeje - many thanks for resurrecting my query. I will look with interest at your solution.

Re: [Solved] Non-modal Dialog

Posted: Thu Jun 11, 2020 10:17 am
by Villeroy
Very interesting, indeed. In order to make this work with non-document windows such as the IDE or the welcome screen:

Code: Select all

   oParent = StarDesktop.getCurrentFrame().getContainerWindow()
This is a good example how the total lack of documentation inhibits thousands of interested coders.
Documentation on createContainerWindow wrote:Methods' Summary
createContainerWindow creates a window for the given URL
Methods' Details
createContainerWindow( [in] string URL,
[in] string WindowType,
[in] XWindowPeer xParent,
[in] ::com::sun::star::uno::XInterface xHandler )
raises( ::com::sun::star::lang::IllegalArgumentException );

Description
creates a window for the given URL
Parameter URL
is the URL.
Today I've learned that "the URL" is meant to be a dialog's script-URL, finally after 20 years.

The xHandler argument is the next interesting argument.

Re: [Solved] Non-modal Dialog

Posted: Thu Jun 11, 2020 10:47 am
by JeJe
My code above is based on part of the code (the 'inner' dialog) from the resizable dialog thread which was originally work by hanya.

viewtopic.php?f=21&t=92867

You can create a resizable dialog with that code - which is fine with a modal dialog, but I found there's a crash if the document window is closed before the dialog is if its non-modal.

Re: [Solved] Non-modal Dialog

Posted: Thu Jun 11, 2020 1:10 pm
by JeJe
You can use another dialog (modal or non-modal) as the oParent with oParent = Dialog.getPeer (but the new dialog must have with title bar set to yes, which is the default value, or there will be a crash)

Edit: indeed generally using this method to try to create a dialog with title bar changed to no causes a crash. Not a problem, just a note that that can't be done.